Skip to contentSkip to conversation

usb/input: Add support for fn key on Apple PowerBooks

PATCH/RFC? Michael Hanselmann 7 participants 46 messages Dec 25, 2005 – Jan 14, 2006 USB

lore
Share & tools
lore
#0 lore raw

This patch adds a basic input hook support to usbhid because the quirks method is outrunning the available bits. A hook for the Fn and Numlock keys on Apple PowerBooks is included.

---

drivers/usb/input/Kconfig +10 -0
diff -rNup linux-2.6.15-rc6.orig/drivers/usb/input/Kconfig linux-2.6.15-rc6/drivers/usb/input/Kconfig
@@ -37,6 +37,16 @@ config USB_HIDINPUT
 
 	  If unsure, say Y.
 
+config USB_HIDINPUT_POWERBOOK
+	bool "Enable support for iBook/PowerBook special keys"
+	default n
+	depends on USB_HIDINPUT
+	help
+	  Say Y here if you want support for the special keys (Fn, Numlock) on
+	  Apple iBooks and PowerBooks.
+
+	  If unsure, say N.
+
 config HID_FF
 	bool "Force feedback support (EXPERIMENTAL)"
 	depends on USB_HIDINPUT && EXPERIMENTAL
drivers/usb/input/Makefile +3 -0
diff -rNup linux-2.6.15-rc6.orig/drivers/usb/input/Makefile linux-2.6.15-rc6/drivers/usb/input/Makefile
@@ -25,6 +25,9 @@ endif
 ifeq ($(CONFIG_HID_FF),y)
 	usbhid-objs	+= hid-ff.o
 endif
+ifeq ($(CONFIG_USB_HIDINPUT_POWERBOOK),y)
+   usbhid-objs += hid-input-powerbook.o
+endif
 
 obj-$(CONFIG_USB_AIPTEK)	+= aiptek.o
 obj-$(CONFIG_USB_ATI_REMOTE)	+= ati_remote.o
drivers/usb/input/hid-input-powerbook.c +226 -0

226 lines not on this page · raw message

drivers/usb/input/hid-input.c +62 -1

105 lines not on this page · raw message

