aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/power/wm97xx_battery.c32
-rw-r--r--include/linux/wm97xx.h18
-rw-r--r--include/linux/wm97xx_batt.h18
3 files changed, 49 insertions, 19 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
27static DEFINE_MUTEX(bat_lock); 26static DEFINE_MUTEX(bat_lock);
28static struct work_struct bat_work; 27static struct work_struct bat_work;
29struct mutex work_lock; 28struct mutex work_lock;
30static int bat_status = POWER_SUPPLY_STATUS_UNKNOWN; 29static int bat_status = POWER_SUPPLY_STATUS_UNKNOWN;
31static struct wm97xx_batt_info *pdata; 30static struct wm97xx_batt_info *gpdata;
32static enum power_supply_property *prop; 31static enum power_supply_property *prop;
33 32
34static unsigned long wm97xx_read_bat(struct power_supply *bat_ps) 33static 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
41static unsigned long wm97xx_read_temp(struct power_supply *bat_ps) 43static 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)
97static void wm97xx_bat_update(struct power_supply *bat_ps) 105static 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
230static int __devexit wm97xx_bat_remove(struct platform_device *dev) 249static 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
261void __init wm97xx_bat_set_pdata(struct wm97xx_batt_info *data) 283void wm97xx_bat_set_pdata(struct wm97xx_batt_info *data)
262{ 284{
263 pdata = data; 285 gpdata = data;
264} 286}
265EXPORT_SYMBOL_GPL(wm97xx_bat_set_pdata); 287EXPORT_SYMBOL_GPL(wm97xx_bat_set_pdata);
266 288
diff --git a/include/linux/wm97xx.h b/include/linux/wm97xx.h
index 6f69968eab24..b2c2297844e3 100644
--- a/include/linux/wm97xx.h
+++ b/include/linux/wm97xx.h
@@ -286,6 +286,24 @@ struct wm97xx {
286 u16 suspend_mode; /* PRP in suspend mode */ 286 u16 suspend_mode; /* PRP in suspend mode */
287}; 287};
288 288
289struct wm97xx_batt_pdata {
290 int batt_aux;
291 int temp_aux;
292 int charge_gpio;
293 int min_voltage;
294 int max_voltage;
295 int batt_div;
296 int batt_mult;
297 int temp_div;
298 int temp_mult;
299 int batt_tech;
300 char *batt_name;
301};
302
303struct wm97xx_pdata {
304 struct wm97xx_batt_pdata *batt_pdata; /* battery data */
305};
306
289/* 307/*
290 * Codec GPIO access (not supported on WM9705) 308 * Codec GPIO access (not supported on WM9705)
291 * This can be used to set/get codec GPIO and Virtual GPIO status. 309 * This can be used to set/get codec GPIO and Virtual GPIO status.
diff --git a/include/linux/wm97xx_batt.h b/include/linux/wm97xx_batt.h
index 9681d1ab0e4f..a1d6419c2ff8 100644
--- a/include/linux/wm97xx_batt.h
+++ b/include/linux/wm97xx_batt.h
@@ -3,22 +3,12 @@
3 3
4#include <linux/wm97xx.h> 4#include <linux/wm97xx.h>
5 5
6struct wm97xx_batt_info { 6#warning This file will be removed soon, use wm97xx.h instead!
7 int batt_aux; 7
8 int temp_aux; 8#define wm97xx_batt_info wm97xx_batt_pdata
9 int charge_gpio;
10 int min_voltage;
11 int max_voltage;
12 int batt_div;
13 int batt_mult;
14 int temp_div;
15 int temp_mult;
16 int batt_tech;
17 char *batt_name;
18};
19 9
20#ifdef CONFIG_BATTERY_WM97XX 10#ifdef CONFIG_BATTERY_WM97XX
21void __init wm97xx_bat_set_pdata(struct wm97xx_batt_info *data); 11void wm97xx_bat_set_pdata(struct wm97xx_batt_info *data);
22#else 12#else
23static inline void wm97xx_bat_set_pdata(struct wm97xx_batt_info *data) {} 13static inline void wm97xx_bat_set_pdata(struct wm97xx_batt_info *data) {}
24#endif 14#endif