samsung-keypad.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. /*
  2. * Samsung keypad driver
  3. *
  4. * Copyright (C) 2010 Samsung Electronics Co.Ltd
  5. * Author: Joonyoung Shim <jy0922.shim@samsung.com>
  6. * Author: Donghwa Lee <dh09.lee@samsung.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. */
  13. #include <linux/clk.h>
  14. #include <linux/delay.h>
  15. #include <linux/err.h>
  16. #include <linux/init.h>
  17. #include <linux/input.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/io.h>
  20. #include <linux/module.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/pm.h>
  23. #include <linux/pm_runtime.h>
  24. #include <linux/slab.h>
  25. #include <linux/of.h>
  26. #include <linux/of_gpio.h>
  27. #include <linux/sched.h>
  28. #include <linux/input/samsung-keypad.h>
  29. #define SAMSUNG_KEYIFCON 0x00
  30. #define SAMSUNG_KEYIFSTSCLR 0x04
  31. #define SAMSUNG_KEYIFCOL 0x08
  32. #define SAMSUNG_KEYIFROW 0x0c
  33. #define SAMSUNG_KEYIFFC 0x10
  34. /* SAMSUNG_KEYIFCON */
  35. #define SAMSUNG_KEYIFCON_INT_F_EN (1 << 0)
  36. #define SAMSUNG_KEYIFCON_INT_R_EN (1 << 1)
  37. #define SAMSUNG_KEYIFCON_DF_EN (1 << 2)
  38. #define SAMSUNG_KEYIFCON_FC_EN (1 << 3)
  39. #define SAMSUNG_KEYIFCON_WAKEUPEN (1 << 4)
  40. /* SAMSUNG_KEYIFSTSCLR */
  41. #define SAMSUNG_KEYIFSTSCLR_P_INT_MASK (0xff << 0)
  42. #define SAMSUNG_KEYIFSTSCLR_R_INT_MASK (0xff << 8)
  43. #define SAMSUNG_KEYIFSTSCLR_R_INT_OFFSET 8
  44. #define S5PV210_KEYIFSTSCLR_P_INT_MASK (0x3fff << 0)
  45. #define S5PV210_KEYIFSTSCLR_R_INT_MASK (0x3fff << 16)
  46. #define S5PV210_KEYIFSTSCLR_R_INT_OFFSET 16
  47. /* SAMSUNG_KEYIFCOL */
  48. #define SAMSUNG_KEYIFCOL_MASK (0xff << 0)
  49. #define S5PV210_KEYIFCOLEN_MASK (0xff << 8)
  50. /* SAMSUNG_KEYIFROW */
  51. #define SAMSUNG_KEYIFROW_MASK (0xff << 0)
  52. #define S5PV210_KEYIFROW_MASK (0x3fff << 0)
  53. /* SAMSUNG_KEYIFFC */
  54. #define SAMSUNG_KEYIFFC_MASK (0x3ff << 0)
  55. enum samsung_keypad_type {
  56. KEYPAD_TYPE_SAMSUNG,
  57. KEYPAD_TYPE_S5PV210,
  58. };
  59. struct samsung_keypad {
  60. struct input_dev *input_dev;
  61. struct platform_device *pdev;
  62. struct clk *clk;
  63. void __iomem *base;
  64. wait_queue_head_t wait;
  65. bool stopped;
  66. bool wake_enabled;
  67. int irq;
  68. enum samsung_keypad_type type;
  69. unsigned int row_shift;
  70. unsigned int rows;
  71. unsigned int cols;
  72. unsigned int row_state[SAMSUNG_MAX_COLS];
  73. #ifdef CONFIG_OF
  74. int row_gpios[SAMSUNG_MAX_ROWS];
  75. int col_gpios[SAMSUNG_MAX_COLS];
  76. #endif
  77. unsigned short keycodes[];
  78. };
  79. static void samsung_keypad_scan(struct samsung_keypad *keypad,
  80. unsigned int *row_state)
  81. {
  82. unsigned int col;
  83. unsigned int val;
  84. for (col = 0; col < keypad->cols; col++) {
  85. if (keypad->type == KEYPAD_TYPE_S5PV210) {
  86. val = S5PV210_KEYIFCOLEN_MASK;
  87. val &= ~(1 << col) << 8;
  88. } else {
  89. val = SAMSUNG_KEYIFCOL_MASK;
  90. val &= ~(1 << col);
  91. }
  92. writel(val, keypad->base + SAMSUNG_KEYIFCOL);
  93. mdelay(1);
  94. val = readl(keypad->base + SAMSUNG_KEYIFROW);
  95. row_state[col] = ~val & ((1 << keypad->rows) - 1);
  96. }
  97. /* KEYIFCOL reg clear */
  98. writel(0, keypad->base + SAMSUNG_KEYIFCOL);
  99. }
  100. static bool samsung_keypad_report(struct samsung_keypad *keypad,
  101. unsigned int *row_state)
  102. {
  103. struct input_dev *input_dev = keypad->input_dev;
  104. unsigned int changed;
  105. unsigned int pressed;
  106. unsigned int key_down = 0;
  107. unsigned int val;
  108. unsigned int col, row;
  109. for (col = 0; col < keypad->cols; col++) {
  110. changed = row_state[col] ^ keypad->row_state[col];
  111. key_down |= row_state[col];
  112. if (!changed)
  113. continue;
  114. for (row = 0; row < keypad->rows; row++) {
  115. if (!(changed & (1 << row)))
  116. continue;
  117. pressed = row_state[col] & (1 << row);
  118. dev_dbg(&keypad->input_dev->dev,
  119. "key %s, row: %d, col: %d\n",
  120. pressed ? "pressed" : "released", row, col);
  121. val = MATRIX_SCAN_CODE(row, col, keypad->row_shift);
  122. input_event(input_dev, EV_MSC, MSC_SCAN, val);
  123. input_report_key(input_dev,
  124. keypad->keycodes[val], pressed);
  125. }
  126. input_sync(keypad->input_dev);
  127. }
  128. memcpy(keypad->row_state, row_state, sizeof(keypad->row_state));
  129. return key_down;
  130. }
  131. static irqreturn_t samsung_keypad_irq(int irq, void *dev_id)
  132. {
  133. struct samsung_keypad *keypad = dev_id;
  134. unsigned int row_state[SAMSUNG_MAX_COLS];
  135. unsigned int val;
  136. bool key_down;
  137. pm_runtime_get_sync(&keypad->pdev->dev);
  138. do {
  139. val = readl(keypad->base + SAMSUNG_KEYIFSTSCLR);
  140. /* Clear interrupt. */
  141. writel(~0x0, keypad->base + SAMSUNG_KEYIFSTSCLR);
  142. samsung_keypad_scan(keypad, row_state);
  143. key_down = samsung_keypad_report(keypad, row_state);
  144. if (key_down)
  145. wait_event_timeout(keypad->wait, keypad->stopped,
  146. msecs_to_jiffies(50));
  147. } while (key_down && !keypad->stopped);
  148. pm_runtime_put(&keypad->pdev->dev);
  149. return IRQ_HANDLED;
  150. }
  151. static void samsung_keypad_start(struct samsung_keypad *keypad)
  152. {
  153. unsigned int val;
  154. pm_runtime_get_sync(&keypad->pdev->dev);
  155. /* Tell IRQ thread that it may poll the device. */
  156. keypad->stopped = false;
  157. clk_enable(keypad->clk);
  158. /* Enable interrupt bits. */
  159. val = readl(keypad->base + SAMSUNG_KEYIFCON);
  160. val |= SAMSUNG_KEYIFCON_INT_F_EN | SAMSUNG_KEYIFCON_INT_R_EN;
  161. writel(val, keypad->base + SAMSUNG_KEYIFCON);
  162. /* KEYIFCOL reg clear. */
  163. writel(0, keypad->base + SAMSUNG_KEYIFCOL);
  164. pm_runtime_put(&keypad->pdev->dev);
  165. }
  166. static void samsung_keypad_stop(struct samsung_keypad *keypad)
  167. {
  168. unsigned int val;
  169. pm_runtime_get_sync(&keypad->pdev->dev);
  170. /* Signal IRQ thread to stop polling and disable the handler. */
  171. keypad->stopped = true;
  172. wake_up(&keypad->wait);
  173. disable_irq(keypad->irq);
  174. /* Clear interrupt. */
  175. writel(~0x0, keypad->base + SAMSUNG_KEYIFSTSCLR);
  176. /* Disable interrupt bits. */
  177. val = readl(keypad->base + SAMSUNG_KEYIFCON);
  178. val &= ~(SAMSUNG_KEYIFCON_INT_F_EN | SAMSUNG_KEYIFCON_INT_R_EN);
  179. writel(val, keypad->base + SAMSUNG_KEYIFCON);
  180. clk_disable(keypad->clk);
  181. /*
  182. * Now that chip should not generate interrupts we can safely
  183. * re-enable the handler.
  184. */
  185. enable_irq(keypad->irq);
  186. pm_runtime_put(&keypad->pdev->dev);
  187. }
  188. static int samsung_keypad_open(struct input_dev *input_dev)
  189. {
  190. struct samsung_keypad *keypad = input_get_drvdata(input_dev);
  191. samsung_keypad_start(keypad);
  192. return 0;
  193. }
  194. static void samsung_keypad_close(struct input_dev *input_dev)
  195. {
  196. struct samsung_keypad *keypad = input_get_drvdata(input_dev);
  197. samsung_keypad_stop(keypad);
  198. }
  199. #ifdef CONFIG_OF
  200. static struct samsung_keypad_platdata *samsung_keypad_parse_dt(
  201. struct device *dev)
  202. {
  203. struct samsung_keypad_platdata *pdata;
  204. struct matrix_keymap_data *keymap_data;
  205. uint32_t *keymap, num_rows = 0, num_cols = 0;
  206. struct device_node *np = dev->of_node, *key_np;
  207. unsigned int key_count = 0;
  208. pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
  209. if (!pdata) {
  210. dev_err(dev, "could not allocate memory for platform data\n");
  211. return NULL;
  212. }
  213. of_property_read_u32(np, "samsung,keypad-num-rows", &num_rows);
  214. of_property_read_u32(np, "samsung,keypad-num-columns", &num_cols);
  215. if (!num_rows || !num_cols) {
  216. dev_err(dev, "number of keypad rows/columns not specified\n");
  217. return NULL;
  218. }
  219. pdata->rows = num_rows;
  220. pdata->cols = num_cols;
  221. keymap_data = devm_kzalloc(dev, sizeof(*keymap_data), GFP_KERNEL);
  222. if (!keymap_data) {
  223. dev_err(dev, "could not allocate memory for keymap data\n");
  224. return NULL;
  225. }
  226. pdata->keymap_data = keymap_data;
  227. for_each_child_of_node(np, key_np)
  228. key_count++;
  229. keymap_data->keymap_size = key_count;
  230. keymap = devm_kzalloc(dev, sizeof(uint32_t) * key_count, GFP_KERNEL);
  231. if (!keymap) {
  232. dev_err(dev, "could not allocate memory for keymap\n");
  233. return NULL;
  234. }
  235. keymap_data->keymap = keymap;
  236. for_each_child_of_node(np, key_np) {
  237. u32 row, col, key_code;
  238. of_property_read_u32(key_np, "keypad,row", &row);
  239. of_property_read_u32(key_np, "keypad,column", &col);
  240. of_property_read_u32(key_np, "linux,code", &key_code);
  241. *keymap++ = KEY(row, col, key_code);
  242. }
  243. if (of_get_property(np, "linux,input-no-autorepeat", NULL))
  244. pdata->no_autorepeat = true;
  245. if (of_get_property(np, "linux,input-wakeup", NULL))
  246. pdata->wakeup = true;
  247. return pdata;
  248. }
  249. static void samsung_keypad_parse_dt_gpio(struct device *dev,
  250. struct samsung_keypad *keypad)
  251. {
  252. struct device_node *np = dev->of_node;
  253. int gpio, ret, row, col;
  254. for (row = 0; row < keypad->rows; row++) {
  255. gpio = of_get_named_gpio(np, "row-gpios", row);
  256. keypad->row_gpios[row] = gpio;
  257. if (!gpio_is_valid(gpio)) {
  258. dev_err(dev, "keypad row[%d]: invalid gpio %d\n",
  259. row, gpio);
  260. continue;
  261. }
  262. ret = gpio_request(gpio, "keypad-row");
  263. if (ret)
  264. dev_err(dev, "keypad row[%d] gpio request failed\n",
  265. row);
  266. }
  267. for (col = 0; col < keypad->cols; col++) {
  268. gpio = of_get_named_gpio(np, "col-gpios", col);
  269. keypad->col_gpios[col] = gpio;
  270. if (!gpio_is_valid(gpio)) {
  271. dev_err(dev, "keypad column[%d]: invalid gpio %d\n",
  272. col, gpio);
  273. continue;
  274. }
  275. ret = gpio_request(gpio, "keypad-col");
  276. if (ret)
  277. dev_err(dev, "keypad column[%d] gpio request failed\n",
  278. col);
  279. }
  280. }
  281. static void samsung_keypad_dt_gpio_free(struct samsung_keypad *keypad)
  282. {
  283. int cnt;
  284. for (cnt = 0; cnt < keypad->rows; cnt++)
  285. if (gpio_is_valid(keypad->row_gpios[cnt]))
  286. gpio_free(keypad->row_gpios[cnt]);
  287. for (cnt = 0; cnt < keypad->cols; cnt++)
  288. if (gpio_is_valid(keypad->col_gpios[cnt]))
  289. gpio_free(keypad->col_gpios[cnt]);
  290. }
  291. #else
  292. static
  293. struct samsung_keypad_platdata *samsung_keypad_parse_dt(struct device *dev)
  294. {
  295. return NULL;
  296. }
  297. static void samsung_keypad_dt_gpio_free(struct samsung_keypad *keypad)
  298. {
  299. }
  300. #endif
  301. static int __devinit samsung_keypad_probe(struct platform_device *pdev)
  302. {
  303. const struct samsung_keypad_platdata *pdata;
  304. const struct matrix_keymap_data *keymap_data;
  305. struct samsung_keypad *keypad;
  306. struct resource *res;
  307. struct input_dev *input_dev;
  308. unsigned int row_shift;
  309. unsigned int keymap_size;
  310. int error;
  311. if (pdev->dev.of_node)
  312. pdata = samsung_keypad_parse_dt(&pdev->dev);
  313. else
  314. pdata = pdev->dev.platform_data;
  315. if (!pdata) {
  316. dev_err(&pdev->dev, "no platform data defined\n");
  317. return -EINVAL;
  318. }
  319. keymap_data = pdata->keymap_data;
  320. if (!keymap_data) {
  321. dev_err(&pdev->dev, "no keymap data defined\n");
  322. return -EINVAL;
  323. }
  324. if (!pdata->rows || pdata->rows > SAMSUNG_MAX_ROWS)
  325. return -EINVAL;
  326. if (!pdata->cols || pdata->cols > SAMSUNG_MAX_COLS)
  327. return -EINVAL;
  328. /* initialize the gpio */
  329. if (pdata->cfg_gpio)
  330. pdata->cfg_gpio(pdata->rows, pdata->cols);
  331. row_shift = get_count_order(pdata->cols);
  332. keymap_size = (pdata->rows << row_shift) * sizeof(keypad->keycodes[0]);
  333. keypad = kzalloc(sizeof(*keypad) + keymap_size, GFP_KERNEL);
  334. input_dev = input_allocate_device();
  335. if (!keypad || !input_dev) {
  336. error = -ENOMEM;
  337. goto err_free_mem;
  338. }
  339. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  340. if (!res) {
  341. error = -ENODEV;
  342. goto err_free_mem;
  343. }
  344. keypad->base = ioremap(res->start, resource_size(res));
  345. if (!keypad->base) {
  346. error = -EBUSY;
  347. goto err_free_mem;
  348. }
  349. keypad->clk = clk_get(&pdev->dev, "keypad");
  350. if (IS_ERR(keypad->clk)) {
  351. dev_err(&pdev->dev, "failed to get keypad clk\n");
  352. error = PTR_ERR(keypad->clk);
  353. goto err_unmap_base;
  354. }
  355. keypad->input_dev = input_dev;
  356. keypad->pdev = pdev;
  357. keypad->row_shift = row_shift;
  358. keypad->rows = pdata->rows;
  359. keypad->cols = pdata->cols;
  360. keypad->stopped = true;
  361. init_waitqueue_head(&keypad->wait);
  362. if (pdev->dev.of_node) {
  363. #ifdef CONFIG_OF
  364. samsung_keypad_parse_dt_gpio(&pdev->dev, keypad);
  365. keypad->type = of_device_is_compatible(pdev->dev.of_node,
  366. "samsung,s5pv210-keypad");
  367. #endif
  368. } else {
  369. keypad->type = platform_get_device_id(pdev)->driver_data;
  370. }
  371. input_dev->name = pdev->name;
  372. input_dev->id.bustype = BUS_HOST;
  373. input_dev->dev.parent = &pdev->dev;
  374. input_set_drvdata(input_dev, keypad);
  375. input_dev->open = samsung_keypad_open;
  376. input_dev->close = samsung_keypad_close;
  377. input_dev->evbit[0] = BIT_MASK(EV_KEY);
  378. if (!pdata->no_autorepeat)
  379. input_dev->evbit[0] |= BIT_MASK(EV_REP);
  380. input_set_capability(input_dev, EV_MSC, MSC_SCAN);
  381. input_dev->keycode = keypad->keycodes;
  382. input_dev->keycodesize = sizeof(keypad->keycodes[0]);
  383. input_dev->keycodemax = pdata->rows << row_shift;
  384. matrix_keypad_build_keymap(keymap_data, row_shift,
  385. input_dev->keycode, input_dev->keybit);
  386. keypad->irq = platform_get_irq(pdev, 0);
  387. if (keypad->irq < 0) {
  388. error = keypad->irq;
  389. goto err_put_clk;
  390. }
  391. error = request_threaded_irq(keypad->irq, NULL, samsung_keypad_irq,
  392. IRQF_ONESHOT, dev_name(&pdev->dev), keypad);
  393. if (error) {
  394. dev_err(&pdev->dev, "failed to register keypad interrupt\n");
  395. goto err_put_clk;
  396. }
  397. device_init_wakeup(&pdev->dev, pdata->wakeup);
  398. platform_set_drvdata(pdev, keypad);
  399. pm_runtime_enable(&pdev->dev);
  400. error = input_register_device(keypad->input_dev);
  401. if (error)
  402. goto err_free_irq;
  403. if (pdev->dev.of_node) {
  404. devm_kfree(&pdev->dev, (void *)pdata->keymap_data->keymap);
  405. devm_kfree(&pdev->dev, (void *)pdata->keymap_data);
  406. devm_kfree(&pdev->dev, (void *)pdata);
  407. }
  408. return 0;
  409. err_free_irq:
  410. free_irq(keypad->irq, keypad);
  411. pm_runtime_disable(&pdev->dev);
  412. device_init_wakeup(&pdev->dev, 0);
  413. platform_set_drvdata(pdev, NULL);
  414. err_put_clk:
  415. clk_put(keypad->clk);
  416. samsung_keypad_dt_gpio_free(keypad);
  417. err_unmap_base:
  418. iounmap(keypad->base);
  419. err_free_mem:
  420. input_free_device(input_dev);
  421. kfree(keypad);
  422. return error;
  423. }
  424. static int __devexit samsung_keypad_remove(struct platform_device *pdev)
  425. {
  426. struct samsung_keypad *keypad = platform_get_drvdata(pdev);
  427. pm_runtime_disable(&pdev->dev);
  428. device_init_wakeup(&pdev->dev, 0);
  429. platform_set_drvdata(pdev, NULL);
  430. input_unregister_device(keypad->input_dev);
  431. /*
  432. * It is safe to free IRQ after unregistering device because
  433. * samsung_keypad_close will shut off interrupts.
  434. */
  435. free_irq(keypad->irq, keypad);
  436. clk_put(keypad->clk);
  437. samsung_keypad_dt_gpio_free(keypad);
  438. iounmap(keypad->base);
  439. kfree(keypad);
  440. return 0;
  441. }
  442. #ifdef CONFIG_PM_RUNTIME
  443. static int samsung_keypad_runtime_suspend(struct device *dev)
  444. {
  445. struct platform_device *pdev = to_platform_device(dev);
  446. struct samsung_keypad *keypad = platform_get_drvdata(pdev);
  447. unsigned int val;
  448. int error;
  449. if (keypad->stopped)
  450. return 0;
  451. /* This may fail on some SoCs due to lack of controller support */
  452. error = enable_irq_wake(keypad->irq);
  453. if (!error)
  454. keypad->wake_enabled = true;
  455. val = readl(keypad->base + SAMSUNG_KEYIFCON);
  456. val |= SAMSUNG_KEYIFCON_WAKEUPEN;
  457. writel(val, keypad->base + SAMSUNG_KEYIFCON);
  458. clk_disable(keypad->clk);
  459. return 0;
  460. }
  461. static int samsung_keypad_runtime_resume(struct device *dev)
  462. {
  463. struct platform_device *pdev = to_platform_device(dev);
  464. struct samsung_keypad *keypad = platform_get_drvdata(pdev);
  465. unsigned int val;
  466. if (keypad->stopped)
  467. return 0;
  468. clk_enable(keypad->clk);
  469. val = readl(keypad->base + SAMSUNG_KEYIFCON);
  470. val &= ~SAMSUNG_KEYIFCON_WAKEUPEN;
  471. writel(val, keypad->base + SAMSUNG_KEYIFCON);
  472. if (keypad->wake_enabled)
  473. disable_irq_wake(keypad->irq);
  474. return 0;
  475. }
  476. #endif
  477. #ifdef CONFIG_PM_SLEEP
  478. static void samsung_keypad_toggle_wakeup(struct samsung_keypad *keypad,
  479. bool enable)
  480. {
  481. unsigned int val;
  482. clk_enable(keypad->clk);
  483. val = readl(keypad->base + SAMSUNG_KEYIFCON);
  484. if (enable) {
  485. val |= SAMSUNG_KEYIFCON_WAKEUPEN;
  486. if (device_may_wakeup(&keypad->pdev->dev))
  487. enable_irq_wake(keypad->irq);
  488. } else {
  489. val &= ~SAMSUNG_KEYIFCON_WAKEUPEN;
  490. if (device_may_wakeup(&keypad->pdev->dev))
  491. disable_irq_wake(keypad->irq);
  492. }
  493. writel(val, keypad->base + SAMSUNG_KEYIFCON);
  494. clk_disable(keypad->clk);
  495. }
  496. static int samsung_keypad_suspend(struct device *dev)
  497. {
  498. struct platform_device *pdev = to_platform_device(dev);
  499. struct samsung_keypad *keypad = platform_get_drvdata(pdev);
  500. struct input_dev *input_dev = keypad->input_dev;
  501. mutex_lock(&input_dev->mutex);
  502. if (input_dev->users)
  503. samsung_keypad_stop(keypad);
  504. samsung_keypad_toggle_wakeup(keypad, true);
  505. mutex_unlock(&input_dev->mutex);
  506. return 0;
  507. }
  508. static int samsung_keypad_resume(struct device *dev)
  509. {
  510. struct platform_device *pdev = to_platform_device(dev);
  511. struct samsung_keypad *keypad = platform_get_drvdata(pdev);
  512. struct input_dev *input_dev = keypad->input_dev;
  513. mutex_lock(&input_dev->mutex);
  514. samsung_keypad_toggle_wakeup(keypad, false);
  515. if (input_dev->users)
  516. samsung_keypad_start(keypad);
  517. mutex_unlock(&input_dev->mutex);
  518. return 0;
  519. }
  520. #endif
  521. static const struct dev_pm_ops samsung_keypad_pm_ops = {
  522. SET_SYSTEM_SLEEP_PM_OPS(samsung_keypad_suspend, samsung_keypad_resume)
  523. SET_RUNTIME_PM_OPS(samsung_keypad_runtime_suspend,
  524. samsung_keypad_runtime_resume, NULL)
  525. };
  526. #ifdef CONFIG_OF
  527. static const struct of_device_id samsung_keypad_dt_match[] = {
  528. { .compatible = "samsung,s3c6410-keypad" },
  529. { .compatible = "samsung,s5pv210-keypad" },
  530. {},
  531. };
  532. MODULE_DEVICE_TABLE(of, samsung_keypad_dt_match);
  533. #else
  534. #define samsung_keypad_dt_match NULL
  535. #endif
  536. static struct platform_device_id samsung_keypad_driver_ids[] = {
  537. {
  538. .name = "samsung-keypad",
  539. .driver_data = KEYPAD_TYPE_SAMSUNG,
  540. }, {
  541. .name = "s5pv210-keypad",
  542. .driver_data = KEYPAD_TYPE_S5PV210,
  543. },
  544. { },
  545. };
  546. MODULE_DEVICE_TABLE(platform, samsung_keypad_driver_ids);
  547. static struct platform_driver samsung_keypad_driver = {
  548. .probe = samsung_keypad_probe,
  549. .remove = __devexit_p(samsung_keypad_remove),
  550. .driver = {
  551. .name = "samsung-keypad",
  552. .owner = THIS_MODULE,
  553. .of_match_table = samsung_keypad_dt_match,
  554. .pm = &samsung_keypad_pm_ops,
  555. },
  556. .id_table = samsung_keypad_driver_ids,
  557. };
  558. module_platform_driver(samsung_keypad_driver);
  559. MODULE_DESCRIPTION("Samsung keypad driver");
  560. MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
  561. MODULE_AUTHOR("Donghwa Lee <dh09.lee@samsung.com>");
  562. MODULE_LICENSE("GPL");