Skip to contentSkip to conversation

Input: add appleir USB driver

PATCH RESEND In review Bastien Nocera 4 participants 14 messages Sep 30, 2010 – Nov 19, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 Input: add appleir USB driver

This driver was originally written by James McKenzie, updated by Greg Kroah-Hartman, further updated by myself, with suspend support added.

More recent versions of the IR receiver are also supported through a patch by Alex Karpenko. The patch also adds support for the 2nd and 5th generation of the controller, and the menu key on newer brushed metal remotes.

Tested on a MacbookAir1,1

---
 Documentation/input/appleir.txt |   46 ++++
 drivers/hid/hid-apple.c         |    4 -
 drivers/hid/hid-core.c          |    7 +-
 drivers/hid/hid-ids.h           |    5 +-
 drivers/input/misc/Kconfig      |   13 +
 drivers/input/misc/Makefile     |    1 +
 drivers/input/misc/appleir.c    |  519 +++++++++++++++++++++++++++++++++++++++
 7 files changed, 588 insertions(+), 7 deletions(-)
 create mode 100644 Documentation/input/appleir.txt
 create mode 100644 drivers/input/misc/appleir.c
Documentation/input/appleir.txt new file +46 -0
new file mode 100644
index 0000000..db637fb
@@ -0,0 +1,46 @@
+Apple IR receiver Driver (appleir)
+----------------------------------
+	Copyright (C) 2009 Bastien Nocera <[email protected]>
+
+The appleir driver is a kernel input driver to handle Apple's IR
+receivers (and associated remotes) in the kernel.
+
+The driver is an input driver which only handles "official" remotes
+as built and sold by Apple.
+
+Authors
+-------
+
+James McKenzie (original driver)
+Alex Karpenko (05ac:8242 support)
+Greg Kroah-Hartman (cleanups and original submission)
+Bastien Nocera (further cleanups, brushed metal "enter"
+button support and suspend support)
+
+Supported hardware
+------------------
+
+- All Apple laptops and desktops from 2005 onwards, except:
+  - the unibody Macbook (2009)
+  - Mac Pro (all versions)
+- Apple TV (all revisions prior to September 2010)
+
+The remote will only support the 6 (old white) or 7 (brushed metal) buttons
+of the remotes as sold by Apple. See the next section if you want to use
+other remotes or want to use lirc with the device instead of the kernel driver.
+
+Using lirc (native) instead of the kernel driver
+------------------------------------------------
+
+First, you will need to disable the kernel driver for the receiver.
+
+This can be achieved by passing quirks to the usbhid driver.
+The quirk line would be:
+usbhid.quirks=0x05ac:0x8242:0x40000010
+
+With 0x05ac being the vendor ID (Apple, you shouldn't need to change this)
+With 0x8242 being the product ID (check the output of lsusb for your hardware)
+And 0x10 being "HID_QUIRK_HIDDEV_FORCE" and 0x40000000 being "HID_QUIRK_NO_IGNORE"
+
+This should force the creation of a hiddev device for the receiver, and
+make it usable under lirc.
drivers/hid/hid-apple.c +0 -4
index bba05d0..0059d5a 100644
@@ -361,10 +361,6 @@ static void apple_remove(struct hid_device *hdev)
 }
 
 static const struct hid_device_id apple_devices[] = {
-	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL),
-		.driver_data = APPLE_HIDDEV | APPLE_IGNORE_HIDINPUT },
-	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4),
-		.driver_data = APPLE_HIDDEV | APPLE_IGNORE_HIDINPUT },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE),
 		.driver_data = APPLE_MIGHTYMOUSE | APPLE_INVERT_HWHEEL },
 
drivers/hid/hid-core.c +5 -2
index baa25ad..abc5bd7 100644
@@ -1244,8 +1244,6 @@ static const struct hid_device_id hid_blacklist[] = {
 #if defined(CONFIG_HID_ACRUX_FF) || defined(CONFIG_HID_ACRUX_FF_MODULE)
 	{ HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802) },
 #endif
-	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL) },
-	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) },
 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICMOUSE) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
@@ -1577,6 +1575,11 @@ static const struct hid_device_id hid_ignore_list[] = {
 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232) },
