Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <biju.das.jz@bp.renesas.com>
Link: https://lore.kernel.org/r/20230902193331.83672-2-biju.das.jz@bp.renesas.com
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

authored by

Biju Das and committed by
Sebastian Reichel
3dc4a291 ab907d99

+35 -35
+35 -35
drivers/power/supply/bq24257_charger.c
··· 35 35 36 36 #define BQ24257_ILIM_SET_DELAY 1000 /* msec */ 37 37 38 - /* 39 - * When adding support for new devices make sure that enum bq2425x_chip and 40 - * bq2425x_chip_name[] always stay in sync! 41 - */ 42 38 enum bq2425x_chip { 43 39 BQ24250, 44 40 BQ24251, 45 41 BQ24257, 46 42 }; 47 43 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; 52 47 }; 53 48 54 49 enum bq24257_fields { ··· 79 84 struct device *dev; 80 85 struct power_supply *charger; 81 86 82 - enum bq2425x_chip chip; 87 + const struct bq2425x_chip_info *info; 83 88 84 89 struct regmap *rmap; 85 90 struct regmap_field *rmap_fields[F_MAX_FIELDS]; ··· 324 329 break; 325 330 326 331 case POWER_SUPPLY_PROP_MODEL_NAME: 327 - val->strval = bq2425x_chip_name[bq->chip]; 332 + val->strval = bq->info->name; 328 333 break; 329 334 330 335 case POWER_SUPPLY_PROP_ONLINE: ··· 942 947 943 948 static int bq24257_probe(struct i2c_client *client) 944 949 { 945 - const struct i2c_device_id *id = i2c_client_get_device_id(client); 946 950 struct i2c_adapter *adapter = client->adapter; 947 951 struct device *dev = &client->dev; 948 - const struct acpi_device_id *acpi_id; 949 952 struct bq24257_device *bq; 950 953 int ret; 951 954 int i; ··· 960 967 bq->client = client; 961 968 bq->dev = dev; 962 969 963 - if (ACPI_HANDLE(dev)) { 964 - acpi_id = acpi_match_device(dev->driver->acpi_match_table, 965 - &client->dev); 966 - if (!acpi_id) { 967 - dev_err(dev, "Failed to match ACPI device\n"); 968 - return -ENODEV; 969 - } 970 - bq->chip = (enum bq2425x_chip)acpi_id->driver_data; 971 - } else { 972 - bq->chip = (enum bq2425x_chip)id->driver_data; 973 - } 970 + bq->info = i2c_get_match_data(client); 971 + if (!bq->info) 972 + return dev_err_probe(dev, -ENODEV, "Failed to match device\n"); 974 973 975 974 mutex_init(&bq->lock); 976 975 ··· 1000 1015 * used for the automatic setting of the input current limit setting so 1001 1016 * explicitly disable that feature. 1002 1017 */ 1003 - if (bq->chip == BQ24250) 1018 + if (bq->info->chip == BQ24250) 1004 1019 bq->iilimit_autoset_enable = false; 1005 1020 1006 1021 if (bq->iilimit_autoset_enable) ··· 1013 1028 * the PG state. We also use a SW-based approach for all other devices 1014 1029 * if the PG pin is either not defined or can't be probed. 1015 1030 */ 1016 - if (bq->chip != BQ24250) 1031 + if (bq->info->chip != BQ24250) 1017 1032 bq24257_pg_gpio_probe(bq); 1018 1033 1019 1034 if (PTR_ERR(bq->pg) == -EPROBE_DEFER) ··· 1051 1066 bq24257_irq_handler_thread, 1052 1067 IRQF_TRIGGER_FALLING | 1053 1068 IRQF_TRIGGER_RISING | IRQF_ONESHOT, 1054 - bq2425x_chip_name[bq->chip], bq); 1069 + bq->info->name, bq); 1055 1070 if (ret) { 1056 1071 dev_err(dev, "Failed to request IRQ #%d\n", client->irq); 1057 1072 return ret; ··· 1117 1132 SET_SYSTEM_SLEEP_PM_OPS(bq24257_suspend, bq24257_resume) 1118 1133 }; 1119 1134 1135 + static const struct bq2425x_chip_info bq24250_info = { 1136 + .name = "bq24250", 1137 + .chip = BQ24250, 1138 + }; 1139 + 1140 + static const struct bq2425x_chip_info bq24251_info = { 1141 + .name = "bq24251", 1142 + .chip = BQ24251, 1143 + }; 1144 + 1145 + static const struct bq2425x_chip_info bq24257_info = { 1146 + .name = "bq24257", 1147 + .chip = BQ24257, 1148 + }; 1149 + 1120 1150 static const struct i2c_device_id bq24257_i2c_ids[] = { 1121 - { "bq24250", BQ24250 }, 1122 - { "bq24251", BQ24251 }, 1123 - { "bq24257", BQ24257 }, 1151 + { "bq24250", (kernel_ulong_t)&bq24250_info }, 1152 + { "bq24251", (kernel_ulong_t)&bq24251_info }, 1153 + { "bq24257", (kernel_ulong_t)&bq24257_info }, 1124 1154 {}, 1125 1155 }; 1126 1156 MODULE_DEVICE_TABLE(i2c, bq24257_i2c_ids); 1127 1157 1128 1158 static const struct of_device_id bq24257_of_match[] __maybe_unused = { 1129 - { .compatible = "ti,bq24250", }, 1130 - { .compatible = "ti,bq24251", }, 1131 - { .compatible = "ti,bq24257", }, 1159 + { .compatible = "ti,bq24250", &bq24250_info }, 1160 + { .compatible = "ti,bq24251", &bq24251_info }, 1161 + { .compatible = "ti,bq24257", &bq24257_info }, 1132 1162 { }, 1133 1163 }; 1134 1164 MODULE_DEVICE_TABLE(of, bq24257_of_match); 1135 1165 1136 1166 #ifdef CONFIG_ACPI 1137 1167 static const struct acpi_device_id bq24257_acpi_match[] = { 1138 - { "BQ242500", BQ24250 }, 1139 - { "BQ242510", BQ24251 }, 1140 - { "BQ242570", BQ24257 }, 1168 + { "BQ242500", (kernel_ulong_t)&bq24250_info }, 1169 + { "BQ242510", (kernel_ulong_t)&bq24251_info }, 1170 + { "BQ242570", (kernel_ulong_t)&bq24257_info }, 1141 1171 {}, 1142 1172 }; 1143 1173 MODULE_DEVICE_TABLE(acpi, bq24257_acpi_match);