adp5588-keys.c 16 KB

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