devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 1/3] dt-bindings: hwmon: g762: Convert to yaml schema
@ 2024-05-30 21:16 Christian Marangi
  2024-05-30 21:16 ` [PATCH v3 2/3] dt-bindings: hwmon: g76x: Add support for g761 Christian Marangi
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Christian Marangi @ 2024-05-30 21:16 UTC (permalink / raw)
  To: Jean Delvare, Guenter Roeck, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Christian Marangi, linux-hwmon, devicetree,
	linux-kernel

Convert g762 Documentation to yaml schema and port all the custom
properties and info.

Add the vendor prefix to name to follow naming standard.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
Changes v3:
- Rename yaml to g762 from g76x

 .../devicetree/bindings/hwmon/g762.txt        | 47 -----------
 .../devicetree/bindings/hwmon/gmt,g762.yaml   | 83 +++++++++++++++++++
 2 files changed, 83 insertions(+), 47 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/hwmon/g762.txt
 create mode 100644 Documentation/devicetree/bindings/hwmon/gmt,g762.yaml

diff --git a/Documentation/devicetree/bindings/hwmon/g762.txt b/Documentation/devicetree/bindings/hwmon/g762.txt
deleted file mode 100644
index 6d154c4923de..000000000000
--- a/Documentation/devicetree/bindings/hwmon/g762.txt
+++ /dev/null
@@ -1,47 +0,0 @@
-GMT G762/G763 PWM Fan controller
-
-Required node properties:
-
- - "compatible": must be either "gmt,g762" or "gmt,g763"
- - "reg": I2C bus address of the device
- - "clocks": a fixed clock providing input clock frequency
-	     on CLK pin of the chip.
-
-Optional properties:
-
- - "fan_startv": fan startup voltage. Accepted values are 0, 1, 2 and 3.
-	       The higher the more.
-
- - "pwm_polarity": pwm polarity. Accepted values are 0 (positive duty)
-	       and 1 (negative duty).
-
- - "fan_gear_mode": fan gear mode. Supported values are 0, 1 and 2.
-
-If an optional property is not set in .dts file, then current value is kept
-unmodified (e.g. u-boot installed value).
-
-Additional information on operational parameters for the device is available
-in Documentation/hwmon/g762.rst. A detailed datasheet for the device is available
-at http://natisbad.org/NAS/refs/GMT_EDS-762_763-080710-0.2.pdf.
-
-Example g762 node:
-
-   clocks {
-	#address-cells = <1>;
-	#size-cells = <0>;
-
-	g762_clk: fixedclk {
-		 compatible = "fixed-clock";
-		 #clock-cells = <0>;
-		 clock-frequency = <8192>;
-	}
-   }
-
-   g762: g762@3e {
-	compatible = "gmt,g762";
-	reg = <0x3e>;
-	clocks = <&g762_clk>
-	fan_gear_mode = <0>; /* chip default */
-	fan_startv = <1>;    /* chip default */
-	pwm_polarity = <0>;  /* chip default */
-   };
diff --git a/Documentation/devicetree/bindings/hwmon/gmt,g762.yaml b/Documentation/devicetree/bindings/hwmon/gmt,g762.yaml
new file mode 100644
index 000000000000..8c179cbbc65c
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/gmt,g762.yaml
@@ -0,0 +1,83 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/hwmon/gmt,g762.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: GMT G762/G763 PWM Fan controller
+
+maintainers:
+  - Christian Marangi <ansuelsmth@gmail.com>
+
+description: |
+  GMT G762/G763 PWM Fan controller.
+
+  If an optional property is not set in DT, then current value is kept
+  unmodified (e.g. bootloader installed value).
+
+  Additional information on operational parameters for the device is available
+  in Documentation/hwmon/g762.rst. A detailed datasheet for the device is available
+  at http://natisbad.org/NAS/refs/GMT_EDS-762_763-080710-0.2.pdf.
+
+properties:
+  compatible:
+    enum:
+      - gmt,g762
+      - gmt,g763
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    description: a fixed clock providing input clock frequency on CLK
+      pin of the chip.
+    maxItems: 1
+
+  fan_startv:
+    description: Fan startup voltage step
+    $ref: /schemas/types.yaml#/definitions/uint32
+    enum: [0, 1, 2, 3]
+
+  pwm_polarity:
+    description: PWM polarity (psotivie or negative duty)
+    $ref: /schemas/types.yaml#/definitions/uint32
+    enum: [0, 1]
+
+  fan_gear_mode:
+    description: FAN gear mode. Configure High speed fan setting factor
+    $ref: /schemas/types.yaml#/definitions/uint32
+    enum: [0, 1, 2]
+
+required:
+  - compatible
+  - reg
+  - clocks
+
+additionalProperties: false
+
+examples:
+  - |
+    clocks {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        g762_clk: fixedclk {
+            compatible = "fixed-clock";
+            #clock-cells = <0>;
+            clock-frequency = <8192>;
+        };
+    };
+
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        g762@3e {
+            compatible = "gmt,g762";
+            reg = <0x3e>;
+            clocks = <&g762_clk>;
+            fan_gear_mode = <0>;
+            fan_startv = <1>;
+            pwm_polarity = <0>;
+        };
+    };
-- 
2.43.0


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

* [PATCH v3 2/3] dt-bindings: hwmon: g76x: Add support for g761
  2024-05-30 21:16 [PATCH v3 1/3] dt-bindings: hwmon: g762: Convert to yaml schema Christian Marangi
@ 2024-05-30 21:16 ` Christian Marangi
  2024-05-30 21:16 ` [PATCH v3 3/3] hwmon: g672: add " Christian Marangi
  2024-06-04 15:48 ` [PATCH v3 1/3] dt-bindings: hwmon: g762: Convert to yaml schema Rob Herring
  2 siblings, 0 replies; 4+ messages in thread
