cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
xilinxlpc
Visitor
Visitor
5,675 Views
Registered: ‎03-01-2016

I can't control gpio in linux. Why?

Hi,

I can read and write emio register in u-boot with md.l and mw.l.

When I config the emio register in u-boot, I can control the gpio pin.

 

But when I mmap(APP) the 0xe000a000(emio base address), or ioremap(KERNEL DRIVER), I read the registers 0x00000000. Of cause, the gpio can't controlled by me.

 

What' wrong with it?

 

Thank you very much.

 

Regards,

Camille

0 Kudos
4 Replies
rfs613
Scholar
Scholar
5,484 Views
Registered: ‎05-28-2013

Hello Camille,

 

Can you try it using "devmem" utility. This command should already be installed on your system.

# devmem 0xe000a000
0x00000280

If this works, then it suggests some error in your application. You can look at the source code for devmem (http://free-electrons.com/pub/mirror/devmem2.c)

0 Kudos
xilinxlpc
Visitor
Visitor
5,046 Views
Registered: ‎03-01-2016

The emio can work normally after I must use "echo 960 > /sys/class/gpio/export" to create gpio960.

 

Have any ways to control the emio?

0 Kudos
rfs613
Scholar
Scholar
5,004 Views
Registered: ‎05-28-2013

Using the /sys/class/gpio method is one of many possible ways to access the GPIO. This makes use of a driver in the kernel, which accesses the same hardware registers at physical address 0xE000A000. The source code for this driver is available in the standard xilinx kernel tree.

 

I'm afraid I do not understand exactly what problem you are facing.

0 Kudos
h.alkan
Visitor
Visitor
539 Views
Registered: ‎12-03-2017

Hi,

I have encountered same problem, and I found the missing step.

Before access GPIO/EMIO register it will need set/update gpio clocks with set bit 22(GPIO_CPU_1XCLKACT) over APER_CLK_CTRL(0x0000012C) reg under  "System Level Control Registers(0xF8000000)".

uint32_t* sysctl = (uint32_t *)mmap(NULL, 0x1000, PROT_READ | PROT_WRITE, MAP_SHARED, fd_mem, (0xF8000000 & ~(0x1000 - 1)));
uint32_t* gpioclk = &sysctl[APER_CLK_CTRL>>2];

uint32_t clks = *gpioclk;
*gpioclk = clks|(1<<22);

 

Best regards