bu21013_ts.c 17 KB

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