From: Christian Marangi @ 2024-05-30 21:16 UTC (permalink / raw)
  To: Jean Delvare, Guenter Roeck, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Christian Marangi, linux-hwmon, devicetree,
	linux-kernel
  Cc: Conor Dooley

Add support for g761 PWM Fan controller. This is an exact copy of g763
with the difference that it does also support an internal clock
oscillator.

With clocks property not defined, the internal clock oscillator is used.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Reviewed-by: Conor Dooley <conor.dooley@microchip.com>
---
Changes v3:
- Add Reviewed-by tag
Changes v2:
- Drop internal-clock property

 .../devicetree/bindings/hwmon/gmt,g762.yaml   | 29 +++++++++++++++++--
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/Documentation/devicetree/bindings/hwmon/gmt,g762.yaml b/Documentation/devicetree/bindings/hwmon/gmt,g762.yaml
index 8c179cbbc65c..a2b1557684da 100644
--- a/Documentation/devicetree/bindings/hwmon/gmt,g762.yaml
+++ b/Documentation/devicetree/bindings/hwmon/gmt,g762.yaml
@@ -4,13 +4,17 @@
 $id: http://devicetree.org/schemas/hwmon/gmt,g762.yaml#
 $schema: http://devicetree.org/meta-schemas/core.yaml#
 
-title: GMT G762/G763 PWM Fan controller
+title: GMT G761/G762/G763 PWM Fan controller
 
 maintainers:
   - Christian Marangi <ansuelsmth@gmail.com>
 
 description: |
-  GMT G762/G763 PWM Fan controller.
+  GMT G761/G762/G763 PWM Fan controller.
+
+  G761 supports an internal-clock hence the clocks property is optional.
+  If not defined, internal-clock will be used. (31KHz is the clock of
+  the internal crystal oscillator)
 
   If an optional property is not set in DT, then current value is kept
   unmodified (e.g. bootloader installed value).
@@ -22,6 +26,7 @@ description: |
 properties:
   compatible:
     enum:
+      - gmt,g761
       - gmt,g762
       - gmt,g763
 
@@ -51,7 +56,17 @@ properties:
 required:
   - compatible
   - reg
-  - clocks
+
+if:
+  properties:
+    compatible:
+      contains:
+        enum:
+          - gmt,g762
+          - gmt,g763
+then:
+  required:
+    - clocks
 
 additionalProperties: false
 
