How could I configure a GPIO as an input?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

How could I configure a GPIO as an input?

ソリューションへジャンプ
5,097件の閲覧回数
janr_
Contributor I

Hello,

i have to figure out how to configure an gpio register as an input.

We use Linux verrsion 3.0.35_4.1.0_130816.

I think board_mx6q_sabresd.c and board_mx6q_sabresd.h are the most important files for the configuration.

I just want to understand where all these gpios are configuraed as inputs or outputs.

In the headerfile there is a MX6Q_PAD_GPIO_1_2. But I can't find these definition in the .c-file.

The names of the gpios seems to change from file to file and I don't know how to go on...

Then there is a gpio.txt, which says to use the gpio_input() and gpio_output() functions. However MX6Q_PAD_GPIO_1_2 is never used as a

parameter in one of these two funtions.

Looking forward to any help!

Jan

ラベル(1)
0 件の賞賛
返信
1 解決策
3,084件の閲覧回数
rickchu
Contributor IV

yes, in your example "MX6Q_PAD_GPIO_2_GPIO_1_2" means to configuration "PAD_GPIO_2" as an GPIO mode in GPIO bank 1, bit 2

If you trace in iomux-mx6q.h, you can found that PAD_GPIO_2 can be configuration to other function too.

#define  MX6Q_PAD_GPIO_2__ESAI1_FST \

#define  MX6Q_PAD_GPIO_2__OBSERVE_MUX_OBSRV_INT_OUT2 \

#define  MX6Q_PAD_GPIO_2__KPP_ROW_6 \

#define  MX6Q_PAD_GPIO_2__CCM_CCM_OUT_1 \

#define  MX6Q_PAD_GPIO_2__CSU_CSU_ALARM_AUT_0 \

#define  MX6Q_PAD_GPIO_2__GPIO_1_2 \

        (_MX6Q_PAD_GPIO_2__GPIO_1_2 | MUX_PAD_CTRL(NO_PAD_CTRL))

#define  MX6Q_PAD_GPIO_2__USDHC2_WP \

#define  MX6Q_PAD_GPIO_2__MLB_MLBDAT \

...

#define _MX6Q_PAD_GPIO_2__GPIO_1_2    \

    IOMUX_PAD(0x0604, 0x0234, 5, 0x0000, 0, 0)

=============================================================

If you look in iomux-v3.h, you can found what IOMUX_PAD() doing.

00.jpg

offset: 0x604

01.jpg
offset: 0x234

Rick

元の投稿で解決策を見る

0 件の賞賛
返信
6 返答(返信)
3,084件の閲覧回数
janr_
Contributor I

Thanks for your detailed answer.

Now I have found these entries:

iomux-mx6q.h

MX6Q_PAD_GPIO_2_GPIO_1_2               \

          IOMUX_PAD(0x0604, 0x0234, 5, 0x0000, 0, 0)

That seems right.

board-mx6q_sabresd.h

static iomux_v3_cfg_t mx6q_sabresd_pads[] = {

...

MX6Q_PAD_GPIO_2_GPIO_1_2.

...

}

That also seems right.

board-mx6q_sabresd.c


#define SABRESD_USR_DEF_RED_LED     IMX_GPIO_NR(1, 2)

Now, I think something like gpio:output(SABRESD_USR_DEF_RED_LED) has to follow in this file.

However there ist not such an entry. Actually it is configured as an output. We can see this due to the led.

Do you know why these function calls are missing?

if (gpio_request(SABRESD_TEST_PIN, "TEST PIN") < 0) {

    pr_err("%s() can't get TEST PIN", __func__);

}

gpio_direction_output(SABRESD_TEST_PIN, 1); // output high

or

gpio_direction_input(SABRESD_TEST_PIN); // input

Perhaps I have understood something wrong.

Thanks for your help.

0 件の賞賛
返信
3,084件の閲覧回数
rickchu
Contributor IV

Hi Jan,

"SABRESD_TEST_PIN" is an example not really in source code, sorry confuse you.

for your another question, you can found "SABRESD_BT_RESET" using the same GPIO define, and it has assigned to control Bluetooth.

