Skip to contentSkip to conversation

Support pwm/tach driver for aspeed ast26xx

PATCH Superseded Billy Tsai 3 participants 13 messages Aug 30, 2023 – Sep 12, 2023

Subsystems (5)

v8 of 14 Superseded Latest is v14 →

lore
Share & tools
lore

Billy Tsai

author reviewer
#0 lore raw

v8 cover Support pwm/tach driver for aspeed ast26xx

Unlike the old design that the register setting of the TACH should based on the configure of the PWM. In ast26xx, the dependency between pwm and tach controller is eliminated and becomes a separate hardware block. One is used to provide pwm output and another is used to monitor the frequency of the input. This driver implements them by exposing two kernel
subsystems: PWM and HWMON. The PWM subsystem can be utilized alongside existing drivers for controlling elements such as fans (pwm-fan.c), beepers (pwm-beeper.c) and so on. Through the HWMON subsystem, the driver provides sysfs interfaces for fan.

Changes since v7:
Cherry-pick the fan-common.yaml and add the following properties:
- min-rpm
- div
- mode
- tach-ch
Fix the warning which is reported by the kernel test robot.

Changes since v6:
Consolidate the PWM and TACH functionalities into a unified driver.

Changes since v5:
- pwm/tach:
- Remove the utilization of common resources from the parent node.
- Change the concept to 16 PWM/TACH controllers, each with one channel, instead of 1 PWM/TACH controller with 16 channels.
- dt-binding:
- Eliminate the usage of simple-mfd.

Changes since v4:
- pwm:
- Fix the return type of get_status function.
- tach:
- read clk source once and re-use it
- Remove the constants variables
- Allocate tach_channel as array
- Use dev->parent
- dt-binding:
- Fix the order of the patches
- Add example and description for tach child node
- Remove pwm extension property

Changes since v3:
- pwm:
- Remove unnecessary include header
- Fix warning Prefer "GPL" over "GPL v2"
- tach:
- Remove the paremeter min_rpm and max_rpm and return the tach value directly without any polling or delay.
- Fix warning Prefer "GPL" over "GPL v2"
- dt-binding:
- Replace underscore in node names with dashes
- Split per subsystem

Changes since v2:
- pwm:
- Use devm_* api to simplify the error cleanup
- Fix the multi-line alignment problem
- tach:
- Add tach-aspeed-ast2600 to index.rst
- Fix the multi-line alignment problem
- Remove the tach enable/disable when read the rpm
- Fix some coding format issue

Changes since v1:
- tach:
- Add the document tach-aspeed-ast2600.rst
- Use devm_* api to simplify the error cleanup.
- Change hwmon register api to devm_hwmon_device_register_with_info

Billy Tsai (2):
dt-bindings: hwmon: Support Aspeed g6 PWM TACH Control
hwmon: (aspeed-g6-pwm-tacho): Support for ASPEED g6 PWM/Fan tach

Naresh Solanki (1):
dt-bindings: hwmon: fan: Add fan binding to schema

 .../bindings/hwmon/aspeed,g6-pwm-tach.yaml    |  67 +++
 .../devicetree/bindings/hwmon/fan-common.yaml |  63 +++
 Documentation/hwmon/aspeed-g6-pwm-tach.rst    |  26 +
 Documentation/hwmon/index.rst                 |   1 +
 drivers/hwmon/Kconfig                         |  11 +
 drivers/hwmon/Makefile                        |   1 +
 drivers/hwmon/aspeed-g6-pwm-tach.c            | 528 ++++++++++++++++++
 7 files changed, 697 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/aspeed,g6-pwm-tach.yaml
 create mode 100644 Documentation/devicetree/bindings/hwmon/fan-common.yaml
 create mode 100644 Documentation/hwmon/aspeed-g6-pwm-tach.rst
 create mode 100644 drivers/hwmon/aspeed-g6-pwm-tach.c
Signature · 1 line
2.25.1
author reviewer
#1 lore raw

PATCH v8 1/3 dt-bindings: hwmon: fan: Add fan binding to schema

From: Naresh Solanki <[email protected]>

Add common fan properties bindings to a schema.

Bindings for fan controllers can reference the common schema for the fan

child nodes:

patternProperties:

    "^fan@[0-2]":
      type: object
      $ref: fan-common.yaml#
---
 .../devicetree/bindings/hwmon/fan-common.yaml | 63 +++++++++++++++++++
 1 file changed, 63 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/fan-common.yaml
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +63 -0
new file mode 100644
index 000000000000..a69b4d553e45
@@ -0,0 +1,63 @@
+# SPDX-License-Identifier: GPL-2.0-or-later OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/hwmon/fan-common.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Common Fan Properties
+
+maintainers:
+  - Naresh Solanki <[email protected]>
+  - Billy Tsai <[email protected]>
+
+properties:
+  max-rpm:
+    description:
+      Max RPM supported by fan.
+    $ref: /schemas/types.yaml#/definitions/uint32
+
+  min-rpm:
+    description:
+      Min RPM supported by fan.
+    $ref: /schemas/types.yaml#/definitions/uint32
+
+  pulses-per-revolution:
+    description:
+      The number of pulse from fan sensor per revolution.
+    $ref: /schemas/types.yaml#/definitions/uint32
+
+  div:
+    description:
+      Fan clock divisor
+    $ref: /schemas/types.yaml#/definitions/uint32
+
+  target-rpm:
+    description:
+      Target RPM the fan should be configured during driver probe.
+    $ref: /schemas/types.yaml#/definitions/uint32
+
+  mode:
+    description:
+      Select the operational mode of the fan.
+    $ref: /schemas/types.yaml#/definitions/uint32
+
+  pwms:
+    description:
+      PWM provider.
+
+  tach-ch:
+    description:
+      The tach channel used for the fan.
+    $ref: /schemas/types.yaml#/definitions/uint32
+
+  label:
+    description:
+      Optional fan label
+
+  fan-supply:
+    description:
+      Power supply for fan.
+
+additionalProperties: true
+
+...
Signature · 1 line
2.25.1
maintainer
#2 lore raw

Re: [PATCH v8 1/3] dt-bindings: hwmon: fan: Add fan binding to schema

Quoted 7 lines · Billy Tsai

From: Naresh Solanki <[email protected]>

Add common fan properties bindings to a schema.

Bindings for fan controllers can reference the common schema for the fan

Quoted 6 lines

child nodes:

patternProperties:

    "^fan@[0-2]":
      type: object
      $ref: fan-common.yaml#

unevaluatedProperties: false

Quoted 14 lines
---
 .../devicetree/bindings/hwmon/fan-common.yaml | 63 +++++++++++++++++++
 1 file changed, 63 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/fan-common.yaml
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +0 -0
new file mode 100644
index 000000000000..a69b4d553e45

