2003-07-16 21:53:01 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2000 - 2003
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*
|
2013-07-08 07:37:19 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2003-07-16 21:53:01 +00:00
|
|
|
*
|
|
|
|
* Hacked for MPC8260 by Murray.Jensen@cmst.csiro.au, 19-Oct-00, with
|
2010-04-15 14:07:28 +00:00
|
|
|
* changes based on the file arch/powerpc/mbxboot/m8260_tty.c from the
|
2003-07-16 21:53:01 +00:00
|
|
|
* Linux/PPC sources (m8260_tty.c had no copyright info in it).
|
2006-06-16 15:04:45 +00:00
|
|
|
*
|
|
|
|
* Martin Krause, 8 Jun 2006
|
2012-09-14 21:44:09 +00:00
|
|
|
* Added SERIAL_MULTI support
|
2003-07-16 21:53:01 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Minimal serial functions needed to use one of the PSC ports
|
|
|
|
* as serial console interface.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2011-04-29 18:03:29 +00:00
|
|
|
#include <linux/compiler.h>
|
2003-07-16 21:53:01 +00:00
|
|
|
#include <mpc5xxx.h>
|
2006-06-16 15:04:45 +00:00
|
|
|
#include <serial.h>
|
|
|
|
|
2006-03-31 16:32:53 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2003-07-16 21:53:01 +00:00
|
|
|
#if defined(CONFIG_PSC_CONSOLE)
|
|
|
|
|
|
|
|
#if CONFIG_PSC_CONSOLE == 1
|
|
|
|
#define PSC_BASE MPC5XXX_PSC1
|
|
|
|
#elif CONFIG_PSC_CONSOLE == 2
|
|
|
|
#define PSC_BASE MPC5XXX_PSC2
|
|
|
|
#elif CONFIG_PSC_CONSOLE == 3
|
|
|
|
#define PSC_BASE MPC5XXX_PSC3
|
|
|
|
#elif CONFIG_PSC_CONSOLE == 4
|
|
|
|
#define PSC_BASE MPC5XXX_PSC4
|
|
|
|
#elif CONFIG_PSC_CONSOLE == 5
|
|
|
|
#define PSC_BASE MPC5XXX_PSC5
|
|
|
|
#elif CONFIG_PSC_CONSOLE == 6
|
|
|
|
#define PSC_BASE MPC5XXX_PSC6
|
|
|
|
#else
|
|
|
|
#error CONFIG_PSC_CONSOLE must be in 1 ... 6
|
|
|
|
#endif
|
|
|
|
|
2012-09-14 21:44:09 +00:00
|
|
|
#if defined(CONFIG_PSC_CONSOLE2)
|
2006-06-16 15:04:45 +00:00
|
|
|
|
|
|
|
#if CONFIG_PSC_CONSOLE2 == 1
|
|
|
|
#define PSC_BASE2 MPC5XXX_PSC1
|
|
|
|
#elif CONFIG_PSC_CONSOLE2 == 2
|
|
|
|
#define PSC_BASE2 MPC5XXX_PSC2
|
|
|
|
#elif CONFIG_PSC_CONSOLE2 == 3
|
|
|
|
#define PSC_BASE2 MPC5XXX_PSC3
|
|
|
|
#elif CONFIG_PSC_CONSOLE2 == 4
|
|
|
|
#define PSC_BASE2 MPC5XXX_PSC4
|
|
|
|
#elif CONFIG_PSC_CONSOLE2 == 5
|
|
|
|
#define PSC_BASE2 MPC5XXX_PSC5
|
|
|
|
#elif CONFIG_PSC_CONSOLE2 == 6
|
|
|
|
#define PSC_BASE2 MPC5XXX_PSC6
|
|
|
|
#else
|
|
|
|
#error CONFIG_PSC_CONSOLE2 must be in 1 ... 6
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
2012-09-14 21:44:09 +00:00
|
|
|
|
|
|
|
int serial_init_dev (unsigned long dev_base)
|
2003-07-16 21:53:01 +00:00
|
|
|
{
|
2006-06-16 15:04:45 +00:00
|
|
|
volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)dev_base;
|
2003-07-16 21:53:01 +00:00
|
|
|
unsigned long baseclk;
|
|
|
|
int div;
|
|
|
|
|
|
|
|
/* reset PSC */
|
|
|
|
psc->command = PSC_SEL_MODE_REG_1;
|
|
|
|
|
|
|
|
/* select clock sources */
|
|
|
|
psc->psc_clock_select = 0;
|
2012-12-13 20:48:53 +00:00
|
|
|
baseclk = (gd->arch.ipb_clk + 16) / 32;
|
2003-07-16 21:53:01 +00:00
|
|
|
|
|
|
|
/* switch to UART mode */
|
|
|
|
psc->sicr = 0;
|
|
|
|
|
|
|
|
/* configure parity, bit length and so on */
|
|
|
|
psc->mode = PSC_MODE_8_BITS | PSC_MODE_PARNONE;
|
|
|
|
psc->mode = PSC_MODE_ONE_STOP;
|
|
|
|
|
|
|
|
/* set up UART divisor */
|
2004-02-09 20:51:26 +00:00
|
|
|
div = (baseclk + (gd->baudrate/2)) / gd->baudrate;
|
|
|
|
psc->ctur = (div >> 8) & 0xff;
|
2003-07-16 21:53:01 +00:00
|
|
|
psc->ctlr = div & 0xff;
|
|
|
|
|
|
|
|
/* disable all interrupts */
|
|
|
|
psc->psc_imr = 0;
|
|
|
|
|
|
|
|
/* reset and enable Rx/Tx */
|
|
|
|
psc->command = PSC_RST_RX;
|
|
|
|
psc->command = PSC_RST_TX;
|
|
|
|
psc->command = PSC_RX_ENABLE | PSC_TX_ENABLE;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2006-06-16 15:04:45 +00:00
|
|
|
void serial_putc_dev (unsigned long dev_base, const char c)
|
2003-07-16 21:53:01 +00:00
|
|
|
{
|
2006-06-16 15:04:45 +00:00
|
|
|
volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)dev_base;
|
2003-07-16 21:53:01 +00:00
|
|
|
|
|
|
|
if (c == '\n')
|
2006-06-16 15:04:45 +00:00
|
|
|
serial_putc_dev (dev_base, '\r');
|
2003-07-16 21:53:01 +00:00
|
|
|
|
|
|
|
/* Wait for last character to go. */
|
|
|
|
while (!(psc->psc_status & PSC_SR_TXEMP))
|
|
|
|
;
|
|
|
|
|
|
|
|
psc->psc_buffer_8 = c;
|
|
|
|
}
|
|
|
|
|
2006-06-16 15:04:45 +00:00
|
|
|
void serial_puts_dev (unsigned long dev_base, const char *s)
|
2003-07-16 21:53:01 +00:00
|
|
|
{
|
|
|
|
while (*s) {
|
2006-06-16 15:04:45 +00:00
|
|
|
serial_putc_dev (dev_base, *s++);
|
2003-07-16 21:53:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-16 15:04:45 +00:00
|
|
|
int serial_getc_dev (unsigned long dev_base)
|
2003-07-16 21:53:01 +00:00
|
|
|
{
|
2006-06-16 15:04:45 +00:00
|
|
|
volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)dev_base;
|
2003-07-16 21:53:01 +00:00
|
|
|
|
|
|
|
/* Wait for a character to arrive. */
|
|
|
|
while (!(psc->psc_status & PSC_SR_RXRDY))
|
|
|
|
;
|
|
|
|
|
|
|
|
return psc->psc_buffer_8;
|
|
|
|
}
|
|
|
|
|
2006-06-16 15:04:45 +00:00
|
|
|
int serial_tstc_dev (unsigned long dev_base)
|
2003-07-16 21:53:01 +00:00
|
|
|
{
|
2006-06-16 15:04:45 +00:00
|
|
|
volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)dev_base;
|
2003-07-16 21:53:01 +00:00
|
|
|
|
|
|
|
return (psc->psc_status & PSC_SR_RXRDY);
|
|
|
|
}
|
|
|
|
|
2006-06-16 15:04:45 +00:00
|
|
|
void serial_setbrg_dev (unsigned long dev_base)
|
2003-07-16 21:53:01 +00:00
|
|
|
{
|
2006-06-16 15:04:45 +00:00
|
|
|
volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)dev_base;
|
2003-07-16 21:53:01 +00:00
|
|
|
unsigned long baseclk, div;
|
|
|
|
|
2012-12-13 20:48:53 +00:00
|
|
|
baseclk = (gd->arch.ipb_clk + 16) / 32;
|
2003-07-16 21:53:01 +00:00
|
|
|
|
|
|
|
/* set up UART divisor */
|
2005-06-27 13:30:03 +00:00
|
|
|
div = (baseclk + (gd->baudrate/2)) / gd->baudrate;
|
2005-09-24 23:09:58 +00:00
|
|
|
psc->ctur = (div >> 8) & 0xFF;
|
|
|
|
psc->ctlr = div & 0xff;
|
2003-07-16 21:53:01 +00:00
|
|
|
}
|
2006-06-16 15:04:45 +00:00
|
|
|
|
2006-08-30 21:09:00 +00:00
|
|
|
void serial_setrts_dev (unsigned long dev_base, int s)
|
|
|
|
{
|
|
|
|
volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)dev_base;
|
|
|
|
|
|
|
|
if (s) {
|
|
|
|
/* Assert RTS (become LOW) */
|
|
|
|
psc->op1 = 0x1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Negate RTS (become HIGH) */
|
|
|
|
psc->op0 = 0x1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int serial_getcts_dev (unsigned long dev_base)
|
|
|
|
{
|
|
|
|
volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)dev_base;
|
|
|
|
|
|
|
|
return (psc->ip & 0x1) ? 0 : 1;
|
|
|
|
}
|
|
|
|
|
2006-06-16 15:04:45 +00:00
|
|
|
int serial0_init(void)
|
|
|
|
{
|
|
|
|
return (serial_init_dev(PSC_BASE));
|
|
|
|
}
|
|
|
|
|
|
|
|
void serial0_setbrg (void)
|
|
|
|
{
|
|
|
|
serial_setbrg_dev(PSC_BASE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void serial0_putc(const char c)
|
|
|
|
{
|
|
|
|
serial_putc_dev(PSC_BASE,c);
|
|
|
|
}
|
|
|
|
|
|
|
|
void serial0_puts(const char *s)
|
|
|
|
{
|
|
|
|
serial_puts_dev(PSC_BASE, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
int serial0_getc(void)
|
|
|
|
{
|
|
|
|
return(serial_getc_dev(PSC_BASE));
|
|
|
|
}
|
|
|
|
|
|
|
|
int serial0_tstc(void)
|
|
|
|
{
|
|
|
|
return (serial_tstc_dev(PSC_BASE));
|
|
|
|
}
|
|
|
|
|
|
|
|
struct serial_device serial0_device =
|
|
|
|
{
|
2012-09-09 16:48:28 +00:00
|
|
|
.name = "serial0",
|
|
|
|
.start = serial0_init,
|
|
|
|
.stop = NULL,
|
|
|
|
.setbrg = serial0_setbrg,
|
|
|
|
.getc = serial0_getc,
|
|
|
|
.tstc = serial0_tstc,
|
|
|
|
.putc = serial0_putc,
|
|
|
|
.puts = serial0_puts,
|
2006-06-16 15:04:45 +00:00
|
|
|
};
|
|
|
|
|
2011-04-29 18:03:29 +00:00
|
|
|
__weak struct serial_device *default_serial_console(void)
|
|
|
|
{
|
|
|
|
return &serial0_device;
|
|
|
|
}
|
|
|
|
|
2012-09-14 21:44:09 +00:00
|
|
|
#ifdef CONFIG_PSC_CONSOLE2
|
|
|
|
int serial1_init(void)
|
|
|
|
{
|
|
|
|
return serial_init_dev(PSC_BASE2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void serial1_setbrg(void)
|
|
|
|
{
|
|
|
|
serial_setbrg_dev(PSC_BASE2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void serial1_putc(const char c)
|
|
|
|
{
|
|
|
|
serial_putc_dev(PSC_BASE2, c);
|
|
|
|
}
|
|
|
|
|
|
|
|
void serial1_puts(const char *s)
|
|
|
|
{
|
|
|
|
serial_puts_dev(PSC_BASE2, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
int serial1_getc(void)
|
|
|
|
{
|
|
|
|
return serial_getc_dev(PSC_BASE2);
|
|
|
|
}
|
|
|
|
|
|
|
|
int serial1_tstc(void)
|
|
|
|
{
|
|
|
|
return serial_tstc_dev(PSC_BASE2);
|
|
|
|
}
|
|
|
|
|
2006-06-16 15:04:45 +00:00
|
|
|
struct serial_device serial1_device =
|
|
|
|
{
|
2012-09-09 16:48:28 +00:00
|
|
|
.name = "serial1",
|
|
|
|
.start = serial1_init,
|
|
|
|
.stop = NULL,
|
|
|
|
.setbrg = serial1_setbrg,
|
|
|
|
.getc = serial1_getc,
|
|
|
|
.tstc = serial1_tstc,
|
|
|
|
.putc = serial1_putc,
|
|
|
|
.puts = serial1_puts,
|
2006-06-16 15:04:45 +00:00
|
|
|
};
|
2012-09-14 21:44:09 +00:00
|
|
|
#endif /* CONFIG_PSC_CONSOLE2 */
|
2006-06-16 15:04:45 +00:00
|
|
|
|
2003-07-16 21:53:01 +00:00
|
|
|
#endif /* CONFIG_PSC_CONSOLE */
|