Google Groups

Re: GPIO use


lon...@gmail.com May 1, 2012 8:26 PM
Posted in group: pandaboard
Hi 
There are 2 things you have to take care when using GPIO.
- The GPIO chip itself
- The mux which control the actual ball/pin will route to GPIO or other peripherals (SPI, I2C...)

Inside the OMAP4 there are 6 GPIO chips each has 32 GPIO (=> total 192 GPIOs). 
Linux only care about the GPIO NUMBER. 6 GPIO chips inside OMAP will register GPIO number from 1 to 192 (AFAIK).
(GPIO_135 belong to chip 5)
Each GPIO_n in Linux has a struct name: struct gpio_desc.
struct gpio_desc {
struct gpio_chip *chip;
unsigned long flags;
/* flag symbols are bit numbers */
#define FLAG_REQUESTED 0
#define FLAG_IS_OUT 1
#define FLAG_RESERVED 2
#define FLAG_EXPORT 3 /* protected by sysfs_lock */
#define FLAG_SYSFS 4 /* exported via /sys/class/gpio/control */
#define FLAG_TRIG_FALL 5 /* trigger on falling edge */
#define FLAG_TRIG_RISE 6 /* trigger on rising edge */
#define FLAG_ACTIVE_LOW 7 /* sysfs value has active low */

#define ID_SHIFT 16 /* add new flags before this one */

#define GPIO_FLAGS_MASK ((1 << ID_SHIFT) - 1)
#define GPIO_TRIGGER_MASK (BIT(FLAG_TRIG_FALL) | BIT(FLAG_TRIG_RISE))

#ifdef CONFIG_DEBUG_FS
const char *label;
#endif
};

/sys/kernel/debug/gpio is actually show you the current value the struct gpio_desc of GPIO_n
you see it's configured as input because the bit 1 the flag is not set. (FLAG_IS_OUT)
to set enable chip output you may do: 
ECHO 135 > /sys/class/gpio/export  /* this will call the function [int gpio_request(unsigned gpio, const char *label)] this function will call to the specific omap's chip function [ &gpio_desc[135]->chip->request(chip, gpio - chip->base) ] this will set the bit in the OMAP4_GPIO_CTRL register to enable the clock for GPIO chip 5 ---> clock for chip 5 will be enable (if it's initially disable) */

ECHO "out" > /sys/class/gpio/gpio135/direction  // this will call [ int gpio_direction_output(unsigned gpio, int value) ] --> set flag FLAG_IS_OUT --->  &gpio_desc[135]->chip->direction_output(chip, gpio, value) ---> set the corresponding bit in the register GPIO_EN of chip 5 to actually enable the pin for out put
 
the result of the 2 above command is you will enable the clock for GPIO chip 5 and set the both the FLAG_IS_OUT in the &gpio_desc[135] and the corresponding bit in GPIO_EN  

BUT, the mux is not configured to route GPIO chip to the actual pin/ball after the 2 command. So you also have to configure the mux mode 3 and output enable. (as already pointed out)



On Saturday, April 21, 2012 9:29:01 AM UTC+8, Prajwal Upadhya wrote:
Hi,
 We are trying to set the GPIO135 available on the (pin 18)J3
expansion
header. We have deployed the android ice cream sandwich on the panda
board.

 For this we have added the line "OMAP4_MUX(MCSPI1_SOMI,
OMAP_MUX_MODE3 | OMAP_PIN_OUTPUT)" in the struct omap_board_mux
board_mux[] of board-omap4panda.c.

 This struct contains all the pin mux configurations. This change does
not seem to let us control the status (High/Low) of the pin. We were
wondering if anybody could point out the extra changes (if any) that
need to be done in order to configure the pin as an output pin.

Also, when we do a cat /sys/kernel/debug/gpio we see this.

GPIOs 0-31, gpio:
 gpio-0   (DVI PD              ) out hi
 gpio-1   (hub_power           ) out hi

GPIOs 32-63, gpio:
 gpio-39  (nfc_int             ) in  lo
 gpio-41  (hdmi_gpio_ls_oe     ) out hi
 gpio-43  (vwl1271             ) out hi
 gpio-46  (kim                 ) out hi
 gpio-60  (hdmi_gpio_hpd       ) out hi
 gpio-62  (hub_nreset          ) out hi
 gpio-63  (?                   ) in  lo

