linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] gpio: ixp4xx: Handle external clock output
@ 2023-09-20 22:23 Linus Walleij
  2023-09-20 22:23 ` [PATCH 1/2] gpio: Rewrite IXP4xx GPIO bindings in schema Linus Walleij
  2023-09-20 22:23 ` [PATCH 2/2] gpio: ixp4xx: Handle clock output on pin 14 and 15 Linus Walleij
  0 siblings, 2 replies; 6+ messages in thread
From: Linus Walleij @ 2023-09-20 22:23 UTC (permalink / raw)
  To: Linus Walleij, Imre Kaloz, Krzysztof Halasa, Bartosz Golaszewski,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: linux-arm-kernel, linux-gpio, devicetree, Linus Walleij

The GPIO block on the very legacy IXP4xx GPIO can provide
a generated clock output on GPIO 14 and GPIO 15. This
provides a straight-forward solution with a flag for each
clock output.

More complicated solutions are thinkable, but I deemed them
overdesigned for this legacy SoC.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
Linus Walleij (2):
      gpio: Rewrite IXP4xx GPIO bindings in schema
      gpio: ixp4xx: Handle clock output on pin 14 and 15

 .../devicetree/bindings/gpio/intel,ixp4xx-gpio.txt | 38 ------------
 .../bindings/gpio/intel,ixp4xx-gpio.yaml           | 70 ++++++++++++++++++++++
 MAINTAINERS                                        |  2 +-
 drivers/gpio/gpio-ixp4xx.c                         | 36 ++++++++++-
 4 files changed, 106 insertions(+), 40 deletions(-)
---
base-commit: 0bb80ecc33a8fb5a682236443c1e740d5c917d1d
change-id: 20230921-ixp4xx-gpio-clocks-7e82289f4bb3

Best regards,
-- 
Linus Walleij <linus.walleij@linaro.org>


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

* [PATCH 1/2] gpio: Rewrite IXP4xx GPIO bindings in schema
  2023-09-20 22:23 [PATCH 0/2] gpio: ixp4xx: Handle external clock output Linus Walleij
