2022-11-07 14:18:12

by Herve Codina

[permalink] [raw]
Subject: [PATCH 1/7] soc: renesas: r9a06g032-sysctrl: Export function to get H2MODE from CFG_USB register

The CFG_USB register is located within the system controller.

We need a helper to get the H2MODE value from the CFG_USB register
without syscon.

Signed-off-by: Herve Codina <[email protected]>
---
drivers/clk/renesas/r9a06g032-clocks.c | 18 ++++++++++++++++++
include/linux/soc/renesas/r9a06g032-sysctrl.h | 2 ++
2 files changed, 20 insertions(+)

diff --git a/drivers/clk/renesas/r9a06g032-clocks.c b/drivers/clk/renesas/r9a06g032-clocks.c
index 1488c9d6e639..c07131c47a9f 100644
--- a/drivers/clk/renesas/r9a06g032-clocks.c
+++ b/drivers/clk/renesas/r9a06g032-clocks.c
@@ -25,6 +25,8 @@
#include <linux/spinlock.h>
#include <dt-bindings/clock/r9a06g032-sysctrl.h>

+#define R9A06G032_SYSCTRL_USB 0x00
+#define R9A06G032_SYSCTRL_USB_H2MODE (1<<1)
#define R9A06G032_SYSCTRL_DMAMUX 0xA0

struct r9a06g032_gate {
@@ -341,6 +343,22 @@ int r9a06g032_sysctrl_set_dmamux(u32 mask, u32 val)
}
EXPORT_SYMBOL_GPL(r9a06g032_sysctrl_set_dmamux);

