ppc85xx_setup.c 9.9 KB

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