31 #include <linux/module.h>
37 #include <linux/slab.h>
38 #include <linux/sched.h>
40 #include <linux/sysctl.h>
44 #include <linux/input.h>
49 #define DRV_NAME "bf54x-keys"
50 #define TIME_SCALE 100
51 #define MAX_MULT (0xFF * TIME_SCALE)
54 static const u16 per_rows[] = {
66 static const u16 per_cols[] = {
91 struct input_dev *
input,
u16 keyident)
95 for (i = 0; i < input->keycodemax; i++)
96 if (bf54x_kpad->
keycode[i + input->keycodemax] == keyident)
101 static inline void bfin_keycodecpy(
unsigned short *
keycode,
102 const unsigned int *pdata_kc,
103 unsigned short keymapsize)
107 for (i = 0; i < keymapsize; i++) {
108 keycode[
i] = pdata_kc[
i] & 0xffff;
109 keycode[i + keymapsize] = pdata_kc[
i] >> 16;
113 static inline u16 bfin_kpad_get_prescale(
u32 timescale)
117 return ((((sclk / 1000) * timescale) / 1024) - 1);
125 static inline void bfin_kpad_clear_irq(
void)
131 static void bfin_kpad_timer(
unsigned long data)
134 struct bf54x_kpad *bf54x_kpad = platform_get_drvdata(pdev);
136 if (bfin_kpad_get_keypressed(bf54x_kpad)) {
143 input_report_key(bf54x_kpad->
input, bf54x_kpad->
lastkey, 0);
144 input_sync(bf54x_kpad->
input);
148 bfin_kpad_clear_irq();
155 struct bf54x_kpad *bf54x_kpad = platform_get_drvdata(pdev);
160 key = bfin_kpad_find_key(bf54x_kpad, input, rowcol);
162 input_report_key(input, key, 1);
165 if (bfin_kpad_get_keypressed(bf54x_kpad)) {
171 input_report_key(input, key, 0);
174 bfin_kpad_clear_irq();
182 struct bf54x_kpad *bf54x_kpad;
184 struct input_dev *
input;
188 dev_err(&pdev->
dev,
"no rows, cols or keymap from pdata\n");
198 bf54x_kpad = kzalloc(
sizeof(
struct bf54x_kpad),
GFP_KERNEL);
202 platform_set_drvdata(pdev, bf54x_kpad);
215 "invalid platform debounce/columndrive time\n");
234 dev_err(&pdev->
dev,
"requesting peripherals failed\n");
241 dev_err(&pdev->
dev,
"requesting peripherals failed\n");
247 if (bf54x_kpad->
irq < 0) {
255 dev_err(&pdev->
dev,
"unable to claim irq %d\n",
260 input = input_allocate_device();
268 input->name = pdev->
name;
269 input->phys =
"bf54x-keys/input0";
270 input->dev.parent = &pdev->
dev;
272 input_set_drvdata(input, bf54x_kpad);
275 input->id.vendor = 0x0001;
276 input->id.product = 0x0001;
277 input->id.version = 0x0100;
279 input->keycodesize =
sizeof(
unsigned short);
281 input->keycode = bf54x_kpad->
keycode;
291 for (i = 0; i < input->keycodemax; i++)
295 error = input_register_device(input);
297 dev_err(&pdev->
dev,
"unable to register input device\n");
318 input_free_device(input);
329 platform_set_drvdata(pdev,
NULL);
337 struct bf54x_kpad *bf54x_kpad = platform_get_drvdata(pdev);
342 input_unregister_device(bf54x_kpad->
input);
349 platform_set_drvdata(pdev,
NULL);
357 struct bf54x_kpad *bf54x_kpad = platform_get_drvdata(pdev);
363 if (device_may_wakeup(&pdev->
dev))
364 enable_irq_wake(bf54x_kpad->
irq);
371 struct bf54x_kpad *bf54x_kpad = platform_get_drvdata(pdev);
377 if (device_may_wakeup(&pdev->
dev))
378 disable_irq_wake(bf54x_kpad->
irq);
383 # define bfin_kpad_suspend NULL
384 # define bfin_kpad_resume NULL
392 .probe = bfin_kpad_probe,