1 // SPDX-License-Identifier: GPL-2.0
2 // STMicroelectronics FTS Touchscreen device driver
4 // Copyright (c) 2017 Samsung Electronics Co., Ltd.
5 // Copyright (c) 2017 Andi Shyti <andi@etezian.org>
7 #include <linux/delay.h>
9 #include <linux/input/mt.h>
10 #include <linux/input/touchscreen.h>
11 #include <linux/interrupt.h>
12 #include <linux/irq.h>
13 #include <linux/leds.h>
14 #include <linux/module.h>
15 #include <linux/pm_runtime.h>
16 #include <linux/regulator/consumer.h>
19 #define STMFTS_READ_INFO 0x80
20 #define STMFTS_READ_STATUS 0x84
21 #define STMFTS_READ_ONE_EVENT 0x85
22 #define STMFTS_READ_ALL_EVENT 0x86
23 #define STMFTS_LATEST_EVENT 0x87
24 #define STMFTS_SLEEP_IN 0x90
25 #define STMFTS_SLEEP_OUT 0x91
26 #define STMFTS_MS_MT_SENSE_OFF 0x92
27 #define STMFTS_MS_MT_SENSE_ON 0x93
28 #define STMFTS_SS_HOVER_SENSE_OFF 0x94
29 #define STMFTS_SS_HOVER_SENSE_ON 0x95
30 #define STMFTS_MS_KEY_SENSE_OFF 0x9a
31 #define STMFTS_MS_KEY_SENSE_ON 0x9b
32 #define STMFTS_SYSTEM_RESET 0xa0
33 #define STMFTS_CLEAR_EVENT_STACK 0xa1
34 #define STMFTS_FULL_FORCE_CALIBRATION 0xa2
35 #define STMFTS_MS_CX_TUNING 0xa3
36 #define STMFTS_SS_CX_TUNING 0xa4
39 #define STMFTS_EV_NO_EVENT 0x00
40 #define STMFTS_EV_MULTI_TOUCH_DETECTED 0x02
41 #define STMFTS_EV_MULTI_TOUCH_ENTER 0x03
42 #define STMFTS_EV_MULTI_TOUCH_LEAVE 0x04
43 #define STMFTS_EV_MULTI_TOUCH_MOTION 0x05
44 #define STMFTS_EV_HOVER_ENTER 0x07
45 #define STMFTS_EV_HOVER_LEAVE 0x08
46 #define STMFTS_EV_HOVER_MOTION 0x09
47 #define STMFTS_EV_KEY_STATUS 0x0e
48 #define STMFTS_EV_ERROR 0x0f
49 #define STMFTS_EV_CONTROLLER_READY 0x10
50 #define STMFTS_EV_SLEEP_OUT_CONTROLLER_READY 0x11
51 #define STMFTS_EV_STATUS 0x16
52 #define STMFTS_EV_DEBUG 0xdb
54 /* multi touch related event masks */
55 #define STMFTS_MASK_EVENT_ID 0x0f
56 #define STMFTS_MASK_TOUCH_ID 0xf0
57 #define STMFTS_MASK_LEFT_EVENT 0x0f
58 #define STMFTS_MASK_X_MSB 0x0f
59 #define STMFTS_MASK_Y_LSB 0xf0
61 /* key related event masks */
62 #define STMFTS_MASK_KEY_NO_TOUCH 0x00
63 #define STMFTS_MASK_KEY_MENU 0x01
64 #define STMFTS_MASK_KEY_BACK 0x02
66 #define STMFTS_EVENT_SIZE 8
67 #define STMFTS_STACK_DEPTH 32
68 #define STMFTS_DATA_MAX_SIZE (STMFTS_EVENT_SIZE * STMFTS_STACK_DEPTH)
69 #define STMFTS_MAX_FINGERS 10
70 #define STMFTS_DEV_NAME "stmfts"
72 enum stmfts_regulators
{
74 STMFTS_REGULATOR_AVDD
,
78 struct i2c_client
*client
;
79 struct input_dev
*input
;
80 struct led_classdev led_cdev
;
83 struct touchscreen_properties prop
;
85 struct regulator_bulk_data regulators
[2];
88 * Presence of ledvdd will be used also to check
89 * whether the LED is supported.
91 struct regulator
*ledvdd
;
99 u8 data
[STMFTS_DATA_MAX_SIZE
];
101 struct completion cmd_done
;
109 static int stmfts_brightness_set(struct led_classdev
*led_cdev
,
110 enum led_brightness value
)
112 struct stmfts_data
*sdata
= container_of(led_cdev
,
113 struct stmfts_data
, led_cdev
);
116 if (value
!= sdata
->led_status
&& sdata
->ledvdd
) {
118 regulator_disable(sdata
->ledvdd
);
120 err
= regulator_enable(sdata
->ledvdd
);
122 dev_warn(&sdata
->client
->dev
,
123 "failed to disable ledvdd regulator: %d\n",
128 sdata
->led_status
= value
;
134 static enum led_brightness
stmfts_brightness_get(struct led_classdev
*led_cdev
)
136 struct stmfts_data
*sdata
= container_of(led_cdev
,
137 struct stmfts_data
, led_cdev
);
139 return !!regulator_is_enabled(sdata
->ledvdd
);
143 * We can't simply use i2c_smbus_read_i2c_block_data because we
144 * need to read more than 255 bytes (
146 static int stmfts_read_events(struct stmfts_data
*sdata
)
148 u8 cmd
= STMFTS_READ_ALL_EVENT
;
149 struct i2c_msg msgs
[2] = {
151 .addr
= sdata
->client
->addr
,
156 .addr
= sdata
->client
->addr
,
158 .len
= STMFTS_DATA_MAX_SIZE
,
164 ret
= i2c_transfer(sdata
->client
->adapter
, msgs
, ARRAY_SIZE(msgs
));
168 return ret
== ARRAY_SIZE(msgs
) ? 0 : -EIO
;
171 static void stmfts_report_contact_event(struct stmfts_data
*sdata
,
174 u8 slot_id
= (event
[0] & STMFTS_MASK_TOUCH_ID
) >> 4;
175 u16 x
= event
[1] | ((event
[2] & STMFTS_MASK_X_MSB
) << 8);
176 u16 y
= (event
[2] >> 4) | (event
[3] << 4);
179 u8 orientation
= event
[6];
182 input_mt_slot(sdata
->input
, slot_id
);
184 input_mt_report_slot_state(sdata
->input
, MT_TOOL_FINGER
, true);
185 input_report_abs(sdata
->input
, ABS_MT_POSITION_X
, x
);
186 input_report_abs(sdata
->input
, ABS_MT_POSITION_Y
, y
);
187 input_report_abs(sdata
->input
, ABS_MT_TOUCH_MAJOR
, maj
);
188 input_report_abs(sdata
->input
, ABS_MT_TOUCH_MINOR
, min
);
189 input_report_abs(sdata
->input
, ABS_MT_PRESSURE
, area
);
190 input_report_abs(sdata
->input
, ABS_MT_ORIENTATION
, orientation
);
192 input_sync(sdata
->input
);
195 static void stmfts_report_contact_release(struct stmfts_data
*sdata
,
198 u8 slot_id
= (event
[0] & STMFTS_MASK_TOUCH_ID
) >> 4;
200 input_mt_slot(sdata
->input
, slot_id
);
201 input_mt_report_slot_state(sdata
->input
, MT_TOOL_FINGER
, false);
203 input_sync(sdata
->input
);
206 static void stmfts_report_hover_event(struct stmfts_data
*sdata
,
209 u16 x
= (event
[2] << 4) | (event
[4] >> 4);
210 u16 y
= (event
[3] << 4) | (event
[4] & STMFTS_MASK_Y_LSB
);
213 input_report_abs(sdata
->input
, ABS_X
, x
);
214 input_report_abs(sdata
->input
, ABS_Y
, y
);
215 input_report_abs(sdata
->input
, ABS_DISTANCE
, z
);
217 input_sync(sdata
->input
);
220 static void stmfts_report_key_event(struct stmfts_data
*sdata
, const u8 event
[])
224 input_report_key(sdata
->input
, KEY_BACK
, 0);
225 input_report_key(sdata
->input
, KEY_MENU
, 0);
228 case STMFTS_MASK_KEY_BACK
:
229 input_report_key(sdata
->input
, KEY_BACK
, 1);
232 case STMFTS_MASK_KEY_MENU
:
233 input_report_key(sdata
->input
, KEY_MENU
, 1);
237 dev_warn(&sdata
->client
->dev
,
238 "unknown key event: %#02x\n", event
[2]);
242 input_sync(sdata
->input
);
245 static void stmfts_parse_events(struct stmfts_data
*sdata
)
249 for (i
= 0; i
< STMFTS_STACK_DEPTH
; i
++) {
250 u8
*event
= &sdata
->data
[i
* STMFTS_EVENT_SIZE
];
254 case STMFTS_EV_CONTROLLER_READY
:
255 case STMFTS_EV_SLEEP_OUT_CONTROLLER_READY
:
256 case STMFTS_EV_STATUS
:
257 complete(&sdata
->cmd_done
);
260 case STMFTS_EV_NO_EVENT
:
261 case STMFTS_EV_DEBUG
:
265 switch (event
[0] & STMFTS_MASK_EVENT_ID
) {
267 case STMFTS_EV_MULTI_TOUCH_ENTER
:
268 case STMFTS_EV_MULTI_TOUCH_MOTION
:
269 stmfts_report_contact_event(sdata
, event
);
272 case STMFTS_EV_MULTI_TOUCH_LEAVE
:
273 stmfts_report_contact_release(sdata
, event
);
276 case STMFTS_EV_HOVER_ENTER
:
277 case STMFTS_EV_HOVER_LEAVE
:
278 case STMFTS_EV_HOVER_MOTION
:
279 stmfts_report_hover_event(sdata
, event
);
282 case STMFTS_EV_KEY_STATUS
:
283 stmfts_report_key_event(sdata
, event
);
286 case STMFTS_EV_ERROR
:
287 dev_warn(&sdata
->client
->dev
,
288 "error code: 0x%x%x%x%x%x%x",
289 event
[6], event
[5], event
[4],
290 event
[3], event
[2], event
[1]);
294 dev_err(&sdata
->client
->dev
,
295 "unknown event %#02x\n", event
[0]);
300 static irqreturn_t
stmfts_irq_handler(int irq
, void *dev
)
302 struct stmfts_data
*sdata
= dev
;
305 mutex_lock(&sdata
->mutex
);
307 err
= stmfts_read_events(sdata
);
309 dev_err(&sdata
->client
->dev
,
310 "failed to read events: %d\n", err
);
312 stmfts_parse_events(sdata
);
314 mutex_unlock(&sdata
->mutex
);
318 static int stmfts_command(struct stmfts_data
*sdata
, const u8 cmd
)
322 reinit_completion(&sdata
->cmd_done
);
324 err
= i2c_smbus_write_byte(sdata
->client
, cmd
);
328 if (!wait_for_completion_timeout(&sdata
->cmd_done
,
329 msecs_to_jiffies(1000)))
335 static int stmfts_input_open(struct input_dev
*dev
)
337 struct stmfts_data
*sdata
= input_get_drvdata(dev
);
340 err
= pm_runtime_get_sync(&sdata
->client
->dev
);
344 err
= i2c_smbus_write_byte(sdata
->client
, STMFTS_MS_MT_SENSE_ON
);
348 mutex_lock(&sdata
->mutex
);
349 sdata
->running
= true;
351 if (sdata
->hover_enabled
) {
352 err
= i2c_smbus_write_byte(sdata
->client
,
353 STMFTS_SS_HOVER_SENSE_ON
);
355 dev_warn(&sdata
->client
->dev
,
356 "failed to enable hover\n");
358 mutex_unlock(&sdata
->mutex
);
360 if (sdata
->use_key
) {
361 err
= i2c_smbus_write_byte(sdata
->client
,
362 STMFTS_MS_KEY_SENSE_ON
);
364 /* I can still use only the touch screen */
365 dev_warn(&sdata
->client
->dev
,
366 "failed to enable touchkey\n");
372 static void stmfts_input_close(struct input_dev
*dev
)
374 struct stmfts_data
*sdata
= input_get_drvdata(dev
);
377 err
= i2c_smbus_write_byte(sdata
->client
, STMFTS_MS_MT_SENSE_OFF
);
379 dev_warn(&sdata
->client
->dev
,
380 "failed to disable touchscreen: %d\n", err
);
382 mutex_lock(&sdata
->mutex
);
384 sdata
->running
= false;
386 if (sdata
->hover_enabled
) {
387 err
= i2c_smbus_write_byte(sdata
->client
,
388 STMFTS_SS_HOVER_SENSE_OFF
);
390 dev_warn(&sdata
->client
->dev
,
391 "failed to disable hover: %d\n", err
);
393 mutex_unlock(&sdata
->mutex
);
395 if (sdata
->use_key
) {
396 err
= i2c_smbus_write_byte(sdata
->client
,
397 STMFTS_MS_KEY_SENSE_OFF
);
399 dev_warn(&sdata
->client
->dev
,
400 "failed to disable touchkey: %d\n", err
);
403 pm_runtime_put_sync(&sdata
->client
->dev
);
406 static ssize_t
stmfts_sysfs_chip_id(struct device
*dev
,
407 struct device_attribute
*attr
, char *buf
)
409 struct stmfts_data
*sdata
= dev_get_drvdata(dev
);
411 return sprintf(buf
, "%#x\n", sdata
->chip_id
);
414 static ssize_t
stmfts_sysfs_chip_version(struct device
*dev
,
415 struct device_attribute
*attr
, char *buf
)
417 struct stmfts_data
*sdata
= dev_get_drvdata(dev
);
419 return sprintf(buf
, "%u\n", sdata
->chip_ver
);
422 static ssize_t
stmfts_sysfs_fw_ver(struct device
*dev
,
423 struct device_attribute
*attr
, char *buf
)
425 struct stmfts_data
*sdata
= dev_get_drvdata(dev
);
427 return sprintf(buf
, "%u\n", sdata
->fw_ver
);
430 static ssize_t
stmfts_sysfs_config_id(struct device
*dev
,
431 struct device_attribute
*attr
, char *buf
)
433 struct stmfts_data
*sdata
= dev_get_drvdata(dev
);
435 return sprintf(buf
, "%#x\n", sdata
->config_id
);
438 static ssize_t
stmfts_sysfs_config_version(struct device
*dev
,
439 struct device_attribute
*attr
, char *buf
)
441 struct stmfts_data
*sdata
= dev_get_drvdata(dev
);
443 return sprintf(buf
, "%u\n", sdata
->config_ver
);
446 static ssize_t
stmfts_sysfs_read_status(struct device
*dev
,
447 struct device_attribute
*attr
, char *buf
)
449 struct stmfts_data
*sdata
= dev_get_drvdata(dev
);
453 err
= i2c_smbus_read_i2c_block_data(sdata
->client
, STMFTS_READ_STATUS
,
454 sizeof(status
), status
);
458 return sprintf(buf
, "%#02x\n", status
[0]);
461 static ssize_t
stmfts_sysfs_hover_enable_read(struct device
*dev
,
462 struct device_attribute
*attr
, char *buf
)
464 struct stmfts_data
*sdata
= dev_get_drvdata(dev
);
466 return sprintf(buf
, "%u\n", sdata
->hover_enabled
);
469 static ssize_t
stmfts_sysfs_hover_enable_write(struct device
*dev
,
470 struct device_attribute
*attr
,
471 const char *buf
, size_t len
)
473 struct stmfts_data
*sdata
= dev_get_drvdata(dev
);
477 if (kstrtoul(buf
, 0, &value
))
480 mutex_lock(&sdata
->mutex
);
482 if (value
& sdata
->hover_enabled
)
486 err
= i2c_smbus_write_byte(sdata
->client
,
487 value
? STMFTS_SS_HOVER_SENSE_ON
:
488 STMFTS_SS_HOVER_SENSE_OFF
);
491 sdata
->hover_enabled
= !!value
;
494 mutex_unlock(&sdata
->mutex
);
499 static DEVICE_ATTR(chip_id
, 0444, stmfts_sysfs_chip_id
, NULL
);
500 static DEVICE_ATTR(chip_version
, 0444, stmfts_sysfs_chip_version
, NULL
);
501 static DEVICE_ATTR(fw_ver
, 0444, stmfts_sysfs_fw_ver
, NULL
);
502 static DEVICE_ATTR(config_id
, 0444, stmfts_sysfs_config_id
, NULL
);
503 static DEVICE_ATTR(config_version
, 0444, stmfts_sysfs_config_version
, NULL
);
504 static DEVICE_ATTR(status
, 0444, stmfts_sysfs_read_status
, NULL
);
505 static DEVICE_ATTR(hover_enable
, 0644, stmfts_sysfs_hover_enable_read
,
506 stmfts_sysfs_hover_enable_write
);
508 static struct attribute
*stmfts_sysfs_attrs
[] = {
509 &dev_attr_chip_id
.attr
,
510 &dev_attr_chip_version
.attr
,
511 &dev_attr_fw_ver
.attr
,
512 &dev_attr_config_id
.attr
,
513 &dev_attr_config_version
.attr
,
514 &dev_attr_status
.attr
,
515 &dev_attr_hover_enable
.attr
,
519 static struct attribute_group stmfts_attribute_group
= {
520 .attrs
= stmfts_sysfs_attrs
523 static int stmfts_power_on(struct stmfts_data
*sdata
)
528 err
= regulator_bulk_enable(ARRAY_SIZE(sdata
->regulators
),
534 * The datasheet does not specify the power on time, but considering
535 * that the reset time is < 10ms, I sleep 20ms to be sure
539 err
= i2c_smbus_read_i2c_block_data(sdata
->client
, STMFTS_READ_INFO
,
543 if (err
!= sizeof(reg
))
546 sdata
->chip_id
= be16_to_cpup((__be16
*)®
[6]);
547 sdata
->chip_ver
= reg
[0];
548 sdata
->fw_ver
= be16_to_cpup((__be16
*)®
[2]);
549 sdata
->config_id
= reg
[4];
550 sdata
->config_ver
= reg
[5];
552 enable_irq(sdata
->client
->irq
);
556 err
= stmfts_command(sdata
, STMFTS_SYSTEM_RESET
);
560 err
= stmfts_command(sdata
, STMFTS_SLEEP_OUT
);
564 /* optional tuning */
565 err
= stmfts_command(sdata
, STMFTS_MS_CX_TUNING
);
567 dev_warn(&sdata
->client
->dev
,
568 "failed to perform mutual auto tune: %d\n", err
);
570 /* optional tuning */
571 err
= stmfts_command(sdata
, STMFTS_SS_CX_TUNING
);
573 dev_warn(&sdata
->client
->dev
,
574 "failed to perform self auto tune: %d\n", err
);
576 err
= stmfts_command(sdata
, STMFTS_FULL_FORCE_CALIBRATION
);
581 * At this point no one is using the touchscreen
582 * and I don't really care about the return value
584 (void) i2c_smbus_write_byte(sdata
->client
, STMFTS_SLEEP_IN
);
589 static void stmfts_power_off(void *data
)
591 struct stmfts_data
*sdata
= data
;
593 disable_irq(sdata
->client
->irq
);
594 regulator_bulk_disable(ARRAY_SIZE(sdata
->regulators
),
598 /* This function is void because I don't want to prevent using the touch key
599 * only because the LEDs don't get registered
601 static int stmfts_enable_led(struct stmfts_data
*sdata
)
605 /* get the regulator for powering the leds on */
606 sdata
->ledvdd
= devm_regulator_get(&sdata
->client
->dev
, "ledvdd");
607 if (IS_ERR(sdata
->ledvdd
))
608 return PTR_ERR(sdata
->ledvdd
);
610 sdata
->led_cdev
.name
= STMFTS_DEV_NAME
;
611 sdata
->led_cdev
.max_brightness
= LED_ON
;
612 sdata
->led_cdev
.brightness
= LED_OFF
;
613 sdata
->led_cdev
.brightness_set_blocking
= stmfts_brightness_set
;
614 sdata
->led_cdev
.brightness_get
= stmfts_brightness_get
;
616 err
= devm_led_classdev_register(&sdata
->client
->dev
, &sdata
->led_cdev
);
618 devm_regulator_put(sdata
->ledvdd
);
625 static int stmfts_probe(struct i2c_client
*client
,
626 const struct i2c_device_id
*id
)
629 struct stmfts_data
*sdata
;
631 if (!i2c_check_functionality(client
->adapter
, I2C_FUNC_I2C
|
632 I2C_FUNC_SMBUS_BYTE_DATA
|
633 I2C_FUNC_SMBUS_I2C_BLOCK
))
636 sdata
= devm_kzalloc(&client
->dev
, sizeof(*sdata
), GFP_KERNEL
);
640 i2c_set_clientdata(client
, sdata
);
642 sdata
->client
= client
;
643 mutex_init(&sdata
->mutex
);
644 init_completion(&sdata
->cmd_done
);
646 sdata
->regulators
[STMFTS_REGULATOR_VDD
].supply
= "vdd";
647 sdata
->regulators
[STMFTS_REGULATOR_AVDD
].supply
= "avdd";
648 err
= devm_regulator_bulk_get(&client
->dev
,
649 ARRAY_SIZE(sdata
->regulators
),
654 sdata
->input
= devm_input_allocate_device(&client
->dev
);
658 sdata
->input
->name
= STMFTS_DEV_NAME
;
659 sdata
->input
->id
.bustype
= BUS_I2C
;
660 sdata
->input
->open
= stmfts_input_open
;
661 sdata
->input
->close
= stmfts_input_close
;
663 input_set_capability(sdata
->input
, EV_ABS
, ABS_MT_POSITION_X
);
664 input_set_capability(sdata
->input
, EV_ABS
, ABS_MT_POSITION_Y
);
665 touchscreen_parse_properties(sdata
->input
, true, &sdata
->prop
);
667 input_set_abs_params(sdata
->input
, ABS_MT_TOUCH_MAJOR
, 0, 255, 0, 0);
668 input_set_abs_params(sdata
->input
, ABS_MT_TOUCH_MINOR
, 0, 255, 0, 0);
669 input_set_abs_params(sdata
->input
, ABS_MT_ORIENTATION
, 0, 255, 0, 0);
670 input_set_abs_params(sdata
->input
, ABS_MT_PRESSURE
, 0, 255, 0, 0);
671 input_set_abs_params(sdata
->input
, ABS_DISTANCE
, 0, 255, 0, 0);
673 sdata
->use_key
= device_property_read_bool(&client
->dev
,
674 "touch-key-connected");
675 if (sdata
->use_key
) {
676 input_set_capability(sdata
->input
, EV_KEY
, KEY_MENU
);
677 input_set_capability(sdata
->input
, EV_KEY
, KEY_BACK
);
680 err
= input_mt_init_slots(sdata
->input
,
681 STMFTS_MAX_FINGERS
, INPUT_MT_DIRECT
);
685 input_set_drvdata(sdata
->input
, sdata
);
688 * stmfts_power_on expects interrupt to be disabled, but
689 * at this point the device is still off and I do not trust
690 * the status of the irq line that can generate some spurious
691 * interrupts. To be on the safe side it's better to not enable
692 * the interrupts during their request.
694 irq_set_status_flags(client
->irq
, IRQ_NOAUTOEN
);
695 err
= devm_request_threaded_irq(&client
->dev
, client
->irq
,
696 NULL
, stmfts_irq_handler
,
698 "stmfts_irq", sdata
);
702 dev_dbg(&client
->dev
, "initializing ST-Microelectronics FTS...\n");
704 err
= stmfts_power_on(sdata
);
708 err
= devm_add_action_or_reset(&client
->dev
, stmfts_power_off
, sdata
);
712 err
= input_register_device(sdata
->input
);
716 if (sdata
->use_key
) {
717 err
= stmfts_enable_led(sdata
);
720 * Even if the LEDs have failed to be initialized and
721 * used in the driver, I can still use the device even
722 * without LEDs. The ledvdd regulator pointer will be
725 dev_warn(&client
->dev
, "unable to use touchkey leds\n");
726 sdata
->ledvdd
= NULL
;
730 err
= devm_device_add_group(&client
->dev
, &stmfts_attribute_group
);
734 pm_runtime_enable(&client
->dev
);
735 device_enable_async_suspend(&client
->dev
);
740 static int stmfts_remove(struct i2c_client
*client
)
742 pm_runtime_disable(&client
->dev
);
747 static int __maybe_unused
stmfts_runtime_suspend(struct device
*dev
)
749 struct stmfts_data
*sdata
= dev_get_drvdata(dev
);
752 ret
= i2c_smbus_write_byte(sdata
->client
, STMFTS_SLEEP_IN
);
754 dev_warn(dev
, "failed to suspend device: %d\n", ret
);
759 static int __maybe_unused
stmfts_runtime_resume(struct device
*dev
)
761 struct stmfts_data
*sdata
= dev_get_drvdata(dev
);
764 ret
= i2c_smbus_write_byte(sdata
->client
, STMFTS_SLEEP_OUT
);
766 dev_err(dev
, "failed to resume device: %d\n", ret
);
771 static int __maybe_unused
stmfts_suspend(struct device
*dev
)
773 struct stmfts_data
*sdata
= dev_get_drvdata(dev
);
775 stmfts_power_off(sdata
);
780 static int __maybe_unused
stmfts_resume(struct device
*dev
)
782 struct stmfts_data
*sdata
= dev_get_drvdata(dev
);
784 return stmfts_power_on(sdata
);
787 static const struct dev_pm_ops stmfts_pm_ops
= {
788 SET_SYSTEM_SLEEP_PM_OPS(stmfts_suspend
, stmfts_resume
)
789 SET_RUNTIME_PM_OPS(stmfts_runtime_suspend
, stmfts_runtime_resume
, NULL
)
793 static const struct of_device_id stmfts_of_match
[] = {
794 { .compatible
= "st,stmfts", },
797 MODULE_DEVICE_TABLE(of
, stmfts_of_match
);
800 static const struct i2c_device_id stmfts_id
[] = {
804 MODULE_DEVICE_TABLE(i2c
, stmfts_id
);
806 static struct i2c_driver stmfts_driver
= {
808 .name
= STMFTS_DEV_NAME
,
809 .of_match_table
= of_match_ptr(stmfts_of_match
),
810 .pm
= &stmfts_pm_ops
,
811 .probe_type
= PROBE_PREFER_ASYNCHRONOUS
,
813 .probe
= stmfts_probe
,
814 .remove
= stmfts_remove
,
815 .id_table
= stmfts_id
,
818 module_i2c_driver(stmfts_driver
);
820 MODULE_AUTHOR("Andi Shyti <andi.shyti@samsung.com>");
821 MODULE_DESCRIPTION("STMicroelectronics FTS Touch Screen");
822 MODULE_LICENSE("GPL v2");