@ 2023-09-20 22:23 ` Linus Walleij
  2023-09-21 18:44   ` Rob Herring
  2023-09-20 22:23 ` [PATCH 2/2] gpio: ixp4xx: Handle clock output on pin 14 and 15 Linus Walleij
  1 sibling, 1 reply; 6+ messages in thread
From: Linus Walleij @ 2023-09-20 22:23 UTC (permalink / raw)
  To: Linus Walleij, Imre Kaloz, Krzysztof Halasa, Bartosz Golaszewski,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: linux-arm-kernel, linux-gpio, devicetree, Linus Walleij

This rewrites the IXP4xx GPIO bindings to use YAML schema,
and adds two new properties to enable fixed clock output on
pins 14 and 15.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 .../devicetree/bindings/gpio/intel,ixp4xx-gpio.txt | 38 ------------
 .../bindings/gpio/intel,ixp4xx-gpio.yaml           | 70 ++++++++++++++++++++++
 MAINTAINERS                                        |  2 +-
 3 files changed, 71 insertions(+), 39 deletions(-)

diff --git a/Documentation/devicetree/bindings/gpio/intel,ixp4xx-gpio.txt b/Documentation/devicetree/bindings/gpio/intel,ixp4xx-gpio.txt
deleted file mode 100644
index 8dc41ed99685..000000000000
--- a/Documentation/devicetree/bindings/gpio/intel,ixp4xx-gpio.txt
+++ /dev/null
@@ -1,38 +0,0 @@
-Intel IXP4xx XScale Networking Processors GPIO
-
-This GPIO controller is found in the Intel IXP4xx processors.
-It supports 16 GPIO lines.
-
-The interrupt portions of the GPIO controller is hierarchical:
-the synchronous edge detector is part of the GPIO block, but the
-actual enabling/disabling of the interrupt line is done in the
-main IXP4xx interrupt controller which has a 1:1 mapping for
-the first 12 GPIO lines to 12 system interrupts.
-
-The remaining 4 GPIO lines can not be used for receiving
-interrupts.
-
-The interrupt parent of this GPIO controller must be the
-IXP4xx interrupt controller.
-
-Required properties:
-
-- compatible : Should be
-  "intel,ixp4xx-gpio"
-- reg : Should contain registers location and length
-- gpio-controller : marks this as a GPIO controller
-- #gpio-cells : Should be 2, see gpio/gpio.txt
-- interrupt-controller : marks this as an interrupt controller
-- #interrupt-cells : a standard two-cell interrupt, see
-  interrupt-controller/interrupts.txt
-
-Example:
-
-gpio0: gpio@c8004000 {
-	compatible = "intel,ixp4xx-gpio";
-	reg = <0xc8004000 0x1000>;
-	gpio-controller;
-	#gpio-cells = <2>;
-	interrupt-controller;
-	#interrupt-cells = <2>;
-};
diff --git a/Documentation/devicetree/bindings/gpio/intel,ixp4xx-gpio.yaml b/Documentation/devicetree/bindings/gpio/intel,ixp4xx-gpio.yaml
new file mode 100644
index 000000000000..bb1fc393bd8c
--- /dev/null
+++ b/Documentation/devicetree/bindings/gpio/intel,ixp4xx-gpio.yaml
@@ -0,0 +1,70 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/gpio/intel,ixp4xx-gpio.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Intel IXP4xx XScale Networking Processors GPIO Controller
+
+description: This GPIO controller is found in the Intel IXP4xx
+  processors. It supports 16 GPIO lines.
+  The interrupt portions of the GPIO controller is hierarchical.
+  The synchronous edge detector is part of the GPIO block, but the
+  actual enabling/disabling of the interrupt line is done in the
+  main IXP4xx interrupt controller which has a 1-to-1 mapping for
+  the first 12 GPIO lines to 12 system interrupts.
+  The remaining 4 GPIO lines can not be used for receiving
+  interrupts.
+  The interrupt parent of this GPIO controller must be the
+  IXP4xx interrupt controller.
+  GPIO 14 and 15 can be used as clock outputs rather than GPIO,
+  and this can be enabled by a special flag.
+
+maintainers:
+  - Linus Walleij <linus.walleij@linaro.org>
+
+properties:
+  compatible:
+    const: intel,ixp4xx-gpio
+
+  reg:
+    maxItems: 1
+
+  gpio-controller: true
+  "#gpio-cells":
+    const: 2
+
+  interrupt-controller: true
+  "#interrupt-cells":
+    const: 2
+
+  intel,ixp4xx-gpio14-clkout:
+    description: If defined, enables clock output on GPIO 14
+      instead of GPIO.
+    type: boolean
+
+  intel,ixp4xx-gpio15-clkout:
+    description: If defined, enables clock output on GPIO 15
+      instead of GPIO.
+    type: boolean
+
+required:
+  - compatible
+  - reg
+  - "#gpio-cells"
+  - interrupt-controller
+  - "#interrupt-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    gpio@c8004000 {
+        compatible = "intel,ixp4xx-gpio";
+        reg = <0xc8004000 0x1000>;
+        gpio-controller;
+        #gpio-cells = <2>;
+        interrupt-controller;
+        #interrupt-cells = <2>;
+    };
diff --git a/MAINTAINERS b/MAINTAINERS
index 90f13281d297..4e216887eb76 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2215,7 +2215,7 @@ M:	Krzysztof Halasa <khalasa@piap.pl>
 L:	linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
 S:	Maintained
 F:	Documentation/devicetree/bindings/arm/intel-ixp4xx.yaml
-F:	Documentation/devicetree/bindings/gpio/intel,ixp4xx-gpio.txt
+F:	Documentation/devicetree/bindings/gpio/intel,ixp4xx-gpio.yaml
 F:	Documentation/devicetree/bindings/interrupt-controller/intel,ixp4xx-interrupt.yaml
 F:	Documentation/devicetree/bindings/memory-controllers/intel,ixp4xx-expansion*
 F:	Documentation/devicetree/bindings/timer/intel,ixp4xx-timer.yaml

-- 
2.41.0


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

* [PATCH 2/2] gpio: ixp4xx: Handle clock output on pin 14 and 15
  2023-09-20 22:23 [PATCH 0/2] gpio: ixp4xx: Handle external clock output Linus Walleij
  2023-09-20 22:23 ` [PATCH 1/2] gpio: Rewrite IXP4xx GPIO bindings in schema Linus Walleij
