linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] gpio clock-names
@ 2022-09-01  1:29 Jianqun Xu
  2022-09-01  1:29 ` [PATCH 1/2] dt-bindings: gpio: rockchip: add clock-names Jianqun Xu
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Jianqun Xu @ 2022-09-01  1:29 UTC (permalink / raw)
  To: linus.walleij, heiko
  Cc: robh+dt, krzysztof.kozlowski+dt, linux-gpio, linux-rockchip,
	Jianqun Xu

Add 'clock-names' for gpio dt nodes.

Jianqun Xu (2):
  dt-bindings: gpio: rockchip: add clock-names
  arm64: dts: rockchip: rk356x add 'clock-names' for gpio nodes

 .../devicetree/bindings/gpio/rockchip,gpio-bank.yaml        | 6 ++++++
 arch/arm64/boot/dts/rockchip/rk356x.dtsi                    | 5 +++++
 2 files changed, 11 insertions(+)

-- 
2.25.1


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

* [PATCH 1/2] dt-bindings: gpio: rockchip: add clock-names
  2022-09-01  1:29 [PATCH 0/2] gpio clock-names Jianqun Xu
@ 2022-09-01  1:29 ` Jianqun Xu
  2022-09-01 11:48   ` Rob Herring
  2022-09-01  1:29 ` [PATCH v1 1/3] gpio: rockchip: make gpio work without cru module Jianqun Xu
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Jianqun Xu @ 2022-09-01  1:29 UTC (permalink / raw)
  To: linus.walleij, heiko
  Cc: robh+dt, krzysztof.kozlowski+dt, linux-gpio, linux-rockchip,
	Jianqun Xu

Add 'clock-names' to the gpio dt node. so the driver could get clocks by
a const char id, this patch names the clock-names as
  - 'bus': the apb clock for cpu to access the gpio controller
  - 'db': the debounce clock for cpu to set debounce clock rate

Since the old dt nodes may have no clock-names, this patch not make them
as part of 'required properties'.

Signed-off-by: Jianqun Xu <jay.xu@rock-chips.com>
---
 .../devicetree/bindings/gpio/rockchip,gpio-bank.yaml        | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/Documentation/devicetree/bindings/gpio/rockchip,gpio-bank.yaml b/Documentation/devicetree/bindings/gpio/rockchip,gpio-bank.yaml
index affd823c881d..d43d4c71bebf 100644
--- a/Documentation/devicetree/bindings/gpio/rockchip,gpio-bank.yaml
+++ b/Documentation/devicetree/bindings/gpio/rockchip,gpio-bank.yaml
@@ -27,6 +27,12 @@ properties:
       - description: APB interface clock source
       - description: GPIO debounce reference clock source
 
+  clock-names:
+    minItems: 1
+    items:
+      - const: bus
+      - const: db
+
   gpio-ranges: true
 
   gpio-controller: true
-- 
2.25.1


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

* [PATCH v1 1/3] gpio: rockchip: make gpio work without cru module
  2022-09-01  1:29 [PATCH 0/2] gpio clock-names Jianqun Xu
  2022-09-01  1:29 ` [PATCH 1/2] dt-bindings: gpio: rockchip: add clock-names Jianqun Xu
@ 2022-09-01  1:29 ` Jianqun Xu
  2022-09-02 18:38   ` Peter Geis
  2022-09-01  1:29 ` [PATCH 2/2] arm64: dts: rockchip: rk356x add 'clock-names' for gpio nodes Jianqun Xu
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Jianqun Xu @ 2022-09-01  1:29 UTC (permalink / raw)
  To: linus.walleij, heiko
  Cc: robh+dt, krzysztof.kozlowski+dt, linux-gpio, linux-rockchip,
	Jianqun Xu

In some case the system may has no builtin cru module, the gpio driver
will fail to get periph clock and debounce clock.

On rockchip SoCs, the pclk and dbg clk are default to be enabled and
ungated, the gpio possible to work without cru module.

