0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/input.h>
0009 #include <linux/module.h>
0010 #include <linux/platform_device.h>
0011 #include <linux/gpio.h>
0012
0013 #include <asm/mach-rc32434/gpio.h>
0014 #include <asm/mach-rc32434/rb.h>
0015
0016 #define DRV_NAME "rb532-button"
0017
0018 #define RB532_BTN_RATE 100
0019 #define RB532_BTN_KSYM BTN_0
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 static bool rb532_button_pressed(void)
0035 {
0036 int val;
0037
0038 set_latch_u5(0, LO_FOFF);
0039 gpio_direction_input(GPIO_BTN_S1);
0040
0041 val = gpio_get_value(GPIO_BTN_S1);
0042
0043 rb532_gpio_set_func(GPIO_BTN_S1);
0044 set_latch_u5(LO_FOFF, 0);
0045
0046 return !val;
0047 }
0048
0049 static void rb532_button_poll(struct input_dev *input)
0050 {
0051 input_report_key(input, RB532_BTN_KSYM, rb532_button_pressed());
0052 input_sync(input);
0053 }
0054
0055 static int rb532_button_probe(struct platform_device *pdev)
0056 {
0057 struct input_dev *input;
0058 int error;
0059
0060 input = devm_input_allocate_device(&pdev->dev);
0061 if (!input)
0062 return -ENOMEM;
0063
0064 input->name = "rb532 button";
0065 input->phys = "rb532/button0";
0066 input->id.bustype = BUS_HOST;
0067
0068 input_set_capability(input, EV_KEY, RB532_BTN_KSYM);
0069
0070 error = input_setup_polling(input, rb532_button_poll);
0071 if (error)
0072 return error;
0073
0074 input_set_poll_interval(input, RB532_BTN_RATE);
0075
0076 error = input_register_device(input);
0077 if (error)
0078 return error;
0079
0080 return 0;
0081 }
0082
0083 static struct platform_driver rb532_button_driver = {
0084 .probe = rb532_button_probe,
0085 .driver = {
0086 .name = DRV_NAME,
0087 },
0088 };
0089 module_platform_driver(rb532_button_driver);
0090
0091 MODULE_AUTHOR("Phil Sutter <n0-1@freewrt.org>");
0092 MODULE_LICENSE("GPL");
0093 MODULE_DESCRIPTION("Support for S1 button on Routerboard 532");
0094 MODULE_ALIAS("platform:" DRV_NAME);