@ 2023-09-20 22:23 ` Linus Walleij
  2023-09-21 11:22   ` Andy Shevchenko
  1 sibling, 1 reply; 6+ messages in thread
From: Linus Walleij @ 2023-09-20 22:23 UTC (permalink / raw)
  To: Linus Walleij, Imre Kaloz, Krzysztof Halasa, Bartosz Golaszewski,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: linux-arm-kernel, linux-gpio, devicetree, Linus Walleij

This makes it possible to provide basic clock output on pins
14 and 15. The clocks are typically used by random electronics,
not modeled in the device tree, so they just need to be provided
on request.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/gpio/gpio-ixp4xx.c | 36 +++++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-ixp4xx.c b/drivers/gpio/gpio-ixp4xx.c
index dde6cf3a5779..6a9d32b4d0d7 100644
--- a/drivers/gpio/gpio-ixp4xx.c
+++ b/drivers/gpio/gpio-ixp4xx.c
@@ -38,6 +38,18 @@
 #define IXP4XX_GPIO_STYLE_MASK		GENMASK(2, 0)
 #define IXP4XX_GPIO_STYLE_SIZE		3
 
+/*
+ * Clock output control register defines.
+ */
+#define IXP4XX_GPCLK_CLK0DC_SHIFT	0
+#define IXP4XX_GPCLK_CLK0TC_SHIFT	4
+#define IXP4XX_GPCLK_CLK0_MASK		GENMASK(7, 0)
+#define IXP4XX_GPCLK_MUX14		BIT(8)
+#define IXP4XX_GPCLK_CLK1DC_SHIFT	16
+#define IXP4XX_GPCLK_CLK1TC_SHIFT	20
+#define IXP4XX_GPCLK_CLK1_MASK		GENMASK(23, 16)
+#define IXP4XX_GPCLK_MUX15		BIT(24)
+
 /**
  * struct ixp4xx_gpio - IXP4 GPIO state container
  * @dev: containing device for this instance
@@ -202,6 +214,7 @@ static int ixp4xx_gpio_probe(struct platform_device *pdev)
 	struct ixp4xx_gpio *g;
 	struct gpio_irq_chip *girq;
 	struct device_node *irq_parent;
+	u32 val;
 	int ret;
 
 	g = devm_kzalloc(dev, sizeof(*g), GFP_KERNEL);
@@ -225,13 +238,34 @@ static int ixp4xx_gpio_probe(struct platform_device *pdev)
 	}
 	g->fwnode = of_node_to_fwnode(np);
 
+	val = __raw_readl(g->base + IXP4XX_REG_GPCLK);
 	/*
 	 * Make sure GPIO 14 and 15 are NOT used as clocks but GPIO on
 	 * specific machines.
 	 */
 	if (of_machine_is_compatible("dlink,dsm-g600-a") ||
 	    of_machine_is_compatible("iom,nas-100d"))
-		__raw_writel(0x0, g->base + IXP4XX_REG_GPCLK);
+		val = 0;
+
+	/*
+	 * Enable clock outputs with default timings of requested clock.
+	 * If you need control over TC and DC, add these to the device
+	 * tree bindings and use them here.
+	 */
+	if (of_property_read_bool(np, "intel,ixp4xx-gpio14-clkout")) {
+		val &= ~IXP4XX_GPCLK_CLK0_MASK;
+		val |= (0 << IXP4XX_GPCLK_CLK0DC_SHIFT);
+		val |= (1 << IXP4XX_GPCLK_CLK0TC_SHIFT);
+		val |= IXP4XX_GPCLK_MUX14;
+	}
+
+	if (of_property_read_bool(np, "intel,ixp4xx-gpio15-clkout")) {
+		val &= ~IXP4XX_GPCLK_CLK1_MASK;
+		val |= (0 << IXP4XX_GPCLK_CLK1DC_SHIFT);
+		val |= (1 << IXP4XX_GPCLK_CLK1TC_SHIFT);
+		val |= IXP4XX_GPCLK_MUX15;
+	}
+	__raw_writel(val, g->base + IXP4XX_REG_GPCLK);
 
 	/*
 	 * This is a very special big-endian ARM issue: when the IXP4xx is

-- 
2.41.0


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

* Re: [PATCH 2/2] gpio: ixp4xx: Handle clock output on pin 14 and 15
  2023-09-20 22:23 ` [PATCH 2/2] gpio: ixp4xx: Handle clock output on pin 14 and 15 Linus Walleij
@ 2023-09-21 11:22   ` Andy Shevchenko
  2023-09-21 12:34     ` Linus Walleij
  0 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2023-09-21 11:22 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Linus Walleij, Imre Kaloz, Krzysztof Halasa, Bartosz Golaszewski,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, linux-arm-kernel,
	linux-gpio, devicetree

On Thu, Sep 21, 2023 at 12:23:46AM +0200, Linus Walleij wrote:
> This makes it possible to provide basic clock output on pins
> 14 and 15. The clocks are typically used by random electronics,
> not modeled in the device tree, so they just need to be provided
> on request.

...

> +	val = __raw_readl(g->base + IXP4XX_REG_GPCLK);

Do we need to read this...

>  	/*
>  	 * Make sure GPIO 14 and 15 are NOT used as clocks but GPIO on
>  	 * specific machines.
>  	 */
>  	if (of_machine_is_compatible("dlink,dsm-g600-a") ||
>  	    of_machine_is_compatible("iom,nas-100d"))
> -		__raw_writel(0x0, g->base + IXP4XX_REG_GPCLK);
> +		val = 0;

