aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power/pcf50633-charger.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/power/pcf50633-charger.c')
-rw-r--r--drivers/power/pcf50633-charger.c95
1 files changed, 54 insertions, 41 deletions
diff --git a/drivers/power/pcf50633-charger.c b/drivers/power/pcf50633-charger.c
index 88fe7db2afcf..d05597b4e40f 100644
--- a/drivers/power/pcf50633-charger.c
+++ b/drivers/power/pcf50633-charger.c
@@ -33,9 +33,9 @@ struct pcf50633_mbc {
33 int adapter_online; 33 int adapter_online;
34 int usb_online; 34 int usb_online;
35 35
36 struct power_supply usb; 36 struct power_supply *usb;
37 struct power_supply adapter; 37 struct power_supply *adapter;
38 struct power_supply ac; 38 struct power_supply *ac;
39}; 39};
40 40
41int pcf50633_mbc_usb_curlim_set(struct pcf50633 *pcf, int ma) 41int pcf50633_mbc_usb_curlim_set(struct pcf50633 *pcf, int ma)
@@ -104,7 +104,7 @@ int pcf50633_mbc_usb_curlim_set(struct pcf50633 *pcf, int ma)
104 PCF50633_MBCC1_CHGENA, PCF50633_MBCC1_CHGENA); 104 PCF50633_MBCC1_CHGENA, PCF50633_MBCC1_CHGENA);
105 } 105 }
106 106
107 power_supply_changed(&mbc->usb); 107 power_supply_changed(mbc->usb);
108 108
109 return ret; 109 return ret;
110} 110}
@@ -278,9 +278,9 @@ pcf50633_mbc_irq_handler(int irq, void *data)
278 else if (irq == PCF50633_IRQ_ADPREM) 278 else if (irq == PCF50633_IRQ_ADPREM)
279 mbc->adapter_online = 0; 279 mbc->adapter_online = 0;
280 280
281 power_supply_changed(&mbc->ac); 281 power_supply_changed(mbc->ac);
282 power_supply_changed(&mbc->usb); 282 power_supply_changed(mbc->usb);
283 power_supply_changed(&mbc->adapter); 283 power_supply_changed(mbc->adapter);
284 284
285 if (mbc->pcf->pdata->mbc_event_callback) 285 if (mbc->pcf->pdata->mbc_event_callback)
286 mbc->pcf->pdata->mbc_event_callback(mbc->pcf, irq); 286 mbc->pcf->pdata->mbc_event_callback(mbc->pcf, irq);
@@ -290,8 +290,7 @@ static int adapter_get_property(struct power_supply *psy,
290 enum power_supply_property psp, 290 enum power_supply_property psp,
291 union power_supply_propval *val) 291 union power_supply_propval *val)
292{ 292{
293 struct pcf50633_mbc *mbc = container_of(psy, 293 struct pcf50633_mbc *mbc = power_supply_get_drvdata(psy);
294 struct pcf50633_mbc, adapter);
295 int ret = 0; 294 int ret = 0;
296 295
297 switch (psp) { 296 switch (psp) {
@@ -309,7 +308,7 @@ static int usb_get_property(struct power_supply *psy,
309 enum power_supply_property psp, 308 enum power_supply_property psp,
310 union power_supply_propval *val) 309 union power_supply_propval *val)
311{ 310{
312 struct pcf50633_mbc *mbc = container_of(psy, struct pcf50633_mbc, usb); 311 struct pcf50633_mbc *mbc = power_supply_get_drvdata(psy);
313 int ret = 0; 312 int ret = 0;
314 u8 usblim = pcf50633_reg_read(mbc->pcf, PCF50633_REG_MBCC7) & 313 u8 usblim = pcf50633_reg_read(mbc->pcf, PCF50633_REG_MBCC7) &
315 PCF50633_MBCC7_USB_MASK; 314 PCF50633_MBCC7_USB_MASK;
@@ -330,7 +329,7 @@ static int ac_get_property(struct power_supply *psy,
330 enum power_supply_property psp, 329 enum power_supply_property psp,
331 union power_supply_propval *val) 330 union power_supply_propval *val)
332{ 331{
333 struct pcf50633_mbc *mbc = container_of(psy, struct pcf50633_mbc, ac); 332 struct pcf50633_mbc *mbc = power_supply_get_drvdata(psy);
334 int ret = 0; 333 int ret = 0;
335 u8 usblim = pcf50633_reg_read(mbc->pcf, PCF50633_REG_MBCC7) & 334 u8 usblim = pcf50633_reg_read(mbc->pcf, PCF50633_REG_MBCC7) &
336 PCF50633_MBCC7_USB_MASK; 335 PCF50633_MBCC7_USB_MASK;
@@ -366,6 +365,30 @@ static const u8 mbc_irq_handlers[] = {
366 PCF50633_IRQ_LOWBAT, 365 PCF50633_IRQ_LOWBAT,
367}; 366};
368 367
368static const struct power_supply_desc pcf50633_mbc_adapter_desc = {
369 .name = "adapter",
370 .type = POWER_SUPPLY_TYPE_MAINS,
371 .properties = power_props,
372 .num_properties = ARRAY_SIZE(power_props),
373 .get_property = &adapter_get_property,
374};
375
376static const struct power_supply_desc pcf50633_mbc_usb_desc = {
377 .name = "usb",
378 .type = POWER_SUPPLY_TYPE_USB,
379 .properties = power_props,
380 .num_properties = ARRAY_SIZE(power_props),
381 .get_property = usb_get_property,
382};
383
384static const struct power_supply_desc pcf50633_mbc_ac_desc = {
385 .name = "ac",
386 .type = POWER_SUPPLY_TYPE_MAINS,
387 .properties = power_props,
388 .num_properties = ARRAY_SIZE(power_props),
389 .get_property = ac_get_property,
390};
391
369static int pcf50633_mbc_probe(struct platform_device *pdev) 392static int pcf50633_mbc_probe(struct platform_device *pdev)
370{ 393{
371 struct power_supply_config psy_cfg = {}; 394 struct power_supply_config psy_cfg = {};
@@ -388,44 +411,34 @@ static int pcf50633_mbc_probe(struct platform_device *pdev)
388 411
389 psy_cfg.supplied_to = mbc->pcf->pdata->batteries; 412 psy_cfg.supplied_to = mbc->pcf->pdata->batteries;
390 psy_cfg.num_supplicants = mbc->pcf->pdata->num_batteries; 413 psy_cfg.num_supplicants = mbc->pcf->pdata->num_batteries;
414 psy_cfg.drv_data = mbc;
391 415
392 /* Create power supplies */ 416 /* Create power supplies */
393 mbc->adapter.name = "adapter"; 417 mbc->adapter = power_supply_register(&pdev->dev,
394 mbc->adapter.type = POWER_SUPPLY_TYPE_MAINS; 418 &pcf50633_mbc_adapter_desc,
395 mbc->adapter.properties = power_props; 419 &psy_cfg);
396 mbc->adapter.num_properties = ARRAY_SIZE(power_props); 420 if (IS_ERR(mbc->adapter)) {
397 mbc->adapter.get_property = &adapter_get_property;
398
399 mbc->usb.name = "usb";
400 mbc->usb.type = POWER_SUPPLY_TYPE_USB;
401 mbc->usb.properties = power_props;
402 mbc->usb.num_properties = ARRAY_SIZE(power_props);
403 mbc->usb.get_property = usb_get_property;
404
405 mbc->ac.name = "ac";
406 mbc->ac.type = POWER_SUPPLY_TYPE_MAINS;
407 mbc->ac.properties = power_props;
408 mbc->ac.num_properties = ARRAY_SIZE(power_props);
409 mbc->ac.get_property = ac_get_property;
410
411 ret = power_supply_register(&pdev->dev, &mbc->adapter, &psy_cfg);
412 if (ret) {
413 dev_err(mbc->pcf->dev, "failed to register adapter\n"); 421 dev_err(mbc->pcf->dev, "failed to register adapter\n");
422 ret = PTR_ERR(mbc->adapter);
414 return ret; 423 return ret;
415 } 424 }
416 425
417 ret = power_supply_register(&pdev->dev, &mbc->usb, &psy_cfg); 426 mbc->usb = power_supply_register(&pdev->dev, &pcf50633_mbc_usb_desc,
418 if (ret) { 427 &psy_cfg);
428 if (IS_ERR(mbc->usb)) {
419 dev_err(mbc->pcf->dev, "failed to register usb\n"); 429 dev_err(mbc->pcf->dev, "failed to register usb\n");
420 power_supply_unregister(&mbc->adapter); 430 power_supply_unregister(mbc->adapter);
431 ret = PTR_ERR(mbc->usb);
421 return ret; 432 return ret;
422 } 433 }
423 434
424 ret = power_supply_register(&pdev->dev, &mbc->ac, &psy_cfg); 435 mbc->ac = power_supply_register(&pdev->dev, &pcf50633_mbc_ac_desc,
425 if (ret) { 436 &psy_cfg);
437 if (IS_ERR(mbc->ac)) {
426 dev_err(mbc->pcf->dev, "failed to register ac\n"); 438 dev_err(mbc->pcf->dev, "failed to register ac\n");
427 power_supply_unregister(&mbc->adapter); 439 power_supply_unregister(mbc->adapter);
428 power_supply_unregister(&mbc->usb); 440 power_supply_unregister(mbc->usb);
441 ret = PTR_ERR(mbc->ac);
429 return ret; 442 return ret;
430 } 443 }
431 444
@@ -452,9 +465,9 @@ static int pcf50633_mbc_remove(struct platform_device *pdev)
452 pcf50633_free_irq(mbc->pcf, mbc_irq_handlers[i]); 465 pcf50633_free_irq(mbc->pcf, mbc_irq_handlers[i]);
453 466
454 sysfs_remove_group(&pdev->dev.kobj, &mbc_attr_group); 467 sysfs_remove_group(&pdev->dev.kobj, &mbc_attr_group);
455 power_supply_unregister(&mbc->usb); 468 power_supply_unregister(mbc->usb);
456 power_supply_unregister(&mbc->adapter); 469 power_supply_unregister(mbc->adapter);
457 power_supply_unregister(&mbc->ac); 470 power_supply_unregister(mbc->ac);
458 471
459 return 0; 472 return 0;
460} 473}