2007-07-27 12:43:59 +00:00
|
|
|
/*
|
2009-05-16 08:47:43 +00:00
|
|
|
* (C) Copyright 2000 - 2009
|
2007-07-27 12:43:59 +00:00
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*
|
|
|
|
* See file CREDITS for list of people who contributed to this
|
|
|
|
* project.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
* Based ont the MPC5200 PSC driver.
|
|
|
|
* Adapted for MPC512x by Jan Wrobel <wrr@semihalf.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Minimal serial functions needed to use one of the PSC ports
|
|
|
|
* as serial console interface.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2009-05-16 08:47:43 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/processor.h>
|
2007-07-27 12:43:59 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
#if defined(CONFIG_PSC_CONSOLE)
|
|
|
|
|
|
|
|
static void fifo_init (volatile psc512x_t *psc)
|
|
|
|
{
|
2008-10-16 13:01:15 +00:00
|
|
|
volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
|
2007-07-27 12:43:59 +00:00
|
|
|
|
|
|
|
/* reset Rx & Tx fifo slice */
|
2009-05-16 08:47:43 +00:00
|
|
|
out_be32(&psc->rfcmd, PSC_FIFO_RESET_SLICE);
|
|
|
|
out_be32(&psc->tfcmd, PSC_FIFO_RESET_SLICE);
|
2007-07-27 12:43:59 +00:00
|
|
|
|
|
|
|
/* disable Tx & Rx FIFO interrupts */
|
2009-05-16 08:47:43 +00:00
|
|
|
out_be32(&psc->rfintmask, 0);
|
|
|
|
out_be32(&psc->tfintmask, 0);
|
2007-07-27 12:43:59 +00:00
|
|
|
|
2009-05-16 08:47:43 +00:00
|
|
|
out_be32(&psc->tfsize, CONSOLE_FIFO_TX_SIZE | (CONSOLE_FIFO_TX_ADDR << 16));
|
|
|
|
out_be32(&psc->rfsize, CONSOLE_FIFO_RX_SIZE | (CONSOLE_FIFO_RX_ADDR << 16));
|
2007-07-27 12:43:59 +00:00
|
|
|
|
|
|
|
/* enable Tx & Rx FIFO slice */
|
2009-05-16 08:47:43 +00:00
|
|
|
out_be32(&psc->rfcmd, PSC_FIFO_ENABLE_SLICE);
|
|
|
|
out_be32(&psc->tfcmd, PSC_FIFO_ENABLE_SLICE);
|
2007-07-27 12:43:59 +00:00
|
|
|
|
2009-05-16 08:47:43 +00:00
|
|
|
out_be32(&im->fifoc.fifoc_cmd, FIFOC_DISABLE_CLOCK_GATE);
|
2007-07-27 12:43:59 +00:00
|
|
|
__asm__ volatile ("sync");
|
|
|
|
}
|
|
|
|
|
2009-06-02 14:53:16 +00:00
|
|
|
void serial_setbrg(void)
|
|
|
|
{
|
|
|
|
volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
|
|
|
|
volatile psc512x_t *psc = (psc512x_t *) &im->psc[CONFIG_PSC_CONSOLE];
|
|
|
|
unsigned long baseclk, div;
|
|
|
|
|
|
|
|
/* calculate dividor for setting PSC CTUR and CTLR registers */
|
|
|
|
baseclk = (gd->ips_clk + 8) / 16;
|
|
|
|
div = (baseclk + (gd->baudrate / 2)) / gd->baudrate;
|
|
|
|
|
|
|
|
out_8(&psc->ctur, (div >> 8) & 0xff);
|
|
|
|
out_8(&psc->ctlr, div & 0xff); /* set baudrate */
|
|
|
|
}
|
|
|
|
|
2007-07-27 12:43:59 +00:00
|
|
|
int serial_init(void)
|
|
|
|
{
|
2008-10-16 13:01:15 +00:00
|
|
|
volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
|
2007-07-27 12:43:59 +00:00
|
|
|
volatile psc512x_t *psc = (psc512x_t *) &im->psc[CONFIG_PSC_CONSOLE];
|
|
|
|
|
|
|
|
fifo_init (psc);
|
|
|
|
|
|
|
|
/* set MR register to point to MR1 */
|
2009-05-16 08:47:43 +00:00
|
|
|
out_8(&psc->command, PSC_SEL_MODE_REG_1);
|
2007-07-27 12:43:59 +00:00
|
|
|
|
|
|
|
/* disable Tx/Rx */
|
2009-05-16 08:47:43 +00:00
|
|
|
out_8(&psc->command, PSC_TX_DISABLE | PSC_RX_DISABLE);
|
2007-07-27 12:43:59 +00:00
|
|
|
|
|
|
|
/* choose the prescaler by 16 for the Tx/Rx clock generation */
|
2009-05-16 08:47:43 +00:00
|
|
|
out_be16(&psc->psc_clock_select, 0xdd00);
|
2007-07-27 12:43:59 +00:00
|
|
|
|
|
|
|
/* switch to UART mode */
|
2009-05-16 08:47:43 +00:00
|
|
|
out_be32(&psc->sicr, 0);
|
2007-07-27 12:43:59 +00:00
|
|
|
|
|
|
|
/* mode register points to mr1 */
|
|
|
|
/* configure parity, bit length and so on in mode register 1*/
|
2009-05-16 08:47:43 +00:00
|
|
|
out_8(&psc->mode, PSC_MODE_8_BITS | PSC_MODE_PARNONE);
|
2007-07-27 12:43:59 +00:00
|
|
|
/* now, mode register points to mr2 */
|
2009-05-16 08:47:43 +00:00
|
|
|
out_8(&psc->mode, PSC_MODE_1_STOPBIT);
|
2007-07-27 12:43:59 +00:00
|
|
|
|
|
|
|
/* set baudrate */
|
2009-06-02 14:53:16 +00:00
|
|
|
serial_setbrg();
|
2007-07-27 12:43:59 +00:00
|
|
|
|
|
|
|
/* disable all interrupts */
|
2009-05-16 08:47:43 +00:00
|
|
|
out_be16(&psc->psc_imr, 0);
|
2007-07-27 12:43:59 +00:00
|
|
|
|
|
|
|
/* reset and enable Rx/Tx */
|
2009-05-16 08:47:43 +00:00
|
|
|
out_8(&psc->command, PSC_RST_RX);
|
|
|
|
out_8(&psc->command, PSC_RST_TX);
|
|
|
|
out_8(&psc->command, PSC_RX_ENABLE | PSC_TX_ENABLE);
|
2007-07-27 12:43:59 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void serial_putc (const char c)
|
|
|
|
{
|
2008-10-16 13:01:15 +00:00
|
|
|
volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
|
2007-07-27 12:43:59 +00:00
|
|
|
volatile psc512x_t *psc = (psc512x_t *) &im->psc[CONFIG_PSC_CONSOLE];
|
|
|
|
|
|
|
|
if (c == '\n')
|
|
|
|
serial_putc ('\r');
|
|
|
|
|
|
|
|
/* Wait for last character to go. */
|
2009-05-16 08:47:43 +00:00
|
|
|
while (!(in_be16(&psc->psc_status) & PSC_SR_TXEMP))
|
2007-07-27 12:43:59 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
psc->tfdata_8 = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
void serial_putc_raw (const char c)
|
|
|
|
{
|
2008-10-16 13:01:15 +00:00
|
|
|
volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
|
2007-07-27 12:43:59 +00:00
|
|
|
volatile psc512x_t *psc = (psc512x_t *) &im->psc[CONFIG_PSC_CONSOLE];
|
|
|
|
|
|
|
|
/* Wait for last character to go. */
|
2009-05-16 08:47:43 +00:00
|
|
|
while (!(in_be16(&psc->psc_status) & PSC_SR_TXEMP))
|
2007-07-27 12:43:59 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
psc->tfdata_8 = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void serial_puts (const char *s)
|
|
|
|
{
|
|
|
|
while (*s) {
|
|
|
|
serial_putc (*s++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int serial_getc (void)
|
|
|
|
{
|
2008-10-16 13:01:15 +00:00
|
|
|
volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
|
2007-07-27 12:43:59 +00:00
|
|
|
volatile psc512x_t *psc = (psc512x_t *) &im->psc[CONFIG_PSC_CONSOLE];
|
|
|
|
|
|
|
|
/* Wait for a character to arrive. */
|
2009-05-16 08:47:43 +00:00
|
|
|
while (in_be32(&psc->rfstat) & PSC_FIFO_EMPTY)
|
2007-07-27 12:43:59 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
return psc->rfdata_8;
|
|
|
|
}
|
|
|
|
|
|
|
|
int serial_tstc (void)
|
|
|
|
{
|
2008-10-16 13:01:15 +00:00
|
|
|
volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
|
2007-07-27 12:43:59 +00:00
|
|
|
volatile psc512x_t *psc = (psc512x_t *) &im->psc[CONFIG_PSC_CONSOLE];
|
|
|
|
|
2009-05-16 08:47:43 +00:00
|
|
|
return !(in_be32(&psc->rfstat) & PSC_FIFO_EMPTY);
|
2007-07-27 12:43:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void serial_setrts(int s)
|
|
|
|
{
|
2008-10-16 13:01:15 +00:00
|
|
|
volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
|
2007-07-27 12:43:59 +00:00
|
|
|
volatile psc512x_t *psc = (psc512x_t *) &im->psc[CONFIG_PSC_CONSOLE];
|
|
|
|
|
|
|
|
if (s) {
|
|
|
|
/* Assert RTS (become LOW) */
|
2009-05-16 08:47:43 +00:00
|
|
|
out_8(&psc->op1, 0x1);
|
2007-07-27 12:43:59 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Negate RTS (become HIGH) */
|
2009-05-16 08:47:43 +00:00
|
|
|
out_8(&psc->op0, 0x1);
|
2007-07-27 12:43:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int serial_getcts(void)
|
|
|
|
{
|
2008-10-16 13:01:15 +00:00
|
|
|
volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
|
2007-07-27 12:43:59 +00:00
|
|
|
volatile psc512x_t *psc = (psc512x_t *) &im->psc[CONFIG_PSC_CONSOLE];
|
|
|
|
|
2009-05-16 08:47:43 +00:00
|
|
|
return (in_8(&psc->ip) & 0x1) ? 0 : 1;
|
2007-07-27 12:43:59 +00:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_PSC_CONSOLE */
|