2021-11-09 22:20:34

by Prabhakar Mahadev Lad

[permalink] [raw]
Subject: [PATCH v2 0/3] RZ/G2L SCI support and sh-sci driver update

Hi All,

This patch series updates binding doc to support RZ/G2L and
adds support to perform deassert/assert in sh-sci driver.

Cheers,
Prabhakar

v2:
* Fixed review comments pointed by Geert.

v1: https://patchwork.kernel.org/project/linux-renesas-soc/cover/
[email protected]/

Lad Prabhakar (3):
dt-bindings: serial: renesas,scif: Make resets as a required property
dt-bindings: serial: renesas,sci: Document RZ/G2L SoC
serial: sh-sci: Add support to deassert/assert reset line

.../bindings/serial/renesas,sci.yaml | 44 ++++++++++++++---
.../bindings/serial/renesas,scif.yaml | 1 +
drivers/tty/serial/sh-sci.c | 47 +++++++++++++++----
3 files changed, 78 insertions(+), 14 deletions(-)

--
2.17.1


2021-11-09 22:20:35

by Prabhakar Mahadev Lad

[permalink] [raw]
Subject: [PATCH v2 1/3] dt-bindings: serial: renesas,scif: Make resets as a required property

Make "resets" as required property for RZ/G2L. On RZ/G2L the devices
should be explicitly pulled out of reset for this reason make "resets"
as required property.

Signed-off-by: Lad Prabhakar <[email protected]>
Reviewed-by: Biju Das <[email protected]>
Reviewed-by: Geert Uytterhoeven <[email protected]>
---
v1->v2
* Added the string in alphabetical sort order
* Included RB tag from Geert
---
Documentation/devicetree/bindings/serial/renesas,scif.yaml | 1 +
1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/serial/renesas,scif.yaml b/Documentation/devicetree/bindings/serial/renesas,scif.yaml
index 6b8731f7f2fb..21fbfa880e29 100644
--- a/Documentation/devicetree/bindings/serial/renesas,scif.yaml
+++ b/Documentation/devicetree/bindings/serial/renesas,scif.yaml
@@ -153,6 +153,7 @@ if:
enum:
- renesas,rcar-gen2-scif
- renesas,rcar-gen3-scif
+ - renesas,scif-r9a07g044
then:
required:
- resets
--
2.17.1

2021-11-09 22:20:46

by Prabhakar Mahadev Lad

[permalink] [raw]
Subject: [PATCH v2 2/3] dt-bindings: serial: renesas,sci: Document RZ/G2L SoC

Add SCI binding documentation for Renesas RZ/G2L SoC.

Also update the example node with RZ/G2L SCI0 node.

Signed-off-by: Lad Prabhakar <[email protected]>
Reviewed-by: Biju Das <[email protected]>
Reviewed-by: Geert Uytterhoeven <[email protected]>
---
v1->v2
* Added const "renesas,sci" entry in compatible property for h8300
* Included RB tag from Geert
---
.../bindings/serial/renesas,sci.yaml | 44 ++++++++++++++++---
1 file changed, 38 insertions(+), 6 deletions(-)

diff --git a/Documentation/devicetree/bindings/serial/renesas,sci.yaml b/Documentation/devicetree/bindings/serial/renesas,sci.yaml
index 22ed2f0b1dc3..141d3b368f10 100644
--- a/Documentation/devicetree/bindings/serial/renesas,sci.yaml
+++ b/Documentation/devicetree/bindings/serial/renesas,sci.yaml
@@ -14,7 +14,12 @@ allOf:

properties:
compatible:
- const: renesas,sci
+ oneOf:
+ - items:
+ - enum:
+ - renesas,r9a07g044-sci # RZ/G2{L,LC}
+ - const: renesas,sci # generic SCI compatible UART
+ - const: renesas,sci # generic SCI compatible UART

reg:
maxItems: 1
@@ -54,18 +59,45 @@ required:
- clocks
- clock-names

+if:
+ properties:
+ compatible:
+ contains:
+ enum:
+ - renesas,r9a07g044-sci
+then:
+ properties:
+ resets:
+ maxItems: 1
+
+ power-domains:
+ maxItems: 1
+
+ required:
+ - resets
+ - power-domains
+
unevaluatedProperties: false

examples:
- |
+ #include <dt-bindings/clock/r9a07g044-cpg.h>
+ #include <dt-bindings/interrupt-controller/arm-gic.h>
+
aliases {
serial0 = &sci0;
};