This patch makes gpio work fine without cru module.

Signed-off-by: Jianqun Xu <jay.xu@rock-chips.com>
---
 drivers/gpio/gpio-rockchip.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c
index a4c4e4584f5b..1da0324445cc 100644
--- a/drivers/gpio/gpio-rockchip.c
+++ b/drivers/gpio/gpio-rockchip.c
@@ -195,6 +195,9 @@ static int rockchip_gpio_set_debounce(struct gpio_chip *gc,
 	unsigned int cur_div_reg;
 	u64 div;
 
+	if (!bank->db_clk)
+		return -ENOENT;
+
 	if (bank->gpio_type == GPIO_TYPE_V2 && !IS_ERR(bank->db_clk)) {
 		div_debounce_support = true;
 		freq = clk_get_rate(bank->db_clk);
@@ -654,8 +657,10 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank)
 		return -EINVAL;
 
 	bank->clk = of_clk_get(bank->of_node, 0);
-	if (IS_ERR(bank->clk))
-		return PTR_ERR(bank->clk);
+	if (IS_ERR(bank->clk)) {
+		bank->clk = NULL;
+		dev_warn(bank->dev, "works without clk pm\n");
+	}
 
 	clk_prepare_enable(bank->clk);
 	id = readl(bank->reg_base + gpio_regs_v2.version_id);
@@ -666,9 +671,8 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank)
 		bank->gpio_type = GPIO_TYPE_V2;
 		bank->db_clk = of_clk_get(bank->of_node, 1);
 		if (IS_ERR(bank->db_clk)) {
-			dev_err(bank->dev, "cannot find debounce clk\n");
-			clk_disable_unprepare(bank->clk);
-			return -EINVAL;
+			bank->db_clk = NULL;
+			dev_warn(bank->dev, "works without debounce clk pm\n");
 		}
 	} else {
 		bank->gpio_regs = &gpio_regs_v1;
-- 
2.25.1


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

* [PATCH 2/2] arm64: dts: rockchip: rk356x add 'clock-names' for gpio nodes
  2022-09-01  1:29 [PATCH 0/2] gpio clock-names Jianqun Xu
  2022-09-01  1:29 ` [PATCH 1/2] dt-bindings: gpio: rockchip: add clock-names Jianqun Xu
  2022-09-01  1:29 ` [PATCH v1 1/3] gpio: rockchip: make gpio work without cru module Jianqun Xu
@ 2022-09-01  1:29 ` Jianqun Xu
  2022-09-01  1:29 ` [PATCH 2/3] gpio: rockchip: get pinctrl node from 'gpio-ranges' property Jianqun Xu
  2022-09-01  1:29 ` [PATCH 3/3] dt-bindings: gpio: rockchip,gpio add optional 'gpio-ranges' Jianqun Xu
  4 siblings, 0 replies; 10+ messages in thread
From: Jianqun Xu @ 2022-09-01  1:29 UTC (permalink / raw)
  To: linus.walleij, heiko
  Cc: robh+dt, krzysztof.kozlowski+dt, linux-gpio, linux-rockchip,
	Jianqun Xu

Add 'clock-names' for gpio nodes on rk356x SoCs, after this patch, the
gpio driver can get the clocks by a const char id, 'bus' for apb clock
and 'db' for the debounce clock.

Signed-off-by: Jianqun Xu <jay.xu@rock-chips.com>
---
 arch/arm64/boot/dts/rockchip/rk356x.dtsi | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/arm64/boot/dts/rockchip/rk356x.dtsi b/arch/arm64/boot/dts/rockchip/rk356x.dtsi
index 319981c3e9f7..66d038720e65 100644
--- a/arch/arm64/boot/dts/rockchip/rk356x.dtsi
+++ b/arch/arm64/boot/dts/rockchip/rk356x.dtsi
@@ -1650,6 +1650,7 @@ gpio0: gpio@fdd60000 {
 			compatible = "rockchip,gpio-bank";
 			reg = <0x0 0xfdd60000 0x0 0x100>;
 			interrupts = <GIC_SPI 33 IRQ_TYPE_LEVEL_HIGH>;
+			clock-names = "bus", "db";
 			clocks = <&pmucru PCLK_GPIO0>, <&pmucru DBCLK_GPIO0>;
 			gpio-controller;
 			#gpio-cells = <2>;
@@ -1661,6 +1662,7 @@ gpio1: gpio@fe740000 {
 			compatible = "rockchip,gpio-bank";
 			reg = <0x0 0xfe740000 0x0 0x100>;
 			interrupts = <GIC_SPI 34 IRQ_TYPE_LEVEL_HIGH>;
+			clock-names = "bus", "db";
 			clocks = <&cru PCLK_GPIO1>, <&cru DBCLK_GPIO1>;
 			gpio-controller;
 			#gpio-cells = <2>;
@@ -1672,6 +1674,7 @@ gpio2: gpio@fe750000 {
 			compatible = "rockchip,gpio-bank";
 			reg = <0x0 0xfe750000 0x0 0x100>;
 			interrupts = <GIC_SPI 35 IRQ_TYPE_LEVEL_HIGH>;
+			clock-names = "bus", "db";
 			clocks = <&cru PCLK_GPIO2>, <&cru DBCLK_GPIO2>;
 			gpio-controller;
 			#gpio-cells = <2>;
@@ -1683,6 +1686,7 @@ gpio3: gpio@fe760000 {
 			compatible = "rockchip,gpio-bank";
 			reg = <0x0 0xfe760000 0x0 0x100>;
 			interrupts = <GIC_SPI 36 IRQ_TYPE_LEVEL_HIGH>;
+			clock-names = "bus", "db";
 			clocks = <&cru PCLK_GPIO3>, <&cru DBCLK_GPIO3>;
 			gpio-controller;
 			#gpio-cells = <2>;
@@ -1694,6 +1698,7 @@ gpio4: gpio@fe770000 {
 			compatible = "rockchip,gpio-bank";
 			reg = <0x0 0xfe770000 0x0 0x100>;
 			interrupts = <GIC_SPI 37 IRQ_TYPE_LEVEL_HIGH>;
+			clock-names = "bus", "db";
 			clocks = <&cru PCLK_GPIO4>, <&cru DBCLK_GPIO4>;
 			gpio-controller;
 			#gpio-cells = <2>;
-- 
2.25.1


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

* [PATCH 2/3] gpio: rockchip: get pinctrl node from 'gpio-ranges' property
  2022-09-01  1:29 [PATCH 0/2] gpio clock-names Jianqun Xu
                   ` (2 preceding siblings ...)
  2022-09-01  1:29 ` [PATCH 2/2] arm64: dts: rockchip: rk356x add 'clock-names' for gpio nodes Jianqun Xu
@ 2022-09-01  1:29 ` Jianqun Xu
  2022-09-01  1:29 ` [PATCH 3/3] dt-bindings: gpio: rockchip,gpio add optional 'gpio-ranges' Jianqun Xu
  4 siblings, 0 replies; 10+ messages in thread
From: Jianqun Xu @ 2022-09-01  1:29 UTC (permalink / raw)
  To: linus.walleij, heiko
  Cc: robh+dt, krzysztof.kozlowski+dt, linux-gpio, linux-rockchip,
	Jianqun Xu

The dt nodes for rockchip soc designes as

    pinctrl: pinctrl {
        gpio {
	};
    };

Currently, we get the pinctrl dt node from parent of gpio, this patch
try to get pinctrl dt node from 'gpio-ranges' property.

After this patch, the dt nodes possible to be

    gpio {
        gpio-ranges = <&pinctrl xxx>;
    };

    pinctrl: pinctrl {
    };

then the gpio driver could register as platform device itself, but not
populate from pinctrl driver.

Signed-off-by: Jianqun Xu <jay.xu@rock-chips.com>
---
 drivers/gpio/gpio-rockchip.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c
index 1da0324445cc..46c54dff92db 100644
--- a/drivers/gpio/gpio-rockchip.c
+++ b/drivers/gpio/gpio-rockchip.c
@@ -690,6 +690,9 @@ rockchip_gpio_find_bank(struct pinctrl_dev *pctldev, int id)
 	int i, found = 0;
 
 	info = pinctrl_dev_get_drvdata(pctldev);
+	if (!info)
+		return NULL;
+
 	bank = info->ctrl->pin_banks;
 	for (i = 0; i < info->ctrl->nr_banks; i++, bank++) {
 		if (bank->bank_num == id) {
@@ -705,15 +708,16 @@ static int rockchip_gpio_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct device_node *np = dev->of_node;
-	struct device_node *pctlnp = of_get_parent(np);
+	struct device_node *pctlnp = NULL;
 	struct pinctrl_dev *pctldev = NULL;
 	struct rockchip_pin_bank *bank = NULL;
 	struct rockchip_pin_output_deferred *cfg;
 	static int gpio;
 	int id, ret;
 
-	if (!np || !pctlnp)
-		return -ENODEV;
+	pctlnp = of_parse_phandle(np, "gpio-ranges", 0);
+	if (!pctlnp)
+		pctlnp = of_get_parent(np);
 
 	pctldev = of_pinctrl_get(pctlnp);
 	if (!pctldev)
-- 
2.25.1


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

* [PATCH 3/3] dt-bindings: gpio: rockchip,gpio add optional 'gpio-ranges'
  2022-09-01  1:29 [PATCH 0/2] gpio clock-names Jianqun Xu
                   ` (3 preceding siblings ...)
  2022-09-01  1:29 ` [PATCH 2/3] gpio: rockchip: get pinctrl node from 'gpio-ranges' property Jianqun Xu
@ 2022-09-01  1:29 ` Jianqun Xu
  2022-09-01 13:32   ` Krzysztof Kozlowski
  4 siblings, 1 reply; 10+ messages in thread
From: Jianqun Xu @ 2022-09-01  1:29 UTC (permalink / raw)
  To: linus.walleij, heiko
  Cc: robh+dt, krzysztof.kozlowski+dt, linux-gpio, linux-rockchip,
	Jianqun Xu

Add a optional property 'gpio-ranges', such as
    gpio-ranges = <&pinctrl 0 0 32>;

When the gpio nodes are under pinctrl, the property 'gpio-ranges' is
a optional property, but when they are under root node, the property
'gpio-ranges' is a required property.

Signed-off-by: Jianqun Xu <jay.xu@rock-chips.com>
---
 .../devicetree/bindings/gpio/rockchip,gpio-bank.yaml       | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/gpio/rockchip,gpio-bank.yaml b/Documentation/devicetree/bindings/gpio/rockchip,gpio-bank.yaml
index d4e42c2b995b..7a075fcea75f 100644
--- a/Documentation/devicetree/bindings/gpio/rockchip,gpio-bank.yaml
+++ b/Documentation/devicetree/bindings/gpio/rockchip,gpio-bank.yaml
@@ -49,7 +49,12 @@ required:
   - interrupt-controller
   - "#interrupt-cells"
 
-additionalProperties: false
+additionalProperties: true
+  gpio-ranges:
+    maxItems: 1
+    description: |
+      The property is a optional if gpio node under pinctrl node;
+      but it is a required property if the gpio is under root node.
 
 examples:
   - |
-- 
2.25.1


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

* Re: [PATCH 1/2] dt-bindings: gpio: rockchip: add clock-names
  2022-09-01  1:29 ` [PATCH 1/2] dt-bindings: gpio: rockchip: add clock-names Jianqun Xu
@ 2022-09-01 11:48   ` Rob Herring
  0 siblings, 0 replies; 10+ messages in thread
From: Rob Herring @ 2022-09-01 11:48 UTC (permalink / raw)
  To: Jianqun Xu
  Cc: Linus Walleij, heiko@sntech.de, Krzysztof Kozlowski,
	open list:GPIO SUBSYSTEM, open list:ARM/Rockchip SoC...

On Wed, Aug 31, 2022 at 8:36 PM Jianqun Xu <jay.xu@rock-chips.com> wrote:
>
> Add 'clock-names' to the gpio dt node. so the driver could get clocks by
> a const char id, this patch names the clock-names as
>   - 'bus': the apb clock for cpu to access the gpio controller
>   - 'db': the debounce clock for cpu to set debounce clock rate
>
> Since the old dt nodes may have no clock-names, this patch not make them
> as part of 'required properties'.
>
> Signed-off-by: Jianqun Xu <jay.xu@rock-chips.com>
> ---
>  .../devicetree/bindings/gpio/rockchip,gpio-bank.yaml        | 6 ++++++
>  1 file changed, 6 insertions(+)

Please resend DT patches to the DT list, so they are tested and reviewed.

Rob

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

* Re: [PATCH 3/3] dt-bindings: gpio: rockchip,gpio add optional 'gpio-ranges'
  2022-09-01  1:29 ` [PATCH 3/3] dt-bindings: gpio: rockchip,gpio add optional 'gpio-ranges' Jianqun Xu
@ 2022-09-01 13:32   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 10+ messages in thread
From: Krzysztof Kozlowski @ 2022-09-01 13:32 UTC (permalink / raw)
  To: Jianqun Xu, linus.walleij, heiko
  Cc: robh+dt, krzysztof.kozlowski+dt, linux-gpio, linux-rockchip

On 01/09/2022 04:29, Jianqun Xu wrote:
> Add a optional property 'gpio-ranges', such as
>     gpio-ranges = <&pinctrl 0 0 32>;
> 
> When the gpio nodes are under pinctrl, the property 'gpio-ranges' is
> a optional property, but when they are under root node, the property
> 'gpio-ranges' is a required property.
> 
> Signed-off-by: Jianqun Xu <jay.xu@rock-chips.com>
> ---
>  .../devicetree/bindings/gpio/rockchip,gpio-bank.yaml       | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/devicetree/bindings/gpio/rockchip,gpio-bank.yaml b/Documentation/devicetree/bindings/gpio/rockchip,gpio-bank.yaml
> index d4e42c2b995b..7a075fcea75f 100644
> --- a/Documentation/devicetree/bindings/gpio/rockchip,gpio-bank.yaml
> +++ b/Documentation/devicetree/bindings/gpio/rockchip,gpio-bank.yaml
> @@ -49,7 +49,12 @@ required:
>    - interrupt-controller
>    - "#interrupt-cells"
>  
> -additionalProperties: false
> +additionalProperties: true

That's not correct. It should stay false.

> +  gpio-ranges:
> +    maxItems: 1
> +    description: |
> +      The property is a optional if gpio node under pinctrl node;
> +      but it is a required property if the gpio is under root node.

This is not in proper place.

Does not look like you tested the bindings. Please run `make
dt_binding_check` (see
Documentation/devicetree/bindings/writing-schema.rst for instructions).

Best regards,
Krzysztof

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

* Re: [PATCH v1 1/3] gpio: rockchip: make gpio work without cru module
  2022-09-01  1:29 ` [PATCH v1 1/3] gpio: rockchip: make gpio work without cru module Jianqun Xu
@ 2022-09-02 18:38   ` Peter Geis
  2022-09-02 21:09     ` Heiko Stübner
  0 siblings, 1 reply; 10+ messages in thread
From: Peter Geis @ 2022-09-02 18:38 UTC (permalink / raw)
  To: Jianqun Xu
  Cc: Linus Walleij, Heiko Stuebner, Rob Herring, Krzysztof Kozlowski,
	open list:GPIO SUBSYSTEM, open list:ARM/Rockchip SoC...

On Wed, Aug 31, 2022 at 9:30 PM Jianqun Xu <jay.xu@rock-chips.com> wrote:
>
> In some case the system may has no builtin cru module, the gpio driver
> will fail to get periph clock and debounce clock.
>
> On rockchip SoCs, the pclk and dbg clk are default to be enabled and
> ungated, the gpio possible to work without cru module.
>
> This patch makes gpio work fine without cru module.

What happens if the cru probes later and these clocks become available
but aren't claimed so clk_disable_unused shuts them down?

>
> Signed-off-by: Jianqun Xu <jay.xu@rock-chips.com>
> ---
>  drivers/gpio/gpio-rockchip.c | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c
> index a4c4e4584f5b..1da0324445cc 100644
> --- a/drivers/gpio/gpio-rockchip.c
> +++ b/drivers/gpio/gpio-rockchip.c
> @@ -195,6 +195,9 @@ static int rockchip_gpio_set_debounce(struct gpio_chip *gc,
>         unsigned int cur_div_reg;
>         u64 div;
>
> +       if (!bank->db_clk)
> +               return -ENOENT;
> +
>         if (bank->gpio_type == GPIO_TYPE_V2 && !IS_ERR(bank->db_clk)) {
>                 div_debounce_support = true;
>                 freq = clk_get_rate(bank->db_clk);
> @@ -654,8 +657,10 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank)
>                 return -EINVAL;
>
>         bank->clk = of_clk_get(bank->of_node, 0);
> -       if (IS_ERR(bank->clk))
> -               return PTR_ERR(bank->clk);
> +       if (IS_ERR(bank->clk)) {
> +               bank->clk = NULL;
> +               dev_warn(bank->dev, "works without clk pm\n");
> +       }
>
>         clk_prepare_enable(bank->clk);
>         id = readl(bank->reg_base + gpio_regs_v2.version_id);
> @@ -666,9 +671,8 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank)
>                 bank->gpio_type = GPIO_TYPE_V2;
>                 bank->db_clk = of_clk_get(bank->of_node, 1);
>                 if (IS_ERR(bank->db_clk)) {
> -                       dev_err(bank->dev, "cannot find debounce clk\n");
> -                       clk_disable_unprepare(bank->clk);
> -                       return -EINVAL;
> +                       bank->db_clk = NULL;
> +                       dev_warn(bank->dev, "works without debounce clk pm\n");
>                 }
>         } else {
>                 bank->gpio_regs = &gpio_regs_v1;
> --
> 2.25.1
>
>
> _______________________________________________
> Linux-rockchip mailing list
> Linux-rockchip@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-rockchip

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

* Re: [PATCH v1 1/3] gpio: rockchip: make gpio work without cru module
  2022-09-02 18:38   ` Peter Geis
@ 2022-09-02 21:09     ` Heiko Stübner
  0 siblings, 0 replies; 10+ messages in thread
From: Heiko Stübner @ 2022-09-02 21:09 UTC (permalink / raw)
  To: Jianqun Xu, Peter Geis
  Cc: Linus Walleij, Rob Herring, Krzysztof Kozlowski,
	open list:GPIO SUBSYSTEM, open list:ARM/Rockchip SoC...

Am Freitag, 2. September 2022, 20:38:27 CEST schrieb Peter Geis:
> On Wed, Aug 31, 2022 at 9:30 PM Jianqun Xu <jay.xu@rock-chips.com> wrote:
> >
> > In some case the system may has no builtin cru module, the gpio driver
> > will fail to get periph clock and debounce clock.
> >
> > On rockchip SoCs, the pclk and dbg clk are default to be enabled and
> > ungated, the gpio possible to work without cru module.
> >
> > This patch makes gpio work fine without cru module.
> 
> What happens if the cru probes later and these clocks become available
> but aren't claimed so clk_disable_unused shuts them down?

Also the clock controller for the soc is such a basic component, who
in their right mind would build a kernel without it and expect anything
to work.

My guess is that is simply hacking around that Android thingy with their
common kernel but vendors being allowed to move all the "special" code
to modules. We had this untested cru-module in mainline for a while
before people found out that the module part seemingly never was
tested ;-) .

The gpio driver is of course dependent on its clock supply, so hacking
around that seems really like a very bad idea.


Heiko



> 
> >
> > Signed-off-by: Jianqun Xu <jay.xu@rock-chips.com>
> > ---
> >  drivers/gpio/gpio-rockchip.c | 14 +++++++++-----
> >  1 file changed, 9 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c
> > index a4c4e4584f5b..1da0324445cc 100644
> > --- a/drivers/gpio/gpio-rockchip.c
> > +++ b/drivers/gpio/gpio-rockchip.c
> > @@ -195,6 +195,9 @@ static int rockchip_gpio_set_debounce(struct gpio_chip *gc,
> >         unsigned int cur_div_reg;
> >         u64 div;
> >
> > +       if (!bank->db_clk)
> > +               return -ENOENT;
> > +
> >         if (bank->gpio_type == GPIO_TYPE_V2 && !IS_ERR(bank->db_clk)) {
> >                 div_debounce_support = true;
> >                 freq = clk_get_rate(bank->db_clk);
> > @@ -654,8 +657,10 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank)
> >                 return -EINVAL;
> >
> >         bank->clk = of_clk_get(bank->of_node, 0);
> > -       if (IS_ERR(bank->clk))
> > -               return PTR_ERR(bank->clk);
> > +       if (IS_ERR(bank->clk)) {
> > +               bank->clk = NULL;
> > +               dev_warn(bank->dev, "works without clk pm\n");
> > +       }
> >
> >         clk_prepare_enable(bank->clk);
> >         id = readl(bank->reg_base + gpio_regs_v2.version_id);
> > @@ -666,9 +671,8 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank)
> >                 bank->gpio_type = GPIO_TYPE_V2;
> >                 bank->db_clk = of_clk_get(bank->of_node, 1);
> >                 if (IS_ERR(bank->db_clk)) {
> > -                       dev_err(bank->dev, "cannot find debounce clk\n");
> > -                       clk_disable_unprepare(bank->clk);
> > -                       return -EINVAL;
> > +                       bank->db_clk = NULL;
> > +                       dev_warn(bank->dev, "works without debounce clk pm\n");
> >                 }
> >         } else {
> >                 bank->gpio_regs = &gpio_regs_v1;
> > --
> > 2.25.1
> >
> >
> > _______________________________________________
> > Linux-rockchip mailing list
> > Linux-rockchip@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/linux-rockchip
> 





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

end of thread, other threads:[~2022-09-02 21:10 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-01  1:29 [PATCH 0/2] gpio clock-names Jianqun Xu
2022-09-01  1:29 ` [PATCH 1/2] dt-bindings: gpio: rockchip: add clock-names Jianqun Xu
2022-09-01 11:48   ` Rob Herring
2022-09-01  1:29 ` [PATCH v1 1/3] gpio: rockchip: make gpio work without cru module Jianqun Xu
2022-09-02 18:38   ` Peter Geis
2022-09-02 21:09     ` Heiko Stübner
2022-09-01  1:29 ` [PATCH 2/2] arm64: dts: rockchip: rk356x add 'clock-names' for gpio nodes Jianqun Xu
2022-09-01  1:29 ` [PATCH 2/3] gpio: rockchip: get pinctrl node from 'gpio-ranges' property Jianqun Xu
2022-09-01  1:29 ` [PATCH 3/3] dt-bindings: gpio: rockchip,gpio add optional 'gpio-ranges' Jianqun Xu
2022-09-01 13:32   ` Krzysztof Kozlowski

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