Openwrt中MT7628/MT7688的全部GPIO复用配置及常用接口DTS配置总结

2023-05-16

Openwrt的不同版本中关于MT7628,MT7688的GPIO配置,存在或多或少的一些小问题

下面将以MT7628AN为基础,介绍其全部的GPIO功能复用配置,以及需要注意的地方

MT76x8一个就47个可作为GPIO引脚,如下

 关于其全部的功能复用表可以参考MTK官方的开发demo版Linkit

 在这全部的引脚中,需要特别注意的是:

1. 网口模式,因为MTK的设计,一共5个网口,要么全部作为普通网口使用,要么只有一个网口(Port0),没有中间选项;

因此,如果需要用到UART2,SDCARD等功能时,系统只剩一个P0网口可用,这也是MTK所宣传的IOT模式

2. SPI接口,datasheet介绍可以作为GPIO使用,但是因为大多系统都接了SPI NOR Flash,因此其不能设置为GPIO模式;而SPI_CS1另一个SPI片选脚,倒是不受影响,可作为GPIO

3. 关于GPIO/GPO的描述,比如I2C的两个脚是GPO,但经实际测试,描述为GPO的其实可以作为输入使用

 

关于DTS配置,其主要参考arch/mips/ralink/mt7620.c文件

static struct rt2880_pmx_group mt7628an_pinmux_data[] = {
	GRP_G("pwm1", pwm1_grp_mt7628, MT7628_GPIO_MODE_MASK,
				1, MT7628_GPIO_MODE_PWM1),
	GRP_G("pwm0", pwm0_grp_mt7628, MT7628_GPIO_MODE_MASK,
				1, MT7628_GPIO_MODE_PWM0),
	GRP_G("uart2", uart2_grp_mt7628, MT7628_GPIO_MODE_MASK,
				1, MT7628_GPIO_MODE_UART2),
	GRP_G("uart1", uart1_grp_mt7628, MT7628_GPIO_MODE_MASK,
				1, MT7628_GPIO_MODE_UART1),
	GRP_G("i2c", i2c_grp_mt7628, MT7628_GPIO_MODE_MASK,
				1, MT7628_GPIO_MODE_I2C),
	GRP("refclk", refclk_grp_mt7628, 1, MT7628_GPIO_MODE_REFCLK),
	GRP("perst", perst_grp_mt7628, 1, MT7628_GPIO_MODE_PERST),
	GRP("wdt", wdt_grp_mt7628, 1, MT7628_GPIO_MODE_WDT),
	GRP("spi", spi_grp_mt7628, 1, MT7628_GPIO_MODE_SPI),
	GRP_G("sdmode", sd_mode_grp_mt7628, MT7628_GPIO_MODE_MASK,
				1, MT7628_GPIO_MODE_SDMODE),
	GRP_G("uart0", uart0_grp_mt7628, MT7628_GPIO_MODE_MASK,
				1, MT7628_GPIO_MODE_UART0),
	GRP_G("i2s", i2s_grp_mt7628, MT7628_GPIO_MODE_MASK,
				1, MT7628_GPIO_MODE_I2S),
	GRP_G("spi cs1", spi_cs1_grp_mt7628, MT7628_GPIO_MODE_MASK,
				1, MT7628_GPIO_MODE_CS1),
	GRP_G("spis", spis_grp_mt7628, MT7628_GPIO_MODE_MASK,
				1, MT7628_GPIO_MODE_SPIS),
	GRP_G("gpio", gpio_grp_mt7628, MT7628_GPIO_MODE_MASK,
				1, MT7628_GPIO_MODE_GPIO),
	GRP_G("wled_an", wled_an_grp_mt7628, MT7628_GPIO_MODE_MASK,
				1, MT7628_GPIO_MODE_WLED_AN)
}

在DTS文件中,填写对应的name和func名字就可以,如:

