1. 程式人生 > >how to port 2.6.x driver to 4.x --關於pinctl 和GPIO

how to port 2.6.x driver to 4.x --關於pinctl 和GPIO

在2.6.x的程式碼裡面對於PIN腳複用都是在對應的晶片的broad code裡面進行配置的,直接呼叫相關的特有API去設定。如我使用的AT91 MSA9260裡面的at91_set_GPIO_periph()用於設定一個PIN為GPIO的模式,at91_set_A_periph() 用於設定一個PIN為A mode。而且每家chip廠商提供的風格和形式都不相同。在3.x之後的程式碼裡面kernel引入了pinctl的驅動,對這些進行了更好的設計:

PINCTRL (PIN CONTROL) subsystem

This document outlines the pin control subsystem in Linux

This subsystem deals with:

- Enumerating and naming controllable pins

- Multiplexing of pins, pads, fingers (etc) see below for details

- Configuration of pins, pads, fingers (etc), such as software-controlled

  biasing and driving mode specific pins, such as pull-up/down, open drain,

  load capacitance etc. 

這些描述是來自kernel的document裡面的(pinctrl.txt)根據我的時間,我認為它可以更好的和DTS工作,更好的和GPIO工作,使得GPIO的API更加通用,這樣我們自己寫的驅動呼叫GPIO的部分就不用去區別不同的chip廠家了。
比如我們配置PINB17為GPIO mode:

