Skip to content

Commit 3dc4a29

Browse files
bijudassre
authored andcommitted
power: supply: bq24257_charger: Make chip type and name in sync
Add struct bq2425x_chip_info to make enum bq2425x_chip and it's name in sync and replace chip->info in struct bq24257_device and add struct bq2425x_chip_info as match data for OF/ACPI/ID tables. Simpilfy probe() by replacing acpi_match_device() and id lookup for retrieving match data by using i2c_get_match_data(). Drop bq2425x_chip_name as there is no user and also drop the comment related to syncing chip and name as it is taken care by struct bq2425x_chip_info. Signed-off-by: Biju Das <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sebastian Reichel <[email protected]>
1 parent ab907d9 commit 3dc4a29

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

drivers/power/supply/bq24257_charger.c

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,15 @@
3535

3636
#define BQ24257_ILIM_SET_DELAY 1000 /* msec */
3737

38-
/*
39-
* When adding support for new devices make sure that enum bq2425x_chip and
40-
* bq2425x_chip_name[] always stay in sync!
41-
*/
4238
enum bq2425x_chip {
4339
BQ24250,
4440
BQ24251,
4541
BQ24257,
4642
};
4743

48-
static const char *const bq2425x_chip_name[] = {
49-
"bq24250",
50-
"bq24251",
51-
"bq24257",
44+
struct bq2425x_chip_info {
45+
const char *const name;
46+
enum bq2425x_chip chip;
5247
};
5348

5449
enum bq24257_fields {
@@ -84,7 +79,7 @@ struct bq24257_device {
8479
struct device *dev;
8580
struct power_supply *charger;
8681

87-
enum bq2425x_chip chip;
82+
const struct bq2425x_chip_info *info;
8883

8984
struct regmap *rmap;
9085
struct regmap_field *rmap_fields[F_MAX_FIELDS];
@@ -329,7 +324,7 @@ static int bq24257_power_supply_get_property(struct power_supply *psy,
329324
break;
330325

331326
case POWER_SUPPLY_PROP_MODEL_NAME:
332-
val->strval = bq2425x_chip_name[bq->chip];
327+
val->strval = bq->info->name;
333328
break;
334329

335330
case POWER_SUPPLY_PROP_ONLINE:
@@ -947,10 +942,8 @@ static int bq24257_fw_probe(struct bq24257_device *bq)
947942

948943
static int bq24257_probe(struct i2c_client *client)
949944
{
950-
const struct i2c_device_id *id = i2c_client_get_device_id(client);
951945
struct i2c_adapter *adapter = client->adapter;
952946
struct device *dev = &client->dev;
953-
const struct acpi_device_id *acpi_id;
954947
struct bq24257_device *bq;
955948
int ret;
956949
int i;
@@ -967,17 +960,9 @@ static int bq24257_probe(struct i2c_client *client)
967960
bq->client = client;
968961
bq->dev = dev;
969962

970-
if (ACPI_HANDLE(dev)) {
971-
acpi_id = acpi_match_device(dev->driver->acpi_match_table,
972-
&client->dev);
973-
if (!acpi_id) {
974-
dev_err(dev, "Failed to match ACPI device\n");
975-
return -ENODEV;
976-
}
977-
bq->chip = (enum bq2425x_chip)acpi_id->driver_data;
978-
} else {
979-
bq->chip = (enum bq2425x_chip)id->driver_data;
980-
}
963+
bq->info = i2c_get_match_data(client);
964+
if (!bq->info)
965+
return dev_err_probe(dev, -ENODEV, "Failed to match device\n");
981966

982967
mutex_init(&bq->lock);
983968

@@ -1015,7 +1000,7 @@ static int bq24257_probe(struct i2c_client *client)
10151000
* used for the automatic setting of the input current limit setting so
10161001
* explicitly disable that feature.
10171002
*/
1018-
if (bq->chip == BQ24250)
1003+
if (bq->info->chip == BQ24250)
10191004
bq->iilimit_autoset_enable = false;
10201005

10211006
if (bq->iilimit_autoset_enable)
@@ -1028,7 +1013,7 @@ static int bq24257_probe(struct i2c_client *client)
10281013
* the PG state. We also use a SW-based approach for all other devices
10291014
* if the PG pin is either not defined or can't be probed.
10301015
*/
1031-
if (bq->chip != BQ24250)
1016+
if (bq->info->chip != BQ24250)
10321017
bq24257_pg_gpio_probe(bq);
10331018

10341019
if (PTR_ERR(bq->pg) == -EPROBE_DEFER)
@@ -1066,7 +1051,7 @@ static int bq24257_probe(struct i2c_client *client)
10661051
bq24257_irq_handler_thread,
10671052
IRQF_TRIGGER_FALLING |
10681053
IRQF_TRIGGER_RISING | IRQF_ONESHOT,
1069-
bq2425x_chip_name[bq->chip], bq);
1054+
bq->info->name, bq);
10701055
if (ret) {
10711056
dev_err(dev, "Failed to request IRQ #%d\n", client->irq);
10721057
return ret;
@@ -1132,27 +1117,42 @@ static const struct dev_pm_ops bq24257_pm = {
11321117
SET_SYSTEM_SLEEP_PM_OPS(bq24257_suspend, bq24257_resume)
11331118
};
11341119

1120+
static const struct bq2425x_chip_info bq24250_info = {
1121+
.name = "bq24250",
1122+
.chip = BQ24250,
1123+
};
1124+
1125+
static const struct bq2425x_chip_info bq24251_info = {
1126+
.name = "bq24251",
1127+
.chip = BQ24251,
1128+
};
1129+
1130+
static const struct bq2425x_chip_info bq24257_info = {
1131+
.name = "bq24257",
1132+
.chip = BQ24257,
1133+
};
1134+
11351135
static const struct i2c_device_id bq24257_i2c_ids[] = {
1136-
{ "bq24250", BQ24250 },
1137-
{ "bq24251", BQ24251 },
1138-
{ "bq24257", BQ24257 },
1136+
{ "bq24250", (kernel_ulong_t)&bq24250_info },
1137+
{ "bq24251", (kernel_ulong_t)&bq24251_info },
1138+
{ "bq24257", (kernel_ulong_t)&bq24257_info },
11391139
{},
11401140
};
11411141
MODULE_DEVICE_TABLE(i2c, bq24257_i2c_ids);
11421142

11431143
static const struct of_device_id bq24257_of_match[] __maybe_unused = {
1144-
{ .compatible = "ti,bq24250", },
1145-
{ .compatible = "ti,bq24251", },
1146-
{ .compatible = "ti,bq24257", },
1144+
{ .compatible = "ti,bq24250", &bq24250_info },
1145+
{ .compatible = "ti,bq24251", &bq24251_info },
1146+
{ .compatible = "ti,bq24257", &bq24257_info },
11471147
{ },
11481148
};
11491149
MODULE_DEVICE_TABLE(of, bq24257_of_match);
11501150

11511151
#ifdef CONFIG_ACPI
11521152
static const struct acpi_device_id bq24257_acpi_match[] = {
1153-
{ "BQ242500", BQ24250 },
1154-
{ "BQ242510", BQ24251 },
1155-
{ "BQ242570", BQ24257 },
1153+
{ "BQ242500", (kernel_ulong_t)&bq24250_info },
1154+
{ "BQ242510", (kernel_ulong_t)&bq24251_info },
1155+
{ "BQ242570", (kernel_ulong_t)&bq24257_info },
11561156
{},
11571157
};
11581158
MODULE_DEVICE_TABLE(acpi, bq24257_acpi_match);

0 commit comments

Comments
 (0)