3 * Martin Winistoerfer, martinwinistoerfer@gmx.ch.
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
26 * Discription: Serial interface driver for SCI1 and SCI2.
27 * Since this code will be called from ROM use
28 * only non-static local variables.
39 * Local function prototypes
42 static int ready_to_send(void);
45 * Minimal global serial functions needed to use one of the SCI modules.
48 int serial_init (void)
50 volatile immap_t *immr = (immap_t *)CFG_IMMR;
54 #if defined(CONFIG_5xx_CONS_SCI1)
55 /* 10-Bit, 1 start bit, 8 data bit, no parity, 1 stop bit */
56 immr->im_qsmcm.qsmcm_scc1r1 = SCI_M_10;
57 immr->im_qsmcm.qsmcm_scc1r1 = SCI_TE | SCI_RE;
59 immr->im_qsmcm.qsmcm_scc2r1 = SCI_M_10;
60 immr->im_qsmcm.qsmcm_scc2r1 = SCI_TE | SCI_RE;
65 void serial_putc(const char c)
67 volatile immap_t *immr = (immap_t *)CFG_IMMR;
69 /* Test for completition */
71 #if defined(CONFIG_5xx_CONS_SCI1)
72 immr->im_qsmcm.qsmcm_sc1dr = (short)c;
74 immr->im_qsmcm.qsmcm_sc2dr = (short)c;
78 #if defined(CONFIG_5xx_CONS_SCI1)
79 immr->im_qsmcm.qsmcm_sc1dr = (short)'\r';
81 immr->im_qsmcm.qsmcm_sc2dr = (short)'\r';
89 volatile immap_t *immr = (immap_t *)CFG_IMMR;
90 volatile short status;
95 #if defined(CONFIG_5xx_CONS_SCI1)
96 status = immr->im_qsmcm.qsmcm_sc1sr;
98 status = immr->im_qsmcm.qsmcm_sc2sr;
101 #if defined(CONFIG_WATCHDOG)
102 reset_5xx_watchdog (immr);
104 } while ((status & SCI_RDRF) == 0);
107 #if defined(CONFIG_5xx_CONS_SCI1)
108 tmp = (unsigned char)(immr->im_qsmcm.qsmcm_sc1dr & SCI_SCXDR_MK);
110 tmp = (unsigned char)( immr->im_qsmcm.qsmcm_sc2dr & SCI_SCXDR_MK);
117 volatile immap_t *immr = (immap_t *)CFG_IMMR;
120 /* New data character ? */
121 #if defined(CONFIG_5xx_CONS_SCI1)
122 status = immr->im_qsmcm.qsmcm_sc1sr;
124 status = immr->im_qsmcm.qsmcm_sc2sr;
126 return (status & SCI_RDRF);
129 void serial_setbrg (void)
131 DECLARE_GLOBAL_DATA_PTR;
132 volatile immap_t *immr = (immap_t *)CFG_IMMR;
136 scxbr = (gd->cpu_clk / (32 * gd->baudrate));
137 #if defined(CONFIG_5xx_CONS_SCI1)
138 immr->im_qsmcm.qsmcm_scc1r0 = (scxbr & SCI_SCXBR_MK);
140 immr->im_qsmcm.qsmcm_scc2r0 = (scxbr & SCI_SCXBR_MK);
144 void serial_puts (const char *s)
152 int ready_to_send(void)
154 volatile immap_t *immr = (immap_t *)CFG_IMMR;
155 volatile short status;
158 #if defined(CONFIG_5xx_CONS_SCI1)
159 status = immr->im_qsmcm.qsmcm_sc1sr;
161 status = immr->im_qsmcm.qsmcm_sc2sr;
164 #if defined(CONFIG_WATCHDOG)
165 reset_5xx_watchdog (immr);
167 } while ((status & SCI_TDRE) == 0);