PageRenderTime 25ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/arch/mips/ddb5xxx/ddb5477/setup.c

https://github.com/fzqing/linux-2.6
C | 407 lines | 241 code | 79 blank | 87 comment | 41 complexity | d56fcbd651198ad8ce56022f1af840c3 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, CC-BY-SA-3.0
  1. /*
  2. *
  3. * Copyright 2001 MontaVista Software Inc.
  4. * Author: jsun@mvista.com or jsun@junsun.net
  5. *
  6. * Copyright (C) 2004 by Ralf Baechle (ralf@linux-mips.org)
  7. *
  8. * arch/mips/ddb5xxx/ddb5477/setup.c
  9. * Setup file for DDB5477.
  10. *
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License as published by the
  13. * Free Software Foundation; either version 2 of the License, or (at your
  14. * option) any later version.
  15. */
  16. #include <linux/config.h>
  17. #include <linux/init.h>
  18. #include <linux/kernel.h>
  19. #include <linux/types.h>
  20. #include <linux/sched.h>
  21. #include <linux/pci.h>
  22. #include <linux/ide.h>
  23. #include <linux/fs.h>
  24. #include <linux/ioport.h>
  25. #include <linux/param.h> /* for HZ */
  26. #include <linux/major.h>
  27. #include <linux/kdev_t.h>
  28. #include <linux/root_dev.h>
  29. #include <asm/cpu.h>
  30. #include <asm/bootinfo.h>
  31. #include <asm/addrspace.h>
  32. #include <asm/time.h>
  33. #include <asm/bcache.h>
  34. #include <asm/irq.h>
  35. #include <asm/reboot.h>
  36. #include <asm/gdb-stub.h>
  37. #include <asm/traps.h>
  38. #include <asm/debug.h>
  39. #include <asm/ddb5xxx/ddb5xxx.h>
  40. #include "lcd44780.h"
  41. #define USE_CPU_COUNTER_TIMER /* whether we use cpu counter */
  42. #define SP_TIMER_BASE DDB_SPT1CTRL_L
  43. #define SP_TIMER_IRQ VRC5477_IRQ_SPT1
  44. static int bus_frequency = CONFIG_DDB5477_BUS_FREQUENCY*1000;
  45. static void ddb_machine_restart(char *command)
  46. {
  47. static void (*back_to_prom) (void) = (void (*)(void)) 0xbfc00000;
  48. u32 t;
  49. /* PCI cold reset */
  50. ddb_pci_reset_bus();
  51. /* CPU cold reset */
  52. t = ddb_in32(DDB_CPUSTAT);
  53. db_assert((t&1));
  54. ddb_out32(DDB_CPUSTAT, t);
  55. /* Call the PROM */
  56. back_to_prom();
  57. }
  58. static void ddb_machine_halt(void)
  59. {
  60. printk("DDB Vrc-5477 halted.\n");
  61. while (1);
  62. }
  63. static void ddb_machine_power_off(void)
  64. {
  65. printk("DDB Vrc-5477 halted. Please turn off the power.\n");
  66. while (1);
  67. }
  68. extern void rtc_ds1386_init(unsigned long base);
  69. static unsigned int __init detect_bus_frequency(unsigned long rtc_base)
  70. {
  71. unsigned int freq;
  72. unsigned char c;
  73. unsigned int t1, t2;
  74. unsigned i;
  75. ddb_out32(SP_TIMER_BASE, 0xffffffff);
  76. ddb_out32(SP_TIMER_BASE+4, 0x1);
  77. ddb_out32(SP_TIMER_BASE+8, 0xffffffff);
  78. /* check if rtc is running */
  79. c= *(volatile unsigned char*)rtc_base;
  80. for(i=0; (c == *(volatile unsigned char*)rtc_base) && (i<100000000); i++);
  81. if (c == *(volatile unsigned char*)rtc_base) {
  82. printk("Failed to detect bus frequency. Use default 83.3MHz.\n");
  83. return 83333000;
  84. }
  85. c= *(volatile unsigned char*)rtc_base;
  86. while (c == *(volatile unsigned char*)rtc_base);
  87. /* we are now at the turn of 1/100th second, if no error. */
  88. t1 = ddb_in32(SP_TIMER_BASE+8);
  89. for (i=0; i< 10; i++) {
  90. c= *(volatile unsigned char*)rtc_base;
  91. while (c == *(volatile unsigned char*)rtc_base);
  92. /* we are now at the turn of another 1/100th second */
  93. t2 = ddb_in32(SP_TIMER_BASE+8);
  94. }
  95. ddb_out32(SP_TIMER_BASE+4, 0x0); /* disable it again */
  96. freq = (t1 - t2)*10;
  97. printk("DDB bus frequency detection : %u \n", freq);
  98. return freq;
  99. }
  100. static void __init ddb_time_init(void)
  101. {
  102. unsigned long rtc_base;
  103. unsigned int i;
  104. /* we have ds1396 RTC chip */
  105. if (mips_machtype == MACH_NEC_ROCKHOPPER
  106. || mips_machtype == MACH_NEC_ROCKHOPPERII) {
  107. rtc_base = KSEG1ADDR(DDB_LCS2_BASE);
  108. } else {
  109. rtc_base = KSEG1ADDR(DDB_LCS1_BASE);
  110. }
  111. rtc_ds1386_init(rtc_base);
  112. /* do we need to do run-time detection of bus speed? */
  113. if (bus_frequency == 0) {
  114. bus_frequency = detect_bus_frequency(rtc_base);
  115. }
  116. /* mips_hpt_frequency is 1/2 of the cpu core freq */
  117. i = (read_c0_config() >> 28 ) & 7;
  118. if ((current_cpu_data.cputype == CPU_R5432) && (i == 3))
  119. i = 4;
  120. mips_hpt_frequency = bus_frequency*(i+4)/4;
  121. }
  122. extern int setup_irq(unsigned int irq, struct irqaction *irqaction);
  123. static void __init ddb_timer_setup(struct irqaction *irq)
  124. {
  125. #if defined(USE_CPU_COUNTER_TIMER)
  126. /* we are using the cpu counter for timer interrupts */
  127. setup_irq(CPU_IRQ_BASE + 7, irq);
  128. #else
  129. /* if we use Special purpose timer 1 */
  130. ddb_out32(SP_TIMER_BASE, bus_frequency/HZ);
  131. ddb_out32(SP_TIMER_BASE+4, 0x1);
  132. setup_irq(SP_TIMER_IRQ, irq);
  133. #endif
  134. }
  135. static void ddb5477_board_init(void);
  136. extern struct pci_controller ddb5477_ext_controller;
  137. extern struct pci_controller ddb5477_io_controller;
  138. static int ddb5477_setup(void)
  139. {
  140. extern int panic_timeout;
  141. /* initialize board - we don't trust the loader */
  142. ddb5477_board_init();
  143. set_io_port_base(KSEG1ADDR(DDB_PCI_IO_BASE));
  144. board_time_init = ddb_time_init;
  145. board_timer_setup = ddb_timer_setup;
  146. _machine_restart = ddb_machine_restart;
  147. _machine_halt = ddb_machine_halt;
  148. _machine_power_off = ddb_machine_power_off;
  149. /* setup resource limits */
  150. ioport_resource.end = DDB_PCI0_IO_SIZE + DDB_PCI1_IO_SIZE - 1;
  151. iomem_resource.end = 0xffffffff;
  152. /* Reboot on panic */
  153. panic_timeout = 180;
  154. register_pci_controller (&ddb5477_ext_controller);
  155. register_pci_controller (&ddb5477_io_controller);
  156. return 0;
  157. }
  158. early_initcall(ddb5477_setup);
  159. static void __init ddb5477_board_init(void)
  160. {
  161. /* ----------- setup PDARs ------------ */
  162. /* SDRAM should have been set */
  163. db_assert(ddb_in32(DDB_SDRAM0) ==
  164. ddb_calc_pdar(DDB_SDRAM_BASE, board_ram_size, 32, 0, 1));
  165. /* SDRAM1 should be turned off. What is this for anyway ? */
  166. db_assert( (ddb_in32(DDB_SDRAM1) & 0xf) == 0);
  167. /* Setup local bus. */
  168. /* Flash U12 PDAR and timing. */
  169. ddb_set_pdar(DDB_LCS0, DDB_LCS0_BASE, DDB_LCS0_SIZE, 16, 0, 0);
  170. ddb_out32(DDB_LCST0, 0x00090842);
  171. /* We need to setup LCS1 and LCS2 differently based on the
  172. board_version */
  173. if (mips_machtype == MACH_NEC_ROCKHOPPER) {
  174. /* Flash U13 PDAR and timing. */
  175. ddb_set_pdar(DDB_LCS1, DDB_LCS1_BASE, DDB_LCS1_SIZE, 16, 0, 0);
  176. ddb_out32(DDB_LCST1, 0x00090842);
  177. /* EPLD (NVRAM, switch, LCD, and mezzanie). */
  178. ddb_set_pdar(DDB_LCS2, DDB_LCS2_BASE, DDB_LCS2_SIZE, 8, 0, 0);
  179. } else {
  180. /* misc */
  181. ddb_set_pdar(DDB_LCS1, DDB_LCS1_BASE, DDB_LCS1_SIZE, 8, 0, 0);
  182. /* mezzanie (?) */
  183. ddb_set_pdar(DDB_LCS2, DDB_LCS2_BASE, DDB_LCS2_SIZE, 16, 0, 0);
  184. }
  185. /* verify VRC5477 base addr */
  186. db_assert(ddb_in32(DDB_VRC5477) ==
  187. ddb_calc_pdar(DDB_VRC5477_BASE, DDB_VRC5477_SIZE, 32, 0, 1));
  188. /* verify BOOT ROM addr */
  189. db_assert(ddb_in32(DDB_BOOTCS) ==
  190. ddb_calc_pdar(DDB_BOOTCS_BASE, DDB_BOOTCS_SIZE, 8, 0, 0));
  191. /* setup PCI windows - window0 for MEM/config, window1 for IO */
  192. ddb_set_pdar(DDB_PCIW0, DDB_PCI0_MEM_BASE, DDB_PCI0_MEM_SIZE, 32, 0, 1);
  193. ddb_set_pdar(DDB_PCIW1, DDB_PCI0_IO_BASE, DDB_PCI0_IO_SIZE, 32, 0, 1);
  194. ddb_set_pdar(DDB_IOPCIW0, DDB_PCI1_MEM_BASE, DDB_PCI1_MEM_SIZE, 32, 0, 1);
  195. ddb_set_pdar(DDB_IOPCIW1, DDB_PCI1_IO_BASE, DDB_PCI1_IO_SIZE, 32, 0, 1);
  196. /* ------------ reset PCI bus and BARs ----------------- */
  197. ddb_pci_reset_bus();
  198. ddb_out32(DDB_BARM010, 0x00000008);
  199. ddb_out32(DDB_BARM011, 0x00000008);
  200. ddb_out32(DDB_BARC0, 0xffffffff);
  201. ddb_out32(DDB_BARM230, 0xffffffff);
  202. ddb_out32(DDB_BAR00, 0xffffffff);
  203. ddb_out32(DDB_BAR10, 0xffffffff);
  204. ddb_out32(DDB_BAR20, 0xffffffff);
  205. ddb_out32(DDB_BAR30, 0xffffffff);
  206. ddb_out32(DDB_BAR40, 0xffffffff);
  207. ddb_out32(DDB_BAR50, 0xffffffff);
  208. ddb_out32(DDB_BARB0, 0xffffffff);
  209. ddb_out32(DDB_BARC1, 0xffffffff);
  210. ddb_out32(DDB_BARM231, 0xffffffff);
  211. ddb_out32(DDB_BAR01, 0xffffffff);
  212. ddb_out32(DDB_BAR11, 0xffffffff);
  213. ddb_out32(DDB_BAR21, 0xffffffff);
  214. ddb_out32(DDB_BAR31, 0xffffffff);
  215. ddb_out32(DDB_BAR41, 0xffffffff);
  216. ddb_out32(DDB_BAR51, 0xffffffff);
  217. ddb_out32(DDB_BARB1, 0xffffffff);
  218. /*
  219. * We use pci master register 0 for memory space / config space
  220. * And we use register 1 for IO space.
  221. * Note that for memory space, we bump up the pci base address
  222. * so that we have 1:1 mapping between PCI memory and cpu physical.
  223. * For PCI IO space, it starts from 0 in PCI IO space but with
  224. * DDB_xx_IO_BASE in CPU physical address space.
  225. */
  226. ddb_set_pmr(DDB_PCIINIT00, DDB_PCICMD_MEM, DDB_PCI0_MEM_BASE,
  227. DDB_PCI_ACCESS_32);
  228. ddb_set_pmr(DDB_PCIINIT10, DDB_PCICMD_IO, 0, DDB_PCI_ACCESS_32);
  229. ddb_set_pmr(DDB_PCIINIT01, DDB_PCICMD_MEM, DDB_PCI1_MEM_BASE,
  230. DDB_PCI_ACCESS_32);
  231. ddb_set_pmr(DDB_PCIINIT11, DDB_PCICMD_IO, DDB_PCI0_IO_SIZE,
  232. DDB_PCI_ACCESS_32);
  233. /* PCI cross window should be set properly */
  234. ddb_set_pdar(DDB_BARP00, DDB_PCI1_MEM_BASE, DDB_PCI1_MEM_SIZE, 32, 0, 1);
  235. ddb_set_pdar(DDB_BARP10, DDB_PCI1_IO_BASE, DDB_PCI1_IO_SIZE, 32, 0, 1);
  236. ddb_set_pdar(DDB_BARP01, DDB_PCI0_MEM_BASE, DDB_PCI0_MEM_SIZE, 32, 0, 1);
  237. ddb_set_pdar(DDB_BARP11, DDB_PCI0_IO_BASE, DDB_PCI0_IO_SIZE, 32, 0, 1);
  238. if (mips_machtype == MACH_NEC_ROCKHOPPER
  239. || mips_machtype == MACH_NEC_ROCKHOPPERII) {
  240. /* Disable bus diagnostics. */
  241. ddb_out32(DDB_PCICTL0_L, 0);
  242. ddb_out32(DDB_PCICTL0_H, 0);
  243. ddb_out32(DDB_PCICTL1_L, 0);
  244. ddb_out32(DDB_PCICTL1_H, 0);
  245. }
  246. if (mips_machtype == MACH_NEC_ROCKHOPPER) {
  247. u16 vid;
  248. struct pci_bus bus;
  249. struct pci_dev dev_m1533;
  250. extern struct pci_ops ddb5477_ext_pci_ops;
  251. bus.parent = NULL; /* we scan the top level only */
  252. bus.ops = &ddb5477_ext_pci_ops;
  253. dev_m1533.bus = &bus;
  254. dev_m1533.sysdata = NULL;
  255. dev_m1533.devfn = 7*8; // slot 7: M1533 SouthBridge.
  256. pci_read_config_word(&dev_m1533, 0, &vid);
  257. if (vid == PCI_VENDOR_ID_AL) {
  258. printk("Changing mips_machtype to MACH_NEC_ROCKHOPPERII\n");
  259. mips_machtype = MACH_NEC_ROCKHOPPERII;
  260. }
  261. }
  262. /* enable USB input buffers */
  263. ddb_out32(DDB_PIBMISC, 0x00000007);
  264. /* For dual-function pins, make them all non-GPIO */
  265. ddb_out32(DDB_GIUFUNSEL, 0x0);
  266. // ddb_out32(DDB_GIUFUNSEL, 0xfe0fcfff); /* NEC recommanded value */
  267. if (mips_machtype == MACH_NEC_ROCKHOPPERII) {
  268. /* enable IDE controller on Ali chip (south bridge) */
  269. u8 temp8;
  270. struct pci_bus bus;
  271. struct pci_dev dev_m1533;
  272. struct pci_dev dev_m5229;
  273. extern struct pci_ops ddb5477_ext_pci_ops;
  274. /* Setup M1535 registers */
  275. bus.parent = NULL; /* we scan the top level only */
  276. bus.ops = &ddb5477_ext_pci_ops;
  277. dev_m1533.bus = &bus;
  278. dev_m1533.sysdata = NULL;
  279. dev_m1533.devfn = 7*8; // slot 7: M1533 SouthBridge.
  280. /* setup IDE controller
  281. * enable IDE controller (bit 6 - 1)
  282. * IDE IDSEL to be addr:A15 (bit 4:5 - 11)
  283. * disable IDE ATA Secondary Bus Signal Pad Control (bit 3 - 0)
  284. * enable IDE ATA Primary Bus Signal Pad Control (bit 2 - 1)
  285. */
  286. pci_write_config_byte(&dev_m1533, 0x58, 0x74);
  287. /*
  288. * positive decode (bit6 -0)
  289. * enable IDE controler interrupt (bit 4 -1)
  290. * setup SIRQ to point to IRQ 14 (bit 3:0 - 1101)
  291. */
  292. pci_write_config_byte(&dev_m1533, 0x44, 0x1d);
  293. /* Setup M5229 registers */
  294. dev_m5229.bus = &bus;
  295. dev_m5229.sysdata = NULL;
  296. dev_m5229.devfn = 4*8; // slot 4 (AD15): M5229 IDE
  297. /*
  298. * enable IDE in the M5229 config register 0x50 (bit 0 - 1)
  299. * M5229 IDSEL is addr:15; see above setting
  300. */
  301. pci_read_config_byte(&dev_m5229, 0x50, &temp8);
  302. pci_write_config_byte(&dev_m5229, 0x50, temp8 | 0x1);
  303. /*
  304. * enable bus master (bit 2) and IO decoding (bit 0)
  305. */
  306. pci_read_config_byte(&dev_m5229, 0x04, &temp8);
  307. pci_write_config_byte(&dev_m5229, 0x04, temp8 | 0x5);
  308. /*
  309. * enable native, copied from arch/ppc/k2boot/head.S
  310. * TODO - need volatile, need to be portable
  311. */
  312. pci_write_config_byte(&dev_m5229, 0x09, 0xef);
  313. /* Set Primary Channel Command Block Timing */
  314. pci_write_config_byte(&dev_m5229, 0x59, 0x31);
  315. /*
  316. * Enable primary channel 40-pin cable
  317. * M5229 register 0x4a (bit 0)
  318. */
  319. pci_read_config_byte(&dev_m5229, 0x4a, &temp8);
  320. pci_write_config_byte(&dev_m5229, 0x4a, temp8 | 0x1);
  321. }
  322. if (mips_machtype == MACH_NEC_ROCKHOPPER
  323. || mips_machtype == MACH_NEC_ROCKHOPPERII) {
  324. printk("lcd44780: initializing\n");
  325. lcd44780_init();
  326. lcd44780_puts("MontaVista Linux");
  327. }
  328. }