setup.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. /*
  2. * setup.c
  3. *
  4. * BRIEF MODULE DESCRIPTION
  5. * Momentum Computer Ocelot-3 board dependent boot routines
  6. *
  7. * Copyright (C) 1996, 1997, 01, 05 Ralf Baechle
  8. * Copyright (C) 2000 RidgeRun, Inc.
  9. * Copyright (C) 2001 Red Hat, Inc.
  10. * Copyright (C) 2002 Momentum Computer
  11. *
  12. * Author: Matthew Dharm, Momentum Computer
  13. * mdharm@momenco.com
  14. *
  15. * Louis Hamilton, Red Hat, Inc.
  16. * hamilton@redhat.com [MIPS64 modifications]
  17. *
  18. * Author: RidgeRun, Inc.
  19. * glonnon@ridgerun.com, skranz@ridgerun.com, stevej@ridgerun.com
  20. *
  21. * Copyright 2001 MontaVista Software Inc.
  22. * Author: jsun@mvista.com or jsun@junsun.net
  23. *
  24. * Copyright 2004 PMC-Sierra
  25. * Author: Manish Lachwani (lachwani@pmc-sierra.com)
  26. *
  27. * Copyright (C) 2004 MontaVista Software Inc.
  28. * Author: Manish Lachwani, mlachwani@mvista.com
  29. *
  30. * This program is free software; you can redistribute it and/or modify it
  31. * under the terms of the GNU General Public License as published by the
  32. * Free Software Foundation; either version 2 of the License, or (at your
  33. * option) any later version.
  34. *
  35. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  36. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  37. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  38. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  39. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  40. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  41. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  42. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  43. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  44. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45. *
  46. * You should have received a copy of the GNU General Public License along
  47. * with this program; if not, write to the Free Software Foundation, Inc.,
  48. * 675 Mass Ave, Cambridge, MA 02139, USA.
  49. */
  50. #include <linux/init.h>
  51. #include <linux/kernel.h>
  52. #include <linux/types.h>
  53. #include <linux/mc146818rtc.h>
  54. #include <linux/ioport.h>
  55. #include <linux/interrupt.h>
  56. #include <linux/pci.h>
  57. #include <linux/timex.h>
  58. #include <linux/bootmem.h>
  59. #include <linux/mv643xx.h>
  60. #include <linux/pm.h>
  61. #include <asm/time.h>
  62. #include <asm/page.h>
  63. #include <asm/bootinfo.h>
  64. #include <asm/io.h>
  65. #include <asm/irq.h>
  66. #include <asm/pci.h>
  67. #include <asm/processor.h>
  68. #include <asm/ptrace.h>
  69. #include <asm/reboot.h>
  70. #include <asm/mc146818rtc.h>
  71. #include <asm/tlbflush.h>
  72. #include "ocelot_3_fpga.h"
  73. /* Marvell Discovery Register Base */
  74. unsigned long marvell_base = (signed)0xf4000000;
  75. /* CPU clock */
  76. unsigned long cpu_clock;
  77. /* RTC/NVRAM */
  78. unsigned char* rtc_base = (unsigned char*)(signed)0xfc800000;
  79. /* FPGA Base */
  80. unsigned long ocelot_fpga_base = (signed)0xfc000000;
  81. /* Serial base */
  82. unsigned long uart_base = (signed)0xfd000000;
  83. /*
  84. * Marvell Discovery SRAM. This is one place where Ethernet
  85. * Tx and Rx descriptors can be placed to improve performance
  86. */
  87. extern unsigned long mv64340_sram_base;
  88. /* These functions are used for rebooting or halting the machine*/
  89. extern void momenco_ocelot_restart(char *command);
  90. extern void momenco_ocelot_halt(void);
  91. extern void momenco_ocelot_power_off(void);
  92. void momenco_time_init(void);
  93. static char reset_reason;
  94. void add_wired_entry(unsigned long entrylo0, unsigned long entrylo1,
  95. unsigned long entryhi, unsigned long pagemask);
  96. static inline unsigned long ENTRYLO(unsigned long paddr)
  97. {
  98. return ((paddr & PAGE_MASK) |
  99. (_PAGE_PRESENT | __READABLE | __WRITEABLE | _PAGE_GLOBAL |
  100. _CACHE_UNCACHED)) >> 6;
  101. }
  102. void __init bus_error_init(void)
  103. {
  104. /* nothing */
  105. }
  106. /*
  107. * setup code for a handoff from a version 2 PMON 2000 PROM
  108. */
  109. void setup_wired_tlb_entries(void)
  110. {
  111. write_c0_wired(0);
  112. local_flush_tlb_all();
  113. /* marvell and extra space */
  114. add_wired_entry(ENTRYLO(0xf4000000), ENTRYLO(0xf4010000), (signed)0xf4000000, PM_64K);
  115. /* fpga, rtc, and uart */
  116. add_wired_entry(ENTRYLO(0xfc000000), ENTRYLO(0xfd000000), (signed)0xfc000000, PM_16M);
  117. }
  118. #define CONV_BCD_TO_BIN(val) (((val) & 0xf) + (((val) >> 4) * 10))
  119. #define CONV_BIN_TO_BCD(val) (((val) % 10) + (((val) / 10) << 4))
  120. unsigned long m48t37y_get_time(void)
  121. {
  122. unsigned int year, month, day, hour, min, sec;
  123. unsigned long flags;
  124. spin_lock_irqsave(&rtc_lock, flags);
  125. /* stop the update */
  126. rtc_base[0x7ff8] = 0x40;
  127. year = CONV_BCD_TO_BIN(rtc_base[0x7fff]);
  128. year += CONV_BCD_TO_BIN(rtc_base[0x7ff1]) * 100;
  129. month = CONV_BCD_TO_BIN(rtc_base[0x7ffe]);
  130. day = CONV_BCD_TO_BIN(rtc_base[0x7ffd]);
  131. hour = CONV_BCD_TO_BIN(rtc_base[0x7ffb]);
  132. min = CONV_BCD_TO_BIN(rtc_base[0x7ffa]);
  133. sec = CONV_BCD_TO_BIN(rtc_base[0x7ff9]);
  134. /* start the update */
  135. rtc_base[0x7ff8] = 0x00;
  136. spin_unlock_irqrestore(&rtc_lock, flags);
  137. return mktime(year, month, day, hour, min, sec);
  138. }
  139. int m48t37y_set_time(unsigned long sec)
  140. {
  141. struct rtc_time tm;
  142. unsigned long flags;
  143. /* convert to a more useful format -- note months count from 0 */
  144. to_tm(sec, &tm);
  145. tm.tm_mon += 1;
  146. spin_lock_irqsave(&rtc_lock, flags);
  147. /* enable writing */
  148. rtc_base[0x7ff8] = 0x80;
  149. /* year */
  150. rtc_base[0x7fff] = CONV_BIN_TO_BCD(tm.tm_year % 100);
  151. rtc_base[0x7ff1] = CONV_BIN_TO_BCD(tm.tm_year / 100);
  152. /* month */
  153. rtc_base[0x7ffe] = CONV_BIN_TO_BCD(tm.tm_mon);
  154. /* day */
  155. rtc_base[0x7ffd] = CONV_BIN_TO_BCD(tm.tm_mday);
  156. /* hour/min/sec */
  157. rtc_base[0x7ffb] = CONV_BIN_TO_BCD(tm.tm_hour);
  158. rtc_base[0x7ffa] = CONV_BIN_TO_BCD(tm.tm_min);
  159. rtc_base[0x7ff9] = CONV_BIN_TO_BCD(tm.tm_sec);
  160. /* day of week -- not really used, but let's keep it up-to-date */
  161. rtc_base[0x7ffc] = CONV_BIN_TO_BCD(tm.tm_wday + 1);
  162. /* disable writing */
  163. rtc_base[0x7ff8] = 0x00;
  164. spin_unlock_irqrestore(&rtc_lock, flags);
  165. return 0;
  166. }
  167. void momenco_timer_setup(struct irqaction *irq)
  168. {
  169. setup_irq(7, irq); /* Timer interrupt, unmask status IM7 */
  170. }
  171. void momenco_time_init(void)
  172. {
  173. setup_wired_tlb_entries();
  174. /*
  175. * Ocelot-3 board has been built with both
  176. * the Rm7900 and the Rm7065C
  177. */
  178. mips_hpt_frequency = cpu_clock / 2;
  179. board_timer_setup = momenco_timer_setup;
  180. rtc_get_time = m48t37y_get_time;
  181. rtc_set_time = m48t37y_set_time;
  182. }
  183. /*
  184. * PCI Support for Ocelot-3
  185. */
  186. /* Bus #0 IO and MEM space */
  187. #define OCELOT_3_PCI_IO_0_START 0xe0000000
  188. #define OCELOT_3_PCI_IO_0_SIZE 0x08000000
  189. #define OCELOT_3_PCI_MEM_0_START 0xc0000000
  190. #define OCELOT_3_PCI_MEM_0_SIZE 0x10000000
  191. /* Bus #1 IO and MEM space */
  192. #define OCELOT_3_PCI_IO_1_START 0xe8000000
  193. #define OCELOT_3_PCI_IO_1_SIZE 0x08000000
  194. #define OCELOT_3_PCI_MEM_1_START 0xd0000000
  195. #define OCELOT_3_PCI_MEM_1_SIZE 0x10000000
  196. static struct resource mv_pci_io_mem0_resource = {
  197. .name = "MV64340 PCI0 IO MEM",
  198. .start = OCELOT_3_PCI_IO_0_START,
  199. .end = OCELOT_3_PCI_IO_0_START + OCELOT_3_PCI_IO_0_SIZE - 1,
  200. .flags = IORESOURCE_IO,
  201. };
  202. static struct resource mv_pci_io_mem1_resource = {
  203. .name = "MV64340 PCI1 IO MEM",
  204. .start = OCELOT_3_PCI_IO_1_START,
  205. .end = OCELOT_3_PCI_IO_1_START + OCELOT_3_PCI_IO_1_SIZE - 1,
  206. .flags = IORESOURCE_IO,
  207. };
  208. static struct resource mv_pci_mem0_resource = {
  209. .name = "MV64340 PCI0 MEM",
  210. .start = OCELOT_3_PCI_MEM_0_START,
  211. .end = OCELOT_3_PCI_MEM_0_START + OCELOT_3_PCI_MEM_0_SIZE - 1,
  212. .flags = IORESOURCE_MEM,
  213. };
  214. static struct resource mv_pci_mem1_resource = {
  215. .name = "MV64340 PCI1 MEM",
  216. .start = OCELOT_3_PCI_MEM_1_START,
  217. .end = OCELOT_3_PCI_MEM_1_START + OCELOT_3_PCI_MEM_1_SIZE - 1,
  218. .flags = IORESOURCE_MEM,
  219. };
  220. static struct mv_pci_controller mv_bus0_controller = {
  221. .pcic = {
  222. .pci_ops = &mv_pci_ops,
  223. .mem_resource = &mv_pci_mem0_resource,
  224. .io_resource = &mv_pci_io_mem0_resource,
  225. },
  226. .config_addr = MV64340_PCI_0_CONFIG_ADDR,
  227. .config_vreg = MV64340_PCI_0_CONFIG_DATA_VIRTUAL_REG,
  228. };
  229. static struct mv_pci_controller mv_bus1_controller = {
  230. .pcic = {
  231. .pci_ops = &mv_pci_ops,
  232. .mem_resource = &mv_pci_mem1_resource,
  233. .io_resource = &mv_pci_io_mem1_resource,
  234. },
  235. .config_addr = MV64340_PCI_1_CONFIG_ADDR,
  236. .config_vreg = MV64340_PCI_1_CONFIG_DATA_VIRTUAL_REG,
  237. };
  238. static __init int __init ja_pci_init(void)
  239. {
  240. uint32_t enable;
  241. extern int pci_probe_only;
  242. /* PMON will assign PCI resources */
  243. pci_probe_only = 1;
  244. enable = ~MV_READ(MV64340_BASE_ADDR_ENABLE);
  245. /*
  246. * We require at least one enabled I/O or PCI memory window or we
  247. * will ignore this PCI bus. We ignore PCI windows 1, 2 and 3.
  248. */
  249. if (enable & (0x01 << 9) || enable & (0x01 << 10))
  250. register_pci_controller(&mv_bus0_controller.pcic);
  251. if (enable & (0x01 << 14) || enable & (0x01 << 15))
  252. register_pci_controller(&mv_bus1_controller.pcic);
  253. ioport_resource.end = OCELOT_3_PCI_IO_0_START + OCELOT_3_PCI_IO_0_SIZE +
  254. OCELOT_3_PCI_IO_1_SIZE - 1;
  255. iomem_resource.end = OCELOT_3_PCI_MEM_0_START + OCELOT_3_PCI_MEM_0_SIZE +
  256. OCELOT_3_PCI_MEM_1_SIZE - 1;
  257. set_io_port_base(OCELOT_3_PCI_IO_0_START); /* mips_io_port_base */
  258. return 0;
  259. }
  260. arch_initcall(ja_pci_init);
  261. void __init plat_setup(void)
  262. {
  263. unsigned int tmpword;
  264. board_time_init = momenco_time_init;
  265. _machine_restart = momenco_ocelot_restart;
  266. _machine_halt = momenco_ocelot_halt;
  267. pm_power_off = momenco_ocelot_power_off;
  268. /* Wired TLB entries */
  269. setup_wired_tlb_entries();
  270. /* shut down ethernet ports, just to be sure our memory doesn't get
  271. * corrupted by random ethernet traffic.
  272. */
  273. MV_WRITE(MV64340_ETH_TRANSMIT_QUEUE_COMMAND_REG(0), 0xff << 8);
  274. MV_WRITE(MV64340_ETH_TRANSMIT_QUEUE_COMMAND_REG(1), 0xff << 8);
  275. MV_WRITE(MV64340_ETH_RECEIVE_QUEUE_COMMAND_REG(0), 0xff << 8);
  276. MV_WRITE(MV64340_ETH_RECEIVE_QUEUE_COMMAND_REG(1), 0xff << 8);
  277. do {}
  278. while (MV_READ(MV64340_ETH_RECEIVE_QUEUE_COMMAND_REG(0)) & 0xff);
  279. do {}
  280. while (MV_READ(MV64340_ETH_RECEIVE_QUEUE_COMMAND_REG(1)) & 0xff);
  281. do {}
  282. while (MV_READ(MV64340_ETH_TRANSMIT_QUEUE_COMMAND_REG(0)) & 0xff);
  283. do {}
  284. while (MV_READ(MV64340_ETH_TRANSMIT_QUEUE_COMMAND_REG(1)) & 0xff);
  285. MV_WRITE(MV64340_ETH_PORT_SERIAL_CONTROL_REG(0),
  286. MV_READ(MV64340_ETH_PORT_SERIAL_CONTROL_REG(0)) & ~1);
  287. MV_WRITE(MV64340_ETH_PORT_SERIAL_CONTROL_REG(1),
  288. MV_READ(MV64340_ETH_PORT_SERIAL_CONTROL_REG(1)) & ~1);
  289. /* Turn off the Bit-Error LED */
  290. OCELOT_FPGA_WRITE(0x80, CLR);
  291. tmpword = OCELOT_FPGA_READ(BOARDREV);
  292. if (tmpword < 26)
  293. printk("Momenco Ocelot-3: Board Assembly Rev. %c\n",
  294. 'A'+tmpword);
  295. else
  296. printk("Momenco Ocelot-3: Board Assembly Revision #0x%x\n",
  297. tmpword);
  298. tmpword = OCELOT_FPGA_READ(FPGA_REV);
  299. printk("FPGA Rev: %d.%d\n", tmpword>>4, tmpword&15);
  300. tmpword = OCELOT_FPGA_READ(RESET_STATUS);
  301. printk("Reset reason: 0x%x\n", tmpword);
  302. switch (tmpword) {
  303. case 0x1:
  304. printk(" - Power-up reset\n");
  305. break;
  306. case 0x2:
  307. printk(" - Push-button reset\n");
  308. break;
  309. case 0x4:
  310. printk(" - cPCI bus reset\n");
  311. break;
  312. case 0x8:
  313. printk(" - Watchdog reset\n");
  314. break;
  315. case 0x10:
  316. printk(" - Software reset\n");
  317. break;
  318. default:
  319. printk(" - Unknown reset cause\n");
  320. }
  321. reset_reason = tmpword;
  322. OCELOT_FPGA_WRITE(0xff, RESET_STATUS);
  323. tmpword = OCELOT_FPGA_READ(CPCI_ID);
  324. printk("cPCI ID register: 0x%02x\n", tmpword);
  325. printk(" - Slot number: %d\n", tmpword & 0x1f);
  326. printk(" - PCI bus present: %s\n", tmpword & 0x40 ? "yes" : "no");
  327. printk(" - System Slot: %s\n", tmpword & 0x20 ? "yes" : "no");
  328. tmpword = OCELOT_FPGA_READ(BOARD_STATUS);
  329. printk("Board Status register: 0x%02x\n", tmpword);
  330. printk(" - User jumper: %s\n", (tmpword & 0x80)?"installed":"absent");
  331. printk(" - Boot flash write jumper: %s\n", (tmpword&0x40)?"installed":"absent");
  332. printk(" - L3 cache size: %d MB\n", (1<<((tmpword&12) >> 2))&~1);
  333. /* Support for 128 MB memory */
  334. add_memory_region(0x0, 0x08000000, BOOT_MEM_RAM);
  335. }