ppc85xx_setup.c 10 KB

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