How can I read the buttons and switches of the apalis eval board from u-boot?

I would like to read the buttons and switches of the apalis eval board in the u-boot prompt over the gpio commands. But I could not find the pin mapping for the corresponding pins in the datasheet docs.toradex.com/101028-apalis-evaluation-board-datasheet.pdf (just the mapping from the buttons and switches to the external connector X34 on page 41). I was also not able to find them in arch/arm/dts/tegra124-apalis.dts as well. How do I find the pin numbers which I need to reference with gpio input [gpio-number]?

How do I find the pin numbers which I need to reference with gpio input [gpio-number]?

One will need to find the actual GPIO number available on MXM3 pins.

e.g.:

To find the GPIO number available on MXM3 pin 37.

MXM3_pin: 37 → Pin_name: PEX_WAKE_N → GPIO instance: GPIO3_PDD.03 → Actual GPIO number: 235

Pin name and GPIO instance information are available in modules data sheet chapter4.4.
For more information also refer this article.

I believe @bhuvan.tx mixed up the module type. As you are targeting Apalis TK1 you would be looking at section 4.5 in the data sheet plus this article.

I’m sorry. Yes I mixed up the module type, the example I gave is for Apalis i.MX6. Will update my answer with relevant example.

Buttons, switches and LEDs are only connected to the X34 connector, if you want to access them from a module you’ll need to connect wires between X34 and other headers that connect to a module.

You can’t.

Have a look at the Evaluation Board schematics and/or datasheet.
The switches, buttons, and LED’s are routed to the X34. You will have to connect them to whatever GPIO you need them for your application.

Then you’re question boils down to how to access GPIOs from U-Boot.

Ok, I found the routing in the Apalis Evaluation Board v1.1a schematics on p. 30 for the buttons and switches. The switches SW1 to SW4 pull the signals SWTICH_1 to SWITCH_4 either to 3V3 or GND. The buttons SW5 to SW8 pull the signals BUITTON_1 to BUTTON_4 to 3V3 (they are pulled GND per default).

From connector X34 the signals need to be connected to corresponding signals (prefarably the GPIO ones MXM3_1 , _3, _7, _11, _13, _15, _17) at connector X2.

Ok, for the TK1 it works like follows:

Apalis TK1 datasheet, chapter “4.5 TK1 Functions List” → X1 Pin (MXM3_pin): 200 <-> TK1 Ball Name (Pin_name): DAP2_SCLK <-> GPIO (GPIO instance): GPIO3_PA.03 (A3) <-> Reset State: pd (pull down) <-> this TK1 specific article <-> Numeric Representation (Actual GPIO number): 3

Setting the pin as input:

Apalis TK1 # gpio input A3 
  gpio: pin A3 (gpio 3) value is 1

Checking if pin is configured as input:

Apalis TK1 # gpio status -a A3
  A3: input: 1 [ ]

When considering the article about how to read gpios from within u-boot, pulling pin 200 up to 3V3 (e.g. by connecting switch signal SW1 to connector X5, signal MXM3_200) an reading the pin level DOES WORK:

Apalis TK1 #  gpio input A3
  gpio: pin A3 (gpio 3) value is 1

THE FOLLOWING DOES NOT WORK:

Apalis TK1 #  gpio input 200
  gpio: pin 200 (gpio 200) value is 1

…this is probably because of the missing pin muxing configuration for 200/A3 in board/toradex/apalis-tk1/pinmux-config-apalis-tk1.h

I checked the configuration of the pin muxing in board/toradex/apalis-tk1/pinmux-config-apalis-tk1.h, added the following to the u-boot source

static const struct tegra_gpio_config apalis_tk1_gpio_inits[] = {
  ...
  GPIO_INIT(A,    2,   IN), /* TK1 pin 204 */
  GPIO_INIT(A,    3,   IN), /* TK1 pin 200 */
  ...
};

the following was already in the u-boot source (with input A1 for comparison)

static const struct pmux_pingrp_config apalis_tk1_pingrps[] = {
  ....
  PINCFG(UART3_CTS_N_PA1,        GMI,          NORMAL, TRISTATE, INPUT,   DEFAULT, DEFAULT),
  PINCFG(DAP2_FS_PA2,            HDA,          NORMAL, NORMAL,   INPUT,   DEFAULT, DEFAULT),
  PINCFG(DAP2_SCLK_PA3,          HDA,          NORMAL, NORMAL,   INPUT,   DEFAULT, DEFAULT),
  ...
};

, compiled u-boot, flashed u-boot onto the TK1 and tried it again.

gpio input 200 and gpio input 204 still do not work like expected. Do I have to change something in addition?

They work as expected. u-boot gpio command takes as an argument SoC gpio number according to the table here, not the edge connector pin number. For A3 it’s 3 and for A2 it’s 2 and for GPIO Z0 it’s 200. For convenience in u-boot you can also use GPIO name (like A3,A2, Z0) instead of a number as you’ve done with A3:

Apalis TK1 # gpio input A3 
   gpio: pin A3 (gpio 3) value is 1

u-boot automatically translated it to number 3

The pin 120 (A1) shows a changed state as well only when using gpio status -a A1 and not when using gpio input 120

Because A1 is a gpio number 1 not 120, 120 is a gpio P0

Thanks a lot. Works… Do I need to compile u-boot with addition of A2 and A3 (GPIO_INIT(A, 2, IN), , GPIO_INIT(A, 3, IN),) at all then?

If you’re only using them in u-boot command line, then no.

pin muxing not required, see comment How can I read the buttons and switches of the apalis eval board from u-boot? - #15 by dominik.tx - Technical Support - Toradex Community