staging: nvec: convert to use platform register and mfdcells
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / nvec / nvec_kbd.c
blob347a38c468747d4ad61b9fcbd07b73c4b2ec6eb8
1 #include <linux/slab.h>
2 #include <linux/input.h>
3 #include <linux/delay.h>
4 #include <linux/platform_device.h>
5 #include "nvec-keytable.h"
6 #include "nvec.h"
8 #define ACK_KBD_EVENT {'\x05', '\xed', '\x01'}
10 static unsigned char keycodes[ARRAY_SIZE(code_tab_102us)
11 + ARRAY_SIZE(extcode_tab_us102)];
13 struct nvec_keys {
14 struct input_dev *input;
15 struct notifier_block notifier;
16 struct nvec_chip *nvec;
19 static struct nvec_keys keys_dev;
21 static int nvec_keys_notifier(struct notifier_block *nb,
22 unsigned long event_type, void *data)
24 int code, state;
25 unsigned char *msg = (unsigned char *)data;
27 if (event_type == NVEC_KB_EVT) {
28 nvec_size _size = (msg[0] & (3 << 5)) >> 5;
30 /* power on/off button */
31 if (_size == NVEC_VAR_SIZE)
32 return NOTIFY_STOP;
34 if (_size == NVEC_3BYTES)
35 msg++;
37 code = msg[1] & 0x7f;
38 state = msg[1] & 0x80;
40 input_report_key(keys_dev.input, code_tabs[_size][code], !state);
41 input_sync(keys_dev.input);
43 return NOTIFY_STOP;
46 return NOTIFY_DONE;
49 static int nvec_kbd_event(struct input_dev *dev, unsigned int type,
50 unsigned int code, int value)
52 unsigned char buf[] = ACK_KBD_EVENT;
53 struct nvec_chip *nvec = keys_dev.nvec;
55 if (type == EV_REP)
56 return 0;
58 if (type != EV_LED)
59 return -1;
61 if (code != LED_CAPSL)
62 return -1;
64 buf[2] = !!value;
65 nvec_write_async(nvec, buf, sizeof(buf));
67 return 0;
70 static int __devinit nvec_kbd_probe(struct platform_device *pdev)
72 struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent);
73 int i, j, err;
74 struct input_dev *idev;
76 j = 0;
78 for (i = 0; i < ARRAY_SIZE(code_tab_102us); ++i)
79 keycodes[j++] = code_tab_102us[i];
81 for (i = 0; i < ARRAY_SIZE(extcode_tab_us102); ++i)
82 keycodes[j++] = extcode_tab_us102[i];
84 idev = input_allocate_device();
85 idev->name = "Tegra nvec keyboard";
86 idev->phys = "i2c3_slave/nvec";
87 idev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP) | BIT_MASK(EV_LED);
88 idev->ledbit[0] = BIT_MASK(LED_CAPSL);
89 idev->event = nvec_kbd_event;
90 idev->keycode = keycodes;
91 idev->keycodesize = sizeof(unsigned char);
92 idev->keycodemax = ARRAY_SIZE(keycodes);
94 for (i = 0; i < ARRAY_SIZE(keycodes); ++i)
95 set_bit(keycodes[i], idev->keybit);
97 clear_bit(0, idev->keybit);
98 err = input_register_device(idev);
99 if (err)
100 goto fail;
102 keys_dev.input = idev;
103 keys_dev.notifier.notifier_call = nvec_keys_notifier;
104 keys_dev.nvec = nvec;
105 nvec_register_notifier(nvec, &keys_dev.notifier, 0);
107 /* Enable keyboard */
108 nvec_write_async(nvec, "\x05\xf4", 2);
110 /* keyboard reset? */
111 nvec_write_async(nvec, "\x05\x03\x01\x01", 4);
112 nvec_write_async(nvec, "\x05\x04\x01", 3);
113 nvec_write_async(nvec, "\x06\x01\xff\x03", 4);
114 /* FIXME
115 wait until keyboard reset is finished
116 or until we have a sync write */
117 mdelay(1000);
119 return 0;
121 fail:
122 input_free_device(idev);
123 return err;
126 static struct platform_driver nvec_kbd_driver = {
127 .probe = nvec_kbd_probe,
128 .driver = {
129 .name = "nvec-kbd",
130 .owner = THIS_MODULE,
134 static int __init nvec_kbd_init(void)
136 return platform_driver_register(&nvec_kbd_driver);
139 module_init(nvec_kbd_init);