예제 #1
0
/*
 * Intialise the serial port with given baudrate
 */
int serial_init_port (int port)
{
	int ret;
	unsigned port_base = port_base_addrs[port];
//    serial_puts_port(port," ");
	while((readl(P_UART_STATUS(port_base)) & (UART_STAT_MASK_XMIT_BUSY)));

    writel(0,P_UART_CONTROL(port_base));
    ret = serial_set_pin_port(port);
    if (ret < 0)
    	return -1;
    
    serial_setbrg_port(port);
#ifndef CONFIG_SERIAL_STP_BITS
#define CONFIG_SERIAL_STP_BITS 1
#endif    
    serial_set_stop_port(port,CONFIG_SERIAL_STP_BITS);
#ifndef CONFIG_SERIAL_PRTY_TYPE
#define CONFIG_SERIAL_PRTY_TYPE 0
#endif

    serial_set_parity_port(port,CONFIG_SERIAL_PRTY_TYPE);
#ifndef CONFIG_SERIAL_CHAR_LEN
#define CONFIG_SERIAL_CHAR_LEN 8
#endif
    serial_set_dlen_port(port,CONFIG_SERIAL_CHAR_LEN);
    writel(readl(P_UART_CONTROL(port_base)) | UART_CNTL_MASK_TX_EN | UART_CNTL_MASK_RX_EN, P_UART_CONTROL(port_base));
    while(!(readl(P_UART_STATUS(port_base)) & UART_STAT_MASK_TFIFO_EMPTY));
    serial_reset_port(port);    
    while((readl(P_UART_STATUS(port_base)) & (UART_STAT_MASK_XMIT_BUSY)));
    serial_putc_port(port,'\n');
   
    return 0;
}
예제 #2
0
static void serial_clr_err (int port)
{
    /* write to the register */
	unsigned port_base=port_base_addrs[port];
	if(readl(P_UART_STATUS(port_base))&(UART_STAT_MASK_PRTY_ERR|UART_STAT_MASK_FRAM_ERR))
		writel((readl(P_UART_CONTROL(port_base)) | UART_CNTL_MASK_CLR_ERR), P_UART_CONTROL(port_base));
}
예제 #3
0
/*
 * Sets data length
 * input[0]: Character length [5, 6, 7, 8]
 */
static void serial_set_dlen_port (int port,int data_len)
{
    unsigned long uart_config;
    unsigned port_base=port_base_addrs[port];
    uart_config = readl(P_UART_CONTROL(port_base)) & ~UART_CNTL_MASK_CHAR_LEN;
    /* data bits */
    switch(data_len)
    {
        case 5:
            uart_config |= UART_CNTL_MASK_CHAR_5BIT;
            break;
        case 6:
            uart_config |= UART_CNTL_MASK_CHAR_6BIT;
            break;
        case 7:
            uart_config |= UART_CNTL_MASK_CHAR_7BIT;
            break;
        case 8:
        default:
            uart_config |= UART_CNTL_MASK_CHAR_8BIT;
            break;
    }   
    
    /* write to the register */
    writel(uart_config, P_UART_CONTROL(port_base));
}
예제 #4
0
파일: serial.c 프로젝트: alpha-it/u-boot
static void serial_init(unsigned set,unsigned tag)
{
	if(arc_param->serial_disable)
		return;

    /* baud rate */
    /*unsigned baud_para=0;*/
    if(tag){//reset uart.
	    setbits_le32(P_AO_RTI_GEN_CNTL_REG0,1<<17);
	    clrbits_le32(P_AO_RTI_GEN_CNTL_REG0,1<<17);
	    delay_ms(10);
			//delay_tick(32*1000);
			//delay_tick(32*1000);
    }

	writel((set&0xfff)
	      | UART_STP_BIT
        | UART_PRTY_BIT
        | UART_CHAR_LEN
        //please do not remove these setting , jerry.yu
        | UART_CNTL_MASK_TX_EN
        | UART_CNTL_MASK_RX_EN
        | UART_CNTL_MASK_RST_TX
        | UART_CNTL_MASK_RST_RX
        | UART_CNTL_MASK_CLR_ERR
	,P_UART_CONTROL(UART_PORT_CONS));
	clrsetbits_le32(P_AO_UART_MISC ,0xf<<20,(set&0xf000)<<8);
  serial_set_pin_port(UART_PORT_CONS);
  clrbits_le32(P_UART_CONTROL(UART_PORT_CONS),
	    UART_CNTL_MASK_RST_TX | UART_CNTL_MASK_RST_RX | UART_CNTL_MASK_CLR_ERR);

}
예제 #5
0
파일: serial.c 프로젝트: alpha-it/u-boot
void uart_reset()
{
	if(arc_param->serial_disable)
		return;

	if(readl(P_UART_REG5(UART_PORT_CONS))==0){
	unsigned uart_cfg = readl(P_UART_CONTROL(UART_PORT_CONS));
	unsigned uart_misc = readl(P_AO_UART_MISC);
	setbits_le32(P_AO_RTI_GEN_CNTL_REG0,1<<17);
	clrbits_le32(P_AO_RTI_GEN_CNTL_REG0,1<<17);
	__udelay(100);
	writel(uart_cfg,P_UART_CONTROL(UART_PORT_CONS));
	writel(uart_misc,P_AO_UART_MISC);
	}else{
	unsigned uart_cfg = readl(P_UART_CONTROL(UART_PORT_CONS));
	unsigned uart_misc = readl(P_AO_UART_MISC);
	unsigned new_baudrate=readl(P_UART_REG5(UART_PORT_CONS));
	setbits_le32(P_AO_RTI_GEN_CNTL_REG0,1<<17);
	clrbits_le32(P_AO_RTI_GEN_CNTL_REG0,1<<17);
	__udelay(100);
	writel(uart_cfg,P_UART_CONTROL(UART_PORT_CONS));
	writel(uart_misc,P_AO_UART_MISC);
	writel(new_baudrate,P_UART_REG5(UART_PORT_CONS));
	__udelay(100);
	}
}
예제 #6
0
파일: serial.c 프로젝트: alpha-it/u-boot
/*
 * Read a single byte from the serial port.
 */
