ppc85xx_setup.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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/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 <syslib/ppc85xx_setup.h>
  31. extern void abort(void);
  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. #if defined(CONFIG_MPC8555_CDS) || defined(CONFIG_MPC8548_CDS)
  113. extern void mpc85xx_cds_enable_via(struct pci_controller *hose);
  114. extern void mpc85xx_cds_fixup_via(struct pci_controller *hose);
  115. #endif
  116. static void __init
  117. mpc85xx_setup_pci1(struct pci_controller *hose)
  118. {
  119. volatile struct ccsr_pci *pci;
  120. volatile struct ccsr_guts *guts;
  121. unsigned short temps;
  122. bd_t *binfo = (bd_t *) __res;
  123. pci = ioremap(binfo->bi_immr_base + MPC85xx_PCI1_OFFSET,
  124. MPC85xx_PCI1_SIZE);
  125. guts = ioremap(binfo->bi_immr_base + MPC85xx_GUTS_OFFSET,
  126. MPC85xx_GUTS_SIZE);
  127. early_read_config_word(hose, 0, 0, PCI_COMMAND, &temps);
  128. temps |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  129. early_write_config_word(hose, 0, 0, PCI_COMMAND, temps);
  130. #define PORDEVSR_PCI (0x00800000) /* PCI Mode */
  131. if (guts->pordevsr & PORDEVSR_PCI) {
  132. early_write_config_byte(hose, 0, 0, PCI_LATENCY_TIMER, 0x80);
  133. } else {
  134. /* PCI-X init */
  135. temps = PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ
  136. | PCI_X_CMD_ERO | PCI_X_CMD_DPERR_E;
  137. early_write_config_word(hose, 0, 0, PCIX_COMMAND, temps);
  138. }
  139. /* Disable all windows (except powar0 since its ignored) */
  140. pci->powar1 = 0;
  141. pci->powar2 = 0;
  142. pci->powar3 = 0;
  143. pci->powar4 = 0;
  144. pci->piwar1 = 0;
  145. pci->piwar2 = 0;
  146. pci->piwar3 = 0;
  147. /* Setup Phys:PCI 1:1 outbound mem window @ MPC85XX_PCI1_LOWER_MEM */
  148. pci->potar1 = (MPC85XX_PCI1_LOWER_MEM >> 12) & 0x000fffff;
  149. pci->potear1 = 0x00000000;
  150. pci->powbar1 = (MPC85XX_PCI1_LOWER_MEM >> 12) & 0x000fffff;
  151. /* Enable, Mem R/W */
  152. pci->powar1 = 0x80044000 |
  153. (__ilog2(MPC85XX_PCI1_UPPER_MEM - MPC85XX_PCI1_LOWER_MEM + 1) - 1);
  154. /* Setup outboud IO windows @ MPC85XX_PCI1_IO_BASE */
  155. pci->potar2 = 0x00000000;
  156. pci->potear2 = 0x00000000;
  157. pci->powbar2 = (MPC85XX_PCI1_IO_BASE >> 12) & 0x000fffff;
  158. /* Enable, IO R/W */
  159. pci->powar2 = 0x80088000 | (__ilog2(MPC85XX_PCI1_IO_SIZE) - 1);
  160. /* Setup 2G inbound Memory Window @ 0 */
  161. pci->pitar1 = 0x00000000;
  162. pci->piwbar1 = 0x00000000;
  163. pci->piwar1 = 0xa0f5501e; /* Enable, Prefetch, Local
  164. Mem, Snoop R/W, 2G */
  165. }
  166. extern int mpc85xx_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin);
  167. extern int mpc85xx_exclude_device(u_char bus, u_char devfn);
  168. #ifdef CONFIG_85xx_PCI2
  169. static void __init
  170. mpc85xx_setup_pci2(struct pci_controller *hose)
  171. {
  172. volatile struct ccsr_pci *pci;
  173. unsigned short temps;
  174. bd_t *binfo = (bd_t *) __res;
  175. pci = ioremap(binfo->bi_immr_base + MPC85xx_PCI2_OFFSET,
  176. MPC85xx_PCI2_SIZE);
  177. early_read_config_word(hose, hose->bus_offset, 0, PCI_COMMAND, &temps);
  178. temps |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  179. early_write_config_word(hose, hose->bus_offset, 0, PCI_COMMAND, temps);
  180. early_write_config_byte(hose, hose->bus_offset, 0, PCI_LATENCY_TIMER, 0x80);
  181. /* Disable all windows (except powar0 since its ignored) */
  182. pci->powar1 = 0;
  183. pci->powar2 = 0;
  184. pci->powar3 = 0;
  185. pci->powar4 = 0;
  186. pci->piwar1 = 0;
  187. pci->piwar2 = 0;
  188. pci->piwar3 = 0;
  189. /* Setup Phys:PCI 1:1 outbound mem window @ MPC85XX_PCI2_LOWER_MEM */
  190. pci->potar1 = (MPC85XX_PCI2_LOWER_MEM >> 12) & 0x000fffff;
  191. pci->potear1 = 0x00000000;
  192. pci->powbar1 = (MPC85XX_PCI2_LOWER_MEM >> 12) & 0x000fffff;
  193. /* Enable, Mem R/W */
  194. pci->powar1 = 0x80044000 |
  195. (__ilog2(MPC85XX_PCI2_UPPER_MEM - MPC85XX_PCI2_LOWER_MEM + 1) - 1);
  196. /* Setup outboud IO windows @ MPC85XX_PCI2_IO_BASE */
  197. pci->potar2 = 0x00000000;
  198. pci->potear2 = 0x00000000;
  199. pci->powbar2 = (MPC85XX_PCI2_IO_BASE >> 12) & 0x000fffff;
  200. /* Enable, IO R/W */
  201. pci->powar2 = 0x80088000 | (__ilog2(MPC85XX_PCI2_IO_SIZE) - 1);
  202. /* Setup 2G inbound Memory Window @ 0 */
  203. pci->pitar1 = 0x00000000;
  204. pci->piwbar1 = 0x00000000;
  205. pci->piwar1 = 0xa0f5501e; /* Enable, Prefetch, Local
  206. Mem, Snoop R/W, 2G */
  207. }
  208. #endif /* CONFIG_85xx_PCI2 */
  209. int mpc85xx_pci1_last_busno = 0;
  210. void __init
  211. mpc85xx_setup_hose(void)
  212. {
  213. struct pci_controller *hose_a;
  214. #ifdef CONFIG_85xx_PCI2
  215. struct pci_controller *hose_b;
  216. #endif
  217. bd_t *binfo = (bd_t *) __res;
  218. hose_a = pcibios_alloc_controller();
  219. if (!hose_a)
  220. return;
  221. ppc_md.pci_swizzle = common_swizzle;
  222. ppc_md.pci_map_irq = mpc85xx_map_irq;
  223. hose_a->first_busno = 0;
  224. hose_a->bus_offset = 0;
  225. hose_a->last_busno = 0xff;
  226. setup_indirect_pci(hose_a, binfo->bi_immr_base + PCI1_CFG_ADDR_OFFSET,
  227. binfo->bi_immr_base + PCI1_CFG_DATA_OFFSET);
  228. hose_a->set_cfg_type = 1;
  229. mpc85xx_setup_pci1(hose_a);
  230. hose_a->pci_mem_offset = MPC85XX_PCI1_MEM_OFFSET;
  231. hose_a->mem_space.start = MPC85XX_PCI1_LOWER_MEM;
  232. hose_a->mem_space.end = MPC85XX_PCI1_UPPER_MEM;
  233. hose_a->io_space.start = MPC85XX_PCI1_LOWER_IO;
  234. hose_a->io_space.end = MPC85XX_PCI1_UPPER_IO;
  235. hose_a->io_base_phys = MPC85XX_PCI1_IO_BASE;
  236. #ifdef CONFIG_85xx_PCI2
  237. hose_a->io_base_virt = ioremap(MPC85XX_PCI1_IO_BASE,
  238. MPC85XX_PCI1_IO_SIZE +
  239. MPC85XX_PCI2_IO_SIZE);
  240. #else
  241. hose_a->io_base_virt = ioremap(MPC85XX_PCI1_IO_BASE,
  242. MPC85XX_PCI1_IO_SIZE);
  243. #endif
  244. isa_io_base = (unsigned long)hose_a->io_base_virt;
  245. /* setup resources */
  246. pci_init_resource(&hose_a->mem_resources[0],
  247. MPC85XX_PCI1_LOWER_MEM,
  248. MPC85XX_PCI1_UPPER_MEM,
  249. IORESOURCE_MEM, "PCI1 host bridge");
  250. pci_init_resource(&hose_a->io_resource,
  251. MPC85XX_PCI1_LOWER_IO,
  252. MPC85XX_PCI1_UPPER_IO,
  253. IORESOURCE_IO, "PCI1 host bridge");
  254. ppc_md.pci_exclude_device = mpc85xx_exclude_device;
  255. #if defined(CONFIG_MPC8555_CDS) || defined(CONFIG_MPC8548_CDS)
  256. /* Pre pciauto_bus_scan VIA init */
  257. mpc85xx_cds_enable_via(hose_a);
  258. #endif
  259. hose_a->last_busno = pciauto_bus_scan(hose_a, hose_a->first_busno);
  260. #if defined(CONFIG_MPC8555_CDS) || defined(CONFIG_MPC8548_CDS)
  261. /* Post pciauto_bus_scan VIA fixup */
  262. mpc85xx_cds_fixup_via(hose_a);
  263. #endif
  264. #ifdef CONFIG_85xx_PCI2
  265. hose_b = pcibios_alloc_controller();
  266. if (!hose_b)
  267. return;
  268. hose_b->bus_offset = hose_a->last_busno + 1;
  269. hose_b->first_busno = hose_a->last_busno + 1;
  270. hose_b->last_busno = 0xff;
  271. setup_indirect_pci(hose_b, binfo->bi_immr_base + PCI2_CFG_ADDR_OFFSET,
  272. binfo->bi_immr_base + PCI2_CFG_DATA_OFFSET);
  273. hose_b->set_cfg_type = 1;
  274. mpc85xx_setup_pci2(hose_b);
  275. hose_b->pci_mem_offset = MPC85XX_PCI2_MEM_OFFSET;
  276. hose_b->mem_space.start = MPC85XX_PCI2_LOWER_MEM;
  277. hose_b->mem_space.end = MPC85XX_PCI2_UPPER_MEM;
  278. hose_b->io_space.start = MPC85XX_PCI2_LOWER_IO;
  279. hose_b->io_space.end = MPC85XX_PCI2_UPPER_IO;
  280. hose_b->io_base_phys = MPC85XX_PCI2_IO_BASE;
  281. hose_b->io_base_virt = hose_a->io_base_virt + MPC85XX_PCI1_IO_SIZE;
  282. /* setup resources */
  283. pci_init_resource(&hose_b->mem_resources[0],
  284. MPC85XX_PCI2_LOWER_MEM,
  285. MPC85XX_PCI2_UPPER_MEM,
  286. IORESOURCE_MEM, "PCI2 host bridge");
  287. pci_init_resource(&hose_b->io_resource,
  288. MPC85XX_PCI2_LOWER_IO,
  289. MPC85XX_PCI2_UPPER_IO,
  290. IORESOURCE_IO, "PCI2 host bridge");
  291. hose_b->last_busno = pciauto_bus_scan(hose_b, hose_b->first_busno);
  292. /* let board code know what the last bus number was on PCI1 */
  293. mpc85xx_pci1_last_busno = hose_a->last_busno;
  294. #endif
  295. return;
  296. }
  297. #endif /* CONFIG_PCI */