diff options
Diffstat (limited to 'arch/ppc64/kernel/udbg_scc.c')
-rw-r--r-- | arch/ppc64/kernel/udbg_scc.c | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/arch/ppc64/kernel/udbg_scc.c b/arch/ppc64/kernel/udbg_scc.c new file mode 100644 index 000000000000..c47fd6c63531 --- /dev/null +++ b/arch/ppc64/kernel/udbg_scc.c | |||
@@ -0,0 +1,136 @@ | |||
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/udbg.h> | ||
14 | #include <asm/processor.h> | ||
15 | #include <asm/naca.h> | ||
16 | #include <asm/io.h> | ||
17 | #include <asm/prom.h> | ||
18 | #include <asm/pmac_feature.h> | ||
19 | |||
20 | extern u8 real_readb(volatile u8 __iomem *addr); | ||
21 | extern void real_writeb(u8 data, volatile u8 __iomem *addr); | ||
22 | |||
23 | #define SCC_TXRDY 4 | ||
24 | #define SCC_RXRDY 1 | ||
25 | |||
26 | static volatile u8 __iomem *sccc; | ||
27 | static volatile u8 __iomem *sccd; | ||
28 | |||
29 | static void udbg_scc_putc(unsigned char c) | ||
30 | { | ||
31 | if (sccc) { | ||
32 | while ((in_8(sccc) & SCC_TXRDY) == 0) | ||
33 | ; | ||
34 | out_8(sccd, c); | ||
35 | if (c == '\n') | ||
36 | udbg_scc_putc('\r'); | ||
37 | } | ||
38 | } | ||
39 | |||
40 | static int udbg_scc_getc_poll(void) | ||
41 | { | ||
42 | if (sccc) { | ||
43 | if ((in_8(sccc) & SCC_RXRDY) != 0) | ||
44 | return in_8(sccd); | ||
45 | else | ||
46 | return -1; | ||
47 | } | ||
48 | return -1; | ||
49 | } | ||
50 | |||
51 | static unsigned char udbg_scc_getc(void) | ||
52 | { | ||
53 | if (sccc) { | ||
54 | while ((in_8(sccc) & SCC_RXRDY) == 0) | ||
55 | ; | ||
56 | return in_8(sccd); | ||
57 | } | ||
58 | return 0; | ||
59 | } | ||
60 | |||
61 | static unsigned char scc_inittab[] = { | ||
62 | 13, 0, /* set baud rate divisor */ | ||
63 | 12, 0, | ||
64 | 14, 1, /* baud rate gen enable, src=rtxc */ | ||
65 | 11, 0x50, /* clocks = br gen */ | ||
66 | 5, 0xea, /* tx 8 bits, assert DTR & RTS */ | ||
67 | 4, 0x46, /* x16 clock, 1 stop */ | ||
68 | 3, 0xc1, /* rx enable, 8 bits */ | ||
69 | }; | ||
70 | |||
71 | void udbg_init_scc(struct device_node *np) | ||
72 | { | ||
73 | u32 *reg; | ||
74 | unsigned long addr; | ||
75 | int i, x; | ||
76 | |||
77 | if (np == NULL) | ||
78 | np = of_find_node_by_name(NULL, "escc"); | ||
79 | if (np == NULL || np->parent == NULL) | ||
80 | return; | ||
81 | |||
82 | udbg_printf("found SCC...\n"); | ||
83 | /* Get address within mac-io ASIC */ | ||
84 | reg = (u32 *)get_property(np, "reg", NULL); | ||
85 | if (reg == NULL) | ||
86 | return; | ||
87 | addr = reg[0]; | ||
88 | udbg_printf("local addr: %lx\n", addr); | ||
89 | /* Get address of mac-io PCI itself */ | ||
90 | reg = (u32 *)get_property(np->parent, "assigned-addresses", NULL); | ||
91 | if (reg == NULL) | ||
92 | return; | ||
93 | addr += reg[2]; | ||
94 | udbg_printf("final addr: %lx\n", addr); | ||
95 | |||
96 | /* Setup for 57600 8N1 */ | ||
97 | addr += 0x20; | ||
98 | sccc = (volatile u8 * __iomem) ioremap(addr & PAGE_MASK, PAGE_SIZE) ; | ||
99 | sccc += addr & ~PAGE_MASK; | ||
100 | sccd = sccc + 0x10; | ||
101 | |||
102 | udbg_printf("ioremap result sccc: %p\n", sccc); | ||
103 | mb(); | ||
104 | |||
105 | for (i = 20000; i != 0; --i) | ||
106 | x = in_8(sccc); | ||
107 | out_8(sccc, 0x09); /* reset A or B side */ | ||
108 | out_8(sccc, 0xc0); | ||
109 | for (i = 0; i < sizeof(scc_inittab); ++i) | ||
110 | out_8(sccc, scc_inittab[i]); | ||
111 | |||
112 | udbg_putc = udbg_scc_putc; | ||
113 | udbg_getc = udbg_scc_getc; | ||
114 | udbg_getc_poll = udbg_scc_getc_poll; | ||
115 | |||
116 | udbg_puts("Hello World !\n"); | ||
117 | } | ||
118 | |||
119 | static void udbg_real_scc_putc(unsigned char c) | ||
120 | { | ||
121 | while ((real_readb(sccc) & SCC_TXRDY) == 0) | ||
122 | ; | ||
123 | real_writeb(c, sccd); | ||
124 | if (c == '\n') | ||
125 | udbg_real_scc_putc('\r'); | ||
126 | } | ||
127 | |||
128 | void udbg_init_pmac_realmode(void) | ||
129 | { | ||
130 | sccc = (volatile u8 __iomem *)0x80013020ul; | ||
131 | sccd = (volatile u8 __iomem *)0x80013030ul; | ||
132 | |||
133 | udbg_putc = udbg_real_scc_putc; | ||
134 | udbg_getc = NULL; | ||
135 | udbg_getc_poll = NULL; | ||
136 | } | ||