AnsweredAssumed Answered

Is gpio_get_value() working correctly?

Question asked by Ed Sutter on Dec 11, 2013
Latest reply on Dec 11, 2013 by Ed Sutter

I'm working with u-boot-2013.10 with an iMX6D based board and just noticed something odd about the gpio_get_value() function in drivers/gpio/mxc_gpio.c (or maybe its just that I don't fully understand the difference between the PSR and DR GPIO control registers)...

 

I have a couple of LEDs on my board connected to GPIO pins.  I just wrote a test function to blink those LEDs.  I first retrieve the current state using gpio_get_value(), then I change the state for the test using gpio_set_value()  and finally I restore the state back to each pin that I originally read.  Turns out that didn't work (it doesn't  restore the state).  Looking closer at the function, I see that it retrieves the bit from the PSR (pad status register); but it appears that this register should only be used on GPIO bits that are programmed as inputs.  When I changed this function to use the DR (data register), then it properly returned the status of the GPIO bit I was interested in.

 

So, it seems to me that the gpio_get_value() function should actually use DR for requests of bits that are programmed as

GPIO output, and PSR for requests of bits that are programmed as GPIO input. 

 

Does that make sense?

Ed

Outcomes