linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] hwmon: (pmbus) add driver for BEL PFE1100 and PFE3000
@ 2019-10-28 23:49 rentao.bupt
  2019-10-28 23:49 ` [PATCH 1/3] hwmon: (pmbus) add BEL PFE1100 power supply driver rentao.bupt
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: rentao.bupt @ 2019-10-28 23:49 UTC (permalink / raw)
  To: Guenter Roeck, Jean Delvare, Jonathan Corbet, linux-hwmon,
	linux-doc, linux-kernel, openbmc, taoren
  Cc: Tao Ren

From: Tao Ren <rentao.bupt@gmail.com>

The patch series adds "bel-pfe" pmbus driver which supports hardware
monitoring for BEL PFE1100 and PFE3000 power supplies.

There are total 3 patches:
  - patch #1 adds the initial version of bel-pfe driver which supports
    BEL PFE1100 power supply.
  - patch #2 adds BEL PFE3000 support into bel-pfe driver.
  - patch #3 adds documentation for PFE1100 and PFE3000 chips.

The driver has been tested on Facebook Wedge40 BMC (with PFE1100) and
Facebook CMM BMC (with PFE3000).

Tao Ren (3):
  hwmon: (pmbus) add BEL PFE1100 power supply driver
  hwmon: (pmbus) add BEL PFE3000 power supply driver
  docs: hwmon: Document bel-pfe pmbus driver

 Documentation/hwmon/bel-pfe.rst | 112 +++++++++++++++++++++++++++
 drivers/hwmon/pmbus/Kconfig     |   9 +++
 drivers/hwmon/pmbus/Makefile    |   1 +
 drivers/hwmon/pmbus/bel-pfe.c   | 131 ++++++++++++++++++++++++++++++++
 4 files changed, 253 insertions(+)
 create mode 100644 Documentation/hwmon/bel-pfe.rst
 create mode 100644 drivers/hwmon/pmbus/bel-pfe.c

-- 
2.17.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/3] hwmon: (pmbus) add BEL PFE1100 power supply driver
  2019-10-28 23:49 [PATCH 0/3] hwmon: (pmbus) add driver for BEL PFE1100 and PFE3000 rentao.bupt
@ 2019-10-28 23:49 ` rentao.bupt
  2019-10-29 12:42   ` Guenter Roeck
  2019-10-28 23:49 ` [PATCH 2/3] hwmon: (pmbus) add BEL PFE3000 " rentao.bupt
  2019-10-28 23:49 ` [PATCH 3/3] docs: hwmon: Document bel-pfe pmbus driver rentao.bupt
  2 siblings, 1 reply; 8+ messages in thread
From: rentao.bupt @ 2019-10-28 23:49 UTC (permalink / raw)
  To: Guenter Roeck, Jean Delvare, Jonathan Corbet, linux-hwmon,
	linux-doc, linux-kernel, openbmc, taoren
  Cc: Tao Ren

From: Tao Ren <rentao.bupt@gmail.com>

Add the driver to support BEL PFE1100 which is 1100 Wat AC to DC power
supply. The chip has only 1 page.

Signed-off-by: Tao Ren <rentao.bupt@gmail.com>
---
 drivers/hwmon/pmbus/Kconfig   |  9 +++++
 drivers/hwmon/pmbus/Makefile  |  1 +
 drivers/hwmon/pmbus/bel-pfe.c | 68 +++++++++++++++++++++++++++++++++++
 3 files changed, 78 insertions(+)
 create mode 100644 drivers/hwmon/pmbus/bel-pfe.c

diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig
index d62d69bb7e49..59859979571d 100644
--- a/drivers/hwmon/pmbus/Kconfig
+++ b/drivers/hwmon/pmbus/Kconfig
@@ -36,6 +36,15 @@ config SENSORS_ADM1275
 	  This driver can also be built as a module. If so, the module will
 	  be called adm1275.
 
+config SENSORS_BEL_PFE
+	tristate "Bel PFE Compatible Power Supplies"
+	help
+	  If you say yes here you get hardware monitoring support for BEL
+	  PFE1100 and PFE3000 Power Supplies.
+
+	  This driver can also be built as a module. If so, the module will
+	  be called bel-pfe.
+
 config SENSORS_IBM_CFFPS
 	tristate "IBM Common Form Factor Power Supply"
 	depends on LEDS_CLASS
diff --git a/drivers/hwmon/pmbus/Makefile b/drivers/hwmon/pmbus/Makefile
index 03bacfcfd660..3f8c1014938b 100644
--- a/drivers/hwmon/pmbus/Makefile
+++ b/drivers/hwmon/pmbus/Makefile
@@ -6,6 +6,7 @@
 obj-$(CONFIG_PMBUS)		+= pmbus_core.o
 obj-$(CONFIG_SENSORS_PMBUS)	+= pmbus.o
 obj-$(CONFIG_SENSORS_ADM1275)	+= adm1275.o
+obj-$(CONFIG_SENSORS_BEL_PFE)	+= bel-pfe.o
 obj-$(CONFIG_SENSORS_IBM_CFFPS)	+= ibm-cffps.o
 obj-$(CONFIG_SENSORS_INSPUR_IPSPS) += inspur-ipsps.o
 obj-$(CONFIG_SENSORS_IR35221)	+= ir35221.o
diff --git a/drivers/hwmon/pmbus/bel-pfe.c b/drivers/hwmon/pmbus/bel-pfe.c
new file mode 100644
index 000000000000..117f9af21bf3
--- /dev/null
+++ b/drivers/hwmon/pmbus/bel-pfe.c
@@ -0,0 +1,68 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Hardware monitoring driver for BEL PFE family power supplies.
+ *
+ * Copyright (c) 2019 Facebook Inc.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include "pmbus.h"
+
+enum chips {pfe1100};
+
+static struct pmbus_driver_info pfe_driver_info[] = {
+	[pfe1100] = {
+		.pages = 1,
+		.format[PSC_VOLTAGE_IN] = linear,
+		.format[PSC_VOLTAGE_OUT] = linear,
+		.format[PSC_CURRENT_IN] = linear,
+		.format[PSC_CURRENT_OUT] = linear,
+		.format[PSC_POWER] = linear,
+		.format[PSC_TEMPERATURE] = linear,
+		.format[PSC_FAN] = linear,
+
+		.func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
+			   PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
+			   PMBUS_HAVE_POUT |
+			   PMBUS_HAVE_VIN | PMBUS_HAVE_IIN |
+			   PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT |
+			   PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2 |
+			   PMBUS_HAVE_STATUS_TEMP |
+			   PMBUS_HAVE_FAN12,
+	},
+};
+
+static int pfe_pmbus_probe(struct i2c_client *client,
+			   const struct i2c_device_id *id)
+{
+	int model;
+
+	model = (int)id->driver_data;
+	return pmbus_do_probe(client, id, &pfe_driver_info[model]);
+}
+
+static const struct i2c_device_id pfe_device_id[] = {
+	{"pfe1100", pfe1100},
+	{}
+};
+
+MODULE_DEVICE_TABLE(i2c, pfe_device_id);
+
+static struct i2c_driver pfe_pmbus_driver = {
+	.driver = {
+		   .name = "bel-pfe",
+	},
+	.probe = pfe_pmbus_probe,
+	.remove = pmbus_do_remove,
+	.id_table = pfe_device_id,
+};
+
+module_i2c_driver(pfe_pmbus_driver);
+
+MODULE_AUTHOR("Tao Ren <rentao.bupt@gmail.com>");
+MODULE_DESCRIPTION("PMBus driver for BEL PFE Family Power Supplies");
+MODULE_LICENSE("GPL");
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/3] hwmon: (pmbus) add BEL PFE3000 power supply driver
  2019-10-28 23:49 [PATCH 0/3] hwmon: (pmbus) add driver for BEL PFE1100 and PFE3000 rentao.bupt
  2019-10-28 23:49 ` [PATCH 1/3] hwmon: (pmbus) add BEL PFE1100 power supply driver rentao.bupt
