2 * (C) Copyright 2004, Freescale, Inc
3 * TsiChung Liew, Tsi-Chung.Liew@freescale.com.
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,
26 * Minimal serial functions needed to use one of the PSC ports
27 * as serial console interface.
33 #include <linux/compiler.h>
35 DECLARE_GLOBAL_DATA_PTR;
37 #define PSC_BASE MMAP_PSC1
39 #if defined(CONFIG_PSC_CONSOLE)
40 static int mpc8220_serial_init(void)
42 volatile psc8220_t *psc = (psc8220_t *) PSC_BASE;
45 /* write to SICR: SIM2 = uart mode,dcd does not affect rx */
50 /* write to CSR: RX/TX baud rate from timers */
51 psc->sr_csr = 0xdd000000;
53 psc->mr1_2 = PSC_MR1_BITS_CHAR_8 | PSC_MR1_NO_PARITY | PSC_MR2_STOP_BITS_1;
55 /* Setting up BaudRate */
56 counter = ((gd->bus_clk / gd->baudrate)) >> 5;
59 /* write to CTUR: divide counter upper byte */
60 psc->ctur = ((counter & 0xff00) << 16);
61 /* write to CTLR: divide counter lower byte */
62 psc->ctlr = ((counter & 0x00ff) << 24);
64 psc->cr = PSC_CR_RST_RX_CMD;
65 psc->cr = PSC_CR_RST_TX_CMD;
66 psc->cr = PSC_CR_RST_ERR_STS_CMD;
67 psc->cr = PSC_CR_RST_BRK_INT_CMD;
68 psc->cr = PSC_CR_RST_MR_PTR_CMD;
70 psc->cr = PSC_CR_RX_ENABLE | PSC_CR_TX_ENABLE;
74 static void mpc8220_serial_putc(const char c)
76 volatile psc8220_t *psc = (psc8220_t *) PSC_BASE;
81 /* Wait for last character to go. */
82 while (!(psc->sr_csr & PSC_SR_TXRDY));
87 static void mpc8220_serial_puts(const char *s)
94 static int mpc8220_serial_getc(void)
96 volatile psc8220_t *psc = (psc8220_t *) PSC_BASE;
98 /* Wait for a character to arrive. */
99 while (!(psc->sr_csr & PSC_SR_RXRDY));
100 return psc->xmitbuf[2];
103 static int mpc8220_serial_tstc(void)
105 volatile psc8220_t *psc = (psc8220_t *) PSC_BASE;
107 return (psc->sr_csr & PSC_SR_RXRDY);
110 static void mpc8220_serial_setbrg(void)
112 volatile psc8220_t *psc = (psc8220_t *) PSC_BASE;
115 counter = ((gd->bus_clk / gd->baudrate)) >> 5;
118 /* write to CTUR: divide counter upper byte */
119 psc->ctur = ((counter & 0xff00) << 16);
120 /* write to CTLR: divide counter lower byte */
121 psc->ctlr = ((counter & 0x00ff) << 24);
123 psc->cr = PSC_CR_RST_RX_CMD;
124 psc->cr = PSC_CR_RST_TX_CMD;
126 psc->cr = PSC_CR_RX_ENABLE | PSC_CR_TX_ENABLE;
129 static struct serial_device mpc8220_serial_drv = {
130 .name = "mpc8220_serial",
131 .start = mpc8220_serial_init,
133 .setbrg = mpc8220_serial_setbrg,
134 .putc = mpc8220_serial_putc,
135 .puts = mpc8220_serial_puts,
136 .getc = mpc8220_serial_getc,
137 .tstc = mpc8220_serial_tstc,
140 void mpc8220_serial_initialize(void)
142 serial_register(&mpc8220_serial_drv);
145 __weak struct serial_device *default_serial_console(void)
147 return &mpc8220_serial_drv;
149 #endif /* CONFIG_PSC_CONSOLE */