diff options
Diffstat (limited to 'drivers/power/jz4740-battery.c')
-rw-r--r-- | drivers/power/jz4740-battery.c | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/drivers/power/jz4740-battery.c b/drivers/power/jz4740-battery.c index 0444434e1927..abdfc21ec13f 100644 --- a/drivers/power/jz4740-battery.c +++ b/drivers/power/jz4740-battery.c | |||
@@ -46,7 +46,8 @@ struct jz_battery { | |||
46 | 46 | ||
47 | struct completion read_completion; | 47 | struct completion read_completion; |
48 | 48 | ||
49 | struct power_supply battery; | 49 | struct power_supply *battery; |
50 | struct power_supply_desc battery_desc; | ||
50 | struct delayed_work work; | 51 | struct delayed_work work; |
51 | 52 | ||
52 | struct mutex lock; | 53 | struct mutex lock; |
@@ -54,7 +55,7 @@ struct jz_battery { | |||
54 | 55 | ||
55 | static inline struct jz_battery *psy_to_jz_battery(struct power_supply *psy) | 56 | static inline struct jz_battery *psy_to_jz_battery(struct power_supply *psy) |
56 | { | 57 | { |
57 | return container_of(psy, struct jz_battery, battery); | 58 | return power_supply_get_drvdata(psy); |
58 | } | 59 | } |
59 | 60 | ||
60 | static irqreturn_t jz_battery_irq_handler(int irq, void *devid) | 61 | static irqreturn_t jz_battery_irq_handler(int irq, void *devid) |
@@ -213,7 +214,7 @@ static void jz_battery_update(struct jz_battery *jz_battery) | |||
213 | } | 214 | } |
214 | 215 | ||
215 | if (has_changed) | 216 | if (has_changed) |
216 | power_supply_changed(&jz_battery->battery); | 217 | power_supply_changed(jz_battery->battery); |
217 | } | 218 | } |
218 | 219 | ||
219 | static enum power_supply_property jz_battery_properties[] = { | 220 | static enum power_supply_property jz_battery_properties[] = { |
@@ -242,8 +243,9 @@ static int jz_battery_probe(struct platform_device *pdev) | |||
242 | { | 243 | { |
243 | int ret = 0; | 244 | int ret = 0; |
244 | struct jz_battery_platform_data *pdata = pdev->dev.parent->platform_data; | 245 | struct jz_battery_platform_data *pdata = pdev->dev.parent->platform_data; |
246 | struct power_supply_config psy_cfg = {}; | ||
245 | struct jz_battery *jz_battery; | 247 | struct jz_battery *jz_battery; |
246 | struct power_supply *battery; | 248 | struct power_supply_desc *battery_desc; |
247 | struct resource *mem; | 249 | struct resource *mem; |
248 | 250 | ||
249 | if (!pdata) { | 251 | if (!pdata) { |
@@ -271,14 +273,17 @@ static int jz_battery_probe(struct platform_device *pdev) | |||
271 | if (IS_ERR(jz_battery->base)) | 273 | if (IS_ERR(jz_battery->base)) |
272 | return PTR_ERR(jz_battery->base); | 274 | return PTR_ERR(jz_battery->base); |
273 | 275 | ||
274 | battery = &jz_battery->battery; | 276 | battery_desc = &jz_battery->battery_desc; |
275 | battery->name = pdata->info.name; | 277 | battery_desc->name = pdata->info.name; |
276 | battery->type = POWER_SUPPLY_TYPE_BATTERY; | 278 | battery_desc->type = POWER_SUPPLY_TYPE_BATTERY; |
277 | battery->properties = jz_battery_properties; | 279 | battery_desc->properties = jz_battery_properties; |
278 | battery->num_properties = ARRAY_SIZE(jz_battery_properties); | 280 | battery_desc->num_properties = ARRAY_SIZE(jz_battery_properties); |
279 | battery->get_property = jz_battery_get_property; | 281 | battery_desc->get_property = jz_battery_get_property; |
280 | battery->external_power_changed = jz_battery_external_power_changed; | 282 | battery_desc->external_power_changed = |
281 | battery->use_for_apm = 1; | 283 | jz_battery_external_power_changed; |
284 | battery_desc->use_for_apm = 1; | ||
285 | |||
286 | psy_cfg.drv_data = jz_battery; | ||
282 | 287 | ||
283 | jz_battery->pdata = pdata; | 288 | jz_battery->pdata = pdata; |
284 | jz_battery->pdev = pdev; | 289 | jz_battery->pdev = pdev; |
@@ -330,9 +335,11 @@ static int jz_battery_probe(struct platform_device *pdev) | |||
330 | else | 335 | else |
331 | jz4740_adc_set_config(pdev->dev.parent, JZ_ADC_CONFIG_BAT_MB, 0); | 336 | jz4740_adc_set_config(pdev->dev.parent, JZ_ADC_CONFIG_BAT_MB, 0); |
332 | 337 | ||
333 | ret = power_supply_register(&pdev->dev, &jz_battery->battery, NULL); | 338 | jz_battery->battery = power_supply_register(&pdev->dev, battery_desc, |
334 | if (ret) { | 339 | &psy_cfg); |
340 | if (IS_ERR(jz_battery->battery)) { | ||
335 | dev_err(&pdev->dev, "power supply battery register failed.\n"); | 341 | dev_err(&pdev->dev, "power supply battery register failed.\n"); |
342 | ret = PTR_ERR(jz_battery->battery); | ||
336 | goto err_free_charge_irq; | 343 | goto err_free_charge_irq; |
337 | } | 344 | } |
338 | 345 | ||
@@ -364,7 +371,7 @@ static int jz_battery_remove(struct platform_device *pdev) | |||
364 | gpio_free(jz_battery->pdata->gpio_charge); | 371 | gpio_free(jz_battery->pdata->gpio_charge); |
365 | } | 372 | } |
366 | 373 | ||
367 | power_supply_unregister(&jz_battery->battery); | 374 | power_supply_unregister(jz_battery->battery); |
368 | 375 | ||
369 | free_irq(jz_battery->irq, jz_battery); | 376 | free_irq(jz_battery->irq, jz_battery); |
370 | 377 | ||