参考资料:

海思Hi3515的UART2和UART3是如何被加载到内核中的

http://blog.163.com/softtwo_2/blog/static/27007702201272364522572/


Hi3520D和Hi3515有些不一样的地方;

Hi3520D的UART驱动位于linux-3.0.y/drivers/tty/serial/amba-pl011.c


添加UART2和UART3需要修改的文件为:linux-3.0.y/arch/arm/mach-hi3520d/core.c和linux-3.0.y/arch/arm/mach-hi3520d/include/mach/irqs.h两个文件;

首先修改 core.c文件,在309行左右的位置修改成如下:

HIL_AMBA_DEVICE(uart0, "uart:0",  UART0,    NULL);
HIL_AMBA_DEVICE(uart1, "uart:1",  UART1,    NULL);
HIL_AMBA_DEVICE(uart2, "uart:2",  UART2,    NULL);
HIL_AMBA_DEVICE(uart3, "uart:3",  UART3,    NULL);


static struct amba_device *amba_devs[] __initdata = {
	&HIL_AMBADEV_NAME(uart0),
	&HIL_AMBADEV_NAME(uart1),
	&HIL_AMBADEV_NAME(uart2),
	&HIL_AMBADEV_NAME(uart3),
};

static struct clk uart_clk;
static struct clk_lookup lookups[4];

static void  uart_clk_init(unsigned long clk)
{
	uart_clk.rate = clk;

	lookups[0].dev_id = "uart:0";
	lookups[0].clk = &uart_clk;

	lookups[1].dev_id = "uart:1";
	lookups[1].clk = &uart_clk;
	
	lookups[2].dev_id = "uart:2";
	lookups[2].clk = &uart_clk;

	lookups[3].dev_id = "uart:3";
	lookups[3].clk = &uart_clk;
}


然后修改irqs.h文件,修改为如下

#define UART0_IRQ		(HI3520D_IRQ_START + 8)
#define UART1_IRQ		(HI3520D_IRQ_START + 9)
#define UART2_IRQ		(HI3520D_IRQ_START + 10)
#define UART3_IRQ		(HI3520D_IRQ_START + 11)

这个样文件就修改完成了;重新编译内核应该就能在dev底下出现ttyAMA2和ttyAMA3了;


备注:还有就是编写串口程序时,需要把GPIO口复用为串口;

HI_MPI_SYS_SetReg(IOCFG_BASE_ADDR+0x050,0x01);			/*	设置GPIO5_1为UART1_RXD					*/
HI_MPI_SYS_SetReg(IOCFG_BASE_ADDR+0x058,0x01);			/*	设置GPIO5_3为UART1_TXD					*/

HI_MPI_SYS_SetReg(IOCFG_BASE_ADDR+0x05C,0x01);			/*	设置GPIO5_4为UART2_RXD					*/
HI_MPI_SYS_SetReg(IOCFG_BASE_ADDR+0x060,0x01);			/*	设置GPIO5_5为UART2_TXD					*/

HI_MPI_SYS_SetReg(IOCFG_BASE_ADDR+0x0B8,0x01);			/*	设置GPIO1_0为UART3_TXD					*/
HI_MPI_SYS_SetReg(IOCFG_BASE_ADDR+0x0BC,0x01);			/*	设置GPIO1_1为UART3_RXD					*/


ARM AMBA PL011 的那个源码在 linux-3.0.y/drivers/tty/serial/amba-pl011.c
进入到内核根目录执行makemenuconfig命令 跳出
选择Device Drivers -> Character devices-> Serial drives 
进入后查看需要将ARM AMBA PL011 加载进内核编译;


Logo

更多推荐