imx_keypad.c 17 KB

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