diff options
author | Peter Ujfalusi <peter.ujfalusi@ti.com> | 2012-12-21 04:43:56 -0500 |
---|---|---|
committer | Bryan Wu <cooloney@gmail.com> | 2013-02-01 20:47:04 -0500 |
commit | 0f86815ad0a2c0c70cbe0ecc2f80571726285461 (patch) | |
tree | bf7d2d0ac9d0171b2975d247e3c2739baffd16a5 | |
parent | 9ea6cdac9ba5fbc65adde4dc6a3cbee1206508df (diff) |
leds: leds-pwm: Preparing the driver for device tree support
In order to be able to add device tree support for leds-pwm driver we need
to rearrange the data structures used by the drivers.
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
Signed-off-by: Bryan Wu <cooloney@gmail.com>
-rw-r--r-- | drivers/leds/leds-pwm.c | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/drivers/leds/leds-pwm.c b/drivers/leds/leds-pwm.c index 351257c2a7b8..c767837522fe 100644 --- a/drivers/leds/leds-pwm.c +++ b/drivers/leds/leds-pwm.c | |||
@@ -30,6 +30,11 @@ struct led_pwm_data { | |||
30 | unsigned int period; | 30 | unsigned int period; |
31 | }; | 31 | }; |
32 | 32 | ||
33 | struct led_pwm_priv { | ||
34 | int num_leds; | ||
35 | struct led_pwm_data leds[0]; | ||
36 | }; | ||
37 | |||
33 | static void led_pwm_set(struct led_classdev *led_cdev, | 38 | static void led_pwm_set(struct led_classdev *led_cdev, |
34 | enum led_brightness brightness) | 39 | enum led_brightness brightness) |
35 | { | 40 | { |
@@ -47,25 +52,29 @@ static void led_pwm_set(struct led_classdev *led_cdev, | |||
47 | } | 52 | } |
48 | } | 53 | } |
49 | 54 | ||
55 | static inline size_t sizeof_pwm_leds_priv(int num_leds) | ||
56 | { | ||
57 | return sizeof(struct led_pwm_priv) + | ||
58 | (sizeof(struct led_pwm_data) * num_leds); | ||
59 | } | ||
60 | |||
50 | static int led_pwm_probe(struct platform_device *pdev) | 61 | static int led_pwm_probe(struct platform_device *pdev) |
51 | { | 62 | { |
52 | struct led_pwm_platform_data *pdata = pdev->dev.platform_data; | 63 | struct led_pwm_platform_data *pdata = pdev->dev.platform_data; |
53 | struct led_pwm *cur_led; | 64 | struct led_pwm_priv *priv; |
54 | struct led_pwm_data *leds_data, *led_dat; | ||
55 | int i, ret = 0; | 65 | int i, ret = 0; |
56 | 66 | ||
57 | if (!pdata) | 67 | if (!pdata) |
58 | return -EBUSY; | 68 | return -EBUSY; |
59 | 69 | ||
60 | leds_data = devm_kzalloc(&pdev->dev, | 70 | priv = devm_kzalloc(&pdev->dev, sizeof_pwm_leds_priv(pdata->num_leds), |
61 | sizeof(struct led_pwm_data) * pdata->num_leds, | 71 | GFP_KERNEL); |
62 | GFP_KERNEL); | 72 | if (!priv) |
63 | if (!leds_data) | ||
64 | return -ENOMEM; | 73 | return -ENOMEM; |
65 | 74 | ||
66 | for (i = 0; i < pdata->num_leds; i++) { | 75 | for (i = 0; i < pdata->num_leds; i++) { |
67 | cur_led = &pdata->leds[i]; | 76 | struct led_pwm *cur_led = &pdata->leds[i]; |
68 | led_dat = &leds_data[i]; | 77 | struct led_pwm_data *led_dat = &priv->leds[i]; |
69 | 78 | ||
70 | led_dat->pwm = devm_pwm_get(&pdev->dev, cur_led->name); | 79 | led_dat->pwm = devm_pwm_get(&pdev->dev, cur_led->name); |
71 | if (IS_ERR(led_dat->pwm)) { | 80 | if (IS_ERR(led_dat->pwm)) { |
@@ -88,15 +97,16 @@ static int led_pwm_probe(struct platform_device *pdev) | |||
88 | if (ret < 0) | 97 | if (ret < 0) |
89 | goto err; | 98 | goto err; |
90 | } | 99 | } |
100 | priv->num_leds = pdata->num_leds; | ||
91 | 101 | ||
92 | platform_set_drvdata(pdev, leds_data); | 102 | platform_set_drvdata(pdev, priv); |
93 | 103 | ||
94 | return 0; | 104 | return 0; |
95 | 105 | ||
96 | err: | 106 | err: |
97 | if (i > 0) { | 107 | if (i > 0) { |
98 | for (i = i - 1; i >= 0; i--) | 108 | for (i = i - 1; i >= 0; i--) |
99 | led_classdev_unregister(&leds_data[i].cdev); | 109 | led_classdev_unregister(&priv->leds[i].cdev); |
100 | } | 110 | } |
101 | 111 | ||
102 | return ret; | 112 | return ret; |
@@ -104,14 +114,11 @@ err: | |||
104 | 114 | ||
105 | static int led_pwm_remove(struct platform_device *pdev) | 115 | static int led_pwm_remove(struct platform_device *pdev) |
106 | { | 116 | { |
117 | struct led_pwm_priv *priv = platform_get_drvdata(pdev); | ||
107 | int i; | 118 | int i; |
108 | struct led_pwm_platform_data *pdata = pdev->dev.platform_data; | ||
109 | struct led_pwm_data *leds_data; | ||
110 | |||
111 | leds_data = platform_get_drvdata(pdev); | ||
112 | 119 | ||
113 | for (i = 0; i < pdata->num_leds; i++) | 120 | for (i = 0; i < priv->num_leds; i++) |
114 | led_classdev_unregister(&leds_data[i].cdev); | 121 | led_classdev_unregister(&priv->leds[i].cdev); |
115 | 122 | ||
116 | return 0; | 123 | return 0; |
117 | } | 124 | } |