aboutsummaryrefslogtreecommitdiffstats
path: root/arch/ppc64/kernel/udbg.c
diff options
context:
space:
mode:
authorMilton Miller <miltonm@bga.com>2005-09-05 21:56:02 -0400
committerPaul Mackerras <paulus@samba.org>2005-09-06 02:07:36 -0400
commit7f853352e79bf57c4ee279b7458ed0c072e2be76 (patch)
tree516f26c2b0e5de059c0fda3c1266285f8084de03 /arch/ppc64/kernel/udbg.c
parent37548d58e5ce53dda609c5b35c0eb62d50d59675 (diff)
[PATCH] ppc64: Split SCC and 15550 udbg code
Split scc and 15550 functions from udbg each into their own file. This makes them more symetric with the lpar and btext code. Signed-off-by: Milton Miller <miltonm@bga.com> Signed-off-by: Anton Blanchard <anton@samba.org> Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch/ppc64/kernel/udbg.c')
-rw-r--r--arch/ppc64/kernel/udbg.c225
1 files changed, 1 insertions, 224 deletions
diff --git a/arch/ppc64/kernel/udbg.c b/arch/ppc64/kernel/udbg.c
index b531583b88d7..67e208500aea 100644
--- a/arch/ppc64/kernel/udbg.c
+++ b/arch/ppc64/kernel/udbg.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * NS16550 Serial Port (uart) debugging stuff. 2 * polling mode stateless debugging stuff, originally for NS16550 Serial Ports
3 * 3 *
4 * c 2001 PPC 64 Team, IBM Corp 4 * c 2001 PPC 64 Team, IBM Corp
5 * 5 *
@@ -19,229 +19,6 @@
19#include <asm/machdep.h> 19#include <asm/machdep.h>
20#include <asm/io.h> 20#include <asm/io.h>
21#include <asm/prom.h> 21#include <asm/prom.h>
22#include <asm/pmac_feature.h>
23
24extern u8 real_readb(volatile u8 __iomem *addr);
25extern void real_writeb(u8 data, volatile u8 __iomem *addr);
26
27struct NS16550 {
28 /* this struct must be packed */
29 unsigned char rbr; /* 0 */
30 unsigned char ier; /* 1 */
31 unsigned char fcr; /* 2 */
32 unsigned char lcr; /* 3 */
33 unsigned char mcr; /* 4 */
34 unsigned char lsr; /* 5 */
35 unsigned char msr; /* 6 */
36 unsigned char scr; /* 7 */
37};
38
39#define thr rbr
40#define iir fcr
41#define dll rbr
42#define dlm ier
43#define dlab lcr
44
45#define LSR_DR 0x01 /* Data ready */
46#define LSR_OE 0x02 /* Overrun */
47#define LSR_PE 0x04 /* Parity error */
48#define LSR_FE 0x08 /* Framing error */
49#define LSR_BI 0x10 /* Break */
50#define LSR_THRE 0x20 /* Xmit holding register empty */
51#define LSR_TEMT 0x40 /* Xmitter empty */
52#define LSR_ERR 0x80 /* Error */
53
54static volatile struct NS16550 __iomem *udbg_comport;
55
56void udbg_init_uart(void __iomem *comport, unsigned int speed)
57{
58 u16 dll = speed ? (115200 / speed) : 12;
59
60 if (comport) {
61 udbg_comport = (struct NS16550 __iomem *)comport;
62 out_8(&udbg_comport->lcr, 0x00);
63 out_8(&udbg_comport->ier, 0xff);
64 out_8(&udbg_comport->ier, 0x00);
65 out_8(&udbg_comport->lcr, 0x80); /* Access baud rate */
66 out_8(&udbg_comport->dll, dll & 0xff); /* 1 = 115200, 2 = 57600,
67 3 = 38400, 12 = 9600 baud */
68 out_8(&udbg_comport->dlm, dll >> 8); /* dll >> 8 which should be zero
69 for fast rates; */
70 out_8(&udbg_comport->lcr, 0x03); /* 8 data, 1 stop, no parity */
71 out_8(&udbg_comport->mcr, 0x03); /* RTS/DTR */
72 out_8(&udbg_comport->fcr ,0x07); /* Clear & enable FIFOs */
73 ppc_md.udbg_putc = udbg_putc; /* set access methods */
74 ppc_md.udbg_getc = udbg_getc;
75 ppc_md.udbg_getc_poll = udbg_getc_poll;
76 }
77}
78
79#ifdef CONFIG_PPC_PMAC
80
81#define SCC_TXRDY 4
82#define SCC_RXRDY 1
83
84static volatile u8 __iomem *sccc;
85static volatile u8 __iomem *sccd;
86
87static unsigned char scc_inittab[] = {
88 13, 0, /* set baud rate divisor */
89 12, 0,
90 14, 1, /* baud rate gen enable, src=rtxc */
91 11, 0x50, /* clocks = br gen */
92 5, 0xea, /* tx 8 bits, assert DTR & RTS */
93 4, 0x46, /* x16 clock, 1 stop */
94 3, 0xc1, /* rx enable, 8 bits */
95};
96
97void udbg_init_scc(struct device_node *np)
98{
99 u32 *reg;
100 unsigned long addr;
101 int i, x;
102
103 if (np == NULL)
104 np = of_find_node_by_name(NULL, "escc");
105 if (np == NULL || np->parent == NULL)
106 return;
107
108 udbg_printf("found SCC...\n");
109 /* Get address within mac-io ASIC */
110 reg = (u32 *)get_property(np, "reg", NULL);
111 if (reg == NULL)
112 return;
113 addr = reg[0];
114 udbg_printf("local addr: %lx\n", addr);
115 /* Get address of mac-io PCI itself */
116 reg = (u32 *)get_property(np->parent, "assigned-addresses", NULL);
117 if (reg == NULL)
118 return;
119 addr += reg[2];
120 udbg_printf("final addr: %lx\n", addr);
121
122 /* Setup for 57600 8N1 */
123 addr += 0x20;
124 sccc = (volatile u8 * __iomem) ioremap(addr & PAGE_MASK, PAGE_SIZE) ;
125 sccc += addr & ~PAGE_MASK;
126 sccd = sccc + 0x10;
127
128 udbg_printf("ioremap result sccc: %p\n", sccc);
129 mb();
130
131 for (i = 20000; i != 0; --i)
132 x = in_8(sccc);
133 out_8(sccc, 0x09); /* reset A or B side */
134 out_8(sccc, 0xc0);
135 for (i = 0; i < sizeof(scc_inittab); ++i)
136 out_8(sccc, scc_inittab[i]);
137
138 ppc_md.udbg_putc = udbg_putc;
139 ppc_md.udbg_getc = udbg_getc;
140 ppc_md.udbg_getc_poll = udbg_getc_poll;
141
142 udbg_puts("Hello World !\n");
143}
144
145#endif /* CONFIG_PPC_PMAC */
146
147#ifdef CONFIG_PPC_PMAC
148static void udbg_real_putc(unsigned char c)
149{
150 while ((real_readb(sccc) & SCC_TXRDY) == 0)
151 ;
152 real_writeb(c, sccd);
153 if (c == '\n')
154 udbg_real_putc('\r');
155}
156
157void udbg_init_pmac_realmode(void)
158{
159 sccc = (volatile u8 __iomem *)0x80013020ul;
160 sccd = (volatile u8 __iomem *)0x80013030ul;
161
162 ppc_md.udbg_putc = udbg_real_putc;
163 ppc_md.udbg_getc = NULL;
164 ppc_md.udbg_getc_poll = NULL;
165}
166#endif /* CONFIG_PPC_PMAC */
167
168#ifdef CONFIG_PPC_MAPLE
169void udbg_maple_real_putc(unsigned char c)
170{
171 if (udbg_comport) {
172 while ((real_readb(&udbg_comport->lsr) & LSR_THRE) == 0)
173 /* wait for idle */;
174 real_writeb(c, &udbg_comport->thr); eieio();
175 if (c == '\n')
176 udbg_maple_real_putc('\r');
177 }
178}
179
180void udbg_init_maple_realmode(void)
181{
182 udbg_comport = (volatile struct NS16550 __iomem *)0xf40003f8;
183
184 ppc_md.udbg_putc = udbg_maple_real_putc;
185 ppc_md.udbg_getc = NULL;
186 ppc_md.udbg_getc_poll = NULL;
187}
188#endif /* CONFIG_PPC_MAPLE */
189
190void udbg_putc(unsigned char c)
191{
192 if (udbg_comport) {
193 while ((in_8(&udbg_comport->lsr) & LSR_THRE) == 0)
194 /* wait for idle */;
195 out_8(&udbg_comport->thr, c);
196 if (c == '\n')
197 udbg_putc('\r');
198 }
199#ifdef CONFIG_PPC_PMAC
200 else if (sccc) {
201 while ((in_8(sccc) & SCC_TXRDY) == 0)
202 ;
203 out_8(sccd, c);
204 if (c == '\n')
205 udbg_putc('\r');
206 }
207#endif /* CONFIG_PPC_PMAC */
208}
209
210int udbg_getc_poll(void)
211{
212 if (udbg_comport) {
213 if ((in_8(&udbg_comport->lsr) & LSR_DR) != 0)
214 return in_8(&udbg_comport->rbr);
215 else
216 return -1;
217 }
218#ifdef CONFIG_PPC_PMAC
219 else if (sccc) {
220 if ((in_8(sccc) & SCC_RXRDY) != 0)
221 return in_8(sccd);
222 else
223 return -1;
224 }
225#endif /* CONFIG_PPC_PMAC */
226 return -1;
227}
228
229unsigned char udbg_getc(void)
230{
231 if (udbg_comport) {
232 while ((in_8(&udbg_comport->lsr) & LSR_DR) == 0)
233 /* wait for char */;
234 return in_8(&udbg_comport->rbr);
235 }
236#ifdef CONFIG_PPC_PMAC
237 else if (sccc) {
238 while ((in_8(sccc) & SCC_RXRDY) == 0)
239 ;
240 return in_8(sccd);
241 }
242#endif /* CONFIG_PPC_PMAC */
243 return 0;
244}
245 22
246void udbg_puts(const char *s) 23void udbg_puts(const char *s)
247{ 24{