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/config.h>
12 #include <linux/types.h>
14 #include <asm/processor.h>
17 #include <asm/pmac_feature.h>
19 extern u8
real_readb(volatile u8 __iomem
*addr
);
20 extern void real_writeb(u8 data
, volatile u8 __iomem
*addr
);
25 static volatile u8 __iomem
*sccc
;
26 static volatile u8 __iomem
*sccd
;
28 static void udbg_scc_putc(char c
)
31 while ((in_8(sccc
) & SCC_TXRDY
) == 0)
39 static int udbg_scc_getc_poll(void)
42 if ((in_8(sccc
) & SCC_RXRDY
) != 0)
50 static int udbg_scc_getc(void)
53 while ((in_8(sccc
) & SCC_RXRDY
) == 0)
60 static unsigned char scc_inittab
[] = {
61 13, 0, /* set baud rate divisor */
63 14, 1, /* baud rate gen enable, src=rtxc */
64 11, 0x50, /* clocks = br gen */
65 5, 0xea, /* tx 8 bits, assert DTR & RTS */
66 4, 0x46, /* x16 clock, 1 stop */
67 3, 0xc1, /* rx enable, 8 bits */
70 void udbg_scc_init(int force_scc
)
74 struct device_node
*stdout
= NULL
, *escc
= NULL
, *macio
= NULL
;
75 struct device_node
*ch
, *ch_def
= NULL
, *ch_a
= NULL
;
79 escc
= of_find_node_by_name(NULL
, "escc");
82 macio
= of_get_parent(escc
);
85 path
= (char *)get_property(of_chosen
, "linux,stdout-path", NULL
);
87 stdout
= of_find_node_by_path(path
);
88 for (ch
= NULL
; (ch
= of_get_next_child(escc
, ch
)) != NULL
;) {
90 ch_def
= of_node_get(ch
);
91 if (strcmp(ch
->name
, "ch-a") == 0)
92 ch_a
= of_node_get(ch
);
94 if (ch_def
== NULL
&& !force_scc
)
97 ch
= ch_def
? ch_def
: ch_a
;
99 /* Get address within mac-io ASIC */
100 reg
= (u32
*)get_property(escc
, "reg", NULL
);
105 /* Get address of mac-io PCI itself */
106 reg
= (u32
*)get_property(macio
, "assigned-addresses", NULL
);
111 /* Lock the serial port */
112 pmac_call_feature(PMAC_FTR_SCC_ENABLE
, ch
,
113 PMAC_SCC_ASYNC
| PMAC_SCC_FLAG_XMON
, 1);
116 /* Setup for 57600 8N1 */
119 sccc
= (volatile u8
* __iomem
) ioremap(addr
& PAGE_MASK
, PAGE_SIZE
) ;
120 sccc
+= addr
& ~PAGE_MASK
;
125 for (i
= 20000; i
!= 0; --i
)
127 out_8(sccc
, 0x09); /* reset A or B side */
129 for (i
= 0; i
< sizeof(scc_inittab
); ++i
)
130 out_8(sccc
, scc_inittab
[i
]);
132 udbg_putc
= udbg_scc_putc
;
133 udbg_getc
= udbg_scc_getc
;
134 udbg_getc_poll
= udbg_scc_getc_poll
;
136 udbg_puts("Hello World !\n");
147 static void udbg_real_scc_putc(char c
)
149 while ((real_readb(sccc
) & SCC_TXRDY
) == 0)
151 real_writeb(c
, sccd
);
153 udbg_real_scc_putc('\r');
156 void __init
udbg_init_pmac_realmode(void)
158 sccc
= (volatile u8 __iomem
*)0x80013020ul
;
159 sccd
= (volatile u8 __iomem
*)0x80013030ul
;
161 udbg_putc
= udbg_real_scc_putc
;
163 udbg_getc_poll
= NULL
;
165 #endif /* CONFIG_PPC64 */