All of lore.kernel.org
 help / color / mirror / Atom feed
* BGPIOF_READ_OUTPUT_REG_SET problem
@ 2015-12-16 14:05 Michael Trimarchi
  2015-12-16 14:50 ` Vladimir Zapolskiy
  2015-12-17  9:00 ` Linus Walleij
  0 siblings, 2 replies; 11+ messages in thread
From: Michael Trimarchi @ 2015-12-16 14:05 UTC (permalink / raw)
  To: Vladimir Zapolskiy; +Cc: Linus Walleij, linux-gpio, michael

Hi

I have get a problem using gpio and imx6q freescale architecture. I don't
really understand how should work your change and I have done a quick
fix for me. Can you explain what was the idea?

Michael

diff --git a/drivers/gpio/gpio-generic.c b/drivers/gpio/gpio-generic.c
index a3f0753..f9c6ff7 100644
--- a/drivers/gpio/gpio-generic.c
+++ b/drivers/gpio/gpio-generic.c
@@ -139,11 +139,14 @@ static int bgpio_get_set(struct gpio_chip *gc, unsigned int gpio)
 {
 	struct bgpio_chip *bgc = to_bgpio_chip(gc);
 	unsigned long pinmask = bgc->pin2mask(bgc, gpio);
+	unsigned long reg;
 
 	if (bgc->dir & pinmask)
-		return bgc->read_reg(bgc->reg_set) & pinmask;
+		reg = bgc->read_reg(bgc->reg_set) & pinmask;
 	else
-		return bgc->read_reg(bgc->reg_dat) & pinmask;
+		reg = bgc->read_reg(bgc->reg_dat) & pinmask;
+
+	return !!(reg &  bgc->pin2mask(bgc, gpio));
 }
 
 static int bgpio_get(struct gpio_chip *gc, unsigned int gpio)
-- 
| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |

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

* Re: BGPIOF_READ_OUTPUT_REG_SET problem
  2015-12-16 14:05 BGPIOF_READ_OUTPUT_REG_SET problem Michael Trimarchi
@ 2015-12-16 14:50 ` Vladimir Zapolskiy
  2015-12-16 15:25   ` Michael Trimarchi
  2015-12-17  9:00 ` Linus Walleij
  1 sibling, 1 reply; 11+ messages in thread
From: Vladimir Zapolskiy @ 2015-12-16 14:50 UTC (permalink / raw)
  To: Michael Trimarchi; +Cc: Linus Walleij, linux-gpio

Hi Michael,

On 16.12.2015 16:05, Michael Trimarchi wrote:
> Hi
> 
> I have get a problem using gpio and imx6q freescale architecture. 

what is the problem you experience? What is the version of the kernel
(commit hash id) you run?

> I don't really understand how should work your change and I have done a quick
> fix for me. Can you explain what was the idea?

I believe here you are talking about changes b19e7f51a5 and
442b2494b17d1 , please explain the problem.

With best wishes,
Vladimir

> Michael
> 
> diff --git a/drivers/gpio/gpio-generic.c b/drivers/gpio/gpio-generic.c
> index a3f0753..f9c6ff7 100644
> --- a/drivers/gpio/gpio-generic.c
> +++ b/drivers/gpio/gpio-generic.c
> @@ -139,11 +139,14 @@ static int bgpio_get_set(struct gpio_chip *gc, unsigned int gpio)
>  {
>  	struct bgpio_chip *bgc = to_bgpio_chip(gc);
>  	unsigned long pinmask = bgc->pin2mask(bgc, gpio);
> +	unsigned long reg;
>  
>  	if (bgc->dir & pinmask)
> -		return bgc->read_reg(bgc->reg_set) & pinmask;
> +		reg = bgc->read_reg(bgc->reg_set) & pinmask;
>  	else
> -		return bgc->read_reg(bgc->reg_dat) & pinmask;
> +		reg = bgc->read_reg(bgc->reg_dat) & pinmask;
> +
> +	return !!(reg &  bgc->pin2mask(bgc, gpio));
>  }
>  
>  static int bgpio_get(struct gpio_chip *gc, unsigned int gpio)
> 

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

* Re: BGPIOF_READ_OUTPUT_REG_SET problem
  2015-12-16 14:50 ` Vladimir Zapolskiy
