Commit 16358542 authored by Guenter Roeck's avatar Guenter Roeck

hwmon: (pmbus) Implement multi-phase support

Some PMBus chips support multiple phases, and report telemetry such
as input current, output current, or temperature for each phase.
Add support for such chips to the PMBus core.

Start with a maximum of 8 phases per page, and assume that supported
sensors per phase are similar for all pages. Only support per-phase
telemetry attributes, no limits or alarms.

As part of this patch, set the initial page variable to 0xff to ensure
that the page is updated when the first page command is issued. Also
only issue page commands if the chip supports more than one page.

Cc: Vadim Pasternak <vadimp@mellanox.com>
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent 43f33b6e
...@@ -227,7 +227,9 @@ currX_lcrit_alarm Output current critical low alarm. ...@@ -227,7 +227,9 @@ currX_lcrit_alarm Output current critical low alarm.
From IOUT_UC_FAULT status. From IOUT_UC_FAULT status.
currX_crit_alarm Current critical high alarm. currX_crit_alarm Current critical high alarm.
From IIN_OC_FAULT or IOUT_OC_FAULT status. From IIN_OC_FAULT or IOUT_OC_FAULT status.
currX_label "iin" or "ioutY" currX_label "iin", "iinY", "iinY.Z", "ioutY", or "ioutY.Z",
where Y reflects the page number and Z reflects the
phase.
powerX_input Measured power. From READ_PIN or READ_POUT register. powerX_input Measured power. From READ_PIN or READ_POUT register.
powerX_cap Output power cap. From POUT_MAX register. powerX_cap Output power cap. From POUT_MAX register.
...@@ -239,7 +241,9 @@ powerX_alarm Power high alarm. ...@@ -239,7 +241,9 @@ powerX_alarm Power high alarm.
From PIN_OP_WARNING or POUT_OP_WARNING status. From PIN_OP_WARNING or POUT_OP_WARNING status.
powerX_crit_alarm Output power critical high alarm. powerX_crit_alarm Output power critical high alarm.
From POUT_OP_FAULT status. From POUT_OP_FAULT status.
powerX_label "pin" or "poutY" powerX_label "pin", "pinY", "pinY.Z", "poutY", or "poutY.Z",
where Y reflects the page number and Z reflects the
phase.
tempX_input Measured temperature. tempX_input Measured temperature.
From READ_TEMPERATURE_X register. From READ_TEMPERATURE_X register.
......
...@@ -362,6 +362,7 @@ enum pmbus_sensor_classes { ...@@ -362,6 +362,7 @@ enum pmbus_sensor_classes {
}; };
#define PMBUS_PAGES 32 /* Per PMBus specification */ #define PMBUS_PAGES 32 /* Per PMBus specification */
#define PMBUS_PHASES 8 /* Maximum number of phases per page */
/* Functionality bit mask */ /* Functionality bit mask */
#define PMBUS_HAVE_VIN BIT(0) #define PMBUS_HAVE_VIN BIT(0)
...@@ -388,13 +389,15 @@ enum pmbus_sensor_classes { ...@@ -388,13 +389,15 @@ enum pmbus_sensor_classes {
#define PMBUS_HAVE_PWM34 BIT(21) #define PMBUS_HAVE_PWM34 BIT(21)
#define PMBUS_HAVE_SAMPLES BIT(22) #define PMBUS_HAVE_SAMPLES BIT(22)
#define PMBUS_PAGE_VIRTUAL BIT(31) #define PMBUS_PHASE_VIRTUAL BIT(30) /* Phases on this page are virtual */
#define PMBUS_PAGE_VIRTUAL BIT(31) /* Page is virtual */
enum pmbus_data_format { linear = 0, direct, vid }; enum pmbus_data_format { linear = 0, direct, vid };
enum vrm_version { vr11 = 0, vr12, vr13, imvp9, amd625mv }; enum vrm_version { vr11 = 0, vr12, vr13, imvp9, amd625mv };
struct pmbus_driver_info { struct pmbus_driver_info {
int pages; /* Total number of pages */ int pages; /* Total number of pages */
u8 phases[PMBUS_PAGES]; /* Number of phases per page */
enum pmbus_data_format format[PSC_NUM_CLASSES]; enum pmbus_data_format format[PSC_NUM_CLASSES];
enum vrm_version vrm_version[PMBUS_PAGES]; /* vrm version per page */ enum vrm_version vrm_version[PMBUS_PAGES]; /* vrm version per page */
/* /*
...@@ -406,6 +409,7 @@ struct pmbus_driver_info { ...@@ -406,6 +409,7 @@ struct pmbus_driver_info {
int R[PSC_NUM_CLASSES]; /* exponent */ int R[PSC_NUM_CLASSES]; /* exponent */
u32 func[PMBUS_PAGES]; /* Functionality, per page */ u32 func[PMBUS_PAGES]; /* Functionality, per page */
u32 pfunc[PMBUS_PHASES];/* Functionality, per phase */
/* /*
* The following functions map manufacturing specific register values * The following functions map manufacturing specific register values
* to PMBus standard register values. Specify only if mapping is * to PMBus standard register values. Specify only if mapping is
......
...@@ -49,6 +49,7 @@ struct pmbus_sensor { ...@@ -49,6 +49,7 @@ struct pmbus_sensor {
char name[PMBUS_NAME_SIZE]; /* sysfs sensor name */ char name[PMBUS_NAME_SIZE]; /* sysfs sensor name */
struct device_attribute attribute; struct device_attribute attribute;
u8 page; /* page number */ u8 page; /* page number */
u8 phase; /* phase number, 0xff for all phases */
u16 reg; /* register */ u16 reg; /* register */
enum pmbus_sensor_classes class; /* sensor class */ enum pmbus_sensor_classes class; /* sensor class */
bool update; /* runtime sensor update needed */ bool update; /* runtime sensor update needed */
...@@ -109,6 +110,7 @@ struct pmbus_data { ...@@ -109,6 +110,7 @@ struct pmbus_data {
int (*read_status)(struct i2c_client *client, int page); int (*read_status)(struct i2c_client *client, int page);
u8 currpage; u8 currpage;
u8 currphase; /* current phase, 0xff for all */
}; };
struct pmbus_debugfs_entry { struct pmbus_debugfs_entry {
...@@ -151,10 +153,11 @@ int pmbus_set_page(struct i2c_client *client, int page, int phase) ...@@ -151,10 +153,11 @@ int pmbus_set_page(struct i2c_client *client, int page, int phase)
struct pmbus_data *data = i2c_get_clientdata(client); struct pmbus_data *data = i2c_get_clientdata(client);
int rv; int rv;
if (page < 0 || page == data->currpage) if (page < 0)
return 0; return 0;
if (!(data->info->func[page] & PMBUS_PAGE_VIRTUAL)) { if (!(data->info->func[page] & PMBUS_PAGE_VIRTUAL) &&
data->info->pages > 1 && page != data->currpage) {
rv = i2c_smbus_write_byte_data(client, PMBUS_PAGE, page); rv = i2c_smbus_write_byte_data(client, PMBUS_PAGE, page);
if (rv < 0) if (rv < 0)
return rv; return rv;
...@@ -166,9 +169,17 @@ int pmbus_set_page(struct i2c_client *client, int page, int phase) ...@@ -166,9 +169,17 @@ int pmbus_set_page(struct i2c_client *client, int page, int phase)
if (rv != page) if (rv != page)
return -EIO; return -EIO;
} }
data->currpage = page; data->currpage = page;
if (data->info->phases[page] && data->currphase != phase &&
!(data->info->func[page] & PMBUS_PHASE_VIRTUAL)) {
rv = i2c_smbus_write_byte_data(client, PMBUS_PHASE,
phase);
if (rv)
return rv;
}
data->currphase = phase;
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(pmbus_set_page); EXPORT_SYMBOL_GPL(pmbus_set_page);
...@@ -602,7 +613,7 @@ static struct pmbus_data *pmbus_update_device(struct device *dev) ...@@ -602,7 +613,7 @@ static struct pmbus_data *pmbus_update_device(struct device *dev)
sensor->data sensor->data
= _pmbus_read_word_data(client, = _pmbus_read_word_data(client,
sensor->page, sensor->page,
0xff, sensor->phase,
sensor->reg); sensor->reg);
} }
pmbus_clear_faults(client); pmbus_clear_faults(client);
...@@ -1084,7 +1095,8 @@ static int pmbus_add_boolean(struct pmbus_data *data, ...@@ -1084,7 +1095,8 @@ static int pmbus_add_boolean(struct pmbus_data *data,
static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data, static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
const char *name, const char *type, const char *name, const char *type,
int seq, int page, int reg, int seq, int page, int phase,
int reg,
enum pmbus_sensor_classes class, enum pmbus_sensor_classes class,
bool update, bool readonly, bool update, bool readonly,
bool convert) bool convert)
...@@ -1108,6 +1120,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data, ...@@ -1108,6 +1120,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
readonly = true; readonly = true;
sensor->page = page; sensor->page = page;
sensor->phase = phase;
sensor->reg = reg; sensor->reg = reg;
sensor->class = class; sensor->class = class;
sensor->update = update; sensor->update = update;
...@@ -1127,7 +1140,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data, ...@@ -1127,7 +1140,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
static int pmbus_add_label(struct pmbus_data *data, static int pmbus_add_label(struct pmbus_data *data,
const char *name, int seq, const char *name, int seq,
const char *lstring, int index) const char *lstring, int index, int phase)
{ {
struct pmbus_label *label; struct pmbus_label *label;
struct device_attribute *a; struct device_attribute *a;
...@@ -1139,11 +1152,21 @@ static int pmbus_add_label(struct pmbus_data *data, ...@@ -1139,11 +1152,21 @@ static int pmbus_add_label(struct pmbus_data *data,
a = &label->attribute; a = &label->attribute;
snprintf(label->name, sizeof(label->name), "%s%d_label", name, seq); snprintf(label->name, sizeof(label->name), "%s%d_label", name, seq);
if (!index) if (!index) {
strncpy(label->label, lstring, sizeof(label->label) - 1); if (phase == 0xff)
else strncpy(label->label, lstring,
snprintf(label->label, sizeof(label->label), "%s%d", lstring, sizeof(label->label) - 1);
index); else
snprintf(label->label, sizeof(label->label), "%s.%d",
lstring, phase);
} else {
if (phase == 0xff)
snprintf(label->label, sizeof(label->label), "%s%d",
lstring, index);
else
snprintf(label->label, sizeof(label->label), "%s%d.%d",
lstring, index, phase);
}
pmbus_dev_attr_init(a, label->name, 0444, pmbus_show_label, NULL); pmbus_dev_attr_init(a, label->name, 0444, pmbus_show_label, NULL);
return pmbus_add_attribute(data, &a->attr); return pmbus_add_attribute(data, &a->attr);
...@@ -1208,7 +1231,7 @@ static int pmbus_add_limit_attrs(struct i2c_client *client, ...@@ -1208,7 +1231,7 @@ static int pmbus_add_limit_attrs(struct i2c_client *client,
for (i = 0; i < nlimit; i++) { for (i = 0; i < nlimit; i++) {
if (pmbus_check_word_register(client, page, l->reg)) { if (pmbus_check_word_register(client, page, l->reg)) {
curr = pmbus_add_sensor(data, name, l->attr, index, curr = pmbus_add_sensor(data, name, l->attr, index,
page, l->reg, attr->class, page, 0xff, l->reg, attr->class,
attr->update || l->update, attr->update || l->update,
false, true); false, true);
if (!curr) if (!curr)
...@@ -1235,7 +1258,7 @@ static int pmbus_add_sensor_attrs_one(struct i2c_client *client, ...@@ -1235,7 +1258,7 @@ static int pmbus_add_sensor_attrs_one(struct i2c_client *client,
struct pmbus_data *data, struct pmbus_data *data,
const struct pmbus_driver_info *info, const struct pmbus_driver_info *info,
const char *name, const char *name,
int index, int page, int index, int page, int phase,
const struct pmbus_sensor_attr *attr, const struct pmbus_sensor_attr *attr,
bool paged) bool paged)
{ {
...@@ -1245,15 +1268,16 @@ static int pmbus_add_sensor_attrs_one(struct i2c_client *client, ...@@ -1245,15 +1268,16 @@ static int pmbus_add_sensor_attrs_one(struct i2c_client *client,
if (attr->label) { if (attr->label) {
ret = pmbus_add_label(data, name, index, attr->label, ret = pmbus_add_label(data, name, index, attr->label,
paged ? page + 1 : 0); paged ? page + 1 : 0, phase);
if (ret) if (ret)
return ret; return ret;
} }
base = pmbus_add_sensor(data, name, "input", index, page, attr->reg, base = pmbus_add_sensor(data, name, "input", index, page, phase,
attr->class, true, true, true); attr->reg, attr->class, true, true, true);
if (!base) if (!base)
return -ENOMEM; return -ENOMEM;
if (attr->sfunc) { /* No limit and alarm attributes for phase specific sensors */
if (attr->sfunc && phase == 0xff) {
ret = pmbus_add_limit_attrs(client, data, info, name, ret = pmbus_add_limit_attrs(client, data, info, name,
index, page, base, attr); index, page, base, attr);
if (ret < 0) if (ret < 0)
...@@ -1323,10 +1347,25 @@ static int pmbus_add_sensor_attrs(struct i2c_client *client, ...@@ -1323,10 +1347,25 @@ static int pmbus_add_sensor_attrs(struct i2c_client *client,
continue; continue;
ret = pmbus_add_sensor_attrs_one(client, data, info, ret = pmbus_add_sensor_attrs_one(client, data, info,
name, index, page, name, index, page,
attrs, paged); 0xff, attrs, paged);
if (ret) if (ret)
return ret; return ret;
index++; index++;
if (info->phases[page]) {
int phase;
for (phase = 0; phase < info->phases[page];
phase++) {
if (!(info->pfunc[phase] & attrs->func))
continue;
ret = pmbus_add_sensor_attrs_one(client,
data, info, name, index, page,
phase, attrs, paged);
if (ret)
return ret;
index++;
}
}
} }
attrs++; attrs++;
} }
...@@ -1830,7 +1869,7 @@ static int pmbus_add_fan_ctrl(struct i2c_client *client, ...@@ -1830,7 +1869,7 @@ static int pmbus_add_fan_ctrl(struct i2c_client *client,
struct pmbus_sensor *sensor; struct pmbus_sensor *sensor;
sensor = pmbus_add_sensor(data, "fan", "target", index, page, sensor = pmbus_add_sensor(data, "fan", "target", index, page,
PMBUS_VIRT_FAN_TARGET_1 + id, PSC_FAN, PMBUS_VIRT_FAN_TARGET_1 + id, 0xff, PSC_FAN,
false, false, true); false, false, true);
if (!sensor) if (!sensor)
...@@ -1841,14 +1880,14 @@ static int pmbus_add_fan_ctrl(struct i2c_client *client, ...@@ -1841,14 +1880,14 @@ static int pmbus_add_fan_ctrl(struct i2c_client *client,
return 0; return 0;
sensor = pmbus_add_sensor(data, "pwm", NULL, index, page, sensor = pmbus_add_sensor(data, "pwm", NULL, index, page,
PMBUS_VIRT_PWM_1 + id, PSC_PWM, PMBUS_VIRT_PWM_1 + id, 0xff, PSC_PWM,
false, false, true); false, false, true);
if (!sensor) if (!sensor)
return -ENOMEM; return -ENOMEM;
sensor = pmbus_add_sensor(data, "pwm", "enable", index, page, sensor = pmbus_add_sensor(data, "pwm", "enable", index, page,
PMBUS_VIRT_PWM_ENABLE_1 + id, PSC_PWM, PMBUS_VIRT_PWM_ENABLE_1 + id, 0xff, PSC_PWM,
true, false, false); true, false, false);
if (!sensor) if (!sensor)
...@@ -1890,7 +1929,7 @@ static int pmbus_add_fan_attributes(struct i2c_client *client, ...@@ -1890,7 +1929,7 @@ static int pmbus_add_fan_attributes(struct i2c_client *client,
continue; continue;
if (pmbus_add_sensor(data, "fan", "input", index, if (pmbus_add_sensor(data, "fan", "input", index,
page, pmbus_fan_registers[f], page, pmbus_fan_registers[f], 0xff,
PSC_FAN, true, true, true) == NULL) PSC_FAN, true, true, true) == NULL)
return -ENOMEM; return -ENOMEM;
...@@ -2490,6 +2529,8 @@ int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id, ...@@ -2490,6 +2529,8 @@ int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id,
if (pdata) if (pdata)
data->flags = pdata->flags; data->flags = pdata->flags;
data->info = info; data->info = info;
data->currpage = 0xff;
data->currphase = 0xfe;
ret = pmbus_init_common(client, data, info); ret = pmbus_init_common(client, data, info);
if (ret < 0) if (ret < 0)
......
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