gpio0 {
pinctrl_gpio0: gpio0-0 {
atmel,pins =
<AT91_PIOB 16 AT91_PERIPH_B GPIO_ACTIVE_LOW/* CAN reset active Low */
AT91_PIOB 17 AT91_PERIPH_B GPIO_ACTIVE_HIGH>;/* CAN Power active High */
};

usart2: [email protected] {
/* ttyS3 -- RS485 */
/* DTR HW/SW enabled/disabled from userspace using ioctl */
linux,rs485-enabled-at-boot-time; /* enable RS485 mode in the bootup */
dtr-gpios = <&pioB 17 0>;  /*xxx, the AT91_PIN_PB17 is a dtr control signal. */
status = "okay";
};

然後我們在我們的驅動程式碼裡面只需要呼叫對應的GPIO 通用介面,如:

gpio_is_valid(int number);

/* set as input or output, returning 0 or negative errno */
int gpio_direction_input(unsigned gpio);
int gpio_direction_output(unsigned gpio, int value);

/* GPIO INPUT:  return zero or nonzero */
int gpio_get_value(unsigned gpio);

/* GPIO OUTPUT */
void gpio_set_value(unsigned gpio, int value);

這樣我們的驅動的程式碼就不用在意不同的chip廠商不同的實現了。是需要把專案的DTS配置好,程式碼的移植性可想而知了。
Note:kernel裡面的document檔案時非常有用的資料,特別是在我們從低版本的kernel升級到高版本時,很多變化我們都是可以從這裡得到最權威的資訊的。

相關推薦

how to port 2.6.x driver to 4.x --關於pinctl GPIO

在2.6.x的程式碼裡面對於PIN腳複用都是在對應的晶片的broad code裡面進行配置的,直接呼叫相關的特有API去設定。如我使用的AT91 MSA9260裡面的at91_set_GPIO_periph()用於設定一個PIN為GPIO的模式,at91_set_A_per

zabbix3.2.6.1升級3.4.4圖文心得

zabbix zabbix升級 zabbix3.4.4 為了在升級過程中將停機時間和數據丟失降低到最小,建議先停機升級Zabbix server,然後再逐個停機升級和啟動Zabbix proxy。當所有的Proxy升級完畢後,再啟動Zabbix Server。在Zabbix server的停機期間

HDP 2.2 ( Hadoop 2.6 ) 叢集的記憶體引數配置引數調優 (Yarn/MapReduce2)

近期在根據叢集上的各節點的物理機配置對叢集的記憶體引數進行調整。  因此較系統的學習了一下hadoop裡對資源調配的各元件的相關引數的含義。 作為示例的配置叢集版本是2.6, hortonworks 2.2.  首先要理解, hadoop 中 yarn 作為資源管理器,

Hadoop-2.6.0+Zookeeper-3.4.6+Spark-1.5.0+Hbase-1.1.2+Hive-1.2.0叢集搭建

前言 本部落格目的在於跟大家分享大資料平臺搭建過程,是筆者半年的結晶。在大資料搭建過程中,希望能給大家提過一些幫助,這也是本部落格的

CentOs6.x安裝mongodb3.4.x

mongo mongodb mongo報錯 linux安裝mongodb 一、系統及安裝說明 系統:CentOS6.x_x64,mongodb-3.4.10。mongodb官方下載地址 https://fastdl.mongodb.org/linux/mongodb-linux-x8

springboot2.x 與 elasticsearch2.4.x整合出錯:None of the configured nodes are available

升級springboot2.x出現如下Elasticsearch相關錯誤: NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{729dgKKVSF-

babel 7.x 結合 webpack 4.x 配置

pac image 分享 技術分享 git ins png ebp mas 今天在學習webpack的使用的時候,由於學習的教程是2018年初的,使用的是 webpack 3.x 和 babel 6.x ,然後學習的過程中出現的了很多問題。 解決問題之後,總結一下新的 ba

IdentityServer 3.1.x 遷移到 4.x

### 一.前言 IdentityServer4 4.x已經正式釋出了,根據官方的 Release Note,3.1.x 到 4.x 的變更也是非常多,今天在將程式碼遷移到 4.x 遇到了一些問題在此記錄下來,我使用的 IdentityServer4 的各種資料持久化,比如 ClientStore,Reso

Hadoop 2.6.x啟動出現:no databode to stop 錯誤

產生錯誤的原因: Hadoop啟動後的PID檔案的預設配置是儲存在/tmp 目錄下的,而linux下 /tmp 目錄會定時清理,所以在叢集執行一段時間後如果在輸入start-all.sh,出現no datanode to stop的錯誤提示,所以我們最好在配置檔案中修改以下PID的預

POM報錯Failure to transfer org.apache.maven.plugins:maven-resources-plugin:pom:2.6 from

upd 下載安裝 window lips all org 選中 osi plugins 解決方式一: 1、查看.m2\repository\org\apache\maven\plugins\maven-resources-plugin\下maven-resources-

maven報Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.6的解決方案

man 一個 art enc resources osi pre read 是我 上面截圖是我在新建maven項目的時候報錯信息提示,我是這麽解決的 1.在pom.xml文件中加入maven-resources-plugin配置 <dependency>

Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.6:war (default-war) on project ca

Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.6:war (default-war) on project cas: Unable to parse configuration of mojo org.apach

How to port new audio codec into Android

  How to port new audio codec into Android 1.Prepare the codec driver  The codec driver i

Porting a Driver from UMDF 1 to UMDF 2

This topic describes how to port a User-Mode Driver Framework (UMDF) 1 driver to UMDF 2. You can start with a UMDF 1 driver that uses Sources/Dirs fil

net core 2.x - 日誌 - to elasiticsearch

記錄日誌到elasticsearch(es),下面簡寫es,然後我們可以通過kibana視覺化的觀察日誌資訊以及統計分析等. 1.起源   年中旬時候,公司有個需求是需要分析使用者的地址,需要先分詞處理然後通過搜尋引擎匹配相關資料,當然這個不是這裡說的重點,主題還是日誌 to es,也就是日誌傳

net core 2.x - 日誌 - to elasticsearch - (2)

你可能會有疑惑,怎麼又來一偏,,,其實我也好奇,因為我已經忘記哪個能跑起來了,,,記憶中,這個好像是沒問題的. 1.使用到的資源   關於es(elasticseach)在.net中的訪問,可以參考es的官網,有很明確的說明了可以使用elasticsearch.net和nest, 需要詳細瞭解的

How to Use Homebrew Zsh Instead of Mac OS X Default

Out of the box Mac OS X version 10.8.x (Lion) comes with zsh version 4.3.11 (i386-apple-darwin12.0). However zsh is currently at versi

Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.6.1:clean (default-clean)

今天碰到這樣一個問題,編譯打包的時候報以下錯誤 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.6.1:clean (default-clean) on project

解決eclipse的Failure to transfer org.apache.maven.plugins:maven-resources-plugin:pom:2.6 from (cl的錯誤方法:

找到setting.xml加入 阿里 <mirror> <!--This sends everything else to /public --> <id>nexus</id> <mirrorO

兔子-Error:(31, 13) Failed to resolve: com.github.chrisbanes:PhotoView:1.2.6 Show in File Show i

Error:(31, 13) Failed to resolve: com.github.chrisbanes:PhotoView:1.2.6   Show in File     Show in Project Structure dialog  解決問題的辦法是在專案的