board_setup.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /*
  2. *
  3. * BRIEF MODULE DESCRIPTION
  4. * Cogent CSB250 board setup.
  5. *
  6. * Copyright 2002 Cogent Computer Systems, Inc.
  7. * dan@embeddededge.com
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2 of the License, or (at your
  12. * option) any later version.
  13. *
  14. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  15. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  16. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  17. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  18. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  19. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  20. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  21. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  23. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. *
  25. * You should have received a copy of the GNU General Public License along
  26. * with this program; if not, write to the Free Software Foundation, Inc.,
  27. * 675 Mass Ave, Cambridge, MA 02139, USA.
  28. */
  29. #include <linux/config.h>
  30. #include <linux/init.h>
  31. #include <linux/sched.h>
  32. #include <linux/ioport.h>
  33. #include <linux/mm.h>
  34. #include <linux/console.h>
  35. #include <linux/mc146818rtc.h>
  36. #include <linux/delay.h>
  37. #include <asm/cpu.h>
  38. #include <asm/bootinfo.h>
  39. #include <asm/irq.h>
  40. #include <asm/keyboard.h>
  41. #include <asm/mipsregs.h>
  42. #include <asm/reboot.h>
  43. #include <asm/pgtable.h>
  44. #include <asm/au1000.h>
  45. #include <asm/csb250.h>
  46. extern int (*board_pci_idsel)(unsigned int devsel, int assert);
  47. int csb250_pci_idsel(unsigned int devsel, int assert);
  48. void __init board_setup(void)
  49. {
  50. u32 pin_func, pin_val;
  51. u32 sys_freqctrl, sys_clksrc;
  52. // set AUX clock to 12MHz * 8 = 96 MHz
  53. au_writel(8, SYS_AUXPLL);
  54. au_writel(0, SYS_PINSTATERD);
  55. udelay(100);
  56. #if defined (CONFIG_USB_OHCI) || defined (CONFIG_AU1X00_USB_DEVICE)
  57. /* GPIO201 is input for PCMCIA card detect */
  58. /* GPIO203 is input for PCMCIA interrupt request */
  59. au_writel(au_readl(GPIO2_DIR) & (u32)(~((1<<1)|(1<<3))), GPIO2_DIR);
  60. /* zero and disable FREQ2 */
  61. sys_freqctrl = au_readl(SYS_FREQCTRL0);
  62. sys_freqctrl &= ~0xFFF00000;
  63. au_writel(sys_freqctrl, SYS_FREQCTRL0);
  64. /* zero and disable USBH/USBD clocks */
  65. sys_clksrc = au_readl(SYS_CLKSRC);
  66. sys_clksrc &= ~0x00007FE0;
  67. au_writel(sys_clksrc, SYS_CLKSRC);
  68. sys_freqctrl = au_readl(SYS_FREQCTRL0);
  69. sys_freqctrl &= ~0xFFF00000;
  70. sys_clksrc = au_readl(SYS_CLKSRC);
  71. sys_clksrc &= ~0x00007FE0;
  72. // FREQ2 = aux/2 = 48 MHz
  73. sys_freqctrl |= ((0<<22) | (1<<21) | (1<<20));
  74. au_writel(sys_freqctrl, SYS_FREQCTRL0);
  75. /*
  76. * Route 48MHz FREQ2 into USB Host and/or Device
  77. */
  78. #ifdef CONFIG_USB_OHCI
  79. sys_clksrc |= ((4<<12) | (0<<11) | (0<<10));
  80. #endif
  81. #ifdef CONFIG_AU1X00_USB_DEVICE
  82. sys_clksrc |= ((4<<7) | (0<<6) | (0<<5));
  83. #endif
  84. au_writel(sys_clksrc, SYS_CLKSRC);
  85. pin_func = au_readl(SYS_PINFUNC) & (u32)(~0x8000);
  86. #ifndef CONFIG_AU1X00_USB_DEVICE
  87. // 2nd USB port is USB host
  88. pin_func |= 0x8000;
  89. #endif
  90. au_writel(pin_func, SYS_PINFUNC);
  91. #endif // defined (CONFIG_USB_OHCI) || defined (CONFIG_AU1X00_USB_DEVICE)
  92. /* Configure GPIO2....it's used by PCI among other things.
  93. */
  94. /* Make everything but GP200 (PCI RST) an input until we get
  95. * the pins set correctly.
  96. */
  97. au_writel(0x00000001, GPIO2_DIR);
  98. /* Set the pins used for output.
  99. * A zero bit will leave PCI reset, LEDs off, power up USB,
  100. * IDSEL disabled.
  101. */
  102. pin_val = ((3 << 30) | (7 << 19) | (1 << 17) | (1 << 16));
  103. au_writel(pin_val, GPIO2_OUTPUT);
  104. /* Set the output direction.
  105. */
  106. pin_val = ((3 << 14) | (7 << 3) | (1 << 1) | (1 << 0));
  107. au_writel(pin_val, GPIO2_DIR);
  108. #ifdef CONFIG_PCI
  109. /* Use FREQ1 for the PCI output clock. We use the
  110. * CPU clock of 384 MHz divided by 12 to get 32 MHz PCI.
  111. * If Michael changes the CPU speed, we need to adjust
  112. * that here as well :-).
  113. */
  114. /* zero and disable FREQ1
  115. */
  116. sys_freqctrl = au_readl(SYS_FREQCTRL0);
  117. sys_freqctrl &= ~0x000ffc00;
  118. au_writel(sys_freqctrl, SYS_FREQCTRL0);
  119. /* zero and disable PCI clock
  120. */
  121. sys_clksrc = au_readl(SYS_CLKSRC);
  122. sys_clksrc &= ~0x000f8000;
  123. au_writel(sys_clksrc, SYS_CLKSRC);
  124. /* Get current values (which really should match above).
  125. */
  126. sys_freqctrl = au_readl(SYS_FREQCTRL0);
  127. sys_freqctrl &= ~0x000ffc00;
  128. sys_clksrc = au_readl(SYS_CLKSRC);
  129. sys_clksrc &= ~0x000f8000;
  130. /* FREQ1 = cpu/12 = 32 MHz
  131. */
  132. sys_freqctrl |= ((5<<12) | (1<<11) | (0<<10));
  133. au_writel(sys_freqctrl, SYS_FREQCTRL0);
  134. /* Just connect the clock without further dividing.
  135. */
  136. sys_clksrc |= ((3<<17) | (0<<16) | (0<<15));
  137. au_writel(sys_clksrc, SYS_CLKSRC);
  138. udelay(1);
  139. /* Now that clocks should be running, take PCI out of reset.
  140. */
  141. pin_val = au_readl(GPIO2_OUTPUT);
  142. pin_val |= ((1 << 16) | 1);
  143. au_writel(pin_val, GPIO2_OUTPUT);
  144. // Setup PCI bus controller
  145. au_writel(0, Au1500_PCI_CMEM);
  146. au_writel(0x00003fff, Au1500_CFG_BASE);
  147. /* We run big endian without any of the software byte swapping,
  148. * so configure the PCI bridge to help us out.
  149. */
  150. au_writel(0xf | (2<<6) | (1<<5) | (1<<4), Au1500_PCI_CFG);
  151. au_writel(0xf0000000, Au1500_PCI_MWMASK_DEV);
  152. au_writel(0, Au1500_PCI_MWBASE_REV_CCL);
  153. au_writel(0x02a00356, Au1500_PCI_STATCMD);
  154. au_writel(0x00003c04, Au1500_PCI_HDRTYPE);
  155. au_writel(0x00000008, Au1500_PCI_MBAR);
  156. au_sync();
  157. board_pci_idsel = csb250_pci_idsel;
  158. #endif
  159. /* Enable sys bus clock divider when IDLE state or no bus activity. */
  160. au_writel(au_readl(SYS_POWERCTRL) | (0x3 << 5), SYS_POWERCTRL);
  161. #ifdef CONFIG_RTC
  162. // Enable the RTC if not already enabled
  163. if (!(au_readl(0xac000028) & 0x20)) {
  164. printk("enabling clock ...\n");
  165. au_writel((au_readl(0xac000028) | 0x20), 0xac000028);
  166. }
  167. // Put the clock in BCD mode
  168. if (readl(0xac00002C) & 0x4) { /* reg B */
  169. au_writel(au_readl(0xac00002c) & ~0x4, 0xac00002c);
  170. au_sync();
  171. }
  172. #endif
  173. }
  174. /* The IDSEL is selected in the GPIO2 register. We will make device
  175. * 12 appear in slot 0 and device 13 appear in slot 1.
  176. */
  177. int
  178. csb250_pci_idsel(unsigned int devsel, int assert)
  179. {
  180. int retval;
  181. unsigned int gpio2_pins;
  182. retval = 1;
  183. /* First, disable both selects, then assert the one requested.
  184. */
  185. au_writel(0xc000c000, GPIO2_OUTPUT);
  186. au_sync();
  187. if (assert) {
  188. if (devsel == 12)
  189. gpio2_pins = 0x40000000;
  190. else if (devsel == 13)
  191. gpio2_pins = 0x80000000;
  192. else {
  193. gpio2_pins = 0xc000c000;
  194. retval = 0;
  195. }
  196. au_writel(gpio2_pins, GPIO2_OUTPUT);
  197. }
  198. au_sync();
  199. return retval;
  200. }