0001
0002
0003
0004
0005
0006
0007 #include <linux/delay.h>
0008 #include <linux/i2c.h>
0009 #include <linux/input/mt.h>
0010 #include <linux/input/touchscreen.h>
0011 #include <linux/interrupt.h>
0012 #include <linux/irq.h>
0013 #include <linux/leds.h>
0014 #include <linux/module.h>
0015 #include <linux/pm_runtime.h>
0016 #include <linux/regulator/consumer.h>
0017
0018
0019 #define STMFTS_READ_INFO 0x80
0020 #define STMFTS_READ_STATUS 0x84
0021 #define STMFTS_READ_ONE_EVENT 0x85
0022 #define STMFTS_READ_ALL_EVENT 0x86
0023 #define STMFTS_LATEST_EVENT 0x87
0024 #define STMFTS_SLEEP_IN 0x90
0025 #define STMFTS_SLEEP_OUT 0x91
0026 #define STMFTS_MS_MT_SENSE_OFF 0x92
0027 #define STMFTS_MS_MT_SENSE_ON 0x93
0028 #define STMFTS_SS_HOVER_SENSE_OFF 0x94
0029 #define STMFTS_SS_HOVER_SENSE_ON 0x95
0030 #define STMFTS_MS_KEY_SENSE_OFF 0x9a
0031 #define STMFTS_MS_KEY_SENSE_ON 0x9b
0032 #define STMFTS_SYSTEM_RESET 0xa0
0033 #define STMFTS_CLEAR_EVENT_STACK 0xa1
0034 #define STMFTS_FULL_FORCE_CALIBRATION 0xa2
0035 #define STMFTS_MS_CX_TUNING 0xa3
0036 #define STMFTS_SS_CX_TUNING 0xa4
0037
0038
0039 #define STMFTS_EV_NO_EVENT 0x00
0040 #define STMFTS_EV_MULTI_TOUCH_DETECTED 0x02
0041 #define STMFTS_EV_MULTI_TOUCH_ENTER 0x03
0042 #define STMFTS_EV_MULTI_TOUCH_LEAVE 0x04
0043 #define STMFTS_EV_MULTI_TOUCH_MOTION 0x05
0044 #define STMFTS_EV_HOVER_ENTER 0x07
0045 #define STMFTS_EV_HOVER_LEAVE 0x08
0046 #define STMFTS_EV_HOVER_MOTION 0x09
0047 #define STMFTS_EV_KEY_STATUS 0x0e
0048 #define STMFTS_EV_ERROR 0x0f
0049 #define STMFTS_EV_CONTROLLER_READY 0x10
0050 #define STMFTS_EV_SLEEP_OUT_CONTROLLER_READY 0x11
0051 #define STMFTS_EV_STATUS 0x16
0052 #define STMFTS_EV_DEBUG 0xdb
0053
0054
0055 #define STMFTS_MASK_EVENT_ID 0x0f
0056 #define STMFTS_MASK_TOUCH_ID 0xf0
0057 #define STMFTS_MASK_LEFT_EVENT 0x0f
0058 #define STMFTS_MASK_X_MSB 0x0f
0059 #define STMFTS_MASK_Y_LSB 0xf0
0060
0061
0062 #define STMFTS_MASK_KEY_NO_TOUCH 0x00
0063 #define STMFTS_MASK_KEY_MENU 0x01
0064 #define STMFTS_MASK_KEY_BACK 0x02
0065
0066 #define STMFTS_EVENT_SIZE 8
0067 #define STMFTS_STACK_DEPTH 32
0068 #define STMFTS_DATA_MAX_SIZE (STMFTS_EVENT_SIZE * STMFTS_STACK_DEPTH)
0069 #define STMFTS_MAX_FINGERS 10
0070 #define STMFTS_DEV_NAME "stmfts"
0071
0072 enum stmfts_regulators {
0073 STMFTS_REGULATOR_VDD,
0074 STMFTS_REGULATOR_AVDD,
0075 };
0076
0077 struct stmfts_data {
0078 struct i2c_client *client;
0079 struct input_dev *input;
0080 struct led_classdev led_cdev;
0081 struct mutex mutex;
0082
0083 struct touchscreen_properties prop;
0084
0085 struct regulator_bulk_data regulators[2];
0086
0087
0088
0089
0090
0091 struct regulator *ledvdd;
0092
0093 u16 chip_id;
0094 u8 chip_ver;
0095 u16 fw_ver;
0096 u8 config_id;
0097 u8 config_ver;
0098
0099 u8 data[STMFTS_DATA_MAX_SIZE];
0100
0101 struct completion cmd_done;
0102
0103 bool use_key;
0104 bool led_status;
0105 bool hover_enabled;
0106 bool running;
0107 };
0108
0109 static int stmfts_brightness_set(struct led_classdev *led_cdev,
0110 enum led_brightness value)
0111 {
0112 struct stmfts_data *sdata = container_of(led_cdev,
0113 struct stmfts_data, led_cdev);
0114 int err;
0115
0116 if (value != sdata->led_status && sdata->ledvdd) {
0117 if (!value) {
0118 regulator_disable(sdata->ledvdd);
0119 } else {
0120 err = regulator_enable(sdata->ledvdd);
0121 if (err) {
0122 dev_warn(&sdata->client->dev,
0123 "failed to disable ledvdd regulator: %d\n",
0124 err);
0125 return err;
0126 }
0127 }
0128 sdata->led_status = value;
0129 }
0130
0131 return 0;
0132 }
0133
0134 static enum led_brightness stmfts_brightness_get(struct led_classdev *led_cdev)
0135 {
0136 struct stmfts_data *sdata = container_of(led_cdev,
0137 struct stmfts_data, led_cdev);
0138
0139 return !!regulator_is_enabled(sdata->ledvdd);
0140 }
0141
0142
0143
0144
0145
0146 static int stmfts_read_events(struct stmfts_data *sdata)
0147 {
0148 u8 cmd = STMFTS_READ_ALL_EVENT;
0149 struct i2c_msg msgs[2] = {
0150 {
0151 .addr = sdata->client->addr,
0152 .len = 1,
0153 .buf = &cmd,
0154 },
0155 {
0156 .addr = sdata->client->addr,
0157 .flags = I2C_M_RD,
0158 .len = STMFTS_DATA_MAX_SIZE,
0159 .buf = sdata->data,
0160 },
0161 };
0162 int ret;
0163
0164 ret = i2c_transfer(sdata->client->adapter, msgs, ARRAY_SIZE(msgs));
0165 if (ret < 0)
0166 return ret;
0167
0168 return ret == ARRAY_SIZE(msgs) ? 0 : -EIO;
0169 }
0170
0171 static void stmfts_report_contact_event(struct stmfts_data *sdata,
0172 const u8 event[])
0173 {
0174 u8 slot_id = (event[0] & STMFTS_MASK_TOUCH_ID) >> 4;
0175 u16 x = event[1] | ((event[2] & STMFTS_MASK_X_MSB) << 8);
0176 u16 y = (event[2] >> 4) | (event[3] << 4);
0177 u8 maj = event[4];
0178 u8 min = event[5];
0179 u8 orientation = event[6];
0180 u8 area = event[7];
0181
0182 input_mt_slot(sdata->input, slot_id);
0183
0184 input_mt_report_slot_state(sdata->input, MT_TOOL_FINGER, true);
0185 input_report_abs(sdata->input, ABS_MT_POSITION_X, x);
0186 input_report_abs(sdata->input, ABS_MT_POSITION_Y, y);
0187 input_report_abs(sdata->input, ABS_MT_TOUCH_MAJOR, maj);
0188 input_report_abs(sdata->input, ABS_MT_TOUCH_MINOR, min);
0189 input_report_abs(sdata->input, ABS_MT_PRESSURE, area);
0190 input_report_abs(sdata->input, ABS_MT_ORIENTATION, orientation);
0191
0192 input_sync(sdata->input);
0193 }
0194
0195 static void stmfts_report_contact_release(struct stmfts_data *sdata,
0196 const u8 event[])
0197 {
0198 u8 slot_id = (event[0] & STMFTS_MASK_TOUCH_ID) >> 4;
0199
0200 input_mt_slot(sdata->input, slot_id);
0201 input_mt_report_slot_inactive(sdata->input);
0202
0203 input_sync(sdata->input);
0204 }
0205
0206 static void stmfts_report_hover_event(struct stmfts_data *sdata,
0207 const u8 event[])
0208 {
0209 u16 x = (event[2] << 4) | (event[4] >> 4);
0210 u16 y = (event[3] << 4) | (event[4] & STMFTS_MASK_Y_LSB);
0211 u8 z = event[5];
0212
0213 input_report_abs(sdata->input, ABS_X, x);
0214 input_report_abs(sdata->input, ABS_Y, y);
0215 input_report_abs(sdata->input, ABS_DISTANCE, z);
0216
0217 input_sync(sdata->input);
0218 }
0219
0220 static void stmfts_report_key_event(struct stmfts_data *sdata, const u8 event[])
0221 {
0222 switch (event[2]) {
0223 case 0:
0224 input_report_key(sdata->input, KEY_BACK, 0);
0225 input_report_key(sdata->input, KEY_MENU, 0);
0226 break;
0227
0228 case STMFTS_MASK_KEY_BACK:
0229 input_report_key(sdata->input, KEY_BACK, 1);
0230 break;
0231
0232 case STMFTS_MASK_KEY_MENU:
0233 input_report_key(sdata->input, KEY_MENU, 1);
0234 break;
0235
0236 default:
0237 dev_warn(&sdata->client->dev,
0238 "unknown key event: %#02x\n", event[2]);
0239 break;
0240 }
0241
0242 input_sync(sdata->input);
0243 }
0244
0245 static void stmfts_parse_events(struct stmfts_data *sdata)
0246 {
0247 int i;
0248
0249 for (i = 0; i < STMFTS_STACK_DEPTH; i++) {
0250 u8 *event = &sdata->data[i * STMFTS_EVENT_SIZE];
0251
0252 switch (event[0]) {
0253
0254 case STMFTS_EV_CONTROLLER_READY:
0255 case STMFTS_EV_SLEEP_OUT_CONTROLLER_READY:
0256 case STMFTS_EV_STATUS:
0257 complete(&sdata->cmd_done);
0258 fallthrough;
0259
0260 case STMFTS_EV_NO_EVENT:
0261 case STMFTS_EV_DEBUG:
0262 return;
0263 }
0264
0265 switch (event[0] & STMFTS_MASK_EVENT_ID) {
0266
0267 case STMFTS_EV_MULTI_TOUCH_ENTER:
0268 case STMFTS_EV_MULTI_TOUCH_MOTION:
0269 stmfts_report_contact_event(sdata, event);
0270 break;
0271
0272 case STMFTS_EV_MULTI_TOUCH_LEAVE:
0273 stmfts_report_contact_release(sdata, event);
0274 break;
0275
0276 case STMFTS_EV_HOVER_ENTER:
0277 case STMFTS_EV_HOVER_LEAVE:
0278 case STMFTS_EV_HOVER_MOTION:
0279 stmfts_report_hover_event(sdata, event);
0280 break;
0281
0282 case STMFTS_EV_KEY_STATUS:
0283 stmfts_report_key_event(sdata, event);
0284 break;
0285
0286 case STMFTS_EV_ERROR:
0287 dev_warn(&sdata->client->dev,
0288 "error code: 0x%x%x%x%x%x%x",
0289 event[6], event[5], event[4],
0290 event[3], event[2], event[1]);
0291 break;
0292
0293 default:
0294 dev_err(&sdata->client->dev,
0295 "unknown event %#02x\n", event[0]);
0296 }
0297 }
0298 }
0299
0300 static irqreturn_t stmfts_irq_handler(int irq, void *dev)
0301 {
0302 struct stmfts_data *sdata = dev;
0303 int err;
0304
0305 mutex_lock(&sdata->mutex);
0306
0307 err = stmfts_read_events(sdata);
0308 if (unlikely(err))
0309 dev_err(&sdata->client->dev,
0310 "failed to read events: %d\n", err);
0311 else
0312 stmfts_parse_events(sdata);
0313
0314 mutex_unlock(&sdata->mutex);
0315 return IRQ_HANDLED;
0316 }
0317
0318 static int stmfts_command(struct stmfts_data *sdata, const u8 cmd)
0319 {
0320 int err;
0321
0322 reinit_completion(&sdata->cmd_done);
0323
0324 err = i2c_smbus_write_byte(sdata->client, cmd);
0325 if (err)
0326 return err;
0327
0328 if (!wait_for_completion_timeout(&sdata->cmd_done,
0329 msecs_to_jiffies(1000)))
0330 return -ETIMEDOUT;
0331
0332 return 0;
0333 }
0334
0335 static int stmfts_input_open(struct input_dev *dev)
0336 {
0337 struct stmfts_data *sdata = input_get_drvdata(dev);
0338 int err;
0339
0340 err = pm_runtime_resume_and_get(&sdata->client->dev);
0341 if (err)
0342 return err;
0343
0344 err = i2c_smbus_write_byte(sdata->client, STMFTS_MS_MT_SENSE_ON);
0345 if (err) {
0346 pm_runtime_put_sync(&sdata->client->dev);
0347 return err;
0348 }
0349
0350 mutex_lock(&sdata->mutex);
0351 sdata->running = true;
0352
0353 if (sdata->hover_enabled) {
0354 err = i2c_smbus_write_byte(sdata->client,
0355 STMFTS_SS_HOVER_SENSE_ON);
0356 if (err)
0357 dev_warn(&sdata->client->dev,
0358 "failed to enable hover\n");
0359 }
0360 mutex_unlock(&sdata->mutex);
0361
0362 if (sdata->use_key) {
0363 err = i2c_smbus_write_byte(sdata->client,
0364 STMFTS_MS_KEY_SENSE_ON);
0365 if (err)
0366
0367 dev_warn(&sdata->client->dev,
0368 "failed to enable touchkey\n");
0369 }
0370
0371 return 0;
0372 }
0373
0374 static void stmfts_input_close(struct input_dev *dev)
0375 {
0376 struct stmfts_data *sdata = input_get_drvdata(dev);
0377 int err;
0378
0379 err = i2c_smbus_write_byte(sdata->client, STMFTS_MS_MT_SENSE_OFF);
0380 if (err)
0381 dev_warn(&sdata->client->dev,
0382 "failed to disable touchscreen: %d\n", err);
0383
0384 mutex_lock(&sdata->mutex);
0385
0386 sdata->running = false;
0387
0388 if (sdata->hover_enabled) {
0389 err = i2c_smbus_write_byte(sdata->client,
0390 STMFTS_SS_HOVER_SENSE_OFF);
0391 if (err)
0392 dev_warn(&sdata->client->dev,
0393 "failed to disable hover: %d\n", err);
0394 }
0395 mutex_unlock(&sdata->mutex);
0396
0397 if (sdata->use_key) {
0398 err = i2c_smbus_write_byte(sdata->client,
0399 STMFTS_MS_KEY_SENSE_OFF);
0400 if (err)
0401 dev_warn(&sdata->client->dev,
0402 "failed to disable touchkey: %d\n", err);
0403 }
0404
0405 pm_runtime_put_sync(&sdata->client->dev);
0406 }
0407
0408 static ssize_t stmfts_sysfs_chip_id(struct device *dev,
0409 struct device_attribute *attr, char *buf)
0410 {
0411 struct stmfts_data *sdata = dev_get_drvdata(dev);
0412
0413 return sprintf(buf, "%#x\n", sdata->chip_id);
0414 }
0415
0416 static ssize_t stmfts_sysfs_chip_version(struct device *dev,
0417 struct device_attribute *attr, char *buf)
0418 {
0419 struct stmfts_data *sdata = dev_get_drvdata(dev);
0420
0421 return sprintf(buf, "%u\n", sdata->chip_ver);
0422 }
0423
0424 static ssize_t stmfts_sysfs_fw_ver(struct device *dev,
0425 struct device_attribute *attr, char *buf)
0426 {
0427 struct stmfts_data *sdata = dev_get_drvdata(dev);
0428
0429 return sprintf(buf, "%u\n", sdata->fw_ver);
0430 }
0431
0432 static ssize_t stmfts_sysfs_config_id(struct device *dev,
0433 struct device_attribute *attr, char *buf)
0434 {
0435 struct stmfts_data *sdata = dev_get_drvdata(dev);
0436
0437 return sprintf(buf, "%#x\n", sdata->config_id);
0438 }
0439
0440 static ssize_t stmfts_sysfs_config_version(struct device *dev,
0441 struct device_attribute *attr, char *buf)
0442 {
0443 struct stmfts_data *sdata = dev_get_drvdata(dev);
0444
0445 return sprintf(buf, "%u\n", sdata->config_ver);
0446 }
0447
0448 static ssize_t stmfts_sysfs_read_status(struct device *dev,
0449 struct device_attribute *attr, char *buf)
0450 {
0451 struct stmfts_data *sdata = dev_get_drvdata(dev);
0452 u8 status[4];
0453 int err;
0454
0455 err = i2c_smbus_read_i2c_block_data(sdata->client, STMFTS_READ_STATUS,
0456 sizeof(status), status);
0457 if (err)
0458 return err;
0459
0460 return sprintf(buf, "%#02x\n", status[0]);
0461 }
0462
0463 static ssize_t stmfts_sysfs_hover_enable_read(struct device *dev,
0464 struct device_attribute *attr, char *buf)
0465 {
0466 struct stmfts_data *sdata = dev_get_drvdata(dev);
0467
0468 return sprintf(buf, "%u\n", sdata->hover_enabled);
0469 }
0470
0471 static ssize_t stmfts_sysfs_hover_enable_write(struct device *dev,
0472 struct device_attribute *attr,
0473 const char *buf, size_t len)
0474 {
0475 struct stmfts_data *sdata = dev_get_drvdata(dev);
0476 unsigned long value;
0477 int err = 0;
0478
0479 if (kstrtoul(buf, 0, &value))
0480 return -EINVAL;
0481
0482 mutex_lock(&sdata->mutex);
0483
0484 if (value && sdata->hover_enabled)
0485 goto out;
0486
0487 if (sdata->running)
0488 err = i2c_smbus_write_byte(sdata->client,
0489 value ? STMFTS_SS_HOVER_SENSE_ON :
0490 STMFTS_SS_HOVER_SENSE_OFF);
0491
0492 if (!err)
0493 sdata->hover_enabled = !!value;
0494
0495 out:
0496 mutex_unlock(&sdata->mutex);
0497
0498 return len;
0499 }
0500
0501 static DEVICE_ATTR(chip_id, 0444, stmfts_sysfs_chip_id, NULL);
0502 static DEVICE_ATTR(chip_version, 0444, stmfts_sysfs_chip_version, NULL);
0503 static DEVICE_ATTR(fw_ver, 0444, stmfts_sysfs_fw_ver, NULL);
0504 static DEVICE_ATTR(config_id, 0444, stmfts_sysfs_config_id, NULL);
0505 static DEVICE_ATTR(config_version, 0444, stmfts_sysfs_config_version, NULL);
0506 static DEVICE_ATTR(status, 0444, stmfts_sysfs_read_status, NULL);
0507 static DEVICE_ATTR(hover_enable, 0644, stmfts_sysfs_hover_enable_read,
0508 stmfts_sysfs_hover_enable_write);
0509
0510 static struct attribute *stmfts_sysfs_attrs[] = {
0511 &dev_attr_chip_id.attr,
0512 &dev_attr_chip_version.attr,
0513 &dev_attr_fw_ver.attr,
0514 &dev_attr_config_id.attr,
0515 &dev_attr_config_version.attr,
0516 &dev_attr_status.attr,
0517 &dev_attr_hover_enable.attr,
0518 NULL
0519 };
0520
0521 static struct attribute_group stmfts_attribute_group = {
0522 .attrs = stmfts_sysfs_attrs
0523 };
0524
0525 static int stmfts_power_on(struct stmfts_data *sdata)
0526 {
0527 int err;
0528 u8 reg[8];
0529
0530 err = regulator_bulk_enable(ARRAY_SIZE(sdata->regulators),
0531 sdata->regulators);
0532 if (err)
0533 return err;
0534
0535
0536
0537
0538
0539 msleep(20);
0540
0541 err = i2c_smbus_read_i2c_block_data(sdata->client, STMFTS_READ_INFO,
0542 sizeof(reg), reg);
0543 if (err < 0)
0544 return err;
0545 if (err != sizeof(reg))
0546 return -EIO;
0547
0548 sdata->chip_id = be16_to_cpup((__be16 *)®[6]);
0549 sdata->chip_ver = reg[0];
0550 sdata->fw_ver = be16_to_cpup((__be16 *)®[2]);
0551 sdata->config_id = reg[4];
0552 sdata->config_ver = reg[5];
0553
0554 enable_irq(sdata->client->irq);
0555
0556 msleep(50);
0557
0558 err = stmfts_command(sdata, STMFTS_SYSTEM_RESET);
0559 if (err)
0560 return err;
0561
0562 err = stmfts_command(sdata, STMFTS_SLEEP_OUT);
0563 if (err)
0564 return err;
0565
0566
0567 err = stmfts_command(sdata, STMFTS_MS_CX_TUNING);
0568 if (err)
0569 dev_warn(&sdata->client->dev,
0570 "failed to perform mutual auto tune: %d\n", err);
0571
0572
0573 err = stmfts_command(sdata, STMFTS_SS_CX_TUNING);
0574 if (err)
0575 dev_warn(&sdata->client->dev,
0576 "failed to perform self auto tune: %d\n", err);
0577
0578 err = stmfts_command(sdata, STMFTS_FULL_FORCE_CALIBRATION);
0579 if (err)
0580 return err;
0581
0582
0583
0584
0585
0586 (void) i2c_smbus_write_byte(sdata->client, STMFTS_SLEEP_IN);
0587
0588 return 0;
0589 }
0590
0591 static void stmfts_power_off(void *data)
0592 {
0593 struct stmfts_data *sdata = data;
0594
0595 disable_irq(sdata->client->irq);
0596 regulator_bulk_disable(ARRAY_SIZE(sdata->regulators),
0597 sdata->regulators);
0598 }
0599
0600
0601
0602
0603 static int stmfts_enable_led(struct stmfts_data *sdata)
0604 {
0605 int err;
0606
0607
0608 sdata->ledvdd = devm_regulator_get(&sdata->client->dev, "ledvdd");
0609 if (IS_ERR(sdata->ledvdd))
0610 return PTR_ERR(sdata->ledvdd);
0611
0612 sdata->led_cdev.name = STMFTS_DEV_NAME;
0613 sdata->led_cdev.max_brightness = LED_ON;
0614 sdata->led_cdev.brightness = LED_OFF;
0615 sdata->led_cdev.brightness_set_blocking = stmfts_brightness_set;
0616 sdata->led_cdev.brightness_get = stmfts_brightness_get;
0617
0618 err = devm_led_classdev_register(&sdata->client->dev, &sdata->led_cdev);
0619 if (err) {
0620 devm_regulator_put(sdata->ledvdd);
0621 return err;
0622 }
0623
0624 return 0;
0625 }
0626
0627 static int stmfts_probe(struct i2c_client *client,
0628 const struct i2c_device_id *id)
0629 {
0630 int err;
0631 struct stmfts_data *sdata;
0632
0633 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C |
0634 I2C_FUNC_SMBUS_BYTE_DATA |
0635 I2C_FUNC_SMBUS_I2C_BLOCK))
0636 return -ENODEV;
0637
0638 sdata = devm_kzalloc(&client->dev, sizeof(*sdata), GFP_KERNEL);
0639 if (!sdata)
0640 return -ENOMEM;
0641
0642 i2c_set_clientdata(client, sdata);
0643
0644 sdata->client = client;
0645 mutex_init(&sdata->mutex);
0646 init_completion(&sdata->cmd_done);
0647
0648 sdata->regulators[STMFTS_REGULATOR_VDD].supply = "vdd";
0649 sdata->regulators[STMFTS_REGULATOR_AVDD].supply = "avdd";
0650 err = devm_regulator_bulk_get(&client->dev,
0651 ARRAY_SIZE(sdata->regulators),
0652 sdata->regulators);
0653 if (err)
0654 return err;
0655
0656 sdata->input = devm_input_allocate_device(&client->dev);
0657 if (!sdata->input)
0658 return -ENOMEM;
0659
0660 sdata->input->name = STMFTS_DEV_NAME;
0661 sdata->input->id.bustype = BUS_I2C;
0662 sdata->input->open = stmfts_input_open;
0663 sdata->input->close = stmfts_input_close;
0664
0665 input_set_capability(sdata->input, EV_ABS, ABS_MT_POSITION_X);
0666 input_set_capability(sdata->input, EV_ABS, ABS_MT_POSITION_Y);
0667 touchscreen_parse_properties(sdata->input, true, &sdata->prop);
0668
0669 input_set_abs_params(sdata->input, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
0670 input_set_abs_params(sdata->input, ABS_MT_TOUCH_MINOR, 0, 255, 0, 0);
0671 input_set_abs_params(sdata->input, ABS_MT_ORIENTATION, 0, 255, 0, 0);
0672 input_set_abs_params(sdata->input, ABS_MT_PRESSURE, 0, 255, 0, 0);
0673 input_set_abs_params(sdata->input, ABS_DISTANCE, 0, 255, 0, 0);
0674
0675 sdata->use_key = device_property_read_bool(&client->dev,
0676 "touch-key-connected");
0677 if (sdata->use_key) {
0678 input_set_capability(sdata->input, EV_KEY, KEY_MENU);
0679 input_set_capability(sdata->input, EV_KEY, KEY_BACK);
0680 }
0681
0682 err = input_mt_init_slots(sdata->input,
0683 STMFTS_MAX_FINGERS, INPUT_MT_DIRECT);
0684 if (err)
0685 return err;
0686
0687 input_set_drvdata(sdata->input, sdata);
0688
0689
0690
0691
0692
0693
0694
0695
0696 err = devm_request_threaded_irq(&client->dev, client->irq,
0697 NULL, stmfts_irq_handler,
0698 IRQF_ONESHOT | IRQF_NO_AUTOEN,
0699 "stmfts_irq", sdata);
0700 if (err)
0701 return err;
0702
0703 dev_dbg(&client->dev, "initializing ST-Microelectronics FTS...\n");
0704
0705 err = stmfts_power_on(sdata);
0706 if (err)
0707 return err;
0708
0709 err = devm_add_action_or_reset(&client->dev, stmfts_power_off, sdata);
0710 if (err)
0711 return err;
0712
0713 err = input_register_device(sdata->input);
0714 if (err)
0715 return err;
0716
0717 if (sdata->use_key) {
0718 err = stmfts_enable_led(sdata);
0719 if (err) {
0720
0721
0722
0723
0724
0725
0726 dev_warn(&client->dev, "unable to use touchkey leds\n");
0727 sdata->ledvdd = NULL;
0728 }
0729 }
0730
0731 err = devm_device_add_group(&client->dev, &stmfts_attribute_group);
0732 if (err)
0733 return err;
0734
0735 pm_runtime_enable(&client->dev);
0736 device_enable_async_suspend(&client->dev);
0737
0738 return 0;
0739 }
0740
0741 static int stmfts_remove(struct i2c_client *client)
0742 {
0743 pm_runtime_disable(&client->dev);
0744
0745 return 0;
0746 }
0747
0748 static int __maybe_unused stmfts_runtime_suspend(struct device *dev)
0749 {
0750 struct stmfts_data *sdata = dev_get_drvdata(dev);
0751 int ret;
0752
0753 ret = i2c_smbus_write_byte(sdata->client, STMFTS_SLEEP_IN);
0754 if (ret)
0755 dev_warn(dev, "failed to suspend device: %d\n", ret);
0756
0757 return ret;
0758 }
0759
0760 static int __maybe_unused stmfts_runtime_resume(struct device *dev)
0761 {
0762 struct stmfts_data *sdata = dev_get_drvdata(dev);
0763 int ret;
0764
0765 ret = i2c_smbus_write_byte(sdata->client, STMFTS_SLEEP_OUT);
0766 if (ret)
0767 dev_err(dev, "failed to resume device: %d\n", ret);
0768
0769 return ret;
0770 }
0771
0772 static int __maybe_unused stmfts_suspend(struct device *dev)
0773 {
0774 struct stmfts_data *sdata = dev_get_drvdata(dev);
0775
0776 stmfts_power_off(sdata);
0777
0778 return 0;
0779 }
0780
0781 static int __maybe_unused stmfts_resume(struct device *dev)
0782 {
0783 struct stmfts_data *sdata = dev_get_drvdata(dev);
0784
0785 return stmfts_power_on(sdata);
0786 }
0787
0788 static const struct dev_pm_ops stmfts_pm_ops = {
0789 SET_SYSTEM_SLEEP_PM_OPS(stmfts_suspend, stmfts_resume)
0790 SET_RUNTIME_PM_OPS(stmfts_runtime_suspend, stmfts_runtime_resume, NULL)
0791 };
0792
0793 #ifdef CONFIG_OF
0794 static const struct of_device_id stmfts_of_match[] = {
0795 { .compatible = "st,stmfts", },
0796 { },
0797 };
0798 MODULE_DEVICE_TABLE(of, stmfts_of_match);
0799 #endif
0800
0801 static const struct i2c_device_id stmfts_id[] = {
0802 { "stmfts", 0 },
0803 { },
0804 };
0805 MODULE_DEVICE_TABLE(i2c, stmfts_id);
0806
0807 static struct i2c_driver stmfts_driver = {
0808 .driver = {
0809 .name = STMFTS_DEV_NAME,
0810 .of_match_table = of_match_ptr(stmfts_of_match),
0811 .pm = &stmfts_pm_ops,
0812 .probe_type = PROBE_PREFER_ASYNCHRONOUS,
0813 },
0814 .probe = stmfts_probe,
0815 .remove = stmfts_remove,
0816 .id_table = stmfts_id,
0817 };
0818
0819 module_i2c_driver(stmfts_driver);
0820
0821 MODULE_AUTHOR("Andi Shyti <andi.shyti@samsung.com>");
0822 MODULE_DESCRIPTION("STMicroelectronics FTS Touch Screen");
0823 MODULE_LICENSE("GPL v2");