drivers/hwmon/pmbus: Add IBM P17531 driver
v2 cover drivers/hwmon/pmbus: Add IBM P17531 driver
From: "Edward A. James" <[email protected]>
This series adds a hwmon pmbus driver for the IBM P17531 power supply. The core monitoring functionality is provided by pmbus. The driver also exports some sysfs entries for raw status register access.
The driver should be probed automatically, so I added it to the witherspoon device-tree.
Edward A. James (5):
drivers/hwmon/pmbus: Add IBM P17531 driver drivers/hwmon/pmbus: p17531: Add non-hwmon attributes
ARM: dts: aspeed: witherspoon: Add P17531 power supply to I2C bus
Documentation: hwmon: Add P17531 documentation
Documentation: ABI: Add P17531 sysfs documentation
Documentation/ABI/testing/sysfs-driver-p17531 | 49 +++++ Documentation/hwmon/p17531 | 53 +++++ arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts | 10 + drivers/hwmon/pmbus/Kconfig | 10 + drivers/hwmon/pmbus/Makefile | 1 + drivers/hwmon/pmbus/p17531.c | 245 +++++++++++++++++++++++ 6 files changed, 368 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-driver-p17531 create mode 100644 Documentation/hwmon/p17531 create mode 100644 drivers/hwmon/pmbus/p17531.c
Signature · 1 line
1.8.3.1
PATCH v2 1/5 drivers/hwmon/pmbus: Add IBM P17531 driver
From: "Edward A. James" <[email protected]>
Add the driver to monitor power supplies with hwmon over pmbus.
--- drivers/hwmon/pmbus/Kconfig | 10 +++ drivers/hwmon/pmbus/Makefile | 1 + drivers/hwmon/pmbus/p17531.c | 165 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 176 insertions(+) create mode 100644 drivers/hwmon/pmbus/p17531.c
drivers/hwmon/pmbus/Kconfig +10 -0
@@ -135,6 +135,16 @@ config SENSORS_MAX8688 This driver can also be built as a module. If so, the module will be called max8688. +config SENSORS_P17531 + tristate "IBM P17531" + default n + help + If you say yes here you get hardware monitoring support for IBM + P17531 power supply. + + This driver can also be built as a module. If so, the module will + be called p17531. + config SENSORS_TPS40422 tristate "TI TPS40422" default n
drivers/hwmon/pmbus/Makefile +1 -0
@@ -14,6 +14,7 @@ obj-$(CONFIG_SENSORS_MAX20751) += max20751.o obj-$(CONFIG_SENSORS_MAX31785) += max31785.o obj-$(CONFIG_SENSORS_MAX34440) += max34440.o obj-$(CONFIG_SENSORS_MAX8688) += max8688.o +obj-$(CONFIG_SENSORS_P17531) += p17531.o obj-$(CONFIG_SENSORS_TPS40422) += tps40422.o obj-$(CONFIG_SENSORS_UCD9000) += ucd9000.o obj-$(CONFIG_SENSORS_UCD9200) += ucd9200.o
drivers/hwmon/pmbus/p17531.c new file +165 -0
165 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Quoted 11 lines · Eddie James
From: "Edward A. James" <[email protected]>
Add the driver to monitor power supplies with hwmon over pmbus.
Signed-off-by Edward A. James <[email protected]>--- drivers/hwmon/pmbus/Kconfig | 10 +++ drivers/hwmon/pmbus/Makefile | 1 + drivers/hwmon/pmbus/p17531.c | 165 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 176 insertions(+) create mode 100644 drivers/hwmon/pmbus/p17531.c
This p17531/P17531 name for the device driver, files, and constants is a bit cryptic. Without going into too much detail on why that is a bad choice (refers to a document revision, not actual device), could a better name be chosen for this device driver?
Quoted 208 lines
drivers/hwmon/pmbus/Kconfig +10
-0@@ -135,6 +135,16 @@ config SENSORS_MAX8688 This driver can also be built as a module. If so, the module will be called max8688. +config SENSORS_P17531 + tristate "IBM P17531" + default n + help + If you say yes here you get hardware monitoring support for IBM + P17531 power supply. + + This driver can also be built as a module. If so, the module will + be called p17531. + config SENSORS_TPS40422 tristate "TI TPS40422" default ndrivers/hwmon/pmbus/Makefile +1
-0@@ -14,6 +14,7 @@ obj-$(CONFIG_SENSORS_MAX20751) += max20751.o obj-$(CONFIG_SENSORS_MAX31785) += max31785.o obj-$(CONFIG_SENSORS_MAX34440) += max34440.o obj-$(CONFIG_SENSORS_MAX8688) += max8688.o +obj-$(CONFIG_SENSORS_P17531) += p17531.o obj-$(CONFIG_SENSORS_TPS40422) += tps40422.o obj-$(CONFIG_SENSORS_UCD9000) += ucd9000.o obj-$(CONFIG_SENSORS_UCD9200) += ucd9200.odrivers/hwmon/pmbus/p17531.c new file +165
-1@@ -0,0 +1,165 @@ +/* +* Copyright 2017 IBM Corp. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +*/ + +#include <linux/device.h> +#include <linux/i2c.h> +#include <linux/jiffies.h> +#include <linux/module.h> + +#include "pmbus.h" + +#define P17531_MFR_FAN_FAULT BIT(0) +#define P17531_MFR_THERMAL_FAULT BIT(1) +#define P17531_MFR_OV_FAULT BIT(2) +#define P17531_MFR_UV_FAULT BIT(3) +#define P17531_MFR_PS_KILL BIT(4) +#define P17531_MFR_OC_FAULT BIT(5) +#define P17531_MFR_VAUX_FAULT BIT(6) +#define P17531_MFR_CURRENT_SHARE_WARNING BIT(7) + +static int p17531_read_word_data (struct i2c_client *client,int page,int reg); + +static int p17531_read_byte_data (struct i2c_client *client,int page,int reg) +{ +int rc, mfr; + +switch (reg) { +case PMBUS_STATUS_BYTE : +case PMBUS_STATUS_WORD : + rc =p17531_read_word_data (client, page,PMBUS_STATUS_WORD ); +break ; +case PMBUS_STATUS_VOUT : +case PMBUS_STATUS_IOUT : +case PMBUS_STATUS_TEMPERATURE : +case PMBUS_STATUS_FAN_12 : + rc =pmbus_read_byte_data (client, page, reg); +if (rc <0 ) +return rc; + + mfr =pmbus_read_byte_data (client, page, +PMBUS_STATUS_MFR_SPECIFIC ); +if (mfr <0 ) +return rc; + +if (reg ==PMBUS_STATUS_FAN_12 ) { +if (mfr &P17531_MFR_FAN_FAULT ) + rc |=PB_FAN_FAN1_FAULT ; + }else if (reg ==PMBUS_STATUS_TEMPERATURE ) { +if (mfr &P17531_MFR_THERMAL_FAULT ) + rc |=PB_TEMP_OT_FAULT ; + }else if (reg ==PMBUS_STATUS_VOUT ) { +if (mfr & + (P17531_MFR_OV_FAULT |P17531_MFR_VAUX_FAULT )) + rc |=PB_VOLTAGE_OV_FAULT ; +if (mfr &P17531_MFR_UV_FAULT ) + rc |=PB_VOLTAGE_UV_FAULT ; + }else if (reg ==PMBUS_STATUS_IOUT ) { +if (mfr &P17531_MFR_OC_FAULT ) + rc |=PB_IOUT_OC_FAULT ; +if (mfr &P17531_MFR_CURRENT_SHARE_WARNING ) + rc |=PB_CURRENT_SHARE_FAULT ; + } +break ; +default : +if (reg >=PMBUS_VIRT_BASE ) +return -ENXIO ; + + rc =pmbus_read_byte_data (client, page, reg); +break ; + } + +return rc; +} + +static int p17531_read_word_data (struct i2c_client *client,int page,int reg) +{ +int rc, mfr; + +switch (reg) { +case PMBUS_STATUS_BYTE : +case PMBUS_STATUS_WORD : + rc =pmbus_read_word_data (client, page,PMBUS_STATUS_WORD ); +if (rc <0 ) +return rc; + + mfr =pmbus_read_byte_data (client, page, +PMBUS_STATUS_MFR_SPECIFIC ); +if (mfr <0 ) +return rc; + +if (mfr &P17531_MFR_PS_KILL ) + rc |=PB_STATUS_OFF ; + +if (mfr) + rc |=PB_STATUS_WORD_MFR ; +break ; +default : +if (reg >=PMBUS_VIRT_BASE ) +return -ENXIO ; + + rc =pmbus_read_word_data (client, page, reg); +if (rc <0 ) + rc =p17531_read_byte_data (client, page, reg); +break ; + } + +return rc; +} + +static struct pmbus_driver_info p17531_info = { + .pages =1 , + .func[0 ] =PMBUS_HAVE_VIN |PMBUS_HAVE_VOUT |PMBUS_HAVE_IOUT | +PMBUS_HAVE_PIN |PMBUS_HAVE_FAN12 |PMBUS_HAVE_TEMP | +PMBUS_HAVE_TEMP2 |PMBUS_HAVE_TEMP3 |PMBUS_HAVE_STATUS_VOUT | +PMBUS_HAVE_STATUS_IOUT |PMBUS_HAVE_STATUS_INPUT | +PMBUS_HAVE_STATUS_TEMP |PMBUS_HAVE_STATUS_FAN12 , + .read_byte_data = p17531_read_byte_data, + .read_word_data = p17531_read_word_data, +}; + +static int p17531_probe (struct i2c_client *client, +const struct i2c_device_id *id) +{ +return pmbus_do_probe (client, id, &p17531_info); +} + +static int p17531_remove (struct i2c_client *client) +{ +return pmbus_do_remove (client); +} + +enum chips { p17531 }; + +static const struct i2c_device_id p17531_id[] = { + {"p17531" , p17531 }, + { } +}; +MODULE_DEVICE_TABLE (i2c, p17531_id); + +static const struct of_device_id p17531_of_match[] = { + { .compatible ="ibm,p17531" }, + {} +}; +MODULE_DEVICE_TABLE (of, p8_i2c_occ_of_match); + +static struct i2c_driver p17531_driver = { + .driver = { + .name ="p17531" , + .of_match_table = p17531_of_match, + }, + .probe = p17531_probe, + .remove = p17531_remove, + .id_table = p17531_id, +}; + +module_i2c_driver (p17531_driver); + +MODULE_AUTHOR ("Eddie James" ); +MODULE_DESCRIPTION ("PMBus driver for IBM P17531" ); +MODULE_LICENSE ("GPL" ); --1.8.3.1
PATCH v2 2/5 drivers/hwmon/pmbus: p17531: Add non-hwmon attributes
In reply to Eddie JamesFrom: "Edward A. James" <[email protected]>
Add sysfs entries to dump out PS registers and clear faults.
--- drivers/hwmon/pmbus/p17531.c | 80 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+)
drivers/hwmon/pmbus/p17531.c +80 -0
@@ -9,8 +9,10 @@#include <linux/device.h> #include <linux/i2c.h> +#include <linux/hwmon-sysfs.h> #include <linux/jiffies.h> #include <linux/module.h> +#include <linux/sysfs.h> #include "pmbus.h"
@@ -123,14 +125,92 @@ static int p17531_read_word_data(struct i2c_client *client, int page, int reg) .read_word_data = p17531_read_word_data, }; +static ssize_t p17531_clear_faults (struct device *dev, +struct device_attribute *dev_attr, +const char *buf,size_t count) +{ +struct i2c_client *client =to_i2c_client (dev); + +pmbus_clear_faults (client); + +return count; +} +static DEVICE_ATTR(clear_faults, 0200, NULL, p17531_clear_faults); + +static ssize_t p17531_show_status_word (struct device *dev, +struct device_attribute *dev_attr, +char *buf) +{ +int rc; +struct i2c_client *client =to_i2c_client (dev); + + rc =pmbus_read_word_data (client,0 ,PMBUS_STATUS_WORD ); +if (rc <0 ) +return rc; + +return snprintf (buf,PAGE_SIZE -1 ,"%04x\n" , rc); +} +static DEVICE_ATTR(status_word, 0444, p17531_show_status_word, NULL); + +static ssize_t p17531_show_status_byte (struct device *dev, +struct device_attribute *dev_attr, +char *buf) +{ +int rc; +struct i2c_client *client =to_i2c_client (dev); +struct sensor_device_attribute *sattr =to_sensor_dev_attr (dev_attr); + + rc =pmbus_read_byte_data (client,0 ,PMBUS_STATUS_VOUT + sattr->index); +if (rc <0 ) +return rc; + +return snprintf (buf,PAGE_SIZE -1 ,"%02x\n" , rc); +} + +static SENSOR_DEVICE_ATTR(status_vout, 0444, p17531_show_status_byte, NULL, 0); +static SENSOR_DEVICE_ATTR(status_iout, 0444, p17531_show_status_byte, NULL, 1); +static SENSOR_DEVICE_ATTR(status_input, 0444, p17531_show_status_byte, NULL, + 2); +static SENSOR_DEVICE_ATTR(status_temp, 0444, p17531_show_status_byte, NULL, 3); +static SENSOR_DEVICE_ATTR(status_cml, 0444, p17531_show_status_byte, NULL, 4); +static SENSOR_DEVICE_ATTR(status_other, 0444, p17531_show_status_byte, NULL, + 5); +static SENSOR_DEVICE_ATTR(status_mfr, 0444, p17531_show_status_byte, NULL, 6); +static SENSOR_DEVICE_ATTR(status_fan, 0444, p17531_show_status_byte, NULL, 7); + +static struct attribute *p17531_attributes[] = { + &dev_attr_clear_faults.attr, + &dev_attr_status_word.attr, + &sensor_dev_attr_status_vout.dev_attr.attr, + &sensor_dev_attr_status_iout.dev_attr.attr, + &sensor_dev_attr_status_input.dev_attr.attr, + &sensor_dev_attr_status_temp.dev_attr.attr, + &sensor_dev_attr_status_cml.dev_attr.attr, + &sensor_dev_attr_status_other.dev_attr.attr, + &sensor_dev_attr_status_mfr.dev_attr.attr, + &sensor_dev_attr_status_fan.dev_attr.attr, +NULL +}; + +static const struct attribute_group p17531_attribute_group = { + .attrs = p17531_attributes, +}; +static int p17531_probe (struct i2c_client *client,const struct i2c_device_id *id) { +int rc =sysfs_create_group (&client->dev.kobj, + &p17531_attribute_group); +if (rc) +return rc; +return pmbus_do_probe (client, id, &p17531_info); }static int p17531_remove (struct i2c_client *client) { +sysfs_remove_group (&client->dev.kobj, &p17531_attribute_group); +return pmbus_do_remove (client); }
Signature · 1 line
1.8.3.1
PATCH v2 3/5 ARM: dts: aspeed: witherspoon: Add P17531 power supply to I2C bus
In reply to Eddie JamesFrom: "Edward A. James" <[email protected]>
--- arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts +10 -0
@@ -321,6 +321,16 @@ type = <PCA955X_TYPE_LED>; }; }; + + p17531@68 { + compatible = "ibm,p17531"; + reg = <0x68>; + }; + + p17531@69 { + compatible = "ibm,p17531"; + reg = <0x69>; + }; }; &i2c4 {
Signature · 1 line
1.8.3.1
PATCH v2 4/5 Documentation: hwmon: Add P17531 documentation
In reply to Eddie JamesFrom: "Edward A. James" <[email protected]>
--- Documentation/hwmon/p17531 | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Documentation/hwmon/p17531
Documentation/hwmon/p17531 new file +53 -0
@@ -0,0 +1,53 @@ +Kernel driver p17531 +==================== + +Supported chips: + * IBM P17531 + +Author: Eddie James <[email protected]> + +Description +----------- + +This driver supports the IBM P17531 power supply. This driver is a client to +the core PMBus driver. + +Usage Notes +----------- + +This driver should auto-detect devices. In the event that it does not, you will +have to instantiate the devices explicitly. Please see +Documentation/i2c/instantiating-devices for details. + +Sysfs entries +------------- + +The following attributes are supported: + +curr1_alarm Output current over-current fault. +curr1_input Measured output current in mA. +curr1_label "iout1" + +fan1_alarm Fan 1 warning. +fan1_fault Fan 1 fault. +fan1_input Fan 1 speed in RPM. +fan2_alarm Fan 2 warning. +fan2_fault Fan 2 fault. +fan2_input Fan 2 speed in RPM. + +in1_alarm Input voltage under-voltage fault. +in1_input Measured input voltage in mV. +in1_label "vin" +in2_alarm Output voltage over-voltage fault. +in2_input Measured output voltage in mV. +in2_label "vout1" + +power1_input Measured input power in uW. +power1_label "pin" + +temp1_alarm PSU inlet ambient temperature over-temperature fault. +temp1_input Measured PSU inlet ambient temp in millidegrees C. +temp2_alarm Secondary rectifier temp over-temperature fault. +temp2_input Measured secondary rectifier temp in millidegrees C. +temp3_alarm ORing FET temperature over-temperature fault. +temp3_input Measured ORing FET temperature in millidegrees C.
Signature · 1 line
1.8.3.1
PATCH v2 5/5 Documentation: ABI: Add P17531 sysfs documentation
In reply to Eddie JamesFrom: "Edward A. James" <[email protected]>
--- Documentation/ABI/testing/sysfs-driver-p17531 | 49 +++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-driver-p17531
Documentation/ABI/testing/sysfs-driver-p17531 new file +49 -0
@@ -0,0 +1,49 @@ +What: /sys/bus/i2c/devices/<dev>/clear_faults +KernelVersion: 4.13 +Contact: [email protected] +Description: Clears pmbus faults for this power supply. + +What: /sys/bus/i2c/devices/<dev>/status_word +KernelVersion: 4.13 +Contact: [email protected] +Description: Displays the STATUS_WORD register. + +What: /sys/bus/i2c/devices/<dev>/status_vout +KernelVersion: 4.13 +Contact: [email protected] +Description: Displays the STATUS_VOUT register. + +What: /sys/bus/i2c/devices/<dev>/status_iout +KernelVersion: 4.13 +Contact: [email protected] +Description: Displays the STATUS_IOUT register. + +What: /sys/bus/i2c/devices/<dev>/status_input +KernelVersion: 4.13 +Contact: [email protected] +Description: Displays the STATUS_INPUT register. + +What: /sys/bus/i2c/devices/<dev>/status_temp +KernelVersion: 4.13 +Contact: [email protected] +Description: Displays the STATUS_TEMPERATURE register. + +What: /sys/bus/i2c/devices/<dev>/status_cml +KernelVersion: 4.13 +Contact: [email protected] +Description: Displays the STATUS_CML register. + +What: /sys/bus/i2c/devices/<dev>/status_other +KernelVersion: 4.13 +Contact: [email protected] +Description: Displays the STATUS_OTHER register. + +What: /sys/bus/i2c/devices/<dev>/status_mfr +KernelVersion: 4.13 +Contact: [email protected] +Description: Displays the STATUS_MFR_SPECIFIC register. + +What: /sys/bus/i2c/devices/<dev>/status_fan +KernelVersion: 4.13 +Contact: [email protected] +Description: Displays the STATUS_FAN register.
Signature · 1 line
1.8.3.1