Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

MIPS/input: Move RB532 button to GPIO descriptors

Convert the Mikrotik RouterBoard RB532 to use GPIO descriptors
by defining a software node for the GPIO chip, then register
the button platform device with full info passing the GPIO
as a device property.

This can be used as a base to move more of the RB532 devices
over to passing GPIOs using device properties.

Use the GPIO_ACTIVE_LOW flag and drop the inversion in the
rb532_button_pressed() function.

Signed-off-by: Linus Walleij <linusw@kernel.org>
Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>

authored by

Linus Walleij and committed by
Thomas Bogendoerfer
42671e9c f992846d

+69 -13
+40 -7
arch/mips/rb532/devices.c
··· 16 16 #include <linux/mtd/mtd.h> 17 17 #include <linux/gpio.h> 18 18 #include <linux/gpio/machine.h> 19 + #include <linux/gpio/property.h> 19 20 #include <linux/gpio_keys.h> 20 21 #include <linux/input.h> 22 + #include <linux/property.h> 21 23 #include <linux/serial_8250.h> 22 24 23 25 #include <asm/bootinfo.h> ··· 39 37 extern unsigned int idt_cpu_freq; 40 38 41 39 static struct mpmc_device dev3; 40 + 41 + static const struct software_node rb532_gpio0_node = { 42 + .name = "gpio0", 43 + }; 42 44 43 45 void set_latch_u5(unsigned char or_mask, unsigned char nand_mask) 44 46 { ··· 195 189 .id = -1, 196 190 }; 197 191 198 - static struct platform_device rb532_button = { 199 - .name = "rb532-button", 200 - .id = -1, 201 - }; 202 - 203 192 static struct resource rb532_wdt_res[] = { 204 193 { 205 194 .name = "rb532_wdt_res", ··· 237 236 &nand_slot0, 238 237 &cf_slot0, 239 238 &rb532_led, 240 - &rb532_button, 241 239 &rb532_uart, 242 240 &rb532_wdt 243 241 }; 242 + 243 + static const struct property_entry rb532_button_properties[] = { 244 + PROPERTY_ENTRY_GPIO("button-gpios", &rb532_gpio0_node, 245 + GPIO_BTN_S1, GPIO_ACTIVE_LOW), 246 + { } 247 + }; 248 + 249 + static const struct platform_device_info rb532_button_info __initconst = { 250 + .name = "rb532-button", 251 + .id = PLATFORM_DEVID_NONE, 252 + .properties = rb532_button_properties, 253 + }; 254 + 244 255 245 256 /* NAND definitions */ 246 257 #define NAND_CHIP_DELAY 25 ··· 280 267 281 268 static int __init plat_setup_devices(void) 282 269 { 270 + struct platform_device *pd; 271 + int ret; 272 + 283 273 /* Look for the CF card reader */ 284 274 if (!readl(IDT434_REG_BASE + DEV1MASK)) 285 275 rb532_devs[2] = NULL; /* disable cf_slot0 at index 2 */ ··· 311 295 rb532_uart_res[0].uartclk = idt_cpu_freq; 312 296 313 297 gpiod_add_lookup_table(&cf_slot0_gpio_table); 314 - return platform_add_devices(rb532_devs, ARRAY_SIZE(rb532_devs)); 298 + ret = platform_add_devices(rb532_devs, ARRAY_SIZE(rb532_devs)); 299 + if (ret) 300 + return ret; 301 + 302 + /* 303 + * Stack devices using full info and properties here, after we 304 + * register the node for the GPIO chip. 305 + */ 306 + software_node_register(&rb532_gpio0_node); 307 + 308 + pd = platform_device_register_full(&rb532_button_info); 309 + ret = PTR_ERR_OR_ZERO(pd); 310 + if (ret) { 311 + pr_err("failed to create RB532 button device: %d\n", ret); 312 + return ret; 313 + } 314 + 315 + return 0; 315 316 } 316 317 317 318 #ifdef CONFIG_NET
+29 -6
drivers/input/misc/rb532_button.c
··· 8 8 #include <linux/input.h> 9 9 #include <linux/module.h> 10 10 #include <linux/platform_device.h> 11 - #include <linux/gpio.h> 11 + #include <linux/gpio/consumer.h> 12 12 13 13 #include <asm/mach-rc32434/gpio.h> 14 14 #include <asm/mach-rc32434/rb.h> ··· 17 17 18 18 #define RB532_BTN_RATE 100 /* msec */ 19 19 #define RB532_BTN_KSYM BTN_0 20 + 21 + /** 22 + * struct rb532_button - RB532 button information 23 + * @gpio: GPIO connected to the button 24 + */ 25 + struct rb532_button { 26 + struct gpio_desc *gpio; 27 + }; 20 28 21 29 /* The S1 button state is provided by GPIO pin 1. But as this 22 30 * pin is also used for uart input as alternate function, the ··· 39 31 * The GPIO value occurs to be inverted, so pin high means 40 32 * button is not pressed. 41 33 */ 42 - static bool rb532_button_pressed(void) 34 + static bool rb532_button_pressed(struct rb532_button *button) 43 35 { 44 36 int val; 45 37 46 38 set_latch_u5(0, LO_FOFF); 47 - gpio_direction_input(GPIO_BTN_S1); 39 + gpiod_direction_input(button->gpio); 48 40 49 - val = gpio_get_value(GPIO_BTN_S1); 41 + val = gpiod_get_value(button->gpio); 50 42 51 43 rb532_gpio_set_func(GPIO_BTN_S1); 52 44 set_latch_u5(LO_FOFF, 0); 53 45 54 - return !val; 46 + return val; 55 47 } 56 48 57 49 static void rb532_button_poll(struct input_dev *input) 58 50 { 59 - input_report_key(input, RB532_BTN_KSYM, rb532_button_pressed()); 51 + struct rb532_button *button = input_get_drvdata(input); 52 + 53 + input_report_key(input, RB532_BTN_KSYM, rb532_button_pressed(button)); 60 54 input_sync(input); 61 55 } 62 56 63 57 static int rb532_button_probe(struct platform_device *pdev) 64 58 { 59 + struct rb532_button *button; 65 60 struct input_dev *input; 66 61 int error; 62 + 63 + button = devm_kzalloc(&pdev->dev, sizeof(*button), GFP_KERNEL); 64 + if (!button) 65 + return -ENOMEM; 66 + 67 + button->gpio = devm_gpiod_get(&pdev->dev, "button", GPIOD_IN); 68 + if (IS_ERR(button->gpio)) 69 + return dev_err_probe(&pdev->dev, PTR_ERR(button->gpio), 70 + "error getting button GPIO\n"); 67 71 68 72 input = devm_input_allocate_device(&pdev->dev); 69 73 if (!input) 70 74 return -ENOMEM; 75 + input_set_drvdata(input, button); 71 76 72 77 input->name = "rb532 button"; 73 78 input->phys = "rb532/button0"; ··· 97 76 error = input_register_device(input); 98 77 if (error) 99 78 return error; 79 + 80 + platform_set_drvdata(pdev, button); 100 81 101 82 return 0; 102 83 }