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