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

platform/x86: barco-p50-gpio: use software nodes for gpio-leds/keys

In preparation of dropping support for legacy GPIO API from gpio-keys
switch the driver to use software nodes/properties to describe
GPIO-connected LED and button.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Link: https://patch.msgid.link/2meuzip4qnxvle4bwk4hbow4j34ii3cwb46xd5inq5btif5mjg@iiygy6ir7vtr
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

authored by

Dmitry Torokhov and committed by
Ilpo Järvinen
4e0bcbd2 01fd7cf3

+62 -42
+62 -42
drivers/platform/x86/barco-p50-gpio.c
··· 11 11 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 12 12 13 13 #include <linux/delay.h> 14 + #include <linux/dev_printk.h> 14 15 #include <linux/dmi.h> 15 16 #include <linux/err.h> 16 17 #include <linux/io.h> ··· 19 18 #include <linux/leds.h> 20 19 #include <linux/module.h> 21 20 #include <linux/platform_device.h> 22 - #include <linux/gpio_keys.h> 23 21 #include <linux/gpio/driver.h> 24 22 #include <linux/gpio/machine.h> 25 - #include <linux/input.h> 23 + #include <linux/gpio/property.h> 24 + #include <linux/input-event-codes.h> 25 + #include <linux/property.h> 26 26 27 27 28 28 #define DRIVER_NAME "barco-p50-gpio" ··· 80 78 [P50_GPIO_LINE_BTN] = "identify-button", 81 79 }; 82 80 83 - 84 - static struct gpiod_lookup_table p50_gpio_led_table = { 85 - .dev_id = "leds-gpio", 86 - .table = { 87 - GPIO_LOOKUP_IDX(DRIVER_NAME, P50_GPIO_LINE_LED, NULL, 0, GPIO_ACTIVE_HIGH), 88 - {} 89 - } 81 + static const struct software_node gpiochip_node = { 82 + .name = DRIVER_NAME, 90 83 }; 91 84 92 85 /* GPIO LEDs */ 93 - static struct gpio_led leds[] = { 94 - { .name = "identify" } 86 + static const struct software_node gpio_leds_node = { 87 + .name = "gpio-leds-identify", 95 88 }; 96 89 97 - static struct gpio_led_platform_data leds_pdata = { 98 - .num_leds = ARRAY_SIZE(leds), 99 - .leds = leds, 90 + static const struct property_entry identify_led_props[] = { 91 + PROPERTY_ENTRY_GPIO("gpios", &gpiochip_node, P50_GPIO_LINE_LED, GPIO_ACTIVE_HIGH), 92 + { } 93 + }; 94 + 95 + static const struct software_node identify_led_node = { 96 + .parent = &gpio_leds_node, 97 + .name = "identify", 98 + .properties = identify_led_props, 100 99 }; 101 100 102 101 /* GPIO keyboard */ 103 - static struct gpio_keys_button buttons[] = { 104 - { 105 - .code = KEY_VENDOR, 106 - .gpio = P50_GPIO_LINE_BTN, 107 - .active_low = 1, 108 - .type = EV_KEY, 109 - .value = 1, 110 - }, 102 + static const struct property_entry gpio_keys_props[] = { 103 + PROPERTY_ENTRY_STRING("label", "identify"), 104 + PROPERTY_ENTRY_U32("poll-interval", 100), 105 + { } 111 106 }; 112 107 113 - static struct gpio_keys_platform_data keys_pdata = { 114 - .buttons = buttons, 115 - .nbuttons = ARRAY_SIZE(buttons), 116 - .poll_interval = 100, 117 - .rep = 0, 118 - .name = "identify", 108 + static const struct software_node gpio_keys_node = { 109 + .name = "gpio-keys-identify", 110 + .properties = gpio_keys_props, 119 111 }; 120 112 113 + static struct property_entry vendor_key_props[] = { 114 + PROPERTY_ENTRY_U32("linux,code", KEY_VENDOR), 115 + PROPERTY_ENTRY_GPIO("gpios", &gpiochip_node, P50_GPIO_LINE_BTN, GPIO_ACTIVE_LOW), 116 + { } 117 + }; 118 + 119 + static const struct software_node vendor_key_node = { 120 + .parent = &gpio_keys_node, 121 + .properties = vendor_key_props, 122 + }; 123 + 124 + static const struct software_node *p50_swnodes[] = { 125 + &gpiochip_node, 126 + &gpio_leds_node, 127 + &identify_led_node, 128 + &gpio_keys_node, 129 + &vendor_key_node, 130 + NULL 131 + }; 121 132 122 133 /* low level access routines */ 123 134 ··· 300 285 301 286 static int p50_gpio_probe(struct platform_device *pdev) 302 287 { 288 + struct platform_device_info key_info = { 289 + .name = "gpio-keys-polled", 290 + .id = PLATFORM_DEVID_NONE, 291 + .parent = &pdev->dev, 292 + }; 293 + struct platform_device_info led_info = { 294 + .name = "leds-gpio", 295 + .id = PLATFORM_DEVID_NONE, 296 + .parent = &pdev->dev, 297 + }; 303 298 struct p50_gpio *p50; 304 299 struct resource *res; 305 300 int ret; ··· 364 339 return ret; 365 340 } 366 341 367 - gpiod_add_lookup_table(&p50_gpio_led_table); 342 + ret = software_node_register_node_group(p50_swnodes); 343 + if (ret) 344 + return dev_err_probe(&pdev->dev, ret, "failed to register software nodes"); 368 345 369 - p50->leds_pdev = platform_device_register_data(&pdev->dev, 370 - "leds-gpio", PLATFORM_DEVID_NONE, &leds_pdata, sizeof(leds_pdata)); 371 - 346 + led_info.fwnode = software_node_fwnode(&gpio_leds_node); 347 + p50->leds_pdev = platform_device_register_full(&led_info); 372 348 if (IS_ERR(p50->leds_pdev)) { 373 349 ret = PTR_ERR(p50->leds_pdev); 374 350 dev_err(&pdev->dev, "Could not register leds-gpio: %d\n", ret); 375 351 goto err_leds; 376 352 } 377 353 378 - /* gpio-keys-polled uses old-style gpio interface, pass the right identifier */ 379 - buttons[0].gpio += p50->gc.base; 380 - 381 - p50->keys_pdev = 382 - platform_device_register_data(&pdev->dev, "gpio-keys-polled", 383 - PLATFORM_DEVID_NONE, 384 - &keys_pdata, sizeof(keys_pdata)); 385 - 354 + key_info.fwnode = software_node_fwnode(&gpio_keys_node); 355 + p50->keys_pdev = platform_device_register_full(&key_info); 386 356 if (IS_ERR(p50->keys_pdev)) { 387 357 ret = PTR_ERR(p50->keys_pdev); 388 358 dev_err(&pdev->dev, "Could not register gpio-keys-polled: %d\n", ret); ··· 389 369 err_keys: 390 370 platform_device_unregister(p50->leds_pdev); 391 371 err_leds: 392 - gpiod_remove_lookup_table(&p50_gpio_led_table); 372 + software_node_unregister_node_group(p50_swnodes); 393 373 394 374 return ret; 395 375 } ··· 401 381 platform_device_unregister(p50->keys_pdev); 402 382 platform_device_unregister(p50->leds_pdev); 403 383 404 - gpiod_remove_lookup_table(&p50_gpio_led_table); 384 + software_node_unregister_node_group(p50_swnodes); 405 385 } 406 386 407 387 static struct platform_driver p50_gpio_driver = {