bubinga.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. unsigned int bar_response, bar;
  104. /*
  105. * Expected PCI mapping:
  106. *
  107. * PLB addr PCI memory addr
  108. * --------------------- ---------------------
  109. * 0000'0000 - 7fff'ffff <--- 0000'0000 - 7fff'ffff
  110. * 8000'0000 - Bfff'ffff ---> 8000'0000 - Bfff'ffff
  111. *
  112. * PLB addr PCI io addr
  113. * --------------------- ---------------------
  114. * e800'0000 - e800'ffff ---> 0000'0000 - 0001'0000
  115. *
  116. * The following code is simplified by assuming that the bootrom
  117. * has been well behaved in following this mapping.
  118. */
  119. #ifdef DEBUG
  120. int i;
  121. printk("ioremap PCLIO_BASE = 0x%x\n", pcip);
  122. printk("PCI bridge regs before fixup \n");
  123. for (i = 0; i <= 3; i++) {
  124. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].ma)));
  125. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].la)));
  126. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].pcila)));
  127. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].pciha)));
  128. }
  129. printk(" ptm1ms\t0x%x\n", in_le32(&(pcip->ptm1ms)));
  130. printk(" ptm1la\t0x%x\n", in_le32(&(pcip->ptm1la)));
  131. printk(" ptm2ms\t0x%x\n", in_le32(&(pcip->ptm2ms)));
  132. printk(" ptm2la\t0x%x\n", in_le32(&(pcip->ptm2la)));
  133. #endif
  134. /* added for IBM boot rom version 1.15 bios bar changes -AK */
  135. /* Disable region first */
  136. out_le32((void *) &(pcip->pmm[0].ma), 0x00000000);
  137. /* PLB starting addr, PCI: 0x80000000 */
  138. out_le32((void *) &(pcip->pmm[0].la), 0x80000000);
  139. /* PCI start addr, 0x80000000 */
  140. out_le32((void *) &(pcip->pmm[0].pcila), PPC405_PCI_MEM_BASE);
  141. /* 512MB range of PLB to PCI */
  142. out_le32((void *) &(pcip->pmm[0].pciha), 0x00000000);
  143. /* Enable no pre-fetch, enable region */
  144. out_le32((void *) &(pcip->pmm[0].ma), ((0xffffffff -
  145. (PPC405_PCI_UPPER_MEM -
  146. PPC405_PCI_MEM_BASE)) | 0x01));
  147. /* Disable region one */
  148. out_le32((void *) &(pcip->pmm[1].ma), 0x00000000);
  149. out_le32((void *) &(pcip->pmm[1].la), 0x00000000);
  150. out_le32((void *) &(pcip->pmm[1].pcila), 0x00000000);
  151. out_le32((void *) &(pcip->pmm[1].pciha), 0x00000000);
  152. out_le32((void *) &(pcip->pmm[1].ma), 0x00000000);
  153. out_le32((void *) &(pcip->ptm1ms), 0x00000001);
  154. /* Disable region two */
  155. out_le32((void *) &(pcip->pmm[2].ma), 0x00000000);
  156. out_le32((void *) &(pcip->pmm[2].la), 0x00000000);
  157. out_le32((void *) &(pcip->pmm[2].pcila), 0x00000000);
  158. out_le32((void *) &(pcip->pmm[2].pciha), 0x00000000);
  159. out_le32((void *) &(pcip->pmm[2].ma), 0x00000000);
  160. out_le32((void *) &(pcip->ptm2ms), 0x00000000);
  161. out_le32((void *) &(pcip->ptm2la), 0x00000000);
  162. /* Zero config bars */
  163. for (bar = PCI_BASE_ADDRESS_1; bar <= PCI_BASE_ADDRESS_2; bar += 4) {
  164. early_write_config_dword(hose, hose->first_busno,
  165. PCI_FUNC(hose->first_busno), bar,
  166. 0x00000000);
  167. early_read_config_dword(hose, hose->first_busno,
  168. PCI_FUNC(hose->first_busno), bar,
  169. &bar_response);
  170. DBG("BUS %d, device %d, Function %d bar 0x%8.8x is 0x%8.8x\n",
  171. hose->first_busno, PCI_SLOT(hose->first_busno),
  172. PCI_FUNC(hose->first_busno), bar, bar_response);
  173. }
  174. /* end work arround */
  175. #ifdef DEBUG
  176. printk("PCI bridge regs after fixup \n");
  177. for (i = 0; i <= 3; i++) {
  178. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].ma)));
  179. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].la)));
  180. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].pcila)));
  181. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].pciha)));
  182. }
  183. printk(" ptm1ms\t0x%x\n", in_le32(&(pcip->ptm1ms)));
  184. printk(" ptm1la\t0x%x\n", in_le32(&(pcip->ptm1la)));
  185. printk(" ptm2ms\t0x%x\n", in_le32(&(pcip->ptm2ms)));
  186. printk(" ptm2la\t0x%x\n", in_le32(&(pcip->ptm2la)));
  187. #endif
  188. }
  189. void __init
  190. bubinga_setup_arch(void)
  191. {
  192. ppc4xx_setup_arch();
  193. ibm_ocp_set_emac(0, 1);
  194. bubinga_early_serial_map();
  195. /* RTC step for the evb405ep */
  196. bubinga_rtc_base = (void *) BUBINGA_RTC_VADDR;
  197. TODC_INIT(TODC_TYPE_DS1743, bubinga_rtc_base, bubinga_rtc_base,
  198. bubinga_rtc_base, 8);
  199. /* Identify the system */
  200. printk("IBM Bubinga port (MontaVista Software, Inc. <source@mvista.com>)\n");
  201. }
  202. void __init
  203. bubinga_map_io(void)
  204. {
  205. ppc4xx_map_io();
  206. io_block_mapping(BUBINGA_RTC_VADDR,
  207. BUBINGA_RTC_PADDR, BUBINGA_RTC_SIZE, _PAGE_IO);
  208. }
  209. void __init
  210. platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  211. unsigned long r6, unsigned long r7)
  212. {
  213. ppc4xx_init(r3, r4, r5, r6, r7);
  214. ppc_md.setup_arch = bubinga_setup_arch;
  215. ppc_md.setup_io_mappings = bubinga_map_io;
  216. #ifdef CONFIG_GEN_RTC
  217. ppc_md.time_init = todc_time_init;
  218. ppc_md.set_rtc_time = todc_set_rtc_time;
  219. ppc_md.get_rtc_time = todc_get_rtc_time;
  220. ppc_md.nvram_read_val = todc_direct_read_val;
  221. ppc_md.nvram_write_val = todc_direct_write_val;
  222. #endif
  223. #ifdef CONFIG_KGDB
  224. ppc_md.early_serial_map = bubinga_early_serial_map;
  225. #endif
  226. }