adp5588-keys.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. /*
  2. * File: drivers/input/keyboard/adp5588_keys.c
  3. * Description: keypad driver for ADP5588 and ADP5587
  4. * I2C QWERTY Keypad and IO Expander
  5. * Bugs: Enter bugs at http://blackfin.uclinux.org/
  6. *
  7. * Copyright (C) 2008-2009 Analog Devices Inc.
  8. * Licensed under the GPL-2 or later.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/version.h>
  12. #include <linux/init.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/irq.h>
  15. #include <linux/workqueue.h>
  16. #include <linux/errno.h>
  17. #include <linux/pm.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/input.h>
  20. #include <linux/i2c.h>
  21. #include <linux/gpio.h>
  22. #include <linux/slab.h>
  23. #include <linux/i2c/adp5588.h>
  24. /* Configuration Register1 */
  25. #define AUTO_INC (1 << 7)
  26. #define GPIEM_CFG (1 << 6)
  27. #define OVR_FLOW_M (1 << 5)
  28. #define INT_CFG (1 << 4)
  29. #define OVR_FLOW_IEN (1 << 3)
  30. #define K_LCK_IM (1 << 2)
  31. #define GPI_IEN (1 << 1)
  32. #define KE_IEN (1 << 0)
  33. /* Interrupt Status Register */
  34. #define CMP2_INT (1 << 5)
  35. #define CMP1_INT (1 << 4)
  36. #define OVR_FLOW_INT (1 << 3)
  37. #define K_LCK_INT (1 << 2)
  38. #define GPI_INT (1 << 1)
  39. #define KE_INT (1 << 0)
  40. /* Key Lock and Event Counter Register */
  41. #define K_LCK_EN (1 << 6)
  42. #define LCK21 0x30
  43. #define KEC 0xF
  44. /* Key Event Register xy */
  45. #define KEY_EV_PRESSED (1 << 7)
  46. #define KEY_EV_MASK (0x7F)
  47. #define KP_SEL(x) (0xFFFF >> (16 - x)) /* 2^x-1 */
  48. #define KEYP_MAX_EVENT 10
  49. #define MAXGPIO 18
  50. #define ADP_BANK(offs) ((offs) >> 3)
  51. #define ADP_BIT(offs) (1u << ((offs) & 0x7))
  52. /*
  53. * Early pre 4.0 Silicon required to delay readout by at least 25ms,
  54. * since the Event Counter Register updated 25ms after the interrupt
  55. * asserted.
  56. */
  57. #define WA_DELAYED_READOUT_REVID(rev) ((rev) < 4)
  58. struct adp5588_kpad {
  59. struct i2c_client *client;
  60. struct input_dev *input;
  61. struct delayed_work work;
  62. unsigned long delay;
  63. unsigned short keycode[ADP5588_KEYMAPSIZE];
  64. const struct adp5588_gpi_map *gpimap;
  65. unsigned short gpimapsize;
  66. #ifdef CONFIG_GPIOLIB
  67. unsigned char gpiomap[MAXGPIO];
  68. bool export_gpio;
  69. struct gpio_chip gc;
  70. struct mutex gpio_lock; /* Protect cached dir, dat_out */
  71. u8 dat_out[3];
  72. u8 dir[3];
  73. #endif
  74. };
  75. static int adp5588_read(struct i2c_client *client, u8 reg)
  76. {
  77. int ret = i2c_smbus_read_byte_data(client, reg);
  78. if (ret < 0)
  79. dev_err(&client->dev, "Read Error\n");
  80. return ret;
  81. }
  82. static int adp5588_write(struct i2c_client *client, u8 reg, u8 val)
  83. {
  84. return i2c_smbus_write_byte_data(client, reg, val);
  85. }
  86. #ifdef CONFIG_GPIOLIB
  87. static int adp5588_gpio_get_value(struct gpio_chip *chip, unsigned off)
  88. {
  89. struct adp5588_kpad *kpad = container_of(chip, struct adp5588_kpad, gc);
  90. unsigned int bank = ADP_BANK(kpad->gpiomap[off]);
  91. unsigned int bit = ADP_BIT(kpad->gpiomap[off]);
  92. return !!(adp5588_read(kpad->client, GPIO_DAT_STAT1 + bank) & bit);
  93. }
  94. static void adp5588_gpio_set_value(struct gpio_chip *chip,
  95. unsigned off, int val)
  96. {
  97. struct adp5588_kpad *kpad = container_of(chip, struct adp5588_kpad, gc);
  98. unsigned int bank = ADP_BANK(kpad->gpiomap[off]);
  99. unsigned int bit = ADP_BIT(kpad->gpiomap[off]);
  100. mutex_lock(&kpad->gpio_lock);
  101. if (val)
  102. kpad->dat_out[bank] |= bit;
  103. else
  104. kpad->dat_out[bank] &= ~bit;
  105. adp5588_write(kpad->client, GPIO_DAT_OUT1 + bank,
  106. kpad->dat_out[bank]);
  107. mutex_unlock(&kpad->gpio_lock);
  108. }
  109. static int adp5588_gpio_direction_input(struct gpio_chip *chip, unsigned off)
  110. {
  111. struct adp5588_kpad *kpad = container_of(chip, struct adp5588_kpad, gc);
  112. unsigned int bank = ADP_BANK(kpad->gpiomap[off]);
  113. unsigned int bit = ADP_BIT(kpad->gpiomap[off]);
  114. int ret;
  115. mutex_lock(&kpad->gpio_lock);
  116. kpad->dir[bank] &= ~bit;
  117. ret = adp5588_write(kpad->client, GPIO_DIR1 + bank, kpad->dir[bank]);
  118. mutex_unlock(&kpad->gpio_lock);
  119. return ret;
  120. }
  121. static int adp5588_gpio_direction_output(struct gpio_chip *chip,
  122. unsigned off, int val)
  123. {
  124. struct adp5588_kpad *kpad = container_of(chip, struct adp5588_kpad, gc);
  125. unsigned int bank = ADP_BANK(kpad->gpiomap[off]);
  126. unsigned int bit = ADP_BIT(kpad->gpiomap[off]);
  127. int ret;
  128. mutex_lock(&kpad->gpio_lock);
  129. kpad->dir[bank] |= bit;
  130. if (val)
  131. kpad->dat_out[bank] |= bit;
  132. else
  133. kpad->dat_out[bank] &= ~bit;
  134. ret = adp5588_write(kpad->client, GPIO_DAT_OUT1 + bank,
  135. kpad->dat_out[bank]);
  136. ret |= adp5588_write(kpad->client, GPIO_DIR1 + bank,
  137. kpad->dir[bank]);
  138. mutex_unlock(&kpad->gpio_lock);
  139. return ret;
  140. }
  141. static int __devinit adp5588_build_gpiomap(struct adp5588_kpad *kpad,
  142. const struct adp5588_kpad_platform_data *pdata)
  143. {
  144. bool pin_used[MAXGPIO];
  145. int n_unused = 0;
  146. int i;
  147. memset(pin_used, 0, sizeof(pin_used));
  148. for (i = 0; i < pdata->rows; i++)
  149. pin_used[i] = true;
  150. for (i = 0; i < pdata->cols; i++)
  151. pin_used[i + GPI_PIN_COL_BASE - GPI_PIN_BASE] = true;
  152. for (i = 0; i < kpad->gpimapsize; i++)
  153. pin_used[kpad->gpimap[i].pin - GPI_PIN_BASE] = true;
  154. for (i = 0; i < MAXGPIO; i++)
  155. if (!pin_used[i])
  156. kpad->gpiomap[n_unused++] = i;
  157. return n_unused;
  158. }
  159. static int __devinit adp5588_gpio_add(struct adp5588_kpad *kpad)
  160. {
  161. struct device *dev = &kpad->client->dev;
  162. const struct adp5588_kpad_platform_data *pdata = dev->platform_data;
  163. const struct adp5588_gpio_platform_data *gpio_data = pdata->gpio_data;
  164. int i, error;
  165. if (!gpio_data)
  166. return 0;
  167. kpad->gc.ngpio = adp5588_build_gpiomap(kpad, pdata);
  168. if (kpad->gc.ngpio == 0) {
  169. dev_info(dev, "No unused gpios left to export\n");
  170. return 0;
  171. }
  172. kpad->export_gpio = true;
  173. kpad->gc.direction_input = adp5588_gpio_direction_input;
  174. kpad->gc.direction_output = adp5588_gpio_direction_output;
  175. kpad->gc.get = adp5588_gpio_get_value;
  176. kpad->gc.set = adp5588_gpio_set_value;
  177. kpad->gc.can_sleep = 1;
  178. kpad->gc.base = gpio_data->gpio_start;
  179. kpad->gc.label = kpad->client->name;
  180. kpad->gc.owner = THIS_MODULE;
  181. mutex_init(&kpad->gpio_lock);
  182. error = gpiochip_add(&kpad->gc);
  183. if (error) {
  184. dev_err(dev, "gpiochip_add failed, err: %d\n", error);
  185. return error;
  186. }
  187. for (i = 0; i <= ADP_BANK(MAXGPIO); i++) {
  188. kpad->dat_out[i] = adp5588_read(kpad->client,
  189. GPIO_DAT_OUT1 + i);
  190. kpad->dir[i] = adp5588_read(kpad->client, GPIO_DIR1 + i);
  191. }
  192. if (gpio_data->setup) {
  193. error = gpio_data->setup(kpad->client,
  194. kpad->gc.base, kpad->gc.ngpio,
  195. gpio_data->context);
  196. if (error)
  197. dev_warn(dev, "setup failed, %d\n", error);
  198. }
  199. return 0;
  200. }
  201. static void __devexit adp5588_gpio_remove(struct adp5588_kpad *kpad)
  202. {
  203. struct device *dev = &kpad->client->dev;
  204. const struct adp5588_kpad_platform_data *pdata = dev->platform_data;
  205. const struct adp5588_gpio_platform_data *gpio_data = pdata->gpio_data;
  206. int error;
  207. if (!kpad->export_gpio)
  208. return;
  209. if (gpio_data->teardown) {
  210. error = gpio_data->teardown(kpad->client,
  211. kpad->gc.base, kpad->gc.ngpio,
  212. gpio_data->context);
  213. if (error)
  214. dev_warn(dev, "teardown failed %d\n", error);
  215. }
  216. error = gpiochip_remove(&kpad->gc);
  217. if (error)
  218. dev_warn(dev, "gpiochip_remove failed %d\n", error);
  219. }
  220. #else
  221. static inline int adp5588_gpio_add(struct adp5588_kpad *kpad)
  222. {
  223. return 0;
  224. }
  225. static inline void adp5588_gpio_remove(struct adp5588_kpad *kpad)
  226. {
  227. }
  228. #endif
  229. static void adp5588_report_events(struct adp5588_kpad *kpad, int ev_cnt)
  230. {
  231. int i, j;
  232. for (i = 0; i < ev_cnt; i++) {
  233. int key = adp5588_read(kpad->client, Key_EVENTA + i);
  234. int key_val = key & KEY_EV_MASK;
  235. if (key_val >= GPI_PIN_BASE && key_val <= GPI_PIN_END) {
  236. for (j = 0; j < kpad->gpimapsize; j++) {
  237. if (key_val == kpad->gpimap[j].pin) {
  238. input_report_switch(kpad->input,
  239. kpad->gpimap[j].sw_evt,
  240. key & KEY_EV_PRESSED);
  241. break;
  242. }
  243. }
  244. } else {
  245. input_report_key(kpad->input,
  246. kpad->keycode[key_val - 1],
  247. key & KEY_EV_PRESSED);
  248. }
  249. }
  250. }
  251. static void adp5588_work(struct work_struct *work)
  252. {
  253. struct adp5588_kpad *kpad = container_of(work,
  254. struct adp5588_kpad, work.work);
  255. struct i2c_client *client = kpad->client;
  256. int status, ev_cnt;
  257. status = adp5588_read(client, INT_STAT);
  258. if (status & OVR_FLOW_INT) /* Unlikely and should never happen */
  259. dev_err(&client->dev, "Event Overflow Error\n");
  260. if (status & KE_INT) {
  261. ev_cnt = adp5588_read(client, KEY_LCK_EC_STAT) & KEC;
  262. if (ev_cnt) {
  263. adp5588_report_events(kpad, ev_cnt);
  264. input_sync(kpad->input);
  265. }
  266. }
  267. adp5588_write(client, INT_STAT, status); /* Status is W1C */
  268. }
  269. static irqreturn_t adp5588_irq(int irq, void *handle)
  270. {
  271. struct adp5588_kpad *kpad = handle;
  272. /*
  273. * use keventd context to read the event fifo registers
  274. * Schedule readout at least 25ms after notification for
  275. * REVID < 4
  276. */
  277. schedule_delayed_work(&kpad->work, kpad->delay);
  278. return IRQ_HANDLED;
  279. }
  280. static int __devinit adp5588_setup(struct i2c_client *client)
  281. {
  282. const struct adp5588_kpad_platform_data *pdata = client->dev.platform_data;
  283. const struct adp5588_gpio_platform_data *gpio_data = pdata->gpio_data;
  284. int i, ret;
  285. unsigned char evt_mode1 = 0, evt_mode2 = 0, evt_mode3 = 0;
  286. ret = adp5588_write(client, KP_GPIO1, KP_SEL(pdata->rows));
  287. ret |= adp5588_write(client, KP_GPIO2, KP_SEL(pdata->cols) & 0xFF);
  288. ret |= adp5588_write(client, KP_GPIO3, KP_SEL(pdata->cols) >> 8);
  289. if (pdata->en_keylock) {
  290. ret |= adp5588_write(client, UNLOCK1, pdata->unlock_key1);
  291. ret |= adp5588_write(client, UNLOCK2, pdata->unlock_key2);
  292. ret |= adp5588_write(client, KEY_LCK_EC_STAT, K_LCK_EN);
  293. }
  294. for (i = 0; i < KEYP_MAX_EVENT; i++)
  295. ret |= adp5588_read(client, Key_EVENTA);
  296. for (i = 0; i < pdata->gpimapsize; i++) {
  297. unsigned short pin = pdata->gpimap[i].pin;
  298. if (pin <= GPI_PIN_ROW_END) {
  299. evt_mode1 |= (1 << (pin - GPI_PIN_ROW_BASE));
  300. } else {
  301. evt_mode2 |= ((1 << (pin - GPI_PIN_COL_BASE)) & 0xFF);
  302. evt_mode3 |= ((1 << (pin - GPI_PIN_COL_BASE)) >> 8);
  303. }
  304. }
  305. if (pdata->gpimapsize) {
  306. ret |= adp5588_write(client, GPI_EM1, evt_mode1);
  307. ret |= adp5588_write(client, GPI_EM2, evt_mode2);
  308. ret |= adp5588_write(client, GPI_EM3, evt_mode3);
  309. }
  310. if (gpio_data) {
  311. for (i = 0; i <= ADP_BANK(MAXGPIO); i++) {
  312. int pull_mask = gpio_data->pullup_dis_mask;
  313. ret |= adp5588_write(client, GPIO_PULL1 + i,
  314. (pull_mask >> (8 * i)) & 0xFF);
  315. }
  316. }
  317. ret |= adp5588_write(client, INT_STAT, CMP2_INT | CMP1_INT |
  318. OVR_FLOW_INT | K_LCK_INT |
  319. GPI_INT | KE_INT); /* Status is W1C */
  320. ret |= adp5588_write(client, CFG, INT_CFG | OVR_FLOW_IEN | KE_IEN);
  321. if (ret < 0) {
  322. dev_err(&client->dev, "Write Error\n");
  323. return ret;
  324. }
  325. return 0;
  326. }
  327. static void __devinit adp5588_report_switch_state(struct adp5588_kpad *kpad)
  328. {
  329. int gpi_stat1 = adp5588_read(kpad->client, GPIO_DAT_STAT1);
  330. int gpi_stat2 = adp5588_read(kpad->client, GPIO_DAT_STAT2);
  331. int gpi_stat3 = adp5588_read(kpad->client, GPIO_DAT_STAT3);
  332. int gpi_stat_tmp, pin_loc;
  333. int i;
  334. for (i = 0; i < kpad->gpimapsize; i++) {
  335. unsigned short pin = kpad->gpimap[i].pin;
  336. if (pin <= GPI_PIN_ROW_END) {
  337. gpi_stat_tmp = gpi_stat1;
  338. pin_loc = pin - GPI_PIN_ROW_BASE;
  339. } else if ((pin - GPI_PIN_COL_BASE) < 8) {
  340. gpi_stat_tmp = gpi_stat2;
  341. pin_loc = pin - GPI_PIN_COL_BASE;
  342. } else {
  343. gpi_stat_tmp = gpi_stat3;
  344. pin_loc = pin - GPI_PIN_COL_BASE - 8;
  345. }
  346. if (gpi_stat_tmp < 0) {
  347. dev_err(&kpad->client->dev,
  348. "Can't read GPIO_DAT_STAT switch %d default to OFF\n",
  349. pin);
  350. gpi_stat_tmp = 0;
  351. }
  352. input_report_switch(kpad->input,
  353. kpad->gpimap[i].sw_evt,
  354. !(gpi_stat_tmp & (1 << pin_loc)));
  355. }
  356. input_sync(kpad->input);
  357. }
  358. static int __devinit adp5588_probe(struct i2c_client *client,
  359. const struct i2c_device_id *id)
  360. {
  361. struct adp5588_kpad *kpad;
  362. const struct adp5588_kpad_platform_data *pdata = client->dev.platform_data;
  363. struct input_dev *input;
  364. unsigned int revid;
  365. int ret, i;
  366. int error;
  367. if (!i2c_check_functionality(client->adapter,
  368. I2C_FUNC_SMBUS_BYTE_DATA)) {
  369. dev_err(&client->dev, "SMBUS Byte Data not Supported\n");
  370. return -EIO;
  371. }
  372. if (!pdata) {
  373. dev_err(&client->dev, "no platform data?\n");
  374. return -EINVAL;
  375. }
  376. if (!pdata->rows || !pdata->cols || !pdata->keymap) {
  377. dev_err(&client->dev, "no rows, cols or keymap from pdata\n");
  378. return -EINVAL;
  379. }
  380. if (pdata->keymapsize != ADP5588_KEYMAPSIZE) {
  381. dev_err(&client->dev, "invalid keymapsize\n");
  382. return -EINVAL;
  383. }
  384. if (!pdata->gpimap && pdata->gpimapsize) {
  385. dev_err(&client->dev, "invalid gpimap from pdata\n");
  386. return -EINVAL;
  387. }
  388. if (pdata->gpimapsize > ADP5588_GPIMAPSIZE_MAX) {
  389. dev_err(&client->dev, "invalid gpimapsize\n");
  390. return -EINVAL;
  391. }
  392. for (i = 0; i < pdata->gpimapsize; i++) {
  393. unsigned short pin = pdata->gpimap[i].pin;
  394. if (pin < GPI_PIN_BASE || pin > GPI_PIN_END) {
  395. dev_err(&client->dev, "invalid gpi pin data\n");
  396. return -EINVAL;
  397. }
  398. if (pin <= GPI_PIN_ROW_END) {
  399. if (pin - GPI_PIN_ROW_BASE + 1 <= pdata->rows) {
  400. dev_err(&client->dev, "invalid gpi row data\n");
  401. return -EINVAL;
  402. }
  403. } else {
  404. if (pin - GPI_PIN_COL_BASE + 1 <= pdata->cols) {
  405. dev_err(&client->dev, "invalid gpi col data\n");
  406. return -EINVAL;
  407. }
  408. }
  409. }
  410. if (!client->irq) {
  411. dev_err(&client->dev, "no IRQ?\n");
  412. return -EINVAL;
  413. }
  414. kpad = kzalloc(sizeof(*kpad), GFP_KERNEL);
  415. input = input_allocate_device();
  416. if (!kpad || !input) {
  417. error = -ENOMEM;
  418. goto err_free_mem;
  419. }
  420. kpad->client = client;
  421. kpad->input = input;
  422. INIT_DELAYED_WORK(&kpad->work, adp5588_work);
  423. ret = adp5588_read(client, DEV_ID);
  424. if (ret < 0) {
  425. error = ret;
  426. goto err_free_mem;
  427. }
  428. revid = (u8) ret & ADP5588_DEVICE_ID_MASK;
  429. if (WA_DELAYED_READOUT_REVID(revid))
  430. kpad->delay = msecs_to_jiffies(30);
  431. input->name = client->name;
  432. input->phys = "adp5588-keys/input0";
  433. input->dev.parent = &client->dev;
  434. input_set_drvdata(input, kpad);
  435. input->id.bustype = BUS_I2C;
  436. input->id.vendor = 0x0001;
  437. input->id.product = 0x0001;
  438. input->id.version = revid;
  439. input->keycodesize = sizeof(kpad->keycode[0]);
  440. input->keycodemax = pdata->keymapsize;
  441. input->keycode = kpad->keycode;
  442. memcpy(kpad->keycode, pdata->keymap,
  443. pdata->keymapsize * input->keycodesize);
  444. kpad->gpimap = pdata->gpimap;
  445. kpad->gpimapsize = pdata->gpimapsize;
  446. /* setup input device */
  447. __set_bit(EV_KEY, input->evbit);
  448. if (pdata->repeat)
  449. __set_bit(EV_REP, input->evbit);
  450. for (i = 0; i < input->keycodemax; i++)
  451. __set_bit(kpad->keycode[i] & KEY_MAX, input->keybit);
  452. __clear_bit(KEY_RESERVED, input->keybit);
  453. if (kpad->gpimapsize)
  454. __set_bit(EV_SW, input->evbit);
  455. for (i = 0; i < kpad->gpimapsize; i++)
  456. __set_bit(kpad->gpimap[i].sw_evt, input->swbit);
  457. error = input_register_device(input);
  458. if (error) {
  459. dev_err(&client->dev, "unable to register input device\n");
  460. goto err_free_mem;
  461. }
  462. error = request_irq(client->irq, adp5588_irq,
  463. IRQF_TRIGGER_FALLING | IRQF_DISABLED,
  464. client->dev.driver->name, kpad);
  465. if (error) {
  466. dev_err(&client->dev, "irq %d busy?\n", client->irq);
  467. goto err_unreg_dev;
  468. }
  469. error = adp5588_setup(client);
  470. if (error)
  471. goto err_free_irq;
  472. if (kpad->gpimapsize)
  473. adp5588_report_switch_state(kpad);
  474. error = adp5588_gpio_add(kpad);
  475. if (error)
  476. goto err_free_irq;
  477. device_init_wakeup(&client->dev, 1);
  478. i2c_set_clientdata(client, kpad);
  479. dev_info(&client->dev, "Rev.%d keypad, irq %d\n", revid, client->irq);
  480. return 0;
  481. err_free_irq:
  482. free_irq(client->irq, kpad);
  483. err_unreg_dev:
  484. input_unregister_device(input);
  485. input = NULL;
  486. err_free_mem:
  487. input_free_device(input);
  488. kfree(kpad);
  489. return error;
  490. }
  491. static int __devexit adp5588_remove(struct i2c_client *client)
  492. {
  493. struct adp5588_kpad *kpad = i2c_get_clientdata(client);
  494. adp5588_write(client, CFG, 0);
  495. free_irq(client->irq, kpad);
  496. cancel_delayed_work_sync(&kpad->work);
  497. input_unregister_device(kpad->input);
  498. adp5588_gpio_remove(kpad);
  499. kfree(kpad);
  500. return 0;
  501. }
  502. #ifdef CONFIG_PM
  503. static int adp5588_suspend(struct device *dev)
  504. {
  505. struct adp5588_kpad *kpad = dev_get_drvdata(dev);
  506. struct i2c_client *client = kpad->client;
  507. disable_irq(client->irq);
  508. cancel_delayed_work_sync(&kpad->work);
  509. if (device_may_wakeup(&client->dev))
  510. enable_irq_wake(client->irq);
  511. return 0;
  512. }
  513. static int adp5588_resume(struct device *dev)
  514. {
  515. struct adp5588_kpad *kpad = dev_get_drvdata(dev);
  516. struct i2c_client *client = kpad->client;
  517. if (device_may_wakeup(&client->dev))
  518. disable_irq_wake(client->irq);
  519. enable_irq(client->irq);
  520. return 0;
  521. }
  522. static const struct dev_pm_ops adp5588_dev_pm_ops = {
  523. .suspend = adp5588_suspend,
  524. .resume = adp5588_resume,
  525. };
  526. #endif
  527. static const struct i2c_device_id adp5588_id[] = {
  528. { KBUILD_MODNAME, 0 },
  529. { "adp5587-keys", 0 },
  530. { }
  531. };
  532. MODULE_DEVICE_TABLE(i2c, adp5588_id);
  533. static struct i2c_driver adp5588_driver = {
  534. .driver = {
  535. .name = KBUILD_MODNAME,
  536. #ifdef CONFIG_PM
  537. .pm = &adp5588_dev_pm_ops,
  538. #endif
  539. },
  540. .probe = adp5588_probe,
  541. .remove = __devexit_p(adp5588_remove),
  542. .id_table = adp5588_id,
  543. };
  544. static int __init adp5588_init(void)
  545. {
  546. return i2c_add_driver(&adp5588_driver);
  547. }
  548. module_init(adp5588_init);
  549. static void __exit adp5588_exit(void)
  550. {
  551. i2c_del_driver(&adp5588_driver);
  552. }
  553. module_exit(adp5588_exit);
  554. MODULE_LICENSE("GPL");
  555. MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
  556. MODULE_DESCRIPTION("ADP5588/87 Keypad driver");
  557. MODULE_ALIAS("platform:adp5588-keys");