2 * linux/arch/mips/tx4938/toshiba_rbtx4938/setup.c
4 * Setup pointers to hardware-dependent routines.
5 * Copyright (C) 2000-2001 Toshiba Corporation
7 * 2003-2005 (c) MontaVista Software, Inc. This file is licensed under the
8 * terms of the GNU General Public License version 2. This program is
9 * licensed "as is" without any warranty of any kind, whether express
12 * Support for TX4938 in 2.6 - Manish Lachwani (mlachwani@mvista.com)
14 #include <linux/init.h>
15 #include <linux/types.h>
16 #include <linux/ioport.h>
17 #include <linux/proc_fs.h>
18 #include <linux/delay.h>
19 #include <linux/interrupt.h>
20 #include <linux/console.h>
21 #include <linux/pci.h>
24 #include <asm/wbflush.h>
25 #include <asm/reboot.h>
28 #include <asm/uaccess.h>
30 #include <asm/bootinfo.h>
31 #include <asm/tx4938/rbtx4938.h>
32 #ifdef CONFIG_SERIAL_TXX9
33 #include <linux/tty.h>
34 #include <linux/serial.h>
35 #include <linux/serial_core.h>
38 extern void rbtx4938_time_init(void) __init;
39 extern char * __init prom_getcmdline(void);
40 static inline void tx4938_report_pcic_status1(struct tx4938_pcic_reg *pcicptr);
42 /* These functions are used for rebooting or halting the machine*/
43 extern void rbtx4938_machine_restart(char *command);
44 extern void rbtx4938_machine_halt(void);
45 extern void rbtx4938_machine_power_off(void);
48 unsigned int txx9_master_clock;
49 unsigned int txx9_cpu_clock;
50 unsigned int txx9_gbus_clock;
52 unsigned long rbtx4938_ce_base[8];
53 unsigned long rbtx4938_ce_size[8];
54 int txboard_pci66_mode;
55 static int tx4938_pcic_trdyto; /* default: disabled */
56 static int tx4938_pcic_retryto; /* default: disabled */
57 static int tx4938_ccfg_toeon = 1;
59 struct tx4938_pcic_reg *pcicptrs[4] = {
60 tx4938_pcicptr /* default setting for TX4938 */
66 } phys_regions[16] __initdata;
67 static int num_phys_regions __initdata;
69 #define PHYS_REGION_MINSIZE 0x10000
71 void rbtx4938_machine_halt(void)
73 printk(KERN_NOTICE "System Halted\n");
77 __asm__(".set\tmips3\n\t"
82 void rbtx4938_machine_power_off(void)
84 rbtx4938_machine_halt();
88 void rbtx4938_machine_restart(char *command)
92 printk("Rebooting...");
93 *rbtx4938_softresetlock_ptr = 1;
94 *rbtx4938_sfvol_ptr = 1;
95 *rbtx4938_softreset_ptr = 1;
102 txboard_add_phys_region(unsigned long base, unsigned long size)
104 if (num_phys_regions >= ARRAY_SIZE(phys_regions)) {
105 printk("phys_region overflow\n");
108 phys_regions[num_phys_regions].base = base;
109 phys_regions[num_phys_regions].size = size;
113 txboard_find_free_phys_region(unsigned long begin, unsigned long end,
119 for (base = begin / size * size; base < end; base += size) {
120 for (i = 0; i < num_phys_regions; i++) {
121 if (phys_regions[i].size &&
122 base <= phys_regions[i].base + (phys_regions[i].size - 1) &&
123 base + (size - 1) >= phys_regions[i].base)
126 if (i == num_phys_regions)
132 txboard_find_free_phys_region_shrink(unsigned long begin, unsigned long end,
135 unsigned long sz, base;
136 for (sz = *size; sz >= PHYS_REGION_MINSIZE; sz /= 2) {
137 base = txboard_find_free_phys_region(begin, end, sz);
146 txboard_request_phys_region_range(unsigned long begin, unsigned long end,
150 base = txboard_find_free_phys_region(begin, end, size);
152 txboard_add_phys_region(base, size);
156 txboard_request_phys_region(unsigned long size)
159 unsigned long begin = 0, end = 0x20000000; /* search low 512MB */
160 base = txboard_find_free_phys_region(begin, end, size);
162 txboard_add_phys_region(base, size);
166 txboard_request_phys_region_shrink(unsigned long *size)
169 unsigned long begin = 0, end = 0x20000000; /* search low 512MB */
170 base = txboard_find_free_phys_region_shrink(begin, end, size);
172 txboard_add_phys_region(base, *size);
178 tx4938_pcic_setup(struct tx4938_pcic_reg *pcicptr,
179 struct pci_controller *channel,
180 unsigned long pci_io_base,
185 /* Disable All Initiator Space */
186 pcicptr->pciccfg &= ~(TX4938_PCIC_PCICCFG_G2PMEN(0)|
187 TX4938_PCIC_PCICCFG_G2PMEN(1)|
188 TX4938_PCIC_PCICCFG_G2PMEN(2)|
189 TX4938_PCIC_PCICCFG_G2PIOEN);
191 /* GB->PCI mappings */
192 pcicptr->g2piomask = (channel->io_resource->end - channel->io_resource->start) >> 4;
193 pcicptr->g2piogbase = pci_io_base |
195 TX4938_PCIC_G2PIOGBASE_ECHG
197 TX4938_PCIC_G2PIOGBASE_BSDIS
200 pcicptr->g2piopbase = 0;
201 for (i = 0; i < 3; i++) {
202 pcicptr->g2pmmask[i] = 0;
203 pcicptr->g2pmgbase[i] = 0;
204 pcicptr->g2pmpbase[i] = 0;
206 if (channel->mem_resource->end) {
207 pcicptr->g2pmmask[0] = (channel->mem_resource->end - channel->mem_resource->start) >> 4;
208 pcicptr->g2pmgbase[0] = channel->mem_resource->start |
210 TX4938_PCIC_G2PMnGBASE_ECHG
212 TX4938_PCIC_G2PMnGBASE_BSDIS
215 pcicptr->g2pmpbase[0] = channel->mem_resource->start;
217 /* PCI->GB mappings (I/O 256B) */
218 pcicptr->p2giopbase = 0; /* 256B */
219 pcicptr->p2giogbase = 0;
220 /* PCI->GB mappings (MEM 512MB (64MB on R1.x)) */
221 pcicptr->p2gm0plbase = 0;
222 pcicptr->p2gm0pubase = 0;
223 pcicptr->p2gmgbase[0] = 0 |
224 TX4938_PCIC_P2GMnGBASE_TMEMEN |
226 TX4938_PCIC_P2GMnGBASE_TECHG
228 TX4938_PCIC_P2GMnGBASE_TBSDIS
231 /* PCI->GB mappings (MEM 16MB) */
232 pcicptr->p2gm1plbase = 0xffffffff;
233 pcicptr->p2gm1pubase = 0xffffffff;
234 pcicptr->p2gmgbase[1] = 0;
235 /* PCI->GB mappings (MEM 1MB) */
236 pcicptr->p2gm2pbase = 0xffffffff; /* 1MB */
237 pcicptr->p2gmgbase[2] = 0;
239 pcicptr->pciccfg &= TX4938_PCIC_PCICCFG_GBWC_MASK;
240 /* Enable Initiator Memory Space */
241 if (channel->mem_resource->end)
242 pcicptr->pciccfg |= TX4938_PCIC_PCICCFG_G2PMEN(0);
243 /* Enable Initiator I/O Space */
244 if (channel->io_resource->end)
245 pcicptr->pciccfg |= TX4938_PCIC_PCICCFG_G2PIOEN;
246 /* Enable Initiator Config */
248 TX4938_PCIC_PCICCFG_ICAEN |
249 TX4938_PCIC_PCICCFG_TCAR;
251 /* Do not use MEMMUL, MEMINF: YMFPCI card causes M_ABORT. */
252 pcicptr->pcicfg1 = 0;
254 pcicptr->g2ptocnt &= ~0xffff;
256 if (tx4938_pcic_trdyto >= 0) {
257 pcicptr->g2ptocnt &= ~0xff;
258 pcicptr->g2ptocnt |= (tx4938_pcic_trdyto & 0xff);
261 if (tx4938_pcic_retryto >= 0) {
262 pcicptr->g2ptocnt &= ~0xff00;
263 pcicptr->g2ptocnt |= ((tx4938_pcic_retryto<<8) & 0xff00);
266 /* Clear All Local Bus Status */
267 pcicptr->pcicstatus = TX4938_PCIC_PCICSTATUS_ALL;
268 /* Enable All Local Bus Interrupts */
269 pcicptr->pcicmask = TX4938_PCIC_PCICSTATUS_ALL;
270 /* Clear All Initiator Status */
271 pcicptr->g2pstatus = TX4938_PCIC_G2PSTATUS_ALL;
272 /* Enable All Initiator Interrupts */
273 pcicptr->g2pmask = TX4938_PCIC_G2PSTATUS_ALL;
274 /* Clear All PCI Status Error */
276 (pcicptr->pcistatus & 0x0000ffff) |
277 (TX4938_PCIC_PCISTATUS_ALL << 16);
278 /* Enable All PCI Status Error Interrupts */
279 pcicptr->pcimask = TX4938_PCIC_PCISTATUS_ALL;
282 /* Reset Bus Arbiter */
283 pcicptr->pbacfg = TX4938_PCIC_PBACFG_RPBA;
285 /* Enable Bus Arbiter */
286 pcicptr->pbacfg = TX4938_PCIC_PBACFG_PBAEN;
289 /* PCIC Int => IRC IRQ16 */
291 (pcicptr->pcicfg2 & 0xffffff00) | TX4938_IR_PCIC;
293 pcicptr->pcistatus = PCI_COMMAND_MASTER |
295 PCI_COMMAND_PARITY | PCI_COMMAND_SERR;
299 tx4938_report_pciclk(void)
301 unsigned long pcode = TX4938_REV_PCODE();
303 printk("TX%lx PCIC --%s PCICLK:",
305 (tx4938_ccfgptr->ccfg & TX4938_CCFG_PCI66) ? " PCI66" : "");
306 if (tx4938_ccfgptr->pcfg & TX4938_PCFG_PCICLKEN_ALL) {
308 switch ((unsigned long)tx4938_ccfgptr->ccfg & TX4938_CCFG_PCIDIVMODE_MASK) {
309 case TX4938_CCFG_PCIDIVMODE_4:
310 pciclk = txx9_cpu_clock / 4; break;
311 case TX4938_CCFG_PCIDIVMODE_4_5:
312 pciclk = txx9_cpu_clock * 2 / 9; break;
313 case TX4938_CCFG_PCIDIVMODE_5:
314 pciclk = txx9_cpu_clock / 5; break;
315 case TX4938_CCFG_PCIDIVMODE_5_5:
316 pciclk = txx9_cpu_clock * 2 / 11; break;
317 case TX4938_CCFG_PCIDIVMODE_8:
318 pciclk = txx9_cpu_clock / 8; break;
319 case TX4938_CCFG_PCIDIVMODE_9:
320 pciclk = txx9_cpu_clock / 9; break;
321 case TX4938_CCFG_PCIDIVMODE_10:
322 pciclk = txx9_cpu_clock / 10; break;
323 case TX4938_CCFG_PCIDIVMODE_11:
324 pciclk = txx9_cpu_clock / 11; break;
326 printk("Internal(%dMHz)", pciclk / 1000000);
335 void __init set_tx4938_pcicptr(int ch, struct tx4938_pcic_reg *pcicptr)
337 pcicptrs[ch] = pcicptr;
340 struct tx4938_pcic_reg *get_tx4938_pcicptr(int ch)
345 static struct pci_dev *fake_pci_dev(struct pci_controller *hose,
346 int top_bus, int busnr, int devfn)
348 static struct pci_dev dev;
349 static struct pci_bus bus;
351 dev.sysdata = (void *)hose;
354 bus.ops = hose->pci_ops;
361 #define EARLY_PCI_OP(rw, size, type) \
362 static int early_##rw##_config_##size(struct pci_controller *hose, \
363 int top_bus, int bus, int devfn, int offset, type value) \
365 return pci_##rw##_config_##size( \
366 fake_pci_dev(hose, top_bus, bus, devfn), \
370 EARLY_PCI_OP(read, word, u16 *)
372 int txboard_pci66_check(struct pci_controller *hose, int top_bus, int current_bus)
377 int devfn_stop = 0xff;
381 printk("PCI: Checking 66MHz capabilities...\n");
383 for (pci_devfn=devfn_start; pci_devfn<devfn_stop; pci_devfn++) {
384 early_read_config_word(hose, top_bus, current_bus, pci_devfn,
385 PCI_VENDOR_ID, &vid);
387 if (vid == 0xffff) continue;
389 /* check 66MHz capability */
393 early_read_config_word(hose, top_bus, current_bus, pci_devfn,
395 if (!(stat & PCI_STATUS_66MHZ)) {
396 printk(KERN_DEBUG "PCI: %02x:%02x not 66MHz capable.\n",
397 current_bus, pci_devfn);
407 tx4938_pciclk66_setup(void)
412 tx4938_ccfgptr->ccfg |= TX4938_CCFG_PCI66;
413 /* Double PCICLK (if possible) */
414 if (tx4938_ccfgptr->pcfg & TX4938_PCFG_PCICLKEN_ALL) {
415 unsigned int pcidivmode =
416 tx4938_ccfgptr->ccfg & TX4938_CCFG_PCIDIVMODE_MASK;
417 switch (pcidivmode) {
418 case TX4938_CCFG_PCIDIVMODE_8:
419 case TX4938_CCFG_PCIDIVMODE_4:
420 pcidivmode = TX4938_CCFG_PCIDIVMODE_4;
421 pciclk = txx9_cpu_clock / 4;
423 case TX4938_CCFG_PCIDIVMODE_9:
424 case TX4938_CCFG_PCIDIVMODE_4_5:
425 pcidivmode = TX4938_CCFG_PCIDIVMODE_4_5;
426 pciclk = txx9_cpu_clock * 2 / 9;
428 case TX4938_CCFG_PCIDIVMODE_10:
429 case TX4938_CCFG_PCIDIVMODE_5:
430 pcidivmode = TX4938_CCFG_PCIDIVMODE_5;
431 pciclk = txx9_cpu_clock / 5;
433 case TX4938_CCFG_PCIDIVMODE_11:
434 case TX4938_CCFG_PCIDIVMODE_5_5:
436 pcidivmode = TX4938_CCFG_PCIDIVMODE_5_5;
437 pciclk = txx9_cpu_clock * 2 / 11;
440 tx4938_ccfgptr->ccfg =
441 (tx4938_ccfgptr->ccfg & ~TX4938_CCFG_PCIDIVMODE_MASK)
443 printk(KERN_DEBUG "PCICLK: ccfg:%08lx\n",
444 (unsigned long)tx4938_ccfgptr->ccfg);
451 extern struct pci_controller tx4938_pci_controller[];
452 static int __init tx4938_pcibios_init(void)
454 unsigned long mem_base[2];
455 unsigned long mem_size[2] = {TX4938_PCIMEM_SIZE_0,TX4938_PCIMEM_SIZE_1}; /* MAX 128M,64K */
456 unsigned long io_base[2];
457 unsigned long io_size[2] = {TX4938_PCIIO_SIZE_0,TX4938_PCIIO_SIZE_1}; /* MAX 16M,64K */
458 /* TX4938 PCIC1: 64K MEM/IO is enough for ETH0,ETH1 */
459 int extarb = !(tx4938_ccfgptr->ccfg & TX4938_CCFG_PCIXARB);
461 PCIBIOS_MIN_IO = 0x00001000UL;
462 PCIBIOS_MIN_MEM = 0x01000000UL;
464 mem_base[0] = txboard_request_phys_region_shrink(&mem_size[0]);
465 io_base[0] = txboard_request_phys_region_shrink(&io_size[0]);
467 printk("TX4938 PCIC -- DID:%04x VID:%04x RID:%02x Arbiter:%s\n",
468 (unsigned short)(tx4938_pcicptr->pciid >> 16),
469 (unsigned short)(tx4938_pcicptr->pciid & 0xffff),
470 (unsigned short)(tx4938_pcicptr->pciccrev & 0xff),
471 extarb ? "External" : "Internal");
474 tx4938_pci_controller[0].io_resource->start = io_base[0];
475 tx4938_pci_controller[0].io_resource->end = (io_base[0] + io_size[0]) - 1;
476 tx4938_pci_controller[0].mem_resource->start = mem_base[0];
477 tx4938_pci_controller[0].mem_resource->end = mem_base[0] + mem_size[0] - 1;
479 set_tx4938_pcicptr(0, tx4938_pcicptr);
481 register_pci_controller(&tx4938_pci_controller[0]);
483 if (tx4938_ccfgptr->ccfg & TX4938_CCFG_PCI66) {
484 printk("TX4938_CCFG_PCI66 already configured\n");
485 txboard_pci66_mode = -1; /* already configured */
489 *rbtx4938_pcireset_ptr = 0;
491 tx4938_ccfgptr->clkctr |= TX4938_CLKCTR_PCIRST;
492 if (txboard_pci66_mode > 0)
493 tx4938_pciclk66_setup();
495 /* clear PCIC reset */
496 tx4938_ccfgptr->clkctr &= ~TX4938_CLKCTR_PCIRST;
497 *rbtx4938_pcireset_ptr = 1;
499 tx4938_report_pcic_status1(tx4938_pcicptr);
501 tx4938_report_pciclk();
502 tx4938_pcic_setup(tx4938_pcicptr, &tx4938_pci_controller[0], io_base[0], extarb);
503 if (txboard_pci66_mode == 0 &&
504 txboard_pci66_check(&tx4938_pci_controller[0], 0, 0)) {
506 *rbtx4938_pcireset_ptr = 0;
508 tx4938_ccfgptr->clkctr |= TX4938_CLKCTR_PCIRST;
509 tx4938_pciclk66_setup();
511 /* clear PCIC reset */
512 tx4938_ccfgptr->clkctr &= ~TX4938_CLKCTR_PCIRST;
513 *rbtx4938_pcireset_ptr = 1;
515 /* Reinitialize PCIC */
516 tx4938_report_pciclk();
517 tx4938_pcic_setup(tx4938_pcicptr, &tx4938_pci_controller[0], io_base[0], extarb);
520 mem_base[1] = txboard_request_phys_region_shrink(&mem_size[1]);
521 io_base[1] = txboard_request_phys_region_shrink(&io_size[1]);
523 tx4938_ccfgptr->clkctr |= TX4938_CLKCTR_PCIC1RST;
524 /* PCI1DMD==0 => PCI1CLK==GBUSCLK/2 => PCI66 */
525 if (!(tx4938_ccfgptr->ccfg & TX4938_CCFG_PCI1DMD))
526 tx4938_ccfgptr->ccfg |= TX4938_CCFG_PCI1_66;
528 tx4938_ccfgptr->ccfg &= ~TX4938_CCFG_PCI1_66;
530 /* clear PCIC1 reset */
531 tx4938_ccfgptr->clkctr &= ~TX4938_CLKCTR_PCIC1RST;
532 tx4938_report_pcic_status1(tx4938_pcic1ptr);
534 printk("TX4938 PCIC1 -- DID:%04x VID:%04x RID:%02x",
535 (unsigned short)(tx4938_pcic1ptr->pciid >> 16),
536 (unsigned short)(tx4938_pcic1ptr->pciid & 0xffff),
537 (unsigned short)(tx4938_pcic1ptr->pciccrev & 0xff));
538 printk("%s PCICLK:%dMHz\n",
539 (tx4938_ccfgptr->ccfg & TX4938_CCFG_PCI1_66) ? " PCI66" : "",
541 ((tx4938_ccfgptr->ccfg & TX4938_CCFG_PCI1DMD) ? 4 : 2) /
544 /* assumption: CPHYSADDR(mips_io_port_base) == io_base[0] */
545 tx4938_pci_controller[1].io_resource->start =
546 io_base[1] - io_base[0];
547 tx4938_pci_controller[1].io_resource->end =
548 io_base[1] - io_base[0] + io_size[1] - 1;
549 tx4938_pci_controller[1].mem_resource->start = mem_base[1];
550 tx4938_pci_controller[1].mem_resource->end =
551 mem_base[1] + mem_size[1] - 1;
552 set_tx4938_pcicptr(1, tx4938_pcic1ptr);
554 register_pci_controller(&tx4938_pci_controller[1]);
556 tx4938_pcic_setup(tx4938_pcic1ptr, &tx4938_pci_controller[1], io_base[1], extarb);
558 /* map ioport 0 to PCI I/O space address 0 */
559 set_io_port_base(KSEG1 + io_base[0]);
564 arch_initcall(tx4938_pcibios_init);
566 #endif /* CONFIG_PCI */
570 /* chip select for SPI devices */
571 #define SEEPROM1_CS 7 /* PIO7 */
572 #define SEEPROM2_CS 0 /* IOC */
573 #define SEEPROM3_CS 1 /* IOC */
574 #define SRTC_CS 2 /* IOC */
576 static int rbtx4938_spi_cs_func(int chipid, int on)
580 case RBTX4938_SEEPROM1_CHIPID:
582 tx4938_pioptr->dout &= ~(1 << SEEPROM1_CS);
584 tx4938_pioptr->dout |= (1 << SEEPROM1_CS);
587 case RBTX4938_SEEPROM2_CHIPID:
588 bit = (1 << SEEPROM2_CS);
590 case RBTX4938_SEEPROM3_CHIPID:
591 bit = (1 << SEEPROM3_CS);
593 case RBTX4938_SRTC_CHIPID:
594 bit = (1 << SRTC_CS);
599 /* bit1,2,4 are low active, bit3 is high active */
600 *rbtx4938_spics_ptr =
601 (*rbtx4938_spics_ptr & ~bit) |
602 ((on ? (bit ^ 0x0b) : ~(bit ^ 0x0b)) & bit);
607 extern int spi_eeprom_read(int chipid, int address, unsigned char *buf, int len);
609 int rbtx4938_get_tx4938_ethaddr(struct pci_dev *dev, unsigned char *addr)
611 struct pci_controller *channel = (struct pci_controller *)dev->bus->sysdata;
612 static unsigned char dat[17];
613 static int read_dat = 0;
616 if (channel != &tx4938_pci_controller[1])
619 switch (PCI_SLOT(dev->devfn)) {
620 case TX4938_PCIC_IDSEL_AD_TO_SLOT(31):
623 case TX4938_PCIC_IDSEL_AD_TO_SLOT(30):
633 /* 0-3: "MAC\0", 4-9:eth0, 10-15:eth1, 16:sum */
634 if (spi_eeprom_read(RBTX4938_SEEPROM1_CHIPID,
635 0, dat, sizeof(dat))) {
636 printk(KERN_ERR "seeprom: read error.\n");
638 if (strcmp(dat, "MAC") != 0)
639 printk(KERN_WARNING "seeprom: bad signature.\n");
640 for (i = 0, sum = 0; i < sizeof(dat); i++)
643 printk(KERN_WARNING "seeprom: bad checksum.\n");
646 memcpy(addr, &dat[4 + 6 * ch], 6);
649 #endif /* CONFIG_PCI */
651 extern void __init txx9_spi_init(unsigned long base, int (*cs_func)(int chipid, int on));
652 static void __init rbtx4938_spi_setup(void)
655 tx4938_ccfgptr->pcfg |= TX4938_PCFG_SPI_SEL;
656 /* chip selects for SPI devices */
657 tx4938_pioptr->dout |= (1 << SEEPROM1_CS);
658 tx4938_pioptr->dir |= (1 << SEEPROM1_CS);
659 txx9_spi_init(TX4938_SPI_REG, rbtx4938_spi_cs_func);
662 static struct resource rbtx4938_fpga_resource;
664 static char pcode_str[8];
665 static struct resource tx4938_reg_resource = {
666 .start = TX4938_REG_BASE,
667 .end = TX4938_REG_BASE + TX4938_REG_SIZE,
669 .flags = IORESOURCE_MEM
672 void __init tx4938_board_setup(void)
675 unsigned long divmode;
677 unsigned long pcode = TX4938_REV_PCODE();
679 ioport_resource.start = 0x1000;
680 ioport_resource.end = 0xffffffff;
681 iomem_resource.start = 0x1000;
682 iomem_resource.end = 0xffffffff; /* expand to 4GB */
684 sprintf(pcode_str, "TX%lx", pcode);
685 /* SDRAMC,EBUSC are configured by PROM */
686 for (i = 0; i < 8; i++) {
687 if (!(tx4938_ebuscptr->cr[i] & 0x8))
688 continue; /* disabled */
689 rbtx4938_ce_base[i] = (unsigned long)TX4938_EBUSC_BA(i);
690 txboard_add_phys_region(rbtx4938_ce_base[i], TX4938_EBUSC_SIZE(i));
694 if (txx9_master_clock) {
695 /* calculate gbus_clock and cpu_clock from master_clock */
696 divmode = (unsigned long)tx4938_ccfgptr->ccfg & TX4938_CCFG_DIVMODE_MASK;
698 case TX4938_CCFG_DIVMODE_8:
699 case TX4938_CCFG_DIVMODE_10:
700 case TX4938_CCFG_DIVMODE_12:
701 case TX4938_CCFG_DIVMODE_16:
702 case TX4938_CCFG_DIVMODE_18:
703 txx9_gbus_clock = txx9_master_clock * 4; break;
705 txx9_gbus_clock = txx9_master_clock;
708 case TX4938_CCFG_DIVMODE_2:
709 case TX4938_CCFG_DIVMODE_8:
710 cpuclk = txx9_gbus_clock * 2; break;
711 case TX4938_CCFG_DIVMODE_2_5:
712 case TX4938_CCFG_DIVMODE_10:
713 cpuclk = txx9_gbus_clock * 5 / 2; break;
714 case TX4938_CCFG_DIVMODE_3:
715 case TX4938_CCFG_DIVMODE_12:
716 cpuclk = txx9_gbus_clock * 3; break;
717 case TX4938_CCFG_DIVMODE_4:
718 case TX4938_CCFG_DIVMODE_16:
719 cpuclk = txx9_gbus_clock * 4; break;
720 case TX4938_CCFG_DIVMODE_4_5:
721 case TX4938_CCFG_DIVMODE_18:
722 cpuclk = txx9_gbus_clock * 9 / 2; break;
724 txx9_cpu_clock = cpuclk;
726 if (txx9_cpu_clock == 0) {
727 txx9_cpu_clock = 300000000; /* 300MHz */
729 /* calculate gbus_clock and master_clock from cpu_clock */
730 cpuclk = txx9_cpu_clock;
731 divmode = (unsigned long)tx4938_ccfgptr->ccfg & TX4938_CCFG_DIVMODE_MASK;
733 case TX4938_CCFG_DIVMODE_2:
734 case TX4938_CCFG_DIVMODE_8:
735 txx9_gbus_clock = cpuclk / 2; break;
736 case TX4938_CCFG_DIVMODE_2_5:
737 case TX4938_CCFG_DIVMODE_10:
738 txx9_gbus_clock = cpuclk * 2 / 5; break;
739 case TX4938_CCFG_DIVMODE_3:
740 case TX4938_CCFG_DIVMODE_12:
741 txx9_gbus_clock = cpuclk / 3; break;
742 case TX4938_CCFG_DIVMODE_4:
743 case TX4938_CCFG_DIVMODE_16:
744 txx9_gbus_clock = cpuclk / 4; break;
745 case TX4938_CCFG_DIVMODE_4_5:
746 case TX4938_CCFG_DIVMODE_18:
747 txx9_gbus_clock = cpuclk * 2 / 9; break;
750 case TX4938_CCFG_DIVMODE_8:
751 case TX4938_CCFG_DIVMODE_10:
752 case TX4938_CCFG_DIVMODE_12:
753 case TX4938_CCFG_DIVMODE_16:
754 case TX4938_CCFG_DIVMODE_18:
755 txx9_master_clock = txx9_gbus_clock / 4; break;
757 txx9_master_clock = txx9_gbus_clock;
760 /* change default value to udelay/mdelay take reasonable time */
761 loops_per_jiffy = txx9_cpu_clock / HZ / 2;
764 /* clear WatchDogReset,BusErrorOnWrite flag (W1C) */
765 tx4938_ccfgptr->ccfg |= TX4938_CCFG_WDRST | TX4938_CCFG_BEOW;
766 /* clear PCIC1 reset */
767 if (tx4938_ccfgptr->clkctr & TX4938_CLKCTR_PCIC1RST)
768 tx4938_ccfgptr->clkctr &= ~TX4938_CLKCTR_PCIC1RST;
770 /* enable Timeout BusError */
771 if (tx4938_ccfg_toeon)
772 tx4938_ccfgptr->ccfg |= TX4938_CCFG_TOE;
775 tx4938_ccfgptr->pcfg &= ~TX4938_PCFG_DMASEL_ALL;
777 /* Use external clock for external arbiter */
778 if (!(tx4938_ccfgptr->ccfg & TX4938_CCFG_PCIXARB))
779 tx4938_ccfgptr->pcfg &= ~TX4938_PCFG_PCICLKEN_ALL;
781 printk("%s -- %dMHz(M%dMHz) CRIR:%08lx CCFG:%Lx PCFG:%Lx\n",
783 cpuclk / 1000000, txx9_master_clock / 1000000,
784 (unsigned long)tx4938_ccfgptr->crir,
785 tx4938_ccfgptr->ccfg,
786 tx4938_ccfgptr->pcfg);
788 printk("%s SDRAMC --", pcode_str);
789 for (i = 0; i < 4; i++) {
790 unsigned long long cr = tx4938_sdramcptr->cr[i];
791 unsigned long ram_base, ram_size;
792 if (!((unsigned long)cr & 0x00000400))
793 continue; /* disabled */
794 ram_base = (unsigned long)(cr >> 49) << 21;
795 ram_size = ((unsigned long)(cr >> 33) + 1) << 21;
796 if (ram_base >= 0x20000000)
797 continue; /* high memory (ignore) */
798 printk(" CR%d:%016Lx", i, cr);
799 txboard_add_phys_region(ram_base, ram_size);
801 printk(" TR:%09Lx\n", tx4938_sdramcptr->tr);
804 if (pcode == 0x4938 && tx4938_sramcptr->cr & 1) {
805 unsigned int size = 0x800;
807 (tx4938_sramcptr->cr >> (39-11)) & ~(size - 1);
808 txboard_add_phys_region(base, size);
812 /* disable interrupt control */
813 tx4938_ircptr->cer = 0;
816 /* disable all timers */
817 for (i = 0; i < TX4938_NR_TMR; i++) {
818 tx4938_tmrptr(i)->tcr = 0x00000020;
819 tx4938_tmrptr(i)->tisr = 0;
820 tx4938_tmrptr(i)->cpra = 0xffffffff;
821 tx4938_tmrptr(i)->itmr = 0;
822 tx4938_tmrptr(i)->ccdr = 0;
823 tx4938_tmrptr(i)->pgmr = 0;
827 TX4938_WR64(0xff1fb150, TX4938_DMA_MCR_MSTEN);
828 TX4938_WR64(0xff1fb950, TX4938_DMA_MCR_MSTEN);
831 tx4938_pioptr->maskcpu = 0;
832 tx4938_pioptr->maskext = 0;
834 /* TX4938 internal registers */
835 if (request_resource(&iomem_resource, &tx4938_reg_resource))
836 printk("request resource for internal registers failed\n");
840 static inline void tx4938_report_pcic_status1(struct tx4938_pcic_reg *pcicptr)
842 unsigned short pcistatus = (unsigned short)(pcicptr->pcistatus >> 16);
843 unsigned long g2pstatus = pcicptr->g2pstatus;
844 unsigned long pcicstatus = pcicptr->pcicstatus;
849 { PCI_STATUS_DETECTED_PARITY, "DetectedParityError" },
850 { PCI_STATUS_SIG_SYSTEM_ERROR, "SignaledSystemError" },
851 { PCI_STATUS_REC_MASTER_ABORT, "ReceivedMasterAbort" },
852 { PCI_STATUS_REC_TARGET_ABORT, "ReceivedTargetAbort" },
853 { PCI_STATUS_SIG_TARGET_ABORT, "SignaledTargetAbort" },
854 { PCI_STATUS_PARITY, "MasterParityError" },
856 { TX4938_PCIC_G2PSTATUS_TTOE, "TIOE" },
857 { TX4938_PCIC_G2PSTATUS_RTOE, "RTOE" },
858 }, pcicstat_tbl[] = {
859 { TX4938_PCIC_PCICSTATUS_PME, "PME" },
860 { TX4938_PCIC_PCICSTATUS_TLB, "TLB" },
861 { TX4938_PCIC_PCICSTATUS_NIB, "NIB" },
862 { TX4938_PCIC_PCICSTATUS_ZIB, "ZIB" },
863 { TX4938_PCIC_PCICSTATUS_PERR, "PERR" },
864 { TX4938_PCIC_PCICSTATUS_SERR, "SERR" },
865 { TX4938_PCIC_PCICSTATUS_GBE, "GBE" },
866 { TX4938_PCIC_PCICSTATUS_IWB, "IWB" },
870 printk("pcistat:%04x(", pcistatus);
871 for (i = 0; i < ARRAY_SIZE(pcistat_tbl); i++)
872 if (pcistatus & pcistat_tbl[i].flag)
873 printk("%s ", pcistat_tbl[i].str);
874 printk("), g2pstatus:%08lx(", g2pstatus);
875 for (i = 0; i < ARRAY_SIZE(g2pstat_tbl); i++)
876 if (g2pstatus & g2pstat_tbl[i].flag)
877 printk("%s ", g2pstat_tbl[i].str);
878 printk("), pcicstatus:%08lx(", pcicstatus);
879 for (i = 0; i < ARRAY_SIZE(pcicstat_tbl); i++)
880 if (pcicstatus & pcicstat_tbl[i].flag)
881 printk("%s ", pcicstat_tbl[i].str);
885 void tx4938_report_pcic_status(void)
888 struct tx4938_pcic_reg *pcicptr;
889 for (i = 0; (pcicptr = get_tx4938_pcicptr(i)) != NULL; i++)
890 tx4938_report_pcic_status1(pcicptr);
893 #endif /* CONFIG_PCI */
895 /* We use onchip r4k counter or TMR timer as our system wide timer
896 * interrupt running at 100HZ. */
898 extern void __init rtc_rx5c348_init(int chipid);
899 void __init rbtx4938_time_init(void)
901 rtc_rx5c348_init(RBTX4938_SRTC_CHIPID);
902 mips_hpt_frequency = txx9_cpu_clock / 2;
905 void __init toshiba_rbtx4938_setup(void)
907 unsigned long long pcfg;
910 iomem_resource.end = 0xffffffff; /* 4GB */
912 if (txx9_master_clock == 0)
913 txx9_master_clock = 25000000; /* 25MHz */
914 tx4938_board_setup();
915 /* setup irq stuff */
916 TX4938_WR(TX4938_MKA(TX4938_IRC_IRDM0), 0x00000000); /* irq trigger */
917 TX4938_WR(TX4938_MKA(TX4938_IRC_IRDM1), 0x00000000); /* irq trigger */
918 /* setup serial stuff */
919 TX4938_WR(0xff1ff314, 0x00000000); /* h/w flow control off */
920 TX4938_WR(0xff1ff414, 0x00000000); /* h/w flow control off */
923 set_io_port_base(RBTX4938_ETHER_BASE);
926 #ifdef CONFIG_SERIAL_TXX9
928 extern int early_serial_txx9_setup(struct uart_port *port);
930 struct uart_port req;
931 for(i = 0; i < 2; i++) {
932 memset(&req, 0, sizeof(req));
934 req.iotype = UPIO_MEM;
935 req.membase = (char *)(0xff1ff300 + i * 0x100);
936 req.mapbase = 0xff1ff300 + i * 0x100;
938 req.flags |= UPF_BUGGY_UART /*HAVE_CTS_LINE*/;
939 req.uartclk = 50000000;
940 early_serial_txx9_setup(&req);
943 #ifdef CONFIG_SERIAL_TXX9_CONSOLE
944 argptr = prom_getcmdline();
945 if (strstr(argptr, "console=") == NULL) {
946 strcat(argptr, " console=ttyS0,38400");
951 #ifdef CONFIG_TOSHIBA_RBTX4938_MPLEX_PIO58_61
952 printk("PIOSEL: disabling both ata and nand selection\n");
954 tx4938_ccfgptr->pcfg &= ~(TX4938_PCFG_NDF_SEL | TX4938_PCFG_ATA_SEL);
957 #ifdef CONFIG_TOSHIBA_RBTX4938_MPLEX_NAND
958 printk("PIOSEL: enabling nand selection\n");
959 tx4938_ccfgptr->pcfg |= TX4938_PCFG_NDF_SEL;
960 tx4938_ccfgptr->pcfg &= ~TX4938_PCFG_ATA_SEL;
963 #ifdef CONFIG_TOSHIBA_RBTX4938_MPLEX_ATA
964 printk("PIOSEL: enabling ata selection\n");
965 tx4938_ccfgptr->pcfg |= TX4938_PCFG_ATA_SEL;
966 tx4938_ccfgptr->pcfg &= ~TX4938_PCFG_NDF_SEL;
970 argptr = prom_getcmdline();
971 if (strstr(argptr, "ip=") == NULL) {
972 strcat(argptr, " ip=any");
979 conswitchp = &dummy_con;
983 rbtx4938_spi_setup();
984 pcfg = tx4938_ccfgptr->pcfg; /* updated */
986 if ((pcfg & (TX4938_PCFG_ATA_SEL | TX4938_PCFG_NDF_SEL)) ==
987 TX4938_PCFG_ATA_SEL) {
988 *rbtx4938_piosel_ptr = (*rbtx4938_piosel_ptr & 0x03) | 0x04;
990 else if ((pcfg & (TX4938_PCFG_ATA_SEL | TX4938_PCFG_NDF_SEL)) ==
991 TX4938_PCFG_NDF_SEL) {
992 *rbtx4938_piosel_ptr = (*rbtx4938_piosel_ptr & 0x03) | 0x08;
995 *rbtx4938_piosel_ptr &= ~(0x08 | 0x04);
998 rbtx4938_fpga_resource.name = "FPGA Registers";
999 rbtx4938_fpga_resource.start = CPHYSADDR(RBTX4938_FPGA_REG_ADDR);
1000 rbtx4938_fpga_resource.end = CPHYSADDR(RBTX4938_FPGA_REG_ADDR) + 0xffff;
1001 rbtx4938_fpga_resource.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
1002 if (request_resource(&iomem_resource, &rbtx4938_fpga_resource))
1003 printk("request resource for fpga failed\n");
1005 /* disable all OnBoard I/O interrupts */
1006 *rbtx4938_imask_ptr = 0;
1008 _machine_restart = rbtx4938_machine_restart;
1009 _machine_halt = rbtx4938_machine_halt;
1010 pm_power_off = rbtx4938_machine_power_off;
1012 *rbtx4938_led_ptr = 0xff;
1013 printk("RBTX4938 --- FPGA(Rev %02x)", *rbtx4938_fpga_rev_ptr);
1014 printk(" DIPSW:%02x,%02x\n",
1015 *rbtx4938_dipsw_ptr, *rbtx4938_bdipsw_ptr);
1018 #ifdef CONFIG_PROC_FS
1019 extern void spi_eeprom_proc_create(struct proc_dir_entry *dir, int chipid);
1020 static int __init tx4938_spi_proc_setup(void)
1022 struct proc_dir_entry *tx4938_spi_eeprom_dir;
1024 tx4938_spi_eeprom_dir = proc_mkdir("spi_eeprom", 0);
1026 if (!tx4938_spi_eeprom_dir)
1029 /* don't allow user access to RBTX4938_SEEPROM1_CHIPID
1030 * as it contains eth0 and eth1 MAC addresses
1032 spi_eeprom_proc_create(tx4938_spi_eeprom_dir, RBTX4938_SEEPROM2_CHIPID);
1033 spi_eeprom_proc_create(tx4938_spi_eeprom_dir, RBTX4938_SEEPROM3_CHIPID);
1038 __initcall(tx4938_spi_proc_setup);