pinctrl {
    state_default: pinctrl0 {
	gpio {
	    ralink,group = "gpio","wled_an", "i2s", "refclk", "perst", "wdt", "spi cs1";
	    ralink,function = "gpio";
	};
}

常用接口及功能配置如下:

UART1开启:

uart1@d00 {
	status = "okay";
};

SPI_CS1 开启,使用系统spi控制器,注意pinctrl-0 = <&spi_pins>, <&spi_cs1_pins>,配置CS1为SPI_CS1功能,同时应该去掉pinctrl0中"spi cs1"的GPIO复用

spi@b00 {
	status = "okay";

	pinctrl-names = "default";
	pinctrl-0 = <&spi_pins>, <&spi_cs1_pins>;
        
        spidev@1 {
		#address-cells = <1>;
		#size-cells = <1>;
		compatible = "spidev";
		reg = <1 0>;
		spi-max-frequency = <40000000>;
        };
}

GPIO模拟SPI配置,如:使用I2S的复用脚0-3,注意先配置I2S为GPIO模式

spi-gpio {
		compatible = "spi-gpio";
		#address-cells = <0x1>;
		cs-gpios = <&gpio0 2 0>;
		gpio-sck = <&gpio0 0 0>;
		gpio-mosi = <&gpio0 3 0>;
		gpio-miso = <&gpio0 1 0>;
		num-chipselects = <1>;
		spidev@0 {
			#address-cells = <0x1>;
			compatible = "spidev";
			spi-max-frequency = <10000000>;
			reg = <0>;
		};
	};

I2C的RTC时钟配置,以PCF8563为例,注意reg地址的问题,pcf8563地址是0x51,常用的ds1307是0x68

i2c@900 {
	status = "okay";
	rtc@51 {
		compatible = "nxp,pcf8563";
		 reg = <0x51>;
	};
};

LED配置参考,注意MT76x8有两组GPIO,GPIO0对应0-31,GPIO1对应32-46

gpio-leds {
		compatible = "gpio-leds";
		modpwr {
			label = "modpwr";
			gpios = <&gpio1 8 1>;
		};
		modrst {
			label = "modrst";
			gpios = <&gpio1 4 0>;
		};
		heart {
			label = "heart";
			gpios = <&gpio1 6 1>;
		};
}

lable对应运行系统中/sys/class/leds/lable/brightness 的lable名字

gpios = <&gpio1 8 1>; 表示GPIO1组,8 表示 32+8 即GPIO40,1表示低电平有效,即默认输出高电平

按键配置参考,

gpio-keys-polled {
		compatible = "gpio-keys-polled";
		#address-cells = <1>;
		#size-cells = <0>;
		poll-interval = <20>;
		vccin {
			label = "BTN_0";
			gpios = <&gpio0 6 0>;
			linux,code = <0x100>;
		};
		reset {
			label = "reset";
			gpios = <&gpio1 7 1>;
			linux,code = <0x198>;
		};
	};

poll-interval 表示输入检测消抖时间,label对应于运行系统中/etc/rc.button/lable,即按键后对应的执行脚本文件,如上述配置,系统中应该存在reset和BTN_0两个脚本, gpios同LED说明

linux,code = <0x198>; 对应input.h的宏定义值,配合驱动文件gpio-button-hotplug.c中的相关配置,如:

static struct bh_map button_map[] = {
	BH_MAP(BTN_0,		"BTN_0"),
	BH_MAP(BTN_1,		"BTN_1"),
	BH_MAP(BTN_2,		"BTN_2"),
	BH_MAP(BTN_3,		"BTN_3"),
	BH_MAP(BTN_4,		"BTN_4"),
	BH_MAP(BTN_5,		"BTN_5"),
	BH_MAP(BTN_6,		"BTN_6"),
	BH_MAP(BTN_7,		"BTN_7"),
	BH_MAP(BTN_8,		"BTN_8"),
	BH_MAP(BTN_9,		"BTN_9"),
	BH_MAP(KEY_POWER,	"power"),
	BH_MAP(KEY_RESTART,	"reset"),
	BH_MAP(KEY_RFKILL,	"rfkill"),
	BH_MAP(KEY_WPS_BUTTON,	"wps"),
	BH_MAP(KEY_WIMAX,	"wwan"),
};

其原理是gpio-button-hotplug驱动会检测按键事件,然后通过netlionk方式广播出来,proc会一直监测事件,触发hotplug,进而执行到相关reset等脚本,热拔插事件也是此类方式,具体不再详细介绍,本文主要介绍引脚复用配置

另,还需注意的是,配置了相关引脚功能后,还需在kernel中开启相关驱动模块以及选择相关的应用才能正常使用

到此,常用接口基本介绍完毕

下面大概提一下不同openwrt版本中的代码错误,以下只贴出正确的code,各位看客有功能错误的各自根据自己的现有版本对比修正即可

1. 看门狗dts 地址错误,位置:target/linux/ramips/dts/mt7628an.dtsi

watchdog: watchdog@100 {
	compatible = "ralink,mt7628an-wdt", "mediatek,mt7621-wdt";
	reg = <0x100 0x30>;

	resets = <&rstctrl 8>;
	reset-names = "wdt";

	interrupt-parent = <&intc>;
	interrupts = <24>;
};

根据DataSheet,watchdog的偏移地址应该是100

同时,如果需要自行喂狗的话,注意先关闭proc进程中自动喂狗功能

2. REFCLK,PERST的配置错误,位置arch/mips/ralink/mt7620.c,原来的reclk和perst引脚配置反了

static struct rt2880_pmx_func refclk_grp_mt7628[] = { FUNC("reclk", 0, 37, 1) };
static struct rt2880_pmx_func perst_grp_mt7628[] = { FUNC("perst", 0, 36, 1) };

3. PHY 0-4的LED不能作为GPIO的问题,参考补丁文件:

--- a/arch/mips/ralink/mt7620.c	2018-09-04 17:14:33.000000000 +0800
+++ b/arch/mips/ralink/mt7620.c	2018-04-09 08:28:51.000000000 +0800
@@ -138,8 +138,8 @@
 	FUNC("i2c", 0, 4, 2),
 };
 
