]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/mips/txx9/generic/setup_tx4938.c
b0a3dc8863fdac8c2506134e71b04318c440f1be
[linux-2.6-omap-h63xx.git] / arch / mips / txx9 / generic / setup_tx4938.c
1 /*
2  * TX4938/4937 setup routines
3  * Based on linux/arch/mips/txx9/rbtx4938/setup.c,
4  *          and RBTX49xx patch from CELF patch archive.
5  *
6  * 2003-2005 (c) MontaVista Software, Inc.
7  * (C) Copyright TOSHIBA CORPORATION 2000-2001, 2004-2007
8  *
9  * This file is subject to the terms and conditions of the GNU General Public
10  * License.  See the file "COPYING" in the main directory of this archive
11  * for more details.
12  */
13 #include <linux/init.h>
14 #include <linux/ioport.h>
15 #include <linux/delay.h>
16 #include <linux/serial_core.h>
17 #include <linux/param.h>
18 #include <asm/txx9irq.h>
19 #include <asm/txx9tmr.h>
20 #include <asm/txx9pio.h>
21 #include <asm/txx9/generic.h>
22 #include <asm/txx9/tx4938.h>
23
24 static void __init tx4938_wdr_init(void)
25 {
26         /* clear WatchDogReset (W1C) */
27         tx4938_ccfg_set(TX4938_CCFG_WDRST);
28         /* do reset on watchdog */
29         tx4938_ccfg_set(TX4938_CCFG_WR);
30 }
31
32 void __init tx4938_wdt_init(void)
33 {
34         txx9_wdt_init(TX4938_TMR_REG(2) & 0xfffffffffULL);
35 }
36
37 static struct resource tx4938_sdram_resource[4];
38 static struct resource tx4938_sram_resource;
39
40 #define TX4938_SRAM_SIZE 0x800
41
42 void __init tx4938_setup(void)
43 {
44         int i;
45         __u32 divmode;
46         int cpuclk = 0;
47         u64 ccfg;
48
49         txx9_reg_res_init(TX4938_REV_PCODE(), TX4938_REG_BASE,
50                           TX4938_REG_SIZE);
51
52         /* SDRAMC,EBUSC are configured by PROM */
53         for (i = 0; i < 8; i++) {
54                 if (!(TX4938_EBUSC_CR(i) & 0x8))
55                         continue;       /* disabled */
56                 txx9_ce_res[i].start = (unsigned long)TX4938_EBUSC_BA(i);
57                 txx9_ce_res[i].end =
58                         txx9_ce_res[i].start + TX4938_EBUSC_SIZE(i) - 1;
59                 request_resource(&iomem_resource, &txx9_ce_res[i]);
60         }
61
62         /* clocks */
63         ccfg = ____raw_readq(&tx4938_ccfgptr->ccfg);
64         if (txx9_master_clock) {
65                 /* calculate gbus_clock and cpu_clock from master_clock */
66                 divmode = (__u32)ccfg & TX4938_CCFG_DIVMODE_MASK;
67                 switch (divmode) {
68                 case TX4938_CCFG_DIVMODE_8:
69                 case TX4938_CCFG_DIVMODE_10:
70                 case TX4938_CCFG_DIVMODE_12:
71                 case TX4938_CCFG_DIVMODE_16:
72                 case TX4938_CCFG_DIVMODE_18:
73                         txx9_gbus_clock = txx9_master_clock * 4; break;
74                 default:
75                         txx9_gbus_clock = txx9_master_clock;
76                 }
77                 switch (divmode) {
78                 case TX4938_CCFG_DIVMODE_2:
79                 case TX4938_CCFG_DIVMODE_8:
80                         cpuclk = txx9_gbus_clock * 2; break;
81                 case TX4938_CCFG_DIVMODE_2_5:
82                 case TX4938_CCFG_DIVMODE_10:
83                         cpuclk = txx9_gbus_clock * 5 / 2; break;
84                 case TX4938_CCFG_DIVMODE_3:
85                 case TX4938_CCFG_DIVMODE_12:
86                         cpuclk = txx9_gbus_clock * 3; break;
87                 case TX4938_CCFG_DIVMODE_4:
88                 case TX4938_CCFG_DIVMODE_16:
89                         cpuclk = txx9_gbus_clock * 4; break;
90                 case TX4938_CCFG_DIVMODE_4_5:
91                 case TX4938_CCFG_DIVMODE_18:
92                         cpuclk = txx9_gbus_clock * 9 / 2; break;
93                 }
94                 txx9_cpu_clock = cpuclk;
95         } else {
96                 if (txx9_cpu_clock == 0)
97                         txx9_cpu_clock = 300000000;     /* 300MHz */
98                 /* calculate gbus_clock and master_clock from cpu_clock */
99                 cpuclk = txx9_cpu_clock;
100                 divmode = (__u32)ccfg & TX4938_CCFG_DIVMODE_MASK;
101                 switch (divmode) {
102                 case TX4938_CCFG_DIVMODE_2:
103                 case TX4938_CCFG_DIVMODE_8:
104                         txx9_gbus_clock = cpuclk / 2; break;
105                 case TX4938_CCFG_DIVMODE_2_5:
106                 case TX4938_CCFG_DIVMODE_10:
107                         txx9_gbus_clock = cpuclk * 2 / 5; break;
108                 case TX4938_CCFG_DIVMODE_3:
109                 case TX4938_CCFG_DIVMODE_12:
110                         txx9_gbus_clock = cpuclk / 3; break;
111                 case TX4938_CCFG_DIVMODE_4:
112                 case TX4938_CCFG_DIVMODE_16:
113                         txx9_gbus_clock = cpuclk / 4; break;
114                 case TX4938_CCFG_DIVMODE_4_5:
115                 case TX4938_CCFG_DIVMODE_18:
116                         txx9_gbus_clock = cpuclk * 2 / 9; break;
117                 }
118                 switch (divmode) {
119                 case TX4938_CCFG_DIVMODE_8:
120                 case TX4938_CCFG_DIVMODE_10:
121                 case TX4938_CCFG_DIVMODE_12:
122                 case TX4938_CCFG_DIVMODE_16:
123                 case TX4938_CCFG_DIVMODE_18:
124                         txx9_master_clock = txx9_gbus_clock / 4; break;
125                 default:
126                         txx9_master_clock = txx9_gbus_clock;
127                 }
128         }
129         /* change default value to udelay/mdelay take reasonable time */
130         loops_per_jiffy = txx9_cpu_clock / HZ / 2;
131
132         /* CCFG */
133         tx4938_wdr_init();
134         /* clear BusErrorOnWrite flag (W1C) */
135         tx4938_ccfg_set(TX4938_CCFG_BEOW);
136         /* enable Timeout BusError */
137         if (txx9_ccfg_toeon)
138                 tx4938_ccfg_set(TX4938_CCFG_TOE);
139
140         /* DMA selection */
141         txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_DMASEL_ALL);
142
143         /* Use external clock for external arbiter */
144         if (!(____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCIARB))
145                 txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_PCICLKEN_ALL);
146
147         printk(KERN_INFO "%s -- %dMHz(M%dMHz) CRIR:%08x CCFG:%llx PCFG:%llx\n",
148                txx9_pcode_str,
149                (cpuclk + 500000) / 1000000,
150                (txx9_master_clock + 500000) / 1000000,
151                (__u32)____raw_readq(&tx4938_ccfgptr->crir),
152                (unsigned long long)____raw_readq(&tx4938_ccfgptr->ccfg),
153                (unsigned long long)____raw_readq(&tx4938_ccfgptr->pcfg));
154
155         printk(KERN_INFO "%s SDRAMC --", txx9_pcode_str);
156         for (i = 0; i < 4; i++) {
157                 __u64 cr = TX4938_SDRAMC_CR(i);
158                 unsigned long base, size;
159                 if (!((__u32)cr & 0x00000400))
160                         continue;       /* disabled */
161                 base = (unsigned long)(cr >> 49) << 21;
162                 size = (((unsigned long)(cr >> 33) & 0x7fff) + 1) << 21;
163                 printk(" CR%d:%016llx", i, (unsigned long long)cr);
164                 tx4938_sdram_resource[i].name = "SDRAM";
165                 tx4938_sdram_resource[i].start = base;
166                 tx4938_sdram_resource[i].end = base + size - 1;
167                 tx4938_sdram_resource[i].flags = IORESOURCE_MEM;
168                 request_resource(&iomem_resource, &tx4938_sdram_resource[i]);
169         }
170         printk(" TR:%09llx\n",
171                (unsigned long long)____raw_readq(&tx4938_sdramcptr->tr));
172
173         /* SRAM */
174         if (txx9_pcode == 0x4938 && ____raw_readq(&tx4938_sramcptr->cr) & 1) {
175                 unsigned int size = TX4938_SRAM_SIZE;
176                 tx4938_sram_resource.name = "SRAM";
177                 tx4938_sram_resource.start =
178                         (____raw_readq(&tx4938_sramcptr->cr) >> (39-11))
179                         & ~(size - 1);
180                 tx4938_sram_resource.end =
181                         tx4938_sram_resource.start + TX4938_SRAM_SIZE - 1;
182                 tx4938_sram_resource.flags = IORESOURCE_MEM;
183                 request_resource(&iomem_resource, &tx4938_sram_resource);
184         }
185
186         /* TMR */
187         /* disable all timers */
188         for (i = 0; i < TX4938_NR_TMR; i++)
189                 txx9_tmr_init(TX4938_TMR_REG(i) & 0xfffffffffULL);
190
191         /* DMA */
192         for (i = 0; i < 2; i++)
193                 ____raw_writeq(TX4938_DMA_MCR_MSTEN,
194                                (void __iomem *)(TX4938_DMA_REG(i) + 0x50));
195
196         /* PIO */
197         txx9_gpio_init(TX4938_PIO_REG & 0xfffffffffULL, 0, TX4938_NUM_PIO);
198         __raw_writel(0, &tx4938_pioptr->maskcpu);
199         __raw_writel(0, &tx4938_pioptr->maskext);
200
201         if (txx9_pcode == 0x4938) {
202                 __u64 pcfg = ____raw_readq(&tx4938_ccfgptr->pcfg);
203                 /* set PCIC1 reset */
204                 txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIC1RST);
205                 if (pcfg & (TX4938_PCFG_ETH0_SEL | TX4938_PCFG_ETH1_SEL)) {
206                         mdelay(1);      /* at least 128 cpu clock */
207                         /* clear PCIC1 reset */
208                         txx9_clear64(&tx4938_ccfgptr->clkctr,
209                                      TX4938_CLKCTR_PCIC1RST);
210                 } else {
211                         printk(KERN_INFO "%s: stop PCIC1\n", txx9_pcode_str);
212                         /* stop PCIC1 */
213                         txx9_set64(&tx4938_ccfgptr->clkctr,
214                                    TX4938_CLKCTR_PCIC1CKD);
215                 }
216                 if (!(pcfg & TX4938_PCFG_ETH0_SEL)) {
217                         printk(KERN_INFO "%s: stop ETH0\n", txx9_pcode_str);
218                         txx9_set64(&tx4938_ccfgptr->clkctr,
219                                    TX4938_CLKCTR_ETH0RST);
220                         txx9_set64(&tx4938_ccfgptr->clkctr,
221                                    TX4938_CLKCTR_ETH0CKD);
222                 }
223                 if (!(pcfg & TX4938_PCFG_ETH1_SEL)) {
224                         printk(KERN_INFO "%s: stop ETH1\n", txx9_pcode_str);
225                         txx9_set64(&tx4938_ccfgptr->clkctr,
226                                    TX4938_CLKCTR_ETH1RST);
227                         txx9_set64(&tx4938_ccfgptr->clkctr,
228                                    TX4938_CLKCTR_ETH1CKD);
229                 }
230         }
231 }
232
233 void __init tx4938_time_init(unsigned int tmrnr)
234 {
235         if (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_TINTDIS)
236                 txx9_clockevent_init(TX4938_TMR_REG(tmrnr) & 0xfffffffffULL,
237                                      TXX9_IRQ_BASE + TX4938_IR_TMR(tmrnr),
238                                      TXX9_IMCLK);
239 }
240
241 void __init tx4938_setup_serial(void)
242 {
243 #ifdef CONFIG_SERIAL_TXX9
244         int i;
245         struct uart_port req;
246         unsigned int ch_mask = 0;
247
248         if (__raw_readq(&tx4938_ccfgptr->pcfg) & TX4938_PCFG_ETH0_SEL)
249                 ch_mask |= 1 << 1; /* disable SIO1 by PCFG setting */
250         for (i = 0; i < 2; i++) {
251                 if ((1 << i) & ch_mask)
252                         continue;
253                 memset(&req, 0, sizeof(req));
254                 req.line = i;
255                 req.iotype = UPIO_MEM;
256                 req.membase = (unsigned char __iomem *)TX4938_SIO_REG(i);
257                 req.mapbase = TX4938_SIO_REG(i) & 0xfffffffffULL;
258                 req.irq = TXX9_IRQ_BASE + TX4938_IR_SIO(i);
259                 req.flags |= UPF_BUGGY_UART /*HAVE_CTS_LINE*/;
260                 req.uartclk = TXX9_IMCLK;
261                 early_serial_txx9_setup(&req);
262         }
263 #endif /* CONFIG_SERIAL_TXX9 */
264 }