+
+/* Exported helper to get the H2MODE bit from USB register */
+int r9a06g032_sysctrl_get_usb_h2mode(bool *h2mode)
+{
+ u32 usb;
+
+ if (!sysctrl_priv)
+ return -EPROBE_DEFER;
+
+ usb = readl(sysctrl_priv->reg + R9A06G032_SYSCTRL_USB);
+ *h2mode = (usb & R9A06G032_SYSCTRL_USB_H2MODE) ? true : false;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(r9a06g032_sysctrl_get_usb_h2mode);
+
/* register/bit pairs are encoded as an uint16_t */
static void
clk_rdesc_set(struct r9a06g032_priv *clocks,
diff --git a/include/linux/soc/renesas/r9a06g032-sysctrl.h b/include/linux/soc/renesas/r9a06g032-sysctrl.h
index 066dfb15cbdd..095e00f27309 100644
--- a/include/linux/soc/renesas/r9a06g032-sysctrl.h
+++ b/include/linux/soc/renesas/r9a06g032-sysctrl.h
@@ -4,8 +4,10 @@

#ifdef CONFIG_CLK_R9A06G032
int r9a06g032_sysctrl_set_dmamux(u32 mask, u32 val);
+int r9a06g032_sysctrl_get_usb_h2mode(bool *h2mode);
#else
static inline int r9a06g032_sysctrl_set_dmamux(u32 mask, u32 val) { return -ENODEV; }
+static inline int r9a06g032_sysctrl_get_usb_h2mode(bool *h2mode) { return -ENODEV; }
#endif

#endif /* __LINUX_SOC_RENESAS_R9A06G032_SYSCTRL_H__ */
--
2.37.3



2022-11-07 16:03:43

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH 1/7] soc: renesas: r9a06g032-sysctrl: Export function to get H2MODE from CFG_USB register

Hi Hervé,

On Mon, Nov 7, 2022 at 2:59 PM Herve Codina <[email protected]> wrote:
> The CFG_USB register is located within the system controller.
>
> We need a helper to get the H2MODE value from the CFG_USB register
> without syscon.
>
> Signed-off-by: Herve Codina <[email protected]>

> --- a/drivers/clk/renesas/r9a06g032-clocks.c
> +++ b/drivers/clk/renesas/r9a06g032-clocks.c
> @@ -25,6 +25,8 @@
> #include <linux/spinlock.h>
> #include <dt-bindings/clock/r9a06g032-sysctrl.h>
>
> +#define R9A06G032_SYSCTRL_USB 0x00
> +#define R9A06G032_SYSCTRL_USB_H2MODE (1<<1)
> #define R9A06G032_SYSCTRL_DMAMUX 0xA0
>
> struct r9a06g032_gate {
> @@ -341,6 +343,22 @@ int r9a06g032_sysctrl_set_dmamux(u32 mask, u32 val)
> }
> EXPORT_SYMBOL_GPL(r9a06g032_sysctrl_set_dmamux);
>
> +
> +/* Exported helper to get the H2MODE bit from USB register */
> +int r9a06g032_sysctrl_get_usb_h2mode(bool *h2mode)
> +{
> + u32 usb;
> +
> + if (!sysctrl_priv)
> + return -EPROBE_DEFER;
> +
> + usb = readl(sysctrl_priv->reg + R9A06G032_SYSCTRL_USB);
> + *h2mode = (usb & R9A06G032_SYSCTRL_USB_H2MODE) ? true : false;
> +
> + return 0;

Perhaps not pass *h2mode, but just return USB_ROLE_{HOST,DEVICE}
(enum usb_role in <linux/usb/role.h>), or a negative error code?

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

2022-11-10 08:47:43

by Herve Codina

[permalink] [raw]
Subject: Re: [PATCH 1/7] soc: renesas: r9a06g032-sysctrl: Export function to get H2MODE from CFG_USB register

Hi Geert,

Oops, my bad I removed all people from the email previously.
Re-added them on this reply.

On Mon, 7 Nov 2022 20:23:06 +0100
Geert Uytterhoeven <[email protected]> wrote:

> Hi Hervé,
>
> On Mon, Nov 7, 2022 at 5:54 PM Herve Codina <[email protected]> wrote:
> > On Mon, 7 Nov 2022 15:40:53 +0100
> > Geert Uytterhoeven <[email protected]> wrote:
> > > On Mon, Nov 7, 2022 at 2:59 PM Herve Codina <[email protected]> wrote:
> > > > The CFG_USB register is located within the system controller.
> > > >
> > > > We need a helper to get the H2MODE value from the CFG_USB register
> > > > without syscon.
> > > >
> > > > Signed-off-by: Herve Codina <[email protected]>
> > >
> > > > --- a/drivers/clk/renesas/r9a06g032-clocks.c
> > > > +++ b/drivers/clk/renesas/r9a06g032-clocks.c
> > > > @@ -25,6 +25,8 @@
> > > > #include <linux/spinlock.h>
> > > > #include <dt-bindings/clock/r9a06g032-sysctrl.h>
> > > >
> > > > +#define R9A06G032_SYSCTRL_USB 0x00
> > > > +#define R9A06G032_SYSCTRL_USB_H2MODE (1<<1)
> > > > #define R9A06G032_SYSCTRL_DMAMUX 0xA0
> > > >
> > > > struct r9a06g032_gate {
> > > > @@ -341,6 +343,22 @@ int r9a06g032_sysctrl_set_dmamux(u32 mask, u32 val)
> > > > }
> > > > EXPORT_SYMBOL_GPL(r9a06g032_sysctrl_set_dmamux);
> > > >
> > > > +
> > > > +/* Exported helper to get the H2MODE bit from USB register */
> > > > +int r9a06g032_sysctrl_get_usb_h2mode(bool *h2mode)
> > > > +{
> > > > + u32 usb;
> > > > +
> > > > + if (!sysctrl_priv)
> > > > + return -EPROBE_DEFER;
> > > > +
> > > > + usb = readl(sysctrl_priv->reg + R9A06G032_SYSCTRL_USB);
> > > > + *h2mode = (usb & R9A06G032_SYSCTRL_USB_H2MODE) ? true : false;
> > > > +
> > > > + return 0;
> > >
> > > Perhaps not pass *h2mode, but just return USB_ROLE_{HOST,DEVICE}
> > > (enum usb_role in <linux/usb/role.h>), or a negative error code?
> >
> > Yes, good idea.
> > I will also rename the function :
> > enum usb_role r9a06g032_sysctrl_get_usb_role(void);
> >
> > Is that ok for you or do you prefer that I keep the previous name ?
>
> r9a06g032_sysctrl_get_usb_role() sounds fine!
> But it should return "int", as the return value can be a negative error code,
> too.

All right, I will do that in v2 series.

Thanks,
Hervé

--
Hervé Codina, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com