linux-sh.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH/RFC 07/12] sh-pfc: Configure pins as GPIOs at request time when handled externally
@ 2013-03-10 18:58 Laurent Pinchart
  2013-03-13 17:40 ` Linus Walleij
  2013-03-13 17:47 ` Laurent Pinchart
  0 siblings, 2 replies; 3+ messages in thread
From: Laurent Pinchart @ 2013-03-10 18:58 UTC (permalink / raw)
  To: linux-sh

When a GPIO is handled by a separate driver the pinmux
gpio_set_direction() handler won't be called. The pin mux type then need
to be configured to GPIO at request time.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
 drivers/pinctrl/sh-pfc/core.c    | 37 ++++++++++++++++---------------------
 drivers/pinctrl/sh-pfc/pinctrl.c | 11 +++++++++++
 2 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/drivers/pinctrl/sh-pfc/core.c b/drivers/pinctrl/sh-pfc/core.c
index feef897..1e022bb 100644
--- a/drivers/pinctrl/sh-pfc/core.c
+++ b/drivers/pinctrl/sh-pfc/core.c
@@ -267,7 +267,7 @@ int sh_pfc_config_mux(struct sh_pfc *pfc, unsigned mark, int pinmux_type)
 	int ret;
 
 	switch (pinmux_type) {
-
+	case PINMUX_TYPE_GPIO:
 	case PINMUX_TYPE_FUNCTION:
 		range = NULL;
 		break;
@@ -296,6 +296,8 @@ int sh_pfc_config_mux(struct sh_pfc *pfc, unsigned mark, int pinmux_type)
 	enum_id = 0;
 	field = 0;
 	value = 0;
+
+	/* Iterate over all the configuration fields we need to update. */
 	while (1) {
 		pos = sh_pfc_mark_to_enum(pfc, mark, pos, &enum_id);
 		if (pos < 0)
@@ -304,18 +306,20 @@ int sh_pfc_config_mux(struct sh_pfc *pfc, unsigned mark, int pinmux_type)
 		if (!enum_id)
 			break;
 
-		/* first check if this is a function enum */
+		/* Check if the configuration field selects a function. If it
+		 * doesn't, skip the field if it's not applicable to the
+		 * requested pinmux type.
+		 */
 		in_range = sh_pfc_enum_in_range(enum_id, &pfc->info->function);
 		if (!in_range) {
-			/* not a function enum */
-			if (range) {
-				/*
-				 * other range exists, so this pin is
-				 * a regular GPIO pin that now is being
-				 * bound to a specific direction.
-				 *
-				 * for this case we only allow function enums
-				 * and the enums that match the other range.
+			if (pinmux_type = PINMUX_TYPE_FUNCTION) {
+				/* Functions are allowed to modify all
+				 * fields.
+				 */
+				in_range = 1;
+			} else if (pinmux_type != PINMUX_TYPE_GPIO) {
+				/* Input/output types can only modify fields
+				 * that correspond to their respective ranges.
 				 */
 				in_range = sh_pfc_enum_in_range(enum_id, range);
 
@@ -326,17 +330,8 @@ int sh_pfc_config_mux(struct sh_pfc *pfc, unsigned mark, int pinmux_type)
 				 */
 				if (in_range && enum_id = range->force)
 					continue;
-			} else {
-				/*
-				 * no other range exists, so this pin
-				 * must then be of the function type.
-				 *
-				 * allow function type pins to select
-				 * any combination of function/in/out
-				 * in their MARK lists.
-				 */
-				in_range = 1;
 			}
+			/* GPIOs are only allowed to modify function fields. */
 		}
 
 		if (!in_range)
diff --git a/drivers/pinctrl/sh-pfc/pinctrl.c b/drivers/pinctrl/sh-pfc/pinctrl.c
index f1804b7..2b35973 100644
--- a/drivers/pinctrl/sh-pfc/pinctrl.c
+++ b/drivers/pinctrl/sh-pfc/pinctrl.c
@@ -180,6 +180,17 @@ static int sh_pfc_gpio_request_enable(struct pinctrl_dev *pctldev,
 		goto done;
 	}
 
+	if (pfc->gpio = NULL) {
+		/* If GPIOs are handled externally the pin mux type need to be
+		 * set to GPIO here.
+		 */
+		const struct sh_pfc_pin *pin = &pfc->info->pins[idx];
+
+		ret = sh_pfc_config_mux(pfc, pin->enum_id, PINMUX_TYPE_GPIO);
+		if (ret < 0)
+			goto done;
+	}
+
 	cfg->type = PINMUX_TYPE_GPIO;
 
 	ret = 0;
-- 
1.8.1.5


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

* Re: [PATCH/RFC 07/12] sh-pfc: Configure pins as GPIOs at request time when handled externally
  2013-03-10 18:58 [PATCH/RFC 07/12] sh-pfc: Configure pins as GPIOs at request time when handled externally Laurent Pinchart
@ 2013-03-13 17:40 ` Linus Walleij
  2013-03-13 17:47 ` Laurent Pinchart
  1 sibling, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2013-03-13 17:40 UTC (permalink / raw)
  To: linux-sh

On Sun, Mar 10, 2013 at 7:58 PM, Laurent Pinchart
<laurent.pinchart+renesas@ideasonboard.com> wrote:

> When a GPIO is handled by a separate driver the pinmux
> gpio_set_direction() handler won't be called. The pin mux type then need
> to be configured to GPIO at request time.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
(...)
> @@ -180,6 +180,17 @@ static int sh_pfc_gpio_request_enable(struct pinctrl_dev *pctldev,
>                 goto done;
>         }
>
> +       if (pfc->gpio = NULL) {
> +               /* If GPIOs are handled externally the pin mux type need to be
> +                * set to GPIO here.
> +                */

So using an external GPIO is the *only* reason why pfc->gpio would be
NULL?

Anyway you can write that if (!pfc->gpio) then...

Yours,
Linus Walleij

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

* Re: [PATCH/RFC 07/12] sh-pfc: Configure pins as GPIOs at request time when handled externally
  2013-03-10 18:58 [PATCH/RFC 07/12] sh-pfc: Configure pins as GPIOs at request time when handled externally Laurent Pinchart
  2013-03-13 17:40 ` Linus Walleij
@ 2013-03-13 17:47 ` Laurent Pinchart
  1 sibling, 0 replies; 3+ messages in thread
From: Laurent Pinchart @ 2013-03-13 17:47 UTC (permalink / raw)
  To: linux-sh

Hi Linus,

On Wednesday 13 March 2013 18:40:07 Linus Walleij wrote:
> On Sun, Mar 10, 2013 at 7:58 PM, Laurent Pinchart wrote:
> > When a GPIO is handled by a separate driver the pinmux
> > gpio_set_direction() handler won't be called. The pin mux type then need
> > to be configured to GPIO at request time.
> > 
> > Signed-off-by: Laurent Pinchart
> > <laurent.pinchart+renesas@ideasonboard.com>
> 
> (...)
> 
> > @@ -180,6 +180,17 @@ static int sh_pfc_gpio_request_enable(struct
> > pinctrl_dev *pctldev,
> >                 goto done;
> >         }
> > 
> > +       if (pfc->gpio = NULL) {
> > +               /* If GPIOs are handled externally the pin mux type need
> > to be
> > +                * set to GPIO here.
> > +                */
> 
> So using an external GPIO is the *only* reason why pfc->gpio would be
> NULL?

That's correct. pfc->gpio points to the GPIO SoC and must always be supplied 
when the PFC driver handles GPIOs.

> Anyway you can write that if (!pfc->gpio) then...

OK.

-- 
Regards,

Laurent Pinchart


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

end of thread, other threads:[~2013-03-13 17:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-10 18:58 [PATCH/RFC 07/12] sh-pfc: Configure pins as GPIOs at request time when handled externally Laurent Pinchart
2013-03-13 17:40 ` Linus Walleij
2013-03-13 17:47 ` Laurent Pinchart

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