* [PATCH 1/2] MIPS: rb532: prepare board support for rb532-button
[not found] <1232651528-19870-1-git-send-email-n0-1@freewrt.org>
@ 2009-01-22 19:12 ` Phil Sutter
[not found] ` <1232651528-19870-2-git-send-email-n0-1@freewrt.org>
1 sibling, 0 replies; 4+ messages in thread
From: Phil Sutter @ 2009-01-22 19:12 UTC (permalink / raw)
To: Dmitry Torokhov; +Cc: linux-input, Ralf Baechle, linux-mips, Florian Fainelli
Add a macro containing the S1 button GPIO pin index, as done for NAND
and CompactFlash GPIO pins. Also remove gpio-keys specific device code
and rename the button device to mach it's driver.
Signed-off-by: Phil Sutter <n0-1@freewrt.org>
---
arch/mips/include/asm/mach-rc32434/gpio.h | 3 +++
arch/mips/rb532/devices.c | 19 +------------------
2 files changed, 4 insertions(+), 18 deletions(-)
diff --git a/arch/mips/include/asm/mach-rc32434/gpio.h b/arch/mips/include/asm/mach-rc32434/gpio.h
index 3cb50d1..12ee8d5 100644
--- a/arch/mips/include/asm/mach-rc32434/gpio.h
+++ b/arch/mips/include/asm/mach-rc32434/gpio.h
@@ -80,6 +80,9 @@ struct rb532_gpio_reg {
/* Compact Flash GPIO pin */
#define CF_GPIO_NUM 13
+/* S1 button GPIO (shared with UART0_SIN) */
+#define GPIO_BTN_S1 1
+
extern void rb532_gpio_set_ilevel(int bit, unsigned gpio);
extern void rb532_gpio_set_istat(int bit, unsigned gpio);
extern void rb532_gpio_set_func(unsigned gpio);
diff --git a/arch/mips/rb532/devices.c b/arch/mips/rb532/devices.c
index 4a5f05b..7b585de 100644
--- a/arch/mips/rb532/devices.c
+++ b/arch/mips/rb532/devices.c
@@ -200,26 +200,9 @@ static struct platform_device rb532_led = {
.id = -1,
};
-static struct gpio_keys_button rb532_gpio_btn[] = {
- {
- .gpio = 1,
- .code = BTN_0,
- .desc = "S1",
- .active_low = 1,
- }
-};
-
-static struct gpio_keys_platform_data rb532_gpio_btn_data = {
- .buttons = rb532_gpio_btn,
- .nbuttons = ARRAY_SIZE(rb532_gpio_btn),
-};
-
static struct platform_device rb532_button = {
- .name = "gpio-keys",
+ .name = "rb532-button",
.id = -1,
- .dev = {
- .platform_data = &rb532_gpio_btn_data,
- }
};
static struct resource rb532_wdt_res[] = {
--
1.5.6.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] input: add driver for S1 button of rb532
[not found] ` <1232651528-19870-2-git-send-email-n0-1@freewrt.org>
@ 2009-01-22 19:12 ` Phil Sutter
2009-01-24 8:34 ` Geert Uytterhoeven
0 siblings, 1 reply; 4+ messages in thread
From: Phil Sutter @ 2009-01-22 19:12 UTC (permalink / raw)
To: Dmitry Torokhov; +Cc: linux-input, Ralf Baechle, linux-mips, Florian Fainelli
Mikrotik's Routerboard 532 has two builtin buttons, from which one
triggers a hardware reset. The other one is accessible through GPIO pin
1. Sadly, this pin is being multiplexed with UART0 input, so enabling it
as interrupt source (as implied by the gpio-keys driver) is not possible
unless UART0 has been turned off. The later one though is a rather bad
idea as the Routerboard is an embedded device with only a single serial
port, so it's almost always used as serial console device.
This patch adds a driver based on INPUT_POLLDEV, which disables the UART
and reconfigures GPIO pin 1 temporarily while reading the button state.
This procedure works fine and has been tested as part of another,
unpublished driver for this device.
Signed-off-by: Phil Sutter <n0-1@freewrt.org>
---
drivers/input/misc/Kconfig | 8 +++
drivers/input/misc/Makefile | 1 +
drivers/input/misc/rb532_button.c | 111 +++++++++++++++++++++++++++++++++++++
3 files changed, 120 insertions(+), 0 deletions(-)
create mode 100644 drivers/input/misc/rb532_button.c
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 67e5553..9666462 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -227,4 +227,12 @@ config INPUT_PCF50633_PMU
Say Y to include support for delivering PMU events via input
layer on NXP PCF50633.
+config INPUT_RB532_BUTTON
+ tristate "Mikrotik Routerboard 532 button interface"
+ depends on MIKROTIK_RB532
+ select INPUT_POLLDEV
+ help
+ Say Y here if you want support for the S1 button built into
+ Mikrotik's Routerboard 532.
+
endif
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index bb62e6e..0bb6a0e 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -22,3 +22,4 @@ obj-$(CONFIG_INPUT_UINPUT) += uinput.o
obj-$(CONFIG_INPUT_APANEL) += apanel.o
obj-$(CONFIG_INPUT_SGI_BTNS) += sgi_btns.o
obj-$(CONFIG_INPUT_PCF50633_PMU) += pcf50633-input.o
+obj-$(CONFIG_INPUT_RB532_BUTTON) += rb532_button.o
diff --git a/drivers/input/misc/rb532_button.c b/drivers/input/misc/rb532_button.c
new file mode 100644
index 0000000..05f2f49
--- /dev/null
+++ b/drivers/input/misc/rb532_button.c
@@ -0,0 +1,111 @@
+/*
+ * Support for the S1 button on Routerboard 532
+ *
+ * Copyright (C) 2009 Phil Sutter <n0-1@freewrt.org>
+ */
+
+#include <linux/input-polldev.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+
+#include <asm/mach-rc32434/gpio.h>
+#include <asm/mach-rc32434/rb.h>
+
+#define DRV_NAME "rb532-button"
+
+#define RB532_BTN_RATE 100 /* msec */
+#define RB532_BTN_KSYM BTN_0
+
+/* The S1 button state is provided by GPIO pin 1. But as this
+ * pin is also used for uart input as alternate function, the
+ * operational modes must be switched first:
+ * 1) disable uart using set_latch_u5()
+ * 2) turn off alternate function implicitly through
+ * gpio_direction_input()
+ * 3) read the GPIO's current value
+ * 4) undo step 2 by enabling alternate function (in this
+ * mode the GPIO direction is fixed, so no change needed)
+ * 5) turn on uart again
+ * The GPIO value occurs to be inverted, so pin high means
+ * button is not pressed.
+ */
+static bool rb532_button_pressed(void) {
+ int val;
+
+ set_latch_u5(0, LO_FOFF);
+ gpio_direction_input(GPIO_BTN_S1);
+
+ val = gpio_get_value(GPIO_BTN_S1);
+
+ rb532_gpio_set_func(GPIO_BTN_S1);
+ set_latch_u5(LO_FOFF, 0);
+
+ return !val;
+}
+
+static void rb532_button_poll(struct input_polled_dev *poll_dev)
+{
+ input_report_key(poll_dev->input, RB532_BTN_KSYM,
+ rb532_button_pressed());
+ input_sync(poll_dev->input);
+}
+
+static int __devinit rb532_button_probe(struct platform_device *pdev)
+{
+ struct input_polled_dev *poll_dev;
+
+ poll_dev = input_allocate_polled_device();
+ if (!poll_dev)
+ return -ENOMEM;
+
+ poll_dev->poll = rb532_button_poll;
+ poll_dev->poll_interval = RB532_BTN_RATE;
+
+ poll_dev->input->name = "rb532 button";
+ poll_dev->input->phys = "rb532/button0";
+ poll_dev->input->id.bustype = BUS_HOST;
+ poll_dev->input->dev.parent = &pdev->dev;
+
+ dev_set_drvdata(&pdev->dev, poll_dev);
+
+ input_set_capability(poll_dev->input, EV_KEY, RB532_BTN_KSYM);
+
+ return input_register_polled_device(poll_dev);
+}
+
+static int __devexit rb532_button_remove(struct platform_device *pdev)
+{
+ struct input_polled_dev *poll_dev = dev_get_drvdata(&pdev->dev);
+
+ input_unregister_polled_device(poll_dev);
+ input_free_polled_device(poll_dev);
+ dev_set_drvdata(&pdev->dev, NULL);
+
+ return 0;
+}
+
+static struct platform_driver rb532_button_driver = {
+ .probe = rb532_button_probe,
+ .remove = __devexit_p(rb532_button_remove),
+ .driver = {
+ .name = DRV_NAME,
+ .owner = THIS_MODULE,
+ },
+};
+
+static int __init rb532_button_init(void)
+{
+ return platform_driver_register(&rb532_button_driver);
+}
+
+static void __exit rb532_button_exit(void)
+{
+ platform_driver_unregister(&rb532_button_driver);
+}
+
+module_init(rb532_button_init);
+module_exit(rb532_button_exit);
+
+MODULE_AUTHOR("Phil Sutter <n0-1@freewrt.org>");
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Support for S1 button on Routerboard 532");
--
1.5.6.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] input: add driver for S1 button of rb532
2009-01-22 19:12 ` [PATCH 2/2] input: add driver for S1 button of rb532 Phil Sutter
@ 2009-01-24 8:34 ` Geert Uytterhoeven
2009-01-24 14:20 ` Phil Sutter
0 siblings, 1 reply; 4+ messages in thread
From: Geert Uytterhoeven @ 2009-01-24 8:34 UTC (permalink / raw)
To: Phil Sutter
Cc: Dmitry Torokhov, linux-input, Ralf Baechle, linux-mips,
Florian Fainelli
On Thu, 22 Jan 2009, Phil Sutter wrote:
> Mikrotik's Routerboard 532 has two builtin buttons, from which one
> triggers a hardware reset. The other one is accessible through GPIO pin
> 1. Sadly, this pin is being multiplexed with UART0 input, so enabling it
> as interrupt source (as implied by the gpio-keys driver) is not possible
> unless UART0 has been turned off. The later one though is a rather bad
> idea as the Routerboard is an embedded device with only a single serial
> port, so it's almost always used as serial console device.
>
> This patch adds a driver based on INPUT_POLLDEV, which disables the UART
> and reconfigures GPIO pin 1 temporarily while reading the button state.
> This procedure works fine and has been tested as part of another,
> unpublished driver for this device.
What happens when you receive UART input while the UART is disabled? Is it
lost?
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] input: add driver for S1 button of rb532
2009-01-24 8:34 ` Geert Uytterhoeven
@ 2009-01-24 14:20 ` Phil Sutter
0 siblings, 0 replies; 4+ messages in thread
From: Phil Sutter @ 2009-01-24 14:20 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Dmitry Torokhov, linux-input, Ralf Baechle, linux-mips,
Florian Fainelli
Hi,
On Sat, Jan 24, 2009 at 09:34:43AM +0100, Geert Uytterhoeven wrote:
> What happens when you receive UART input while the UART is disabled? Is it
> lost?
Yes, the input is lost, as well as any output sent by the device while
UART0 is disabled. I've tested this adding a msleep() of 5s in between
the calls to set_latch_u5() and increasing the delay between polls to
10s.
I've tried to reproduce this behaviour without the changes from above
using a loop flooding the output of the serial console with increasing
numbers, with somehow strange results. Instead of missing some output,
occasionally the log shows additional characters (some non-printable).
Also (seldomly) digits are replaced by other chars (also not necesarily
printable).
So I can at least assume the two drivers interfere with each other,
which could lead to bad results when using the UART for more advanced
stuff. Although it may be possible to introduce some kind of locking for
the serial output, I doubt this can be done with the input part, as the
device is turned off while polling so data shouldn't even reach the device.
Any ideas?
Greetings, Phil
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-01-24 14:17 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1232651528-19870-1-git-send-email-n0-1@freewrt.org>
2009-01-22 19:12 ` [PATCH 1/2] MIPS: rb532: prepare board support for rb532-button Phil Sutter
[not found] ` <1232651528-19870-2-git-send-email-n0-1@freewrt.org>
2009-01-22 19:12 ` [PATCH 2/2] input: add driver for S1 button of rb532 Phil Sutter
2009-01-24 8:34 ` Geert Uytterhoeven
2009-01-24 14:20 ` Phil Sutter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).