diff options
Diffstat (limited to 'drivers/hwmon/pmbus')
-rw-r--r-- | drivers/hwmon/pmbus/pmbus_core.c | 80 |
1 files changed, 52 insertions, 28 deletions
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index 32f4530cd1e8..cb5e255a84c6 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c | |||
@@ -109,6 +109,7 @@ struct pmbus_data { | |||
109 | * so we keep them all together. | 109 | * so we keep them all together. |
110 | */ | 110 | */ |
111 | u8 status[PB_NUM_STATUS_REG]; | 111 | u8 status[PB_NUM_STATUS_REG]; |
112 | u8 status_register; | ||
112 | 113 | ||
113 | u8 currpage; | 114 | u8 currpage; |
114 | }; | 115 | }; |
@@ -285,9 +286,10 @@ EXPORT_SYMBOL_GPL(pmbus_clear_faults); | |||
285 | 286 | ||
286 | static int pmbus_check_status_cml(struct i2c_client *client) | 287 | static int pmbus_check_status_cml(struct i2c_client *client) |
287 | { | 288 | { |
289 | struct pmbus_data *data = i2c_get_clientdata(client); | ||
288 | int status, status2; | 290 | int status, status2; |
289 | 291 | ||
290 | status = _pmbus_read_byte_data(client, -1, PMBUS_STATUS_BYTE); | 292 | status = _pmbus_read_byte_data(client, -1, data->status_register); |
291 | if (status < 0 || (status & PB_STATUS_CML)) { | 293 | if (status < 0 || (status & PB_STATUS_CML)) { |
292 | status2 = _pmbus_read_byte_data(client, -1, PMBUS_STATUS_CML); | 294 | status2 = _pmbus_read_byte_data(client, -1, PMBUS_STATUS_CML); |
293 | if (status2 < 0 || (status2 & PB_CML_FAULT_INVALID_COMMAND)) | 295 | if (status2 < 0 || (status2 & PB_CML_FAULT_INVALID_COMMAND)) |
@@ -344,7 +346,7 @@ static struct pmbus_data *pmbus_update_device(struct device *dev) | |||
344 | for (i = 0; i < info->pages; i++) | 346 | for (i = 0; i < info->pages; i++) |
345 | data->status[PB_STATUS_BASE + i] | 347 | data->status[PB_STATUS_BASE + i] |
346 | = _pmbus_read_byte_data(client, i, | 348 | = _pmbus_read_byte_data(client, i, |
347 | PMBUS_STATUS_BYTE); | 349 | data->status_register); |
348 | for (i = 0; i < info->pages; i++) { | 350 | for (i = 0; i < info->pages; i++) { |
349 | if (!(info->func[i] & PMBUS_HAVE_STATUS_VOUT)) | 351 | if (!(info->func[i] & PMBUS_HAVE_STATUS_VOUT)) |
350 | continue; | 352 | continue; |
@@ -1015,7 +1017,7 @@ static int pmbus_add_sensor_attrs_one(struct i2c_client *client, | |||
1015 | */ | 1017 | */ |
1016 | if (!ret && attr->gbit && | 1018 | if (!ret && attr->gbit && |
1017 | pmbus_check_byte_register(client, page, | 1019 | pmbus_check_byte_register(client, page, |
1018 | PMBUS_STATUS_BYTE)) { | 1020 | data->status_register)) { |
1019 | ret = pmbus_add_boolean(data, name, "alarm", index, | 1021 | ret = pmbus_add_boolean(data, name, "alarm", index, |
1020 | NULL, NULL, | 1022 | NULL, NULL, |
1021 | PB_STATUS_BASE + page, | 1023 | PB_STATUS_BASE + page, |
@@ -1683,6 +1685,51 @@ static int pmbus_identify_common(struct i2c_client *client, | |||
1683 | return 0; | 1685 | return 0; |
1684 | } | 1686 | } |
1685 | 1687 | ||
1688 | static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data, | ||
1689 | struct pmbus_driver_info *info) | ||
1690 | { | ||
1691 | struct device *dev = &client->dev; | ||
1692 | int ret; | ||
1693 | |||
1694 | /* | ||
1695 | * Some PMBus chips don't support PMBUS_STATUS_BYTE, so try | ||
1696 | * to use PMBUS_STATUS_WORD instead if that is the case. | ||
1697 | * Bail out if both registers are not supported. | ||
1698 | */ | ||
1699 | data->status_register = PMBUS_STATUS_BYTE; | ||
1700 | ret = i2c_smbus_read_byte_data(client, PMBUS_STATUS_BYTE); | ||
1701 | if (ret < 0 || ret == 0xff) { | ||
1702 | data->status_register = PMBUS_STATUS_WORD; | ||
1703 | ret = i2c_smbus_read_word_data(client, PMBUS_STATUS_WORD); | ||
1704 | if (ret < 0 || ret == 0xffff) { | ||
1705 | dev_err(dev, "PMBus status register not found\n"); | ||
1706 | return -ENODEV; | ||
1707 | } | ||
1708 | } | ||
1709 | |||
1710 | pmbus_clear_faults(client); | ||
1711 | |||
1712 | if (info->identify) { | ||
1713 | ret = (*info->identify)(client, info); | ||
1714 | if (ret < 0) { | ||
1715 | dev_err(dev, "Chip identification failed\n"); | ||
1716 | return ret; | ||
1717 | } | ||
1718 | } | ||
1719 | |||
1720 | if (info->pages <= 0 || info->pages > PMBUS_PAGES) { | ||
1721 | dev_err(dev, "Bad number of PMBus pages: %d\n", info->pages); | ||
1722 | return -ENODEV; | ||
1723 | } | ||
1724 | |||
1725 | ret = pmbus_identify_common(client, data); | ||
1726 | if (ret < 0) { | ||
1727 | dev_err(dev, "Failed to identify chip capabilities\n"); | ||
1728 | return ret; | ||
1729 | } | ||
1730 | return 0; | ||
1731 | } | ||
1732 | |||
1686 | int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id, | 1733 | int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id, |
1687 | struct pmbus_driver_info *info) | 1734 | struct pmbus_driver_info *info) |
1688 | { | 1735 | { |
@@ -1707,36 +1754,13 @@ int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id, | |||
1707 | mutex_init(&data->update_lock); | 1754 | mutex_init(&data->update_lock); |
1708 | data->dev = dev; | 1755 | data->dev = dev; |
1709 | 1756 | ||
1710 | /* Bail out if PMBus status register does not exist. */ | ||
1711 | if (i2c_smbus_read_byte_data(client, PMBUS_STATUS_BYTE) < 0) { | ||
1712 | dev_err(dev, "PMBus status register not found\n"); | ||
1713 | return -ENODEV; | ||
1714 | } | ||
1715 | |||
1716 | if (pdata) | 1757 | if (pdata) |
1717 | data->flags = pdata->flags; | 1758 | data->flags = pdata->flags; |
1718 | data->info = info; | 1759 | data->info = info; |
1719 | 1760 | ||
1720 | pmbus_clear_faults(client); | 1761 | ret = pmbus_init_common(client, data, info); |
1721 | 1762 | if (ret < 0) | |
1722 | if (info->identify) { | ||
1723 | ret = (*info->identify)(client, info); | ||
1724 | if (ret < 0) { | ||
1725 | dev_err(dev, "Chip identification failed\n"); | ||
1726 | return ret; | ||
1727 | } | ||
1728 | } | ||
1729 | |||
1730 | if (info->pages <= 0 || info->pages > PMBUS_PAGES) { | ||
1731 | dev_err(dev, "Bad number of PMBus pages: %d\n", info->pages); | ||
1732 | return -ENODEV; | ||
1733 | } | ||
1734 | |||
1735 | ret = pmbus_identify_common(client, data); | ||
1736 | if (ret < 0) { | ||
1737 | dev_err(dev, "Failed to identify chip capabilities\n"); | ||
1738 | return ret; | 1763 | return ret; |
1739 | } | ||
1740 | 1764 | ||
1741 | ret = pmbus_find_attributes(client, data); | 1765 | ret = pmbus_find_attributes(client, data); |
1742 | if (ret) | 1766 | if (ret) |