aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/input/touchscreen/Kconfig11
-rw-r--r--drivers/input/touchscreen/Makefile1
-rw-r--r--drivers/input/touchscreen/mcs5000_ts.c318
-rw-r--r--include/linux/i2c/mcs5000_ts.h24
4 files changed, 354 insertions, 0 deletions
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index 5a252d449e5..6dfb0a2b0a7 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -169,6 +169,17 @@ config TOUCHSCREEN_WACOM_W8001
169 To compile this driver as a module, choose M here: the 169 To compile this driver as a module, choose M here: the
170 module will be called wacom_w8001. 170 module will be called wacom_w8001.
171 171
172config TOUCHSCREEN_MCS5000
173 tristate "MELFAS MCS-5000 touchscreen"
174 depends on I2C
175 help
176 Say Y here if you have the MELFAS MCS-5000 touchscreen controller
177 chip in your system.
178
179 If unsure, say N.
180
181 To compile this driver as a module, choose M here: the
182 module will be called mcs5000_ts.
172 183
173config TOUCHSCREEN_MTOUCH 184config TOUCHSCREEN_MTOUCH
174 tristate "MicroTouch serial touchscreens" 185 tristate "MicroTouch serial touchscreens"
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile
index 3e1c5e0b952..a882ca16506 100644
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -17,6 +17,7 @@ obj-$(CONFIG_TOUCHSCREEN_EETI) += eeti_ts.o
17obj-$(CONFIG_TOUCHSCREEN_ELO) += elo.o 17obj-$(CONFIG_TOUCHSCREEN_ELO) += elo.o
18obj-$(CONFIG_TOUCHSCREEN_FUJITSU) += fujitsu_ts.o 18obj-$(CONFIG_TOUCHSCREEN_FUJITSU) += fujitsu_ts.o
19obj-$(CONFIG_TOUCHSCREEN_INEXIO) += inexio.o 19obj-$(CONFIG_TOUCHSCREEN_INEXIO) += inexio.o
20obj-$(CONFIG_TOUCHSCREEN_MCS5000) += mcs5000_ts.o
20obj-$(CONFIG_TOUCHSCREEN_MIGOR) += migor_ts.o 21obj-$(CONFIG_TOUCHSCREEN_MIGOR) += migor_ts.o
21obj-$(CONFIG_TOUCHSCREEN_MTOUCH) += mtouch.o 22obj-$(CONFIG_TOUCHSCREEN_MTOUCH) += mtouch.o
22obj-$(CONFIG_TOUCHSCREEN_MK712) += mk712.o 23obj-$(CONFIG_TOUCHSCREEN_MK712) += mk712.o
diff --git a/drivers/input/touchscreen/mcs5000_ts.c b/drivers/input/touchscreen/mcs5000_ts.c
new file mode 100644
index 00000000000..4c28b89757f
--- /dev/null
+++ b/drivers/input/touchscreen/mcs5000_ts.c
@@ -0,0 +1,318 @@
1/*
2 * mcs5000_ts.c - Touchscreen driver for MELFAS MCS-5000 controller
3 *
4 * Copyright (C) 2009 Samsung Electronics Co.Ltd
5 * Author: Joonyoung Shim <jy0922.shim@samsung.com>
6 *
7 * Based on wm97xx-core.c
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 *
14 */
15
16#include <linux/module.h>
17#include <linux/init.h>
18#include <linux/i2c.h>
19#include <linux/i2c/mcs5000_ts.h>
20#include <linux/interrupt.h>
21#include <linux/input.h>
22#include <linux/irq.h>
23
24/* Registers */
25#define MCS5000_TS_STATUS 0x00
26#define STATUS_OFFSET 0
27#define STATUS_NO (0 << STATUS_OFFSET)
28#define STATUS_INIT (1 << STATUS_OFFSET)
29#define STATUS_SENSING (2 << STATUS_OFFSET)
30#define STATUS_COORD (3 << STATUS_OFFSET)
31#define STATUS_GESTURE (4 << STATUS_OFFSET)
32#define ERROR_OFFSET 4
33#define ERROR_NO (0 << ERROR_OFFSET)
34#define ERROR_POWER_ON_RESET (1 << ERROR_OFFSET)
35#define ERROR_INT_RESET (2 << ERROR_OFFSET)
36#define ERROR_EXT_RESET (3 << ERROR_OFFSET)
37#define ERROR_INVALID_REG_ADDRESS (8 << ERROR_OFFSET)
38#define ERROR_INVALID_REG_VALUE (9 << ERROR_OFFSET)
39
40#define MCS5000_TS_OP_MODE 0x01
41#define RESET_OFFSET 0
42#define RESET_NO (0 << RESET_OFFSET)
43#define RESET_EXT_SOFT (1 << RESET_OFFSET)
44#define OP_MODE_OFFSET 1
45#define OP_MODE_SLEEP (0 << OP_MODE_OFFSET)
46#define OP_MODE_ACTIVE (1 << OP_MODE_OFFSET)
47#define GESTURE_OFFSET 4
48#define GESTURE_DISABLE (0 << GESTURE_OFFSET)
49#define GESTURE_ENABLE (1 << GESTURE_OFFSET)
50#define PROXIMITY_OFFSET 5
51#define PROXIMITY_DISABLE (0 << PROXIMITY_OFFSET)
52#define PROXIMITY_ENABLE (1 << PROXIMITY_OFFSET)
53#define SCAN_MODE_OFFSET 6
54#define SCAN_MODE_INTERRUPT (0 << SCAN_MODE_OFFSET)
55#define SCAN_MODE_POLLING (1 << SCAN_MODE_OFFSET)
56#define REPORT_RATE_OFFSET 7
57#define REPORT_RATE_40 (0 << REPORT_RATE_OFFSET)
58#define REPORT_RATE_80 (1 << REPORT_RATE_OFFSET)
59
60#define MCS5000_TS_SENS_CTL 0x02
61#define MCS5000_TS_FILTER_CTL 0x03
62#define PRI_FILTER_OFFSET 0
63#define SEC_FILTER_OFFSET 4
64
65#define MCS5000_TS_X_SIZE_UPPER 0x08
66#define MCS5000_TS_X_SIZE_LOWER 0x09
67#define MCS5000_TS_Y_SIZE_UPPER 0x0A
68#define MCS5000_TS_Y_SIZE_LOWER 0x0B
69
70#define MCS5000_TS_INPUT_INFO 0x10
71#define INPUT_TYPE_OFFSET 0
72#define INPUT_TYPE_NONTOUCH (0 << INPUT_TYPE_OFFSET)
73#define INPUT_TYPE_SINGLE (1 << INPUT_TYPE_OFFSET)
74#define INPUT_TYPE_DUAL (2 << INPUT_TYPE_OFFSET)
75#define INPUT_TYPE_PALM (3 << INPUT_TYPE_OFFSET)
76#define INPUT_TYPE_PROXIMITY (7 << INPUT_TYPE_OFFSET)
77#define GESTURE_CODE_OFFSET 3
78#define GESTURE_CODE_NO (0 << GESTURE_CODE_OFFSET)
79
80#define MCS5000_TS_X_POS_UPPER 0x11
81#define MCS5000_TS_X_POS_LOWER 0x12
82#define MCS5000_TS_Y_POS_UPPER 0x13
83#define MCS5000_TS_Y_POS_LOWER 0x14
84#define MCS5000_TS_Z_POS 0x15
85#define MCS5000_TS_WIDTH 0x16
86#define MCS5000_TS_GESTURE_VAL 0x17
87#define MCS5000_TS_MODULE_REV 0x20
88#define MCS5000_TS_FIRMWARE_VER 0x21
89
90/* Touchscreen absolute values */
91#define MCS5000_MAX_XC 0x3ff
92#define MCS5000_MAX_YC 0x3ff
93
94enum mcs5000_ts_read_offset {
95 READ_INPUT_INFO,
96 READ_X_POS_UPPER,
97 READ_X_POS_LOWER,
98 READ_Y_POS_UPPER,
99 READ_Y_POS_LOWER,
100 READ_BLOCK_SIZE,
101};
102
103/* Each client has this additional data */
104struct mcs5000_ts_data {
105 struct i2c_client *client;
106 struct input_dev *input_dev;
107 const struct mcs5000_ts_platform_data *platform_data;
108};
109
110static irqreturn_t mcs5000_ts_interrupt(int irq, void *dev_id)
111{
112 struct mcs5000_ts_data *data = dev_id;
113 struct i2c_client *client = data->client;
114 u8 buffer[READ_BLOCK_SIZE];
115 int err;
116 int x;
117 int y;
118
119 err = i2c_smbus_read_i2c_block_data(client, MCS5000_TS_INPUT_INFO,
120 READ_BLOCK_SIZE, buffer);
121 if (err < 0) {
122 dev_err(&client->dev, "%s, err[%d]\n", __func__, err);
123 goto out;
124 }
125
126 switch (buffer[READ_INPUT_INFO]) {
127 case INPUT_TYPE_NONTOUCH:
128 input_report_key(data->input_dev, BTN_TOUCH, 0);
129 input_sync(data->input_dev);
130 break;
131
132 case INPUT_TYPE_SINGLE:
133 x = (buffer[READ_X_POS_UPPER] << 8) | buffer[READ_X_POS_LOWER];
134 y = (buffer[READ_Y_POS_UPPER] << 8) | buffer[READ_Y_POS_LOWER];
135
136 input_report_key(data->input_dev, BTN_TOUCH, 1);
137 input_report_abs(data->input_dev, ABS_X, x);
138 input_report_abs(data->input_dev, ABS_Y, y);
139 input_sync(data->input_dev);
140 break;
141
142 case INPUT_TYPE_DUAL:
143 /* TODO */
144 break;
145
146 case INPUT_TYPE_PALM:
147 /* TODO */
148 break;
149
150 case INPUT_TYPE_PROXIMITY:
151 /* TODO */
152 break;
153
154 default:
155 dev_err(&client->dev, "Unknown ts input type %d\n",
156 buffer[READ_INPUT_INFO]);
157 break;
158 }
159
160 out:
161 return IRQ_HANDLED;
162}
163
164static void mcs5000_ts_phys_init(struct mcs5000_ts_data *data)
165{
166 const struct mcs5000_ts_platform_data *platform_data =
167 data->platform_data;
168 struct i2c_client *client = data->client;
169
170 /* Touch reset & sleep mode */
171 i2c_smbus_write_byte_data(client, MCS5000_TS_OP_MODE,
172 RESET_EXT_SOFT | OP_MODE_SLEEP);
173
174 /* Touch size */
175 i2c_smbus_write_byte_data(client, MCS5000_TS_X_SIZE_UPPER,
176 platform_data->x_size >> 8);
177 i2c_smbus_write_byte_data(client, MCS5000_TS_X_SIZE_LOWER,
178 platform_data->x_size & 0xff);
179 i2c_smbus_write_byte_data(client, MCS5000_TS_Y_SIZE_UPPER,
180 platform_data->y_size >> 8);
181 i2c_smbus_write_byte_data(client, MCS5000_TS_Y_SIZE_LOWER,
182 platform_data->y_size & 0xff);
183
184 /* Touch active mode & 80 report rate */
185 i2c_smbus_write_byte_data(data->client, MCS5000_TS_OP_MODE,
186 OP_MODE_ACTIVE | REPORT_RATE_80);
187}
188
189static int __devinit mcs5000_ts_probe(struct i2c_client *client,
190 const struct i2c_device_id *id)
191{
192 struct mcs5000_ts_data *data;
193 struct input_dev *input_dev;
194 int ret;
195
196 if (!client->dev.platform_data)
197 return -EINVAL;
198
199 data = kzalloc(sizeof(struct mcs5000_ts_data), GFP_KERNEL);
200 input_dev = input_allocate_device();
201 if (!data || !input_dev) {
202 dev_err(&client->dev, "Failed to allocate memory\n");
203 ret = -ENOMEM;
204 goto err_free_mem;
205 }
206
207 data->client = client;
208 data->input_dev = input_dev;
209 data->platform_data = client->dev.platform_data;
210
211 input_dev->name = "MELPAS MCS-5000 Touchscreen";
212 input_dev->id.bustype = BUS_I2C;
213 input_dev->dev.parent = &client->dev;
214
215 __set_bit(EV_ABS, input_dev->evbit);
216 __set_bit(EV_KEY, input_dev->evbit);
217 __set_bit(BTN_TOUCH, input_dev->keybit);
218 input_set_abs_params(input_dev, ABS_X, 0, MCS5000_MAX_XC, 0, 0);
219 input_set_abs_params(input_dev, ABS_Y, 0, MCS5000_MAX_YC, 0, 0);
220
221 input_set_drvdata(input_dev, data);
222
223 if (data->platform_data->cfg_pin)
224 data->platform_data->cfg_pin();
225
226 ret = request_threaded_irq(client->irq, NULL, mcs5000_ts_interrupt,
227 IRQF_TRIGGER_LOW | IRQF_ONESHOT, "mcs5000_ts", data);
228
229 if (ret < 0) {
230 dev_err(&client->dev, "Failed to register interrupt\n");
231 goto err_free_mem;
232 }
233
234 ret = input_register_device(data->input_dev);
235 if (ret < 0)
236 goto err_free_irq;
237
238 mcs5000_ts_phys_init(data);
239 i2c_set_clientdata(client, data);
240
241 return 0;
242
243err_free_irq:
244 free_irq(client->irq, data);
245err_free_mem:
246 input_free_device(input_dev);
247 kfree(data);
248 return ret;
249}
250
251static int __devexit mcs5000_ts_remove(struct i2c_client *client)
252{
253 struct mcs5000_ts_data *data = i2c_get_clientdata(client);
254
255 free_irq(client->irq, data);
256 input_unregister_device(data->input_dev);
257 kfree(data);
258 i2c_set_clientdata(client, NULL);
259
260 return 0;
261}
262
263#ifdef CONFIG_PM
264static int mcs5000_ts_suspend(struct i2c_client *client, pm_message_t mesg)
265{
266 /* Touch sleep mode */
267 i2c_smbus_write_byte_data(client, MCS5000_TS_OP_MODE, OP_MODE_SLEEP);
268
269 return 0;
270}
271
272static int mcs5000_ts_resume(struct i2c_client *client)
273{
274 struct mcs5000_ts_data *data = i2c_get_clientdata(client);
275
276 mcs5000_ts_phys_init(data);
277
278 return 0;
279}
280#else
281#define mcs5000_ts_suspend NULL
282#define mcs5000_ts_resume NULL
283#endif
284
285static const struct i2c_device_id mcs5000_ts_id[] = {
286 { "mcs5000_ts", 0 },
287 { }
288};
289MODULE_DEVICE_TABLE(i2c, mcs5000_ts_id);
290
291static struct i2c_driver mcs5000_ts_driver = {
292 .probe = mcs5000_ts_probe,
293 .remove = __devexit_p(mcs5000_ts_remove),
294 .suspend = mcs5000_ts_suspend,
295 .resume = mcs5000_ts_resume,
296 .driver = {
297 .name = "mcs5000_ts",
298 },
299 .id_table = mcs5000_ts_id,
300};
301
302static int __init mcs5000_ts_init(void)
303{
304 return i2c_add_driver(&mcs5000_ts_driver);
305}
306
307static void __exit mcs5000_ts_exit(void)
308{
309 i2c_del_driver(&mcs5000_ts_driver);
310}
311
312module_init(mcs5000_ts_init);
313module_exit(mcs5000_ts_exit);
314
315/* Module information */
316MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
317MODULE_DESCRIPTION("Touchscreen driver for MELFAS MCS-5000 controller");
318MODULE_LICENSE("GPL");
diff --git a/include/linux/i2c/mcs5000_ts.h b/include/linux/i2c/mcs5000_ts.h
new file mode 100644
index 00000000000..5a117b5ca15
--- /dev/null
+++ b/include/linux/i2c/mcs5000_ts.h
@@ -0,0 +1,24 @@
1/*
2 * mcs5000_ts.h
3 *
4 * Copyright (C) 2009 Samsung Electronics Co.Ltd
5 * Author: Joonyoung Shim <jy0922.shim@samsung.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 */
13
14#ifndef __LINUX_MCS5000_TS_H
15#define __LINUX_MCS5000_TS_H
16
17/* platform data for the MELFAS MCS-5000 touchscreen driver */
18struct mcs5000_ts_platform_data {
19 void (*cfg_pin)(void);
20 int x_size;
21 int y_size;
22};
23
24#endif /* __LINUX_MCS5000_TS_H */