bu21013_ts.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. /*
  2. * Copyright (C) ST-Ericsson SA 2010
  3. * Author: Naveen Kumar G <naveen.gaddipati@stericsson.com> for ST-Ericsson
  4. * License terms:GNU General Public License (GPL) version 2
  5. */
  6. #include <linux/kernel.h>
  7. #include <linux/delay.h>
  8. #include <linux/interrupt.h>
  9. #include <linux/i2c.h>
  10. #include <linux/workqueue.h>
  11. #include <linux/input.h>
  12. #include <linux/input/bu21013.h>
  13. #include <linux/slab.h>
  14. #include <linux/regulator/consumer.h>
  15. #include <linux/module.h>
  16. #include <linux/gpio.h>
  17. #define PEN_DOWN_INTR 0
  18. #define MAX_FINGERS 2
  19. #define RESET_DELAY 30
  20. #define PENUP_TIMEOUT (10)
  21. #define DELTA_MIN 16
  22. #define MASK_BITS 0x03
  23. #define SHIFT_8 8
  24. #define SHIFT_2 2
  25. #define LENGTH_OF_BUFFER 11
  26. #define I2C_RETRY_COUNT 5
  27. #define BU21013_SENSORS_BTN_0_7_REG 0x70
  28. #define BU21013_SENSORS_BTN_8_15_REG 0x71
  29. #define BU21013_SENSORS_BTN_16_23_REG 0x72
  30. #define BU21013_X1_POS_MSB_REG 0x73
  31. #define BU21013_X1_POS_LSB_REG 0x74
  32. #define BU21013_Y1_POS_MSB_REG 0x75
  33. #define BU21013_Y1_POS_LSB_REG 0x76
  34. #define BU21013_X2_POS_MSB_REG 0x77
  35. #define BU21013_X2_POS_LSB_REG 0x78
  36. #define BU21013_Y2_POS_MSB_REG 0x79
  37. #define BU21013_Y2_POS_LSB_REG 0x7A
  38. #define BU21013_INT_CLR_REG 0xE8
  39. #define BU21013_INT_MODE_REG 0xE9
  40. #define BU21013_GAIN_REG 0xEA
  41. #define BU21013_OFFSET_MODE_REG 0xEB
  42. #define BU21013_XY_EDGE_REG 0xEC
  43. #define BU21013_RESET_REG 0xED
  44. #define BU21013_CALIB_REG 0xEE
  45. #define BU21013_DONE_REG 0xEF
  46. #define BU21013_SENSOR_0_7_REG 0xF0
  47. #define BU21013_SENSOR_8_15_REG 0xF1
  48. #define BU21013_SENSOR_16_23_REG 0xF2
  49. #define BU21013_POS_MODE1_REG 0xF3
  50. #define BU21013_POS_MODE2_REG 0xF4
  51. #define BU21013_CLK_MODE_REG 0xF5
  52. #define BU21013_IDLE_REG 0xFA
  53. #define BU21013_FILTER_REG 0xFB
  54. #define BU21013_TH_ON_REG 0xFC
  55. #define BU21013_TH_OFF_REG 0xFD
  56. #define BU21013_RESET_ENABLE 0x01
  57. #define BU21013_SENSORS_EN_0_7 0x3F
  58. #define BU21013_SENSORS_EN_8_15 0xFC
  59. #define BU21013_SENSORS_EN_16_23 0x1F
  60. #define BU21013_POS_MODE1_0 0x02
  61. #define BU21013_POS_MODE1_1 0x04
  62. #define BU21013_POS_MODE1_2 0x08
  63. #define BU21013_POS_MODE2_ZERO 0x01
  64. #define BU21013_POS_MODE2_AVG1 0x02
  65. #define BU21013_POS_MODE2_AVG2 0x04
  66. #define BU21013_POS_MODE2_EN_XY 0x08
  67. #define BU21013_POS_MODE2_EN_RAW 0x10
  68. #define BU21013_POS_MODE2_MULTI 0x80
  69. #define BU21013_CLK_MODE_DIV 0x01
  70. #define BU21013_CLK_MODE_EXT 0x02
  71. #define BU21013_CLK_MODE_CALIB 0x80
  72. #define BU21013_IDLET_0 0x01
  73. #define BU21013_IDLET_1 0x02
  74. #define BU21013_IDLET_2 0x04
  75. #define BU21013_IDLET_3 0x08
  76. #define BU21013_IDLE_INTERMIT_EN 0x10
  77. #define BU21013_DELTA_0_6 0x7F
  78. #define BU21013_FILTER_EN 0x80
  79. #define BU21013_INT_MODE_LEVEL 0x00
  80. #define BU21013_INT_MODE_EDGE 0x01
  81. #define BU21013_GAIN_0 0x01
  82. #define BU21013_GAIN_1 0x02
  83. #define BU21013_GAIN_2 0x04
  84. #define BU21013_OFFSET_MODE_DEFAULT 0x00
  85. #define BU21013_OFFSET_MODE_MOVE 0x01
  86. #define BU21013_OFFSET_MODE_DISABLE 0x02
  87. #define BU21013_TH_ON_0 0x01
  88. #define BU21013_TH_ON_1 0x02
  89. #define BU21013_TH_ON_2 0x04
  90. #define BU21013_TH_ON_3 0x08
  91. #define BU21013_TH_ON_4 0x10
  92. #define BU21013_TH_ON_5 0x20
  93. #define BU21013_TH_ON_6 0x40
  94. #define BU21013_TH_ON_7 0x80
  95. #define BU21013_TH_ON_MAX 0xFF
  96. #define BU21013_TH_OFF_0 0x01
  97. #define BU21013_TH_OFF_1 0x02
  98. #define BU21013_TH_OFF_2 0x04
  99. #define BU21013_TH_OFF_3 0x08
  100. #define BU21013_TH_OFF_4 0x10
  101. #define BU21013_TH_OFF_5 0x20
  102. #define BU21013_TH_OFF_6 0x40
  103. #define BU21013_TH_OFF_7 0x80
  104. #define BU21013_TH_OFF_MAX 0xFF
  105. #define BU21013_X_EDGE_0 0x01
  106. #define BU21013_X_EDGE_1 0x02
  107. #define BU21013_X_EDGE_2 0x04
  108. #define BU21013_X_EDGE_3 0x08
  109. #define BU21013_Y_EDGE_0 0x10
  110. #define BU21013_Y_EDGE_1 0x20
  111. #define BU21013_Y_EDGE_2 0x40
  112. #define BU21013_Y_EDGE_3 0x80
  113. #define BU21013_DONE 0x01
  114. #define BU21013_NUMBER_OF_X_SENSORS (6)
  115. #define BU21013_NUMBER_OF_Y_SENSORS (11)
  116. #define DRIVER_TP "bu21013_tp"
  117. /**
  118. * struct bu21013_ts_data - touch panel data structure
  119. * @client: pointer to the i2c client
  120. * @wait: variable to wait_queue_head_t structure
  121. * @touch_stopped: touch stop flag
  122. * @chip: pointer to the touch panel controller
  123. * @in_dev: pointer to the input device structure
  124. * @intr_pin: interrupt pin value
  125. * @regulator: pointer to the Regulator used for touch screen
  126. *
  127. * Touch panel device data structure
  128. */
  129. struct bu21013_ts_data {
  130. struct i2c_client *client;
  131. wait_queue_head_t wait;
  132. const struct bu21013_platform_device *chip;
  133. struct input_dev *in_dev;
  134. struct regulator *regulator;
  135. unsigned int irq;
  136. unsigned int intr_pin;
  137. bool touch_stopped;
  138. };
  139. /**
  140. * bu21013_read_block_data(): read the touch co-ordinates
  141. * @data: bu21013_ts_data structure pointer
  142. * @buf: byte pointer
  143. *
  144. * Read the touch co-ordinates using i2c read block into buffer
  145. * and returns integer.
  146. */
  147. static int bu21013_read_block_data(struct bu21013_ts_data *data, u8 *buf)
  148. {
  149. int ret, i;
  150. for (i = 0; i < I2C_RETRY_COUNT; i++) {
  151. ret = i2c_smbus_read_i2c_block_data
  152. (data->client, BU21013_SENSORS_BTN_0_7_REG,
  153. LENGTH_OF_BUFFER, buf);
  154. if (ret == LENGTH_OF_BUFFER)
  155. return 0;
  156. }
  157. return -EINVAL;
  158. }
  159. /**
  160. * bu21013_do_touch_report(): Get the touch co-ordinates
  161. * @data: bu21013_ts_data structure pointer
  162. *
  163. * Get the touch co-ordinates from touch sensor registers and writes
  164. * into device structure and returns integer.
  165. */
  166. static int bu21013_do_touch_report(struct bu21013_ts_data *data)
  167. {
  168. u8 buf[LENGTH_OF_BUFFER];
  169. unsigned int pos_x[2], pos_y[2];
  170. bool has_x_sensors, has_y_sensors;
  171. int finger_down_count = 0;
  172. int i;
  173. if (data == NULL)
  174. return -EINVAL;
  175. if (bu21013_read_block_data(data, buf) < 0)
  176. return -EINVAL;
  177. has_x_sensors = hweight32(buf[0] & BU21013_SENSORS_EN_0_7);
  178. has_y_sensors = hweight32(((buf[1] & BU21013_SENSORS_EN_8_15) |
  179. ((buf[2] & BU21013_SENSORS_EN_16_23) << SHIFT_8)) >> SHIFT_2);
  180. if (!has_x_sensors || !has_y_sensors)
  181. return 0;
  182. for (i = 0; i < MAX_FINGERS; i++) {
  183. const u8 *p = &buf[4 * i + 3];
  184. unsigned int x = p[0] << SHIFT_2 | (p[1] & MASK_BITS);
  185. unsigned int y = p[2] << SHIFT_2 | (p[3] & MASK_BITS);
  186. if (x == 0 || y == 0)
  187. continue;
  188. pos_x[finger_down_count] = x;
  189. pos_y[finger_down_count] = y;
  190. finger_down_count++;
  191. }
  192. if (finger_down_count) {
  193. if (finger_down_count == 2 &&
  194. (abs(pos_x[0] - pos_x[1]) < DELTA_MIN ||
  195. abs(pos_y[0] - pos_y[1]) < DELTA_MIN)) {
  196. return 0;
  197. }
  198. for (i = 0; i < finger_down_count; i++) {
  199. if (data->chip->x_flip)
  200. pos_x[i] = data->chip->touch_x_max - pos_x[i];
  201. if (data->chip->y_flip)
  202. pos_y[i] = data->chip->touch_y_max - pos_y[i];
  203. input_report_abs(data->in_dev,
  204. ABS_MT_POSITION_X, pos_x[i]);
  205. input_report_abs(data->in_dev,
  206. ABS_MT_POSITION_Y, pos_y[i]);
  207. input_mt_sync(data->in_dev);
  208. }
  209. } else
  210. input_mt_sync(data->in_dev);
  211. input_sync(data->in_dev);
  212. return 0;
  213. }
  214. /**
  215. * bu21013_gpio_irq() - gpio thread function for touch interrupt
  216. * @irq: irq value
  217. * @device_data: void pointer
  218. *
  219. * This gpio thread function for touch interrupt
  220. * and returns irqreturn_t.
  221. */
  222. static irqreturn_t bu21013_gpio_irq(int irq, void *device_data)
  223. {
  224. struct bu21013_ts_data *data = device_data;
  225. struct i2c_client *i2c = data->client;
  226. int retval;
  227. do {
  228. retval = bu21013_do_touch_report(data);
  229. if (retval < 0) {
  230. dev_err(&i2c->dev, "bu21013_do_touch_report failed\n");
  231. return IRQ_NONE;
  232. }
  233. data->intr_pin = gpio_get_value(data->chip->touch_pin);
  234. if (data->intr_pin == PEN_DOWN_INTR)
  235. wait_event_timeout(data->wait, data->touch_stopped,
  236. msecs_to_jiffies(2));
  237. } while (!data->intr_pin && !data->touch_stopped);
  238. return IRQ_HANDLED;
  239. }
  240. /**
  241. * bu21013_init_chip() - power on sequence for the bu21013 controller
  242. * @data: device structure pointer
  243. *
  244. * This function is used to power on
  245. * the bu21013 controller and returns integer.
  246. */
  247. static int bu21013_init_chip(struct bu21013_ts_data *data)
  248. {
  249. int retval;
  250. struct i2c_client *i2c = data->client;
  251. retval = i2c_smbus_write_byte_data(i2c, BU21013_RESET_REG,
  252. BU21013_RESET_ENABLE);
  253. if (retval < 0) {
  254. dev_err(&i2c->dev, "BU21013_RESET reg write failed\n");
  255. return retval;
  256. }
  257. msleep(RESET_DELAY);
  258. retval = i2c_smbus_write_byte_data(i2c, BU21013_SENSOR_0_7_REG,
  259. BU21013_SENSORS_EN_0_7);
  260. if (retval < 0) {
  261. dev_err(&i2c->dev, "BU21013_SENSOR_0_7 reg write failed\n");
  262. return retval;
  263. }
  264. retval = i2c_smbus_write_byte_data(i2c, BU21013_SENSOR_8_15_REG,
  265. BU21013_SENSORS_EN_8_15);
  266. if (retval < 0) {
  267. dev_err(&i2c->dev, "BU21013_SENSOR_8_15 reg write failed\n");
  268. return retval;
  269. }
  270. retval = i2c_smbus_write_byte_data(i2c, BU21013_SENSOR_16_23_REG,
  271. BU21013_SENSORS_EN_16_23);
  272. if (retval < 0) {
  273. dev_err(&i2c->dev, "BU21013_SENSOR_16_23 reg write failed\n");
  274. return retval;
  275. }
  276. retval = i2c_smbus_write_byte_data(i2c, BU21013_POS_MODE1_REG,
  277. (BU21013_POS_MODE1_0 | BU21013_POS_MODE1_1));
  278. if (retval < 0) {
  279. dev_err(&i2c->dev, "BU21013_POS_MODE1 reg write failed\n");
  280. return retval;
  281. }
  282. retval = i2c_smbus_write_byte_data(i2c, BU21013_POS_MODE2_REG,
  283. (BU21013_POS_MODE2_ZERO | BU21013_POS_MODE2_AVG1 |
  284. BU21013_POS_MODE2_AVG2 | BU21013_POS_MODE2_EN_RAW |
  285. BU21013_POS_MODE2_MULTI));
  286. if (retval < 0) {
  287. dev_err(&i2c->dev, "BU21013_POS_MODE2 reg write failed\n");
  288. return retval;
  289. }
  290. if (data->chip->ext_clk)
  291. retval = i2c_smbus_write_byte_data(i2c, BU21013_CLK_MODE_REG,
  292. (BU21013_CLK_MODE_EXT | BU21013_CLK_MODE_CALIB));
  293. else
  294. retval = i2c_smbus_write_byte_data(i2c, BU21013_CLK_MODE_REG,
  295. (BU21013_CLK_MODE_DIV | BU21013_CLK_MODE_CALIB));
  296. if (retval < 0) {
  297. dev_err(&i2c->dev, "BU21013_CLK_MODE reg write failed\n");
  298. return retval;
  299. }
  300. retval = i2c_smbus_write_byte_data(i2c, BU21013_IDLE_REG,
  301. (BU21013_IDLET_0 | BU21013_IDLE_INTERMIT_EN));
  302. if (retval < 0) {
  303. dev_err(&i2c->dev, "BU21013_IDLE reg write failed\n");
  304. return retval;
  305. }
  306. retval = i2c_smbus_write_byte_data(i2c, BU21013_INT_MODE_REG,
  307. BU21013_INT_MODE_LEVEL);
  308. if (retval < 0) {
  309. dev_err(&i2c->dev, "BU21013_INT_MODE reg write failed\n");
  310. return retval;
  311. }
  312. retval = i2c_smbus_write_byte_data(i2c, BU21013_FILTER_REG,
  313. (BU21013_DELTA_0_6 |
  314. BU21013_FILTER_EN));
  315. if (retval < 0) {
  316. dev_err(&i2c->dev, "BU21013_FILTER reg write failed\n");
  317. return retval;
  318. }
  319. retval = i2c_smbus_write_byte_data(i2c, BU21013_TH_ON_REG,
  320. BU21013_TH_ON_5);
  321. if (retval < 0) {
  322. dev_err(&i2c->dev, "BU21013_TH_ON reg write failed\n");
  323. return retval;
  324. }
  325. retval = i2c_smbus_write_byte_data(i2c, BU21013_TH_OFF_REG,
  326. BU21013_TH_OFF_4 | BU21013_TH_OFF_3);
  327. if (retval < 0) {
  328. dev_err(&i2c->dev, "BU21013_TH_OFF reg write failed\n");
  329. return retval;
  330. }
  331. retval = i2c_smbus_write_byte_data(i2c, BU21013_GAIN_REG,
  332. (BU21013_GAIN_0 | BU21013_GAIN_1));
  333. if (retval < 0) {
  334. dev_err(&i2c->dev, "BU21013_GAIN reg write failed\n");
  335. return retval;
  336. }
  337. retval = i2c_smbus_write_byte_data(i2c, BU21013_OFFSET_MODE_REG,
  338. BU21013_OFFSET_MODE_DEFAULT);
  339. if (retval < 0) {
  340. dev_err(&i2c->dev, "BU21013_OFFSET_MODE reg write failed\n");
  341. return retval;
  342. }
  343. retval = i2c_smbus_write_byte_data(i2c, BU21013_XY_EDGE_REG,
  344. (BU21013_X_EDGE_0 | BU21013_X_EDGE_2 |
  345. BU21013_Y_EDGE_1 | BU21013_Y_EDGE_3));
  346. if (retval < 0) {
  347. dev_err(&i2c->dev, "BU21013_XY_EDGE reg write failed\n");
  348. return retval;
  349. }
  350. retval = i2c_smbus_write_byte_data(i2c, BU21013_DONE_REG,
  351. BU21013_DONE);
  352. if (retval < 0) {
  353. dev_err(&i2c->dev, "BU21013_REG_DONE reg write failed\n");
  354. return retval;
  355. }
  356. return 0;
  357. }
  358. /**
  359. * bu21013_free_irq() - frees IRQ registered for touchscreen
  360. * @bu21013_data: device structure pointer
  361. *
  362. * This function signals interrupt thread to stop processing and
  363. * frees interrupt.
  364. */
  365. static void bu21013_free_irq(struct bu21013_ts_data *bu21013_data)
  366. {
  367. bu21013_data->touch_stopped = true;
  368. wake_up(&bu21013_data->wait);
  369. free_irq(bu21013_data->irq, bu21013_data);
  370. }
  371. /**
  372. * bu21013_cs_disable() - deconfigures the touch panel controller
  373. * @bu21013_data: device structure pointer
  374. *
  375. * This function is used to deconfigure the chip selection
  376. * for touch panel controller.
  377. */
  378. static void bu21013_cs_disable(struct bu21013_ts_data *bu21013_data)
  379. {
  380. int error;
  381. error = gpio_direction_output(bu21013_data->chip->cs_pin, 0);
  382. if (error < 0)
  383. dev_warn(&bu21013_data->client->dev,
  384. "%s: gpio direction failed, error: %d\n",
  385. __func__, error);
  386. else
  387. gpio_set_value(bu21013_data->chip->cs_pin, 0);
  388. gpio_free(bu21013_data->chip->cs_pin);
  389. }
  390. /**
  391. * bu21013_probe() - initializes the i2c-client touchscreen driver
  392. * @client: i2c client structure pointer
  393. * @id: i2c device id pointer
  394. *
  395. * This function used to initializes the i2c-client touchscreen
  396. * driver and returns integer.
  397. */
  398. static int bu21013_probe(struct i2c_client *client,
  399. const struct i2c_device_id *id)
  400. {
  401. struct bu21013_ts_data *bu21013_data;
  402. struct input_dev *in_dev;
  403. const struct bu21013_platform_device *pdata =
  404. client->dev.platform_data;
  405. int error;
  406. if (!i2c_check_functionality(client->adapter,
  407. I2C_FUNC_SMBUS_BYTE_DATA)) {
  408. dev_err(&client->dev, "i2c smbus byte data not supported\n");
  409. return -EIO;
  410. }
  411. if (!pdata) {
  412. dev_err(&client->dev, "platform data not defined\n");
  413. return -EINVAL;
  414. }
  415. if (!gpio_is_valid(pdata->touch_pin)) {
  416. dev_err(&client->dev, "invalid touch_pin supplied\n");
  417. return -EINVAL;
  418. }
  419. bu21013_data = kzalloc(sizeof(struct bu21013_ts_data), GFP_KERNEL);
  420. in_dev = input_allocate_device();
  421. if (!bu21013_data || !in_dev) {
  422. dev_err(&client->dev, "device memory alloc failed\n");
  423. error = -ENOMEM;
  424. goto err_free_mem;
  425. }
  426. bu21013_data->in_dev = in_dev;
  427. bu21013_data->chip = pdata;
  428. bu21013_data->client = client;
  429. bu21013_data->irq = gpio_to_irq(pdata->touch_pin);
  430. bu21013_data->regulator = regulator_get(&client->dev, "avdd");
  431. if (IS_ERR(bu21013_data->regulator)) {
  432. dev_err(&client->dev, "regulator_get failed\n");
  433. error = PTR_ERR(bu21013_data->regulator);
  434. goto err_free_mem;
  435. }
  436. error = regulator_enable(bu21013_data->regulator);
  437. if (error < 0) {
  438. dev_err(&client->dev, "regulator enable failed\n");
  439. goto err_put_regulator;
  440. }
  441. bu21013_data->touch_stopped = false;
  442. init_waitqueue_head(&bu21013_data->wait);
  443. /* configure the gpio pins */
  444. error = gpio_request_one(pdata->cs_pin, GPIOF_OUT_INIT_HIGH,
  445. "touchp_reset");
  446. if (error < 0) {
  447. dev_err(&client->dev, "Unable to request gpio reset_pin\n");
  448. goto err_disable_regulator;
  449. }
  450. /* configure the touch panel controller */
  451. error = bu21013_init_chip(bu21013_data);
  452. if (error) {
  453. dev_err(&client->dev, "error in bu21013 config\n");
  454. goto err_cs_disable;
  455. }
  456. /* register the device to input subsystem */
  457. in_dev->name = DRIVER_TP;
  458. in_dev->id.bustype = BUS_I2C;
  459. in_dev->dev.parent = &client->dev;
  460. __set_bit(EV_SYN, in_dev->evbit);
  461. __set_bit(EV_KEY, in_dev->evbit);
  462. __set_bit(EV_ABS, in_dev->evbit);
  463. input_set_abs_params(in_dev, ABS_MT_POSITION_X, 0,
  464. pdata->touch_x_max, 0, 0);
  465. input_set_abs_params(in_dev, ABS_MT_POSITION_Y, 0,
  466. pdata->touch_y_max, 0, 0);
  467. input_set_drvdata(in_dev, bu21013_data);
  468. error = request_threaded_irq(bu21013_data->irq, NULL, bu21013_gpio_irq,
  469. IRQF_TRIGGER_FALLING | IRQF_SHARED |
  470. IRQF_ONESHOT,
  471. DRIVER_TP, bu21013_data);
  472. if (error) {
  473. dev_err(&client->dev, "request irq %d failed\n",
  474. bu21013_data->irq);
  475. goto err_cs_disable;
  476. }
  477. error = input_register_device(in_dev);
  478. if (error) {
  479. dev_err(&client->dev, "failed to register input device\n");
  480. goto err_free_irq;
  481. }
  482. device_init_wakeup(&client->dev, pdata->wakeup);
  483. i2c_set_clientdata(client, bu21013_data);
  484. return 0;
  485. err_free_irq:
  486. bu21013_free_irq(bu21013_data);
  487. err_cs_disable:
  488. bu21013_cs_disable(bu21013_data);
  489. err_disable_regulator:
  490. regulator_disable(bu21013_data->regulator);
  491. err_put_regulator:
  492. regulator_put(bu21013_data->regulator);
  493. err_free_mem:
  494. input_free_device(in_dev);
  495. kfree(bu21013_data);
  496. return error;
  497. }
  498. /**
  499. * bu21013_remove() - removes the i2c-client touchscreen driver
  500. * @client: i2c client structure pointer
  501. *
  502. * This function uses to remove the i2c-client
  503. * touchscreen driver and returns integer.
  504. */
  505. static int bu21013_remove(struct i2c_client *client)
  506. {
  507. struct bu21013_ts_data *bu21013_data = i2c_get_clientdata(client);
  508. bu21013_free_irq(bu21013_data);
  509. bu21013_cs_disable(bu21013_data);
  510. input_unregister_device(bu21013_data->in_dev);
  511. regulator_disable(bu21013_data->regulator);
  512. regulator_put(bu21013_data->regulator);
  513. kfree(bu21013_data);
  514. device_init_wakeup(&client->dev, false);
  515. return 0;
  516. }
  517. #ifdef CONFIG_PM
  518. /**
  519. * bu21013_suspend() - suspend the touch screen controller
  520. * @dev: pointer to device structure
  521. *
  522. * This function is used to suspend the
  523. * touch panel controller and returns integer
  524. */
  525. static int bu21013_suspend(struct device *dev)
  526. {
  527. struct bu21013_ts_data *bu21013_data = dev_get_drvdata(dev);
  528. struct i2c_client *client = bu21013_data->client;
  529. bu21013_data->touch_stopped = true;
  530. if (device_may_wakeup(&client->dev))
  531. enable_irq_wake(bu21013_data->irq);
  532. else
  533. disable_irq(bu21013_data->irq);
  534. regulator_disable(bu21013_data->regulator);
  535. return 0;
  536. }
  537. /**
  538. * bu21013_resume() - resume the touch screen controller
  539. * @dev: pointer to device structure
  540. *
  541. * This function is used to resume the touch panel
  542. * controller and returns integer.
  543. */
  544. static int bu21013_resume(struct device *dev)
  545. {
  546. struct bu21013_ts_data *bu21013_data = dev_get_drvdata(dev);
  547. struct i2c_client *client = bu21013_data->client;
  548. int retval;
  549. retval = regulator_enable(bu21013_data->regulator);
  550. if (retval < 0) {
  551. dev_err(&client->dev, "bu21013 regulator enable failed\n");
  552. return retval;
  553. }
  554. retval = bu21013_init_chip(bu21013_data);
  555. if (retval < 0) {
  556. dev_err(&client->dev, "bu21013 controller config failed\n");
  557. return retval;
  558. }
  559. bu21013_data->touch_stopped = false;
  560. if (device_may_wakeup(&client->dev))
  561. disable_irq_wake(bu21013_data->irq);
  562. else
  563. enable_irq(bu21013_data->irq);
  564. return 0;
  565. }
  566. static const struct dev_pm_ops bu21013_dev_pm_ops = {
  567. .suspend = bu21013_suspend,
  568. .resume = bu21013_resume,
  569. };
  570. #endif
  571. static const struct i2c_device_id bu21013_id[] = {
  572. { DRIVER_TP, 0 },
  573. { }
  574. };
  575. MODULE_DEVICE_TABLE(i2c, bu21013_id);
  576. static struct i2c_driver bu21013_driver = {
  577. .driver = {
  578. .name = DRIVER_TP,
  579. .owner = THIS_MODULE,
  580. #ifdef CONFIG_PM
  581. .pm = &bu21013_dev_pm_ops,
  582. #endif
  583. },
  584. .probe = bu21013_probe,
  585. .remove = bu21013_remove,
  586. .id_table = bu21013_id,
  587. };
  588. module_i2c_driver(bu21013_driver);
  589. MODULE_LICENSE("GPL v2");
  590. MODULE_AUTHOR("Naveen Kumar G <naveen.gaddipati@stericsson.com>");
  591. MODULE_DESCRIPTION("bu21013 touch screen controller driver");