未加星标

Linux Device Tree Pinctrl Tutorial

字体大小 | |
[系统(linux) 所属分类 系统(linux) | 发布者 店小二05 | 时间 2019 | 作者 红领巾 ] 0人收藏点击收藏

Better Styled: http://blog.modest-destiny.com/posts/linux-device-tree-pinctrl-tutorial/

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:

Official Website for the Chip ( AM4379 Chip Webpage )

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

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

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:

You can get it from the github ( Linux source tree ) ( The Linux Kernel Archives ) You can get it in the SDK on chip's official website ( AM4379 Chip Webpage ) 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. In this file, it re-enables some devices based on the actual board's functionalities.

Note 1: 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.

Note 2 : Also, most of the kernel source code (written in C) listed in the blog is for reference only. I do not encourage beginners to dig deep in.

GPIO LED Practice

Since most of the functionalities one would like to edit is the GPIO (General Purpose Input Output) pins, 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.


Linux Device Tree Pinctrl Tutorial

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


Linux Device Tree Pinctrl Tutorial
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, aka. turning led D8 off.

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

// file: am4372.dtsi
gpio5: gpio@48322000 {
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";
led@0 {
label = "tl437x:green:heartbeat";
gpios = <&gpio5 9 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "heartbeat";
default-state = "off";
};
led@1 {
label = "tl437x:green:mmc0";
gpios = <&gpio5 8 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "mmc0";
default-state = "off";
};
led@2 {
label = "user-led0";
gpios = <&gpio5 10 GPIO_ACTIVE_HIGH>;
default-state = "on";
};
led@3 {
label = "user-led1";
gpios = <&gpio5 11 GPIO_ACTIVE_HIGH>;
default-state = "on";
};
led@4 {
label = "user-led2";
gpios = <&gpio5 12 GPIO_ACTIVE_HIGH>;
default-state = "on";
};
led@5 {
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 (PI

本文系统(linux)相关术语:linux系统 鸟哥的linux私房菜 linux命令大全 linux操作系统

代码区博客精选文章
分页:12
转载请注明
本文标题:Linux Device Tree Pinctrl Tutorial
本站链接:https://www.codesec.net/view/628258.html


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(linux) | 评论(0) | 阅读(199)