Commit a314c5c0 authored by Grant Likely's avatar Grant Likely

leds/leds-gpio: merge platform_driver with of_platform_driver

Both interfaces can be driven with the same driver, and
of_platform_driver is getting removed.  This patch merges the two
driver registrations.
Signed-off-by: default avatarGrant Likely <grant.likely@secretlab.ca>
parent 4ebb24f7
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/leds.h> #include <linux/leds.h>
#include <linux/of_platform.h>
#include <linux/of_gpio.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/workqueue.h> #include <linux/workqueue.h>
...@@ -151,96 +153,34 @@ static void delete_gpio_led(struct gpio_led_data *led) ...@@ -151,96 +153,34 @@ static void delete_gpio_led(struct gpio_led_data *led)
gpio_free(led->gpio); gpio_free(led->gpio);
} }
#ifdef CONFIG_LEDS_GPIO_PLATFORM struct gpio_leds_priv {
static int __devinit gpio_led_probe(struct platform_device *pdev) int num_leds;
{ struct gpio_led_data leds[];
struct gpio_led_platform_data *pdata = pdev->dev.platform_data; };
struct gpio_led_data *leds_data;
int i, ret = 0;
if (!pdata)
return -EBUSY;
leds_data = kzalloc(sizeof(struct gpio_led_data) * pdata->num_leds,
GFP_KERNEL);
if (!leds_data)
return -ENOMEM;
for (i = 0; i < pdata->num_leds; i++) {
ret = create_gpio_led(&pdata->leds[i], &leds_data[i],
&pdev->dev, pdata->gpio_blink_set);
if (ret < 0)
goto err;
}
platform_set_drvdata(pdev, leds_data);
return 0;
err:
for (i = i - 1; i >= 0; i--)
delete_gpio_led(&leds_data[i]);
kfree(leds_data);
return ret;
}
static int __devexit gpio_led_remove(struct platform_device *pdev) static inline int sizeof_gpio_leds_priv(int num_leds)
{ {
int i; return sizeof(struct gpio_leds_priv) +
struct gpio_led_platform_data *pdata = pdev->dev.platform_data; (sizeof(struct gpio_led_data) * num_leds);
struct gpio_led_data *leds_data;
leds_data = platform_get_drvdata(pdev);
for (i = 0; i < pdata->num_leds; i++)
delete_gpio_led(&leds_data[i]);
kfree(leds_data);
return 0;
} }
static struct platform_driver gpio_led_driver = {
.probe = gpio_led_probe,
.remove = __devexit_p(gpio_led_remove),
.driver = {
.name = "leds-gpio",
.owner = THIS_MODULE,
},
};
MODULE_ALIAS("platform:leds-gpio");
#endif /* CONFIG_LEDS_GPIO_PLATFORM */
/* Code to create from OpenFirmware platform devices */ /* Code to create from OpenFirmware platform devices */
#ifdef CONFIG_LEDS_GPIO_OF #ifdef CONFIG_LEDS_GPIO_OF
#include <linux/of_platform.h> static struct gpio_leds_priv * __devinit gpio_leds_create_of(struct platform_device *pdev)
#include <linux/of_gpio.h>
struct gpio_led_of_platform_data {
int num_leds;
struct gpio_led_data led_data[];
};
static int __devinit of_gpio_leds_probe(struct platform_device *ofdev,
const struct of_device_id *match)
{ {
struct device_node *np = ofdev->dev.of_node, *child; struct device_node *np = pdev->dev.of_node, *child;
struct gpio_led_of_platform_data *pdata; struct gpio_leds_priv *priv;
int count = 0, ret; int count = 0, ret;
/* count LEDs defined by this device, so we know how much to allocate */ /* count LEDs in this device, so we know how much to allocate */
for_each_child_of_node(np, child) for_each_child_of_node(np, child)
count++; count++;
if (!count) if (!count)
return 0; /* or ENODEV? */ return NULL;
pdata = kzalloc(sizeof(*pdata) + sizeof(struct gpio_led_data) * count, priv = kzalloc(sizeof_gpio_leds_priv(count), GFP_KERNEL);
GFP_KERNEL); if (!priv)
if (!pdata) return NULL;
return -ENOMEM;
for_each_child_of_node(np, child) { for_each_child_of_node(np, child) {
struct gpio_led led = {}; struct gpio_led led = {};
...@@ -256,92 +196,112 @@ static int __devinit of_gpio_leds_probe(struct platform_device *ofdev, ...@@ -256,92 +196,112 @@ static int __devinit of_gpio_leds_probe(struct platform_device *ofdev,
if (state) { if (state) {
if (!strcmp(state, "keep")) if (!strcmp(state, "keep"))
led.default_state = LEDS_GPIO_DEFSTATE_KEEP; led.default_state = LEDS_GPIO_DEFSTATE_KEEP;
else if(!strcmp(state, "on")) else if (!strcmp(state, "on"))
led.default_state = LEDS_GPIO_DEFSTATE_ON; led.default_state = LEDS_GPIO_DEFSTATE_ON;
else else
led.default_state = LEDS_GPIO_DEFSTATE_OFF; led.default_state = LEDS_GPIO_DEFSTATE_OFF;
} }
ret = create_gpio_led(&led, &pdata->led_data[pdata->num_leds++], ret = create_gpio_led(&led, &priv->leds[priv->num_leds++],
&ofdev->dev, NULL); &pdev->dev, NULL);
if (ret < 0) { if (ret < 0) {
of_node_put(child); of_node_put(child);
goto err; goto err;
} }
} }
dev_set_drvdata(&ofdev->dev, pdata); return priv;
return 0;
err: err:
for (count = pdata->num_leds - 2; count >= 0; count--) for (count = priv->num_leds - 2; count >= 0; count--)
delete_gpio_led(&pdata->led_data[count]); delete_gpio_led(&priv->leds[count]);
kfree(priv);
return NULL;
}
static const struct of_device_id of_gpio_leds_match[] = {
{ .compatible = "gpio-leds", },
{},
};
#else
static struct gpio_leds_priv * __devinit gpio_leds_create_of(struct platform_device *pdev)
{
return NULL;
}
#define of_gpio_leds_match NULL
#endif
kfree(pdata);
static int __devinit gpio_led_probe(struct platform_device *pdev)
{
struct gpio_led_platform_data *pdata = pdev->dev.platform_data;
struct gpio_leds_priv *priv;
int i, ret = 0;
if (pdata && pdata->num_leds) {
priv = kzalloc(sizeof_gpio_leds_priv(pdata->num_leds),
GFP_KERNEL);
if (!priv)
return -ENOMEM;
priv->num_leds = pdata->num_leds;
for (i = 0; i < priv->num_leds; i++) {
ret = create_gpio_led(&pdata->leds[i],
&priv->leds[i],
&pdev->dev, pdata->gpio_blink_set);
if (ret < 0) {
/* On failure: unwind the led creations */
for (i = i - 1; i >= 0; i--)
delete_gpio_led(&priv->leds[i]);
kfree(priv);
return ret; return ret;
}
}
} else {
priv = gpio_leds_create_of(pdev);
if (!priv)
return -ENODEV;
}
platform_set_drvdata(pdev, priv);
return 0;
} }
static int __devexit of_gpio_leds_remove(struct platform_device *ofdev) static int __devexit gpio_led_remove(struct platform_device *pdev)
{ {
struct gpio_led_of_platform_data *pdata = dev_get_drvdata(&ofdev->dev); struct gpio_leds_priv *priv = dev_get_drvdata(&pdev->dev);
int i; int i;
for (i = 0; i < pdata->num_leds; i++) for (i = 0; i < priv->num_leds; i++)
delete_gpio_led(&pdata->led_data[i]); delete_gpio_led(&priv->leds[i]);
kfree(pdata); dev_set_drvdata(&pdev->dev, NULL);
kfree(priv);
dev_set_drvdata(&ofdev->dev, NULL);
return 0; return 0;
} }
static const struct of_device_id of_gpio_leds_match[] = { static struct platform_driver gpio_led_driver = {
{ .compatible = "gpio-leds", }, .probe = gpio_led_probe,
{}, .remove = __devexit_p(gpio_led_remove),
};
static struct of_platform_driver of_gpio_leds_driver = {
.driver = { .driver = {
.name = "of_gpio_leds", .name = "leds-gpio",
.owner = THIS_MODULE, .owner = THIS_MODULE,
.of_match_table = of_gpio_leds_match, .of_match_table = of_gpio_leds_match,
}, },
.probe = of_gpio_leds_probe,
.remove = __devexit_p(of_gpio_leds_remove),
}; };
#endif
MODULE_ALIAS("platform:leds-gpio");
static int __init gpio_led_init(void) static int __init gpio_led_init(void)
{ {
int ret = 0; return platform_driver_register(&gpio_led_driver);
#ifdef CONFIG_LEDS_GPIO_PLATFORM
ret = platform_driver_register(&gpio_led_driver);
if (ret)
return ret;
#endif
#ifdef CONFIG_LEDS_GPIO_OF
ret = of_register_platform_driver(&of_gpio_leds_driver);
#endif
#ifdef CONFIG_LEDS_GPIO_PLATFORM
if (ret)
platform_driver_unregister(&gpio_led_driver);
#endif
return ret;
} }
static void __exit gpio_led_exit(void) static void __exit gpio_led_exit(void)
{ {
#ifdef CONFIG_LEDS_GPIO_PLATFORM
platform_driver_unregister(&gpio_led_driver); platform_driver_unregister(&gpio_led_driver);
#endif
#ifdef CONFIG_LEDS_GPIO_OF
of_unregister_platform_driver(&of_gpio_leds_driver);
#endif
} }
module_init(gpio_led_init); module_init(gpio_led_init);
......
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