GPIOs 64-95, gpio:

GPIOs 96-127, gpio:
 gpio-127 (audpwron            ) out lo

GPIOs 128-159, gpio:
 gpio-134 (nfc_firm            ) in  lo
 gpio-135 (nfc_ven             ) in  lo

GPIOs 160-191, gpio:

The pin (GPIO135) is registered as an input pin instead as an output
pin as configured by the mux configuration mentioned earlier. We are
not sure y this is happening. It would be very helpful if anyone can
guide us.

On Mar 26, 9:11 pm, David Anders <danders....@gmail.com> wrote:
> samsounda,
>
> please review the docs on compile linux kernel for pandaboard.
>
> Dave
>
> On Mar 26, 10:14 pm, samsounda...@gmail.com wrote:
>
>
>
>
>
>
>
> > I am having the same problem. I changed the files as you mentioned but what
> > do I do from here? How do I get the file compiled and installed?
>
> > On Wednesday, March 14, 2012 2:14:40 PM UTC-5, qua...@gmail.com wrote:
>
> > > *Mux probably means "Pins Multiplexing"*
>
> > > see:* *http://elinux.org/BeagleBoardPinMux
>
> > > Details of OMAP35x PinMux can be found in OMAP35x Applications Processor
> > > TRM <http://www.ti.com/lit/ug/spruf98u/spruf98u.pdf> (spruf98u.pdf) in
> > > section *7.4.4.3 Pad Multiplexing Register Fields* (page 782)
>
> > > I created initalization part forGPIO. When I tried to showGPIOstatus
> > > via "cat /sys/kernel/debug/gpio" I saw this:
>
> > > GPIOs 32-63,gpio:
>
> > >gpio-32 (pandaboard_exp_menu ) in hi
>
> > >gpio-33 (pandaboard_exp_volup) in hi
>
> > >gpio-36 (pandaboard_exp_power) in hi
>
> > >gpio-37 (pandaboard_exp_voldw) in lo
>
> > >gpio-38 (pandaboard_exp_back ) in lo
>
> > > I was not able to controlgpio-37 andgpio-38 (low state).
>
> > > If you have some similar problem with addressing ofGPIOyou must add some
> > > snipped to board-omap4panda.c file.*
> > > *
>
> > >  find (board-omap4panda.c):
>
> > > #ifdef CONFIG_OMAP_MUX
>
> > > static struct omap_board_mux board_mux[] __initdata = {
>
> > >  and append code like this:
>
> > >  * */**GPIOExpansion board */
>
> > > // AD12 -GPIO36 - HOME
>
> > > OMAP4_MUX(GPMC_AD12, OMAP_PIN_INPUT | OMAP_MUX_MODE3),
>
> > > // AD08 -GPIO32 - MENU
>
> > > OMAP4_MUX(GPMC_AD8, OMAP_PIN_INPUT | OMAP_MUX_MODE3),
>
> > > // AD14 -GPIO38 - BACK
>
> > > OMAP4_MUX(GPMC_AD14, OMAP_PIN_INPUT | OMAP_MUX_MODE3),
>
> > > // AD09 -GPIO33 - VOLUME_UP
>
> > > OMAP4_MUX(GPMC_AD9, OMAP_PIN_INPUT | OMAP_MUX_MODE3),
>
> > > // AD13 -GPIO37 - VOLUME_DOWN
>
> > > OMAP4_MUX(GPMC_AD13, OMAP_PIN_INPUT | OMAP_MUX_MODE3),
>
> > > Note: This snipped is from my configuration for chipsee expansion board.

On Saturday, April 21, 2012 9:29:01 AM UTC+8, Prajwal Upadhya wrote:
Hi,
 We are trying to set the GPIO135 available on the (pin 18)J3
expansion
header. We have deployed the android ice cream sandwich on the panda
board.

 For this we have added the line "OMAP4_MUX(MCSPI1_SOMI,
OMAP_MUX_MODE3 | OMAP_PIN_OUTPUT)" in the struct omap_board_mux
board_mux[] of board-omap4panda.c.

 This struct contains all the pin mux configurations. This change does
not seem to let us control the status (High/Low) of the pin. We were
wondering if anybody could point out the extra changes (if any) that
need to be done in order to configure the pin as an output pin.

