MT7688/MT7628-GPIO使用

creator_ly 2022-01-07 11:00:31 阅读数:667

mt7688 mt mt7628-gpio mt gpio



7688/7628的GPIO一共有47個,GPIO0-GPIO46,這些GPIO有複用的功能,按功能模塊進行配置,比如I2C有兩根線,將其設置為GPIO模式,則兩根就都是GPIO模式了,不可為別的功能。


一般有兩種方法配置

1.通過寄存器進行配置

下面的使用前提不要被DTS或者驅動什麼占用,如switch芯片的network配置

功能的定義由兩個地址寄存器。

GPIO1_MODE = 0x10000060

MT7688/MT7628-GPIO使用_引脚

GPIO2_MODE = 0x10000064

MT7688/MT7628-GPIO使用_寄存器_02

可以看到兩個寄存器覆蓋了所有的複用引脚,舉個例子,如要將GPIO0/1設置成GPIO模式:

先查看GPIO0/1引脚的默認功能如下,為I2S的引脚。

MT7688/MT7628-GPIO使用_引脚_03

所以需要找到I2S的配置寄存器,以下為部分GPIO1_MODE寄存器的含義:

MT7688/MT7628-GPIO使用_引脚_04

可看到I2C為GPIO1_MODE的第20:21比特。

所以需要做的就是將原本GPIO1_MODE寄存器的值都出來,然後將7:6比特設置成01即可。

comnIoctlRegOption(GPIO1_MODE, 0x1 << 6, 0x3 << 6); //I2S,GPIO0-4

000000001
0x1 << 6即 val = 001000000

00000011
0x3 << 6即 mask = 011000000

reg_val[2] = {0, 0};有兩個值,一個是傳進去的addr,一個該地址返回的val

reg_val[0] = add;
read(fd, reg_val, 8); //reg_val[0]為傳入的addr,reg_val[1]為val

reg_val[1] &= ~mask; //A &= ~B,將A值的B比特清0,即011000000,第6、7比特清0
reg_val[1] |= (val & mask); //A |= B,將A值的B比特置1,即001000000,第6比特置1


