2 * udbg for for zilog scc ports as found on Apple PowerMacs
4 * Copyright (C) 2001-2005 PPC 64 Team, IBM Corp
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.
11 #include <linux/types.h>
13 #include <asm/processor.h>
16 #include <asm/pmac_feature.h>
18 extern u8
real_readb(volatile u8 __iomem
*addr
);
19 extern void real_writeb(u8 data
, volatile u8 __iomem
*addr
);
24 static volatile u8 __iomem
*sccc
;
25 static volatile u8 __iomem
*sccd
;
27 static void udbg_scc_putc(char c
)
30 while ((in_8(sccc
) & SCC_TXRDY
) == 0)
38 static int udbg_scc_getc_poll(void)
41 if ((in_8(sccc
) & SCC_RXRDY
) != 0)
49 static int udbg_scc_getc(void)
52 while ((in_8(sccc
) & SCC_RXRDY
) == 0)
59 static unsigned char scc_inittab
[] = {
60 13, 0, /* set baud rate divisor */
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 */
69 void udbg_scc_init(int force_scc
)
73 struct device_node
*stdout
= NULL
, *escc
= NULL
, *macio
= NULL
;
74 struct device_node
*ch
, *ch_def
= NULL
, *ch_a
= NULL
;
78 escc
= of_find_node_by_name(NULL
, "escc");
81 macio
= of_get_parent(escc
);
84 path
= of_get_property(of_chosen
, "linux,stdout-path", NULL
);
86 stdout
= of_find_node_by_path(path
);
87 for (ch
= NULL
; (ch
= of_get_next_child(escc
, ch
)) != NULL
;) {
89 ch_def
= of_node_get(ch
);
90 if (strcmp(ch
->name
, "ch-a") == 0)
91 ch_a
= of_node_get(ch
);
93 if (ch_def
== NULL
&& !force_scc
)
96 ch
= ch_def
? ch_def
: ch_a
;
98 /* Get address within mac-io ASIC */
99 reg
= of_get_property(escc
, "reg", NULL
);
104 /* Get address of mac-io PCI itself */
105 reg
= of_get_property(macio
, "assigned-addresses", NULL
);
110 /* Lock the serial port */
111 pmac_call_feature(PMAC_FTR_SCC_ENABLE
, ch
,
112 PMAC_SCC_ASYNC
| PMAC_SCC_FLAG_XMON
, 1);
116 sccc
= ioremap(addr
& PAGE_MASK
, PAGE_SIZE
) ;
117 sccc
+= addr
& ~PAGE_MASK
;
122 for (i
= 20000; i
!= 0; --i
)
124 out_8(sccc
, 0x09); /* reset A or B side */
127 /* If SCC was the OF output port, read the BRG value, else
128 * Setup for 57600 8N1
130 if (ch_def
!= NULL
) {
132 scc_inittab
[1] = in_8(sccc
);
134 scc_inittab
[3] = in_8(sccc
);
137 for (i
= 0; i
< sizeof(scc_inittab
); ++i
)
138 out_8(sccc
, scc_inittab
[i
]);
141 udbg_putc
= udbg_scc_putc
;
142 udbg_getc
= udbg_scc_getc
;
143 udbg_getc_poll
= udbg_scc_getc_poll
;
145 udbg_puts("Hello World !\n");
156 static void udbg_real_scc_putc(char c
)
158 while ((real_readb(sccc
) & SCC_TXRDY
) == 0)
160 real_writeb(c
, sccd
);
162 udbg_real_scc_putc('\r');
165 void __init
udbg_init_pmac_realmode(void)
167 sccc
= (volatile u8 __iomem
*)0x80013020ul
;
168 sccd
= (volatile u8 __iomem
*)0x80013030ul
;
170 udbg_putc
= udbg_real_scc_putc
;
172 udbg_getc_poll
= NULL
;
174 #endif /* CONFIG_PPC64 */