wm97xx_battery.c (cc9b94029e9ef51787af908e9856b1eed314bc00) wm97xx_battery.c (6480af4915d6ffb66afc39eee4e9e66cbf59b938)
1/*
2 * Battery measurement code for WM97xx
3 *
4 * based on tosa_battery.c
5 *
6 * Copyright (C) 2008 Marek Vasut <marek.vasut@gmail.com>
7 *
8 * This program is free software; you can redistribute it and/or modify

--- 16 unchanged lines hidden (view full) ---

25
26static struct work_struct bat_work;
27static DEFINE_MUTEX(work_lock);
28static int bat_status = POWER_SUPPLY_STATUS_UNKNOWN;
29static enum power_supply_property *prop;
30
31static unsigned long wm97xx_read_bat(struct power_supply *bat_ps)
32{
1/*
2 * Battery measurement code for WM97xx
3 *
4 * based on tosa_battery.c
5 *
6 * Copyright (C) 2008 Marek Vasut <marek.vasut@gmail.com>
7 *
8 * This program is free software; you can redistribute it and/or modify

--- 16 unchanged lines hidden (view full) ---

25
26static struct work_struct bat_work;
27static DEFINE_MUTEX(work_lock);
28static int bat_status = POWER_SUPPLY_STATUS_UNKNOWN;
29static enum power_supply_property *prop;
30
31static unsigned long wm97xx_read_bat(struct power_supply *bat_ps)
32{
33 struct wm97xx_pdata *wmdata = bat_ps->dev.parent->platform_data;
34 struct wm97xx_batt_pdata *pdata = wmdata->batt_pdata;
33 struct wm97xx_batt_pdata *pdata = power_supply_get_drvdata(bat_ps);
35
36 return wm97xx_read_aux_adc(dev_get_drvdata(bat_ps->dev.parent),
37 pdata->batt_aux) * pdata->batt_mult /
38 pdata->batt_div;
39}
40
41static unsigned long wm97xx_read_temp(struct power_supply *bat_ps)
42{
34
35 return wm97xx_read_aux_adc(dev_get_drvdata(bat_ps->dev.parent),
36 pdata->batt_aux) * pdata->batt_mult /
37 pdata->batt_div;
38}
39
40static unsigned long wm97xx_read_temp(struct power_supply *bat_ps)
41{
43 struct wm97xx_pdata *wmdata = bat_ps->dev.parent->platform_data;
44 struct wm97xx_batt_pdata *pdata = wmdata->batt_pdata;
42 struct wm97xx_batt_pdata *pdata = power_supply_get_drvdata(bat_ps);
45
46 return wm97xx_read_aux_adc(dev_get_drvdata(bat_ps->dev.parent),
47 pdata->temp_aux) * pdata->temp_mult /
48 pdata->temp_div;
49}
50
51static int wm97xx_bat_get_property(struct power_supply *bat_ps,
52 enum power_supply_property psp,
53 union power_supply_propval *val)
54{
43
44 return wm97xx_read_aux_adc(dev_get_drvdata(bat_ps->dev.parent),
45 pdata->temp_aux) * pdata->temp_mult /
46 pdata->temp_div;
47}
48
49static int wm97xx_bat_get_property(struct power_supply *bat_ps,
50 enum power_supply_property psp,
51 union power_supply_propval *val)
52{
55 struct wm97xx_pdata *wmdata = bat_ps->dev.parent->platform_data;
56 struct wm97xx_batt_pdata *pdata = wmdata->batt_pdata;
53 struct wm97xx_batt_pdata *pdata = power_supply_get_drvdata(bat_ps);
57
58 switch (psp) {
59 case POWER_SUPPLY_PROP_STATUS:
60 val->intval = bat_status;
61 break;
62 case POWER_SUPPLY_PROP_TECHNOLOGY:
63 val->intval = pdata->batt_tech;
64 break;

--- 33 unchanged lines hidden (view full) ---

98static void wm97xx_bat_external_power_changed(struct power_supply *bat_ps)
99{
100 schedule_work(&bat_work);
101}
102
103static void wm97xx_bat_update(struct power_supply *bat_ps)
104{
105 int old_status = bat_status;
54
55 switch (psp) {
56 case POWER_SUPPLY_PROP_STATUS:
57 val->intval = bat_status;
58 break;
59 case POWER_SUPPLY_PROP_TECHNOLOGY:
60 val->intval = pdata->batt_tech;
61 break;

--- 33 unchanged lines hidden (view full) ---

95static void wm97xx_bat_external_power_changed(struct power_supply *bat_ps)
96{
97 schedule_work(&bat_work);
98}
99
100static void wm97xx_bat_update(struct power_supply *bat_ps)
101{
102 int old_status = bat_status;
106 struct wm97xx_pdata *wmdata = bat_ps->dev.parent->platform_data;
107 struct wm97xx_batt_pdata *pdata = wmdata->batt_pdata;
103 struct wm97xx_batt_pdata *pdata = power_supply_get_drvdata(bat_ps);
108
109 mutex_lock(&work_lock);
110
111 bat_status = (pdata->charge_gpio >= 0) ?
112 (gpio_get_value(pdata->charge_gpio) ?
113 POWER_SUPPLY_STATUS_DISCHARGING :
114 POWER_SUPPLY_STATUS_CHARGING) :
115 POWER_SUPPLY_STATUS_UNKNOWN;

--- 45 unchanged lines hidden (view full) ---

161};
162#endif
163
164static int wm97xx_bat_probe(struct platform_device *dev)
165{
166 int ret = 0;
167 int props = 1; /* POWER_SUPPLY_PROP_PRESENT */
168 int i = 0;
104
105 mutex_lock(&work_lock);
106
107 bat_status = (pdata->charge_gpio >= 0) ?
108 (gpio_get_value(pdata->charge_gpio) ?
109 POWER_SUPPLY_STATUS_DISCHARGING :
110 POWER_SUPPLY_STATUS_CHARGING) :
111 POWER_SUPPLY_STATUS_UNKNOWN;

