1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * udbg for zilog scc ports as found on Apple PowerMacs
5 * Copyright (C) 2001-2005 PPC 64 Team, IBM Corp
7 #include <linux/types.h>
9 #include <asm/processor.h>
12 #include <asm/pmac_feature.h>
14 extern u8
real_readb(volatile u8 __iomem
*addr
);
15 extern void real_writeb(u8 data
, volatile u8 __iomem
*addr
);
20 static volatile u8 __iomem
*sccc
;
21 static volatile u8 __iomem
*sccd
;
23 static void udbg_scc_putc(char c
)
26 while ((in_8(sccc
) & SCC_TXRDY
) == 0)
34 static int udbg_scc_getc_poll(void)
37 if ((in_8(sccc
) & SCC_RXRDY
) != 0)
45 static int udbg_scc_getc(void)
48 while ((in_8(sccc
) & SCC_RXRDY
) == 0)
55 static unsigned char scc_inittab
[] = {
56 13, 0, /* set baud rate divisor */
58 14, 1, /* baud rate gen enable, src=rtxc */
59 11, 0x50, /* clocks = br gen */
60 5, 0xea, /* tx 8 bits, assert DTR & RTS */
61 4, 0x46, /* x16 clock, 1 stop */
62 3, 0xc1, /* rx enable, 8 bits */
65 void udbg_scc_init(int force_scc
)
69 struct device_node
*stdout
= NULL
, *escc
= NULL
, *macio
= NULL
;
70 struct device_node
*ch
, *ch_def
= NULL
, *ch_a
= NULL
;
74 escc
= of_find_node_by_name(NULL
, "escc");
77 macio
= of_get_parent(escc
);
80 path
= of_get_property(of_chosen
, "linux,stdout-path", NULL
);
82 stdout
= of_find_node_by_path(path
);
83 for_each_child_of_node(escc
, ch
) {
85 ch_def
= of_node_get(ch
);
86 if (of_node_name_eq(ch
, "ch-a"))
87 ch_a
= of_node_get(ch
);
89 if (ch_def
== NULL
&& !force_scc
)
92 ch
= ch_def
? ch_def
: ch_a
;
94 /* Get address within mac-io ASIC */
95 reg
= of_get_property(escc
, "reg", NULL
);
100 /* Get address of mac-io PCI itself */
101 reg
= of_get_property(macio
, "assigned-addresses", NULL
);
106 /* Lock the serial port */
107 pmac_call_feature(PMAC_FTR_SCC_ENABLE
, ch
,
108 PMAC_SCC_ASYNC
| PMAC_SCC_FLAG_XMON
, 1);
112 sccc
= ioremap(addr
& PAGE_MASK
, PAGE_SIZE
) ;
113 sccc
+= addr
& ~PAGE_MASK
;
118 for (i
= 20000; i
!= 0; --i
)
120 out_8(sccc
, 0x09); /* reset A or B side */
123 /* If SCC was the OF output port, read the BRG value, else
124 * Setup for 38400 or 57600 8N1 depending on the machine
126 if (ch_def
!= NULL
) {
128 scc_inittab
[1] = in_8(sccc
);
130 scc_inittab
[3] = in_8(sccc
);
131 } else if (of_machine_is_compatible("RackMac1,1")
132 || of_machine_is_compatible("RackMac1,2")
133 || of_machine_is_compatible("MacRISC4")) {
134 /* Xserves and G5s default to 57600 */
138 /* Others default to 38400 */
143 for (i
= 0; i
< sizeof(scc_inittab
); ++i
)
144 out_8(sccc
, scc_inittab
[i
]);
147 udbg_putc
= udbg_scc_putc
;
148 udbg_getc
= udbg_scc_getc
;
149 udbg_getc_poll
= udbg_scc_getc_poll
;
151 udbg_puts("Hello World !\n");
162 static void udbg_real_scc_putc(char c
)
164 while ((real_readb(sccc
) & SCC_TXRDY
) == 0)
166 real_writeb(c
, sccd
);
168 udbg_real_scc_putc('\r');
171 void __init
udbg_init_pmac_realmode(void)
173 sccc
= (volatile u8 __iomem
*)0x80013020ul
;
174 sccd
= (volatile u8 __iomem
*)0x80013030ul
;
176 udbg_putc
= udbg_real_scc_putc
;
178 udbg_getc_poll
= NULL
;
180 #endif /* CONFIG_PPC64 */