@@ -80,4 +95,12 @@ examples:
             fan_startv = <1>;
             pwm_polarity = <0>;
         };
+
+        g761@1e {
+            compatible = "gmt,g761";
+            reg = <0x1e>;
+            fan_gear_mode = <0>;
+            fan_startv = <1>;
+            pwm_polarity = <0>;
+        };
     };
-- 
2.43.0


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

* [PATCH v3 3/3] hwmon: g672: add support for g761
  2024-05-30 21:16 [PATCH v3 1/3] dt-bindings: hwmon: g762: Convert to yaml schema Christian Marangi
  2024-05-30 21:16 ` [PATCH v3 2/3] dt-bindings: hwmon: g76x: Add support for g761 Christian Marangi
@ 2024-05-30 21:16 ` Christian Marangi
  2024-06-04 15:48 ` [PATCH v3 1/3] dt-bindings: hwmon: g762: Convert to yaml schema Rob Herring
  2 siblings, 0 replies; 4+ messages in thread
From: Christian Marangi @ 2024-05-30 21:16 UTC (permalink / raw)
  To: Jean Delvare, Guenter Roeck, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Christian Marangi, linux-hwmon, devicetree,
	linux-kernel

Add support for g761 PWM Fan Controller.

The g761 is a copy of the g763 with the only difference of supporting
and internal clock. The internal clock is used if no clocks property is
defined in device node and in such case the required bit is enabled and
clock handling is skipped.

The internal clock oscillator runs at 31KHz.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
Changes v2:
- Rework handling of internal clock

 drivers/hwmon/g762.c | 33 ++++++++++++++++++++++++++++++---
 1 file changed, 30 insertions(+), 3 deletions(-)

diff --git a/drivers/hwmon/g762.c b/drivers/hwmon/g762.c
index af1228708e25..a00cf3245eec 100644
--- a/drivers/hwmon/g762.c
+++ b/drivers/hwmon/g762.c
@@ -69,6 +69,7 @@ enum g762_regs {
 #define G762_REG_FAN_CMD1_PWM_POLARITY  0x02 /* PWM polarity */
 #define G762_REG_FAN_CMD1_PULSE_PER_REV 0x01 /* pulse per fan revolution */
 
+#define G761_REG_FAN_CMD2_FAN_CLOCK     0x20 /* choose internal clock*/
 #define G762_REG_FAN_CMD2_GEAR_MODE_1   0x08 /* fan gear mode */
 #define G762_REG_FAN_CMD2_GEAR_MODE_0   0x04
 #define G762_REG_FAN_CMD2_FAN_STARTV_1  0x02 /* fan startup voltage */
@@ -115,6 +116,7 @@ enum g762_regs {
 
 struct g762_data {
 	struct i2c_client *client;
+	bool internal_clock;
 	struct clk *clk;
 
 	/* update mutex */
@@ -566,6 +568,7 @@ static int do_set_fan_startv(struct device *dev, unsigned long val)
 
 #ifdef CONFIG_OF
 static const struct of_device_id g762_dt_match[] = {
+	{ .compatible = "gmt,g761" },
 	{ .compatible = "gmt,g762" },
 	{ .compatible = "gmt,g763" },
 	{ },
@@ -597,6 +600,21 @@ static int g762_of_clock_enable(struct i2c_client *client)
 	if (!client->dev.of_node)
 		return 0;
 
+	data = i2c_get_clientdata(client);
+
+	/*
+	 * Skip CLK detection and handling if we use internal clock.
+	 * This is only valid for g761.
+	 */
+	data->internal_clock = of_device_is_compatible(client->dev.of_node,
+						       "gmt,g761") &&
+			       !of_property_present(client->dev.of_node,
+						    "clocks");
+	if (data->internal_clock) {
+		do_set_clk_freq(&client->dev, 32768);
+		return 0;
+	}
+
 	clk = of_clk_get(client->dev.of_node, 0);
 	if (IS_ERR(clk)) {
 		dev_err(&client->dev, "failed to get clock\n");
@@ -616,7 +634,6 @@ static int g762_of_clock_enable(struct i2c_client *client)
 		goto clk_unprep;
 	}
 
-	data = i2c_get_clientdata(client);
 	data->clk = clk;
 
 	ret = devm_add_action(&client->dev, g762_of_clock_disable, data);
@@ -1025,16 +1042,26 @@ ATTRIBUTE_GROUPS(g762);
 static inline int g762_fan_init(struct device *dev)
 {
 	struct g762_data *data = g762_update_client(dev);
+	int ret;
 
 	if (IS_ERR(data))
 		return PTR_ERR(data);
 
+	/* internal_clock can only be set with compatible g761 */
+	if (data->internal_clock)
+		data->fan_cmd2 |= G761_REG_FAN_CMD2_FAN_CLOCK;
+
 	data->fan_cmd1 |= G762_REG_FAN_CMD1_DET_FAN_FAIL;
 	data->fan_cmd1 |= G762_REG_FAN_CMD1_DET_FAN_OOC;
 	data->valid = false;
 
-	return i2c_smbus_write_byte_data(data->client, G762_REG_FAN_CMD1,
-					 data->fan_cmd1);
+	ret = i2c_smbus_write_byte_data(data->client, G762_REG_FAN_CMD1,
+					data->fan_cmd1);
+	if (ret)
+		return ret;
+
+	return i2c_smbus_write_byte_data(data->client, G762_REG_FAN_CMD2,
+					 data->fan_cmd2);
 }
 
 static int g762_probe(struct i2c_client *client)
-- 
2.43.0


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

* Re: [PATCH v3 1/3] dt-bindings: hwmon: g762: Convert to yaml schema
  2024-05-30 21:16 [PATCH v3 1/3] dt-bindings: hwmon: g762: Convert to yaml schema Christian Marangi
  2024-05-30 21:16 ` [PATCH v3 2/3] dt-bindings: hwmon: g76x: Add support for g761 Christian Marangi
  2024-05-30 21:16 ` [PATCH v3 3/3] hwmon: g672: add " Christian Marangi
@ 2024-06-04 15:48 ` Rob Herring
  2 siblings, 0 replies; 4+ messages in thread
