mbox series

[v3,0/3] Renesas RZ/G2L CANFD support

Message ID 20210721194951.30983-1-prabhakar.mahadev-lad.rj@bp.renesas.com
Headers show
Series Renesas RZ/G2L CANFD support | expand

Message

Lad Prabhakar July 21, 2021, 7:49 p.m. UTC
Hi All,

This patch series adds CANFD support to Renesas RZ/G2L family.

CANFD block on RZ/G2L SoC is almost identical to one found on
R-Car Gen3 SoC's. On RZ/G2L SoC interrupt sources for each channel
are split into individual sources.

Cheers,
Prabhakar

Changes for v3:
* Dropped core clock addition patches from this series (its queued
  up already in renesas-clk-for-v5.15)
* Added reset-names in binding doc as suggested by Philipp
* Updated interrupt names in binding doc as suggested by Geert
* Updated the driver to handle the above DT binding changes

Changes for v2:
* Added interrupt-names property and marked it as required for
  RZ/G2L family
* Added descriptions for reset property
* Re-used irq handlers on RZ/G2L SoC
* Added new enum for chip_id
* Dropped R9A07G044_LAST_CORE_CLK
* Dropped patch (clk: renesas: r9a07g044-cpg: Add clock and reset
  entries for CANFD) as its been merged into renesas tree

Lad Prabhakar (3):
  dt-bindings: net: can: renesas,rcar-canfd: Document RZ/G2L SoC
  can: rcar_canfd: Add support for RZ/G2L family
  arm64: dts: renesas: r9a07g044: Add CANFD node

 .../bindings/net/can/renesas,rcar-canfd.yaml  |  69 ++++++-
 arch/arm64/boot/dts/renesas/r9a07g044.dtsi    |  41 +++++
 drivers/net/can/rcar/rcar_canfd.c             | 173 +++++++++++++++---
 3 files changed, 253 insertions(+), 30 deletions(-)

Comments

Geert Uytterhoeven July 26, 2021, 9:53 a.m. UTC | #1
Hi Prabhakar,

On Wed, Jul 21, 2021 at 9:50 PM Lad Prabhakar
<prabhakar.mahadev-lad.rj@bp.renesas.com> wrote:
> CANFD block on RZ/G2L SoC is almost identical to one found on
> R-Car Gen3 SoC's. On RZ/G2L SoC interrupt sources for each channel
> are split into different sources and the IP doesn't divide (1/2)
> CANFD clock within the IP.
>
> This patch adds compatible string for RZ/G2L family and registers
> the irq handlers required for CANFD operation. IRQ numbers are now
> fetched based on names instead of indices. For backward compatibility
> on non RZ/G2L SoC's we fallback reading based on indices.
>
> Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>

Thanks for the update!

I think you misunderstood my comment on v1 about the interrupt
handlers, cfr. below.

> --- a/drivers/net/can/rcar/rcar_canfd.c
> +++ b/drivers/net/can/rcar/rcar_canfd.c

