bu21013_ts.c 18 KB

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