1 #include <linux/slab.h>
2 #include <linux/input.h>
3 #include <linux/delay.h>
4 #include "nvec-keytable.h"
7 #define ACK_KBD_EVENT {'\x05','\xed','\x01'}
9 static unsigned char keycodes
[ARRAY_SIZE(code_tab_102us
)
10 + ARRAY_SIZE(extcode_tab_us102
)];
13 struct input_dev
*input
;
14 struct notifier_block notifier
;
15 struct nvec_chip
*nvec
;
18 static struct nvec_keys keys_dev
;
20 static int nvec_keys_notifier(struct notifier_block
*nb
,
21 unsigned long event_type
, void *data
)
24 unsigned char *msg
= (unsigned char *)data
;
26 if (event_type
== NVEC_KB_EVT
) {
27 nvec_size _size
= (msg
[0] & (3 << 5)) >> 5;
29 /* power on/off button */
30 if(_size
== NVEC_VAR_SIZE
)
33 if(_size
== NVEC_3BYTES
)
37 state
= msg
[1] & 0x80;
39 input_report_key(keys_dev
.input
, code_tabs
[_size
][code
], !state
);
40 input_sync(keys_dev
.input
);
48 static int nvec_kbd_event(struct input_dev
*dev
, unsigned int type
,
49 unsigned int code
, int value
)
51 unsigned char buf
[] = ACK_KBD_EVENT
;
52 struct nvec_chip
*nvec
= keys_dev
.nvec
;
64 nvec_write_async(nvec
, buf
, sizeof(buf
));
69 int __init
nvec_kbd_init(struct nvec_chip
*nvec
)
72 struct input_dev
*idev
;
76 for(i
= 0; i
< ARRAY_SIZE(code_tab_102us
); ++i
)
77 keycodes
[j
++] = code_tab_102us
[i
];
79 for(i
= 0; i
< ARRAY_SIZE(extcode_tab_us102
); ++i
)
80 keycodes
[j
++]=extcode_tab_us102
[i
];
82 idev
= input_allocate_device();
83 idev
->name
= "Tegra nvec keyboard";
84 idev
->phys
= "i2c3_slave/nvec";
85 idev
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_REP
) | BIT_MASK(EV_LED
);
86 idev
->ledbit
[0] = BIT_MASK(LED_CAPSL
);
87 idev
->event
= nvec_kbd_event
;
88 idev
->keycode
= keycodes
;
89 idev
->keycodesize
= sizeof(unsigned char);
90 idev
->keycodemax
= ARRAY_SIZE(keycodes
);
92 for( i
= 0; i
< ARRAY_SIZE(keycodes
); ++i
)
93 set_bit(keycodes
[i
], idev
->keybit
);
95 clear_bit(0, idev
->keybit
);
96 err
= input_register_device(idev
);
100 keys_dev
.input
= idev
;
101 keys_dev
.notifier
.notifier_call
= nvec_keys_notifier
;
102 keys_dev
.nvec
= nvec
;
103 nvec_register_notifier(nvec
, &keys_dev
.notifier
, 0);
105 /* Enable keyboard */
106 nvec_write_async(nvec
, "\x05\xf4", 2);
108 /* keyboard reset? */
109 nvec_write_async(nvec
, "\x05\x03\x01\x01", 4);
110 nvec_write_async(nvec
, "\x05\x04\x01", 3);
111 nvec_write_async(nvec
, "\x06\x01\xff\x03", 4);
113 wait until keyboard reset is finished
114 or until we have a sync write */
120 input_free_device(idev
);