2 * (C) Copyright 2000 - 2003
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * Hacked for MPC8260 by Murray.Jensen@cmst.csiro.au, 19-Oct-00, with
24 * changes based on the file arch/ppc/mbxboot/m8260_tty.c from the
25 * Linux/PPC sources (m8260_tty.c had no copyright info in it).
29 * Minimal serial functions needed to use one of the PSC ports
30 * as serial console interface.
36 #if defined(CONFIG_PSC_CONSOLE)
38 #if CONFIG_PSC_CONSOLE == 1
39 #define PSC_BASE MPC5XXX_PSC1
40 #elif CONFIG_PSC_CONSOLE == 2
41 #define PSC_BASE MPC5XXX_PSC2
42 #elif CONFIG_PSC_CONSOLE == 3
43 #define PSC_BASE MPC5XXX_PSC3
44 #elif defined(CONFIG_MGT5100)
45 #error CONFIG_PSC_CONSOLE must be in 1, 2 or 3
46 #elif CONFIG_PSC_CONSOLE == 4
47 #define PSC_BASE MPC5XXX_PSC4
48 #elif CONFIG_PSC_CONSOLE == 5
49 #define PSC_BASE MPC5XXX_PSC5
50 #elif CONFIG_PSC_CONSOLE == 6
51 #define PSC_BASE MPC5XXX_PSC6
53 #error CONFIG_PSC_CONSOLE must be in 1 ... 6
56 int serial_init (void)
58 DECLARE_GLOBAL_DATA_PTR;
60 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)PSC_BASE;
61 unsigned long baseclk;
65 psc->command = PSC_SEL_MODE_REG_1;
67 /* select clock sources */
68 #if defined(CONFIG_MGT5100)
69 psc->psc_clock_select = 0xdd00;
70 baseclk = (CFG_MPC5XXX_CLKIN + 16) / 32;
71 #elif defined(CONFIG_MPC5200)
72 psc->psc_clock_select = 0;
73 baseclk = (gd->ipb_clk + 16) / 32;
76 /* switch to UART mode */
79 /* configure parity, bit length and so on */
80 #if defined(CONFIG_MGT5100)
81 psc->mode = PSC_MODE_ERR | PSC_MODE_8_BITS | PSC_MODE_PARNONE;
82 #elif defined(CONFIG_MPC5200)
83 psc->mode = PSC_MODE_8_BITS | PSC_MODE_PARNONE;
85 psc->mode = PSC_MODE_ONE_STOP;
87 /* set up UART divisor */
88 div = (baseclk + (gd->baudrate/2)) / gd->baudrate;
89 psc->ctur = (div >> 8) & 0xff;
90 psc->ctlr = div & 0xff;
92 /* disable all interrupts */
95 /* reset and enable Rx/Tx */
96 psc->command = PSC_RST_RX;
97 psc->command = PSC_RST_TX;
98 psc->command = PSC_RX_ENABLE | PSC_TX_ENABLE;
104 serial_putc(const char c)
106 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)PSC_BASE;
111 /* Wait for last character to go. */
112 while (!(psc->psc_status & PSC_SR_TXEMP))
115 psc->psc_buffer_8 = c;
119 serial_puts (const char *s)
129 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)PSC_BASE;
131 /* Wait for a character to arrive. */
132 while (!(psc->psc_status & PSC_SR_RXRDY))
135 return psc->psc_buffer_8;
141 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)PSC_BASE;
143 return (psc->psc_status & PSC_SR_RXRDY);
149 DECLARE_GLOBAL_DATA_PTR;
151 volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)PSC_BASE;
152 unsigned long baseclk, div;
154 #if defined(CONFIG_MGT5100)
155 baseclk = CFG_MPC5XXX_CLKIN / 32;
156 #elif defined(CONFIG_MPC5200)
157 baseclk = (gd->ipb_clk + 16) / 32;
160 /* set up UART divisor */
161 div = (baseclk + (gd->baudrate/2)) / gd->baudrate;
162 psc->ctur = div >> 8;
163 psc->ctlr = div & 0xff;
165 #endif /* CONFIG_PSC_CONSOLE */