_INT32 comnIoctlRegOption(_UINT32 add, _UINT32 val, _UINT32 mask)
{
int fd = -1;
_UINT32 reg_val[2] = {0, 0};

fd = open(REG_DEV_NAME , O_RDWR|O_NOCTTY|O_NDELAY);
if(fd < 0)
{
printf("comnIoctl(RegOption) Cann't Open %s\r\n", REG_DEV_NAME);
return EOS_ERROR;
}
//set Reset IO Output
reg_val[0] = add;
read(fd, reg_val, 8);
reg_val[1] &= ~mask;
reg_val[1] |= (val & mask);
write(fd, reg_val, 8);

close(fd);
return EOS_OK;
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
comnIoctlRegOption(GPIO1_MODE, 0x1 << 10, 0x3 << 10); //SD,GPIO22-29
comnIoctlRegOption(GPIO1_MODE, 0x1 << 2, 0x3 << 2); //SPIS,GPIO14-17
comnIoctlRegOption(GPIO1_MODE, 0x1 << 26, 0x3 << 26); //UART2,GPIO20-21

comnIoctlGpioInit(GPIO_SIM_CP, GPIO_DIR_OUT, 1);
comnIoctlGpioInit(GPIO_SIM_PL, GPIO_DIR_OUT, 1);
comnIoctlGpioInit(GPIO_SIM_DET0, GPIO_DIR_IN, 1);
comnIoctlGpioInit(GPIO_SIM_DET1, GPIO_DIR_IN, 1);
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
#define GPIO1_MODE_ADD 0x10000060
#define GPIO2_MODE_ADD 0x10000064
#define GPIO0_CTRL_ADD 0X10000600
#define GPIO0_DATA_ADD 0X10000620 //read or write data
#define GPIO1_CTRL_ADD 0X10000604
#define GPIO1_DATA_ADD 0X10000624
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.

下面給出幾個已經封裝好的函數,以前後期直接使用

1、寄存器配置
_INT32 comnIoctlRegOption(_UINT32 add, _UINT32 val, _UINT32 mask)
{
int fd = -1;
_UINT32 reg_val[2] = {0, 0};

fd = open(REG_DEV_NAME , O_RDWR|O_NOCTTY|O_NDELAY);
if(fd < 0)
{
printf("comnIoctl(RegOption) Cann't Open %s\r\n", REG_DEV_NAME);
return EOS_ERROR;
}
//set Reset IO Output
reg_val[0] = add;
read(fd, reg_val, 8);
reg_val[1] &= ~mask;
reg_val[1] |= (val & mask);
write(fd, reg_val, 8);

close(fd);
return EOS_OK;
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
2、輸入輸出模式配置
_INT32 comnIoctlGpioInit(_UCHAR8 gpio, _UCHAR8 dir, _UCHAR8 val)
{
_INT32 fd = -1;
_UINT32 reg_val[2] = {0, 0};
_UINT32 gpio_ctrl_reg_add = 0;
_UINT32 gpio_data_reg_add = 0;

if(gpio < 32)
{
gpio_ctrl_reg_add = REG_GPIO_CTRL0;
gpio_data_reg_add = REG_GPIO_DATA0;
}
else if(gpio >= 32)
{
gpio_ctrl_reg_add = REG_GPIO_CTRL1;
gpio_data_reg_add = REG_GPIO_DATA1;
gpio -= 32;
}

fd = open(REG_DEV_NAME , O_RDWR|O_NOCTTY|O_NDELAY);
if(fd < 0)
{
printf("comnIoctl(GpioInit) Cann't Open %s\r\n", REG_DEV_NAME);
return EOS_ERROR;
}
//set the io port,out or in
reg_val[0] = gpio_ctrl_reg_add;
read(fd, reg_val, 8);

if(dir == GPIO_DIR_OUT)
{
reg_val[1] |= 1 << gpio;
}
else if(dir == GPIO_DIR_IN)
{
reg_val[1] &= ~(1 << gpio);
}
write(fd, reg_val, 8);

//set the val
reg_val[0] = gpio_data_reg_add;
read(fd, reg_val, 8);
if(val > 0)
{
reg_val[1] |= 1 << gpio;
}
else
{
reg_val[1] &= ~(1 << gpio);
}
write(fd, reg_val, 8);
close(fd);

return EOS_OK;
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
3、輸出高低
_INT32 comnIoctlGpioSetValue(_UCHAR8 gpio, _UCHAR8 val)
{
_INT32 fd = -1;
_UINT32 reg_val[2] = {0, 0};
_UINT32 gpio_data_reg_add = 0;

if((gpio > 63) || (val > 1))
{
printf("comnIoctl(GpioSetValue) paramer is wrong!\n");
return EOS_ERROR;
}

if(gpio < 32)
{
gpio_data_reg_add = REG_GPIO_DATA0;
}
else if(gpio >= 32)
{
gpio_data_reg_add = REG_GPIO_DATA1;
gpio -= 32;
}

fd = open(REG_DEV_NAME , O_RDWR|O_NOCTTY|O_NDELAY);
if(fd < 0)
{
//printf("comnIoctl(GpioSetValue) Cann't Open %s\r\n", REG_DEV_NAME);
return EOS_ERROR;
}
//輸出0/1
reg_val[0] = gpio_data_reg_add;
read(fd, reg_val, 8);
if(val == 0)
{
reg_val[1] &= ~(1 << gpio);
}
else if(val == 1)
{
reg_val[1] |= 1 << gpio;
}
write(fd, reg_val, 8);

close(fd);
return EOS_OK;
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
4、讀IO電平
_INT32 comnIoctlGpioGetValue(_UCHAR8 gpio)
{
_INT32 fd = -1;
_UINT32 reg_val[2] = {0, 0};
_UINT32 gpio_data_reg_add = 0;

if(gpio > 63)
{
printf("comnIoctl(GpioGetValue) paramer is wrong!\n");
return EOS_ERROR;
}

if(gpio < 32)
{
gpio_data_reg_add = REG_GPIO_DATA0;
}
else if(gpio >= 32)
{
gpio_data_reg_add = REG_GPIO_DATA1;
gpio -= 32;
}

fd = open(REG_DEV_NAME , O_RDWR|O_NOCTTY|O_NDELAY);
if(fd < 0)
{
//printf("comnIoctl(GpioGetValue) Cann't Open %s\r\n", REG_DEV_NAME);
return EOS_ERROR;
}
//輸出0/1
reg_val[0] = gpio_data_reg_add;
read(fd, reg_val, 8);
close(fd);

return ((reg_val[1] >> gpio) & 1);
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.

2.多寄存器控制的GPIO

MT7688/MT7628-GPIO使用_寄存器_05

如上圖,SD卡由​​EPHY_AGPIO_AIO_EN(非EPHY_APGIO_AIO_EN)​​​和​​SD_MODE​​兩個寄存器控制,都要置1才可以

MT7688/MT7628-GPIO使用_寄存器_06

對於​​SD_MODE​​置1比較容易,上面已經給出方法,如下:

comnIoctlRegOption(GPIO1_MODE, 0x1 << 10, 0x3 << 10); //SD,GPIO22-29
  • 1.

​EPHY_AGPIO_AIO_EN​​即AGPIO_CFG的17-29比特置1,為了通用comnIoctlRegOption函數,做如下設置。

comnIoctlRegOption(AGPIO_CFG, 0xF << 17, 0xF << 17); //EPHY_AGPIO_AIO_EN[4:1],GPIO14-29

000001111
0xF << 6即 val = 00001111 00000000 000000000

00001111
0xF << 6即 mask = 00001111 00000000 000000000

reg_val[2] = {0, 0};有兩個值,一個是傳進去的addr,一個該地址返回的val

reg_val[0] = add;
read(fd, reg_val, 8); //reg_val[0]為傳入的addr,reg_val[1]為val

reg_val[1] &= ~mask; //A &= ~B,將A值的B比特清0,第17-20比特清0
reg_val[1] |= (val & mask); //A |= B,將A值的B比特置1,第17-20比特置1
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.

3.通過DTS進行配置

 ​http://wiki.wrtnode.cc/index.php?title=GPIO資源​

DTS格式有點類似Json,一般系統都會有兩個dts,一個芯片的dtsi,如:​​$(TOPDIR)/target/linux/ramips/dts/mt7628an.dts​​​另一個板子的配置dts,如:​​$(TOPDIR)/target/linux/ramips/dts/WRTNODE2P.dts​​。板子配置的dts會include芯片的dtsi,如下:

/dts-v1/;

/include/ "mt7628an.dtsi"

  • 1.
  • 2.
  • 3.
1、MT7620

mt7620a.dtsi

結合mt7620的datasheet裏GPIO pin share schemes以及在mt7620n.dtsi裏我們看到有,將GPIO#0到GPIO#72(中間有僅僅做GPO或GPI的)分為四組GPIO0-GPIO3;


  • 對應GPIO0是從GPIO#0開始到GPIO#23,一共有24個;
  • 對應GPIO1是從GPIO#24開始到GPIO#39,一共有16個;
  • 對應GPIO2是從GPIO#40開始到GPIO#71,一共有32個;
  • 對應GPIO3對應的是GPIO#72,僅有一個。

gpio0: [email protected] {
compatible = "ralink,mt7620a-gpio", "ralink,rt2880-gpio";
reg = <0x600 0x34>;

resets = <&rstctrl 13>;
reset-names = "pio";

interrupt-parent = <&intc>;
interrupts = <6>;

gpio-controller;
#gpio-cells = <2>;

ralink,gpio-base = <0>;
ralink,num-gpios = <24>;
ralink,register-map = [ 00 04 08 0c
20 24 28 2c
30 34 ];
};

gpio1: [email protected] {
compatible = "ralink,mt7620a-gpio", "ralink,rt2880-gpio";
reg = <0x638 0x24>;

interrupt-parent = <&intc>;
interrupts = <6>;

gpio-controller;
#gpio-cells = <2>;

ralink,gpio-base = <24>;
ralink,num-gpios = <16>;
ralink,register-map = [ 00 04 08 0c
10 14 18 1c
20 24 ];

status = "disabled";
};

gpio2: [email protected] {
compatible = "ralink,mt7620a-gpio", "ralink,rt2880-gpio";
reg = <0x660 0x24>;

interrupt-parent = <&intc>;
interrupts = <6>;

gpio-controller;
#gpio-cells = <2>;

ralink,gpio-base = <40>;
ralink,num-gpios = <32>;
ralink,register-map = [ 00 04 08 0c
10 14 18 1c
20 24 ];

status = "disabled";
};

gpio3: [email protected] {
compatible = "ralink,mt7620a-gpio", "ralink,rt2880-gpio";
reg = <0x688 0x24>;

interrupt-parent = <&intc>;
interrupts = <6>;

gpio-controller;
#gpio-cells = <2>;

ralink,gpio-base = <72>;
ralink,num-gpios = <1>;
ralink,register-map = [ 00 04 08 0c
10 14 18 1c
20 24 ];

status = "disabled";
};
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.

上面的gpio1/2/3的​​status = "disabled"​​,默認是關閉的,如果要使用需要在dts裏面打開,如下:

[email protected] {
gpio1: [email protected] {
status = "okay";
};

gpio2: [email protected] {
status = "okay";
};

gpio3: [email protected] {
status = "okay";
};
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.

如果引脚的功能有被複用到的,也需要把複用引脚釋放,添加到​​ralink,group​​裏面,如下:

pinctrl {
state_default: pinctrl0 {
default {
ralink,group = "ephy", "wled", "pa", "i2c", "wdt", "uartf", "spi refclk";
ralink,function = "gpio";
};
};
};
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.

上面的ephy/i2c/spi refclk等名稱在​​build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7628/linux-3.18.29/arch/mips/ralink/mt7620.c​​裏面有定義,如下:

static struct rt2880_pmx_group mt7620a_pinmux_data[] = {
GRP("i2c", i2c_grp, 1, MT7620_GPIO_MODE_I2C),
GRP("uartf", uartf_grp, MT7620_GPIO_MODE_UART0_MASK,
MT7620_GPIO_MODE_UART0_SHIFT),
GRP("spi", spi_grp, 1, MT7620_GPIO_MODE_SPI),
GRP("uartlite", uartlite_grp, 1, MT7620_GPIO_MODE_UART1),
GRP_G("wdt", wdt_grp, MT7620_GPIO_MODE_WDT_MASK,
MT7620_GPIO_MODE_WDT_GPIO, MT7620_GPIO_MODE_WDT_SHIFT),
GRP("mdio", mdio_grp, 1, MT7620_GPIO_MODE_MDIO),
GRP("rgmii1", rgmii1_grp, 1, MT7620_GPIO_MODE_RGMII1),
GRP("spi refclk", refclk_grp, 1, MT7620_GPIO_MODE_SPI_REF_CLK),
GRP_G("pcie", pcie_rst_grp, MT7620_GPIO_MODE_PCIE_MASK,
MT7620_GPIO_MODE_PCIE_GPIO, MT7620_GPIO_MODE_PCIE_SHIFT),
GRP_G("nd_sd", nd_sd_grp, MT7620_GPIO_MODE_ND_SD_MASK,
MT7620_GPIO_MODE_ND_SD_GPIO, MT7620_GPIO_MODE_ND_SD_SHIFT),
GRP("rgmii2", rgmii2_grp, 1, MT7620_GPIO_MODE_RGMII2),
GRP("wled", wled_grp, 1, MT7620_GPIO_MODE_WLED),
GRP("ephy", ephy_grp, 1, MT7620_GPIO_MODE_EPHY),
GRP("pa", pa_grp, 1, MT7620_GPIO_MODE_PA),
{ 0 }
};
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.

第一個參數就是名稱,第二個參數,對應該組引脚的解析個數,如:

static struct rt2880_pmx_func i2c_grp[] = { FUNC("i2c", 0, 1, 2) };
static struct rt2880_pmx_func spi_grp[] = { FUNC("spi", 0, 3, 4) };
static struct rt2880_pmx_func uartlite_grp[] = { FUNC("uartlite", 0, 15, 2) };
static struct rt2880_pmx_func mdio_grp[] = { FUNC("mdio", 0, 22, 2) };
static struct rt2880_pmx_func rgmii1_grp[] = { FUNC("rgmii1", 0, 24, 12) };
static struct rt2880_pmx_func refclk_grp[] = { FUNC("spi refclk", 0, 37, 3) };
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.

i2c後面的1,2,代錶從gpio1開始,占用2個引脚;spi refclk的37,3,代錶從gpio37開始,占用3個引脚;這些跟功能引脚的定義其實是對應的,如下:

MT7688/MT7628-GPIO使用_引脚_07

gpio-leds {
compatible = "gpio-leds";
indicator {
label = "wrtnode:blue:indicator";
gpios = <&gpio1 14 0>;
};
};
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
2、MT7688

mt7628an.dtsi

mt7628an.dtsi裏有對gpio的注册,一共將GPIO分為三組,分別為gpio0、gpio1、gpio2

每組gpio包含32個gpio;在WRTnode2R/2P上只用到了gpio0和gpio1兩組。

[email protected] {
#address-cells = <1>;
#size-cells = <0>;

compatible = "mtk,mt7628-gpio", "mtk,mt7621-gpio";
reg = <0x600 0x100>;

interrupt-parent = <&intc>;
interrupts = <6>;

gpio0: [email protected] {
reg = <0>;
compatible = "mtk,mt7621-gpio-bank";
gpio-controller;
#gpio-cells = <2>;
};

gpio1: [email protected] {
reg = <1>;
compatible = "mtk,mt7621-gpio-bank";
gpio-controller;
#gpio-cells = <2>;
};

gpio2: [email protected] {
reg = <2>;
compatible = "mtk,mt7621-gpio-bank";
gpio-controller;
#gpio-cells = <2>;
};
};
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.

與MT7620不同的是,這三組gpio都是開啟的,在dts中就不用在操作。

與MT7620相同的是,如果引脚的功能有被複用到的,也需要把複用引脚釋放,添加到​​ralink,group​​裏面,如下:

pinctrl {
state_default: pinctrl0 {
gpio {
ralink,group = "i2c", "gpio", "jtag";
ralink,function = "gpio";
};
};
};
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.

不過MT7620個MT7628的引脚功能分布式不一樣的,所以在​​build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7628/linux-3.18.29/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),
GRP_G("wled_kn", wled_kn_grp_mt7628, MT7628_GPIO_MODE_MASK, 1, MT7628_GPIO_MODE_WLED_KN),
{ 0 }
};
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.

第二個參數,對應該組引脚的解析個數,如:

static struct rt2880_pmx_func i2c_grp_mt7628[] = {
FUNC("-", 3, 4, 2),
FUNC("debug", 2, 4, 2),
FUNC("gpio", 1, 4, 2),
FUNC("i2c", 0, 4, 2),
};
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.

i2c後面的4,2,代錶從gpio4開始,占用2個引脚;與MT7620的gpio1-2是不一樣的。

MT7688/MT7628-GPIO使用_寄存器_08

gpio_export {
compatible = "gpio-export";
#size-cells = <0>;

lte4power {
gpio-export,name = "G4Power";
gpio-export,output = <0>;
gpios = <&gpio0 29 0>; //GPIO_ACTIVE_HIGH
};

lte4reset {
gpio-export,name = "G4Reset";
gpio-export,output = <0>;
gpios = <&gpio0 28 0>;
};

lte4status {
gpio-export,name = "G4Status";
gpio-export,input = <0>;
gpios = <&gpio0 22 0>; //GPIO_ACTIVE_HIGH
};
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
gpio-leds {
compatible = "gpio-leds";
indicator {
label = "wrtnode:blue:indicator";
gpios = <&gpio1 9 1>;
};
};


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

[email protected]:/sys/class/leds# ls
wrtnode:blue:indicator
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.



版权声明:本文为[creator_ly]所创,转载请带上原文链接,感谢。 https://gsmany.com/2022/01/202201071100308391.html