Skip to content

Commit aaaeae7

Browse files
andredlag-linaro
authored andcommitted
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 <[email protected]> Signed-off-by: André Draszik <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lee Jones <[email protected]>
1 parent 0c33784 commit aaaeae7

File tree

1 file changed

+66
-67
lines changed

1 file changed

+66
-67
lines changed

drivers/mfd/sec-i2c.c

Lines changed: 66 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,16 @@
2020
#include <linux/mfd/samsung/s5m8767.h>
2121
#include <linux/mod_devicetable.h>
2222
#include <linux/module.h>
23-
#include <linux/of.h>
2423
#include <linux/pm.h>
24+
#include <linux/property.h>
2525
#include <linux/regmap.h>
2626
#include "sec-core.h"
2727

28+
struct sec_pmic_i2c_platform_data {
29+
const struct regmap_config *regmap_cfg;
30+
unsigned long device_type;
31+
};
32+
2833
static bool s2mpa01_volatile(struct device *dev, unsigned int reg)
2934
{
3035
switch (reg) {
@@ -136,52 +141,20 @@ static const struct regmap_config s5m8767_regmap_config = {
136141

137142
static int sec_pmic_i2c_probe(struct i2c_client *client)
138143
{
139-
const struct regmap_config *regmap;
140-
unsigned long device_type;
144+
const struct sec_pmic_i2c_platform_data *pdata;
141145
struct regmap *regmap_pmic;
142146

143-
device_type = (unsigned long)of_device_get_match_data(&client->dev);
144-
145-
switch (device_type) {
146-
case S2DOS05:
147-
regmap = &s2dos05_regmap_config;
148-
break;
149-
case S2MPA01:
150-
regmap = &s2mpa01_regmap_config;
151-
break;
152-
case S2MPS11X:
153-
regmap = &s2mps11_regmap_config;
154-
break;
155-
case S2MPS13X:
156-
regmap = &s2mps13_regmap_config;
157-
break;
158-
case S2MPS14X:
159-
regmap = &s2mps14_regmap_config;
160-
break;
161-
case S2MPS15X:
162-
regmap = &s2mps15_regmap_config;
163-
break;
164-
case S2MPU02:
165-
regmap = &s2mpu02_regmap_config;
166-
break;
167-
case S2MPU05:
168-
regmap = &s2mpu05_regmap_config;
169-
break;
170-
case S5M8767X:
171-
regmap = &s5m8767_regmap_config;
172-
break;
173-
default:
147+
pdata = device_get_match_data(&client->dev);
148+
if (!pdata)
174149
return dev_err_probe(&client->dev, -ENODEV,
175-
"Unsupported device type %lu\n",
176-
device_type);
177-
}
150+
"Unsupported device type\n");
178151

179-
regmap_pmic = devm_regmap_init_i2c(client, regmap);
152+
regmap_pmic = devm_regmap_init_i2c(client, pdata->regmap_cfg);
180153
if (IS_ERR(regmap_pmic))
181154
return dev_err_probe(&client->dev, PTR_ERR(regmap_pmic),
182155
"regmap init failed\n");
183156

184-
return sec_pmic_probe(&client->dev, device_type, client->irq,
157+
return sec_pmic_probe(&client->dev, pdata->device_type, client->irq,
185158
regmap_pmic, client);
186159
}
187160

@@ -190,35 +163,61 @@ static void sec_pmic_i2c_shutdown(struct i2c_client *i2c)
190163
sec_pmic_shutdown(&i2c->dev);
191164
}
192165

166+
static const struct sec_pmic_i2c_platform_data s2dos05_data = {
167+
.regmap_cfg = &s2dos05_regmap_config,
168+
.device_type = S2DOS05
169+
};
170+
171+
static const struct sec_pmic_i2c_platform_data s2mpa01_data = {
172+
.regmap_cfg = &s2mpa01_regmap_config,
173+
.device_type = S2MPA01,
174+
};
175+
176+
static const struct sec_pmic_i2c_platform_data s2mps11_data = {
177+
.regmap_cfg = &s2mps11_regmap_config,
178+
.device_type = S2MPS11X,
179+
};
180+
181+
static const struct sec_pmic_i2c_platform_data s2mps13_data = {
182+
.regmap_cfg = &s2mps13_regmap_config,
183+
.device_type = S2MPS13X,
184+
};
185+
186+
static const struct sec_pmic_i2c_platform_data s2mps14_data = {
187+
.regmap_cfg = &s2mps14_regmap_config,
188+
.device_type = S2MPS14X,
189+
};
190+
191+
static const struct sec_pmic_i2c_platform_data s2mps15_data = {
192+
.regmap_cfg = &s2mps15_regmap_config,
193+
.device_type = S2MPS15X,
194+
};
195+
196+
static const struct sec_pmic_i2c_platform_data s2mpu02_data = {
197+
.regmap_cfg = &s2mpu02_regmap_config,
198+
.device_type = S2MPU02,
199+
};
200+
201+
static const struct sec_pmic_i2c_platform_data s2mpu05_data = {
202+
.regmap_cfg = &s2mpu05_regmap_config,
203+
.device_type = S2MPU05,
204+
};
205+
206+
static const struct sec_pmic_i2c_platform_data s5m8767_data = {
207+
.regmap_cfg = &s5m8767_regmap_config,
208+
.device_type = S5M8767X,
209+
};
210+
193211
static const struct of_device_id sec_pmic_i2c_of_match[] = {
194-
{
195-
.compatible = "samsung,s2dos05",
196-
.data = (void *)S2DOS05,
197-
}, {
198-
.compatible = "samsung,s2mpa01-pmic",
199-
.data = (void *)S2MPA01,
200-
}, {
201-
.compatible = "samsung,s2mps11-pmic",
202-
.data = (void *)S2MPS11X,
203-
}, {
204-
.compatible = "samsung,s2mps13-pmic",
205-
.data = (void *)S2MPS13X,
206-
}, {
207-
.compatible = "samsung,s2mps14-pmic",
208-
.data = (void *)S2MPS14X,
209-
}, {
210-
.compatible = "samsung,s2mps15-pmic",
211-
.data = (void *)S2MPS15X,
212-
}, {
213-
.compatible = "samsung,s2mpu02-pmic",
214-
.data = (void *)S2MPU02,
215-
}, {
216-
.compatible = "samsung,s2mpu05-pmic",
217-
.data = (void *)S2MPU05,
218-
}, {
219-
.compatible = "samsung,s5m8767-pmic",
220-
.data = (void *)S5M8767X,
221-
},
212+
{ .compatible = "samsung,s2dos05", .data = &s2dos05_data, },
213+
{ .compatible = "samsung,s2mpa01-pmic", .data = &s2mpa01_data, },
214+
{ .compatible = "samsung,s2mps11-pmic", .data = &s2mps11_data, },
215+
{ .compatible = "samsung,s2mps13-pmic", .data = &s2mps13_data, },
216+
{ .compatible = "samsung,s2mps14-pmic", .data = &s2mps14_data, },
217+
{ .compatible = "samsung,s2mps15-pmic", .data = &s2mps15_data, },
218+
{ .compatible = "samsung,s2mpu02-pmic", .data = &s2mpu02_data, },
219+
{ .compatible = "samsung,s2mpu05-pmic", .data = &s2mpu05_data, },
220+
{ .compatible = "samsung,s5m8767-pmic", .data = &s5m8767_data, },
222221
{ },
223222
};
224223
MODULE_DEVICE_TABLE(of, sec_pmic_i2c_of_match);

0 commit comments

Comments
 (0)