All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gpio: menz127: use the new open drain callback
@ 2016-04-09 19:56 Linus Walleij
  2016-05-11 17:39 ` Andreas Werner
  0 siblings, 1 reply; 2+ messages in thread
From: Linus Walleij @ 2016-04-09 19:56 UTC (permalink / raw)
  To: linux-gpio, Alexandre Courbot; +Cc: Linus Walleij, Andreas Werner

The menz127 driver tries to support open drain by detecting it
at request time. However: without the new callbacks from the
gpiolib it is not really working: the core will still just emulate
the open drain mode by switching the line to an input.

By adding a hook into the new .set_single_ended() call rather than
trying to autodetect at request() time, proper open drain can be
supported.

Cc: Andreas Werner <andy@wernerandy.de>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/gpio/gpio-menz127.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/drivers/gpio/gpio-menz127.c b/drivers/gpio/gpio-menz127.c
index 8c1ab8e1974f..334fe270dcf1 100644
--- a/drivers/gpio/gpio-menz127.c
+++ b/drivers/gpio/gpio-menz127.c
@@ -88,21 +88,25 @@ static int men_z127_debounce(struct gpio_chip *gc, unsigned gpio,
 	return 0;
 }
 
-static int men_z127_request(struct gpio_chip *gc, unsigned gpio_pin)
+static int men_z127_set_single_ended(struct gpio_chip *gc,
+				     unsigned offset,
+				     enum single_ended_mode mode)
 {
 	struct men_z127_gpio *priv = gpiochip_get_data(gc);
 	u32 od_en;
 
-	if (gpio_pin >= gc->ngpio)
-		return -EINVAL;
+	if (mode != LINE_MODE_OPEN_DRAIN &&
+	    mode != LINE_MODE_PUSH_PULL)
+		return -ENOTSUPP;
 
 	spin_lock(&priv->lock);
 	od_en = readl(priv->reg_base + MEN_Z127_ODER);
 
-	if (gpiochip_line_is_open_drain(gc, gpio_pin))
-		od_en |= BIT(gpio_pin);
+	if (mode == LINE_MODE_OPEN_DRAIN)
+		od_en |= BIT(offset);
 	else
-		od_en &= ~BIT(gpio_pin);
+		/* Implicitly LINE_MODE_PUSH_PULL */
+		od_en &= ~BIT(offset);
 
 	writel(od_en, priv->reg_base + MEN_Z127_ODER);
 	spin_unlock(&priv->lock);
@@ -147,7 +151,7 @@ static int men_z127_probe(struct mcb_device *mdev,
 		goto err_unmap;
 
 	men_z127_gpio->gc.set_debounce = men_z127_debounce;
-	men_z127_gpio->gc.request = men_z127_request;
+	men_z127_gpio->gc.set_single_ended = men_z127_set_single_ended;
 
 	ret = gpiochip_add_data(&men_z127_gpio->gc, men_z127_gpio);
 	if (ret) {
-- 
2.4.3


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

* Re: [PATCH] gpio: menz127: use the new open drain callback
  2016-04-09 19:56 [PATCH] gpio: menz127: use the new open drain callback Linus Walleij
@ 2016-05-11 17:39 ` Andreas Werner
  0 siblings, 0 replies; 2+ messages in thread
From: Andreas Werner @ 2016-05-11 17:39 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-gpio, Alexandre Courbot

On Sat, Apr 09, 2016 at 09:56:55PM +0200, Linus Walleij wrote:
> The menz127 driver tries to support open drain by detecting it
> at request time. However: without the new callbacks from the
> gpiolib it is not really working: the core will still just emulate
> the open drain mode by switching the line to an input.
> 
> By adding a hook into the new .set_single_ended() call rather than
> trying to autodetect at request() time, proper open drain can be
> supported.
> 
> Cc: Andreas Werner <andy@wernerandy.de>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
>  drivers/gpio/gpio-menz127.c | 18 +++++++++++-------
>  1 file changed, 11 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/gpio/gpio-menz127.c b/drivers/gpio/gpio-menz127.c
> index 8c1ab8e1974f..334fe270dcf1 100644
> --- a/drivers/gpio/gpio-menz127.c
> +++ b/drivers/gpio/gpio-menz127.c
> @@ -88,21 +88,25 @@ static int men_z127_debounce(struct gpio_chip *gc, unsigned gpio,
>  	return 0;
>  }
>  
> -static int men_z127_request(struct gpio_chip *gc, unsigned gpio_pin)
> +static int men_z127_set_single_ended(struct gpio_chip *gc,
> +				     unsigned offset,
> +				     enum single_ended_mode mode)
>  {
>  	struct men_z127_gpio *priv = gpiochip_get_data(gc);
>  	u32 od_en;
>  
> -	if (gpio_pin >= gc->ngpio)
> -		return -EINVAL;
> +	if (mode != LINE_MODE_OPEN_DRAIN &&
> +	    mode != LINE_MODE_PUSH_PULL)
> +		return -ENOTSUPP;
>  
>  	spin_lock(&priv->lock);
>  	od_en = readl(priv->reg_base + MEN_Z127_ODER);
>  
> -	if (gpiochip_line_is_open_drain(gc, gpio_pin))
> -		od_en |= BIT(gpio_pin);
> +	if (mode == LINE_MODE_OPEN_DRAIN)
> +		od_en |= BIT(offset);
>  	else
> -		od_en &= ~BIT(gpio_pin);
> +		/* Implicitly LINE_MODE_PUSH_PULL */
> +		od_en &= ~BIT(offset);
>  
>  	writel(od_en, priv->reg_base + MEN_Z127_ODER);
>  	spin_unlock(&priv->lock);
> @@ -147,7 +151,7 @@ static int men_z127_probe(struct mcb_device *mdev,
>  		goto err_unmap;
>  
>  	men_z127_gpio->gc.set_debounce = men_z127_debounce;
> -	men_z127_gpio->gc.request = men_z127_request;
> +	men_z127_gpio->gc.set_single_ended = men_z127_set_single_ended;
>  
>  	ret = gpiochip_add_data(&men_z127_gpio->gc, men_z127_gpio);
>  	if (ret) {
> -- 
> 2.4.3
> 

Hi Linus,
sorry for the late answer.

I will try to get the hardware and will test the patch.

I think this is exactly what I need to support the "real" open drain
mode.

Regards
Andy


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

end of thread, other threads:[~2016-05-11 17:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-09 19:56 [PATCH] gpio: menz127: use the new open drain callback Linus Walleij
2016-05-11 17:39 ` Andreas Werner

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.