Linux Audio

Check our new training course

Loading...
v6.8
 1// SPDX-License-Identifier: GPL-2.0-only
 2/*
 3 * Support for the S1 button on Routerboard 532
 4 *
 5 * Copyright (C) 2009  Phil Sutter <n0-1@freewrt.org>
 6 */
 7
 8#include <linux/input.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 /* msec */
19#define RB532_BTN_KSYM BTN_0
20
21/* The S1 button state is provided by GPIO pin 1. But as this
22 * pin is also used for uart input as alternate function, the
23 * operational modes must be switched first:
24 * 1) disable uart using set_latch_u5()
25 * 2) turn off alternate function implicitly through
26 *    gpio_direction_input()
27 * 3) read the GPIO's current value
28 * 4) undo step 2 by enabling alternate function (in this
29 *    mode the GPIO direction is fixed, so no change needed)
30 * 5) turn on uart again
31 * The GPIO value occurs to be inverted, so pin high means
32 * button is not pressed.
33 */
34static 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
49static void rb532_button_poll(struct input_dev *input)
50{
51	input_report_key(input, RB532_BTN_KSYM, rb532_button_pressed());
52	input_sync(input);
 
53}
54
55static int rb532_button_probe(struct platform_device *pdev)
56{
57	struct input_dev *input;
58	int error;
59
60	input = devm_input_allocate_device(&pdev->dev);
61	if (!input)
62		return -ENOMEM;
63
64	input->name = "rb532 button";
65	input->phys = "rb532/button0";
66	input->id.bustype = BUS_HOST;
67
68	input_set_capability(input, EV_KEY, RB532_BTN_KSYM);
 
 
 
69
70	error = input_setup_polling(input, rb532_button_poll);
71	if (error)
72		return error;
73
74	input_set_poll_interval(input, RB532_BTN_RATE);
75
76	error = input_register_device(input);
77	if (error)
 
78		return error;
 
 
 
 
 
 
 
 
 
 
 
79
80	return 0;
81}
82
83static struct platform_driver rb532_button_driver = {
84	.probe = rb532_button_probe,
 
85	.driver = {
86		.name = DRV_NAME,
87	},
88};
89module_platform_driver(rb532_button_driver);
90
91MODULE_AUTHOR("Phil Sutter <n0-1@freewrt.org>");
92MODULE_LICENSE("GPL");
93MODULE_DESCRIPTION("Support for S1 button on Routerboard 532");
94MODULE_ALIAS("platform:" DRV_NAME);
v4.6
 
  1/*
  2 * Support for the S1 button on Routerboard 532
  3 *
  4 * Copyright (C) 2009  Phil Sutter <n0-1@freewrt.org>
  5 */
  6
  7#include <linux/input-polldev.h>
  8#include <linux/module.h>
  9#include <linux/platform_device.h>
 10#include <linux/gpio.h>
 11
 12#include <asm/mach-rc32434/gpio.h>
 13#include <asm/mach-rc32434/rb.h>
 14
 15#define DRV_NAME "rb532-button"
 16
 17#define RB532_BTN_RATE 100 /* msec */
 18#define RB532_BTN_KSYM BTN_0
 19
 20/* The S1 button state is provided by GPIO pin 1. But as this
 21 * pin is also used for uart input as alternate function, the
 22 * operational modes must be switched first:
 23 * 1) disable uart using set_latch_u5()
 24 * 2) turn off alternate function implicitly through
 25 *    gpio_direction_input()
 26 * 3) read the GPIO's current value
 27 * 4) undo step 2 by enabling alternate function (in this
 28 *    mode the GPIO direction is fixed, so no change needed)
 29 * 5) turn on uart again
 30 * The GPIO value occurs to be inverted, so pin high means
 31 * button is not pressed.
 32 */
 33static bool rb532_button_pressed(void)
 34{
 35	int val;
 36
 37	set_latch_u5(0, LO_FOFF);
 38	gpio_direction_input(GPIO_BTN_S1);
 39
 40	val = gpio_get_value(GPIO_BTN_S1);
 41
 42	rb532_gpio_set_func(GPIO_BTN_S1);
 43	set_latch_u5(LO_FOFF, 0);
 44
 45	return !val;
 46}
 47
 48static void rb532_button_poll(struct input_polled_dev *poll_dev)
 49{
 50	input_report_key(poll_dev->input, RB532_BTN_KSYM,
 51			 rb532_button_pressed());
 52	input_sync(poll_dev->input);
 53}
 54
 55static int rb532_button_probe(struct platform_device *pdev)
 56{
 57	struct input_polled_dev *poll_dev;
 58	int error;
 59
 60	poll_dev = input_allocate_polled_device();
 61	if (!poll_dev)
 62		return -ENOMEM;
 63
 64	poll_dev->poll = rb532_button_poll;
 65	poll_dev->poll_interval = RB532_BTN_RATE;
 
 66
 67	poll_dev->input->name = "rb532 button";
 68	poll_dev->input->phys = "rb532/button0";
 69	poll_dev->input->id.bustype = BUS_HOST;
 70	poll_dev->input->dev.parent = &pdev->dev;
 71
 72	dev_set_drvdata(&pdev->dev, poll_dev);
 
 
 73
 74	input_set_capability(poll_dev->input, EV_KEY, RB532_BTN_KSYM);
 75
 76	error = input_register_polled_device(poll_dev);
 77	if (error) {
 78		input_free_polled_device(poll_dev);
 79		return error;
 80	}
 81
 82	return 0;
 83}
 84
 85static int rb532_button_remove(struct platform_device *pdev)
 86{
 87	struct input_polled_dev *poll_dev = dev_get_drvdata(&pdev->dev);
 88
 89	input_unregister_polled_device(poll_dev);
 90	input_free_polled_device(poll_dev);
 91
 92	return 0;
 93}
 94
 95static struct platform_driver rb532_button_driver = {
 96	.probe = rb532_button_probe,
 97	.remove = rb532_button_remove,
 98	.driver = {
 99		.name = DRV_NAME,
100	},
101};
102module_platform_driver(rb532_button_driver);
103
104MODULE_AUTHOR("Phil Sutter <n0-1@freewrt.org>");
105MODULE_LICENSE("GPL");
106MODULE_DESCRIPTION("Support for S1 button on Routerboard 532");
107MODULE_ALIAS("platform:" DRV_NAME);