Add 2.6.37 support
[openwrt/staging/lynxis/omap.git] / target / linux / xburst / patches-2.6.35 / 801-n526-lpc.patch
1 From f5978b5a9701fe1ddeffa0c5f73923fcaf31129e Mon Sep 17 00:00:00 2001
2 From: Lars-Peter Clausen <lars@metafoo.de>
3 Date: Wed, 12 May 2010 14:23:43 +0200
4 Subject: [PATCH] Add n526 lpc driver
5
6 ---
7 drivers/misc/Kconfig | 9 ++
8 drivers/misc/Makefile | 1 +
9 drivers/misc/n526-lpc.c | 237 +++++++++++++++++++++++++++++++++++++++++++++++
10 3 files changed, 247 insertions(+), 0 deletions(-)
11 create mode 100644 drivers/misc/n526-lpc.c
12
13 --- a/drivers/misc/Kconfig
14 +++ b/drivers/misc/Kconfig
15 @@ -361,6 +361,15 @@ config N516_LPC
16 help
17 N516 keyboard & power controller driver
18
19 +config N526_LPC
20 + tristate "N526 LPC934 coprocessor"
21 + depends on JZ4740_N526
22 + help
23 + If you say yes here you get support for the N526s NXP LPC934 coprocessor.
24 + It is used as a keyboard controllor and for power management.
25 +
26 + If you have a N526 you probably want to say Y here.
27 +
28 source "drivers/misc/c2port/Kconfig"
29 source "drivers/misc/eeprom/Kconfig"
30 source "drivers/misc/cb710/Kconfig"
31 --- a/drivers/misc/Makefile
32 +++ b/drivers/misc/Makefile
33 @@ -32,3 +32,4 @@ obj-y += eeprom/
34 obj-y += cb710/
35 obj-$(CONFIG_VMWARE_BALLOON) += vmware_balloon.o
36 obj-$(CONFIG_N516_LPC) += n516-lpc.o
37 +obj-$(CONFIG_N526_LPC) += n526-lpc.o
38 --- /dev/null
39 +++ b/drivers/misc/n526-lpc.c
40 @@ -0,0 +1,237 @@
41 +/*
42 + * Copyright (C) 2009, Lars-Peter Clausen <lars@metafoo.de>
43 + *
44 + * This program is free software; you can redistribute it and/or modify
45 + * it under the terms of the GNU General Public License version 2 as
46 + * published by the Free Software Foundation.
47 + *
48 + * You should have received a copy of the GNU General Public License along
49 + * with this program; if not, write to the Free Software Foundation, Inc.,
50 + * 675 Mass Ave, Cambridge, MA 02139, USA.
51 + *
52 + */
53 +
54 +#include <linux/kernel.h>
55 +#include <linux/module.h>
56 +#include <linux/i2c.h>
57 +#include <linux/input.h>
58 +#include <linux/irq.h>
59 +#include <linux/interrupt.h>
60 +
61 +#include <linux/workqueue.h>
62 +
63 +#include <asm/mach-jz4740/irq.h>
64 +#include <asm/mach-jz4740/gpio.h>
65 +
66 +struct n526_lpc {
67 + struct i2c_client *client;
68 + struct input_dev *input;
69 +
70 + struct work_struct work;
71 +};
72 +
73 +static const unsigned int n526_lpc_keymap[] = {
74 + [0x01] = KEY_PAGEUP,
75 + [0x02] = KEY_PAGEDOWN,
76 + [0x03] = KEY_VOLUMEUP,
77 + [0x04] = KEY_VOLUMEDOWN,
78 + [0x06] = KEY_1,
79 + [0x07] = KEY_Q,
80 + [0x08] = KEY_A,
81 + [0x09] = KEY_Z,
82 + [0x0a] = KEY_LEFTSHIFT,
83 + [0x0b] = KEY_2,
84 + [0x0c] = KEY_W,
85 + [0x0d] = KEY_S,
86 + [0x0e] = KEY_X,
87 + [0x0f] = KEY_REFRESH,
88 + [0x10] = KEY_3,
89 + [0x11] = KEY_E,
90 + [0x12] = KEY_D,
91 + [0x13] = KEY_C,
92 + [0x14] = KEY_DOCUMENTS,
93 + [0x15] = KEY_4,
94 + [0x16] = KEY_R,
95 + [0x17] = KEY_F,
96 + [0x18] = KEY_V,
97 + [0x19] = KEY_MUTE,
98 + [0x1a] = KEY_5,
99 + [0x1b] = KEY_T,
100 + [0x1c] = KEY_G,
101 + [0x1d] = KEY_B,
102 + [0x1e] = KEY_DELETE,
103 + [0x1f] = KEY_6,
104 + [0x20] = KEY_Y,
105 + [0x21] = KEY_H,
106 + [0x22] = KEY_N,
107 + [0x23] = KEY_SPACE,
108 + [0x24] = KEY_7,
109 + [0x25] = KEY_U,
110 + [0x26] = KEY_J,
111 + [0x27] = KEY_M,
112 +/* [0x28] = KEY_SYM, */
113 + [0x29] = KEY_8,
114 + [0x2a] = KEY_I,
115 + [0x2b] = KEY_K,
116 + [0x2c] = KEY_MENU,
117 + [0x2d] = KEY_LEFT,
118 + [0x2e] = KEY_9,
119 + [0x2f] = KEY_O,
120 + [0x30] = KEY_L,
121 + [0x31] = KEY_UP,
122 + [0x32] = KEY_DOWN,
123 + [0x33] = KEY_0,
124 + [0x34] = KEY_P,
125 + [0x35] = KEY_BACKSPACE,
126 + [0x36] = KEY_ENTER,
127 + [0x37] = KEY_RIGHT,
128 +};
129 +
130 +static void n526_lpc_irq_work(struct work_struct *work)
131 +{
132 + int ret;
133 + struct n526_lpc *n526_lpc = container_of(work, struct n526_lpc, work);
134 + struct i2c_client *client = n526_lpc->client;
135 + unsigned char raw_msg;
136 + struct i2c_msg msg = {client->addr, client->flags | I2C_M_RD, 1, &raw_msg};
137 + unsigned char keycode;
138 +
139 +
140 + ret = i2c_transfer(client->adapter, &msg, 1);
141 +
142 + if (ret != 1) {
143 + dev_err(&client->dev, "Failed to read lpc status\n");
144 + }
145 +
146 + keycode = raw_msg & 0x7f;
147 +
148 + if (keycode < ARRAY_SIZE(n526_lpc_keymap)) {
149 + input_report_key(n526_lpc->input, n526_lpc_keymap[keycode],
150 + !(raw_msg & 0x80));
151 + input_sync(n526_lpc->input);
152 + }
153 +}
154 +
155 +static irqreturn_t n526_lpc_irq(int irq, void *dev_id)
156 +{
157 + struct n526_lpc *n526_lpc = dev_id;
158 +
159 + schedule_work(&n526_lpc->work);
160 + return IRQ_HANDLED;
161 +}
162 +
163 +static int __devinit n526_lpc_probe(struct i2c_client *client,
164 + const struct i2c_device_id *id)
165 +{
166 + int ret;
167 + size_t i;
168 + struct n526_lpc *n526_lpc;
169 + struct input_dev *input;
170 +
171 + n526_lpc = kmalloc(sizeof(*n526_lpc), GFP_KERNEL);
172 +
173 + if (!n526_lpc) {
174 + dev_err(&client->dev, "Failed to allocate device structure\n");
175 + return -ENOMEM;
176 + }
177 +
178 + input = input_allocate_device();
179 + if (!input) {
180 + dev_err(&client->dev, "Failed to allocate input device\n");
181 + ret = -ENOMEM;
182 + goto err_free;
183 + }
184 +
185 + input->name = "n526-keys";
186 + input->phys = "n526-keys/input0";
187 + input->dev.parent = &client->dev;
188 + input->id.bustype = BUS_I2C;
189 + input->id.vendor = 0x0001;
190 + input->id.product = 0x0001;
191 + input->id.version = 0x0001;
192 +
193 + __set_bit(EV_KEY, input->evbit);
194 +
195 + for (i = 0; i < ARRAY_SIZE(n526_lpc_keymap); ++i) {
196 + if (n526_lpc_keymap[i] != 0)
197 + __set_bit(n526_lpc_keymap[i], input->keybit);
198 + }
199 +
200 + ret = input_register_device(input);
201 +
202 + if (ret) {
203 + dev_err(&client->dev, "Failed to register input device: %d\n", ret);
204 + goto err_free_input;
205 + }
206 +
207 + n526_lpc->client = client;
208 + n526_lpc->input = input;
209 + INIT_WORK(&n526_lpc->work, n526_lpc_irq_work);
210 +
211 + ret = request_irq(client->irq, n526_lpc_irq, IRQF_TRIGGER_FALLING,
212 + "n526-lpc", n526_lpc);
213 + if (ret) {
214 + dev_err(&client->dev, "Failed to request irq: %d\n", ret);
215 + goto err_unregister_input;
216 + }
217 +
218 + i2c_set_clientdata(client, n526_lpc);
219 +
220 + return 0;
221 +
222 +err_unregister_input:
223 + input_unregister_device(input);
224 +err_free_input:
225 + input_free_device(input);
226 +err_free:
227 + kfree(n526_lpc);
228 +
229 + return ret;
230 +}
231 +
232 +static int n526_lpc_remove(struct i2c_client *client)
233 +{
234 + struct n526_lpc *n526_lpc = i2c_get_clientdata(client);
235 +
236 + free_irq(client->irq, n526_lpc);
237 +
238 + i2c_set_clientdata(client, NULL);
239 + input_unregister_device(n526_lpc->input);
240 + input_free_device(n526_lpc->input);
241 + kfree(n526_lpc);
242 +
243 + return 0;
244 +}
245 +
246 +static const struct i2c_device_id n526_lpc_id[] = {
247 + { "n526-lpc", 0 },
248 + { }
249 +};
250 +MODULE_DEVICE_TABLE(i2c, n526_lpc_id);
251 +
252 +static struct i2c_driver n526_lpc_driver = {
253 + .driver = {
254 + .name = "n526-lpc",
255 + .owner = THIS_MODULE,
256 + },
257 + .probe = n526_lpc_probe,
258 + .remove = n526_lpc_remove,
259 + .id_table = n526_lpc_id,
260 +};
261 +
262 +static int __init n526_lpc_init(void)
263 +{
264 + return i2c_add_driver(&n526_lpc_driver);
265 +}
266 +module_init(n526_lpc_init);
267 +
268 +static void __exit n526_lpc_exit(void)
269 +{
270 + i2c_del_driver(&n526_lpc_driver);
271 +}
272 +module_exit(n526_lpc_exit);
273 +
274 +MODULE_LICENSE("GPL");
275 +MODULE_AUTHOR("Lars-Peter Clausen");
276 +MODULE_DESCRIPTION("n526 keypad driver");
277 +MODULE_ALIAS("i2c:n526-keys");