> @@ -1577,6 +1586,53 @@ static int rcar_canfd_channel_probe(struct rcar_canfd_global *gpriv, u32 ch,
>         priv->can.clock.freq = fcan_freq;
>         dev_info(&pdev->dev, "can_clk rate is %u\n", priv->can.clock.freq);
>
> +       if (gpriv->chip_id == RENESAS_RZG2L) {
> +               char *irq_name;
> +               int err_irq;
> +               int tx_irq;
> +
> +               err_irq = platform_get_irq_byname(pdev, ch == 0 ? "ch0_err" : "ch1_err");
> +               if (err_irq < 0) {
> +                       err = err_irq;
> +                       goto fail;
> +               }
> +
> +               tx_irq = platform_get_irq_byname(pdev, ch == 0 ? "ch0_trx" : "ch1_trx");
> +               if (tx_irq < 0) {
> +                       err = tx_irq;
> +                       goto fail;
> +               }
> +
> +               irq_name = devm_kasprintf(&pdev->dev, GFP_KERNEL,
> +                                         "canfd.ch%d_err", ch);
> +               if (!irq_name) {
> +                       err = -ENOMEM;
> +                       goto fail;
> +               }
> +               err = devm_request_irq(&pdev->dev, err_irq,
> +                                      rcar_canfd_channel_interrupt, 0,

This is the same interrupt handler...

> +                                      irq_name, gpriv);
> +               if (err) {
> +                       dev_err(&pdev->dev, "devm_request_irq CH Err(%d) failed, error %d\n",
> +                               err_irq, err);
> +                       goto fail;
> +               }
> +               irq_name = devm_kasprintf(&pdev->dev, GFP_KERNEL,
> +                                         "canfd.ch%d_trx", ch);
> +               if (!irq_name) {
> +                       err = -ENOMEM;
> +                       goto fail;
> +               }
> +               err = devm_request_irq(&pdev->dev, tx_irq,
> +                                      rcar_canfd_channel_interrupt, 0,

... as this one.

> +                                      irq_name, gpriv);
> +               if (err) {
> +                       dev_err(&pdev->dev, "devm_request_irq Tx (%d) failed, error %d\n",
> +                               tx_irq, err);
> +                       goto fail;
> +               }
> +       }
> +
>         if (gpriv->fdmode) {
>                 priv->can.bittiming_const = &rcar_canfd_nom_bittiming_const;
>                 priv->can.data_bittiming_const =

> @@ -1711,20 +1798,51 @@ static int rcar_canfd_probe(struct platform_device *pdev)
>         gpriv->base = addr;
>
>         /* Request IRQ that's common for both channels */
> -       err = devm_request_irq(&pdev->dev, ch_irq,
> -                              rcar_canfd_channel_interrupt, 0,
> -                              "canfd.chn", gpriv);
> -       if (err) {
> -               dev_err(&pdev->dev, "devm_request_irq(%d) failed, error %d\n",
> -                       ch_irq, err);
> -               goto fail_dev;
> +       if (gpriv->chip_id == RENESAS_RCAR_GEN3) {
> +               err = devm_request_irq(&pdev->dev, ch_irq,
> +                                      rcar_canfd_channel_interrupt, 0,
> +                                      "canfd.ch_int", gpriv);
> +               if (err) {
> +                       dev_err(&pdev->dev, "devm_request_irq(%d) failed, error %d\n",
> +                               ch_irq, err);
> +                       goto fail_dev;
> +               }
> +
> +               err = devm_request_irq(&pdev->dev, g_irq,
> +                                      rcar_canfd_global_interrupt, 0,
> +                                      "canfd.g_int", gpriv);
> +               if (err) {
> +                       dev_err(&pdev->dev, "devm_request_irq(%d) failed, error %d\n",
> +                               g_irq, err);
> +                       goto fail_dev;
> +               }
> +       } else {
> +               err = devm_request_irq(&pdev->dev, g_recc_irq,
> +                                      rcar_canfd_global_interrupt, 0,

This is the same interrupt handler...

> +                                      "canfd.g_recc", gpriv);
> +
> +               if (err) {
> +                       dev_err(&pdev->dev, "devm_request_irq(%d) failed, error %d\n",
> +                               g_recc_irq, err);
> +                       goto fail_dev;
> +               }
> +
> +               err = devm_request_irq(&pdev->dev, g_err_irq,
> +                                      rcar_canfd_global_interrupt, 0,

... as this one.

> +                                      "canfd.g_err", gpriv);
> +               if (err) {
> +                       dev_err(&pdev->dev, "devm_request_irq(%d) failed, error %d\n",
> +                               g_err_irq, err);
> +                       goto fail_dev;
> +               }
>         }
> -       err = devm_request_irq(&pdev->dev, g_irq,
> -                              rcar_canfd_global_interrupt, 0,
> -                              "canfd.gbl", gpriv);
> +
> +       err = reset_control_reset(gpriv->rstc1);
> +       if (err)
> +               goto fail_dev;
> +       err = reset_control_reset(gpriv->rstc2);
>         if (err) {
> -               dev_err(&pdev->dev, "devm_request_irq(%d) failed, error %d\n",
> -                       g_irq, err);
> +               reset_control_assert(gpriv->rstc1);
>                 goto fail_dev;
>         }

I did not object to having fine-grained interrupt handlers on RZ/G2L.
I did object to duplicating code in global and fine-grained interrupt
handlers.

The trick to have both is to let the global interrupt handlers call
(conditionally) into the fine-grained handlers. In pseudo-code:

    global_interrupt_handler()
    {
            if (...)
                    fine_grained_handler1();

            if (...)
                    fine_grained_handler2();
            ...
    }

On R-Car Gen3, you register the global interrupt handlers, as before.
On RZ/G2L, you register the fine-grained interrupt handlers instead.

Gr{oetje,eeting}s,

                        Geert
Lad, Prabhakar July 26, 2021, 9:58 p.m. UTC | #2
Hi Geert,

Thank you for the review.

On Mon, Jul 26, 2021 at 10:53 AM Geert Uytterhoeven
<geert@linux-m68k.org> wrote:
>
> Hi Prabhakar,
>
> On Wed, Jul 21, 2021 at 9:50 PM Lad Prabhakar
> <prabhakar.mahadev-lad.rj@bp.renesas.com> wrote:
> > CANFD block on RZ/G2L SoC is almost identical to one found on
> > R-Car Gen3 SoC's. On RZ/G2L SoC interrupt sources for each channel
> > are split into different sources and the IP doesn't divide (1/2)
> > CANFD clock within the IP.
> >
> > This patch adds compatible string for RZ/G2L family and registers
> > the irq handlers required for CANFD operation. IRQ numbers are now
> > fetched based on names instead of indices. For backward compatibility
> > on non RZ/G2L SoC's we fallback reading based on indices.
> >
> > Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
>
> Thanks for the update!
>
> I think you misunderstood my comment on v1 about the interrupt
> handlers, cfr. below.
>
Argh my bad I took it the other way round!

> > --- a/drivers/net/can/rcar/rcar_canfd.c
> > +++ b/drivers/net/can/rcar/rcar_canfd.c
>
> > @@ -1577,6 +1586,53 @@ static int rcar_canfd_channel_probe(struct rcar_canfd_global *gpriv, u32 ch,
> >         priv->can.clock.freq = fcan_freq;
> >         dev_info(&pdev->dev, "can_clk rate is %u\n", priv->can.clock.freq);
> >
> > +       if (gpriv->chip_id == RENESAS_RZG2L) {
> > +               char *irq_name;
> > +               int err_irq;
> > +               int tx_irq;
> > +
> > +               err_irq = platform_get_irq_byname(pdev, ch == 0 ? "ch0_err" : "ch1_err");
> > +               if (err_irq < 0) {
> > +                       err = err_irq;
> > +                       goto fail;
> > +               }
> > +
> > +               tx_irq = platform_get_irq_byname(pdev, ch == 0 ? "ch0_trx" : "ch1_trx");
> > +               if (tx_irq < 0) {
> > +                       err = tx_irq;
> > +                       goto fail;
> > +               }
> > +
> > +               irq_name = devm_kasprintf(&pdev->dev, GFP_KERNEL,
> > +                                         "canfd.ch%d_err", ch);
> > +               if (!irq_name) {
> > +                       err = -ENOMEM;
> > +                       goto fail;
> > +               }
> > +               err = devm_request_irq(&pdev->dev, err_irq,
> > +                                      rcar_canfd_channel_interrupt, 0,
>
> This is the same interrupt handler...
>
> > +                                      irq_name, gpriv);
> > +               if (err) {
> > +                       dev_err(&pdev->dev, "devm_request_irq CH Err(%d) failed, error %d\n",
> > +                               err_irq, err);
> > +                       goto fail;
> > +               }
> > +               irq_name = devm_kasprintf(&pdev->dev, GFP_KERNEL,
> > +                                         "canfd.ch%d_trx", ch);
> > +               if (!irq_name) {
> > +                       err = -ENOMEM;
> > +                       goto fail;
> > +               }
> > +               err = devm_request_irq(&pdev->dev, tx_irq,
> > +                                      rcar_canfd_channel_interrupt, 0,
>
> ... as this one.
>
> > +                                      irq_name, gpriv);
> > +               if (err) {
> > +                       dev_err(&pdev->dev, "devm_request_irq Tx (%d) failed, error %d\n",
> > +                               tx_irq, err);
> > +                       goto fail;
> > +               }
> > +       }
> > +
> >         if (gpriv->fdmode) {
> >                 priv->can.bittiming_const = &rcar_canfd_nom_bittiming_const;
> >                 priv->can.data_bittiming_const =
>
> > @@ -1711,20 +1798,51 @@ static int rcar_canfd_probe(struct platform_device *pdev)
> >         gpriv->base = addr;
> >
> >         /* Request IRQ that's common for both channels */
> > -       err = devm_request_irq(&pdev->dev, ch_irq,
> > -                              rcar_canfd_channel_interrupt, 0,
> > -                              "canfd.chn", gpriv);
> > -       if (err) {
> > -               dev_err(&pdev->dev, "devm_request_irq(%d) failed, error %d\n",
> > -                       ch_irq, err);
> > -               goto fail_dev;
> > +       if (gpriv->chip_id == RENESAS_RCAR_GEN3) {
> > +               err = devm_request_irq(&pdev->dev, ch_irq,
> > +                                      rcar_canfd_channel_interrupt, 0,
> > +                                      "canfd.ch_int", gpriv);
> > +               if (err) {
> > +                       dev_err(&pdev->dev, "devm_request_irq(%d) failed, error %d\n",
> > +                               ch_irq, err);
> > +                       goto fail_dev;
> > +               }
> > +
> > +               err = devm_request_irq(&pdev->dev, g_irq,
> > +                                      rcar_canfd_global_interrupt, 0,
> > +                                      "canfd.g_int", gpriv);
> > +               if (err) {
> > +                       dev_err(&pdev->dev, "devm_request_irq(%d) failed, error %d\n",
> > +                               g_irq, err);
> > +                       goto fail_dev;
> > +               }
> > +       } else {
> > +               err = devm_request_irq(&pdev->dev, g_recc_irq,
> > +                                      rcar_canfd_global_interrupt, 0,
>
> This is the same interrupt handler...
>
> > +                                      "canfd.g_recc", gpriv);
> > +
> > +               if (err) {
> > +                       dev_err(&pdev->dev, "devm_request_irq(%d) failed, error %d\n",
> > +                               g_recc_irq, err);
> > +                       goto fail_dev;
> > +               }
> > +
> > +               err = devm_request_irq(&pdev->dev, g_err_irq,
> > +                                      rcar_canfd_global_interrupt, 0,
>
> ... as this one.
>
> > +                                      "canfd.g_err", gpriv);
> > +               if (err) {
> > +                       dev_err(&pdev->dev, "devm_request_irq(%d) failed, error %d\n",
> > +                               g_err_irq, err);
> > +                       goto fail_dev;
> > +               }
> >         }
> > -       err = devm_request_irq(&pdev->dev, g_irq,
> > -                              rcar_canfd_global_interrupt, 0,
> > -                              "canfd.gbl", gpriv);
> > +
> > +       err = reset_control_reset(gpriv->rstc1);
> > +       if (err)
> > +               goto fail_dev;
> > +       err = reset_control_reset(gpriv->rstc2);
> >         if (err) {
> > -               dev_err(&pdev->dev, "devm_request_irq(%d) failed, error %d\n",
> > -                       g_irq, err);
> > +               reset_control_assert(gpriv->rstc1);
> >                 goto fail_dev;
> >         }
>
> I did not object to having fine-grained interrupt handlers on RZ/G2L.
> I did object to duplicating code in global and fine-grained interrupt
> handlers.
>
> The trick to have both is to let the global interrupt handlers call
> (conditionally) into the fine-grained handlers. In pseudo-code:
>
>     global_interrupt_handler()
>     {
>             if (...)
>                     fine_grained_handler1();
>
>             if (...)
>                     fine_grained_handler2();
>             ...
>     }
>
> On R-Car Gen3, you register the global interrupt handlers, as before.
> On RZ/G2L, you register the fine-grained interrupt handlers instead.
>
Agreed will re-spin with the fine-grained version tomorrow.

Cheers,
Prabhakar

> Gr{oetje,eeting}s,
>
>                         Geert
>
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
>
> 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