+	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL) },
+	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL2) },
+	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL3) },
+	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) },
+	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL5) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_T91MT)},
 	{ HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM)},
 	{ HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM2)},
drivers/hid/hid-ids.h +4 -1
index 11af537..360a5ca 100644
@@ -100,8 +100,11 @@
 #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS   0x023b
 #define USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY	0x030a
 #define USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY	0x030b
-#define USB_DEVICE_ID_APPLE_ATV_IRCONTROL	0x8241
+#define USB_DEVICE_ID_APPLE_IRCONTROL	0x8240
+#define USB_DEVICE_ID_APPLE_IRCONTROL2	0x1440
+#define USB_DEVICE_ID_APPLE_IRCONTROL3	0x8241
 #define USB_DEVICE_ID_APPLE_IRCONTROL4	0x8242
+#define USB_DEVICE_ID_APPLE_IRCONTROL5	0x8243
 
 #define USB_VENDOR_ID_ASUS		0x0486
 #define USB_DEVICE_ID_ASUS_T91MT	0x0185
drivers/input/misc/Kconfig +13 -0
index 60de906..2f2f2e7 100644
@@ -209,6 +209,19 @@ config INPUT_KEYSPAN_REMOTE
 	  To compile this driver as a module, choose M here: the module will
 	  be called keyspan_remote.
 
+config INPUT_APPLEIR
+	tristate "Apple infrared receiver (built in)"
+	depends on USB_ARCH_HAS_HCD
+	select USB
+	help
+	  Say Y here if you want to use a Apple infrared remote control. All
+	  the Apple computers from 2005 onwards include such a port, except
+	  the unibody Macbook (2009), and Mac Pros. This receiver is also
+	  used in the Apple TV set-top box prior to the 2010 model.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called appleir.
+
 config INPUT_POWERMATE
 	tristate "Griffin PowerMate and Contour Jog support"
 	depends on USB_ARCH_HAS_HCD
drivers/input/misc/Makefile +1 -0
index 1fe1f6c..d5ef2b9 100644
@@ -13,6 +13,7 @@ obj-$(CONFIG_INPUT_ADXL34X)		+= adxl34x.o
 obj-$(CONFIG_INPUT_ADXL34X_I2C)		+= adxl34x-i2c.o
 obj-$(CONFIG_INPUT_ADXL34X_SPI)		+= adxl34x-spi.o
 obj-$(CONFIG_INPUT_APANEL)		+= apanel.o
+obj-$(CONFIG_INPUT_APPLEIR)		+= appleir.o
 obj-$(CONFIG_INPUT_ATI_REMOTE)		+= ati_remote.o
 obj-$(CONFIG_INPUT_ATI_REMOTE2)		+= ati_remote2.o
 obj-$(CONFIG_INPUT_ATLAS_BTNS)		+= atlas_btns.o
drivers/input/misc/appleir.c new file +519 -0

519 lines not on this page · raw message

Signature · 1 line
1.7.2.2
maintainer
#1 lore raw

Bastien,

Quoted 11 lines · Bastien Nocera

This driver was originally written by James McKenzie, updated by Greg Kroah-Hartman, further updated by myself, with suspend support added.

More recent versions of the IR receiver are also supported through a patch by Alex Karpenko. The patch also adds support for the 2nd and 5th generation of the controller, and the menu key on newer brushed metal remotes.

Tested on a MacbookAir1,1

There are no changes from the last time you sent it, right? I'll try to get the driver in .37 but after that we should probably move it over to the new IR infrastructure...

Thanks.

Signature · 1 line
Dmitry
#2 lore raw
Quoted 12 lines · Dmitry Torokhov

Bastien,

Quoted 9 lines · Bastien Nocera

This driver was originally written by James McKenzie, updated by Greg Kroah-Hartman, further updated by myself, with suspend support added.

More recent versions of the IR receiver are also supported through a patch by Alex Karpenko. The patch also adds support for the 2nd and 5th generation of the controller, and the menu key on newer brushed metal remotes.

Quoted 4 lines
Quoted 2 lines

Tested on a MacbookAir1,1

There are no changes from the last time you sent it, right?

No, but given that I received no comments on it since I submitted it in February, and again a couple of weeks ago, I thought it might need somebody else to look into it.

Quoted 3 lines