Also, when we do a cat /sys/kernel/debug/gpio we see this.

GPIOs 0-31, gpio:
 gpio-0   (DVI PD              ) out hi
 gpio-1   (hub_power           ) out hi

GPIOs 32-63, gpio:
 gpio-39  (nfc_int             ) in  lo
 gpio-41  (hdmi_gpio_ls_oe     ) out hi
 gpio-43  (vwl1271             ) out hi
 gpio-46  (kim                 ) out hi
 gpio-60  (hdmi_gpio_hpd       ) out hi
 gpio-62  (hub_nreset          ) out hi
 gpio-63  (?                   ) in  lo

GPIOs 64-95, gpio:

GPIOs 96-127, gpio:
 gpio-127 (audpwron            ) out lo

GPIOs 128-159, gpio:
 gpio-134 (nfc_firm            ) in  lo
 gpio-135 (nfc_ven             ) in  lo

GPIOs 160-191, gpio:

The pin (GPIO135) is registered as an input pin instead as an output
pin as configured by the mux configuration mentioned earlier. We are
not sure y this is happening. It would be very helpful if anyone can
guide us.

On Mar 26, 9:11 pm, David Anders <danders....@gmail.com> wrote:
> samsounda,
>
> please review the docs on compile linux kernel for pandaboard.
>
> Dave
>
> On Mar 26, 10:14 pm, samsounda...@gmail.com wrote:
>
>
>
>
>
>
>
> > I am having the same problem. I changed the files as you mentioned but what
> > do I do from here? How do I get the file compiled and installed?
>
> > On Wednesday, March 14, 2012 2:14:40 PM UTC-5, qua...@gmail.com wrote:
>
> > > *Mux probably means "Pins Multiplexing"*
>
> > > see:* *http://elinux.org/BeagleBoardPinMux
>
> > > Details of OMAP35x PinMux can be found in OMAP35x Applications Processor
> > > TRM <http://www.ti.com/lit/ug/spruf98u/spruf98u.pdf> (spruf98u.pdf) in
> > > section *7.4.4.3 Pad Multiplexing Register Fields* (page 782)
>
> > > I created initalization part forGPIO. When I tried to showGPIOstatus
> > > via "cat /sys/kernel/debug/gpio" I saw this:
>
> > > GPIOs 32-63,gpio:
>
> > >gpio-32 (pandaboard_exp_menu ) in hi
>
> > >gpio-33 (pandaboard_exp_volup) in hi
>
> > >gpio-36 (pandaboard_exp_power) in hi
>
> > >gpio-37 (pandaboard_exp_voldw) in lo
>
> > >gpio-38 (pandaboard_exp_back ) in lo
>
> > > I was not able to controlgpio-37 andgpio-38 (low state).
>
> > > If you have some similar problem with addressing ofGPIOyou must add some
> > > snipped to board-omap4panda.c file.*
> > > *
>
> > >  find (board-omap4panda.c):
>
> > > #ifdef CONFIG_OMAP_MUX
>
> > > static struct omap_board_mux board_mux[] __initdata = {
>
> > >  and append code like this:
>
> > >  * */**GPIOExpansion board */
>
> > > // AD12 -GPIO36 - HOME
>
> > > OMAP4_MUX(GPMC_AD12, OMAP_PIN_INPUT | OMAP_MUX_MODE3),
>
> > > // AD08 -GPIO32 - MENU
>
> > > OMAP4_MUX(GPMC_AD8, OMAP_PIN_INPUT | OMAP_MUX_MODE3),
>
> > > // AD14 -GPIO38 - BACK
>
> > > OMAP4_MUX(GPMC_AD14, OMAP_PIN_INPUT | OMAP_MUX_MODE3),
>
> > > // AD09 -GPIO33 - VOLUME_UP
>
> > > OMAP4_MUX(GPMC_AD9, OMAP_PIN_INPUT | OMAP_MUX_MODE3),
>
> > > // AD13 -GPIO37 - VOLUME_DOWN
>
> > > OMAP4_MUX(GPMC_AD13, OMAP_PIN_INPUT | OMAP_MUX_MODE3),
>
> > > Note: This snipped is from my configuration for chipsee expansion board.