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 | */ | |
7f853352 | 11 | #include <linux/types.h> |
188d2ce7 | 12 | #include <asm/udbg.h> |
7f853352 | 13 | #include <asm/processor.h> |
7f853352 MM |
14 | #include <asm/io.h> |
15 | #include <asm/prom.h> | |
16 | #include <asm/pmac_feature.h> | |
17 | ||
18 | extern u8 real_readb(volatile u8 __iomem *addr); | |
19 | extern void real_writeb(u8 data, volatile u8 __iomem *addr); | |
20 | ||
21 | #define SCC_TXRDY 4 | |
22 | #define SCC_RXRDY 1 | |
23 | ||
24 | static volatile u8 __iomem *sccc; | |
25 | static volatile u8 __iomem *sccd; | |
26 | ||
51d3082f | 27 | static void udbg_scc_putc(char c) |
7f853352 MM |
28 | { |
29 | if (sccc) { | |
30 | while ((in_8(sccc) & SCC_TXRDY) == 0) | |
31 | ; | |
32 | out_8(sccd, c); | |
33 | if (c == '\n') | |
34 | udbg_scc_putc('\r'); | |
35 | } | |
36 | } | |
37 | ||
38 | static int udbg_scc_getc_poll(void) | |
39 | { | |
40 | if (sccc) { | |
41 | if ((in_8(sccc) & SCC_RXRDY) != 0) | |
42 | return in_8(sccd); | |
43 | else | |
44 | return -1; | |
45 | } | |
46 | return -1; | |
47 | } | |
48 | ||
bb6b9b28 | 49 | static int udbg_scc_getc(void) |
7f853352 MM |
50 | { |
51 | if (sccc) { | |
52 | while ((in_8(sccc) & SCC_RXRDY) == 0) | |
53 | ; | |
54 | return in_8(sccd); | |
55 | } | |
bb6b9b28 | 56 | return -1; |
7f853352 MM |
57 | } |
58 | ||
59 | static unsigned char scc_inittab[] = { | |
60 | 13, 0, /* set baud rate divisor */ | |
61 | 12, 0, | |
62 | 14, 1, /* baud rate gen enable, src=rtxc */ | |
63 | 11, 0x50, /* clocks = br gen */ | |
64 | 5, 0xea, /* tx 8 bits, assert DTR & RTS */ | |
65 | 4, 0x46, /* x16 clock, 1 stop */ | |
66 | 3, 0xc1, /* rx enable, 8 bits */ | |
67 | }; | |
68 | ||
51d3082f | 69 | void udbg_scc_init(int force_scc) |
7f853352 MM |
70 | { |
71 | u32 *reg; | |
72 | unsigned long addr; | |
51d3082f BH |
73 | struct device_node *stdout = NULL, *escc = NULL, *macio = NULL; |
74 | struct device_node *ch, *ch_def = NULL, *ch_a = NULL; | |
75 | char *path; | |
7f853352 MM |
76 | int i, x; |
77 | ||
51d3082f BH |
78 | escc = of_find_node_by_name(NULL, "escc"); |
79 | if (escc == NULL) | |
80 | goto bail; | |
81 | macio = of_get_parent(escc); | |
82 | if (macio == NULL) | |
83 | goto bail; | |
84 | path = (char *)get_property(of_chosen, "linux,stdout-path", NULL); | |
85 | if (path != NULL) | |
86 | stdout = of_find_node_by_path(path); | |
87 | for (ch = NULL; (ch = of_get_next_child(escc, ch)) != NULL;) { | |
88 | if (ch == stdout) | |
89 | ch_def = of_node_get(ch); | |
90 | if (strcmp(ch->name, "ch-a") == 0) | |
91 | ch_a = of_node_get(ch); | |
92 | } | |
93 | if (ch_def == NULL && !force_scc) | |
94 | goto bail; | |
95 | ||
96 | ch = ch_def ? ch_def : ch_a; | |
7f853352 | 97 | |
7f853352 | 98 | /* Get address within mac-io ASIC */ |
51d3082f | 99 | reg = (u32 *)get_property(escc, "reg", NULL); |
7f853352 | 100 | if (reg == NULL) |
51d3082f | 101 | goto bail; |
7f853352 | 102 | addr = reg[0]; |
51d3082f | 103 | |
7f853352 | 104 | /* Get address of mac-io PCI itself */ |
51d3082f | 105 | reg = (u32 *)get_property(macio, "assigned-addresses", NULL); |
7f853352 | 106 | if (reg == NULL) |
51d3082f | 107 | goto bail; |
7f853352 | 108 | addr += reg[2]; |
51d3082f BH |
109 | |
110 | /* Lock the serial port */ | |
111 | pmac_call_feature(PMAC_FTR_SCC_ENABLE, ch, | |
112 | PMAC_SCC_ASYNC | PMAC_SCC_FLAG_XMON, 1); | |
113 | ||
7f853352 MM |
114 | |
115 | /* Setup for 57600 8N1 */ | |
51d3082f BH |
116 | if (ch == ch_a) |
117 | addr += 0x20; | |
af308377 | 118 | sccc = ioremap(addr & PAGE_MASK, PAGE_SIZE) ; |
7f853352 MM |
119 | sccc += addr & ~PAGE_MASK; |
120 | sccd = sccc + 0x10; | |
121 | ||
7f853352 MM |
122 | mb(); |
123 | ||
124 | for (i = 20000; i != 0; --i) | |
125 | x = in_8(sccc); | |
126 | out_8(sccc, 0x09); /* reset A or B side */ | |
127 | out_8(sccc, 0xc0); | |
128 | for (i = 0; i < sizeof(scc_inittab); ++i) | |
129 | out_8(sccc, scc_inittab[i]); | |
130 | ||
c8f1c8be MM |
131 | udbg_putc = udbg_scc_putc; |
132 | udbg_getc = udbg_scc_getc; | |
133 | udbg_getc_poll = udbg_scc_getc_poll; | |
7f853352 MM |
134 | |
135 | udbg_puts("Hello World !\n"); | |
51d3082f BH |
136 | |
137 | bail: | |
138 | of_node_put(macio); | |
139 | of_node_put(escc); | |
140 | of_node_put(stdout); | |
141 | of_node_put(ch_def); | |
142 | of_node_put(ch_a); | |
7f853352 MM |
143 | } |
144 | ||
51d3082f BH |
145 | #ifdef CONFIG_PPC64 |
146 | static void udbg_real_scc_putc(char c) | |
7f853352 MM |
147 | { |
148 | while ((real_readb(sccc) & SCC_TXRDY) == 0) | |
149 | ; | |
150 | real_writeb(c, sccd); | |
151 | if (c == '\n') | |
152 | udbg_real_scc_putc('\r'); | |
153 | } | |
154 | ||
296167ae | 155 | void __init udbg_init_pmac_realmode(void) |
7f853352 MM |
156 | { |
157 | sccc = (volatile u8 __iomem *)0x80013020ul; | |
158 | sccd = (volatile u8 __iomem *)0x80013030ul; | |
159 | ||
c8f1c8be MM |
160 | udbg_putc = udbg_real_scc_putc; |
161 | udbg_getc = NULL; | |
162 | udbg_getc_poll = NULL; | |
7f853352 | 163 | } |
51d3082f | 164 | #endif /* CONFIG_PPC64 */ |