1c942fddfSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
23197704cSRobert Dolca /* -------------------------------------------------------------------------
33197704cSRobert Dolca * Copyright (C) 2014-2015, Intel Corporation
43197704cSRobert Dolca *
53197704cSRobert Dolca * Derived from:
63197704cSRobert Dolca * gslX68X.c
73197704cSRobert Dolca * Copyright (C) 2010-2015, Shanghai Sileadinc Co.Ltd
83197704cSRobert Dolca *
93197704cSRobert Dolca * -------------------------------------------------------------------------
103197704cSRobert Dolca */
113197704cSRobert Dolca
123197704cSRobert Dolca #include <linux/i2c.h>
133197704cSRobert Dolca #include <linux/module.h>
143197704cSRobert Dolca #include <linux/acpi.h>
153197704cSRobert Dolca #include <linux/interrupt.h>
163197704cSRobert Dolca #include <linux/gpio/consumer.h>
173197704cSRobert Dolca #include <linux/delay.h>
183197704cSRobert Dolca #include <linux/firmware.h>
193197704cSRobert Dolca #include <linux/input.h>
203197704cSRobert Dolca #include <linux/input/mt.h>
213197704cSRobert Dolca #include <linux/input/touchscreen.h>
223197704cSRobert Dolca #include <linux/pm.h>
23e4791877SHans de Goede #include <linux/pm_runtime.h>
243197704cSRobert Dolca #include <linux/irq.h>
256f6deb48SHans de Goede #include <linux/regulator/consumer.h>
263197704cSRobert Dolca
273197704cSRobert Dolca #include <asm/unaligned.h>
283197704cSRobert Dolca
293197704cSRobert Dolca #define SILEAD_TS_NAME "silead_ts"
303197704cSRobert Dolca
313197704cSRobert Dolca #define SILEAD_REG_RESET 0xE0
323197704cSRobert Dolca #define SILEAD_REG_DATA 0x80
333197704cSRobert Dolca #define SILEAD_REG_TOUCH_NR 0x80
343197704cSRobert Dolca #define SILEAD_REG_POWER 0xBC
353197704cSRobert Dolca #define SILEAD_REG_CLOCK 0xE4
363197704cSRobert Dolca #define SILEAD_REG_STATUS 0xB0
373197704cSRobert Dolca #define SILEAD_REG_ID 0xFC
383197704cSRobert Dolca #define SILEAD_REG_MEM_CHECK 0xB0
393197704cSRobert Dolca
403197704cSRobert Dolca #define SILEAD_STATUS_OK 0x5A5A5A5A
413197704cSRobert Dolca #define SILEAD_TS_DATA_LEN 44
423197704cSRobert Dolca #define SILEAD_CLOCK 0x04
433197704cSRobert Dolca
443197704cSRobert Dolca #define SILEAD_CMD_RESET 0x88
453197704cSRobert Dolca #define SILEAD_CMD_START 0x00
463197704cSRobert Dolca
473197704cSRobert Dolca #define SILEAD_POINT_DATA_LEN 0x04
483197704cSRobert Dolca #define SILEAD_POINT_Y_OFF 0x00
493197704cSRobert Dolca #define SILEAD_POINT_Y_MSB_OFF 0x01
503197704cSRobert Dolca #define SILEAD_POINT_X_OFF 0x02
513197704cSRobert Dolca #define SILEAD_POINT_X_MSB_OFF 0x03
52eca3be9bSHans de Goede #define SILEAD_EXTRA_DATA_MASK 0xF0
533197704cSRobert Dolca
543197704cSRobert Dolca #define SILEAD_CMD_SLEEP_MIN 10000
553197704cSRobert Dolca #define SILEAD_CMD_SLEEP_MAX 20000
563197704cSRobert Dolca #define SILEAD_POWER_SLEEP 20
573197704cSRobert Dolca #define SILEAD_STARTUP_SLEEP 30
583197704cSRobert Dolca
593197704cSRobert Dolca #define SILEAD_MAX_FINGERS 10
603197704cSRobert Dolca
613197704cSRobert Dolca enum silead_ts_power {
623197704cSRobert Dolca SILEAD_POWER_ON = 1,
633197704cSRobert Dolca SILEAD_POWER_OFF = 0
643197704cSRobert Dolca };
653197704cSRobert Dolca
663197704cSRobert Dolca struct silead_ts_data {
673197704cSRobert Dolca struct i2c_client *client;
683197704cSRobert Dolca struct gpio_desc *gpio_power;
693197704cSRobert Dolca struct input_dev *input;
70046612a3SHans de Goede struct input_dev *pen_input;
716f6deb48SHans de Goede struct regulator_bulk_data regulators[2];
723197704cSRobert Dolca char fw_name[64];
733197704cSRobert Dolca struct touchscreen_properties prop;
743197704cSRobert Dolca u32 chip_id;
753197704cSRobert Dolca struct input_mt_pos pos[SILEAD_MAX_FINGERS];
763197704cSRobert Dolca int slots[SILEAD_MAX_FINGERS];
773197704cSRobert Dolca int id[SILEAD_MAX_FINGERS];
7866d27d84SHans de Goede u32 efi_fw_min_max[4];
7966d27d84SHans de Goede bool efi_fw_min_max_set;
80046612a3SHans de Goede bool pen_supported;
81046612a3SHans de Goede bool pen_down;
82046612a3SHans de Goede u32 pen_x_res;
83046612a3SHans de Goede u32 pen_y_res;
84046612a3SHans de Goede int pen_up_count;
853197704cSRobert Dolca };
863197704cSRobert Dolca
873197704cSRobert Dolca struct silead_fw_data {
883197704cSRobert Dolca u32 offset;
893197704cSRobert Dolca u32 val;
903197704cSRobert Dolca };
913197704cSRobert Dolca
silead_apply_efi_fw_min_max(struct silead_ts_data * data)9266d27d84SHans de Goede static void silead_apply_efi_fw_min_max(struct silead_ts_data *data)
9366d27d84SHans de Goede {
9466d27d84SHans de Goede struct input_absinfo *absinfo_x = &data->input->absinfo[ABS_MT_POSITION_X];
9566d27d84SHans de Goede struct input_absinfo *absinfo_y = &data->input->absinfo[ABS_MT_POSITION_Y];
9666d27d84SHans de Goede
9766d27d84SHans de Goede if (!data->efi_fw_min_max_set)
9866d27d84SHans de Goede return;
9966d27d84SHans de Goede
10066d27d84SHans de Goede absinfo_x->minimum = data->efi_fw_min_max[0];
10166d27d84SHans de Goede absinfo_x->maximum = data->efi_fw_min_max[1];
10266d27d84SHans de Goede absinfo_y->minimum = data->efi_fw_min_max[2];
10366d27d84SHans de Goede absinfo_y->maximum = data->efi_fw_min_max[3];
10466d27d84SHans de Goede
10566d27d84SHans de Goede if (data->prop.invert_x) {
10666d27d84SHans de Goede absinfo_x->maximum -= absinfo_x->minimum;
10766d27d84SHans de Goede absinfo_x->minimum = 0;
10866d27d84SHans de Goede }
10966d27d84SHans de Goede
11066d27d84SHans de Goede if (data->prop.invert_y) {
11166d27d84SHans de Goede absinfo_y->maximum -= absinfo_y->minimum;
11266d27d84SHans de Goede absinfo_y->minimum = 0;
11366d27d84SHans de Goede }
11466d27d84SHans de Goede
11566d27d84SHans de Goede if (data->prop.swap_x_y) {
11666d27d84SHans de Goede swap(absinfo_x->minimum, absinfo_y->minimum);
11766d27d84SHans de Goede swap(absinfo_x->maximum, absinfo_y->maximum);
11866d27d84SHans de Goede }
11966d27d84SHans de Goede }
12066d27d84SHans de Goede
silead_ts_request_input_dev(struct silead_ts_data * data)1213197704cSRobert Dolca static int silead_ts_request_input_dev(struct silead_ts_data *data)
1223197704cSRobert Dolca {
1233197704cSRobert Dolca struct device *dev = &data->client->dev;
1243197704cSRobert Dolca int error;
1253197704cSRobert Dolca
1263197704cSRobert Dolca data->input = devm_input_allocate_device(dev);
1273197704cSRobert Dolca if (!data->input) {
1283197704cSRobert Dolca dev_err(dev,
1293197704cSRobert Dolca "Failed to allocate input device\n");
1303197704cSRobert Dolca return -ENOMEM;
1313197704cSRobert Dolca }
1323197704cSRobert Dolca
1333197704cSRobert Dolca input_set_abs_params(data->input, ABS_MT_POSITION_X, 0, 4095, 0, 0);
1343197704cSRobert Dolca input_set_abs_params(data->input, ABS_MT_POSITION_Y, 0, 4095, 0, 0);
1353197704cSRobert Dolca touchscreen_parse_properties(data->input, true, &data->prop);
13666d27d84SHans de Goede silead_apply_efi_fw_min_max(data);
1373197704cSRobert Dolca
138*9d88edbeSHans de Goede input_mt_init_slots(data->input, SILEAD_MAX_FINGERS,
1393197704cSRobert Dolca INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED |
1403197704cSRobert Dolca INPUT_MT_TRACK);
1413197704cSRobert Dolca
142eca3be9bSHans de Goede if (device_property_read_bool(dev, "silead,home-button"))
143eca3be9bSHans de Goede input_set_capability(data->input, EV_KEY, KEY_LEFTMETA);
144eca3be9bSHans de Goede
1453197704cSRobert Dolca data->input->name = SILEAD_TS_NAME;
1463197704cSRobert Dolca data->input->phys = "input/ts";
1473197704cSRobert Dolca data->input->id.bustype = BUS_I2C;
1483197704cSRobert Dolca
1493197704cSRobert Dolca error = input_register_device(data->input);
1503197704cSRobert Dolca if (error) {
1513197704cSRobert Dolca dev_err(dev, "Failed to register input device: %d\n", error);
1523197704cSRobert Dolca return error;
1533197704cSRobert Dolca }
1543197704cSRobert Dolca
1553197704cSRobert Dolca return 0;
1563197704cSRobert Dolca }
1573197704cSRobert Dolca
silead_ts_request_pen_input_dev(struct silead_ts_data * data)158046612a3SHans de Goede static int silead_ts_request_pen_input_dev(struct silead_ts_data *data)
159046612a3SHans de Goede {
160046612a3SHans de Goede struct device *dev = &data->client->dev;
161046612a3SHans de Goede int error;
162046612a3SHans de Goede
163046612a3SHans de Goede if (!data->pen_supported)
164046612a3SHans de Goede return 0;
165046612a3SHans de Goede
166046612a3SHans de Goede data->pen_input = devm_input_allocate_device(dev);
167046612a3SHans de Goede if (!data->pen_input)
168046612a3SHans de Goede return -ENOMEM;
169046612a3SHans de Goede
170046612a3SHans de Goede input_set_abs_params(data->pen_input, ABS_X, 0, 4095, 0, 0);
171046612a3SHans de Goede input_set_abs_params(data->pen_input, ABS_Y, 0, 4095, 0, 0);
172046612a3SHans de Goede input_set_capability(data->pen_input, EV_KEY, BTN_TOUCH);
173046612a3SHans de Goede input_set_capability(data->pen_input, EV_KEY, BTN_TOOL_PEN);
174046612a3SHans de Goede set_bit(INPUT_PROP_DIRECT, data->pen_input->propbit);
175046612a3SHans de Goede touchscreen_parse_properties(data->pen_input, false, &data->prop);
176046612a3SHans de Goede input_abs_set_res(data->pen_input, ABS_X, data->pen_x_res);
177046612a3SHans de Goede input_abs_set_res(data->pen_input, ABS_Y, data->pen_y_res);
178046612a3SHans de Goede
179046612a3SHans de Goede data->pen_input->name = SILEAD_TS_NAME " pen";
180046612a3SHans de Goede data->pen_input->phys = "input/pen";
181046612a3SHans de Goede data->input->id.bustype = BUS_I2C;
182046612a3SHans de Goede
183046612a3SHans de Goede error = input_register_device(data->pen_input);
184046612a3SHans de Goede if (error) {
185046612a3SHans de Goede dev_err(dev, "Failed to register pen input device: %d\n", error);
186046612a3SHans de Goede return error;
187046612a3SHans de Goede }
188046612a3SHans de Goede
189046612a3SHans de Goede return 0;
190046612a3SHans de Goede }
191046612a3SHans de Goede
silead_ts_set_power(struct i2c_client * client,enum silead_ts_power state)1923197704cSRobert Dolca static void silead_ts_set_power(struct i2c_client *client,
1933197704cSRobert Dolca enum silead_ts_power state)
1943197704cSRobert Dolca {
1953197704cSRobert Dolca struct silead_ts_data *data = i2c_get_clientdata(client);
1963197704cSRobert Dolca
1973197704cSRobert Dolca if (data->gpio_power) {
1983197704cSRobert Dolca gpiod_set_value_cansleep(data->gpio_power, state);
1993197704cSRobert Dolca msleep(SILEAD_POWER_SLEEP);
2003197704cSRobert Dolca }
2013197704cSRobert Dolca }
2023197704cSRobert Dolca
silead_ts_handle_pen_data(struct silead_ts_data * data,u8 * buf)203046612a3SHans de Goede static bool silead_ts_handle_pen_data(struct silead_ts_data *data, u8 *buf)
204046612a3SHans de Goede {
205046612a3SHans de Goede u8 *coord = buf + SILEAD_POINT_DATA_LEN;
206046612a3SHans de Goede struct input_mt_pos pos;
207046612a3SHans de Goede
208046612a3SHans de Goede if (!data->pen_supported || buf[2] != 0x00 || buf[3] != 0x00)
209046612a3SHans de Goede return false;
210046612a3SHans de Goede
211046612a3SHans de Goede if (buf[0] == 0x00 && buf[1] == 0x00 && data->pen_down) {
212046612a3SHans de Goede data->pen_up_count++;
213046612a3SHans de Goede if (data->pen_up_count == 6) {
214046612a3SHans de Goede data->pen_down = false;
215046612a3SHans de Goede goto sync;
216046612a3SHans de Goede }
217046612a3SHans de Goede return true;
218046612a3SHans de Goede }
219046612a3SHans de Goede
220046612a3SHans de Goede if (buf[0] == 0x01 && buf[1] == 0x08) {
221046612a3SHans de Goede touchscreen_set_mt_pos(&pos, &data->prop,
222046612a3SHans de Goede get_unaligned_le16(&coord[SILEAD_POINT_X_OFF]) & 0xfff,
223046612a3SHans de Goede get_unaligned_le16(&coord[SILEAD_POINT_Y_OFF]) & 0xfff);
224046612a3SHans de Goede
225046612a3SHans de Goede input_report_abs(data->pen_input, ABS_X, pos.x);
226046612a3SHans de Goede input_report_abs(data->pen_input, ABS_Y, pos.y);
227046612a3SHans de Goede
228046612a3SHans de Goede data->pen_up_count = 0;
229046612a3SHans de Goede data->pen_down = true;
230046612a3SHans de Goede goto sync;
231046612a3SHans de Goede }
232046612a3SHans de Goede
233046612a3SHans de Goede return false;
234046612a3SHans de Goede
235046612a3SHans de Goede sync:
236046612a3SHans de Goede input_report_key(data->pen_input, BTN_TOOL_PEN, data->pen_down);
237046612a3SHans de Goede input_report_key(data->pen_input, BTN_TOUCH, data->pen_down);
238046612a3SHans de Goede input_sync(data->pen_input);
239046612a3SHans de Goede return true;
240046612a3SHans de Goede }
241046612a3SHans de Goede
silead_ts_read_data(struct i2c_client * client)2423197704cSRobert Dolca static void silead_ts_read_data(struct i2c_client *client)
2433197704cSRobert Dolca {
2443197704cSRobert Dolca struct silead_ts_data *data = i2c_get_clientdata(client);
2453197704cSRobert Dolca struct input_dev *input = data->input;
2463197704cSRobert Dolca struct device *dev = &client->dev;
2473197704cSRobert Dolca u8 *bufp, buf[SILEAD_TS_DATA_LEN];
248eca3be9bSHans de Goede int touch_nr, softbutton, error, i;
249eca3be9bSHans de Goede bool softbutton_pressed = false;
2503197704cSRobert Dolca
2513197704cSRobert Dolca error = i2c_smbus_read_i2c_block_data(client, SILEAD_REG_DATA,
2523197704cSRobert Dolca SILEAD_TS_DATA_LEN, buf);
2533197704cSRobert Dolca if (error < 0) {
2543197704cSRobert Dolca dev_err(dev, "Data read error %d\n", error);
2553197704cSRobert Dolca return;
2563197704cSRobert Dolca }
2573197704cSRobert Dolca
258*9d88edbeSHans de Goede if (buf[0] > SILEAD_MAX_FINGERS) {
2593197704cSRobert Dolca dev_warn(dev, "More touches reported then supported %d > %d\n",
260*9d88edbeSHans de Goede buf[0], SILEAD_MAX_FINGERS);
261*9d88edbeSHans de Goede buf[0] = SILEAD_MAX_FINGERS;
2623197704cSRobert Dolca }
2633197704cSRobert Dolca
264046612a3SHans de Goede if (silead_ts_handle_pen_data(data, buf))
265046612a3SHans de Goede goto sync; /* Pen is down, release all previous touches */
266046612a3SHans de Goede
267eca3be9bSHans de Goede touch_nr = 0;
2683197704cSRobert Dolca bufp = buf + SILEAD_POINT_DATA_LEN;
269eca3be9bSHans de Goede for (i = 0; i < buf[0]; i++, bufp += SILEAD_POINT_DATA_LEN) {
270eca3be9bSHans de Goede softbutton = (bufp[SILEAD_POINT_Y_MSB_OFF] &
271eca3be9bSHans de Goede SILEAD_EXTRA_DATA_MASK) >> 4;
272eca3be9bSHans de Goede
273eca3be9bSHans de Goede if (softbutton) {
274eca3be9bSHans de Goede /*
275eca3be9bSHans de Goede * For now only respond to softbutton == 0x01, some
276eca3be9bSHans de Goede * tablets *without* a capacative button send 0x04
277eca3be9bSHans de Goede * when crossing the edges of the screen.
278eca3be9bSHans de Goede */
279eca3be9bSHans de Goede if (softbutton == 0x01)
280eca3be9bSHans de Goede softbutton_pressed = true;
281eca3be9bSHans de Goede
282eca3be9bSHans de Goede continue;
283eca3be9bSHans de Goede }
284eca3be9bSHans de Goede
285eca3be9bSHans de Goede /*
286eca3be9bSHans de Goede * Bits 4-7 are the touch id, note not all models have
287eca3be9bSHans de Goede * hardware touch ids so atm we don't use these.
288eca3be9bSHans de Goede */
289eca3be9bSHans de Goede data->id[touch_nr] = (bufp[SILEAD_POINT_X_MSB_OFF] &
290eca3be9bSHans de Goede SILEAD_EXTRA_DATA_MASK) >> 4;
291eca3be9bSHans de Goede touchscreen_set_mt_pos(&data->pos[touch_nr], &data->prop,
2923197704cSRobert Dolca get_unaligned_le16(&bufp[SILEAD_POINT_X_OFF]) & 0xfff,
2933197704cSRobert Dolca get_unaligned_le16(&bufp[SILEAD_POINT_Y_OFF]) & 0xfff);
294eca3be9bSHans de Goede touch_nr++;
2953197704cSRobert Dolca }
2963197704cSRobert Dolca
2973197704cSRobert Dolca input_mt_assign_slots(input, data->slots, data->pos, touch_nr, 0);
2983197704cSRobert Dolca
2993197704cSRobert Dolca for (i = 0; i < touch_nr; i++) {
3003197704cSRobert Dolca input_mt_slot(input, data->slots[i]);
3013197704cSRobert Dolca input_mt_report_slot_state(input, MT_TOOL_FINGER, true);
3023197704cSRobert Dolca input_report_abs(input, ABS_MT_POSITION_X, data->pos[i].x);
3033197704cSRobert Dolca input_report_abs(input, ABS_MT_POSITION_Y, data->pos[i].y);
3043197704cSRobert Dolca
3053197704cSRobert Dolca dev_dbg(dev, "x=%d y=%d hw_id=%d sw_id=%d\n", data->pos[i].x,
3063197704cSRobert Dolca data->pos[i].y, data->id[i], data->slots[i]);
3073197704cSRobert Dolca }
3083197704cSRobert Dolca
309046612a3SHans de Goede sync:
3103197704cSRobert Dolca input_mt_sync_frame(input);
311eca3be9bSHans de Goede input_report_key(input, KEY_LEFTMETA, softbutton_pressed);
3123197704cSRobert Dolca input_sync(input);
3133197704cSRobert Dolca }
3143197704cSRobert Dolca
silead_ts_init(struct i2c_client * client)3153197704cSRobert Dolca static int silead_ts_init(struct i2c_client *client)
3163197704cSRobert Dolca {
3173197704cSRobert Dolca int error;
3183197704cSRobert Dolca
3193197704cSRobert Dolca error = i2c_smbus_write_byte_data(client, SILEAD_REG_RESET,
3203197704cSRobert Dolca SILEAD_CMD_RESET);
3213197704cSRobert Dolca if (error)
3223197704cSRobert Dolca goto i2c_write_err;
3233197704cSRobert Dolca usleep_range(SILEAD_CMD_SLEEP_MIN, SILEAD_CMD_SLEEP_MAX);
3243197704cSRobert Dolca
3253197704cSRobert Dolca error = i2c_smbus_write_byte_data(client, SILEAD_REG_TOUCH_NR,
326*9d88edbeSHans de Goede SILEAD_MAX_FINGERS);
3273197704cSRobert Dolca if (error)
3283197704cSRobert Dolca goto i2c_write_err;
3293197704cSRobert Dolca usleep_range(SILEAD_CMD_SLEEP_MIN, SILEAD_CMD_SLEEP_MAX);
3303197704cSRobert Dolca
3313197704cSRobert Dolca error = i2c_smbus_write_byte_data(client, SILEAD_REG_CLOCK,
3323197704cSRobert Dolca SILEAD_CLOCK);
3333197704cSRobert Dolca if (error)
3343197704cSRobert Dolca goto i2c_write_err;
3353197704cSRobert Dolca usleep_range(SILEAD_CMD_SLEEP_MIN, SILEAD_CMD_SLEEP_MAX);
3363197704cSRobert Dolca
3373197704cSRobert Dolca error = i2c_smbus_write_byte_data(client, SILEAD_REG_RESET,
3383197704cSRobert Dolca SILEAD_CMD_START);
3393197704cSRobert Dolca if (error)
3403197704cSRobert Dolca goto i2c_write_err;
3413197704cSRobert Dolca usleep_range(SILEAD_CMD_SLEEP_MIN, SILEAD_CMD_SLEEP_MAX);
3423197704cSRobert Dolca
3433197704cSRobert Dolca return 0;
3443197704cSRobert Dolca
3453197704cSRobert Dolca i2c_write_err:
3463197704cSRobert Dolca dev_err(&client->dev, "Registers clear error %d\n", error);
3473197704cSRobert Dolca return error;
3483197704cSRobert Dolca }
3493197704cSRobert Dolca
silead_ts_reset(struct i2c_client * client)3503197704cSRobert Dolca static int silead_ts_reset(struct i2c_client *client)
3513197704cSRobert Dolca {
3523197704cSRobert Dolca int error;
3533197704cSRobert Dolca
3543197704cSRobert Dolca error = i2c_smbus_write_byte_data(client, SILEAD_REG_RESET,
3553197704cSRobert Dolca SILEAD_CMD_RESET);
3563197704cSRobert Dolca if (error)
3573197704cSRobert Dolca goto i2c_write_err;
3583197704cSRobert Dolca usleep_range(SILEAD_CMD_SLEEP_MIN, SILEAD_CMD_SLEEP_MAX);
3593197704cSRobert Dolca
3603197704cSRobert Dolca error = i2c_smbus_write_byte_data(client, SILEAD_REG_CLOCK,
3613197704cSRobert Dolca SILEAD_CLOCK);
3623197704cSRobert Dolca if (error)
3633197704cSRobert Dolca goto i2c_write_err;
3643197704cSRobert Dolca usleep_range(SILEAD_CMD_SLEEP_MIN, SILEAD_CMD_SLEEP_MAX);
3653197704cSRobert Dolca
3663197704cSRobert Dolca error = i2c_smbus_write_byte_data(client, SILEAD_REG_POWER,
3673197704cSRobert Dolca SILEAD_CMD_START);
3683197704cSRobert Dolca if (error)
3693197704cSRobert Dolca goto i2c_write_err;
3703197704cSRobert Dolca usleep_range(SILEAD_CMD_SLEEP_MIN, SILEAD_CMD_SLEEP_MAX);
3713197704cSRobert Dolca
3723197704cSRobert Dolca return 0;
3733197704cSRobert Dolca
3743197704cSRobert Dolca i2c_write_err:
3753197704cSRobert Dolca dev_err(&client->dev, "Chip reset error %d\n", error);
3763197704cSRobert Dolca return error;
3773197704cSRobert Dolca }
3783197704cSRobert Dolca
silead_ts_startup(struct i2c_client * client)3793197704cSRobert Dolca static int silead_ts_startup(struct i2c_client *client)
3803197704cSRobert Dolca {
3813197704cSRobert Dolca int error;
3823197704cSRobert Dolca
3833197704cSRobert Dolca error = i2c_smbus_write_byte_data(client, SILEAD_REG_RESET, 0x00);
3843197704cSRobert Dolca if (error) {
3853197704cSRobert Dolca dev_err(&client->dev, "Startup error %d\n", error);
3863197704cSRobert Dolca return error;
3873197704cSRobert Dolca }
3883197704cSRobert Dolca
3893197704cSRobert Dolca msleep(SILEAD_STARTUP_SLEEP);
3903197704cSRobert Dolca
3913197704cSRobert Dolca return 0;
3923197704cSRobert Dolca }
3933197704cSRobert Dolca
silead_ts_load_fw(struct i2c_client * client)3943197704cSRobert Dolca static int silead_ts_load_fw(struct i2c_client *client)
3953197704cSRobert Dolca {
3963197704cSRobert Dolca struct device *dev = &client->dev;
3973197704cSRobert Dolca struct silead_ts_data *data = i2c_get_clientdata(client);
39866d27d84SHans de Goede const struct firmware *fw = NULL;
3993197704cSRobert Dolca struct silead_fw_data *fw_data;
40066d27d84SHans de Goede unsigned int fw_size, i;
4013197704cSRobert Dolca int error;
4023197704cSRobert Dolca
4033197704cSRobert Dolca dev_dbg(dev, "Firmware file name: %s", data->fw_name);
4043197704cSRobert Dolca
40566d27d84SHans de Goede /*
40666d27d84SHans de Goede * Unfortunately, at the time of writing this comment, we have been unable to
40766d27d84SHans de Goede * get permission from Silead, or from device OEMs, to distribute the necessary
40866d27d84SHans de Goede * Silead firmware files in linux-firmware.
40966d27d84SHans de Goede *
41066d27d84SHans de Goede * On a whole bunch of devices the UEFI BIOS code contains a touchscreen driver,
41166d27d84SHans de Goede * which contains an embedded copy of the firmware. The fw-loader code has a
41266d27d84SHans de Goede * "platform" fallback mechanism, which together with info on the firmware
41366d27d84SHans de Goede * from drivers/platform/x86/touchscreen_dmi.c will use the firmware from the
41466d27d84SHans de Goede * UEFI driver when the firmware is missing from /lib/firmware. This makes the
41566d27d84SHans de Goede * touchscreen work OOTB without users needing to manually download the firmware.
41666d27d84SHans de Goede *
41766d27d84SHans de Goede * The firmware bundled with the original Windows/Android is usually newer then
41866d27d84SHans de Goede * the firmware in the UEFI driver and it is better calibrated. This better
41966d27d84SHans de Goede * calibration can lead to significant differences in the reported min/max
42066d27d84SHans de Goede * coordinates.
42166d27d84SHans de Goede *
42266d27d84SHans de Goede * To deal with this we first try to load the firmware without "platform"
42366d27d84SHans de Goede * fallback. If that fails we retry with "platform" fallback and if that
42466d27d84SHans de Goede * succeeds we apply an (optional) set of alternative min/max values from the
42566d27d84SHans de Goede * "silead,efi-fw-min-max" property.
42666d27d84SHans de Goede */
42766d27d84SHans de Goede error = firmware_request_nowarn(&fw, data->fw_name, dev);
42866d27d84SHans de Goede if (error) {
429b4a87bcdSHans de Goede error = firmware_request_platform(&fw, data->fw_name, dev);
4303197704cSRobert Dolca if (error) {
4313197704cSRobert Dolca dev_err(dev, "Firmware request error %d\n", error);
4323197704cSRobert Dolca return error;
4333197704cSRobert Dolca }
4343197704cSRobert Dolca
43566d27d84SHans de Goede error = device_property_read_u32_array(dev, "silead,efi-fw-min-max",
43666d27d84SHans de Goede data->efi_fw_min_max,
43766d27d84SHans de Goede ARRAY_SIZE(data->efi_fw_min_max));
43866d27d84SHans de Goede if (!error)
43966d27d84SHans de Goede data->efi_fw_min_max_set = true;
440046612a3SHans de Goede
441046612a3SHans de Goede /* The EFI (platform) embedded fw does not have pen support */
442046612a3SHans de Goede if (data->pen_supported) {
443046612a3SHans de Goede dev_warn(dev, "Warning loading '%s' from filesystem failed, using EFI embedded copy.\n",
444046612a3SHans de Goede data->fw_name);
445046612a3SHans de Goede dev_warn(dev, "Warning pen support is known to be broken in the EFI embedded fw version\n");
446046612a3SHans de Goede data->pen_supported = false;
447046612a3SHans de Goede }
44866d27d84SHans de Goede }
44966d27d84SHans de Goede
4503197704cSRobert Dolca fw_size = fw->size / sizeof(*fw_data);
4513197704cSRobert Dolca fw_data = (struct silead_fw_data *)fw->data;
4523197704cSRobert Dolca
4533197704cSRobert Dolca for (i = 0; i < fw_size; i++) {
4543197704cSRobert Dolca error = i2c_smbus_write_i2c_block_data(client,
4553197704cSRobert Dolca fw_data[i].offset,
4563197704cSRobert Dolca 4,
4573197704cSRobert Dolca (u8 *)&fw_data[i].val);
4583197704cSRobert Dolca if (error) {
4593197704cSRobert Dolca dev_err(dev, "Firmware load error %d\n", error);
4603197704cSRobert Dolca break;
4613197704cSRobert Dolca }
4623197704cSRobert Dolca }
4633197704cSRobert Dolca
4643197704cSRobert Dolca release_firmware(fw);
4653197704cSRobert Dolca return error ?: 0;
4663197704cSRobert Dolca }
4673197704cSRobert Dolca
silead_ts_get_status(struct i2c_client * client)4683197704cSRobert Dolca static u32 silead_ts_get_status(struct i2c_client *client)
4693197704cSRobert Dolca {
4703197704cSRobert Dolca int error;
4713197704cSRobert Dolca __le32 status;
4723197704cSRobert Dolca
4733197704cSRobert Dolca error = i2c_smbus_read_i2c_block_data(client, SILEAD_REG_STATUS,
4743197704cSRobert Dolca sizeof(status), (u8 *)&status);
4753197704cSRobert Dolca if (error < 0) {
4763197704cSRobert Dolca dev_err(&client->dev, "Status read error %d\n", error);
4773197704cSRobert Dolca return error;
4783197704cSRobert Dolca }
4793197704cSRobert Dolca
4803197704cSRobert Dolca return le32_to_cpu(status);
4813197704cSRobert Dolca }
4823197704cSRobert Dolca
silead_ts_get_id(struct i2c_client * client)4833197704cSRobert Dolca static int silead_ts_get_id(struct i2c_client *client)
4843197704cSRobert Dolca {
4853197704cSRobert Dolca struct silead_ts_data *data = i2c_get_clientdata(client);
4863197704cSRobert Dolca __le32 chip_id;
4873197704cSRobert Dolca int error;
4883197704cSRobert Dolca
4893197704cSRobert Dolca error = i2c_smbus_read_i2c_block_data(client, SILEAD_REG_ID,
4903197704cSRobert Dolca sizeof(chip_id), (u8 *)&chip_id);
491e4791877SHans de Goede if (error < 0)
4923197704cSRobert Dolca return error;
4933197704cSRobert Dolca
4943197704cSRobert Dolca data->chip_id = le32_to_cpu(chip_id);
4953197704cSRobert Dolca dev_info(&client->dev, "Silead chip ID: 0x%8X", data->chip_id);
4963197704cSRobert Dolca
4973197704cSRobert Dolca return 0;
4983197704cSRobert Dolca }
4993197704cSRobert Dolca
silead_ts_setup(struct i2c_client * client)5003197704cSRobert Dolca static int silead_ts_setup(struct i2c_client *client)
5013197704cSRobert Dolca {
5023197704cSRobert Dolca int error;
5033197704cSRobert Dolca u32 status;
5043197704cSRobert Dolca
505e4791877SHans de Goede /*
506e4791877SHans de Goede * Some buggy BIOS-es bring up the chip in a stuck state where it
507e4791877SHans de Goede * blocks the I2C bus. The following steps are necessary to
508e4791877SHans de Goede * unstuck the chip / bus:
509e4791877SHans de Goede * 1. Turn off the Silead chip.
510e4791877SHans de Goede * 2. Try to do an I2C transfer with the chip, this will fail in
511e4791877SHans de Goede * response to which the I2C-bus-driver will call:
512e4791877SHans de Goede * i2c_recover_bus() which will unstuck the I2C-bus. Note the
513e4791877SHans de Goede * unstuck-ing of the I2C bus only works if we first drop the
514e4791877SHans de Goede * chip off the bus by turning it off.
515e4791877SHans de Goede * 3. Turn the chip back on.
516e4791877SHans de Goede *
517e4791877SHans de Goede * On the x86/ACPI systems were this problem is seen, step 1. and
518e4791877SHans de Goede * 3. require making ACPI calls and dealing with ACPI Power
519e4791877SHans de Goede * Resources. The workaround below runtime-suspends the chip to
520e4791877SHans de Goede * turn it off, leaving it up to the ACPI subsystem to deal with
521e4791877SHans de Goede * this.
522e4791877SHans de Goede */
523e4791877SHans de Goede
524e4791877SHans de Goede if (device_property_read_bool(&client->dev,
525e4791877SHans de Goede "silead,stuck-controller-bug")) {
526e4791877SHans de Goede pm_runtime_set_active(&client->dev);
527e4791877SHans de Goede pm_runtime_enable(&client->dev);
528e4791877SHans de Goede pm_runtime_allow(&client->dev);
529e4791877SHans de Goede
530e4791877SHans de Goede pm_runtime_suspend(&client->dev);
531e4791877SHans de Goede
532e4791877SHans de Goede dev_warn(&client->dev, FW_BUG "Stuck I2C bus: please ignore the next 'controller timed out' error\n");
533e4791877SHans de Goede silead_ts_get_id(client);
534e4791877SHans de Goede
535e4791877SHans de Goede /* The forbid will also resume the device */
536e4791877SHans de Goede pm_runtime_forbid(&client->dev);
537e4791877SHans de Goede pm_runtime_disable(&client->dev);
538e4791877SHans de Goede }
539e4791877SHans de Goede
5403197704cSRobert Dolca silead_ts_set_power(client, SILEAD_POWER_OFF);
5413197704cSRobert Dolca silead_ts_set_power(client, SILEAD_POWER_ON);
5423197704cSRobert Dolca
5433197704cSRobert Dolca error = silead_ts_get_id(client);
544e4791877SHans de Goede if (error) {
545e4791877SHans de Goede dev_err(&client->dev, "Chip ID read error %d\n", error);
5463197704cSRobert Dolca return error;
547e4791877SHans de Goede }
5483197704cSRobert Dolca
5493197704cSRobert Dolca error = silead_ts_init(client);
5503197704cSRobert Dolca if (error)
5513197704cSRobert Dolca return error;
5523197704cSRobert Dolca
5533197704cSRobert Dolca error = silead_ts_reset(client);
5543197704cSRobert Dolca if (error)
5553197704cSRobert Dolca return error;
5563197704cSRobert Dolca
5573197704cSRobert Dolca error = silead_ts_load_fw(client);
5583197704cSRobert Dolca if (error)
5593197704cSRobert Dolca return error;
5603197704cSRobert Dolca
5613197704cSRobert Dolca error = silead_ts_startup(client);
5623197704cSRobert Dolca if (error)
5633197704cSRobert Dolca return error;
5643197704cSRobert Dolca
5653197704cSRobert Dolca status = silead_ts_get_status(client);
5663197704cSRobert Dolca if (status != SILEAD_STATUS_OK) {
5673197704cSRobert Dolca dev_err(&client->dev,
5683197704cSRobert Dolca "Initialization error, status: 0x%X\n", status);
5693197704cSRobert Dolca return -ENODEV;
5703197704cSRobert Dolca }
5713197704cSRobert Dolca
5723197704cSRobert Dolca return 0;
5733197704cSRobert Dolca }
5743197704cSRobert Dolca
silead_ts_threaded_irq_handler(int irq,void * id)5753197704cSRobert Dolca static irqreturn_t silead_ts_threaded_irq_handler(int irq, void *id)
5763197704cSRobert Dolca {
5773197704cSRobert Dolca struct silead_ts_data *data = id;
5783197704cSRobert Dolca struct i2c_client *client = data->client;
5793197704cSRobert Dolca
5803197704cSRobert Dolca silead_ts_read_data(client);
5813197704cSRobert Dolca
5823197704cSRobert Dolca return IRQ_HANDLED;
5833197704cSRobert Dolca }
5843197704cSRobert Dolca
silead_ts_read_props(struct i2c_client * client)5853197704cSRobert Dolca static void silead_ts_read_props(struct i2c_client *client)
5863197704cSRobert Dolca {
5873197704cSRobert Dolca struct silead_ts_data *data = i2c_get_clientdata(client);
5883197704cSRobert Dolca struct device *dev = &client->dev;
5893197704cSRobert Dolca const char *str;
5903197704cSRobert Dolca int error;
5913197704cSRobert Dolca
59243ba5883SHans de Goede error = device_property_read_string(dev, "firmware-name", &str);
5933197704cSRobert Dolca if (!error)
59443ba5883SHans de Goede snprintf(data->fw_name, sizeof(data->fw_name),
59543ba5883SHans de Goede "silead/%s", str);
5963197704cSRobert Dolca else
5973197704cSRobert Dolca dev_dbg(dev, "Firmware file name read error. Using default.");
598046612a3SHans de Goede
599046612a3SHans de Goede data->pen_supported = device_property_read_bool(dev, "silead,pen-supported");
600046612a3SHans de Goede device_property_read_u32(dev, "silead,pen-resolution-x", &data->pen_x_res);
601046612a3SHans de Goede device_property_read_u32(dev, "silead,pen-resolution-y", &data->pen_y_res);
6023197704cSRobert Dolca }
6033197704cSRobert Dolca
6043197704cSRobert Dolca #ifdef CONFIG_ACPI
silead_ts_set_default_fw_name(struct silead_ts_data * data,const struct i2c_device_id * id)6053197704cSRobert Dolca static int silead_ts_set_default_fw_name(struct silead_ts_data *data,
6063197704cSRobert Dolca const struct i2c_device_id *id)
6073197704cSRobert Dolca {
6083197704cSRobert Dolca const struct acpi_device_id *acpi_id;
6093197704cSRobert Dolca struct device *dev = &data->client->dev;
6103197704cSRobert Dolca int i;
6113197704cSRobert Dolca
6123197704cSRobert Dolca if (ACPI_HANDLE(dev)) {
6133197704cSRobert Dolca acpi_id = acpi_match_device(dev->driver->acpi_match_table, dev);
6143197704cSRobert Dolca if (!acpi_id)
6153197704cSRobert Dolca return -ENODEV;
6163197704cSRobert Dolca
6174af2ff91SHans de Goede snprintf(data->fw_name, sizeof(data->fw_name),
6184af2ff91SHans de Goede "silead/%s.fw", acpi_id->id);
6193197704cSRobert Dolca
6203197704cSRobert Dolca for (i = 0; i < strlen(data->fw_name); i++)
6213197704cSRobert Dolca data->fw_name[i] = tolower(data->fw_name[i]);
6223197704cSRobert Dolca } else {
6234af2ff91SHans de Goede snprintf(data->fw_name, sizeof(data->fw_name),
6244af2ff91SHans de Goede "silead/%s.fw", id->name);
6253197704cSRobert Dolca }
6263197704cSRobert Dolca
6273197704cSRobert Dolca return 0;
6283197704cSRobert Dolca }
6293197704cSRobert Dolca #else
silead_ts_set_default_fw_name(struct silead_ts_data * data,const struct i2c_device_id * id)6303197704cSRobert Dolca static int silead_ts_set_default_fw_name(struct silead_ts_data *data,
6313197704cSRobert Dolca const struct i2c_device_id *id)
6323197704cSRobert Dolca {
6334af2ff91SHans de Goede snprintf(data->fw_name, sizeof(data->fw_name),
6344af2ff91SHans de Goede "silead/%s.fw", id->name);
6353197704cSRobert Dolca return 0;
6363197704cSRobert Dolca }
6373197704cSRobert Dolca #endif
6383197704cSRobert Dolca
silead_disable_regulator(void * arg)6396f6deb48SHans de Goede static void silead_disable_regulator(void *arg)
6406f6deb48SHans de Goede {
6416f6deb48SHans de Goede struct silead_ts_data *data = arg;
6426f6deb48SHans de Goede
6436f6deb48SHans de Goede regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators);
6446f6deb48SHans de Goede }
6456f6deb48SHans de Goede
silead_ts_probe(struct i2c_client * client)64609a77dc4SUwe Kleine-König static int silead_ts_probe(struct i2c_client *client)
6473197704cSRobert Dolca {
64809a77dc4SUwe Kleine-König const struct i2c_device_id *id = i2c_client_get_device_id(client);
6493197704cSRobert Dolca struct silead_ts_data *data;
6503197704cSRobert Dolca struct device *dev = &client->dev;
6513197704cSRobert Dolca int error;
6523197704cSRobert Dolca
6533197704cSRobert Dolca if (!i2c_check_functionality(client->adapter,
6543197704cSRobert Dolca I2C_FUNC_I2C |
6553197704cSRobert Dolca I2C_FUNC_SMBUS_READ_I2C_BLOCK |
6563197704cSRobert Dolca I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) {
6573197704cSRobert Dolca dev_err(dev, "I2C functionality check failed\n");
6583197704cSRobert Dolca return -ENXIO;
6593197704cSRobert Dolca }
6603197704cSRobert Dolca
6613197704cSRobert Dolca data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
6623197704cSRobert Dolca if (!data)
6633197704cSRobert Dolca return -ENOMEM;
6643197704cSRobert Dolca
6653197704cSRobert Dolca i2c_set_clientdata(client, data);
6663197704cSRobert Dolca data->client = client;
6673197704cSRobert Dolca
6683197704cSRobert Dolca error = silead_ts_set_default_fw_name(data, id);
6693197704cSRobert Dolca if (error)
6703197704cSRobert Dolca return error;
6713197704cSRobert Dolca
6723197704cSRobert Dolca silead_ts_read_props(client);
6733197704cSRobert Dolca
6744c976acbSBhaskar Chowdhury /* We must have the IRQ provided by DT or ACPI subsystem */
6753197704cSRobert Dolca if (client->irq <= 0)
6763197704cSRobert Dolca return -ENODEV;
6773197704cSRobert Dolca
6786f6deb48SHans de Goede data->regulators[0].supply = "vddio";
6796f6deb48SHans de Goede data->regulators[1].supply = "avdd";
6806f6deb48SHans de Goede error = devm_regulator_bulk_get(dev, ARRAY_SIZE(data->regulators),
6816f6deb48SHans de Goede data->regulators);
6826f6deb48SHans de Goede if (error)
6836f6deb48SHans de Goede return error;
6846f6deb48SHans de Goede
6856f6deb48SHans de Goede /*
6866f6deb48SHans de Goede * Enable regulators at probe and disable them at remove, we need
6876f6deb48SHans de Goede * to keep the chip powered otherwise it forgets its firmware.
6886f6deb48SHans de Goede */
6896f6deb48SHans de Goede error = regulator_bulk_enable(ARRAY_SIZE(data->regulators),
6906f6deb48SHans de Goede data->regulators);
6916f6deb48SHans de Goede if (error)
6926f6deb48SHans de Goede return error;
6936f6deb48SHans de Goede
6946f6deb48SHans de Goede error = devm_add_action_or_reset(dev, silead_disable_regulator, data);
6956f6deb48SHans de Goede if (error)
6966f6deb48SHans de Goede return error;
6976f6deb48SHans de Goede
6983197704cSRobert Dolca /* Power GPIO pin */
6995cab4d84SHans de Goede data->gpio_power = devm_gpiod_get_optional(dev, "power", GPIOD_OUT_LOW);
70021142c1cSKrzysztof Kozlowski if (IS_ERR(data->gpio_power))
70121142c1cSKrzysztof Kozlowski return dev_err_probe(dev, PTR_ERR(data->gpio_power),
70221142c1cSKrzysztof Kozlowski "Shutdown GPIO request failed\n");
7033197704cSRobert Dolca
7043197704cSRobert Dolca error = silead_ts_setup(client);
7053197704cSRobert Dolca if (error)
7063197704cSRobert Dolca return error;
7073197704cSRobert Dolca
7083197704cSRobert Dolca error = silead_ts_request_input_dev(data);
7093197704cSRobert Dolca if (error)
7103197704cSRobert Dolca return error;
7113197704cSRobert Dolca
712046612a3SHans de Goede error = silead_ts_request_pen_input_dev(data);
713046612a3SHans de Goede if (error)
714046612a3SHans de Goede return error;
715046612a3SHans de Goede
7163197704cSRobert Dolca error = devm_request_threaded_irq(dev, client->irq,
7173197704cSRobert Dolca NULL, silead_ts_threaded_irq_handler,
7183197704cSRobert Dolca IRQF_ONESHOT, client->name, data);
7193197704cSRobert Dolca if (error) {
7203197704cSRobert Dolca if (error != -EPROBE_DEFER)
7213197704cSRobert Dolca dev_err(dev, "IRQ request failed %d\n", error);
7223197704cSRobert Dolca return error;
7233197704cSRobert Dolca }
7243197704cSRobert Dolca
7253197704cSRobert Dolca return 0;
7263197704cSRobert Dolca }
7273197704cSRobert Dolca
silead_ts_suspend(struct device * dev)7285a886382SJonathan Cameron static int silead_ts_suspend(struct device *dev)
7293197704cSRobert Dolca {
7303197704cSRobert Dolca struct i2c_client *client = to_i2c_client(dev);
7313197704cSRobert Dolca
7321943d172SHans de Goede disable_irq(client->irq);
7333197704cSRobert Dolca silead_ts_set_power(client, SILEAD_POWER_OFF);
7343197704cSRobert Dolca return 0;
7353197704cSRobert Dolca }
7363197704cSRobert Dolca
silead_ts_resume(struct device * dev)7375a886382SJonathan Cameron static int silead_ts_resume(struct device *dev)
7383197704cSRobert Dolca {
7393197704cSRobert Dolca struct i2c_client *client = to_i2c_client(dev);
740dde27443SJulian Sax bool second_try = false;
7413197704cSRobert Dolca int error, status;
7423197704cSRobert Dolca
7433197704cSRobert Dolca silead_ts_set_power(client, SILEAD_POWER_ON);
7443197704cSRobert Dolca
745dde27443SJulian Sax retry:
7463197704cSRobert Dolca error = silead_ts_reset(client);
7473197704cSRobert Dolca if (error)
7483197704cSRobert Dolca return error;
7493197704cSRobert Dolca
750dde27443SJulian Sax if (second_try) {
751dde27443SJulian Sax error = silead_ts_load_fw(client);
752dde27443SJulian Sax if (error)
753dde27443SJulian Sax return error;
754dde27443SJulian Sax }
755dde27443SJulian Sax
7563197704cSRobert Dolca error = silead_ts_startup(client);
7573197704cSRobert Dolca if (error)
7583197704cSRobert Dolca return error;
7593197704cSRobert Dolca
7603197704cSRobert Dolca status = silead_ts_get_status(client);
7613197704cSRobert Dolca if (status != SILEAD_STATUS_OK) {
762dde27443SJulian Sax if (!second_try) {
763dde27443SJulian Sax second_try = true;
764dde27443SJulian Sax dev_dbg(dev, "Reloading firmware after unsuccessful resume\n");
765dde27443SJulian Sax goto retry;
766dde27443SJulian Sax }
7673197704cSRobert Dolca dev_err(dev, "Resume error, status: 0x%02x\n", status);
7683197704cSRobert Dolca return -ENODEV;
7693197704cSRobert Dolca }
7703197704cSRobert Dolca
7711943d172SHans de Goede enable_irq(client->irq);
7721943d172SHans de Goede
7733197704cSRobert Dolca return 0;
7743197704cSRobert Dolca }
7753197704cSRobert Dolca
7765a886382SJonathan Cameron static DEFINE_SIMPLE_DEV_PM_OPS(silead_ts_pm, silead_ts_suspend, silead_ts_resume);
7773197704cSRobert Dolca
7783197704cSRobert Dolca static const struct i2c_device_id silead_ts_id[] = {
7793197704cSRobert Dolca { "gsl1680", 0 },
7803197704cSRobert Dolca { "gsl1688", 0 },
7813197704cSRobert Dolca { "gsl3670", 0 },
7823197704cSRobert Dolca { "gsl3675", 0 },
7833197704cSRobert Dolca { "gsl3692", 0 },
7843197704cSRobert Dolca { "mssl1680", 0 },
7853197704cSRobert Dolca { }
7863197704cSRobert Dolca };
7873197704cSRobert Dolca MODULE_DEVICE_TABLE(i2c, silead_ts_id);
7883197704cSRobert Dolca
7893197704cSRobert Dolca #ifdef CONFIG_ACPI
7903197704cSRobert Dolca static const struct acpi_device_id silead_ts_acpi_match[] = {
7913197704cSRobert Dolca { "GSL1680", 0 },
7923197704cSRobert Dolca { "GSL1688", 0 },
7933197704cSRobert Dolca { "GSL3670", 0 },
7943197704cSRobert Dolca { "GSL3675", 0 },
7953197704cSRobert Dolca { "GSL3692", 0 },
7963197704cSRobert Dolca { "MSSL1680", 0 },
7973993a163SMaruyama Shohei { "MSSL0001", 0 },
798fc573af6SHans de Goede { "MSSL0002", 0 },
7990e658060SDaniel Smith { "MSSL0017", 0 },
8003197704cSRobert Dolca { }
8013197704cSRobert Dolca };
8023197704cSRobert Dolca MODULE_DEVICE_TABLE(acpi, silead_ts_acpi_match);
8033197704cSRobert Dolca #endif
8043197704cSRobert Dolca
805483e55d9SJavier Martinez Canillas #ifdef CONFIG_OF
806483e55d9SJavier Martinez Canillas static const struct of_device_id silead_ts_of_match[] = {
807483e55d9SJavier Martinez Canillas { .compatible = "silead,gsl1680" },
808483e55d9SJavier Martinez Canillas { .compatible = "silead,gsl1688" },
809483e55d9SJavier Martinez Canillas { .compatible = "silead,gsl3670" },
810483e55d9SJavier Martinez Canillas { .compatible = "silead,gsl3675" },
811483e55d9SJavier Martinez Canillas { .compatible = "silead,gsl3692" },
812483e55d9SJavier Martinez Canillas { },
813483e55d9SJavier Martinez Canillas };
814483e55d9SJavier Martinez Canillas MODULE_DEVICE_TABLE(of, silead_ts_of_match);
815483e55d9SJavier Martinez Canillas #endif
816483e55d9SJavier Martinez Canillas
8173197704cSRobert Dolca static struct i2c_driver silead_ts_driver = {
818d8bde56dSUwe Kleine-König .probe = silead_ts_probe,
8193197704cSRobert Dolca .id_table = silead_ts_id,
8203197704cSRobert Dolca .driver = {
8213197704cSRobert Dolca .name = SILEAD_TS_NAME,
8223197704cSRobert Dolca .acpi_match_table = ACPI_PTR(silead_ts_acpi_match),
823483e55d9SJavier Martinez Canillas .of_match_table = of_match_ptr(silead_ts_of_match),
8245a886382SJonathan Cameron .pm = pm_sleep_ptr(&silead_ts_pm),
8253197704cSRobert Dolca },
8263197704cSRobert Dolca };
8273197704cSRobert Dolca module_i2c_driver(silead_ts_driver);
8283197704cSRobert Dolca
8293197704cSRobert Dolca MODULE_AUTHOR("Robert Dolca <robert.dolca@intel.com>");
8303197704cSRobert Dolca MODULE_DESCRIPTION("Silead I2C touchscreen driver");
8313197704cSRobert Dolca MODULE_LICENSE("GPL");
832