Skip to content

Commit b01e7c3

Browse files
andanicolaesre
authored andcommitted
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 <[email protected]> Signed-off-by: Sebastian Reichel <[email protected]>
1 parent f6d8b77 commit b01e7c3

File tree

1 file changed

+55
-18
lines changed

1 file changed

+55
-18
lines changed

drivers/power/bq2415x_charger.c

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <linux/idr.h>
3636
#include <linux/i2c.h>
3737
#include <linux/slab.h>
38+
#include <linux/acpi.h>
3839

3940
#include <linux/power/bq2415x_charger.h>
4041

@@ -1530,13 +1531,14 @@ static int bq2415x_probe(struct i2c_client *client,
15301531
{
15311532
int ret;
15321533
int num;
1533-
char *name;
1534+
char *name = NULL;
15341535
struct bq2415x_device *bq;
15351536
struct device_node *np = client->dev.of_node;
15361537
struct bq2415x_platform_data *pdata = client->dev.platform_data;
1538+
const struct acpi_device_id *acpi_id = NULL;
15371539

1538-
if (!np && !pdata) {
1539-
dev_err(&client->dev, "platform data missing\n");
1540+
if (!np && !pdata && !ACPI_HANDLE(&client->dev)) {
1541+
dev_err(&client->dev, "Neither devicetree, nor platform data, nor ACPI support\n");
15401542
return -ENODEV;
15411543
}
15421544

@@ -1547,7 +1549,14 @@ static int bq2415x_probe(struct i2c_client *client,
15471549
if (num < 0)
15481550
return num;
15491551

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+
}
15511560
if (!name) {
15521561
dev_err(&client->dev, "failed to allocate device name\n");
15531562
ret = -ENOMEM;
@@ -1573,7 +1582,7 @@ static int bq2415x_probe(struct i2c_client *client,
15731582
ret = -EPROBE_DEFER;
15741583
goto error_2;
15751584
}
1576-
} else if (pdata->notify_device) {
1585+
} else if (pdata && pdata->notify_device) {
15771586
bq->notify_psy = power_supply_get_by_name(pdata->notify_device);
15781587
} else {
15791588
bq->notify_psy = NULL;
@@ -1583,36 +1592,45 @@ static int bq2415x_probe(struct i2c_client *client,
15831592

15841593
bq->id = num;
15851594
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;
15871599
bq->name = name;
15881600
bq->mode = BQ2415X_MODE_OFF;
15891601
bq->reported_mode = BQ2415X_MODE_OFF;
15901602
bq->autotimer = 0;
15911603
bq->automode = 0;
15921604

1593-
if (np) {
1594-
ret = of_property_read_u32(np, "ti,current-limit",
1595-
&bq->init_data.current_limit);
1605+
if (np || ACPI_HANDLE(bq->dev)) {
1606+
ret = device_property_read_u32(bq->dev,
1607+
"ti,current-limit",
1608+
&bq->init_data.current_limit);
15961609
if (ret)
15971610
goto error_3;
1598-
ret = of_property_read_u32(np, "ti,weak-battery-voltage",
1599-
&bq->init_data.weak_battery_voltage);
1611+
ret = device_property_read_u32(bq->dev,
1612+
"ti,weak-battery-voltage",
1613+
&bq->init_data.weak_battery_voltage);
16001614
if (ret)
16011615
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",
16031618
&bq->init_data.battery_regulation_voltage);
16041619
if (ret)
16051620
goto error_3;
1606-
ret = of_property_read_u32(np, "ti,charge-current",
1607-
&bq->init_data.charge_current);
1621+
ret = device_property_read_u32(bq->dev,
1622+
"ti,charge-current",
1623+
&bq->init_data.charge_current);
16081624
if (ret)
16091625
goto error_3;
1610-
ret = of_property_read_u32(np, "ti,termination-current",
1611-
&bq->init_data.termination_current);
1626+
ret = device_property_read_u32(bq->dev,
1627+
"ti,termination-current",
1628+
&bq->init_data.termination_current);
16121629
if (ret)
16131630
goto error_3;
1614-
ret = of_property_read_u32(np, "ti,resistor-sense",
1615-
&bq->init_data.resistor_sense);
1631+
ret = device_property_read_u32(bq->dev,
1632+
"ti,resistor-sense",
1633+
&bq->init_data.resistor_sense);
16161634
if (ret)
16171635
goto error_3;
16181636
} else {
@@ -1728,9 +1746,28 @@ static const struct i2c_device_id bq2415x_i2c_id_table[] = {
17281746
};
17291747
MODULE_DEVICE_TABLE(i2c, bq2415x_i2c_id_table);
17301748

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+
17311767
static struct i2c_driver bq2415x_driver = {
17321768
.driver = {
17331769
.name = "bq2415x-charger",
1770+
.acpi_match_table = ACPI_PTR(bq2415x_i2c_acpi_match),
17341771
},
17351772
.probe = bq2415x_probe,
17361773
.remove = bq2415x_remove,

0 commit comments

Comments
 (0)