2 * nvec_kbd: keyboard driver for a NVIDIA compliant embedded controller
4 * Copyright (C) 2011 The AC100 Kernel Team <ac100@lists.launchpad.net>
6 * Authors: Pierre-Hugues Husson <phhusson@free.fr>
7 * Marc Dietrich <marvin24@gmx.de>
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file "COPYING" in the main directory of this archive
15 #include <linux/module.h>
16 #include <linux/slab.h>
17 #include <linux/input.h>
18 #include <linux/delay.h>
19 #include <linux/platform_device.h>
21 #include "nvec-keytable.h"
24 #define ACK_KBD_EVENT {'\x05', '\xed', '\x01'}
26 static const char led_on
[3] = "\x05\xed\x07";
27 static const char led_off
[3] = "\x05\xed\x00";
28 static unsigned char keycodes
[ARRAY_SIZE(code_tab_102us
)
29 + ARRAY_SIZE(extcode_tab_us102
)];
32 struct input_dev
*input
;
33 struct notifier_block notifier
;
34 struct nvec_chip
*nvec
;
38 static struct nvec_keys keys_dev
;
40 static void nvec_kbd_toggle_led(void)
42 keys_dev
.caps_lock
= !keys_dev
.caps_lock
;
44 if (keys_dev
.caps_lock
)
45 nvec_write_async(keys_dev
.nvec
, led_on
, sizeof(led_on
));
47 nvec_write_async(keys_dev
.nvec
, led_off
, sizeof(led_off
));
50 static int nvec_keys_notifier(struct notifier_block
*nb
,
51 unsigned long event_type
, void *data
)
54 unsigned char *msg
= (unsigned char *)data
;
56 if (event_type
== NVEC_KB_EVT
) {
57 int _size
= (msg
[0] & (3 << 5)) >> 5;
59 /* power on/off button */
60 if (_size
== NVEC_VAR_SIZE
)
63 if (_size
== NVEC_3BYTES
)
67 state
= msg
[1] & 0x80;
69 if (code_tabs
[_size
][code
] == KEY_CAPSLOCK
&& state
)
70 nvec_kbd_toggle_led();
72 input_report_key(keys_dev
.input
, code_tabs
[_size
][code
],
74 input_sync(keys_dev
.input
);
82 static int nvec_kbd_event(struct input_dev
*dev
, unsigned int type
,
83 unsigned int code
, int value
)
85 unsigned char buf
[] = ACK_KBD_EVENT
;
86 struct nvec_chip
*nvec
= keys_dev
.nvec
;
94 if (code
!= LED_CAPSL
)
98 nvec_write_async(nvec
, buf
, sizeof(buf
));
103 static int __devinit
nvec_kbd_probe(struct platform_device
*pdev
)
105 struct nvec_chip
*nvec
= dev_get_drvdata(pdev
->dev
.parent
);
107 struct input_dev
*idev
;
111 for (i
= 0; i
< ARRAY_SIZE(code_tab_102us
); ++i
)
112 keycodes
[j
++] = code_tab_102us
[i
];
114 for (i
= 0; i
< ARRAY_SIZE(extcode_tab_us102
); ++i
)
115 keycodes
[j
++] = extcode_tab_us102
[i
];
117 idev
= input_allocate_device();
118 idev
->name
= "nvec keyboard";
120 idev
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_REP
) | BIT_MASK(EV_LED
);
121 idev
->ledbit
[0] = BIT_MASK(LED_CAPSL
);
122 idev
->event
= nvec_kbd_event
;
123 idev
->keycode
= keycodes
;
124 idev
->keycodesize
= sizeof(unsigned char);
125 idev
->keycodemax
= ARRAY_SIZE(keycodes
);
127 for (i
= 0; i
< ARRAY_SIZE(keycodes
); ++i
)
128 set_bit(keycodes
[i
], idev
->keybit
);
130 clear_bit(0, idev
->keybit
);
131 err
= input_register_device(idev
);
135 keys_dev
.input
= idev
;
136 keys_dev
.notifier
.notifier_call
= nvec_keys_notifier
;
137 keys_dev
.nvec
= nvec
;
138 nvec_register_notifier(nvec
, &keys_dev
.notifier
, 0);
140 /* Enable keyboard */
141 nvec_write_async(nvec
, "\x05\xf4", 2);
143 /* keyboard reset? */
144 nvec_write_async(nvec
, "\x05\x03\x01\x01", 4);
145 nvec_write_async(nvec
, "\x05\x04\x01", 3);
146 nvec_write_async(nvec
, "\x06\x01\xff\x03", 4);
148 wait until keyboard reset is finished
149 or until we have a sync write */
152 /* Disable caps lock LED */
153 nvec_write_async(nvec
, led_off
, sizeof(led_off
));
158 input_free_device(idev
);
162 static struct platform_driver nvec_kbd_driver
= {
163 .probe
= nvec_kbd_probe
,
166 .owner
= THIS_MODULE
,
170 static int __init
nvec_kbd_init(void)
172 return platform_driver_register(&nvec_kbd_driver
);
175 module_init(nvec_kbd_init
);
177 MODULE_AUTHOR("Marc Dietrich <marvin24@gmx.de>");
178 MODULE_DESCRIPTION("NVEC keyboard driver");
179 MODULE_LICENSE("GPL");