Documentation/devicetree/bindings/hwmon/fan-common.yaml line 1

Quoted 1 line
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +1 -0
@@ -0,0 +1,63 @@
+# SPDX-License-Identifier: GPL-2.0-or-later OR BSD-2-Clause

Drop 'or-later'. It's GPL2 only.

Quoted 6 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +6 -0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/hwmon/fan-common.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Common Fan Properties

Documentation/devicetree/bindings/hwmon/fan-common.yaml line 17

Quoted 10 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +10 -0
+
+maintainers:
+  - Naresh Solanki <[email protected]>
+  - Billy Tsai <[email protected]>
+
+properties:
+  max-rpm:
+    description:
+      Max RPM supported by fan.
+    $ref: /schemas/types.yaml#/definitions/uint32

Physics will limit this to something much less than 2^32. Add some constraints. 10000?

Documentation/devicetree/bindings/hwmon/fan-common.yaml line 22

Quoted 5 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +5 -0
+
+  min-rpm:
+    description:
+      Min RPM supported by fan.
+    $ref: /schemas/types.yaml#/definitions/uint32

ditto

Documentation/devicetree/bindings/hwmon/fan-common.yaml line 27

Quoted 5 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +5 -0
+
+  pulses-per-revolution:
+    description:
+      The number of pulse from fan sensor per revolution.
+    $ref: /schemas/types.yaml#/definitions/uint32

Needs constraints. I assume this is never more than 4 (or 2 even)?

Documentation/devicetree/bindings/hwmon/fan-common.yaml line 29

Quoted 1 line
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +1 -0
+  div:

Too generic of a name.

Documentation/devicetree/bindings/hwmon/fan-common.yaml line 30

Quoted 2 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +2 -0
+    description:
+      Fan clock divisor

But what is a fan clock?

Documentation/devicetree/bindings/hwmon/fan-common.yaml line 36

Quoted 5 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +5 -0
+    $ref: /schemas/types.yaml#/definitions/uint32
+
+  target-rpm:
+    description:
+      Target RPM the fan should be configured during driver probe.

What driver? By the time the OS driver runs, a bunch of other boot software has already run on modern systems. So this value would likely be used much earlier. The point is that when exactly is outside the scope of DT. This is "what RPM do I use in case of no other information (e.g. temperature)".

Documentation/devicetree/bindings/hwmon/fan-common.yaml line 39

Quoted 3 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +3 -0
+    $ref: /schemas/types.yaml#/definitions/uint32
+
+  mode:

Too generic.

Documentation/devicetree/bindings/hwmon/fan-common.yaml line 40

Quoted 2 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +2 -0
+    description:
+      Select the operational mode of the fan.

What are modes? Spin and don't spin?

Documentation/devicetree/bindings/hwmon/fan-common.yaml line 46

Quoted 5 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +5 -0
+    $ref: /schemas/types.yaml#/definitions/uint32
+
+  pwms:
+    description:
+      PWM provider.

maxItems: 1

I don't think there are fans with more than 1 PWM input?

Documentation/devicetree/bindings/hwmon/fan-common.yaml line 51

Quoted 5 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +5 -0
+
+  tach-ch:
+    description:
+      The tach channel used for the fan.
+    $ref: /schemas/types.yaml#/definitions/uint32

The existing ASpeed version of this property allows more than 1 entry. I don't understand how a fan would have 2 tach signals, but if so, the generic property should allow for that.

Perhaps 'reg' should be defined in here with some text saying 'reg' corresponds to the fan controller specific id which may be the PWM+TACH channel, PWM channel (deprecated), or TACH channel. I think there are examples of all 3 of these cases.

Quoted 15 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +12 -0
+
+  label:
+    description:
+      Optional fan label
+
+  fan-supply:
+    description:
+      Power supply for fan.
+
+additionalProperties: true
+
+...
Signature · 1 line
2.25.1
author reviewer
#3 lore raw

Re: [PATCH v8 1/3] dt-bindings: hwmon: fan: Add fan binding to schema

Quoted 7 lines · Billy Tsai
Quoted 7 lines

From: Naresh Solanki <[email protected]>

Add common fan properties bindings to a schema.

Bindings for fan controllers can reference the common schema for the fan

Quoted 8 lines
Quoted 6 lines

child nodes:

patternProperties:

    "^fan@[0-2]":
      type: object
      $ref: fan-common.yaml#

unevaluatedProperties: false

OK, I will add this.

Quoted 8 lines
Quoted 8 lines
---
 .../devicetree/bindings/hwmon/fan-common.yaml | 63 +++++++++++++++++++
 1 file changed, 63 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/fan-common.yaml
Quoted 9 lines

Documentation/devicetree/bindings/hwmon/fan-common.yaml line 1

Quoted 7 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +1 -0
new file mode 100644
index 000000000000..a69b4d553e45
@@ -0,0 +1,63 @@
+# SPDX-License-Identifier: GPL-2.0-or-later OR BSD-2-Clause

Drop 'or-later'. It's GPL2 only.

OK, I will fix it.

Quoted 29 lines
Quoted 6 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +6 -0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/hwmon/fan-common.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Common Fan Properties

Documentation/devicetree/bindings/hwmon/fan-common.yaml line 17

Quoted 10 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +10 -0
+
+maintainers:
+  - Naresh Solanki <[email protected]>
+  - Billy Tsai <[email protected]>
+
+properties:
+  max-rpm:
+    description:
+      Max RPM supported by fan.
+    $ref: /schemas/types.yaml#/definitions/uint32

Physics will limit this to something much less than 2^32. Add some constraints. 10000?

Documentation/devicetree/bindings/hwmon/fan-common.yaml line 22

Quoted 5 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +5 -0
+
+  min-rpm:
+    description:
+      Min RPM supported by fan.
+    $ref: /schemas/types.yaml#/definitions/uint32

ditto

Quoted 7 lines

Documentation/devicetree/bindings/hwmon/fan-common.yaml line 27

Quoted 5 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +5 -0
+
+  pulses-per-revolution:
+    description:
+      The number of pulse from fan sensor per revolution.
+    $ref: /schemas/types.yaml#/definitions/uint32

Needs constraints. I assume this is never more than 4 (or 2 even)?

Do you think we should add the contraint in the common binding? In my option, the limit of the max/min rpm should be declared by the binding if necessary, because the usage of each fan monitor is based on the connection of the tach pin.

Quoted 8 lines

Documentation/devicetree/bindings/hwmon/fan-common.yaml line 29

Quoted 1 line
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +1 -0
+  div:

Too generic of a name.