SPL_STATIC_FUNC
int serial_getc(void)
{
    unsigned char ch;
    /* Wait till character is placed in fifo */
  	while((readl(P_UART_STATUS(UART_PORT_CONS)) & UART_STAT_MASK_RFIFO_CNT)==0) ;

    /* Also check for overflow errors */
    if (readl(P_UART_STATUS(UART_PORT_CONS)) & (UART_STAT_MASK_PRTY_ERR | UART_STAT_MASK_FRAM_ERR))
	{
	    setbits_le32(P_UART_CONTROL(UART_PORT_CONS),UART_CNTL_MASK_CLR_ERR);
	    clrbits_le32(P_UART_CONTROL(UART_PORT_CONS),UART_CNTL_MASK_CLR_ERR);
	}

    ch = readl(P_UART_RFIFO(UART_PORT_CONS)) & 0x00ff;
    return ((int)ch);

}
예제 #7
0
/*
 * Read a single byte from the serial port. 
 */
int serial_getc_port (int port)
{
    unsigned char ch;   
    unsigned port_base = port_base_addrs[port];
    /* Wait till character is placed in fifo */
  	while((readl(P_UART_STATUS(port_base)) & UART_STAT_MASK_RFIFO_CNT)==0) ;
  	ch = readl(P_UART_RFIFO(port_base)) & 0x00ff;
    /* Also check for overflow errors */
    if (readl(P_UART_STATUS(port_base)) & (UART_STAT_MASK_PRTY_ERR | UART_STAT_MASK_FRAM_ERR))
    {
    	writel(readl(P_UART_CONTROL(port_base)) |UART_CNTL_MASK_CLR_ERR,P_UART_CONTROL(port_base));//clear errors
        writel(readl(P_UART_CONTROL(port_base)) & (~UART_CNTL_MASK_CLR_ERR),P_UART_CONTROL(port_base));

    }
    

    return ((int)ch);

}
예제 #8
0
/*
 * Sets stop bits
 * input[0]: stop_bits (1, 2)
 */
