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
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
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
19 N516 keyboard & power controller driver
22 + tristate "N526 LPC934 coprocessor"
23 + depends on JZ4740_N526
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.
28 + If you have a N526 you probably want to say Y here.
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/
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
44 index 0000000..4ac5c79
46 +++ b/drivers/misc/n526-lpc.c
49 + * Copyright (C) 2009, Lars-Peter Clausen <lars@metafoo.de>
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.
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.
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>
68 +#include <linux/workqueue.h>
70 +#include <asm/mach-jz4740/irq.h>
71 +#include <asm/mach-jz4740/gpio.h>
74 + struct i2c_client *client;
75 + struct input_dev *input;
77 + struct work_struct work;
80 +static const unsigned int n526_lpc_keymap[] = {
81 + [0x01] = KEY_PAGEUP,
82 + [0x02] = KEY_PAGEDOWN,
83 + [0x03] = KEY_VOLUMEUP,
84 + [0x04] = KEY_VOLUMEDOWN,
89 + [0x0a] = KEY_LEFTSHIFT,
94 + [0x0f] = KEY_REFRESH,
99 + [0x14] = KEY_DOCUMENTS,
109 + [0x1e] = KEY_DELETE,
114 + [0x23] = KEY_SPACE,
119 +/* [0x28] = KEY_SYM, */
132 + [0x35] = KEY_BACKSPACE,
133 + [0x36] = KEY_ENTER,
134 + [0x37] = KEY_RIGHT,
137 +static void n526_lpc_irq_work(struct work_struct *work)
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;
147 + ret = i2c_transfer(client->adapter, &msg, 1);
150 + dev_err(&client->dev, "Failed to read lpc status\n");
153 + keycode = raw_msg & 0x7f;
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);
162 +static irqreturn_t n526_lpc_irq(int irq, void *dev_id)
164 + struct n526_lpc *n526_lpc = dev_id;
166 + schedule_work(&n526_lpc->work);
167 + return IRQ_HANDLED;
170 +static int __devinit n526_lpc_probe(struct i2c_client *client,
171 + const struct i2c_device_id *id)
175 + struct n526_lpc *n526_lpc;
176 + struct input_dev *input;
178 + n526_lpc = kmalloc(sizeof(*n526_lpc), GFP_KERNEL);
181 + dev_err(&client->dev, "Failed to allocate device structure\n");
185 + input = input_allocate_device();
187 + dev_err(&client->dev, "Failed to allocate input device\n");
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;
200 + __set_bit(EV_KEY, input->evbit);
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);
207 + ret = input_register_device(input);
210 + dev_err(&client->dev, "Failed to register input device: %d\n", ret);
211 + goto err_free_input;
214 + n526_lpc->client = client;
215 + n526_lpc->input = input;
216 + INIT_WORK(&n526_lpc->work, n526_lpc_irq_work);
218 + ret = request_irq(client->irq, n526_lpc_irq, IRQF_TRIGGER_FALLING,
219 + "n526-lpc", n526_lpc);
221 + dev_err(&client->dev, "Failed to request irq: %d\n", ret);
222 + goto err_unregister_input;
225 + i2c_set_clientdata(client, n526_lpc);
229 +err_unregister_input:
230 + input_unregister_device(input);
232 + input_free_device(input);
239 +static int n526_lpc_remove(struct i2c_client *client)
241 + struct n526_lpc *n526_lpc = i2c_get_clientdata(client);
243 + free_irq(client->irq, n526_lpc);
245 + i2c_set_clientdata(client, NULL);
246 + input_unregister_device(n526_lpc->input);
247 + input_free_device(n526_lpc->input);
253 +static const struct i2c_device_id n526_lpc_id[] = {
257 +MODULE_DEVICE_TABLE(i2c, n526_lpc_id);
259 +static struct i2c_driver n526_lpc_driver = {
261 + .name = "n526-lpc",
262 + .owner = THIS_MODULE,
264 + .probe = n526_lpc_probe,
265 + .remove = n526_lpc_remove,
266 + .id_table = n526_lpc_id,
269 +static int __init n526_lpc_init(void)
271 + return i2c_add_driver(&n526_lpc_driver);
273 +module_init(n526_lpc_init);
275 +static void __exit n526_lpc_exit(void)
277 + i2c_del_driver(&n526_lpc_driver);
279 +module_exit(n526_lpc_exit);
281 +MODULE_LICENSE("GPL");
282 +MODULE_AUTHOR("Lars-Peter Clausen");
283 +MODULE_DESCRIPTION("n526 keypad driver");
284 +MODULE_ALIAS("i2c:n526-keys");