Documentation/devicetree/bindings/hwmon/fan-common.yaml line 30

Quoted 2 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +2 -0
+    description:
+      Fan clock divisor

But what is a fan clock?

This is the divisor for the tachometer sampling clock, which determines the sensitivity of the tach pin. So, if the name of the property changes to 'tach-div,' is it acceptable to you?

Quoted 11 lines

Documentation/devicetree/bindings/hwmon/fan-common.yaml line 36

Quoted 5 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +5 -0
+    $ref: /schemas/types.yaml#/definitions/uint32
+
+  target-rpm:
+    description:
+      Target RPM the fan should be configured during driver probe.

What driver? By the time the OS driver runs, a bunch of other boot software has already run on modern systems. So this value would likely be used much earlier. The point is that when exactly is outside the scope of DT. This is "what RPM do I use in case of no other information (e.g. temperature)".

So, the description should be changed to 'The default desired fan speed in RPM,' and we shouldn't mention the timing of the property's operation in the DT, is that correct?

Quoted 10 lines

Documentation/devicetree/bindings/hwmon/fan-common.yaml line 39

Quoted 3 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +3 -0
+    $ref: /schemas/types.yaml#/definitions/uint32
+
+  mode:

Too generic.

Documentation/devicetree/bindings/hwmon/fan-common.yaml line 40

Quoted 2 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +2 -0
+    description:
+      Select the operational mode of the fan.

What are modes? Spin and don't spin?

The mode is used to indicate the driving mode of the fan (DC, PWM and so on). So, if the name of the property changes to 'fan-driving-mode,' is it acceptable to you?

Quoted 9 lines

Documentation/devicetree/bindings/hwmon/fan-common.yaml line 46

Quoted 5 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +5 -0
+    $ref: /schemas/types.yaml#/definitions/uint32
+
+  pwms:
+    description:
+      PWM provider.

maxItems: 1

I don't think there are fans with more than 1 PWM input?

Ok, I will add the constraint for the pwm input.

Quoted 9 lines

Documentation/devicetree/bindings/hwmon/fan-common.yaml line 51

Quoted 5 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +5 -0
+
+  tach-ch:
+    description:
+      The tach channel used for the fan.
+    $ref: /schemas/types.yaml#/definitions/uint32

The existing ASpeed version of this property allows more than 1 entry. I don't understand how a fan would have 2 tach signals, but if so, the generic property should allow for that.

Ok, I will modify it to the uint32-array

Quoted 4 lines

Perhaps 'reg' should be defined in here with some text saying 'reg' corresponds to the fan controller specific id which may be the PWM+TACH channel, PWM channel (deprecated), or TACH channel. I think there are examples of all 3 of these cases.

I don't think it's necessary for the 'reg' because the case you mentioned is already covered by the property 'tach-ch' and the 'pwms'.

Quoted 15 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +12 -0
+
+  label:
+    description:
+      Optional fan label
+
+  fan-supply:
+    description:
+      Power supply for fan.
+
+additionalProperties: true
+
+...
Signature · 1 line
2.25.1
maintainer
#4 lore raw

Re: [PATCH v8 1/3] dt-bindings: hwmon: fan: Add fan binding to schema

Quoted 33 lines · Billy Tsai
Quoted 31 lines · Billy Tsai

Documentation/devicetree/bindings/hwmon/fan-common.yaml line 17

Quoted 13 lines

From: Naresh Solanki <[email protected]>

Add common fan properties bindings to a schema.

Bindings for fan controllers can reference the common schema for the fan

Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +5 -0
+properties:
+  max-rpm:
+    description:
+      Max RPM supported by fan.
+    $ref: /schemas/types.yaml#/definitions/uint32

Physics will limit this to something much less than 2^32. Add some constraints. 10000?

Documentation/devicetree/bindings/hwmon/fan-common.yaml line 22

Quoted 5 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +5 -0
+
+  min-rpm:
+    description:
+      Min RPM supported by fan.
+    $ref: /schemas/types.yaml#/definitions/uint32

ditto

Quoted 5 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +5 -0
+
+  pulses-per-revolution:
+    description:
+      The number of pulse from fan sensor per revolution.
+    $ref: /schemas/types.yaml#/definitions/uint32
Quoted 6 lines
Quoted 1 line

Needs constraints. I assume this is never more than 4 (or 2 even)?

Do you think we should add the contraint in the common binding? In my option, the limit of the max/min rpm should be declared by the binding if necessary, because the usage of each fan monitor is based on the connection of the tach pin.

Yes, I think we should have default limits.

Unless we go as far as a schema for every specific fan model, then there is actually no way we can have specific limits unless the fan controllers have some limits.

The most I see in tree for pulses-per-revolution is 2. There's no value in more. So set the max to 4 and then if anyone needs more they can bump the value.

Or maybe there's some electrical/mechanical design reason fans are 1 or 2 pulses and we'll never see anything else? This document[1] seems to indicate that is indeed the case. (First hit googling "fan tach signal pulses")

Quoted 6 lines
Quoted 5 lines
Quoted 3 lines

+ div:

Too generic of a name.

Quoted 7 lines
Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+    description:
+      Fan clock divisor

But what is a fan clock?

This is the divisor for the tachometer sampling clock, which determines the sensitivity of the tach pin. So, if the name of the property changes to 'tach-div,' is it acceptable to you?

That sounds like a property of the controller, not the fan, so it belongs in the controller binding. Is this really a common thing?

Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +5 -0
+    $ref: /schemas/types.yaml#/definitions/uint32
+
+  target-rpm:
+    description:
+      Target RPM the fan should be configured during driver probe.
Quoted 8 lines
Quoted 5 lines

What driver? By the time the OS driver runs, a bunch of other boot software has already run on modern systems. So this value would likely be used much earlier. The point is that when exactly is outside the scope of DT. This is "what RPM do I use in case of no other information (e.g. temperature)".

So, the description should be changed to 'The default desired fan speed in RPM,' and we shouldn't mention the timing of the property's operation in the DT, is that correct?

Correct.

Quoted 7 lines
Quoted 6 lines

Documentation/devicetree/bindings/hwmon/fan-common.yaml line 39

Quoted 4 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +3 -0
+    $ref: /schemas/types.yaml#/definitions/uint32
+
+  mode:

Too generic.

Quoted 7 lines
Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+    description:
+      Select the operational mode of the fan.

What are modes? Spin and don't spin?

The mode is used to indicate the driving mode of the fan (DC, PWM and so on). So, if the name of the property changes to 'fan-driving-mode,' is it acceptable to you?

I tend to think that should be implied from the parent node and/or other properties. PWM if "pwms" property is present. DC if the supply is variable. We could also use compatible strings in the fan nodes if there's a need.