@ 2015-12-16 15:25   ` Michael Trimarchi
  2015-12-16 18:17     ` Michael Trimarchi
  2015-12-16 18:58     ` Vladimir Zapolskiy
  0 siblings, 2 replies; 11+ messages in thread
From: Michael Trimarchi @ 2015-12-16 15:25 UTC (permalink / raw)
  To: Vladimir Zapolskiy; +Cc: Linus Walleij, linux-gpio

Hi

On Wed, Dec 16, 2015 at 04:50:07PM +0200, Vladimir Zapolskiy wrote:
> Hi Michael,
> 
> On 16.12.2015 16:05, Michael Trimarchi wrote:
> > Hi
> > 
> > I have get a problem using gpio and imx6q freescale architecture. 
> 
> what is the problem you experience? What is the version of the kernel
> (commit hash id) you run?
> 

I don't want the mask back when I read the gpio. I want to know if it's
1 or 0

Michael

> > I don't really understand how should work your change and I have done a quick
> > fix for me. Can you explain what was the idea?
> 
> I believe here you are talking about changes b19e7f51a5 and
> 442b2494b17d1 , please explain the problem.
> 
> With best wishes,
> Vladimir
> 
> > Michael
> > 
> > diff --git a/drivers/gpio/gpio-generic.c b/drivers/gpio/gpio-generic.c
> > index a3f0753..f9c6ff7 100644
> > --- a/drivers/gpio/gpio-generic.c
> > +++ b/drivers/gpio/gpio-generic.c
> > @@ -139,11 +139,14 @@ static int bgpio_get_set(struct gpio_chip *gc, unsigned int gpio)
> >  {
> >  	struct bgpio_chip *bgc = to_bgpio_chip(gc);
> >  	unsigned long pinmask = bgc->pin2mask(bgc, gpio);
> > +	unsigned long reg;
> >  
> >  	if (bgc->dir & pinmask)
> > -		return bgc->read_reg(bgc->reg_set) & pinmask;
> > +		reg = bgc->read_reg(bgc->reg_set) & pinmask;
> >  	else
> > -		return bgc->read_reg(bgc->reg_dat) & pinmask;
> > +		reg = bgc->read_reg(bgc->reg_dat) & pinmask;
> > +
> > +	return !!(reg &  bgc->pin2mask(bgc, gpio));
> >  }
> >  
> >  static int bgpio_get(struct gpio_chip *gc, unsigned int gpio)
> > 

-- 
| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |

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

* Re: BGPIOF_READ_OUTPUT_REG_SET problem
  2015-12-16 15:25   ` Michael Trimarchi
@ 2015-12-16 18:17     ` Michael Trimarchi
  2015-12-16 19:18       ` Vladimir Zapolskiy
  2015-12-16 18:58     ` Vladimir Zapolskiy
  1 sibling, 1 reply; 11+ messages in thread
From: Michael Trimarchi @ 2015-12-16 18:17 UTC (permalink / raw)
  To: Vladimir Zapolskiy; +Cc: Linus Walleij, linux-gpio

Hi

On Wed, Dec 16, 2015 at 04:25:11PM +0100, Michael Trimarchi wrote:
> Hi
> 
> On Wed, Dec 16, 2015 at 04:50:07PM +0200, Vladimir Zapolskiy wrote:
> > Hi Michael,
> > 
> > On 16.12.2015 16:05, Michael Trimarchi wrote:
> > > Hi
> > > 
> > > I have get a problem using gpio and imx6q freescale architecture. 
> > 
> > what is the problem you experience? What is the version of the kernel
> > (commit hash id) you run?
> > 
> 
> I don't want the mask back when I read the gpio. I want to know if it's
> 1 or 0
> 

This is my starting commit on my local tree:

dd5ae6818ccd4ab0aa6f7d84e88f60a48af0fb52

Michael


> Michael
> 
> > > I don't really understand how should work your change and I have done a quick
> > > fix for me. Can you explain what was the idea?
> > 
> > I believe here you are talking about changes b19e7f51a5 and
> > 442b2494b17d1 , please explain the problem.
> > 
> > With best wishes,
> > Vladimir
> > 
> > > Michael
> > > 
> > > diff --git a/drivers/gpio/gpio-generic.c b/drivers/gpio/gpio-generic.c
> > > index a3f0753..f9c6ff7 100644
> > > --- a/drivers/gpio/gpio-generic.c
> > > +++ b/drivers/gpio/gpio-generic.c
> > > @@ -139,11 +139,14 @@ static int bgpio_get_set(struct gpio_chip *gc, unsigned int gpio)
> > >  {
> > >  	struct bgpio_chip *bgc = to_bgpio_chip(gc);
> > >  	unsigned long pinmask = bgc->pin2mask(bgc, gpio);
> > > +	unsigned long reg;
> > >  
> > >  	if (bgc->dir & pinmask)
> > > -		return bgc->read_reg(bgc->reg_set) & pinmask;
> > > +		reg = bgc->read_reg(bgc->reg_set) & pinmask;
> > >  	else
> > > -		return bgc->read_reg(bgc->reg_dat) & pinmask;
> > > +		reg = bgc->read_reg(bgc->reg_dat) & pinmask;
> > > +
> > > +	return !!(reg &  bgc->pin2mask(bgc, gpio));
> > >  }
> > >  
> > >  static int bgpio_get(struct gpio_chip *gc, unsigned int gpio)
> > > 
> 
> -- 
> | Michael Nazzareno Trimarchi                     Amarula Solutions BV |
> | COO  -  Founder                                      Cruquiuskade 47 |
> | +31(0)851119172                                 Amsterdam 1018 AM NL |
> |                  [`as] http://www.amarulasolutions.com               |

