MT7621原厂openwrt SDK使能串口2和串口3

 

MT7621有三个串口,项目需要将三个串口都使能;

 

首先按照openwrt的方法修改DTS文件来使能串口2和串口3是不行的,经试验,还是要按照MTK传统的方法,修改内核源码来解决;不同SDK版本可能不一定相同,因此仅供参考。

 

一)首先修改gpio mode使能串口2和串口3;

原厂SDK,默认串口3是不使能的;需要通过修改ralink_gpio.h和ralink_gpio.c来先将串口3使能;

 

linux-ramips_mt7621/linux-3.10.14-p112871/drivers/char/ralink_gpio.h

 

下面是#define RALINK_GPIOMODE_UART3 和 #define RALINK_GPIOMODE_UART2的默认定义

#elif defined (CONFIG_RALINK_MT7621)

 

#define RALINK_GPIOMODE_UART1               0x02

#define RALINK_GPIOMODE_I2C             0x04

#define RALINK_GPIOMODE_UART3               0x08

#define RALINK_GPIOMODE_UART2               0x20

#define RALINK_GPIOMODE_JTAG                   0x80

#define RALINK_GPIOMODE_WDT                   0x100

#define RALINK_GPIOMODE_PERST                 0x400

#define RALINK_GPIOMODE_MDIO                 0x1000

#define RALINK_GPIOMODE_GE1           0x4000

#define RALINK_GPIOMODE_GE2           0x8000

#define RALINK_GPIOMODE_SPI             0x10000

#define RALINK_GPIOMODE_SDXC                  0x40000

#define RALINK_GPIOMODE_ESWINT             0x100000

 

#elif defined (CONFIG_RALINK_MT7628)

 

根据手册中的说明,如果要使能串口2和串口3的话,修改如下

//#define RALINK_GPIOMODE_UART3            0x08

//#define RALINK_GPIOMODE_UART2            0x20

#define RALINK_GPIOMODE_UART3               0x00

#define RALINK_GPIOMODE_UART2               0x00

 

 

另外一个宏是RALINK_GPIOMODE_DFT,定义了板子默认的GPIOMODE;可以根据自己的需求进行修改;

 

// if you would like to enable GPIO mode for other pins, please modify this value

// !! Warning: changing this value may make other features(MDIO, PCI, etc) lose efficacy

#if defined (CONFIG_RALINK_MT7621)

#define RALINK_GPIOMODE_DFT            (RALINK_GPIOMODE_UART2 | RALINK_GPIOMODE_UART3 | RALINK_GPIOMODE_WDT)

#elif defined (CONFIG_RALINK_MT7620)

#define RALINK_GPIOMODE_DFT            (RALINK_GPIOMODE_I2C)

#elif defined (CONFIG_RALINK_MT7628)

#define RALINK_GPIOMODE_DFT            (RALINK_GPIOMODE_UART2 | RALINK_GPIOMODE_UART3) | (RALINK_GPIOMODE_SPI_CS1) | (RALINK_GPIOMODE_WDT)

#else

#define RALINK_GPIOMODE_DFT             (RALINK_GPIOMODE_UARTF)

#endif

 

 

在ralink_gpio.c中它在如下地方使用到;

int __init ralink_gpio_init(void)

{

         unsigned int i;

         u32 gpiomode;

……

 

//config these pins to gpio mode

         gpiomode = le32_to_cpu(*(volatile u32 *)(RALINK_REG_GPIOMODE));

#if !defined (CONFIG_RALINK_RT2880)

         gpiomode &= ~0x1C;  //clear bit[2:4]UARTF_SHARE_MODE

#endif

#if defined (CONFIG_RALINK_MT7620)

         gpiomode &= ~0x2000;  //clear bit[13] WLAN_LED

#endif

#if defined (CONFIG_RALINK_MT7621)

         gpiomode &= ~0x3C;  //clear bit[2:6]UART2_SHARE_MODE UART3_SHARE_MODE

#endif

         gpiomode |= RALINK_GPIOMODE_DFT;

         *(volatile u32 *)(RALINK_REG_GPIOMODE) = cpu_to_le32(gpiomode);

 

 

 

二)在init.c中创建对应的串口设备

 

1)串口的中断号在如下文件中定义

surfboardint.h

#define SURFBOARDINT_UART_LITE1  26     /* UART Lite */

#define SURFBOARDINT_UART_LITE2  27     /* UART Lite */

#define SURFBOARDINT_UART_LITE3  28     /* UART Lite */

#define SURFBOARDINT_UART        SURFBOARDINT_UART_LITE2 //ttyS0

#define SURFBOARDINT_UART1       SURFBOARDINT_UART_LITE1 //ttyS1

 

 

2)修改init.c

linux-ramips_mt7621/linux-3.10.14-p112871/arch/mips/relink/init.c中

 

static struct uart_port serial_req[3];

__init int prom_init_serial_port(void)

{

 

……

#if defined (CONFIG_RALINK_MT7621) 

  serial_req[2].type       = PORT_16550A;

  serial_req[2].line       = 2;

  serial_req[2].irq        = SURFBOARDINT_UART_LITE3;

  serial_req[2].flags      = UPF_FIXED_TYPE;

  serial_req[2].uartclk    = 50000000;

 

  serial_req[2].iotype     = UPIO_MEM32;

  serial_req[2].regshift   = 2;

  serial_req[2].mapbase    = RALINK_UART_LITE3_BASE;

  serial_req[2].membase    = ioremap_nocache(RALINK_UART_LITE3_BASE, PAGE_SIZE);

  early_serial_setup(&serial_req[2]);

#endif

 

以及修改prom_get_ttysnum和serial_setbrg这两个函数,增加对串口3的描述;

 

 

 

三)修改CONFIG_SERIAL_8250_RUNTIME_UARTS

 

通过配置内核,以让串口驱动支持串口3

drivers\tty\serial\8250\8250_core.c

static unsigned int nr_uarts = CONFIG_SERIAL_8250_RUNTIME_UARTS;

 

通过“make  kernel_menuconfig”修改系统串口数量 CONFIG_SERIAL_8250_RUNTIME_UARTS

#

# Serial drivers

#

CONFIG_SERIAL_8250=y

# CONFIG_SERIAL_8250_DEPRECATED_OPTIONS is not set

CONFIG_SERIAL_8250_CONSOLE=y

# CONFIG_SERIAL_8250_PCI is not set

CONFIG_SERIAL_8250_NR_UARTS=4

CONFIG_SERIAL_8250_RUNTIME_UARTS=2

# CONFIG_SERIAL_8250_EXTENDED is not set

# CONFIG_SERIAL_8250_DW is not set

# CONFIG_SERIAL_8250_RT288X is not set

 

 

static void __init serial8250_isa_init_ports(void)

{

         struct uart_8250_port *up;

         static int first = 1;

         int i, irqflag = 0;

 

         if (!first)

                   return;

         first = 0;

 

         if (nr_uarts > UART_NR)

                   nr_uarts = UART_NR;

 

         for (i = 0; i < nr_uarts; i++) {

                   struct uart_8250_port *up = &serial8250_ports[i];

                   struct uart_port *port = &up->port;

 

你可能感兴趣的:(openwrt,ralink)