blob: 8306ba333ddaf86d2160080fa7c549bef9602b8d [file] [log] [blame]
Ralf Baechle23fbee92005-07-25 22:45:45 +00001/*
Ralf Baechle23fbee92005-07-25 22:45:45 +00002 * Setup pointers to hardware-dependent routines.
3 * Copyright (C) 2000-2001 Toshiba Corporation
4 *
5 * 2003-2005 (c) MontaVista Software, Inc. This file is licensed under the
6 * terms of the GNU General Public License version 2. This program is
7 * licensed "as is" without any warranty of any kind, whether express
8 * or implied.
9 *
10 * Support for TX4938 in 2.6 - Manish Lachwani (mlachwani@mvista.com)
11 */
Ralf Baechle23fbee92005-07-25 22:45:45 +000012#include <linux/init.h>
13#include <linux/types.h>
14#include <linux/ioport.h>
Ralf Baechle23fbee92005-07-25 22:45:45 +000015#include <linux/delay.h>
16#include <linux/interrupt.h>
17#include <linux/console.h>
Ralf Baechlefcdb27a2006-01-18 17:37:07 +000018#include <linux/pm.h>
Atsushi Nemoto57e386c2007-05-01 00:27:58 +090019#include <linux/platform_device.h>
Atsushi Nemoto4cad1542008-04-05 00:56:09 +090020#include <linux/gpio.h>
Ralf Baechlefcdb27a2006-01-18 17:37:07 +000021
Ralf Baechle23fbee92005-07-25 22:45:45 +000022#include <asm/reboot.h>
Ralf Baechle23fbee92005-07-25 22:45:45 +000023#include <asm/time.h>
Atsushi Nemoto229f7732007-10-25 01:34:09 +090024#include <asm/txx9tmr.h>
Ralf Baechle23fbee92005-07-25 22:45:45 +000025#include <asm/io.h>
26#include <asm/bootinfo.h>
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090027#include <asm/txx9/generic.h>
28#include <asm/txx9/pci.h>
Atsushi Nemoto22b1d702008-07-11 00:31:36 +090029#include <asm/txx9/rbtx4938.h>
Ralf Baechle23fbee92005-07-25 22:45:45 +000030#ifdef CONFIG_SERIAL_TXX9
Ralf Baechle23fbee92005-07-25 22:45:45 +000031#include <linux/serial_core.h>
32#endif
Atsushi Nemotof74cf6f2007-06-22 23:22:06 +090033#include <linux/spi/spi.h>
Atsushi Nemoto22b1d702008-07-11 00:31:36 +090034#include <asm/txx9/spi.h>
Atsushi Nemoto4cad1542008-04-05 00:56:09 +090035#include <asm/txx9pio.h>
Ralf Baechle23fbee92005-07-25 22:45:45 +000036
Ralf Baechle23fbee92005-07-25 22:45:45 +000037extern char * __init prom_getcmdline(void);
Ralf Baechle23fbee92005-07-25 22:45:45 +000038/* These functions are used for rebooting or halting the machine*/
39extern void rbtx4938_machine_restart(char *command);
40extern void rbtx4938_machine_halt(void);
41extern void rbtx4938_machine_power_off(void);
42
Ralf Baechle23fbee92005-07-25 22:45:45 +000043static int tx4938_ccfg_toeon = 1;
44
Ralf Baechle23fbee92005-07-25 22:45:45 +000045void rbtx4938_machine_halt(void)
46{
47 printk(KERN_NOTICE "System Halted\n");
48 local_irq_disable();
49
50 while (1)
51 __asm__(".set\tmips3\n\t"
52 "wait\n\t"
53 ".set\tmips0");
54}
55
56void rbtx4938_machine_power_off(void)
57{
58 rbtx4938_machine_halt();
59 /* no return */
60}
61
62void rbtx4938_machine_restart(char *command)
63{
64 local_irq_disable();
65
66 printk("Rebooting...");
Atsushi Nemoto66140c82008-04-14 21:49:07 +090067 writeb(1, rbtx4938_softresetlock_addr);
68 writeb(1, rbtx4938_sfvol_addr);
69 writeb(1, rbtx4938_softreset_addr);
70 while(1)
71 ;
Ralf Baechle23fbee92005-07-25 22:45:45 +000072}
73
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090074static void __init rbtx4938_pci_setup(void)
Ralf Baechle23fbee92005-07-25 22:45:45 +000075{
Ralf Baechle23fbee92005-07-25 22:45:45 +000076#ifdef CONFIG_PCI
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090077 int extarb = !(__raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCIARB);
78 struct pci_controller *c = &txx9_primary_pcic;
Ralf Baechle23fbee92005-07-25 22:45:45 +000079
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090080 register_pci_controller(c);
Ralf Baechle23fbee92005-07-25 22:45:45 +000081
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090082 if (__raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCI66)
83 txx9_pci_option =
84 (txx9_pci_option & ~TXX9_PCI_OPT_CLK_MASK) |
85 TXX9_PCI_OPT_CLK_66; /* already configured */
Ralf Baechle23fbee92005-07-25 22:45:45 +000086
87 /* Reset PCI Bus */
Atsushi Nemoto66140c82008-04-14 21:49:07 +090088 writeb(0, rbtx4938_pcireset_addr);
Ralf Baechle23fbee92005-07-25 22:45:45 +000089 /* Reset PCIC */
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090090 txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
91 if ((txx9_pci_option & TXX9_PCI_OPT_CLK_MASK) ==
92 TXX9_PCI_OPT_CLK_66)
Ralf Baechle23fbee92005-07-25 22:45:45 +000093 tx4938_pciclk66_setup();
94 mdelay(10);
95 /* clear PCIC reset */
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090096 txx9_clear64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
Atsushi Nemoto66140c82008-04-14 21:49:07 +090097 writeb(1, rbtx4938_pcireset_addr);
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090098 iob();
Ralf Baechle23fbee92005-07-25 22:45:45 +000099
100 tx4938_report_pciclk();
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900101 tx4927_pcic_setup(tx4938_pcicptr, c, extarb);
102 if ((txx9_pci_option & TXX9_PCI_OPT_CLK_MASK) ==
103 TXX9_PCI_OPT_CLK_AUTO &&
104 txx9_pci66_check(c, 0, 0)) {
Ralf Baechle23fbee92005-07-25 22:45:45 +0000105 /* Reset PCI Bus */
Atsushi Nemoto66140c82008-04-14 21:49:07 +0900106 writeb(0, rbtx4938_pcireset_addr);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000107 /* Reset PCIC */
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900108 txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000109 tx4938_pciclk66_setup();
110 mdelay(10);
111 /* clear PCIC reset */
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900112 txx9_clear64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
Atsushi Nemoto66140c82008-04-14 21:49:07 +0900113 writeb(1, rbtx4938_pcireset_addr);
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900114 iob();
Ralf Baechle23fbee92005-07-25 22:45:45 +0000115 /* Reinitialize PCIC */
116 tx4938_report_pciclk();
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900117 tx4927_pcic_setup(tx4938_pcicptr, c, extarb);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000118 }
119
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900120 if (__raw_readq(&tx4938_ccfgptr->pcfg) &
121 (TX4938_PCFG_ETH0_SEL|TX4938_PCFG_ETH1_SEL)) {
122 /* Reset PCIC1 */
123 txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIC1RST);
124 /* PCI1DMD==0 => PCI1CLK==GBUSCLK/2 => PCI66 */
125 if (!(__raw_readq(&tx4938_ccfgptr->ccfg)
126 & TX4938_CCFG_PCI1DMD))
127 tx4938_ccfg_set(TX4938_CCFG_PCI1_66);
128 mdelay(10);
129 /* clear PCIC1 reset */
130 txx9_clear64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIC1RST);
131 tx4938_report_pci1clk();
Ralf Baechle23fbee92005-07-25 22:45:45 +0000132
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900133 /* mem:64K(max), io:64K(max) (enough for ETH0,ETH1) */
134 c = txx9_alloc_pci_controller(NULL, 0, 0x10000, 0, 0x10000);
135 register_pci_controller(c);
136 tx4927_pcic_setup(tx4938_pcic1ptr, c, 0);
137 }
Ralf Baechle23fbee92005-07-25 22:45:45 +0000138#endif /* CONFIG_PCI */
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900139}
Ralf Baechle23fbee92005-07-25 22:45:45 +0000140
141/* SPI support */
142
143/* chip select for SPI devices */
144#define SEEPROM1_CS 7 /* PIO7 */
145#define SEEPROM2_CS 0 /* IOC */
146#define SEEPROM3_CS 1 /* IOC */
147#define SRTC_CS 2 /* IOC */
148
Atsushi Nemotof74cf6f2007-06-22 23:22:06 +0900149static int __init rbtx4938_ethaddr_init(void)
Ralf Baechle23fbee92005-07-25 22:45:45 +0000150{
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900151#ifdef CONFIG_PCI
Atsushi Nemoto2db30152007-07-02 22:43:06 +0900152 unsigned char dat[17];
Atsushi Nemotof74cf6f2007-06-22 23:22:06 +0900153 unsigned char sum;
154 int i;
155
156 /* 0-3: "MAC\0", 4-9:eth0, 10-15:eth1, 16:sum */
Atsushi Nemoto2db30152007-07-02 22:43:06 +0900157 if (spi_eeprom_read(SEEPROM1_CS, 0, dat, sizeof(dat))) {
Atsushi Nemotof74cf6f2007-06-22 23:22:06 +0900158 printk(KERN_ERR "seeprom: read error.\n");
Atsushi Nemoto2db30152007-07-02 22:43:06 +0900159 return -ENODEV;
160 } else {
Atsushi Nemotof74cf6f2007-06-22 23:22:06 +0900161 if (strcmp(dat, "MAC") != 0)
162 printk(KERN_WARNING "seeprom: bad signature.\n");
163 for (i = 0, sum = 0; i < sizeof(dat); i++)
164 sum += dat[i];
165 if (sum)
166 printk(KERN_WARNING "seeprom: bad checksum.\n");
Ralf Baechle23fbee92005-07-25 22:45:45 +0000167 }
Atsushi Nemoto2db30152007-07-02 22:43:06 +0900168 for (i = 0; i < 2; i++) {
Atsushi Nemoto06675e62008-01-19 01:15:52 +0900169 unsigned int id =
170 TXX9_IRQ_BASE + (i ? TX4938_IR_ETH1 : TX4938_IR_ETH0);
Atsushi Nemoto2db30152007-07-02 22:43:06 +0900171 struct platform_device *pdev;
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900172 if (!(__raw_readq(&tx4938_ccfgptr->pcfg) &
Atsushi Nemoto2db30152007-07-02 22:43:06 +0900173 (i ? TX4938_PCFG_ETH1_SEL : TX4938_PCFG_ETH0_SEL)))
174 continue;
175 pdev = platform_device_alloc("tc35815-mac", id);
176 if (!pdev ||
177 platform_device_add_data(pdev, &dat[4 + 6 * i], 6) ||
178 platform_device_add(pdev))
179 platform_device_put(pdev);
180 }
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900181#endif /* CONFIG_PCI */
Ralf Baechle23fbee92005-07-25 22:45:45 +0000182 return 0;
183}
Ralf Baechle23fbee92005-07-25 22:45:45 +0000184
Ralf Baechle23fbee92005-07-25 22:45:45 +0000185static void __init rbtx4938_spi_setup(void)
186{
187 /* set SPI_SEL */
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900188 txx9_set64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_SPI_SEL);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000189}
190
191static struct resource rbtx4938_fpga_resource;
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900192static struct resource tx4938_sdram_resource[4];
193static struct resource tx4938_sram_resource;
Ralf Baechle23fbee92005-07-25 22:45:45 +0000194
195void __init tx4938_board_setup(void)
196{
197 int i;
198 unsigned long divmode;
199 int cpuclk = 0;
200 unsigned long pcode = TX4938_REV_PCODE();
201
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900202 ioport_resource.start = 0;
Ralf Baechle23fbee92005-07-25 22:45:45 +0000203 ioport_resource.end = 0xffffffff;
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900204 iomem_resource.start = 0;
Ralf Baechle23fbee92005-07-25 22:45:45 +0000205 iomem_resource.end = 0xffffffff; /* expand to 4GB */
206
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900207 txx9_reg_res_init(pcode, TX4938_REG_BASE,
208 TX4938_REG_SIZE);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000209 /* SDRAMC,EBUSC are configured by PROM */
210 for (i = 0; i < 8; i++) {
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900211 if (!(TX4938_EBUSC_CR(i) & 0x8))
Ralf Baechle23fbee92005-07-25 22:45:45 +0000212 continue; /* disabled */
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900213 txx9_ce_res[i].start = (unsigned long)TX4938_EBUSC_BA(i);
214 txx9_ce_res[i].end =
215 txx9_ce_res[i].start + TX4938_EBUSC_SIZE(i) - 1;
216 request_resource(&iomem_resource, &txx9_ce_res[i]);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000217 }
218
219 /* clocks */
220 if (txx9_master_clock) {
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900221 u64 ccfg = ____raw_readq(&tx4938_ccfgptr->ccfg);
Ralf Baechle348c9132007-07-28 11:46:15 +0100222 /* calculate gbus_clock and cpu_clock_freq from master_clock */
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900223 divmode = (__u32)ccfg & TX4938_CCFG_DIVMODE_MASK;
Ralf Baechle23fbee92005-07-25 22:45:45 +0000224 switch (divmode) {
225 case TX4938_CCFG_DIVMODE_8:
226 case TX4938_CCFG_DIVMODE_10:
227 case TX4938_CCFG_DIVMODE_12:
228 case TX4938_CCFG_DIVMODE_16:
229 case TX4938_CCFG_DIVMODE_18:
230 txx9_gbus_clock = txx9_master_clock * 4; break;
231 default:
232 txx9_gbus_clock = txx9_master_clock;
233 }
234 switch (divmode) {
235 case TX4938_CCFG_DIVMODE_2:
236 case TX4938_CCFG_DIVMODE_8:
237 cpuclk = txx9_gbus_clock * 2; break;
238 case TX4938_CCFG_DIVMODE_2_5:
239 case TX4938_CCFG_DIVMODE_10:
240 cpuclk = txx9_gbus_clock * 5 / 2; break;
241 case TX4938_CCFG_DIVMODE_3:
242 case TX4938_CCFG_DIVMODE_12:
243 cpuclk = txx9_gbus_clock * 3; break;
244 case TX4938_CCFG_DIVMODE_4:
245 case TX4938_CCFG_DIVMODE_16:
246 cpuclk = txx9_gbus_clock * 4; break;
247 case TX4938_CCFG_DIVMODE_4_5:
248 case TX4938_CCFG_DIVMODE_18:
249 cpuclk = txx9_gbus_clock * 9 / 2; break;
250 }
251 txx9_cpu_clock = cpuclk;
252 } else {
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900253 u64 ccfg = ____raw_readq(&tx4938_ccfgptr->ccfg);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000254 if (txx9_cpu_clock == 0) {
255 txx9_cpu_clock = 300000000; /* 300MHz */
256 }
Ralf Baechle348c9132007-07-28 11:46:15 +0100257 /* calculate gbus_clock and master_clock from cpu_clock_freq */
Ralf Baechle23fbee92005-07-25 22:45:45 +0000258 cpuclk = txx9_cpu_clock;
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900259 divmode = (__u32)ccfg & TX4938_CCFG_DIVMODE_MASK;
Ralf Baechle23fbee92005-07-25 22:45:45 +0000260 switch (divmode) {
261 case TX4938_CCFG_DIVMODE_2:
262 case TX4938_CCFG_DIVMODE_8:
263 txx9_gbus_clock = cpuclk / 2; break;
264 case TX4938_CCFG_DIVMODE_2_5:
265 case TX4938_CCFG_DIVMODE_10:
266 txx9_gbus_clock = cpuclk * 2 / 5; break;
267 case TX4938_CCFG_DIVMODE_3:
268 case TX4938_CCFG_DIVMODE_12:
269 txx9_gbus_clock = cpuclk / 3; break;
270 case TX4938_CCFG_DIVMODE_4:
271 case TX4938_CCFG_DIVMODE_16:
272 txx9_gbus_clock = cpuclk / 4; break;
273 case TX4938_CCFG_DIVMODE_4_5:
274 case TX4938_CCFG_DIVMODE_18:
275 txx9_gbus_clock = cpuclk * 2 / 9; break;
276 }
277 switch (divmode) {
278 case TX4938_CCFG_DIVMODE_8:
279 case TX4938_CCFG_DIVMODE_10:
280 case TX4938_CCFG_DIVMODE_12:
281 case TX4938_CCFG_DIVMODE_16:
282 case TX4938_CCFG_DIVMODE_18:
283 txx9_master_clock = txx9_gbus_clock / 4; break;
284 default:
285 txx9_master_clock = txx9_gbus_clock;
286 }
287 }
288 /* change default value to udelay/mdelay take reasonable time */
289 loops_per_jiffy = txx9_cpu_clock / HZ / 2;
290
291 /* CCFG */
292 /* clear WatchDogReset,BusErrorOnWrite flag (W1C) */
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900293 tx4938_ccfg_set(TX4938_CCFG_WDRST | TX4938_CCFG_BEOW);
Atsushi Nemoto2064ba22007-11-24 01:20:27 +0900294 /* do reset on watchdog */
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900295 tx4938_ccfg_set(TX4938_CCFG_WR);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000296 /* clear PCIC1 reset */
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900297 txx9_clear64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIC1RST);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000298
299 /* enable Timeout BusError */
300 if (tx4938_ccfg_toeon)
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900301 tx4938_ccfg_set(TX4938_CCFG_TOE);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000302
303 /* DMA selection */
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900304 txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_DMASEL_ALL);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000305
306 /* Use external clock for external arbiter */
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900307 if (!(____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCIARB))
308 txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_PCICLKEN_ALL);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000309
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900310 printk(KERN_INFO "%s -- %dMHz(M%dMHz) CRIR:%08x CCFG:%llx PCFG:%llx\n",
311 txx9_pcode_str,
312 (cpuclk + 500000) / 1000000,
313 (txx9_master_clock + 500000) / 1000000,
314 (__u32)____raw_readq(&tx4938_ccfgptr->crir),
315 (unsigned long long)____raw_readq(&tx4938_ccfgptr->ccfg),
316 (unsigned long long)____raw_readq(&tx4938_ccfgptr->pcfg));
Ralf Baechle23fbee92005-07-25 22:45:45 +0000317
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900318 printk(KERN_INFO "%s SDRAMC --", txx9_pcode_str);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000319 for (i = 0; i < 4; i++) {
320 unsigned long long cr = tx4938_sdramcptr->cr[i];
321 unsigned long ram_base, ram_size;
322 if (!((unsigned long)cr & 0x00000400))
323 continue; /* disabled */
324 ram_base = (unsigned long)(cr >> 49) << 21;
325 ram_size = ((unsigned long)(cr >> 33) + 1) << 21;
326 if (ram_base >= 0x20000000)
327 continue; /* high memory (ignore) */
328 printk(" CR%d:%016Lx", i, cr);
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900329 tx4938_sdram_resource[i].name = "SDRAM";
330 tx4938_sdram_resource[i].start = ram_base;
331 tx4938_sdram_resource[i].end = ram_base + ram_size - 1;
332 tx4938_sdram_resource[i].flags = IORESOURCE_MEM;
333 request_resource(&iomem_resource, &tx4938_sdram_resource[i]);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000334 }
335 printk(" TR:%09Lx\n", tx4938_sdramcptr->tr);
336
337 /* SRAM */
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900338 if (tx4938_sramcptr->cr & 1) {
Ralf Baechle23fbee92005-07-25 22:45:45 +0000339 unsigned int size = 0x800;
340 unsigned long base =
341 (tx4938_sramcptr->cr >> (39-11)) & ~(size - 1);
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900342 tx4938_sram_resource.name = "SRAM";
343 tx4938_sram_resource.start = base;
344 tx4938_sram_resource.end = base + size - 1;
345 tx4938_sram_resource.flags = IORESOURCE_MEM;
346 request_resource(&iomem_resource, &tx4938_sram_resource);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000347 }
348
Ralf Baechle23fbee92005-07-25 22:45:45 +0000349 /* TMR */
Atsushi Nemoto229f7732007-10-25 01:34:09 +0900350 for (i = 0; i < TX4938_NR_TMR; i++)
351 txx9_tmr_init(TX4938_TMR_REG(i) & 0xfffffffffULL);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000352
353 /* enable DMA */
Atsushi Nemoto66140c82008-04-14 21:49:07 +0900354 for (i = 0; i < 2; i++)
355 ____raw_writeq(TX4938_DMA_MCR_MSTEN,
356 (void __iomem *)(TX4938_DMA_REG(i) + 0x50));
Ralf Baechle23fbee92005-07-25 22:45:45 +0000357
358 /* PIO */
Atsushi Nemoto4cad1542008-04-05 00:56:09 +0900359 __raw_writel(0, &tx4938_pioptr->maskcpu);
360 __raw_writel(0, &tx4938_pioptr->maskext);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000361
Ralf Baechle23fbee92005-07-25 22:45:45 +0000362#ifdef CONFIG_PCI
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900363 txx9_alloc_pci_controller(&txx9_primary_pcic, 0, 0, 0, 0);
364#endif
Ralf Baechle23fbee92005-07-25 22:45:45 +0000365}
366
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900367static void __init rbtx4938_time_init(void)
Ralf Baechle23fbee92005-07-25 22:45:45 +0000368{
Ralf Baechle23fbee92005-07-25 22:45:45 +0000369 mips_hpt_frequency = txx9_cpu_clock / 2;
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900370 if (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_TINTDIS)
Atsushi Nemoto229f7732007-10-25 01:34:09 +0900371 txx9_clockevent_init(TX4938_TMR_REG(0) & 0xfffffffffULL,
372 TXX9_IRQ_BASE + TX4938_IR_TMR(0),
373 txx9_gbus_clock / 2);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000374}
375
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900376static void __init rbtx4938_mem_setup(void)
Ralf Baechle23fbee92005-07-25 22:45:45 +0000377{
378 unsigned long long pcfg;
379 char *argptr;
380
381 iomem_resource.end = 0xffffffff; /* 4GB */
382
383 if (txx9_master_clock == 0)
384 txx9_master_clock = 25000000; /* 25MHz */
385 tx4938_board_setup();
Ralf Baechle23fbee92005-07-25 22:45:45 +0000386#ifndef CONFIG_PCI
387 set_io_port_base(RBTX4938_ETHER_BASE);
388#endif
389
390#ifdef CONFIG_SERIAL_TXX9
391 {
392 extern int early_serial_txx9_setup(struct uart_port *port);
393 int i;
394 struct uart_port req;
395 for(i = 0; i < 2; i++) {
396 memset(&req, 0, sizeof(req));
397 req.line = i;
398 req.iotype = UPIO_MEM;
399 req.membase = (char *)(0xff1ff300 + i * 0x100);
400 req.mapbase = 0xff1ff300 + i * 0x100;
Atsushi Nemotoc87abd72007-08-02 23:36:02 +0900401 req.irq = RBTX4938_IRQ_IRC_SIO(i);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000402 req.flags |= UPF_BUGGY_UART /*HAVE_CTS_LINE*/;
403 req.uartclk = 50000000;
404 early_serial_txx9_setup(&req);
405 }
406 }
407#ifdef CONFIG_SERIAL_TXX9_CONSOLE
408 argptr = prom_getcmdline();
409 if (strstr(argptr, "console=") == NULL) {
410 strcat(argptr, " console=ttyS0,38400");
411 }
412#endif
413#endif
414
415#ifdef CONFIG_TOSHIBA_RBTX4938_MPLEX_PIO58_61
416 printk("PIOSEL: disabling both ata and nand selection\n");
417 local_irq_disable();
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900418 txx9_clear64(&tx4938_ccfgptr->pcfg,
419 TX4938_PCFG_NDF_SEL | TX4938_PCFG_ATA_SEL);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000420#endif
421
422#ifdef CONFIG_TOSHIBA_RBTX4938_MPLEX_NAND
423 printk("PIOSEL: enabling nand selection\n");
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900424 txx9_set64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_NDF_SEL);
425 txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_ATA_SEL);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000426#endif
427
428#ifdef CONFIG_TOSHIBA_RBTX4938_MPLEX_ATA
429 printk("PIOSEL: enabling ata selection\n");
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900430 txx9_set64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_ATA_SEL);
431 txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_NDF_SEL);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000432#endif
433
434#ifdef CONFIG_IP_PNP
435 argptr = prom_getcmdline();
436 if (strstr(argptr, "ip=") == NULL) {
437 strcat(argptr, " ip=any");
438 }
439#endif
440
441
442#ifdef CONFIG_FB
443 {
444 conswitchp = &dummy_con;
445 }
446#endif
447
448 rbtx4938_spi_setup();
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900449 pcfg = ____raw_readq(&tx4938_ccfgptr->pcfg); /* updated */
Ralf Baechle23fbee92005-07-25 22:45:45 +0000450 /* fixup piosel */
451 if ((pcfg & (TX4938_PCFG_ATA_SEL | TX4938_PCFG_NDF_SEL)) ==
Atsushi Nemoto66140c82008-04-14 21:49:07 +0900452 TX4938_PCFG_ATA_SEL)
453 writeb((readb(rbtx4938_piosel_addr) & 0x03) | 0x04,
454 rbtx4938_piosel_addr);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000455 else if ((pcfg & (TX4938_PCFG_ATA_SEL | TX4938_PCFG_NDF_SEL)) ==
Atsushi Nemoto66140c82008-04-14 21:49:07 +0900456 TX4938_PCFG_NDF_SEL)
457 writeb((readb(rbtx4938_piosel_addr) & 0x03) | 0x08,
458 rbtx4938_piosel_addr);
459 else
460 writeb(readb(rbtx4938_piosel_addr) & ~(0x08 | 0x04),
461 rbtx4938_piosel_addr);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000462
463 rbtx4938_fpga_resource.name = "FPGA Registers";
464 rbtx4938_fpga_resource.start = CPHYSADDR(RBTX4938_FPGA_REG_ADDR);
465 rbtx4938_fpga_resource.end = CPHYSADDR(RBTX4938_FPGA_REG_ADDR) + 0xffff;
466 rbtx4938_fpga_resource.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
467 if (request_resource(&iomem_resource, &rbtx4938_fpga_resource))
468 printk("request resource for fpga failed\n");
469
Ralf Baechle23fbee92005-07-25 22:45:45 +0000470 _machine_restart = rbtx4938_machine_restart;
471 _machine_halt = rbtx4938_machine_halt;
Ralf Baechlefcdb27a2006-01-18 17:37:07 +0000472 pm_power_off = rbtx4938_machine_power_off;
Ralf Baechle23fbee92005-07-25 22:45:45 +0000473
Atsushi Nemoto66140c82008-04-14 21:49:07 +0900474 writeb(0xff, rbtx4938_led_addr);
475 printk(KERN_INFO "RBTX4938 --- FPGA(Rev %02x) DIPSW:%02x,%02x\n",
476 readb(rbtx4938_fpga_rev_addr),
477 readb(rbtx4938_dipsw_addr), readb(rbtx4938_bdipsw_addr));
Ralf Baechle23fbee92005-07-25 22:45:45 +0000478}
479
Atsushi Nemoto57e386c2007-05-01 00:27:58 +0900480static int __init rbtx4938_ne_init(void)
481{
482 struct resource res[] = {
483 {
484 .start = RBTX4938_RTL_8019_BASE,
485 .end = RBTX4938_RTL_8019_BASE + 0x20 - 1,
486 .flags = IORESOURCE_IO,
487 }, {
488 .start = RBTX4938_RTL_8019_IRQ,
489 .flags = IORESOURCE_IRQ,
490 }
491 };
492 struct platform_device *dev =
493 platform_device_register_simple("ne", -1,
494 res, ARRAY_SIZE(res));
495 return IS_ERR(dev) ? PTR_ERR(dev) : 0;
496}
Atsushi Nemoto3896b052007-06-22 23:21:55 +0900497
498/* GPIO support */
499
Atsushi Nemoto4cad1542008-04-05 00:56:09 +0900500int gpio_to_irq(unsigned gpio)
501{
502 return -EINVAL;
503}
504
505int irq_to_gpio(unsigned irq)
506{
507 return -EINVAL;
508}
509
Atsushi Nemoto3896b052007-06-22 23:21:55 +0900510static DEFINE_SPINLOCK(rbtx4938_spi_gpio_lock);
511
Atsushi Nemoto4cad1542008-04-05 00:56:09 +0900512static void rbtx4938_spi_gpio_set(struct gpio_chip *chip, unsigned int offset,
513 int value)
Atsushi Nemoto3896b052007-06-22 23:21:55 +0900514{
515 u8 val;
516 unsigned long flags;
Atsushi Nemoto3896b052007-06-22 23:21:55 +0900517 spin_lock_irqsave(&rbtx4938_spi_gpio_lock, flags);
Atsushi Nemoto66140c82008-04-14 21:49:07 +0900518 val = readb(rbtx4938_spics_addr);
Atsushi Nemoto3896b052007-06-22 23:21:55 +0900519 if (value)
Atsushi Nemoto4cad1542008-04-05 00:56:09 +0900520 val |= 1 << offset;
Atsushi Nemoto3896b052007-06-22 23:21:55 +0900521 else
Atsushi Nemoto4cad1542008-04-05 00:56:09 +0900522 val &= ~(1 << offset);
Atsushi Nemoto66140c82008-04-14 21:49:07 +0900523 writeb(val, rbtx4938_spics_addr);
Atsushi Nemoto3896b052007-06-22 23:21:55 +0900524 mmiowb();
525 spin_unlock_irqrestore(&rbtx4938_spi_gpio_lock, flags);
526}
527
Atsushi Nemoto4cad1542008-04-05 00:56:09 +0900528static int rbtx4938_spi_gpio_dir_out(struct gpio_chip *chip,
529 unsigned int offset, int value)
Atsushi Nemoto3896b052007-06-22 23:21:55 +0900530{
Atsushi Nemoto4cad1542008-04-05 00:56:09 +0900531 rbtx4938_spi_gpio_set(chip, offset, value);
Atsushi Nemoto3896b052007-06-22 23:21:55 +0900532 return 0;
533}
534
Atsushi Nemoto4cad1542008-04-05 00:56:09 +0900535static struct gpio_chip rbtx4938_spi_gpio_chip = {
536 .set = rbtx4938_spi_gpio_set,
537 .direction_output = rbtx4938_spi_gpio_dir_out,
538 .label = "RBTX4938-SPICS",
539 .base = 16,
540 .ngpio = 3,
541};
Atsushi Nemotof74cf6f2007-06-22 23:22:06 +0900542
543/* SPI support */
544
545static void __init txx9_spi_init(unsigned long base, int irq)
546{
547 struct resource res[] = {
548 {
549 .start = base,
550 .end = base + 0x20 - 1,
551 .flags = IORESOURCE_MEM,
Atsushi Nemotof74cf6f2007-06-22 23:22:06 +0900552 }, {
553 .start = irq,
554 .flags = IORESOURCE_IRQ,
555 },
556 };
Atsushi Nemoto4ccdb4c2007-08-30 23:56:25 -0700557 platform_device_register_simple("spi_txx9", 0,
Atsushi Nemotof74cf6f2007-06-22 23:22:06 +0900558 res, ARRAY_SIZE(res));
559}
560
561static int __init rbtx4938_spi_init(void)
562{
563 struct spi_board_info srtc_info = {
Atsushi Nemoto9f90a032007-08-19 22:32:10 +0900564 .modalias = "rtc-rs5c348",
Atsushi Nemotof74cf6f2007-06-22 23:22:06 +0900565 .max_speed_hz = 1000000, /* 1.0Mbps @ Vdd 2.0V */
566 .bus_num = 0,
567 .chip_select = 16 + SRTC_CS,
568 /* Mode 1 (High-Active, Shift-Then-Sample), High Avtive CS */
569 .mode = SPI_MODE_1 | SPI_CS_HIGH,
570 };
571 spi_register_board_info(&srtc_info, 1);
572 spi_eeprom_register(SEEPROM1_CS);
573 spi_eeprom_register(16 + SEEPROM2_CS);
574 spi_eeprom_register(16 + SEEPROM3_CS);
Atsushi Nemoto4cad1542008-04-05 00:56:09 +0900575 gpio_request(16 + SRTC_CS, "rtc-rs5c348");
576 gpio_direction_output(16 + SRTC_CS, 0);
577 gpio_request(SEEPROM1_CS, "seeprom1");
578 gpio_direction_output(SEEPROM1_CS, 1);
579 gpio_request(16 + SEEPROM2_CS, "seeprom2");
580 gpio_direction_output(16 + SEEPROM2_CS, 1);
581 gpio_request(16 + SEEPROM3_CS, "seeprom3");
582 gpio_direction_output(16 + SEEPROM3_CS, 1);
Atsushi Nemotof74cf6f2007-06-22 23:22:06 +0900583 txx9_spi_init(TX4938_SPI_REG & 0xfffffffffULL, RBTX4938_IRQ_IRC_SPI);
584 return 0;
585}
Atsushi Nemoto4cad1542008-04-05 00:56:09 +0900586
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900587static void __init rbtx4938_arch_init(void)
Atsushi Nemoto4cad1542008-04-05 00:56:09 +0900588{
589 txx9_gpio_init(TX4938_PIO_REG & 0xfffffffffULL, 0, 16);
590 gpiochip_add(&rbtx4938_spi_gpio_chip);
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900591 rbtx4938_pci_setup();
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900592 rbtx4938_spi_init();
Atsushi Nemoto4cad1542008-04-05 00:56:09 +0900593}
Atsushi Nemotof74cf6f2007-06-22 23:22:06 +0900594
Atsushi Nemoto2064ba22007-11-24 01:20:27 +0900595/* Watchdog support */
596
597static int __init txx9_wdt_init(unsigned long base)
598{
599 struct resource res = {
600 .start = base,
601 .end = base + 0x100 - 1,
602 .flags = IORESOURCE_MEM,
Atsushi Nemoto2064ba22007-11-24 01:20:27 +0900603 };
604 struct platform_device *dev =
605 platform_device_register_simple("txx9wdt", -1, &res, 1);
606 return IS_ERR(dev) ? PTR_ERR(dev) : 0;
607}
608
609static int __init rbtx4938_wdt_init(void)
610{
611 return txx9_wdt_init(TX4938_TMR_REG(2) & 0xfffffffffULL);
612}
Atsushi Nemoto2064ba22007-11-24 01:20:27 +0900613
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900614static void __init rbtx4938_device_init(void)
Atsushi Nemotof74cf6f2007-06-22 23:22:06 +0900615{
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900616 rbtx4938_ethaddr_init();
617 rbtx4938_ne_init();
618 rbtx4938_wdt_init();
Atsushi Nemotof74cf6f2007-06-22 23:22:06 +0900619}
Atsushi Nemotof74cf6f2007-06-22 23:22:06 +0900620
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900621struct txx9_board_vec rbtx4938_vec __initdata = {
622 .type = MACH_TOSHIBA_RBTX4938,
623 .system = "Toshiba RBTX4938",
624 .prom_init = rbtx4938_prom_init,
625 .mem_setup = rbtx4938_mem_setup,
626 .irq_setup = rbtx4938_irq_setup,
627 .time_init = rbtx4938_time_init,
628 .device_init = rbtx4938_device_init,
629 .arch_init = rbtx4938_arch_init,
630#ifdef CONFIG_PCI
631 .pci_map_irq = rbtx4938_pci_map_irq,
632#endif
633};