-- 
| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |

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

* Re: BGPIOF_READ_OUTPUT_REG_SET problem
  2015-12-16 15:25   ` Michael Trimarchi
  2015-12-16 18:17     ` Michael Trimarchi
@ 2015-12-16 18:58     ` Vladimir Zapolskiy
  2015-12-17  9:09       ` Linus Walleij
  1 sibling, 1 reply; 11+ messages in thread
From: Vladimir Zapolskiy @ 2015-12-16 18:58 UTC (permalink / raw)
  To: Michael Trimarchi, Linus Walleij; +Cc: linux-gpio, Bjorn Andersson

Hi Michael,

On 16.12.2015 17:25, Michael Trimarchi wrote:
> Hi
> 
> On Wed, Dec 16, 2015 at 04:50:07PM +0200, Vladimir Zapolskiy wrote:
>> Hi Michael,
>>
>> On 16.12.2015 16:05, Michael Trimarchi wrote:
>>> Hi
>>>
>>> I have get a problem using gpio and imx6q freescale architecture. 
>>
>> what is the problem you experience? What is the version of the kernel
>> (commit hash id) you run?
>>
> 
> I don't want the mask back when I read the gpio. I want to know if it's
> 1 or 0

I hope I figured out what is your problem.

At the time when I submitted b19e7f51a5 (dated Apr 29, 2015) return type of
_gpiod_get_raw_value() was bool, so it did not matter if you return mask or
0/1 value.

Later on Bjorn's commit e20538b82 ("gpio: Propagate errors from
chip->get()") (dated Aug 28, 2015) changed the return type from bool to int,
so you get the error now.

I would like to mention some points.

a) the Bjorn's commit brings the same problem to more GPIO drivers, this is
a short and not totally verified list (only function names):

* da9055_gpio_get()
* davinci_gpio_get()
* em_gio_get()
* intel_gpio_get()
* ttl_get_value()
* max732x_gpio_get_value()
* ioh_gpio_get()
* mpc8572_gpio_get()
* mpc8xxx_gpio_get()
* msic_gpio_get()
* pcf857x_get()
* pch_gpio_get()
* sa1100_gpio_get()
* gsta_gpio_get()
* tc3589x_gpio_get()
* tz1090_gpio_get()
* tz1090_pdc_gpio_get()

The list of gc.get() functions which may return a negative value today is
much shorter, so counting gpiochip drivers commit e20538b82 brings more bugs
than fixes.

I believe the right decision will be to fix all currently broken gpiochip
.get() functions, most probably returning a negative error was done on
purpose, Linus, please confirm.

b) from Bjorn's commit:

-static bool _gpiod_get_raw_value(const struct gpio_desc *desc)
+static int _gpiod_get_raw_value(const struct gpio_desc *desc)
 {
 	struct gpio_chip	*chip;
-	bool value;
 	int offset;
+	int value;

 	chip = desc->chip;
 	offset = gpio_chip_hwgpio(desc);
-	value = chip->get ? chip->get(chip, offset) : false;
+	value = chip->get ? chip->get(chip, offset) : -EIO;
+	value = value < 0 ? value : !!value;

^^^ this !! is a naive attempt to imitate backward compatible behaviour,
however it is broken, because if some !0 value is returned, then it might
happen that (value < 0) branch is selected.

Michael, is it your case? Do you receive an error, when reading a
GPIO[x*32+31] line status?

 	trace_gpio_value(desc_to_gpio(desc), 1, value);
	return value;
 }

c) here are the results of my testing on iMX6 SabreSD (edb42dc7bc0 on
Torvald's branch with a slightly modified DTS):

  output (red LED D3):

  % echo 2 > /sys/class/gpio/export
  % echo out > /sys/class/gpio/gpio2/direction
  % echo 1 > /sys/class/gpio/gpio2/value
  % cat /sys/class/gpio/gpio2/value
  1

  input (vol dn button)
  % echo 5 > /sys/class/gpio/export
  % echo in > /sys/class/gpio/gpio5/direction
  % cat /sys/class/gpio/gpio5/value
  1

Everything seems to be ok with gpios other than 31 + x*32, but the problem
of course exists.

Michael, try to revert e20538b82 and retest on your end, I would appreciate
to know the results.

Linus, I missed any relative discussion on the mailing list, what is the
final decision, can _gpiod_get_raw_value() return errors or not? In other
words which one of two gpiochip classes is broken, the one which returns
errors as negative values in .get() or the one which returns masks? I
believe it should be easier to fix the second one, even if it is larger
though :)

