Skip to content

Commit 74413bd

Browse files
srelag-linaro
authored andcommitted
mfd: rk8xx-i2c: Use device_get_match_data
Simplify the device identification logic by supplying the relevant information via of_match_data. This also removes the dev_info() printing the chip version, since that's supplied by the match data now. Due to lack of hardware this change is compile-tested only. Tested-by: Diederik de Haas <didi.debian@cknow.org> # Rock64, Quartz64 Model A + B Tested-by: Vincent Legoll <vincent.legoll@gmail.com> # Pine64 QuartzPro64 Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com> Link: https://lore.kernel.org/r/20230504173618.142075-7-sebastian.reichel@collabora.com Signed-off-by: Lee Jones <lee@kernel.org>
1 parent c20e8c5 commit 74413bd

2 files changed

Lines changed: 37 additions & 54 deletions

File tree

drivers/mfd/rk8xx-core.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,8 +597,6 @@ int rk8xx_probe(struct device *dev, int variant, unsigned int irq, struct regmap
597597
return -EINVAL;
598598
}
599599

600-
dev_info(dev, "chip id: 0x%x\n", (unsigned int)rk808->variant);
601-
602600
if (!irq)
603601
return dev_err_probe(dev, -EINVAL, "No interrupt support, no core IRQ\n");
604602

drivers/mfd/rk8xx-i2c.c

Lines changed: 37 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
#include <linux/of.h>
1717
#include <linux/regmap.h>
1818

19+
struct rk8xx_i2c_platform_data {
20+
const struct regmap_config *regmap_cfg;
21+
int variant;
22+
};
23+
1924
static bool rk808_is_volatile_reg(struct device *dev, unsigned int reg)
2025
{
2126
/*
@@ -103,66 +108,46 @@ static const struct regmap_config rk817_regmap_config = {
103108
.volatile_reg = rk817_is_volatile_reg,
104109
};
105110

106-
static int rk8xx_i2c_get_variant(struct i2c_client *client)
107-
{
108-
u8 pmic_id_msb, pmic_id_lsb;
109-
int msb, lsb;
110-
111-
if (of_device_is_compatible(client->dev.of_node, "rockchip,rk817") ||
112-
of_device_is_compatible(client->dev.of_node, "rockchip,rk809")) {
113-
pmic_id_msb = RK817_ID_MSB;
114-
pmic_id_lsb = RK817_ID_LSB;
115-
} else {
116-
pmic_id_msb = RK808_ID_MSB;
117-
pmic_id_lsb = RK808_ID_LSB;
118-
}
111+
static const struct rk8xx_i2c_platform_data rk805_data = {
112+
.regmap_cfg = &rk805_regmap_config,
113+
.variant = RK805_ID,
114+
};
115+
116+
static const struct rk8xx_i2c_platform_data rk808_data = {
117+
.regmap_cfg = &rk808_regmap_config,
118+
.variant = RK808_ID,
119+
};
119120

120-
/* Read chip variant */
121-
msb = i2c_smbus_read_byte_data(client, pmic_id_msb);
122-
if (msb < 0)
123-
return dev_err_probe(&client->dev, msb, "failed to read the chip id MSB\n");
121+
static const struct rk8xx_i2c_platform_data rk809_data = {
122+
.regmap_cfg = &rk817_regmap_config,
123+
.variant = RK809_ID,
124+
};
124125

125-
lsb = i2c_smbus_read_byte_data(client, pmic_id_lsb);
126-
if (lsb < 0)
127-
return dev_err_probe(&client->dev, lsb, "failed to read the chip id LSB\n");
126+
static const struct rk8xx_i2c_platform_data rk817_data = {
127+
.regmap_cfg = &rk817_regmap_config,
128+
.variant = RK817_ID,
129+
};
128130

129-
return ((msb << 8) | lsb) & RK8XX_ID_MSK;
130-
}
131+
static const struct rk8xx_i2c_platform_data rk818_data = {
132+
.regmap_cfg = &rk818_regmap_config,
133+
.variant = RK818_ID,
134+
};
131135

132136
static int rk8xx_i2c_probe(struct i2c_client *client)
133137
{
134-
const struct regmap_config *regmap_cfg;
138+
const struct rk8xx_i2c_platform_data *data;
135139
struct regmap *regmap;
136-
int variant;
137140

138-
variant = rk8xx_i2c_get_variant(client);
139-
if (variant < 0)
140-
return variant;
141-
142-
switch (variant) {
143-
case RK805_ID:
144-
regmap_cfg = &rk805_regmap_config;
145-
break;
146-
case RK808_ID:
147-
regmap_cfg = &rk808_regmap_config;
148-
break;
149-
case RK818_ID:
150-
regmap_cfg = &rk818_regmap_config;
151-
break;
152-
case RK809_ID:
153-
case RK817_ID:
154-
regmap_cfg = &rk817_regmap_config;
155-
break;
156-
default:
157-
return dev_err_probe(&client->dev, -EINVAL, "Unsupported RK8XX ID %x\n", variant);
158-
}
141+
data = device_get_match_data(&client->dev);
142+
if (!data)
143+
return -ENODEV;
159144

160-
regmap = devm_regmap_init_i2c(client, regmap_cfg);
145+
regmap = devm_regmap_init_i2c(client, data->regmap_cfg);
161146
if (IS_ERR(regmap))
162147
return dev_err_probe(&client->dev, PTR_ERR(regmap),
163148
"regmap initialization failed\n");
164149

165-
return rk8xx_probe(&client->dev, variant, client->irq, regmap);
150+
return rk8xx_probe(&client->dev, data->variant, client->irq, regmap);
166151
}
167152

168153
static void rk8xx_i2c_shutdown(struct i2c_client *client)
@@ -173,11 +158,11 @@ static void rk8xx_i2c_shutdown(struct i2c_client *client)
173158
static SIMPLE_DEV_PM_OPS(rk8xx_i2c_pm_ops, rk8xx_suspend, rk8xx_resume);
174159

175160
static const struct of_device_id rk8xx_i2c_of_match[] = {
176-
{ .compatible = "rockchip,rk805" },
177-
{ .compatible = "rockchip,rk808" },
178-
{ .compatible = "rockchip,rk809" },
179-
{ .compatible = "rockchip,rk817" },
180-
{ .compatible = "rockchip,rk818" },
161+
{ .compatible = "rockchip,rk805", .data = &rk805_data },
162+
{ .compatible = "rockchip,rk808", .data = &rk808_data },
163+
{ .compatible = "rockchip,rk809", .data = &rk809_data },
164+
{ .compatible = "rockchip,rk817", .data = &rk817_data },
165+
{ .compatible = "rockchip,rk818", .data = &rk818_data },
181166
{ },
182167
};
183168
MODULE_DEVICE_TABLE(of, rk8xx_i2c_of_match);

0 commit comments

Comments
 (0)