adp5588-keys.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  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. gpiochip_remove(&kpad->gc);
  200. }
  201. #else
  202. static inline int adp5588_gpio_add(struct adp5588_kpad *kpad)
  203. {
  204. return 0;
  205. }
  206. static inline void adp5588_gpio_remove(struct adp5588_kpad *kpad)
  207. {
  208. }
  209. #endif
  210. static void adp5588_report_events(struct adp5588_kpad *kpad, int ev_cnt)
  211. {
  212. int i, j;
  213. for (i = 0; i < ev_cnt; i++) {
  214. int key = adp5588_read(kpad->client, Key_EVENTA + i);
  215. int key_val = key & KEY_EV_MASK;
  216. if (key_val >= GPI_PIN_BASE && key_val <= GPI_PIN_END) {
  217. for (j = 0; j < kpad->gpimapsize; j++) {
  218. if (key_val == kpad->gpimap[j].pin) {
  219. input_report_switch(kpad->input,
  220. kpad->gpimap[j].sw_evt,
  221. key & KEY_EV_PRESSED);
  222. break;
  223. }
  224. }
  225. } else {
  226. input_report_key(kpad->input,
  227. kpad->keycode[key_val - 1],
  228. key & KEY_EV_PRESSED);
  229. }
  230. }
  231. }
  232. static void adp5588_work(struct work_struct *work)
  233. {
  234. struct adp5588_kpad *kpad = container_of(work,
  235. struct adp5588_kpad, work.work);
  236. struct i2c_client *client = kpad->client;
  237. int status, ev_cnt;
  238. status = adp5588_read(client, INT_STAT);
  239. if (status & ADP5588_OVR_FLOW_INT) /* Unlikely and should never happen */
  240. dev_err(&client->dev, "Event Overflow Error\n");
  241. if (status & ADP5588_KE_INT) {
  242. ev_cnt = adp5588_read(client, KEY_LCK_EC_STAT) & ADP5588_KEC;
  243. if (ev_cnt) {
  244. adp5588_report_events(kpad, ev_cnt);
  245. input_sync(kpad->input);
  246. }
  247. }
  248. adp5588_write(client, INT_STAT, status); /* Status is W1C */
  249. }
  250. static irqreturn_t adp5588_irq(int irq, void *handle)
  251. {
  252. struct adp5588_kpad *kpad = handle;
  253. /*
  254. * use keventd context to read the event fifo registers
  255. * Schedule readout at least 25ms after notification for
  256. * REVID < 4
  257. */
  258. schedule_delayed_work(&kpad->work, kpad->delay);
  259. return IRQ_HANDLED;
  260. }
  261. static int adp5588_setup(struct i2c_client *client)
  262. {
  263. const struct adp5588_kpad_platform_data *pdata =
  264. dev_get_platdata(&client->dev);
  265. const struct adp5588_gpio_platform_data *gpio_data = pdata->gpio_data;
  266. int i, ret;
  267. unsigned char evt_mode1 = 0, evt_mode2 = 0, evt_mode3 = 0;
  268. ret = adp5588_write(client, KP_GPIO1, KP_SEL(pdata->rows));
  269. ret |= adp5588_write(client, KP_GPIO2, KP_SEL(pdata->cols) & 0xFF);
  270. ret |= adp5588_write(client, KP_GPIO3, KP_SEL(pdata->cols) >> 8);
  271. if (pdata->en_keylock) {
  272. ret |= adp5588_write(client, UNLOCK1, pdata->unlock_key1);
  273. ret |= adp5588_write(client, UNLOCK2, pdata->unlock_key2);
  274. ret |= adp5588_write(client, KEY_LCK_EC_STAT, ADP5588_K_LCK_EN);
  275. }
  276. for (i = 0; i < KEYP_MAX_EVENT; i++)
  277. ret |= adp5588_read(client, Key_EVENTA);
  278. for (i = 0; i < pdata->gpimapsize; i++) {
  279. unsigned short pin = pdata->gpimap[i].pin;
  280. if (pin <= GPI_PIN_ROW_END) {
  281. evt_mode1 |= (1 << (pin - GPI_PIN_ROW_BASE));
  282. } else {
  283. evt_mode2 |= ((1 << (pin - GPI_PIN_COL_BASE)) & 0xFF);
  284. evt_mode3 |= ((1 << (pin - GPI_PIN_COL_BASE)) >> 8);
  285. }
  286. }
  287. if (pdata->gpimapsize) {
  288. ret |= adp5588_write(client, GPI_EM1, evt_mode1);
  289. ret |= adp5588_write(client, GPI_EM2, evt_mode2);
  290. ret |= adp5588_write(client, GPI_EM3, evt_mode3);
  291. }
  292. if (gpio_data) {
  293. for (i = 0; i <= ADP5588_BANK(ADP5588_MAXGPIO); i++) {
  294. int pull_mask = gpio_data->pullup_dis_mask;
  295. ret |= adp5588_write(client, GPIO_PULL1 + i,
  296. (pull_mask >> (8 * i)) & 0xFF);
  297. }
  298. }
  299. ret |= adp5588_write(client, INT_STAT,
  300. ADP5588_CMP2_INT | ADP5588_CMP1_INT |
  301. ADP5588_OVR_FLOW_INT | ADP5588_K_LCK_INT |
  302. ADP5588_GPI_INT | ADP5588_KE_INT); /* Status is W1C */
  303. ret |= adp5588_write(client, CFG, ADP5588_INT_CFG |
  304. ADP5588_OVR_FLOW_IEN |
  305. ADP5588_KE_IEN);
  306. if (ret < 0) {
  307. dev_err(&client->dev, "Write Error\n");
  308. return ret;
  309. }
  310. return 0;
  311. }
  312. static void adp5588_report_switch_state(struct adp5588_kpad *kpad)
  313. {
  314. int gpi_stat1 = adp5588_read(kpad->client, GPIO_DAT_STAT1);
  315. int gpi_stat2 = adp5588_read(kpad->client, GPIO_DAT_STAT2);
  316. int gpi_stat3 = adp5588_read(kpad->client, GPIO_DAT_STAT3);
  317. int gpi_stat_tmp, pin_loc;
  318. int i;
  319. for (i = 0; i < kpad->gpimapsize; i++) {
  320. unsigned short pin = kpad->gpimap[i].pin;
  321. if (pin <= GPI_PIN_ROW_END) {
  322. gpi_stat_tmp = gpi_stat1;
  323. pin_loc = pin - GPI_PIN_ROW_BASE;
  324. } else if ((pin - GPI_PIN_COL_BASE) < 8) {
  325. gpi_stat_tmp = gpi_stat2;
  326. pin_loc = pin - GPI_PIN_COL_BASE;
  327. } else {
  328. gpi_stat_tmp = gpi_stat3;
  329. pin_loc = pin - GPI_PIN_COL_BASE - 8;
  330. }
  331. if (gpi_stat_tmp < 0) {
  332. dev_err(&kpad->client->dev,
  333. "Can't read GPIO_DAT_STAT switch %d default to OFF\n",
  334. pin);
  335. gpi_stat_tmp = 0;
  336. }
  337. input_report_switch(kpad->input,
  338. kpad->gpimap[i].sw_evt,
  339. !(gpi_stat_tmp & (1 << pin_loc)));
  340. }
  341. input_sync(kpad->input);
  342. }
  343. static int adp5588_probe(struct i2c_client *client,
  344. const struct i2c_device_id *id)
  345. {
  346. struct adp5588_kpad *kpad;
  347. const struct adp5588_kpad_platform_data *pdata =
  348. dev_get_platdata(&client->dev);
  349. struct input_dev *input;
  350. unsigned int revid;
  351. int ret, i;
  352. int error;
  353. if (!i2c_check_functionality(client->adapter,
  354. I2C_FUNC_SMBUS_BYTE_DATA)) {
  355. dev_err(&client->dev, "SMBUS Byte Data not Supported\n");
  356. return -EIO;
  357. }
  358. if (!pdata) {
  359. dev_err(&client->dev, "no platform data?\n");
  360. return -EINVAL;
  361. }
  362. if (!pdata->rows || !pdata->cols || !pdata->keymap) {
  363. dev_err(&client->dev, "no rows, cols or keymap from pdata\n");
  364. return -EINVAL;
  365. }
  366. if (pdata->keymapsize != ADP5588_KEYMAPSIZE) {
  367. dev_err(&client->dev, "invalid keymapsize\n");
  368. return -EINVAL;
  369. }
  370. if (!pdata->gpimap && pdata->gpimapsize) {
  371. dev_err(&client->dev, "invalid gpimap from pdata\n");
  372. return -EINVAL;
  373. }
  374. if (pdata->gpimapsize > ADP5588_GPIMAPSIZE_MAX) {
  375. dev_err(&client->dev, "invalid gpimapsize\n");
  376. return -EINVAL;
  377. }
  378. for (i = 0; i < pdata->gpimapsize; i++) {
  379. unsigned short pin = pdata->gpimap[i].pin;
  380. if (pin < GPI_PIN_BASE || pin > GPI_PIN_END) {
  381. dev_err(&client->dev, "invalid gpi pin data\n");
  382. return -EINVAL;
  383. }
  384. if (pin <= GPI_PIN_ROW_END) {
  385. if (pin - GPI_PIN_ROW_BASE + 1 <= pdata->rows) {
  386. dev_err(&client->dev, "invalid gpi row data\n");
  387. return -EINVAL;
  388. }
  389. } else {
  390. if (pin - GPI_PIN_COL_BASE + 1 <= pdata->cols) {
  391. dev_err(&client->dev, "invalid gpi col data\n");
  392. return -EINVAL;
  393. }
  394. }
  395. }
  396. if (!client->irq) {
  397. dev_err(&client->dev, "no IRQ?\n");
  398. return -EINVAL;
  399. }
  400. kpad = kzalloc(sizeof(*kpad), GFP_KERNEL);
  401. input = input_allocate_device();
  402. if (!kpad || !input) {
  403. error = -ENOMEM;
  404. goto err_free_mem;
  405. }
  406. kpad->client = client;
  407. kpad->input = input;
  408. INIT_DELAYED_WORK(&kpad->work, adp5588_work);
  409. ret = adp5588_read(client, DEV_ID);
  410. if (ret < 0) {
  411. error = ret;
  412. goto err_free_mem;
  413. }
  414. revid = (u8) ret & ADP5588_DEVICE_ID_MASK;
  415. if (WA_DELAYED_READOUT_REVID(revid))
  416. kpad->delay = msecs_to_jiffies(30);
  417. input->name = client->name;
  418. input->phys = "adp5588-keys/input0";
  419. input->dev.parent = &client->dev;
  420. input_set_drvdata(input, kpad);
  421. input->id.bustype = BUS_I2C;
  422. input->id.vendor = 0x0001;
  423. input->id.product = 0x0001;
  424. input->id.version = revid;
  425. input->keycodesize = sizeof(kpad->keycode[0]);
  426. input->keycodemax = pdata->keymapsize;
  427. input->keycode = kpad->keycode;
  428. memcpy(kpad->keycode, pdata->keymap,
  429. pdata->keymapsize * input->keycodesize);
  430. kpad->gpimap = pdata->gpimap;
  431. kpad->gpimapsize = pdata->gpimapsize;
  432. /* setup input device */
  433. __set_bit(EV_KEY, input->evbit);
  434. if (pdata->repeat)
  435. __set_bit(EV_REP, input->evbit);
  436. for (i = 0; i < input->keycodemax; i++)
  437. if (kpad->keycode[i] <= KEY_MAX)
  438. __set_bit(kpad->keycode[i], input->keybit);
  439. __clear_bit(KEY_RESERVED, input->keybit);
  440. if (kpad->gpimapsize)
  441. __set_bit(EV_SW, input->evbit);
  442. for (i = 0; i < kpad->gpimapsize; i++)
  443. __set_bit(kpad->gpimap[i].sw_evt, input->swbit);
  444. error = input_register_device(input);
  445. if (error) {
  446. dev_err(&client->dev, "unable to register input device\n");
  447. goto err_free_mem;
  448. }
  449. error = request_irq(client->irq, adp5588_irq,
  450. IRQF_TRIGGER_FALLING,
  451. client->dev.driver->name, kpad);
  452. if (error) {
  453. dev_err(&client->dev, "irq %d busy?\n", client->irq);
  454. goto err_unreg_dev;
  455. }
  456. error = adp5588_setup(client);
  457. if (error)
  458. goto err_free_irq;
  459. if (kpad->gpimapsize)
  460. adp5588_report_switch_state(kpad);
  461. error = adp5588_gpio_add(kpad);
  462. if (error)
  463. goto err_free_irq;
  464. device_init_wakeup(&client->dev, 1);
  465. i2c_set_clientdata(client, kpad);
  466. dev_info(&client->dev, "Rev.%d keypad, irq %d\n", revid, client->irq);
  467. return 0;
  468. err_free_irq:
  469. free_irq(client->irq, kpad);
  470. cancel_delayed_work_sync(&kpad->work);
  471. err_unreg_dev:
  472. input_unregister_device(input);
  473. input = NULL;
  474. err_free_mem:
  475. input_free_device(input);
  476. kfree(kpad);
  477. return error;
  478. }
  479. static int adp5588_remove(struct i2c_client *client)
  480. {
  481. struct adp5588_kpad *kpad = i2c_get_clientdata(client);
  482. adp5588_write(client, CFG, 0);
  483. free_irq(client->irq, kpad);
  484. cancel_delayed_work_sync(&kpad->work);
  485. input_unregister_device(kpad->input);
  486. adp5588_gpio_remove(kpad);
  487. kfree(kpad);
  488. return 0;
  489. }
  490. #ifdef CONFIG_PM
  491. static int adp5588_suspend(struct device *dev)
  492. {
  493. struct adp5588_kpad *kpad = dev_get_drvdata(dev);
  494. struct i2c_client *client = kpad->client;
  495. disable_irq(client->irq);
  496. cancel_delayed_work_sync(&kpad->work);
  497. if (device_may_wakeup(&client->dev))
  498. enable_irq_wake(client->irq);
  499. return 0;
  500. }
  501. static int adp5588_resume(struct device *dev)
  502. {
  503. struct adp5588_kpad *kpad = dev_get_drvdata(dev);
  504. struct i2c_client *client = kpad->client;
  505. if (device_may_wakeup(&client->dev))
  506. disable_irq_wake(client->irq);
  507. enable_irq(client->irq);
  508. return 0;
  509. }
  510. static const struct dev_pm_ops adp5588_dev_pm_ops = {
  511. .suspend = adp5588_suspend,
  512. .resume = adp5588_resume,
  513. };
  514. #endif
  515. static const struct i2c_device_id adp5588_id[] = {
  516. { "adp5588-keys", 0 },
  517. { "adp5587-keys", 0 },
  518. { }
  519. };
  520. MODULE_DEVICE_TABLE(i2c, adp5588_id);
  521. static struct i2c_driver adp5588_driver = {
  522. .driver = {
  523. .name = KBUILD_MODNAME,
  524. #ifdef CONFIG_PM
  525. .pm = &adp5588_dev_pm_ops,
  526. #endif
  527. },
  528. .probe = adp5588_probe,
  529. .remove = adp5588_remove,
  530. .id_table = adp5588_id,
  531. };
  532. module_i2c_driver(adp5588_driver);
  533. MODULE_LICENSE("GPL");
  534. MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
  535. MODULE_DESCRIPTION("ADP5588/87 Keypad driver");