With best wishes,
Vladimir

>>> I don't really understand how should work your change and I have done a quick
>>> fix for me. Can you explain what was the idea?
>>
>> I believe here you are talking about changes b19e7f51a5 and
>> 442b2494b17d1 , please explain the problem.
>>
>> With best wishes,
>> Vladimir
>>
>>> Michael
>>>
>>> diff --git a/drivers/gpio/gpio-generic.c b/drivers/gpio/gpio-generic.c
>>> index a3f0753..f9c6ff7 100644
>>> --- a/drivers/gpio/gpio-generic.c
>>> +++ b/drivers/gpio/gpio-generic.c
>>> @@ -139,11 +139,14 @@ static int bgpio_get_set(struct gpio_chip *gc, unsigned int gpio)
>>>  {
>>>  	struct bgpio_chip *bgc = to_bgpio_chip(gc);
>>>  	unsigned long pinmask = bgc->pin2mask(bgc, gpio);
>>> +	unsigned long reg;
>>>  
>>>  	if (bgc->dir & pinmask)
>>> -		return bgc->read_reg(bgc->reg_set) & pinmask;
>>> +		reg = bgc->read_reg(bgc->reg_set) & pinmask;
>>>  	else
>>> -		return bgc->read_reg(bgc->reg_dat) & pinmask;
>>> +		reg = bgc->read_reg(bgc->reg_dat) & pinmask;
>>> +
>>> +	return !!(reg &  bgc->pin2mask(bgc, gpio));
>>>  }
>>>  
>>>  static int bgpio_get(struct gpio_chip *gc, unsigned int gpio)
>>>
> 


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

* Re: BGPIOF_READ_OUTPUT_REG_SET problem
  2015-12-16 18:17     ` Michael Trimarchi
@ 2015-12-16 19:18       ` Vladimir Zapolskiy
       [not found]         ` <CAOf5uwmM2T6VVVfBLUED5=a4ZMpY10oJg_r3FCzAW+XkRLxbww@mail.gmail.com>
  0 siblings, 1 reply; 11+ messages in thread
From: Vladimir Zapolskiy @ 2015-12-16 19:18 UTC (permalink / raw)
  To: Michael Trimarchi; +Cc: Linus Walleij, linux-gpio

Hi Michael,

On 16.12.2015 20:17, Michael Trimarchi wrote:
> Hi
> 
> On Wed, Dec 16, 2015 at 04:25:11PM +0100, Michael Trimarchi wrote:
>> Hi
>>
>> On Wed, Dec 16, 2015 at 04:50:07PM +0200, Vladimir Zapolskiy wrote:
>>> Hi Michael,
>>>
>>> On 16.12.2015 16:05, Michael Trimarchi wrote:
>>>> Hi
>>>>
>>>> I have get a problem using gpio and imx6q freescale architecture. 
>>>
>>> what is the problem you experience? What is the version of the kernel
>>> (commit hash id) you run?
>>>
>>
>> I don't want the mask back when I read the gpio. I want to know if it's
>> 1 or 0

now I got what you want, but actually I didn't get completely what is your
problem. Please be more descriptive.

> 
> This is my starting commit on my local tree:
> 
> dd5ae6818ccd4ab0aa6f7d84e88f60a48af0fb52

Good, so it is on Torvalds' branch and you have a potentially problematic
commit e20538b82 applied.

By the way you may try to git-bisect the problem, I may be wrong in my
assumptions regarding that commit.

With best wishes,
Vladimir

>>>> I don't really understand how should work your change and I have done a quick
>>>> fix for me. Can you explain what was the idea?
>>>
>>> I believe here you are talking about changes b19e7f51a5 and
>>> 442b2494b17d1 , please explain the problem.
>>>
>>> With best wishes,
>>> Vladimir
>>>
>>>> Michael
>>>>
>>>> diff --git a/drivers/gpio/gpio-generic.c b/drivers/gpio/gpio-generic.c
>>>> index a3f0753..f9c6ff7 100644
>>>> --- a/drivers/gpio/gpio-generic.c
>>>> +++ b/drivers/gpio/gpio-generic.c
>>>> @@ -139,11 +139,14 @@ static int bgpio_get_set(struct gpio_chip *gc, unsigned int gpio)
>>>>  {
>>>>  	struct bgpio_chip *bgc = to_bgpio_chip(gc);
>>>>  	unsigned long pinmask = bgc->pin2mask(bgc, gpio);
>>>> +	unsigned long reg;
>>>>  
>>>>  	if (bgc->dir & pinmask)
>>>> -		return bgc->read_reg(bgc->reg_set) & pinmask;
>>>> +		reg = bgc->read_reg(bgc->reg_set) & pinmask;
>>>>  	else
>>>> -		return bgc->read_reg(bgc->reg_dat) & pinmask;
>>>> +		reg = bgc->read_reg(bgc->reg_dat) & pinmask;
>>>> +
>>>> +	return !!(reg &  bgc->pin2mask(bgc, gpio));
>>>>  }
>>>>  
>>>>  static int bgpio_get(struct gpio_chip *gc, unsigned int gpio)
>>>>
>>
>> -- 
>> | Michael Nazzareno Trimarchi                     Amarula Solutions BV |
>> | COO  -  Founder                                      Cruquiuskade 47 |
>> | +31(0)851119172                                 Amsterdam 1018 AM NL |
>> |                  [`as] http://www.amarulasolutions.com               |
> 


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

