adp5588-keys.c 16 KB

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