bubinga.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*
  2. * Support for IBM PPC 405EP evaluation board (Bubinga).
  3. *
  4. * Author: SAW (IBM), derived from walnut.c.
  5. * Maintained by MontaVista Software <source@mvista.com>
  6. *
  7. * 2003 (c) MontaVista Softare Inc. This file is licensed under the
  8. * terms of the GNU General Public License version 2. This program is
  9. * licensed "as is" without any warranty of any kind, whether express
  10. * or implied.
  11. */
  12. #include <linux/init.h>
  13. #include <linux/smp.h>
  14. #include <linux/threads.h>
  15. #include <linux/param.h>
  16. #include <linux/string.h>
  17. #include <linux/blkdev.h>
  18. #include <linux/pci.h>
  19. #include <linux/rtc.h>
  20. #include <linux/tty.h>
  21. #include <linux/serial.h>
  22. #include <linux/serial_core.h>
  23. #include <asm/system.h>
  24. #include <asm/pci-bridge.h>
  25. #include <asm/processor.h>
  26. #include <asm/machdep.h>
  27. #include <asm/page.h>
  28. #include <asm/time.h>
  29. #include <asm/io.h>
  30. #include <asm/todc.h>
  31. #include <asm/kgdb.h>
  32. #include <asm/ocp.h>
  33. #include <asm/ibm_ocp_pci.h>
  34. #include <platforms/4xx/ibm405ep.h>
  35. #undef DEBUG
  36. #ifdef DEBUG
  37. #define DBG(x...) printk(x)
  38. #else
  39. #define DBG(x...)
  40. #endif
  41. extern bd_t __res;
  42. void *bubinga_rtc_base;
  43. /* Some IRQs unique to the board
  44. * Used by the generic 405 PCI setup functions in ppc4xx_pci.c
  45. */
  46. int __init
  47. ppc405_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
  48. {
  49. static char pci_irq_table[][4] =
  50. /*
  51. * PCI IDSEL/INTPIN->INTLINE
  52. * A B C D
  53. */
  54. {
  55. {28, 28, 28, 28}, /* IDSEL 1 - PCI slot 1 */
  56. {29, 29, 29, 29}, /* IDSEL 2 - PCI slot 2 */
  57. {30, 30, 30, 30}, /* IDSEL 3 - PCI slot 3 */
  58. {31, 31, 31, 31}, /* IDSEL 4 - PCI slot 4 */
  59. };
  60. const long min_idsel = 1, max_idsel = 4, irqs_per_slot = 4;
  61. return PCI_IRQ_TABLE_LOOKUP;
  62. };
  63. /* The serial clock for the chip is an internal clock determined by
  64. * different clock speeds/dividers.
  65. * Calculate the proper input baud rate and setup the serial driver.
  66. */
  67. static void __init
  68. bubinga_early_serial_map(void)
  69. {
  70. u32 uart_div;
  71. int uart_clock;
  72. struct uart_port port;
  73. /* Calculate the serial clock input frequency
  74. *
  75. * The base baud is the PLL OUTA (provided in the board info
  76. * structure) divided by the external UART Divisor, divided
  77. * by 16.
  78. */
  79. uart_div = (mfdcr(DCRN_CPC0_UCR_BASE) & DCRN_CPC0_UCR_U0DIV);
  80. uart_clock = __res.bi_procfreq / uart_div;
  81. /* Setup serial port access */
  82. memset(&port, 0, sizeof(port));
  83. port.membase = (void*)ACTING_UART0_IO_BASE;
  84. port.irq = ACTING_UART0_INT;
  85. port.uartclk = uart_clock;
  86. port.regshift = 0;
  87. port.iotype = UPIO_MEM;
  88. port.flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST;
  89. port.line = 0;
  90. if (early_serial_setup(&port) != 0) {
  91. printk("Early serial init of port 0 failed\n");
  92. }
  93. port.membase = (void*)ACTING_UART1_IO_BASE;
  94. port.irq = ACTING_UART1_INT;
  95. port.line = 1;
  96. if (early_serial_setup(&port) != 0) {
  97. printk("Early serial init of port 1 failed\n");
  98. }
  99. }
  100. void __init
  101. bios_fixup(struct pci_controller *hose, struct pcil0_regs *pcip)
  102. {
  103. #ifdef CONFIG_PCI
  104. unsigned int bar_response, bar;
  105. /*
  106. * Expected PCI mapping:
  107. *
  108. * PLB addr PCI memory addr
  109. * --------------------- ---------------------
  110. * 0000'0000 - 7fff'ffff <--- 0000'0000 - 7fff'ffff
  111. * 8000'0000 - Bfff'ffff ---> 8000'0000 - Bfff'ffff
  112. *
  113. * PLB addr PCI io addr
  114. * --------------------- ---------------------
  115. * e800'0000 - e800'ffff ---> 0000'0000 - 0001'0000
  116. *
  117. * The following code is simplified by assuming that the bootrom
  118. * has been well behaved in following this mapping.
  119. */
  120. #ifdef DEBUG
  121. int i;
  122. printk("ioremap PCLIO_BASE = 0x%x\n", pcip);
  123. printk("PCI bridge regs before fixup \n");
  124. for (i = 0; i <= 3; i++) {
  125. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].ma)));
  126. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].la)));
  127. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].pcila)));
  128. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].pciha)));
  129. }
  130. printk(" ptm1ms\t0x%x\n", in_le32(&(pcip->ptm1ms)));
  131. printk(" ptm1la\t0x%x\n", in_le32(&(pcip->ptm1la)));
  132. printk(" ptm2ms\t0x%x\n", in_le32(&(pcip->ptm2ms)));
  133. printk(" ptm2la\t0x%x\n", in_le32(&(pcip->ptm2la)));
  134. #endif
  135. /* added for IBM boot rom version 1.15 bios bar changes -AK */
  136. /* Disable region first */
  137. out_le32((void *) &(pcip->pmm[0].ma), 0x00000000);
  138. /* PLB starting addr, PCI: 0x80000000 */
  139. out_le32((void *) &(pcip->pmm[0].la), 0x80000000);
  140. /* PCI start addr, 0x80000000 */
  141. out_le32((void *) &(pcip->pmm[0].pcila), PPC405_PCI_MEM_BASE);
  142. /* 512MB range of PLB to PCI */
  143. out_le32((void *) &(pcip->pmm[0].pciha), 0x00000000);
  144. /* Enable no pre-fetch, enable region */
  145. out_le32((void *) &(pcip->pmm[0].ma), ((0xffffffff -
  146. (PPC405_PCI_UPPER_MEM -
  147. PPC405_PCI_MEM_BASE)) | 0x01));
  148. /* Disable region one */
  149. out_le32((void *) &(pcip->pmm[1].ma), 0x00000000);
  150. out_le32((void *) &(pcip->pmm[1].la), 0x00000000);
  151. out_le32((void *) &(pcip->pmm[1].pcila), 0x00000000);
  152. out_le32((void *) &(pcip->pmm[1].pciha), 0x00000000);
  153. out_le32((void *) &(pcip->pmm[1].ma), 0x00000000);
  154. out_le32((void *) &(pcip->ptm1ms), 0x00000001);
  155. /* Disable region two */
  156. out_le32((void *) &(pcip->pmm[2].ma), 0x00000000);
  157. out_le32((void *) &(pcip->pmm[2].la), 0x00000000);
  158. out_le32((void *) &(pcip->pmm[2].pcila), 0x00000000);
  159. out_le32((void *) &(pcip->pmm[2].pciha), 0x00000000);
  160. out_le32((void *) &(pcip->pmm[2].ma), 0x00000000);
  161. out_le32((void *) &(pcip->ptm2ms), 0x00000000);
  162. out_le32((void *) &(pcip->ptm2la), 0x00000000);
  163. /* Zero config bars */
  164. for (bar = PCI_BASE_ADDRESS_1; bar <= PCI_BASE_ADDRESS_2; bar += 4) {
  165. early_write_config_dword(hose, hose->first_busno,
  166. PCI_FUNC(hose->first_busno), bar,
  167. 0x00000000);
  168. early_read_config_dword(hose, hose->first_busno,
  169. PCI_FUNC(hose->first_busno), bar,
  170. &bar_response);
  171. DBG("BUS %d, device %d, Function %d bar 0x%8.8x is 0x%8.8x\n",
  172. hose->first_busno, PCI_SLOT(hose->first_busno),
  173. PCI_FUNC(hose->first_busno), bar, bar_response);
  174. }
  175. /* end workaround */
  176. #ifdef DEBUG
  177. printk("PCI bridge regs after fixup \n");
  178. for (i = 0; i <= 3; i++) {
  179. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].ma)));
  180. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].la)));
  181. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].pcila)));
  182. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].pciha)));
  183. }
  184. printk(" ptm1ms\t0x%x\n", in_le32(&(pcip->ptm1ms)));
  185. printk(" ptm1la\t0x%x\n", in_le32(&(pcip->ptm1la)));
  186. printk(" ptm2ms\t0x%x\n", in_le32(&(pcip->ptm2ms)));
  187. printk(" ptm2la\t0x%x\n", in_le32(&(pcip->ptm2la)));
  188. #endif
  189. #endif
  190. }
  191. void __init
  192. bubinga_setup_arch(void)
  193. {
  194. ppc4xx_setup_arch();
  195. ibm_ocp_set_emac(0, 1);
  196. bubinga_early_serial_map();
  197. /* RTC step for the evb405ep */
  198. bubinga_rtc_base = (void *) BUBINGA_RTC_VADDR;
  199. TODC_INIT(TODC_TYPE_DS1743, bubinga_rtc_base, bubinga_rtc_base,
  200. bubinga_rtc_base, 8);
  201. /* Identify the system */
  202. printk("IBM Bubinga port (MontaVista Software, Inc. <source@mvista.com>)\n");
  203. }
  204. void __init
  205. bubinga_map_io(void)
  206. {
  207. ppc4xx_map_io();
  208. io_block_mapping(BUBINGA_RTC_VADDR,
  209. BUBINGA_RTC_PADDR, BUBINGA_RTC_SIZE, _PAGE_IO);
  210. }
  211. void __init
  212. platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  213. unsigned long r6, unsigned long r7)
  214. {
  215. ppc4xx_init(r3, r4, r5, r6, r7);
  216. ppc_md.setup_arch = bubinga_setup_arch;
  217. ppc_md.setup_io_mappings = bubinga_map_io;
  218. #ifdef CONFIG_GEN_RTC
  219. ppc_md.time_init = todc_time_init;
  220. ppc_md.set_rtc_time = todc_set_rtc_time;
  221. ppc_md.get_rtc_time = todc_get_rtc_time;
  222. ppc_md.nvram_read_val = todc_direct_read_val;
  223. ppc_md.nvram_write_val = todc_direct_write_val;
  224. #endif
  225. #ifdef CONFIG_KGDB
  226. ppc_md.early_serial_map = bubinga_early_serial_map;
  227. #endif
  228. }