drivers/usb/input/hid.h +25 -0
diff -rNup linux-2.6.15-rc6.orig/drivers/usb/input/hid.h linux-2.6.15-rc6/drivers/usb/input/hid.h
@@ -368,10 +368,33 @@ struct hid_control_fifo {
 #define HID_CTRL_RUNNING	1
 #define HID_OUT_RUNNING		2
 
+struct hid_input_hook_device {
+	u16 idVendor;
+	u16 idProduct;
+};
+
+struct hid_input_hook {
+	struct list_head list;
+	struct hid_input_hook_device *devices;
+
+	int (*init)(struct hid_device*);
+	void (*exit)(struct hid_device*);
+	int (*event)(struct hid_device *hid, struct hid_field *field,
+		     struct hid_usage *usage, __s32 value, struct pt_regs *regs);
+	int (*conf)(struct hid_input *hidinput, struct hid_field *field,
+		    struct hid_usage *usage);
+};
+
+#ifdef CONFIG_USB_HIDINPUT_POWERBOOK
+extern struct hid_input_hook usbhid_input_powerbook;
+#endif
+
 struct hid_input {
 	struct list_head list;
 	struct hid_report *report;
 	struct input_dev *input;
+
+	struct hid_input_hook *hook;
 };
 
 struct hid_device {							/* device report descriptor */
@@ -431,6 +454,8 @@ struct hid_device {							/* device repo
 	void (*ff_exit)(struct hid_device*);                            /* Called by hid_exit_ff(hid) */
 	int (*ff_event)(struct hid_device *hid, struct input_dev *input,
 			unsigned int type, unsigned int code, int value);
+
+	void *hook_private;
 };
 
 #define HID_GLOBAL_STACK_SIZE 4
#1 lore raw
Quoted 7 lines · Michael Hanselmann

This patch adds a basic input hook support to usbhid because the quirks method is outrunning the available bits. A hook for the Fn and Numlock keys on Apple PowerBooks is included.

This makes the keyboard useable on latest generations of Apple PowerBooks, so please apply asap :)

Ben.

#2 lore raw
In reply to Michael Hanselmann
Quoted 3 lines · Michael Hanselmann

This patch adds a basic input hook support to usbhid because the quirks method is outrunning the available bits. A hook for the Fn and Numlock keys on Apple PowerBooks is included.

Well, we have used 11 out of 32 available bits so there still some reserves. My concern is that your implementation allows only one hook to be installed while with quirks you can have several of them active per device.

As far as the hook itself - i have that feeling that it should not be done in kernel but via a keymap.

Signature · 1 line
Dmitry
#3 lore raw
Quoted 9 lines · Dmitry Torokhov
Quoted 3 lines · Michael Hanselmann

This patch adds a basic input hook support to usbhid because the quirks method is outrunning the available bits. A hook for the Fn and Numlock keys on Apple PowerBooks is included.

Well, we have used 11 out of 32 available bits so there still some reserves. My concern is that your implementation allows only one hook to be installed while with quirks you can have several of them active per device.

I haven't looked at the details so I can't comment much there, though the hook has the interest of making it possible to have it in a module that gets separately loaded if necessary, no ? Maybe the driver could maintain a list of hooks ?

Quoted 2 lines

As far as the hook itself - i have that feeling that it should not be done in kernel but via a keymap.

While I understand your feeling, it's a bit annoying in this specific case because previous models did this in hardware and all mac keymaps already account for that. Knowing how nasty it has been to get mac keymaps updated and in a good shape, and to get distros to properly get them, it makes a lot of sense to have this small hook in the kernel that makes the USB keyboard behave exactly like the older ADB couterparts.

Ben.

#35 lore raw
In reply to Dmitry Torokhov
Quoted 4 lines · Dmitry Torokhov

Well, we have used 11 out of 32 available bits so there still some reserves. My concern is that your implementation allows only one hook to be installed while with quirks you can have several of them active per device.

Below you find an implementation using quirks:

---

drivers/usb/input/hid-core.c +4 -0
diff -rNup linux-2.6.15-rc7.orig/drivers/usb/input/hid-core.c linux-2.6.15-rc7/drivers/usb/input/hid-core.c
@@ -1580,6 +1580,10 @@ static struct hid_blacklist {
 	{ USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RUMBLEPAD, HID_QUIRK_BADPAD },
 	{ USB_VENDOR_ID_TOPMAX, USB_DEVICE_ID_TOPMAX_COBRAPAD, HID_QUIRK_BADPAD },
 
+	{ USB_VENDOR_ID_APPLE, 0x0214, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x0215, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x0216, HID_QUIRK_POWERBOOK_HAS_FN },
+
 	{ 0, 0 }
 };
 
drivers/usb/input/hid-input.c +134 -2

166 lines not on this page · raw message

drivers/usb/input/hid.h +3 -0
diff -rNup linux-2.6.15-rc7.orig/drivers/usb/input/hid.h linux-2.6.15-rc7/drivers/usb/input/hid.h
@@ -246,6 +246,9 @@ struct hid_item {
 #define HID_QUIRK_2WHEEL_MOUSE_HACK_5		0x100
 #define HID_QUIRK_2WHEEL_MOUSE_HACK_ON		0x200
 #define HID_QUIRK_2WHEEL_POWERMOUSE		0x400
+#define HID_QUIRK_POWERBOOK_HAS_FN		0x0000800
+#define HID_QUIRK_POWERBOOK_FN_ON		0x0001000
+#define HID_QUIRK_POWERBOOK_NUMLOCK_ON		0x0002000
 
 /*
  * This is the global environment of the parser. This information is
#36 lore raw
Quoted 1 line · Michael Hanselmann

+#define HID_QUIRK_POWERBOOK_NUMLOCK_ON 0x0002000

Aww, please ignore that one when looking at the patch. It's not used and I'll resubmit the patch anyway with a full Signed-off-by & Co. once you approve it.

Greets,
Michael

#37 lore raw
In reply to Michael Hanselmann
Quoted 7 lines · Michael Hanselmann
Quoted 4 lines · Dmitry Torokhov

Well, we have used 11 out of 32 available bits so there still some reserves. My concern is that your implementation allows only one hook to be installed while with quirks you can have several of them active per device.

Below you find an implementation using quirks:

I've been using the other patch for some time now and while it's a life-saver, it does have one annoying little issue: If you press a key with the Fn key down and release that key with the Fn key up, your key is stuck. That is, the patch changes the keycode for Up & Down events separately based on the Fn state at the time of the event.

What should be done is that when you release a key, you send the key up with the keycode that matches the Fn state at the time the key was pressed. That can easily be done using a simple bitmap that keeps track of the Fn state on keydown for the various keycodes.

Ben.

#38 lore raw
Quoted 4 lines · Benjamin Herrenschmidt

I've been using the other patch for some time now and while it's a life-saver, it does have one annoying little issue: If you press a key with the Fn key down and release that key with the Fn key up, your key is stuck.

I noticed something like that with the numlock key as well but didn't have time to fix it yet.

Other than that, have you found any keys that aren't mapped or are mapped incorrectly?

The new patch adds quite some code to hid-input.c, should it be configuratible via .config?

Thanks,
Michael

#39 lore raw
Quoted 11 lines · Michael Hanselmann
Quoted 4 lines · Benjamin Herrenschmidt

I've been using the other patch for some time now and while it's a life-saver, it does have one annoying little issue: If you press a key with the Fn key down and release that key with the Fn key up, your key is stuck.

I noticed something like that with the numlock key as well but didn't have time to fix it yet.

Other than that, have you found any keys that aren't mapped or are mapped incorrectly?

I haven't but then I haven't tested in depth neither. Such little bugs if any can always be fixed later anyway.

Quoted 2 lines

The new patch adds quite some code to hid-input.c, should it be configuratible via .config?

Possibly yes, since it's only useful for mac laptops...

Ben.

#45 lore raw
In reply to Michael Hanselmann
Quoted 13 lines · Michael Hanselmann
Quoted 4 lines · Dmitry Torokhov

Well, we have used 11 out of 32 available bits so there still some reserves. My concern is that your implementation allows only one hook to be installed while with quirks you can have several of them active per device.

Below you find an implementation using quirks:

---
diff -rNup linux-2.6.15-rc7.orig/drivers/usb/input/hid-core.c linux-2.6.15-rc7/drivers/usb/input/hid-core.c

drivers/usb/input/hid-core.c static struct hid_blacklist { · line 1586

Quoted 7 lines
drivers/usb/input/hid-core.c +4 -0
@@ -1580,6 +1580,10 @@ static struct hid_blacklist {
 	{ USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RUMBLEPAD, HID_QUIRK_BADPAD },
 	{ USB_VENDOR_ID_TOPMAX, USB_DEVICE_ID_TOPMAX_COBRAPAD, HID_QUIRK_BADPAD },
 
+	{ USB_VENDOR_ID_APPLE, 0x0214, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x0215, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x0216, HID_QUIRK_POWERBOOK_HAS_FN },
+

Works fine for me on a slightly older (jul '05) Powerbook after adding the following USB identifiers:

+       { USB_VENDOR_ID_APPLE, 0x020E, HID_QUIRK_POWERBOOK_HAS_FN },
+       { USB_VENDOR_ID_APPLE, 0x020F, HID_QUIRK_POWERBOOK_HAS_FN },
+       { USB_VENDOR_ID_APPLE, 0x030A, HID_QUIRK_POWERBOOK_HAS_FN },
+       { USB_VENDOR_ID_APPLE, 0x030B, HID_QUIRK_POWERBOOK_HAS_FN },

Mine is a 020F but the other three ones should be fine too (those are taken from the appletouch trackpad driver).

Stelian.

Signature · 1 line
Stelian Pop <[email protected]>
author Acked-by Rene Nussbaumer Acked-by Johannes Berg Acked-by Benjamin Herrenschmidt
#40 lore raw
In reply to Benjamin Herrenschmidt
Quoted 4 lines · Benjamin Herrenschmidt

I've been using the other patch for some time now and while it's a life-saver, it does have one annoying little issue: If you press a key with the Fn key down and release that key with the Fn key up, your key is stuck.

Here's another patch with this and some other issues fixed.

---

drivers/usb/input/Kconfig +10 -0
diff -rNup linux-2.6.15-rc7.orig/drivers/usb/input/Kconfig linux-2.6.15-rc7/drivers/usb/input/Kconfig
@@ -37,6 +37,16 @@ config USB_HIDINPUT
 
 	  If unsure, say Y.
 
+config USB_HIDINPUT_POWERBOOK
+	bool "Enable support for iBook/PowerBook special keys"
+	default n
+	depends on USB_HIDINPUT
+	help
+	  Say Y here if you want support for the special keys (Fn, Numlock) on
+	  Apple iBooks and PowerBooks.
+
+	  If unsure, say N.
+
 config HID_FF
 	bool "Force feedback support (EXPERIMENTAL)"
 	depends on USB_HIDINPUT && EXPERIMENTAL
drivers/usb/input/hid-core.c +8 -0
diff -rNup linux-2.6.15-rc7.orig/drivers/usb/input/hid-core.c linux-2.6.15-rc7/drivers/usb/input/hid-core.c
@@ -1580,6 +1580,14 @@ static struct hid_blacklist {
 	{ USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RUMBLEPAD, HID_QUIRK_BADPAD },
 	{ USB_VENDOR_ID_TOPMAX, USB_DEVICE_ID_TOPMAX_COBRAPAD, HID_QUIRK_BADPAD },
 
+	{ USB_VENDOR_ID_APPLE, 0x020E, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x020F, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x0214, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x0215, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x0216, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x030A, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x030B, HID_QUIRK_POWERBOOK_HAS_FN },
+
 	{ 0, 0 }
 };
 
drivers/usb/input/hid-input.c +169 -1

194 lines not on this page · raw message

drivers/usb/input/hid.h +10 -0
diff -rNup linux-2.6.15-rc7.orig/drivers/usb/input/hid.h linux-2.6.15-rc7/drivers/usb/input/hid.h
@@ -246,6 +246,8 @@ struct hid_item {
 #define HID_QUIRK_2WHEEL_MOUSE_HACK_5		0x100
 #define HID_QUIRK_2WHEEL_MOUSE_HACK_ON		0x200
 #define HID_QUIRK_2WHEEL_POWERMOUSE		0x400
+#define HID_QUIRK_POWERBOOK_HAS_FN		0x0000800
+#define HID_QUIRK_POWERBOOK_FN_ON		0x0001000
 
 /*
  * This is the global environment of the parser. This information is
@@ -431,6 +433,14 @@ struct hid_device {							/* device repo
 	void (*ff_exit)(struct hid_device*);                            /* Called by hid_exit_ff(hid) */
 	int (*ff_event)(struct hid_device *hid, struct input_dev *input,
 			unsigned int type, unsigned int code, int value);
+
+#ifdef CONFIG_USB_HIDINPUT_POWERBOOK
+	/* We do this here because it's only relevant for the
+	 * USB devices, not for all input_dev's.
+	 */
+	unsigned long pb_fn[NBITS(KEY_MAX)];
+	unsigned long pb_numlock[NBITS(KEY_MAX)];
+#endif
 };
 
 #define HID_GLOBAL_STACK_SIZE 4
#41 lore raw

drivers/usb/input/hid-input.c static struct { · line 128

Quoted 12 lines · Michael Hanselmann
drivers/usb/input/hid-input.c +12 -0
+static int powerbook_fkeysfirst = 1;
+module_param_named(pb_fkeysfirst, powerbook_fkeysfirst, bool, 0644);
+MODULE_PARM_DESC(powerbook_fkeysfirst, "Use fn special keys only while pressing fn");
+
+static int powerbook_enablefnkeys = 1;
+module_param_named(pb_enablefnkeys, powerbook_enablefnkeys, bool, 0644);
+MODULE_PARM_DESC(powerbook_enablefnkeys, "Enable fn special keys");
+
+static int powerbook_enablekeypad = 1;
+module_param_named(pb_enablekeypad, powerbook_enablekeypad, bool, 0644);
+MODULE_PARM_DESC(powerbook_enablekeypad, "Enable keypad keys");
+#endif

I think these should be inverted to, something like pbook_disable_keypad, pbook_disable_fnkeys and pbook_fnfirst.

Two reasons. First, it just makes more sense to pass a module param to turn something on (doing powerbook_enablekeypad=0 isn't as intuitive as pbook_disable_keypad=1). Second reason is that since these are static vars, defaulting them to uninitialized (leaving them in the bss, as 0) reduces binary size.

Signature · 3 lines
   Ben Collins <[email protected]>
   Developer
   Ubuntu Linux
#42 lore raw

Hello Ben

Quoted 2 lines · Ben Collins

I think these should be inverted to, something like pbook_disable_keypad, pbook_disable_fnkeys and pbook_fnfirst.

I've changed that in the patch below:

---

drivers/usb/input/Kconfig +10 -0
diff -rNup linux-2.6.15-rc7.orig/drivers/usb/input/Kconfig linux-2.6.15-rc7/drivers/usb/input/Kconfig
@@ -37,6 +37,16 @@ config USB_HIDINPUT
 
 	  If unsure, say Y.
 
+config USB_HIDINPUT_POWERBOOK
+	bool "Enable support for iBook/PowerBook special keys"
+	default n
+	depends on USB_HIDINPUT
+	help
+	  Say Y here if you want support for the special keys (Fn, Numlock) on
+	  Apple iBooks and PowerBooks.
+
+	  If unsure, say N.
+
 config HID_FF
 	bool "Force feedback support (EXPERIMENTAL)"
 	depends on USB_HIDINPUT && EXPERIMENTAL
drivers/usb/input/hid-core.c +8 -0
diff -rNup linux-2.6.15-rc7.orig/drivers/usb/input/hid-core.c linux-2.6.15-rc7/drivers/usb/input/hid-core.c
@@ -1580,6 +1580,14 @@ static struct hid_blacklist {
 	{ USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RUMBLEPAD, HID_QUIRK_BADPAD },
 	{ USB_VENDOR_ID_TOPMAX, USB_DEVICE_ID_TOPMAX_COBRAPAD, HID_QUIRK_BADPAD },
 
+	{ USB_VENDOR_ID_APPLE, 0x020E, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x020F, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x0214, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x0215, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x0216, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x030A, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x030B, HID_QUIRK_POWERBOOK_HAS_FN },
+
 	{ 0, 0 }
 };
 
drivers/usb/input/hid-input.c +170 -1

195 lines not on this page · raw message

drivers/usb/input/hid.h +10 -0
diff -rNup linux-2.6.15-rc7.orig/drivers/usb/input/hid.h linux-2.6.15-rc7/drivers/usb/input/hid.h
@@ -246,6 +246,8 @@ struct hid_item {
 #define HID_QUIRK_2WHEEL_MOUSE_HACK_5		0x100
 #define HID_QUIRK_2WHEEL_MOUSE_HACK_ON		0x200
 #define HID_QUIRK_2WHEEL_POWERMOUSE		0x400
+#define HID_QUIRK_POWERBOOK_HAS_FN		0x00000800
+#define HID_QUIRK_POWERBOOK_FN_ON		0x00001000
 
 /*
  * This is the global environment of the parser. This information is
@@ -431,6 +433,14 @@ struct hid_device {							/* device repo
 	void (*ff_exit)(struct hid_device*);                            /* Called by hid_exit_ff(hid) */
 	int (*ff_event)(struct hid_device *hid, struct input_dev *input,
 			unsigned int type, unsigned int code, int value);
+
+#ifdef CONFIG_USB_HIDINPUT_POWERBOOK
+	/* We do this here because it's only relevant for the
+	 * USB devices, not for all input_dev's.
+	 */
+	unsigned long pb_fn[NBITS(KEY_MAX)];
+	unsigned long pb_numlock[NBITS(KEY_MAX)];
+#endif
 };
 
 #define HID_GLOBAL_STACK_SIZE 4
#43 lore raw

drivers/usb/input/hid-input.c static struct { · line 129

Quoted 13 lines
drivers/usb/input/hid-input.c +12 -0
+static int usbhid_pb_fkeyslast = 0;
+module_param_named(pb_fkeyslast, usbhid_pb_fkeyslast, bool, 0644);
+MODULE_PARM_DESC(usbhid_pb_fkeyslast, "Use F keys only while pressing fn on PowerBooks");
+
+static int usbhid_pb_disablefnkeys = 0;
+module_param_named(pb_disablefnkeys, usbhid_pb_disablefnkeys, bool, 0644);
+MODULE_PARM_DESC(usbhid_pb_disablefnkeys, "Disable fn special keys on PowerBooks");
+
+static int usbhid_pb_disablekeypad = 0;
+module_param_named(pb_disablekeypad, usbhid_pb_disablekeypad, bool, 0644);
+MODULE_PARM_DESC(usbhid_pb_disablekeypad, "Disable keypad keys on PowerBooks");
+#endif

For it to be useful, you have to not initialize them (since they are static, they will be zero'd anyway). Initializing them defeats the purpose.

static int usbhid_pb_fkeyslast;
etc.

Signature · 3 lines
   Ben Collins <[email protected]>
   Developer
   Ubuntu Linux
#44 lore raw
Quoted 3 lines · Ben Collins

For it to be useful, you have to not initialize them (since they are static, they will be zero'd anyway). Initializing them defeats the purpose.

Dang, should have known that. I feel somewhat guilty having to send so many patches. Anyway, here's another one with that small issue fixed:

---

drivers/usb/input/Kconfig +10 -0
diff -rNup linux-2.6.15-rc7.orig/drivers/usb/input/Kconfig linux-2.6.15-rc7/drivers/usb/input/Kconfig
@@ -37,6 +37,16 @@ config USB_HIDINPUT
 
 	  If unsure, say Y.
 
+config USB_HIDINPUT_POWERBOOK
+	bool "Enable support for iBook/PowerBook special keys"
+	default n
+	depends on USB_HIDINPUT
+	help
+	  Say Y here if you want support for the special keys (Fn, Numlock) on
+	  Apple iBooks and PowerBooks.
+
+	  If unsure, say N.
+
 config HID_FF
 	bool "Force feedback support (EXPERIMENTAL)"
 	depends on USB_HIDINPUT && EXPERIMENTAL
drivers/usb/input/hid-core.c +8 -0
diff -rNup linux-2.6.15-rc7.orig/drivers/usb/input/hid-core.c linux-2.6.15-rc7/drivers/usb/input/hid-core.c
@@ -1580,6 +1580,14 @@ static struct hid_blacklist {
 	{ USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RUMBLEPAD, HID_QUIRK_BADPAD },
 	{ USB_VENDOR_ID_TOPMAX, USB_DEVICE_ID_TOPMAX_COBRAPAD, HID_QUIRK_BADPAD },
 
+	{ USB_VENDOR_ID_APPLE, 0x020E, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x020F, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x0214, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x0215, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x0216, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x030A, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x030B, HID_QUIRK_POWERBOOK_HAS_FN },
+
 	{ 0, 0 }
 };
 
drivers/usb/input/hid-input.c +170 -1

195 lines not on this page · raw message

drivers/usb/input/hid.h +10 -0
diff -rNup linux-2.6.15-rc7.orig/drivers/usb/input/hid.h linux-2.6.15-rc7/drivers/usb/input/hid.h
@@ -246,6 +246,8 @@ struct hid_item {
 #define HID_QUIRK_2WHEEL_MOUSE_HACK_5		0x100
 #define HID_QUIRK_2WHEEL_MOUSE_HACK_ON		0x200
 #define HID_QUIRK_2WHEEL_POWERMOUSE		0x400
+#define HID_QUIRK_POWERBOOK_HAS_FN		0x00000800
+#define HID_QUIRK_POWERBOOK_FN_ON		0x00001000
 
 /*
  * This is the global environment of the parser. This information is
@@ -431,6 +433,14 @@ struct hid_device {							/* device repo
 	void (*ff_exit)(struct hid_device*);                            /* Called by hid_exit_ff(hid) */
 	int (*ff_event)(struct hid_device *hid, struct input_dev *input,
 			unsigned int type, unsigned int code, int value);
+
+#ifdef CONFIG_USB_HIDINPUT_POWERBOOK
+	/* We do this here because it's only relevant for the
+	 * USB devices, not for all input_dev's.
+	 */
+	unsigned long pb_fn[NBITS(KEY_MAX)];
+	unsigned long pb_numlock[NBITS(KEY_MAX)];
+#endif
 };
 
 #define HID_GLOBAL_STACK_SIZE 4
#4 lore raw
In reply to Benjamin Herrenschmidt
Quoted 5 lines · Benjamin Herrenschmidt
Quoted 2 lines · Dmitry Torokhov

As far as the hook itself - i have that feeling that it should not be done in kernel but via a keymap.

Quoted 7 lines

While I understand your feeling, it's a bit annoying in this specific case because previous models did this in hardware and all mac keymaps already account for that. Knowing how nasty it has been to get mac keymaps updated and in a good shape, and to get distros to properly get them, it makes a lot of sense to have this small hook in the kernel that makes the USB keyboard behave exactly like the older ADB couterparts.

Ok, I am looking at the patch again, and I have a question - do we really need these 3 module parameters? If the goal is to be compatible with older keyboards then shouldn't we stick to one behavior?

--
Dmitry

#5 lore raw
Quoted 3 lines · Dmitry Torokhov

Ok, I am looking at the patch again, and I have a question - do we really need these 3 module parameters? If the goal is to be compatible with older keyboards then shouldn't we stick to one behavior?

The old keyboard was controlled by ADB (Apple Desktop Bus) commands sent by pbbuttonsd. That doesn't work for the USB keyboard because the conversion is not done in hardware like with the old ones. ioctl's would also be possible, but I'm not sure wether they would be easy to do for USB devices. Module parameters can be changed using sysfs.

Greets,
Michael

#13 lore raw
In reply to Dmitry Torokhov
Quoted 4 lines

Ok, I am looking at the patch again, and I have a question - do we really need these 3 module parameters? If the goal is to be compatible with older keyboards then shouldn't we stick to one behavior?

I personally think one parameter is plenty enough (on/off) . Michael, can you send Dimitri the latest version of that patch please ?

Ben.

#6 lore raw
In reply to Michael Hanselmann
Quoted 10 lines · Michael Hanselmann
Quoted 3 lines · Dmitry Torokhov

Ok, I am looking at the patch again, and I have a question - do we really need these 3 module parameters? If the goal is to be compatible with older keyboards then shouldn't we stick to one behavior?

The old keyboard was controlled by ADB (Apple Desktop Bus) commands sent by pbbuttonsd. That doesn't work for the USB keyboard because the conversion is not done in hardware like with the old ones. ioctl's would also be possible, but I'm not sure wether they would be easy to do for USB devices. Module parameters can be changed using sysfs.

Yeah, but the question is why 3 ? I think one (on/off) is enough. Do you have any case where people actually change the other ones ?

Ben.

#7 lore raw
Quoted 2 lines · Benjamin Herrenschmidt

Yeah, but the question is why 3 ? I think one (on/off) is enough. Do you have any case where people actually change the other ones ?

Johannes Berg told me he wants to use the fn key alone to switch the keyboard layout or something. For such uses, the pb_enablefn is there. pb_fkeyslast is to emulate the behaviour of KBDMode from pbbuttonsd. The last one, pb_disablekeypad could left out. It doesn't add much code and might be used by some people, too.

Greets,
Michael

#8 lore raw
Quoted 6 lines · Michael Hanselmann
Quoted 2 lines · Benjamin Herrenschmidt

Yeah, but the question is why 3 ? I think one (on/off) is enough. Do you have any case where people actually change the other ones ?

Johannes Berg told me he wants to use the fn key alone to switch the keyboard layout or something. For such uses, the pb_enablefn is there.

What does it do ? Just send a keycode ? That should be unconditionnal. The Fn key should change a keycode always. I don't see why you would that to be off.

Quoted 3 lines

pb_fkeyslast is to emulate the behaviour of KBDMode from pbbuttonsd. The last one, pb_disablekeypad could left out. It doesn't add much code and might be used by some people, too.

The ony one we need is the one enabling/disabing the old behaviour.

Ben.

#9 lore raw
Quoted 2 lines · Benjamin Herrenschmidt
Quoted 2 lines

Johannes Berg told me he wants to use the fn key alone to switch the keyboard layout or something. For such uses, the pb_enablefn is there.

Sorry, actually it's called pb_disablefn now.

Quoted 3 lines

What does it do ? Just send a keycode ? That should be unconditionnal. The Fn key should change a keycode always. I don't see why you would that to be off.

No, if that parameter is disabled, it translates key combinations like Fn+F1 to KEY_BRIGHTNESSUP. If it's enabled, it only sends KEY_FN.

Greets,
Michael

#14 lore raw
In reply to Benjamin Herrenschmidt
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 3 lines

Ok, I am looking at the patch again, and I have a question - do we really need these 3 module parameters? If the goal is to be compatible with older keyboards then shouldn't we stick to one behavior?

I personally think one parameter is plenty enough (on/off) . Michael, can you send Dimitri the latest version of that patch please ?

I agree. If you need the compatible behavior.

Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR
author Acked-by Rene Nussbaumer Acked-by Johannes Berg Acked-by Benjamin Herrenschmidt
#15 lore raw
In reply to Benjamin Herrenschmidt
Quoted 2 lines · Benjamin Herrenschmidt

I personally think one parameter is plenty enough (on/off) . Michael, can you send Dimitri the latest version of that patch please ?

Here it is, CC to Dmitry.

This patch implements support for the fn key on PowerBooks using USB based keyboards.

---

drivers/usb/input/Kconfig +10 -0
diff -rNup linux-2.6.15-rc7.orig/drivers/usb/input/Kconfig linux-2.6.15-rc7/drivers/usb/input/Kconfig
@@ -37,6 +37,16 @@ config USB_HIDINPUT
 
 	  If unsure, say Y.
 
+config USB_HIDINPUT_POWERBOOK
+	bool "Enable support for iBook/PowerBook special keys"
+	default n
+	depends on USB_HIDINPUT
+	help
+	  Say Y here if you want support for the special keys (Fn, Numlock) on
+	  Apple iBooks and PowerBooks.
+
+	  If unsure, say N.
+
 config HID_FF
 	bool "Force feedback support (EXPERIMENTAL)"
 	depends on USB_HIDINPUT && EXPERIMENTAL
drivers/usb/input/hid-core.c +8 -0
diff -rNup linux-2.6.15-rc7.orig/drivers/usb/input/hid-core.c linux-2.6.15-rc7/drivers/usb/input/hid-core.c
@@ -1580,6 +1580,14 @@ static struct hid_blacklist {
 	{ USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RUMBLEPAD, HID_QUIRK_BADPAD },
 	{ USB_VENDOR_ID_TOPMAX, USB_DEVICE_ID_TOPMAX_COBRAPAD, HID_QUIRK_BADPAD },
 
+	{ USB_VENDOR_ID_APPLE, 0x020E, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x020F, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x0214, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x0215, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x0216, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x030A, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x030B, HID_QUIRK_POWERBOOK_HAS_FN },
+
 	{ 0, 0 }
 };
 
drivers/usb/input/hid-input.c +170 -1

195 lines not on this page · raw message

drivers/usb/input/hid.h +10 -0
diff -rNup linux-2.6.15-rc7.orig/drivers/usb/input/hid.h linux-2.6.15-rc7/drivers/usb/input/hid.h
@@ -246,6 +246,8 @@ struct hid_item {
 #define HID_QUIRK_2WHEEL_MOUSE_HACK_5		0x100
 #define HID_QUIRK_2WHEEL_MOUSE_HACK_ON		0x200
 #define HID_QUIRK_2WHEEL_POWERMOUSE		0x400
+#define HID_QUIRK_POWERBOOK_HAS_FN		0x00000800
+#define HID_QUIRK_POWERBOOK_FN_ON		0x00001000
 
 /*
  * This is the global environment of the parser. This information is
@@ -431,6 +433,14 @@ struct hid_device {							/* device repo
 	void (*ff_exit)(struct hid_device*);                            /* Called by hid_exit_ff(hid) */
 	int (*ff_event)(struct hid_device *hid, struct input_dev *input,
 			unsigned int type, unsigned int code, int value);
+
+#ifdef CONFIG_USB_HIDINPUT_POWERBOOK
+	/* We do this here because it's only relevant for the
+	 * USB devices, not for all input_dev's.
+	 */
+	unsigned long pb_fn[NBITS(KEY_MAX)];
+	unsigned long pb_numlock[NBITS(KEY_MAX)];
+#endif
 };
 
 #define HID_GLOBAL_STACK_SIZE 4
#10 lore raw
In reply to Michael Hanselmann
Quoted 4 lines · Michael Hanselmann
Quoted 2 lines · Benjamin Herrenschmidt
Quoted 2 lines

Johannes Berg told me he wants to use the fn key alone to switch the keyboard layout or something. For such uses, the pb_enablefn is there.

Quoted 8 lines

Sorry, actually it's called pb_disablefn now.

Quoted 3 lines

What does it do ? Just send a keycode ? That should be unconditionnal. The Fn key should change a keycode always. I don't see why you would that to be off.

No, if that parameter is disabled, it translates key combinations like Fn+F1 to KEY_BRIGHTNESSUP. If it's enabled, it only sends KEY_FN.

I believe a better behavior would be to send KEY_FN and then KEY_BRIGHTNESSUP when enabled and KEY_FN and KEY_F1 when disabled.

Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR
#11 lore raw
Quoted 5 lines · Vojtech Pavlik
Quoted 2 lines

No, if that parameter is disabled, it translates key combinations like Fn+F1 to KEY_BRIGHTNESSUP. If it's enabled, it only sends KEY_FN.

I believe a better behavior would be to send KEY_FN and then KEY_BRIGHTNESSUP when enabled and KEY_FN and KEY_F1 when disabled.

That's done. It sends KEY_FN as any other key. If a key is pressed while the fn key is pressed, it uses the table to look up the new code. Releasing is also done with the corresponding keycodes.

Greets,
Michael

#12 lore raw
In reply to Michael Hanselmann
Quoted 4 lines · Michael Hanselmann
Quoted 2 lines · Benjamin Herrenschmidt
Quoted 2 lines

Johannes Berg told me he wants to use the fn key alone to switch the keyboard layout or something. For such uses, the pb_enablefn is there.

Quoted 8 lines

Sorry, actually it's called pb_disablefn now.

Quoted 3 lines

What does it do ? Just send a keycode ? That should be unconditionnal. The Fn key should change a keycode always. I don't see why you would that to be off.

No, if that parameter is disabled, it translates key combinations like Fn+F1 to KEY_BRIGHTNESSUP. If it's enabled, it only sends KEY_FN.

But that should be the full translation no ? I don't see why you are splitting in translating the special keys and translating the rest of the keyboard...

Ben.

author Acked-by Rene Nussbaumer Acked-by Johannes Berg Acked-by Benjamin Herrenschmidt
#16 lore raw
In reply to Dmitry Torokhov
Quoted 3 lines · Dmitry Torokhov

Ok, I am looking at the patch again, and I have a question - do we really need these 3 module parameters? If the goal is to be compatible with older keyboards then shouldn't we stick to one behavior?

After clearing the other points with Benjamin Herrenschmidt, I created another patch which you find below.

This patch implements support for the fn key on PowerBooks using USB based keyboards.

---

drivers/usb/input/hid-core.c +8 -0
diff -upr linux-2.6.15.orig/drivers/usb/input/hid-core.c linux-2.6.15/drivers/usb/input/hid-core.c
@@ -1580,6 +1580,14 @@ static struct hid_blacklist {
 	{ USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RUMBLEPAD, HID_QUIRK_BADPAD },
 	{ USB_VENDOR_ID_TOPMAX, USB_DEVICE_ID_TOPMAX_COBRAPAD, HID_QUIRK_BADPAD },
 
+	{ USB_VENDOR_ID_APPLE, 0x020E, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x020F, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x0214, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x0215, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x0216, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x030A, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x030B, HID_QUIRK_POWERBOOK_HAS_FN },
+
 	{ 0, 0 }
 };
 
drivers/usb/input/hid.h +10 -0
diff -upr linux-2.6.15.orig/drivers/usb/input/hid.h linux-2.6.15/drivers/usb/input/hid.h
@@ -246,6 +246,8 @@ struct hid_item {
 #define HID_QUIRK_2WHEEL_MOUSE_HACK_5		0x100
 #define HID_QUIRK_2WHEEL_MOUSE_HACK_ON		0x200
 #define HID_QUIRK_2WHEEL_POWERMOUSE		0x400
+#define HID_QUIRK_POWERBOOK_HAS_FN		0x00000800
+#define HID_QUIRK_POWERBOOK_FN_ON		0x00001000
 
 /*
  * This is the global environment of the parser. This information is
@@ -431,6 +433,14 @@ struct hid_device {							/* device repo
 	void (*ff_exit)(struct hid_device*);                            /* Called by hid_exit_ff(hid) */
 	int (*ff_event)(struct hid_device *hid, struct input_dev *input,
 			unsigned int type, unsigned int code, int value);
+
+#ifdef CONFIG_USB_HIDINPUT_POWERBOOK
+	/* We do this here because it's only relevant for the
+	 * USB devices, not for all input_dev's.
+	 */
+	unsigned long pb_fn[NBITS(KEY_MAX)];
+	unsigned long pb_numlock[NBITS(KEY_MAX)];
+#endif
 };
 
 #define HID_GLOBAL_STACK_SIZE 4
drivers/usb/input/hid-input.c +159 -1

184 lines not on this page · raw message

drivers/usb/input/Kconfig +10 -0
diff -upr linux-2.6.15.orig/drivers/usb/input/Kconfig linux-2.6.15/drivers/usb/input/Kconfig
@@ -37,6 +37,16 @@ config USB_HIDINPUT
 
 	  If unsure, say Y.
 
+config USB_HIDINPUT_POWERBOOK
+	bool "Enable support for iBook/PowerBook special keys"
+	default n
+	depends on USB_HIDINPUT
+	help
+	  Say Y here if you want support for the special keys (Fn, Numlock) on
+	  Apple iBooks and PowerBooks.
+
+	  If unsure, say N.
+
 config HID_FF
 	bool "Force feedback support (EXPERIMENTAL)"
 	depends on USB_HIDINPUT && EXPERIMENTAL
#17 lore raw
Quoted 4 lines · Michael Hanselmann

* This is the global environment of the parser. This information is

drivers/usb/input/hid.h +0 -0
@@ -431,6 +433,14 @@ struct hid_device {							/* device repo
 	void (*ff_exit)(struct hid_device*);                            /* Called by hid_exit_ff(hid) */
 	int (*ff_event)(struct hid_device *hid, struct input_dev *input,

drivers/usb/input/hid.h struct hid_device { /* device repo · line 444

Quoted 10 lines
drivers/usb/input/hid.h +8 -0
 			unsigned int type, unsigned int code, int value);
+
+#ifdef CONFIG_USB_HIDINPUT_POWERBOOK
+	/* We do this here because it's only relevant for the
+	 * USB devices, not for all input_dev's.
+	 */
+	unsigned long pb_fn[NBITS(KEY_MAX)];
+	unsigned long pb_numlock[NBITS(KEY_MAX)];
+#endif
 };

I don't understand the comment above ? You are adding this to all struct hid_device ? There can be only one of those keyboards plugged at one point in time, I don't think there is any problem having the above static in the driver rather than in the hid_device structure.

.../...

drivers/usb/input/hid-input.c void hidinput_hid_event(struct hid_devic · line 642

Quoted 6 lines
drivers/usb/input/hid-input.c +5 -0
+	if ((hid->quirks & HID_QUIRK_POWERBOOK_HAS_FN) &&
+	    hidinput_pb_event(hid, input, usage, value)) {
+		return;
+	}
+

Dimitry might disagree but it's generally considered bad taste to have { and } for a single statement :)

Quoted 23 lines
drivers/usb/input/hid-input.c +0 -0
 	if (usage->hat_min < usage->hat_max || usage->hat_dir) {
 		int hat_dir = usage->hat_dir;
 		if (!hat_dir)

diff -upr linux-2.6.15.orig/drivers/usb/input/Kconfig linux-2.6.15/drivers/usb/input/Kconfig

drivers/usb/input/Kconfig +10 -0
@@ -37,6 +37,16 @@ config USB_HIDINPUT
 
 	  If unsure, say Y.
 
+config USB_HIDINPUT_POWERBOOK
+	bool "Enable support for iBook/PowerBook special keys"
+	default n
+	depends on USB_HIDINPUT
+	help
+	  Say Y here if you want support for the special keys (Fn, Numlock) on
+	  Apple iBooks and PowerBooks.
+
+	  If unsure, say N.
+
 config HID_FF
 	bool "Force feedback support (EXPERIMENTAL)"
 	depends on USB_HIDINPUT && EXPERIMENTAL
author Acked-by Rene Nussbaumer Acked-by Johannes Berg Acked-by Benjamin Herrenschmidt
#18 lore raw
Quoted 4 lines · Benjamin Herrenschmidt

I don't understand the comment above ? You are adding this to all struct hid_device ? There can be only one of those keyboards plugged at one point in time, I don't think there is any problem having the above static in the driver rather than in the hid_device structure.

While I don't agree on that, I still modified the patch.

This patch implements support for the fn key on Apple PowerBooks using USB based keyboards.

---

drivers/usb/input/hid-core.c +8 -0
diff -upr linux-2.6.15.orig/drivers/usb/input/hid-core.c linux-2.6.15/drivers/usb/input/hid-core.c
@@ -1580,6 +1580,14 @@ static struct hid_blacklist {
 	{ USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RUMBLEPAD, HID_QUIRK_BADPAD },
 	{ USB_VENDOR_ID_TOPMAX, USB_DEVICE_ID_TOPMAX_COBRAPAD, HID_QUIRK_BADPAD },
 
+	{ USB_VENDOR_ID_APPLE, 0x020E, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x020F, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x0214, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x0215, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x0216, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x030A, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x030B, HID_QUIRK_POWERBOOK_HAS_FN },
+
 	{ 0, 0 }
 };
 
drivers/usb/input/hid.h +2 -0
diff -upr linux-2.6.15.orig/drivers/usb/input/hid.h linux-2.6.15/drivers/usb/input/hid.h
@@ -246,6 +246,8 @@ struct hid_item {
 #define HID_QUIRK_2WHEEL_MOUSE_HACK_5		0x100
 #define HID_QUIRK_2WHEEL_MOUSE_HACK_ON		0x200
 #define HID_QUIRK_2WHEEL_POWERMOUSE		0x400
+#define HID_QUIRK_POWERBOOK_HAS_FN		0x00000800
+#define HID_QUIRK_POWERBOOK_FN_ON		0x00001000
 
 /*
  * This is the global environment of the parser. This information is
drivers/usb/input/hid-input.c +161 -1

186 lines not on this page · raw message

drivers/usb/input/Kconfig +10 -0
diff -upr linux-2.6.15.orig/drivers/usb/input/Kconfig linux-2.6.15/drivers/usb/input/Kconfig
@@ -37,6 +37,16 @@ config USB_HIDINPUT
 
 	  If unsure, say Y.
 
+config USB_HIDINPUT_POWERBOOK
+	bool "Enable support for iBook/PowerBook special keys"
+	default n
+	depends on USB_HIDINPUT
+	help
+	  Say Y here if you want support for the special keys (Fn, Numlock) on
+	  Apple iBooks and PowerBooks.
+
+	  If unsure, say N.
+
 config HID_FF
 	bool "Force feedback support (EXPERIMENTAL)"
 	depends on USB_HIDINPUT && EXPERIMENTAL
#32 lore raw
In reply to Benjamin Herrenschmidt
Quoted 13 lines · Benjamin Herrenschmidt
Quoted 11 lines · Michael Hanselmann

* This is the global environment of the parser. This information is

drivers/usb/input/hid.h +6 -0
@@ -431,6 +433,14 @@ struct hid_device {							/* device repo
 	void (*ff_exit)(struct hid_device*);                            /* Called by hid_exit_ff(hid) */
 	int (*ff_event)(struct hid_device *hid, struct input_dev *input,
 			unsigned int type, unsigned int code, int value);
+
+#ifdef CONFIG_USB_HIDINPUT_POWERBOOK
+	/* We do this here because it's only relevant for the
+	 * USB devices, not for all input_dev's.
+	 */
+	unsigned long pb_fn[NBITS(KEY_MAX)];
Quoted 8 lines

drivers/usb/input/hid.h struct hid_device { /* device repo · line 444

Quoted 3 lines
drivers/usb/input/hid.h +2 -0
+	unsigned long pb_numlock[NBITS(KEY_MAX)];
+#endif
 };

I don't understand the comment above ? You are adding this to all struct hid_device ? There can be only one of those keyboards plugged at one point in time, I don't think there is any problem having the above static in the driver rather than in the hid_device structure.

I think having it in struct hid_device is safer. We might want to dynamically allocate only for PowerBook keyboards, though, to save memory.

Quoted 4 lines

.../...

Quoted 1 line
Quoted 8 lines

drivers/usb/input/hid-input.c void hidinput_hid_event(struct hid_devic · line 642

Quoted 5 lines
drivers/usb/input/hid-input.c +5 -0
+	if ((hid->quirks & HID_QUIRK_POWERBOOK_HAS_FN) &&
+	    hidinput_pb_event(hid, input, usage, value)) {
+		return;
+	}
+

Dimitry might disagree but it's generally considered bad taste to have { and } for a single statement :)

I do agree, though.

Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR
author Acked-by Rene Nussbaumer Acked-by Johannes Berg Acked-by Benjamin Herrenschmidt
#33 lore raw
Quoted 3 lines · Vojtech Pavlik

I think having it in struct hid_device is safer. We might want to dynamically allocate only for PowerBook keyboards, though, to save memory.

These two arrays take 128 Bytes. I don't think it's possible to write the code to allocate and set them in such short code. Beside of that, it would affect more code than only hid-input.c, at least hid-core.c would need modifications, too.

Benjamin Herrenschmidt had the idea of a private field which each device can use for its own purposes. That's a task for another patch, tough.

This patch implements support for the fn key on Apple PowerBooks using USB based keyboards.

---

drivers/usb/input/hid-core.c +8 -0
diff -upr linux-2.6.15.orig/drivers/usb/input/hid-core.c linux-2.6.15/drivers/usb/input/hid-core.c
@@ -1580,6 +1580,14 @@ static struct hid_blacklist {
 	{ USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RUMBLEPAD, HID_QUIRK_BADPAD },
 	{ USB_VENDOR_ID_TOPMAX, USB_DEVICE_ID_TOPMAX_COBRAPAD, HID_QUIRK_BADPAD },
 
+	{ USB_VENDOR_ID_APPLE, 0x020E, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x020F, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x0214, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x0215, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x0216, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x030A, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x030B, HID_QUIRK_POWERBOOK_HAS_FN },
+
 	{ 0, 0 }
 };
 
drivers/usb/input/hid.h +7 -0
diff -upr linux-2.6.15.orig/drivers/usb/input/hid.h linux-2.6.15/drivers/usb/input/hid.h
@@ -246,6 +246,8 @@ struct hid_item {
 #define HID_QUIRK_2WHEEL_MOUSE_HACK_5		0x100
 #define HID_QUIRK_2WHEEL_MOUSE_HACK_ON		0x200
 #define HID_QUIRK_2WHEEL_POWERMOUSE		0x400
+#define HID_QUIRK_POWERBOOK_HAS_FN		0x00000800
+#define HID_QUIRK_POWERBOOK_FN_ON		0x00001000
 
 /*
  * This is the global environment of the parser. This information is
@@ -431,6 +433,11 @@ struct hid_device {							/* device repo
 	void (*ff_exit)(struct hid_device*);                            /* Called by hid_exit_ff(hid) */
 	int (*ff_event)(struct hid_device *hid, struct input_dev *input,
 			unsigned int type, unsigned int code, int value);
+
+#ifdef CONFIG_USB_HIDINPUT_POWERBOOK
+	unsigned long pb_pressed_fn[NBITS(KEY_MAX)];
+	unsigned long pb_pressed_numlock[NBITS(KEY_MAX)];
+#endif
 };
 
 #define HID_GLOBAL_STACK_SIZE 4
drivers/usb/input/hid-input.c +158 -1

183 lines not on this page · raw message

drivers/usb/input/Kconfig +10 -0
diff -upr linux-2.6.15.orig/drivers/usb/input/Kconfig linux-2.6.15/drivers/usb/input/Kconfig
@@ -37,6 +37,16 @@ config USB_HIDINPUT
 
 	  If unsure, say Y.
 
+config USB_HIDINPUT_POWERBOOK
+	bool "Enable support for iBook/PowerBook special keys"
+	default n
+	depends on USB_HIDINPUT
+	help
+	  Say Y here if you want support for the special keys (Fn, Numlock) on
+	  Apple iBooks and PowerBooks.
+
+	  If unsure, say N.
+
 config HID_FF
 	bool "Force feedback support (EXPERIMENTAL)"
 	depends on USB_HIDINPUT && EXPERIMENTAL
#34 lore raw
Quoted 10 lines · Michael Hanselmann
Quoted 3 lines · Vojtech Pavlik

I think having it in struct hid_device is safer. We might want to dynamically allocate only for PowerBook keyboards, though, to save memory.

These two arrays take 128 Bytes. I don't think it's possible to write the code to allocate and set them in such short code. Beside of that, it would affect more code than only hid-input.c, at least hid-core.c would need modifications, too.

Quoted 5 lines

Benjamin Herrenschmidt had the idea of a private field which each device can use for its own purposes. That's a task for another patch, tough.

This patch implements support for the fn key on Apple PowerBooks using USB based keyboards.

Dimitri, I think the patch is good enough now and should go in for 2.6.16.

Thanks !
Ben.

#19 lore raw
In reply to Michael Hanselmann
Quoted 8 lines · Michael Hanselmann
Quoted 4 lines · Benjamin Herrenschmidt

I don't understand the comment above ? You are adding this to all struct hid_device ? There can be only one of those keyboards plugged at one point in time, I don't think there is any problem having the above static in the driver rather than in the hid_device structure.

While I don't agree on that, I still modified the patch.

I disagree as well, but if we get semantics right we can merge it in this form and adjust later.

drivers/usb/input/hid-input.c static struct { · line 127

Quoted 7 lines
drivers/usb/input/hid-input.c +7 -0
+static int usbhid_pb_fnmode = 1;
+module_param_named(pb_fnmode, usbhid_pb_fnmode, int, 0644);
+MODULE_PARM_DESC(usbhid_pb_fnmode,
+	"Mode of fn key on PowerBooks (0 = disabled, "
+	"1 = fkeyslast, 2 = fkeysfirst)");
+#endif
+

That should be "MODULE_PARM_DESC(pb_fn_mode, ...)". Also, since this is for compatibility with ADB, why do we have 3 options? Doesn't ADB have only 2?

drivers/usb/input/hid-input.c static struct { · line 138

Quoted 8 lines

#define map_abs(c) do { usage->code = c; usage->type = EV_ABS; bit = input->absbit; max = ABS_MAX; } while (0)
#define map_rel(c) do { usage->code = c; usage->type = EV_REL; bit = input->relbit; max = REL_MAX; } while (0)
#define map_key(c) do { usage->code = c; usage->type = EV_KEY; bit = input->keybit; max = KEY_MAX; } while (0)

drivers/usb/input/hid-input.c +1 -0
@@ -73,6 +135,80 @@ static struct {
 #define map_key_clear(c)	do { map_key(c); clear_bit(c, bit); } while (0)
 #define map_ff_effect(c)	do { set_bit(c, input->ffbit); } while (0)
 
+static inline struct hidinput_key_translation *find_translation(

I thought is was agreed that we'd avoid "inlines" in .c files?

drivers/usb/input/hid-input.c static struct { · line 147

Quoted 9 lines
drivers/usb/input/hid-input.c +9 -0
+	struct hidinput_key_translation *table, u16 from)
+{
+	struct hidinput_key_translation *trans;
+
+	/* Look for the translation */
+	for(trans = table; trans->from && (trans->from != from); trans++);
+
+	return (trans->from?trans:NULL);
+}

I'd prefer liberal amount of spaces applied here </extreme nitpick mode>

Quoted 35 lines
drivers/usb/input/hid-input.c +35 -0
+
+static int hidinput_pb_event(struct hid_device *hid, struct input_dev *input,
+	struct hid_usage *usage, __s32 value)
+{
+#ifdef CONFIG_USB_HIDINPUT_POWERBOOK
+	struct hidinput_key_translation *trans;
+
+	if (usage->code == KEY_FN) {
+		if (value) hid->quirks |=  HID_QUIRK_POWERBOOK_FN_ON;
+		else       hid->quirks &= ~HID_QUIRK_POWERBOOK_FN_ON;
+
+		input_event(input, usage->type, usage->code, value);
+
+		return 1;
+	}
+
+	if (usbhid_pb_fnmode) {
+		int try_translate, do_translate;
+
+		trans = find_translation(powerbook_fn_keys, usage->code);
+		if (trans) {
+			if (test_bit(usage->code, usbhid_pb_fn))
+				do_translate = 1;
+			else if (trans->flags & POWERBOOK_FLAG_FKEY)
+				do_translate =
+					(usbhid_pb_fnmode == 2 &&  (hid->quirks & HID_QUIRK_POWERBOOK_FN_ON)) ||
+					(usbhid_pb_fnmode == 1 && !(hid->quirks & HID_QUIRK_POWERBOOK_FN_ON));
+			else
+				do_translate = (hid->quirks & HID_QUIRK_POWERBOOK_FN_ON);
+
+			if (do_translate) {
+				if (value)
+					set_bit(usage->code, usbhid_pb_fn);
+				else
+					clear_bit(usage->code, usbhid_pb_fn);

drivers/usb/input/hid-input.c static struct { · line 192

Quoted 10 lines
drivers/usb/input/hid-input.c +10 -0
+
+				input_event(input, usage->type, trans->to, value);
+
+				return 1;
+			}
+		}
+
+		try_translate = test_bit(usage->code, usbhid_pb_numlock)?1:
+				test_bit(LED_NUML, input->led);
+		if (try_translate) {

Isn't this the same as

		if (test_bit(usage->code, usbhid_pb_numlock) || test_bit(LED_NUML, input->led))

but harder to read?

Signature · 1 line
Dmitry
author Acked-by Rene Nussbaumer Acked-by Johannes Berg Acked-by Benjamin Herrenschmidt
#20 lore raw
Quoted 2 lines · Dmitry Torokhov

Also, since this is for compatibility with ADB, why do we have 3 options? Doesn't ADB have only 2?

Some people want to use the fn key without having the translations. I'm not sure wether the ADB hardware even supported this. So far, it's at least not useless.

Quoted 1 line

I thought is was agreed that we'd avoid "inlines" in .c files?

I wasn't sure if that all got trough yet.

Quoted 3 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	return (trans->from?trans:NULL);

I'd prefer liberal amount of spaces applied here </extreme nitpick mode>

Hopefully fixed in a Dmitry-compatible way. :-)

Quoted 9 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+		try_translate = test_bit(usage->code, usbhid_pb_numlock)?1:
+				test_bit(LED_NUML, input->led);
+		if (try_translate) {

Isn't this the same as

		if (test_bit(usage->code, usbhid_pb_numlock) || test_bit(LED_NUML, input->led))

but harder to read?

It indeed is. Fixed.

New patch:

This patch implements support for the fn key on Apple PowerBooks using USB based keyboards.

---

drivers/usb/input/hid-core.c +8 -0
diff -upr linux-2.6.15.orig/drivers/usb/input/hid-core.c linux-2.6.15/drivers/usb/input/hid-core.c
@@ -1580,6 +1580,14 @@ static struct hid_blacklist {
 	{ USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RUMBLEPAD, HID_QUIRK_BADPAD },
 	{ USB_VENDOR_ID_TOPMAX, USB_DEVICE_ID_TOPMAX_COBRAPAD, HID_QUIRK_BADPAD },
 
+	{ USB_VENDOR_ID_APPLE, 0x020E, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x020F, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x0214, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x0215, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x0216, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x030A, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x030B, HID_QUIRK_POWERBOOK_HAS_FN },
+
 	{ 0, 0 }
 };
 
drivers/usb/input/hid.h +7 -0
diff -upr linux-2.6.15.orig/drivers/usb/input/hid.h linux-2.6.15/drivers/usb/input/hid.h
@@ -246,6 +246,8 @@ struct hid_item {
 #define HID_QUIRK_2WHEEL_MOUSE_HACK_5		0x100
 #define HID_QUIRK_2WHEEL_MOUSE_HACK_ON		0x200
 #define HID_QUIRK_2WHEEL_POWERMOUSE		0x400
+#define HID_QUIRK_POWERBOOK_HAS_FN		0x00000800
+#define HID_QUIRK_POWERBOOK_FN_ON		0x00001000
 
 /*
  * This is the global environment of the parser. This information is
@@ -431,6 +433,11 @@ struct hid_device {							/* device repo
 	void (*ff_exit)(struct hid_device*);                            /* Called by hid_exit_ff(hid) */
 	int (*ff_event)(struct hid_device *hid, struct input_dev *input,
 			unsigned int type, unsigned int code, int value);
+
+#ifdef CONFIG_USB_HIDINPUT_POWERBOOK
+	unsigned long pb_pressed_fn[NBITS(KEY_MAX)];
+	unsigned long pb_pressed_numlock[NBITS(KEY_MAX)];
+#endif
 };
 
 #define HID_GLOBAL_STACK_SIZE 4
drivers/usb/input/hid-input.c +159 -1

184 lines not on this page · raw message

drivers/usb/input/Kconfig +10 -0
diff -upr linux-2.6.15.orig/drivers/usb/input/Kconfig linux-2.6.15/drivers/usb/input/Kconfig
@@ -37,6 +37,16 @@ config USB_HIDINPUT
 
 	  If unsure, say Y.
 
+config USB_HIDINPUT_POWERBOOK
+	bool "Enable support for iBook/PowerBook special keys"
+	default n
+	depends on USB_HIDINPUT
+	help
+	  Say Y here if you want support for the special keys (Fn, Numlock) on
+	  Apple iBooks and PowerBooks.
+
+	  If unsure, say N.
+
 config HID_FF
 	bool "Force feedback support (EXPERIMENTAL)"
 	depends on USB_HIDINPUT && EXPERIMENTAL
#21 lore raw
Quoted 1 line · Michael Hanselmann

It indeed is. Fixed.

It gets better all the time. ;)

Quoted 15 lines

New patch:

This patch implements support for the fn key on Apple PowerBooks using USB based keyboards.

---

drivers/usb/input/hid-input.c +0 -0
@@ -325,7 +459,27 @@ static void hidinput_configure_usage(str
 
 			set_bit(EV_REP, input->evbit);

drivers/usb/input/hid-input.c static void hidinput_configure_usage(str · line 469

Quoted 10 lines
drivers/usb/input/hid-input.c +8 -1
 			switch(usage->hid & HID_USAGE) {
-				case 0x003: map_key_clear(KEY_FN);		break;
+#ifdef CONFIG_USB_HIDINPUT_POWERBOOK
+				/* The fn key on Apple PowerBooks */
+				case 0x0003: {
+					struct hidinput_key_translation *trans;
+
+					map_key_clear(KEY_FN);
+
+					set_bit(KEY_FN, input->keybit);

The set_bit(KEY_FN, input->keybit) is superfluous here, right? map_key_clear(KEY_FN); will take care of that further down.

Quoted 16 lines
drivers/usb/input/hid-input.c +13 -0
+					set_bit(KEY_NUMLOCK, input->keybit);
+
+					/* Enable all needed keys */
+					for(trans = powerbook_fn_keys; trans->from; trans++)
+						set_bit(trans->to, input->keybit);
+
+					for(trans = powerbook_numlock_keys; trans->from; trans++)
+						set_bit(trans->to, input->keybit);
+
+					goto ignore;
+				}
+#endif
+
 				default:    goto ignore;
 			}
 			break;
Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR
#26 lore raw
In reply to Dmitry Torokhov
Quoted 4 lines

That should be "MODULE_PARM_DESC(pb_fn_mode, ...)". Also, since this is for compatibility with ADB, why do we have 3 options? Doesn't ADB have only 2?

No, the ADB keyboard can operate in 2 modes that can be set with a PMU command, I forgot about that in my earlier comments. In one mode, you get the "special" behaviour by default on the Fx keys and you get Fx when pressing Fn-Fx, and in the other mode, you get the Fx by default and the special behaviour when pressing Fn-Fx.

Quoted 3 lines
Quoted 1 line

+static inline struct hidinput_key_translation *find_translation(

I thought is was agreed that we'd avoid "inlines" in .c files?

Ah ? I have certainly missed that discussion ...

Quoted 11 lines

drivers/usb/input/hid-input.c static struct { · line 147

Quoted 9 lines
drivers/usb/input/hid-input.c +9 -0
+	struct hidinput_key_translation *table, u16 from)
+{
+	struct hidinput_key_translation *trans;
+
+	/* Look for the translation */
+	for(trans = table; trans->from && (trans->from != from); trans++);
+
+	return (trans->from?trans:NULL);
+}

I'd prefer liberal amount of spaces applied here </extreme nitpick mode>

Me too :)

Quoted 9 lines

drivers/usb/input/hid-input.c static struct { · line 192

Quoted 3 lines
drivers/usb/input/hid-input.c +3 -0
+		try_translate = test_bit(usage->code, usbhid_pb_numlock)?1:
+				test_bit(LED_NUML, input->led);
+		if (try_translate) {

Isn't this the same as

		if (test_bit(usage->code, usbhid_pb_numlock) || test_bit(LED_NUML, input->led))

but harder to read?

No. If the first one is 0, the second one will not matter in the first version, while it will in yours.

Ben.

#27 lore raw
Quoted 7 lines · Benjamin Herrenschmidt
Quoted 7 lines

drivers/usb/input/hid-input.c static struct { · line 192

Quoted 4 lines
drivers/usb/input/hid-input.c +3 -0
+		try_translate = test_bit(usage->code, usbhid_pb_numlock)?1:
+				test_bit(LED_NUML, input->led);
+		if (try_translate) {

Isn't this the same as

Quoted 6 lines
Quoted 3 lines
		if (test_bit(usage->code, usbhid_pb_numlock) || test_bit(LED_NUML, input->led))

but harder to read?

No. If the first one is 0, the second one will not matter in the first version, while it will in yours.

Forget me, I'm stupid or rather I should finish by breakfast before writing stupid things ;) Of course you are right, they are equivalent.

Ben.

author Acked-by Rene Nussbaumer Acked-by Johannes Berg Acked-by Benjamin Herrenschmidt
#22 lore raw
In reply to Vojtech Pavlik
Quoted 5 lines · Vojtech Pavlik

Review

Quoted 2 lines
(quoted diff) +2 -0
+					map_key_clear(KEY_FN);
+					set_bit(KEY_FN, input->keybit);

The set_bit(KEY_FN, input->keybit) is superfluous here, right? map_key_clear(KEY_FN); will take care of that further down.

Okay, fixed in the patch below.

This patch implements support for the fn key on Apple PowerBooks using USB based keyboards.

---

drivers/usb/input/hid-core.c +8 -0
diff -upr linux-2.6.15.orig/drivers/usb/input/hid-core.c linux-2.6.15/drivers/usb/input/hid-core.c
@@ -1580,6 +1580,14 @@ static struct hid_blacklist {
 	{ USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RUMBLEPAD, HID_QUIRK_BADPAD },
 	{ USB_VENDOR_ID_TOPMAX, USB_DEVICE_ID_TOPMAX_COBRAPAD, HID_QUIRK_BADPAD },
 
+	{ USB_VENDOR_ID_APPLE, 0x020E, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x020F, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x0214, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x0215, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x0216, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x030A, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x030B, HID_QUIRK_POWERBOOK_HAS_FN },
+
 	{ 0, 0 }
 };
 
drivers/usb/input/hid.h +7 -0
diff -upr linux-2.6.15.orig/drivers/usb/input/hid.h linux-2.6.15/drivers/usb/input/hid.h
@@ -246,6 +246,8 @@ struct hid_item {
 #define HID_QUIRK_2WHEEL_MOUSE_HACK_5		0x100
 #define HID_QUIRK_2WHEEL_MOUSE_HACK_ON		0x200
 #define HID_QUIRK_2WHEEL_POWERMOUSE		0x400
+#define HID_QUIRK_POWERBOOK_HAS_FN		0x00000800
+#define HID_QUIRK_POWERBOOK_FN_ON		0x00001000
 
 /*
  * This is the global environment of the parser. This information is
@@ -431,6 +433,11 @@ struct hid_device {							/* device repo
 	void (*ff_exit)(struct hid_device*);                            /* Called by hid_exit_ff(hid) */
 	int (*ff_event)(struct hid_device *hid, struct input_dev *input,
 			unsigned int type, unsigned int code, int value);
+
+#ifdef CONFIG_USB_HIDINPUT_POWERBOOK
+	unsigned long pb_pressed_fn[NBITS(KEY_MAX)];
+	unsigned long pb_pressed_numlock[NBITS(KEY_MAX)];
+#endif
 };
 
 #define HID_GLOBAL_STACK_SIZE 4
drivers/usb/input/hid-input.c +156 -1

181 lines not on this page · raw message

drivers/usb/input/Kconfig +10 -0
diff -upr linux-2.6.15.orig/drivers/usb/input/Kconfig linux-2.6.15/drivers/usb/input/Kconfig
@@ -37,6 +37,16 @@ config USB_HIDINPUT
 
 	  If unsure, say Y.
 
+config USB_HIDINPUT_POWERBOOK
+	bool "Enable support for iBook/PowerBook special keys"
+	default n
+	depends on USB_HIDINPUT
+	help
+	  Say Y here if you want support for the special keys (Fn, Numlock) on
+	  Apple iBooks and PowerBooks.
+
+	  If unsure, say N.
+
 config HID_FF
 	bool "Force feedback support (EXPERIMENTAL)"
 	depends on USB_HIDINPUT && EXPERIMENTAL
#28 lore raw
In reply to Benjamin Herrenschmidt
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 4 lines

That should be "MODULE_PARM_DESC(pb_fn_mode, ...)". Also, since this is for compatibility with ADB, why do we have 3 options? Doesn't ADB have only 2?

No, the ADB keyboard can operate in 2 modes that can be set with a PMU command, I forgot about that in my earlier comments. In one mode, you get the "special" behaviour by default on the Fx keys and you get Fx when pressing Fn-Fx, and in the other mode, you get the Fx by default and the special behaviour when pressing Fn-Fx.

Right, so do we need "no translation, fnkeyfirst and fnkeylast" option or just "fnkeyfirst and fnkeyast"?

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

+static inline struct hidinput_key_translation *find_translation(

I thought is was agreed that we'd avoid "inlines" in .c files?

Ah ? I have certainly missed that discussion ...

Newer GCCs, unit-at-a-time, etc. etc. - teher was pretty long discussion about letting GCC decide on inlining.

Quoted 7 lines
Quoted 7 lines

drivers/usb/input/hid-input.c static struct {

Quoted 7 lines
drivers/usb/input/hid-input.c +6 -0
+   struct hidinput_key_translation *table, u16 from)
+{
+   struct hidinput_key_translation *trans;
+
+   /* Look for the translation */
+   for(trans =3D table; trans->from && (trans->from !=3D from); tran=

s++);

Quoted 10 lines
Quoted 5 lines

drivers/usb/input/hid-input.c static struct { · line 147

Quoted 3 lines
drivers/usb/input/hid-input.c +3 -0
+
+   return (trans->from?trans:NULL);
+}

I'd prefer liberal amount of spaces applied here </extreme nitpick mode=

Me too :)

Quoted 1 line
Quoted 1 line

+ try_translate =3D test_bit(usage->code, usbhid_pb_numlock=

)?1:

Quoted 6 lines
Quoted 6 lines

drivers/usb/input/hid-input.c static struct { · line 192

Quoted 2 lines
drivers/usb/input/hid-input.c +2 -0
+                           test_bit(LED_NUML, input->led);
+           if (try_translate) {

Isn't this the same as

              if (test_bit(usage->code, usbhid_pb_numlock) || test_bit(=

LED_NUML, input->led))

Quoted 6 lines
Quoted 2 lines

but harder to read?

No. If the first one is 0, the second one will not matter in the first version, while it will in yours.

Huh? You mean 1, right?

    try_translate =3D 0;
    if (test_bit(usage->code, usbhid_pb_numlock))
         try_translate =3D 1;
    else if (test_bit(LED_NUML, input->led))
         try_translate =3D 1;
    else
Quoted 4 lines

Ben.

--
Dmitry

#29 lore raw
Quoted 3 lines · Dmitry Torokhov
Quoted 2 lines · Benjamin Herrenschmidt
Quoted 2 lines

That should be "MODULE_PARM_DESC(pb_fn_mode, ...)". Also, since this =

is

Quoted 1 line
Quoted 1 line
Quoted 1 line

for compatibility with ADB, why do we have 3 options? Doesn't ADB hav=

e

Quoted 4 lines
Quoted 4 lines
Quoted 1 line

only 2?

No, the ADB keyboard can operate in 2 modes that can be set with a PMU command, I forgot about that in my earlier comments. In one mode, you g=

et

Quoted 2 lines
Quoted 2 lines

the "special" behaviour by default on the Fx keys and you get Fx when pressing Fn-Fx, and in the other mode, you get the Fx by default and th=

e

Quoted 16 lines
Quoted 2 lines

special behaviour when pressing Fn-Fx.

Right, so do we need "no translation, fnkeyfirst and fnkeylast" option or just "fnkeyfirst and fnkeyast"?

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

+static inline struct hidinput_key_translation *find_translation(

I thought is was agreed that we'd avoid "inlines" in .c files?

Ah ? I have certainly missed that discussion ...

Newer GCCs, unit-at-a-time, etc. etc. - teher was pretty long discussion about letting GCC decide on inlining.

Quoted 1 line
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/usb/input/hid-input.c static struct {

Quoted 6 lines
drivers/usb/input/hid-input.c +6 -0
+   struct hidinput_key_translation *table, u16 from)
+{
+   struct hidinput_key_translation *trans;
+
+   /* Look for the translation */
+   for(trans =3D table; trans->from && (trans->from !=3D from); tr=

ans++);

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

drivers/usb/input/hid-input.c static struct { · line 147

Quoted 3 lines
drivers/usb/input/hid-input.c +3 -0
+
+   return (trans->from?trans:NULL);
+}

I'd prefer liberal amount of spaces applied here </extreme nitpick mo=

de>

Quoted 4 lines
Quoted 4 lines

Me too :)

Quoted 1 line
Quoted 1 line

+ try_translate =3D test_bit(usage->code, usbhid_pb_numlo=

ck)?1:

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/usb/input/hid-input.c static struct { · line 192

Quoted 2 lines
drivers/usb/input/hid-input.c +2 -0
+                           test_bit(LED_NUML, input->led);
+           if (try_translate) {

Isn't this the same as

              if (test_bit(usage->code, usbhid_pb_numlock) || test_bi=

t(LED_NUML, input->led))

Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

but harder to read?

No. If the first one is 0, the second one will not matter in the first version, while it will in yours.

Quoted 9 lines

Huh? You mean 1, right?

   try_translate =3D 0;
   if (test_bit(usage->code, usbhid_pb_numlock))
        try_translate =3D 1;
   else if (test_bit(LED_NUML, input->led))
        try_translate =3D 1;
   else

Uhg, accidentially hit send, sorry... Ok, nevermind, I see your other messa= ge ;)

--
Dmitry

#30 lore raw
In reply to Dmitry Torokhov
Quoted 2 lines

Right, so do we need "no translation, fnkeyfirst and fnkeylast" option or just "fnkeyfirst and fnkeyast"?

I think "no translation" should still be around if people want to handle it entirely from userland no ?

That is:

- no translation : nothing special is done, Fx sends Fx keycode
regardless of Fn key, Fn key itsef sends a keycode for itself, there is no emulation of numlock

- fnkeyfirst / fnkeylast : Either Fx is translated and Fn-Fx is not or
the opposite. Numlock emulation is enabled.

Quoted 1 line

Huh? You mean 1, right?

Yah, forget it, I was on crack.

#31 lore raw
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 2 lines

Right, so do we need "no translation, fnkeyfirst and fnkeylast" option or just "fnkeyfirst and fnkeyast"?

I think "no translation" should still be around if people want to handle it entirely from userland no ?

Quoted 8 lines

That is:

- no translation : nothing special is done, Fx sends Fx keycode
regardless of Fn key, Fn key itsef sends a keycode for itself, there is no emulation of numlock

- fnkeyfirst / fnkeylast : Either Fx is translated and Fn-Fx is not or
the opposite. Numlock emulation is enabled.

OK then, I will push the patch to Linus.

--
Dmitry

#23 lore raw
In reply to Michael Hanselmann
Quoted 1 line · Michael Hanselmann

-=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=

=A0=A0=A0=A0=A0=A0=A0case 0x003: map_key_clear(KEY_FN);=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0break;

Quoted 2 lines

+#ifdef CONFIG_USB_HIDINPUT_POWERBOOK +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=

=A0=A0=A0=A0=A0=A0=A0/* The fn key on Apple PowerBooks */

Quoted 1 line

+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=

=A0=A0=A0=A0=A0=A0=A0case 0x0003: {

Quoted 1 line

+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=

=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0struct hidinput_key_translatio= n *trans;

Quoted 2 lines

+ +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=

=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0map_key_clear(KEY_FN);

Quoted 1 line

+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=

=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0set_bit(KEY_NUMLOCK, input->ke= ybit);

Quoted 1 line

+

One little thing - I think that we should report FN key even if PowerBook support is disabled. Can I solicit input on the patch below (I also rearran= ged
teh code slightly)?=20

=2D-=20
Dmitry

=46rom: Michael Hanselmann <[email protected]>

Input: HID - add support for fn key on Apple PowerBooks

This patch implements support for the fn key on Apple PowerBooks using USB based keyboards and makes them behave like their ADB counterparts.

=2D--

 drivers/usb/input/Kconfig     |   10 ++
 drivers/usb/input/hid-core.c  |    8 ++
 drivers/usb/input/hid-input.c |  166 +++++++++++++++++++++++++++++++++++++=
++++-
 drivers/usb/input/hid.h       |   31 ++++---
 4 files changed, 201 insertions(+), 14 deletions(-)

Index: work/drivers/usb/input/hid-core.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=2D-- work.orig/drivers/usb/input/hid-core.c
+++ work/drivers/usb/input/hid-core.c
@@ -1585,6 +1585,14 @@ static const struct hid_blacklist {
=20
{ USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION, HID_QUIRK_CYMOTION=
},
=20
+ { USB_VENDOR_ID_APPLE, 0x020E, HID_QUIRK_POWERBOOK_HAS_FN },
+ { USB_VENDOR_ID_APPLE, 0x020F, HID_QUIRK_POWERBOOK_HAS_FN },
+ { USB_VENDOR_ID_APPLE, 0x0214, HID_QUIRK_POWERBOOK_HAS_FN },
+ { USB_VENDOR_ID_APPLE, 0x0215, HID_QUIRK_POWERBOOK_HAS_FN },
+ { USB_VENDOR_ID_APPLE, 0x0216, HID_QUIRK_POWERBOOK_HAS_FN },
+ { USB_VENDOR_ID_APPLE, 0x030A, HID_QUIRK_POWERBOOK_HAS_FN },
+ { USB_VENDOR_ID_APPLE, 0x030B, HID_QUIRK_POWERBOOK_HAS_FN },
+
{ 0, 0 }
};
=20
Index: work/drivers/usb/input/hid.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=2D-- work.orig/drivers/usb/input/hid.h
+++ work/drivers/usb/input/hid.h
@@ -235,18 +235,20 @@ struct hid_item {
* HID device quirks.
*/
=20
=2D#define HID_QUIRK_INVERT 0x001
=2D#define HID_QUIRK_NOTOUCH 0x002
=2D#define HID_QUIRK_IGNORE 0x004
=2D#define HID_QUIRK_NOGET 0x008
=2D#define HID_QUIRK_HIDDEV 0x010
=2D#define HID_QUIRK_BADPAD 0x020
=2D#define HID_QUIRK_MULTI_INPUT 0x040
=2D#define HID_QUIRK_2WHEEL_MOUSE_HACK_7 0x080
=2D#define HID_QUIRK_2WHEEL_MOUSE_HACK_5 0x100
=2D#define HID_QUIRK_2WHEEL_MOUSE_HACK_ON 0x200
=2D#define HID_QUIRK_2WHEEL_POWERMOUSE 0x400
=2D#define HID_QUIRK_CYMOTION 0x800
+#define HID_QUIRK_INVERT 0x00000001
+#define HID_QUIRK_NOTOUCH 0x00000002
+#define HID_QUIRK_IGNORE 0x00000004
+#define HID_QUIRK_NOGET 0x00000008
+#define HID_QUIRK_HIDDEV 0x00000010
+#define HID_QUIRK_BADPAD 0x00000020
+#define HID_QUIRK_MULTI_INPUT 0x00000040
+#define HID_QUIRK_2WHEEL_MOUSE_HACK_7 0x00000080
+#define HID_QUIRK_2WHEEL_MOUSE_HACK_5 0x00000100
+#define HID_QUIRK_2WHEEL_MOUSE_HACK_ON 0x00000200
+#define HID_QUIRK_2WHEEL_POWERMOUSE 0x00000400
+#define HID_QUIRK_CYMOTION 0x00000800
+#define HID_QUIRK_POWERBOOK_HAS_FN 0x00001000
+#define HID_QUIRK_POWERBOOK_FN_ON 0x00002000
=20
/*
* This is the global environment of the parser. This information is
@@ -432,6 +434,11 @@ struct hid_device { /* device repo
void (*ff_exit)(struct hid_device*); /* Called=
by hid_exit_ff(hid) */
int (*ff_event)(struct hid_device *hid, struct input_dev *input,
unsigned int type, unsigned int code, int value);
+
+#ifdef CONFIG_USB_HIDINPUT_POWERBOOK
+ unsigned long pb_pressed_fn[NBITS(KEY_MAX)];
+ unsigned long pb_pressed_numlock[NBITS(KEY_MAX)];
+#endif
};
=20
#define HID_GLOBAL_STACK_SIZE 4
Index: work/drivers/usb/input/hid-input.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=2D-- work.orig/drivers/usb/input/hid-input.c
+++ work/drivers/usb/input/hid-input.c
@@ -73,6 +73,160 @@ static const struct {
#define map_key_clear(c) do { map_key(c); clear_bit(c, bit); } while (0)
#define map_ff_effect(c) do { set_bit(c, input->ffbit); } while (0)
=20
+#ifdef CONFIG_USB_HIDINPUT_POWERBOOK
+
+struct hidinput_key_translation {
+ u16 from;
+ u16 to;
+ u8 flags;
+};
+
+#define POWERBOOK_FLAG_FKEY 0x01
+
+static struct hidinput_key_translation powerbook_fn_keys[] =3D {
+ { KEY_BACKSPACE, KEY_DELETE },
+ { KEY_F1, KEY_BRIGHTNESSDOWN, POWERBOOK_FLAG_FKEY },
+ { KEY_F2, KEY_BRIGHTNESSUP, POWERBOOK_FLAG_FKEY },
+ { KEY_F3, KEY_MUTE, POWERBOOK_FLAG_FKEY },
+ { KEY_F4, KEY_VOLUMEDOWN, POWERBOOK_FLAG_FKEY },
+ { KEY_F5, KEY_VOLUMEUP, POWERBOOK_FLAG_FKEY },
+ { KEY_F6, KEY_NUMLOCK, POWERBOOK_FLAG_FKEY },
+ { KEY_F7, KEY_SWITCHVIDEOMODE, POWERBOOK_FLAG_FKEY },
+ { KEY_F8, KEY_KBDILLUMTOGGLE, POWERBOOK_FLAG_FKEY },
+ { KEY_F9, KEY_KBDILLUMDOWN, POWERBOOK_FLAG_FKEY },
+ { KEY_F10, KEY_KBDILLUMUP, POWERBOOK_FLAG_FKEY },
+ { KEY_UP, KEY_PAGEUP },
+ { KEY_DOWN, KEY_PAGEDOWN },
+ { KEY_LEFT, KEY_HOME },
+ { KEY_RIGHT, KEY_END },
+ { }
+};
+
+static struct hidinput_key_translation powerbook_numlock_keys[] =3D {
+ { KEY_J, KEY_KP1 },
+ { KEY_K, KEY_KP2 },
+ { KEY_L, KEY_KP3 },
+ { KEY_U, KEY_KP4 },
+ { KEY_I, KEY_KP5 },
+ { KEY_O, KEY_KP6 },
+ { KEY_7, KEY_KP7 },
+ { KEY_8, KEY_KP8 },
+ { KEY_9, KEY_KP9 },
+ { KEY_M, KEY_KP0 },
+ { KEY_DOT, KEY_KPDOT },
+ { KEY_SLASH, KEY_KPPLUS },
+ { KEY_SEMICOLON, KEY_KPMINUS },
+ { KEY_P, KEY_KPASTERISK },
+ { KEY_MINUS, KEY_KPEQUAL },
+ { KEY_0, KEY_KPSLASH },
+ { KEY_F6, KEY_NUMLOCK },
+ { KEY_KPENTER, KEY_KPENTER },
+ { KEY_BACKSPACE, KEY_BACKSPACE },
+ { }
+};
+
+static int usbhid_pb_fnmode =3D 1;
+module_param_named(pb_fnmode, usbhid_pb_fnmode, int, 0644); +MODULE_PARM_DESC(pb_fnmode,
+ "Mode of fn key on PowerBooks (0 =3D disabled, 1 =3D fkeyslast, 2 =3D fke=
ysfirst)");
+
+static struct hidinput_key_translation *find_translation(struct hidinput_k= ey_translation *table, u16 from)
+{
+ struct hidinput_key_translation *trans;
+
+ /* Look for the translation */
+ for (trans =3D table; trans->from; trans++)
+ if (trans->from =3D=3D from)
+ return trans;
+
+ return NULL;
+}
+
+static int hidinput_pb_event(struct hid_device *hid, struct input_dev *inp= ut,
+ struct hid_usage *usage, __s32 value)
+{
+ struct hidinput_key_translation *trans;
+
+ if (usage->code =3D=3D KEY_FN) {
+ if (value) hid->quirks |=3D HID_QUIRK_POWERBOOK_FN_ON;
+ else hid->quirks &=3D ~HID_QUIRK_POWERBOOK_FN_ON;
+
+ input_event(input, usage->type, usage->code, value);
+
+ return 1;
+ }
+
+ if (usbhid_pb_fnmode) {
+ int do_translate;
+
+ trans =3D find_translation(powerbook_fn_keys, usage->code);
+ if (trans) {
+ if (test_bit(usage->code, hid->pb_pressed_fn))
+ do_translate =3D 1;
+ else if (trans->flags & POWERBOOK_FLAG_FKEY)
+ do_translate =3D
+ (usbhid_pb_fnmode =3D=3D 2 && (hid->quirks & HID_QUIRK_POWERBOOK_FN_=
ON)) ||
+ (usbhid_pb_fnmode =3D=3D 1 && !(hid->quirks & HID_QUIRK_POWERBOOK_FN_=
ON));
+ else
+ do_translate =3D (hid->quirks & HID_QUIRK_POWERBOOK_FN_ON);
+
+ if (do_translate) {
+ if (value)
+ set_bit(usage->code, hid->pb_pressed_fn);
+ else
+ clear_bit(usage->code, hid->pb_pressed_fn);
+
+ input_event(input, usage->type, trans->to, value);
+
+ return 1;
+ }
+ }
+
+ if (test_bit(usage->code, hid->pb_pressed_numlock) ||
+ test_bit(LED_NUML, input->led)) {
+ trans =3D find_translation(powerbook_numlock_keys, usage->code);
+
+ if (trans) {
+ if (value)
+ set_bit(usage->code, hid->pb_pressed_numlock);
+ else
+ clear_bit(usage->code, hid->pb_pressed_numlock);
+
+ input_event(input, usage->type, trans->to, value);
+ }
+
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+static void hidinput_pb_setup(struct input_dev *input)
+{
+ struct hidinput_key_translation *trans;
+
+ set_bit(KEY_NUMLOCK, input->keybit);
+
+ /* Enable all needed keys */
+ for (trans =3D powerbook_fn_keys; trans->from; trans++)
+ set_bit(trans->to, input->keybit);
+
+ for (trans =3D powerbook_numlock_keys; trans->from; trans++)
+ set_bit(trans->to, input->keybit);
+}
+#else
+static inline int hidinput_pb_event(struct hid_device *hid, struct input_d= ev *input,
+ struct hid_usage *usage, __s32 value)
+{
+ return 0;
+}
+
+static inline void hidinput_pb_setup(struct input_dev *input)
+{
+}
+#endif
+
static void hidinput_configure_usage(struct hid_input *hidinput, struct hi=
d_field *field,
struct hid_usage *usage)
{
@@ -336,7 +490,12 @@ static void hidinput_configure_usage(str
=20
set_bit(EV_REP, input->evbit); switch(usage->hid & HID_USAGE) {
=2D case 0x003: map_key_clear(KEY_FN); break;
+ case 0x003:
+ /* The fn key on Apple PowerBooks */
+ map_key_clear(KEY_FN);
+ hidinput_pb_setup(input);
+ break;
+
default: goto ignore;
}
break;
@@ -493,6 +652,9 @@ void hidinput_hid_event(struct hid_devic
return;
}
=20
+ if ((hid->quirks & HID_QUIRK_POWERBOOK_HAS_FN) && hidinput_pb_event(hid, =
input, usage, value))
+ return;
+
if (usage->hat_min < usage->hat_max || usage->hat_dir) {
int hat_dir =3D usage->hat_dir;
if (!hat_dir)
@@ -535,7 +697,7 @@ void hidinput_hid_event(struct hid_devic
return;
}
=20
=2D if((usage->type =3D=3D EV_KEY) && (usage->code =3D=3D 0)) /* Key 0 is "=
unassigned", not KEY_UNKNOWN */
+ if ((usage->type =3D=3D EV_KEY) && (usage->code =3D=3D 0)) /* Key 0 is "u=
nassigned", not KEY_UNKNOWN */
return;
=20
input_event(input, usage->type, usage->code, value);
Index: work/drivers/usb/input/Kconfig =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=2D-- work.orig/drivers/usb/input/Kconfig
+++ work/drivers/usb/input/Kconfig
@@ -37,6 +37,16 @@ config USB_HIDINPUT
=20
If unsure, say Y.
=20
+config USB_HIDINPUT_POWERBOOK
+ bool "Enable support for iBook/PowerBook special keys"
+ default n
+ depends on USB_HIDINPUT
+ help
+ Say Y here if you want support for the special keys (Fn, Numlock) on
+ Apple iBooks and PowerBooks.
+
+ If unsure, say N.
+
config HID_FF
bool "Force feedback support (EXPERIMENTAL)"
depends on USB_HIDINPUT && EXPERIMENTAL

#24 lore raw
Quoted 14 lines · Dmitry Torokhov

drivers/usb/input/hid-input.c static void hidinput_configure_usage(str · line 469

Quoted 9 lines · Michael Hanselmann

-                               case 0x003: map_key_clear(KEY_FN);              break;

drivers/usb/input/hid-input.c +8 -0
+#ifdef CONFIG_USB_HIDINPUT_POWERBOOK
+                               /* The fn key on Apple PowerBooks */
+                               case 0x0003: {
+                                       struct hidinput_key_translation *trans;
+
+                                       map_key_clear(KEY_FN);
+                                       set_bit(KEY_NUMLOCK, input->keybit);
+

One little thing - I think that we should report FN key even if PowerBook support is disabled. Can I solicit input on the patch below (I also rearranged teh code slightly)?

Looks fine. We might want to skip adding the keys to the bitmap if the support is compiled in, but disabled, but then it wouldn't be possible to enable it at runtime.

Quoted 314 lines
Signature · 26 lines
-- 
Dmitry

From: Michael Hanselmann <[email protected]>

Input: HID - add support for fn key on Apple PowerBooks

This patch implements support for the fn key on Apple PowerBooks using
USB based keyboards and makes them behave like their ADB counterparts.

Signed-off-by: Michael Hanselmann <[email protected]>
Acked-by: Rene Nussbaumer <[email protected]>
Acked-by: Johannes Berg <[email protected]>
Acked-by: Benjamin Herrenschmidt <[email protected]>

Signed-off-by: Dmitry Torokhov <[email protected]>
---

 drivers/usb/input/Kconfig     |   10 ++
 drivers/usb/input/hid-core.c  |    8 ++
 drivers/usb/input/hid-input.c |  166 +++++++++++++++++++++++++++++++++++++++++-
 drivers/usb/input/hid.h       |   31 ++++---
 4 files changed, 201 insertions(+), 14 deletions(-)

Index: work/drivers/usb/input/hid-core.c
===================================================================
drivers/usb/input/hid-core.c +8 -0
@@ -1585,6 +1585,14 @@ static const struct hid_blacklist {
 
 	{ USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION, HID_QUIRK_CYMOTION },
 
+	{ USB_VENDOR_ID_APPLE, 0x020E, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x020F, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x0214, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x0215, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x0216, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x030A, HID_QUIRK_POWERBOOK_HAS_FN },
+	{ USB_VENDOR_ID_APPLE, 0x030B, HID_QUIRK_POWERBOOK_HAS_FN },
+
 	{ 0, 0 }
 };
 

Index: work/drivers/usb/input/hid.h
===================================================================

drivers/usb/input/hid.h +19 -12
@@ -235,18 +235,20 @@ struct hid_item {
  * HID device quirks.
  */
 
-#define HID_QUIRK_INVERT			0x001
-#define HID_QUIRK_NOTOUCH			0x002
-#define HID_QUIRK_IGNORE			0x004
-#define HID_QUIRK_NOGET				0x008
-#define HID_QUIRK_HIDDEV			0x010
-#define HID_QUIRK_BADPAD			0x020
-#define HID_QUIRK_MULTI_INPUT			0x040
-#define HID_QUIRK_2WHEEL_MOUSE_HACK_7		0x080
-#define HID_QUIRK_2WHEEL_MOUSE_HACK_5		0x100
-#define HID_QUIRK_2WHEEL_MOUSE_HACK_ON		0x200
-#define HID_QUIRK_2WHEEL_POWERMOUSE		0x400
-#define HID_QUIRK_CYMOTION			0x800
+#define HID_QUIRK_INVERT			0x00000001
+#define HID_QUIRK_NOTOUCH			0x00000002
+#define HID_QUIRK_IGNORE			0x00000004
+#define HID_QUIRK_NOGET				0x00000008
+#define HID_QUIRK_HIDDEV			0x00000010
+#define HID_QUIRK_BADPAD			0x00000020
+#define HID_QUIRK_MULTI_INPUT			0x00000040
+#define HID_QUIRK_2WHEEL_MOUSE_HACK_7		0x00000080
+#define HID_QUIRK_2WHEEL_MOUSE_HACK_5		0x00000100
+#define HID_QUIRK_2WHEEL_MOUSE_HACK_ON		0x00000200
+#define HID_QUIRK_2WHEEL_POWERMOUSE		0x00000400
+#define HID_QUIRK_CYMOTION			0x00000800
+#define HID_QUIRK_POWERBOOK_HAS_FN		0x00001000
+#define HID_QUIRK_POWERBOOK_FN_ON		0x00002000
 
 /*
  * This is the global environment of the parser. This information is
@@ -432,6 +434,11 @@ struct hid_device {							/* device repo
 	void (*ff_exit)(struct hid_device*);                            /* Called by hid_exit_ff(hid) */
 	int (*ff_event)(struct hid_device *hid, struct input_dev *input,
 			unsigned int type, unsigned int code, int value);
+
+#ifdef CONFIG_USB_HIDINPUT_POWERBOOK
+	unsigned long pb_pressed_fn[NBITS(KEY_MAX)];
+	unsigned long pb_pressed_numlock[NBITS(KEY_MAX)];
+#endif
 };
 
 #define HID_GLOBAL_STACK_SIZE 4

Index: work/drivers/usb/input/hid-input.c
===================================================================

drivers/usb/input/hid-input.c +164 -2
@@ -73,6 +73,160 @@ static const struct {
 #define map_key_clear(c)	do { map_key(c); clear_bit(c, bit); } while (0)
 #define map_ff_effect(c)	do { set_bit(c, input->ffbit); } while (0)
 
+#ifdef CONFIG_USB_HIDINPUT_POWERBOOK
+
+struct hidinput_key_translation {
+	u16 from;
+	u16 to;
+	u8 flags;
+};
+
+#define POWERBOOK_FLAG_FKEY 0x01
+
+static struct hidinput_key_translation powerbook_fn_keys[] = {
+	{ KEY_BACKSPACE, KEY_DELETE },
+	{ KEY_F1,	KEY_BRIGHTNESSDOWN,	POWERBOOK_FLAG_FKEY },
+	{ KEY_F2,	KEY_BRIGHTNESSUP,	POWERBOOK_FLAG_FKEY },
+	{ KEY_F3,	KEY_MUTE,		POWERBOOK_FLAG_FKEY },
+	{ KEY_F4,	KEY_VOLUMEDOWN,		POWERBOOK_FLAG_FKEY },
+	{ KEY_F5,	KEY_VOLUMEUP,		POWERBOOK_FLAG_FKEY },
+	{ KEY_F6,	KEY_NUMLOCK,		POWERBOOK_FLAG_FKEY },
+	{ KEY_F7,	KEY_SWITCHVIDEOMODE,	POWERBOOK_FLAG_FKEY },
+	{ KEY_F8,	KEY_KBDILLUMTOGGLE,	POWERBOOK_FLAG_FKEY },
+	{ KEY_F9,	KEY_KBDILLUMDOWN,	POWERBOOK_FLAG_FKEY },
+	{ KEY_F10,	KEY_KBDILLUMUP,		POWERBOOK_FLAG_FKEY },
+	{ KEY_UP,	KEY_PAGEUP },
+	{ KEY_DOWN,	KEY_PAGEDOWN },
+	{ KEY_LEFT,	KEY_HOME },
+	{ KEY_RIGHT,	KEY_END },
+	{ }
+};
+
+static struct hidinput_key_translation powerbook_numlock_keys[] = {
+	{ KEY_J,	KEY_KP1 },
+	{ KEY_K,	KEY_KP2 },
+	{ KEY_L,	KEY_KP3 },
+	{ KEY_U,	KEY_KP4 },
+	{ KEY_I,	KEY_KP5 },
+	{ KEY_O,	KEY_KP6 },
+	{ KEY_7,	KEY_KP7 },
+	{ KEY_8,	KEY_KP8 },
+	{ KEY_9,	KEY_KP9 },
+	{ KEY_M,	KEY_KP0 },
+	{ KEY_DOT,	KEY_KPDOT },
+	{ KEY_SLASH,	KEY_KPPLUS },
+	{ KEY_SEMICOLON, KEY_KPMINUS },
+	{ KEY_P,	KEY_KPASTERISK },
+	{ KEY_MINUS,	KEY_KPEQUAL },
+	{ KEY_0,	KEY_KPSLASH },
+	{ KEY_F6,	KEY_NUMLOCK },
+	{ KEY_KPENTER,	KEY_KPENTER },
+	{ KEY_BACKSPACE, KEY_BACKSPACE },
+	{ }
+};
+
+static int usbhid_pb_fnmode = 1;
+module_param_named(pb_fnmode, usbhid_pb_fnmode, int, 0644);
+MODULE_PARM_DESC(pb_fnmode,
+	"Mode of fn key on PowerBooks (0 = disabled, 1 = fkeyslast, 2 = fkeysfirst)");
+
+static struct hidinput_key_translation *find_translation(struct hidinput_key_translation *table, u16 from)
+{
+	struct hidinput_key_translation *trans;
+
+	/* Look for the translation */
+	for (trans = table; trans->from; trans++)
+		if (trans->from == from)
+			return trans;
+
+	return NULL;
+}
+
+static int hidinput_pb_event(struct hid_device *hid, struct input_dev *input,
+			     struct hid_usage *usage, __s32 value)
+{
+	struct hidinput_key_translation *trans;
+
+	if (usage->code == KEY_FN) {
+		if (value) hid->quirks |=  HID_QUIRK_POWERBOOK_FN_ON;
+		else       hid->quirks &= ~HID_QUIRK_POWERBOOK_FN_ON;
+
+		input_event(input, usage->type, usage->code, value);
+
+		return 1;
+	}
+
+	if (usbhid_pb_fnmode) {
+		int do_translate;
+
+		trans = find_translation(powerbook_fn_keys, usage->code);
+		if (trans) {
+			if (test_bit(usage->code, hid->pb_pressed_fn))
+				do_translate = 1;
+			else if (trans->flags & POWERBOOK_FLAG_FKEY)
+				do_translate =
+					(usbhid_pb_fnmode == 2 &&  (hid->quirks & HID_QUIRK_POWERBOOK_FN_ON)) ||
+					(usbhid_pb_fnmode == 1 && !(hid->quirks & HID_QUIRK_POWERBOOK_FN_ON));
+			else
+				do_translate = (hid->quirks & HID_QUIRK_POWERBOOK_FN_ON);
+
+			if (do_translate) {
+				if (value)
+					set_bit(usage->code, hid->pb_pressed_fn);
+				else
+					clear_bit(usage->code, hid->pb_pressed_fn);
+
+				input_event(input, usage->type, trans->to, value);
+
+				return 1;
+			}
+		}
+
+		if (test_bit(usage->code, hid->pb_pressed_numlock) ||
+		    test_bit(LED_NUML, input->led)) {
+			trans = find_translation(powerbook_numlock_keys, usage->code);
+
+			if (trans) {
+				if (value)
+					set_bit(usage->code, hid->pb_pressed_numlock);
+				else
+					clear_bit(usage->code, hid->pb_pressed_numlock);
+
+				input_event(input, usage->type, trans->to, value);
+			}
+
+			return 1;
+		}
+	}
+
+	return 0;
+}
+
+static void hidinput_pb_setup(struct input_dev *input)
+{
+	struct hidinput_key_translation *trans;
+
+	set_bit(KEY_NUMLOCK, input->keybit);
+
+	/* Enable all needed keys */
+	for (trans = powerbook_fn_keys; trans->from; trans++)
+		set_bit(trans->to, input->keybit);
+
+	for (trans = powerbook_numlock_keys; trans->from; trans++)
+		set_bit(trans->to, input->keybit);
+}
+#else
+static inline int hidinput_pb_event(struct hid_device *hid, struct input_dev *input,
+				    struct hid_usage *usage, __s32 value)
+{
+	return 0;
+}
+
+static inline void hidinput_pb_setup(struct input_dev *input)
+{
+}
+#endif
+
 static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_field *field,
 				     struct hid_usage *usage)
 {
@@ -336,7 +490,12 @@ static void hidinput_configure_usage(str
 
 			set_bit(EV_REP, input->evbit);
 			switch(usage->hid & HID_USAGE) {
-				case 0x003: map_key_clear(KEY_FN);		break;
+				case 0x003:
+					/* The fn key on Apple PowerBooks */
+					map_key_clear(KEY_FN);
+					hidinput_pb_setup(input);
+					break;
+
 				default:    goto ignore;
 			}
 			break;
@@ -493,6 +652,9 @@ void hidinput_hid_event(struct hid_devic
 		return;
 	}
 
+	if ((hid->quirks & HID_QUIRK_POWERBOOK_HAS_FN) && hidinput_pb_event(hid, input, usage, value))
+		return;
+
 	if (usage->hat_min < usage->hat_max || usage->hat_dir) {
 		int hat_dir = usage->hat_dir;
 		if (!hat_dir)
@@ -535,7 +697,7 @@ void hidinput_hid_event(struct hid_devic
 		return;
 	}
 
-	if((usage->type == EV_KEY) && (usage->code == 0)) /* Key 0 is "unassigned", not KEY_UNKNOWN */
+	if ((usage->type == EV_KEY) && (usage->code == 0)) /* Key 0 is "unassigned", not KEY_UNKNOWN */
 		return;
 
 	input_event(input, usage->type, usage->code, value);

Index: work/drivers/usb/input/Kconfig
===================================================================

drivers/usb/input/Kconfig +10 -0
@@ -37,6 +37,16 @@ config USB_HIDINPUT
 
 	  If unsure, say Y.
 
+config USB_HIDINPUT_POWERBOOK
+	bool "Enable support for iBook/PowerBook special keys"
+	default n
+	depends on USB_HIDINPUT
+	help
+	  Say Y here if you want support for the special keys (Fn, Numlock) on
+	  Apple iBooks and PowerBooks.
+
+	  If unsure, say N.
+
 config HID_FF
 	bool "Force feedback support (EXPERIMENTAL)"
 	depends on USB_HIDINPUT && EXPERIMENTAL
Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR
#25 lore raw
In reply to Dmitry Torokhov

Hello Dmitry

Quoted 3 lines · Dmitry Torokhov

One little thing - I think that we should report FN key even if PowerBook support is disabled. Can I solicit input on the patch below (I also rearranged teh code slightly)?

Yeah, all looks fine for me.

Greets,
Michael