cpci405.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * Board setup routines for the esd CPCI-405 cPCI Board.
  3. *
  4. * Copyright 2001-2006 esd electronic system design - hannover germany
  5. *
  6. * Authors: Matthias Fuchs
  7. * matthias.fuchs@esd-electronics.com
  8. * Stefan Roese
  9. * stefan.roese@esd-electronics.com
  10. *
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License as published by the
  13. * Free Software Foundation; either version 2 of the License, or (at your
  14. * option) any later version.
  15. *
  16. */
  17. #include <linux/init.h>
  18. #include <linux/pci.h>
  19. #include <asm/system.h>
  20. #include <asm/pci-bridge.h>
  21. #include <asm/machdep.h>
  22. #include <asm/todc.h>
  23. #include <linux/serial.h>
  24. #include <linux/serial_core.h>
  25. #include <linux/serial_8250.h>
  26. #include <asm/ocp.h>
  27. #include <asm/ibm_ocp_pci.h>
  28. #include <platforms/4xx/ibm405gp.h>
  29. #ifdef CONFIG_GEN_RTC
  30. void *cpci405_nvram;
  31. #endif
  32. extern bd_t __res;
  33. /*
  34. * Some IRQs unique to CPCI-405.
  35. */
  36. int __init
  37. ppc405_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
  38. {
  39. static char pci_irq_table[][4] =
  40. /*
  41. * PCI IDSEL/INTPIN->INTLINE
  42. * A B C D
  43. */
  44. {
  45. {28, 29, 30, 27}, /* IDSEL 15 - cPCI slot 8 */
  46. {29, 30, 27, 28}, /* IDSEL 16 - cPCI slot 7 */
  47. {30, 27, 28, 29}, /* IDSEL 17 - cPCI slot 6 */
  48. {27, 28, 29, 30}, /* IDSEL 18 - cPCI slot 5 */
  49. {28, 29, 30, 27}, /* IDSEL 19 - cPCI slot 4 */
  50. {29, 30, 27, 28}, /* IDSEL 20 - cPCI slot 3 */
  51. {30, 27, 28, 29}, /* IDSEL 21 - cPCI slot 2 */
  52. };
  53. const long min_idsel = 15, max_idsel = 21, irqs_per_slot = 4;
  54. return PCI_IRQ_TABLE_LOOKUP;
  55. };
  56. /* The serial clock for the chip is an internal clock determined by
  57. * different clock speeds/dividers.
  58. * Calculate the proper input baud rate and setup the serial driver.
  59. */
  60. static void __init
  61. cpci405_early_serial_map(void)
  62. {
  63. u32 uart_div;
  64. int uart_clock;
  65. struct uart_port port;
  66. /* Calculate the serial clock input frequency
  67. *
  68. * The uart clock is the cpu frequency (provided in the board info
  69. * structure) divided by the external UART Divisor.
  70. */
  71. uart_div = ((mfdcr(DCRN_CHCR_BASE) & CHR0_UDIV) >> 1) + 1;
  72. uart_clock = __res.bi_procfreq / uart_div;
  73. /* Setup serial port access */
  74. memset(&port, 0, sizeof(port));
  75. #if defined(CONFIG_UART0_TTYS0)
  76. port.membase = (void*)UART0_IO_BASE;
  77. port.irq = UART0_INT;
  78. #else
  79. port.membase = (void*)UART1_IO_BASE;
  80. port.irq = UART1_INT;
  81. #endif
  82. port.uartclk = uart_clock;
  83. port.regshift = 0;
  84. port.iotype = UPIO_MEM;
  85. port.flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST;
  86. port.line = 0;
  87. if (early_serial_setup(&port) != 0) {
  88. printk("Early serial init of port 0 failed\n");
  89. }
  90. #if defined(CONFIG_UART0_TTYS0)
  91. port.membase = (void*)UART1_IO_BASE;
  92. port.irq = UART1_INT;
  93. #else
  94. port.membase = (void*)UART0_IO_BASE;
  95. port.irq = UART0_INT;
  96. #endif
  97. port.line = 1;
  98. if (early_serial_setup(&port) != 0) {
  99. printk("Early serial init of port 1 failed\n");
  100. }
  101. }
  102. void __init
  103. cpci405_setup_arch(void)
  104. {
  105. ppc4xx_setup_arch();
  106. ibm_ocp_set_emac(0, 0);
  107. cpci405_early_serial_map();
  108. #ifdef CONFIG_GEN_RTC
  109. TODC_INIT(TODC_TYPE_MK48T35,
  110. cpci405_nvram, cpci405_nvram, cpci405_nvram, 8);
  111. #endif
  112. }
  113. void __init
  114. bios_fixup(struct pci_controller *hose, struct pcil0_regs *pcip)
  115. {
  116. #ifdef CONFIG_PCI
  117. unsigned int bar_response, bar;
  118. /* Disable region first */
  119. out_le32((void *) &(pcip->pmm[0].ma), 0x00000000);
  120. /* PLB starting addr, PCI: 0x80000000 */
  121. out_le32((void *) &(pcip->pmm[0].la), 0x80000000);
  122. /* PCI start addr, 0x80000000 */
  123. out_le32((void *) &(pcip->pmm[0].pcila), PPC405_PCI_MEM_BASE);
  124. /* 512MB range of PLB to PCI */
  125. out_le32((void *) &(pcip->pmm[0].pciha), 0x00000000);
  126. /* Enable no pre-fetch, enable region */
  127. out_le32((void *) &(pcip->pmm[0].ma), ((0xffffffff -
  128. (PPC405_PCI_UPPER_MEM -
  129. PPC405_PCI_MEM_BASE)) | 0x01));
  130. /* Disable region one */
  131. out_le32((void *) &(pcip->pmm[1].ma), 0x00000000);
  132. out_le32((void *) &(pcip->pmm[1].la), 0x00000000);
  133. out_le32((void *) &(pcip->pmm[1].pcila), 0x00000000);
  134. out_le32((void *) &(pcip->pmm[1].pciha), 0x00000000);
  135. out_le32((void *) &(pcip->pmm[1].ma), 0x00000000);
  136. out_le32((void *) &(pcip->ptm1ms), 0x00000001);
  137. /* Disable region two */
  138. out_le32((void *) &(pcip->pmm[2].ma), 0x00000000);
  139. out_le32((void *) &(pcip->pmm[2].la), 0x00000000);
  140. out_le32((void *) &(pcip->pmm[2].pcila), 0x00000000);
  141. out_le32((void *) &(pcip->pmm[2].pciha), 0x00000000);
  142. out_le32((void *) &(pcip->pmm[2].ma), 0x00000000);
  143. out_le32((void *) &(pcip->ptm2ms), 0x00000000);
  144. out_le32((void *) &(pcip->ptm2la), 0x00000000);
  145. /* Zero config bars */
  146. for (bar = PCI_BASE_ADDRESS_1; bar <= PCI_BASE_ADDRESS_2; bar += 4) {
  147. early_write_config_dword(hose, hose->first_busno,
  148. PCI_FUNC(hose->first_busno), bar,
  149. 0x00000000);
  150. early_read_config_dword(hose, hose->first_busno,
  151. PCI_FUNC(hose->first_busno), bar,
  152. &bar_response);
  153. }
  154. #endif
  155. }
  156. void __init
  157. cpci405_map_io(void)
  158. {
  159. ppc4xx_map_io();
  160. #ifdef CONFIG_GEN_RTC
  161. cpci405_nvram = ioremap(CPCI405_NVRAM_PADDR, CPCI405_NVRAM_SIZE);
  162. #endif
  163. }
  164. void __init
  165. platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  166. unsigned long r6, unsigned long r7)
  167. {
  168. ppc4xx_init(r3, r4, r5, r6, r7);
  169. ppc_md.setup_arch = cpci405_setup_arch;
  170. ppc_md.setup_io_mappings = cpci405_map_io;
  171. #ifdef CONFIG_GEN_RTC
  172. ppc_md.time_init = todc_time_init;
  173. ppc_md.set_rtc_time = todc_set_rtc_time;
  174. ppc_md.get_rtc_time = todc_get_rtc_time;
  175. ppc_md.nvram_read_val = todc_direct_read_val;
  176. ppc_md.nvram_write_val = todc_direct_write_val;
  177. #endif
  178. }