That reminds me, both of these modes probably need a table of voltage/duty-cycle to RPMs. I imagine it's not always a linear response. Naresh also privately sent me (don't do that) an updated common binding which we discussed the need for this. I expect him to comment further with details.

Quoted 18 lines
Quoted 9 lines

Documentation/devicetree/bindings/hwmon/fan-common.yaml line 46

Quoted 5 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +5 -0
+    $ref: /schemas/types.yaml#/definitions/uint32
+
+  pwms:
+    description:
+      PWM provider.

maxItems: 1

I don't think there are fans with more than 1 PWM input?

Ok, I will add the constraint for the pwm input.

Quoted 5 lines
Quoted 5 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +5 -0
+
+  tach-ch:
+    description:
+      The tach channel used for the fan.
+    $ref: /schemas/types.yaml#/definitions/uint32
Quoted 5 lines
Quoted 3 lines

The existing ASpeed version of this property allows more than 1 entry. I don't understand how a fan would have 2 tach signals, but if so, the generic property should allow for that.

Ok, I will modify it to the uint32-array

Perhaps uint8-array to align with existing versions of the property.

Quoted 8 lines
Quoted 5 lines

Perhaps 'reg' should be defined in here with some text saying 'reg' corresponds to the fan controller specific id which may be the PWM+TACH channel, PWM channel (deprecated), or TACH channel. I think there are examples of all 3 of these cases.

I don't think it's necessary for the 'reg' because the case you mentioned is already covered by the property 'tach-ch' and the 'pwms'.

Yes, but when we have N child nodes of the same thing, we usually have "reg" and its value corresponds to how the parent identifies each child. We already have a mixture using PWM or tach channel. Yes, this can all just be in the fan controllers binding, but putting it here would just document the options.

Rob

[1] http://www.comairrotron.com/methods-monitoring-fan-performance

author reviewer
#5 lore raw

Re: [PATCH v8 1/3] dt-bindings: hwmon: fan: Add fan binding to schema

Quoted 46 lines · Billy Tsai
Quoted 33 lines · Billy Tsai
Quoted 31 lines

Documentation/devicetree/bindings/hwmon/fan-common.yaml line 17

Quoted 13 lines

From: Naresh Solanki <[email protected]>

Add common fan properties bindings to a schema.

Bindings for fan controllers can reference the common schema for the fan

Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +5 -0
+properties:
+  max-rpm:
+    description:
+      Max RPM supported by fan.
+    $ref: /schemas/types.yaml#/definitions/uint32

Physics will limit this to something much less than 2^32. Add some constraints. 10000?

Documentation/devicetree/bindings/hwmon/fan-common.yaml line 22

Quoted 5 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +5 -0
+
+  min-rpm:
+    description:
+      Min RPM supported by fan.
+    $ref: /schemas/types.yaml#/definitions/uint32

ditto

Quoted 5 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +5 -0
+
+  pulses-per-revolution:
+    description:
+      The number of pulse from fan sensor per revolution.
+    $ref: /schemas/types.yaml#/definitions/uint32
Quoted 6 lines
Quoted 1 line

Needs constraints. I assume this is never more than 4 (or 2 even)?

Do you think we should add the contraint in the common binding? In my option, the limit of the max/min rpm should be declared by the binding if necessary, because the usage of each fan monitor is based on the connection of the tach pin.

Yes, I think we should have default limits.

Unless we go as far as a schema for every specific fan model, then there is actually no way we can have specific limits unless the fan controllers have some limits.

Quoted 8 lines

The most I see in tree for pulses-per-revolution is 2. There's no value in more. So set the max to 4 and then if anyone needs more they can bump the value.

Or maybe there's some electrical/mechanical design reason fans are 1 or 2 pulses and we'll never see anything else? This document[1] seems to indicate that is indeed the case. (First hit googling "fan tach signal pulses")

OK, I will add the maximum value for the max-rpm, min-rpm and pulses-per-revolution.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines

+ div:

Too generic of a name.

Quoted 2 lines
(quoted diff) +2 -0
+    description:
+      Fan clock divisor
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

But what is a fan clock?

This is the divisor for the tachometer sampling clock, which determines the sensitivity of the tach pin. So, if the name of the property changes to 'tach-div,' is it acceptable to you?

That sounds like a property of the controller, not the fan, so it belongs in the controller binding. Is this really a common thing?

Yes, I believe this is a common feature for fans. You can refer to the Documentation/hwmon/sysfs-interface.rst, where the fan divisor is defined for users, determining the fan's sensitivity.

Quoted 29 lines
Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +5 -0
+    $ref: /schemas/types.yaml#/definitions/uint32
+
+  target-rpm:
+    description:
+      Target RPM the fan should be configured during driver probe.
Quoted 8 lines
Quoted 5 lines

What driver? By the time the OS driver runs, a bunch of other boot software has already run on modern systems. So this value would likely be used much earlier. The point is that when exactly is outside the scope of DT. This is "what RPM do I use in case of no other information (e.g. temperature)".

So, the description should be changed to 'The default desired fan speed in RPM,' and we shouldn't mention the timing of the property's operation in the DT, is that correct?

Correct.

Quoted 12 lines
Quoted 11 lines

Documentation/devicetree/bindings/hwmon/fan-common.yaml line 39

Quoted 4 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +3 -0
+    $ref: /schemas/types.yaml#/definitions/uint32
+
+  mode:

Too generic.

Review

Quoted 2 lines
(quoted diff) +2 -0
+    description:
+      Select the operational mode of the fan.

What are modes? Spin and don't spin?

Quoted 7 lines
Quoted 2 lines

The mode is used to indicate the driving mode of the fan (DC, PWM and so on). So, if the name of the property changes to 'fan-driving-mode,' is it acceptable to you?

I tend to think that should be implied from the parent node and/or other properties. PWM if "pwms" property is present. DC if the supply is variable. We could also use compatible strings in the fan nodes if there's a need.

So, it looks that this property isn't necessary for the fan. And it should be determined by the present of the driving source. is that correct?

Quoted 5 lines

That reminds me, both of these modes probably need a table of voltage/duty-cycle to RPMs. I imagine it's not always a linear response. Naresh also privately sent me (don't do that) an updated common binding which we discussed the need for this. I expect him to comment further with details.

For this purpose, we should add the speed-map like the usage of the gpio-fan, right?
https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/hwmon/gpio-fan.txt

Quoted 18 lines
Quoted 18 lines
Quoted 9 lines

Documentation/devicetree/bindings/hwmon/fan-common.yaml line 46

Quoted 5 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +5 -0
+    $ref: /schemas/types.yaml#/definitions/uint32
+
+  pwms:
+    description:
+      PWM provider.

