Re: [leds-pca9532] Add gpio capability

From: H Hartley Sweeten
Date: Mon Jan 31 2011 - 18:57:01 EST


>>>> + if (gpios) {
>>>> + data->gpio.label = "gpio-pca9532";
>>>> + data->gpio.set = pca9532_gpio_set_value;
>>>> + data->gpio.get = pca9532_gpio_get_value;
>>>> + data->gpio.request = pca9532_gpio_request_pin;
>>>> + data->gpio.can_sleep = 1;
>>>> + data->gpio.base = pdata->gpio_base;
>>>> + data->gpio.ngpio = 16;
>>>> + data->gpio.dev = &client->dev;
>>>> + data->gpio.owner = THIS_MODULE;
>>>
>>> I'd assume that you also need to define a direction_output-function which
>>> always
>>> returns success?
>>
>> Yes, you are right. It is not possible to set direction in hw, but I
>> should provide them.
>
> It should be okay to skip direction_input, because gpiolib will return an error
> if it is not available. This is exactly why IMO you need a direction_output
> returning 0. Otherwise drivers checking if that operation was successful, might
> be fooled.

From the datasheet:


6.4 Pins used as GPIOs

LEDn pins not used to control LEDs can be used as General Purpose I/Os (GPIOs).

To use as input, set LEDn to high-impendance (00) and then read the pin state
via the INPUT0 or INPUT1 register.

For use as output, connect external pull-up resistor to the pin and size it
according to the DC recommended operating characteristics. LEDn output is HIGH
when the output is programmed as high-impedance, and LOW when programmed LOW
through the 'LED selector' register. The output can be pulse-width controlled
when PWM0 or PWM1 are used.


So, you should provide both a direction_input and direction_output.

Regards,
Hartley
èº{.nÇ+‰·Ÿ®‰­†+%ŠËlzwm…ébëæìr¸›zX§»®w¥Š{ayºÊÚë,j­¢f£¢·hš‹àz¹®w¥¢¸ ¢·¦j:+v‰¨ŠwèjØm¶Ÿÿ¾«‘êçzZ+ƒùšŽŠÝj"ú!¶iO•æ¬z·švØ^¶m§ÿðà nÆàþY&—