bu21013_ts.c 17 KB

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