2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* drivers/macintosh/mac_hid.c
|
|
|
|
*
|
|
|
|
* HID support stuff for Macintosh computers.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2000 Franz Sirl.
|
|
|
|
*
|
|
|
|
* This file will soon be removed in favor of an uinput userspace tool.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/proc_fs.h>
|
|
|
|
#include <linux/sysctl.h>
|
|
|
|
#include <linux/input.h>
|
|
|
|
#include <linux/module.h>
|
2007-08-22 21:01:35 +00:00
|
|
|
#include <linux/kbd_kern.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
|
2005-09-15 07:01:41 +00:00
|
|
|
static struct input_dev *emumousebtn;
|
|
|
|
static int emumousebtn_input_register(void);
|
2007-02-10 20:35:12 +00:00
|
|
|
static int mouse_emulate_buttons;
|
2005-04-16 22:20:36 +00:00
|
|
|
static int mouse_button2_keycode = KEY_RIGHTCTRL; /* right control key */
|
|
|
|
static int mouse_button3_keycode = KEY_RIGHTALT; /* right option key */
|
2007-02-10 20:35:12 +00:00
|
|
|
static int mouse_last_keycode;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#if defined(CONFIG_SYSCTL)
|
|
|
|
/* file(s) in /proc/sys/dev/mac_hid */
|
2007-03-07 22:41:07 +00:00
|
|
|
static ctl_table mac_hid_files[] = {
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
.ctl_name = DEV_MAC_HID_MOUSE_BUTTON_EMULATION,
|
|
|
|
.procname = "mouse_button_emulation",
|
|
|
|
.data = &mouse_emulate_buttons,
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
|
|
|
.proc_handler = &proc_dointvec,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.ctl_name = DEV_MAC_HID_MOUSE_BUTTON2_KEYCODE,
|
|
|
|
.procname = "mouse_button2_keycode",
|
|
|
|
.data = &mouse_button2_keycode,
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
|
|
|
.proc_handler = &proc_dointvec,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.ctl_name = DEV_MAC_HID_MOUSE_BUTTON3_KEYCODE,
|
|
|
|
.procname = "mouse_button3_keycode",
|
|
|
|
.data = &mouse_button3_keycode,
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
|
|
|
.proc_handler = &proc_dointvec,
|
|
|
|
},
|
|
|
|
{ .ctl_name = 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* dir in /proc/sys/dev */
|
2007-03-07 22:41:07 +00:00
|
|
|
static ctl_table mac_hid_dir[] = {
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
.ctl_name = DEV_MAC_HID,
|
|
|
|
.procname = "mac_hid",
|
|
|
|
.maxlen = 0,
|
|
|
|
.mode = 0555,
|
|
|
|
.child = mac_hid_files,
|
|
|
|
},
|
|
|
|
{ .ctl_name = 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* /proc/sys/dev itself, in case that is not there yet */
|
2007-03-07 22:41:07 +00:00
|
|
|
static ctl_table mac_hid_root_dir[] = {
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
.ctl_name = CTL_DEV,
|
|
|
|
.procname = "dev",
|
|
|
|
.maxlen = 0,
|
|
|
|
.mode = 0555,
|
|
|
|
.child = mac_hid_dir,
|
|
|
|
},
|
|
|
|
{ .ctl_name = 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct ctl_table_header *mac_hid_sysctl_header;
|
|
|
|
|
|
|
|
#endif /* endif CONFIG_SYSCTL */
|
|
|
|
|
|
|
|
int mac_hid_mouse_emulate_buttons(int caller, unsigned int keycode, int down)
|
|
|
|
{
|
|
|
|
switch (caller) {
|
|
|
|
case 1:
|
|
|
|
/* Called from keyboard.c */
|
|
|
|
if (mouse_emulate_buttons
|
|
|
|
&& (keycode == mouse_button2_keycode
|
|
|
|
|| keycode == mouse_button3_keycode)) {
|
|
|
|
if (mouse_emulate_buttons == 1) {
|
2005-09-15 07:01:41 +00:00
|
|
|
input_report_key(emumousebtn,
|
2005-04-16 22:20:36 +00:00
|
|
|
keycode == mouse_button2_keycode ? BTN_MIDDLE : BTN_RIGHT,
|
|
|
|
down);
|
2005-09-15 07:01:41 +00:00
|
|
|
input_sync(emumousebtn);
|
2005-04-16 22:20:36 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
mouse_last_keycode = down ? keycode : 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-04-18 04:25:38 +00:00
|
|
|
static struct lock_class_key emumousebtn_event_class;
|
|
|
|
static struct lock_class_key emumousebtn_mutex_class;
|
|
|
|
|
2005-09-15 07:01:41 +00:00
|
|
|
static int emumousebtn_input_register(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-11-24 05:43:22 +00:00
|
|
|
int ret;
|
|
|
|
|
2005-09-15 07:01:41 +00:00
|
|
|
emumousebtn = input_allocate_device();
|
|
|
|
if (!emumousebtn)
|
|
|
|
return -ENOMEM;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-04-26 01:40:01 +00:00
|
|
|
lockdep_set_class(&emumousebtn->event_lock, &emumousebtn_event_class);
|
|
|
|
lockdep_set_class(&emumousebtn->mutex, &emumousebtn_mutex_class);
|
2008-04-18 04:25:38 +00:00
|
|
|
|
2005-09-15 07:01:41 +00:00
|
|
|
emumousebtn->name = "Macintosh mouse button emulation";
|
|
|
|
emumousebtn->id.bustype = BUS_ADB;
|
|
|
|
emumousebtn->id.vendor = 0x0001;
|
|
|
|
emumousebtn->id.product = 0x0001;
|
|
|
|
emumousebtn->id.version = 0x0100;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-10-19 06:40:32 +00:00
|
|
|
emumousebtn->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
|
|
|
|
emumousebtn->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) |
|
|
|
|
BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
|
|
|
|
emumousebtn->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-11-24 05:43:22 +00:00
|
|
|
ret = input_register_device(emumousebtn);
|
|
|
|
if (ret)
|
|
|
|
input_free_device(emumousebtn);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-11-24 05:43:22 +00:00
|
|
|
return ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 22:41:07 +00:00
|
|
|
static int __init mac_hid_init(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-09-15 07:01:41 +00:00
|
|
|
int err;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-09-15 07:01:41 +00:00
|
|
|
err = emumousebtn_input_register();
|
|
|
|
if (err)
|
|
|
|
return err;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#if defined(CONFIG_SYSCTL)
|
2007-02-14 08:34:09 +00:00
|
|
|
mac_hid_sysctl_header = register_sysctl_table(mac_hid_root_dir);
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif /* CONFIG_SYSCTL */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
device_initcall(mac_hid_init);
|