Commit 836954da authored by Guenter Roeck's avatar Guenter Roeck

hwmon: (ltc2978) Move code to read chip ID into separate function

Verifying the chip type is getting more complicated with new chips,
since not all chips support the same mechanism to read the chip type.
Move the code into a separate function to simplify adding support for
those chips.
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent 33836ee9
...@@ -388,10 +388,36 @@ static const struct regulator_desc ltc2978_reg_desc[] = { ...@@ -388,10 +388,36 @@ static const struct regulator_desc ltc2978_reg_desc[] = {
}; };
#endif /* CONFIG_SENSORS_LTC2978_REGULATOR */ #endif /* CONFIG_SENSORS_LTC2978_REGULATOR */
static int ltc2978_get_id(struct i2c_client *client)
{
int chip_id;
chip_id = i2c_smbus_read_word_data(client, LTC2978_MFR_SPECIAL_ID);
if (chip_id < 0)
return chip_id;
if (chip_id == LTC2974_ID_REV1 || chip_id == LTC2974_ID_REV2)
return ltc2974;
else if (chip_id == LTC2977_ID)
return ltc2977;
else if (chip_id == LTC2978_ID_REV1 || chip_id == LTC2978_ID_REV2 ||
chip_id == LTC2978A_ID)
return ltc2978;
else if ((chip_id & LTC3880_ID_MASK) == LTC3880_ID)
return ltc3880;
else if ((chip_id & LTC3883_ID_MASK) == LTC3883_ID)
return ltc3883;
else if ((chip_id & LTM4676_ID_MASK) == LTM4676_ID)
return ltm4676;
dev_err(&client->dev, "Unsupported chip ID 0x%x\n", chip_id);
return -ENODEV;
}
static int ltc2978_probe(struct i2c_client *client, static int ltc2978_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
int chip_id, i; int i, chip_id;
struct ltc2978_data *data; struct ltc2978_data *data;
struct pmbus_driver_info *info; struct pmbus_driver_info *info;
...@@ -404,27 +430,11 @@ static int ltc2978_probe(struct i2c_client *client, ...@@ -404,27 +430,11 @@ static int ltc2978_probe(struct i2c_client *client,
if (!data) if (!data)
return -ENOMEM; return -ENOMEM;
chip_id = i2c_smbus_read_word_data(client, LTC2978_MFR_SPECIAL_ID); chip_id = ltc2978_get_id(client);
if (chip_id < 0) if (chip_id < 0)
return chip_id; return chip_id;
if (chip_id == LTC2974_ID_REV1 || chip_id == LTC2974_ID_REV2) { data->id = chip_id;
data->id = ltc2974;
} else if (chip_id == LTC2977_ID) {
data->id = ltc2977;
} else if (chip_id == LTC2978_ID_REV1 || chip_id == LTC2978_ID_REV2 ||
chip_id == LTC2978A_ID) {
data->id = ltc2978;
} else if ((chip_id & LTC3880_ID_MASK) == LTC3880_ID) {
data->id = ltc3880;
} else if ((chip_id & LTC3883_ID_MASK) == LTC3883_ID) {
data->id = ltc3883;
} else if ((chip_id & LTM4676_ID_MASK) == LTM4676_ID) {
data->id = ltm4676;
} else {
dev_err(&client->dev, "Unsupported chip ID 0x%x\n", chip_id);
return -ENODEV;
}
if (data->id != id->driver_data) if (data->id != id->driver_data)
dev_warn(&client->dev, dev_warn(&client->dev,
"Device mismatch: Configured %s, detected %s\n", "Device mismatch: Configured %s, detected %s\n",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment