Skip to contentSkip to conversation

Add support for the Gateworks System Controller

PATCH Superseded Tim Harvey 4 participants 9 messages Mar 17, 2020 – Mar 20, 2020

Subsystems (5)

v6 of 11 Superseded Latest is v11 →

lore
Share & tools
lore

Tim Harvey

author maintainer
#0 lore raw

v6 cover Add support for the Gateworks System Controller

This series adds support for the Gateworks System Controller used on Gateworks Laguna, Ventana, and Newport product families.

The GSC is an MSP430 I2C slave controller whose firmware embeds the following features:
- I/O expander (16 GPIO's emulating a PCA955x)
- EEPROM (enumating AT24)
- RTC (enumating DS1672)
- HWMON
- Interrupt controller with tamper detect, user pushbotton
- Watchdog controller capable of full board power-cycle
- Power Control capable of full board power-cycle

see http://trac.gateworks.com/wiki/gsc for more details
---
v6:
- hwmon: fix size of info field
- hwmon: improve pwm output control documentation
- hwmon: include unit suffix in divider and offset
- hwmon: change subnode name to gsc-adc
- hwmon: change to fan subnode
- hwmon: fix voltage offset
- dt-bindings: fix commit message typo
- dt-bindings: drop invalid description from #interrupt-cells property
- dt-bindings: fix adc pattern property
- dt-bindings: add unit suffix
- dt-bindings: replace hwmon/adc with adc/channel
- dt-bindings: changed adc type to gw,mode
- dt-bindings: add unit suffix and drop ref for voltage-divider
- dt-bindings: add unit suffix for voltage-offset
- dt-bindings: moved fan to its own subnode with base register

v5:
- fix checkpatch issues
- fix dt_binding_check issues
- address feedback from v4

v4:
- hwmon: move to using pwm<n>_auto_point<m>_{pwm,temp} for FAN PWM
- hwmon: remove unncessary resolution/scaling properties for ADCs
- bindings: update to yaml Documentation
- removed watchdog driver

v3:
- removed unnecessary input driver
- added wdt driver
- bindings: encorporated feedback from mailng list
- hwmon:
- encoroprated feedback from mailng list
- added support for raw ADC voltage input used in newer GSC firmware

v2:
- change license comment block style
- remove COMPILE_TEST
- fixed whitespace issues
- replaced a printk with dev_err
- remove DEBUG
- simplify regmap_bulk_read err check
- remove break after returns in switch statement
- fix fan setpoint buffer address
- remove unnecessary parens
- consistently use struct device *dev pointer
- add validation for hwmon child node props
- move parsing of of to own function
- use strlcpy to ensure null termination
- fix static array sizes and removed unnecessary initializers
- dynamically allocate channels
- fix fan input label
- support platform data

Tim Harvey (3):
dt-bindings: mfd: Add Gateworks System Controller bindings
mfd: add Gateworks System Controller core driver
hwmon: add Gateworks System Controller support

 .../devicetree/bindings/mfd/gateworks-gsc.yaml     | 172 ++++++++++
 Documentation/hwmon/gsc-hwmon.rst                  |  53 +++
 Documentation/hwmon/index.rst                      |   1 +
 MAINTAINERS                                        |  11 +
 drivers/hwmon/Kconfig                              |   9 +
 drivers/hwmon/Makefile                             |   1 +
 drivers/hwmon/gsc-hwmon.c                          | 372 +++++++++++++++++++++
 drivers/mfd/Kconfig                                |  10 +
 drivers/mfd/Makefile                               |   1 +
 drivers/mfd/gateworks-gsc.c                        | 292 ++++++++++++++++
 include/linux/mfd/gsc.h                            |  72 ++++
 include/linux/platform_data/gsc_hwmon.h            |  44 +++
 12 files changed, 1038 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/gateworks-gsc.yaml
 create mode 100644 Documentation/hwmon/gsc-hwmon.rst
 create mode 100644 drivers/hwmon/gsc-hwmon.c
 create mode 100644 drivers/mfd/gateworks-gsc.c
 create mode 100644 include/linux/mfd/gsc.h
 create mode 100644 include/linux/platform_data/gsc_hwmon.h
Signature · 1 line
2.7.4
author maintainer
#1 lore raw

PATCH v6 1/3 dt-bindings: mfd: Add Gateworks System Controller bindings

This patch adds documentation of device-tree bindings for the Gateworks System Controller (GSC).

---
v6:
- fix commit message typo
- drop invalid description from #interrupt-cells property
- fix adc pattern property
- add unit suffix
- replace hwmon/adc with adc/channel
- changed adc type to gw,mode
- add unit suffix and drop ref for voltage-divider
- add unit suffix for voltage-offset
- moved fan to its own subnode with base register

v5:
- resolve dt_binding_check issues

v4:
- move to using pwm<n>_auto_point<m>_{pwm,temp} for FAN PWM
- remove unncessary resolution/scaling properties for ADCs
- update to yaml
- remove watchdog

v3:
- replaced _ with -
- remove input bindings
- added full description of hwmon
- fix unit address of hwmon child nodes

---
 .../devicetree/bindings/mfd/gateworks-gsc.yaml     | 172 +++++++++++++++++++++
 1 file changed, 172 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/gateworks-gsc.yaml
Documentation/devicetree/bindings/mfd/gateworks-gsc.yaml new file +172 -0
new file mode 100644
index 00000000..e921e67
@@ -0,0 +1,172 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/gateworks-gsc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Gateworks System Controller multi-function device
+
+description: |
+  The GSC is a Multifunction I2C slave device with the following submodules:
+   - Watchdog Timer
+   - GPIO
+   - Pushbutton controller
+   - Hardware Monitor with ADC's for temperature and voltage rails and
+     fan controller
+
+maintainers:
+  - Tim Harvey <[email protected]>
+  - Robert Jones <[email protected]>
+
+properties:
+  $nodename:
+    pattern: "gsc@[0-9a-f]{1,2}"
+  compatible:
+    const: gw,gsc
+
+  reg:
+    description: I2C device address
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  interrupt-controller: true
+
+  "#interrupt-cells":
+    const: 1
+
+  adc:
+    type: object
+    description: Optional Hardware Monitoring module
+
+    properties:
+      compatible:
+        const: gw,gsc-adc
+
+      "#address-cells":
+        const: 1
+
+      "#size-cells":
+        const: 0
+
+    patternProperties:
+      "^channel@[0-9]+$":
+        type: object
+        description: |
+          Properties for a single ADC which can report cooked values
+          (ie temperature sensor based on thermister), raw values
+          (ie voltage rail with a pre-scaling resistor divider).
+
+        properties:
+          reg:
+            description: Register of the ADC
+            maxItems: 1
+
+          label:
+            description: Name of the ADC input
+
+          gw,mode:
+            description: |
+              conversion mode:
+                0 - temperature, in C*10
+                1 - pre-scaled voltage value
+                2 - scaled voltage based on an optional resistor divider
+                    and optional offset
+            allOf:
+              - $ref: /schemas/types.yaml#/definitions/uint32
+            enum: [0, 1, 2]
+
+          gw,voltage-divider-milli-ohms:
+            description: values of resistors for divider on raw ADC input
+            items:
+              - description: R1
+              - description: R2
+
+          gw,voltage-offset-microvolt:
+            $ref: /schemas/types.yaml#/definitions/uint32
+            description: |
+              A positive voltage offset to apply to a raw ADC
+              (ie to compensate for a diode drop).
+
+        required:
+          - gw,mode
+          - reg
+          - label
+
+    required:
+      - compatible
+      - "#address-cells"
+      - "#size-cells"
+
+  fan:
+    type: object
+    description: Optional FAN controller
+
+    properties:
+      compatible:
+        const: gw,gsc-fan
+
+      base:
+        $ref: /schemas/types.yaml#/definitions/uint32
+        description: The fan controller base address
+        maxItems: 1
+
+    required:
+      - compatible
+      - base
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - interrupt-controller
+  - "#interrupt-cells"
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        gsc@20 {
+            compatible = "gw,gsc";
+            reg = <0x20>;
+            interrupt-parent = <&gpio1>;
+            interrupts = <4 GPIO_ACTIVE_LOW>;
+            interrupt-controller;
+            #interrupt-cells = <1>;
+
+            adc {
+                compatible = "gw,gsc-adc";
+                #address-cells = <1>;
+                #size-cells = <0>;
+
+                channel@0 { /* A0: Board Temperature */
+                    gw,mode = <0>;
+                    reg = <0x00>;
+                    label = "temp";
+                };
+
+                channel@2 { /* A1: Input Voltage (raw ADC) */
+                    gw,mode = <1>;
+                    reg = <0x02>;
+                    label = "vdd_vin";
+                    gw,voltage-divider-milli-ohms = <22100 1000>;
+                    gw,voltage-offset-microvolt = <800000>;
+                };
+
+                channel@b { /* A2: Battery voltage */
+                    gw,mode = <1>;
+                    reg = <0x0b>;
+                    label = "vdd_bat";
+                };
+            };
+
+            fan {
+                compatible = "gw,gsc-fan";
+                base = <0x2c>;
+            };
+        };
+    };
Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH v6 1/3] dt-bindings: mfd: Add Gateworks System Controller bindings

Quoted 116 lines · Tim Harvey

This patch adds documentation of device-tree bindings for the Gateworks System Controller (GSC).

---
v6:
- fix commit message typo
- drop invalid description from #interrupt-cells property
- fix adc pattern property
- add unit suffix
- replace hwmon/adc with adc/channel
- changed adc type to gw,mode
- add unit suffix and drop ref for voltage-divider
- add unit suffix for voltage-offset
- moved fan to its own subnode with base register

v5:
- resolve dt_binding_check issues

v4:
- move to using pwm<n>_auto_point<m>_{pwm,temp} for FAN PWM
- remove unncessary resolution/scaling properties for ADCs
- update to yaml
- remove watchdog

v3:
- replaced _ with -
- remove input bindings
- added full description of hwmon
- fix unit address of hwmon child nodes

---
 .../devicetree/bindings/mfd/gateworks-gsc.yaml     | 172 +++++++++++++++++++++
 1 file changed, 172 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/gateworks-gsc.yaml
Documentation/devicetree/bindings/mfd/gateworks-gsc.yaml new file +74 -0
new file mode 100644
index 00000000..e921e67
@@ -0,0 +1,172 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/gateworks-gsc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Gateworks System Controller multi-function device
+
+description: |
+  The GSC is a Multifunction I2C slave device with the following submodules:
+   - Watchdog Timer
+   - GPIO
+   - Pushbutton controller
+   - Hardware Monitor with ADC's for temperature and voltage rails and
+     fan controller
+
+maintainers:
+  - Tim Harvey <[email protected]>
+  - Robert Jones <[email protected]>
+
+properties:
+  $nodename:
+    pattern: "gsc@[0-9a-f]{1,2}"
+  compatible:
+    const: gw,gsc
+
+  reg:
+    description: I2C device address
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  interrupt-controller: true
+
+  "#interrupt-cells":
+    const: 1
+
+  adc:
+    type: object
+    description: Optional Hardware Monitoring module
+
+    properties:
+      compatible:
+        const: gw,gsc-adc
+
+      "#address-cells":
+        const: 1
+
+      "#size-cells":
+        const: 0
+
+    patternProperties:
+      "^channel@[0-9]+$":
+        type: object
+        description: |
+          Properties for a single ADC which can report cooked values
+          (ie temperature sensor based on thermister), raw values
+          (ie voltage rail with a pre-scaling resistor divider).
+
+        properties:
+          reg:
+            description: Register of the ADC
+            maxItems: 1
+
+          label:
+            description: Name of the ADC input
+
+          gw,mode:
+            description: |
+              conversion mode:
+                0 - temperature, in C*10
+                1 - pre-scaled voltage value
+                2 - scaled voltage based on an optional resistor divider

Documentation/devicetree/bindings/mfd/gateworks-gsc.yaml line 84

Quoted 10 lines
Documentation/devicetree/bindings/mfd/gateworks-gsc.yaml new file +10 -0
+                    and optional offset
+            allOf:
+              - $ref: /schemas/types.yaml#/definitions/uint32
+            enum: [0, 1, 2]
+
+          gw,voltage-divider-milli-ohms:
+            description: values of resistors for divider on raw ADC input
+            items:
+              - description: R1
+              - description: R2

Aren't there some constraints on the values? You could do something like this:

            maxItems: 2
            items:
              minimum: 1
              maximum: 2000

I know I said the way you have it is fine, but the example fails with it like this. It's related to how we encode the DT data for validation and some schema fixups we do to cut down on some boilerplate. We could just fix the example (with <> around each value), but having constraints is better.

Documentation/devicetree/bindings/mfd/gateworks-gsc.yaml line 87

Quoted 3 lines
Documentation/devicetree/bindings/mfd/gateworks-gsc.yaml new file +3 -0
+
+          gw,voltage-offset-microvolt:
+            $ref: /schemas/types.yaml#/definitions/uint32

Can drop this as .*-microvolt has a defined type.

Are there some constraints?

Quoted 5 lines
Documentation/devicetree/bindings/mfd/gateworks-gsc.yaml new file +5 -0
+            description: |
+              A positive voltage offset to apply to a raw ADC
+              (ie to compensate for a diode drop).
+
+        required:

Documentation/devicetree/bindings/mfd/gateworks-gsc.yaml line 102

Quoted 10 lines
Documentation/devicetree/bindings/mfd/gateworks-gsc.yaml new file +10 -0
+          - gw,mode
+          - reg
+          - label
+
+    required:
+      - compatible
+      - "#address-cells"
+      - "#size-cells"
+
+  fan:

fan-controller

Save 'fan' for if/when we have a node representing the fan itself.

Documentation/devicetree/bindings/mfd/gateworks-gsc.yaml line 110

Quoted 8 lines
Documentation/devicetree/bindings/mfd/gateworks-gsc.yaml new file +8 -0
+    type: object
+    description: Optional FAN controller
+
+    properties:
+      compatible:
+        const: gw,gsc-fan
+
+      base:

What happened to 'reg'? While inconsistent that adc doesn't have an address, better that than inventing your own address property.

Quoted 65 lines
Documentation/devicetree/bindings/mfd/gateworks-gsc.yaml new file +62 -1
+        $ref: /schemas/types.yaml#/definitions/uint32
+        description: The fan controller base address
+        maxItems: 1
+
+    required:
+      - compatible
+      - base
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - interrupt-controller
+  - "#interrupt-cells"
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        gsc@20 {
+            compatible = "gw,gsc";
+            reg = <0x20>;
+            interrupt-parent = <&gpio1>;
+            interrupts = <4 GPIO_ACTIVE_LOW>;
+            interrupt-controller;
+            #interrupt-cells = <1>;
+
+            adc {
+                compatible = "gw,gsc-adc";
+                #address-cells = <1>;
+                #size-cells = <0>;
+
+                channel@0 { /* A0: Board Temperature */
+                    gw,mode = <0>;
+                    reg = <0x00>;
+                    label = "temp";
+                };
+
+                channel@2 { /* A1: Input Voltage (raw ADC) */
+                    gw,mode = <1>;
+                    reg = <0x02>;
+                    label = "vdd_vin";
+                    gw,voltage-divider-milli-ohms = <22100 1000>;
+                    gw,voltage-offset-microvolt = <800000>;
+                };
+
+                channel@b { /* A2: Battery voltage */
+                    gw,mode = <1>;
+                    reg = <0x0b>;
+                    label = "vdd_bat";
+                };
+            };
+
+            fan {
+                compatible = "gw,gsc-fan";
+                base = <0x2c>;
+            };
+        };
+    };
--

2.7.4

author maintainer
#3 lore raw

PATCH v6 2/3 mfd: add Gateworks System Controller core driver

In reply to Tim Harvey

The Gateworks System Controller (GSC) is an I2C slave controller implemented with an MSP430 micro-controller whose firmware embeds the following features:
- I/O expander (16 GPIO's) using PCA955x protocol
- Real Time Clock using DS1672 protocol
- User EEPROM using AT24 protocol
- HWMON using custom protocol
- Interrupt controller with tamper detect, user pushbotton
- Watchdog controller capable of full board power-cycle
- Power Control capable of full board power-cycle

see http://trac.gateworks.com/wiki/gsc for more details

---
v6:
- remove duplicate signature and fix commit log

v5:
- simplify powerdown function

v4:
- remove hwmon max reg check/define
- fix powerdown function

v3:
- rename gsc->gateworks-gsc
- remove uncecessary include for linux/mfd/core.h
- upercase I2C in comments
- remove i2c debug
- remove uncecessary comments
- don't use KBUILD_MODNAME for name
- remove unnecessary v1/v2/v3 tracking
- unregister hwmon i2c adapter on remove

v2:
- change license comment block style
- remove COMPILE_TEST (Randy)
- fixed whitespace issues
- replaced a printk with dev_err

---
 MAINTAINERS                 |   8 ++
 drivers/mfd/Kconfig         |  10 ++
 drivers/mfd/Makefile        |   1 +
 drivers/mfd/gateworks-gsc.c | 292 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/gsc.h     |  72 +++++++++++
 5 files changed, 383 insertions(+)
 create mode 100644 drivers/mfd/gateworks-gsc.c
 create mode 100644 include/linux/mfd/gsc.h
MAINTAINERS +8 -0
index 56765f5..bb79b60 100644
@@ -6839,6 +6839,14 @@ F:	tools/testing/selftests/futex/
 F:	tools/perf/bench/futex*
 F:	Documentation/*futex*
 
+GATEWORKS SYSTEM CONTROLLER (GSC) DRIVER
+M:	Tim Harvey <[email protected]>
+M:	Robert Jones <[email protected]>
+S:	Maintained
+F:	Documentation/devicetree/bindings/mfd/gateworks-gsc.yaml
+F:	drivers/mfd/gateworks-gsc.c
+F:	include/linux/mfd/gsc.h
+
 GCC PLUGINS
 M:	Kees Cook <[email protected]>
 R:	Emese Revfy <[email protected]>
drivers/mfd/Kconfig +10 -0
index 4209008..d84725a 100644
@@ -407,6 +407,16 @@ config MFD_EXYNOS_LPASS
 	  Select this option to enable support for Samsung Exynos Low Power
 	  Audio Subsystem.
 
+config MFD_GATEWORKS_GSC
+	tristate "Gateworks System Controller"
+	depends on (I2C && OF)
+	select MFD_CORE
+	select REGMAP_I2C
+	select REGMAP_IRQ
+	help
+	  Enable support for the Gateworks System Controller found
+	  on Gateworks Single Board Computers.
+
 config MFD_MC13XXX
 	tristate
 	depends on (SPI_MASTER || I2C)
drivers/mfd/Makefile +1 -0
index aed99f0..c82b442 100644
@@ -15,6 +15,7 @@ obj-$(CONFIG_MFD_BCM590XX)	+= bcm590xx.o
 obj-$(CONFIG_MFD_BD9571MWV)	+= bd9571mwv.o
 obj-$(CONFIG_MFD_CROS_EC_DEV)	+= cros_ec_dev.o
 obj-$(CONFIG_MFD_EXYNOS_LPASS)	+= exynos-lpass.o
+obj-$(CONFIG_MFD_GATEWORKS_GSC)	+= gateworks-gsc.o
 
 obj-$(CONFIG_HTC_PASIC3)	+= htc-pasic3.o
 obj-$(CONFIG_HTC_I2CPLD)	+= htc-i2cpld.o
drivers/mfd/gateworks-gsc.c new file +292 -0

292 lines not on this page · raw message

include/linux/mfd/gsc.h new file +72 -0

72 lines not on this page · raw message

Signature · 1 line
2.7.4
author maintainer
#4 lore raw

PATCH v6 3/3 hwmon: add Gateworks System Controller support

In reply to Tim Harvey

The Gateworks System Controller has a hwmon sub-component that exposes up to 16 ADC's, some of which are temperature sensors, others which are voltage inputs. The ADC configuration (register mapping and name) is configured via device-tree and varies board to board.

Cc Guenter Roeck <[email protected]>

---
v6:
- fix size of info field
- improve pwm output control documentation
- include unit suffix in divider and offset
- change adc subnode name to gsc-adc
- change fan base to fan subnode
- change adc type to mode
- fix voltage offset scaling

v5:
- fix various checkpatch issues
- correct gsc-hwmon.rst in MAINTAINERS
- encorporate Gunter's feedback:
- switch to SENSOR_DEVICE_ATTR_{RW,RO}
- use tmp value to avoid excessive pointer deference
- simplify shift operation
- scale voffset once
- simplify is_visible function
- remove empty line at end of file

v4:
- adjust for uV offset from device-tree
- remove unnecessary optional write function
- remove register range check
- change dev_err prints to use gsc dev
- hard-code resolution/scaling for raw adcs
- describe units of ADC resolution
- move to using pwm<n>_auto_point<m>_{pwm,temp} for FAN PWM
- ensure space before/after operators
- remove unnecessary parens
- remove more debugging
- add default case and comment for type_voltage
- remove unnecessary index bounds checks for channel
- remove unnecessary clearing of struct fields
- added Documentation/hwmon/gsc-hwmon.rst

v3:
- add voltage_raw input type and supporting fields
- add channel validation to is_visible function
- remove unnecessary channel validation from read/write functions

v2:
- change license comment style
- remove DEBUG
- simplify regmap_bulk_read err check
- remove break after returns in switch statement
- fix fan setpoint buffer address
- remove unnecessary parens
- consistently use struct device *dev pointer
- change license/comment block
- add validation for hwmon child node props
- move parsing of of to own function
- use strlcpy to ensure null termination
- fix static array sizes and removed unnecessary initializers
- dynamically allocate channels
- fix fan input label
- support platform data
- fixed whitespace issues

---
 Documentation/hwmon/gsc-hwmon.rst       |  53 +++++
 Documentation/hwmon/index.rst           |   1 +
 MAINTAINERS                             |   3 +
 drivers/hwmon/Kconfig                   |   9 +
 drivers/hwmon/Makefile                  |   1 +
 drivers/hwmon/gsc-hwmon.c               | 372 ++++++++++++++++++++++++++++++++
 include/linux/platform_data/gsc_hwmon.h |  44 ++++
 7 files changed, 483 insertions(+)
 create mode 100644 Documentation/hwmon/gsc-hwmon.rst
 create mode 100644 drivers/hwmon/gsc-hwmon.c
 create mode 100644 include/linux/platform_data/gsc_hwmon.h
Documentation/hwmon/gsc-hwmon.rst new file +53 -0
new file mode 100644
index 00000000..ffac392
@@ -0,0 +1,53 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Kernel driver gsc-hwmon
+=======================
+
+Supported chips: Gateworks GSC
+Datasheet: http://trac.gateworks.com/wiki/gsc
+Author: Tim Harvey <[email protected]>
+
+Description:
+------------
+
+This driver supports hardware monitoring for the temperature sensor,
+various ADC's connected to the GSC, and optional FAN controller available
+on some boards.
+
+
+Voltage Monitoring
+------------------
+
+The voltage inputs are scaled either internally or by the driver depending
+on the GSC version and firmware. The values returned by the driver do not need
+further scaling. The voltage input labels provide the voltage rail name:
+
+inX_input                  Measured voltage (mV).
+inX_label                  Name of voltage rail.
+
+
+Temperature Monitoring
+----------------------
+
+Temperatures are measured with 12-bit or 10-bit resolution and are scaled
+either internally or by the driver depending on the GSC version and firmware.
+The values returned by the driver reflect millidegree Celcius:
+
+tempX_input                Measured temperature.
+tempX_label                Name of temperature input.
+
+
+PWM Output Control
+------------------
+
+The GSC features 1 PWM output that operates in automatic mode where the
+PWM value will be scalled depending on 6 temperature boundaries.
+The tempeature boundaries are read-write and in millidegree Celcius and the
+read-only PWM values range from 0 (off) to 255 (full speed).
+Fan speed will be set to minimum (off) when the temperature sensor reads
+less than pwm1_auto_point1_temp and maximum when the temperature sensor
+equals or exceeds pwm1_auto_point6_temp.
+
+pwm1_auto_point[1-6]_pwm       PWM value.
+pwm1_auto_point[1-6]_temp      Temperature boundary.
+
Documentation/hwmon/index.rst +1 -0
index 43cc605..a4fab69 100644
@@ -58,6 +58,7 @@ Hardware Monitoring Kernel Drivers
    ftsteutates
    g760a
    g762
+   gsc-hwmon
    gl518sm
    hih6130
    ibmaem
MAINTAINERS +3 -0
index bb79b60..3f15542 100644
@@ -6846,6 +6846,9 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/mfd/gateworks-gsc.yaml
 F:	drivers/mfd/gateworks-gsc.c
 F:	include/linux/mfd/gsc.h
+F:	Documentation/hwmon/gsc-hwmon.rst
+F:	drivers/hwmon/gsc-hwmon.c
+F:	include/linux/platform_data/gsc_hwmon.h
 
 GCC PLUGINS
 M:	Kees Cook <[email protected]>
drivers/hwmon/Kconfig +9 -0
index 23dfe84..99dae13 100644
@@ -494,6 +494,15 @@ config SENSORS_F75375S
 	  This driver can also be built as a module. If so, the module
 	  will be called f75375s.
 
+config SENSORS_GSC
+        tristate "Gateworks System Controller ADC"
+        depends on MFD_GATEWORKS_GSC
+        help
+          Support for the Gateworks System Controller A/D converters.
+
+	  To compile this driver as a module, choose M here:
+	  the module will be called gsc-hwmon.
+
 config SENSORS_MC13783_ADC
         tristate "Freescale MC13783/MC13892 ADC"
         depends on MFD_MC13XXX
drivers/hwmon/Makefile +1 -0
index 6db5db9..259cba7 100644
@@ -71,6 +71,7 @@ obj-$(CONFIG_SENSORS_G760A)	+= g760a.o
 obj-$(CONFIG_SENSORS_G762)	+= g762.o
 obj-$(CONFIG_SENSORS_GL518SM)	+= gl518sm.o
 obj-$(CONFIG_SENSORS_GL520SM)	+= gl520sm.o
+obj-$(CONFIG_SENSORS_GSC)	+= gsc-hwmon.o
 obj-$(CONFIG_SENSORS_GPIO_FAN)	+= gpio-fan.o
 obj-$(CONFIG_SENSORS_HIH6130)	+= hih6130.o
 obj-$(CONFIG_SENSORS_ULTRA45)	+= ultra45_env.o
drivers/hwmon/gsc-hwmon.c new file +372 -0

372 lines not on this page · raw message

include/linux/platform_data/gsc_hwmon.h new file +44 -0

44 lines not on this page · raw message

Signature · 1 line
2.7.4
reviewer
#5 lore raw

Re: [PATCH v6 3/3] hwmon: add Gateworks System Controller support

drivers/hwmon/Kconfig config SENSORS_F75375S · line 501

Quoted 13 lines · Tim Harvey
drivers/hwmon/Kconfig +5 -0
index 23dfe84..99dae13 100644
@@ -494,6 +494,15 @@ config SENSORS_F75375S
 	  This driver can also be built as a module. If so, the module
 	  will be called f75375s.
 
+config SENSORS_GSC
+        tristate "Gateworks System Controller ADC"
+        depends on MFD_GATEWORKS_GSC
+        help
+          Support for the Gateworks System Controller A/D converters.

Hi Tim,
Those 4 lines above should be using tabs for indentation.
+ 2 spaces on the final "Support" line.

Quoted 7 lines
drivers/hwmon/Kconfig +4 -0
+
+	  To compile this driver as a module, choose M here:
+	  the module will be called gsc-hwmon.
+
 config SENSORS_MC13783_ADC
         tristate "Freescale MC13783/MC13892 ADC"
         depends on MFD_MC13XXX
Signature · 1 line
~Randy
author maintainer
#6 lore raw

Re: [PATCH v6 3/3] hwmon: add Gateworks System Controller support

Quoted 10 lines · Randy Dunlap
Quoted 8 lines · Tim Harvey
drivers/hwmon/Kconfig +0 -0
index 23dfe84..99dae13 100644
@@ -494,6 +494,15 @@ config SENSORS_F75375S
        This driver can also be built as a module. If so, the module
        will be called f75375s.
 
Quoted 9 lines

drivers/hwmon/Kconfig config SENSORS_F75375S · line 501

Quoted 5 lines
drivers/hwmon/Kconfig +5 -0
+config SENSORS_GSC
+        tristate "Gateworks System Controller ADC"
+        depends on MFD_GATEWORKS_GSC
+        help
+          Support for the Gateworks System Controller A/D converters.

Hi Tim,
Those 4 lines above should be using tabs for indentation.
+ 2 spaces on the final "Support" line.

Randy,

Thanks - can't believe I didn't see that. Checkpatch didn't catch it either.

I'll fix for v7.

Tim

maintainer
#7 lore raw

Re: [PATCH v6 3/3] hwmon: add Gateworks System Controller support

In reply to Tim Harvey
Quoted 218 lines · Tim Harvey

The Gateworks System Controller has a hwmon sub-component that exposes up to 16 ADC's, some of which are temperature sensors, others which are voltage inputs. The ADC configuration (register mapping and name) is configured via device-tree and varies board to board.

Cc Guenter Roeck <[email protected]>

---
v6:
- fix size of info field
- improve pwm output control documentation
- include unit suffix in divider and offset
- change adc subnode name to gsc-adc
- change fan base to fan subnode
- change adc type to mode
- fix voltage offset scaling

v5:
- fix various checkpatch issues
- correct gsc-hwmon.rst in MAINTAINERS
- encorporate Gunter's feedback:
- switch to SENSOR_DEVICE_ATTR_{RW,RO}
- use tmp value to avoid excessive pointer deference
- simplify shift operation
- scale voffset once
- simplify is_visible function
- remove empty line at end of file

v4:
- adjust for uV offset from device-tree
- remove unnecessary optional write function
- remove register range check
- change dev_err prints to use gsc dev
- hard-code resolution/scaling for raw adcs
- describe units of ADC resolution
- move to using pwm<n>_auto_point<m>_{pwm,temp} for FAN PWM
- ensure space before/after operators
- remove unnecessary parens
- remove more debugging
- add default case and comment for type_voltage
- remove unnecessary index bounds checks for channel
- remove unnecessary clearing of struct fields
- added Documentation/hwmon/gsc-hwmon.rst

v3:
- add voltage_raw input type and supporting fields
- add channel validation to is_visible function
- remove unnecessary channel validation from read/write functions

v2:
- change license comment style
- remove DEBUG
- simplify regmap_bulk_read err check
- remove break after returns in switch statement
- fix fan setpoint buffer address
- remove unnecessary parens
- consistently use struct device *dev pointer
- change license/comment block
- add validation for hwmon child node props
- move parsing of of to own function
- use strlcpy to ensure null termination
- fix static array sizes and removed unnecessary initializers
- dynamically allocate channels
- fix fan input label
- support platform data
- fixed whitespace issues

---
 Documentation/hwmon/gsc-hwmon.rst       |  53 +++++
 Documentation/hwmon/index.rst           |   1 +
 MAINTAINERS                             |   3 +
 drivers/hwmon/Kconfig                   |   9 +
 drivers/hwmon/Makefile                  |   1 +
 drivers/hwmon/gsc-hwmon.c               | 372 ++++++++++++++++++++++++++++++++
 include/linux/platform_data/gsc_hwmon.h |  44 ++++
 7 files changed, 483 insertions(+)
 create mode 100644 Documentation/hwmon/gsc-hwmon.rst
 create mode 100644 drivers/hwmon/gsc-hwmon.c
 create mode 100644 include/linux/platform_data/gsc_hwmon.h
Documentation/hwmon/gsc-hwmon.rst new file +53 -0
new file mode 100644
index 00000000..ffac392
@@ -0,0 +1,53 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Kernel driver gsc-hwmon
+=======================
+
+Supported chips: Gateworks GSC
+Datasheet: http://trac.gateworks.com/wiki/gsc
+Author: Tim Harvey <[email protected]>
+
+Description:
+------------
+
+This driver supports hardware monitoring for the temperature sensor,
+various ADC's connected to the GSC, and optional FAN controller available
+on some boards.
+
+
+Voltage Monitoring
+------------------
+
+The voltage inputs are scaled either internally or by the driver depending
+on the GSC version and firmware. The values returned by the driver do not need
+further scaling. The voltage input labels provide the voltage rail name:
+
+inX_input                  Measured voltage (mV).
+inX_label                  Name of voltage rail.
+
+
+Temperature Monitoring
+----------------------
+
+Temperatures are measured with 12-bit or 10-bit resolution and are scaled
+either internally or by the driver depending on the GSC version and firmware.
+The values returned by the driver reflect millidegree Celcius:
+
+tempX_input                Measured temperature.
+tempX_label                Name of temperature input.
+
+
+PWM Output Control
+------------------
+
+The GSC features 1 PWM output that operates in automatic mode where the
+PWM value will be scalled depending on 6 temperature boundaries.
+The tempeature boundaries are read-write and in millidegree Celcius and the
+read-only PWM values range from 0 (off) to 255 (full speed).
+Fan speed will be set to minimum (off) when the temperature sensor reads
+less than pwm1_auto_point1_temp and maximum when the temperature sensor
+equals or exceeds pwm1_auto_point6_temp.
+
+pwm1_auto_point[1-6]_pwm       PWM value.
+pwm1_auto_point[1-6]_temp      Temperature boundary.
+
Documentation/hwmon/index.rst +1 -0
index 43cc605..a4fab69 100644
@@ -58,6 +58,7 @@ Hardware Monitoring Kernel Drivers
    ftsteutates
    g760a
    g762
+   gsc-hwmon
    gl518sm
    hih6130
    ibmaem
MAINTAINERS +3 -0
index bb79b60..3f15542 100644
@@ -6846,6 +6846,9 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/mfd/gateworks-gsc.yaml
 F:	drivers/mfd/gateworks-gsc.c
 F:	include/linux/mfd/gsc.h
+F:	Documentation/hwmon/gsc-hwmon.rst
+F:	drivers/hwmon/gsc-hwmon.c
+F:	include/linux/platform_data/gsc_hwmon.h
 
 GCC PLUGINS
 M:	Kees Cook <[email protected]>
drivers/hwmon/Kconfig +9 -0
index 23dfe84..99dae13 100644
@@ -494,6 +494,15 @@ config SENSORS_F75375S
 	  This driver can also be built as a module. If so, the module
 	  will be called f75375s.
 
+config SENSORS_GSC
+        tristate "Gateworks System Controller ADC"
+        depends on MFD_GATEWORKS_GSC
+        help
+          Support for the Gateworks System Controller A/D converters.
+
+	  To compile this driver as a module, choose M here:
+	  the module will be called gsc-hwmon.
+
 config SENSORS_MC13783_ADC
         tristate "Freescale MC13783/MC13892 ADC"
         depends on MFD_MC13XXX
drivers/hwmon/Makefile +1 -0
index 6db5db9..259cba7 100644
@@ -71,6 +71,7 @@ obj-$(CONFIG_SENSORS_G760A)	+= g760a.o
 obj-$(CONFIG_SENSORS_G762)	+= g762.o
 obj-$(CONFIG_SENSORS_GL518SM)	+= gl518sm.o
 obj-$(CONFIG_SENSORS_GL520SM)	+= gl520sm.o
+obj-$(CONFIG_SENSORS_GSC)	+= gsc-hwmon.o
 obj-$(CONFIG_SENSORS_GPIO_FAN)	+= gpio-fan.o
 obj-$(CONFIG_SENSORS_HIH6130)	+= hih6130.o
 obj-$(CONFIG_SENSORS_ULTRA45)	+= ultra45_env.o
drivers/hwmon/gsc-hwmon.c new file +16 -0
new file mode 100644
index 00000000..c498786
@@ -0,0 +1,372 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Driver for Gateworks System Controller Hardware Monitor module
+ *
+ * Copyright (C) 2020 Gateworks Corporation
+ */
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/mfd/gsc.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <linux/slab.h>
+
+#include <linux/platform_data/gsc_hwmon.h>

drivers/hwmon/gsc-hwmon.c line 26

Quoted 10 lines
drivers/hwmon/gsc-hwmon.c new file +10 -0
+
+#define GSC_HWMON_MAX_TEMP_CH	16
+#define GSC_HWMON_MAX_IN_CH	16
+
+#define GSC_HWMON_RESOLUTION	12
+#define GSC_HWMON_VREF		2500
+
+struct gsc_hwmon_data {
+	struct gsc_dev *gsc;
+	struct device *dev;

What is 'dev' used for ? I don't think it is necessary.

Guenter

author maintainer
#8 lore raw

Re: [PATCH v6 3/3] hwmon: add Gateworks System Controller support

Quoted 224 lines · Guenter Roeck
Quoted 222 lines · Tim Harvey

The Gateworks System Controller has a hwmon sub-component that exposes up to 16 ADC's, some of which are temperature sensors, others which are voltage inputs. The ADC configuration (register mapping and name) is configured via device-tree and varies board to board.

Cc Guenter Roeck <[email protected]>

---
v6:
- fix size of info field
- improve pwm output control documentation
- include unit suffix in divider and offset
- change adc subnode name to gsc-adc
- change fan base to fan subnode
- change adc type to mode
- fix voltage offset scaling

v5:
- fix various checkpatch issues
- correct gsc-hwmon.rst in MAINTAINERS
- encorporate Gunter's feedback:
- switch to SENSOR_DEVICE_ATTR_{RW,RO}
- use tmp value to avoid excessive pointer deference
- simplify shift operation
- scale voffset once
- simplify is_visible function
- remove empty line at end of file

v4:
- adjust for uV offset from device-tree
- remove unnecessary optional write function
- remove register range check
- change dev_err prints to use gsc dev
- hard-code resolution/scaling for raw adcs
- describe units of ADC resolution
- move to using pwm<n>_auto_point<m>_{pwm,temp} for FAN PWM
- ensure space before/after operators
- remove unnecessary parens
- remove more debugging
- add default case and comment for type_voltage
- remove unnecessary index bounds checks for channel
- remove unnecessary clearing of struct fields
- added Documentation/hwmon/gsc-hwmon.rst

v3:
- add voltage_raw input type and supporting fields
- add channel validation to is_visible function
- remove unnecessary channel validation from read/write functions

v2:
- change license comment style
- remove DEBUG
- simplify regmap_bulk_read err check
- remove break after returns in switch statement
- fix fan setpoint buffer address
- remove unnecessary parens
- consistently use struct device *dev pointer
- change license/comment block
- add validation for hwmon child node props
- move parsing of of to own function
- use strlcpy to ensure null termination
- fix static array sizes and removed unnecessary initializers
- dynamically allocate channels
- fix fan input label
- support platform data
- fixed whitespace issues

---
 Documentation/hwmon/gsc-hwmon.rst       |  53 +++++
 Documentation/hwmon/index.rst           |   1 +
 MAINTAINERS                             |   3 +
 drivers/hwmon/Kconfig                   |   9 +
 drivers/hwmon/Makefile                  |   1 +
 drivers/hwmon/gsc-hwmon.c               | 372 ++++++++++++++++++++++++++++++++
 include/linux/platform_data/gsc_hwmon.h |  44 ++++
 7 files changed, 483 insertions(+)
 create mode 100644 Documentation/hwmon/gsc-hwmon.rst
 create mode 100644 drivers/hwmon/gsc-hwmon.c
 create mode 100644 include/linux/platform_data/gsc_hwmon.h
Documentation/hwmon/gsc-hwmon.rst new file +53 -0
new file mode 100644
index 00000000..ffac392
@@ -0,0 +1,53 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Kernel driver gsc-hwmon
+=======================
+
+Supported chips: Gateworks GSC
+Datasheet: http://trac.gateworks.com/wiki/gsc
+Author: Tim Harvey <[email protected]>
+
+Description:
+------------
+
+This driver supports hardware monitoring for the temperature sensor,
+various ADC's connected to the GSC, and optional FAN controller available
+on some boards.
+
+
+Voltage Monitoring
+------------------
+
+The voltage inputs are scaled either internally or by the driver depending
+on the GSC version and firmware. The values returned by the driver do not need
+further scaling. The voltage input labels provide the voltage rail name:
+
+inX_input                  Measured voltage (mV).
+inX_label                  Name of voltage rail.
+
+
+Temperature Monitoring
+----------------------
+
+Temperatures are measured with 12-bit or 10-bit resolution and are scaled
+either internally or by the driver depending on the GSC version and firmware.
+The values returned by the driver reflect millidegree Celcius:
+
+tempX_input                Measured temperature.
+tempX_label                Name of temperature input.
+
+
+PWM Output Control
+------------------
+
+The GSC features 1 PWM output that operates in automatic mode where the
+PWM value will be scalled depending on 6 temperature boundaries.
+The tempeature boundaries are read-write and in millidegree Celcius and the
+read-only PWM values range from 0 (off) to 255 (full speed).
+Fan speed will be set to minimum (off) when the temperature sensor reads
+less than pwm1_auto_point1_temp and maximum when the temperature sensor
+equals or exceeds pwm1_auto_point6_temp.
+
+pwm1_auto_point[1-6]_pwm       PWM value.
+pwm1_auto_point[1-6]_temp      Temperature boundary.
+
Documentation/hwmon/index.rst +1 -0
index 43cc605..a4fab69 100644
@@ -58,6 +58,7 @@ Hardware Monitoring Kernel Drivers
    ftsteutates
    g760a
    g762
+   gsc-hwmon
    gl518sm
    hih6130
    ibmaem
MAINTAINERS +3 -0
index bb79b60..3f15542 100644
@@ -6846,6 +6846,9 @@ S:      Maintained
 F:   Documentation/devicetree/bindings/mfd/gateworks-gsc.yaml
 F:   drivers/mfd/gateworks-gsc.c
 F:   include/linux/mfd/gsc.h
+F:   Documentation/hwmon/gsc-hwmon.rst
+F:   drivers/hwmon/gsc-hwmon.c
+F:   include/linux/platform_data/gsc_hwmon.h
 
 GCC PLUGINS
 M:   Kees Cook <[email protected]>
drivers/hwmon/Kconfig +9 -0
index 23dfe84..99dae13 100644
@@ -494,6 +494,15 @@ config SENSORS_F75375S
        This driver can also be built as a module. If so, the module
        will be called f75375s.
 
+config SENSORS_GSC
+        tristate "Gateworks System Controller ADC"
+        depends on MFD_GATEWORKS_GSC
+        help
+          Support for the Gateworks System Controller A/D converters.
+
+       To compile this driver as a module, choose M here:
+       the module will be called gsc-hwmon.
+
 config SENSORS_MC13783_ADC
         tristate "Freescale MC13783/MC13892 ADC"
         depends on MFD_MC13XXX
drivers/hwmon/Makefile +1 -0
index 6db5db9..259cba7 100644
@@ -71,6 +71,7 @@ obj-$(CONFIG_SENSORS_G760A) += g760a.o
 obj-$(CONFIG_SENSORS_G762)   += g762.o
 obj-$(CONFIG_SENSORS_GL518SM)        += gl518sm.o
 obj-$(CONFIG_SENSORS_GL520SM)        += gl520sm.o
+obj-$(CONFIG_SENSORS_GSC)    += gsc-hwmon.o
 obj-$(CONFIG_SENSORS_GPIO_FAN)       += gpio-fan.o
 obj-$(CONFIG_SENSORS_HIH6130)        += hih6130.o
 obj-$(CONFIG_SENSORS_ULTRA45)        += ultra45_env.o
drivers/hwmon/gsc-hwmon.c new file +20 -0
new file mode 100644
index 00000000..c498786
@@ -0,0 +1,372 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Driver for Gateworks System Controller Hardware Monitor module
+ *
+ * Copyright (C) 2020 Gateworks Corporation
+ */
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/mfd/gsc.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <linux/slab.h>
+
+#include <linux/platform_data/gsc_hwmon.h>
+
+#define GSC_HWMON_MAX_TEMP_CH        16
+#define GSC_HWMON_MAX_IN_CH  16
+
Quoted 9 lines

drivers/hwmon/gsc-hwmon.c line 26

Quoted 6 lines
drivers/hwmon/gsc-hwmon.c new file +6 -0
+#define GSC_HWMON_RESOLUTION 12
+#define GSC_HWMON_VREF               2500
+
+struct gsc_hwmon_data {
+     struct gsc_dev *gsc;
+     struct device *dev;

What is 'dev' used for ? I don't think it is necessary.

Agreed - will remove.

Thanks!

Tim