aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power
diff options
context:
space:
mode:
authorSebastian Reichel <sre@debian.org>2013-11-24 11:49:30 -0500
committerAnton Vorontsov <anton@enomsg.org>2013-12-23 21:21:32 -0500
commitfaffd234cf85ddfe3959055bea0af2d21bc85f63 (patch)
tree63007a1f0c17a2bbfb23843ee8197f5f34a59b09 /drivers/power
parentabce97708a9b5ba897ad94fa289804d8af8d3ea9 (diff)
bq2415x_charger: Add DT support
This adds DT support to the bq2415x driver. Signed-off-by: Sebastian Reichel <sre@debian.org> Reviewed-by: Pavel Machek <pavel@ucw.cz> Signed-off-by: Anton Vorontsov <anton@enomsg.org>
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/bq2415x_charger.c72
1 files changed, 52 insertions, 20 deletions
diff --git a/drivers/power/bq2415x_charger.c b/drivers/power/bq2415x_charger.c
index 0bece7026056..79a37f6d3307 100644
--- a/drivers/power/bq2415x_charger.c
+++ b/drivers/power/bq2415x_charger.c
@@ -170,6 +170,7 @@ struct bq2415x_device {
170 struct bq2415x_platform_data init_data; 170 struct bq2415x_platform_data init_data;
171 struct power_supply charger; 171 struct power_supply charger;
172 struct delayed_work work; 172 struct delayed_work work;
173 struct power_supply *notify_psy;
173 struct notifier_block nb; 174 struct notifier_block nb;
174 enum bq2415x_mode reported_mode;/* mode reported by hook function */ 175 enum bq2415x_mode reported_mode;/* mode reported by hook function */
175 enum bq2415x_mode mode; /* current configured mode */ 176 enum bq2415x_mode mode; /* current configured mode */
@@ -810,7 +811,7 @@ static int bq2415x_notifier_call(struct notifier_block *nb,
810 if (val != PSY_EVENT_PROP_CHANGED) 811 if (val != PSY_EVENT_PROP_CHANGED)
811 return NOTIFY_OK; 812 return NOTIFY_OK;
812 813
813 if (strcmp(psy->name, bq->init_data.notify_device) != 0) 814 if (psy != bq->notify_psy)
814 return NOTIFY_OK; 815 return NOTIFY_OK;
815 816
816 dev_dbg(bq->dev, "notifier call was called\n"); 817 dev_dbg(bq->dev, "notifier call was called\n");
@@ -1542,10 +1543,11 @@ static int bq2415x_probe(struct i2c_client *client,
1542 int num; 1543 int num;
1543 char *name; 1544 char *name;
1544 struct bq2415x_device *bq; 1545 struct bq2415x_device *bq;
1545 struct power_supply *psy; 1546 struct device_node *np = client->dev.of_node;
1547 struct bq2415x_platform_data *pdata = client->dev.platform_data;
1546 1548
1547 if (!client->dev.platform_data) { 1549 if (!np && !pdata) {
1548 dev_err(&client->dev, "platform data not set\n"); 1550 dev_err(&client->dev, "platform data missing\n");
1549 return -ENODEV; 1551 return -ENODEV;
1550 } 1552 }
1551 1553
@@ -1570,6 +1572,17 @@ static int bq2415x_probe(struct i2c_client *client,
1570 goto error_2; 1572 goto error_2;
1571 } 1573 }
1572 1574
1575 if (np) {
1576 bq->notify_psy = power_supply_get_by_phandle(np, "ti,usb-charger-detection");
1577
1578 if (!bq->notify_psy)
1579 return -EPROBE_DEFER;
1580 }
1581 else if (pdata->notify_device)
1582 bq->notify_psy = power_supply_get_by_name(pdata->notify_device);
1583 else
1584 bq->notify_psy = NULL;
1585
1573 i2c_set_clientdata(client, bq); 1586 i2c_set_clientdata(client, bq);
1574 1587
1575 bq->id = num; 1588 bq->id = num;
@@ -1581,8 +1594,34 @@ static int bq2415x_probe(struct i2c_client *client,
1581 bq->autotimer = 0; 1594 bq->autotimer = 0;
1582 bq->automode = 0; 1595 bq->automode = 0;
1583 1596
1584 memcpy(&bq->init_data, client->dev.platform_data, 1597 if (np) {
1585 sizeof(bq->init_data)); 1598 ret = of_property_read_u32(np, "ti,current-limit",
1599 &bq->init_data.current_limit);
1600 if (ret)
1601 return ret;
1602 ret = of_property_read_u32(np, "ti,weak-battery-voltage",
1603 &bq->init_data.weak_battery_voltage);
1604 if (ret)
1605 return ret;
1606 ret = of_property_read_u32(np, "ti,battery-regulation-voltage",
1607 &bq->init_data.battery_regulation_voltage);
1608 if (ret)
1609 return ret;
1610 ret = of_property_read_u32(np, "ti,charge-current",
1611 &bq->init_data.charge_current);
1612 if (ret)
1613 return ret;
1614 ret = of_property_read_u32(np, "ti,termination-current",
1615 &bq->init_data.termination_current);
1616 if (ret)
1617 return ret;
1618 ret = of_property_read_u32(np, "ti,resistor-sense",
1619 &bq->init_data.resistor_sense);
1620 if (ret)
1621 return ret;
1622 } else {
1623 memcpy(&bq->init_data, pdata, sizeof(bq->init_data));
1624 }
1586 1625
1587 bq2415x_reset_chip(bq); 1626 bq2415x_reset_chip(bq);
1588 1627
@@ -1604,25 +1643,18 @@ static int bq2415x_probe(struct i2c_client *client,
1604 goto error_4; 1643 goto error_4;
1605 } 1644 }
1606 1645
1607 if (bq->init_data.notify_device) { 1646 if (bq->notify_psy) {
1608 bq->nb.notifier_call = bq2415x_notifier_call; 1647 bq->nb.notifier_call = bq2415x_notifier_call;
1609 ret = power_supply_reg_notifier(&bq->nb); 1648 ret = power_supply_reg_notifier(&bq->nb);
1610 if (ret) { 1649 if (ret) {
1611 dev_err(bq->dev, "failed to reg notifier: %d\n", ret); 1650 dev_err(bq->dev, "failed to reg notifier: %d\n", ret);
1612 goto error_5; 1651 goto error_5;
1613 } 1652 }
1614 psy = power_supply_get_by_name(bq->init_data.notify_device); 1653
1615 if (psy) { 1654 /* Query for initial reported_mode and set it */
1616 /* Query for initial reported_mode and set it */ 1655 bq2415x_notifier_call(&bq->nb, PSY_EVENT_PROP_CHANGED, bq->notify_psy);
1617 bq2415x_notifier_call(&bq->nb, 1656 bq2415x_set_mode(bq, bq->reported_mode);
1618 PSY_EVENT_PROP_CHANGED, psy); 1657
1619 bq2415x_set_mode(bq, bq->reported_mode);
1620 } else {
1621 dev_info(bq->dev, "notifier power supply device (%s) "
1622 "for automode is not registred yet... "
1623 "automode will not work without that device\n",
1624 bq->init_data.notify_device);
1625 }
1626 bq->automode = 1; 1658 bq->automode = 1;
1627 dev_info(bq->dev, "automode enabled\n"); 1659 dev_info(bq->dev, "automode enabled\n");
1628 } else { 1660 } else {
@@ -1657,7 +1689,7 @@ static int bq2415x_remove(struct i2c_client *client)
1657{ 1689{
1658 struct bq2415x_device *bq = i2c_get_clientdata(client); 1690 struct bq2415x_device *bq = i2c_get_clientdata(client);
1659 1691
1660 if (bq->init_data.notify_device) 1692 if (bq->notify_psy)
1661 power_supply_unreg_notifier(&bq->nb); 1693 power_supply_unreg_notifier(&bq->nb);
1662 1694
1663 bq2415x_sysfs_exit(bq); 1695 bq2415x_sysfs_exit(bq);