...if we are going to discard it anyway here?

Maybe

	if (...)
		val = 0;
	else
		val = readl();

?

...

> +	/*
> +	 * Enable clock outputs with default timings of requested clock.
> +	 * If you need control over TC and DC, add these to the device
> +	 * tree bindings and use them here.
> +	 */

Shouldn't this be integrated into PPS subsystem?

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH 2/2] gpio: ixp4xx: Handle clock output on pin 14 and 15
  2023-09-21 11:22   ` Andy Shevchenko
@ 2023-09-21 12:34     ` Linus Walleij
  0 siblings, 0 replies; 6+ messages in thread
From: Linus Walleij @ 2023-09-21 12:34 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Linus Walleij, Imre Kaloz, Krzysztof Halasa, Bartosz Golaszewski,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, linux-arm-kernel,
	linux-gpio, devicetree

On Thu, Sep 21, 2023 at 1:23 PM Andy Shevchenko <andy@kernel.org> wrote:

> Maybe
>
>         if (...)
>                 val = 0;
>         else
>                 val = readl();
>
> ?

Neat, I'll do this!

> > +     /*
> > +      * Enable clock outputs with default timings of requested clock.
> > +      * If you need control over TC and DC, add these to the device
> > +      * tree bindings and use them here.
> > +      */
>
> Shouldn't this be integrated into PPS subsystem?

PPS is for GPS, we *could* integrate it into the clk subsystem (with
configuration cells and all hoopla) but as I state in the cover letter
I think it becomes overengineered for this legacy system, there are
no users or benefit of that added complexity as compared to these
few-liners.

Yours,
Linus Walleij

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

* Re: [PATCH 1/2] gpio: Rewrite IXP4xx GPIO bindings in schema
  2023-09-20 22:23 ` [PATCH 1/2] gpio: Rewrite IXP4xx GPIO bindings in schema Linus Walleij
@ 2023-09-21 18:44   ` Rob Herring
  0 siblings, 0 replies; 6+ messages in thread
From: Rob Herring @ 2023-09-21 18:44 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Linus Walleij, Imre Kaloz, Krzysztof Halasa, Bartosz Golaszewski,
	Andy Shevchenko, Krzysztof Kozlowski, Conor Dooley,
	linux-arm-kernel, linux-gpio, devicetree

