powerpmc250.c 8.4 KB

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