@ 2019-10-28 23:49 ` rentao.bupt
  2019-10-29 12:50   ` Guenter Roeck
  2019-10-28 23:49 ` [PATCH 3/3] docs: hwmon: Document bel-pfe pmbus driver rentao.bupt
  2 siblings, 1 reply; 8+ messages in thread
From: rentao.bupt @ 2019-10-28 23:49 UTC (permalink / raw)
  To: Guenter Roeck, Jean Delvare, Jonathan Corbet, linux-hwmon,
	linux-doc, linux-kernel, openbmc, taoren
  Cc: Tao Ren

From: Tao Ren <rentao.bupt@gmail.com>

Add the driver to support BEL PFE3000 which is 3000 Wat AC to DC power
supply. The chip has 8 pages.

Signed-off-by: Tao Ren <rentao.bupt@gmail.com>
---
 drivers/hwmon/pmbus/bel-pfe.c | 65 ++++++++++++++++++++++++++++++++++-
 1 file changed, 64 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/pmbus/bel-pfe.c b/drivers/hwmon/pmbus/bel-pfe.c
index 117f9af21bf3..7b6c90b056c9 100644
--- a/drivers/hwmon/pmbus/bel-pfe.c
+++ b/drivers/hwmon/pmbus/bel-pfe.c
@@ -10,9 +10,21 @@
 #include <linux/init.h>
 #include <linux/err.h>
 #include <linux/i2c.h>
+#include <linux/pmbus.h>
+
 #include "pmbus.h"
 
-enum chips {pfe1100};
+enum chips {pfe1100, pfe3000};
+
+/*
+ * Disable status check for pfe3000 devices, because some devices report
+ * communication error (invalid command) for VOUT_MODE command (0x20)
+ * although correct VOUT_MODE (0x16) is returned: it leads to incorrect
+ * exponent in linear mode.
+ */
+static struct pmbus_platform_data pfe3000_plat_data = {
+	.flags = PMBUS_SKIP_STATUS_CHECK,
+};
 
 static struct pmbus_driver_info pfe_driver_info[] = {
 	[pfe1100] = {
@@ -34,6 +46,45 @@ static struct pmbus_driver_info pfe_driver_info[] = {
 			   PMBUS_HAVE_STATUS_TEMP |
 			   PMBUS_HAVE_FAN12,
 	},
+
+	[pfe3000] = {
+		.pages = 8,
+		.format[PSC_VOLTAGE_IN] = linear,
+		.format[PSC_VOLTAGE_OUT] = linear,
+		.format[PSC_CURRENT_IN] = linear,
+		.format[PSC_CURRENT_OUT] = linear,
+		.format[PSC_POWER] = linear,
+		.format[PSC_TEMPERATURE] = linear,
+		.format[PSC_FAN] = linear,
+
+		/* Page 0: V1. */
+		.func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
+			   PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
+			   PMBUS_HAVE_POUT | PMBUS_HAVE_FAN12 |
+			   PMBUS_HAVE_VIN | PMBUS_HAVE_IIN |
+			   PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT |
+			   PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2 |
+			   PMBUS_HAVE_TEMP3 | PMBUS_HAVE_STATUS_TEMP |
+			   PMBUS_HAVE_VCAP,
+
+		/* Page 1: Vsb. */
+		.func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
+			   PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
+			   PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT |
+			   PMBUS_HAVE_POUT,
+
+		/*
+		 * Page 2: V1 Ishare.
+		 * Page 4: V1 Cathode.
+		 * Page 5: Vsb Cathode.
+		 * Page 6: V1 Sense.
+		 * Page 3 and 7 are reserved.
+		 */
+		.func[2] = PMBUS_HAVE_VOUT,
+		.func[4] = PMBUS_HAVE_VOUT,
+		.func[5] = PMBUS_HAVE_VOUT,
+		.func[6] = PMBUS_HAVE_VOUT,
+	},
 };
 
 static int pfe_pmbus_probe(struct i2c_client *client,
@@ -42,11 +93,23 @@ static int pfe_pmbus_probe(struct i2c_client *client,
 	int model;
 
 	model = (int)id->driver_data;
+
+	/*
+	 * PFE3000-12-069RA devices may not stay in page 0 during device
+	 * probe which leads to probe failure (read status word failed).
+	 * So let's set the device to page 0 at the beginning.
+	 */
+	if (model == pfe3000) {
+		client->dev.platform_data = &pfe3000_plat_data;
+		i2c_smbus_write_byte_data(client, PMBUS_PAGE, 0);
+	}
+
 	return pmbus_do_probe(client, id, &pfe_driver_info[model]);
 }
 
 static const struct i2c_device_id pfe_device_id[] = {
 	{"pfe1100", pfe1100},
+	{"pfe3000", pfe3000},
 	{}
 };
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/3] docs: hwmon: Document bel-pfe pmbus driver
  2019-10-28 23:49 [PATCH 0/3] hwmon: (pmbus) add driver for BEL PFE1100 and PFE3000 rentao.bupt
  2019-10-28 23:49 ` [PATCH 1/3] hwmon: (pmbus) add BEL PFE1100 power supply driver rentao.bupt
  2019-10-28 23:49 ` [PATCH 2/3] hwmon: (pmbus) add BEL PFE3000 " rentao.bupt
@ 2019-10-28 23:49 ` rentao.bupt
  2 siblings, 0 replies; 8+ messages in thread
