1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * dm355evm_keys.c - support buttons and IR remote on DM355 EVM board
5 * Copyright (c) 2008 by David Brownell
7 #include <linux/kernel.h>
8 #include <linux/slab.h>
9 #include <linux/input.h>
10 #include <linux/input/sparse-keymap.h>
11 #include <linux/platform_device.h>
12 #include <linux/interrupt.h>
14 #include <linux/mfd/dm355evm_msp.h>
15 #include <linux/module.h>
19 * The MSP430 firmware on the DM355 EVM monitors on-board pushbuttons
20 * and an IR receptor used for the remote control. When any key is
21 * pressed, or its autorepeat kicks in, an event is sent. This driver
22 * read those events from the small (32 event) queue and reports them.
24 * Note that physically there can only be one of these devices.
26 * This driver was tested with firmware revision A4.
28 struct dm355evm_keys
{
29 struct input_dev
*input
;
33 /* These initial keycodes can be remapped */
34 static const struct key_entry dm355evm_keys
[] = {
36 * Pushbuttons on the EVM board ... note that the labels for these
37 * are SW10/SW11/etc on the PC board. The left/right orientation
38 * comes only from the firmware's documentation, and presumes the
39 * power connector is immediately in front of you and the IR sensor
40 * is to the right. (That is, rotate the board counter-clockwise
41 * by 90 degrees from the SW10/etc and "DM355 EVM" labels.)
43 { KE_KEY
, 0x00d8, { KEY_OK
} }, /* SW12 */
44 { KE_KEY
, 0x00b8, { KEY_UP
} }, /* SW13 */
45 { KE_KEY
, 0x00e8, { KEY_DOWN
} }, /* SW11 */
46 { KE_KEY
, 0x0078, { KEY_LEFT
} }, /* SW14 */
47 { KE_KEY
, 0x00f0, { KEY_RIGHT
} }, /* SW10 */
50 * IR buttons ... codes assigned to match the universal remote
51 * provided with the EVM (Philips PM4S) using DVD code 0020.
53 * These event codes match firmware documentation, but other
54 * remote controls could easily send more RC5-encoded events.
55 * The PM4S manual was used in several cases to help select
56 * a keycode reflecting the intended usage.
58 * RC5 codes are 14 bits, with two start bits (0x3 prefix)
59 * and a toggle bit (masked out below).
61 { KE_KEY
, 0x300c, { KEY_POWER
} }, /* NOTE: docs omit this */
62 { KE_KEY
, 0x3000, { KEY_NUMERIC_0
} },
63 { KE_KEY
, 0x3001, { KEY_NUMERIC_1
} },
64 { KE_KEY
, 0x3002, { KEY_NUMERIC_2
} },
65 { KE_KEY
, 0x3003, { KEY_NUMERIC_3
} },
66 { KE_KEY
, 0x3004, { KEY_NUMERIC_4
} },
67 { KE_KEY
, 0x3005, { KEY_NUMERIC_5
} },
68 { KE_KEY
, 0x3006, { KEY_NUMERIC_6
} },
69 { KE_KEY
, 0x3007, { KEY_NUMERIC_7
} },
70 { KE_KEY
, 0x3008, { KEY_NUMERIC_8
} },
71 { KE_KEY
, 0x3009, { KEY_NUMERIC_9
} },
72 { KE_KEY
, 0x3022, { KEY_ENTER
} },
73 { KE_KEY
, 0x30ec, { KEY_MODE
} }, /* "tv/vcr/..." */
74 { KE_KEY
, 0x300f, { KEY_SELECT
} }, /* "info" */
75 { KE_KEY
, 0x3020, { KEY_CHANNELUP
} }, /* "up" */
76 { KE_KEY
, 0x302e, { KEY_MENU
} }, /* "in/out" */
77 { KE_KEY
, 0x3011, { KEY_VOLUMEDOWN
} }, /* "left" */
78 { KE_KEY
, 0x300d, { KEY_MUTE
} }, /* "ok" */
79 { KE_KEY
, 0x3010, { KEY_VOLUMEUP
} }, /* "right" */
80 { KE_KEY
, 0x301e, { KEY_SUBTITLE
} }, /* "cc" */
81 { KE_KEY
, 0x3021, { KEY_CHANNELDOWN
} },/* "down" */
82 { KE_KEY
, 0x3022, { KEY_PREVIOUS
} },
83 { KE_KEY
, 0x3026, { KEY_SLEEP
} },
84 { KE_KEY
, 0x3172, { KEY_REWIND
} }, /* NOTE: docs wrongly say 0x30ca */
85 { KE_KEY
, 0x3175, { KEY_PLAY
} },
86 { KE_KEY
, 0x3174, { KEY_FASTFORWARD
} },
87 { KE_KEY
, 0x3177, { KEY_RECORD
} },
88 { KE_KEY
, 0x3176, { KEY_STOP
} },
89 { KE_KEY
, 0x3169, { KEY_PAUSE
} },
93 * Because we communicate with the MSP430 using I2C, and all I2C calls
94 * in Linux sleep, we use a threaded IRQ handler. The IRQ itself is
95 * active low, but we go through the GPIO controller so we can trigger
96 * on falling edges and not worry about enabling/disabling the IRQ in
97 * the keypress handling path.
99 static irqreturn_t
dm355evm_keys_irq(int irq
, void *_keys
)
101 static u16 last_event
;
102 struct dm355evm_keys
*keys
= _keys
;
103 const struct key_entry
*ke
;
104 unsigned int keycode
;
108 /* For simplicity we ignore INPUT_COUNT and just read
109 * events until we get the "queue empty" indicator.
110 * Reading INPUT_LOW decrements the count.
113 status
= dm355evm_msp_read(DM355EVM_MSP_INPUT_HIGH
);
115 dev_dbg(keys
->dev
, "input high err %d\n",
121 status
= dm355evm_msp_read(DM355EVM_MSP_INPUT_LOW
);
123 dev_dbg(keys
->dev
, "input low err %d\n",
131 /* Press and release a button: two events, same code.
132 * Press and hold (autorepeat), then release: N events
133 * (N > 2), same code. For RC5 buttons the toggle bits
134 * distinguish (for example) "1-autorepeat" from "1 1";
135 * but PCB buttons don't support that bit.
137 * So we must synthesize release events. We do that by
138 * mapping events to a press/release event pair; then
139 * to avoid adding extra events, skip the second event
142 if (event
== last_event
) {
148 /* ignore the RC5 toggle bit */
151 /* find the key, or report it as unknown */
152 ke
= sparse_keymap_entry_from_scancode(keys
->input
, event
);
153 keycode
= ke
? ke
->keycode
: KEY_UNKNOWN
;
155 "input event 0x%04x--> keycode %d\n",
158 /* report press + release */
159 input_report_key(keys
->input
, keycode
, 1);
160 input_sync(keys
->input
);
161 input_report_key(keys
->input
, keycode
, 0);
162 input_sync(keys
->input
);
168 /*----------------------------------------------------------------------*/
170 static int dm355evm_keys_probe(struct platform_device
*pdev
)
172 struct dm355evm_keys
*keys
;
173 struct input_dev
*input
;
177 keys
= devm_kzalloc(&pdev
->dev
, sizeof (*keys
), GFP_KERNEL
);
181 input
= devm_input_allocate_device(&pdev
->dev
);
185 keys
->dev
= &pdev
->dev
;
188 input
->name
= "DM355 EVM Controls";
189 input
->phys
= "dm355evm/input0";
191 input
->id
.bustype
= BUS_I2C
;
192 input
->id
.product
= 0x0355;
193 input
->id
.version
= dm355evm_msp_read(DM355EVM_MSP_FIRMREV
);
195 error
= sparse_keymap_setup(input
, dm355evm_keys
, NULL
);
199 /* REVISIT: flush the event queue? */
201 /* set up "threaded IRQ handler" */
202 irq
= platform_get_irq(pdev
, 0);
206 error
= devm_request_threaded_irq(&pdev
->dev
, irq
,
207 NULL
, dm355evm_keys_irq
,
208 IRQF_TRIGGER_FALLING
| IRQF_ONESHOT
,
209 dev_name(&pdev
->dev
), keys
);
214 error
= input_register_device(input
);
221 /* REVISIT: add suspend/resume when DaVinci supports it. The IRQ should
222 * be able to wake up the system. When device_may_wakeup(&pdev->dev), call
223 * enable_irq_wake() on suspend, and disable_irq_wake() on resume.
227 * I2C is used to talk to the MSP430, but this platform device is
228 * exposed by an MFD driver that manages I2C communications.
230 static struct platform_driver dm355evm_keys_driver
= {
231 .probe
= dm355evm_keys_probe
,
233 .name
= "dm355evm_keys",
236 module_platform_driver(dm355evm_keys_driver
);
238 MODULE_LICENSE("GPL");