static void serial_set_stop_port (int port,int stop_bits)
{   
    unsigned long uart_config;
    unsigned port_base=port_base_addrs[port];

    uart_config = readl(P_UART_CONTROL(port_base)) & ~UART_CNTL_MASK_STP_BITS;
    /* stop bits */
    switch(stop_bits)
    {
        case 2:
            uart_config |= UART_CNTL_MASK_STP_2BIT;
            break;
        case 1:
        default:
            uart_config |= UART_CNTL_MASK_STP_1BIT;
            break;      
    }
    
    /* write to the register */
    writel(uart_config, P_UART_CONTROL(port_base));
}
예제 #9
0
파일: serial.c 프로젝트: alpha-it/u-boot
SPL_STATIC_FUNC void serial_init(unsigned set)
{
    /* baud rate */
	writel(set
	    |UART_CNTL_MASK_RST_TX
	    |UART_CNTL_MASK_RST_RX
	    |UART_CNTL_MASK_CLR_ERR
	    |UART_CNTL_MASK_TX_EN
	    |UART_CNTL_MASK_RX_EN
	,P_UART_CONTROL(UART_PORT_CONS));
	switch(readl(0xd9040004))
	{
	case 0x74e: //M8B revA
	case 0xb72: //M8M2 revA
		writel(	(1<<24)|(1 << 23)|((8000000/(CONFIG_BAUDRATE)) -1),0xc81004d4); // set xtal as M8B/M8M2 uart-ao clock source,xtal is 24000000,
	    //new baudrate formula is (24000000/3/baudrate),0xc81004d4 is AO_UART0_REG5 address
		break;
	}
    serial_set_pin_port(UART_PORT_CONS);
    clrbits_le32(P_UART_CONTROL(UART_PORT_CONS),
	    UART_CNTL_MASK_RST_TX | UART_CNTL_MASK_RST_RX | UART_CNTL_MASK_CLR_ERR);

}
예제 #10
0
/*
 * Sets parity type
 * input[0]: 1 -- enable parity, 0 -- disable;
 * input[1]: 1 -- odd parity, 0 -- even parity;
 */
static void serial_set_parity_port(int port,int type)
{
    unsigned long uart_config;
    unsigned port_base=port_base_addrs[port];

    uart_config = readl(P_UART_CONTROL(port_base)) & ~(UART_CNTL_MASK_PRTY_TYPE | UART_CNTL_MASK_PRTY_EN);
#if 0   //changed by Elvis --- disable parity
    uart_config |= UART_CNTL_MASK_PRTY_EN;
    /* parity bits */
    if(type&2)
        uart_config |= UART_CNTL_MASK_PRTY_EN;
    if(type&1)
        uart_config |= UART_CNTL_MASK_PRTY_ODD;
    else
        uart_config |= UART_CNTL_MASK_PRTY_EVEN;
 #endif   
    /* write to the register */
    writel(uart_config, P_UART_CONTROL(port_base));
//    if(port==UART_B)
//    {
//        while(1)
//        serial_puts_port(UART_B,"aaa\n");
//    }
}
예제 #11
0
/*
 * Sets baudarate
 */
void serial_setbrg_port (int port)
{
        
    unsigned long baud_para;
    DECLARE_GLOBAL_DATA_PTR;
    unsigned port_base=port_base_addrs[port];
    
    /* baud rate */
    baud_para=get_clk81()/(gd->baudrate*4) -1;
//   baud_para=25000000/(115200*4) -1;

    baud_para &= UART_CNTL_MASK_BAUD_RATE;
    
    /* write to the register */ 
    writel((readl(P_UART_CONTROL(port_base)) & ~UART_CNTL_MASK_BAUD_RATE) | baud_para, P_UART_CONTROL(port_base));
}
예제 #12
0
/*
 * reset the uart state machine
 */
static void serial_reset_port(int port) {
	unsigned port_base = port_base_addrs[port];
	/* write to the register */
	writel(readl(P_UART_CONTROL(port_base)) | UART_CNTL_MASK_RST_TX | UART_CNTL_MASK_RST_RX | UART_CNTL_MASK_CLR_ERR, P_UART_CONTROL(port_base));
	writel(readl(P_UART_CONTROL(port_base)) & ~(UART_CNTL_MASK_RST_TX | UART_CNTL_MASK_RST_RX | UART_CNTL_MASK_CLR_ERR), P_UART_CONTROL(port_base));
}
예제 #13
0
파일: serial.c 프로젝트: alpha-it/u-boot
static void serial_clr_err(void)
{
    if(readl(P_UART_STATUS(UART_PORT_CONS))&(UART_STAT_MASK_PRTY_ERR|UART_STAT_MASK_FRAM_ERR))
	    setbits_le32(P_UART_CONTROL(UART_PORT_CONS),UART_CNTL_MASK_CLR_ERR);
}