blob: 0d39bafea794278968384700b19f7125bd8785cf [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Toshiba rbtx4927 specific setup
3 *
4 * Author: MontaVista Software, Inc.
5 * source@mvista.com
6 *
7 * Copyright 2001-2002 MontaVista Software Inc.
8 *
9 * Copyright (C) 1996, 97, 2001, 04 Ralf Baechle (ralf@linux-mips.org)
10 * Copyright (C) 2000 RidgeRun, Inc.
11 * Author: RidgeRun, Inc.
12 * glonnon@ridgerun.com, skranz@ridgerun.com, stevej@ridgerun.com
13 *
14 * Copyright 2001 MontaVista Software Inc.
15 * Author: jsun@mvista.com or jsun@junsun.net
16 *
17 * Copyright 2002 MontaVista Software Inc.
18 * Author: Michael Pruznick, michael_pruznick@mvista.com
19 *
20 * Copyright (C) 2000-2001 Toshiba Corporation
21 *
22 * Copyright (C) 2004 MontaVista Software Inc.
23 * Author: Manish Lachwani, mlachwani@mvista.com
24 *
25 * This program is free software; you can redistribute it and/or modify it
26 * under the terms of the GNU General Public License as published by the
27 * Free Software Foundation; either version 2 of the License, or (at your
28 * option) any later version.
29 *
30 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
31 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
32 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
33 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
34 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
35 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
36 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
37 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
38 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
39 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * You should have received a copy of the GNU General Public License along
42 * with this program; if not, write to the Free Software Foundation, Inc.,
43 * 675 Mass Ave, Cambridge, MA 02139, USA.
44 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/init.h>
46#include <linux/kernel.h>
47#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <linux/ioport.h>
Atsushi Nemotoa0574e02007-03-01 00:40:21 +090049#include <linux/platform_device.h>
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090050#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <asm/reboot.h>
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090053#include <asm/txx9/generic.h>
54#include <asm/txx9/pci.h>
Atsushi Nemoto22b1d702008-07-11 00:31:36 +090055#include <asm/txx9/rbtx4927.h>
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090056#include <asm/txx9/tx4938.h> /* for TX4937 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#ifdef CONFIG_PCI
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090059static void __init tx4927_pci_setup(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090061 int extarb = !(__raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_PCIARB);
62 struct pci_controller *c = &txx9_primary_pcic;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090064 register_pci_controller(c);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090066 if (__raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_PCI66)
67 txx9_pci_option =
68 (txx9_pci_option & ~TXX9_PCI_OPT_CLK_MASK) |
69 TXX9_PCI_OPT_CLK_66; /* already configured */
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090071 /* Reset PCI Bus */
72 writeb(1, rbtx4927_pcireset_addr);
73 /* Reset PCIC */
74 txx9_set64(&tx4927_ccfgptr->clkctr, TX4927_CLKCTR_PCIRST);
75 if ((txx9_pci_option & TXX9_PCI_OPT_CLK_MASK) ==
76 TXX9_PCI_OPT_CLK_66)
77 tx4927_pciclk66_setup();
78 mdelay(10);
79 /* clear PCIC reset */
80 txx9_clear64(&tx4927_ccfgptr->clkctr, TX4927_CLKCTR_PCIRST);
81 writeb(0, rbtx4927_pcireset_addr);
82 iob();
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090084 tx4927_report_pciclk();
85 tx4927_pcic_setup(tx4927_pcicptr, c, extarb);
86 if ((txx9_pci_option & TXX9_PCI_OPT_CLK_MASK) ==
87 TXX9_PCI_OPT_CLK_AUTO &&
88 txx9_pci66_check(c, 0, 0)) {
89 /* Reset PCI Bus */
90 writeb(1, rbtx4927_pcireset_addr);
91 /* Reset PCIC */
92 txx9_set64(&tx4927_ccfgptr->clkctr, TX4927_CLKCTR_PCIRST);
93 tx4927_pciclk66_setup();
94 mdelay(10);
95 /* clear PCIC reset */
96 txx9_clear64(&tx4927_ccfgptr->clkctr, TX4927_CLKCTR_PCIRST);
97 writeb(0, rbtx4927_pcireset_addr);
98 iob();
99 /* Reinitialize PCIC */
100 tx4927_report_pciclk();
101 tx4927_pcic_setup(tx4927_pcicptr, c, extarb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 }
Atsushi Nemoto455cc252008-07-25 23:01:35 +0900103 tx4927_setup_pcierr_irq();
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900104}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900106static void __init tx4937_pci_setup(void)
107{
108 int extarb = !(__raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCIARB);
109 struct pci_controller *c = &txx9_primary_pcic;
110
111 register_pci_controller(c);
112
113 if (__raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCI66)
114 txx9_pci_option =
115 (txx9_pci_option & ~TXX9_PCI_OPT_CLK_MASK) |
116 TXX9_PCI_OPT_CLK_66; /* already configured */
117
118 /* Reset PCI Bus */
119 writeb(1, rbtx4927_pcireset_addr);
120 /* Reset PCIC */
121 txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
122 if ((txx9_pci_option & TXX9_PCI_OPT_CLK_MASK) ==
123 TXX9_PCI_OPT_CLK_66)
124 tx4938_pciclk66_setup();
125 mdelay(10);
126 /* clear PCIC reset */
127 txx9_clear64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
128 writeb(0, rbtx4927_pcireset_addr);
129 iob();
130
131 tx4938_report_pciclk();
132 tx4927_pcic_setup(tx4938_pcicptr, c, extarb);
133 if ((txx9_pci_option & TXX9_PCI_OPT_CLK_MASK) ==
134 TXX9_PCI_OPT_CLK_AUTO &&
135 txx9_pci66_check(c, 0, 0)) {
136 /* Reset PCI Bus */
137 writeb(1, rbtx4927_pcireset_addr);
138 /* Reset PCIC */
139 txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
140 tx4938_pciclk66_setup();
141 mdelay(10);
142 /* clear PCIC reset */
143 txx9_clear64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
144 writeb(0, rbtx4927_pcireset_addr);
145 iob();
146 /* Reinitialize PCIC */
147 tx4938_report_pciclk();
148 tx4927_pcic_setup(tx4938_pcicptr, c, extarb);
149 }
Atsushi Nemoto455cc252008-07-25 23:01:35 +0900150 tx4938_setup_pcierr_irq();
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900151}
152
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900153static void __init rbtx4927_arch_init(void)
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900154{
Yoichi Yuasaa38c4752008-07-13 20:01:04 +0900155 tx4927_pci_setup();
156}
157
158static void __init rbtx4937_arch_init(void)
159{
160 tx4937_pci_setup();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161}
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900162#else
163#define rbtx4927_arch_init NULL
Yoichi Yuasaa38c4752008-07-13 20:01:04 +0900164#define rbtx4937_arch_init NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165#endif /* CONFIG_PCI */
166
Atsushi Nemoto7b226092008-07-14 00:15:04 +0900167static void toshiba_rbtx4927_restart(char *command)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 /* enable the s/w reset register */
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900170 writeb(1, rbtx4927_softresetlock_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
172 /* wait for enable to be seen */
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900173 while (!(readb(rbtx4927_softresetlock_addr) & 1))
174 ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
176 /* do a s/w reset */
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900177 writeb(1, rbtx4927_softreset_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
Atsushi Nemotoa49297e2008-07-24 00:25:17 +0900179 /* fallback */
180 (*_machine_halt)();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181}
182
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900183static void __init rbtx4927_clock_init(void);
184static void __init rbtx4937_clock_init(void);
185
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900186static void __init rbtx4927_mem_setup(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187{
Atsushi Nemotoa02eb8d2007-08-28 00:28:09 +0900188 u32 cp0_config;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 char *argptr;
190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 /* enable caches -- HCP5 does this, pmon does not */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 cp0_config = read_c0_config();
193 cp0_config = cp0_config & ~(TX49_CONF_IC | TX49_CONF_DC);
194 write_c0_config(cp0_config);
195
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900196 if (TX4927_REV_PCODE() == 0x4927) {
197 rbtx4927_clock_init();
198 tx4927_setup();
199 } else {
200 rbtx4937_clock_init();
201 tx4938_setup();
202 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 _machine_restart = toshiba_rbtx4927_restart;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
206#ifdef CONFIG_PCI
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900207 txx9_alloc_pci_controller(&txx9_primary_pcic,
208 RBTX4927_PCIMEM, RBTX4927_PCIMEM_SIZE,
209 RBTX4927_PCIIO, RBTX4927_PCIIO_SIZE);
Atsushi Nemoto07517522008-07-24 00:25:15 +0900210 txx9_board_pcibios_setup = tx4927_pcibios_setup;
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900211#else
212 set_io_port_base(KSEG1 + RBTX4927_ISA_IO_OFFSET);
213#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
Atsushi Nemoto7779a5e2008-07-25 23:08:06 +0900215 tx4927_sio_init(0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216#ifdef CONFIG_SERIAL_TXX9_CONSOLE
Atsushi Nemotobb72f1f2008-07-24 00:25:21 +0900217 argptr = prom_getcmdline();
218 if (!strstr(argptr, "console="))
219 strcat(argptr, " console=ttyS0,38400");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221}
222
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900223static void __init rbtx4927_clock_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224{
Yoichi Yuasaa00fb662008-07-13 19:54:08 +0900225 /*
226 * ASSUMPTION: PCIDIVMODE is configured for PCI 33MHz or 66MHz.
227 *
228 * For TX4927:
229 * PCIDIVMODE[12:11]'s initial value is given by S9[4:3] (ON:0, OFF:1).
230 * CPU 166MHz: PCI 66MHz : PCIDIVMODE: 00 (1/2.5)
231 * CPU 200MHz: PCI 66MHz : PCIDIVMODE: 01 (1/3)
232 * CPU 166MHz: PCI 33MHz : PCIDIVMODE: 10 (1/5)
233 * CPU 200MHz: PCI 33MHz : PCIDIVMODE: 11 (1/6)
234 * i.e. S9[3]: ON (83MHz), OFF (100MHz)
Yoichi Yuasab6c40532008-07-13 20:02:13 +0900235 */
236 switch ((unsigned long)__raw_readq(&tx4927_ccfgptr->ccfg) &
237 TX4927_CCFG_PCIDIVMODE_MASK) {
238 case TX4927_CCFG_PCIDIVMODE_2_5:
239 case TX4927_CCFG_PCIDIVMODE_5:
240 txx9_cpu_clock = 166666666; /* 166MHz */
241 break;
242 default:
243 txx9_cpu_clock = 200000000; /* 200MHz */
244 }
Yoichi Yuasab6c40532008-07-13 20:02:13 +0900245}
246
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900247static void __init rbtx4937_clock_init(void)
Yoichi Yuasab6c40532008-07-13 20:02:13 +0900248{
249 /*
250 * ASSUMPTION: PCIDIVMODE is configured for PCI 33MHz or 66MHz.
Yoichi Yuasaa00fb662008-07-13 19:54:08 +0900251 *
252 * For TX4937:
253 * PCIDIVMODE[12:11]'s initial value is given by S1[5:4] (ON:0, OFF:1)
254 * PCIDIVMODE[10] is 0.
255 * CPU 266MHz: PCI 33MHz : PCIDIVMODE: 000 (1/8)
256 * CPU 266MHz: PCI 66MHz : PCIDIVMODE: 001 (1/4)
257 * CPU 300MHz: PCI 33MHz : PCIDIVMODE: 010 (1/9)
258 * CPU 300MHz: PCI 66MHz : PCIDIVMODE: 011 (1/4.5)
259 * CPU 333MHz: PCI 33MHz : PCIDIVMODE: 100 (1/10)
260 * CPU 333MHz: PCI 66MHz : PCIDIVMODE: 101 (1/5)
261 */
Yoichi Yuasab6c40532008-07-13 20:02:13 +0900262 switch ((unsigned long)__raw_readq(&tx4938_ccfgptr->ccfg) &
263 TX4938_CCFG_PCIDIVMODE_MASK) {
264 case TX4938_CCFG_PCIDIVMODE_8:
265 case TX4938_CCFG_PCIDIVMODE_4:
266 txx9_cpu_clock = 266666666; /* 266MHz */
267 break;
268 case TX4938_CCFG_PCIDIVMODE_9:
269 case TX4938_CCFG_PCIDIVMODE_4_5:
270 txx9_cpu_clock = 300000000; /* 300MHz */
271 break;
272 default:
273 txx9_cpu_clock = 333333333; /* 333MHz */
274 }
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900275}
Yoichi Yuasaa00fb662008-07-13 19:54:08 +0900276
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900277static void __init rbtx4927_time_init(void)
278{
279 tx4927_time_init(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280}
281
Atsushi Nemotobb72f1f2008-07-24 00:25:21 +0900282static void __init toshiba_rbtx4927_rtc_init(void)
Atsushi Nemotoa0574e02007-03-01 00:40:21 +0900283{
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900284 struct resource res = {
285 .start = RBTX4927_BRAMRTC_BASE - IO_BASE,
286 .end = RBTX4927_BRAMRTC_BASE - IO_BASE + 0x800 - 1,
Atsushi Nemotoa0574e02007-03-01 00:40:21 +0900287 .flags = IORESOURCE_MEM,
288 };
Atsushi Nemotobb72f1f2008-07-24 00:25:21 +0900289 platform_device_register_simple("rtc-ds1742", -1, &res, 1);
Atsushi Nemotoa0574e02007-03-01 00:40:21 +0900290}
Atsushi Nemoto57e386c2007-05-01 00:27:58 +0900291
Atsushi Nemotobb72f1f2008-07-24 00:25:21 +0900292static void __init rbtx4927_ne_init(void)
Atsushi Nemoto57e386c2007-05-01 00:27:58 +0900293{
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900294 struct resource res[] = {
Atsushi Nemoto57e386c2007-05-01 00:27:58 +0900295 {
296 .start = RBTX4927_RTL_8019_BASE,
297 .end = RBTX4927_RTL_8019_BASE + 0x20 - 1,
298 .flags = IORESOURCE_IO,
299 }, {
300 .start = RBTX4927_RTL_8019_IRQ,
301 .flags = IORESOURCE_IRQ,
302 }
303 };
Atsushi Nemotobb72f1f2008-07-24 00:25:21 +0900304 platform_device_register_simple("ne", -1, res, ARRAY_SIZE(res));
Atsushi Nemoto57e386c2007-05-01 00:27:58 +0900305}
Atsushi Nemoto2064ba22007-11-24 01:20:27 +0900306
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900307static void __init rbtx4927_device_init(void)
Atsushi Nemoto2064ba22007-11-24 01:20:27 +0900308{
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900309 toshiba_rbtx4927_rtc_init();
310 rbtx4927_ne_init();
Atsushi Nemoto68314722008-07-24 00:25:18 +0900311 tx4927_wdt_init();
Atsushi Nemoto2064ba22007-11-24 01:20:27 +0900312}
Atsushi Nemoto2064ba22007-11-24 01:20:27 +0900313
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900314struct txx9_board_vec rbtx4927_vec __initdata = {
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900315 .system = "Toshiba RBTX4927",
316 .prom_init = rbtx4927_prom_init,
317 .mem_setup = rbtx4927_mem_setup,
318 .irq_setup = rbtx4927_irq_setup,
319 .time_init = rbtx4927_time_init,
320 .device_init = rbtx4927_device_init,
321 .arch_init = rbtx4927_arch_init,
322#ifdef CONFIG_PCI
323 .pci_map_irq = rbtx4927_pci_map_irq,
324#endif
325};
326struct txx9_board_vec rbtx4937_vec __initdata = {
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900327 .system = "Toshiba RBTX4937",
328 .prom_init = rbtx4927_prom_init,
329 .mem_setup = rbtx4927_mem_setup,
330 .irq_setup = rbtx4927_irq_setup,
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900331 .time_init = rbtx4927_time_init,
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900332 .device_init = rbtx4927_device_init,
Yoichi Yuasaa38c4752008-07-13 20:01:04 +0900333 .arch_init = rbtx4937_arch_init,
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900334#ifdef CONFIG_PCI
335 .pci_map_irq = rbtx4927_pci_map_irq,
336#endif
337};