gpio-button-hotplug.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. /*
  2. * GPIO Button Hotplug driver
  3. *
  4. * Copyright (C) 2012 Felix Fietkau <[email protected]>
  5. * Copyright (C) 2008-2010 Gabor Juhos <[email protected]>
  6. *
  7. * Based on the diag.c - GPIO interface driver for Broadcom boards
  8. * Copyright (C) 2006 Mike Baker <[email protected]>,
  9. * Copyright (C) 2006-2007 Felix Fietkau <[email protected]>
  10. * Copyright (C) 2008 Andy Boyett <[email protected]>
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License version 2 as published
  14. * by the Free Software Foundation.
  15. */
  16. #include <linux/module.h>
  17. #include <linux/version.h>
  18. #include <linux/kmod.h>
  19. #include <linux/workqueue.h>
  20. #include <linux/skbuff.h>
  21. #include <linux/netlink.h>
  22. #include <linux/kobject.h>
  23. #include <linux/input.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/of_gpio.h>
  27. #include <linux/of_irq.h>
  28. #include <linux/gpio_keys.h>
  29. #include <linux/gpio/consumer.h>
  30. #define BH_SKB_SIZE 2048
  31. #define DRV_NAME "gpio-keys"
  32. #define PFX DRV_NAME ": "
  33. struct bh_event {
  34. const char *name;
  35. unsigned int type;
  36. char *action;
  37. unsigned long seen;
  38. struct sk_buff *skb;
  39. struct work_struct work;
  40. };
  41. struct bh_map {
  42. unsigned int code;
  43. const char *name;
  44. };
  45. struct gpio_keys_button_data {
  46. struct delayed_work work;
  47. unsigned long seen;
  48. int map_entry;
  49. int last_state;
  50. int count;
  51. int threshold;
  52. int can_sleep;
  53. int irq;
  54. unsigned int software_debounce;
  55. struct gpio_desc *gpiod;
  56. const struct gpio_keys_button *b;
  57. };
  58. extern u64 uevent_next_seqnum(void);
  59. #define BH_MAP(_code, _name) \
  60. { \
  61. .code = (_code), \
  62. .name = (_name), \
  63. }
  64. static struct bh_map button_map[] = {
  65. BH_MAP(BTN_0, "BTN_0"),
  66. BH_MAP(BTN_1, "BTN_1"),
  67. BH_MAP(BTN_2, "BTN_2"),
  68. BH_MAP(BTN_3, "BTN_3"),
  69. BH_MAP(BTN_4, "BTN_4"),
  70. BH_MAP(BTN_5, "BTN_5"),
  71. BH_MAP(BTN_6, "BTN_6"),
  72. BH_MAP(BTN_7, "BTN_7"),
  73. BH_MAP(BTN_8, "BTN_8"),
  74. BH_MAP(BTN_9, "BTN_9"),
  75. BH_MAP(KEY_BRIGHTNESS_ZERO, "brightness_zero"),
  76. BH_MAP(KEY_CONFIG, "config"),
  77. BH_MAP(KEY_COPY, "copy"),
  78. BH_MAP(KEY_EJECTCD, "eject"),
  79. BH_MAP(KEY_HELP, "help"),
  80. BH_MAP(KEY_LIGHTS_TOGGLE, "lights_toggle"),
  81. BH_MAP(KEY_PHONE, "phone"),
  82. BH_MAP(KEY_POWER, "power"),
  83. BH_MAP(KEY_POWER2, "reboot"),
  84. BH_MAP(KEY_RESTART, "reset"),
  85. BH_MAP(KEY_RFKILL, "rfkill"),
  86. BH_MAP(KEY_VIDEO, "video"),
  87. BH_MAP(KEY_VOLUMEDOWN, "volume_down"),
  88. BH_MAP(KEY_VOLUMEUP, "volume_up"),
  89. BH_MAP(KEY_WIMAX, "wwan"),
  90. BH_MAP(KEY_WLAN, "wlan"),
  91. BH_MAP(KEY_WPS_BUTTON, "wps"),
  92. };
  93. /* -------------------------------------------------------------------------*/
  94. static __printf(3, 4)
  95. int bh_event_add_var(struct bh_event *event, int argv, const char *format, ...)
  96. {
  97. static char buf[128];
  98. char *s;
  99. va_list args;
  100. int len;
  101. if (argv)
  102. return 0;
  103. va_start(args, format);
  104. len = vsnprintf(buf, sizeof(buf), format, args);
  105. va_end(args);
  106. if (len >= sizeof(buf)) {
  107. WARN(1, "buffer size too small");
  108. return -ENOMEM;
  109. }
  110. s = skb_put(event->skb, len + 1);
  111. strcpy(s, buf);
  112. pr_debug(PFX "added variable '%s'\n", s);
  113. return 0;
  114. }
  115. static int button_hotplug_fill_event(struct bh_event *event)
  116. {
  117. int ret;
  118. ret = bh_event_add_var(event, 0, "HOME=%s", "/");
  119. if (ret)
  120. return ret;
  121. ret = bh_event_add_var(event, 0, "PATH=%s",
  122. "/sbin:/bin:/usr/sbin:/usr/bin");
  123. if (ret)
  124. return ret;
  125. ret = bh_event_add_var(event, 0, "SUBSYSTEM=%s", "button");
  126. if (ret)
  127. return ret;
  128. ret = bh_event_add_var(event, 0, "ACTION=%s", event->action);
  129. if (ret)
  130. return ret;
  131. ret = bh_event_add_var(event, 0, "BUTTON=%s", event->name);
  132. if (ret)
  133. return ret;
  134. if (event->type == EV_SW) {
  135. ret = bh_event_add_var(event, 0, "TYPE=%s", "switch");
  136. if (ret)
  137. return ret;
  138. }
  139. ret = bh_event_add_var(event, 0, "SEEN=%ld", event->seen);
  140. if (ret)
  141. return ret;
  142. ret = bh_event_add_var(event, 0, "SEQNUM=%llu", uevent_next_seqnum());
  143. return ret;
  144. }
  145. static void button_hotplug_work(struct work_struct *work)
  146. {
  147. struct bh_event *event = container_of(work, struct bh_event, work);
  148. int ret = 0;
  149. event->skb = alloc_skb(BH_SKB_SIZE, GFP_KERNEL);
  150. if (!event->skb)
  151. goto out_free_event;
  152. ret = bh_event_add_var(event, 0, "%s@", event->action);
  153. if (ret)
  154. goto out_free_skb;
  155. ret = button_hotplug_fill_event(event);
  156. if (ret)
  157. goto out_free_skb;
  158. NETLINK_CB(event->skb).dst_group = 1;
  159. broadcast_uevent(event->skb, 0, 1, GFP_KERNEL);
  160. out_free_skb:
  161. if (ret) {
  162. pr_err(PFX "work error %d\n", ret);
  163. kfree_skb(event->skb);
  164. }
  165. out_free_event:
  166. kfree(event);
  167. }
  168. static int button_hotplug_create_event(const char *name, unsigned int type,
  169. unsigned long seen, int pressed)
  170. {
  171. struct bh_event *event;
  172. pr_debug(PFX "create event, name=%s, seen=%lu, pressed=%d\n",
  173. name, seen, pressed);
  174. event = kzalloc(sizeof(*event), GFP_KERNEL);
  175. if (!event)
  176. return -ENOMEM;
  177. event->name = name;
  178. event->type = type;
  179. event->seen = seen;
  180. event->action = pressed ? "pressed" : "released";
  181. INIT_WORK(&event->work, (void *)(void *)button_hotplug_work);
  182. schedule_work(&event->work);
  183. return 0;
  184. }
  185. /* -------------------------------------------------------------------------*/
  186. static int button_get_index(unsigned int code)
  187. {
  188. int i;
  189. for (i = 0; i < ARRAY_SIZE(button_map); i++)
  190. if (button_map[i].code == code)
  191. return i;
  192. return -1;
  193. }
  194. static int gpio_button_get_value(struct gpio_keys_button_data *bdata)
  195. {
  196. int val;
  197. if (bdata->can_sleep)
  198. val = !!gpio_get_value_cansleep(bdata->b->gpio);
  199. else
  200. val = !!gpio_get_value(bdata->b->gpio);
  201. return val ^ bdata->b->active_low;
  202. }
  203. static void gpio_keys_handle_button(struct gpio_keys_button_data *bdata)
  204. {
  205. unsigned int type = bdata->b->type ?: EV_KEY;
  206. int state = gpio_button_get_value(bdata);
  207. unsigned long seen = jiffies;
  208. pr_debug(PFX "event type=%u, code=%u, pressed=%d\n",
  209. type, bdata->b->code, state);
  210. /* is this the initialization state? */
  211. if (bdata->last_state == -1) {
  212. /*
  213. * Don't advertise unpressed buttons on initialization.
  214. * Just save their state and continue otherwise this
  215. * can cause OpenWrt to enter failsafe.
  216. */
  217. if (type == EV_KEY && state == 0)
  218. goto set_state;
  219. /*
  220. * But we are very interested in pressed buttons and
  221. * initial switch state. These will be reported to
  222. * userland.
  223. */
  224. } else if (bdata->last_state == state) {
  225. /* reset asserted counter (only relevant for polled keys) */
  226. bdata->count = 0;
  227. return;
  228. }
  229. if (bdata->count < bdata->threshold) {
  230. bdata->count++;
  231. return;
  232. }
  233. if (bdata->seen == 0)
  234. bdata->seen = seen;
  235. button_hotplug_create_event(button_map[bdata->map_entry].name, type,
  236. (seen - bdata->seen) / HZ, state);
  237. bdata->seen = seen;
  238. set_state:
  239. bdata->last_state = state;
  240. bdata->count = 0;
  241. }
  242. struct gpio_keys_button_dev {
  243. int polled;
  244. struct delayed_work work;
  245. struct device *dev;
  246. struct gpio_keys_platform_data *pdata;
  247. struct gpio_keys_button_data data[0];
  248. };
  249. static void gpio_keys_polled_queue_work(struct gpio_keys_button_dev *bdev)
  250. {
  251. struct gpio_keys_platform_data *pdata = bdev->pdata;
  252. unsigned long delay = msecs_to_jiffies(pdata->poll_interval);
  253. if (delay >= HZ)
  254. delay = round_jiffies_relative(delay);
  255. schedule_delayed_work(&bdev->work, delay);
  256. }
  257. static void gpio_keys_polled_poll(struct work_struct *work)
  258. {
  259. struct gpio_keys_button_dev *bdev =
  260. container_of(work, struct gpio_keys_button_dev, work.work);
  261. int i;
  262. for (i = 0; i < bdev->pdata->nbuttons; i++) {
  263. struct gpio_keys_button_data *bdata = &bdev->data[i];
  264. if (bdata->gpiod)
  265. gpio_keys_handle_button(bdata);
  266. }
  267. gpio_keys_polled_queue_work(bdev);
  268. }
  269. static void gpio_keys_polled_close(struct gpio_keys_button_dev *bdev)
  270. {
  271. struct gpio_keys_platform_data *pdata = bdev->pdata;
  272. cancel_delayed_work_sync(&bdev->work);
  273. if (pdata->disable)
  274. pdata->disable(bdev->dev);
  275. }
  276. static void gpio_keys_irq_work_func(struct work_struct *work)
  277. {
  278. struct gpio_keys_button_data *bdata = container_of(work,
  279. struct gpio_keys_button_data, work.work);
  280. gpio_keys_handle_button(bdata);
  281. }
  282. static irqreturn_t button_handle_irq(int irq, void *_bdata)
  283. {
  284. struct gpio_keys_button_data *bdata =
  285. (struct gpio_keys_button_data *) _bdata;
  286. mod_delayed_work(system_wq, &bdata->work,
  287. msecs_to_jiffies(bdata->software_debounce));
  288. return IRQ_HANDLED;
  289. }
  290. #ifdef CONFIG_OF
  291. static struct gpio_keys_platform_data *
  292. gpio_keys_get_devtree_pdata(struct device *dev)
  293. {
  294. struct device_node *node, *pp;
  295. struct gpio_keys_platform_data *pdata;
  296. struct gpio_keys_button *button;
  297. int error;
  298. int nbuttons;
  299. int i = 0;
  300. node = dev->of_node;
  301. if (!node)
  302. return NULL;
  303. nbuttons = of_get_child_count(node);
  304. if (nbuttons == 0)
  305. return NULL;
  306. pdata = devm_kzalloc(dev, sizeof(*pdata) + nbuttons * (sizeof *button),
  307. GFP_KERNEL);
  308. if (!pdata) {
  309. error = -ENOMEM;
  310. goto err_out;
  311. }
  312. pdata->buttons = (struct gpio_keys_button *)(pdata + 1);
  313. pdata->nbuttons = nbuttons;
  314. pdata->rep = !!of_get_property(node, "autorepeat", NULL);
  315. of_property_read_u32(node, "poll-interval", &pdata->poll_interval);
  316. for_each_child_of_node(node, pp) {
  317. enum of_gpio_flags flags;
  318. if (!of_find_property(pp, "gpios", NULL)) {
  319. pdata->nbuttons--;
  320. dev_warn(dev, "Found button without gpios\n");
  321. continue;
  322. }
  323. button = (struct gpio_keys_button *)(&pdata->buttons[i++]);
  324. button->irq = irq_of_parse_and_map(pp, 0);
  325. button->gpio = of_get_gpio_flags(pp, 0, &flags);
  326. if (button->gpio < 0) {
  327. error = button->gpio;
  328. if (error != -ENOENT) {
  329. if (error != -EPROBE_DEFER)
  330. dev_err(dev,
  331. "Failed to get gpio flags, error: %d\n",
  332. error);
  333. return ERR_PTR(error);
  334. }
  335. } else {
  336. button->active_low = !!(flags & OF_GPIO_ACTIVE_LOW);
  337. }
  338. if (of_property_read_u32(pp, "linux,code", &button->code)) {
  339. dev_err(dev, "Button without keycode: 0x%x\n",
  340. button->gpio);
  341. error = -EINVAL;
  342. goto err_out;
  343. }
  344. button->desc = of_get_property(pp, "label", NULL);
  345. if (of_property_read_u32(pp, "linux,input-type", &button->type))
  346. button->type = EV_KEY;
  347. button->wakeup = !!of_get_property(pp, "gpio-key,wakeup", NULL);
  348. if (of_property_read_u32(pp, "debounce-interval",
  349. &button->debounce_interval))
  350. button->debounce_interval = 5;
  351. }
  352. if (pdata->nbuttons == 0) {
  353. error = -EINVAL;
  354. goto err_out;
  355. }
  356. return pdata;
  357. err_out:
  358. return ERR_PTR(error);
  359. }
  360. static struct of_device_id gpio_keys_of_match[] = {
  361. { .compatible = "gpio-keys", },
  362. { },
  363. };
  364. MODULE_DEVICE_TABLE(of, gpio_keys_of_match);
  365. static struct of_device_id gpio_keys_polled_of_match[] = {
  366. { .compatible = "gpio-keys-polled", },
  367. { },
  368. };
  369. MODULE_DEVICE_TABLE(of, gpio_keys_polled_of_match);
  370. #else
  371. static inline struct gpio_keys_platform_data *
  372. gpio_keys_get_devtree_pdata(struct device *dev)
  373. {
  374. return NULL;
  375. }
  376. #endif
  377. static int gpio_keys_button_probe(struct platform_device *pdev,
  378. struct gpio_keys_button_dev **_bdev, int polled)
  379. {
  380. struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
  381. struct device *dev = &pdev->dev;
  382. struct gpio_keys_button_dev *bdev;
  383. struct gpio_keys_button *buttons;
  384. int error;
  385. int i;
  386. if (!pdata) {
  387. pdata = gpio_keys_get_devtree_pdata(dev);
  388. if (IS_ERR(pdata))
  389. return PTR_ERR(pdata);
  390. if (!pdata) {
  391. dev_err(dev, "missing platform data\n");
  392. return -EINVAL;
  393. }
  394. }
  395. if (polled && !pdata->poll_interval) {
  396. dev_err(dev, "missing poll_interval value\n");
  397. return -EINVAL;
  398. }
  399. buttons = devm_kzalloc(dev, pdata->nbuttons * sizeof(struct gpio_keys_button),
  400. GFP_KERNEL);
  401. if (!buttons) {
  402. dev_err(dev, "no memory for button data\n");
  403. return -ENOMEM;
  404. }
  405. memcpy(buttons, pdata->buttons, pdata->nbuttons * sizeof(struct gpio_keys_button));
  406. bdev = devm_kzalloc(dev, sizeof(struct gpio_keys_button_dev) +
  407. pdata->nbuttons * sizeof(struct gpio_keys_button_data),
  408. GFP_KERNEL);
  409. if (!bdev) {
  410. dev_err(dev, "no memory for private data\n");
  411. return -ENOMEM;
  412. }
  413. bdev->polled = polled;
  414. for (i = 0; i < pdata->nbuttons; i++) {
  415. struct gpio_keys_button *button = &buttons[i];
  416. struct gpio_keys_button_data *bdata = &bdev->data[i];
  417. unsigned int gpio = button->gpio;
  418. if (button->wakeup) {
  419. dev_err(dev, "does not support wakeup\n");
  420. return -EINVAL;
  421. }
  422. bdata->map_entry = button_get_index(button->code);
  423. if (bdata->map_entry < 0) {
  424. dev_warn(dev, "does not support key code:%u\n",
  425. button->code);
  426. continue;
  427. }
  428. if (!(button->type == 0 || button->type == EV_KEY ||
  429. button->type == EV_SW)) {
  430. dev_warn(dev, "only supports buttons or switches\n");
  431. continue;
  432. }
  433. error = devm_gpio_request(dev, gpio,
  434. button->desc ? button->desc : DRV_NAME);
  435. if (error) {
  436. dev_err(dev, "unable to claim gpio %u, err=%d\n",
  437. gpio, error);
  438. return error;
  439. }
  440. bdata->gpiod = gpio_to_desc(gpio);
  441. if (!bdata->gpiod)
  442. return -EINVAL;
  443. error = gpio_direction_input(gpio);
  444. if (error) {
  445. dev_err(dev,
  446. "unable to set direction on gpio %u, err=%d\n",
  447. gpio, error);
  448. return error;
  449. }
  450. bdata->can_sleep = gpio_cansleep(gpio);
  451. bdata->last_state = -1; /* Unknown state on boot */
  452. if (bdev->polled) {
  453. bdata->threshold = DIV_ROUND_UP(button->debounce_interval,
  454. pdata->poll_interval);
  455. } else {
  456. /* bdata->threshold = 0; already initialized */
  457. if (button->debounce_interval) {
  458. error = gpiod_set_debounce(bdata->gpiod,
  459. button->debounce_interval * 1000);
  460. /*
  461. * use timer if gpiolib doesn't provide
  462. * debounce.
  463. */
  464. if (error < 0) {
  465. bdata->software_debounce =
  466. button->debounce_interval;
  467. }
  468. }
  469. }
  470. bdata->b = &pdata->buttons[i];
  471. }
  472. bdev->dev = &pdev->dev;
  473. bdev->pdata = pdata;
  474. platform_set_drvdata(pdev, bdev);
  475. *_bdev = bdev;
  476. return 0;
  477. }
  478. static int gpio_keys_probe(struct platform_device *pdev)
  479. {
  480. struct gpio_keys_platform_data *pdata;
  481. struct gpio_keys_button_dev *bdev;
  482. int ret, i;
  483. ret = gpio_keys_button_probe(pdev, &bdev, 0);
  484. if (ret)
  485. return ret;
  486. pdata = bdev->pdata;
  487. for (i = 0; i < pdata->nbuttons; i++) {
  488. const struct gpio_keys_button *button = &pdata->buttons[i];
  489. struct gpio_keys_button_data *bdata = &bdev->data[i];
  490. unsigned long irqflags = IRQF_ONESHOT;
  491. INIT_DELAYED_WORK(&bdata->work, gpio_keys_irq_work_func);
  492. if (!bdata->gpiod)
  493. continue;
  494. if (!button->irq) {
  495. bdata->irq = gpio_to_irq(button->gpio);
  496. if (bdata->irq < 0) {
  497. dev_err(&pdev->dev, "failed to get irq for gpio:%d\n",
  498. button->gpio);
  499. continue;
  500. }
  501. irqflags |= IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING;
  502. } else {
  503. bdata->irq = button->irq;
  504. }
  505. schedule_delayed_work(&bdata->work,
  506. msecs_to_jiffies(bdata->software_debounce));
  507. ret = devm_request_threaded_irq(&pdev->dev,
  508. bdata->irq, NULL, button_handle_irq,
  509. irqflags, dev_name(&pdev->dev), bdata);
  510. if (ret < 0) {
  511. bdata->irq = 0;
  512. dev_err(&pdev->dev, "failed to request irq:%d for gpio:%d\n",
  513. bdata->irq, button->gpio);
  514. continue;
  515. } else {
  516. dev_dbg(&pdev->dev, "gpio:%d has irq:%d\n",
  517. button->gpio, bdata->irq);
  518. }
  519. }
  520. return 0;
  521. }
  522. static int gpio_keys_polled_probe(struct platform_device *pdev)
  523. {
  524. struct gpio_keys_platform_data *pdata;
  525. struct gpio_keys_button_dev *bdev;
  526. int ret;
  527. ret = gpio_keys_button_probe(pdev, &bdev, 1);
  528. if (ret)
  529. return ret;
  530. INIT_DELAYED_WORK(&bdev->work, gpio_keys_polled_poll);
  531. pdata = bdev->pdata;
  532. if (pdata->enable)
  533. pdata->enable(bdev->dev);
  534. gpio_keys_polled_queue_work(bdev);
  535. return ret;
  536. }
  537. static void gpio_keys_irq_close(struct gpio_keys_button_dev *bdev)
  538. {
  539. struct gpio_keys_platform_data *pdata = bdev->pdata;
  540. size_t i;
  541. for (i = 0; i < pdata->nbuttons; i++) {
  542. struct gpio_keys_button_data *bdata = &bdev->data[i];
  543. disable_irq(bdata->irq);
  544. cancel_delayed_work_sync(&bdata->work);
  545. }
  546. }
  547. static int gpio_keys_remove(struct platform_device *pdev)
  548. {
  549. struct gpio_keys_button_dev *bdev = platform_get_drvdata(pdev);
  550. platform_set_drvdata(pdev, NULL);
  551. if (bdev->polled)
  552. gpio_keys_polled_close(bdev);
  553. else
  554. gpio_keys_irq_close(bdev);
  555. return 0;
  556. }
  557. static struct platform_driver gpio_keys_driver = {
  558. .probe = gpio_keys_probe,
  559. .remove = gpio_keys_remove,
  560. .driver = {
  561. .name = "gpio-keys",
  562. .owner = THIS_MODULE,
  563. .of_match_table = of_match_ptr(gpio_keys_of_match),
  564. },
  565. };
  566. static struct platform_driver gpio_keys_polled_driver = {
  567. .probe = gpio_keys_polled_probe,
  568. .remove = gpio_keys_remove,
  569. .driver = {
  570. .name = "gpio-keys-polled",
  571. .owner = THIS_MODULE,
  572. .of_match_table = of_match_ptr(gpio_keys_polled_of_match),
  573. },
  574. };
  575. static int __init gpio_button_init(void)
  576. {
  577. int ret;
  578. ret = platform_driver_register(&gpio_keys_driver);
  579. if (ret)
  580. return ret;
  581. ret = platform_driver_register(&gpio_keys_polled_driver);
  582. if (ret)
  583. platform_driver_unregister(&gpio_keys_driver);
  584. return ret;
  585. }
  586. static void __exit gpio_button_exit(void)
  587. {
  588. platform_driver_unregister(&gpio_keys_driver);
  589. platform_driver_unregister(&gpio_keys_polled_driver);
  590. }
  591. module_init(gpio_button_init);
  592. module_exit(gpio_button_exit);
  593. MODULE_AUTHOR("Gabor Juhos <[email protected]>");
  594. MODULE_AUTHOR("Felix Fietkau <[email protected]>");
  595. MODULE_DESCRIPTION("Polled GPIO Buttons hotplug driver");
  596. MODULE_LICENSE("GPL v2");
  597. MODULE_ALIAS("platform:" DRV_NAME);