#define SABRESD_BT_RESET                    IMX_GPIO_NR(1, 2)

#define SABRESD_USR_DEF_RED_LED    IMX_GPIO_NR(1, 2)

static void mx6q_sd_bt_reset(void)

{

    printk(KERN_INFO "mx6q_sd_bt_reset");

   gpio_request(SABRESD_BT_RESET, "bt-reset");

    gpio_direction_output(SABRESD_BT_RESET, 0);

    /* pull down reset pin at least >5ms */

    mdelay(6);

    /* pull up after power supply BT */

    gpio_direction_output(SABRESD_BT_RESET, 1);

    gpio_free(SABRESD_BT_RESET);

    msleep(100);

}

Rick

3,084件の閲覧回数
janr_
Contributor I

Hello,

thanks for your response.

It was my fault. Of course there is no gpio_request(TEST_PIN).

Actually I can't find  gpio_direction_output(SABRESD_USR_DEF_RED_LED).

Perhaps the initialization takes place in a different file?

- Jan

0 件の賞賛
返信
3,084件の閲覧回数
janr_
Contributor I

Concerning the first step:

1. set SoC PAD to GPIO mode in board_mx6q_sabresd.h

In the board_mx6q_sbresd.h, I can add a variable like "MX6Q_PAD_GPIO_2_GPIO_1_2" to an array.
Perhaps do you mean iomux-mx6q.h?


There I can configure it like this:

#define _MX6Q_PAD_GPIO_7_GPIO_1_7                     \

IOMUX_PAD(ox0610, 0x0240, 5, 0x0000, 0, 0)

0 件の賞賛
返信
3,085件の閲覧回数
rickchu
Contributor IV

yes, in your example "MX6Q_PAD_GPIO_2_GPIO_1_2" means to configuration "PAD_GPIO_2" as an GPIO mode in GPIO bank 1, bit 2

If you trace in iomux-mx6q.h, you can found that PAD_GPIO_2 can be configuration to other function too.

#define  MX6Q_PAD_GPIO_2__ESAI1_FST \

#define  MX6Q_PAD_GPIO_2__OBSERVE_MUX_OBSRV_INT_OUT2 \

#define  MX6Q_PAD_GPIO_2__KPP_ROW_6 \

#define  MX6Q_PAD_GPIO_2__CCM_CCM_OUT_1 \

#define  MX6Q_PAD_GPIO_2__CSU_CSU_ALARM_AUT_0 \

#define  MX6Q_PAD_GPIO_2__GPIO_1_2 \

        (_MX6Q_PAD_GPIO_2__GPIO_1_2 | MUX_PAD_CTRL(NO_PAD_CTRL))

#define  MX6Q_PAD_GPIO_2__USDHC2_WP \

#define  MX6Q_PAD_GPIO_2__MLB_MLBDAT \

...

#define _MX6Q_PAD_GPIO_2__GPIO_1_2    \

    IOMUX_PAD(0x0604, 0x0234, 5, 0x0000, 0, 0)

=============================================================

If you look in iomux-v3.h, you can found what IOMUX_PAD() doing.

00.jpg

offset: 0x604

01.jpg
offset: 0x234

Rick

0 件の賞賛
返信
3,084件の閲覧回数
rickchu
Contributor IV

Hi Jan,

To configuration a PAD to GPIO as an input or as an output mode, can follow up below steps:

1. set SoC PAD to GPIO mode in board_mx6q_sabresd.h

2. confirm which GPIO group and number belong to by check iMX6 datasheet or by Tool (IOMux Tool v3.2.1.0)

3. add new define in board_mx6q_sabresd.c

#define SABRESD_TEST_PIN    IMX_GPIO_NR(GPIO_GROUP, GPIO_NUMBER)

4. request GPIO by using kernel API

if (gpio_request(SABRESD_TEST_PIN, "TEST PIN") < 0) {

    pr_err("%s() can't get TEST PIN", __func__);

}

gpio_direction_output(SABRESD_TEST_PIN, 1); // output high

or

gpio_direction_input(SABRESD_TEST_PIN); // input

You can keep trace source code to get full picture in kernel source codes.

Hope this information help you.

Rick