2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3 * Author: Andi Shyti <andi.shyti@samsung.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * STMicroelectronics FTS Touchscreen device driver
12 #include <linux/delay.h>
13 #include <linux/i2c.h>
14 #include <linux/input/mt.h>
15 #include <linux/input/touchscreen.h>
16 #include <linux/interrupt.h>
17 #include <linux/irq.h>
18 #include <linux/leds.h>
19 #include <linux/module.h>
20 #include <linux/pm_runtime.h>
21 #include <linux/regulator/consumer.h>
24 #define STMFTS_READ_INFO 0x80
25 #define STMFTS_READ_STATUS 0x84
26 #define STMFTS_READ_ONE_EVENT 0x85
27 #define STMFTS_READ_ALL_EVENT 0x86
28 #define STMFTS_LATEST_EVENT 0x87
29 #define STMFTS_SLEEP_IN 0x90
30 #define STMFTS_SLEEP_OUT 0x91
31 #define STMFTS_MS_MT_SENSE_OFF 0x92
32 #define STMFTS_MS_MT_SENSE_ON 0x93
33 #define STMFTS_SS_HOVER_SENSE_OFF 0x94
34 #define STMFTS_SS_HOVER_SENSE_ON 0x95
35 #define STMFTS_MS_KEY_SENSE_OFF 0x9a
36 #define STMFTS_MS_KEY_SENSE_ON 0x9b
37 #define STMFTS_SYSTEM_RESET 0xa0
38 #define STMFTS_CLEAR_EVENT_STACK 0xa1
39 #define STMFTS_FULL_FORCE_CALIBRATION 0xa2
40 #define STMFTS_MS_CX_TUNING 0xa3
41 #define STMFTS_SS_CX_TUNING 0xa4
44 #define STMFTS_EV_NO_EVENT 0x00
45 #define STMFTS_EV_MULTI_TOUCH_DETECTED 0x02
46 #define STMFTS_EV_MULTI_TOUCH_ENTER 0x03
47 #define STMFTS_EV_MULTI_TOUCH_LEAVE 0x04
48 #define STMFTS_EV_MULTI_TOUCH_MOTION 0x05
49 #define STMFTS_EV_HOVER_ENTER 0x07
50 #define STMFTS_EV_HOVER_LEAVE 0x08
51 #define STMFTS_EV_HOVER_MOTION 0x09
52 #define STMFTS_EV_KEY_STATUS 0x0e
53 #define STMFTS_EV_ERROR 0x0f
54 #define STMFTS_EV_CONTROLLER_READY 0x10
55 #define STMFTS_EV_SLEEP_OUT_CONTROLLER_READY 0x11
56 #define STMFTS_EV_STATUS 0x16
57 #define STMFTS_EV_DEBUG 0xdb
59 /* multi touch related event masks */
60 #define STMFTS_MASK_EVENT_ID 0x0f
61 #define STMFTS_MASK_TOUCH_ID 0xf0
62 #define STMFTS_MASK_LEFT_EVENT 0x0f
63 #define STMFTS_MASK_X_MSB 0x0f
64 #define STMFTS_MASK_Y_LSB 0xf0
66 /* key related event masks */
67 #define STMFTS_MASK_KEY_NO_TOUCH 0x00
68 #define STMFTS_MASK_KEY_MENU 0x01
69 #define STMFTS_MASK_KEY_BACK 0x02
71 #define STMFTS_EVENT_SIZE 8
72 #define STMFTS_STACK_DEPTH 32
73 #define STMFTS_DATA_MAX_SIZE (STMFTS_EVENT_SIZE * STMFTS_STACK_DEPTH)
74 #define STMFTS_MAX_FINGERS 10
75 #define STMFTS_DEV_NAME "stmfts"
77 enum stmfts_regulators
{
79 STMFTS_REGULATOR_AVDD
,
83 struct i2c_client
*client
;
84 struct input_dev
*input
;
85 struct led_classdev led_cdev
;
88 struct touchscreen_properties prop
;
90 struct regulator_bulk_data regulators
[2];
93 * Presence of ledvdd will be used also to check
94 * whether the LED is supported.
96 struct regulator
*ledvdd
;
104 u8 data
[STMFTS_DATA_MAX_SIZE
];
106 struct completion cmd_done
;
114 static void stmfts_brightness_set(struct led_classdev
*led_cdev
,
115 enum led_brightness value
)
117 struct stmfts_data
*sdata
= container_of(led_cdev
,
118 struct stmfts_data
, led_cdev
);
121 if (value
== sdata
->led_status
|| !sdata
->ledvdd
)
125 regulator_disable(sdata
->ledvdd
);
127 err
= regulator_enable(sdata
->ledvdd
);
129 dev_warn(&sdata
->client
->dev
,
130 "failed to disable ledvdd regulator: %d\n",
134 sdata
->led_status
= value
;
137 static enum led_brightness
stmfts_brightness_get(struct led_classdev
*led_cdev
)
139 struct stmfts_data
*sdata
= container_of(led_cdev
,
140 struct stmfts_data
, led_cdev
);
142 return !!regulator_is_enabled(sdata
->ledvdd
);
146 * We can't simply use i2c_smbus_read_i2c_block_data because we
147 * need to read more than 255 bytes (
149 static int stmfts_read_events(struct stmfts_data
*sdata
)
151 u8 cmd
= STMFTS_READ_ALL_EVENT
;
152 struct i2c_msg msgs
[2] = {
154 .addr
= sdata
->client
->addr
,
159 .addr
= sdata
->client
->addr
,
161 .len
= STMFTS_DATA_MAX_SIZE
,
167 ret
= i2c_transfer(sdata
->client
->adapter
, msgs
, ARRAY_SIZE(msgs
));
171 return ret
== ARRAY_SIZE(msgs
) ? 0 : -EIO
;
174 static void stmfts_report_contact_event(struct stmfts_data
*sdata
,
177 u8 slot_id
= (event
[0] & STMFTS_MASK_TOUCH_ID
) >> 4;
178 u16 x
= event
[1] | ((event
[2] & STMFTS_MASK_X_MSB
) << 8);
179 u16 y
= (event
[2] >> 4) | (event
[3] << 4);
182 u8 orientation
= event
[6];
185 input_mt_slot(sdata
->input
, slot_id
);
187 input_mt_report_slot_state(sdata
->input
, MT_TOOL_FINGER
, true);
188 input_report_abs(sdata
->input
, ABS_MT_POSITION_X
, x
);
189 input_report_abs(sdata
->input
, ABS_MT_POSITION_Y
, y
);
190 input_report_abs(sdata
->input
, ABS_MT_TOUCH_MAJOR
, maj
);
191 input_report_abs(sdata
->input
, ABS_MT_TOUCH_MINOR
, min
);
192 input_report_abs(sdata
->input
, ABS_MT_PRESSURE
, area
);
193 input_report_abs(sdata
->input
, ABS_MT_ORIENTATION
, orientation
);
195 input_sync(sdata
->input
);
198 static void stmfts_report_contact_release(struct stmfts_data
*sdata
,
201 u8 slot_id
= (event
[0] & STMFTS_MASK_TOUCH_ID
) >> 4;
203 input_mt_slot(sdata
->input
, slot_id
);
204 input_mt_report_slot_state(sdata
->input
, MT_TOOL_FINGER
, false);
206 input_sync(sdata
->input
);
209 static void stmfts_report_hover_event(struct stmfts_data
*sdata
,
212 u16 x
= (event
[2] << 4) | (event
[4] >> 4);
213 u16 y
= (event
[3] << 4) | (event
[4] & STMFTS_MASK_Y_LSB
);
216 input_report_abs(sdata
->input
, ABS_X
, x
);
217 input_report_abs(sdata
->input
, ABS_Y
, y
);
218 input_report_abs(sdata
->input
, ABS_DISTANCE
, z
);
220 input_sync(sdata
->input
);
223 static void stmfts_report_key_event(struct stmfts_data
*sdata
, const u8 event
[])
227 input_report_key(sdata
->input
, KEY_BACK
, 0);
228 input_report_key(sdata
->input
, KEY_MENU
, 0);
231 case STMFTS_MASK_KEY_BACK
:
232 input_report_key(sdata
->input
, KEY_BACK
, 1);
235 case STMFTS_MASK_KEY_MENU
:
236 input_report_key(sdata
->input
, KEY_MENU
, 1);
240 dev_warn(&sdata
->client
->dev
,
241 "unknown key event: %#02x\n", event
[2]);
245 input_sync(sdata
->input
);
248 static void stmfts_parse_events(struct stmfts_data
*sdata
)
252 for (i
= 0; i
< STMFTS_STACK_DEPTH
; i
++) {
253 u8
*event
= &sdata
->data
[i
* STMFTS_EVENT_SIZE
];
257 case STMFTS_EV_CONTROLLER_READY
:
258 case STMFTS_EV_SLEEP_OUT_CONTROLLER_READY
:
259 case STMFTS_EV_STATUS
:
260 complete(&sdata
->cmd_done
);
263 case STMFTS_EV_NO_EVENT
:
264 case STMFTS_EV_DEBUG
:
268 switch (event
[0] & STMFTS_MASK_EVENT_ID
) {
270 case STMFTS_EV_MULTI_TOUCH_ENTER
:
271 case STMFTS_EV_MULTI_TOUCH_MOTION
:
272 stmfts_report_contact_event(sdata
, event
);
275 case STMFTS_EV_MULTI_TOUCH_LEAVE
:
276 stmfts_report_contact_release(sdata
, event
);
279 case STMFTS_EV_HOVER_ENTER
:
280 case STMFTS_EV_HOVER_LEAVE
:
281 case STMFTS_EV_HOVER_MOTION
:
282 stmfts_report_hover_event(sdata
, event
);
285 case STMFTS_EV_KEY_STATUS
:
286 stmfts_report_key_event(sdata
, event
);
289 case STMFTS_EV_ERROR
:
290 dev_warn(&sdata
->client
->dev
,
291 "error code: 0x%x%x%x%x%x%x",
292 event
[6], event
[5], event
[4],
293 event
[3], event
[2], event
[1]);
297 dev_err(&sdata
->client
->dev
,
298 "unknown event %#02x\n", event
[0]);
303 static irqreturn_t
stmfts_irq_handler(int irq
, void *dev
)
305 struct stmfts_data
*sdata
= dev
;
308 mutex_lock(&sdata
->mutex
);
310 err
= stmfts_read_events(sdata
);
312 dev_err(&sdata
->client
->dev
,
313 "failed to read events: %d\n", err
);
315 stmfts_parse_events(sdata
);
317 mutex_unlock(&sdata
->mutex
);
321 static int stmfts_command(struct stmfts_data
*sdata
, const u8 cmd
)
325 reinit_completion(&sdata
->cmd_done
);
327 err
= i2c_smbus_write_byte(sdata
->client
, cmd
);
331 if (!wait_for_completion_timeout(&sdata
->cmd_done
,
332 msecs_to_jiffies(1000)))
338 static int stmfts_input_open(struct input_dev
*dev
)
340 struct stmfts_data
*sdata
= input_get_drvdata(dev
);
343 err
= pm_runtime_get_sync(&sdata
->client
->dev
);
347 err
= i2c_smbus_write_byte(sdata
->client
, STMFTS_MS_MT_SENSE_ON
);
351 mutex_lock(&sdata
->mutex
);
352 sdata
->running
= true;
354 if (sdata
->hover_enabled
) {
355 err
= i2c_smbus_write_byte(sdata
->client
,
356 STMFTS_SS_HOVER_SENSE_ON
);
358 dev_warn(&sdata
->client
->dev
,
359 "failed to enable hover\n");
361 mutex_unlock(&sdata
->mutex
);
363 if (sdata
->use_key
) {
364 err
= i2c_smbus_write_byte(sdata
->client
,
365 STMFTS_MS_KEY_SENSE_ON
);
367 /* I can still use only the touch screen */
368 dev_warn(&sdata
->client
->dev
,
369 "failed to enable touchkey\n");
375 static void stmfts_input_close(struct input_dev
*dev
)
377 struct stmfts_data
*sdata
= input_get_drvdata(dev
);
380 err
= i2c_smbus_write_byte(sdata
->client
, STMFTS_MS_MT_SENSE_OFF
);
382 dev_warn(&sdata
->client
->dev
,
383 "failed to disable touchscreen: %d\n", err
);
385 mutex_lock(&sdata
->mutex
);
387 sdata
->running
= false;
389 if (sdata
->hover_enabled
) {
390 err
= i2c_smbus_write_byte(sdata
->client
,
391 STMFTS_SS_HOVER_SENSE_OFF
);
393 dev_warn(&sdata
->client
->dev
,
394 "failed to disable hover: %d\n", err
);
396 mutex_unlock(&sdata
->mutex
);
398 if (sdata
->use_key
) {
399 err
= i2c_smbus_write_byte(sdata
->client
,
400 STMFTS_MS_KEY_SENSE_OFF
);
402 dev_warn(&sdata
->client
->dev
,
403 "failed to disable touchkey: %d\n", err
);
406 pm_runtime_put_sync(&sdata
->client
->dev
);
409 static ssize_t
stmfts_sysfs_chip_id(struct device
*dev
,
410 struct device_attribute
*attr
, char *buf
)
412 struct stmfts_data
*sdata
= dev_get_drvdata(dev
);
414 return sprintf(buf
, "%#x\n", sdata
->chip_id
);
417 static ssize_t
stmfts_sysfs_chip_version(struct device
*dev
,
418 struct device_attribute
*attr
, char *buf
)
420 struct stmfts_data
*sdata
= dev_get_drvdata(dev
);
422 return sprintf(buf
, "%u\n", sdata
->chip_ver
);
425 static ssize_t
stmfts_sysfs_fw_ver(struct device
*dev
,
426 struct device_attribute
*attr
, char *buf
)
428 struct stmfts_data
*sdata
= dev_get_drvdata(dev
);
430 return sprintf(buf
, "%u\n", sdata
->fw_ver
);
433 static ssize_t
stmfts_sysfs_config_id(struct device
*dev
,
434 struct device_attribute
*attr
, char *buf
)
436 struct stmfts_data
*sdata
= dev_get_drvdata(dev
);
438 return sprintf(buf
, "%#x\n", sdata
->config_id
);
441 static ssize_t
stmfts_sysfs_config_version(struct device
*dev
,
442 struct device_attribute
*attr
, char *buf
)
444 struct stmfts_data
*sdata
= dev_get_drvdata(dev
);
446 return sprintf(buf
, "%u\n", sdata
->config_ver
);
449 static ssize_t
stmfts_sysfs_read_status(struct device
*dev
,
450 struct device_attribute
*attr
, char *buf
)
452 struct stmfts_data
*sdata
= dev_get_drvdata(dev
);
456 err
= i2c_smbus_read_i2c_block_data(sdata
->client
, STMFTS_READ_STATUS
,
457 sizeof(status
), status
);
461 return sprintf(buf
, "%#02x\n", status
[0]);
464 static ssize_t
stmfts_sysfs_hover_enable_read(struct device
*dev
,
465 struct device_attribute
*attr
, char *buf
)
467 struct stmfts_data
*sdata
= dev_get_drvdata(dev
);
469 return sprintf(buf
, "%u\n", sdata
->hover_enabled
);
472 static ssize_t
stmfts_sysfs_hover_enable_write(struct device
*dev
,
473 struct device_attribute
*attr
,
474 const char *buf
, size_t len
)
476 struct stmfts_data
*sdata
= dev_get_drvdata(dev
);
480 if (kstrtoul(buf
, 0, &value
))
483 mutex_lock(&sdata
->mutex
);
485 if (value
& sdata
->hover_enabled
)
489 err
= i2c_smbus_write_byte(sdata
->client
,
490 value
? STMFTS_SS_HOVER_SENSE_ON
:
491 STMFTS_SS_HOVER_SENSE_OFF
);
494 sdata
->hover_enabled
= !!value
;
497 mutex_unlock(&sdata
->mutex
);
502 static DEVICE_ATTR(chip_id
, 0444, stmfts_sysfs_chip_id
, NULL
);
503 static DEVICE_ATTR(chip_version
, 0444, stmfts_sysfs_chip_version
, NULL
);
504 static DEVICE_ATTR(fw_ver
, 0444, stmfts_sysfs_fw_ver
, NULL
);
505 static DEVICE_ATTR(config_id
, 0444, stmfts_sysfs_config_id
, NULL
);
506 static DEVICE_ATTR(config_version
, 0444, stmfts_sysfs_config_version
, NULL
);
507 static DEVICE_ATTR(status
, 0444, stmfts_sysfs_read_status
, NULL
);
508 static DEVICE_ATTR(hover_enable
, 0644, stmfts_sysfs_hover_enable_read
,
509 stmfts_sysfs_hover_enable_write
);
511 static struct attribute
*stmfts_sysfs_attrs
[] = {
512 &dev_attr_chip_id
.attr
,
513 &dev_attr_chip_version
.attr
,
514 &dev_attr_fw_ver
.attr
,
515 &dev_attr_config_id
.attr
,
516 &dev_attr_config_version
.attr
,
517 &dev_attr_status
.attr
,
518 &dev_attr_hover_enable
.attr
,
522 static struct attribute_group stmfts_attribute_group
= {
523 .attrs
= stmfts_sysfs_attrs
526 static int stmfts_power_on(struct stmfts_data
*sdata
)
531 err
= regulator_bulk_enable(ARRAY_SIZE(sdata
->regulators
),
537 * The datasheet does not specify the power on time, but considering
538 * that the reset time is < 10ms, I sleep 20ms to be sure
542 err
= i2c_smbus_read_i2c_block_data(sdata
->client
, STMFTS_READ_INFO
,
546 if (err
!= sizeof(reg
))
549 sdata
->chip_id
= be16_to_cpup((__be16
*)®
[6]);
550 sdata
->chip_ver
= reg
[0];
551 sdata
->fw_ver
= be16_to_cpup((__be16
*)®
[2]);
552 sdata
->config_id
= reg
[4];
553 sdata
->config_ver
= reg
[5];
555 enable_irq(sdata
->client
->irq
);
559 err
= stmfts_command(sdata
, STMFTS_SYSTEM_RESET
);
563 err
= stmfts_command(sdata
, STMFTS_SLEEP_OUT
);
567 /* optional tuning */
568 err
= stmfts_command(sdata
, STMFTS_MS_CX_TUNING
);
570 dev_warn(&sdata
->client
->dev
,
571 "failed to perform mutual auto tune: %d\n", err
);
573 /* optional tuning */
574 err
= stmfts_command(sdata
, STMFTS_SS_CX_TUNING
);
576 dev_warn(&sdata
->client
->dev
,
577 "failed to perform self auto tune: %d\n", err
);
579 err
= stmfts_command(sdata
, STMFTS_FULL_FORCE_CALIBRATION
);
584 * At this point no one is using the touchscreen
585 * and I don't really care about the return value
587 (void) i2c_smbus_write_byte(sdata
->client
, STMFTS_SLEEP_IN
);
592 static void stmfts_power_off(void *data
)
594 struct stmfts_data
*sdata
= data
;
596 disable_irq(sdata
->client
->irq
);
597 regulator_bulk_disable(ARRAY_SIZE(sdata
->regulators
),
601 /* This function is void because I don't want to prevent using the touch key
602 * only because the LEDs don't get registered
604 static int stmfts_enable_led(struct stmfts_data
*sdata
)
608 /* get the regulator for powering the leds on */
609 sdata
->ledvdd
= devm_regulator_get(&sdata
->client
->dev
, "ledvdd");
610 if (IS_ERR(sdata
->ledvdd
))
611 return PTR_ERR(sdata
->ledvdd
);
613 sdata
->led_cdev
.name
= STMFTS_DEV_NAME
;
614 sdata
->led_cdev
.max_brightness
= LED_ON
;
615 sdata
->led_cdev
.brightness
= LED_OFF
;
616 sdata
->led_cdev
.brightness_set
= stmfts_brightness_set
;
617 sdata
->led_cdev
.brightness_get
= stmfts_brightness_get
;
619 err
= devm_led_classdev_register(&sdata
->client
->dev
, &sdata
->led_cdev
);
621 devm_regulator_put(sdata
->ledvdd
);
628 static int stmfts_probe(struct i2c_client
*client
,
629 const struct i2c_device_id
*id
)
632 struct stmfts_data
*sdata
;
634 if (!i2c_check_functionality(client
->adapter
, I2C_FUNC_I2C
|
635 I2C_FUNC_SMBUS_BYTE_DATA
|
636 I2C_FUNC_SMBUS_I2C_BLOCK
))
639 sdata
= devm_kzalloc(&client
->dev
, sizeof(*sdata
), GFP_KERNEL
);
643 i2c_set_clientdata(client
, sdata
);
645 sdata
->client
= client
;
646 mutex_init(&sdata
->mutex
);
647 init_completion(&sdata
->cmd_done
);
649 sdata
->regulators
[STMFTS_REGULATOR_VDD
].supply
= "vdd";
650 sdata
->regulators
[STMFTS_REGULATOR_AVDD
].supply
= "avdd";
651 err
= devm_regulator_bulk_get(&client
->dev
,
652 ARRAY_SIZE(sdata
->regulators
),
657 sdata
->input
= devm_input_allocate_device(&client
->dev
);
661 sdata
->input
->name
= STMFTS_DEV_NAME
;
662 sdata
->input
->id
.bustype
= BUS_I2C
;
663 sdata
->input
->open
= stmfts_input_open
;
664 sdata
->input
->close
= stmfts_input_close
;
666 touchscreen_parse_properties(sdata
->input
, true, &sdata
->prop
);
668 input_set_abs_params(sdata
->input
, ABS_MT_POSITION_X
, 0,
669 sdata
->prop
.max_x
, 0, 0);
670 input_set_abs_params(sdata
->input
, ABS_MT_POSITION_Y
, 0,
671 sdata
->prop
.max_y
, 0, 0);
672 input_set_abs_params(sdata
->input
, ABS_MT_TOUCH_MAJOR
, 0, 255, 0, 0);
673 input_set_abs_params(sdata
->input
, ABS_MT_TOUCH_MINOR
, 0, 255, 0, 0);
674 input_set_abs_params(sdata
->input
, ABS_MT_ORIENTATION
, 0, 255, 0, 0);
675 input_set_abs_params(sdata
->input
, ABS_MT_PRESSURE
, 0, 255, 0, 0);
676 input_set_abs_params(sdata
->input
, ABS_DISTANCE
, 0, 255, 0, 0);
678 sdata
->use_key
= device_property_read_bool(&client
->dev
,
679 "touch-key-connected");
680 if (sdata
->use_key
) {
681 input_set_capability(sdata
->input
, EV_KEY
, KEY_MENU
);
682 input_set_capability(sdata
->input
, EV_KEY
, KEY_BACK
);
685 err
= input_mt_init_slots(sdata
->input
,
686 STMFTS_MAX_FINGERS
, INPUT_MT_DIRECT
);
690 input_set_drvdata(sdata
->input
, sdata
);
692 err
= devm_request_threaded_irq(&client
->dev
, client
->irq
,
693 NULL
, stmfts_irq_handler
,
695 "stmfts_irq", sdata
);
699 /* stmfts_power_on expects interrupt to be disabled */
700 disable_irq(client
->irq
);
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
= sysfs_create_group(&sdata
->client
->dev
.kobj
,
731 &stmfts_attribute_group
);
735 pm_runtime_enable(&client
->dev
);
740 static int stmfts_remove(struct i2c_client
*client
)
742 pm_runtime_disable(&client
->dev
);
743 sysfs_remove_group(&client
->dev
.kobj
, &stmfts_attribute_group
);
748 static int __maybe_unused
stmfts_runtime_suspend(struct device
*dev
)
750 struct stmfts_data
*sdata
= dev_get_drvdata(dev
);
753 ret
= i2c_smbus_write_byte(sdata
->client
, STMFTS_SLEEP_IN
);
755 dev_warn(dev
, "failed to suspend device: %d\n", ret
);
760 static int __maybe_unused
stmfts_runtime_resume(struct device
*dev
)
762 struct stmfts_data
*sdata
= dev_get_drvdata(dev
);
765 ret
= i2c_smbus_write_byte(sdata
->client
, STMFTS_SLEEP_OUT
);
767 dev_err(dev
, "failed to resume device: %d\n", ret
);
772 static int __maybe_unused
stmfts_suspend(struct device
*dev
)
774 struct stmfts_data
*sdata
= dev_get_drvdata(dev
);
776 stmfts_power_off(sdata
);
781 static int __maybe_unused
stmfts_resume(struct device
*dev
)
783 struct stmfts_data
*sdata
= dev_get_drvdata(dev
);
785 return stmfts_power_on(sdata
);
788 static const struct dev_pm_ops stmfts_pm_ops
= {
789 SET_SYSTEM_SLEEP_PM_OPS(stmfts_suspend
, stmfts_resume
)
790 SET_RUNTIME_PM_OPS(stmfts_runtime_suspend
, stmfts_runtime_resume
, NULL
)
794 static const struct of_device_id stmfts_of_match
[] = {
795 { .compatible
= "st,stmfts", },
798 MODULE_DEVICE_TABLE(of
, stmfts_of_match
);
801 static const struct i2c_device_id stmfts_id
[] = {
805 MODULE_DEVICE_TABLE(i2c
, stmfts_id
);
807 static struct i2c_driver stmfts_driver
= {
809 .name
= STMFTS_DEV_NAME
,
810 .of_match_table
= of_match_ptr(stmfts_of_match
),
811 .pm
= &stmfts_pm_ops
,
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");