@@ -20,11 +20,16 @@
#include <linux/mfd/samsung/s5m8767.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
-#include <linux/of.h>
#include <linux/pm.h>
+#include <linux/property.h>
#include <linux/regmap.h>
#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) {
@@ -153,55 +158,23 @@ sec_pmic_i2c_parse_dt_pdata(struct device *dev,
static int sec_pmic_i2c_probe(struct i2c_client *client)
{
+ const struct sec_pmic_i2c_platform_data *pdata;
struct sec_pmic_probe_data probedata;
- const struct regmap_config *regmap;
- unsigned long device_type;
struct regmap *regmap_pmic;
- sec_pmic_i2c_parse_dt_pdata(&client->dev, &probedata);
-
- 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);
+ sec_pmic_i2c_parse_dt_pdata(&client->dev, &probedata);
+
+ 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, &probedata, client);
}
@@ -210,35 +183,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 = &s2mps15_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);
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. Signed-off-by: André Draszik <andre.draszik@linaro.org> --- drivers/mfd/sec-i2c.c | 137 +++++++++++++++++++++++++------------------------- 1 file changed, 68 insertions(+), 69 deletions(-)