--- 45 unchanged lines hidden (view full) ---

157};
158#endif
159
160static int wm97xx_bat_probe(struct platform_device *dev)
161{
162 int ret = 0;
163 int props = 1; /* POWER_SUPPLY_PROP_PRESENT */
164 int i = 0;
169 struct wm97xx_pdata *wmdata = dev->dev.platform_data;
170 struct wm97xx_batt_pdata *pdata;
165 struct wm97xx_batt_pdata *pdata = dev->dev.platform_data;
166 struct power_supply_config cfg = {};
171
167
172 if (!wmdata) {
168 if (!pdata) {
173 dev_err(&dev->dev, "No platform data supplied\n");
174 return -EINVAL;
175 }
176
169 dev_err(&dev->dev, "No platform data supplied\n");
170 return -EINVAL;
171 }
172
177 pdata = wmdata->batt_pdata;
173 cfg.drv_data = pdata;
178
179 if (dev->id != -1)
180 return -EINVAL;
181
182 if (!pdata) {
183 dev_err(&dev->dev, "No platform_data supplied\n");
184 return -EINVAL;
185 }

--- 52 unchanged lines hidden (view full) ---

238 "back to name \"wm97xx-batt\"\n");
239 bat_psy_desc.name = "wm97xx-batt";
240 } else
241 bat_psy_desc.name = pdata->batt_name;
242
243 bat_psy_desc.properties = prop;
244 bat_psy_desc.num_properties = props;
245
174
175 if (dev->id != -1)
176 return -EINVAL;
177
178 if (!pdata) {
179 dev_err(&dev->dev, "No platform_data supplied\n");
180 return -EINVAL;
181 }

--- 52 unchanged lines hidden (view full) ---

234 "back to name \"wm97xx-batt\"\n");
235 bat_psy_desc.name = "wm97xx-batt";
236 } else
237 bat_psy_desc.name = pdata->batt_name;
238
239 bat_psy_desc.properties = prop;
240 bat_psy_desc.num_properties = props;
241
246 bat_psy = power_supply_register(&dev->dev, &bat_psy_desc, NULL);
242 bat_psy = power_supply_register(&dev->dev, &bat_psy_desc, &cfg);
247 if (!IS_ERR(bat_psy)) {
248 schedule_work(&bat_work);
249 } else {
250 ret = PTR_ERR(bat_psy);
251 goto err4;
252 }
253
254 return 0;

--- 6 unchanged lines hidden (view full) ---

261 if (gpio_is_valid(pdata->charge_gpio))
262 gpio_free(pdata->charge_gpio);
263err:
264 return ret;
265}
266
267static int wm97xx_bat_remove(struct platform_device *dev)
268{
243 if (!IS_ERR(bat_psy)) {
244 schedule_work(&bat_work);
245 } else {
246 ret = PTR_ERR(bat_psy);
247 goto err4;
248 }
249
250 return 0;

--- 6 unchanged lines hidden (view full) ---

257 if (gpio_is_valid(pdata->charge_gpio))
258 gpio_free(pdata->charge_gpio);
259err:
260 return ret;
261}
262
263static int wm97xx_bat_remove(struct platform_device *dev)
264{
269 struct wm97xx_pdata *wmdata = dev->dev.platform_data;
270 struct wm97xx_batt_pdata *pdata = wmdata->batt_pdata;
265 struct wm97xx_batt_pdata *pdata = dev->dev.platform_data;
271
272 if (pdata && gpio_is_valid(pdata->charge_gpio)) {
273 free_irq(gpio_to_irq(pdata->charge_gpio), dev);
274 gpio_free(pdata->charge_gpio);
275 }
276 cancel_work_sync(&bat_work);
277 power_supply_unregister(bat_psy);
278 kfree(prop);

--- 19 unchanged lines hidden ---
266
267 if (pdata && gpio_is_valid(pdata->charge_gpio)) {
268 free_irq(gpio_to_irq(pdata->charge_gpio), dev);
269 gpio_free(pdata->charge_gpio);
270 }
271 cancel_work_sync(&bat_work);
272 power_supply_unregister(bat_psy);
273 kfree(prop);

--- 19 unchanged lines hidden ---