[xburst] Add 2.6.37 support
[openwrt/svn-archive/archive.git] / target / linux / xburst / patches-2.6.37 / 801-n526-lpc.patch
1 From 3959d6b8837faf00c7902c5537de2a2eba3c1b7e 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 5/5] Add n526 lpc driver
5
6 ---
7 drivers/misc/Kconfig | 9 ++
8 drivers/misc/Makefile | 1 +
9 drivers/misc/n526-lpc.c | 238 +++++++++++++++++++++++++++++++++++++++++++++++
10 3 files changed, 248 insertions(+), 0 deletions(-)
11 create mode 100644 drivers/misc/n526-lpc.c
12
13 --- a/drivers/misc/Kconfig
14 +++ b/drivers/misc/Kconfig
15 @@ -460,6 +460,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 @@ -43,3 +43,4 @@ obj-$(CONFIG_PCH_PHUB) += pch_phub.o
34 obj-y += ti-st/
35 obj-$(CONFIG_AB8500_PWM) += ab8500-pwm.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,238 @@
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 +#include <linux/slab.h>
61 +
62 +#include <linux/workqueue.h>
63 +
64 +#include <asm/mach-jz4740/irq.h>
65 +#include <asm/mach-jz4740/gpio.h>
66 +
67 +struct n526_lpc {
68 + struct i2c_client *client;
69 + struct input_dev *input;
70 +
71 + struct work_struct work;
72 +};
73 +
74 +static const unsigned int n526_lpc_keymap[] = {
75 + [0x01] = KEY_PAGEUP,
76 + [0x02] = KEY_PAGEDOWN,
77 + [0x03] = KEY_VOLUMEUP,
78 + [0x04] = KEY_VOLUMEDOWN,
79 + [0x06] = KEY_1,
80 + [0x07] = KEY_Q,
81 + [0x08] = KEY_A,
82 + [0x09] = KEY_Z,
83 + [0x0a] = KEY_LEFTSHIFT,
84 + [0x0b] = KEY_2,
85 + [0x0c] = KEY_W,
86 + [0x0d] = KEY_S,
87 + [0x0e] = KEY_X,
88 + [0x0f] = KEY_REFRESH,
89 + [0x10] = KEY_3,
90 + [0x11] = KEY_E,
91 + [0x12] = KEY_D,
92 + [0x13] = KEY_C,
93 + [0x14] = KEY_DOCUMENTS,
94 + [0x15] = KEY_4,
95 + [0x16] = KEY_R,
96 + [0x17] = KEY_F,
97 + [0x18] = KEY_V,
98 + [0x19] = KEY_MUTE,
99 + [0x1a] = KEY_5,
100 + [0x1b] = KEY_T,
101 + [0x1c] = KEY_G,
102 + [0x1d] = KEY_B,
103 + [0x1e] = KEY_DELETE,
104 + [0x1f] = KEY_6,
105 + [0x20] = KEY_Y,
106 + [0x21] = KEY_H,
107 + [0x22] = KEY_N,
108 + [0x23] = KEY_SPACE,
109 + [0x24] = KEY_7,
110 + [0x25] = KEY_U,
111 + [0x26] = KEY_J,
112 + [0x27] = KEY_M,
113 +/* [0x28] = KEY_SYM, */
114 + [0x29] = KEY_8,
115 + [0x2a] = KEY_I,
116 + [0x2b] = KEY_K,
117 + [0x2c] = KEY_MENU,
118 + [0x2d] = KEY_LEFT,
119 + [0x2e] = KEY_9,
120 + [0x2f] = KEY_O,
121 + [0x30] = KEY_L,
122 + [0x31] = KEY_UP,
123 + [0x32] = KEY_DOWN,
124 + [0x33] = KEY_0,
125 + [0x34] = KEY_P,
126 + [0x35] = KEY_BACKSPACE,
127 + [0x36] = KEY_ENTER,
128 + [0x37] = KEY_RIGHT,
129 +};
130 +
131 +static void n526_lpc_irq_work(struct work_struct *work)
132 +{
133 + int ret;
134 + struct n526_lpc *n526_lpc = container_of(work, struct n526_lpc, work);
135 + struct i2c_client *client = n526_lpc->client;
136 + unsigned char raw_msg;
137 + struct i2c_msg msg = {client->addr, client->flags | I2C_M_RD, 1, &raw_msg};
138 + unsigned char keycode;
139 +
140 +
141 + ret = i2c_transfer(client->adapter, &msg, 1);
142 +
143 + if (ret != 1) {
144 + dev_err(&client->dev, "Failed to read lpc status\n");
145 + }
146 +
147 + keycode = raw_msg & 0x7f;
148 +
149 + if (keycode < ARRAY_SIZE(n526_lpc_keymap)) {
150 + input_report_key(n526_lpc->input, n526_lpc_keymap[keycode],
151 + !(raw_msg & 0x80));
152 + input_sync(n526_lpc->input);
153 + }
154 +}
155 +
156 +static irqreturn_t n526_lpc_irq(int irq, void *dev_id)
157 +{
158 + struct n526_lpc *n526_lpc = dev_id;
159 +
160 + schedule_work(&n526_lpc->work);
161 + return IRQ_HANDLED;
162 +}
163 +
164 +static int __devinit n526_lpc_probe(struct i2c_client *client,
165 + const struct i2c_device_id *id)
166 +{
167 + int ret;
168 + size_t i;
169 + struct n526_lpc *n526_lpc;
170 + struct input_dev *input;
171 +
172 + n526_lpc = kmalloc(sizeof(*n526_lpc), GFP_KERNEL);
173 +
174 + if (!n526_lpc) {
175 + dev_err(&client->dev, "Failed to allocate device structure\n");
176 + return -ENOMEM;
177 + }
178 +
179 + input = input_allocate_device();
180 + if (!input) {
181 + dev_err(&client->dev, "Failed to allocate input device\n");
182 + ret = -ENOMEM;
183 + goto err_free;
184 + }
185 +
186 + input->name = "n526-keys";
187 + input->phys = "n526-keys/input0";
188 + input->dev.parent = &client->dev;
189 + input->id.bustype = BUS_I2C;
190 + input->id.vendor = 0x0001;
191 + input->id.product = 0x0001;
192 + input->id.version = 0x0001;
193 +
194 + __set_bit(EV_KEY, input->evbit);
195 +
196 + for (i = 0; i < ARRAY_SIZE(n526_lpc_keymap); ++i) {
197 + if (n526_lpc_keymap[i] != 0)
198 + __set_bit(n526_lpc_keymap[i], input->keybit);
199 + }
200 +
201 + ret = input_register_device(input);
202 +
203 + if (ret) {
204 + dev_err(&client->dev, "Failed to register input device: %d\n", ret);
205 + goto err_free_input;
206 + }
207 +
208 + n526_lpc->client = client;
209 + n526_lpc->input = input;
210 + INIT_WORK(&n526_lpc->work, n526_lpc_irq_work);
211 +
212 + ret = request_irq(client->irq, n526_lpc_irq, IRQF_TRIGGER_FALLING,
213 + "n526-lpc", n526_lpc);
214 + if (ret) {
215 + dev_err(&client->dev, "Failed to request irq: %d\n", ret);
216 + goto err_unregister_input;
217 + }
218 +
219 + i2c_set_clientdata(client, n526_lpc);
220 +
221 + return 0;
222 +
223 +err_unregister_input:
224 + input_unregister_device(input);
225 +err_free_input:
226 + input_free_device(input);
227 +err_free:
228 + kfree(n526_lpc);
229 +
230 + return ret;
231 +}
232 +
233 +static int n526_lpc_remove(struct i2c_client *client)
234 +{
235 + struct n526_lpc *n526_lpc = i2c_get_clientdata(client);
236 +
237 + free_irq(client->irq, n526_lpc);
238 +
239 + i2c_set_clientdata(client, NULL);
240 + input_unregister_device(n526_lpc->input);
241 + input_free_device(n526_lpc->input);
242 + kfree(n526_lpc);
243 +
244 + return 0;
245 +}
246 +
247 +static const struct i2c_device_id n526_lpc_id[] = {
248 + { "n526-lpc", 0 },
249 + { }
250 +};
251 +MODULE_DEVICE_TABLE(i2c, n526_lpc_id);
252 +
253 +static struct i2c_driver n526_lpc_driver = {
254 + .driver = {
255 + .name = "n526-lpc",
256 + .owner = THIS_MODULE,
257 + },
258 + .probe = n526_lpc_probe,
259 + .remove = n526_lpc_remove,
260 + .id_table = n526_lpc_id,
261 +};
262 +
263 +static int __init n526_lpc_init(void)
264 +{
265 + return i2c_add_driver(&n526_lpc_driver);
266 +}
267 +module_init(n526_lpc_init);
268 +
269 +static void __exit n526_lpc_exit(void)
270 +{
271 + i2c_del_driver(&n526_lpc_driver);
272 +}
273 +module_exit(n526_lpc_exit);
274 +
275 +MODULE_LICENSE("GPL");
276 +MODULE_AUTHOR("Lars-Peter Clausen");
277 +MODULE_DESCRIPTION("n526 keypad driver");
278 +MODULE_ALIAS("i2c:n526-keys");