blob: 144d2cada8205695ea96a9767278eac010cf2dec [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 Nemotof74cf6f2007-06-22 23:22:06 +090020#include <linux/clk.h>
Atsushi Nemoto4cad1542008-04-05 00:56:09 +090021#include <linux/gpio.h>
Ralf Baechlefcdb27a2006-01-18 17:37:07 +000022
Ralf Baechle23fbee92005-07-25 22:45:45 +000023#include <asm/reboot.h>
Ralf Baechle23fbee92005-07-25 22:45:45 +000024#include <asm/time.h>
Atsushi Nemoto229f7732007-10-25 01:34:09 +090025#include <asm/txx9tmr.h>
Ralf Baechle23fbee92005-07-25 22:45:45 +000026#include <asm/io.h>
27#include <asm/bootinfo.h>
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090028#include <asm/txx9/generic.h>
29#include <asm/txx9/pci.h>
Atsushi Nemoto22b1d702008-07-11 00:31:36 +090030#include <asm/txx9/rbtx4938.h>
Ralf Baechle23fbee92005-07-25 22:45:45 +000031#ifdef CONFIG_SERIAL_TXX9
Ralf Baechle23fbee92005-07-25 22:45:45 +000032#include <linux/serial_core.h>
33#endif
Atsushi Nemotof74cf6f2007-06-22 23:22:06 +090034#include <linux/spi/spi.h>
Atsushi Nemoto22b1d702008-07-11 00:31:36 +090035#include <asm/txx9/spi.h>
Atsushi Nemoto4cad1542008-04-05 00:56:09 +090036#include <asm/txx9pio.h>
Ralf Baechle23fbee92005-07-25 22:45:45 +000037
Ralf Baechle23fbee92005-07-25 22:45:45 +000038extern char * __init prom_getcmdline(void);
Ralf Baechle23fbee92005-07-25 22:45:45 +000039/* These functions are used for rebooting or halting the machine*/
40extern void rbtx4938_machine_restart(char *command);
41extern void rbtx4938_machine_halt(void);
42extern void rbtx4938_machine_power_off(void);
43
Ralf Baechle23fbee92005-07-25 22:45:45 +000044static int tx4938_ccfg_toeon = 1;
45
Ralf Baechle23fbee92005-07-25 22:45:45 +000046void rbtx4938_machine_halt(void)
47{
48 printk(KERN_NOTICE "System Halted\n");
49 local_irq_disable();
50
51 while (1)
52 __asm__(".set\tmips3\n\t"
53 "wait\n\t"
54 ".set\tmips0");
55}
56
57void rbtx4938_machine_power_off(void)
58{
59 rbtx4938_machine_halt();
60 /* no return */
61}
62
63void rbtx4938_machine_restart(char *command)
64{
65 local_irq_disable();
66
67 printk("Rebooting...");
Atsushi Nemoto66140c82008-04-14 21:49:07 +090068 writeb(1, rbtx4938_softresetlock_addr);
69 writeb(1, rbtx4938_sfvol_addr);
70 writeb(1, rbtx4938_softreset_addr);
71 while(1)
72 ;
Ralf Baechle23fbee92005-07-25 22:45:45 +000073}
74
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090075static void __init rbtx4938_pci_setup(void)
Ralf Baechle23fbee92005-07-25 22:45:45 +000076{
Ralf Baechle23fbee92005-07-25 22:45:45 +000077#ifdef CONFIG_PCI
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090078 int extarb = !(__raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCIARB);
79 struct pci_controller *c = &txx9_primary_pcic;
Ralf Baechle23fbee92005-07-25 22:45:45 +000080
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090081 register_pci_controller(c);
Ralf Baechle23fbee92005-07-25 22:45:45 +000082
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090083 if (__raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCI66)
84 txx9_pci_option =
85 (txx9_pci_option & ~TXX9_PCI_OPT_CLK_MASK) |
86 TXX9_PCI_OPT_CLK_66; /* already configured */
Ralf Baechle23fbee92005-07-25 22:45:45 +000087
88 /* Reset PCI Bus */
Atsushi Nemoto66140c82008-04-14 21:49:07 +090089 writeb(0, rbtx4938_pcireset_addr);
Ralf Baechle23fbee92005-07-25 22:45:45 +000090 /* Reset PCIC */
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090091 txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
92 if ((txx9_pci_option & TXX9_PCI_OPT_CLK_MASK) ==
93 TXX9_PCI_OPT_CLK_66)
Ralf Baechle23fbee92005-07-25 22:45:45 +000094 tx4938_pciclk66_setup();
95 mdelay(10);
96 /* clear PCIC reset */
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090097 txx9_clear64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
Atsushi Nemoto66140c82008-04-14 21:49:07 +090098 writeb(1, rbtx4938_pcireset_addr);
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090099 iob();
Ralf Baechle23fbee92005-07-25 22:45:45 +0000100
101 tx4938_report_pciclk();
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900102 tx4927_pcic_setup(tx4938_pcicptr, c, extarb);
103 if ((txx9_pci_option & TXX9_PCI_OPT_CLK_MASK) ==
104 TXX9_PCI_OPT_CLK_AUTO &&
105 txx9_pci66_check(c, 0, 0)) {
Ralf Baechle23fbee92005-07-25 22:45:45 +0000106 /* Reset PCI Bus */
Atsushi Nemoto66140c82008-04-14 21:49:07 +0900107 writeb(0, rbtx4938_pcireset_addr);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000108 /* Reset PCIC */
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900109 txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000110 tx4938_pciclk66_setup();
111 mdelay(10);
112 /* clear PCIC reset */
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900113 txx9_clear64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
Atsushi Nemoto66140c82008-04-14 21:49:07 +0900114 writeb(1, rbtx4938_pcireset_addr);
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900115 iob();
Ralf Baechle23fbee92005-07-25 22:45:45 +0000116 /* Reinitialize PCIC */
117 tx4938_report_pciclk();
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900118 tx4927_pcic_setup(tx4938_pcicptr, c, extarb);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000119 }
120
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900121 if (__raw_readq(&tx4938_ccfgptr->pcfg) &
122 (TX4938_PCFG_ETH0_SEL|TX4938_PCFG_ETH1_SEL)) {
123 /* Reset PCIC1 */
124 txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIC1RST);
125 /* PCI1DMD==0 => PCI1CLK==GBUSCLK/2 => PCI66 */
126 if (!(__raw_readq(&tx4938_ccfgptr->ccfg)
127 & TX4938_CCFG_PCI1DMD))
128 tx4938_ccfg_set(TX4938_CCFG_PCI1_66);
129 mdelay(10);
130 /* clear PCIC1 reset */
131 txx9_clear64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIC1RST);
132 tx4938_report_pci1clk();
Ralf Baechle23fbee92005-07-25 22:45:45 +0000133
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900134 /* mem:64K(max), io:64K(max) (enough for ETH0,ETH1) */
135 c = txx9_alloc_pci_controller(NULL, 0, 0x10000, 0, 0x10000);
136 register_pci_controller(c);
137 tx4927_pcic_setup(tx4938_pcic1ptr, c, 0);
138 }
Ralf Baechle23fbee92005-07-25 22:45:45 +0000139#endif /* CONFIG_PCI */
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900140}
Ralf Baechle23fbee92005-07-25 22:45:45 +0000141
142/* SPI support */
143
144/* chip select for SPI devices */
145#define SEEPROM1_CS 7 /* PIO7 */
146#define SEEPROM2_CS 0 /* IOC */
147#define SEEPROM3_CS 1 /* IOC */
148#define SRTC_CS 2 /* IOC */
149
Atsushi Nemotof74cf6f2007-06-22 23:22:06 +0900150#ifdef CONFIG_PCI
Atsushi Nemotof74cf6f2007-06-22 23:22:06 +0900151static int __init rbtx4938_ethaddr_init(void)
Ralf Baechle23fbee92005-07-25 22:45:45 +0000152{
Atsushi Nemoto2db30152007-07-02 22:43:06 +0900153 unsigned char dat[17];
Atsushi Nemotof74cf6f2007-06-22 23:22:06 +0900154 unsigned char sum;
155 int i;
156
157 /* 0-3: "MAC\0", 4-9:eth0, 10-15:eth1, 16:sum */
Atsushi Nemoto2db30152007-07-02 22:43:06 +0900158 if (spi_eeprom_read(SEEPROM1_CS, 0, dat, sizeof(dat))) {
Atsushi Nemotof74cf6f2007-06-22 23:22:06 +0900159 printk(KERN_ERR "seeprom: read error.\n");
Atsushi Nemoto2db30152007-07-02 22:43:06 +0900160 return -ENODEV;
161 } else {
Atsushi Nemotof74cf6f2007-06-22 23:22:06 +0900162 if (strcmp(dat, "MAC") != 0)
163 printk(KERN_WARNING "seeprom: bad signature.\n");
164 for (i = 0, sum = 0; i < sizeof(dat); i++)
165 sum += dat[i];
166 if (sum)
167 printk(KERN_WARNING "seeprom: bad checksum.\n");
Ralf Baechle23fbee92005-07-25 22:45:45 +0000168 }
Atsushi Nemoto2db30152007-07-02 22:43:06 +0900169 for (i = 0; i < 2; i++) {
Atsushi Nemoto06675e62008-01-19 01:15:52 +0900170 unsigned int id =
171 TXX9_IRQ_BASE + (i ? TX4938_IR_ETH1 : TX4938_IR_ETH0);
Atsushi Nemoto2db30152007-07-02 22:43:06 +0900172 struct platform_device *pdev;
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900173 if (!(__raw_readq(&tx4938_ccfgptr->pcfg) &
Atsushi Nemoto2db30152007-07-02 22:43:06 +0900174 (i ? TX4938_PCFG_ETH1_SEL : TX4938_PCFG_ETH0_SEL)))
175 continue;
176 pdev = platform_device_alloc("tc35815-mac", id);
177 if (!pdev ||
178 platform_device_add_data(pdev, &dat[4 + 6 * i], 6) ||
179 platform_device_add(pdev))
180 platform_device_put(pdev);
181 }
Ralf Baechle23fbee92005-07-25 22:45:45 +0000182 return 0;
183}
Atsushi Nemotof74cf6f2007-06-22 23:22:06 +0900184device_initcall(rbtx4938_ethaddr_init);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000185#endif /* CONFIG_PCI */
186
Ralf Baechle23fbee92005-07-25 22:45:45 +0000187static void __init rbtx4938_spi_setup(void)
188{
189 /* set SPI_SEL */
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900190 txx9_set64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_SPI_SEL);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000191}
192
193static struct resource rbtx4938_fpga_resource;
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900194static struct resource tx4938_sdram_resource[4];
195static struct resource tx4938_sram_resource;
Ralf Baechle23fbee92005-07-25 22:45:45 +0000196
197void __init tx4938_board_setup(void)
198{
199 int i;
200 unsigned long divmode;
201 int cpuclk = 0;
202 unsigned long pcode = TX4938_REV_PCODE();
203
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900204 ioport_resource.start = 0;
Ralf Baechle23fbee92005-07-25 22:45:45 +0000205 ioport_resource.end = 0xffffffff;
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900206 iomem_resource.start = 0;
Ralf Baechle23fbee92005-07-25 22:45:45 +0000207 iomem_resource.end = 0xffffffff; /* expand to 4GB */
208
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900209 txx9_reg_res_init(pcode, TX4938_REG_BASE,
210 TX4938_REG_SIZE);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000211 /* SDRAMC,EBUSC are configured by PROM */
212 for (i = 0; i < 8; i++) {
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900213 if (!(TX4938_EBUSC_CR(i) & 0x8))
Ralf Baechle23fbee92005-07-25 22:45:45 +0000214 continue; /* disabled */
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900215 txx9_ce_res[i].start = (unsigned long)TX4938_EBUSC_BA(i);
216 txx9_ce_res[i].end =
217 txx9_ce_res[i].start + TX4938_EBUSC_SIZE(i) - 1;
218 request_resource(&iomem_resource, &txx9_ce_res[i]);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000219 }
220
221 /* clocks */
222 if (txx9_master_clock) {
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900223 u64 ccfg = ____raw_readq(&tx4938_ccfgptr->ccfg);
Ralf Baechle348c9132007-07-28 11:46:15 +0100224 /* calculate gbus_clock and cpu_clock_freq from master_clock */
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900225 divmode = (__u32)ccfg & TX4938_CCFG_DIVMODE_MASK;
Ralf Baechle23fbee92005-07-25 22:45:45 +0000226 switch (divmode) {
227 case TX4938_CCFG_DIVMODE_8:
228 case TX4938_CCFG_DIVMODE_10:
229 case TX4938_CCFG_DIVMODE_12:
230 case TX4938_CCFG_DIVMODE_16:
231 case TX4938_CCFG_DIVMODE_18:
232 txx9_gbus_clock = txx9_master_clock * 4; break;
233 default:
234 txx9_gbus_clock = txx9_master_clock;
235 }
236 switch (divmode) {
237 case TX4938_CCFG_DIVMODE_2:
238 case TX4938_CCFG_DIVMODE_8:
239 cpuclk = txx9_gbus_clock * 2; break;
240 case TX4938_CCFG_DIVMODE_2_5:
241 case TX4938_CCFG_DIVMODE_10:
242 cpuclk = txx9_gbus_clock * 5 / 2; break;
243 case TX4938_CCFG_DIVMODE_3:
244 case TX4938_CCFG_DIVMODE_12:
245 cpuclk = txx9_gbus_clock * 3; break;
246 case TX4938_CCFG_DIVMODE_4:
247 case TX4938_CCFG_DIVMODE_16:
248 cpuclk = txx9_gbus_clock * 4; break;
249 case TX4938_CCFG_DIVMODE_4_5:
250 case TX4938_CCFG_DIVMODE_18:
251 cpuclk = txx9_gbus_clock * 9 / 2; break;
252 }
253 txx9_cpu_clock = cpuclk;
254 } else {
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900255 u64 ccfg = ____raw_readq(&tx4938_ccfgptr->ccfg);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000256 if (txx9_cpu_clock == 0) {
257 txx9_cpu_clock = 300000000; /* 300MHz */
258 }
Ralf Baechle348c9132007-07-28 11:46:15 +0100259 /* calculate gbus_clock and master_clock from cpu_clock_freq */
Ralf Baechle23fbee92005-07-25 22:45:45 +0000260 cpuclk = txx9_cpu_clock;
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900261 divmode = (__u32)ccfg & TX4938_CCFG_DIVMODE_MASK;
Ralf Baechle23fbee92005-07-25 22:45:45 +0000262 switch (divmode) {
263 case TX4938_CCFG_DIVMODE_2:
264 case TX4938_CCFG_DIVMODE_8:
265 txx9_gbus_clock = cpuclk / 2; break;
266 case TX4938_CCFG_DIVMODE_2_5:
267 case TX4938_CCFG_DIVMODE_10:
268 txx9_gbus_clock = cpuclk * 2 / 5; break;
269 case TX4938_CCFG_DIVMODE_3:
270 case TX4938_CCFG_DIVMODE_12:
271 txx9_gbus_clock = cpuclk / 3; break;
272 case TX4938_CCFG_DIVMODE_4:
273 case TX4938_CCFG_DIVMODE_16:
274 txx9_gbus_clock = cpuclk / 4; break;
275 case TX4938_CCFG_DIVMODE_4_5:
276 case TX4938_CCFG_DIVMODE_18:
277 txx9_gbus_clock = cpuclk * 2 / 9; break;
278 }
279 switch (divmode) {
280 case TX4938_CCFG_DIVMODE_8:
281 case TX4938_CCFG_DIVMODE_10:
282 case TX4938_CCFG_DIVMODE_12:
283 case TX4938_CCFG_DIVMODE_16:
284 case TX4938_CCFG_DIVMODE_18:
285 txx9_master_clock = txx9_gbus_clock / 4; break;
286 default:
287 txx9_master_clock = txx9_gbus_clock;
288 }
289 }
290 /* change default value to udelay/mdelay take reasonable time */
291 loops_per_jiffy = txx9_cpu_clock / HZ / 2;
292
293 /* CCFG */
294 /* clear WatchDogReset,BusErrorOnWrite flag (W1C) */
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900295 tx4938_ccfg_set(TX4938_CCFG_WDRST | TX4938_CCFG_BEOW);
Atsushi Nemoto2064ba22007-11-24 01:20:27 +0900296 /* do reset on watchdog */
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900297 tx4938_ccfg_set(TX4938_CCFG_WR);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000298 /* clear PCIC1 reset */
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900299 txx9_clear64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIC1RST);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000300
301 /* enable Timeout BusError */
302 if (tx4938_ccfg_toeon)
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900303 tx4938_ccfg_set(TX4938_CCFG_TOE);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000304
305 /* DMA selection */
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900306 txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_DMASEL_ALL);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000307
308 /* Use external clock for external arbiter */
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900309 if (!(____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCIARB))
310 txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_PCICLKEN_ALL);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000311
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900312 printk(KERN_INFO "%s -- %dMHz(M%dMHz) CRIR:%08x CCFG:%llx PCFG:%llx\n",
313 txx9_pcode_str,
314 (cpuclk + 500000) / 1000000,
315 (txx9_master_clock + 500000) / 1000000,
316 (__u32)____raw_readq(&tx4938_ccfgptr->crir),
317 (unsigned long long)____raw_readq(&tx4938_ccfgptr->ccfg),
318 (unsigned long long)____raw_readq(&tx4938_ccfgptr->pcfg));
Ralf Baechle23fbee92005-07-25 22:45:45 +0000319
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900320 printk(KERN_INFO "%s SDRAMC --", txx9_pcode_str);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000321 for (i = 0; i < 4; i++) {
322 unsigned long long cr = tx4938_sdramcptr->cr[i];
323 unsigned long ram_base, ram_size;
324 if (!((unsigned long)cr & 0x00000400))
325 continue; /* disabled */
326 ram_base = (unsigned long)(cr >> 49) << 21;
327 ram_size = ((unsigned long)(cr >> 33) + 1) << 21;
328 if (ram_base >= 0x20000000)
329 continue; /* high memory (ignore) */
330 printk(" CR%d:%016Lx", i, cr);
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900331 tx4938_sdram_resource[i].name = "SDRAM";
332 tx4938_sdram_resource[i].start = ram_base;
333 tx4938_sdram_resource[i].end = ram_base + ram_size - 1;
334 tx4938_sdram_resource[i].flags = IORESOURCE_MEM;
335 request_resource(&iomem_resource, &tx4938_sdram_resource[i]);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000336 }
337 printk(" TR:%09Lx\n", tx4938_sdramcptr->tr);
338
339 /* SRAM */
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900340 if (tx4938_sramcptr->cr & 1) {
Ralf Baechle23fbee92005-07-25 22:45:45 +0000341 unsigned int size = 0x800;
342 unsigned long base =
343 (tx4938_sramcptr->cr >> (39-11)) & ~(size - 1);
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900344 tx4938_sram_resource.name = "SRAM";
345 tx4938_sram_resource.start = base;
346 tx4938_sram_resource.end = base + size - 1;
347 tx4938_sram_resource.flags = IORESOURCE_MEM;
348 request_resource(&iomem_resource, &tx4938_sram_resource);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000349 }
350
Ralf Baechle23fbee92005-07-25 22:45:45 +0000351 /* TMR */
Atsushi Nemoto229f7732007-10-25 01:34:09 +0900352 for (i = 0; i < TX4938_NR_TMR; i++)
353 txx9_tmr_init(TX4938_TMR_REG(i) & 0xfffffffffULL);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000354
355 /* enable DMA */
Atsushi Nemoto66140c82008-04-14 21:49:07 +0900356 for (i = 0; i < 2; i++)
357 ____raw_writeq(TX4938_DMA_MCR_MSTEN,
358 (void __iomem *)(TX4938_DMA_REG(i) + 0x50));
Ralf Baechle23fbee92005-07-25 22:45:45 +0000359
360 /* PIO */
Atsushi Nemoto4cad1542008-04-05 00:56:09 +0900361 __raw_writel(0, &tx4938_pioptr->maskcpu);
362 __raw_writel(0, &tx4938_pioptr->maskext);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000363
Ralf Baechle23fbee92005-07-25 22:45:45 +0000364#ifdef CONFIG_PCI
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900365 txx9_alloc_pci_controller(&txx9_primary_pcic, 0, 0, 0, 0);
366#endif
Ralf Baechle23fbee92005-07-25 22:45:45 +0000367}
368
Ralf Baechle4b550482007-10-11 23:46:08 +0100369void __init plat_time_init(void)
Ralf Baechle23fbee92005-07-25 22:45:45 +0000370{
Ralf Baechle23fbee92005-07-25 22:45:45 +0000371 mips_hpt_frequency = txx9_cpu_clock / 2;
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900372 if (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_TINTDIS)
Atsushi Nemoto229f7732007-10-25 01:34:09 +0900373 txx9_clockevent_init(TX4938_TMR_REG(0) & 0xfffffffffULL,
374 TXX9_IRQ_BASE + TX4938_IR_TMR(0),
375 txx9_gbus_clock / 2);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000376}
377
Atsushi Nemoto8b6c2322007-10-24 23:16:56 +0900378void __init plat_mem_setup(void)
Ralf Baechle23fbee92005-07-25 22:45:45 +0000379{
380 unsigned long long pcfg;
381 char *argptr;
382
383 iomem_resource.end = 0xffffffff; /* 4GB */
384
385 if (txx9_master_clock == 0)
386 txx9_master_clock = 25000000; /* 25MHz */
387 tx4938_board_setup();
Ralf Baechle23fbee92005-07-25 22:45:45 +0000388#ifndef CONFIG_PCI
389 set_io_port_base(RBTX4938_ETHER_BASE);
390#endif
391
392#ifdef CONFIG_SERIAL_TXX9
393 {
394 extern int early_serial_txx9_setup(struct uart_port *port);
395 int i;
396 struct uart_port req;
397 for(i = 0; i < 2; i++) {
398 memset(&req, 0, sizeof(req));
399 req.line = i;
400 req.iotype = UPIO_MEM;
401 req.membase = (char *)(0xff1ff300 + i * 0x100);
402 req.mapbase = 0xff1ff300 + i * 0x100;
Atsushi Nemotoc87abd72007-08-02 23:36:02 +0900403 req.irq = RBTX4938_IRQ_IRC_SIO(i);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000404 req.flags |= UPF_BUGGY_UART /*HAVE_CTS_LINE*/;
405 req.uartclk = 50000000;
406 early_serial_txx9_setup(&req);
407 }
408 }
409#ifdef CONFIG_SERIAL_TXX9_CONSOLE
410 argptr = prom_getcmdline();
411 if (strstr(argptr, "console=") == NULL) {
412 strcat(argptr, " console=ttyS0,38400");
413 }
414#endif
415#endif
416
417#ifdef CONFIG_TOSHIBA_RBTX4938_MPLEX_PIO58_61
418 printk("PIOSEL: disabling both ata and nand selection\n");
419 local_irq_disable();
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900420 txx9_clear64(&tx4938_ccfgptr->pcfg,
421 TX4938_PCFG_NDF_SEL | TX4938_PCFG_ATA_SEL);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000422#endif
423
424#ifdef CONFIG_TOSHIBA_RBTX4938_MPLEX_NAND
425 printk("PIOSEL: enabling nand selection\n");
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900426 txx9_set64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_NDF_SEL);
427 txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_ATA_SEL);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000428#endif
429
430#ifdef CONFIG_TOSHIBA_RBTX4938_MPLEX_ATA
431 printk("PIOSEL: enabling ata selection\n");
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900432 txx9_set64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_ATA_SEL);
433 txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_NDF_SEL);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000434#endif
435
436#ifdef CONFIG_IP_PNP
437 argptr = prom_getcmdline();
438 if (strstr(argptr, "ip=") == NULL) {
439 strcat(argptr, " ip=any");
440 }
441#endif
442
443
444#ifdef CONFIG_FB
445 {
446 conswitchp = &dummy_con;
447 }
448#endif
449
450 rbtx4938_spi_setup();
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900451 pcfg = ____raw_readq(&tx4938_ccfgptr->pcfg); /* updated */
Ralf Baechle23fbee92005-07-25 22:45:45 +0000452 /* fixup piosel */
453 if ((pcfg & (TX4938_PCFG_ATA_SEL | TX4938_PCFG_NDF_SEL)) ==
Atsushi Nemoto66140c82008-04-14 21:49:07 +0900454 TX4938_PCFG_ATA_SEL)
455 writeb((readb(rbtx4938_piosel_addr) & 0x03) | 0x04,
456 rbtx4938_piosel_addr);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000457 else if ((pcfg & (TX4938_PCFG_ATA_SEL | TX4938_PCFG_NDF_SEL)) ==
Atsushi Nemoto66140c82008-04-14 21:49:07 +0900458 TX4938_PCFG_NDF_SEL)
459 writeb((readb(rbtx4938_piosel_addr) & 0x03) | 0x08,
460 rbtx4938_piosel_addr);
461 else
462 writeb(readb(rbtx4938_piosel_addr) & ~(0x08 | 0x04),
463 rbtx4938_piosel_addr);
Ralf Baechle23fbee92005-07-25 22:45:45 +0000464
465 rbtx4938_fpga_resource.name = "FPGA Registers";
466 rbtx4938_fpga_resource.start = CPHYSADDR(RBTX4938_FPGA_REG_ADDR);
467 rbtx4938_fpga_resource.end = CPHYSADDR(RBTX4938_FPGA_REG_ADDR) + 0xffff;
468 rbtx4938_fpga_resource.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
469 if (request_resource(&iomem_resource, &rbtx4938_fpga_resource))
470 printk("request resource for fpga failed\n");
471
Ralf Baechle23fbee92005-07-25 22:45:45 +0000472 _machine_restart = rbtx4938_machine_restart;
473 _machine_halt = rbtx4938_machine_halt;
Ralf Baechlefcdb27a2006-01-18 17:37:07 +0000474 pm_power_off = rbtx4938_machine_power_off;
Ralf Baechle23fbee92005-07-25 22:45:45 +0000475
Atsushi Nemoto66140c82008-04-14 21:49:07 +0900476 writeb(0xff, rbtx4938_led_addr);
477 printk(KERN_INFO "RBTX4938 --- FPGA(Rev %02x) DIPSW:%02x,%02x\n",
478 readb(rbtx4938_fpga_rev_addr),
479 readb(rbtx4938_dipsw_addr), readb(rbtx4938_bdipsw_addr));
Ralf Baechle23fbee92005-07-25 22:45:45 +0000480}
481
Atsushi Nemoto57e386c2007-05-01 00:27:58 +0900482static int __init rbtx4938_ne_init(void)
483{
484 struct resource res[] = {
485 {
486 .start = RBTX4938_RTL_8019_BASE,
487 .end = RBTX4938_RTL_8019_BASE + 0x20 - 1,
488 .flags = IORESOURCE_IO,
489 }, {
490 .start = RBTX4938_RTL_8019_IRQ,
491 .flags = IORESOURCE_IRQ,
492 }
493 };
494 struct platform_device *dev =
495 platform_device_register_simple("ne", -1,
496 res, ARRAY_SIZE(res));
497 return IS_ERR(dev) ? PTR_ERR(dev) : 0;
498}
499device_initcall(rbtx4938_ne_init);
Atsushi Nemoto3896b052007-06-22 23:21:55 +0900500
501/* GPIO support */
502
Atsushi Nemoto4cad1542008-04-05 00:56:09 +0900503int gpio_to_irq(unsigned gpio)
504{
505 return -EINVAL;
506}
507
508int irq_to_gpio(unsigned irq)
509{
510 return -EINVAL;
511}
512
Atsushi Nemoto3896b052007-06-22 23:21:55 +0900513static DEFINE_SPINLOCK(rbtx4938_spi_gpio_lock);
514
Atsushi Nemoto4cad1542008-04-05 00:56:09 +0900515static void rbtx4938_spi_gpio_set(struct gpio_chip *chip, unsigned int offset,
516 int value)
Atsushi Nemoto3896b052007-06-22 23:21:55 +0900517{
518 u8 val;
519 unsigned long flags;
Atsushi Nemoto3896b052007-06-22 23:21:55 +0900520 spin_lock_irqsave(&rbtx4938_spi_gpio_lock, flags);
Atsushi Nemoto66140c82008-04-14 21:49:07 +0900521 val = readb(rbtx4938_spics_addr);
Atsushi Nemoto3896b052007-06-22 23:21:55 +0900522 if (value)
Atsushi Nemoto4cad1542008-04-05 00:56:09 +0900523 val |= 1 << offset;
Atsushi Nemoto3896b052007-06-22 23:21:55 +0900524 else
Atsushi Nemoto4cad1542008-04-05 00:56:09 +0900525 val &= ~(1 << offset);
Atsushi Nemoto66140c82008-04-14 21:49:07 +0900526 writeb(val, rbtx4938_spics_addr);
Atsushi Nemoto3896b052007-06-22 23:21:55 +0900527 mmiowb();
528 spin_unlock_irqrestore(&rbtx4938_spi_gpio_lock, flags);
529}
530
Atsushi Nemoto4cad1542008-04-05 00:56:09 +0900531static int rbtx4938_spi_gpio_dir_out(struct gpio_chip *chip,
532 unsigned int offset, int value)
Atsushi Nemoto3896b052007-06-22 23:21:55 +0900533{
Atsushi Nemoto4cad1542008-04-05 00:56:09 +0900534 rbtx4938_spi_gpio_set(chip, offset, value);
Atsushi Nemoto3896b052007-06-22 23:21:55 +0900535 return 0;
536}
537
Atsushi Nemoto4cad1542008-04-05 00:56:09 +0900538static struct gpio_chip rbtx4938_spi_gpio_chip = {
539 .set = rbtx4938_spi_gpio_set,
540 .direction_output = rbtx4938_spi_gpio_dir_out,
541 .label = "RBTX4938-SPICS",
542 .base = 16,
543 .ngpio = 3,
544};
Atsushi Nemotof74cf6f2007-06-22 23:22:06 +0900545
546/* SPI support */
547
548static void __init txx9_spi_init(unsigned long base, int irq)
549{
550 struct resource res[] = {
551 {
552 .start = base,
553 .end = base + 0x20 - 1,
554 .flags = IORESOURCE_MEM,
Atsushi Nemotof74cf6f2007-06-22 23:22:06 +0900555 }, {
556 .start = irq,
557 .flags = IORESOURCE_IRQ,
558 },
559 };
Atsushi Nemoto4ccdb4c2007-08-30 23:56:25 -0700560 platform_device_register_simple("spi_txx9", 0,
Atsushi Nemotof74cf6f2007-06-22 23:22:06 +0900561 res, ARRAY_SIZE(res));
562}
563
564static int __init rbtx4938_spi_init(void)
565{
566 struct spi_board_info srtc_info = {
Atsushi Nemoto9f90a032007-08-19 22:32:10 +0900567 .modalias = "rtc-rs5c348",
Atsushi Nemotof74cf6f2007-06-22 23:22:06 +0900568 .max_speed_hz = 1000000, /* 1.0Mbps @ Vdd 2.0V */
569 .bus_num = 0,
570 .chip_select = 16 + SRTC_CS,
571 /* Mode 1 (High-Active, Shift-Then-Sample), High Avtive CS */
572 .mode = SPI_MODE_1 | SPI_CS_HIGH,
573 };
574 spi_register_board_info(&srtc_info, 1);
575 spi_eeprom_register(SEEPROM1_CS);
576 spi_eeprom_register(16 + SEEPROM2_CS);
577 spi_eeprom_register(16 + SEEPROM3_CS);
Atsushi Nemoto4cad1542008-04-05 00:56:09 +0900578 gpio_request(16 + SRTC_CS, "rtc-rs5c348");
579 gpio_direction_output(16 + SRTC_CS, 0);
580 gpio_request(SEEPROM1_CS, "seeprom1");
581 gpio_direction_output(SEEPROM1_CS, 1);
582 gpio_request(16 + SEEPROM2_CS, "seeprom2");
583 gpio_direction_output(16 + SEEPROM2_CS, 1);
584 gpio_request(16 + SEEPROM3_CS, "seeprom3");
585 gpio_direction_output(16 + SEEPROM3_CS, 1);
Atsushi Nemotof74cf6f2007-06-22 23:22:06 +0900586 txx9_spi_init(TX4938_SPI_REG & 0xfffffffffULL, RBTX4938_IRQ_IRC_SPI);
587 return 0;
588}
Atsushi Nemoto4cad1542008-04-05 00:56:09 +0900589
590static int __init rbtx4938_arch_init(void)
591{
592 txx9_gpio_init(TX4938_PIO_REG & 0xfffffffffULL, 0, 16);
593 gpiochip_add(&rbtx4938_spi_gpio_chip);
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +0900594 rbtx4938_pci_setup();
Atsushi Nemoto4cad1542008-04-05 00:56:09 +0900595 return rbtx4938_spi_init();
596}
597arch_initcall(rbtx4938_arch_init);
Atsushi Nemotof74cf6f2007-06-22 23:22:06 +0900598
Atsushi Nemoto2064ba22007-11-24 01:20:27 +0900599/* Watchdog support */
600
601static int __init txx9_wdt_init(unsigned long base)
602{
603 struct resource res = {
604 .start = base,
605 .end = base + 0x100 - 1,
606 .flags = IORESOURCE_MEM,
Atsushi Nemoto2064ba22007-11-24 01:20:27 +0900607 };
608 struct platform_device *dev =
609 platform_device_register_simple("txx9wdt", -1, &res, 1);
610 return IS_ERR(dev) ? PTR_ERR(dev) : 0;
611}
612
613static int __init rbtx4938_wdt_init(void)
614{
615 return txx9_wdt_init(TX4938_TMR_REG(2) & 0xfffffffffULL);
616}
617device_initcall(rbtx4938_wdt_init);
618
Atsushi Nemotof74cf6f2007-06-22 23:22:06 +0900619/* Minimum CLK support */
620
621struct clk *clk_get(struct device *dev, const char *id)
622{
623 if (!strcmp(id, "spi-baseclk"))
624 return (struct clk *)(txx9_gbus_clock / 2 / 4);
Atsushi Nemoto2064ba22007-11-24 01:20:27 +0900625 if (!strcmp(id, "imbus_clk"))
626 return (struct clk *)(txx9_gbus_clock / 2);
Atsushi Nemotof74cf6f2007-06-22 23:22:06 +0900627 return ERR_PTR(-ENOENT);
628}
629EXPORT_SYMBOL(clk_get);
630
631int clk_enable(struct clk *clk)
632{
633 return 0;
634}
635EXPORT_SYMBOL(clk_enable);
636
637void clk_disable(struct clk *clk)
638{
639}
640EXPORT_SYMBOL(clk_disable);
641
642unsigned long clk_get_rate(struct clk *clk)
643{
644 return (unsigned long)clk;
645}
646EXPORT_SYMBOL(clk_get_rate);
647
648void clk_put(struct clk *clk)
649{
650}
651EXPORT_SYMBOL(clk_put);