cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Observer
Observer
4,433 Views
Registered: ‎11-11-2013

How to read the state of 8bits_gpio ? Why the gpio-demo read "all 1"?

     

Hi , all!

I test some codes on ML605 board.

I want to read the state of 8bits-leds. I have set the 8bits-leds to I/O in XPS env.

 

Here is a part of my gpio driver.

 

//initial function
phys = 0x40020000;
virt =(unsigned long )ioremap(phys, 0x10000);
GPBDAT = (unsigned long *)(virt + 0x00);
GPBCON = (unsigned long *)(virt + 0x04);
tmp &= 0x00000000; //00000000
writel(tmp,GPBDAT);
writel(tmp,GPBCON);

 

 
//ioctl function
 
writel(0xFF,GPBCON);//11111111b
mdelay(10);
tmp=readl(GPBDAT);//
printk("tmp_before=%d\n",tmp);//Why the number I got is always all 1 (0xFF) ? And when GPBCON=0x3f,then here is 0x3f
writel(0x00,GPBCON);//00000000b        
if(cmd==0) //
{
tmp &= (~(1<<arg));
}
else //
{
tmp |= (1<<arg); 
}
writel(tmp,GPBDAT);//
mdelay(10);
printk("tmp_GPBDAT=%d\n",tmp);

 

 

so why the GPBCON value affect the GPBDAT ? How should I configure the 3 state registers ?

 

But it work well when I just initial the GPBCON with 0x0. I can read and write the 8bits_leds by readl and writel function. Why ?

Why we needn't to set the direction (input or output ) of GPIOs before we use readl or writel to the data registers?

 

 

And then I run the gpio-demo.

 

 ~ # gpio-demo 
Usage: gpio-demo [-g GPIO_BASE] COMMAND 
where COMMAND is one of: 
-i Input value from GPIO and print it 
-o VALUE Output value to GPIO 
-c Cylon test pattern 
-k KIT test pattern 
GPIO_BASE indicates which GPIO chip to talk to (The number can be 
found at /sys/class/gpio/gpiochipN). 
The highest gpiochipN is the first gpio listed in the dts file, 
and the lowest gpiochipN is the last gpio listed in the dts file. 
E.g.If the gpiochip240 is the LED_8bit gpio, and I want to output '1' 
to the LED_8bit gpio, the command should be: 
gpio-demo -g 240 -o 1  

 

 

The number of ML605 8bits_leds is 248.

 

Whatever I write to 248 by gpio-demo -g 248 -o 0x**, the output of "gpio-demo -g 248 -i" is 0xFF. Why ?

 

Thanks. Please help me .

 

0 Kudos
Reply
2 Replies
Highlighted
Anonymous
Not applicable
4,421 Views

Can you try use the example driver code in the install directory? There is example code to init the gpio ip, and allow you to set the gpio direction. Can you try this?
0 Kudos
Reply
Highlighted
Observer
Observer
4,394 Views
Registered: ‎11-11-2013

Thanks. I will have a try. But why the gpio-demo read the GPIO "all 1" ? This program has the  considered the direction. 

0 Kudos
Reply