Skip to main content

Finding Pinctrl Offsets of Particular Devices for Linux Device Tree

When porting drivers on a specific board for a comparatively new linux kernel, it is common to edit the linux device tree files to put together all the device configurations with register values, working modes and pin control offsets set to expected values.

Here in this post we focus on the exact steps one needs to find the correct pin control offset for specific devices. Here we'd take TI's AM4379 (AM437x) chip as an example for this tutorial.

Preparation

We need the following documents available in hand:

  1. Official Website for the Chip (AM4379 Chip Webpage)

  2. Processor Datasheet (AM437x Sitara™ Processors datasheet (Rev. D))

  3. TRM (the Technical Reference Manual) (AM437x and AMIC120 ARM® Cortex™-A9 Processors Technical Reference Manual (Rev. H))

  4. The Schematic Diagram for the Development Board

    • You might get it from the website where you bought the development board
    • You might get it from the hardware engineer colleagues in your office

We need a Linux kernel source tree that you aim for porting:

Understanding What Device Tree is

Before getting your hands dirty on editing your own device tree, you must get a glance on what device tree is and what it is for.

There're some information available in eLinux Wiki (Device Tree Reference).

Further, you might want the spec in hand where you may get it from Devicetree org's github repo.

(Maybe I'll take some time to write something about it in another blog post.)

Locate the Device Tree Code in SDK/Kernel

Here we use the SDK's kernel source tree, which pinned at Linux kernel 3.14 release.

The SDK's kernel is edited and added the am437x-gp-evm devboard device tree which we'll start from here.

Let's first locate the device tree files related to the devboard in /arch/arm/boot/dts directory:

Filename Description
skeleton.dtsi The bare minimum device tree.
am4372.dtsi The AM4372 SoC Chip Device Tree. Should be included for all devboards that use AM437x chip.
am437x-gp-evm.dts The example devboard model's device tree file from TI.

Note: file am437x-gp-evm.dts is only available in SDK's kernel source tree, but not available from kernel archive.

Read the Device Tree Code

You may take the am437x-gp-evm model as a good starting point to port to your own AM4379 board which suits your needs.

Let's take a quick glance on am4372.dtsi file. The purpose of the file is to define the capability of the SoC chip while most of the functionalities are disabled by default.

Then, one should write a devboard model specific file which configures the devices in need which comes to the am437x-gp-evm.dts file.

Note: There're also some other models based on AM437x SoC chip provided by TI including am437x-gp-easyevm.dts, am437x-gp-evm-captouch.dts, am437x-gp-evm-fpga-emmc.dts, am437x-gp-evm-fpga-nandflash.dts, am437x-gp-evm-hdmi.dts, am437x-sk-evm.dts, etc. They can also be reference starting point as well.

GPIO LED

Since most of the functionalities one would like to edit is the GPIO (General Purpose Input Output) pins, so let's first start off by turning off a LED on a board on boot.

 

Aim: Turn off led D8 on boot by default.

 

The default device tree configuration turns on all the user leds when the board boots.

User Leds Default DTS Boot

 

Let's take a look at the led circuits in the schematic diagram.

User Leds Schematic Diagram

It shows that if you pull up the GPIO pin, the corresponding green led lightens, and vice versa. Therefore, we just need to setup GPIO5[10] to "pull down mode" to match our aim, turning led "D8" off.

 

Let's collect some information available in device tree source files.

// file: am4372.dtsi
gpio5: [email protected] {
    compatible = "ti,am4372-gpio","ti,omap4-gpio";
    reg = <0x48322000 0x1000>;
    interrupts = <GIC_SPI 148 IRQ_TYPE_LEVEL_HIGH>;
    gpio-controller;
    #gpio-cells = <2>;
    interrupt-controller;
    #interrupt-cells = <2>;
    ti,hwmods = "gpio6";
    status = "disabled";
};
// file: am437x-gp-evm.dts
leds {
  pinctrl-names = "default", "sleep";
  pinctrl-0 = <&user_leds_default>;
  pinctrl-1 = <&user_leds_sleep>;

  compatible = "gpio-leds";

  [email protected] {
    label = "tl437x:green:heartbeat";
    gpios = <&gpio5 9 GPIO_ACTIVE_HIGH>;
    linux,default-trigger = "heartbeat";
    default-state = "off";
  };

  [email protected] {
    label = "tl437x:green:mmc0";
    gpios = <&gpio5 8 GPIO_ACTIVE_HIGH>;
    linux,default-trigger = "mmc0";
    default-state = "off";
  };

  [email protected] {
    label = "user-led0";
    gpios = <&gpio5 10 GPIO_ACTIVE_HIGH>;
    default-state = "on";
  };

  [email protected] {
    label = "user-led1";
    gpios = <&gpio5 11 GPIO_ACTIVE_HIGH>;
    default-state = "on";
  };

  [email protected] {
    label = "user-led2";
    gpios = <&gpio5 12 GPIO_ACTIVE_HIGH>;
    default-state = "on";
  };

  [email protected] {
    label = "user-led3";
    gpios = <&gpio5 13 GPIO_ACTIVE_HIGH>;
    default-state = "on";
  };
};

user_leds_default: user_leds_default {
  pinctrl-single,pins = <
    0x238 (PIN_OUTPUT_PULLUP | MUX_MODE7)	/* gpio5_8.gpio5_8 */
    0x23c (PIN_OUTPUT_PULLUP | MUX_MODE7)	/* gpio5_9.gpio5_9 */
    0x240 (PIN_OUTPUT_PULLUP | MUX_MODE7)	/* gpio5_10.gpio5_10 */
    0x244 (PIN_OUTPUT_PULLUP | MUX_MODE7)	/* gpio5_11.gpio5_11 */
    0x248 (PIN_OUTPUT_PULLUP | MUX_MODE7)	/* gpio5_12.gpio5_12 */
    0x24c (PIN_OUTPUT_PULLUP | MUX_MODE7)	/* gpio5_13.gpio5_13 */
  >;
};

user_leds_sleep: user_leds_sleep {
  pinctrl-single,pins = <
    0x238 (PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpio5_8.gpio5_8 */
    0x23c (PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpio5_9.gpio5_9 */
    0x240 (PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpio5_10.gpio5_10 */
    0x244 (PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpio5_11.gpio5_11 */
    0x248 (PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpio5_12.gpio5_12 */
    0x24c (PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpio5_13.gpio5_13 */
  >;
};

&gpio5 {
    status = "okay";
    ti,no-reset-on-init;
};

 

The gpio5 definition in am4372.dtsi file shows

 

Comments

Comments powered by Disqus