setup.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. /*
  2. * BRIEF MODULE DESCRIPTION
  3. * Momentum Computer Ocelot-C and -CS board dependent boot routines
  4. *
  5. * Copyright (C) 1996, 1997, 2001 Ralf Baechle
  6. * Copyright (C) 2000 RidgeRun, Inc.
  7. * Copyright (C) 2001 Red Hat, Inc.
  8. * Copyright (C) 2002 Momentum Computer
  9. *
  10. * Author: Matthew Dharm, Momentum Computer
  11. * mdharm@momenco.com
  12. *
  13. * Louis Hamilton, Red Hat, Inc.
  14. * hamilton@redhat.com [MIPS64 modifications]
  15. *
  16. * Author: RidgeRun, Inc.
  17. * glonnon@ridgerun.com, skranz@ridgerun.com, stevej@ridgerun.com
  18. *
  19. * Copyright 2001 MontaVista Software Inc.
  20. * Author: jsun@mvista.com or jsun@junsun.net
  21. *
  22. * This program is free software; you can redistribute it and/or modify it
  23. * under the terms of the GNU General Public License as published by the
  24. * Free Software Foundation; either version 2 of the License, or (at your
  25. * option) any later version.
  26. *
  27. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  28. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  29. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  30. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  31. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  32. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  33. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  34. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  35. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  36. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. * You should have received a copy of the GNU General Public License along
  39. * with this program; if not, write to the Free Software Foundation, Inc.,
  40. * 675 Mass Ave, Cambridge, MA 02139, USA.
  41. *
  42. */
  43. #include <linux/bcd.h>
  44. #include <linux/init.h>
  45. #include <linux/kernel.h>
  46. #include <linux/types.h>
  47. #include <linux/mm.h>
  48. #include <linux/swap.h>
  49. #include <linux/ioport.h>
  50. #include <linux/sched.h>
  51. #include <linux/interrupt.h>
  52. #include <linux/pci.h>
  53. #include <linux/pm.h>
  54. #include <linux/timex.h>
  55. #include <linux/vmalloc.h>
  56. #include <linux/mv643xx.h>
  57. #include <asm/time.h>
  58. #include <asm/bootinfo.h>
  59. #include <asm/page.h>
  60. #include <asm/io.h>
  61. #include <asm/irq.h>
  62. #include <asm/pci.h>
  63. #include <asm/processor.h>
  64. #include <asm/reboot.h>
  65. #include <asm/marvell.h>
  66. #include <linux/bootmem.h>
  67. #include <linux/blkdev.h>
  68. #include "ocelot_c_fpga.h"
  69. unsigned long marvell_base;
  70. unsigned int cpu_clock;
  71. /* These functions are used for rebooting or halting the machine*/
  72. extern void momenco_ocelot_restart(char *command);
  73. extern void momenco_ocelot_halt(void);
  74. extern void momenco_ocelot_power_off(void);
  75. void momenco_time_init(void);
  76. static char reset_reason;
  77. void add_wired_entry(unsigned long entrylo0, unsigned long entrylo1, unsigned long entryhi, unsigned long pagemask);
  78. static unsigned long ENTRYLO(unsigned long paddr)
  79. {
  80. return ((paddr & PAGE_MASK) |
  81. (_PAGE_PRESENT | __READABLE | __WRITEABLE | _PAGE_GLOBAL |
  82. _CACHE_UNCACHED)) >> 6;
  83. }
  84. /* setup code for a handoff from a version 2 PMON 2000 PROM */
  85. void PMON_v2_setup(void)
  86. {
  87. /* Some wired TLB entries for the MV64340 and perhiperals. The
  88. MV64340 is going to be hit on every IRQ anyway - there's
  89. absolutely no point in letting it be a random TLB entry, as
  90. it'll just cause needless churning of the TLB. And we use
  91. the other half for the serial port, which is just a PITA
  92. otherwise :)
  93. Device Physical Virtual
  94. MV64340 Internal Regs 0xf4000000 0xf4000000
  95. Ocelot-C[S] PLD (CS0) 0xfc000000 0xfc000000
  96. NVRAM (CS1) 0xfc800000 0xfc800000
  97. UARTs (CS2) 0xfd000000 0xfd000000
  98. Internal SRAM 0xfe000000 0xfe000000
  99. M-Systems DOC (CS3) 0xff000000 0xff000000
  100. */
  101. printk("PMON_v2_setup\n");
  102. #ifdef CONFIG_64BIT
  103. /* marvell and extra space */
  104. add_wired_entry(ENTRYLO(0xf4000000), ENTRYLO(0xf4010000), 0xfffffffff4000000, PM_64K);
  105. /* fpga, rtc, and uart */
  106. add_wired_entry(ENTRYLO(0xfc000000), ENTRYLO(0xfd000000), 0xfffffffffc000000, PM_16M);
  107. /* m-sys and internal SRAM */
  108. add_wired_entry(ENTRYLO(0xfe000000), ENTRYLO(0xff000000), 0xfffffffffe000000, PM_16M);
  109. marvell_base = 0xfffffffff4000000;
  110. #else
  111. /* marvell and extra space */
  112. add_wired_entry(ENTRYLO(0xf4000000), ENTRYLO(0xf4010000), 0xf4000000, PM_64K);
  113. /* fpga, rtc, and uart */
  114. add_wired_entry(ENTRYLO(0xfc000000), ENTRYLO(0xfd000000), 0xfc000000, PM_16M);
  115. /* m-sys and internal SRAM */
  116. add_wired_entry(ENTRYLO(0xfe000000), ENTRYLO(0xff000000), 0xfe000000, PM_16M);
  117. marvell_base = 0xf4000000;
  118. #endif
  119. }
  120. unsigned long m48t37y_get_time(void)
  121. {
  122. #ifdef CONFIG_64BIT
  123. unsigned char *rtc_base = (unsigned char*)0xfffffffffc800000;
  124. #else
  125. unsigned char* rtc_base = (unsigned char*)0xfc800000;
  126. #endif
  127. unsigned int year, month, day, hour, min, sec;
  128. unsigned long flags;
  129. spin_lock_irqsave(&rtc_lock, flags);
  130. /* stop the update */
  131. rtc_base[0x7ff8] = 0x40;
  132. year = BCD2BIN(rtc_base[0x7fff]);
  133. year += BCD2BIN(rtc_base[0x7ff1]) * 100;
  134. month = BCD2BIN(rtc_base[0x7ffe]);
  135. day = BCD2BIN(rtc_base[0x7ffd]);
  136. hour = BCD2BIN(rtc_base[0x7ffb]);
  137. min = BCD2BIN(rtc_base[0x7ffa]);
  138. sec = BCD2BIN(rtc_base[0x7ff9]);
  139. /* start the update */
  140. rtc_base[0x7ff8] = 0x00;
  141. spin_unlock_irqrestore(&rtc_lock, flags);
  142. return mktime(year, month, day, hour, min, sec);
  143. }
  144. int m48t37y_set_time(unsigned long sec)
  145. {
  146. #ifdef CONFIG_64BIT
  147. unsigned char* rtc_base = (unsigned char*)0xfffffffffc800000;
  148. #else
  149. unsigned char* rtc_base = (unsigned char*)0xfc800000;
  150. #endif
  151. struct rtc_time tm;
  152. unsigned long flags;
  153. /* convert to a more useful format -- note months count from 0 */
  154. to_tm(sec, &tm);
  155. tm.tm_mon += 1;
  156. spin_lock_irqsave(&rtc_lock, flags);
  157. /* enable writing */
  158. rtc_base[0x7ff8] = 0x80;
  159. /* year */
  160. rtc_base[0x7fff] = BIN2BCD(tm.tm_year % 100);
  161. rtc_base[0x7ff1] = BIN2BCD(tm.tm_year / 100);
  162. /* month */
  163. rtc_base[0x7ffe] = BIN2BCD(tm.tm_mon);
  164. /* day */
  165. rtc_base[0x7ffd] = BIN2BCD(tm.tm_mday);
  166. /* hour/min/sec */
  167. rtc_base[0x7ffb] = BIN2BCD(tm.tm_hour);
  168. rtc_base[0x7ffa] = BIN2BCD(tm.tm_min);
  169. rtc_base[0x7ff9] = BIN2BCD(tm.tm_sec);
  170. /* day of week -- not really used, but let's keep it up-to-date */
  171. rtc_base[0x7ffc] = BIN2BCD(tm.tm_wday + 1);
  172. /* disable writing */
  173. rtc_base[0x7ff8] = 0x00;
  174. spin_unlock_irqrestore(&rtc_lock, flags);
  175. return 0;
  176. }
  177. void __init plat_timer_setup(struct irqaction *irq)
  178. {
  179. setup_irq(7, irq);
  180. }
  181. void momenco_time_init(void)
  182. {
  183. #ifdef CONFIG_CPU_SR71000
  184. mips_hpt_frequency = cpu_clock;
  185. #elif defined(CONFIG_CPU_RM7000)
  186. mips_hpt_frequency = cpu_clock / 2;
  187. #else
  188. #error Unknown CPU for this board
  189. #endif
  190. printk("momenco_time_init cpu_clock=%d\n", cpu_clock);
  191. rtc_mips_get_time = m48t37y_get_time;
  192. rtc_mips_set_time = m48t37y_set_time;
  193. }
  194. void __init plat_mem_setup(void)
  195. {
  196. unsigned int tmpword;
  197. board_time_init = momenco_time_init;
  198. _machine_restart = momenco_ocelot_restart;
  199. _machine_halt = momenco_ocelot_halt;
  200. pm_power_off = momenco_ocelot_power_off;
  201. /*
  202. * initrd_start = (unsigned long)ocelot_initrd_start;
  203. * initrd_end = (unsigned long)ocelot_initrd_start + (ulong)ocelot_initrd_size;
  204. * initrd_below_start_ok = 1;
  205. */
  206. /* do handoff reconfiguration */
  207. PMON_v2_setup();
  208. /* shut down ethernet ports, just to be sure our memory doesn't get
  209. * corrupted by random ethernet traffic.
  210. */
  211. MV_WRITE(MV643XX_ETH_TRANSMIT_QUEUE_COMMAND_REG(0), 0xff << 8);
  212. MV_WRITE(MV643XX_ETH_TRANSMIT_QUEUE_COMMAND_REG(1), 0xff << 8);
  213. MV_WRITE(MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(0), 0xff << 8);
  214. MV_WRITE(MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(1), 0xff << 8);
  215. do {}
  216. while (MV_READ(MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(0)) & 0xff);
  217. do {}
  218. while (MV_READ(MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(1)) & 0xff);
  219. do {}
  220. while (MV_READ(MV643XX_ETH_TRANSMIT_QUEUE_COMMAND_REG(0)) & 0xff);
  221. do {}
  222. while (MV_READ(MV643XX_ETH_TRANSMIT_QUEUE_COMMAND_REG(1)) & 0xff);
  223. MV_WRITE(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(0),
  224. MV_READ(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(0)) & ~1);
  225. MV_WRITE(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(1),
  226. MV_READ(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(1)) & ~1);
  227. /* Turn off the Bit-Error LED */
  228. OCELOT_FPGA_WRITE(0x80, CLR);
  229. tmpword = OCELOT_FPGA_READ(BOARDREV);
  230. #ifdef CONFIG_CPU_SR71000
  231. if (tmpword < 26)
  232. printk("Momenco Ocelot-CS: Board Assembly Rev. %c\n",
  233. 'A'+tmpword);
  234. else
  235. printk("Momenco Ocelot-CS: Board Assembly Revision #0x%x\n",
  236. tmpword);
  237. #else
  238. if (tmpword < 26)
  239. printk("Momenco Ocelot-C: Board Assembly Rev. %c\n",
  240. 'A'+tmpword);
  241. else
  242. printk("Momenco Ocelot-C: Board Assembly Revision #0x%x\n",
  243. tmpword);
  244. #endif
  245. tmpword = OCELOT_FPGA_READ(FPGA_REV);
  246. printk("FPGA Rev: %d.%d\n", tmpword>>4, tmpword&15);
  247. tmpword = OCELOT_FPGA_READ(RESET_STATUS);
  248. printk("Reset reason: 0x%x\n", tmpword);
  249. switch (tmpword) {
  250. case 0x1:
  251. printk(" - Power-up reset\n");
  252. break;
  253. case 0x2:
  254. printk(" - Push-button reset\n");
  255. break;
  256. case 0x4:
  257. printk(" - cPCI bus reset\n");
  258. break;
  259. case 0x8:
  260. printk(" - Watchdog reset\n");
  261. break;
  262. case 0x10:
  263. printk(" - Software reset\n");
  264. break;
  265. default:
  266. printk(" - Unknown reset cause\n");
  267. }
  268. reset_reason = tmpword;
  269. OCELOT_FPGA_WRITE(0xff, RESET_STATUS);
  270. tmpword = OCELOT_FPGA_READ(CPCI_ID);
  271. printk("cPCI ID register: 0x%02x\n", tmpword);
  272. printk(" - Slot number: %d\n", tmpword & 0x1f);
  273. printk(" - PCI bus present: %s\n", tmpword & 0x40 ? "yes" : "no");
  274. printk(" - System Slot: %s\n", tmpword & 0x20 ? "yes" : "no");
  275. tmpword = OCELOT_FPGA_READ(BOARD_STATUS);
  276. printk("Board Status register: 0x%02x\n", tmpword);
  277. printk(" - User jumper: %s\n", (tmpword & 0x80)?"installed":"absent");
  278. printk(" - Boot flash write jumper: %s\n", (tmpword&0x40)?"installed":"absent");
  279. printk(" - L3 Cache size: %d MiB\n", (1<<((tmpword&12) >> 2))&~1);
  280. printk(" - SDRAM size: %d MiB\n", 1<<(6+(tmpword&3)));
  281. switch(tmpword &3) {
  282. case 3:
  283. /* 512MiB */
  284. add_memory_region(0x0, 0x200<<20, BOOT_MEM_RAM);
  285. break;
  286. case 2:
  287. /* 256MiB */
  288. add_memory_region(0x0, 0x100<<20, BOOT_MEM_RAM);
  289. break;
  290. case 1:
  291. /* 128MiB */
  292. add_memory_region(0x0, 0x80<<20, BOOT_MEM_RAM);
  293. break;
  294. case 0:
  295. /* 1GiB -- needs CONFIG_HIGHMEM */
  296. add_memory_region(0x0, 0x400<<20, BOOT_MEM_RAM);
  297. break;
  298. }
  299. }
  300. /*
  301. * This needs to be one of the first initcalls, because no I/O port access
  302. * can work before this
  303. */
  304. static int io_base_ioremap(void)
  305. {
  306. void __iomem * io_remap_range = ioremap(0xc0000000UL, 0x10000);
  307. if (!io_remap_range)
  308. panic("Could not ioremap I/O port range");
  309. set_io_port_base((unsigned long) io_remap_range);
  310. return 0;
  311. }
  312. module_init(io_base_ioremap);