upstream u-boot with additional patches for our devices/boards:
https://lists.denx.de/pipermail/u-boot/2017-March/282789.html (AXP crashes) ;
Gbit ethernet patch for some LIME2 revisions ;
with SPI flash support
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
369 lines
8.7 KiB
369 lines
8.7 KiB
22 years ago
|
/*
|
||
|
* (INCA) ASC UART support
|
||
|
*/
|
||
|
|
||
22 years ago
|
#include <config.h>
|
||
|
|
||
|
#ifdef CONFIG_PURPLE
|
||
|
#define serial_init asc_serial_init
|
||
|
#define serial_putc asc_serial_putc
|
||
|
#define serial_puts asc_serial_puts
|
||
|
#define serial_getc asc_serial_getc
|
||
|
#define serial_tstc asc_serial_tstc
|
||
|
#define serial_setbrg asc_serial_setbrg
|
||
|
#endif
|
||
|
|
||
22 years ago
|
#include <common.h>
|
||
|
#include <asm/inca-ip.h>
|
||
22 years ago
|
#include "asc_serial.h"
|
||
22 years ago
|
|
||
22 years ago
|
#ifdef CONFIG_PURPLE
|
||
|
|
||
|
#undef ASC_FIFO_PRESENT
|
||
|
#define TOUT_LOOP 100000
|
||
|
|
||
|
/* Set base address for second FPI interrupt control register bank */
|
||
22 years ago
|
#define SFPI_INTCON_BASEADDR 0xBF0F0000
|
||
22 years ago
|
|
||
|
/* Register offset from base address */
|
||
|
#define FBS_ISR 0x00000000 /* Interrupt status register */
|
||
|
#define FBS_IMR 0x00000008 /* Interrupt mask register */
|
||
|
#define FBS_IDIS 0x00000010 /* Interrupt disable register */
|
||
|
|
||
|
/* Interrupt status register bits */
|
||
|
#define FBS_ISR_AT 0x00000040 /* ASC transmit interrupt */
|
||
17 years ago
|
#define FBS_ISR_AR 0x00000020 /* ASC receive interrupt */
|
||
22 years ago
|
#define FBS_ISR_AE 0x00000010 /* ASC error interrupt */
|
||
|
#define FBS_ISR_AB 0x00000008 /* ASC transmit buffer interrupt */
|
||
17 years ago
|
#define FBS_ISR_AS 0x00000004 /* ASC start of autobaud detection interrupt */
|
||
22 years ago
|
#define FBS_ISR_AF 0x00000002 /* ASC end of autobaud detection interrupt */
|
||
|
|
||
|
#else
|
||
|
|
||
|
#define ASC_FIFO_PRESENT
|
||
|
|
||
|
#endif
|
||
|
|
||
|
|
||
22 years ago
|
#define SET_BIT(reg, mask) reg |= (mask)
|
||
|
#define CLEAR_BIT(reg, mask) reg &= (~mask)
|
||
|
#define CLEAR_BITS(reg, mask) CLEAR_BIT(reg, mask)
|
||
|
#define SET_BITS(reg, mask) SET_BIT(reg, mask)
|
||
|
#define SET_BITFIELD(reg, mask, off, val) {reg &= (~mask); reg |= (val << off);}
|
||
|
|
||
|
extern uint incaip_get_fpiclk(void);
|
||
|
|
||
|
static int serial_setopt (void);
|
||
|
|
||
|
/* pointer to ASC register base address */
|
||
|
static volatile incaAsc_t *pAsc = (incaAsc_t *)INCA_IP_ASC;
|
||
|
|
||
|
/******************************************************************************
|
||
|
*
|
||
|
* serial_init - initialize a INCAASC channel
|
||
|
*
|
||
|
* This routine initializes the number of data bits, parity
|
||
|
* and set the selected baud rate. Interrupts are disabled.
|
||
|
* Set the modem control signals if the option is selected.
|
||
|
*
|
||
|
* RETURNS: N/A
|
||
|
*/
|
||
|
|
||
|
int serial_init (void)
|
||
|
{
|
||
22 years ago
|
#ifdef CONFIG_INCA_IP
|
||
22 years ago
|
/* we have to set PMU.EN13 bit to enable an ASC device*/
|
||
|
INCAASC_PMU_ENABLE(13);
|
||
22 years ago
|
#endif
|
||
22 years ago
|
|
||
22 years ago
|
/* and we have to set CLC register*/
|
||
|
CLEAR_BIT(pAsc->asc_clc, ASCCLC_DISS);
|
||
|
SET_BITFIELD(pAsc->asc_clc, ASCCLC_RMCMASK, ASCCLC_RMCOFFSET, 0x0001);
|
||
22 years ago
|
|
||
22 years ago
|
/* initialy we are in async mode */
|
||
|
pAsc->asc_con = ASCCON_M_8ASYNC;
|
||
|
|
||
|
/* select input port */
|
||
|
pAsc->asc_pisel = (CONSOLE_TTY & 0x1);
|
||
|
|
||
22 years ago
|
#ifdef ASC_FIFO_PRESENT
|
||
22 years ago
|
/* TXFIFO's filling level */
|
||
|
SET_BITFIELD(pAsc->asc_txfcon, ASCTXFCON_TXFITLMASK,
|
||
22 years ago
|
ASCTXFCON_TXFITLOFF, INCAASC_TXFIFO_FL);
|
||
22 years ago
|
/* enable TXFIFO */
|
||
|
SET_BIT(pAsc->asc_txfcon, ASCTXFCON_TXFEN);
|
||
|
|
||
|
/* RXFIFO's filling level */
|
||
22 years ago
|
SET_BITFIELD(pAsc->asc_txfcon, ASCRXFCON_RXFITLMASK,
|
||
|
ASCRXFCON_RXFITLOFF, INCAASC_RXFIFO_FL);
|
||
22 years ago
|
/* enable RXFIFO */
|
||
|
SET_BIT(pAsc->asc_rxfcon, ASCRXFCON_RXFEN);
|
||
22 years ago
|
#endif
|
||
22 years ago
|
|
||
|
/* enable error signals */
|
||
|
SET_BIT(pAsc->asc_con, ASCCON_FEN);
|
||
|
SET_BIT(pAsc->asc_con, ASCCON_OEN);
|
||
|
|
||
22 years ago
|
#ifdef CONFIG_INCA_IP
|
||
22 years ago
|
/* acknowledge ASC interrupts */
|
||
|
ASC_INTERRUPTS_CLEAR(INCAASC_IRQ_LINE_ALL);
|
||
|
|
||
|
/* disable ASC interrupts */
|
||
|
ASC_INTERRUPTS_DISABLE(INCAASC_IRQ_LINE_ALL);
|
||
22 years ago
|
#endif
|
||
22 years ago
|
|
||
22 years ago
|
#ifdef ASC_FIFO_PRESENT
|
||
22 years ago
|
/* set FIFOs into the transparent mode */
|
||
|
SET_BIT(pAsc->asc_txfcon, ASCTXFCON_TXTMEN);
|
||
|
SET_BIT(pAsc->asc_rxfcon, ASCRXFCON_RXTMEN);
|
||
22 years ago
|
#endif
|
||
22 years ago
|
|
||
|
/* set baud rate */
|
||
|
serial_setbrg();
|
||
|
|
||
|
/* set the options */
|
||
|
serial_setopt();
|
||
22 years ago
|
|
||
22 years ago
|
return 0;
|
||
|
}
|
||
|
|
||
|
void serial_setbrg (void)
|
||
|
{
|
||
|
ulong uiReloadValue, fdv;
|
||
|
ulong f_ASC;
|
||
|
|
||
22 years ago
|
#ifdef CONFIG_INCA_IP
|
||
22 years ago
|
f_ASC = incaip_get_fpiclk();
|
||
22 years ago
|
#else
|
||
|
f_ASC = ASC_CLOCK_RATE;
|
||
|
#endif
|
||
22 years ago
|
|
||
|
#ifndef INCAASC_USE_FDV
|
||
|
fdv = 2;
|
||
|
uiReloadValue = (f_ASC / (fdv * 16 * CONFIG_BAUDRATE)) - 1;
|
||
22 years ago
|
#else
|
||
22 years ago
|
fdv = INCAASC_FDV_HIGH_BAUDRATE;
|
||
|
uiReloadValue = (f_ASC / (8192 * CONFIG_BAUDRATE / fdv)) - 1;
|
||
|
#endif /* INCAASC_USE_FDV */
|
||
22 years ago
|
|
||
22 years ago
|
if ( (uiReloadValue < 0) || (uiReloadValue > 8191) )
|
||
|
{
|
||
|
#ifndef INCAASC_USE_FDV
|
||
22 years ago
|
fdv = 3;
|
||
|
uiReloadValue = (f_ASC / (fdv * 16 * CONFIG_BAUDRATE)) - 1;
|
||
|
#else
|
||
|
fdv = INCAASC_FDV_LOW_BAUDRATE;
|
||
|
uiReloadValue = (f_ASC / (8192 * CONFIG_BAUDRATE / fdv)) - 1;
|
||
22 years ago
|
#endif /* INCAASC_USE_FDV */
|
||
22 years ago
|
|
||
|
if ( (uiReloadValue < 0) || (uiReloadValue > 8191) )
|
||
|
{
|
||
|
return; /* can't impossibly generate that baud rate */
|
||
|
}
|
||
22 years ago
|
}
|
||
|
|
||
|
/* Disable Baud Rate Generator; BG should only be written when R=0 */
|
||
|
CLEAR_BIT(pAsc->asc_con, ASCCON_R);
|
||
|
|
||
|
#ifndef INCAASC_USE_FDV
|
||
|
/*
|
||
|
* Disable Fractional Divider (FDE)
|
||
|
* Divide clock by reload-value + constant (BRS)
|
||
|
*/
|
||
|
/* FDE = 0 */
|
||
|
CLEAR_BIT(pAsc->asc_con, ASCCON_FDE);
|
||
|
|
||
|
if ( fdv == 2 )
|
||
22 years ago
|
CLEAR_BIT(pAsc->asc_con, ASCCON_BRS); /* BRS = 0 */
|
||
22 years ago
|
else
|
||
22 years ago
|
SET_BIT(pAsc->asc_con, ASCCON_BRS); /* BRS = 1 */
|
||
22 years ago
|
|
||
|
#else /* INCAASC_USE_FDV */
|
||
|
|
||
|
/* Enable Fractional Divider */
|
||
|
SET_BIT(pAsc->asc_con, ASCCON_FDE); /* FDE = 1 */
|
||
|
|
||
|
/* Set fractional divider value */
|
||
|
pAsc->asc_fdv = fdv & ASCFDV_VALUE_MASK;
|
||
|
|
||
|
#endif /* INCAASC_USE_FDV */
|
||
|
|
||
|
/* Set reload value in BG */
|
||
|
pAsc->asc_bg = uiReloadValue;
|
||
|
|
||
|
/* Enable Baud Rate Generator */
|
||
|
SET_BIT(pAsc->asc_con, ASCCON_R); /* R = 1 */
|
||
|
}
|
||
|
|
||
|
/*******************************************************************************
|
||
|
*
|
||
|
* serial_setopt - set the serial options
|
||
|
*
|
||
|
* Set the channel operating mode to that specified. Following options
|
||
|
* are supported: CREAD, CSIZE, PARENB, and PARODD.
|
||
|
*
|
||
|
* Note, this routine disables the transmitter. The calling routine
|
||
|
* may have to re-enable it.
|
||
|
*
|
||
|
* RETURNS:
|
||
|
* Returns 0 to indicate success, otherwise -1 is returned
|
||
|
*/
|
||
|
|
||
|
static int serial_setopt (void)
|
||
|
{
|
||
|
ulong con;
|
||
|
|
||
|
switch ( ASC_OPTIONS & ASCOPT_CSIZE )
|
||
|
{
|
||
|
/* 7-bit-data */
|
||
|
case ASCOPT_CS7:
|
||
22 years ago
|
con = ASCCON_M_7ASYNCPAR; /* 7-bit-data and parity bit */
|
||
|
break;
|
||
22 years ago
|
|
||
|
/* 8-bit-data */
|
||
|
case ASCOPT_CS8:
|
||
22 years ago
|
if ( ASC_OPTIONS & ASCOPT_PARENB )
|
||
|
con = ASCCON_M_8ASYNCPAR; /* 8-bit-data and parity bit */
|
||
|
else
|
||
|
con = ASCCON_M_8ASYNC; /* 8-bit-data no parity */
|
||
|
break;
|
||
|
|
||
|
/*
|
||
22 years ago
|
* only 7 and 8-bit frames are supported
|
||
22 years ago
|
* if we don't use IOCTL extensions
|
||
22 years ago
|
*/
|
||
|
default:
|
||
22 years ago
|
return -1;
|
||
22 years ago
|
}
|
||
|
|
||
|
if ( ASC_OPTIONS & ASCOPT_STOPB )
|
||
22 years ago
|
SET_BIT(con, ASCCON_STP); /* 2 stop bits */
|
||
22 years ago
|
else
|
||
22 years ago
|
CLEAR_BIT(con, ASCCON_STP); /* 1 stop bit */
|
||
22 years ago
|
|
||
|
if ( ASC_OPTIONS & ASCOPT_PARENB )
|
||
22 years ago
|
SET_BIT(con, ASCCON_PEN); /* enable parity checking */
|
||
22 years ago
|
else
|
||
22 years ago
|
CLEAR_BIT(con, ASCCON_PEN); /* disable parity checking */
|
||
|
|
||
22 years ago
|
if ( ASC_OPTIONS & ASCOPT_PARODD )
|
||
22 years ago
|
SET_BIT(con, ASCCON_ODD); /* odd parity */
|
||
22 years ago
|
else
|
||
22 years ago
|
CLEAR_BIT(con, ASCCON_ODD); /* even parity */
|
||
22 years ago
|
|
||
|
if ( ASC_OPTIONS & ASCOPT_CREAD )
|
||
22 years ago
|
SET_BIT(pAsc->asc_whbcon, ASCWHBCON_SETREN); /* Receiver enable */
|
||
22 years ago
|
|
||
|
pAsc->asc_con |= con;
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
void serial_putc (const char c)
|
||
|
{
|
||
22 years ago
|
#ifdef ASC_FIFO_PRESENT
|
||
22 years ago
|
uint txFl = 0;
|
||
22 years ago
|
#else
|
||
|
uint timeout = 0;
|
||
|
#endif
|
||
22 years ago
|
|
||
|
if (c == '\n') serial_putc ('\r');
|
||
|
|
||
22 years ago
|
#ifdef ASC_FIFO_PRESENT
|
||
22 years ago
|
/* check do we have a free space in the TX FIFO */
|
||
|
/* get current filling level */
|
||
|
do
|
||
|
{
|
||
|
txFl = ( pAsc->asc_fstat & ASCFSTAT_TXFFLMASK ) >> ASCFSTAT_TXFFLOFF;
|
||
|
}
|
||
|
while ( txFl == INCAASC_TXFIFO_FULL );
|
||
22 years ago
|
#else
|
||
|
|
||
|
while(!(*(volatile unsigned long*)(SFPI_INTCON_BASEADDR + FBS_ISR) &
|
||
|
FBS_ISR_AB))
|
||
|
{
|
||
|
if (timeout++ > TOUT_LOOP)
|
||
|
{
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
#endif
|
||
22 years ago
|
|
||
|
pAsc->asc_tbuf = c; /* write char to Transmit Buffer Register */
|
||
22 years ago
|
|
||
|
#ifndef ASC_FIFO_PRESENT
|
||
|
*(volatile unsigned long*)(SFPI_INTCON_BASEADDR + FBS_ISR) = FBS_ISR_AB |
|
||
22 years ago
|
FBS_ISR_AT;
|
||
22 years ago
|
#endif
|
||
22 years ago
|
|
||
22 years ago
|
/* check for errors */
|
||
|
if ( pAsc->asc_con & ASCCON_OE )
|
||
|
{
|
||
22 years ago
|
SET_BIT(pAsc->asc_whbcon, ASCWHBCON_CLROE);
|
||
|
return;
|
||
22 years ago
|
}
|
||
|
}
|
||
|
|
||
|
void serial_puts (const char *s)
|
||
|
{
|
||
|
while (*s)
|
||
|
{
|
||
|
serial_putc (*s++);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
int serial_getc (void)
|
||
|
{
|
||
|
ulong symbol_mask;
|
||
|
char c;
|
||
|
|
||
|
while (!serial_tstc());
|
||
|
|
||
|
symbol_mask =
|
||
|
((ASC_OPTIONS & ASCOPT_CSIZE) == ASCOPT_CS7) ? (0x7f) : (0xff);
|
||
22 years ago
|
|
||
22 years ago
|
c = (char)(pAsc->asc_rbuf & symbol_mask);
|
||
|
|
||
22 years ago
|
#ifndef ASC_FIFO_PRESENT
|
||
|
*(volatile unsigned long*)(SFPI_INTCON_BASEADDR + FBS_ISR) = FBS_ISR_AR;
|
||
|
#endif
|
||
|
|
||
22 years ago
|
return c;
|
||
|
}
|
||
|
|
||
|
int serial_tstc (void)
|
||
|
{
|
||
|
int res = 1;
|
||
|
|
||
22 years ago
|
#ifdef ASC_FIFO_PRESENT
|
||
22 years ago
|
if ( (pAsc->asc_fstat & ASCFSTAT_RXFFLMASK) == 0 )
|
||
|
{
|
||
22 years ago
|
res = 0;
|
||
22 years ago
|
}
|
||
22 years ago
|
#else
|
||
|
if (!(*(volatile unsigned long*)(SFPI_INTCON_BASEADDR + FBS_ISR) &
|
||
22 years ago
|
FBS_ISR_AR))
|
||
|
|
||
22 years ago
|
{
|
||
22 years ago
|
res = 0;
|
||
22 years ago
|
}
|
||
|
#endif
|
||
22 years ago
|
else if ( pAsc->asc_con & ASCCON_FE )
|
||
|
{
|
||
22 years ago
|
SET_BIT(pAsc->asc_whbcon, ASCWHBCON_CLRFE);
|
||
|
res = 0;
|
||
22 years ago
|
}
|
||
|
else if ( pAsc->asc_con & ASCCON_PE )
|
||
|
{
|
||
22 years ago
|
SET_BIT(pAsc->asc_whbcon, ASCWHBCON_CLRPE);
|
||
|
res = 0;
|
||
22 years ago
|
}
|
||
|
else if ( pAsc->asc_con & ASCCON_OE )
|
||
|
{
|
||
22 years ago
|
SET_BIT(pAsc->asc_whbcon, ASCWHBCON_CLROE);
|
||
|
res = 0;
|
||
22 years ago
|
}
|
||
|
|
||
|
return res;
|
||
|
}
|