Re: [v4, 2/6] pmbus: Add driver for Maxim MAX31785 Intelligent Fan Controller

2017-11-05 Thread Guenter Roeck
On Fri, Nov 03, 2017 at 03:53:02PM +1100, Andrew Jeffery wrote:
> The Maxim MAX31785 is a PMBus device providing closed-loop, multi-channel fan
> management with temperature and remote voltage sensing. Various fan control
> features are provided, including PWM frequency control, temperature 
> hysteresis,
> dual tachometer measurements, and fan health monitoring.
> 
I updated the above text a little to make it more obvious that "are provided"
refers to the chip, not (yet) to the driver.

> This patch presents a basic driver using only the existing features of the
> PMBus subsystem.
> 
> Signed-off-by: Andrew Jeffery 

Applied to hwmon-next.

> ---
>  Documentation/hwmon/max31785   |  51 ++
>  drivers/hwmon/pmbus/Kconfig|  10 
>  drivers/hwmon/pmbus/Makefile   |   1 +
>  drivers/hwmon/pmbus/max31785.c | 116 
> +
>  4 files changed, 178 insertions(+)
>  create mode 100644 Documentation/hwmon/max31785
>  create mode 100644 drivers/hwmon/pmbus/max31785.c
> 
> diff --git a/Documentation/hwmon/max31785 b/Documentation/hwmon/max31785
> new file mode 100644
> index ..45fb6093dec2
> --- /dev/null
> +++ b/Documentation/hwmon/max31785
> @@ -0,0 +1,51 @@
> +Kernel driver max31785
> +==
> +
> +Supported chips:
> +  * Maxim MAX31785, MAX31785A
> +Prefix: 'max31785' or 'max31785a'
> +Addresses scanned: -
> +Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX31785.pdf
> +
> +Author: Andrew Jeffery 
> +
> +Description
> +---
> +
> +The Maxim MAX31785 is a PMBus device providing closed-loop, multi-channel fan
> +management with temperature and remote voltage sensing. Various fan control
> +features are provided, including PWM frequency control, temperature 
> hysteresis,
> +dual tachometer measurements, and fan health monitoring.
> +
> +For dual rotor fan configuration, the MAX31785 exposes the slowest rotor of 
> the
> +two in the fan[1-4]_input attributes.
> +
> +Usage Notes
> +---
> +
> +This driver does not probe for PMBus devices. You will have to instantiate
> +devices explicitly.
> +
> +Sysfs attributes
> +
> +
> +fan[1-4]_alarm   Fan alarm.
> +fan[1-4]_fault   Fan fault.
> +fan[1-4]_input   Fan RPM.
> +
> +in[1-6]_crit Critical maximum output voltage
> +in[1-6]_crit_alarm   Output voltage critical high alarm
> +in[1-6]_inputMeasured output voltage
> +in[1-6]_label"vout[18-23]"
> +in[1-6]_lcritCritical minimum output voltage
> +in[1-6]_lcrit_alarm  Output voltage critical low alarm
> +in[1-6]_max  Maximum output voltage
> +in[1-6]_max_alarmOutput voltage high alarm
> +in[1-6]_min  Minimum output voltage
> +in[1-6]_min_alarmOutput voltage low alarm
> +
> +temp[1-11]_crit  Critical high temperature
> +temp[1-11]_crit_alarmChip temperature critical high alarm
> +temp[1-11]_input Measured temperature
> +temp[1-11]_max   Maximum temperature
> +temp[1-11]_max_alarm Chip temperature high alarm
> diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig
> index 40019325b517..08479006c7f9 100644
> --- a/drivers/hwmon/pmbus/Kconfig
> +++ b/drivers/hwmon/pmbus/Kconfig
> @@ -114,6 +114,16 @@ config SENSORS_MAX20751
> This driver can also be built as a module. If so, the module will
> be called max20751.
>  
> +config SENSORS_MAX31785
> + tristate "Maxim MAX31785 and compatibles"
> + default n
> + help
> +   If you say yes here you get hardware monitoring support for Maxim
> +   MAX31785.
> +
> +   This driver can also be built as a module. If so, the module will
> +   be called max31785.
> +
>  config SENSORS_MAX34440
>   tristate "Maxim MAX34440 and compatibles"
>   default n
> diff --git a/drivers/hwmon/pmbus/Makefile b/drivers/hwmon/pmbus/Makefile
> index 459a6be3390e..a8bf0e490db9 100644
> --- a/drivers/hwmon/pmbus/Makefile
> +++ b/drivers/hwmon/pmbus/Makefile
> @@ -12,6 +12,7 @@ obj-$(CONFIG_SENSORS_LTC2978)   += ltc2978.o
>  obj-$(CONFIG_SENSORS_LTC3815)+= ltc3815.o
>  obj-$(CONFIG_SENSORS_MAX16064)   += max16064.o
>  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_TPS40422)   += tps40422.o
> diff --git a/drivers/hwmon/pmbus/max31785.c b/drivers/hwmon/pmbus/max31785.c
> new file mode 100644
> index ..9313849d5160
> --- /dev/null
> +++ b/drivers/hwmon/pmbus/max31785.c
> @@ -0,0 +1,116 @@
> +/*
> + * Copyright (C) 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, o

[PATCH v4 2/6] pmbus: Add driver for Maxim MAX31785 Intelligent Fan Controller

2017-11-02 Thread Andrew Jeffery
The Maxim MAX31785 is a PMBus device providing closed-loop, multi-channel fan
management with temperature and remote voltage sensing. Various fan control
features are provided, including PWM frequency control, temperature hysteresis,
dual tachometer measurements, and fan health monitoring.

This patch presents a basic driver using only the existing features of the
PMBus subsystem.

Signed-off-by: Andrew Jeffery 
---
 Documentation/hwmon/max31785   |  51 ++
 drivers/hwmon/pmbus/Kconfig|  10 
 drivers/hwmon/pmbus/Makefile   |   1 +
 drivers/hwmon/pmbus/max31785.c | 116 +
 4 files changed, 178 insertions(+)
 create mode 100644 Documentation/hwmon/max31785
 create mode 100644 drivers/hwmon/pmbus/max31785.c

diff --git a/Documentation/hwmon/max31785 b/Documentation/hwmon/max31785
new file mode 100644
index ..45fb6093dec2
--- /dev/null
+++ b/Documentation/hwmon/max31785
@@ -0,0 +1,51 @@
+Kernel driver max31785
+==
+
+Supported chips:
+  * Maxim MAX31785, MAX31785A
+Prefix: 'max31785' or 'max31785a'
+Addresses scanned: -
+Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX31785.pdf
+
+Author: Andrew Jeffery 
+
+Description
+---
+
+The Maxim MAX31785 is a PMBus device providing closed-loop, multi-channel fan
+management with temperature and remote voltage sensing. Various fan control
+features are provided, including PWM frequency control, temperature hysteresis,
+dual tachometer measurements, and fan health monitoring.
+
+For dual rotor fan configuration, the MAX31785 exposes the slowest rotor of the
+two in the fan[1-4]_input attributes.
+
+Usage Notes
+---
+
+This driver does not probe for PMBus devices. You will have to instantiate
+devices explicitly.
+
+Sysfs attributes
+
+
+fan[1-4]_alarm Fan alarm.
+fan[1-4]_fault Fan fault.
+fan[1-4]_input Fan RPM.
+
+in[1-6]_crit   Critical maximum output voltage
+in[1-6]_crit_alarm Output voltage critical high alarm
+in[1-6]_input  Measured output voltage
+in[1-6]_label  "vout[18-23]"
+in[1-6]_lcrit  Critical minimum output voltage
+in[1-6]_lcrit_alarmOutput voltage critical low alarm
+in[1-6]_maxMaximum output voltage
+in[1-6]_max_alarm  Output voltage high alarm
+in[1-6]_minMinimum output voltage
+in[1-6]_min_alarm  Output voltage low alarm
+
+temp[1-11]_critCritical high temperature
+temp[1-11]_crit_alarm  Chip temperature critical high alarm
+temp[1-11]_input   Measured temperature
+temp[1-11]_max Maximum temperature
+temp[1-11]_max_alarm   Chip temperature high alarm
diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig
index 40019325b517..08479006c7f9 100644
--- a/drivers/hwmon/pmbus/Kconfig
+++ b/drivers/hwmon/pmbus/Kconfig
@@ -114,6 +114,16 @@ config SENSORS_MAX20751
  This driver can also be built as a module. If so, the module will
  be called max20751.
 
+config SENSORS_MAX31785
+   tristate "Maxim MAX31785 and compatibles"
+   default n
+   help
+ If you say yes here you get hardware monitoring support for Maxim
+ MAX31785.
+
+ This driver can also be built as a module. If so, the module will
+ be called max31785.
+
 config SENSORS_MAX34440
tristate "Maxim MAX34440 and compatibles"
default n
diff --git a/drivers/hwmon/pmbus/Makefile b/drivers/hwmon/pmbus/Makefile
index 459a6be3390e..a8bf0e490db9 100644
--- a/drivers/hwmon/pmbus/Makefile
+++ b/drivers/hwmon/pmbus/Makefile
@@ -12,6 +12,7 @@ obj-$(CONFIG_SENSORS_LTC2978) += ltc2978.o
 obj-$(CONFIG_SENSORS_LTC3815)  += ltc3815.o
 obj-$(CONFIG_SENSORS_MAX16064) += max16064.o
 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_TPS40422) += tps40422.o
diff --git a/drivers/hwmon/pmbus/max31785.c b/drivers/hwmon/pmbus/max31785.c
new file mode 100644
index ..9313849d5160
--- /dev/null
+++ b/drivers/hwmon/pmbus/max31785.c
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 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 
+#include 
+#include 
+#include 
+#include 
+#include "pmbus.h"
+
+enum max31785_regs {
+   MFR_REVISION= 0x9b,
+};
+
+#define MAX31785_NR_PAGES  23
+
+#define MAX31785_FAN_FUNCS \
+   (PMBUS_HAVE_FAN12 | PMBUS_HAVE_STATUS_FAN12)
+
+#define MAX31785_TEMP_FUNCS \
+   (PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP)
+
+#define MAX31785_VOUT_FUNCS \
+   (PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT)
+
+static const struct pmbus_