Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 143148
b: refs/heads/master
c: d9bdffd
h: refs/heads/master
v: v3
  • Loading branch information
Phil Sutter authored and Dmitry Torokhov committed Mar 10, 2009
1 parent 2469724 commit 9412430
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 19 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 73969ff0eda233f140bcbed1251431387b43f383
refs/heads/master: d9bdffd2102404e8ea5f71c5b88dad890984164d
3 changes: 3 additions & 0 deletions trunk/arch/mips/include/asm/mach-rc32434/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 1 addition & 18 deletions trunk/arch/mips/rb532/devices.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
Expand Down
12 changes: 12 additions & 0 deletions trunk/drivers/input/misc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,16 @@ config INPUT_GPIO_ROTARY_ENCODER
To compile this driver as a module, choose M here: the
module will be called rotary_encoder.

config INPUT_RB532_BUTTON
tristate "Mikrotik Routerboard 532 button interface"
depends on MIKROTIK_RB532
depends on GPIOLIB && GENERIC_GPIO
select INPUT_POLLDEV
help
Say Y here if you want support for the S1 button built into
Mikrotik's Routerboard 532.

To compile this driver as a module, choose M here: the
module will be called rb532_button.

endif
1 change: 1 addition & 0 deletions trunk/drivers/input/misc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ 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_GPIO_ROTARY_ENCODER) += rotary_encoder.o
obj-$(CONFIG_INPUT_RB532_BUTTON) += rb532_button.o

120 changes: 120 additions & 0 deletions trunk/drivers/input/misc/rb532_button.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
* 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;
int error;

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);

error = input_register_polled_device(poll_dev);
if (error) {
input_free_polled_device(poll_dev);
return error;
}

return 0;
}

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");
MODULE_ALIAS("platform:" DRV_NAME);

0 comments on commit 9412430

Please sign in to comment.