I'll try
to get the driver in .37 but after that we should probably move it over to the new IR infrastructure...

I'm not sure what that would bring us, nor do I have any experience in using the ir-core. From what I understood, it still needed fleshing out.

Cheers

#6 lore raw
In reply to Bastien Nocera

Am Donnerstag, 30. September 2010, 12:57:55 schrieb Bastien Nocera:

Quoted 24 lines
drivers/input/misc/appleir.c new file +24 -0
+static int get_key(int data)
+{
+	switch (data) {
+	case 0x02:
+	case 0x03:
+		/* menu */
+		return 1;
+	case 0x04:
+	case 0x05:
+		/* >" */
+		return 2;
+	case 0x06:
+	case 0x07:
+		/* >> */
+		return 3;
+	case 0x08:
+	case 0x09:
+		/* << */
+		return 4;
+	case 0x0a:
+	case 0x0b:
+		/* + */
+		return 5;
+	case 0x0c:

drivers/input/misc/appleir.c line 180

Quoted 10 lines
drivers/input/misc/appleir.c new file +10 -0
+	case 0x0d:
+		/* - */
+		return 6;
+	case 0x5c:
+		/* Middle button, on newer remotes,
+		 * part of a 2 packet-command */
+		return -7;
+	default:
+		return -1;
+	}

Is this really better than a table lookup?

Quoted 10 lines
drivers/input/misc/appleir.c new file +10 -0
+
+static void new_data(struct appleir *appleir, u8 *data, int len)
+{
+	static const u8 keydown[] = { 0x25, 0x87, 0xee };
+	static const u8 keyrepeat[] = { 0x26, };
+	static const u8 flatbattery[] = { 0x25, 0x87, 0xe0 };
+
+	if (debug)
+		dump_packet(appleir, "received", data, len);
+

drivers/input/misc/appleir.c line 230

Quoted 10 lines
drivers/input/misc/appleir.c new file +10 -0
+	if (len != 5)
+		return;
+
+	if (!memcmp(data, keydown, sizeof(keydown))) {
+		int index;
+
+		/* If we already have a key down, take it up before marking
+		   this one down */
+		if (appleir->current_key)
+			key_up(appleir, appleir->current_key);

This races with the timer. You can end up with a key reported up twice.

Quoted 29 lines
drivers/input/misc/appleir.c new file +27 -0
+		/* Handle dual packet commands */
+		if (appleir->prev_key_idx > 0)
+			index = appleir->prev_key_idx;
+		else
+			index = get_key(data[4]);
+
+		if (index > 0) {
+			appleir->current_key = appleir->keymap[index];
+
+			key_down(appleir, appleir->current_key);
+			/* Remote doesn't do key up, either pull them up, in the test
+			   above, or here set a timer which pulls them up after 1/8 s */
+			mod_timer(&appleir->key_up_timer, jiffies + HZ / 8);
+			appleir->prev_key_idx = 0;
+			return;
+		} else if (index == -7) {
+			/* Remember key for next packet */
+			appleir->prev_key_idx = 0 - index;
+			return;
+		}
+	}
 
 
+static int appleir_open(struct input_dev *dev)
+{
+	struct appleir *appleir = input_get_drvdata(dev);
+	struct usb_interface *intf = usb_ifnum_to_if(appleir->usbdev, 0);
+	int r;
+

drivers/input/misc/appleir.c line 315

Quoted 10 lines
drivers/input/misc/appleir.c new file +10 -0
+	r = usb_autopm_get_interface(intf);
+	if (r) {
+		dev_err(&intf->dev,
+			"%s(): usb_autopm_get_interface() = %d\n", __func__, r);
+		return r;
+	}
+
+	mutex_lock(&appleir_mutex);
+
+	if (usb_submit_urb(appleir->urb, GFP_ATOMIC)) {

No need for ATOMIC

drivers/input/misc/appleir.c line 324

Quoted 9 lines
drivers/input/misc/appleir.c new file +9 -0
+		r = -EIO;
+		goto fail;
+	}
+
+	appleir->flags |= APPLEIR_OPENED;
+
+	mutex_unlock(&appleir_mutex);
+
+	usb_autopm_put_interface(intf);

This does not enable remote wakeup. Why? Looks like a bug.

Quoted 6 lines
drivers/input/misc/appleir.c new file +6 -0
+	return 0;
+fail:
+	mutex_unlock(&appleir_mutex);
+	usb_autopm_put_interface(intf);
+	return r;
+}

drivers/input/misc/appleir.c line 341

Quoted 10 lines
drivers/input/misc/appleir.c new file +10 -0
+
+static void appleir_close(struct input_dev *dev)
+{
+	struct appleir *appleir = input_get_drvdata(dev);
+
+	mutex_lock(&appleir_mutex);
+
+	if (!(appleir->flags & APPLEIR_SUSPENDED)) {
+		usb_kill_urb(appleir->urb);
+		del_timer_sync(&appleir->key_up_timer);

You can close with a key unreleased.

Quoted 6 lines
drivers/input/misc/appleir.c new file +6 -0
+	}
+
+	appleir->flags &= ~APPLEIR_OPENED;
+
+	mutex_unlock(&appleir_mutex);
+}

drivers/input/misc/appleir.c line 457

Quoted 10 lines
drivers/input/misc/appleir.c new file +8 -0
+
 
 
+static int appleir_suspend(struct usb_interface *interface,
+			   pm_message_t message)
+{
+	struct appleir *appleir = usb_get_intfdata(interface);
+
+	mutex_lock(&appleir_mutex);
+	if (appleir->flags & APPLEIR_OPENED)

Why bother checking?

Review

Quoted 1 line
(quoted diff) +1 -0
+		usb_kill_urb(appleir->urb);

If the system goes to sleep you'd better report a pressed key as released here and kill the timer.

Quoted 19 lines
drivers/input/misc/appleir.c new file +19 -0
+
+	appleir->flags |= APPLEIR_SUSPENDED;
+
+	mutex_unlock(&appleir_mutex);
+
+	return 0;
+}
+
+static int appleir_resume(struct usb_interface *interface)
+{
+	struct appleir *appleir;
+	int r = 0;
+
+	appleir = usb_get_intfdata(interface);
+
+	mutex_lock(&appleir_mutex);
+	if (appleir->flags & APPLEIR_OPENED) {
+		struct usb_endpoint_descriptor *endpoint;
+

drivers/input/misc/appleir.c line 487

Quoted 10 lines
drivers/input/misc/appleir.c new file +10 -0
+		endpoint = &interface->cur_altsetting->endpoint[0].desc;
+		usb_fill_int_urb(appleir->urb, appleir->usbdev,
+				 usb_rcvintpipe(appleir->usbdev, endpoint->bEndpointAddress),
+				 appleir->data, 8,
+				 appleir_urb, appleir, endpoint->bInterval);
+		appleir->urb->transfer_dma = appleir->dma_buf;
+		appleir->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
+
+		/* And reset the USB device */
+		if (usb_submit_urb(appleir->urb, GFP_ATOMIC))

GFP_NOIO is sufficient.

drivers/input/misc/appleir.c line 505

Quoted 8 lines
drivers/input/misc/appleir.c new file +8 -0
+static struct usb_driver appleir_driver = {
+	.name                 = "appleir",
+	.probe                = appleir_probe,
+	.disconnect           = appleir_disconnect,
+	.suspend              = appleir_suspend,
+	.resume               = appleir_resume,
+	.reset_resume         = appleir_resume,
+	.id_table             = appleir_ids,

If you want runtime power management you need to define supports_autosuspend.

Regards
Oliver

maintainer
#7 lore raw
Quoted 30 lines · Oliver Neukum

Am Donnerstag, 30. September 2010, 12:57:55 schrieb Bastien Nocera:

Quoted 28 lines
drivers/input/misc/appleir.c new file +28 -0
+static int get_key(int data)
+{
+	switch (data) {
+	case 0x02:
+	case 0x03:
+		/* menu */
+		return 1;
+	case 0x04:
+	case 0x05:
+		/* >" */
+		return 2;
+	case 0x06:
+	case 0x07:
+		/* >> */
+		return 3;
+	case 0x08:
+	case 0x09:
+		/* << */
+		return 4;
+	case 0x0a:
+	case 0x0b:
+		/* + */
+		return 5;
+	case 0x0c:
+	case 0x0d:
+		/* - */
+		return 6;
+	case 0x5c:
Quoted 9 lines

drivers/input/misc/appleir.c line 180

Quoted 6 lines
drivers/input/misc/appleir.c new file +6 -0
+		/* Middle button, on newer remotes,
+		 * part of a 2 packet-command */
+		return -7;
+	default:
+		return -1;
+	}

Is this really better than a table lookup?

I think this driver should simply be converted to sparse keymap. It will also make sure that keymap can be changed from userspace.

Quoted 32 lines
Quoted 9 lines
drivers/input/misc/appleir.c new file +9 -0
+static void new_data(struct appleir *appleir, u8 *data, int len)
+{
+	static const u8 keydown[] = { 0x25, 0x87, 0xee };
+	static const u8 keyrepeat[] = { 0x26, };
+	static const u8 flatbattery[] = { 0x25, 0x87, 0xe0 };
+
+	if (debug)
+		dump_packet(appleir, "received", data, len);
+

drivers/input/misc/appleir.c line 230

Quoted 10 lines
drivers/input/misc/appleir.c new file +10 -0
+	if (len != 5)
+		return;
+
+	if (!memcmp(data, keydown, sizeof(keydown))) {
+		int index;
+
+		/* If we already have a key down, take it up before marking
+		   this one down */
+		if (appleir->current_key)
+			key_up(appleir, appleir->current_key);

This races with the timer. You can end up with a key reported up twice.

Quoted 10 lines
drivers/input/misc/appleir.c new file +10 -0
+		/* Handle dual packet commands */
+		if (appleir->prev_key_idx > 0)
+			index = appleir->prev_key_idx;
+		else
+			index = get_key(data[4]);
+
+		if (index > 0) {
+			appleir->current_key = appleir->keymap[index];
+
+			key_down(appleir, appleir->current_key);
Quoted 8 lines

drivers/input/misc/appleir.c line 249

Quoted 8 lines
drivers/input/misc/appleir.c new file +8 -0
+			/* Remote doesn't do key up, either pull them up, in the test
+			   above, or here set a timer which pulls them up after 1/8 s */
+			mod_timer(&appleir->key_up_timer, jiffies + HZ / 8);
+			appleir->prev_key_idx = 0;
+			return;
+		} else if (index == -7) {
+			/* Remember key for next packet */
+			appleir->prev_key_idx = 0 - index;

So it alwas sets prev_key_index to 7 which is ">>". What about the middle button?

Quoted 46 lines
Quoted 11 lines
drivers/input/misc/appleir.c new file +9 -0
+			return;
+		}
+	}
 
 
+static int appleir_open(struct input_dev *dev)
+{
+	struct appleir *appleir = input_get_drvdata(dev);
+	struct usb_interface *intf = usb_ifnum_to_if(appleir->usbdev, 0);
+	int r;
+

drivers/input/misc/appleir.c line 315

Quoted 10 lines
drivers/input/misc/appleir.c new file +10 -0
+	r = usb_autopm_get_interface(intf);
+	if (r) {
+		dev_err(&intf->dev,
+			"%s(): usb_autopm_get_interface() = %d\n", __func__, r);
+		return r;
+	}
+
+	mutex_lock(&appleir_mutex);
+
+	if (usb_submit_urb(appleir->urb, GFP_ATOMIC)) {

No need for ATOMIC

drivers/input/misc/appleir.c line 324

Quoted 9 lines
drivers/input/misc/appleir.c new file +9 -0
+		r = -EIO;
+		goto fail;
+	}
+
+	appleir->flags |= APPLEIR_OPENED;
+
+	mutex_unlock(&appleir_mutex);
+
+	usb_autopm_put_interface(intf);

This does not enable remote wakeup. Why? Looks like a bug.

Quoted 10 lines
drivers/input/misc/appleir.c new file +10 -0
+	return 0;
+fail:
+	mutex_unlock(&appleir_mutex);
+	usb_autopm_put_interface(intf);
+	return r;
+}
+
+static void appleir_close(struct input_dev *dev)
+{
+	struct appleir *appleir = input_get_drvdata(dev);
Quoted 8 lines

drivers/input/misc/appleir.c line 341

Quoted 6 lines
drivers/input/misc/appleir.c new file +6 -0
+
+	mutex_lock(&appleir_mutex);
+
+	if (!(appleir->flags & APPLEIR_SUSPENDED)) {
+		usb_kill_urb(appleir->urb);
+		del_timer_sync(&appleir->key_up_timer);

You can close with a key unreleased.

I think this is handled by input core. We forcibly send release events when device is disconnected; this takes care of surprise disconnect case. OTOH if input_dev->close() is called that means that there are no more listeners for the events so the fact that a key is still pressed is not interesting to anyone.

Quoted 20 lines
Quoted 7 lines
drivers/input/misc/appleir.c new file +6 -0
+	}
+
+	appleir->flags &= ~APPLEIR_OPENED;
+
+	mutex_unlock(&appleir_mutex);
+}

drivers/input/misc/appleir.c line 457

Quoted 10 lines
drivers/input/misc/appleir.c new file +8 -0
+
 
 
+static int appleir_suspend(struct usb_interface *interface,
+			   pm_message_t message)
+{
+	struct appleir *appleir = usb_get_intfdata(interface);
+
+	mutex_lock(&appleir_mutex);
+	if (appleir->flags & APPLEIR_OPENED)

Why bother checking?

Quoted 4 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+		usb_kill_urb(appleir->urb);

If the system goes to sleep you'd better report a pressed key as released here and kill the timer.

Input core sends "release" events upon resume so we should be OK.

Thanks.

Signature · 1 line
Dmitry
#8 lore raw

Am Dienstag, 5. Oktober 2010, 06:45:20 schrieb Dmitry Torokhov:

Quoted 11 lines
Quoted 10 lines

drivers/input/misc/appleir.c line 341

Quoted 8 lines
drivers/input/misc/appleir.c new file +8 -0
+{
+   struct appleir *appleir = input_get_drvdata(dev);
+
+   mutex_lock(&appleir_mutex);
+
+   if (!(appleir->flags & APPLEIR_SUSPENDED)) {
+           usb_kill_urb(appleir->urb);
+           del_timer_sync(&appleir->key_up_timer);

You can close with a key unreleased.

Quoted 5 lines

I think this is handled by input core. We forcibly send release events when device is disconnected; this takes care of surprise disconnect case. OTOH if input_dev->close() is called that means that there are no more listeners for the events so the fact that a key is still pressed is not interesting to anyone.

But what about the next opener? He'll get a completely spurious key release event, as the next key is pressed.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

+ usb_kill_urb(appleir->urb);

If the system goes to sleep you'd better report a pressed key as released here and kill the timer.

Input core sends "release" events upon resume so we should be OK.

I see. OK, this is covered.

Regards
Oliver

maintainer
#9 lore raw
Quoted 12 lines · Oliver Neukum

Am Dienstag, 5. Oktober 2010, 06:45:20 schrieb Dmitry Torokhov:

Quoted 11 lines
Quoted 10 lines

drivers/input/misc/appleir.c line 341

Quoted 8 lines
drivers/input/misc/appleir.c new file +8 -0
+{
+   struct appleir *appleir = input_get_drvdata(dev);
+
+   mutex_lock(&appleir_mutex);
+
+   if (!(appleir->flags & APPLEIR_SUSPENDED)) {
+           usb_kill_urb(appleir->urb);
+           del_timer_sync(&appleir->key_up_timer);

You can close with a key unreleased.

Quoted 8 lines
Quoted 5 lines

I think this is handled by input core. We forcibly send release events when device is disconnected; this takes care of surprise disconnect case. OTOH if input_dev->close() is called that means that there are no more listeners for the events so the fact that a key is still pressed is not interesting to anyone.

But what about the next opener? He'll get a completely spurious key release event, as the next key is pressed.

How does the opening of a device handle relate to a device state? Userspace should expect to see releases without presses (in case they weren't the first client that opened the device).

But I guess we should reset the "last key" here, just in case.

Quoted 9 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

+ usb_kill_urb(appleir->urb);

If the system goes to sleep you'd better report a pressed key as released here and kill the timer.

Input core sends "release" events upon resume so we should be OK.

I see. OK, this is covered.

Might be a good idea to reset "last key" here as well. No need to send 2nd release event later on.

Signature · 1 line
Dmitry
#10 lore raw

Am Dienstag, 5. Oktober 2010, 08:08:22 schrieb Dmitry Torokhov:

Quoted 4 lines
Quoted 2 lines

But what about the next opener? He'll get a completely spurious key release event, as the next key is pressed.

How does the opening of a device handle relate to a device state?

It doesn't.

Quoted 2 lines

Userspace should expect to see releases without presses (in case they weren't the first client that opened the device).

Yes, but based on sane timing. From the time stamps user space would conclude that the key had been pressed at an unknown time before open and released at the time the event indicates. Possibly it would compute that the key had been held for at least hours.

Regards
Oliver

maintainer
#11 lore raw
Quoted 8 lines · Oliver Neukum

Am Dienstag, 5. Oktober 2010, 08:08:22 schrieb Dmitry Torokhov:

Quoted 4 lines
Quoted 2 lines

But what about the next opener? He'll get a completely spurious key release event, as the next key is pressed.

How does the opening of a device handle relate to a device state?

It doesn't.

Quoted 8 lines
Quoted 2 lines

Userspace should expect to see releases without presses (in case they weren't the first client that opened the device).

Yes, but based on sane timing. From the time stamps user space would conclude that the key had been pressed at an unknown time before open and released at the time the event indicates. Possibly it would compute that the key had been held for at least hours.

I do not understand. If a client never seen the "press" event and only saw "release" event it can't make any assumptions about timing. Press could be a millisecond ago or an hour ago, it just does not know. And such scenario can easily happen if the client is second to open the device.

I think the only sane behavior for clients is to ignore release events for keys that they did not see "down" event for.

-
Dmitry

#12 lore raw

Am Dienstag, 5. Oktober 2010, 17:55:52 schrieb Dmitry Torokhov:

Quoted 11 lines
Quoted 5 lines

Yes, but based on sane timing. From the time stamps user space would conclude that the key had been pressed at an unknown time before open and released at the time the event indicates. Possibly it would compute that the key had been held for at least hours.

I do not understand. If a client never seen the "press" event and only saw "release" event it can't make any assumptions about timing. Press could be a millisecond ago or an hour ago, it just does not know. And such scenario can easily happen if the client is second to open the device.

As soon as you open a device you see key presses. If you see a release without a press, the press must have happened before you opened. So if you know when you opened and when a key is released, you'll have a lower limit on how long the key must have been held down.

Regards
Oliver

maintainer
#13 lore raw
Quoted 13 lines · Oliver Neukum

Am Dienstag, 5. Oktober 2010, 17:55:52 schrieb Dmitry Torokhov:

Quoted 11 lines
Quoted 5 lines

Yes, but based on sane timing. From the time stamps user space would conclude that the key had been pressed at an unknown time before open and released at the time the event indicates. Possibly it would compute that the key had been held for at least hours.

I do not understand. If a client never seen the "press" event and only saw "release" event it can't make any assumptions about timing. Press could be a millisecond ago or an hour ago, it just does not know. And such scenario can easily happen if the client is second to open the device.

Quoted 5 lines

As soon as you open a device you see key presses. If you see a release without a press, the press must have happened before you opened. So if you know when you opened and when a key is released, you'll have a lower limit on how long the key must have been held down.

Yes. I still do not see the usefulness of this data.

Signature · 1 line
Dmitry
#3 lore raw
In reply to Bastien Nocera
Quoted 2 lines · Bastien Nocera
Quoted 1 line · Dmitry Torokhov

Bastien,

...

Quoted 6 lines
Quoted 3 lines

I'll try
to get the driver in .37 but after that we should probably move it over to the new IR infrastructure...

I'm not sure what that would bring us, nor do I have any experience in using the ir-core. From what I understood, it still needed fleshing out.

There are a few things that still need fleshing out, but nothing really that should have any major impact on a potential port of this driver.

Off the top of my head, the main thing it would give you is the ability to upload your own keymap for the receiver. Then someone wanting to use more than 6 buttons or whatever it is might still be able to get the benefits of in-kernel decoding with everything coming through the input layer, rather than using lirc or the like.

Signature · 2 lines
Jarod Wilson
[email protected]
#4 lore raw
Quoted 8 lines · Jarod Wilson
Quoted 2 lines · Bastien Nocera
Quoted 1 line · Dmitry Torokhov

Bastien,

...

Quoted 4 lines
Quoted 3 lines

I'll try
to get the driver in .37 but after that we should probably move it over to the new IR infrastructure...

Quoted 8 lines
Quoted 2 lines

I'm not sure what that would bring us, nor do I have any experience in using the ir-core. From what I understood, it still needed fleshing out.

There are a few things that still need fleshing out, but nothing really that should have any major impact on a potential port of this driver.

Off the top of my head, the main thing it would give you is the ability to upload your own keymap for the receiver.

You could already change the keymap...

Quoted 2 lines

Then someone wanting to use more
than 6 buttons

But only for the 6 buttons supported.

Quoted 3 lines

or whatever it is might still be able to get the benefits
of in-kernel decoding with everything coming through the input layer, rather than using lirc or the like.

I see very little benefits myself (I mean, unless you're adamant that you want to use a remote that's not intended for that computer, but we already have lirc user-space driver for doing that), and it would remove metadata from the events, so we couldn't do "remote filtering" (each remote has a semi-random UID, which gets passed in with the events).

When the appleir patch was finally accepted (which means I need to get off my arse and do the changes Oliver mentioned), working on UID filtering is next on my list of TODOs.

Cheers

#5 lore raw
Quoted 12 lines · Bastien Nocera
Quoted 11 lines · Jarod Wilson
Quoted 2 lines · Bastien Nocera
Quoted 1 line · Dmitry Torokhov

Bastien,

...

Quoted 6 lines
Quoted 3 lines

I'll try
to get the driver in .37 but after that we should probably move it over to the new IR infrastructure...

I'm not sure what that would bring us, nor do I have any experience in using the ir-core. From what I understood, it still needed fleshing out.

Quoted 7 lines
Quoted 5 lines

There are a few things that still need fleshing out, but nothing really that should have any major impact on a potential port of this driver.

Off the top of my head, the main thing it would give you is the ability to upload your own keymap for the receiver.

You could already change the keymap...

You could change the mapping for the 6 buttons, but new scancode to keycode mappings wouldn't be possible. That's assuming the driver actually does raw IR decode -- the scancodes I see in the key tables in the driver definitely match decoded NEC that I get when using the Apple remote with another raw IR receiver (mceusb). Reading through the code though, it appears the IR signal is decoded in hardware and only the resulting scancodes are passed along... I wonder if it passes along scancodes for all NEC signals or if its doing filtering... I have sufficiently equipped Apple hardware of my own that I suppose I really ought to prod.

Quoted 5 lines
Quoted 2 lines

Then someone wanting to use more
than 6 buttons

But only for the 6 buttons supported.

Quoted 7 lines
Quoted 3 lines

or whatever it is might still be able to get the benefits
of in-kernel decoding with everything coming through the input layer, rather than using lirc or the like.

I see very little benefits myself (I mean, unless you're adamant that you want to use a remote that's not intended for that computer, but we already have lirc user-space driver for doing that),

I don't see why we shouldn't be able to do it in-kernel too, without the need for any userspace daemon. The bigger win though is probably de-duplication of keyup/keydown/timer logic. I had similar duplication in the imon driver (which is also scancode-based), and the code is smaller and cleaner after being adapted to use ir/rc-core functions.

Quoted 3 lines

and it would remove
metadata from the events, so we couldn't do "remote filtering" (each remote has a semi-random UID, which gets passed in with the events).

No it wouldn't. The lsb of the decoded NEC pulse train contains the ID, I'm able to see it just fine with other raw IR receivers and some experimental patches we're kicking around on linux-media.

Quoted 3 lines

When the appleir patch was finally accepted (which means I need to get off my arse and do the changes Oliver mentioned), working on UID filtering is next on my list of TODOs.

I've got an implementation here using the in-kernel NEC decoder, an Apple remote any an mceusb transceiver that works. Its not terribly *elegant*, but it does work. (Executive summary: if not doing pairing, zero out the pair ID and use the full 32-bit scancode with a default keytable that has 0x00 in the pair ID position. If doing pairing, pass that byte unmodified, and upload a keymap that matches).

Signature · 2 lines
Jarod Wilson
[email protected]