From: Rob Herring @ 2024-06-04 15:48 UTC (permalink / raw)
  To: Christian Marangi
  Cc: Jean Delvare, Guenter Roeck, Krzysztof Kozlowski, Conor Dooley,
	linux-hwmon, devicetree, linux-kernel

On Thu, May 30, 2024 at 11:16:50PM +0200, Christian Marangi wrote:
> Convert g762 Documentation to yaml schema and port all the custom
> properties and info.
> 
> Add the vendor prefix to name to follow naming standard.
> 
> Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
> ---
> Changes v3:
> - Rename yaml to g762 from g76x
> 
>  .../devicetree/bindings/hwmon/g762.txt        | 47 -----------
>  .../devicetree/bindings/hwmon/gmt,g762.yaml   | 83 +++++++++++++++++++
>  2 files changed, 83 insertions(+), 47 deletions(-)
>  delete mode 100644 Documentation/devicetree/bindings/hwmon/g762.txt
>  create mode 100644 Documentation/devicetree/bindings/hwmon/gmt,g762.yaml
> 
> diff --git a/Documentation/devicetree/bindings/hwmon/g762.txt b/Documentation/devicetree/bindings/hwmon/g762.txt
> deleted file mode 100644
> index 6d154c4923de..000000000000
> --- a/Documentation/devicetree/bindings/hwmon/g762.txt
> +++ /dev/null
> @@ -1,47 +0,0 @@
> -GMT G762/G763 PWM Fan controller
> -
> -Required node properties:
> -
> - - "compatible": must be either "gmt,g762" or "gmt,g763"
> - - "reg": I2C bus address of the device
> - - "clocks": a fixed clock providing input clock frequency
> -	     on CLK pin of the chip.
> -
> -Optional properties:
> -
> - - "fan_startv": fan startup voltage. Accepted values are 0, 1, 2 and 3.
> -	       The higher the more.
> -
> - - "pwm_polarity": pwm polarity. Accepted values are 0 (positive duty)
> -	       and 1 (negative duty).
> -
> - - "fan_gear_mode": fan gear mode. Supported values are 0, 1 and 2.
> -
> -If an optional property is not set in .dts file, then current value is kept
> -unmodified (e.g. u-boot installed value).
> -
> -Additional information on operational parameters for the device is available
> -in Documentation/hwmon/g762.rst. A detailed datasheet for the device is available
> -at http://natisbad.org/NAS/refs/GMT_EDS-762_763-080710-0.2.pdf.
> -
> -Example g762 node:
> -
> -   clocks {
> -	#address-cells = <1>;
> -	#size-cells = <0>;
> -
> -	g762_clk: fixedclk {
> -		 compatible = "fixed-clock";
> -		 #clock-cells = <0>;
> -		 clock-frequency = <8192>;
> -	}
> -   }
> -
> -   g762: g762@3e {
> -	compatible = "gmt,g762";
> -	reg = <0x3e>;
> -	clocks = <&g762_clk>
> -	fan_gear_mode = <0>; /* chip default */
> -	fan_startv = <1>;    /* chip default */
> -	pwm_polarity = <0>;  /* chip default */
> -   };
> diff --git a/Documentation/devicetree/bindings/hwmon/gmt,g762.yaml b/Documentation/devicetree/bindings/hwmon/gmt,g762.yaml
> new file mode 100644
> index 000000000000..8c179cbbc65c
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/hwmon/gmt,g762.yaml
> @@ -0,0 +1,83 @@
> +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/hwmon/gmt,g762.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: GMT G762/G763 PWM Fan controller
> +
> +maintainers:
> +  - Christian Marangi <ansuelsmth@gmail.com>
> +
> +description: |
> +  GMT G762/G763 PWM Fan controller.
> +
> +  If an optional property is not set in DT, then current value is kept
> +  unmodified (e.g. bootloader installed value).
> +
> +  Additional information on operational parameters for the device is available
> +  in Documentation/hwmon/g762.rst. A detailed datasheet for the device is available
> +  at http://natisbad.org/NAS/refs/GMT_EDS-762_763-080710-0.2.pdf.
> +
> +properties:
> +  compatible:
> +    enum:
> +      - gmt,g762
> +      - gmt,g763
> +
> +  reg:
> +    maxItems: 1
> +
> +  clocks:
> +    description: a fixed clock providing input clock frequency on CLK
> +      pin of the chip.
> +    maxItems: 1
> +
> +  fan_startv:
> +    description: Fan startup voltage step
> +    $ref: /schemas/types.yaml#/definitions/uint32
> +    enum: [0, 1, 2, 3]
> +
> +  pwm_polarity:
> +    description: PWM polarity (psotivie or negative duty)

