ppc85xx_setup.c 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. /*
  2. * MPC85XX common board code
  3. *
  4. * Maintainer: Kumar Gala <galak@kernel.crashing.org>
  5. *
  6. * Copyright 2004 Freescale Semiconductor Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. */
  13. #include <linux/config.h>
  14. #include <linux/types.h>
  15. #include <linux/module.h>
  16. #include <linux/init.h>
  17. #include <linux/pci.h>
  18. #include <linux/serial.h>
  19. #include <linux/tty.h> /* for linux/serial_core.h */
  20. #include <linux/serial_core.h>
  21. #include <linux/serial_8250.h>
  22. #include <asm/time.h>
  23. #include <asm/mpc85xx.h>
  24. #include <asm/immap_85xx.h>
  25. #include <asm/mmu.h>
  26. #include <asm/ppc_sys.h>
  27. #include <asm/kgdb.h>
  28. #include <asm/machdep.h>
  29. #include <syslib/ppc85xx_setup.h>
  30. extern void abort(void);
  31. /* Return the amount of memory */
  32. unsigned long __init
  33. mpc85xx_find_end_of_memory(void)
  34. {
  35. bd_t *binfo;
  36. binfo = (bd_t *) __res;
  37. return binfo->bi_memsize;
  38. }
  39. /* The decrementer counts at the system (internal) clock freq divided by 8 */
  40. void __init
  41. mpc85xx_calibrate_decr(void)
  42. {
  43. bd_t *binfo = (bd_t *) __res;
  44. unsigned int freq, divisor;
  45. /* get the core frequency */
  46. freq = binfo->bi_busfreq;
  47. /* The timebase is updated every 8 bus clocks, HID0[SEL_TBCLK] = 0 */
  48. divisor = 8;
  49. tb_ticks_per_jiffy = freq / divisor / HZ;
  50. tb_to_us = mulhwu_scale_factor(freq / divisor, 1000000);
  51. /* Set the time base to zero */
  52. mtspr(SPRN_TBWL, 0);
  53. mtspr(SPRN_TBWU, 0);
  54. /* Clear any pending timer interrupts */
  55. mtspr(SPRN_TSR, TSR_ENW | TSR_WIS | TSR_DIS | TSR_FIS);
  56. /* Enable decrementer interrupt */
  57. mtspr(SPRN_TCR, TCR_DIE);
  58. }
  59. #ifdef CONFIG_SERIAL_8250
  60. void __init
  61. mpc85xx_early_serial_map(void)
  62. {
  63. #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
  64. struct uart_port serial_req;
  65. #endif
  66. struct plat_serial8250_port *pdata;
  67. bd_t *binfo = (bd_t *) __res;
  68. pdata = (struct plat_serial8250_port *) ppc_sys_get_pdata(MPC85xx_DUART);
  69. /* Setup serial port access */
  70. pdata[0].uartclk = binfo->bi_busfreq;
  71. pdata[0].mapbase += binfo->bi_immr_base;
  72. pdata[0].membase = ioremap(pdata[0].mapbase, MPC85xx_UART0_SIZE);
  73. #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
  74. memset(&serial_req, 0, sizeof (serial_req));
  75. serial_req.iotype = UPIO_MEM;
  76. serial_req.mapbase = pdata[0].mapbase;
  77. serial_req.membase = pdata[0].membase;
  78. serial_req.regshift = 0;
  79. gen550_init(0, &serial_req);
  80. #endif
  81. pdata[1].uartclk = binfo->bi_busfreq;
  82. pdata[1].mapbase += binfo->bi_immr_base;
  83. pdata[1].membase = ioremap(pdata[1].mapbase, MPC85xx_UART0_SIZE);
  84. #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
  85. /* Assume gen550_init() doesn't modify serial_req */
  86. serial_req.mapbase = pdata[1].mapbase;
  87. serial_req.membase = pdata[1].membase;
  88. gen550_init(1, &serial_req);
  89. #endif
  90. }
  91. #endif
  92. void
  93. mpc85xx_restart(char *cmd)
  94. {
  95. local_irq_disable();
  96. abort();
  97. }
  98. void
  99. mpc85xx_power_off(void)
  100. {
  101. local_irq_disable();
  102. for(;;);
  103. }
  104. void
  105. mpc85xx_halt(void)
  106. {
  107. local_irq_disable();
  108. for(;;);
  109. }
  110. #ifdef CONFIG_PCI
  111. #if defined(CONFIG_MPC8555_CDS) || defined(CONFIG_MPC8548_CDS)
  112. extern void mpc85xx_cds_enable_via(struct pci_controller *hose);
  113. extern void mpc85xx_cds_fixup_via(struct pci_controller *hose);
  114. #endif
  115. static void __init
  116. mpc85xx_setup_pci1(struct pci_controller *hose)
  117. {
  118. volatile struct ccsr_pci *pci;
  119. volatile struct ccsr_guts *guts;
  120. unsigned short temps;
  121. bd_t *binfo = (bd_t *) __res;
  122. pci = ioremap(binfo->bi_immr_base + MPC85xx_PCI1_OFFSET,
  123. MPC85xx_PCI1_SIZE);
  124. guts = ioremap(binfo->bi_immr_base + MPC85xx_GUTS_OFFSET,
  125. MPC85xx_GUTS_SIZE);
  126. early_read_config_word(hose, 0, 0, PCI_COMMAND, &temps);
  127. temps |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  128. early_write_config_word(hose, 0, 0, PCI_COMMAND, temps);
  129. #define PORDEVSR_PCI (0x00800000) /* PCI Mode */
  130. if (guts->pordevsr & PORDEVSR_PCI) {
  131. early_write_config_byte(hose, 0, 0, PCI_LATENCY_TIMER, 0x80);
  132. } else {
  133. /* PCI-X init */
  134. temps = PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ
  135. | PCI_X_CMD_ERO | PCI_X_CMD_DPERR_E;
  136. early_write_config_word(hose, 0, 0, PCIX_COMMAND, temps);
  137. }
  138. /* Disable all windows (except powar0 since its ignored) */
  139. pci->powar1 = 0;
  140. pci->powar2 = 0;
  141. pci->powar3 = 0;
  142. pci->powar4 = 0;
  143. pci->piwar1 = 0;
  144. pci->piwar2 = 0;
  145. pci->piwar3 = 0;
  146. /* Setup Phys:PCI 1:1 outbound mem window @ MPC85XX_PCI1_LOWER_MEM */
  147. pci->potar1 = (MPC85XX_PCI1_LOWER_MEM >> 12) & 0x000fffff;
  148. pci->potear1 = 0x00000000;
  149. pci->powbar1 = (MPC85XX_PCI1_LOWER_MEM >> 12) & 0x000fffff;
  150. /* Enable, Mem R/W */
  151. pci->powar1 = 0x80044000 |
  152. (__ilog2(MPC85XX_PCI1_UPPER_MEM - MPC85XX_PCI1_LOWER_MEM + 1) - 1);
  153. /* Setup outbound IO windows @ MPC85XX_PCI1_IO_BASE */
  154. pci->potar2 = (MPC85XX_PCI1_LOWER_IO >> 12) & 0x000fffff;
  155. pci->potear2 = 0x00000000;
  156. pci->powbar2 = (MPC85XX_PCI1_IO_BASE >> 12) & 0x000fffff;
  157. /* Enable, IO R/W */
  158. pci->powar2 = 0x80088000 | (__ilog2(MPC85XX_PCI1_IO_SIZE) - 1);
  159. /* Setup 2G inbound Memory Window @ 0 */
  160. pci->pitar1 = 0x00000000;
  161. pci->piwbar1 = 0x00000000;
  162. pci->piwar1 = 0xa0f5501e; /* Enable, Prefetch, Local
  163. Mem, Snoop R/W, 2G */
  164. }
  165. extern int mpc85xx_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin);
  166. extern int mpc85xx_exclude_device(u_char bus, u_char devfn);
  167. #ifdef CONFIG_85xx_PCI2
  168. static void __init
  169. mpc85xx_setup_pci2(struct pci_controller *hose)
  170. {
  171. volatile struct ccsr_pci *pci;
  172. unsigned short temps;
  173. bd_t *binfo = (bd_t *) __res;
  174. pci = ioremap(binfo->bi_immr_base + MPC85xx_PCI2_OFFSET,
  175. MPC85xx_PCI2_SIZE);
  176. early_read_config_word(hose, hose->bus_offset, 0, PCI_COMMAND, &temps);
  177. temps |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  178. early_write_config_word(hose, hose->bus_offset, 0, PCI_COMMAND, temps);
  179. early_write_config_byte(hose, hose->bus_offset, 0, PCI_LATENCY_TIMER, 0x80);
  180. /* Disable all windows (except powar0 since its ignored) */
  181. pci->powar1 = 0;
  182. pci->powar2 = 0;
  183. pci->powar3 = 0;
  184. pci->powar4 = 0;
  185. pci->piwar1 = 0;
  186. pci->piwar2 = 0;
  187. pci->piwar3 = 0;
  188. /* Setup Phys:PCI 1:1 outbound mem window @ MPC85XX_PCI2_LOWER_MEM */
  189. pci->potar1 = (MPC85XX_PCI2_LOWER_MEM >> 12) & 0x000fffff;
  190. pci->potear1 = 0x00000000;
  191. pci->powbar1 = (MPC85XX_PCI2_LOWER_MEM >> 12) & 0x000fffff;
  192. /* Enable, Mem R/W */
  193. pci->powar1 = 0x80044000 |
  194. (__ilog2(MPC85XX_PCI2_UPPER_MEM - MPC85XX_PCI2_LOWER_MEM + 1) - 1);
  195. /* Setup outbound IO windows @ MPC85XX_PCI2_IO_BASE */
  196. pci->potar2 = (MPC85XX_PCI2_LOWER_IO >> 12) & 0x000fffff;
  197. pci->potear2 = 0x00000000;
  198. pci->powbar2 = (MPC85XX_PCI2_IO_BASE >> 12) & 0x000fffff;
  199. /* Enable, IO R/W */
  200. pci->powar2 = 0x80088000 | (__ilog2(MPC85XX_PCI2_IO_SIZE) - 1);
  201. /* Setup 2G inbound Memory Window @ 0 */
  202. pci->pitar1 = 0x00000000;
  203. pci->piwbar1 = 0x00000000;
  204. pci->piwar1 = 0xa0f5501e; /* Enable, Prefetch, Local
  205. Mem, Snoop R/W, 2G */
  206. }
  207. #endif /* CONFIG_85xx_PCI2 */
  208. int mpc85xx_pci1_last_busno = 0;
  209. void __init
  210. mpc85xx_setup_hose(void)
  211. {
  212. struct pci_controller *hose_a;
  213. #ifdef CONFIG_85xx_PCI2
  214. struct pci_controller *hose_b;
  215. #endif
  216. bd_t *binfo = (bd_t *) __res;
  217. hose_a = pcibios_alloc_controller();
  218. if (!hose_a)
  219. return;
  220. ppc_md.pci_swizzle = common_swizzle;
  221. ppc_md.pci_map_irq = mpc85xx_map_irq;
  222. hose_a->first_busno = 0;
  223. hose_a->bus_offset = 0;
  224. hose_a->last_busno = 0xff;
  225. setup_indirect_pci(hose_a, binfo->bi_immr_base + PCI1_CFG_ADDR_OFFSET,
  226. binfo->bi_immr_base + PCI1_CFG_DATA_OFFSET);
  227. hose_a->set_cfg_type = 1;
  228. mpc85xx_setup_pci1(hose_a);
  229. hose_a->pci_mem_offset = MPC85XX_PCI1_MEM_OFFSET;
  230. hose_a->mem_space.start = MPC85XX_PCI1_LOWER_MEM;
  231. hose_a->mem_space.end = MPC85XX_PCI1_UPPER_MEM;
  232. hose_a->io_space.start = MPC85XX_PCI1_LOWER_IO;
  233. hose_a->io_space.end = MPC85XX_PCI1_UPPER_IO;
  234. hose_a->io_base_phys = MPC85XX_PCI1_IO_BASE;
  235. #ifdef CONFIG_85xx_PCI2
  236. hose_a->io_base_virt = ioremap(MPC85XX_PCI1_IO_BASE,
  237. MPC85XX_PCI1_IO_SIZE +
  238. MPC85XX_PCI2_IO_SIZE);
  239. #else
  240. hose_a->io_base_virt = ioremap(MPC85XX_PCI1_IO_BASE,
  241. MPC85XX_PCI1_IO_SIZE);
  242. #endif
  243. isa_io_base = (unsigned long)hose_a->io_base_virt;
  244. /* setup resources */
  245. pci_init_resource(&hose_a->mem_resources[0],
  246. MPC85XX_PCI1_LOWER_MEM,
  247. MPC85XX_PCI1_UPPER_MEM,
  248. IORESOURCE_MEM, "PCI1 host bridge");
  249. pci_init_resource(&hose_a->io_resource,
  250. MPC85XX_PCI1_LOWER_IO,
  251. MPC85XX_PCI1_UPPER_IO,
  252. IORESOURCE_IO, "PCI1 host bridge");
  253. ppc_md.pci_exclude_device = mpc85xx_exclude_device;
  254. #if defined(CONFIG_MPC8555_CDS) || defined(CONFIG_MPC8548_CDS)
  255. /* Pre pciauto_bus_scan VIA init */
  256. mpc85xx_cds_enable_via(hose_a);
  257. #endif
  258. hose_a->last_busno = pciauto_bus_scan(hose_a, hose_a->first_busno);
  259. #if defined(CONFIG_MPC8555_CDS) || defined(CONFIG_MPC8548_CDS)
  260. /* Post pciauto_bus_scan VIA fixup */
  261. mpc85xx_cds_fixup_via(hose_a);
  262. #endif
  263. #ifdef CONFIG_85xx_PCI2
  264. hose_b = pcibios_alloc_controller();
  265. if (!hose_b)
  266. return;
  267. hose_b->bus_offset = hose_a->last_busno + 1;
  268. hose_b->first_busno = hose_a->last_busno + 1;
  269. hose_b->last_busno = 0xff;
  270. setup_indirect_pci(hose_b, binfo->bi_immr_base + PCI2_CFG_ADDR_OFFSET,
  271. binfo->bi_immr_base + PCI2_CFG_DATA_OFFSET);
  272. hose_b->set_cfg_type = 1;
  273. mpc85xx_setup_pci2(hose_b);
  274. hose_b->pci_mem_offset = MPC85XX_PCI2_MEM_OFFSET;
  275. hose_b->mem_space.start = MPC85XX_PCI2_LOWER_MEM;
  276. hose_b->mem_space.end = MPC85XX_PCI2_UPPER_MEM;
  277. hose_b->io_space.start = MPC85XX_PCI2_LOWER_IO;
  278. hose_b->io_space.end = MPC85XX_PCI2_UPPER_IO;
  279. hose_b->io_base_phys = MPC85XX_PCI2_IO_BASE;
  280. hose_b->io_base_virt = hose_a->io_base_virt + MPC85XX_PCI1_IO_SIZE;
  281. /* setup resources */
  282. pci_init_resource(&hose_b->mem_resources[0],
  283. MPC85XX_PCI2_LOWER_MEM,
  284. MPC85XX_PCI2_UPPER_MEM,
  285. IORESOURCE_MEM, "PCI2 host bridge");
  286. pci_init_resource(&hose_b->io_resource,
  287. MPC85XX_PCI2_LOWER_IO,
  288. MPC85XX_PCI2_UPPER_IO,
  289. IORESOURCE_IO, "PCI2 host bridge");
  290. hose_b->last_busno = pciauto_bus_scan(hose_b, hose_b->first_busno);
  291. /* let board code know what the last bus number was on PCI1 */
  292. mpc85xx_pci1_last_busno = hose_a->last_busno;
  293. #endif
  294. return;
  295. }
  296. #endif /* CONFIG_PCI */