-static struct rt2880_pmx_func refclk_grp_mt7628[] = { FUNC("reclk", 0, 36, 1) };
-static struct rt2880_pmx_func perst_grp_mt7628[] = { FUNC("perst", 0, 37, 1) };
+static struct rt2880_pmx_func refclk_grp_mt7628[] = { FUNC("reclk", 0, 37, 1) };
+static struct rt2880_pmx_func perst_grp_mt7628[] = { FUNC("perst", 0, 36, 1) };
 static struct rt2880_pmx_func wdt_grp_mt7628[] = { FUNC("wdt", 0, 38, 1) };
 static struct rt2880_pmx_func spi_grp_mt7628[] = { FUNC("spi", 0, 7, 4) };
 
@@ -185,23 +185,50 @@
 	FUNC("gpio", 0, 11, 1),
 };
 
-static struct rt2880_pmx_func wled_kn_grp_mt7628[] = {
-	FUNC("rsvd", 3, 35, 1),
-	FUNC("rsvd", 2, 35, 1),
-	FUNC("gpio", 1, 35, 1),
-	FUNC("wled_kn", 0, 35, 1),
+struct rt2880_pmx_func wled_an_grp_mt7628[] = {
+        FUNC("rsvd", 3, 44, 1),
+        FUNC("rsvd", 2, 44, 1),
+        FUNC("gpio", 1, 44, 1),
+        FUNC("wled_an", 0,44, 1),
+};
+
+static struct rt2880_pmx_func ephy_p0_grp_mt7628[] = {
+        FUNC("rsvd", 3, 43, 1),
+        FUNC("rsvd", 2, 43, 1),
+        FUNC("gpio", 1, 43, 1),
+        FUNC("ephy", 0, 43, 1),
+};
+
+static struct rt2880_pmx_func ephy_p1_grp_mt7628[] = {
+        FUNC("rsvd", 3, 42, 1),
+        FUNC("rsvd", 2, 42, 1),
+        FUNC("gpio", 1, 42, 1),
+        FUNC("ephy", 0, 42, 1),
+};
+static struct rt2880_pmx_func ephy_p2_grp_mt7628[] = {
+        FUNC("rsvd", 3, 41, 1),
+        FUNC("rsvd", 2, 41, 1),
+        FUNC("gpio", 1, 41, 1),
+        FUNC("ephy", 0, 41, 1),
+};
+static struct rt2880_pmx_func ephy_p3_grp_mt7628[] = {
+        FUNC("rsvd", 3, 40, 1),
+        FUNC("rsvd", 2, 40, 1),
+        FUNC("gpio", 1, 40, 1),
+        FUNC("ephy", 0, 40, 1),
+};
+static struct rt2880_pmx_func ephy_p4_grp_mt7628[] = {
+        FUNC("rsvd", 3, 39, 1),
+        FUNC("rsvd", 2, 39, 1),
+        FUNC("gpio", 1, 39, 1),
+        FUNC("ephy", 0, 39, 1),
 };
-
-static struct rt2880_pmx_func wled_an_grp_mt7628[] = {
-	FUNC("rsvd", 3, 44, 1),
-	FUNC("rsvd", 2, 44, 1),
-	FUNC("gpio", 1, 44, 1),
-	FUNC("wled_an", 0, 44, 1),
-};
-
 #define MT7628_GPIO_MODE_MASK		0x3
-
-#define MT7628_GPIO_MODE_WLED_KN	48
+#define MT7628_GPIO_MODE_EPHY_P4        42
+#define MT7628_GPIO_MODE_EPHY_P3        40
+#define MT7628_GPIO_MODE_EPHY_P2        38
+#define MT7628_GPIO_MODE_EPHY_P1        36
+#define MT7628_GPIO_MODE_EPHY_P0        34
 #define MT7628_GPIO_MODE_WLED_AN	32
 #define MT7628_GPIO_MODE_PWM1		30
 #define MT7628_GPIO_MODE_PWM0		28
@@ -236,7 +263,12 @@
 	GRP_G("spis", spis_grp_mt7628, MT7628_GPIO_MODE_MASK, 1, MT7628_GPIO_MODE_SPIS),
 	GRP_G("gpio", gpio_grp_mt7628, MT7628_GPIO_MODE_MASK, 1, MT7628_GPIO_MODE_GPIO),
 	GRP_G("wled_an", wled_an_grp_mt7628, MT7628_GPIO_MODE_MASK, 1, MT7628_GPIO_MODE_WLED_AN),
-	GRP_G("wled_kn", wled_kn_grp_mt7628, MT7628_GPIO_MODE_MASK, 1, MT7628_GPIO_MODE_WLED_KN),
+		GRP_G("ephy_p0", ephy_p0_grp_mt7628, MT7628_GPIO_MODE_MASK, 1, MT7628_GPIO_MODE_EPHY_P0),
+        GRP_G("ephy_p1", ephy_p1_grp_mt7628, MT7628_GPIO_MODE_MASK, 1, MT7628_GPIO_MODE_EPHY_P1),
+        GRP_G("ephy_p2", ephy_p2_grp_mt7628, MT7628_GPIO_MODE_MASK, 1, MT7628_GPIO_MODE_EPHY_P2),
+        GRP_G("ephy_p3", ephy_p3_grp_mt7628, MT7628_GPIO_MODE_MASK, 1, MT7628_GPIO_MODE_EPHY_P3),
+        GRP_G("ephy_p4", ephy_p4_grp_mt7628, MT7628_GPIO_MODE_MASK, 1, MT7628_GPIO_MODE_EPHY_P4),
+
 	{ 0 }
 };
 
 

 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Openwrt中MT7628/MT7688的全部GPIO复用配置及常用接口DTS配置总结 的相关文章

  • 欠拟合、过拟合及其解决方法

    在我们机器学习或者训练深度神经网络的时候经常会出现欠拟合和过拟合这两个问题 xff0c 但是 xff0c 一开始我们的模型往往是欠拟合的 xff0c 也正是因为如此才有了优化的空间 xff0c 我们需要不断的调整算法来使得模型的表达能拿更强
  • ubuntu18.04安装ROS Melodic的详细过程以及填坑经历

    一 版本说明 ROS官方将在2021年不再维护Kinetic xff0c 后续使用Ubuntu18 04 43 Melodic组合 xff0c Melodic支持时间到2023年5月 二 安装前Ubuntu18 04设置 打开Ubuntu1
  • win10和ubuntu20双系统设置默认启动系统为win10

    在win10下安装了Ubuntu20 04系统 xff0c 默认情况下 xff0c 启动的是Ubuntu系统 要将默认启动系统设置成win10 xff0c 方法如下 xff1a 1 进入ubuntu系统 xff0c 按住Ctrl 43 Al
  • Keil添加芯片支持包(Pack)

    1 前言 一直用STM32的芯片 xff0c 现在想看看工程是否可以在其他厂家的芯片上跑 xff0c 可是keil的Device中只有ST厂家的 因此 xff0c 尝试在keil中添加其他厂家的芯片支持包 2 keil软件内安装 点击工具栏
  • Qt 设置窗体大小和背景颜色

    1 一种方法是设置它的最大窗口值和最小窗口值 xff0c 并且使最大值和最小值相等 简单的示例 xff1a setMinimumSize 370 150 setMaximumSize 370 150 此时窗口大小便被固定为 xff08 37
  • Shell 脚本详解

    简介 shell xff1a 蛋 壳 shell脚本是在操作系统外 xff0c 可以直接调用系统内核命令的一个脚本语言 shell脚本可以分为两大类组成 xff1a 1 命令行 xff08 系统命令行 xff09 2 脚本语法 xff08
  • Windows——电脑不能连接手机热点(WLAN显示已经禁用)的解决办法

    笔记本电脑提示 xff1a 已关闭无线功能 基于这篇博客之上 xff0c 在第二步中 xff0c 关闭WLAN AutoConfig 服务 xff0c 之后重新打开WLAN AutoConfig 服务 xff0c 即可
  • Ubuntu——系统语言由英文切换到中文的方法

    一 方法一 ubuntu设置系统语言为中文 二 方法二 若方法一中不能拖动中文输入法到第一行 xff0c 则可以直接采取卸载英文输入法 xff0c 这样就中文输入法到第一行了 xff0c 切换成中文了 英文输入法可以根据需要考虑是否安装 一
  • RealSense D435——基本介绍

    一 结构介绍 采用的是结构光Tof成像方案 正面的四个摄像头从左至右 xff0c 依次是左红外相机 红外点阵投影仪 右红外相机 RGB相机 xff08 前三个负责形成深度图 xff0c 最后一个就形成RGB图 xff09 二 小贴士 RGB
  • RealSense D435——相机内参获取

    RealSense D435 相机内参获取 一 参考博客二 小贴士2 1 遇到的问题及解决方案问题一描述问题一解决方法问题二描述问题二解决方法 一 参考博客 RealSense D435内参获取环境配置 xff1a Realsense D4
  • Vscode——报错解决:Unable to start debugging.Unexpected GDB output from command. 或 程序点击运行一直无结果

    一 报错截图 1 Unable to start debugging Unexpected GDB output from command 2 程序点击运行一直无结果 二 原因 路径中含有中文 三 解决办法 将文件放入不包含中文的路径下
  • Github——合并分支

    一 当两个分支不一样时 xff0c 会出现下面的标志 xff08 前提是设定了分支保护 xff09 xff0c 点击Compare amp pull request 二 选择双方分支 三 处理请求 四 确认请求
  • 基于四旋翼飞行器的陀螺仪、加速度计、磁力计传感器说明

    一 什么是磁力计 加速度计和陀螺仪以及他们之间的区别 1 什么是陀螺仪 加速度计和磁力计 xff1f xff08 1 xff09 陀螺仪 xff08 Gyroscope GYRO Sensor xff09 也叫地感器 xff0c 三轴陀螺仪
  • 操作系统(二) -- 操作系统的接口与实现

    前言操作系统的接口 什么是操作系统的接口POSIX标准 系统调用的实现 1 xff0c 用户程序能不能直接调用系统内核2 xff0c 如果不能直接调用 xff0c 为什么 xff1f 如何实现的3 xff0c 用户程序如何才能调用系统内核系
  • 自动驾驶路径规划技术-高速公路路径规划

    Path Planning Highway Driving project Github https github com williamhyin CarND Path Planning Email williamhyin 64 outlo
  • FYI, MySQL高效分页

    在Percona Performance Conference 2009大会上来自yahoo的Surat Singh Bhati surat 64 yahoo inc com 和 Rick James rjames 64 yahoo inc
  • 【论文理解】ArcFace: Additive Angular Margin Loss for Deep Face Recognition(InsightFace)

    论文地址 xff1a https arxiv org abs 1801 07698 github xff1a https github com deepinsight insightface 这篇论文基本介绍了近期较为流行的人脸识别模型 x
  • Ubuntu录屏

    1 CTRL 43 ALT 43 SHIFT 43 R 开始录屏 2 CTRL 43 ALT 43 SHIFT 43 R 结束录屏 3 视频保持路径 xff1a Video xxx webm 注意 xff1a 默认录屏时间为30秒 xff0
  • make的命令行选项

    http www linuxsir org main doc gnumake GNUmake v3 80 zh CN html make 09 html 这些参数可以通过man手册查看 红色是比较有用的选项 b m 忽略 xff0c 提供其
  • 泛化,实现,依赖,关联(聚合,组合)

    UML 中类与类 类与接口 接口与接口这间的关系有 泛化 generalization 关系 关联 association 关系 关联 聚合 合成 依赖 dependency 关系 xff0c 实现 realization 关系 目录 泛化

随机推荐