bu21013_ts.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) ST-Ericsson SA 2010
  4. * Author: Naveen Kumar G <[email protected]> for ST-Ericsson
  5. */
  6. #include <linux/bitops.h>
  7. #include <linux/delay.h>
  8. #include <linux/gpio/consumer.h>
  9. #include <linux/i2c.h>
  10. #include <linux/input.h>
  11. #include <linux/input/mt.h>
  12. #include <linux/input/touchscreen.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/property.h>
  17. #include <linux/regulator/consumer.h>
  18. #include <linux/slab.h>
  19. #include <linux/types.h>
  20. #define MAX_FINGERS 2
  21. #define RESET_DELAY 30
  22. #define PENUP_TIMEOUT (10)
  23. #define DELTA_MIN 16
  24. #define MASK_BITS 0x03
  25. #define SHIFT_8 8
  26. #define SHIFT_2 2
  27. #define LENGTH_OF_BUFFER 11
  28. #define I2C_RETRY_COUNT 5
  29. #define BU21013_SENSORS_BTN_0_7_REG 0x70
  30. #define BU21013_SENSORS_BTN_8_15_REG 0x71
  31. #define BU21013_SENSORS_BTN_16_23_REG 0x72
  32. #define BU21013_X1_POS_MSB_REG 0x73
  33. #define BU21013_X1_POS_LSB_REG 0x74
  34. #define BU21013_Y1_POS_MSB_REG 0x75
  35. #define BU21013_Y1_POS_LSB_REG 0x76
  36. #define BU21013_X2_POS_MSB_REG 0x77
  37. #define BU21013_X2_POS_LSB_REG 0x78
  38. #define BU21013_Y2_POS_MSB_REG 0x79
  39. #define BU21013_Y2_POS_LSB_REG 0x7A
  40. #define BU21013_INT_CLR_REG 0xE8
  41. #define BU21013_INT_MODE_REG 0xE9
  42. #define BU21013_GAIN_REG 0xEA
  43. #define BU21013_OFFSET_MODE_REG 0xEB
  44. #define BU21013_XY_EDGE_REG 0xEC
  45. #define BU21013_RESET_REG 0xED
  46. #define BU21013_CALIB_REG 0xEE
  47. #define BU21013_DONE_REG 0xEF
  48. #define BU21013_SENSOR_0_7_REG 0xF0
  49. #define BU21013_SENSOR_8_15_REG 0xF1
  50. #define BU21013_SENSOR_16_23_REG 0xF2
  51. #define BU21013_POS_MODE1_REG 0xF3
  52. #define BU21013_POS_MODE2_REG 0xF4
  53. #define BU21013_CLK_MODE_REG 0xF5
  54. #define BU21013_IDLE_REG 0xFA
  55. #define BU21013_FILTER_REG 0xFB
  56. #define BU21013_TH_ON_REG 0xFC
  57. #define BU21013_TH_OFF_REG 0xFD
  58. #define BU21013_RESET_ENABLE 0x01
  59. #define BU21013_SENSORS_EN_0_7 0x3F
  60. #define BU21013_SENSORS_EN_8_15 0xFC
  61. #define BU21013_SENSORS_EN_16_23 0x1F
  62. #define BU21013_POS_MODE1_0 0x02
  63. #define BU21013_POS_MODE1_1 0x04
  64. #define BU21013_POS_MODE1_2 0x08
  65. #define BU21013_POS_MODE2_ZERO 0x01
  66. #define BU21013_POS_MODE2_AVG1 0x02
  67. #define BU21013_POS_MODE2_AVG2 0x04
  68. #define BU21013_POS_MODE2_EN_XY 0x08
  69. #define BU21013_POS_MODE2_EN_RAW 0x10
  70. #define BU21013_POS_MODE2_MULTI 0x80
  71. #define BU21013_CLK_MODE_DIV 0x01
  72. #define BU21013_CLK_MODE_EXT 0x02
  73. #define BU21013_CLK_MODE_CALIB 0x80
  74. #define BU21013_IDLET_0 0x01
  75. #define BU21013_IDLET_1 0x02
  76. #define BU21013_IDLET_2 0x04
  77. #define BU21013_IDLET_3 0x08
  78. #define BU21013_IDLE_INTERMIT_EN 0x10
  79. #define BU21013_DELTA_0_6 0x7F
  80. #define BU21013_FILTER_EN 0x80
  81. #define BU21013_INT_MODE_LEVEL 0x00
  82. #define BU21013_INT_MODE_EDGE 0x01
  83. #define BU21013_GAIN_0 0x01
  84. #define BU21013_GAIN_1 0x02
  85. #define BU21013_GAIN_2 0x04
  86. #define BU21013_OFFSET_MODE_DEFAULT 0x00
  87. #define BU21013_OFFSET_MODE_MOVE 0x01
  88. #define BU21013_OFFSET_MODE_DISABLE 0x02
  89. #define BU21013_TH_ON_0 0x01
  90. #define BU21013_TH_ON_1 0x02
  91. #define BU21013_TH_ON_2 0x04
  92. #define BU21013_TH_ON_3 0x08
  93. #define BU21013_TH_ON_4 0x10
  94. #define BU21013_TH_ON_5 0x20
  95. #define BU21013_TH_ON_6 0x40
  96. #define BU21013_TH_ON_7 0x80
  97. #define BU21013_TH_ON_MAX 0xFF
  98. #define BU21013_TH_OFF_0 0x01
  99. #define BU21013_TH_OFF_1 0x02
  100. #define BU21013_TH_OFF_2 0x04
  101. #define BU21013_TH_OFF_3 0x08
  102. #define BU21013_TH_OFF_4 0x10
  103. #define BU21013_TH_OFF_5 0x20
  104. #define BU21013_TH_OFF_6 0x40
  105. #define BU21013_TH_OFF_7 0x80
  106. #define BU21013_TH_OFF_MAX 0xFF
  107. #define BU21013_X_EDGE_0 0x01
  108. #define BU21013_X_EDGE_1 0x02
  109. #define BU21013_X_EDGE_2 0x04
  110. #define BU21013_X_EDGE_3 0x08
  111. #define BU21013_Y_EDGE_0 0x10
  112. #define BU21013_Y_EDGE_1 0x20
  113. #define BU21013_Y_EDGE_2 0x40
  114. #define BU21013_Y_EDGE_3 0x80
  115. #define BU21013_DONE 0x01
  116. #define BU21013_NUMBER_OF_X_SENSORS (6)
  117. #define BU21013_NUMBER_OF_Y_SENSORS (11)
  118. #define DRIVER_TP "bu21013_tp"
  119. /**
  120. * struct bu21013_ts - touch panel data structure
  121. * @client: pointer to the i2c client
  122. * @in_dev: pointer to the input device structure
  123. * @props: the device coordinate transformation properties
  124. * @regulator: pointer to the Regulator used for touch screen
  125. * @cs_gpiod: chip select GPIO line
  126. * @int_gpiod: touch interrupt GPIO line
  127. * @touch_x_max: maximum X coordinate reported by the device
  128. * @touch_y_max: maximum Y coordinate reported by the device
  129. * @x_flip: indicates that the driver should invert X coordinate before
  130. * reporting
  131. * @y_flip: indicates that the driver should invert Y coordinate before
  132. * reporting
  133. * @touch_stopped: touch stop flag
  134. *
  135. * Touch panel device data structure
  136. */
  137. struct bu21013_ts {
  138. struct i2c_client *client;
  139. struct input_dev *in_dev;
  140. struct touchscreen_properties props;
  141. struct regulator *regulator;
  142. struct gpio_desc *cs_gpiod;
  143. struct gpio_desc *int_gpiod;
  144. u32 touch_x_max;
  145. u32 touch_y_max;
  146. bool x_flip;
  147. bool y_flip;
  148. bool touch_stopped;
  149. };
  150. static int bu21013_read_block_data(struct bu21013_ts *ts, u8 *buf)
  151. {
  152. int ret, i;
  153. for (i = 0; i < I2C_RETRY_COUNT; i++) {
  154. ret = i2c_smbus_read_i2c_block_data(ts->client,
  155. BU21013_SENSORS_BTN_0_7_REG,
  156. LENGTH_OF_BUFFER, buf);
  157. if (ret == LENGTH_OF_BUFFER)
  158. return 0;
  159. }
  160. return -EINVAL;
  161. }
  162. static int bu21013_do_touch_report(struct bu21013_ts *ts)
  163. {
  164. struct input_dev *input = ts->in_dev;
  165. struct input_mt_pos pos[MAX_FINGERS];
  166. int slots[MAX_FINGERS];
  167. u8 buf[LENGTH_OF_BUFFER];
  168. bool has_x_sensors, has_y_sensors;
  169. int finger_down_count = 0;
  170. int i;
  171. if (bu21013_read_block_data(ts, buf) < 0)
  172. return -EINVAL;
  173. has_x_sensors = hweight32(buf[0] & BU21013_SENSORS_EN_0_7);
  174. has_y_sensors = hweight32(((buf[1] & BU21013_SENSORS_EN_8_15) |
  175. ((buf[2] & BU21013_SENSORS_EN_16_23) << SHIFT_8)) >> SHIFT_2);
  176. if (!has_x_sensors || !has_y_sensors)
  177. return 0;
  178. for (i = 0; i < MAX_FINGERS; i++) {
  179. const u8 *data = &buf[4 * i + 3];
  180. unsigned int x, y;
  181. x = data[0] << SHIFT_2 | (data[1] & MASK_BITS);
  182. y = data[2] << SHIFT_2 | (data[3] & MASK_BITS);
  183. if (x != 0 && y != 0)
  184. touchscreen_set_mt_pos(&pos[finger_down_count++],
  185. &ts->props, x, y);
  186. }
  187. if (finger_down_count == 2 &&
  188. (abs(pos[0].x - pos[1].x) < DELTA_MIN ||
  189. abs(pos[0].y - pos[1].y) < DELTA_MIN)) {
  190. return 0;
  191. }
  192. input_mt_assign_slots(input, slots, pos, finger_down_count, DELTA_MIN);
  193. for (i = 0; i < finger_down_count; i++) {
  194. input_mt_slot(input, slots[i]);
  195. input_mt_report_slot_state(input, MT_TOOL_FINGER, true);
  196. input_report_abs(input, ABS_MT_POSITION_X, pos[i].x);
  197. input_report_abs(input, ABS_MT_POSITION_Y, pos[i].y);
  198. }
  199. input_mt_sync_frame(input);
  200. input_sync(input);
  201. return 0;
  202. }
  203. static irqreturn_t bu21013_gpio_irq(int irq, void *device_data)
  204. {
  205. struct bu21013_ts *ts = device_data;
  206. int keep_polling;
  207. int error;
  208. do {
  209. error = bu21013_do_touch_report(ts);
  210. if (error) {
  211. dev_err(&ts->client->dev, "%s failed\n", __func__);
  212. break;
  213. }
  214. if (unlikely(ts->touch_stopped))
  215. break;
  216. keep_polling = ts->int_gpiod ?
  217. gpiod_get_value(ts->int_gpiod) : false;
  218. if (keep_polling)
  219. usleep_range(2000, 2500);
  220. } while (keep_polling);
  221. return IRQ_HANDLED;
  222. }
  223. static int bu21013_init_chip(struct bu21013_ts *ts)
  224. {
  225. struct i2c_client *client = ts->client;
  226. int error;
  227. error = i2c_smbus_write_byte_data(client, BU21013_RESET_REG,
  228. BU21013_RESET_ENABLE);
  229. if (error) {
  230. dev_err(&client->dev, "BU21013_RESET reg write failed\n");
  231. return error;
  232. }
  233. msleep(RESET_DELAY);
  234. error = i2c_smbus_write_byte_data(client, BU21013_SENSOR_0_7_REG,
  235. BU21013_SENSORS_EN_0_7);
  236. if (error) {
  237. dev_err(&client->dev, "BU21013_SENSOR_0_7 reg write failed\n");
  238. return error;
  239. }
  240. error = i2c_smbus_write_byte_data(client, BU21013_SENSOR_8_15_REG,
  241. BU21013_SENSORS_EN_8_15);
  242. if (error) {
  243. dev_err(&client->dev, "BU21013_SENSOR_8_15 reg write failed\n");
  244. return error;
  245. }
  246. error = i2c_smbus_write_byte_data(client, BU21013_SENSOR_16_23_REG,
  247. BU21013_SENSORS_EN_16_23);
  248. if (error) {
  249. dev_err(&client->dev, "BU21013_SENSOR_16_23 reg write failed\n");
  250. return error;
  251. }
  252. error = i2c_smbus_write_byte_data(client, BU21013_POS_MODE1_REG,
  253. BU21013_POS_MODE1_0 |
  254. BU21013_POS_MODE1_1);
  255. if (error) {
  256. dev_err(&client->dev, "BU21013_POS_MODE1 reg write failed\n");
  257. return error;
  258. }
  259. error = i2c_smbus_write_byte_data(client, BU21013_POS_MODE2_REG,
  260. BU21013_POS_MODE2_ZERO |
  261. BU21013_POS_MODE2_AVG1 |
  262. BU21013_POS_MODE2_AVG2 |
  263. BU21013_POS_MODE2_EN_RAW |
  264. BU21013_POS_MODE2_MULTI);
  265. if (error) {
  266. dev_err(&client->dev, "BU21013_POS_MODE2 reg write failed\n");
  267. return error;
  268. }
  269. error = i2c_smbus_write_byte_data(client, BU21013_CLK_MODE_REG,
  270. BU21013_CLK_MODE_DIV |
  271. BU21013_CLK_MODE_CALIB);
  272. if (error) {
  273. dev_err(&client->dev, "BU21013_CLK_MODE reg write failed\n");
  274. return error;
  275. }
  276. error = i2c_smbus_write_byte_data(client, BU21013_IDLE_REG,
  277. BU21013_IDLET_0 |
  278. BU21013_IDLE_INTERMIT_EN);
  279. if (error) {
  280. dev_err(&client->dev, "BU21013_IDLE reg write failed\n");
  281. return error;
  282. }
  283. error = i2c_smbus_write_byte_data(client, BU21013_INT_MODE_REG,
  284. BU21013_INT_MODE_LEVEL);
  285. if (error) {
  286. dev_err(&client->dev, "BU21013_INT_MODE reg write failed\n");
  287. return error;
  288. }
  289. error = i2c_smbus_write_byte_data(client, BU21013_FILTER_REG,
  290. BU21013_DELTA_0_6 |
  291. BU21013_FILTER_EN);
  292. if (error) {
  293. dev_err(&client->dev, "BU21013_FILTER reg write failed\n");
  294. return error;
  295. }
  296. error = i2c_smbus_write_byte_data(client, BU21013_TH_ON_REG,
  297. BU21013_TH_ON_5);
  298. if (error) {
  299. dev_err(&client->dev, "BU21013_TH_ON reg write failed\n");
  300. return error;
  301. }
  302. error = i2c_smbus_write_byte_data(client, BU21013_TH_OFF_REG,
  303. BU21013_TH_OFF_4 | BU21013_TH_OFF_3);
  304. if (error) {
  305. dev_err(&client->dev, "BU21013_TH_OFF reg write failed\n");
  306. return error;
  307. }
  308. error = i2c_smbus_write_byte_data(client, BU21013_GAIN_REG,
  309. BU21013_GAIN_0 | BU21013_GAIN_1);
  310. if (error) {
  311. dev_err(&client->dev, "BU21013_GAIN reg write failed\n");
  312. return error;
  313. }
  314. error = i2c_smbus_write_byte_data(client, BU21013_OFFSET_MODE_REG,
  315. BU21013_OFFSET_MODE_DEFAULT);
  316. if (error) {
  317. dev_err(&client->dev, "BU21013_OFFSET_MODE reg write failed\n");
  318. return error;
  319. }
  320. error = i2c_smbus_write_byte_data(client, BU21013_XY_EDGE_REG,
  321. BU21013_X_EDGE_0 |
  322. BU21013_X_EDGE_2 |
  323. BU21013_Y_EDGE_1 |
  324. BU21013_Y_EDGE_3);
  325. if (error) {
  326. dev_err(&client->dev, "BU21013_XY_EDGE reg write failed\n");
  327. return error;
  328. }
  329. error = i2c_smbus_write_byte_data(client, BU21013_DONE_REG,
  330. BU21013_DONE);
  331. if (error) {
  332. dev_err(&client->dev, "BU21013_REG_DONE reg write failed\n");
  333. return error;
  334. }
  335. return 0;
  336. }
  337. static void bu21013_power_off(void *_ts)
  338. {
  339. struct bu21013_ts *ts = _ts;
  340. regulator_disable(ts->regulator);
  341. }
  342. static void bu21013_disable_chip(void *_ts)
  343. {
  344. struct bu21013_ts *ts = _ts;
  345. gpiod_set_value(ts->cs_gpiod, 0);
  346. }
  347. static int bu21013_probe(struct i2c_client *client,
  348. const struct i2c_device_id *id)
  349. {
  350. struct bu21013_ts *ts;
  351. struct input_dev *in_dev;
  352. struct input_absinfo *info;
  353. u32 max_x = 0, max_y = 0;
  354. int error;
  355. if (!i2c_check_functionality(client->adapter,
  356. I2C_FUNC_SMBUS_BYTE_DATA)) {
  357. dev_err(&client->dev, "i2c smbus byte data not supported\n");
  358. return -EIO;
  359. }
  360. if (!client->irq) {
  361. dev_err(&client->dev, "No IRQ set up\n");
  362. return -EINVAL;
  363. }
  364. ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL);
  365. if (!ts)
  366. return -ENOMEM;
  367. ts->client = client;
  368. ts->x_flip = device_property_read_bool(&client->dev, "rohm,flip-x");
  369. ts->y_flip = device_property_read_bool(&client->dev, "rohm,flip-y");
  370. in_dev = devm_input_allocate_device(&client->dev);
  371. if (!in_dev) {
  372. dev_err(&client->dev, "device memory alloc failed\n");
  373. return -ENOMEM;
  374. }
  375. ts->in_dev = in_dev;
  376. input_set_drvdata(in_dev, ts);
  377. /* register the device to input subsystem */
  378. in_dev->name = DRIVER_TP;
  379. in_dev->id.bustype = BUS_I2C;
  380. device_property_read_u32(&client->dev, "rohm,touch-max-x", &max_x);
  381. device_property_read_u32(&client->dev, "rohm,touch-max-y", &max_y);
  382. input_set_abs_params(in_dev, ABS_MT_POSITION_X, 0, max_x, 0, 0);
  383. input_set_abs_params(in_dev, ABS_MT_POSITION_Y, 0, max_y, 0, 0);
  384. touchscreen_parse_properties(in_dev, true, &ts->props);
  385. /* Adjust for the legacy "flip" properties, if present */
  386. if (!ts->props.invert_x &&
  387. device_property_read_bool(&client->dev, "rohm,flip-x")) {
  388. info = &in_dev->absinfo[ABS_MT_POSITION_X];
  389. info->maximum -= info->minimum;
  390. info->minimum = 0;
  391. }
  392. if (!ts->props.invert_y &&
  393. device_property_read_bool(&client->dev, "rohm,flip-y")) {
  394. info = &in_dev->absinfo[ABS_MT_POSITION_Y];
  395. info->maximum -= info->minimum;
  396. info->minimum = 0;
  397. }
  398. error = input_mt_init_slots(in_dev, MAX_FINGERS,
  399. INPUT_MT_DIRECT | INPUT_MT_TRACK |
  400. INPUT_MT_DROP_UNUSED);
  401. if (error) {
  402. dev_err(&client->dev, "failed to initialize MT slots");
  403. return error;
  404. }
  405. ts->regulator = devm_regulator_get(&client->dev, "avdd");
  406. if (IS_ERR(ts->regulator)) {
  407. dev_err(&client->dev, "regulator_get failed\n");
  408. return PTR_ERR(ts->regulator);
  409. }
  410. error = regulator_enable(ts->regulator);
  411. if (error) {
  412. dev_err(&client->dev, "regulator enable failed\n");
  413. return error;
  414. }
  415. error = devm_add_action_or_reset(&client->dev, bu21013_power_off, ts);
  416. if (error) {
  417. dev_err(&client->dev, "failed to install power off handler\n");
  418. return error;
  419. }
  420. /* Named "CS" on the chip, DT binding is "reset" */
  421. ts->cs_gpiod = devm_gpiod_get(&client->dev, "reset", GPIOD_OUT_HIGH);
  422. error = PTR_ERR_OR_ZERO(ts->cs_gpiod);
  423. if (error) {
  424. if (error != -EPROBE_DEFER)
  425. dev_err(&client->dev, "failed to get CS GPIO\n");
  426. return error;
  427. }
  428. gpiod_set_consumer_name(ts->cs_gpiod, "BU21013 CS");
  429. error = devm_add_action_or_reset(&client->dev,
  430. bu21013_disable_chip, ts);
  431. if (error) {
  432. dev_err(&client->dev,
  433. "failed to install chip disable handler\n");
  434. return error;
  435. }
  436. /* Named "INT" on the chip, DT binding is "touch" */
  437. ts->int_gpiod = devm_gpiod_get_optional(&client->dev,
  438. "touch", GPIOD_IN);
  439. error = PTR_ERR_OR_ZERO(ts->int_gpiod);
  440. if (error) {
  441. if (error != -EPROBE_DEFER)
  442. dev_err(&client->dev, "failed to get INT GPIO\n");
  443. return error;
  444. }
  445. if (ts->int_gpiod)
  446. gpiod_set_consumer_name(ts->int_gpiod, "BU21013 INT");
  447. /* configure the touch panel controller */
  448. error = bu21013_init_chip(ts);
  449. if (error) {
  450. dev_err(&client->dev, "error in bu21013 config\n");
  451. return error;
  452. }
  453. error = devm_request_threaded_irq(&client->dev, client->irq,
  454. NULL, bu21013_gpio_irq,
  455. IRQF_ONESHOT, DRIVER_TP, ts);
  456. if (error) {
  457. dev_err(&client->dev, "request irq %d failed\n",
  458. client->irq);
  459. return error;
  460. }
  461. error = input_register_device(in_dev);
  462. if (error) {
  463. dev_err(&client->dev, "failed to register input device\n");
  464. return error;
  465. }
  466. i2c_set_clientdata(client, ts);
  467. return 0;
  468. }
  469. static void bu21013_remove(struct i2c_client *client)
  470. {
  471. struct bu21013_ts *ts = i2c_get_clientdata(client);
  472. /* Make sure IRQ will exit quickly even if there is contact */
  473. ts->touch_stopped = true;
  474. /* The resources will be freed by devm */
  475. }
  476. static int __maybe_unused bu21013_suspend(struct device *dev)
  477. {
  478. struct i2c_client *client = to_i2c_client(dev);
  479. struct bu21013_ts *ts = i2c_get_clientdata(client);
  480. ts->touch_stopped = true;
  481. mb();
  482. disable_irq(client->irq);
  483. if (!device_may_wakeup(&client->dev))
  484. regulator_disable(ts->regulator);
  485. return 0;
  486. }
  487. static int __maybe_unused bu21013_resume(struct device *dev)
  488. {
  489. struct i2c_client *client = to_i2c_client(dev);
  490. struct bu21013_ts *ts = i2c_get_clientdata(client);
  491. int error;
  492. if (!device_may_wakeup(&client->dev)) {
  493. error = regulator_enable(ts->regulator);
  494. if (error) {
  495. dev_err(&client->dev,
  496. "failed to re-enable regulator when resuming\n");
  497. return error;
  498. }
  499. error = bu21013_init_chip(ts);
  500. if (error) {
  501. dev_err(&client->dev,
  502. "failed to reinitialize chip when resuming\n");
  503. return error;
  504. }
  505. }
  506. ts->touch_stopped = false;
  507. mb();
  508. enable_irq(client->irq);
  509. return 0;
  510. }
  511. static SIMPLE_DEV_PM_OPS(bu21013_dev_pm_ops, bu21013_suspend, bu21013_resume);
  512. static const struct i2c_device_id bu21013_id[] = {
  513. { DRIVER_TP, 0 },
  514. { }
  515. };
  516. MODULE_DEVICE_TABLE(i2c, bu21013_id);
  517. static struct i2c_driver bu21013_driver = {
  518. .driver = {
  519. .name = DRIVER_TP,
  520. .pm = &bu21013_dev_pm_ops,
  521. },
  522. .probe = bu21013_probe,
  523. .remove = bu21013_remove,
  524. .id_table = bu21013_id,
  525. };
  526. module_i2c_driver(bu21013_driver);
  527. MODULE_LICENSE("GPL v2");
  528. MODULE_AUTHOR("Naveen Kumar G <[email protected]>");
  529. MODULE_DESCRIPTION("bu21013 touch screen controller driver");