From aaaeae7e2ad1574fad3c68e249f02fa87a600516 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20Draszik?= Date: Wed, 9 Apr 2025 21:37:38 +0100 Subject: [PATCH] mfd: sec-i2c: Rework platform data and regmap instantiating MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: André Draszik Link: https://lore.kernel.org/r/20250409-s2mpg10-v4-17-d66d5f39b6bf@linaro.org Signed-off-by: Lee Jones --- drivers/mfd/sec-i2c.c | 133 +++++++++++++++++++++--------------------- 1 file changed, 66 insertions(+), 67 deletions(-) diff --git a/drivers/mfd/sec-i2c.c b/drivers/mfd/sec-i2c.c index 81f90003eea2..41b09f5e3c49 100644 --- a/drivers/mfd/sec-i2c.c +++ b/drivers/mfd/sec-i2c.c @@ -20,11 +20,16 @@ #include #include #include -#include #include +#include #include #include "sec-core.h" +struct sec_pmic_i2c_platform_data { + const struct regmap_config *regmap_cfg; + unsigned long device_type; +}; + static bool s2mpa01_volatile(struct device *dev, unsigned int reg) { switch (reg) { @@ -136,52 +141,20 @@ static const struct regmap_config s5m8767_regmap_config = { static int sec_pmic_i2c_probe(struct i2c_client *client) { - const struct regmap_config *regmap; - unsigned long device_type; + const struct sec_pmic_i2c_platform_data *pdata; struct regmap *regmap_pmic; - device_type = (unsigned long)of_device_get_match_data(&client->dev); - - switch (device_type) { - case S2DOS05: - regmap = &s2dos05_regmap_config; - break; - case S2MPA01: - regmap = &s2mpa01_regmap_config; - break; - case S2MPS11X: - regmap = &s2mps11_regmap_config; - break; - case S2MPS13X: - regmap = &s2mps13_regmap_config; - break; - case S2MPS14X: - regmap = &s2mps14_regmap_config; - break; - case S2MPS15X: - regmap = &s2mps15_regmap_config; - break; - case S2MPU02: - regmap = &s2mpu02_regmap_config; - break; - case S2MPU05: - regmap = &s2mpu05_regmap_config; - break; - case S5M8767X: - regmap = &s5m8767_regmap_config; - break; - default: + pdata = device_get_match_data(&client->dev); + if (!pdata) return dev_err_probe(&client->dev, -ENODEV, - "Unsupported device type %lu\n", - device_type); - } + "Unsupported device type\n"); - regmap_pmic = devm_regmap_init_i2c(client, regmap); + regmap_pmic = devm_regmap_init_i2c(client, pdata->regmap_cfg); if (IS_ERR(regmap_pmic)) return dev_err_probe(&client->dev, PTR_ERR(regmap_pmic), "regmap init failed\n"); - return sec_pmic_probe(&client->dev, device_type, client->irq, + return sec_pmic_probe(&client->dev, pdata->device_type, client->irq, regmap_pmic, client); } @@ -190,35 +163,61 @@ static void sec_pmic_i2c_shutdown(struct i2c_client *i2c) sec_pmic_shutdown(&i2c->dev); } +static const struct sec_pmic_i2c_platform_data s2dos05_data = { + .regmap_cfg = &s2dos05_regmap_config, + .device_type = S2DOS05 +}; + +static const struct sec_pmic_i2c_platform_data s2mpa01_data = { + .regmap_cfg = &s2mpa01_regmap_config, + .device_type = S2MPA01, +}; + +static const struct sec_pmic_i2c_platform_data s2mps11_data = { + .regmap_cfg = &s2mps11_regmap_config, + .device_type = S2MPS11X, +}; + +static const struct sec_pmic_i2c_platform_data s2mps13_data = { + .regmap_cfg = &s2mps13_regmap_config, + .device_type = S2MPS13X, +}; + +static const struct sec_pmic_i2c_platform_data s2mps14_data = { + .regmap_cfg = &s2mps14_regmap_config, + .device_type = S2MPS14X, +}; + +static const struct sec_pmic_i2c_platform_data s2mps15_data = { + .regmap_cfg = &s2mps15_regmap_config, + .device_type = S2MPS15X, +}; + +static const struct sec_pmic_i2c_platform_data s2mpu02_data = { + .regmap_cfg = &s2mpu02_regmap_config, + .device_type = S2MPU02, +}; + +static const struct sec_pmic_i2c_platform_data s2mpu05_data = { + .regmap_cfg = &s2mpu05_regmap_config, + .device_type = S2MPU05, +}; + +static const struct sec_pmic_i2c_platform_data s5m8767_data = { + .regmap_cfg = &s5m8767_regmap_config, + .device_type = S5M8767X, +}; + static const struct of_device_id sec_pmic_i2c_of_match[] = { - { - .compatible = "samsung,s2dos05", - .data = (void *)S2DOS05, - }, { - .compatible = "samsung,s2mpa01-pmic", - .data = (void *)S2MPA01, - }, { - .compatible = "samsung,s2mps11-pmic", - .data = (void *)S2MPS11X, - }, { - .compatible = "samsung,s2mps13-pmic", - .data = (void *)S2MPS13X, - }, { - .compatible = "samsung,s2mps14-pmic", - .data = (void *)S2MPS14X, - }, { - .compatible = "samsung,s2mps15-pmic", - .data = (void *)S2MPS15X, - }, { - .compatible = "samsung,s2mpu02-pmic", - .data = (void *)S2MPU02, - }, { - .compatible = "samsung,s2mpu05-pmic", - .data = (void *)S2MPU05, - }, { - .compatible = "samsung,s5m8767-pmic", - .data = (void *)S5M8767X, - }, + { .compatible = "samsung,s2dos05", .data = &s2dos05_data, }, + { .compatible = "samsung,s2mpa01-pmic", .data = &s2mpa01_data, }, + { .compatible = "samsung,s2mps11-pmic", .data = &s2mps11_data, }, + { .compatible = "samsung,s2mps13-pmic", .data = &s2mps13_data, }, + { .compatible = "samsung,s2mps14-pmic", .data = &s2mps14_data, }, + { .compatible = "samsung,s2mps15-pmic", .data = &s2mps15_data, }, + { .compatible = "samsung,s2mpu02-pmic", .data = &s2mpu02_data, }, + { .compatible = "samsung,s2mpu05-pmic", .data = &s2mpu05_data, }, + { .compatible = "samsung,s5m8767-pmic", .data = &s5m8767_data, }, { }, }; MODULE_DEVICE_TABLE(of, sec_pmic_i2c_of_match); -- 2.50.1