typo

> +    $ref: /schemas/types.yaml#/definitions/uint32
> +    enum: [0, 1]
> +
> +  fan_gear_mode:
> +    description: FAN gear mode. Configure High speed fan setting factor
> +    $ref: /schemas/types.yaml#/definitions/uint32
> +    enum: [0, 1, 2]
> +
> +required:
> +  - compatible
> +  - reg
> +  - clocks
> +
> +additionalProperties: false
> +
> +examples:
> +  - |
> +    clocks {
> +        #address-cells = <1>;
> +        #size-cells = <0>;
> +
> +        g762_clk: fixedclk {
> +            compatible = "fixed-clock";
> +            #clock-cells = <0>;
> +            clock-frequency = <8192>;
> +        };

Drop. Providers are outside the scope of bindings.

With that,

Reviewed-by: Rob Herring (Arm) <robh@kernel.org>

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

end of thread, other threads:[~2024-06-04 15:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-30 21:16 [PATCH v3 1/3] dt-bindings: hwmon: g762: Convert to yaml schema Christian Marangi
2024-05-30 21:16 ` [PATCH v3 2/3] dt-bindings: hwmon: g76x: Add support for g761 Christian Marangi
2024-05-30 21:16 ` [PATCH v3 3/3] hwmon: g672: add " Christian Marangi
2024-06-04 15:48 ` [PATCH v3 1/3] dt-bindings: hwmon: g762: Convert to yaml schema Rob Herring

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