powerpmc250.c 8.5 KB

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