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