imx_keypad.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. /*
  2. * Driver for the IMX keypad port.
  3. * Copyright (C) 2009 Alberto Panizzo <maramaopercheseimorto@gmail.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * <<Power management needs to be implemented>>.
  10. */
  11. #include <linux/clk.h>
  12. #include <linux/delay.h>
  13. #include <linux/device.h>
  14. #include <linux/err.h>
  15. #include <linux/init.h>
  16. #include <linux/input/matrix_keypad.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/io.h>
  19. #include <linux/jiffies.h>
  20. #include <linux/kernel.h>
  21. #include <linux/module.h>
  22. #include <linux/of.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/slab.h>
  25. #include <linux/timer.h>
  26. /*
  27. * Keypad Controller registers (halfword)
  28. */
  29. #define KPCR 0x00 /* Keypad Control Register */
  30. #define KPSR 0x02 /* Keypad Status Register */
  31. #define KBD_STAT_KPKD (0x1 << 0) /* Key Press Interrupt Status bit (w1c) */
  32. #define KBD_STAT_KPKR (0x1 << 1) /* Key Release Interrupt Status bit (w1c) */
  33. #define KBD_STAT_KDSC (0x1 << 2) /* Key Depress Synch Chain Status bit (w1c)*/
  34. #define KBD_STAT_KRSS (0x1 << 3) /* Key Release Synch Status bit (w1c)*/
  35. #define KBD_STAT_KDIE (0x1 << 8) /* Key Depress Interrupt Enable Status bit */
  36. #define KBD_STAT_KRIE (0x1 << 9) /* Key Release Interrupt Enable */
  37. #define KBD_STAT_KPPEN (0x1 << 10) /* Keypad Clock Enable */
  38. #define KDDR 0x04 /* Keypad Data Direction Register */
  39. #define KPDR 0x06 /* Keypad Data Register */
  40. #define MAX_MATRIX_KEY_ROWS 8
  41. #define MAX_MATRIX_KEY_COLS 8
  42. #define MATRIX_ROW_SHIFT 3
  43. #define MAX_MATRIX_KEY_NUM (MAX_MATRIX_KEY_ROWS * MAX_MATRIX_KEY_COLS)
  44. struct imx_keypad {
  45. struct clk *clk;
  46. struct input_dev *input_dev;
  47. void __iomem *mmio_base;
  48. int irq;
  49. struct timer_list check_matrix_timer;
  50. /*
  51. * The matrix is stable only if no changes are detected after
  52. * IMX_KEYPAD_SCANS_FOR_STABILITY scans
  53. */
  54. #define IMX_KEYPAD_SCANS_FOR_STABILITY 3
  55. int stable_count;
  56. bool enabled;
  57. /* Masks for enabled rows/cols */
  58. unsigned short rows_en_mask;
  59. unsigned short cols_en_mask;
  60. unsigned short keycodes[MAX_MATRIX_KEY_NUM];
  61. /*
  62. * Matrix states:
  63. * -stable: achieved after a complete debounce process.
  64. * -unstable: used in the debouncing process.
  65. */
  66. unsigned short matrix_stable_state[MAX_MATRIX_KEY_COLS];
  67. unsigned short matrix_unstable_state[MAX_MATRIX_KEY_COLS];
  68. };
  69. /* Scan the matrix and return the new state in *matrix_volatile_state. */
  70. static void imx_keypad_scan_matrix(struct imx_keypad *keypad,
  71. unsigned short *matrix_volatile_state)
  72. {
  73. int col;
  74. unsigned short reg_val;
  75. for (col = 0; col < MAX_MATRIX_KEY_COLS; col++) {
  76. if ((keypad->cols_en_mask & (1 << col)) == 0)
  77. continue;
  78. /*
  79. * Discharge keypad capacitance:
  80. * 2. write 1s on column data.
  81. * 3. configure columns as totem-pole to discharge capacitance.
  82. * 4. configure columns as open-drain.
  83. */
  84. reg_val = readw(keypad->mmio_base + KPDR);
  85. reg_val |= 0xff00;
  86. writew(reg_val, keypad->mmio_base + KPDR);
  87. reg_val = readw(keypad->mmio_base + KPCR);
  88. reg_val &= ~((keypad->cols_en_mask & 0xff) << 8);
  89. writew(reg_val, keypad->mmio_base + KPCR);
  90. udelay(2);
  91. reg_val = readw(keypad->mmio_base + KPCR);
  92. reg_val |= (keypad->cols_en_mask & 0xff) << 8;
  93. writew(reg_val, keypad->mmio_base + KPCR);
  94. /*
  95. * 5. Write a single column to 0, others to 1.
  96. * 6. Sample row inputs and save data.
  97. * 7. Repeat steps 2 - 6 for remaining columns.
  98. */
  99. reg_val = readw(keypad->mmio_base + KPDR);
  100. reg_val &= ~(1 << (8 + col));
  101. writew(reg_val, keypad->mmio_base + KPDR);
  102. /*
  103. * Delay added to avoid propagating the 0 from column to row
  104. * when scanning.
  105. */
  106. udelay(5);
  107. /*
  108. * 1s in matrix_volatile_state[col] means key pressures
  109. * throw data from non enabled rows.
  110. */
  111. reg_val = readw(keypad->mmio_base + KPDR);
  112. matrix_volatile_state[col] = (~reg_val) & keypad->rows_en_mask;
  113. }
  114. /*
  115. * Return in standby mode:
  116. * 9. write 0s to columns
  117. */
  118. reg_val = readw(keypad->mmio_base + KPDR);
  119. reg_val &= 0x00ff;
  120. writew(reg_val, keypad->mmio_base + KPDR);
  121. }
  122. /*
  123. * Compare the new matrix state (volatile) with the stable one stored in
  124. * keypad->matrix_stable_state and fire events if changes are detected.
  125. */
  126. static void imx_keypad_fire_events(struct imx_keypad *keypad,
  127. unsigned short *matrix_volatile_state)
  128. {
  129. struct input_dev *input_dev = keypad->input_dev;
  130. int row, col;
  131. for (col = 0; col < MAX_MATRIX_KEY_COLS; col++) {
  132. unsigned short bits_changed;
  133. int code;
  134. if ((keypad->cols_en_mask & (1 << col)) == 0)
  135. continue; /* Column is not enabled */
  136. bits_changed = keypad->matrix_stable_state[col] ^
  137. matrix_volatile_state[col];
  138. if (bits_changed == 0)
  139. continue; /* Column does not contain changes */
  140. for (row = 0; row < MAX_MATRIX_KEY_ROWS; row++) {
  141. if ((keypad->rows_en_mask & (1 << row)) == 0)
  142. continue; /* Row is not enabled */
  143. if ((bits_changed & (1 << row)) == 0)
  144. continue; /* Row does not contain changes */
  145. code = MATRIX_SCAN_CODE(row, col, MATRIX_ROW_SHIFT);
  146. input_event(input_dev, EV_MSC, MSC_SCAN, code);
  147. input_report_key(input_dev, keypad->keycodes[code],
  148. matrix_volatile_state[col] & (1 << row));
  149. dev_dbg(&input_dev->dev, "Event code: %d, val: %d",
  150. keypad->keycodes[code],
  151. matrix_volatile_state[col] & (1 << row));
  152. }
  153. }
  154. input_sync(input_dev);
  155. }
  156. /*
  157. * imx_keypad_check_for_events is the timer handler.
  158. */
  159. static void imx_keypad_check_for_events(unsigned long data)
  160. {
  161. struct imx_keypad *keypad = (struct imx_keypad *) data;
  162. unsigned short matrix_volatile_state[MAX_MATRIX_KEY_COLS];
  163. unsigned short reg_val;
  164. bool state_changed, is_zero_matrix;
  165. int i;
  166. memset(matrix_volatile_state, 0, sizeof(matrix_volatile_state));
  167. imx_keypad_scan_matrix(keypad, matrix_volatile_state);
  168. state_changed = false;
  169. for (i = 0; i < MAX_MATRIX_KEY_COLS; i++) {
  170. if ((keypad->cols_en_mask & (1 << i)) == 0)
  171. continue;
  172. if (keypad->matrix_unstable_state[i] ^ matrix_volatile_state[i]) {
  173. state_changed = true;
  174. break;
  175. }
  176. }
  177. /*
  178. * If the matrix state is changed from the previous scan
  179. * (Re)Begin the debouncing process, saving the new state in
  180. * keypad->matrix_unstable_state.
  181. * else
  182. * Increase the count of number of scans with a stable state.
  183. */
  184. if (state_changed) {
  185. memcpy(keypad->matrix_unstable_state, matrix_volatile_state,
  186. sizeof(matrix_volatile_state));
  187. keypad->stable_count = 0;
  188. } else
  189. keypad->stable_count++;
  190. /*
  191. * If the matrix is not as stable as we want reschedule scan
  192. * in the near future.
  193. */
  194. if (keypad->stable_count < IMX_KEYPAD_SCANS_FOR_STABILITY) {
  195. mod_timer(&keypad->check_matrix_timer,
  196. jiffies + msecs_to_jiffies(10));
  197. return;
  198. }
  199. /*
  200. * If the matrix state is stable, fire the events and save the new
  201. * stable state. Note, if the matrix is kept stable for longer
  202. * (keypad->stable_count > IMX_KEYPAD_SCANS_FOR_STABILITY) all
  203. * events have already been generated.
  204. */
  205. if (keypad->stable_count == IMX_KEYPAD_SCANS_FOR_STABILITY) {
  206. imx_keypad_fire_events(keypad, matrix_volatile_state);
  207. memcpy(keypad->matrix_stable_state, matrix_volatile_state,
  208. sizeof(matrix_volatile_state));
  209. }
  210. is_zero_matrix = true;
  211. for (i = 0; i < MAX_MATRIX_KEY_COLS; i++) {
  212. if (matrix_volatile_state[i] != 0) {
  213. is_zero_matrix = false;
  214. break;
  215. }
  216. }
  217. if (is_zero_matrix) {
  218. /*
  219. * All keys have been released. Enable only the KDI
  220. * interrupt for future key presses (clear the KDI
  221. * status bit and its sync chain before that).
  222. */
  223. reg_val = readw(keypad->mmio_base + KPSR);
  224. reg_val |= KBD_STAT_KPKD | KBD_STAT_KDSC;
  225. writew(reg_val, keypad->mmio_base + KPSR);
  226. reg_val = readw(keypad->mmio_base + KPSR);
  227. reg_val |= KBD_STAT_KDIE;
  228. reg_val &= ~KBD_STAT_KRIE;
  229. writew(reg_val, keypad->mmio_base + KPSR);
  230. } else {
  231. /*
  232. * Some keys are still pressed. Schedule a rescan in
  233. * attempt to detect multiple key presses and enable
  234. * the KRI interrupt to react quickly to key release
  235. * event.
  236. */
  237. mod_timer(&keypad->check_matrix_timer,
  238. jiffies + msecs_to_jiffies(60));
  239. reg_val = readw(keypad->mmio_base + KPSR);
  240. reg_val |= KBD_STAT_KPKR | KBD_STAT_KRSS;
  241. writew(reg_val, keypad->mmio_base + KPSR);
  242. reg_val = readw(keypad->mmio_base + KPSR);
  243. reg_val |= KBD_STAT_KRIE;
  244. reg_val &= ~KBD_STAT_KDIE;
  245. writew(reg_val, keypad->mmio_base + KPSR);
  246. }
  247. }
  248. static irqreturn_t imx_keypad_irq_handler(int irq, void *dev_id)
  249. {
  250. struct imx_keypad *keypad = dev_id;
  251. unsigned short reg_val;
  252. reg_val = readw(keypad->mmio_base + KPSR);
  253. /* Disable both interrupt types */
  254. reg_val &= ~(KBD_STAT_KRIE | KBD_STAT_KDIE);
  255. /* Clear interrupts status bits */
  256. reg_val |= KBD_STAT_KPKR | KBD_STAT_KPKD;
  257. writew(reg_val, keypad->mmio_base + KPSR);
  258. if (keypad->enabled) {
  259. /* The matrix is supposed to be changed */
  260. keypad->stable_count = 0;
  261. /* Schedule the scanning procedure near in the future */
  262. mod_timer(&keypad->check_matrix_timer,
  263. jiffies + msecs_to_jiffies(2));
  264. }
  265. return IRQ_HANDLED;
  266. }
  267. static void imx_keypad_config(struct imx_keypad *keypad)
  268. {
  269. unsigned short reg_val;
  270. /*
  271. * Include enabled rows in interrupt generation (KPCR[7:0])
  272. * Configure keypad columns as open-drain (KPCR[15:8])
  273. */
  274. reg_val = readw(keypad->mmio_base + KPCR);
  275. reg_val |= keypad->rows_en_mask & 0xff; /* rows */
  276. reg_val |= (keypad->cols_en_mask & 0xff) << 8; /* cols */
  277. writew(reg_val, keypad->mmio_base + KPCR);
  278. /* Write 0's to KPDR[15:8] (Colums) */
  279. reg_val = readw(keypad->mmio_base + KPDR);
  280. reg_val &= 0x00ff;
  281. writew(reg_val, keypad->mmio_base + KPDR);
  282. /* Configure columns as output, rows as input (KDDR[15:0]) */
  283. writew(0xff00, keypad->mmio_base + KDDR);
  284. /*
  285. * Clear Key Depress and Key Release status bit.
  286. * Clear both synchronizer chain.
  287. */
  288. reg_val = readw(keypad->mmio_base + KPSR);
  289. reg_val |= KBD_STAT_KPKR | KBD_STAT_KPKD |
  290. KBD_STAT_KDSC | KBD_STAT_KRSS;
  291. writew(reg_val, keypad->mmio_base + KPSR);
  292. /* Enable KDI and disable KRI (avoid false release events). */
  293. reg_val |= KBD_STAT_KDIE;
  294. reg_val &= ~KBD_STAT_KRIE;
  295. writew(reg_val, keypad->mmio_base + KPSR);
  296. }
  297. static void imx_keypad_inhibit(struct imx_keypad *keypad)
  298. {
  299. unsigned short reg_val;
  300. /* Inhibit KDI and KRI interrupts. */
  301. reg_val = readw(keypad->mmio_base + KPSR);
  302. reg_val &= ~(KBD_STAT_KRIE | KBD_STAT_KDIE);
  303. reg_val |= KBD_STAT_KPKR | KBD_STAT_KPKD;
  304. writew(reg_val, keypad->mmio_base + KPSR);
  305. /* Colums as open drain and disable all rows */
  306. reg_val = (keypad->cols_en_mask & 0xff) << 8;
  307. writew(reg_val, keypad->mmio_base + KPCR);
  308. }
  309. static void imx_keypad_close(struct input_dev *dev)
  310. {
  311. struct imx_keypad *keypad = input_get_drvdata(dev);
  312. dev_dbg(&dev->dev, ">%s\n", __func__);
  313. /* Mark keypad as being inactive */
  314. keypad->enabled = false;
  315. synchronize_irq(keypad->irq);
  316. del_timer_sync(&keypad->check_matrix_timer);
  317. imx_keypad_inhibit(keypad);
  318. /* Disable clock unit */
  319. clk_disable_unprepare(keypad->clk);
  320. }
  321. static int imx_keypad_open(struct input_dev *dev)
  322. {
  323. struct imx_keypad *keypad = input_get_drvdata(dev);
  324. int error;
  325. dev_dbg(&dev->dev, ">%s\n", __func__);
  326. /* Enable the kpp clock */
  327. error = clk_prepare_enable(keypad->clk);
  328. if (error)
  329. return error;
  330. /* We became active from now */
  331. keypad->enabled = true;
  332. imx_keypad_config(keypad);
  333. /* Sanity control, not all the rows must be actived now. */
  334. if ((readw(keypad->mmio_base + KPDR) & keypad->rows_en_mask) == 0) {
  335. dev_err(&dev->dev,
  336. "too many keys pressed, control pins initialisation\n");
  337. goto open_err;
  338. }
  339. return 0;
  340. open_err:
  341. imx_keypad_close(dev);
  342. return -EIO;
  343. }
  344. #ifdef CONFIG_OF
  345. static struct of_device_id imx_keypad_of_match[] = {
  346. { .compatible = "fsl,imx21-kpp", },
  347. { /* sentinel */ }
  348. };
  349. MODULE_DEVICE_TABLE(of, imx_keypad_of_match);
  350. #endif
  351. static int imx_keypad_probe(struct platform_device *pdev)
  352. {
  353. const struct matrix_keymap_data *keymap_data = pdev->dev.platform_data;
  354. struct imx_keypad *keypad;
  355. struct input_dev *input_dev;
  356. struct resource *res;
  357. int irq, error, i, row, col;
  358. if (!keymap_data && !pdev->dev.of_node) {
  359. dev_err(&pdev->dev, "no keymap defined\n");
  360. return -EINVAL;
  361. }
  362. irq = platform_get_irq(pdev, 0);
  363. if (irq < 0) {
  364. dev_err(&pdev->dev, "no irq defined in platform data\n");
  365. return -EINVAL;
  366. }
  367. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  368. if (res == NULL) {
  369. dev_err(&pdev->dev, "no I/O memory defined in platform data\n");
  370. return -EINVAL;
  371. }
  372. res = request_mem_region(res->start, resource_size(res), pdev->name);
  373. if (res == NULL) {
  374. dev_err(&pdev->dev, "failed to request I/O memory\n");
  375. return -EBUSY;
  376. }
  377. input_dev = input_allocate_device();
  378. if (!input_dev) {
  379. dev_err(&pdev->dev, "failed to allocate the input device\n");
  380. error = -ENOMEM;
  381. goto failed_rel_mem;
  382. }
  383. keypad = kzalloc(sizeof(struct imx_keypad), GFP_KERNEL);
  384. if (!keypad) {
  385. dev_err(&pdev->dev, "not enough memory for driver data\n");
  386. error = -ENOMEM;
  387. goto failed_free_input;
  388. }
  389. keypad->input_dev = input_dev;
  390. keypad->irq = irq;
  391. keypad->stable_count = 0;
  392. setup_timer(&keypad->check_matrix_timer,
  393. imx_keypad_check_for_events, (unsigned long) keypad);
  394. keypad->mmio_base = ioremap(res->start, resource_size(res));
  395. if (keypad->mmio_base == NULL) {
  396. dev_err(&pdev->dev, "failed to remap I/O memory\n");
  397. error = -ENOMEM;
  398. goto failed_free_priv;
  399. }
  400. keypad->clk = clk_get(&pdev->dev, NULL);
  401. if (IS_ERR(keypad->clk)) {
  402. dev_err(&pdev->dev, "failed to get keypad clock\n");
  403. error = PTR_ERR(keypad->clk);
  404. goto failed_unmap;
  405. }
  406. /* Init the Input device */
  407. input_dev->name = pdev->name;
  408. input_dev->id.bustype = BUS_HOST;
  409. input_dev->dev.parent = &pdev->dev;
  410. input_dev->open = imx_keypad_open;
  411. input_dev->close = imx_keypad_close;
  412. error = matrix_keypad_build_keymap(keymap_data, NULL,
  413. MAX_MATRIX_KEY_ROWS,
  414. MAX_MATRIX_KEY_COLS,
  415. keypad->keycodes, input_dev);
  416. if (error) {
  417. dev_err(&pdev->dev, "failed to build keymap\n");
  418. goto failed_clock_put;
  419. }
  420. /* Search for rows and cols enabled */
  421. for (row = 0; row < MAX_MATRIX_KEY_ROWS; row++) {
  422. for (col = 0; col < MAX_MATRIX_KEY_COLS; col++) {
  423. i = MATRIX_SCAN_CODE(row, col, MATRIX_ROW_SHIFT);
  424. if (keypad->keycodes[i] != KEY_RESERVED) {
  425. keypad->rows_en_mask |= 1 << row;
  426. keypad->cols_en_mask |= 1 << col;
  427. }
  428. }
  429. }
  430. dev_dbg(&pdev->dev, "enabled rows mask: %x\n", keypad->rows_en_mask);
  431. dev_dbg(&pdev->dev, "enabled cols mask: %x\n", keypad->cols_en_mask);
  432. __set_bit(EV_REP, input_dev->evbit);
  433. input_set_capability(input_dev, EV_MSC, MSC_SCAN);
  434. input_set_drvdata(input_dev, keypad);
  435. /* Ensure that the keypad will stay dormant until opened */
  436. clk_prepare_enable(keypad->clk);
  437. imx_keypad_inhibit(keypad);
  438. clk_disable_unprepare(keypad->clk);
  439. error = request_irq(irq, imx_keypad_irq_handler, 0,
  440. pdev->name, keypad);
  441. if (error) {
  442. dev_err(&pdev->dev, "failed to request IRQ\n");
  443. goto failed_clock_put;
  444. }
  445. /* Register the input device */
  446. error = input_register_device(input_dev);
  447. if (error) {
  448. dev_err(&pdev->dev, "failed to register input device\n");
  449. goto failed_free_irq;
  450. }
  451. platform_set_drvdata(pdev, keypad);
  452. device_init_wakeup(&pdev->dev, 1);
  453. return 0;
  454. failed_free_irq:
  455. free_irq(irq, pdev);
  456. failed_clock_put:
  457. clk_put(keypad->clk);
  458. failed_unmap:
  459. iounmap(keypad->mmio_base);
  460. failed_free_priv:
  461. kfree(keypad);
  462. failed_free_input:
  463. input_free_device(input_dev);
  464. failed_rel_mem:
  465. release_mem_region(res->start, resource_size(res));
  466. return error;
  467. }
  468. static int imx_keypad_remove(struct platform_device *pdev)
  469. {
  470. struct imx_keypad *keypad = platform_get_drvdata(pdev);
  471. struct resource *res;
  472. dev_dbg(&pdev->dev, ">%s\n", __func__);
  473. platform_set_drvdata(pdev, NULL);
  474. input_unregister_device(keypad->input_dev);
  475. free_irq(keypad->irq, keypad);
  476. clk_put(keypad->clk);
  477. iounmap(keypad->mmio_base);
  478. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  479. release_mem_region(res->start, resource_size(res));
  480. kfree(keypad);
  481. return 0;
  482. }
  483. #ifdef CONFIG_PM_SLEEP
  484. static int imx_kbd_suspend(struct device *dev)
  485. {
  486. struct platform_device *pdev = to_platform_device(dev);
  487. struct imx_keypad *kbd = platform_get_drvdata(pdev);
  488. struct input_dev *input_dev = kbd->input_dev;
  489. /* imx kbd can wake up system even clock is disabled */
  490. mutex_lock(&input_dev->mutex);
  491. if (input_dev->users)
  492. clk_disable_unprepare(kbd->clk);
  493. mutex_unlock(&input_dev->mutex);
  494. if (device_may_wakeup(&pdev->dev))
  495. enable_irq_wake(kbd->irq);
  496. return 0;
  497. }
  498. static int imx_kbd_resume(struct device *dev)
  499. {
  500. struct platform_device *pdev = to_platform_device(dev);
  501. struct imx_keypad *kbd = platform_get_drvdata(pdev);
  502. struct input_dev *input_dev = kbd->input_dev;
  503. int ret = 0;
  504. if (device_may_wakeup(&pdev->dev))
  505. disable_irq_wake(kbd->irq);
  506. mutex_lock(&input_dev->mutex);
  507. if (input_dev->users) {
  508. ret = clk_prepare_enable(kbd->clk);
  509. if (ret)
  510. goto err_clk;
  511. }
  512. err_clk:
  513. mutex_unlock(&input_dev->mutex);
  514. return ret;
  515. }
  516. #endif
  517. static SIMPLE_DEV_PM_OPS(imx_kbd_pm_ops, imx_kbd_suspend, imx_kbd_resume);
  518. static struct platform_driver imx_keypad_driver = {
  519. .driver = {
  520. .name = "imx-keypad",
  521. .owner = THIS_MODULE,
  522. .pm = &imx_kbd_pm_ops,
  523. .of_match_table = of_match_ptr(imx_keypad_of_match),
  524. },
  525. .probe = imx_keypad_probe,
  526. .remove = imx_keypad_remove,
  527. };
  528. module_platform_driver(imx_keypad_driver);
  529. MODULE_AUTHOR("Alberto Panizzo <maramaopercheseimorto@gmail.com>");
  530. MODULE_DESCRIPTION("IMX Keypad Port Driver");
  531. MODULE_LICENSE("GPL v2");
  532. MODULE_ALIAS("platform:imx-keypad");