maxItems: 1

I don't think there are fans with more than 1 PWM input?

Ok, I will add the constraint for the pwm input.

Quoted 5 lines
Quoted 5 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +5 -0
+
+  tach-ch:
+    description:
+      The tach channel used for the fan.
+    $ref: /schemas/types.yaml#/definitions/uint32
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

The existing ASpeed version of this property allows more than 1 entry. I don't understand how a fan would have 2 tach signals, but if so, the generic property should allow for that.

Ok, I will modify it to the uint32-array

Perhaps uint8-array to align with existing versions of the property.

Ok, I will modify it to the uint8-array.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

Perhaps 'reg' should be defined in here with some text saying 'reg' corresponds to the fan controller specific id which may be the PWM+TACH channel, PWM channel (deprecated), or TACH channel. I think there are examples of all 3 of these cases.

Quoted 8 lines
Quoted 2 lines

I don't think it's necessary for the 'reg' because the case you mentioned is already covered by the property 'tach-ch' and the 'pwms'.

Yes, but when we have N child nodes of the same thing, we usually have "reg" and its value corresponds to how the parent identifies each child. We already have a mixture using PWM or tach channel. Yes, this can all just be in the fan controllers binding, but putting it here would just document the options.

Ok, I will add reg property for the option.

Quoted 4 lines

Rob

[1] http://www.comairrotron.com/methods-monitoring-fan-performance

maintainer
#6 lore raw

Re: [PATCH v8 1/3] dt-bindings: hwmon: fan: Add fan binding to schema

Quoted 69 lines · Billy Tsai
Quoted 46 lines · Billy Tsai
Quoted 33 lines · Billy Tsai
Quoted 31 lines

Documentation/devicetree/bindings/hwmon/fan-common.yaml line 17

Quoted 13 lines

From: Naresh Solanki <[email protected]>

Add common fan properties bindings to a schema.

Bindings for fan controllers can reference the common schema for the fan

Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +5 -0
+properties:
+  max-rpm:
+    description:
+      Max RPM supported by fan.
+    $ref: /schemas/types.yaml#/definitions/uint32

Physics will limit this to something much less than 2^32. Add some constraints. 10000?

Documentation/devicetree/bindings/hwmon/fan-common.yaml line 22

Quoted 5 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +5 -0
+
+  min-rpm:
+    description:
+      Min RPM supported by fan.
+    $ref: /schemas/types.yaml#/definitions/uint32

ditto

Quoted 5 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +5 -0
+
+  pulses-per-revolution:
+    description:
+      The number of pulse from fan sensor per revolution.
+    $ref: /schemas/types.yaml#/definitions/uint32
Quoted 6 lines
Quoted 1 line

Needs constraints. I assume this is never more than 4 (or 2 even)?

Do you think we should add the contraint in the common binding? In my option, the limit of the max/min rpm should be declared by the binding if necessary, because the usage of each fan monitor is based on the connection of the tach pin.

Yes, I think we should have default limits.

Unless we go as far as a schema for every specific fan model, then there is actually no way we can have specific limits unless the fan controllers have some limits.

Quoted 8 lines

The most I see in tree for pulses-per-revolution is 2. There's no value in more. So set the max to 4 and then if anyone needs more they can bump the value.

Or maybe there's some electrical/mechanical design reason fans are 1 or 2 pulses and we'll never see anything else? This document[1] seems to indicate that is indeed the case. (First hit googling "fan tach signal pulses")

OK, I will add the maximum value for the max-rpm, min-rpm and pulses-per-revolution.

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 3 lines

+ div:

Too generic of a name.

Review

Quoted 2 lines
(quoted diff) +2 -0
+    description:
+      Fan clock divisor

But what is a fan clock?

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

This is the divisor for the tachometer sampling clock, which determines the sensitivity of the tach pin. So, if the name of the property changes to 'tach-div,' is it acceptable to you?

That sounds like a property of the controller, not the fan, so it belongs in the controller binding. Is this really a common thing?

Yes, I believe this is a common feature for fans. You can refer to the Documentation/hwmon/sysfs-interface.rst, where the fan divisor is defined for users, determining the fan's sensitivity.

It's a feature of the controller, but I guess since it may be a per fan or tach channel setting having it in the fan node is fine. 'tach-div' is fine.

Quoted 33 lines
Quoted 32 lines
Quoted 7 lines
Quoted 6 lines
Quoted 6 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +5 -0
+    $ref: /schemas/types.yaml#/definitions/uint32
+
+  target-rpm:
+    description:
+      Target RPM the fan should be configured during driver probe.
Quoted 8 lines
Quoted 5 lines

What driver? By the time the OS driver runs, a bunch of other boot software has already run on modern systems. So this value would likely be used much earlier. The point is that when exactly is outside the scope of DT. This is "what RPM do I use in case of no other information (e.g. temperature)".

So, the description should be changed to 'The default desired fan speed in RPM,' and we shouldn't mention the timing of the property's operation in the DT, is that correct?

Correct.

Quoted 14 lines
Quoted 11 lines

Documentation/devicetree/bindings/hwmon/fan-common.yaml line 39

Quoted 4 lines
Documentation/devicetree/bindings/hwmon/fan-common.yaml new file +3 -0
+    $ref: /schemas/types.yaml#/definitions/uint32
+
+  mode:

Too generic.

Review

Quoted 2 lines
(quoted diff) +2 -0
+    description:
+      Select the operational mode of the fan.

What are modes? Spin and don't spin?

The mode is used to indicate the driving mode of the fan (DC, PWM and so on). So, if the name of the property changes to 'fan-driving-mode,' is it acceptable to you?

Quoted 7 lines
Quoted 4 lines

I tend to think that should be implied from the parent node and/or other properties. PWM if "pwms" property is present. DC if the supply is variable. We could also use compatible strings in the fan nodes if there's a need.

So, it looks that this property isn't necessary for the fan. And it should be determined by the present of the driving source. is that correct?

Looking back, I see Guenter asked for something like this. So I guess it is fine to keep if he still thinks we need it. I think it could also be implied a bit more clearly if we do 'cooling-levels' as below. The fan controller should know what modes it can do. Duty cycle vs. voltage in uV is pretty easy to distinguish.

Quoted 9 lines
Quoted 6 lines

That reminds me, both of these modes probably need a table of voltage/duty-cycle to RPMs. I imagine it's not always a linear response. Naresh also privately sent me (don't do that) an updated common binding which we discussed the need for this. I expect him to comment further with details.

For this purpose, we should add the speed-map like the usage of the gpio-fan, right?
https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/hwmon/gpio-fan.txt

