diff mbox series

[v2,2/2] pinctrl: single: set pinmux from pins debug file

Message ID 20210517200002.6316-3-dariobin@libero.it
State New
Headers show
Series None | expand

Commit Message

Dario Binacchi May 17, 2021, 8 p.m. UTC
As described in section 9.1 of the TI reference manual for AM335x [1],
"For writing to the control module registers, the MPU will need to be in
privileged mode of operation and writes will not work from user mode".
By adding the pin_dbg_set helper to pcs_pinctrl_ops it will be possible
to write these registers from the pins debug:

cd /sys/kernel/debug/pinctrl/44e10800.pinmux-pinctrl-single/
echo <pin-number> <reg-value> >pins

[1] https://www.ti.com/lit/ug/spruh73q/spruh73q.pdf

Signed-off-by: Dario Binacchi <dariobin@libero.it>

---

Changes in v2:
- Remove CONFIG_SOC_AM33XX dependency.

 drivers/pinctrl/pinctrl-single.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Comments

Tony Lindgren May 18, 2021, 6:05 a.m. UTC | #1
Hi,

I noticed few more things I started to wonder about after
looking at this again.

* Dario Binacchi <dariobin@libero.it> [210517 20:00]:
> +static int pcs_pin_dbg_set(struct pinctrl_dev *pctldev, unsigned int pin,
> +			   char *buf)
> +{
> +	struct pcs_device *pcs;
> +	unsigned int val, mux_bytes;
> +
> +	buf = skip_spaces(buf);
> +	if (kstrtouint(buf, 0, &val))
> +		return -EINVAL;
> +
> +	pcs = pinctrl_dev_get_drvdata(pctldev);
> +
> +	mux_bytes = pcs->width / BITS_PER_BYTE;
> +	pcs->write(val, pcs->base + pin * mux_bytes);
> +	return 0;
> +}

Since you're adding a new interface, how about pass unsigned
int val instead of char *buf?

>  static void pcs_dt_free_map(struct pinctrl_dev *pctldev,
>  				struct pinctrl_map *map, unsigned num_maps)
>  {
> @@ -331,6 +348,9 @@ static const struct pinctrl_ops pcs_pinctrl_ops = {
>  	.get_group_name = pinctrl_generic_get_group_name,
>  	.get_group_pins = pinctrl_generic_get_group_pins,
>  	.pin_dbg_show = pcs_pin_dbg_show,
> +#if IS_ENABLED(CONFIG_DEVMEM)
> +	.pin_dbg_set = pcs_pin_dbg_set,
> +#endif
>  	.dt_node_to_map = pcs_dt_node_to_map,
>  	.dt_free_map = pcs_dt_free_map,
>  };

It might be better to always have the .pin_dbg_set around to
avoid the IS_ENABLED(CONFIG_DEVMEM).

Does the new interface need something under Documentation too?

Regards,

Tony
Dario Binacchi May 18, 2021, 8:57 a.m. UTC | #2
Hi Tony,

> Il 18/05/2021 08:05 Tony Lindgren <tony@atomide.com> ha scritto:

> 

>  

> Hi,

> 

> I noticed few more things I started to wonder about after

> looking at this again.

> 

> * Dario Binacchi <dariobin@libero.it> [210517 20:00]:

> > +static int pcs_pin_dbg_set(struct pinctrl_dev *pctldev, unsigned int pin,

> > +			   char *buf)

> > +{

> > +	struct pcs_device *pcs;

> > +	unsigned int val, mux_bytes;

> > +

> > +	buf = skip_spaces(buf);

> > +	if (kstrtouint(buf, 0, &val))

> > +		return -EINVAL;

> > +

> > +	pcs = pinctrl_dev_get_drvdata(pctldev);

> > +

> > +	mux_bytes = pcs->width / BITS_PER_BYTE;

> > +	pcs->write(val, pcs->base + pin * mux_bytes);

> > +	return 0;

> > +}

> 

> Since you're adding a new interface, how about pass unsigned

> int val instead of char *buf?


I thought about passing char *buf because it seemed more generic 
to me. As the output of pin_dbg_show() depends on the platform 
driver, perhaps pin_dbg_set() may need driver-dependent data.
Is it possible that only the value to be set in the register 
(unsigned int) is required?

> 

> >  static void pcs_dt_free_map(struct pinctrl_dev *pctldev,

> >  				struct pinctrl_map *map, unsigned num_maps)

> >  {

> > @@ -331,6 +348,9 @@ static const struct pinctrl_ops pcs_pinctrl_ops = {

> >  	.get_group_name = pinctrl_generic_get_group_name,

> >  	.get_group_pins = pinctrl_generic_get_group_pins,

> >  	.pin_dbg_show = pcs_pin_dbg_show,

> > +#if IS_ENABLED(CONFIG_DEVMEM)

> > +	.pin_dbg_set = pcs_pin_dbg_set,

> > +#endif

> >  	.dt_node_to_map = pcs_dt_node_to_map,

> >  	.dt_free_map = pcs_dt_free_map,

> >  };

> 

> It might be better to always have the .pin_dbg_set around to

> avoid the IS_ENABLED(CONFIG_DEVMEM).


Ok, I'll remove the CONFIG_DEVMEM dependency

> 

> Does the new interface need something under Documentation too?


Yes, the description of `pins` in Documentation/driver-api/pin-control.rst 
needs to be updated. I'll add another patch to the series.

Thanks and regards,
Dario

> 

> Regards,

> 

> Tony
Tony Lindgren May 21, 2021, 9:25 a.m. UTC | #3
* Dario Binacchi <dariobin@libero.it> [210518 08:57]:
> I thought about passing char *buf because it seemed more generic 
> to me. As the output of pin_dbg_show() depends on the platform 
> driver, perhaps pin_dbg_set() may need driver-dependent data.
> Is it possible that only the value to be set in the register 
> (unsigned int) is required?

Maybe Linus W can answer this one.

Regards,

Tony
diff mbox series

Patch

diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
index 2c9c9835f375..8497414e3384 100644
--- a/drivers/pinctrl/pinctrl-single.c
+++ b/drivers/pinctrl/pinctrl-single.c
@@ -313,6 +313,23 @@  static void pcs_pin_dbg_show(struct pinctrl_dev *pctldev,
 	seq_printf(s, "%zx %08x %s ", pa, val, DRIVER_NAME);
 }
 
+static int pcs_pin_dbg_set(struct pinctrl_dev *pctldev, unsigned int pin,
+			   char *buf)
+{
+	struct pcs_device *pcs;
+	unsigned int val, mux_bytes;
+
+	buf = skip_spaces(buf);
+	if (kstrtouint(buf, 0, &val))
+		return -EINVAL;
+
+	pcs = pinctrl_dev_get_drvdata(pctldev);
+
+	mux_bytes = pcs->width / BITS_PER_BYTE;
+	pcs->write(val, pcs->base + pin * mux_bytes);
+	return 0;
+}
+
 static void pcs_dt_free_map(struct pinctrl_dev *pctldev,
 				struct pinctrl_map *map, unsigned num_maps)
 {
@@ -331,6 +348,9 @@  static const struct pinctrl_ops pcs_pinctrl_ops = {
 	.get_group_name = pinctrl_generic_get_group_name,
 	.get_group_pins = pinctrl_generic_get_group_pins,
 	.pin_dbg_show = pcs_pin_dbg_show,
+#if IS_ENABLED(CONFIG_DEVMEM)
+	.pin_dbg_set = pcs_pin_dbg_set,
+#endif
 	.dt_node_to_map = pcs_dt_node_to_map,
 	.dt_free_map = pcs_dt_free_map,
 };