powerpmc250.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. /*
  2. * Board setup routines for Force PowerPMC-250 Processor PMC
  3. *
  4. * Author: Troy Benjegerdes <tbenjegerdes@mvista.com>
  5. * Borrowed heavily from prpmc750_*.c by
  6. * Matt Porter <mporter@mvista.com>
  7. *
  8. * 2001 (c) MontaVista, Software, Inc. This file is licensed under
  9. * the terms of the GNU General Public License version 2. This program
  10. * is licensed "as is" without any warranty of any kind, whether express
  11. * or implied.
  12. */
  13. #include <linux/stddef.h>
  14. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/errno.h>
  17. #include <linux/reboot.h>
  18. #include <linux/pci.h>
  19. #include <linux/kdev_t.h>
  20. #include <linux/types.h>
  21. #include <linux/major.h>
  22. #include <linux/initrd.h>
  23. #include <linux/console.h>
  24. #include <linux/delay.h>
  25. #include <linux/slab.h>
  26. #include <linux/seq_file.h>
  27. #include <linux/ide.h>
  28. #include <linux/root_dev.h>
  29. #include <asm/byteorder.h>
  30. #include <asm/system.h>
  31. #include <asm/pgtable.h>
  32. #include <asm/page.h>
  33. #include <asm/dma.h>
  34. #include <asm/io.h>
  35. #include <asm/irq.h>
  36. #include <asm/machdep.h>
  37. #include <asm/time.h>
  38. #include <platforms/powerpmc250.h>
  39. #include <asm/open_pic.h>
  40. #include <asm/pci-bridge.h>
  41. #include <asm/mpc10x.h>
  42. #include <asm/uaccess.h>
  43. #include <asm/bootinfo.h>
  44. extern void powerpmc250_find_bridges(void);
  45. extern unsigned long loops_per_jiffy;
  46. static u_char powerpmc250_openpic_initsenses[] __initdata =
  47. {
  48. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  49. 1, /* PMC INTA (also MPC107 output interrupt INTA) */
  50. 1, /* PMC INTB (also I82559 Ethernet controller) */
  51. 1, /* PMC INTC */
  52. 1, /* PMC INTD */
  53. 0, /* DUART interrupt (active high) */
  54. };
  55. static int
  56. powerpmc250_show_cpuinfo(struct seq_file *m)
  57. {
  58. seq_printf(m,"machine\t\t: Force PowerPMC250\n");
  59. return 0;
  60. }
  61. static void __init
  62. powerpmc250_setup_arch(void)
  63. {
  64. /* init to some ~sane value until calibrate_delay() runs */
  65. loops_per_jiffy = 50000000/HZ;
  66. /* Lookup PCI host bridges */
  67. powerpmc250_find_bridges();
  68. #ifdef CONFIG_BLK_DEV_INITRD
  69. if (initrd_start)
  70. ROOT_DEV = Root_RAM0;
  71. else
  72. #endif
  73. #ifdef CONFIG_ROOT_NFS
  74. ROOT_DEV = Root_NFS;
  75. #else
  76. ROOT_DEV = Root_SDA2;
  77. #endif
  78. printk("Force PowerPMC250 port (C) 2001 MontaVista Software, Inc. (source@mvista.com)\n");
  79. }
  80. #if 0
  81. /*
  82. * Compute the PrPMC750's bus speed using the baud clock as a
  83. * reference.
  84. */
  85. unsigned long __init powerpmc250_get_bus_speed(void)
  86. {
  87. unsigned long tbl_start, tbl_end;
  88. unsigned long current_state, old_state, bus_speed;
  89. unsigned char lcr, dll, dlm;
  90. int baud_divisor, count;
  91. /* Read the UART's baud clock divisor */
  92. lcr = readb(PRPMC750_SERIAL_0_LCR);
  93. writeb(lcr | UART_LCR_DLAB, PRPMC750_SERIAL_0_LCR);
  94. dll = readb(PRPMC750_SERIAL_0_DLL);
  95. dlm = readb(PRPMC750_SERIAL_0_DLM);
  96. writeb(lcr & ~UART_LCR_DLAB, PRPMC750_SERIAL_0_LCR);
  97. baud_divisor = (dlm << 8) | dll;
  98. /*
  99. * Use the baud clock divisor and base baud clock
  100. * to determine the baud rate and use that as
  101. * the number of baud clock edges we use for
  102. * the time base sample. Make it half the baud
  103. * rate.
  104. */
  105. count = PRPMC750_BASE_BAUD / (baud_divisor * 16);
  106. /* Find the first edge of the baud clock */
  107. old_state = readb(PRPMC750_STATUS_REG) & PRPMC750_BAUDOUT_MASK;
  108. do {
  109. current_state = readb(PRPMC750_STATUS_REG) &
  110. PRPMC750_BAUDOUT_MASK;
  111. } while(old_state == current_state);
  112. old_state = current_state;
  113. /* Get the starting time base value */
  114. tbl_start = get_tbl();
  115. /*
  116. * Loop until we have found a number of edges equal
  117. * to half the count (half the baud rate)
  118. */
  119. do {
  120. do {
  121. current_state = readb(PRPMC750_STATUS_REG) &
  122. PRPMC750_BAUDOUT_MASK;
  123. } while(old_state == current_state);
  124. old_state = current_state;
  125. } while (--count);
  126. /* Get the ending time base value */
  127. tbl_end = get_tbl();
  128. /* Compute bus speed */
  129. bus_speed = (tbl_end-tbl_start)*128;
  130. return bus_speed;
  131. }
  132. #endif
  133. static void __init
  134. powerpmc250_calibrate_decr(void)
  135. {
  136. unsigned long freq;
  137. int divisor = 4;
  138. //freq = powerpmc250_get_bus_speed();
  139. #warning hardcoded bus freq
  140. freq = 100000000;
  141. tb_ticks_per_jiffy = freq / (HZ * divisor);
  142. tb_to_us = mulhwu_scale_factor(freq/divisor, 1000000);
  143. }
  144. static void
  145. powerpmc250_restart(char *cmd)
  146. {
  147. local_irq_disable();
  148. /* Hard reset */
  149. writeb(0x11, 0xfe000332);
  150. while(1);
  151. }
  152. static void
  153. powerpmc250_halt(void)
  154. {
  155. local_irq_disable();
  156. while (1);
  157. }
  158. static void
  159. powerpmc250_power_off(void)
  160. {
  161. powerpmc250_halt();
  162. }
  163. static void __init
  164. powerpmc250_init_IRQ(void)
  165. {
  166. OpenPIC_InitSenses = powerpmc250_openpic_initsenses;
  167. OpenPIC_NumInitSenses = sizeof(powerpmc250_openpic_initsenses);
  168. mpc10x_set_openpic();
  169. }
  170. /*
  171. * Set BAT 3 to map 0xf0000000 to end of physical memory space.
  172. */
  173. static __inline__ void
  174. powerpmc250_set_bat(void)
  175. {
  176. unsigned long bat3u, bat3l;
  177. static int mapping_set = 0;
  178. if (!mapping_set)
  179. {
  180. __asm__ __volatile__(
  181. " lis %0,0xf000\n \
  182. ori %1,%0,0x002a\n \
  183. ori %0,%0,0x1ffe\n \
  184. mtspr 0x21e,%0\n \
  185. mtspr 0x21f,%1\n \
  186. isync\n \
  187. sync "
  188. : "=r" (bat3u), "=r" (bat3l));
  189. mapping_set = 1;
  190. }
  191. return;
  192. }
  193. static unsigned long __init
  194. powerpmc250_find_end_of_memory(void)
  195. {
  196. /* Cover I/O space with a BAT */
  197. /* yuck, better hope your ram size is a power of 2 -- paulus */
  198. powerpmc250_set_bat();
  199. return mpc10x_get_mem_size(MPC10X_MEM_MAP_B);
  200. }
  201. static void __init
  202. powerpmc250_map_io(void)
  203. {
  204. io_block_mapping(0xfe000000, 0xfe000000, 0x02000000, _PAGE_IO);
  205. }
  206. void __init
  207. platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  208. unsigned long r6, unsigned long r7)
  209. {
  210. parse_bootinfo(find_bootinfo());
  211. #ifdef CONFIG_BLK_DEV_INITRD
  212. if ( r4 )
  213. {
  214. initrd_start = r4 + KERNELBASE;
  215. initrd_end = r5 + KERNELBASE;
  216. }
  217. #endif
  218. /* Copy cmd_line parameters */
  219. if ( r6)
  220. {
  221. *(char *)(r7 + KERNELBASE) = 0;
  222. strcpy(cmd_line, (char *)(r6 + KERNELBASE));
  223. }
  224. isa_io_base = MPC10X_MAPB_ISA_IO_BASE;
  225. isa_mem_base = MPC10X_MAPB_ISA_MEM_BASE;
  226. pci_dram_offset = MPC10X_MAPB_DRAM_OFFSET;
  227. ppc_md.setup_arch = powerpmc250_setup_arch;
  228. ppc_md.show_cpuinfo = powerpmc250_show_cpuinfo;
  229. ppc_md.init_IRQ = powerpmc250_init_IRQ;
  230. ppc_md.get_irq = openpic_get_irq;
  231. ppc_md.find_end_of_memory = powerpmc250_find_end_of_memory;
  232. ppc_md.setup_io_mappings = powerpmc250_map_io;
  233. ppc_md.restart = powerpmc250_restart;
  234. ppc_md.power_off = powerpmc250_power_off;
  235. ppc_md.halt = powerpmc250_halt;
  236. /* PowerPMC250 has no timekeeper part */
  237. ppc_md.time_init = NULL;
  238. ppc_md.get_rtc_time = NULL;
  239. ppc_md.set_rtc_time = NULL;
  240. ppc_md.calibrate_decr = powerpmc250_calibrate_decr;
  241. }
  242. /*
  243. * (This used to be arch/ppc/platforms/powerpmc250_pci.c)
  244. *
  245. * PCI support for Force PowerPMC250
  246. *
  247. */
  248. #undef DEBUG
  249. #ifdef DEBUG
  250. #define DBG(x...) printk(x)
  251. #else
  252. #define DBG(x...)
  253. #endif /* DEBUG */
  254. static inline int __init
  255. powerpmc250_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
  256. {
  257. static char pci_irq_table[][4] =
  258. /*
  259. * PCI IDSEL/INTPIN->INTLINE
  260. * A B C D
  261. */
  262. {
  263. {17, 0, 0, 0}, /* Device 11 - 82559 */
  264. {0, 0, 0, 0}, /* 12 */
  265. {0, 0, 0, 0}, /* 13 */
  266. {0, 0, 0, 0}, /* 14 */
  267. {0, 0, 0, 0}, /* 15 */
  268. {16, 17, 18, 19}, /* Device 16 - PMC A1?? */
  269. };
  270. const long min_idsel = 11, max_idsel = 16, irqs_per_slot = 4;
  271. return PCI_IRQ_TABLE_LOOKUP;
  272. };
  273. static int
  274. powerpmc250_exclude_device(u_char bus, u_char devfn)
  275. {
  276. /*
  277. * While doing PCI Scan the MPC107 will 'detect' itself as
  278. * device on the PCI Bus, will create an incorrect response and
  279. * later will respond incorrectly to Configuration read coming
  280. * from another device.
  281. *
  282. * The work around is that when doing a PCI Scan one
  283. * should skip its own device number in the scan.
  284. *
  285. * The top IDsel is AD13 and the middle is AD14.
  286. *
  287. * -- Note from force
  288. */
  289. if ((bus == 0) && (PCI_SLOT(devfn) == 13 || PCI_SLOT(devfn) == 14)) {
  290. return PCIBIOS_DEVICE_NOT_FOUND;
  291. }
  292. else {
  293. return PCIBIOS_SUCCESSFUL;
  294. }
  295. }
  296. void __init
  297. powerpmc250_find_bridges(void)
  298. {
  299. struct pci_controller* hose;
  300. hose = pcibios_alloc_controller();
  301. if (!hose){
  302. printk("Can't allocate PCI 'hose' structure!!!\n");
  303. return;
  304. }
  305. hose->first_busno = 0;
  306. hose->last_busno = 0xff;
  307. if (mpc10x_bridge_init(hose,
  308. MPC10X_MEM_MAP_B,
  309. MPC10X_MEM_MAP_B,
  310. MPC10X_MAPB_EUMB_BASE) == 0) {
  311. hose->mem_resources[0].end = 0xffffffff;
  312. hose->last_busno = pciauto_bus_scan(hose, hose->first_busno);
  313. /* ppc_md.pcibios_fixup = pcore_pcibios_fixup; */
  314. ppc_md.pci_swizzle = common_swizzle;
  315. ppc_md.pci_exclude_device = powerpmc250_exclude_device;
  316. ppc_md.pci_map_irq = powerpmc250_map_irq;
  317. } else {
  318. if (ppc_md.progress)
  319. ppc_md.progress("Bridge init failed", 0x100);
  320. printk("Host bridge init failed\n");
  321. }
  322. }