Skip to content

Commit 4e0bcbd

Browse files
dtorij-intel
authored andcommitted
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>
1 parent 01fd7cf commit 4e0bcbd

1 file changed

Lines changed: 62 additions & 42 deletions

File tree

drivers/platform/x86/barco-p50-gpio.c

Lines changed: 62 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,19 @@
1111
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
1212

1313
#include <linux/delay.h>
14+
#include <linux/dev_printk.h>
1415
#include <linux/dmi.h>
1516
#include <linux/err.h>
1617
#include <linux/io.h>
1718
#include <linux/kernel.h>
1819
#include <linux/leds.h>
1920
#include <linux/module.h>
2021
#include <linux/platform_device.h>
21-
#include <linux/gpio_keys.h>
2222
#include <linux/gpio/driver.h>
2323
#include <linux/gpio/machine.h>
24-
#include <linux/input.h>
24+
#include <linux/gpio/property.h>
25+
#include <linux/input-event-codes.h>
26+
#include <linux/property.h>
2527

2628

2729
#define DRIVER_NAME "barco-p50-gpio"
@@ -78,44 +80,57 @@ static const char * const gpio_names[] = {
7880
[P50_GPIO_LINE_BTN] = "identify-button",
7981
};
8082

81-
82-
static struct gpiod_lookup_table p50_gpio_led_table = {
83-
.dev_id = "leds-gpio",
84-
.table = {
85-
GPIO_LOOKUP_IDX(DRIVER_NAME, P50_GPIO_LINE_LED, NULL, 0, GPIO_ACTIVE_HIGH),
86-
{}
87-
}
83+
static const struct software_node gpiochip_node = {
84+
.name = DRIVER_NAME,
8885
};
8986

9087
/* GPIO LEDs */
91-
static struct gpio_led leds[] = {
92-
{ .name = "identify" }
88+
static const struct software_node gpio_leds_node = {
89+
.name = "gpio-leds-identify",
9390
};
9491

95-
static struct gpio_led_platform_data leds_pdata = {
96-
.num_leds = ARRAY_SIZE(leds),
97-
.leds = leds,
92+
static const struct property_entry identify_led_props[] = {
93+
PROPERTY_ENTRY_GPIO("gpios", &gpiochip_node, P50_GPIO_LINE_LED, GPIO_ACTIVE_HIGH),
94+
{ }
95+
};
96+
97+
static const struct software_node identify_led_node = {
98+
.parent = &gpio_leds_node,
99+
.name = "identify",
100+
.properties = identify_led_props,
98101
};
99102

100103
/* GPIO keyboard */
101-
static struct gpio_keys_button buttons[] = {
102-
{
103-
.code = KEY_VENDOR,
104-
.gpio = P50_GPIO_LINE_BTN,
105-
.active_low = 1,
106-
.type = EV_KEY,
107-
.value = 1,
108-
},
104+
static const struct property_entry gpio_keys_props[] = {
105+
PROPERTY_ENTRY_STRING("label", "identify"),
106+
PROPERTY_ENTRY_U32("poll-interval", 100),
107+
{ }
109108
};
110109

111-
static struct gpio_keys_platform_data keys_pdata = {
112-
.buttons = buttons,
113-
.nbuttons = ARRAY_SIZE(buttons),
114-
.poll_interval = 100,
115-
.rep = 0,
116-
.name = "identify",
110+
static const struct software_node gpio_keys_node = {
111+
.name = "gpio-keys-identify",
112+
.properties = gpio_keys_props,
117113
};
118114

115+
static struct property_entry vendor_key_props[] = {
116+
PROPERTY_ENTRY_U32("linux,code", KEY_VENDOR),
117+
PROPERTY_ENTRY_GPIO("gpios", &gpiochip_node, P50_GPIO_LINE_BTN, GPIO_ACTIVE_LOW),
118+
{ }
119+
};
120+
121+
static const struct software_node vendor_key_node = {
122+
.parent = &gpio_keys_node,
123+
.properties = vendor_key_props,
124+
};
125+
126+
static const struct software_node *p50_swnodes[] = {
127+
&gpiochip_node,
128+
&gpio_leds_node,
129+
&identify_led_node,
130+
&gpio_keys_node,
131+
&vendor_key_node,
132+
NULL
133+
};
119134

120135
/* low level access routines */
121136

@@ -285,6 +300,16 @@ static int p50_gpio_set(struct gpio_chip *gc, unsigned int offset, int value)
285300

286301
static int p50_gpio_probe(struct platform_device *pdev)
287302
{
303+
struct platform_device_info key_info = {
304+
.name = "gpio-keys-polled",
305+
.id = PLATFORM_DEVID_NONE,
306+
.parent = &pdev->dev,
307+
};
308+
struct platform_device_info led_info = {
309+
.name = "leds-gpio",
310+
.id = PLATFORM_DEVID_NONE,
311+
.parent = &pdev->dev,
312+
};
288313
struct p50_gpio *p50;
289314
struct resource *res;
290315
int ret;
@@ -339,25 +364,20 @@ static int p50_gpio_probe(struct platform_device *pdev)
339364
return ret;
340365
}
341366

342-
gpiod_add_lookup_table(&p50_gpio_led_table);
343-
344-
p50->leds_pdev = platform_device_register_data(&pdev->dev,
345-
"leds-gpio", PLATFORM_DEVID_NONE, &leds_pdata, sizeof(leds_pdata));
367+
ret = software_node_register_node_group(p50_swnodes);
368+
if (ret)
369+
return dev_err_probe(&pdev->dev, ret, "failed to register software nodes");
346370

371+
led_info.fwnode = software_node_fwnode(&gpio_leds_node);
372+
p50->leds_pdev = platform_device_register_full(&led_info);
347373
if (IS_ERR(p50->leds_pdev)) {
348374
ret = PTR_ERR(p50->leds_pdev);
349375
dev_err(&pdev->dev, "Could not register leds-gpio: %d\n", ret);
350376
goto err_leds;
351377
}
352378

353-
/* gpio-keys-polled uses old-style gpio interface, pass the right identifier */
354-
buttons[0].gpio += p50->gc.base;
355-
356-
p50->keys_pdev =
357-
platform_device_register_data(&pdev->dev, "gpio-keys-polled",
358-
PLATFORM_DEVID_NONE,
359-
&keys_pdata, sizeof(keys_pdata));
360-
379+
key_info.fwnode = software_node_fwnode(&gpio_keys_node);
380+
p50->keys_pdev = platform_device_register_full(&key_info);
361381
if (IS_ERR(p50->keys_pdev)) {
362382
ret = PTR_ERR(p50->keys_pdev);
363383
dev_err(&pdev->dev, "Could not register gpio-keys-polled: %d\n", ret);
@@ -369,7 +389,7 @@ static int p50_gpio_probe(struct platform_device *pdev)
369389
err_keys:
370390
platform_device_unregister(p50->leds_pdev);
371391
err_leds:
372-
gpiod_remove_lookup_table(&p50_gpio_led_table);
392+
software_node_unregister_node_group(p50_swnodes);
373393

374394
return ret;
375395
}
@@ -381,7 +401,7 @@ static void p50_gpio_remove(struct platform_device *pdev)
381401
platform_device_unregister(p50->keys_pdev);
382402
platform_device_unregister(p50->leds_pdev);
383403

384-
gpiod_remove_lookup_table(&p50_gpio_led_table);
404+
software_node_unregister_node_group(p50_swnodes);
385405
}
386406

387407
static struct platform_driver p50_gpio_driver = {

0 commit comments

Comments
 (0)