* Re: BGPIOF_READ_OUTPUT_REG_SET problem
       [not found]         ` <CAOf5uwmM2T6VVVfBLUED5=a4ZMpY10oJg_r3FCzAW+XkRLxbww@mail.gmail.com>
@ 2015-12-16 20:01           ` Vladimir Zapolskiy
  2015-12-17  7:31             ` Michael Trimarchi
  0 siblings, 1 reply; 11+ messages in thread
From: Vladimir Zapolskiy @ 2015-12-16 20:01 UTC (permalink / raw)
  To: Michael Trimarchi; +Cc: Linus Walleij, linux-gpio

Hi Michael,

On 16.12.2015 21:38, Michael Trimarchi wrote:
> Hi
> 
> On Dec 16, 2015 8:18 PM, "Vladimir Zapolskiy" <vladimir_zapolskiy@mentor.com
> <mailto:vladimir_zapolskiy@mentor.com>> wrote:
>>
>> Hi Michael,
>>
>> On 16.12.2015 20:17, Michael Trimarchi wrote:
>> > Hi
>> >
>> > On Wed, Dec 16, 2015 at 04:25:11PM +0100, Michael Trimarchi wrote:
>> >> Hi
>> >>
>> >> On Wed, Dec 16, 2015 at 04:50:07PM +0200, Vladimir Zapolskiy wrote:
>> >>> Hi Michael,
>> >>>
>> >>> On 16.12.2015 16:05, Michael Trimarchi wrote:
>> >>>> Hi
>> >>>>
>> >>>> I have get a problem using gpio and imx6q freescale architecture.
>> >>>
>> >>> what is the problem you experience? What is the version of the kernel
>> >>> (commit hash id) you run?
>> >>>
>> >>
>> >> I don't want the mask back when I read the gpio. I want to know if it's
>> >> 1 or 0
>>
>> now I got what you want, but actually I didn't get completely what is your
>> problem. Please be more descriptive.
>>
>> >
>> > This is my starting commit on my local tree:
>> >
>> > dd5ae6818ccd4ab0aa6f7d84e88f60a48af0fb52
>>
>> Good, so it is on Torvalds' branch and you have a potentially problematic
>> commit e20538b82 applied.
>>
>> By the way you may try to git-bisect the problem, I may be wrong in my
>> assumptions regarding that commit.
>>
> 
> gc.get pointer should be assigned to function with same semantic. So on my
> tree semantic of function is different. 

Putting aside returned negative values, the problem is gone, if you change
the semantics in your tree and assume that gc.get() returns values: low - 0
and high - !0 (not necessary 1)? Because if you apply this logic, you get
+18 correctly working gpiochip drivers in your tree.

> I understand your point but we have two problems in mainline. One
> 0x10000000 and other get function.

Yes, the problem with the Bjorn's commit still exists. As well as another
kind of problem, if the commit is not applied.

With best wishes,
Vladimir

>> >>>> I don't really understand how should work your change and I have done
> a quick
>> >>>> fix for me. Can you explain what was the idea?
>> >>>
>> >>> I believe here you are talking about changes b19e7f51a5 and
>> >>> 442b2494b17d1 , please explain the problem.
>> >>>
>> >>> With best wishes,
>> >>> Vladimir
>> >>>
>> >>>> Michael
>> >>>>
>> >>>> diff --git a/drivers/gpio/gpio-generic.c b/drivers/gpio/gpio-generic.c
>> >>>> index a3f0753..f9c6ff7 100644
>> >>>> --- a/drivers/gpio/gpio-generic.c
>> >>>> +++ b/drivers/gpio/gpio-generic.c
>> >>>> @@ -139,11 +139,14 @@ static int bgpio_get_set(struct gpio_chip *gc,
> unsigned int gpio)
>> >>>>  {
>> >>>>    struct bgpio_chip *bgc = to_bgpio_chip(gc);
>> >>>>    unsigned long pinmask = bgc->pin2mask(bgc, gpio);
>> >>>> +  unsigned long reg;
>> >>>>
>> >>>>    if (bgc->dir & pinmask)
>> >>>> -          return bgc->read_reg(bgc->reg_set) & pinmask;
>> >>>> +          reg = bgc->read_reg(bgc->reg_set) & pinmask;
>> >>>>    else
>> >>>> -          return bgc->read_reg(bgc->reg_dat) & pinmask;
>> >>>> +          reg = bgc->read_reg(bgc->reg_dat) & pinmask;
>> >>>> +
>> >>>> +  return !!(reg &  bgc->pin2mask(bgc, gpio));
>> >>>>  }
>> >>>>
>> >>>>  static int bgpio_get(struct gpio_chip *gc, unsigned int gpio)
>> >>>>
>> >>
>> >> --
>> >> | Michael Nazzareno Trimarchi                     Amarula Solutions BV |
>> >> | COO  -  Founder                                      Cruquiuskade 47 |
>> >> | +31(0)851119172                                 Amsterdam 1018 AM NL |
>> >> |                  [`as] http://www.amarulasolutions.com               |
>> >
>>
> 


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