From: rentao.bupt @ 2019-10-28 23:49 UTC (permalink / raw)
  To: Guenter Roeck, Jean Delvare, Jonathan Corbet, linux-hwmon,
	linux-doc, linux-kernel, openbmc, taoren
  Cc: Tao Ren

From: Tao Ren <rentao.bupt@gmail.com>

Add documentation for bel-pfe pmbus driver which supports BEL PFE1100 and
PFE3000 power supplies.

Signed-off-by: Tao Ren <rentao.bupt@gmail.com>
---
 Documentation/hwmon/bel-pfe.rst | 112 ++++++++++++++++++++++++++++++++
 1 file changed, 112 insertions(+)
 create mode 100644 Documentation/hwmon/bel-pfe.rst

diff --git a/Documentation/hwmon/bel-pfe.rst b/Documentation/hwmon/bel-pfe.rst
new file mode 100644
index 000000000000..4b4a7d67854c
--- /dev/null
+++ b/Documentation/hwmon/bel-pfe.rst
@@ -0,0 +1,112 @@
+Kernel driver bel-pfe
+======================
+
+Supported chips:
+
+  * BEL PFE1100
+
+    Prefixes: 'pfe1100'
+
+    Addresses scanned: -
+
+    Datasheet: https://www.belfuse.com/resources/datasheets/powersolutions/ds-bps-pfe1100-12-054xa.pdf
+
+  * BEL PFE3000
+
+    Prefixes: 'pfe3000'
+
+    Addresses scanned: -
+
+    Datasheet: https://www.belfuse.com/resources/datasheets/powersolutions/ds-bps-pfe3000-series.pdf
+
+Author: Tao Ren <rentao.bupt@gmail.com>
+
+
+Description
+-----------
+
+This driver supports hardware monitoring for below power supply devices
+which support PMBus Protocol:
+
+  * BEL PFE1100
+
+    1100 Watt AC to DC power-factor-corrected (PFC) power supply.
+    PMBus Communication Manual is not publicly available.
+
+  * BEL PFE3000
+
+    3000 Watt AC/DC power-factor-corrected (PFC) and DC-DC power supply.
+    PMBus Communication Manual is not publicly available.
+
+The driver is a client driver to the core PMBus driver. Please see
+Documentation/hwmon/pmbus.rst for details on PMBus client drivers.
+
+
+Usage Notes
+-----------
+
+This driver does not auto-detect devices. You will have to instantiate the
+devices explicitly. Please see Documentation/i2c/instantiating-devices.rst for
+details.
+
+Example: the following will load the driver for an PFE3000 at address 0x20
+on I2C bus #1::
+
+	$ modprobe bel-pfe
+	$ echo pfe3000 0x20 > /sys/bus/i2c/devices/i2c-1/new_device
+
+
+Platform data support
+---------------------
+
+The driver supports standard PMBus driver platform data.
+
+
+Sysfs entries
+-------------
+
+======================= =======================================================
+curr1_label		"iin"
+curr1_input		Measured input current
+curr1_max               Input current max value
+curr1_max_alarm         Input current max alarm
+
+curr[2-3]_label		"iout[1-2]"
+curr[2-3]_input		Measured output current
+curr[2-3]_max           Output current max value
+curr[2-3]_max_alarm     Output current max alarm
+
+fan[1-2]_input          Fan 1 and 2 speed in RPM
+fan1_target             Set fan speed reference for both fans
+
+in1_label		"vin"
+in1_input		Measured input voltage
+in1_crit		Input voltage critical max value
+in1_crit_alarm		Input voltage critical max alarm
+in1_lcrit               Input voltage critical min value
+in1_lcrit_alarm         Input voltage critical min alarm
+in1_max                 Input voltage max value
+in1_max_alarm           Input voltage max alarm
+
+in2_label               "vcap"
+in2_input               Hold up capacitor voltage
+
+in[3-8]_label		"vout[1-3,5-7]"
+in[3-8]_input		Measured output voltage
+in[3-4]_alarm           vout[1-2] output voltage alarm
+
+power[1-2]_label	"pin[1-2]"
+power[1-2]_input        Measured input power
+power[1-2]_alarm	Input power high alarm
+
+power[3-4]_label	"pout[1-2]"
+power[3-4]_input	Measured output power
+
+temp[1-3]_input		Measured temperature
+temp[1-3]_alarm         Temperature alarm
+======================= =======================================================
+
+.. note::
+
+    - curr3, fan2, vout[2-7], vcap, pin2, pout2 and temp3 attributes only
+      exist for PFE3000.
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] hwmon: (pmbus) add BEL PFE1100 power supply driver
  2019-10-28 23:49 ` [PATCH 1/3] hwmon: (pmbus) add BEL PFE1100 power supply driver rentao.bupt
@ 2019-10-29 12:42   ` Guenter Roeck
  2019-10-29 17:53     ` Tao Ren
  0 siblings, 1 reply; 8+ messages in thread
From: Guenter Roeck @ 2019-10-29 12:42 UTC (permalink / raw)
  To: rentao.bupt
  Cc: Jean Delvare, Jonathan Corbet, linux-hwmon, linux-doc,
	linux-kernel, openbmc, taoren

On Mon, Oct 28, 2019 at 04:49:02PM -0700, rentao.bupt@gmail.com wrote:
> From: Tao Ren <rentao.bupt@gmail.com>
> 
> Add the driver to support BEL PFE1100 which is 1100 Wat AC to DC power
> supply. The chip has only 1 page.
> 
> Signed-off-by: Tao Ren <rentao.bupt@gmail.com>

Please combine with the next patch.

> ---
>  drivers/hwmon/pmbus/Kconfig   |  9 +++++
>  drivers/hwmon/pmbus/Makefile  |  1 +
>  drivers/hwmon/pmbus/bel-pfe.c | 68 +++++++++++++++++++++++++++++++++++
>  3 files changed, 78 insertions(+)
>  create mode 100644 drivers/hwmon/pmbus/bel-pfe.c
> 
> diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig
> index d62d69bb7e49..59859979571d 100644
> --- a/drivers/hwmon/pmbus/Kconfig
> +++ b/drivers/hwmon/pmbus/Kconfig
> @@ -36,6 +36,15 @@ config SENSORS_ADM1275
>  	  This driver can also be built as a module. If so, the module will
>  	  be called adm1275.
>  
> +config SENSORS_BEL_PFE
> +	tristate "Bel PFE Compatible Power Supplies"
> +	help
> +	  If you say yes here you get hardware monitoring support for BEL
> +	  PFE1100 and PFE3000 Power Supplies.
> +
> +	  This driver can also be built as a module. If so, the module will
> +	  be called bel-pfe.
> +
>  config SENSORS_IBM_CFFPS
>  	tristate "IBM Common Form Factor Power Supply"
>  	depends on LEDS_CLASS
> diff --git a/drivers/hwmon/pmbus/Makefile b/drivers/hwmon/pmbus/Makefile
> index 03bacfcfd660..3f8c1014938b 100644
> --- a/drivers/hwmon/pmbus/Makefile
> +++ b/drivers/hwmon/pmbus/Makefile
> @@ -6,6 +6,7 @@
>  obj-$(CONFIG_PMBUS)		+= pmbus_core.o
>  obj-$(CONFIG_SENSORS_PMBUS)	+= pmbus.o
>  obj-$(CONFIG_SENSORS_ADM1275)	+= adm1275.o
> +obj-$(CONFIG_SENSORS_BEL_PFE)	+= bel-pfe.o
>  obj-$(CONFIG_SENSORS_IBM_CFFPS)	+= ibm-cffps.o
>  obj-$(CONFIG_SENSORS_INSPUR_IPSPS) += inspur-ipsps.o
>  obj-$(CONFIG_SENSORS_IR35221)	+= ir35221.o
> diff --git a/drivers/hwmon/pmbus/bel-pfe.c b/drivers/hwmon/pmbus/bel-pfe.c
> new file mode 100644
> index 000000000000..117f9af21bf3
> --- /dev/null
> +++ b/drivers/hwmon/pmbus/bel-pfe.c
> @@ -0,0 +1,68 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Hardware monitoring driver for BEL PFE family power supplies.
> + *
> + * Copyright (c) 2019 Facebook Inc.
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/init.h>
> +#include <linux/err.h>
> +#include <linux/i2c.h>

Alphabetic include file order, please.

> +#include "pmbus.h"
> +
> +enum chips {pfe1100};
> +
> +static struct pmbus_driver_info pfe_driver_info[] = {
> +	[pfe1100] = {
> +		.pages = 1,
> +		.format[PSC_VOLTAGE_IN] = linear,
> +		.format[PSC_VOLTAGE_OUT] = linear,
> +		.format[PSC_CURRENT_IN] = linear,
> +		.format[PSC_CURRENT_OUT] = linear,
> +		.format[PSC_POWER] = linear,
> +		.format[PSC_TEMPERATURE] = linear,
> +		.format[PSC_FAN] = linear,
> +
> +		.func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
> +			   PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
> +			   PMBUS_HAVE_POUT |
> +			   PMBUS_HAVE_VIN | PMBUS_HAVE_IIN |
> +			   PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT |
> +			   PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2 |
> +			   PMBUS_HAVE_STATUS_TEMP |
> +			   PMBUS_HAVE_FAN12,
> +	},
> +};
> +
> +static int pfe_pmbus_probe(struct i2c_client *client,
> +			   const struct i2c_device_id *id)
> +{
> +	int model;
> +
> +	model = (int)id->driver_data;
> +	return pmbus_do_probe(client, id, &pfe_driver_info[model]);
> +}
> +
> +static const struct i2c_device_id pfe_device_id[] = {
> +	{"pfe1100", pfe1100},
> +	{}
> +};
> +
> +MODULE_DEVICE_TABLE(i2c, pfe_device_id);
> +
> +static struct i2c_driver pfe_pmbus_driver = {
> +	.driver = {
> +		   .name = "bel-pfe",
> +	},
> +	.probe = pfe_pmbus_probe,
> +	.remove = pmbus_do_remove,
> +	.id_table = pfe_device_id,
> +};
> +
> +module_i2c_driver(pfe_pmbus_driver);
> +
> +MODULE_AUTHOR("Tao Ren <rentao.bupt@gmail.com>");
> +MODULE_DESCRIPTION("PMBus driver for BEL PFE Family Power Supplies");
> +MODULE_LICENSE("GPL");

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/3] hwmon: (pmbus) add BEL PFE3000 power supply driver
  2019-10-28 23:49 ` [PATCH 2/3] hwmon: (pmbus) add BEL PFE3000 " rentao.bupt
