This source file includes following definitions.
- rb532_button_pressed
- rb532_button_poll
- rb532_button_probe
- rb532_button_remove
1
2
3
4
5
6
7
8 #include <linux/input-polldev.h>
9 #include <linux/module.h>
10 #include <linux/platform_device.h>
11 #include <linux/gpio.h>
12
13 #include <asm/mach-rc32434/gpio.h>
14 #include <asm/mach-rc32434/rb.h>
15
16 #define DRV_NAME "rb532-button"
17
18 #define RB532_BTN_RATE 100
19 #define RB532_BTN_KSYM BTN_0
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 static bool rb532_button_pressed(void)
35 {
36 int val;
37
38 set_latch_u5(0, LO_FOFF);
39 gpio_direction_input(GPIO_BTN_S1);
40
41 val = gpio_get_value(GPIO_BTN_S1);
42
43 rb532_gpio_set_func(GPIO_BTN_S1);
44 set_latch_u5(LO_FOFF, 0);
45
46 return !val;
47 }
48
49 static void rb532_button_poll(struct input_polled_dev *poll_dev)
50 {
51 input_report_key(poll_dev->input, RB532_BTN_KSYM,
52 rb532_button_pressed());
53 input_sync(poll_dev->input);
54 }
55
56 static int rb532_button_probe(struct platform_device *pdev)
57 {
58 struct input_polled_dev *poll_dev;
59 int error;
60
61 poll_dev = input_allocate_polled_device();
62 if (!poll_dev)
63 return -ENOMEM;
64
65 poll_dev->poll = rb532_button_poll;
66 poll_dev->poll_interval = RB532_BTN_RATE;
67
68 poll_dev->input->name = "rb532 button";
69 poll_dev->input->phys = "rb532/button0";
70 poll_dev->input->id.bustype = BUS_HOST;
71 poll_dev->input->dev.parent = &pdev->dev;
72
73 dev_set_drvdata(&pdev->dev, poll_dev);
74
75 input_set_capability(poll_dev->input, EV_KEY, RB532_BTN_KSYM);
76
77 error = input_register_polled_device(poll_dev);
78 if (error) {
79 input_free_polled_device(poll_dev);
80 return error;
81 }
82
83 return 0;
84 }
85
86 static int rb532_button_remove(struct platform_device *pdev)
87 {
88 struct input_polled_dev *poll_dev = dev_get_drvdata(&pdev->dev);
89
90 input_unregister_polled_device(poll_dev);
91 input_free_polled_device(poll_dev);
92
93 return 0;
94 }
95
96 static struct platform_driver rb532_button_driver = {
97 .probe = rb532_button_probe,
98 .remove = rb532_button_remove,
99 .driver = {
100 .name = DRV_NAME,
101 },
102 };
103 module_platform_driver(rb532_button_driver);
104
105 MODULE_AUTHOR("Phil Sutter <n0-1@freewrt.org>");
106 MODULE_LICENSE("GPL");
107 MODULE_DESCRIPTION("Support for S1 button on Routerboard 532");
108 MODULE_ALIAS("platform:" DRV_NAME);