[ARM] 4768/2: ixp4xx: Button and LED updates for the nas100d board
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-ixp4xx / nas100d-setup.c
index a3b4c6ac570858e42ce96b8618cecfbaf80ea089..213a4cea9117b04c3d8cd88188ff80ff95f3688f 100644 (file)
@@ -15,6 +15,8 @@
 #include <linux/kernel.h>
 #include <linux/serial.h>
 #include <linux/serial_8250.h>
+#include <linux/leds.h>
+#include <linux/i2c-gpio.h>
 
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
@@ -37,16 +39,47 @@ static struct platform_device nas100d_flash = {
        .resource               = &nas100d_flash_resource,
 };
 
-static struct ixp4xx_i2c_pins nas100d_i2c_gpio_pins = {
+#ifdef CONFIG_LEDS_IXP4XX
+static struct resource nas100d_led_resources[] = {
+       {
+               .name           = "wlan",   /* green led */
+               .start          = NAS100D_LED_WLAN_GPIO,
+               .end            = NAS100D_LED_WLAN_GPIO,
+               .flags          = IXP4XX_GPIO_LOW,
+       },
+       {
+               .name           = "power",  /* blue power led (off=flashing) */
+               .start          = NAS100D_LED_PWR_GPIO,
+               .end            = NAS100D_LED_PWR_GPIO,
+               .flags          = IXP4XX_GPIO_LOW,
+       },
+       {
+               .name           = "disk",   /* yellow led */
+               .start          = NAS100D_LED_DISK_GPIO,
+               .end            = NAS100D_LED_DISK_GPIO,
+               .flags          = IXP4XX_GPIO_LOW,
+       },
+};
+
+static struct platform_device nas100d_leds = {
+       .name                   = "IXP4XX-GPIO-LED",
+       .id                     = -1,
+       .num_resources          = ARRAY_SIZE(nas100d_led_resources),
+       .resource               = nas100d_led_resources,
+};
+#endif
+
+static struct i2c_gpio_platform_data nas100d_i2c_gpio_data = {
        .sda_pin                = NAS100D_SDA_PIN,
        .scl_pin                = NAS100D_SCL_PIN,
 };
 
-static struct platform_device nas100d_i2c_controller = {
-       .name                   = "IXP4XX-I2C",
+static struct platform_device nas100d_i2c_gpio = {
+       .name                   = "i2c-gpio",
        .id                     = 0,
-       .dev.platform_data      = &nas100d_i2c_gpio_pins,
-       .num_resources          = 0,
+       .dev     = {
+               .platform_data  = &nas100d_i2c_gpio_data,
+       },
 };
 
 static struct resource nas100d_uart_resources[] = {
@@ -93,9 +126,11 @@ static struct platform_device nas100d_uart = {
 };
 
 static struct platform_device *nas100d_devices[] __initdata = {
-       &nas100d_i2c_controller,
+       &nas100d_i2c_gpio,
        &nas100d_flash,
-       &nas100d_uart,
+#ifdef CONFIG_LEDS_IXP4XX
+       &nas100d_leds,
+#endif
 };
 
 static void nas100d_power_off(void)
@@ -122,6 +157,13 @@ static void __init nas100d_init(void)
 
        pm_power_off = nas100d_power_off;
 
+       /*
+        * This is only useful on a modified machine, but it is valuable
+        * to have it first in order to see debug messages, and so that
+        * it does *not* get removed if platform_add_devices fails!
+        */
+       (void)platform_device_register(&nas100d_uart);
+
        platform_add_devices(nas100d_devices, ARRAY_SIZE(nas100d_devices));
 }