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 --- a/drivers/misc/Kconfig
14 +++ b/drivers/misc/Kconfig
15 @@ -361,6 +361,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 @@ -32,3 +32,4 @@ obj-y += eeprom/
35 obj-$(CONFIG_VMWARE_BALLOON) += vmware_balloon.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>
61 +#include <linux/workqueue.h>
63 +#include <asm/mach-jz4740/irq.h>
64 +#include <asm/mach-jz4740/gpio.h>
67 + struct i2c_client *client;
68 + struct input_dev *input;
70 + struct work_struct work;
73 +static const unsigned int n526_lpc_keymap[] = {
74 + [0x01] = KEY_PAGEUP,
75 + [0x02] = KEY_PAGEDOWN,
76 + [0x03] = KEY_VOLUMEUP,
77 + [0x04] = KEY_VOLUMEDOWN,
82 + [0x0a] = KEY_LEFTSHIFT,
87 + [0x0f] = KEY_REFRESH,
92 + [0x14] = KEY_DOCUMENTS,
102 + [0x1e] = KEY_DELETE,
107 + [0x23] = KEY_SPACE,
112 +/* [0x28] = KEY_SYM, */
125 + [0x35] = KEY_BACKSPACE,
126 + [0x36] = KEY_ENTER,
127 + [0x37] = KEY_RIGHT,
130 +static void n526_lpc_irq_work(struct work_struct *work)
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;
140 + ret = i2c_transfer(client->adapter, &msg, 1);
143 + dev_err(&client->dev, "Failed to read lpc status\n");
146 + keycode = raw_msg & 0x7f;
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);
155 +static irqreturn_t n526_lpc_irq(int irq, void *dev_id)
157 + struct n526_lpc *n526_lpc = dev_id;
159 + schedule_work(&n526_lpc->work);
160 + return IRQ_HANDLED;
163 +static int __devinit n526_lpc_probe(struct i2c_client *client,
164 + const struct i2c_device_id *id)
168 + struct n526_lpc *n526_lpc;
169 + struct input_dev *input;
171 + n526_lpc = kmalloc(sizeof(*n526_lpc), GFP_KERNEL);
174 + dev_err(&client->dev, "Failed to allocate device structure\n");
178 + input = input_allocate_device();
180 + dev_err(&client->dev, "Failed to allocate input device\n");
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;
193 + __set_bit(EV_KEY, input->evbit);
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);
200 + ret = input_register_device(input);
203 + dev_err(&client->dev, "Failed to register input device: %d\n", ret);
204 + goto err_free_input;
207 + n526_lpc->client = client;
208 + n526_lpc->input = input;
209 + INIT_WORK(&n526_lpc->work, n526_lpc_irq_work);
211 + ret = request_irq(client->irq, n526_lpc_irq, IRQF_TRIGGER_FALLING,
212 + "n526-lpc", n526_lpc);
214 + dev_err(&client->dev, "Failed to request irq: %d\n", ret);
215 + goto err_unregister_input;
218 + i2c_set_clientdata(client, n526_lpc);
222 +err_unregister_input:
223 + input_unregister_device(input);
225 + input_free_device(input);
232 +static int n526_lpc_remove(struct i2c_client *client)
234 + struct n526_lpc *n526_lpc = i2c_get_clientdata(client);
236 + free_irq(client->irq, n526_lpc);
238 + i2c_set_clientdata(client, NULL);
239 + input_unregister_device(n526_lpc->input);
240 + input_free_device(n526_lpc->input);
246 +static const struct i2c_device_id n526_lpc_id[] = {
250 +MODULE_DEVICE_TABLE(i2c, n526_lpc_id);
252 +static struct i2c_driver n526_lpc_driver = {
254 + .name = "n526-lpc",
255 + .owner = THIS_MODULE,
257 + .probe = n526_lpc_probe,
258 + .remove = n526_lpc_remove,
259 + .id_table = n526_lpc_id,
262 +static int __init n526_lpc_init(void)
264 + return i2c_add_driver(&n526_lpc_driver);
266 +module_init(n526_lpc_init);
268 +static void __exit n526_lpc_exit(void)
270 + i2c_del_driver(&n526_lpc_driver);
272 +module_exit(n526_lpc_exit);
274 +MODULE_LICENSE("GPL");
275 +MODULE_AUTHOR("Lars-Peter Clausen");
276 +MODULE_DESCRIPTION("n526 keypad driver");
277 +MODULE_ALIAS("i2c:n526-keys");