On Thu, Sep 21, 2023 at 12:23:45AM +0200, Linus Walleij wrote:
> This rewrites the IXP4xx GPIO bindings to use YAML schema,
> and adds two new properties to enable fixed clock output on
> pins 14 and 15.
> 
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
>  .../devicetree/bindings/gpio/intel,ixp4xx-gpio.txt | 38 ------------
>  .../bindings/gpio/intel,ixp4xx-gpio.yaml           | 70 ++++++++++++++++++++++
>  MAINTAINERS                                        |  2 +-
>  3 files changed, 71 insertions(+), 39 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/gpio/intel,ixp4xx-gpio.txt b/Documentation/devicetree/bindings/gpio/intel,ixp4xx-gpio.txt
> deleted file mode 100644
> index 8dc41ed99685..000000000000
> --- a/Documentation/devicetree/bindings/gpio/intel,ixp4xx-gpio.txt
> +++ /dev/null
> @@ -1,38 +0,0 @@
> -Intel IXP4xx XScale Networking Processors GPIO
> -
> -This GPIO controller is found in the Intel IXP4xx processors.
> -It supports 16 GPIO lines.
> -
> -The interrupt portions of the GPIO controller is hierarchical:
> -the synchronous edge detector is part of the GPIO block, but the
> -actual enabling/disabling of the interrupt line is done in the
> -main IXP4xx interrupt controller which has a 1:1 mapping for
> -the first 12 GPIO lines to 12 system interrupts.
> -
> -The remaining 4 GPIO lines can not be used for receiving
> -interrupts.
> -
> -The interrupt parent of this GPIO controller must be the
> -IXP4xx interrupt controller.
> -
> -Required properties:
> -
> -- compatible : Should be
> -  "intel,ixp4xx-gpio"
> -- reg : Should contain registers location and length
> -- gpio-controller : marks this as a GPIO controller
> -- #gpio-cells : Should be 2, see gpio/gpio.txt
> -- interrupt-controller : marks this as an interrupt controller
> -- #interrupt-cells : a standard two-cell interrupt, see
> -  interrupt-controller/interrupts.txt
> -
> -Example:
> -
> -gpio0: gpio@c8004000 {
> -	compatible = "intel,ixp4xx-gpio";
> -	reg = <0xc8004000 0x1000>;
> -	gpio-controller;
> -	#gpio-cells = <2>;
> -	interrupt-controller;
> -	#interrupt-cells = <2>;
> -};
> diff --git a/Documentation/devicetree/bindings/gpio/intel,ixp4xx-gpio.yaml b/Documentation/devicetree/bindings/gpio/intel,ixp4xx-gpio.yaml
> new file mode 100644
> index 000000000000..bb1fc393bd8c
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/gpio/intel,ixp4xx-gpio.yaml
> @@ -0,0 +1,70 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/gpio/intel,ixp4xx-gpio.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Intel IXP4xx XScale Networking Processors GPIO Controller
> +
> +description: This GPIO controller is found in the Intel IXP4xx
> +  processors. It supports 16 GPIO lines.
> +  The interrupt portions of the GPIO controller is hierarchical.
> +  The synchronous edge detector is part of the GPIO block, but the
> +  actual enabling/disabling of the interrupt line is done in the
> +  main IXP4xx interrupt controller which has a 1-to-1 mapping for
> +  the first 12 GPIO lines to 12 system interrupts.
> +  The remaining 4 GPIO lines can not be used for receiving
> +  interrupts.
> +  The interrupt parent of this GPIO controller must be the
> +  IXP4xx interrupt controller.
> +  GPIO 14 and 15 can be used as clock outputs rather than GPIO,
> +  and this can be enabled by a special flag.

Do you care about the formatting here? If so, you are missing a '|'. If 
not, you have strange line breaks.

> +
> +maintainers:
> +  - Linus Walleij <linus.walleij@linaro.org>
> +
> +properties:
> +  compatible:
> +    const: intel,ixp4xx-gpio
> +
> +  reg:
> +    maxItems: 1
> +
> +  gpio-controller: true

Blank line between DT properties

> +  "#gpio-cells":
> +    const: 2
> +
> +  interrupt-controller: true

Blank line

> +  "#interrupt-cells":
> +    const: 2

Otherwise, with those nits fixed:

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

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

end of thread, other threads:[~2023-09-21 20:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-20 22:23 [PATCH 0/2] gpio: ixp4xx: Handle external clock output Linus Walleij
2023-09-20 22:23 ` [PATCH 1/2] gpio: Rewrite IXP4xx GPIO bindings in schema Linus Walleij
2023-09-21 18:44   ` Rob Herring
2023-09-20 22:23 ` [PATCH 2/2] gpio: ixp4xx: Handle clock output on pin 14 and 15 Linus Walleij
2023-09-21 11:22   ` Andy Shevchenko
2023-09-21 12:34     ` Linus Walleij

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).