diff options
author | Anda-Maria Nicolae <anda-maria.nicolae@intel.com> | 2015-05-12 05:11:33 -0400 |
---|---|---|
committer | Sebastian Reichel <sre@kernel.org> | 2015-05-23 14:03:00 -0400 |
commit | b01e7c3b803e6f0498d4db0b124e3b4efb5ac728 (patch) | |
tree | 3f83d18f21e37d9d3e68abc12804c0a1bff7e976 /drivers/power/bq2415x_charger.c | |
parent | f6d8b7744f692def009b9b354a39daf503bc9e00 (diff) |
power_supply: bq2415x_charger: Add ACPI support
Replace of_property_read_u32() with device_property_read_u32(), which is a
wrapper over ACPI and device tree enumeration methods.
When ACPI enumeration is used, automode is not supported. Therefore,
bq2415x_charger does not update its input current automatically, depending
on the USB port type that is connected to. Input current may be updated via
sysfs.
Signed-off-by: Anda-Maria Nicolae <anda-maria.nicolae@intel.com>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
Diffstat (limited to 'drivers/power/bq2415x_charger.c')
-rw-r--r-- | drivers/power/bq2415x_charger.c | 73 |
1 files changed, 55 insertions, 18 deletions
diff --git a/drivers/power/bq2415x_charger.c b/drivers/power/bq2415x_charger.c index 2cf8ec747fc2..e98dcb661cc9 100644 --- a/drivers/power/bq2415x_charger.c +++ b/drivers/power/bq2415x_charger.c | |||
@@ -35,6 +35,7 @@ | |||
35 | #include <linux/idr.h> | 35 | #include <linux/idr.h> |
36 | #include <linux/i2c.h> | 36 | #include <linux/i2c.h> |
37 | #include <linux/slab.h> | 37 | #include <linux/slab.h> |
38 | #include <linux/acpi.h> | ||
38 | 39 | ||
39 | #include <linux/power/bq2415x_charger.h> | 40 | #include <linux/power/bq2415x_charger.h> |
40 | 41 | ||
@@ -1530,13 +1531,14 @@ static int bq2415x_probe(struct i2c_client *client, | |||
1530 | { | 1531 | { |
1531 | int ret; | 1532 | int ret; |
1532 | int num; | 1533 | int num; |
1533 | char *name; | 1534 | char *name = NULL; |
1534 | struct bq2415x_device *bq; | 1535 | struct bq2415x_device *bq; |
1535 | struct device_node *np = client->dev.of_node; | 1536 | struct device_node *np = client->dev.of_node; |
1536 | struct bq2415x_platform_data *pdata = client->dev.platform_data; | 1537 | struct bq2415x_platform_data *pdata = client->dev.platform_data; |
1538 | const struct acpi_device_id *acpi_id = NULL; | ||
1537 | 1539 | ||
1538 | if (!np && !pdata) { | 1540 | if (!np && !pdata && !ACPI_HANDLE(&client->dev)) { |
1539 | dev_err(&client->dev, "platform data missing\n"); | 1541 | dev_err(&client->dev, "Neither devicetree, nor platform data, nor ACPI support\n"); |
1540 | return -ENODEV; | 1542 | return -ENODEV; |
1541 | } | 1543 | } |
1542 | 1544 | ||
@@ -1547,7 +1549,14 @@ static int bq2415x_probe(struct i2c_client *client, | |||
1547 | if (num < 0) | 1549 | if (num < 0) |
1548 | return num; | 1550 | return num; |
1549 | 1551 | ||
1550 | name = kasprintf(GFP_KERNEL, "%s-%d", id->name, num); | 1552 | if (id) { |
1553 | name = kasprintf(GFP_KERNEL, "%s-%d", id->name, num); | ||
1554 | } else if (ACPI_HANDLE(&client->dev)) { | ||
1555 | acpi_id = | ||
1556 | acpi_match_device(client->dev.driver->acpi_match_table, | ||
1557 | &client->dev); | ||
1558 | name = kasprintf(GFP_KERNEL, "%s-%d", acpi_id->id, num); | ||
1559 | } | ||
1551 | if (!name) { | 1560 | if (!name) { |
1552 | dev_err(&client->dev, "failed to allocate device name\n"); | 1561 | dev_err(&client->dev, "failed to allocate device name\n"); |
1553 | ret = -ENOMEM; | 1562 | ret = -ENOMEM; |
@@ -1573,7 +1582,7 @@ static int bq2415x_probe(struct i2c_client *client, | |||
1573 | ret = -EPROBE_DEFER; | 1582 | ret = -EPROBE_DEFER; |
1574 | goto error_2; | 1583 | goto error_2; |
1575 | } | 1584 | } |
1576 | } else if (pdata->notify_device) { | 1585 | } else if (pdata && pdata->notify_device) { |
1577 | bq->notify_psy = power_supply_get_by_name(pdata->notify_device); | 1586 | bq->notify_psy = power_supply_get_by_name(pdata->notify_device); |
1578 | } else { | 1587 | } else { |
1579 | bq->notify_psy = NULL; | 1588 | bq->notify_psy = NULL; |
@@ -1583,36 +1592,45 @@ static int bq2415x_probe(struct i2c_client *client, | |||
1583 | 1592 | ||
1584 | bq->id = num; | 1593 | bq->id = num; |
1585 | bq->dev = &client->dev; | 1594 | bq->dev = &client->dev; |
1586 | bq->chip = id->driver_data; | 1595 | if (id) |
1596 | bq->chip = id->driver_data; | ||
1597 | else if (ACPI_HANDLE(bq->dev)) | ||
1598 | bq->chip = acpi_id->driver_data; | ||
1587 | bq->name = name; | 1599 | bq->name = name; |
1588 | bq->mode = BQ2415X_MODE_OFF; | 1600 | bq->mode = BQ2415X_MODE_OFF; |
1589 | bq->reported_mode = BQ2415X_MODE_OFF; | 1601 | bq->reported_mode = BQ2415X_MODE_OFF; |
1590 | bq->autotimer = 0; | 1602 | bq->autotimer = 0; |
1591 | bq->automode = 0; | 1603 | bq->automode = 0; |
1592 | 1604 | ||
1593 | if (np) { | 1605 | if (np || ACPI_HANDLE(bq->dev)) { |
1594 | ret = of_property_read_u32(np, "ti,current-limit", | 1606 | ret = device_property_read_u32(bq->dev, |
1595 | &bq->init_data.current_limit); | 1607 | "ti,current-limit", |
1608 | &bq->init_data.current_limit); | ||
1596 | if (ret) | 1609 | if (ret) |
1597 | goto error_3; | 1610 | goto error_3; |
1598 | ret = of_property_read_u32(np, "ti,weak-battery-voltage", | 1611 | ret = device_property_read_u32(bq->dev, |
1599 | &bq->init_data.weak_battery_voltage); | 1612 | "ti,weak-battery-voltage", |
1613 | &bq->init_data.weak_battery_voltage); | ||
1600 | if (ret) | 1614 | if (ret) |
1601 | goto error_3; | 1615 | goto error_3; |
1602 | ret = of_property_read_u32(np, "ti,battery-regulation-voltage", | 1616 | ret = device_property_read_u32(bq->dev, |
1617 | "ti,battery-regulation-voltage", | ||
1603 | &bq->init_data.battery_regulation_voltage); | 1618 | &bq->init_data.battery_regulation_voltage); |
1604 | if (ret) | 1619 | if (ret) |
1605 | goto error_3; | 1620 | goto error_3; |
1606 | ret = of_property_read_u32(np, "ti,charge-current", | 1621 | ret = device_property_read_u32(bq->dev, |
1607 | &bq->init_data.charge_current); | 1622 | "ti,charge-current", |
1623 | &bq->init_data.charge_current); | ||
1608 | if (ret) | 1624 | if (ret) |
1609 | goto error_3; | 1625 | goto error_3; |
1610 | ret = of_property_read_u32(np, "ti,termination-current", | 1626 | ret = device_property_read_u32(bq->dev, |
1611 | &bq->init_data.termination_current); | 1627 | "ti,termination-current", |
1628 | &bq->init_data.termination_current); | ||
1612 | if (ret) | 1629 | if (ret) |
1613 | goto error_3; | 1630 | goto error_3; |
1614 | ret = of_property_read_u32(np, "ti,resistor-sense", | 1631 | ret = device_property_read_u32(bq->dev, |
1615 | &bq->init_data.resistor_sense); | 1632 | "ti,resistor-sense", |
1633 | &bq->init_data.resistor_sense); | ||
1616 | if (ret) | 1634 | if (ret) |
1617 | goto error_3; | 1635 | goto error_3; |
1618 | } else { | 1636 | } else { |
@@ -1728,9 +1746,28 @@ static const struct i2c_device_id bq2415x_i2c_id_table[] = { | |||
1728 | }; | 1746 | }; |
1729 | MODULE_DEVICE_TABLE(i2c, bq2415x_i2c_id_table); | 1747 | MODULE_DEVICE_TABLE(i2c, bq2415x_i2c_id_table); |
1730 | 1748 | ||
1749 | static const struct acpi_device_id bq2415x_i2c_acpi_match[] = { | ||
1750 | { "BQ2415X", BQUNKNOWN }, | ||
1751 | { "BQ241500", BQ24150 }, | ||
1752 | { "BQA24150", BQ24150A }, | ||
1753 | { "BQ241510", BQ24151 }, | ||
1754 | { "BQA24151", BQ24151A }, | ||
1755 | { "BQ241520", BQ24152 }, | ||
1756 | { "BQ241530", BQ24153 }, | ||
1757 | { "BQA24153", BQ24153A }, | ||
1758 | { "BQ241550", BQ24155 }, | ||
1759 | { "BQ241560", BQ24156 }, | ||
1760 | { "BQA24156", BQ24156A }, | ||
1761 | { "BQS24157", BQ24157S }, | ||
1762 | { "BQ241580", BQ24158 }, | ||
1763 | {}, | ||
1764 | }; | ||
1765 | MODULE_DEVICE_TABLE(acpi, bq2415x_i2c_acpi_match); | ||
1766 | |||
1731 | static struct i2c_driver bq2415x_driver = { | 1767 | static struct i2c_driver bq2415x_driver = { |
1732 | .driver = { | 1768 | .driver = { |
1733 | .name = "bq2415x-charger", | 1769 | .name = "bq2415x-charger", |
1770 | .acpi_match_table = ACPI_PTR(bq2415x_i2c_acpi_match), | ||
1734 | }, | 1771 | }, |
1735 | .probe = bq2415x_probe, | 1772 | .probe = bq2415x_probe, |
1736 | .remove = bq2415x_remove, | 1773 | .remove = bq2415x_remove, |