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

power: supply: bq2515x: Simpilfy bq2515x_read_properties() and probe()

Add struct bq2515x_info and replace device_id->info in struct
bq2515x_device.

Simpilfy bq2515x_read_properties() and probe() by adding struct
bq2425x_chip_info as match data for OF/ID tables and use
i2c_get_match_data for retrieving match data instead of ID lookup.

Drop enum bq2515x_id as there is no user.

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
Link: https://lore.kernel.org/r/20230902200518.91585-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
ef2730fb 92bbb93a

+29 -32
+29 -32
drivers/power/supply/bq2515x_charger.c
··· 147 147 int iprechg; 148 148 }; 149 149 150 - enum bq2515x_id { 151 - BQ25150, 152 - BQ25155, 150 + /** 151 + * struct bq2515x_info - 152 + * @regmap_config: register map config 153 + * @ilim: input current limit 154 + */ 155 + struct bq2515x_info { 156 + const struct regmap_config *regmap_config; 157 + int ilim; 153 158 }; 154 159 155 160 /** ··· 169 164 * @ac_detect_gpio: power good (PG) pin 170 165 * @ce_gpio: charge enable (CE) pin 171 166 * 167 + * @info: device info 172 168 * @model_name: string value describing device model 173 - * @device_id: value of device_id 174 169 * @mains_online: boolean value indicating power supply online 175 170 * 176 171 * @init_data: charger initialization data structure ··· 186 181 struct gpio_desc *ac_detect_gpio; 187 182 struct gpio_desc *ce_gpio; 188 183 184 + const struct bq2515x_info *info; 189 185 char model_name[I2C_NAME_SIZE]; 190 - int device_id; 191 186 bool mains_online; 192 187 193 188 struct bq2515x_init_data init_data; ··· 1003 998 ret = device_property_read_u32(bq2515x->dev, 1004 999 "input-current-limit-microamp", 1005 1000 &bq2515x->init_data.ilim); 1006 - if (ret) { 1007 - switch (bq2515x->device_id) { 1008 - case BQ25150: 1009 - bq2515x->init_data.ilim = BQ25150_DEFAULT_ILIM_UA; 1010 - break; 1011 - case BQ25155: 1012 - bq2515x->init_data.ilim = BQ25155_DEFAULT_ILIM_UA; 1013 - break; 1014 - } 1015 - } 1001 + if (ret) 1002 + bq2515x->init_data.ilim = bq2515x->info->ilim; 1016 1003 1017 1004 bq2515x->ac_detect_gpio = devm_gpiod_get_optional(bq2515x->dev, 1018 1005 "ac-detect", GPIOD_IN); ··· 1091 1094 1092 1095 strncpy(bq2515x->model_name, id->name, I2C_NAME_SIZE); 1093 1096 1094 - bq2515x->device_id = id->driver_data; 1095 - 1096 - switch (bq2515x->device_id) { 1097 - case BQ25150: 1098 - bq2515x->regmap = devm_regmap_init_i2c(client, 1099 - &bq25150_regmap_config); 1100 - break; 1101 - case BQ25155: 1102 - bq2515x->regmap = devm_regmap_init_i2c(client, 1103 - &bq25155_regmap_config); 1104 - break; 1105 - } 1106 - 1097 + bq2515x->info = i2c_get_match_data(client); 1098 + bq2515x->regmap = devm_regmap_init_i2c(client, 1099 + bq2515x->info->regmap_config); 1107 1100 if (IS_ERR(bq2515x->regmap)) { 1108 1101 dev_err(dev, "failed to allocate register map\n"); 1109 1102 return PTR_ERR(bq2515x->regmap); ··· 1126 1139 return 0; 1127 1140 } 1128 1141 1142 + static const struct bq2515x_info bq25150 = { 1143 + .regmap_config = &bq25150_regmap_config, 1144 + .ilim = BQ25150_DEFAULT_ILIM_UA, 1145 + }; 1146 + 1147 + static const struct bq2515x_info bq25155 = { 1148 + .regmap_config = &bq25155_regmap_config, 1149 + .ilim = BQ25155_DEFAULT_ILIM_UA, 1150 + }; 1151 + 1129 1152 static const struct i2c_device_id bq2515x_i2c_ids[] = { 1130 - { "bq25150", BQ25150, }, 1131 - { "bq25155", BQ25155, }, 1153 + { "bq25150", (kernel_ulong_t)&bq25150 }, 1154 + { "bq25155", (kernel_ulong_t)&bq25155 }, 1132 1155 {}, 1133 1156 }; 1134 1157 MODULE_DEVICE_TABLE(i2c, bq2515x_i2c_ids); 1135 1158 1136 1159 static const struct of_device_id bq2515x_of_match[] = { 1137 - { .compatible = "ti,bq25150", }, 1138 - { .compatible = "ti,bq25155", }, 1160 + { .compatible = "ti,bq25150", .data = &bq25150 }, 1161 + { .compatible = "ti,bq25155", .data = &bq25155 }, 1139 1162 { }, 1140 1163 }; 1141 1164 MODULE_DEVICE_TABLE(of, bq2515x_of_match);