gpio-button-hotplug.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  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. 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 = !!gpiod_get_value_cansleep(bdata->gpiod);
  199. else
  200. val = !!gpiod_get_value(bdata->gpiod);
  201. return val;
  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 nbuttons;
  298. int i = 0;
  299. node = dev->of_node;
  300. if (!node)
  301. return NULL;
  302. nbuttons = of_get_child_count(node);
  303. if (nbuttons == 0)
  304. return ERR_PTR(-EINVAL);
  305. pdata = devm_kzalloc(dev, sizeof(*pdata) + nbuttons * (sizeof *button),
  306. GFP_KERNEL);
  307. if (!pdata)
  308. return ERR_PTR(-ENOMEM);
  309. pdata->buttons = (struct gpio_keys_button *)(pdata + 1);
  310. pdata->nbuttons = nbuttons;
  311. pdata->rep = !!of_get_property(node, "autorepeat", NULL);
  312. of_property_read_u32(node, "poll-interval", &pdata->poll_interval);
  313. for_each_child_of_node(node, pp) {
  314. button = (struct gpio_keys_button *)(&pdata->buttons[i++]);
  315. if (of_property_read_u32(pp, "linux,code", &button->code)) {
  316. dev_err(dev, "Button node '%s' without keycode\n",
  317. pp->full_name);
  318. of_node_put(pp);
  319. return ERR_PTR(-EINVAL);
  320. }
  321. button->desc = of_get_property(pp, "label", NULL);
  322. if (of_property_read_u32(pp, "linux,input-type", &button->type))
  323. button->type = EV_KEY;
  324. button->wakeup = !!of_get_property(pp, "gpio-key,wakeup", NULL);
  325. if (of_property_read_u32(pp, "debounce-interval",
  326. &button->debounce_interval))
  327. button->debounce_interval = 5;
  328. button->irq = irq_of_parse_and_map(pp, 0);
  329. button->gpio = -ENOENT; /* mark this as device-tree */
  330. }
  331. return pdata;
  332. }
  333. static struct of_device_id gpio_keys_of_match[] = {
  334. { .compatible = "gpio-keys", },
  335. { },
  336. };
  337. MODULE_DEVICE_TABLE(of, gpio_keys_of_match);
  338. static struct of_device_id gpio_keys_polled_of_match[] = {
  339. { .compatible = "gpio-keys-polled", },
  340. { },
  341. };
  342. MODULE_DEVICE_TABLE(of, gpio_keys_polled_of_match);
  343. #else
  344. static inline struct gpio_keys_platform_data *
  345. gpio_keys_get_devtree_pdata(struct device *dev)
  346. {
  347. return NULL;
  348. }
  349. #endif
  350. static int gpio_keys_button_probe(struct platform_device *pdev,
  351. struct gpio_keys_button_dev **_bdev, int polled)
  352. {
  353. struct device *dev = &pdev->dev;
  354. struct gpio_keys_platform_data *pdata = dev_get_platdata(dev);
  355. struct gpio_keys_button_dev *bdev;
  356. struct gpio_keys_button *buttons;
  357. struct device_node *prev = NULL;
  358. int error = 0;
  359. int i;
  360. if (!pdata) {
  361. pdata = gpio_keys_get_devtree_pdata(dev);
  362. if (IS_ERR(pdata))
  363. return PTR_ERR(pdata);
  364. if (!pdata) {
  365. dev_err(dev, "missing platform data\n");
  366. return -EINVAL;
  367. }
  368. }
  369. if (polled && !pdata->poll_interval) {
  370. dev_err(dev, "missing poll_interval value\n");
  371. return -EINVAL;
  372. }
  373. buttons = devm_kzalloc(dev, pdata->nbuttons * sizeof(struct gpio_keys_button),
  374. GFP_KERNEL);
  375. if (!buttons) {
  376. dev_err(dev, "no memory for button data\n");
  377. return -ENOMEM;
  378. }
  379. memcpy(buttons, pdata->buttons, pdata->nbuttons * sizeof(struct gpio_keys_button));
  380. bdev = devm_kzalloc(dev, sizeof(struct gpio_keys_button_dev) +
  381. pdata->nbuttons * sizeof(struct gpio_keys_button_data),
  382. GFP_KERNEL);
  383. if (!bdev) {
  384. dev_err(dev, "no memory for private data\n");
  385. return -ENOMEM;
  386. }
  387. bdev->polled = polled;
  388. for (i = 0; i < pdata->nbuttons; i++) {
  389. struct gpio_keys_button *button = &buttons[i];
  390. struct gpio_keys_button_data *bdata = &bdev->data[i];
  391. const char *desc = button->desc ? button->desc : DRV_NAME;
  392. if (button->wakeup) {
  393. dev_err(dev, "does not support wakeup\n");
  394. error = -EINVAL;
  395. goto out;
  396. }
  397. bdata->map_entry = button_get_index(button->code);
  398. if (bdata->map_entry < 0) {
  399. dev_err(dev, "does not support key code:%u\n",
  400. button->code);
  401. error = -EINVAL;
  402. goto out;
  403. }
  404. if (!(button->type == 0 || button->type == EV_KEY ||
  405. button->type == EV_SW)) {
  406. dev_err(dev, "only supports buttons or switches\n");
  407. error = -EINVAL;
  408. goto out;
  409. }
  410. if (button->irq) {
  411. dev_err(dev, "skipping button %s (only gpio buttons supported)\n",
  412. button->desc);
  413. bdata->b = &pdata->buttons[i];
  414. continue;
  415. }
  416. if (gpio_is_valid(button->gpio)) {
  417. /* legacy platform data... but is it the lookup table? */
  418. bdata->gpiod = devm_gpiod_get_index(dev, desc, i,
  419. GPIOD_IN);
  420. if (IS_ERR(bdata->gpiod)) {
  421. /* or the legacy (button->gpio is good) way? */
  422. error = devm_gpio_request_one(dev,
  423. button->gpio, GPIOF_IN | (
  424. button->active_low ? GPIOF_ACTIVE_LOW :
  425. 0), desc);
  426. if (error) {
  427. if (error != -EPROBE_DEFER) {
  428. dev_err(dev, "unable to claim gpio %d, err=%d\n",
  429. button->gpio, error);
  430. }
  431. goto out;
  432. }
  433. bdata->gpiod = gpio_to_desc(button->gpio);
  434. }
  435. } else {
  436. /* Device-tree */
  437. struct device_node *child =
  438. of_get_next_child(dev->of_node, prev);
  439. bdata->gpiod = devm_gpiod_get_from_of_node(dev,
  440. child, "gpios", 0, GPIOD_IN, desc);
  441. prev = child;
  442. }
  443. if (IS_ERR_OR_NULL(bdata->gpiod)) {
  444. error = IS_ERR(bdata->gpiod) ? PTR_ERR(bdata->gpiod) :
  445. -EINVAL;
  446. goto out;
  447. }
  448. bdata->can_sleep = gpiod_cansleep(bdata->gpiod);
  449. bdata->last_state = -1; /* Unknown state on boot */
  450. if (bdev->polled) {
  451. bdata->threshold = DIV_ROUND_UP(button->debounce_interval,
  452. pdata->poll_interval);
  453. } else {
  454. /* bdata->threshold = 0; already initialized */
  455. if (button->debounce_interval) {
  456. error = gpiod_set_debounce(bdata->gpiod,
  457. button->debounce_interval * 1000);
  458. /*
  459. * use timer if gpiolib doesn't provide
  460. * debounce.
  461. */
  462. if (error < 0) {
  463. bdata->software_debounce =
  464. button->debounce_interval;
  465. }
  466. }
  467. }
  468. bdata->b = &pdata->buttons[i];
  469. }
  470. bdev->dev = &pdev->dev;
  471. bdev->pdata = pdata;
  472. platform_set_drvdata(pdev, bdev);
  473. *_bdev = bdev;
  474. error = 0;
  475. out:
  476. of_node_put(prev);
  477. return error;
  478. }
  479. static int gpio_keys_probe(struct platform_device *pdev)
  480. {
  481. struct gpio_keys_platform_data *pdata;
  482. struct gpio_keys_button_dev *bdev;
  483. int ret, i;
  484. ret = gpio_keys_button_probe(pdev, &bdev, 0);
  485. if (ret)
  486. return ret;
  487. pdata = bdev->pdata;
  488. for (i = 0; i < pdata->nbuttons; i++) {
  489. const struct gpio_keys_button *button = &pdata->buttons[i];
  490. struct gpio_keys_button_data *bdata = &bdev->data[i];
  491. unsigned long irqflags = IRQF_ONESHOT;
  492. INIT_DELAYED_WORK(&bdata->work, gpio_keys_irq_work_func);
  493. if (!button->irq) {
  494. bdata->irq = gpiod_to_irq(bdata->gpiod);
  495. if (bdata->irq < 0) {
  496. dev_err(&pdev->dev, "failed to get irq for gpio:%d\n",
  497. button->gpio);
  498. continue;
  499. }
  500. irqflags |= IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING;
  501. } else {
  502. bdata->irq = button->irq;
  503. }
  504. schedule_delayed_work(&bdata->work,
  505. msecs_to_jiffies(bdata->software_debounce));
  506. ret = devm_request_threaded_irq(&pdev->dev,
  507. bdata->irq, NULL, button_handle_irq,
  508. irqflags, dev_name(&pdev->dev), bdata);
  509. if (ret < 0) {
  510. bdata->irq = 0;
  511. dev_err(&pdev->dev, "failed to request irq:%d for gpio:%d\n",
  512. bdata->irq, button->gpio);
  513. continue;
  514. } else {
  515. dev_dbg(&pdev->dev, "gpio:%d has irq:%d\n",
  516. button->gpio, bdata->irq);
  517. }
  518. }
  519. return 0;
  520. }
  521. static int gpio_keys_polled_probe(struct platform_device *pdev)
  522. {
  523. struct gpio_keys_platform_data *pdata;
  524. struct gpio_keys_button_dev *bdev;
  525. int ret;
  526. ret = gpio_keys_button_probe(pdev, &bdev, 1);
  527. if (ret)
  528. return ret;
  529. INIT_DELAYED_WORK(&bdev->work, gpio_keys_polled_poll);
  530. pdata = bdev->pdata;
  531. if (pdata->enable)
  532. pdata->enable(bdev->dev);
  533. gpio_keys_polled_queue_work(bdev);
  534. return ret;
  535. }
  536. static void gpio_keys_irq_close(struct gpio_keys_button_dev *bdev)
  537. {
  538. struct gpio_keys_platform_data *pdata = bdev->pdata;
  539. size_t i;
  540. for (i = 0; i < pdata->nbuttons; i++) {
  541. struct gpio_keys_button_data *bdata = &bdev->data[i];
  542. disable_irq(bdata->irq);
  543. cancel_delayed_work_sync(&bdata->work);
  544. }
  545. }
  546. static int gpio_keys_remove(struct platform_device *pdev)
  547. {
  548. struct gpio_keys_button_dev *bdev = platform_get_drvdata(pdev);
  549. platform_set_drvdata(pdev, NULL);
  550. if (bdev->polled)
  551. gpio_keys_polled_close(bdev);
  552. else
  553. gpio_keys_irq_close(bdev);
  554. return 0;
  555. }
  556. static struct platform_driver gpio_keys_driver = {
  557. .probe = gpio_keys_probe,
  558. .remove = gpio_keys_remove,
  559. .driver = {
  560. .name = "gpio-keys",
  561. .owner = THIS_MODULE,
  562. .of_match_table = of_match_ptr(gpio_keys_of_match),
  563. },
  564. };
  565. static struct platform_driver gpio_keys_polled_driver = {
  566. .probe = gpio_keys_polled_probe,
  567. .remove = gpio_keys_remove,
  568. .driver = {
  569. .name = "gpio-keys-polled",
  570. .owner = THIS_MODULE,
  571. .of_match_table = of_match_ptr(gpio_keys_polled_of_match),
  572. },
  573. };
  574. static int __init gpio_button_init(void)
  575. {
  576. int ret;
  577. ret = platform_driver_register(&gpio_keys_driver);
  578. if (ret)
  579. return ret;
  580. ret = platform_driver_register(&gpio_keys_polled_driver);
  581. if (ret)
  582. platform_driver_unregister(&gpio_keys_driver);
  583. return ret;
  584. }
  585. static void __exit gpio_button_exit(void)
  586. {
  587. platform_driver_unregister(&gpio_keys_driver);
  588. platform_driver_unregister(&gpio_keys_polled_driver);
  589. }
  590. module_init(gpio_button_init);
  591. module_exit(gpio_button_exit);
  592. MODULE_AUTHOR("Gabor Juhos <[email protected]>");
  593. MODULE_AUTHOR("Felix Fietkau <[email protected]>");
  594. MODULE_DESCRIPTION("Polled GPIO Buttons hotplug driver");
  595. MODULE_LICENSE("GPL v2");
  596. MODULE_ALIAS("platform:" DRV_NAME);