Commit | Line | Data |
---|---|---|
7f853352 MM |
1 | /* |
2 | * udbg for for zilog scc ports as found on Apple PowerMacs | |
3 | * | |
4 | * Copyright (C) 2001-2005 PPC 64 Team, IBM Corp | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU General Public License | |
8 | * as published by the Free Software Foundation; either version | |
9 | * 2 of the License, or (at your option) any later version. | |
10 | */ | |
11 | #include <linux/config.h> | |
12 | #include <linux/types.h> | |
13 | #include <asm/ppcdebug.h> | |
14 | #include <asm/processor.h> | |
15 | #include <asm/naca.h> | |
16 | #include <asm/uaccess.h> | |
17 | #include <asm/machdep.h> | |
18 | #include <asm/io.h> | |
19 | #include <asm/prom.h> | |
20 | #include <asm/pmac_feature.h> | |
21 | ||
22 | extern u8 real_readb(volatile u8 __iomem *addr); | |
23 | extern void real_writeb(u8 data, volatile u8 __iomem *addr); | |
24 | ||
25 | #define SCC_TXRDY 4 | |
26 | #define SCC_RXRDY 1 | |
27 | ||
28 | static volatile u8 __iomem *sccc; | |
29 | static volatile u8 __iomem *sccd; | |
30 | ||
31 | static void udbg_scc_putc(unsigned char c) | |
32 | { | |
33 | if (sccc) { | |
34 | while ((in_8(sccc) & SCC_TXRDY) == 0) | |
35 | ; | |
36 | out_8(sccd, c); | |
37 | if (c == '\n') | |
38 | udbg_scc_putc('\r'); | |
39 | } | |
40 | } | |
41 | ||
42 | static int udbg_scc_getc_poll(void) | |
43 | { | |
44 | if (sccc) { | |
45 | if ((in_8(sccc) & SCC_RXRDY) != 0) | |
46 | return in_8(sccd); | |
47 | else | |
48 | return -1; | |
49 | } | |
50 | return -1; | |
51 | } | |
52 | ||
53 | static unsigned char udbg_scc_getc(void) | |
54 | { | |
55 | if (sccc) { | |
56 | while ((in_8(sccc) & SCC_RXRDY) == 0) | |
57 | ; | |
58 | return in_8(sccd); | |
59 | } | |
60 | return 0; | |
61 | } | |
62 | ||
63 | static unsigned char scc_inittab[] = { | |
64 | 13, 0, /* set baud rate divisor */ | |
65 | 12, 0, | |
66 | 14, 1, /* baud rate gen enable, src=rtxc */ | |
67 | 11, 0x50, /* clocks = br gen */ | |
68 | 5, 0xea, /* tx 8 bits, assert DTR & RTS */ | |
69 | 4, 0x46, /* x16 clock, 1 stop */ | |
70 | 3, 0xc1, /* rx enable, 8 bits */ | |
71 | }; | |
72 | ||
73 | void udbg_init_scc(struct device_node *np) | |
74 | { | |
75 | u32 *reg; | |
76 | unsigned long addr; | |
77 | int i, x; | |
78 | ||
79 | if (np == NULL) | |
80 | np = of_find_node_by_name(NULL, "escc"); | |
81 | if (np == NULL || np->parent == NULL) | |
82 | return; | |
83 | ||
84 | udbg_printf("found SCC...\n"); | |
85 | /* Get address within mac-io ASIC */ | |
86 | reg = (u32 *)get_property(np, "reg", NULL); | |
87 | if (reg == NULL) | |
88 | return; | |
89 | addr = reg[0]; | |
90 | udbg_printf("local addr: %lx\n", addr); | |
91 | /* Get address of mac-io PCI itself */ | |
92 | reg = (u32 *)get_property(np->parent, "assigned-addresses", NULL); | |
93 | if (reg == NULL) | |
94 | return; | |
95 | addr += reg[2]; | |
96 | udbg_printf("final addr: %lx\n", addr); | |
97 | ||
98 | /* Setup for 57600 8N1 */ | |
99 | addr += 0x20; | |
100 | sccc = (volatile u8 * __iomem) ioremap(addr & PAGE_MASK, PAGE_SIZE) ; | |
101 | sccc += addr & ~PAGE_MASK; | |
102 | sccd = sccc + 0x10; | |
103 | ||
104 | udbg_printf("ioremap result sccc: %p\n", sccc); | |
105 | mb(); | |
106 | ||
107 | for (i = 20000; i != 0; --i) | |
108 | x = in_8(sccc); | |
109 | out_8(sccc, 0x09); /* reset A or B side */ | |
110 | out_8(sccc, 0xc0); | |
111 | for (i = 0; i < sizeof(scc_inittab); ++i) | |
112 | out_8(sccc, scc_inittab[i]); | |
113 | ||
114 | ppc_md.udbg_putc = udbg_scc_putc; | |
115 | ppc_md.udbg_getc = udbg_scc_getc; | |
116 | ppc_md.udbg_getc_poll = udbg_scc_getc_poll; | |
117 | ||
118 | udbg_puts("Hello World !\n"); | |
119 | } | |
120 | ||
121 | static void udbg_real_scc_putc(unsigned char c) | |
122 | { | |
123 | while ((real_readb(sccc) & SCC_TXRDY) == 0) | |
124 | ; | |
125 | real_writeb(c, sccd); | |
126 | if (c == '\n') | |
127 | udbg_real_scc_putc('\r'); | |
128 | } | |
129 | ||
130 | void udbg_init_pmac_realmode(void) | |
131 | { | |
132 | sccc = (volatile u8 __iomem *)0x80013020ul; | |
133 | sccd = (volatile u8 __iomem *)0x80013030ul; | |
134 | ||
135 | ppc_md.udbg_putc = udbg_real_scc_putc; | |
136 | ppc_md.udbg_getc = NULL; | |
137 | ppc_md.udbg_getc_poll = NULL; | |
138 | } |