diff options
| author | Joonyoung Shim <jy0922.shim@samsung.com> | 2010-07-04 04:21:25 -0400 |
|---|---|---|
| committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2010-07-04 04:23:26 -0400 |
| commit | 312e8e8a9e2471b0ada7366497fffb3ff1a40e2c (patch) | |
| tree | 45f91b8099e5fbcebfcb3a208902013a4bb9fb0c | |
| parent | 866d7d7b4a4e1d502b136bcc8af605091fe4c7b5 (diff) | |
Input: mcs - Add MCS touchkey driver
This adds support for MELPAS MCS5000/MSC5080 touch key controllers.
Signed-off-by: Joonyoung Shim <jy0922.shim@samsung.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
| -rw-r--r-- | drivers/input/keyboard/Kconfig | 12 | ||||
| -rw-r--r-- | drivers/input/keyboard/Makefile | 1 | ||||
| -rw-r--r-- | drivers/input/keyboard/mcs_touchkey.c | 239 | ||||
| -rw-r--r-- | drivers/input/touchscreen/mcs5000_ts.c | 6 | ||||
| -rw-r--r-- | include/linux/i2c/mcs.h | 34 | ||||
| -rw-r--r-- | include/linux/i2c/mcs5000_ts.h | 24 |
6 files changed, 289 insertions, 27 deletions
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig index d8fa5d724c57..c7480934ceeb 100644 --- a/drivers/input/keyboard/Kconfig +++ b/drivers/input/keyboard/Kconfig | |||
| @@ -297,6 +297,18 @@ config KEYBOARD_MAX7359 | |||
| 297 | To compile this driver as a module, choose M here: the | 297 | To compile this driver as a module, choose M here: the |
| 298 | module will be called max7359_keypad. | 298 | module will be called max7359_keypad. |
| 299 | 299 | ||
| 300 | config KEYBOARD_MCS | ||
| 301 | tristate "MELFAS MCS Touchkey" | ||
| 302 | depends on I2C | ||
| 303 | help | ||
| 304 | Say Y here if you have the MELFAS MCS5000/5080 touchkey controller | ||
| 305 | chip in your system. | ||
| 306 | |||
| 307 | If unsure, say N. | ||
| 308 | |||
| 309 | To compile this driver as a module, choose M here: the | ||
| 310 | module will be called mcs_touchkey. | ||
| 311 | |||
| 300 | config KEYBOARD_IMX | 312 | config KEYBOARD_IMX |
| 301 | tristate "IMX keypad support" | 313 | tristate "IMX keypad support" |
| 302 | depends on ARCH_MXC | 314 | depends on ARCH_MXC |
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile index 4596d0c6f922..0a16674ed3d2 100644 --- a/drivers/input/keyboard/Makefile +++ b/drivers/input/keyboard/Makefile | |||
| @@ -26,6 +26,7 @@ obj-$(CONFIG_KEYBOARD_LOCOMO) += locomokbd.o | |||
| 26 | obj-$(CONFIG_KEYBOARD_MAPLE) += maple_keyb.o | 26 | obj-$(CONFIG_KEYBOARD_MAPLE) += maple_keyb.o |
| 27 | obj-$(CONFIG_KEYBOARD_MATRIX) += matrix_keypad.o | 27 | obj-$(CONFIG_KEYBOARD_MATRIX) += matrix_keypad.o |
| 28 | obj-$(CONFIG_KEYBOARD_MAX7359) += max7359_keypad.o | 28 | obj-$(CONFIG_KEYBOARD_MAX7359) += max7359_keypad.o |
| 29 | obj-$(CONFIG_KEYBOARD_MCS) += mcs_touchkey.o | ||
| 29 | obj-$(CONFIG_KEYBOARD_NEWTON) += newtonkbd.o | 30 | obj-$(CONFIG_KEYBOARD_NEWTON) += newtonkbd.o |
| 30 | obj-$(CONFIG_KEYBOARD_OMAP) += omap-keypad.o | 31 | obj-$(CONFIG_KEYBOARD_OMAP) += omap-keypad.o |
| 31 | obj-$(CONFIG_KEYBOARD_OPENCORES) += opencores-kbd.o | 32 | obj-$(CONFIG_KEYBOARD_OPENCORES) += opencores-kbd.o |
diff --git a/drivers/input/keyboard/mcs_touchkey.c b/drivers/input/keyboard/mcs_touchkey.c new file mode 100644 index 000000000000..63b849d7e90b --- /dev/null +++ b/drivers/input/keyboard/mcs_touchkey.c | |||
| @@ -0,0 +1,239 @@ | |||
| 1 | /* | ||
| 2 | * mcs_touchkey.c - Touchkey driver for MELFAS MCS5000/5080 controller | ||
| 3 | * | ||
| 4 | * Copyright (C) 2010 Samsung Electronics Co.Ltd | ||
| 5 | * Author: HeungJun Kim <riverful.kim@samsung.com> | ||
| 6 | * Author: Joonyoung Shim <jy0922.shim@samsung.com> | ||
| 7 | * | ||
| 8 | * This program is free software; you can redistribute it and/or modify it | ||
| 9 | * under the terms of the GNU General Public License as published by the | ||
| 10 | * Free Software Foundation; either version 2 of the License, or (at your | ||
| 11 | * option) any later version. | ||
| 12 | */ | ||
| 13 | |||
| 14 | #include <linux/module.h> | ||
| 15 | #include <linux/init.h> | ||
| 16 | #include <linux/i2c.h> | ||
| 17 | #include <linux/i2c/mcs.h> | ||
| 18 | #include <linux/interrupt.h> | ||
| 19 | #include <linux/input.h> | ||
| 20 | #include <linux/irq.h> | ||
| 21 | #include <linux/slab.h> | ||
| 22 | |||
| 23 | /* MCS5000 Touchkey */ | ||
| 24 | #define MCS5000_TOUCHKEY_STATUS 0x04 | ||
| 25 | #define MCS5000_TOUCHKEY_STATUS_PRESS 7 | ||
| 26 | #define MCS5000_TOUCHKEY_FW 0x0a | ||
| 27 | #define MCS5000_TOUCHKEY_BASE_VAL 0x61 | ||
| 28 | |||
| 29 | /* MCS5080 Touchkey */ | ||
| 30 | #define MCS5080_TOUCHKEY_STATUS 0x00 | ||
| 31 | #define MCS5080_TOUCHKEY_STATUS_PRESS 3 | ||
| 32 | #define MCS5080_TOUCHKEY_FW 0x01 | ||
| 33 | #define MCS5080_TOUCHKEY_BASE_VAL 0x1 | ||
| 34 | |||
| 35 | enum mcs_touchkey_type { | ||
| 36 | MCS5000_TOUCHKEY, | ||
| 37 | MCS5080_TOUCHKEY, | ||
| 38 | }; | ||
| 39 | |||
| 40 | struct mcs_touchkey_chip { | ||
| 41 | unsigned int status_reg; | ||
| 42 | unsigned int pressbit; | ||
| 43 | unsigned int press_invert; | ||
| 44 | unsigned int baseval; | ||
| 45 | }; | ||
| 46 | |||
| 47 | struct mcs_touchkey_data { | ||
| 48 | struct i2c_client *client; | ||
| 49 | struct input_dev *input_dev; | ||
| 50 | struct mcs_touchkey_chip chip; | ||
| 51 | unsigned int key_code; | ||
| 52 | unsigned int key_val; | ||
| 53 | unsigned short keycodes[]; | ||
| 54 | }; | ||
| 55 | |||
| 56 | static irqreturn_t mcs_touchkey_interrupt(int irq, void *dev_id) | ||
| 57 | { | ||
| 58 | struct mcs_touchkey_data *data = dev_id; | ||
| 59 | struct mcs_touchkey_chip *chip = &data->chip; | ||
| 60 | struct i2c_client *client = data->client; | ||
| 61 | struct input_dev *input = data->input_dev; | ||
| 62 | unsigned int key_val; | ||
| 63 | unsigned int pressed; | ||
| 64 | int val; | ||
| 65 | |||
| 66 | val = i2c_smbus_read_byte_data(client, chip->status_reg); | ||
| 67 | if (val < 0) { | ||
| 68 | dev_err(&client->dev, "i2c read error [%d]\n", val); | ||
| 69 | goto out; | ||
| 70 | } | ||
| 71 | |||
| 72 | pressed = (val & (1 << chip->pressbit)) >> chip->pressbit; | ||
| 73 | if (chip->press_invert) | ||
| 74 | pressed ^= chip->press_invert; | ||
| 75 | |||
| 76 | /* key_val is 0 when released, so we should use key_val of press. */ | ||
| 77 | if (pressed) { | ||
| 78 | key_val = val & (0xff >> (8 - chip->pressbit)); | ||
| 79 | if (!key_val) | ||
| 80 | goto out; | ||
| 81 | key_val -= chip->baseval; | ||
| 82 | data->key_code = data->keycodes[key_val]; | ||
| 83 | data->key_val = key_val; | ||
| 84 | } | ||
| 85 | |||
| 86 | input_event(input, EV_MSC, MSC_SCAN, data->key_val); | ||
| 87 | input_report_key(input, data->key_code, pressed); | ||
| 88 | input_sync(input); | ||
| 89 | |||
| 90 | dev_dbg(&client->dev, "key %d %d %s\n", data->key_val, data->key_code, | ||
| 91 | pressed ? "pressed" : "released"); | ||
| 92 | |||
| 93 | out: | ||
| 94 | return IRQ_HANDLED; | ||
| 95 | } | ||
| 96 | |||
| 97 | static int __devinit mcs_touchkey_probe(struct i2c_client *client, | ||
| 98 | const struct i2c_device_id *id) | ||
| 99 | { | ||
| 100 | const struct mcs_platform_data *pdata; | ||
| 101 | struct mcs_touchkey_data *data; | ||
| 102 | struct input_dev *input_dev; | ||
| 103 | unsigned int fw_reg; | ||
| 104 | int fw_ver; | ||
| 105 | int error; | ||
| 106 | int i; | ||
| 107 | |||
| 108 | pdata = client->dev.platform_data; | ||
| 109 | if (!pdata) { | ||
| 110 | dev_err(&client->dev, "no platform data defined\n"); | ||
| 111 | return -EINVAL; | ||
| 112 | } | ||
| 113 | |||
| 114 | data = kzalloc(sizeof(struct mcs_touchkey_data) + | ||
| 115 | sizeof(data->keycodes[0]) * (pdata->key_maxval + 1), | ||
| 116 | GFP_KERNEL); | ||
| 117 | input_dev = input_allocate_device(); | ||
| 118 | if (!data || !input_dev) { | ||
| 119 | dev_err(&client->dev, "Failed to allocate memory\n"); | ||
| 120 | error = -ENOMEM; | ||
| 121 | goto err_free_mem; | ||
| 122 | } | ||
| 123 | |||
| 124 | data->client = client; | ||
| 125 | data->input_dev = input_dev; | ||
| 126 | |||
| 127 | if (id->driver_data == MCS5000_TOUCHKEY) { | ||
| 128 | data->chip.status_reg = MCS5000_TOUCHKEY_STATUS; | ||
| 129 | data->chip.pressbit = MCS5000_TOUCHKEY_STATUS_PRESS; | ||
| 130 | data->chip.baseval = MCS5000_TOUCHKEY_BASE_VAL; | ||
| 131 | fw_reg = MCS5000_TOUCHKEY_FW; | ||
| 132 | } else { | ||
| 133 | data->chip.status_reg = MCS5080_TOUCHKEY_STATUS; | ||
| 134 | data->chip.pressbit = MCS5080_TOUCHKEY_STATUS_PRESS; | ||
| 135 | data->chip.press_invert = 1; | ||
| 136 | data->chip.baseval = MCS5080_TOUCHKEY_BASE_VAL; | ||
| 137 | fw_reg = MCS5080_TOUCHKEY_FW; | ||
| 138 | } | ||
| 139 | |||
| 140 | fw_ver = i2c_smbus_read_byte_data(client, fw_reg); | ||
| 141 | if (fw_ver < 0) { | ||
| 142 | error = fw_ver; | ||
| 143 | dev_err(&client->dev, "i2c read error[%d]\n", error); | ||
