10 #include <linux/module.h>
13 #include <linux/i2c.h>
18 #include <linux/slab.h>
21 #define MMS114_MODE_CONTROL 0x01
22 #define MMS114_OPERATION_MODE_MASK 0xE
23 #define MMS114_ACTIVE (1 << 1)
25 #define MMS114_XY_RESOLUTION_H 0x02
26 #define MMS114_X_RESOLUTION 0x03
27 #define MMS114_Y_RESOLUTION 0x04
28 #define MMS114_CONTACT_THRESHOLD 0x05
29 #define MMS114_MOVING_THRESHOLD 0x06
32 #define MMS114_PACKET_SIZE 0x0F
33 #define MMS114_INFOMATION 0x10
34 #define MMS114_TSP_REV 0xF0
37 #define MMS114_I2C_DELAY 50
40 #define MMS114_POWERON_DELAY 200
43 #define MMS114_MAX_AREA 0xff
45 #define MMS114_MAX_TOUCH 10
46 #define MMS114_PACKET_NUM 8
49 #define MMS114_TYPE_NONE 0
50 #define MMS114_TYPE_TOUCHSCREEN 1
51 #define MMS114_TYPE_TOUCHKEY 2
75 unsigned int len,
u8 *
val)
100 "%s: i2c transfer failed (%d)\n", __func__, error);
101 return error < 0 ? error : -
EIO;
116 error = __mms114_read_reg(data, reg, 1, &val);
117 return error < 0 ? error :
val;
120 static int mms114_write_reg(
struct mms114_data *data,
unsigned int reg,
133 "%s: i2c send failed (%d)\n", __func__, error);
134 return error < 0 ? error : -
EIO;
148 struct input_dev *input_dev = data->
input_dev;
154 dev_err(&client->
dev,
"Wrong touch id (%d)\n", touch->
id);
168 "Wrong touch coordinates (%d, %d)\n", x, y);
178 "id: %d, type: %d, pressed: %d, x: %d, y: %d, width: %d, strength: %d\n",
196 struct input_dev *input_dev = data->
input_dev;
204 if (!input_dev->users) {
211 if (packet_size <= 0)
221 for (index = 0; index < touch_size; index++)
222 mms114_process_mt(data, touch + index);
248 static int mms114_get_version(
struct mms114_data *data)
258 dev_info(dev,
"TSP Rev: 0x%x, HW Rev: 0x%x, Firmware Ver: 0x%x\n",
259 buf[0], buf[1], buf[3]);
264 static int mms114_setup_regs(
struct mms114_data *data)
270 error = mms114_get_version(data);
274 error = mms114_set_active(data,
true);
278 val = (pdata->
x_size >> 8) & 0xf;
279 val |= ((pdata->
y_size >> 8) & 0xf) << 4;
284 val = pdata->
x_size & 0xff;
289 val = pdata->
y_size & 0xff;
322 error = mms114_setup_regs(data);
326 if (data->
pdata->cfg_pin)
327 data->
pdata->cfg_pin(
true);
340 if (data->
pdata->cfg_pin)
341 data->
pdata->cfg_pin(
false);
349 static int mms114_input_open(
struct input_dev *dev)
353 return mms114_start(data);
356 static void mms114_input_close(
struct input_dev *dev)
367 struct input_dev *input_dev;
370 if (!client->
dev.platform_data) {
371 dev_err(&client->
dev,
"Need platform data\n");
375 if (!i2c_check_functionality(client->
adapter,
378 "Need i2c bus that supports protocol mangling\n");
383 input_dev = input_allocate_device();
384 if (!data || !input_dev) {
385 dev_err(&client->
dev,
"Failed to allocate memory\n");
392 data->
pdata = client->
dev.platform_data;
394 input_dev->name =
"MELPAS MMS114 Touchscreen";
395 input_dev->id.bustype =
BUS_I2C;
396 input_dev->dev.parent = &client->
dev;
397 input_dev->open = mms114_input_open;
398 input_dev->close = mms114_input_close;
403 input_set_abs_params(input_dev,
ABS_X, 0, data->
pdata->x_size, 0, 0);
404 input_set_abs_params(input_dev,
ABS_Y, 0, data->
pdata->y_size, 0, 0);
411 0, data->
pdata->x_size, 0, 0);
413 0, data->
pdata->y_size, 0, 0);
416 input_set_drvdata(input_dev, data);
417 i2c_set_clientdata(client, data);
423 "Unable to get the Core regulator (%d)\n", error);
428 if (IS_ERR(data->
io_reg)) {
429 error = PTR_ERR(data->
io_reg);
431 "Unable to get the IO regulator (%d)\n", error);
438 dev_err(&client->
dev,
"Failed to register interrupt\n");
443 error = input_register_device(data->
input_dev);
456 input_free_device(input_dev);
463 struct mms114_data *data = i2c_get_clientdata(client);
468 input_unregister_device(data->
input_dev);
474 #ifdef CONFIG_PM_SLEEP
475 static int mms114_suspend(
struct device *dev)
478 struct mms114_data *data = i2c_get_clientdata(client);
479 struct input_dev *input_dev = data->
input_dev;
489 input_sync(input_dev);
492 if (input_dev->users)
499 static int mms114_resume(
struct device *dev)
502 struct mms114_data *data = i2c_get_clientdata(client);
503 struct input_dev *input_dev = data->
input_dev;
507 if (input_dev->users) {
508 error = mms114_start(data);
532 .pm = &mms114_pm_ops,
534 .probe = mms114_probe,
536 .id_table = mms114_id,