[U-Boot] [PATCH 0/2] arm nomadik: gpio and i2c

Heiko Schocher hs at denx.de
Mon Jul 20 11:23:51 CEST 2009


Hello Alessandro,

Alessandro Rubini wrote:
>> Agreed. So we need an gpio_core.c / .h which defines the following
>> functions (just a proposal):
> 
> Yes.
> 
>> typedef struct gpio_adapter {
>> 	int	(*init_pin)(int pin);
>> 	int	(*set)(int pin, value);
>> 	int	(*get)(int pin);
>> 	int	(*dir)(int pin, int direction);	
>> 	int	(*level)(int pin, int level);
>> }
> 
> I don't understand the init_pin function, nor what "level" is.

init_pin:
  you call this function, if you want to use this pin as an gpio.
  (BTW: init pin should look like this,
    changing init_pin(pin, dir, value);
      with value only used if setting it as an output)
  functionality:
    - Setup the GPIO registers for using this pin as GPIO
    - Maybe setting a marker in the gpio_core, that this pin is usable
      now for gpio. This marker can be checked in the other functions,
      which use this pin ...

level:
  we can set the output level with this function directly ... ok,
  not really needed ... but maybe nice to have ... if thinking for
  the i2c bitbang driver, we save on all set() calls the output
  settings ... maybe more then one register changes, if switching
  between input/output ...

> Actually, even "dir" can be dropped: a get configures as input, a set
> configures as output, the extra instruction is very little overhead.

See my comment above. I just like the idea, that a user can control this
separately.

> But an alternate function configuration is definitely needed: everybody
> has alternate functions associated to the pins. Just say "0" is gpio
> and 1...n is SoC-specific.

what with deinit_pin(pin, function)? That would be in shape with init_pin()?

(There, we could also unset the marker, that this pin is no longer used
for gpio ...)

> So, are you going to write it? Or should someone else do that?

Hmm... if nobody else volunteers, maybe I find time for it ... but I
think, there should be more ratings, if this is a way to go ... also,
if we make a gpio_core, would we have some commands for it (show
status of gpios, directly access the gpios per commandshell, ...)?

Also, a board can have more then one gpio adapter, how we address
such a case?

Just a fast thought about that:
- adding to typedef struct gpio_adapter also a "name" field
- allow to register more than one gpio adapter
- addressing the different adapters through an int ... called gpio_device?

So the core functions look something like that:

int gpio_init(gpio_adap *adap); (returns a int gpio_device)

int gpio_init_pin(gpio_device, pin, dir, value);
int gpio_set(gpio_device, pin, value)
int gpio_get(gpio_device, pin)
int gpio_dir(gpio_device, pin, dir)
int gpio_level(gpio_device, pin, level)

bye
Heiko
-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany


More information about the U-Boot mailing list