@ 2019-10-29 12:50   ` Guenter Roeck
  2019-10-29 17:58     ` Tao Ren
  0 siblings, 1 reply; 8+ messages in thread
From: Guenter Roeck @ 2019-10-29 12:50 UTC (permalink / raw)
  To: rentao.bupt
  Cc: Jean Delvare, Jonathan Corbet, linux-hwmon, linux-doc,
	linux-kernel, openbmc, taoren

On Mon, Oct 28, 2019 at 04:49:03PM -0700, rentao.bupt@gmail.com wrote:
> From: Tao Ren <rentao.bupt@gmail.com>
> 
> Add the driver to support BEL PFE3000 which is 3000 Wat AC to DC power

which is a ...

Watt

> supply. The chip has 8 pages.

FWIW, that is a bit misleading here. It isn't really 8 pages. I would suggest
to drop that comment (or, if you insist, at least add "two of which are
reserved").

> 
> Signed-off-by: Tao Ren <rentao.bupt@gmail.com>
> ---
>  drivers/hwmon/pmbus/bel-pfe.c | 65 ++++++++++++++++++++++++++++++++++-
>  1 file changed, 64 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/pmbus/bel-pfe.c b/drivers/hwmon/pmbus/bel-pfe.c
> index 117f9af21bf3..7b6c90b056c9 100644
> --- a/drivers/hwmon/pmbus/bel-pfe.c
> +++ b/drivers/hwmon/pmbus/bel-pfe.c
> @@ -10,9 +10,21 @@
>  #include <linux/init.h>
>  #include <linux/err.h>
>  #include <linux/i2c.h>
> +#include <linux/pmbus.h>
> +
>  #include "pmbus.h"
>  
> -enum chips {pfe1100};
> +enum chips {pfe1100, pfe3000};
> +
> +/*
> + * Disable status check for pfe3000 devices, because some devices report
> + * communication error (invalid command) for VOUT_MODE command (0x20)
> + * although correct VOUT_MODE (0x16) is returned: it leads to incorrect
> + * exponent in linear mode.
> + */
> +static struct pmbus_platform_data pfe3000_plat_data = {
> +	.flags = PMBUS_SKIP_STATUS_CHECK,
> +};
>  
>  static struct pmbus_driver_info pfe_driver_info[] = {
>  	[pfe1100] = {
> @@ -34,6 +46,45 @@ static struct pmbus_driver_info pfe_driver_info[] = {
>  			   PMBUS_HAVE_STATUS_TEMP |
>  			   PMBUS_HAVE_FAN12,
>  	},
> +
> +	[pfe3000] = {
> +		.pages = 8,
> +		.format[PSC_VOLTAGE_IN] = linear,
> +		.format[PSC_VOLTAGE_OUT] = linear,
> +		.format[PSC_CURRENT_IN] = linear,
> +		.format[PSC_CURRENT_OUT] = linear,
> +		.format[PSC_POWER] = linear,
> +		.format[PSC_TEMPERATURE] = linear,
> +		.format[PSC_FAN] = linear,
> +
> +		/* Page 0: V1. */
> +		.func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
> +			   PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
> +			   PMBUS_HAVE_POUT | PMBUS_HAVE_FAN12 |
> +			   PMBUS_HAVE_VIN | PMBUS_HAVE_IIN |
> +			   PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT |
> +			   PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2 |
> +			   PMBUS_HAVE_TEMP3 | PMBUS_HAVE_STATUS_TEMP |
> +			   PMBUS_HAVE_VCAP,
> +
> +		/* Page 1: Vsb. */
> +		.func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
> +			   PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
> +			   PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT |
> +			   PMBUS_HAVE_POUT,
> +
> +		/*
> +		 * Page 2: V1 Ishare.
> +		 * Page 4: V1 Cathode.
> +		 * Page 5: Vsb Cathode.
> +		 * Page 6: V1 Sense.
> +		 * Page 3 and 7 are reserved.

If page 7 is reserved, and doesn't have any attributes, it doesn't really
make sense to claim support for 8 pages above. I would suugest to make it 7.

> +		 */
> +		.func[2] = PMBUS_HAVE_VOUT,
> +		.func[4] = PMBUS_HAVE_VOUT,
> +		.func[5] = PMBUS_HAVE_VOUT,
> +		.func[6] = PMBUS_HAVE_VOUT,
> +	},
>  };
>  
>  static int pfe_pmbus_probe(struct i2c_client *client,
> @@ -42,11 +93,23 @@ static int pfe_pmbus_probe(struct i2c_client *client,
>  	int model;
>  
>  	model = (int)id->driver_data;
> +
> +	/*
> +	 * PFE3000-12-069RA devices may not stay in page 0 during device
> +	 * probe which leads to probe failure (read status word failed).
> +	 * So let's set the device to page 0 at the beginning.
> +	 */
> +	if (model == pfe3000) {
> +		client->dev.platform_data = &pfe3000_plat_data;
> +		i2c_smbus_write_byte_data(client, PMBUS_PAGE, 0);
> +	}
> +
>  	return pmbus_do_probe(client, id, &pfe_driver_info[model]);
>  }
>  
>  static const struct i2c_device_id pfe_device_id[] = {
>  	{"pfe1100", pfe1100},
> +	{"pfe3000", pfe3000},
>  	{}
>  };
>  

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] hwmon: (pmbus) add BEL PFE1100 power supply driver
  2019-10-29 12:42   ` Guenter Roeck
@ 2019-10-29 17:53     ` Tao Ren
  0 siblings, 0 replies; 8+ messages in thread
From: Tao Ren @ 2019-10-29 17:53 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Jean Delvare, Jonathan Corbet, linux-hwmon, linux-doc,
	linux-kernel, openbmc, taoren

On Tue, Oct 29, 2019 at 05:42:55AM -0700, Guenter Roeck wrote:
> On Mon, Oct 28, 2019 at 04:49:02PM -0700, rentao.bupt@gmail.com wrote:
> > From: Tao Ren <rentao.bupt@gmail.com>
> > 
> > Add the driver to support BEL PFE1100 which is 1100 Wat AC to DC power
> > supply. The chip has only 1 page.
> > 
> > Signed-off-by: Tao Ren <rentao.bupt@gmail.com>
> 
> Please combine with the next patch.

Sure. Will combine the 2 patches in v2.

> > ---
> >  drivers/hwmon/pmbus/Kconfig   |  9 +++++
> >  drivers/hwmon/pmbus/Makefile  |  1 +
> >  drivers/hwmon/pmbus/bel-pfe.c | 68 +++++++++++++++++++++++++++++++++++
> >  3 files changed, 78 insertions(+)
> >  create mode 100644 drivers/hwmon/pmbus/bel-pfe.c
> > 
> > diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig
> > index d62d69bb7e49..59859979571d 100644
> > --- a/drivers/hwmon/pmbus/Kconfig
> > +++ b/drivers/hwmon/pmbus/Kconfig
> > @@ -36,6 +36,15 @@ config SENSORS_ADM1275
> >  	  This driver can also be built as a module. If so, the module will
> >  	  be called adm1275.
> >  
> > +config SENSORS_BEL_PFE
> > +	tristate "Bel PFE Compatible Power Supplies"
> > +	help
> > +	  If you say yes here you get hardware monitoring support for BEL
> > +	  PFE1100 and PFE3000 Power Supplies.
> > +
> > +	  This driver can also be built as a module. If so, the module will
> > +	  be called bel-pfe.
> > +
> >  config SENSORS_IBM_CFFPS
> >  	tristate "IBM Common Form Factor Power Supply"
> >  	depends on LEDS_CLASS
> > diff --git a/drivers/hwmon/pmbus/Makefile b/drivers/hwmon/pmbus/Makefile
> > index 03bacfcfd660..3f8c1014938b 100644
> > --- a/drivers/hwmon/pmbus/Makefile
> > +++ b/drivers/hwmon/pmbus/Makefile
> > @@ -6,6 +6,7 @@
> >  obj-$(CONFIG_PMBUS)		+= pmbus_core.o
> >  obj-$(CONFIG_SENSORS_PMBUS)	+= pmbus.o
> >  obj-$(CONFIG_SENSORS_ADM1275)	+= adm1275.o
> > +obj-$(CONFIG_SENSORS_BEL_PFE)	+= bel-pfe.o
> >  obj-$(CONFIG_SENSORS_IBM_CFFPS)	+= ibm-cffps.o
> >  obj-$(CONFIG_SENSORS_INSPUR_IPSPS) += inspur-ipsps.o
> >  obj-$(CONFIG_SENSORS_IR35221)	+= ir35221.o
> > diff --git a/drivers/hwmon/pmbus/bel-pfe.c b/drivers/hwmon/pmbus/bel-pfe.c
> > new file mode 100644
> > index 000000000000..117f9af21bf3
> > --- /dev/null
> > +++ b/drivers/hwmon/pmbus/bel-pfe.c
> > @@ -0,0 +1,68 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/*
> > + * Hardware monitoring driver for BEL PFE family power supplies.
> > + *
> > + * Copyright (c) 2019 Facebook Inc.
> > + */
> > +
> > +#include <linux/kernel.h>
> > +#include <linux/module.h>
> > +#include <linux/init.h>
> > +#include <linux/err.h>
> > +#include <linux/i2c.h>
> 
> Alphabetic include file order, please.

Got it. Will take care of it in v2.
 
> > +#include "pmbus.h"
> > +
> > +enum chips {pfe1100};
> > +
> > +static struct pmbus_driver_info pfe_driver_info[] = {
> > +	[pfe1100] = {
> > +		.pages = 1,
> > +		.format[PSC_VOLTAGE_IN] = linear,
> > +		.format[PSC_VOLTAGE_OUT] = linear,
> > +		.format[PSC_CURRENT_IN] = linear,
> > +		.format[PSC_CURRENT_OUT] = linear,
> > +		.format[PSC_POWER] = linear,
> > +		.format[PSC_TEMPERATURE] = linear,
> > +		.format[PSC_FAN] = linear,
> > +
> > +		.func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
> > +			   PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
> > +			   PMBUS_HAVE_POUT |
> > +			   PMBUS_HAVE_VIN | PMBUS_HAVE_IIN |
> > +			   PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT |
> > +			   PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2 |
> > +			   PMBUS_HAVE_STATUS_TEMP |
> > +			   PMBUS_HAVE_FAN12,
> > +	},
> > +};
> > +
> > +static int pfe_pmbus_probe(struct i2c_client *client,
> > +			   const struct i2c_device_id *id)
> > +{
> > +	int model;
> > +
> > +	model = (int)id->driver_data;
> > +	return pmbus_do_probe(client, id, &pfe_driver_info[model]);
> > +}
> > +
> > +static const struct i2c_device_id pfe_device_id[] = {
> > +	{"pfe1100", pfe1100},
> > +	{}
> > +};
> > +
> > +MODULE_DEVICE_TABLE(i2c, pfe_device_id);
> > +
> > +static struct i2c_driver pfe_pmbus_driver = {
> > +	.driver = {
> > +		   .name = "bel-pfe",
> > +	},
> > +	.probe = pfe_pmbus_probe,
> > +	.remove = pmbus_do_remove,
> > +	.id_table = pfe_device_id,
> > +};
> > +
> > +module_i2c_driver(pfe_pmbus_driver);
> > +
> > +MODULE_AUTHOR("Tao Ren <rentao.bupt@gmail.com>");
> > +MODULE_DESCRIPTION("PMBus driver for BEL PFE Family Power Supplies");
> > +MODULE_LICENSE("GPL");

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/3] hwmon: (pmbus) add BEL PFE3000 power supply driver
  2019-10-29 12:50   ` Guenter Roeck
@ 2019-10-29 17:58     ` Tao Ren
  0 siblings, 0 replies; 8+ messages in thread
From: Tao Ren @ 2019-10-29 17:58 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Jean Delvare, Jonathan Corbet, linux-hwmon, linux-doc,
	linux-kernel, openbmc, taoren

On Tue, Oct 29, 2019 at 05:50:48AM -0700, Guenter Roeck wrote:
> On Mon, Oct 28, 2019 at 04:49:03PM -0700, rentao.bupt@gmail.com wrote:
> > From: Tao Ren <rentao.bupt@gmail.com>
> > 
> > Add the driver to support BEL PFE3000 which is 3000 Wat AC to DC power
> 
> which is a ...
> 
> Watt

My bad.. I just moved to a new machine and didn't notice import errors
printed by checkpatch.pl: it might be the reason why the error is not
detected by checkpach.pl.
Thanks for pointing it out, will fix it in v2.
 
> > supply. The chip has 8 pages.
> 
> FWIW, that is a bit misleading here. It isn't really 8 pages. I would suggest
> to drop that comment (or, if you insist, at least add "two of which are
> reserved").

I will remove the part in patch v2.

> > 
> > Signed-off-by: Tao Ren <rentao.bupt@gmail.com>
> > ---
> >  drivers/hwmon/pmbus/bel-pfe.c | 65 ++++++++++++++++++++++++++++++++++-
> >  1 file changed, 64 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/hwmon/pmbus/bel-pfe.c b/drivers/hwmon/pmbus/bel-pfe.c
> > index 117f9af21bf3..7b6c90b056c9 100644
> > --- a/drivers/hwmon/pmbus/bel-pfe.c
> > +++ b/drivers/hwmon/pmbus/bel-pfe.c
> > @@ -10,9 +10,21 @@
> >  #include <linux/init.h>
> >  #include <linux/err.h>
> >  #include <linux/i2c.h>
> > +#include <linux/pmbus.h>
> > +
> >  #include "pmbus.h"
> >  
> > -enum chips {pfe1100};
> > +enum chips {pfe1100, pfe3000};
> > +
> > +/*
> > + * Disable status check for pfe3000 devices, because some devices report
> > + * communication error (invalid command) for VOUT_MODE command (0x20)
> > + * although correct VOUT_MODE (0x16) is returned: it leads to incorrect
> > + * exponent in linear mode.
> > + */
> > +static struct pmbus_platform_data pfe3000_plat_data = {
> > +	.flags = PMBUS_SKIP_STATUS_CHECK,
> > +};
> >  
> >  static struct pmbus_driver_info pfe_driver_info[] = {
> >  	[pfe1100] = {
> > @@ -34,6 +46,45 @@ static struct pmbus_driver_info pfe_driver_info[] = {
> >  			   PMBUS_HAVE_STATUS_TEMP |
> >  			   PMBUS_HAVE_FAN12,
> >  	},
> > +
> > +	[pfe3000] = {
> > +		.pages = 8,
> > +		.format[PSC_VOLTAGE_IN] = linear,
> > +		.format[PSC_VOLTAGE_OUT] = linear,
> > +		.format[PSC_CURRENT_IN] = linear,
> > +		.format[PSC_CURRENT_OUT] = linear,
> > +		.format[PSC_POWER] = linear,
> > +		.format[PSC_TEMPERATURE] = linear,
> > +		.format[PSC_FAN] = linear,
> > +
> > +		/* Page 0: V1. */
> > +		.func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
> > +			   PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
> > +			   PMBUS_HAVE_POUT | PMBUS_HAVE_FAN12 |
> > +			   PMBUS_HAVE_VIN | PMBUS_HAVE_IIN |
> > +			   PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT |
> > +			   PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2 |
> > +			   PMBUS_HAVE_TEMP3 | PMBUS_HAVE_STATUS_TEMP |
> > +			   PMBUS_HAVE_VCAP,
> > +
> > +		/* Page 1: Vsb. */
> > +		.func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
> > +			   PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
> > +			   PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT |
> > +			   PMBUS_HAVE_POUT,
> > +
> > +		/*
> > +		 * Page 2: V1 Ishare.
> > +		 * Page 4: V1 Cathode.
> > +		 * Page 5: Vsb Cathode.
> > +		 * Page 6: V1 Sense.
> > +		 * Page 3 and 7 are reserved.
> 
> If page 7 is reserved, and doesn't have any attributes, it doesn't really
> make sense to claim support for 8 pages above. I would suugest to make it 7.

Will set total pages to 7 in patch v2.
 
> > +		 */
> > +		.func[2] = PMBUS_HAVE_VOUT,
> > +		.func[4] = PMBUS_HAVE_VOUT,
> > +		.func[5] = PMBUS_HAVE_VOUT,
> > +		.func[6] = PMBUS_HAVE_VOUT,
> > +	},
> >  };
> >  
> >  static int pfe_pmbus_probe(struct i2c_client *client,
> > @@ -42,11 +93,23 @@ static int pfe_pmbus_probe(struct i2c_client *client,
> >  	int model;
> >  
> >  	model = (int)id->driver_data;
> > +
> > +	/*
> > +	 * PFE3000-12-069RA devices may not stay in page 0 during device
> > +	 * probe which leads to probe failure (read status word failed).
> > +	 * So let's set the device to page 0 at the beginning.
> > +	 */
> > +	if (model == pfe3000) {
> > +		client->dev.platform_data = &pfe3000_plat_data;
> > +		i2c_smbus_write_byte_data(client, PMBUS_PAGE, 0);
> > +	}
> > +
> >  	return pmbus_do_probe(client, id, &pfe_driver_info[model]);
> >  }
> >  
> >  static const struct i2c_device_id pfe_device_id[] = {
> >  	{"pfe1100", pfe1100},
> > +	{"pfe3000", pfe3000},
> >  	{}
> >  };
> >  

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-10-29 17:59 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-28 23:49 [PATCH 0/3] hwmon: (pmbus) add driver for BEL PFE1100 and PFE3000 rentao.bupt
2019-10-28 23:49 ` [PATCH 1/3] hwmon: (pmbus) add BEL PFE1100 power supply driver rentao.bupt
2019-10-29 12:42   ` Guenter Roeck
2019-10-29 17:53     ` Tao Ren
2019-10-28 23:49 ` [PATCH 2/3] hwmon: (pmbus) add BEL PFE3000 " rentao.bupt
2019-10-29 12:50   ` Guenter Roeck
2019-10-29 17:58     ` Tao Ren
2019-10-28 23:49 ` [PATCH 3/3] docs: hwmon: Document bel-pfe pmbus driver rentao.bupt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).