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>
13 #include <asm/ppcdebug.h>
14 #include <asm/processor.h>
16 #include <asm/uaccess.h>
17 #include <asm/machdep.h>
20 #include <asm/pmac_feature.h>
22 extern u8 real_readb(volatile u8 __iomem *addr);
23 extern void real_writeb(u8 data, volatile u8 __iomem *addr);
28 static volatile u8 __iomem *sccc;
29 static volatile u8 __iomem *sccd;
31 static void udbg_scc_putc(unsigned char c)
34 while ((in_8(sccc) & SCC_TXRDY) == 0)
42 static int udbg_scc_getc_poll(void)
45 if ((in_8(sccc) & SCC_RXRDY) != 0)
53 static unsigned char udbg_scc_getc(void)
56 while ((in_8(sccc) & SCC_RXRDY) == 0)
63 static unsigned char scc_inittab[] = {
64 13, 0, /* set baud rate divisor */
66 14, 1, /* baud rate gen enable, src=rtxc */
67 11, 0x50, /* clocks = br gen */
68 5, 0xea, /* tx 8 bits, assert DTR & RTS */
69 4, 0x46, /* x16 clock, 1 stop */
70 3, 0xc1, /* rx enable, 8 bits */
73 void udbg_init_scc(struct device_node *np)
80 np = of_find_node_by_name(NULL, "escc");
81 if (np == NULL || np->parent == NULL)
84 udbg_printf("found SCC...\n");
85 /* Get address within mac-io ASIC */
86 reg = (u32 *)get_property(np, "reg", NULL);
90 udbg_printf("local addr: %lx\n", addr);
91 /* Get address of mac-io PCI itself */
92 reg = (u32 *)get_property(np->parent, "assigned-addresses", NULL);
96 udbg_printf("final addr: %lx\n", addr);
98 /* Setup for 57600 8N1 */
100 sccc = (volatile u8 * __iomem) ioremap(addr & PAGE_MASK, PAGE_SIZE) ;
101 sccc += addr & ~PAGE_MASK;
104 udbg_printf("ioremap result sccc: %p\n", sccc);
107 for (i = 20000; i != 0; --i)
109 out_8(sccc, 0x09); /* reset A or B side */
111 for (i = 0; i < sizeof(scc_inittab); ++i)
112 out_8(sccc, scc_inittab[i]);
114 ppc_md.udbg_putc = udbg_scc_putc;
115 ppc_md.udbg_getc = udbg_scc_getc;
116 ppc_md.udbg_getc_poll = udbg_scc_getc_poll;
118 udbg_puts("Hello World !\n");
121 static void udbg_real_scc_putc(unsigned char c)
123 while ((real_readb(sccc) & SCC_TXRDY) == 0)
125 real_writeb(c, sccd);
127 udbg_real_scc_putc('\r');
130 void udbg_init_pmac_realmode(void)
132 sccc = (volatile u8 __iomem *)0x80013020ul;
133 sccd = (volatile u8 __iomem *)0x80013030ul;
135 ppc_md.udbg_putc = udbg_real_scc_putc;
136 ppc_md.udbg_getc = NULL;
137 ppc_md.udbg_getc_poll = NULL;