Commit e4ecf2bd authored by Linus Walleij's avatar Linus Walleij

ARM: plat-versatile: convert LEDs to platform device

The LEDs were initialized unconditionally with an fs_initcall()
which doesn't play well with multiplatform. Convert the driver
to a platform device and convert all boards with these LEDs
to register a platform device and pass the register as a
resource instead.

Tested successfully on the Versatile/AB and RealView PB1176.

Cc: Bryan Wu <cooloney@gmail.com>
Cc: Richard Purdie <rpurdie@rpsys.net>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Pawel Moll <pawel.moll@arm.com>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent d1cb3ecf
...@@ -148,6 +148,21 @@ struct platform_device realview_cf_device = { ...@@ -148,6 +148,21 @@ struct platform_device realview_cf_device = {
}, },
}; };
static struct resource realview_leds_resources[] = {
{
.start = REALVIEW_SYS_BASE + REALVIEW_SYS_LED_OFFSET,
.end = REALVIEW_SYS_BASE + REALVIEW_SYS_LED_OFFSET + 4,
.flags = IORESOURCE_MEM,
},
};
struct platform_device realview_leds_device = {
.name = "versatile-leds",
.id = -1,
.num_resources = ARRAY_SIZE(realview_leds_resources),
.resource = realview_leds_resources,
};
static struct resource realview_i2c_resource = { static struct resource realview_i2c_resource = {
.start = REALVIEW_I2C_BASE, .start = REALVIEW_I2C_BASE,
.end = REALVIEW_I2C_BASE + SZ_4K - 1, .end = REALVIEW_I2C_BASE + SZ_4K - 1,
......
...@@ -37,6 +37,7 @@ struct machine_desc; ...@@ -37,6 +37,7 @@ struct machine_desc;
extern struct platform_device realview_flash_device; extern struct platform_device realview_flash_device;
extern struct platform_device realview_cf_device; extern struct platform_device realview_cf_device;
extern struct platform_device realview_leds_device;
extern struct platform_device realview_i2c_device; extern struct platform_device realview_i2c_device;
extern struct mmci_platform_data realview_mmc0_plat_data; extern struct mmci_platform_data realview_mmc0_plat_data;
extern struct mmci_platform_data realview_mmc1_plat_data; extern struct mmci_platform_data realview_mmc1_plat_data;
......
...@@ -452,6 +452,7 @@ static void __init realview_eb_init(void) ...@@ -452,6 +452,7 @@ static void __init realview_eb_init(void)
realview_flash_register(&realview_eb_flash_resource, 1); realview_flash_register(&realview_eb_flash_resource, 1);
platform_device_register(&realview_i2c_device); platform_device_register(&realview_i2c_device);
platform_device_register(&char_lcd_device); platform_device_register(&char_lcd_device);
platform_device_register(&realview_leds_device);
eth_device_register(); eth_device_register();
realview_usb_register(realview_eb_isp1761_resources); realview_usb_register(realview_eb_isp1761_resources);
......
...@@ -367,6 +367,7 @@ static void __init realview_pb1176_init(void) ...@@ -367,6 +367,7 @@ static void __init realview_pb1176_init(void)
realview_usb_register(realview_pb1176_isp1761_resources); realview_usb_register(realview_pb1176_isp1761_resources);
platform_device_register(&pmu_device); platform_device_register(&pmu_device);
platform_device_register(&char_lcd_device); platform_device_register(&char_lcd_device);
platform_device_register(&realview_leds_device);
for (i = 0; i < ARRAY_SIZE(amba_devs); i++) { for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
struct amba_device *d = amba_devs[i]; struct amba_device *d = amba_devs[i];
......
...@@ -347,6 +347,7 @@ static void __init realview_pb11mp_init(void) ...@@ -347,6 +347,7 @@ static void __init realview_pb11mp_init(void)
realview_eth_register(NULL, realview_pb11mp_smsc911x_resources); realview_eth_register(NULL, realview_pb11mp_smsc911x_resources);
platform_device_register(&realview_i2c_device); platform_device_register(&realview_i2c_device);
platform_device_register(&realview_cf_device); platform_device_register(&realview_cf_device);
platform_device_register(&realview_leds_device);
realview_usb_register(realview_pb11mp_isp1761_resources); realview_usb_register(realview_pb11mp_isp1761_resources);
platform_device_register(&pmu_device); platform_device_register(&pmu_device);
......
...@@ -289,6 +289,7 @@ static void __init realview_pba8_init(void) ...@@ -289,6 +289,7 @@ static void __init realview_pba8_init(void)
realview_eth_register(NULL, realview_pba8_smsc911x_resources); realview_eth_register(NULL, realview_pba8_smsc911x_resources);
platform_device_register(&realview_i2c_device); platform_device_register(&realview_i2c_device);
platform_device_register(&realview_cf_device); platform_device_register(&realview_cf_device);
platform_device_register(&realview_leds_device);
realview_usb_register(realview_pba8_isp1761_resources); realview_usb_register(realview_pba8_isp1761_resources);
platform_device_register(&pmu_device); platform_device_register(&pmu_device);
......
...@@ -385,6 +385,7 @@ static void __init realview_pbx_init(void) ...@@ -385,6 +385,7 @@ static void __init realview_pbx_init(void)
realview_eth_register(NULL, realview_pbx_smsc911x_resources); realview_eth_register(NULL, realview_pbx_smsc911x_resources);
platform_device_register(&realview_i2c_device); platform_device_register(&realview_i2c_device);
platform_device_register(&realview_cf_device); platform_device_register(&realview_cf_device);
platform_device_register(&realview_leds_device);
realview_usb_register(realview_pbx_isp1761_resources); realview_usb_register(realview_pbx_isp1761_resources);
for (i = 0; i < ARRAY_SIZE(amba_devs); i++) { for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
......
...@@ -310,6 +310,21 @@ static struct platform_device char_lcd_device = { ...@@ -310,6 +310,21 @@ static struct platform_device char_lcd_device = {
.resource = char_lcd_resources, .resource = char_lcd_resources,
}; };
static struct resource leds_resources[] = {
{
.start = VERSATILE_SYS_BASE + VERSATILE_SYS_LED_OFFSET,
.end = VERSATILE_SYS_BASE + VERSATILE_SYS_LED_OFFSET + 4,
.flags = IORESOURCE_MEM,
},
};
static struct platform_device leds_device = {
.name = "versatile-leds",
.id = -1,
.num_resources = ARRAY_SIZE(leds_resources),
.resource = leds_resources,
};
/* /*
* Clock handling * Clock handling
*/ */
...@@ -795,6 +810,7 @@ void __init versatile_init(void) ...@@ -795,6 +810,7 @@ void __init versatile_init(void)
platform_device_register(&versatile_i2c_device); platform_device_register(&versatile_i2c_device);
platform_device_register(&smc91x_device); platform_device_register(&smc91x_device);
platform_device_register(&char_lcd_device); platform_device_register(&char_lcd_device);
platform_device_register(&leds_device);
for (i = 0; i < ARRAY_SIZE(amba_devs); i++) { for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
struct amba_device *d = amba_devs[i]; struct amba_device *d = amba_devs[i];
......
...@@ -7,22 +7,14 @@ ...@@ -7,22 +7,14 @@
*/ */
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/module.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/leds.h> #include <linux/leds.h>
#include <linux/platform_device.h>
#include <mach/hardware.h>
#include <mach/platform.h>
#ifdef VERSATILE_SYS_BASE
#define LEDREG (__io_address(VERSATILE_SYS_BASE) + VERSATILE_SYS_LED_OFFSET)
#endif
#ifdef REALVIEW_SYS_BASE
#define LEDREG (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_LED_OFFSET)
#endif
struct versatile_led { struct versatile_led {
void __iomem *base;
struct led_classdev cdev; struct led_classdev cdev;
u8 mask; u8 mask;
}; };
...@@ -50,30 +42,37 @@ static void versatile_led_set(struct led_classdev *cdev, ...@@ -50,30 +42,37 @@ static void versatile_led_set(struct led_classdev *cdev,
{ {
struct versatile_led *led = container_of(cdev, struct versatile_led *led = container_of(cdev,
struct versatile_led, cdev); struct versatile_led, cdev);
u32 reg = readl(LEDREG); u32 reg = readl(led->base);
if (b != LED_OFF) if (b != LED_OFF)
reg |= led->mask; reg |= led->mask;
else else
reg &= ~led->mask; reg &= ~led->mask;
writel(reg, LEDREG); writel(reg, led->base);
} }
static enum led_brightness versatile_led_get(struct led_classdev *cdev) static enum led_brightness versatile_led_get(struct led_classdev *cdev)
{ {
struct versatile_led *led = container_of(cdev, struct versatile_led *led = container_of(cdev,
struct versatile_led, cdev); struct versatile_led, cdev);
u32 reg = readl(LEDREG); u32 reg = readl(led->base);
return (reg & led->mask) ? LED_FULL : LED_OFF; return (reg & led->mask) ? LED_FULL : LED_OFF;
} }
static int __init versatile_leds_init(void) static int versatile_leds_probe(struct platform_device *dev)
{ {
int i; int i;
struct resource *res;
void __iomem *base;
res = platform_get_resource(dev, IORESOURCE_MEM, 0);
base = devm_ioremap_resource(&dev->dev, res);
if (IS_ERR(base))
return PTR_ERR(base);
/* All off */ /* All off */
writel(0, LEDREG); writel(0, base);
for (i = 0; i < ARRAY_SIZE(versatile_leds); i++) { for (i = 0; i < ARRAY_SIZE(versatile_leds); i++) {
struct versatile_led *led; struct versatile_led *led;
...@@ -81,6 +80,7 @@ static int __init versatile_leds_init(void) ...@@ -81,6 +80,7 @@ static int __init versatile_leds_init(void)
if (!led) if (!led)
break; break;
led->base = base;
led->cdev.name = versatile_leds[i].name; led->cdev.name = versatile_leds[i].name;
led->cdev.brightness_set = versatile_led_set; led->cdev.brightness_set = versatile_led_set;
led->cdev.brightness_get = versatile_led_get; led->cdev.brightness_get = versatile_led_get;
...@@ -96,8 +96,15 @@ static int __init versatile_leds_init(void) ...@@ -96,8 +96,15 @@ static int __init versatile_leds_init(void)
return 0; return 0;
} }
/* static struct platform_driver versatile_leds_driver = {
* Since we may have triggers on any subsystem, defer registration .driver = {
* until after subsystem_init. .name = "versatile-leds",
*/ },
fs_initcall(versatile_leds_init); .probe = versatile_leds_probe,
};
module_platform_driver(versatile_leds_driver);
MODULE_AUTHOR("Linus Walleij <linus.walleij@linaro.org>");
MODULE_DESCRIPTION("ARM Versatile LED driver");
MODULE_LICENSE("GPL v2");
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment