Skip to content

Commit 6c848d7

Browse files
committed
regulator: mp8859: Validate and log device identifier information
Ensure that we are talking to a device which reports the expected ID register information and log the OTP and revision information for diagnostic purposes. Tested-by: Markus Reichl <[email protected]> Signed-off-by: Mark Brown <[email protected]> Link: https://msgid.link/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent b65e914 commit 6c848d7

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

drivers/regulator/mp8859.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,46 @@ static int mp8859_i2c_probe(struct i2c_client *i2c)
147147
struct regulator_config config = {.dev = &i2c->dev};
148148
struct regmap *regmap = devm_regmap_init_i2c(i2c, &mp8859_regmap);
149149
struct regulator_dev *rdev;
150+
unsigned int val, rev;
150151

151152
if (IS_ERR(regmap)) {
152153
ret = PTR_ERR(regmap);
153154
dev_err(&i2c->dev, "regmap init failed: %d\n", ret);
154155
return ret;
155156
}
157+
158+
ret = regmap_read(regmap, MP8859_MFR_ID_REG, &val);
159+
if (ret != 0) {
160+
dev_err(&i2c->dev, "Failed to read manufacturer ID: %d\n", ret);
161+
return ret;
162+
}
163+
if (val != 0x9) {
164+
dev_err(&i2c->dev, "Manufacturer ID %x != 9\n", val);
165+
return -EINVAL;
166+
}
167+
168+
ret = regmap_read(regmap, MP8859_DEV_ID_REG, &val);
169+
if (ret != 0) {
170+
dev_err(&i2c->dev, "Failed to read device ID: %d\n", ret);
171+
return ret;
172+
}
173+
if (val != 0x58) {
174+
dev_err(&i2c->dev, "Manufacturer ID %x != 0x58\n", val);
175+
return -EINVAL;
176+
}
177+
178+
ret = regmap_read(regmap, MP8859_IC_REV_REG, &rev);
179+
if (ret != 0) {
180+
dev_err(&i2c->dev, "Failed to read device revision: %d\n", ret);
181+
return ret;
182+
}
183+
ret = regmap_read(regmap, MP8859_ID1_REG, &val);
184+
if (ret != 0) {
185+
dev_err(&i2c->dev, "Failed to read device ID1: %d\n", ret);
186+
return ret;
187+
}
188+
dev_info(&i2c->dev, "MP8859-%04d revision %d\n", val, rev);
189+
156190
rdev = devm_regulator_register(&i2c->dev, &mp8859_regulators[0],
157191
&config);
158192

0 commit comments

Comments
 (0)