2011-02-01 08:01:48

by Wolfram Sang

[permalink] [raw]
Subject: Re: [leds-pca9532] Add gpio capability

> From the datasheet:
[...]
> So, you should provide both a direction_input and direction_output.

He did in V2 of this patch (what made me also download the datasheet ;)).

Regards,

Wolfram

--
Pengutronix e.K. | Wolfram Sang |
Industrial Linux Solutions | http://www.pengutronix.de/ |


Attachments:
(No filename) (350.00 B)
signature.asc (197.00 B)
Digital signature
Download all attachments

2011-02-01 16:27:27

by Hartley Sweeten

[permalink] [raw]
Subject: RE: [leds-pca9532] Add gpio capability

On Tuesday, February 01, 2011 1:02 AM, Wolfram Sang wrote:
>> From the datasheet:
>>[...]
>> So, you should provide both a direction_input and direction_output.
>
> He did in V2 of this patch (what made me also download the datasheet ;)).

Ok. Just looked at the v2 patch.

> +static int pca9532_gpio_direction_input(struct gpio_chip *gc, unsigned offset)
> +{
> + struct pca9532_data *data = container_of(gc, struct pca9532_data, gpio);
> + struct pca9532_led *led = &data->leds[offset];
> +
> + /* To use as input ensure pin is not driven */
> + led->state = PCA9532_OFF;
> + pca9532_setled(led);
> +
> + return 0;
> +}
> +

This looks good. When configured as an input the pin needs to be set high-impedance,
00 which is PCA9532_OFF).

> +static int pca9532_gpio_direction_output(struct gpio_chip *gc,
> unsigned offset, int val)
> +{
> + return 0;
> +}
> +

Not good. When the pin is configured as an output, the direction_output method also
requests that the pin be set to a desired level. For this driver that means that the
pca9532_gpio_direction_output function just needs to call pca9532_gpio_set_value.

Regards,
Hartley

2011-02-01 17:22:23

by Joachim Eastwood

[permalink] [raw]
Subject: Re: [leds-pca9532] Add gpio capability

On 2/1/11, H Hartley Sweeten <[email protected]> wrote:
> On Tuesday, February 01, 2011 1:02 AM, Wolfram Sang wrote:
>>> From the datasheet:
>>>[...]
>>> So, you should provide both a direction_input and direction_output.
>>
>> He did in V2 of this patch (what made me also download the datasheet ;)).
>
> Ok. Just looked at the v2 patch.
>
>> +static int pca9532_gpio_direction_input(struct gpio_chip *gc, unsigned
>> offset)
>> +{
>> + struct pca9532_data *data = container_of(gc, struct pca9532_data, gpio);
>> + struct pca9532_led *led = &data->leds[offset];
>> +
>> + /* To use as input ensure pin is not driven */
>> + led->state = PCA9532_OFF;
>> + pca9532_setled(led);
>> +
>> + return 0;
>> +}
>> +
>
> This looks good. When configured as an input the pin needs to be set
> high-impedance,
> 00 which is PCA9532_OFF).
>
>> +static int pca9532_gpio_direction_output(struct gpio_chip *gc,
>> unsigned offset, int val)
>> +{
>> + return 0;
>> +}
>> +
>
> Not good. When the pin is configured as an output, the direction_output
> method also
> requests that the pin be set to a desired level. For this driver that means
> that the
> pca9532_gpio_direction_output function just needs to call
> pca9532_gpio_set_value.

ops, I overlooked the 'val' parameter in the direction_output
function. I will create a v3.

Seems like I have been a bit careless with the direction setting... I
didn't really think through it since PCA9532 has no explicit direction
register.

Thanks for looking!

regards
Joachim Eastwood

> Regards,
> Hartley
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>

2011-02-01 18:44:16

by Wolfram Sang

[permalink] [raw]
Subject: Re: [leds-pca9532] Add gpio capability


> > +static int pca9532_gpio_direction_output(struct gpio_chip *gc,
> > unsigned offset, int val)
> > +{
> > + return 0;
> > +}
> > +
>
> Not good. When the pin is configured as an output, the direction_output method also
> requests that the pin be set to a desired level. For this driver that means that the
> pca9532_gpio_direction_output function just needs to call pca9532_gpio_set_value.

Ack, missed that. Thanks a lot!

--
Pengutronix e.K. | Wolfram Sang |
Industrial Linux Solutions | http://www.pengutronix.de/ |


Attachments:
(No filename) (585.00 B)
signature.asc (197.00 B)
Digital signature
Download all attachments