drm: fix issues with systems with no MTRR
[pandora-kernel.git] / arch / powerpc / kernel / udbg_scc.c
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/io.h>
16 #include <asm/prom.h>
17 #include <asm/pmac_feature.h>
18
19 extern u8 real_readb(volatile u8 __iomem  *addr);
20 extern void real_writeb(u8 data, volatile u8 __iomem *addr);
21
22 #define SCC_TXRDY       4
23 #define SCC_RXRDY       1
24
25 static volatile u8 __iomem *sccc;
26 static volatile u8 __iomem *sccd;
27
28 static void udbg_scc_putc(unsigned char c)
29 {
30         if (sccc) {
31                 while ((in_8(sccc) & SCC_TXRDY) == 0)
32                         ;
33                 out_8(sccd,  c);
34                 if (c == '\n')
35                         udbg_scc_putc('\r');
36         }
37 }
38
39 static int udbg_scc_getc_poll(void)
40 {
41         if (sccc) {
42                 if ((in_8(sccc) & SCC_RXRDY) != 0)
43                         return in_8(sccd);
44                 else
45                         return -1;
46         }
47         return -1;
48 }
49
50 static unsigned char udbg_scc_getc(void)
51 {
52         if (sccc) {
53                 while ((in_8(sccc) & SCC_RXRDY) == 0)
54                         ;
55                 return in_8(sccd);
56         }
57         return 0;
58 }
59
60 static unsigned char scc_inittab[] = {
61     13, 0,              /* set baud rate divisor */
62     12, 0,
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 */
68 };
69
70 void udbg_init_scc(struct device_node *np)
71 {
72         u32 *reg;
73         unsigned long addr;
74         int i, x;
75
76         if (np == NULL)
77                 np = of_find_node_by_name(NULL, "escc");
78         if (np == NULL || np->parent == NULL)
79                 return;
80
81         udbg_printf("found SCC...\n");
82         /* Get address within mac-io ASIC */
83         reg = (u32 *)get_property(np, "reg", NULL);
84         if (reg == NULL)
85                 return;
86         addr = reg[0];
87         udbg_printf("local addr: %lx\n", addr);
88         /* Get address of mac-io PCI itself */
89         reg = (u32 *)get_property(np->parent, "assigned-addresses", NULL);
90         if (reg == NULL)
91                 return;
92         addr += reg[2];
93         udbg_printf("final addr: %lx\n", addr);
94
95         /* Setup for 57600 8N1 */
96         addr += 0x20;
97         sccc = (volatile u8 * __iomem) ioremap(addr & PAGE_MASK, PAGE_SIZE) ;
98         sccc += addr & ~PAGE_MASK;
99         sccd = sccc + 0x10;
100
101         udbg_printf("ioremap result sccc: %p\n", sccc);
102         mb();
103
104         for (i = 20000; i != 0; --i)
105                 x = in_8(sccc);
106         out_8(sccc, 0x09);              /* reset A or B side */
107         out_8(sccc, 0xc0);
108         for (i = 0; i < sizeof(scc_inittab); ++i)
109                 out_8(sccc, scc_inittab[i]);
110
111         udbg_putc = udbg_scc_putc;
112         udbg_getc = udbg_scc_getc;
113         udbg_getc_poll = udbg_scc_getc_poll;
114
115         udbg_puts("Hello World !\n");
116 }
117
118 static void udbg_real_scc_putc(unsigned char c)
119 {
120         while ((real_readb(sccc) & SCC_TXRDY) == 0)
121                 ;
122         real_writeb(c, sccd);
123         if (c == '\n')
124                 udbg_real_scc_putc('\r');
125 }
126
127 void udbg_init_pmac_realmode(void)
128 {
129         sccc = (volatile u8 __iomem *)0x80013020ul;
130         sccd = (volatile u8 __iomem *)0x80013030ul;
131
132         udbg_putc = udbg_real_scc_putc;
133         udbg_getc = NULL;
134         udbg_getc_poll = NULL;
135 }