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

mfd: sec-i2c: Rework platform data and regmap instantiating

Instead of a large open-coded switch statement, just add both regmap
config and device type to the OF match data. This allows us to have all
related information in one place, and avoids a long switch() statement.

Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: André Draszik <andre.draszik@linaro.org>
Link: https://lore.kernel.org/r/20250409-s2mpg10-v4-17-d66d5f39b6bf@linaro.org
Signed-off-by: Lee Jones <lee@kernel.org>

authored by

André Draszik and committed by
Lee Jones
aaaeae7e 0c33784a

+66 -67
+66 -67
drivers/mfd/sec-i2c.c
··· 20 20 #include <linux/mfd/samsung/s5m8767.h> 21 21 #include <linux/mod_devicetable.h> 22 22 #include <linux/module.h> 23 - #include <linux/of.h> 24 23 #include <linux/pm.h> 24 + #include <linux/property.h> 25 25 #include <linux/regmap.h> 26 26 #include "sec-core.h" 27 + 28 + struct sec_pmic_i2c_platform_data { 29 + const struct regmap_config *regmap_cfg; 30 + unsigned long device_type; 31 + }; 27 32 28 33 static bool s2mpa01_volatile(struct device *dev, unsigned int reg) 29 34 { ··· 141 136 142 137 static int sec_pmic_i2c_probe(struct i2c_client *client) 143 138 { 144 - const struct regmap_config *regmap; 145 - unsigned long device_type; 139 + const struct sec_pmic_i2c_platform_data *pdata; 146 140 struct regmap *regmap_pmic; 147 141 148 - device_type = (unsigned long)of_device_get_match_data(&client->dev); 149 - 150 - switch (device_type) { 151 - case S2DOS05: 152 - regmap = &s2dos05_regmap_config; 153 - break; 154 - case S2MPA01: 155 - regmap = &s2mpa01_regmap_config; 156 - break; 157 - case S2MPS11X: 158 - regmap = &s2mps11_regmap_config; 159 - break; 160 - case S2MPS13X: 161 - regmap = &s2mps13_regmap_config; 162 - break; 163 - case S2MPS14X: 164 - regmap = &s2mps14_regmap_config; 165 - break; 166 - case S2MPS15X: 167 - regmap = &s2mps15_regmap_config; 168 - break; 169 - case S2MPU02: 170 - regmap = &s2mpu02_regmap_config; 171 - break; 172 - case S2MPU05: 173 - regmap = &s2mpu05_regmap_config; 174 - break; 175 - case S5M8767X: 176 - regmap = &s5m8767_regmap_config; 177 - break; 178 - default: 142 + pdata = device_get_match_data(&client->dev); 143 + if (!pdata) 179 144 return dev_err_probe(&client->dev, -ENODEV, 180 - "Unsupported device type %lu\n", 181 - device_type); 182 - } 145 + "Unsupported device type\n"); 183 146 184 - regmap_pmic = devm_regmap_init_i2c(client, regmap); 147 + regmap_pmic = devm_regmap_init_i2c(client, pdata->regmap_cfg); 185 148 if (IS_ERR(regmap_pmic)) 186 149 return dev_err_probe(&client->dev, PTR_ERR(regmap_pmic), 187 150 "regmap init failed\n"); 188 151 189 - return sec_pmic_probe(&client->dev, device_type, client->irq, 152 + return sec_pmic_probe(&client->dev, pdata->device_type, client->irq, 190 153 regmap_pmic, client); 191 154 } 192 155 ··· 163 190 sec_pmic_shutdown(&i2c->dev); 164 191 } 165 192 193 + static const struct sec_pmic_i2c_platform_data s2dos05_data = { 194 + .regmap_cfg = &s2dos05_regmap_config, 195 + .device_type = S2DOS05 196 + }; 197 + 198 + static const struct sec_pmic_i2c_platform_data s2mpa01_data = { 199 + .regmap_cfg = &s2mpa01_regmap_config, 200 + .device_type = S2MPA01, 201 + }; 202 + 203 + static const struct sec_pmic_i2c_platform_data s2mps11_data = { 204 + .regmap_cfg = &s2mps11_regmap_config, 205 + .device_type = S2MPS11X, 206 + }; 207 + 208 + static const struct sec_pmic_i2c_platform_data s2mps13_data = { 209 + .regmap_cfg = &s2mps13_regmap_config, 210 + .device_type = S2MPS13X, 211 + }; 212 + 213 + static const struct sec_pmic_i2c_platform_data s2mps14_data = { 214 + .regmap_cfg = &s2mps14_regmap_config, 215 + .device_type = S2MPS14X, 216 + }; 217 + 218 + static const struct sec_pmic_i2c_platform_data s2mps15_data = { 219 + .regmap_cfg = &s2mps15_regmap_config, 220 + .device_type = S2MPS15X, 221 + }; 222 + 223 + static const struct sec_pmic_i2c_platform_data s2mpu02_data = { 224 + .regmap_cfg = &s2mpu02_regmap_config, 225 + .device_type = S2MPU02, 226 + }; 227 + 228 + static const struct sec_pmic_i2c_platform_data s2mpu05_data = { 229 + .regmap_cfg = &s2mpu05_regmap_config, 230 + .device_type = S2MPU05, 231 + }; 232 + 233 + static const struct sec_pmic_i2c_platform_data s5m8767_data = { 234 + .regmap_cfg = &s5m8767_regmap_config, 235 + .device_type = S5M8767X, 236 + }; 237 + 166 238 static const struct of_device_id sec_pmic_i2c_of_match[] = { 167 - { 168 - .compatible = "samsung,s2dos05", 169 - .data = (void *)S2DOS05, 170 - }, { 171 - .compatible = "samsung,s2mpa01-pmic", 172 - .data = (void *)S2MPA01, 173 - }, { 174 - .compatible = "samsung,s2mps11-pmic", 175 - .data = (void *)S2MPS11X, 176 - }, { 177 - .compatible = "samsung,s2mps13-pmic", 178 - .data = (void *)S2MPS13X, 179 - }, { 180 - .compatible = "samsung,s2mps14-pmic", 181 - .data = (void *)S2MPS14X, 182 - }, { 183 - .compatible = "samsung,s2mps15-pmic", 184 - .data = (void *)S2MPS15X, 185 - }, { 186 - .compatible = "samsung,s2mpu02-pmic", 187 - .data = (void *)S2MPU02, 188 - }, { 189 - .compatible = "samsung,s2mpu05-pmic", 190 - .data = (void *)S2MPU05, 191 - }, { 192 - .compatible = "samsung,s5m8767-pmic", 193 - .data = (void *)S5M8767X, 194 - }, 239 + { .compatible = "samsung,s2dos05", .data = &s2dos05_data, }, 240 + { .compatible = "samsung,s2mpa01-pmic", .data = &s2mpa01_data, }, 241 + { .compatible = "samsung,s2mps11-pmic", .data = &s2mps11_data, }, 242 + { .compatible = "samsung,s2mps13-pmic", .data = &s2mps13_data, }, 243 + { .compatible = "samsung,s2mps14-pmic", .data = &s2mps14_data, }, 244 + { .compatible = "samsung,s2mps15-pmic", .data = &s2mps15_data, }, 245 + { .compatible = "samsung,s2mpu02-pmic", .data = &s2mpu02_data, }, 246 + { .compatible = "samsung,s2mpu05-pmic", .data = &s2mpu05_data, }, 247 + { .compatible = "samsung,s5m8767-pmic", .data = &s5m8767_data, }, 195 248 { }, 196 249 }; 197 250 MODULE_DEVICE_TABLE(of, sec_pmic_i2c_of_match);