That should be fine. I guess it comes down to whether we want one property or 3 depending on whether the control is voltage, duty-cycle, GPIO pins state, etc. Unfortunately, it's "gpio-fan,speed-map", not "speed-map", so we can't use that as-is. There's also "cooling-levels" which can accomplish the same thing. We don't know RPMs with that, but do we need to? Maybe, as it seems some drivers want to set speed in RPMs from userspace. Could also do something like this:

cooling-levels = < 33 66 100>;
rpm-levels = <500 1000 1500>;

"rpm-levels" would replace the min-rpm/max-rpm properties.

Also, looking at gpio-fan.txt, it looks like you should add "#cooling-cells" as well.

Rob

author reviewer
#7 lore raw

PATCH v8 2/3 dt-bindings: hwmon: Support Aspeed g6 PWM TACH Control

In reply to Billy Tsai

Document the compatible for aspeed,ast2600-pwm-tach device, which can support up to 16 PWM outputs and 16 fan tach input.

---
 .../bindings/hwmon/aspeed,g6-pwm-tach.yaml    | 67 +++++++++++++++++++
 1 file changed, 67 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/aspeed,g6-pwm-tach.yaml
Documentation/devicetree/bindings/hwmon/aspeed,g6-pwm-tach.yaml new file +67 -0
new file mode 100644
index 000000000000..95bac5588c04
@@ -0,0 +1,67 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (C) 2021 Aspeed, Inc.
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/hwmon/aspeed,g6-pwm-tach.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: ASPEED G6 PWM and Fan Tach controller device driver
+
+maintainers:
+  - Billy Tsai <[email protected]>
+
+description: |
+  The ASPEED PWM controller can support up to 16 PWM outputs.
+  The ASPEED Fan Tacho controller can support up to 16 fan tach input.
+
+properties:
+  compatible:
+    enum:
+      - aspeed,ast2600-pwm-tach
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+  resets:
+    maxItems: 1
+
+  "#pwm-cells":
+    const: 3
+
+patternProperties:
+  "^fan[0-9a-f]_hwmon+$":
+    $ref: fan-common.yaml#
+    required:
+      - tach-ch
+
+required:
+  - reg
+  - clocks
+  - resets
+  - "#pwm-cells"
+  - compatible
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/aspeed-clock.h>
+    pwm_tach: pwm-tach-controller at 1e610000 {
+      compatible = "aspeed,ast2600-pwm-tach";
+      reg = <0x1e610000 0x100>;
+      clocks = <&syscon ASPEED_CLK_AHB>;
+      resets = <&syscon ASPEED_RESET_PWM>;
+      #pwm-cells = <3>;
+      fan0_hwmon {
+        tach-ch = <0x0>;
+      };
+      fan1_hwmon {
+        tach-ch = <0x1>;
+      };
+      fan2_hwmon {
+        tach-ch = <0x2>;
+      };
+    };
Signature · 1 line
2.25.1
maintainer
#8 lore raw

Re: [PATCH v8 2/3] dt-bindings: hwmon: Support Aspeed g6 PWM TACH Control

Quoted 15 lines · Billy Tsai

Document the compatible for aspeed,ast2600-pwm-tach device, which can support up to 16 PWM outputs and 16 fan tach input.

---
 .../bindings/hwmon/aspeed,g6-pwm-tach.yaml    | 67 +++++++++++++++++++
 1 file changed, 67 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/aspeed,g6-pwm-tach.yaml
Documentation/devicetree/bindings/hwmon/aspeed,g6-pwm-tach.yaml new file +0 -0
new file mode 100644
index 000000000000..95bac5588c04

Documentation/devicetree/bindings/hwmon/aspeed,g6-pwm-tach.yaml line 2

Quoted 2 lines
Documentation/devicetree/bindings/hwmon/aspeed,g6-pwm-tach.yaml new file +2 -0
@@ -0,0 +1,67 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (C) 2021 Aspeed, Inc.

A few years out of date.

Documentation/devicetree/bindings/hwmon/aspeed,g6-pwm-tach.yaml line 15

Quoted 13 lines
Documentation/devicetree/bindings/hwmon/aspeed,g6-pwm-tach.yaml new file +13 -0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/hwmon/aspeed,g6-pwm-tach.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: ASPEED G6 PWM and Fan Tach controller device driver
+
+maintainers:
+  - Billy Tsai <[email protected]>
+
+description: |
+  The ASPEED PWM controller can support up to 16 PWM outputs.
+  The ASPEED Fan Tacho controller can support up to 16 fan tach input.

Are PWM and tach channels independent? Would be useful to know here.

Quoted 10 lines
Documentation/devicetree/bindings/hwmon/aspeed,g6-pwm-tach.yaml new file +10 -0
+
+properties:
+  compatible:
+    enum:
+      - aspeed,ast2600-pwm-tach
+
+  reg:
+    maxItems: 1
+
+  clocks:

Documentation/devicetree/bindings/hwmon/aspeed,g6-pwm-tach.yaml line 35

Quoted 10 lines
Documentation/devicetree/bindings/hwmon/aspeed,g6-pwm-tach.yaml new file +10 -0
+    maxItems: 1
+
+  resets:
+    maxItems: 1
+
+  "#pwm-cells":
+    const: 3
+
+patternProperties:
+  "^fan[0-9a-f]_hwmon+$":

Drop 'hwmon'. Standard practice for naming without 'reg' is '^fan-[0-9]+$'.

Documentation/devicetree/bindings/hwmon/aspeed,g6-pwm-tach.yaml line 36

Quoted 1 line
Documentation/devicetree/bindings/hwmon/aspeed,g6-pwm-tach.yaml new file +1 -0
+    $ref: fan-common.yaml#

unevaluatedProperties: false

Quoted 11 lines
Documentation/devicetree/bindings/hwmon/aspeed,g6-pwm-tach.yaml new file +11 -0
+    required:
+      - tach-ch
+
+required:
+  - reg
+  - clocks
+  - resets
+  - "#pwm-cells"
+  - compatible
+
+additionalProperties: false

Documentation/devicetree/bindings/hwmon/aspeed,g6-pwm-tach.yaml line 57

