Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with IR NEC protocol #45

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions drivers/media/rc/gpio-ir-recv.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct gpio_rc_dev {
struct rc_dev *rcdev;
int gpio_nr;
bool active_low;
struct timer_list flush_timer;
};

#ifdef CONFIG_OF
Expand Down Expand Up @@ -93,12 +94,26 @@ static irqreturn_t gpio_ir_recv_irq(int irq, void *dev_id)
if (rc < 0)
goto err_get_value;

mod_timer(&gpio_dev->flush_timer,
jiffies + nsecs_to_jiffies(gpio_dev->rcdev->timeout));

ir_raw_event_handle(gpio_dev->rcdev);

err_get_value:
return IRQ_HANDLED;
}

static void flush_timer(unsigned long arg)
{
struct gpio_rc_dev *gpio_dev = (struct gpio_rc_dev *)arg;
DEFINE_IR_RAW_EVENT(ev);

ev.timeout = true;
ev.duration = gpio_dev->rcdev->timeout;
ir_raw_event_store(gpio_dev->rcdev, &ev);
ir_raw_event_handle(gpio_dev->rcdev);
}

static int gpio_ir_recv_probe(struct platform_device *pdev)
{
struct gpio_rc_dev *gpio_dev;
Expand Down Expand Up @@ -144,6 +159,9 @@ static int gpio_ir_recv_probe(struct platform_device *pdev)
rcdev->input_id.version = 0x0100;
rcdev->dev.parent = &pdev->dev;
rcdev->driver_name = GPIO_IR_DRIVER_NAME;
rcdev->min_timeout = 1;
rcdev->timeout = IR_DEFAULT_TIMEOUT;
rcdev->max_timeout = 10 * IR_DEFAULT_TIMEOUT;
if (pdata->allowed_protos)
rcdev->allowed_protocols = pdata->allowed_protos;
else
Expand All @@ -154,6 +172,9 @@ static int gpio_ir_recv_probe(struct platform_device *pdev)
gpio_dev->gpio_nr = pdata->gpio_nr;
gpio_dev->active_low = pdata->active_low;

setup_timer(&gpio_dev->flush_timer, flush_timer,
(unsigned long)gpio_dev);

rc = gpio_request(pdata->gpio_nr, "gpio-ir-recv");
if (rc < 0)
goto err_gpio_request;
Expand Down Expand Up @@ -196,6 +217,7 @@ static int gpio_ir_recv_remove(struct platform_device *pdev)
struct gpio_rc_dev *gpio_dev = platform_get_drvdata(pdev);

free_irq(gpio_to_irq(gpio_dev->gpio_nr), gpio_dev);
del_timer_sync(&gpio_dev->flush_timer);
rc_unregister_device(gpio_dev->rcdev);
gpio_free(gpio_dev->gpio_nr);
kfree(gpio_dev);
Expand Down
5 changes: 4 additions & 1 deletion drivers/media/rc/ir-nec-decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,10 @@ static int ir_nec_decode(struct rc_dev *dev, struct ir_raw_event ev)
if (send_32bits) {
/* NEC transport, but modified protocol, used by at
* least Apple and TiVo remotes */
scancode = data->bits;
scancode = not_address << 24 |
address << 16 |
not_command << 8 |
command;
IR_dprintk(1, "NEC (modified) scancode 0x%08x\n", scancode);
} else if ((address ^ not_address) != 0xff) {
/* Extended NEC */
Expand Down
86 changes: 43 additions & 43 deletions drivers/media/rc/keymaps/rc-tivo.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,62 +15,62 @@
* Initial mapping is for the TiVo remote included in the Nero LiquidTV bundle,
* which also ships with a TiVo-branded IR transceiver, supported by the mceusb
* driver. Note that the remote uses an NEC-ish protocol, but instead of having
* a command/not_command pair, it has a vendor ID of 0xa10c, but some keys, the
* a command/not_command pair, it has a vendor ID of 0x3085, but some keys, the
* NEC extended checksums do pass, so the table presently has the intended
* values and the checksum-passed versions for those keys.
*/
static struct rc_map_table tivo[] = {
{ 0xa10c900f, KEY_MEDIA }, /* TiVo Button */
{ 0xa10c0807, KEY_POWER2 }, /* TV Power */
{ 0xa10c8807, KEY_TV }, /* Live TV/Swap */
{ 0xa10c2c03, KEY_VIDEO_NEXT }, /* TV Input */
{ 0xa10cc807, KEY_INFO },
{ 0xa10cfa05, KEY_CYCLEWINDOWS }, /* Window */
{ 0x3085f009, KEY_MEDIA }, /* TiVo Button */
{ 0x3085e010, KEY_POWER2 }, /* TV Power */
{ 0x3085e011, KEY_TV }, /* Live TV/Swap */
{ 0x3085c034, KEY_VIDEO_NEXT }, /* TV Input */
{ 0x3085e013, KEY_INFO },
{ 0x3085a05f, KEY_CYCLEWINDOWS }, /* Window */
{ 0x0085305f, KEY_CYCLEWINDOWS },
{ 0xa10c6c03, KEY_EPG }, /* Guide */
{ 0x3085c036, KEY_EPG }, /* Guide */

{ 0xa10c2807, KEY_UP },
{ 0xa10c6807, KEY_DOWN },
{ 0xa10ce807, KEY_LEFT },
{ 0xa10ca807, KEY_RIGHT },
{ 0x3085e014, KEY_UP },
{ 0x3085e016, KEY_DOWN },
{ 0x3085e017, KEY_LEFT },
{ 0x3085e015, KEY_RIGHT },

{ 0xa10c1807, KEY_SCROLLDOWN }, /* Red Thumbs Down */
{ 0xa10c9807, KEY_SELECT },
{ 0xa10c5807, KEY_SCROLLUP }, /* Green Thumbs Up */
{ 0x3085e018, KEY_SCROLLDOWN }, /* Red Thumbs Down */
{ 0x3085e019, KEY_SELECT },
{ 0x3085e01a, KEY_SCROLLUP }, /* Green Thumbs Up */

{ 0xa10c3807, KEY_VOLUMEUP },
{ 0xa10cb807, KEY_VOLUMEDOWN },
{ 0xa10cd807, KEY_MUTE },
{ 0xa10c040b, KEY_RECORD },
{ 0xa10c7807, KEY_CHANNELUP },
{ 0xa10cf807, KEY_CHANNELDOWN },
{ 0x3085e01c, KEY_VOLUMEUP },
{ 0x3085e01d, KEY_VOLUMEDOWN },
{ 0x3085e01b, KEY_MUTE },
{ 0x3085d020, KEY_RECORD },
{ 0x3085e01e, KEY_CHANNELUP },
{ 0x3085e01f, KEY_CHANNELDOWN },
{ 0x0085301f, KEY_CHANNELDOWN },

{ 0xa10c840b, KEY_PLAY },
{ 0xa10cc40b, KEY_PAUSE },
{ 0xa10ca40b, KEY_SLOW },
{ 0xa10c440b, KEY_REWIND },
{ 0xa10c240b, KEY_FASTFORWARD },
{ 0xa10c640b, KEY_PREVIOUS },
{ 0xa10ce40b, KEY_NEXT }, /* ->| */
{ 0x3085d021, KEY_PLAY },
{ 0x3085d023, KEY_PAUSE },
{ 0x3085d025, KEY_SLOW },
{ 0x3085d022, KEY_REWIND },
{ 0x3085d024, KEY_FASTFORWARD },
{ 0x3085d026, KEY_PREVIOUS },
{ 0x3085d027, KEY_NEXT }, /* ->| */

{ 0xa10c220d, KEY_ZOOM }, /* Aspect */
{ 0xa10c120d, KEY_STOP },
{ 0xa10c520d, KEY_DVD }, /* DVD Menu */
{ 0x3085b044, KEY_ZOOM }, /* Aspect */
{ 0x3085b048, KEY_STOP },
{ 0x3085b04a, KEY_DVD }, /* DVD Menu */

{ 0xa10c140b, KEY_NUMERIC_1 },
{ 0xa10c940b, KEY_NUMERIC_2 },
{ 0xa10c540b, KEY_NUMERIC_3 },
{ 0xa10cd40b, KEY_NUMERIC_4 },
{ 0xa10c340b, KEY_NUMERIC_5 },
{ 0xa10cb40b, KEY_NUMERIC_6 },
{ 0xa10c740b, KEY_NUMERIC_7 },
{ 0xa10cf40b, KEY_NUMERIC_8 },
{ 0x3085d028, KEY_NUMERIC_1 },
{ 0x3085d029, KEY_NUMERIC_2 },
{ 0x3085d02a, KEY_NUMERIC_3 },
{ 0x3085d02b, KEY_NUMERIC_4 },
{ 0x3085d02c, KEY_NUMERIC_5 },
{ 0x3085d02d, KEY_NUMERIC_6 },
{ 0x3085d02e, KEY_NUMERIC_7 },
{ 0x3085d02f, KEY_NUMERIC_8 },
{ 0x0085302f, KEY_NUMERIC_8 },
{ 0xa10c0c03, KEY_NUMERIC_9 },
{ 0xa10c8c03, KEY_NUMERIC_0 },
{ 0xa10ccc03, KEY_ENTER },
{ 0xa10c4c03, KEY_CLEAR },
{ 0x3085c030, KEY_NUMERIC_9 },
{ 0x3085c031, KEY_NUMERIC_0 },
{ 0x3085c033, KEY_ENTER },
{ 0x3085c032, KEY_CLEAR },
};

static struct rc_map_list tivo_map = {
Expand Down
1 change: 1 addition & 0 deletions include/media/rc-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ static inline void init_ir_raw_event(struct ir_raw_event *ev)
memset(ev, 0, sizeof(*ev));
}

#define IR_DEFAULT_TIMEOUT MS_TO_NS(125)
#define IR_MAX_DURATION 500000000 /* 500 ms */
#define US_TO_NS(usec) ((usec) * 1000)
#define MS_TO_US(msec) ((msec) * 1000)
Expand Down