- sci0: serial@ffff78 {
- compatible = "renesas,sci";
- reg = <0xffff78 8>;
- interrupts = <88 0>, <89 0>, <90 0>, <91 0>;
- clocks = <&fclk>;
+ sci0: serial@1004d000 {
+ compatible = "renesas,r9a07g044-sci", "renesas,sci";
+ reg = <0x1004d000 0x400>;
+ interrupts = <GIC_SPI 405 IRQ_TYPE_LEVEL_HIGH>,
+ <GIC_SPI 406 IRQ_TYPE_LEVEL_HIGH>,
+ <GIC_SPI 407 IRQ_TYPE_LEVEL_HIGH>,
+ <GIC_SPI 408 IRQ_TYPE_LEVEL_HIGH>;
+ interrupt-names = "eri", "rxi", "txi", "tei";
+ clocks = <&cpg CPG_MOD R9A07G044_SCI0_CLKP>;
clock-names = "fck";
+ power-domains = <&cpg>;
+ resets = <&cpg R9A07G044_SCI0_RST>;
};
--
2.17.1

2021-11-09 23:37:35

by Prabhakar Mahadev Lad

[permalink] [raw]
Subject: [PATCH v2 3/3] serial: sh-sci: Add support to deassert/assert reset line

On RZ/G2L SoC we need to explicitly deassert the reset line
for the device to work, use this opportunity to deassert/assert
reset line in sh-sci driver.

This patch adds support to read the "resets" property (if available)
from DT and perform deassert/assert when required.

Also, propagate the error to the caller of sci_parse_dt() instead of
returning NULL in case of failure.

Signed-off-by: Lad Prabhakar <[email protected]>
Reviewed-by: Biju Das <[email protected]>
---
v1->v2
* deassert/assert reset line if available on all SoC's
* Updated commit message
---
drivers/tty/serial/sh-sci.c | 47 ++++++++++++++++++++++++++++++-------
1 file changed, 39 insertions(+), 8 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 89ee43061d3a..7aced84d2f04 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -37,6 +37,7 @@
#include <linux/of_device.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
+#include <linux/reset.h>
#include <linux/scatterlist.h>
#include <linux/serial.h>
#include <linux/serial_sci.h>
@@ -3203,23 +3204,53 @@ static const struct of_device_id of_sci_match[] = {
};
MODULE_DEVICE_TABLE(of, of_sci_match);

+static void sci_reset_control_assert(void *data)
+{
+ reset_control_assert(data);
+}
+
static struct plat_sci_port *sci_parse_dt(struct platform_device *pdev,
unsigned int *dev_id)
{
struct device_node *np = pdev->dev.of_node;
+ const struct of_device_id *of_id;
+ struct reset_control *rstc;
struct plat_sci_port *p;
struct sci_port *sp;
const void *data;
- int id;
+ int id, ret;

if (!IS_ENABLED(CONFIG_OF) || !np)
- return NULL;
+ return ERR_PTR(-EINVAL);
+
+ of_id = of_match_device(of_sci_match, &pdev->dev);
+ if (!of_id)
+ return ERR_PTR(-EINVAL);

- data = of_device_get_match_data(&pdev->dev);
+ rstc = devm_reset_control_get_optional_exclusive(&pdev->dev, NULL);
+ if (IS_ERR(rstc)) {
+ dev_err(&pdev->dev, "failed to get reset ctrl %ld\n", PTR_ERR(rstc));
+ return ERR_PTR(PTR_ERR(rstc));
+ }
+
+ ret = reset_control_deassert(rstc);
+ if (ret) {
+ dev_err(&pdev->dev, "failed to deassert reset %d\n", ret);
+ return ERR_PTR(ret);
+ }
+
+ ret = devm_add_action_or_reset(&pdev->dev, sci_reset_control_assert, rstc);
+ if (ret) {
+ dev_err(&pdev->dev, "failed to register assert devm action, %d\n",
+ ret);
+ return ERR_PTR(ret);
+ }
+
+ data = of_id->data;

p = devm_kzalloc(&pdev->dev, sizeof(struct plat_sci_port), GFP_KERNEL);
if (!p)
- return NULL;
+ return ERR_PTR(-ENOMEM);

/* Get the line number from the aliases node. */
id = of_alias_get_id(np, "serial");
@@ -3227,11 +3258,11 @@ static struct plat_sci_port *sci_parse_dt(struct platform_device *pdev,
id = ffz(sci_ports_in_use);
if (id < 0) {
dev_err(&pdev->dev, "failed to get alias id (%d)\n", id);
- return NULL;
+ return ERR_PTR(-EINVAL);
}
if (id >= ARRAY_SIZE(sci_ports)) {
dev_err(&pdev->dev, "serial%d out of range\n", id);
- return NULL;
+ return ERR_PTR(-EINVAL);
}

sp = &sci_ports[id];
@@ -3318,8 +3349,8 @@ static int sci_probe(struct platform_device *dev)

if (dev->dev.of_node) {
p = sci_parse_dt(dev, &dev_id);
- if (p == NULL)
- return -EINVAL;
+ if (IS_ERR(p))
+ return PTR_ERR(p);
} else {
p = dev->dev.platform_data;
if (p == NULL) {
--
2.17.1

2021-11-09 23:49:21

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH v2 3/3] serial: sh-sci: Add support to deassert/assert reset line

Hi Prabhakar,

On Tue, Nov 9, 2021 at 1:17 PM Lad Prabhakar
<[email protected]> wrote:
> On RZ/G2L SoC we need to explicitly deassert the reset line
> for the device to work, use this opportunity to deassert/assert
> reset line in sh-sci driver.
>
> This patch adds support to read the "resets" property (if available)
> from DT and perform deassert/assert when required.
>
> Also, propagate the error to the caller of sci_parse_dt() instead of
> returning NULL in case of failure.
>
> Signed-off-by: Lad Prabhakar <[email protected]>
> Reviewed-by: Biju Das <[email protected]>
> ---
> v1->v2
> * deassert/assert reset line if available on all SoC's
> * Updated commit message

Thanks for the update!

> --- a/drivers/tty/serial/sh-sci.c
> +++ b/drivers/tty/serial/sh-sci.c
> @@ -37,6 +37,7 @@
> #include <linux/of_device.h>
> #include <linux/platform_device.h>
> #include <linux/pm_runtime.h>
> +#include <linux/reset.h>
> #include <linux/scatterlist.h>
> #include <linux/serial.h>
> #include <linux/serial_sci.h>
> @@ -3203,23 +3204,53 @@ static const struct of_device_id of_sci_match[] = {
> };
> MODULE_DEVICE_TABLE(of, of_sci_match);
>
> +static void sci_reset_control_assert(void *data)
> +{
> + reset_control_assert(data);
> +}
> +
> static struct plat_sci_port *sci_parse_dt(struct platform_device *pdev,
> unsigned int *dev_id)
> {
> struct device_node *np = pdev->dev.of_node;
> + const struct of_device_id *of_id;

Not needed.

> + struct reset_control *rstc;
> struct plat_sci_port *p;
> struct sci_port *sp;
> const void *data;
> - int id;
> + int id, ret;
>
> if (!IS_ENABLED(CONFIG_OF) || !np)
> - return NULL;
> + return ERR_PTR(-EINVAL);
> +
> + of_id = of_match_device(of_sci_match, &pdev->dev);
> + if (!of_id)
> + return ERR_PTR(-EINVAL);
>
> - data = of_device_get_match_data(&pdev->dev);

Please keep the old construct using of_device_get_match_data().

> + rstc = devm_reset_control_get_optional_exclusive(&pdev->dev, NULL);
> + if (IS_ERR(rstc)) {
> + dev_err(&pdev->dev, "failed to get reset ctrl %ld\n", PTR_ERR(rstc));
> + return ERR_PTR(PTR_ERR(rstc));

The error might be -EPROBE_DEFER, so please use
"return ERR_PTR(dev_err_probe(...))", to avoid printing the message
in case of probe deferral.

BTW, ERR_CAST() is a shorthand for ERR_PTR(PTR_ERR()).

> + }
> +
> + ret = reset_control_deassert(rstc);
> + if (ret) {
> + dev_err(&pdev->dev, "failed to deassert reset %d\n", ret);
> + return ERR_PTR(ret);
> + }
> +
> + ret = devm_add_action_or_reset(&pdev->dev, sci_reset_control_assert, rstc);
> + if (ret) {
> + dev_err(&pdev->dev, "failed to register assert devm action, %d\n",
> + ret);
> + return ERR_PTR(ret);
> + }
> +
> + data = of_id->data;
>
> p = devm_kzalloc(&pdev->dev, sizeof(struct plat_sci_port), GFP_KERNEL);
> if (!p)
> - return NULL;
> + return ERR_PTR(-ENOMEM);
>
> /* Get the line number from the aliases node. */
> id = of_alias_get_id(np, "serial");

I gave this a try on Salvator-XS, and noticed no regressions.
I will test this on more SCIF variants later.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

2021-11-10 01:18:47

by Philipp Zabel

[permalink] [raw]
Subject: Re: [PATCH v2 3/3] serial: sh-sci: Add support to deassert/assert reset line

On Tue, 2021-11-09 at 12:16 +0000, Lad Prabhakar wrote:
> On RZ/G2L SoC we need to explicitly deassert the reset line
> for the device to work, use this opportunity to deassert/assert
> reset line in sh-sci driver.
>
> This patch adds support to read the "resets" property (if available)
> from DT and perform deassert/assert when required.
>
> Also, propagate the error to the caller of sci_parse_dt() instead of
> returning NULL in case of failure.
>
> Signed-off-by: Lad Prabhakar <[email protected]>
> Reviewed-by: Biju Das <[email protected]>

Reviewed-by: Philipp Zabel <[email protected]>

regards
Philipp

2021-11-10 01:19:26

by Lad, Prabhakar

[permalink] [raw]
Subject: Re: [PATCH v2 3/3] serial: sh-sci: Add support to deassert/assert reset line

Hi Geert,

Thank you for the review.

On Tue, Nov 9, 2021 at 12:58 PM Geert Uytterhoeven <[email protected]> wrote:
>
> Hi Prabhakar,
>
> On Tue, Nov 9, 2021 at 1:17 PM Lad Prabhakar
> <[email protected]> wrote:
> > On RZ/G2L SoC we need to explicitly deassert the reset line
> > for the device to work, use this opportunity to deassert/assert
> > reset line in sh-sci driver.
> >
> > This patch adds support to read the "resets" property (if available)
> > from DT and perform deassert/assert when required.
> >
> > Also, propagate the error to the caller of sci_parse_dt() instead of
> > returning NULL in case of failure.
> >
> > Signed-off-by: Lad Prabhakar <[email protected]>
> > Reviewed-by: Biju Das <[email protected]>
> > ---
> > v1->v2
> > * deassert/assert reset line if available on all SoC's
> > * Updated commit message
>
> Thanks for the update!
>
> > --- a/drivers/tty/serial/sh-sci.c
> > +++ b/drivers/tty/serial/sh-sci.c
> > @@ -37,6 +37,7 @@
> > #include <linux/of_device.h>
> > #include <linux/platform_device.h>
> > #include <linux/pm_runtime.h>
> > +#include <linux/reset.h>
> > #include <linux/scatterlist.h>
> > #include <linux/serial.h>
> > #include <linux/serial_sci.h>
> > @@ -3203,23 +3204,53 @@ static const struct of_device_id of_sci_match[] = {
> > };
> > MODULE_DEVICE_TABLE(of, of_sci_match);
> >
> > +static void sci_reset_control_assert(void *data)
> > +{
> > + reset_control_assert(data);
> > +}
> > +
> > static struct plat_sci_port *sci_parse_dt(struct platform_device *pdev,
> > unsigned int *dev_id)
> > {
> > struct device_node *np = pdev->dev.of_node;
> > + const struct of_device_id *of_id;
>
> Not needed.
>
Agreed.

> > + struct reset_control *rstc;
> > struct plat_sci_port *p;
> > struct sci_port *sp;
> > const void *data;
> > - int id;
> > + int id, ret;
> >
> > if (!IS_ENABLED(CONFIG_OF) || !np)
> > - return NULL;
> > + return ERR_PTR(-EINVAL);
> > +
> > + of_id = of_match_device(of_sci_match, &pdev->dev);
> > + if (!of_id)
> > + return ERR_PTR(-EINVAL);
> >
> > - data = of_device_get_match_data(&pdev->dev);
>
> Please keep the old construct using of_device_get_match_data().
>
OK.

> > + rstc = devm_reset_control_get_optional_exclusive(&pdev->dev, NULL);
> > + if (IS_ERR(rstc)) {
> > + dev_err(&pdev->dev, "failed to get reset ctrl %ld\n", PTR_ERR(rstc));
> > + return ERR_PTR(PTR_ERR(rstc));
>
> The error might be -EPROBE_DEFER, so please use
> "return ERR_PTR(dev_err_probe(...))", to avoid printing the message
> in case of probe deferral.
>
Agreed, will use dev_err_probe().

> BTW, ERR_CAST() is a shorthand for ERR_PTR(PTR_ERR()).
>
Thanks for the pointer.

> > + }
> > +
> > + ret = reset_control_deassert(rstc);
> > + if (ret) {
> > + dev_err(&pdev->dev, "failed to deassert reset %d\n", ret);
> > + return ERR_PTR(ret);
> > + }
> > +
> > + ret = devm_add_action_or_reset(&pdev->dev, sci_reset_control_assert, rstc);
> > + if (ret) {
> > + dev_err(&pdev->dev, "failed to register assert devm action, %d\n",
> > + ret);
> > + return ERR_PTR(ret);
> > + }
> > +
> > + data = of_id->data;
> >
> > p = devm_kzalloc(&pdev->dev, sizeof(struct plat_sci_port), GFP_KERNEL);
> > if (!p)
> > - return NULL;
> > + return ERR_PTR(-ENOMEM);
> >
> > /* Get the line number from the aliases node. */
> > id = of_alias_get_id(np, "serial");
>
> I gave this a try on Salvator-XS, and noticed no regressions.
> I will test this on more SCIF variants later.
>
Thanks, I will re-spin a v3 just for this lone patch. I hope that's OK.

Cheers,
Prabhakar

> Gr{oetje,eeting}s,
>
> Geert
>
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
>
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
> -- Linus Torvalds