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 <m.reichl@fivetechno.de>
Signed-off-by: Mark Brown <broonie@kernel.org>
Link: https://msgid.link/r/20240225-regulator-mp8859-v1-2-68ee2c839ded@kernel.org
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Mark Brown 2024-02-25 14:59:28 +00:00
parent b65e9149bd
commit 6c848d772e
No known key found for this signature in database
GPG key ID: 24D68B725D5487D0

View file

@ -147,12 +147,46 @@ static int mp8859_i2c_probe(struct i2c_client *i2c)
struct regulator_config config = {.dev = &i2c->dev};
struct regmap *regmap = devm_regmap_init_i2c(i2c, &mp8859_regmap);
struct regulator_dev *rdev;
unsigned int val, rev;
if (IS_ERR(regmap)) {
ret = PTR_ERR(regmap);
dev_err(&i2c->dev, "regmap init failed: %d\n", ret);
return ret;
}
ret = regmap_read(regmap, MP8859_MFR_ID_REG, &val);
if (ret != 0) {
dev_err(&i2c->dev, "Failed to read manufacturer ID: %d\n", ret);
return ret;
}
if (val != 0x9) {
dev_err(&i2c->dev, "Manufacturer ID %x != 9\n", val);
return -EINVAL;
}
ret = regmap_read(regmap, MP8859_DEV_ID_REG, &val);
if (ret != 0) {
dev_err(&i2c->dev, "Failed to read device ID: %d\n", ret);
return ret;
}
if (val != 0x58) {
dev_err(&i2c->dev, "Manufacturer ID %x != 0x58\n", val);
return -EINVAL;
}
ret = regmap_read(regmap, MP8859_IC_REV_REG, &rev);
if (ret != 0) {
dev_err(&i2c->dev, "Failed to read device revision: %d\n", ret);
return ret;
}
ret = regmap_read(regmap, MP8859_ID1_REG, &val);
if (ret != 0) {
dev_err(&i2c->dev, "Failed to read device ID1: %d\n", ret);
return ret;
}
dev_info(&i2c->dev, "MP8859-%04d revision %d\n", val, rev);
rdev = devm_regulator_register(&i2c->dev, &mp8859_regulators[0],
&config);