* Re: BGPIOF_READ_OUTPUT_REG_SET problem
  2015-12-16 20:01           ` Vladimir Zapolskiy
@ 2015-12-17  7:31             ` Michael Trimarchi
  0 siblings, 0 replies; 11+ messages in thread
From: Michael Trimarchi @ 2015-12-17  7:31 UTC (permalink / raw)
  To: Vladimir Zapolskiy; +Cc: Linus Walleij, linux-gpio

Hi Vladimir

On Wed, Dec 16, 2015 at 9:01 PM, Vladimir Zapolskiy
<vladimir_zapolskiy@mentor.com> wrote:
> Hi Michael,
>
> On 16.12.2015 21:38, Michael Trimarchi wrote:
>> Hi
>>
>> On Dec 16, 2015 8:18 PM, "Vladimir Zapolskiy" <vladimir_zapolskiy@mentor.com
>> <mailto:vladimir_zapolskiy@mentor.com>> wrote:
>>>
>>> Hi Michael,
>>>
>>> On 16.12.2015 20:17, Michael Trimarchi wrote:
>>> > Hi
>>> >
>>> > On Wed, Dec 16, 2015 at 04:25:11PM +0100, Michael Trimarchi wrote:
>>> >> Hi
>>> >>
>>> >> On Wed, Dec 16, 2015 at 04:50:07PM +0200, Vladimir Zapolskiy wrote:
>>> >>> Hi Michael,
>>> >>>
>>> >>> On 16.12.2015 16:05, Michael Trimarchi wrote:
>>> >>>> Hi
>>> >>>>
>>> >>>> I have get a problem using gpio and imx6q freescale architecture.
>>> >>>
>>> >>> what is the problem you experience? What is the version of the kernel
>>> >>> (commit hash id) you run?
>>> >>>
>>> >>
>>> >> I don't want the mask back when I read the gpio. I want to know if it's
>>> >> 1 or 0
>>>
>>> now I got what you want, but actually I didn't get completely what is your
>>> problem. Please be more descriptive.
>>>
>>> >
>>> > This is my starting commit on my local tree:
>>> >
>>> > dd5ae6818ccd4ab0aa6f7d84e88f60a48af0fb52
>>>
>>> Good, so it is on Torvalds' branch and you have a potentially problematic
>>> commit e20538b82 applied.
>>>
>>> By the way you may try to git-bisect the problem, I may be wrong in my
>>> assumptions regarding that commit.
>>>
>>
>> gc.get pointer should be assigned to function with same semantic. So on my
>> tree semantic of function is different.
>
> Putting aside returned negative values, the problem is gone, if you change
> the semantics in your tree and assume that gc.get() returns values: low - 0
> and high - !0 (not necessary 1)? Because if you apply this logic, you get
> +18 correctly working gpiochip drivers in your tree.
>
>> I understand your point but we have two problems in mainline. One
>> 0x10000000 and other get function.
>
> Yes, the problem with the Bjorn's commit still exists. As well as another
> kind of problem, if the commit is not applied.
>

It can be fine if >get() return 0 or 1 to the corresponding gpio and error
in case of failure (like in gpio expander for example). My patch make
the implementation
of bgpio_get_set equal to bgpio_get. I don't find any sense to let the
bgpio_get_set to return
the mask because ofcourse 31 gpio can not work. Revert does not solve
the problem because
we need to have int return value in general and not boolean

Michael