Quoted 10 lines
Documentation/devicetree/bindings/hwmon/aspeed,g6-pwm-tach.yaml new file +10 -0
+
+examples:
+  - |
+    #include <dt-bindings/clock/aspeed-clock.h>
+    pwm_tach: pwm-tach-controller at 1e610000 {
+      compatible = "aspeed,ast2600-pwm-tach";
+      reg = <0x1e610000 0x100>;
+      clocks = <&syscon ASPEED_CLK_AHB>;
+      resets = <&syscon ASPEED_RESET_PWM>;
+      #pwm-cells = <3>;

Blank line.

Documentation/devicetree/bindings/hwmon/aspeed,g6-pwm-tach.yaml line 59

Quoted 2 lines
Documentation/devicetree/bindings/hwmon/aspeed,g6-pwm-tach.yaml new file +2 -0
+      fan0_hwmon {
+        tach-ch = <0x0>;

Don't you need 'pwms'?

Documentation/devicetree/bindings/hwmon/aspeed,g6-pwm-tach.yaml line 60

Quoted 1 line
Documentation/devicetree/bindings/hwmon/aspeed,g6-pwm-tach.yaml new file +1 -0
+      };

Blank line.

Quoted 10 lines
Documentation/devicetree/bindings/hwmon/aspeed,g6-pwm-tach.yaml new file +7 -0
+      fan1_hwmon {
+        tach-ch = <0x1>;
+      };
+      fan2_hwmon {
+        tach-ch = <0x2>;
+      };
+    };
Signature · 1 line
2.25.1
author reviewer
#9 lore raw

Re: [PATCH v8 2/3] dt-bindings: hwmon: Support Aspeed g6 PWM TACH Control

Quoted 13 lines

Documentation/devicetree/bindings/hwmon/aspeed,g6-pwm-tach.yaml line 57

