How do I read GPIO pins in linux on imx27?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

How do I read GPIO pins in linux on imx27?

跳至解决方案
2,898 次查看
perda
Contributor I
Hi,

I have added support for a touch-screen using an ADS7843. The interface to the SPI bus is ok with allot of ugly tweaks to spi and ads7846 code :smileysad:. Some code is stolen and some is made using allot of looking into an oscilloscope.
The driver kind of works now except I am not able to read the gpio-pin (MX27_PIN_PC_BVD2) I get the pen-down interrupt from. The interrupts comes every time I touch the screen but the function mxc_get_gpio_datain(MX27_PIN_PC_BVD2) always returns 0.
Is there any other way that I should read the gpio-pin? I haven't found any code for the imx27 that uses the mxc_get_gpio_datain, should I use some other gpio function?

Here is some of my code:

mx27ads.c:
...
static int mx27_ads7846_pendown_state(void)
{
 return !mxc_get_gpio_datain(MX27_PIN_PC_BVD2);
}

static struct ads7846_platform_data ads_info = {
 .model   = 7843,
        .vref_delay_usecs = 100,
 .x_max          = 0x0fff,
 .y_max          = 0x0fff,
 .x_plate_ohms  = 440,
 .y_plate_ohms  = 250,
 .get_pendown_state = mx27_ads7846_pendown_state,
};

static struct spi_board_info mxc_spi_board_info[] __initdata = {
 {
  .modalias = "ads7846",
  .platform_data = &ads_info,
  .irq = IOMUX_TO_IRQ(MX27_PIN_PC_BVD2),
  .max_speed_hz = 500000,
  .bus_num = 1,
  .chip_select = 0,
  .mode = 0,
  },
};

...

mx27ads_gpio.c:
...
void gpio_spi_active(int cspi_mod)
{
 switch (cspi_mod) {
 case 0:
  /* SPI1 */
  gpio_request_mux(MX27_PIN_CSPI1_MOSI, GPIO_MUX_PRIMARY);
  gpio_request_mux(MX27_PIN_CSPI1_MISO, GPIO_MUX_PRIMARY);
  gpio_request_mux(MX27_PIN_CSPI1_SCLK, GPIO_MUX_PRIMARY);
  gpio_request_mux(MX27_PIN_CSPI1_RDY, GPIO_MUX_PRIMARY);
  gpio_request_mux(MX27_PIN_CSPI1_SS0, GPIO_MUX_PRIMARY);
  gpio_request_mux(MX27_PIN_CSPI1_SS1, GPIO_MUX_PRIMARY);
  gpio_request_mux(MX27_PIN_CSPI1_SS2, GPIO_MUX_PRIMARY);
  gpio_config_mux(MX27_PIN_PC_BVD2, GPIO_MUX_GPIO);
  mxc_set_gpio_direction(MX27_PIN_PC_BVD2, 1);

  break;
 case 1:
...

 
br,
Per
0 项奖励
回复
1 解答
744 次查看
perda
Contributor I
I have got a response from Freescale's Technical Support that solved my problem. The response is below:


There is Bugzilla #1253 (about using the PSR instead of the DR) (that should to be corrected in n ext BSP releases).

In the file arch/arm/plat-mxc/gpio.c the last line of the function mxc_get_gpio_datain should be :

return (__raw_readl(port->base + GPIO_PSR) >> GPIO_TO_INDEX(gpio)) & 1;

(using GPIO_PSR instead of GPIO_DR)

Note : for i.MX31 it is allowed to use DR instead of PSR, but for i.MX27 this causes bugs, because DR register does not reflect real input signal state.


/per

在原帖中查看解决方案

0 项奖励
回复
1 回复
745 次查看
perda
Contributor I
I have got a response from Freescale's Technical Support that solved my problem. The response is below:


There is Bugzilla #1253 (about using the PSR instead of the DR) (that should to be corrected in n ext BSP releases).

In the file arch/arm/plat-mxc/gpio.c the last line of the function mxc_get_gpio_datain should be :

return (__raw_readl(port->base + GPIO_PSR) >> GPIO_TO_INDEX(gpio)) & 1;

(using GPIO_PSR instead of GPIO_DR)

Note : for i.MX31 it is allowed to use DR instead of PSR, but for i.MX27 this causes bugs, because DR register does not reflect real input signal state.


/per
0 项奖励
回复