Skip to content

Commit 4ebb6c9

Browse files
dtortsbogend
authored andcommitted
MIPS: alchemy: mtx1: switch to static device properties
Convert GPIO-connected buttons and LEDs on MTX1 board to software nodes/properties, so that support for platform data can be removed from gpio-keys driver (which will rely purely on generic device properties for configuration). Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
1 parent 5850847 commit 4ebb6c9

1 file changed

Lines changed: 124 additions & 57 deletions

File tree

arch/mips/alchemy/board-mtx1.c

Lines changed: 124 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99
#include <linux/interrupt.h>
1010
#include <linux/kernel.h>
1111
#include <linux/platform_device.h>
12-
#include <linux/leds.h>
13-
#include <linux/gpio.h>
1412
#include <linux/gpio/machine.h>
15-
#include <linux/gpio_keys.h>
13+
#include <linux/gpio/property.h>
1614
#include <linux/input.h>
1715
#include <linux/mtd/partitions.h>
1816
#include <linux/mtd/physmap.h>
@@ -80,64 +78,134 @@ void __init board_setup(void)
8078

8179
/******************************************************************************/
8280

83-
static struct gpio_keys_button mtx1_gpio_button[] = {
84-
{
85-
.gpio = 207,
86-
.code = BTN_0,
87-
.desc = "System button",
88-
}
81+
static const struct software_node mtx1_gpiochip_node = {
82+
.name = "alchemy-gpio2",
8983
};
9084

91-
static struct gpio_keys_platform_data mtx1_buttons_data = {
92-
.buttons = mtx1_gpio_button,
93-
.nbuttons = ARRAY_SIZE(mtx1_gpio_button),
85+
static const struct software_node mtx1_gpio_keys_node = {
86+
.name = "mtx1-gpio-keys",
9487
};
9588

96-
static struct platform_device mtx1_button = {
97-
.name = "gpio-keys",
98-
.id = -1,
99-
.dev = {
100-
.platform_data = &mtx1_buttons_data,
101-
}
89+
static const struct property_entry mtx1_button_props[] = {
90+
PROPERTY_ENTRY_U32("linux,code", BTN_0),
91+
PROPERTY_ENTRY_GPIO("gpios", &mtx1_gpiochip_node, 7, GPIO_ACTIVE_HIGH),
92+
PROPERTY_ENTRY_STRING("label", "System button"),
93+
{ }
10294
};
10395

104-
static struct gpiod_lookup_table mtx1_wdt_gpio_table = {
105-
.dev_id = "mtx1-wdt.0",
106-
.table = {
107-
/* Global number 215 is offset 15 on Alchemy GPIO 2 */
108-
GPIO_LOOKUP("alchemy-gpio2", 15, NULL, GPIO_ACTIVE_HIGH),
109-
{ },
110-
},
96+
static const struct software_node mtx1_button_node = {
97+
.parent = &mtx1_gpio_keys_node,
98+
.properties = mtx1_button_props,
99+
};
100+
101+
static const struct software_node *mtx1_gpio_keys_swnodes[] __initconst = {
102+
&mtx1_gpio_keys_node,
103+
&mtx1_button_node,
104+
NULL
111105
};
112106

113-
static struct platform_device mtx1_wdt = {
107+
static void __init mtx1_keys_init(void)
108+
{
109+
struct platform_device_info keys_info = {
110+
.name = "gpio-keys",
111+
.id = PLATFORM_DEVID_NONE,
112+
};
113+
struct platform_device *pd;
114+
int err;
115+
116+
err = software_node_register_node_group(mtx1_gpio_keys_swnodes);
117+
if (err) {
118+
pr_err("failed to register gpio-keys software nodes: %d\n", err);
119+
return;
120+
}
121+
122+
keys_info.fwnode = software_node_fwnode(&mtx1_gpio_keys_node);
123+
124+
pd = platform_device_register_full(&keys_info);
125+
err = PTR_ERR_OR_ZERO(pd);
126+
if (err)
127+
pr_err("failed to create gpio-keys device: %d\n", err);
128+
}
129+
130+
/* Global number 215 is offset 15 on Alchemy GPIO 2 */
131+
static const struct property_entry mtx1_wdt_props[] = {
132+
PROPERTY_ENTRY_GPIO("gpios", &mtx1_gpiochip_node, 15, GPIO_ACTIVE_HIGH),
133+
{ }
134+
};
135+
136+
static struct platform_device_info mtx1_wdt_info __initconst = {
114137
.name = "mtx1-wdt",
115138
.id = 0,
139+
.properties = mtx1_wdt_props,
116140
};
117141

118-
static const struct gpio_led default_leds[] = {
119-
{
120-
.name = "mtx1:green",
121-
.gpio = 211,
122-
}, {
123-
.name = "mtx1:red",
124-
.gpio = 212,
125-
},
142+
static void __init mtx1_wdt_init(void)
143+
{
144+
struct platform_device *pd;
145+
int err;
146+
147+
pd = platform_device_register_full(&mtx1_wdt_info);
148+
err = PTR_ERR_OR_ZERO(pd);
149+
if (err)
150+
pr_err("failed to create gpio-keys device: %d\n", err);
151+
}
152+
153+
static const struct software_node mtx1_gpio_leds_node = {
154+
.name = "mtx1-leds",
126155
};
127156

128-
static struct gpio_led_platform_data mtx1_led_data = {
129-
.num_leds = ARRAY_SIZE(default_leds),
130-
.leds = default_leds,
157+
static const struct property_entry mtx1_green_led_props[] = {
158+
PROPERTY_ENTRY_GPIO("gpios", &mtx1_gpiochip_node, 11, GPIO_ACTIVE_HIGH),
159+
{ }
131160
};
132161

133-
static struct platform_device mtx1_gpio_leds = {
134-
.name = "leds-gpio",
135-
.id = -1,
136-
.dev = {
137-
.platform_data = &mtx1_led_data,
138-
}
162+
static const struct software_node mtx1_green_led_node = {
163+
.name = "mtx1:green",
164+
.parent = &mtx1_gpio_leds_node,
165+
.properties = mtx1_green_led_props,
139166
};
140167

168+
static const struct property_entry mtx1_red_led_props[] = {
169+
PROPERTY_ENTRY_GPIO("gpios", &mtx1_gpiochip_node, 12, GPIO_ACTIVE_HIGH),
170+
{ }
171+
};
172+
173+
static const struct software_node mtx1_red_led_node = {
174+
.name = "mtx1:red",
175+
.parent = &mtx1_gpio_leds_node,
176+
.properties = mtx1_red_led_props,
177+
};
178+
179+
static const struct software_node *mtx1_gpio_leds_swnodes[] = {
180+
&mtx1_gpio_leds_node,
181+
&mtx1_green_led_node,
182+
&mtx1_red_led_node,
183+
NULL
184+
};
185+
186+
static void __init mtx1_leds_init(void)
187+
{
188+
struct platform_device_info led_info = {
189+
.name = "leds-gpio",
190+
.id = PLATFORM_DEVID_NONE,
191+
};
192+
struct platform_device *led_dev;
193+
int err;
194+
195+
err = software_node_register_node_group(mtx1_gpio_leds_swnodes);
196+
if (err) {
197+
pr_err("failed to register LED software nodes: %d\n", err);
198+
return;
199+
}
200+
201+
led_info.fwnode = software_node_fwnode(&mtx1_gpio_leds_node);
202+
203+
led_dev = platform_device_register_full(&led_info);
204+
err = PTR_ERR_OR_ZERO(led_dev);
205+
if (err)
206+
pr_err("failed to create LED device: %d\n", err);
207+
}
208+
141209
static struct mtd_partition mtx1_mtd_partitions[] = {
142210
{
143211
.name = "filesystem",
@@ -247,9 +315,6 @@ static struct platform_device mtx1_pci_host = {
247315

248316
static struct platform_device *mtx1_devs[] __initdata = {
249317
&mtx1_pci_host,
250-
&mtx1_gpio_leds,
251-
&mtx1_wdt,
252-
&mtx1_button,
253318
&mtx1_mtd,
254319
};
255320

@@ -270,16 +335,18 @@ static int __init mtx1_register_devices(void)
270335

271336
au1xxx_override_eth_cfg(0, &mtx1_au1000_eth0_pdata);
272337

273-
rc = gpio_request(mtx1_gpio_button[0].gpio,
274-
mtx1_gpio_button[0].desc);
275-
if (rc < 0) {
276-
printk(KERN_INFO "mtx1: failed to request %d\n",
277-
mtx1_gpio_button[0].gpio);
278-
goto out;
279-
}
280-
gpio_direction_input(mtx1_gpio_button[0].gpio);
281-
out:
282-
gpiod_add_lookup_table(&mtx1_wdt_gpio_table);
283-
return platform_add_devices(mtx1_devs, ARRAY_SIZE(mtx1_devs));
338+
rc = software_node_register(&mtx1_gpiochip_node);
339+
if (rc)
340+
return rc;
341+
342+
rc = platform_add_devices(mtx1_devs, ARRAY_SIZE(mtx1_devs));
343+
if (rc)
344+
return rc;
345+
346+
mtx1_leds_init();
347+
mtx1_wdt_init();
348+
mtx1_keys_init();
349+
350+
return 0;
284351
}
285352
arch_initcall(mtx1_register_devices);

0 commit comments

Comments
 (0)