> With best wishes,
> Vladimir
>
>>> >>>> I don't really understand how should work your change and I have done
>> a quick
>>> >>>> fix for me. Can you explain what was the idea?
>>> >>>
>>> >>> I believe here you are talking about changes b19e7f51a5 and
>>> >>> 442b2494b17d1 , please explain the problem.
>>> >>>
>>> >>> With best wishes,
>>> >>> Vladimir
>>> >>>
>>> >>>> Michael
>>> >>>>
>>> >>>> diff --git a/drivers/gpio/gpio-generic.c b/drivers/gpio/gpio-generic.c
>>> >>>> index a3f0753..f9c6ff7 100644
>>> >>>> --- a/drivers/gpio/gpio-generic.c
>>> >>>> +++ b/drivers/gpio/gpio-generic.c
>>> >>>> @@ -139,11 +139,14 @@ static int bgpio_get_set(struct gpio_chip *gc,
>> unsigned int gpio)
>>> >>>>  {
>>> >>>>    struct bgpio_chip *bgc = to_bgpio_chip(gc);
>>> >>>>    unsigned long pinmask = bgc->pin2mask(bgc, gpio);
>>> >>>> +  unsigned long reg;
>>> >>>>
>>> >>>>    if (bgc->dir & pinmask)
>>> >>>> -          return bgc->read_reg(bgc->reg_set) & pinmask;
>>> >>>> +          reg = bgc->read_reg(bgc->reg_set) & pinmask;
>>> >>>>    else
>>> >>>> -          return bgc->read_reg(bgc->reg_dat) & pinmask;
>>> >>>> +          reg = bgc->read_reg(bgc->reg_dat) & pinmask;
>>> >>>> +
>>> >>>> +  return !!(reg &  bgc->pin2mask(bgc, gpio));
>>> >>>>  }
>>> >>>>
>>> >>>>  static int bgpio_get(struct gpio_chip *gc, unsigned int gpio)
>>> >>>>
>>> >>
>>> >> --
>>> >> | Michael Nazzareno Trimarchi                     Amarula Solutions BV |
>>> >> | COO  -  Founder                                      Cruquiuskade 47 |
>>> >> | +31(0)851119172                                 Amsterdam 1018 AM NL |
>>> >> |                  [`as] http://www.amarulasolutions.com               |
>>> >
>>>
>>
>



-- 
| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |

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

* Re: BGPIOF_READ_OUTPUT_REG_SET problem
  2015-12-16 14:05 BGPIOF_READ_OUTPUT_REG_SET problem Michael Trimarchi
  2015-12-16 14:50 ` Vladimir Zapolskiy
@ 2015-12-17  9:00 ` Linus Walleij
  2015-12-17  9:04   ` Michael Trimarchi
  1 sibling, 1 reply; 11+ messages in thread
From: Linus Walleij @ 2015-12-17  9:00 UTC (permalink / raw)
  To: Michael Trimarchi; +Cc: Vladimir Zapolskiy, linux-gpio

On Wed, Dec 16, 2015 at 3:05 PM, Michael Trimarchi
<michael@amarulasolutions.com> wrote:

> I have get a problem using gpio and imx6q freescale architecture. I don't
> really understand how should work your change and I have done a quick
> fix for me. Can you explain what was the idea?
>
> Michael
>
> diff --git a/drivers/gpio/gpio-generic.c b/drivers/gpio/gpio-generic.c
> index a3f0753..f9c6ff7 100644
> --- a/drivers/gpio/gpio-generic.c
> +++ b/drivers/gpio/gpio-generic.c
> @@ -139,11 +139,14 @@ static int bgpio_get_set(struct gpio_chip *gc, unsigned int gpio)
>  {
>         struct bgpio_chip *bgc = to_bgpio_chip(gc);
>         unsigned long pinmask = bgc->pin2mask(bgc, gpio);
> +       unsigned long reg;
>
>         if (bgc->dir & pinmask)
> -               return bgc->read_reg(bgc->reg_set) & pinmask;
> +               reg = bgc->read_reg(bgc->reg_set) & pinmask;
>         else
> -               return bgc->read_reg(bgc->reg_dat) & pinmask;
> +               reg = bgc->read_reg(bgc->reg_dat) & pinmask;
> +
> +       return !!(reg &  bgc->pin2mask(bgc, gpio));
>  }

This looks identical to this fix I have queued for fixes:
https://git.kernel.org/cgit/linux/kernel/git/linusw/linux-gpio.git/commit/?h=fixes&id=21f2856498ff09a03ebc8f9ff7581451a221d81b

Yours,
Linus Walleij

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

* Re: BGPIOF_READ_OUTPUT_REG_SET problem
  2015-12-17  9:00 ` Linus Walleij
@ 2015-12-17  9:04   ` Michael Trimarchi
  0 siblings, 0 replies; 11+ messages in thread
From: Michael Trimarchi @ 2015-12-17  9:04 UTC (permalink / raw)
  To: Linus Walleij; +Cc: Vladimir Zapolskiy, linux-gpio

Hi


On Thu, Dec 17, 2015 at 10:00 AM, Linus Walleij
<linus.walleij@linaro.org> wrote:
> On Wed, Dec 16, 2015 at 3:05 PM, Michael Trimarchi
> <michael@amarulasolutions.com> wrote:
>
>> I have get a problem using gpio and imx6q freescale architecture. I don't
>> really understand how should work your change and I have done a quick
>> fix for me. Can you explain what was the idea?
>>
>> Michael
>>
>> diff --git a/drivers/gpio/gpio-generic.c b/drivers/gpio/gpio-generic.c
>> index a3f0753..f9c6ff7 100644
>> --- a/drivers/gpio/gpio-generic.c
>> +++ b/drivers/gpio/gpio-generic.c
>> @@ -139,11 +139,14 @@ static int bgpio_get_set(struct gpio_chip *gc, unsigned int gpio)
>>  {
>>         struct bgpio_chip *bgc = to_bgpio_chip(gc);
>>         unsigned long pinmask = bgc->pin2mask(bgc, gpio);
>> +       unsigned long reg;
>>
>>         if (bgc->dir & pinmask)
>> -               return bgc->read_reg(bgc->reg_set) & pinmask;
>> +               reg = bgc->read_reg(bgc->reg_set) & pinmask;
>>         else
>> -               return bgc->read_reg(bgc->reg_dat) & pinmask;
>> +               reg = bgc->read_reg(bgc->reg_dat) & pinmask;
>> +
>> +       return !!(reg &  bgc->pin2mask(bgc, gpio));
>>  }
>
> This looks identical to this fix I have queued for fixes:
> https://git.kernel.org/cgit/linux/kernel/git/linusw/linux-gpio.git/commit/?h=fixes&id=21f2856498ff09a03ebc8f9ff7581451a221d81b
>

Good, so I can confirm that it's urgent

Michael

> Yours,
> Linus Walleij



-- 
| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |

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

* Re: BGPIOF_READ_OUTPUT_REG_SET problem
  2015-12-16 18:58     ` Vladimir Zapolskiy
@ 2015-12-17  9:09       ` Linus Walleij
  0 siblings, 0 replies; 11+ messages in thread
From: Linus Walleij @ 2015-12-17  9:09 UTC (permalink / raw)
  To: Vladimir Zapolskiy; +Cc: Michael Trimarchi, linux-gpio, Bjorn Andersson

On Wed, Dec 16, 2015 at 7:58 PM, Vladimir Zapolskiy
<vladimir_zapolskiy@mentor.com> wrote:

> Later on Bjorn's commit e20538b82 ("gpio: Propagate errors from
> chip->get()") (dated Aug 28, 2015) changed the return type from bool to int,
> so you get the error now.

Right.

> I believe the right decision will be to fix all currently broken gpiochip
> .get() functions, most probably returning a negative error was done on
> purpose, Linus, please confirm.

On (A): yes the right thing to do is to fix all broken .get() functions.
Help appreciated.

Yes, that is described in a response in the mail chain: we once believed
that get/set would not return negative so I was about to actually make
them bool. I was thinking it's just a register write or something.
gpiolib was once invented for that simple usecase.

But then we realized that e.g. a GPIO expander can fail an I2C
transaction for whatever reason (hardware failure for example) and
we need to handle that, so Björn's fix is the right one and we need
to fix the drivers.

I'm sorry for not realizing the scope of the problem :(

>         chip = desc->chip;
>         offset = gpio_chip_hwgpio(desc);
> -       value = chip->get ? chip->get(chip, offset) : false;
> +       value = chip->get ? chip->get(chip, offset) : -EIO;
> +       value = value < 0 ? value : !!value;
>
> ^^^ this !! is a naive attempt to imitate backward compatible behaviour,
> however it is broken, because if some !0 value is returned, then it might
> happen that (value < 0) branch is selected.

Hm. But we still need to propagate errors.

Maybe we should patch this back to not propagate errors for the
v4.4-rcS and then revert that and do the real fix, proofreading all
vulnerable drivers for v4.5, what do you say?

(I'll send a patch.)

> Linus, I missed any relative discussion on the mailing list, what is the
> final decision, can _gpiod_get_raw_value() return errors or not?

What do you think about my proposal to revert to the old behaviour
for v4.4 and we'll go over all drivers and provide a deeper fix in v4.5?

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2015-12-17  9:09 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-16 14:05 BGPIOF_READ_OUTPUT_REG_SET problem Michael Trimarchi
2015-12-16 14:50 ` Vladimir Zapolskiy
2015-12-16 15:25   ` Michael Trimarchi
2015-12-16 18:17     ` Michael Trimarchi
2015-12-16 19:18       ` Vladimir Zapolskiy
     [not found]         ` <CAOf5uwmM2T6VVVfBLUED5=a4ZMpY10oJg_r3FCzAW+XkRLxbww@mail.gmail.com>
2015-12-16 20:01           ` Vladimir Zapolskiy
2015-12-17  7:31             ` Michael Trimarchi
2015-12-16 18:58     ` Vladimir Zapolskiy
2015-12-17  9:09       ` Linus Walleij
2015-12-17  9:00 ` Linus Walleij
2015-12-17  9:04   ` Michael Trimarchi

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.