[ar71xx] simplify leds-gpio device registration
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files / arch / mips / ar71xx / platform.c
index 3c9b74ca2c3d4f8a04026cbfc679159debe79d34..3bda20e52da0788e38a5a0732bd55f15e1f193a1 100644 (file)
@@ -334,6 +334,44 @@ void __init ar71xx_add_device_spi(struct ar71xx_spi_platform_data *pdata,
        platform_device_register(&ar71xx_spi_device);
 }
 
+void __init ar71xx_add_device_leds_gpio(int id, unsigned num_leds,
+                               struct gpio_led *leds)
+{
+       struct platform_device *pdev;
+       struct gpio_led_platform_data pdata;
+       struct gpio_led *p;
+       int err;
+
+       p = kmalloc(num_leds * sizeof(*p), GFP_KERNEL);
+       if (!p)
+               return;
+
+       memcpy(p, leds, num_leds * sizeof(*p));
+
+       pdev = platform_device_alloc("leds-gpio", id);
+       if (!pdev)
+               goto err_free_leds;
+
+       pdata.num_leds = num_leds;
+       pdata.leds = leds;
+
+       err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
+       if (err)
+               goto err_put_pdev;
+
+       err = platform_device_add(pdev);
+       if (err)
+               goto err_put_pdev;
+
+       return;
+
+err_put_pdev:
+       platform_device_put(pdev);
+
+err_free_leds:
+       kfree(p);
+}
+
 void __init ar71xx_set_mac_base(char *mac_str)
 {
        u8 tmp[ETH_ALEN];