diff options
author | Marek Vasut <marek.vasut@gmail.com> | 2009-08-31 00:20:12 -0400 |
---|---|---|
committer | Anton Vorontsov <avorontsov@ru.mvista.com> | 2009-09-04 12:20:58 -0400 |
commit | b8bdc1d0cfc488ac0d94724639f9a61b0a5a1d40 (patch) | |
tree | 7a0748ce1b1dd440658cb20320037c92b651267d /drivers | |
parent | 32bb0e0c778a4a6cd4534a5b98f08cd45e9ab5b9 (diff) |
wm97xx_battery: Use platform_data
This patch converts the wm97xx-battery driver to use platform_data
supplied by ac97 bus.
Signed-off-by: Marek Vasut <marek.vasut@gmail.com>
Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/power/wm97xx_battery.c | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/drivers/power/wm97xx_battery.c b/drivers/power/wm97xx_battery.c index 8bde92126d34..14ebd960ebe5 100644 --- a/drivers/power/wm97xx_battery.c +++ b/drivers/power/wm97xx_battery.c | |||
@@ -22,17 +22,19 @@ | |||
22 | #include <linux/spinlock.h> | 22 | #include <linux/spinlock.h> |
23 | #include <linux/interrupt.h> | 23 | #include <linux/interrupt.h> |
24 | #include <linux/gpio.h> | 24 | #include <linux/gpio.h> |
25 | #include <linux/wm97xx_batt.h> | ||
26 | 25 | ||
27 | static DEFINE_MUTEX(bat_lock); | 26 | static DEFINE_MUTEX(bat_lock); |
28 | static struct work_struct bat_work; | 27 | static struct work_struct bat_work; |
29 | struct mutex work_lock; | 28 | struct mutex work_lock; |
30 | static int bat_status = POWER_SUPPLY_STATUS_UNKNOWN; | 29 | static int bat_status = POWER_SUPPLY_STATUS_UNKNOWN; |
31 | static struct wm97xx_batt_info *pdata; | 30 | static struct wm97xx_batt_info *gpdata; |
32 | static enum power_supply_property *prop; | 31 | static enum power_supply_property *prop; |
33 | 32 | ||
34 | static unsigned long wm97xx_read_bat(struct power_supply *bat_ps) | 33 | static unsigned long wm97xx_read_bat(struct power_supply *bat_ps) |
35 | { | 34 | { |
35 | struct wm97xx_pdata *wmdata = bat_ps->dev->parent->platform_data; | ||
36 | struct wm97xx_batt_pdata *pdata = wmdata->batt_pdata; | ||
37 | |||
36 | return wm97xx_read_aux_adc(bat_ps->dev->parent->driver_data, | 38 | return wm97xx_read_aux_adc(bat_ps->dev->parent->driver_data, |
37 | pdata->batt_aux) * pdata->batt_mult / | 39 | pdata->batt_aux) * pdata->batt_mult / |
38 | pdata->batt_div; | 40 | pdata->batt_div; |
@@ -40,6 +42,9 @@ static unsigned long wm97xx_read_bat(struct power_supply *bat_ps) | |||
40 | 42 | ||
41 | static unsigned long wm97xx_read_temp(struct power_supply *bat_ps) | 43 | static unsigned long wm97xx_read_temp(struct power_supply *bat_ps) |
42 | { | 44 | { |
45 | struct wm97xx_pdata *wmdata = bat_ps->dev->parent->platform_data; | ||
46 | struct wm97xx_batt_pdata *pdata = wmdata->batt_pdata; | ||
47 | |||
43 | return wm97xx_read_aux_adc(bat_ps->dev->parent->driver_data, | 48 | return wm97xx_read_aux_adc(bat_ps->dev->parent->driver_data, |
44 | pdata->temp_aux) * pdata->temp_mult / | 49 | pdata->temp_aux) * pdata->temp_mult / |
45 | pdata->temp_div; | 50 | pdata->temp_div; |
@@ -49,6 +54,9 @@ static int wm97xx_bat_get_property(struct power_supply *bat_ps, | |||
49 | enum power_supply_property psp, | 54 | enum power_supply_property psp, |
50 | union power_supply_propval *val) | 55 | union power_supply_propval *val) |
51 | { | 56 | { |
57 | struct wm97xx_pdata *wmdata = bat_ps->dev->parent->platform_data; | ||
58 | struct wm97xx_batt_pdata *pdata = wmdata->batt_pdata; | ||
59 | |||
52 | switch (psp) { | 60 | switch (psp) { |
53 | case POWER_SUPPLY_PROP_STATUS: | 61 | case POWER_SUPPLY_PROP_STATUS: |
54 | val->intval = bat_status; | 62 | val->intval = bat_status; |
@@ -97,6 +105,8 @@ static void wm97xx_bat_external_power_changed(struct power_supply *bat_ps) | |||
97 | static void wm97xx_bat_update(struct power_supply *bat_ps) | 105 | static void wm97xx_bat_update(struct power_supply *bat_ps) |
98 | { | 106 | { |
99 | int old_status = bat_status; | 107 | int old_status = bat_status; |
108 | struct wm97xx_pdata *wmdata = bat_ps->dev->parent->platform_data; | ||
109 | struct wm97xx_batt_pdata *pdata = wmdata->batt_pdata; | ||
100 | 110 | ||
101 | mutex_lock(&work_lock); | 111 | mutex_lock(&work_lock); |
102 | 112 | ||
@@ -149,6 +159,15 @@ static int __devinit wm97xx_bat_probe(struct platform_device *dev) | |||
149 | int ret = 0; | 159 | int ret = 0; |
150 | int props = 1; /* POWER_SUPPLY_PROP_PRESENT */ | 160 | int props = 1; /* POWER_SUPPLY_PROP_PRESENT */ |
151 | int i = 0; | 161 | int i = 0; |
162 | struct wm97xx_pdata *wmdata = dev->dev.platform_data; | ||
163 | struct wm97xx_batt_pdata *pdata; | ||
164 | |||
165 | if (gpdata) { | ||
166 | dev_err(&dev->dev, "Do not pass platform_data through " | ||
167 | "wm97xx_bat_set_pdata!\n"); | ||
168 | return -EINVAL; | ||
169 | } else | ||
170 | pdata = wmdata->batt_pdata; | ||
152 | 171 | ||
153 | if (dev->id != -1) | 172 | if (dev->id != -1) |
154 | return -EINVAL; | 173 | return -EINVAL; |
@@ -156,7 +175,7 @@ static int __devinit wm97xx_bat_probe(struct platform_device *dev) | |||
156 | mutex_init(&work_lock); | 175 | mutex_init(&work_lock); |
157 | 176 | ||
158 | if (!pdata) { | 177 | if (!pdata) { |
159 | dev_err(&dev->dev, "Please use wm97xx_bat_set_pdata\n"); | 178 | dev_err(&dev->dev, "No platform_data supplied\n"); |
160 | return -EINVAL; | 179 | return -EINVAL; |
161 | } | 180 | } |
162 | 181 | ||
@@ -229,6 +248,9 @@ err: | |||
229 | 248 | ||
230 | static int __devexit wm97xx_bat_remove(struct platform_device *dev) | 249 | static int __devexit wm97xx_bat_remove(struct platform_device *dev) |
231 | { | 250 | { |
251 | struct wm97xx_pdata *wmdata = dev->dev.platform_data; | ||
252 | struct wm97xx_batt_pdata *pdata = wmdata->batt_pdata; | ||
253 | |||
232 | if (pdata && pdata->charge_gpio && pdata->charge_gpio >= 0) | 254 | if (pdata && pdata->charge_gpio && pdata->charge_gpio >= 0) |
233 | gpio_free(pdata->charge_gpio); | 255 | gpio_free(pdata->charge_gpio); |
234 | flush_scheduled_work(); | 256 | flush_scheduled_work(); |
@@ -258,9 +280,9 @@ static void __exit wm97xx_bat_exit(void) | |||
258 | platform_driver_unregister(&wm97xx_bat_driver); | 280 | platform_driver_unregister(&wm97xx_bat_driver); |
259 | } | 281 | } |
260 | 282 | ||
261 | void __init wm97xx_bat_set_pdata(struct wm97xx_batt_info *data) | 283 | void wm97xx_bat_set_pdata(struct wm97xx_batt_info *data) |
262 | { | 284 | { |
263 | pdata = data; | 285 | gpdata = data; |
264 | } | 286 | } |
265 | EXPORT_SYMBOL_GPL(wm97xx_bat_set_pdata); | 287 | EXPORT_SYMBOL_GPL(wm97xx_bat_set_pdata); |
266 | 288 | ||