1 From 626675b8f03f416a6b1c50f69dabb8a3f27b200a 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 | 238 +++++++++++++++++++++++++++++++++++++++++++++++
10 3 files changed, 248 insertions(+), 0 deletions(-)
11 create mode 100644 drivers/misc/n526-lpc.c
13 --- a/drivers/misc/Kconfig
14 +++ b/drivers/misc/Kconfig
15 @@ -398,6 +398,15 @@ config N516_LPC
17 N516 keyboard & power controller driver
20 + tristate "N526 LPC934 coprocessor"
21 + depends on JZ4740_N526
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.
26 + If you have a N526 you probably want to say Y here.
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 @@ -36,3 +36,4 @@ obj-y += cb710/
34 obj-$(CONFIG_VMWARE_BALLOON) += vmw_balloon.o
35 obj-$(CONFIG_ARM_CHARLCD) += arm-charlcd.o
36 obj-$(CONFIG_N516_LPC) += n516-lpc.o
37 +obj-$(CONFIG_N526_LPC) += n526-lpc.o
39 +++ b/drivers/misc/n526-lpc.c
42 + * Copyright (C) 2009, Lars-Peter Clausen <lars@metafoo.de>
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.
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.
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>
62 +#include <linux/workqueue.h>
64 +#include <asm/mach-jz4740/irq.h>
65 +#include <asm/mach-jz4740/gpio.h>
68 + struct i2c_client *client;
69 + struct input_dev *input;
71 + struct work_struct work;
74 +static const unsigned int n526_lpc_keymap[] = {
75 + [0x01] = KEY_PAGEUP,
76 + [0x02] = KEY_PAGEDOWN,
77 + [0x03] = KEY_VOLUMEUP,
78 + [0x04] = KEY_VOLUMEDOWN,
83 + [0x0a] = KEY_LEFTSHIFT,
88 + [0x0f] = KEY_REFRESH,
93 + [0x14] = KEY_DOCUMENTS,
103 + [0x1e] = KEY_DELETE,
108 + [0x23] = KEY_SPACE,
113 +/* [0x28] = KEY_SYM, */
126 + [0x35] = KEY_BACKSPACE,
127 + [0x36] = KEY_ENTER,
128 + [0x37] = KEY_RIGHT,
131 +static void n526_lpc_irq_work(struct work_struct *work)
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;
141 + ret = i2c_transfer(client->adapter, &msg, 1);
144 + dev_err(&client->dev, "Failed to read lpc status\n");
147 + keycode = raw_msg & 0x7f;
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);
156 +static irqreturn_t n526_lpc_irq(int irq, void *dev_id)
158 + struct n526_lpc *n526_lpc = dev_id;
160 + schedule_work(&n526_lpc->work);
161 + return IRQ_HANDLED;
164 +static int __devinit n526_lpc_probe(struct i2c_client *client,
165 + const struct i2c_device_id *id)
169 + struct n526_lpc *n526_lpc;
170 + struct input_dev *input;
172 + n526_lpc = kmalloc(sizeof(*n526_lpc), GFP_KERNEL);
175 + dev_err(&client->dev, "Failed to allocate device structure\n");
179 + input = input_allocate_device();
181 + dev_err(&client->dev, "Failed to allocate input device\n");
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;
194 + __set_bit(EV_KEY, input->evbit);
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);
201 + ret = input_register_device(input);
204 + dev_err(&client->dev, "Failed to register input device: %d\n", ret);
205 + goto err_free_input;
208 + n526_lpc->client = client;
209 + n526_lpc->input = input;
210 + INIT_WORK(&n526_lpc->work, n526_lpc_irq_work);
212 + ret = request_irq(client->irq, n526_lpc_irq, IRQF_TRIGGER_FALLING,
213 + "n526-lpc", n526_lpc);
215 + dev_err(&client->dev, "Failed to request irq: %d\n", ret);
216 + goto err_unregister_input;
219 + i2c_set_clientdata(client, n526_lpc);
223 +err_unregister_input:
224 + input_unregister_device(input);
226 + input_free_device(input);
233 +static int n526_lpc_remove(struct i2c_client *client)
235 + struct n526_lpc *n526_lpc = i2c_get_clientdata(client);
237 + free_irq(client->irq, n526_lpc);
239 + i2c_set_clientdata(client, NULL);
240 + input_unregister_device(n526_lpc->input);
241 + input_free_device(n526_lpc->input);
247 +static const struct i2c_device_id n526_lpc_id[] = {
251 +MODULE_DEVICE_TABLE(i2c, n526_lpc_id);
253 +static struct i2c_driver n526_lpc_driver = {
255 + .name = "n526-lpc",
256 + .owner = THIS_MODULE,
258 + .probe = n526_lpc_probe,
259 + .remove = n526_lpc_remove,
260 + .id_table = n526_lpc_id,
263 +static int __init n526_lpc_init(void)
265 + return i2c_add_driver(&n526_lpc_driver);
267 +module_init(n526_lpc_init);
269 +static void __exit n526_lpc_exit(void)
271 + i2c_del_driver(&n526_lpc_driver);
273 +module_exit(n526_lpc_exit);
275 +MODULE_LICENSE("GPL");
276 +MODULE_AUTHOR("Lars-Peter Clausen");
277 +MODULE_DESCRIPTION("n526 keypad driver");
278 +MODULE_ALIAS("i2c:n526-keys");