ppc85xx_setup.c 9.4 KB

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