Skip to contentSkip to conversation

Problems when accessing to registers in GPIO

DISCUSSION A. Nolson 1 participant 1 message Mar 1, 2008

lore
Share & tools
lore

A. Nolson

author
#0 lore raw

Hi,

I am getting some problems when trying to access to the GPIO registers from the userland of my secretlab's linux 2.6.24-rc3 ( Xilinx ML403 ). I am using io_remap() functions ( from http://www.denx.de/wiki/bin/view/PPCEmbedded/DeviceDrivers ) and I was successfully able to test them with some own-made IP cores. However, I am having problems when trying to do it in the same way with the GPIO IP core from Xilinx ( the ones I am using to interface to the LEDs , buttons and LCD ).

If I try to access to the buttons in the board I don't really have any problem since the tri-state control register is automatically set to "all inputs" when the IP is turned on. But when I try to use the LEDs and I need to configure the tris-state as outputs, they don't work . I am doing the following:

   //memory mapping
   if(    (led_base = (volatile int*) ioremap(BASE_GPIO,8)) == NULL ||
           (but_base = (volatile int*) ioremap(BASE_GPIO_B, 8)) == NULL )
   {
       perror( "Cannot allocate memory for GPIO/n");
       return 1;
   }
    
   led_tri = (char*)led_base + 0x4;
   but_tri = (char*)but_base + 0x4;

   //configure as inputs and outputs
   printf("configuring IOs...");
   *led_tri = 0x00;//configure them as outputs
   *but_tri = 0xFF;//configure them as inputs

while(1)

   {
       data = *but_base;
//     printf("data:%x\n",data);
      *led_base = data;
      usleep(50000);

}

If I try to allocate the tri-state registers as integer I get "Bus Error" when accessing to them. I don't know really what is the problem. If I try to the same without operating system, this is, directly using XPS, I manage to make the buttons and leds work perfectly. Anybody can help me with this?

/A