Quoted 10 lines
Documentation/devicetree/bindings/hwmon/aspeed,g6-pwm-tach.yaml new file +10 -0
+
+examples:
+  - |
+    #include <dt-bindings/clock/aspeed-clock.h>
+    pwm_tach: pwm-tach-controller at 1e610000 {
+      compatible = "aspeed,ast2600-pwm-tach";
+      reg = <0x1e610000 0x100>;
+      clocks = <&syscon ASPEED_CLK_AHB>;
+      resets = <&syscon ASPEED_RESET_PWM>;
+      #pwm-cells = <3>;

Blank line.

Quoted 4 lines

Documentation/devicetree/bindings/hwmon/aspeed,g6-pwm-tach.yaml line 59

Quoted 2 lines
Documentation/devicetree/bindings/hwmon/aspeed,g6-pwm-tach.yaml new file +2 -0
+      fan0_hwmon {
+        tach-ch = <0x0>;

Don't you need 'pwms'?

Yes, I only want to create the fan monitor without fan control.

Quoted 1 line

+ };

author reviewer
#10 lore raw

PATCH v8 3/3 hwmon: (aspeed-g6-pwm-tacho): Support for ASPEED g6 PWM/Fan tach

In reply to Billy Tsai

The driver support two functions: PWM and Tachometer. The PWM feature can handle up to 16 output ports, while the Tachometer can monitor to up to 16 input ports as well. This driver implements them by exposing two kernel
subsystems: PWM and HWMON. The PWM subsystem can be utilized alongside existing drivers for controlling elements such as fans (pwm-fan.c), beepers (pwm-beeper.c) and so on. Through the HWMON subsystem, the driver provides sysfs interfaces for fan.

---
 Documentation/hwmon/aspeed-g6-pwm-tach.rst |  26 +
 Documentation/hwmon/index.rst              |   1 +
 drivers/hwmon/Kconfig                      |  11 +
 drivers/hwmon/Makefile                     |   1 +
 drivers/hwmon/aspeed-g6-pwm-tach.c         | 528 +++++++++++++++++++++
 5 files changed, 567 insertions(+)
 create mode 100644 Documentation/hwmon/aspeed-g6-pwm-tach.rst
 create mode 100644 drivers/hwmon/aspeed-g6-pwm-tach.c
Documentation/hwmon/aspeed-g6-pwm-tach.rst new file +26 -0
new file mode 100644
index 000000000000..17398fe397fe
@@ -0,0 +1,26 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+Kernel driver aspeed-g6-pwm-tach
+=================================
+
+Supported chips:
+	ASPEED AST2600
+
+Authors:
+	<[email protected]>
+
+Description:
+------------
+This driver implements support for ASPEED AST2600 Fan Tacho controller.
+The controller supports up to 16 tachometer inputs.
+
+The driver provides the following sensor accesses in sysfs:
+
+=============== ======= ======================================================
+fanX_input	ro	provide current fan rotation value in RPM as reported
+			by the fan to the device.
+fanX_div	rw	Fan divisor: Supported value are power of 4 (1, 4, 16
+                        64, ... 4194304)
+                        The larger divisor, the less rpm accuracy and the less
+                        affected by fan signal glitch.
+=============== ======= ======================================================
Documentation/hwmon/index.rst +1 -0
index 5c1052d8c57c..614a18477e9f 100644
@@ -43,6 +43,7 @@ Hardware Monitoring Kernel Drivers
    aquacomputer_d5next
    asb100
    asc7621
+   aspeed-g6-pwm-tach
    aspeed-pwm-tacho
    asus_ec_sensors
    asus_wmi_sensors
drivers/hwmon/Kconfig +11 -0
index 283e0adafbc1..1f82df1979db 100644
@@ -411,6 +411,17 @@ config SENSORS_ASPEED
 	  This driver can also be built as a module. If so, the module
 	  will be called aspeed_pwm_tacho.
 
+config SENSORS_ASPEED_G6
+	tristate "ASPEED g6 PWM and Fan tach driver"
+	depends on ARCH_ASPEED || COMPILE_TEST
+	depends on PWM
+	help
+	  This driver provides support for ASPEED G6 PWM and Fan Tach
+	  controllers.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called aspeed_pwm_tacho.
+
 config SENSORS_ATXP1
 	tristate "Attansic ATXP1 VID controller"
 	depends on I2C
drivers/hwmon/Makefile +1 -0
index abefc16c1e1e..1fbb66c37a7c 100644
@@ -54,6 +54,7 @@ obj-$(CONFIG_SENSORS_ARM_SCPI)	+= scpi-hwmon.o
 obj-$(CONFIG_SENSORS_AS370)	+= as370-hwmon.o
 obj-$(CONFIG_SENSORS_ASC7621)	+= asc7621.o
 obj-$(CONFIG_SENSORS_ASPEED)	+= aspeed-pwm-tacho.o
+obj-$(CONFIG_SENSORS_ASPEED_G6) += aspeed-g6-pwm-tach.o
 obj-$(CONFIG_SENSORS_ATXP1)	+= atxp1.o
 obj-$(CONFIG_SENSORS_AXI_FAN_CONTROL) += axi-fan-control.o
 obj-$(CONFIG_SENSORS_BT1_PVT)	+= bt1-pvt.o
drivers/hwmon/aspeed-g6-pwm-tach.c new file +528 -0

528 lines not on this page · raw message

Signature · 1 line
2.25.1
#11 lore raw

Re: [PATCH v8 3/3] hwmon: (aspeed-g6-pwm-tacho): Support for ASPEED g6 PWM/Fan tach

Quoted 7 lines · Billy Tsai
drivers/hwmon/aspeed-g6-pwm-tach.c new file +7 -0
+static int aspeed_tach_hwmon_write(struct device *dev,
+				   enum hwmon_sensor_types type, u32 attr,
+				   int channel, long val)
+{
+	struct aspeed_pwm_tach_data *priv = dev_get_drvdata(dev);
+	u32 reg_val;
+

drivers/hwmon/aspeed-g6-pwm-tach.c line 353

Quoted 10 lines
drivers/hwmon/aspeed-g6-pwm-tach.c new file +10 -0
+	switch (attr) {
+	case hwmon_fan_div:
+		if (!is_power_of_2(val) || (ilog2(val) % 2) ||
+		    DIV_TO_REG(val) > 0xb)
+			return -EINVAL;
+		priv->tach_divisor = val;
+		reg_val = readl(priv->base + TACH_ASPEED_CTRL(channel));
+		reg_val &= ~TACH_ASPEED_CLK_DIV_T_MASK;
+		reg_val |= FIELD_GET(TACH_ASPEED_CLK_DIV_T_MASK,
+				     DIV_TO_REG(priv->tach_divisor));

Hi Billy,
I notice the fanX_div is always shows 1 after I set 1024. I think FIELD_GET() needs to replaced with FIELD_PREP().

Quoted 14 lines
drivers/hwmon/aspeed-g6-pwm-tach.c new file +12 -0
+		writel(reg_val, priv->base + TACH_ASPEED_CTRL(channel));
+		break;
+	default:
+		return -EOPNOTSUPP;
+	}
+
+	return 0;
+}
 
 
+static void aspeed_present_fan_tach(struct aspeed_pwm_tach_data *priv, u32 tach_ch)
+{
+	u32 val;
+

drivers/hwmon/aspeed-g6-pwm-tach.c line 416

Quoted 10 lines
drivers/hwmon/aspeed-g6-pwm-tach.c new file +10 -0
+	priv->tach_present[tach_ch] = true;
+	priv->tach_divisor = DEFAULT_TACH_DIV;
+
+	val = readl(priv->base + TACH_ASPEED_CTRL(tach_ch));
+	val &= ~(TACH_ASPEED_INVERS_LIMIT | TACH_ASPEED_DEBOUNCE_MASK |
+		 TACH_ASPEED_IO_EDGE_MASK | TACH_ASPEED_CLK_DIV_T_MASK |
+		 TACH_ASPEED_THRESHOLD_MASK);
+	val |= (DEBOUNCE_3_CLK << TACH_ASPEED_DEBOUNCE_BIT) | F2F_EDGES |
+	       FIELD_GET(TACH_ASPEED_CLK_DIV_T_MASK,
+			 DIV_TO_REG(priv->tach_divisor));

And here as well.

Quoted 6 lines
drivers/hwmon/aspeed-g6-pwm-tach.c new file +5 -0
+	writel(val, priv->base + TACH_ASPEED_CTRL(tach_ch));
+
+	aspeed_tach_ch_enable(priv, tach_ch, true);
+}
+
author reviewer
#12 lore raw

Re: [PATCH v8 3/3] hwmon: (aspeed-g6-pwm-tacho): Support for ASPEED g6 PWM/Fan tach

Quoted 49 lines · Billy Tsai
Quoted 7 lines
drivers/hwmon/aspeed-g6-pwm-tach.c new file +7 -0
+static int aspeed_tach_hwmon_write(struct device *dev,
+                                enum hwmon_sensor_types type, u32 attr,
+                                int channel, long val)
+{
+     struct aspeed_pwm_tach_data *priv = dev_get_drvdata(dev);
+     u32 reg_val;
+

drivers/hwmon/aspeed-g6-pwm-tach.c line 353

Quoted 10 lines
drivers/hwmon/aspeed-g6-pwm-tach.c new file +10 -0
+     switch (attr) {
+     case hwmon_fan_div:
+             if (!is_power_of_2(val) || (ilog2(val) % 2) ||
+                 DIV_TO_REG(val) > 0xb)
+                     return -EINVAL;
+             priv->tach_divisor = val;
+             reg_val = readl(priv->base + TACH_ASPEED_CTRL(channel));
+             reg_val &= ~TACH_ASPEED_CLK_DIV_T_MASK;
+             reg_val |= FIELD_GET(TACH_ASPEED_CLK_DIV_T_MASK,
+                                  DIV_TO_REG(priv->tach_divisor));

Hi Billy,
I notice the fanX_div is always shows 1 after I set 1024. I think FIELD_GET() needs to replaced with FIELD_PREP().

Quoted 14 lines
drivers/hwmon/aspeed-g6-pwm-tach.c new file +12 -0
+             writel(reg_val, priv->base + TACH_ASPEED_CTRL(channel));
+             break;
+     default:
+             return -EOPNOTSUPP;
+     }
+
+     return 0;
+}
 
 
+static void aspeed_present_fan_tach(struct aspeed_pwm_tach_data *priv, u32 tach_ch)
+{
+     u32 val;
+

drivers/hwmon/aspeed-g6-pwm-tach.c line 416

Quoted 10 lines
drivers/hwmon/aspeed-g6-pwm-tach.c new file +10 -0
+     priv->tach_present[tach_ch] = true;
+     priv->tach_divisor = DEFAULT_TACH_DIV;
+
+     val = readl(priv->base + TACH_ASPEED_CTRL(tach_ch));
+     val &= ~(TACH_ASPEED_INVERS_LIMIT | TACH_ASPEED_DEBOUNCE_MASK |
+              TACH_ASPEED_IO_EDGE_MASK | TACH_ASPEED_CLK_DIV_T_MASK |
+              TACH_ASPEED_THRESHOLD_MASK);
+     val |= (DEBOUNCE_3_CLK << TACH_ASPEED_DEBOUNCE_BIT) | F2F_EDGES |
+            FIELD_GET(TACH_ASPEED_CLK_DIV_T_MASK,
+                      DIV_TO_REG(priv->tach_divisor));

And here as well.

Quoted 6 lines

drivers/hwmon/aspeed-g6-pwm-tach.c line 421

Quoted 6 lines
drivers/hwmon/aspeed-g6-pwm-tach.c new file +5 -0
+     writel(val, priv->base + TACH_ASPEED_CTRL(tach_ch));
+
+     aspeed_tach_ch_enable(priv, tach_ch, true);
+}
+

Hi Potin,

I will fix it in next verison of the patch.

Thanks for reviewing.