setup.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:8k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  *
  3.  * BRIEF MODULE DESCRIPTION
  4.  * Alchemy Pb1000 board setup.
  5.  *
  6.  * Copyright 2000 MontaVista Software Inc.
  7.  * Author: MontaVista Software, Inc.
  8.  *          ppopov@mvista.com or source@mvista.com
  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.  *  THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR IMPLIED
  16.  *  WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
  17.  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
  18.  *  NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT, INDIRECT,
  19.  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  20.  *  NOT LIMITED   TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF
  21.  *  USE, DATA,  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  22.  *  ANY THEORY OF LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT
  23.  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  24.  *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25.  *
  26.  *  You should have received a copy of the  GNU General Public License along
  27.  *  with this program; if not, write  to the Free Software Foundation, Inc.,
  28.  *  675 Mass Ave, Cambridge, MA 02139, USA.
  29.  */
  30. #include <linux/config.h>
  31. #include <linux/init.h>
  32. #include <linux/sched.h>
  33. #include <linux/ioport.h>
  34. #include <linux/mm.h>
  35. #include <linux/console.h>
  36. #include <linux/mc146818rtc.h>
  37. #include <linux/delay.h>
  38. #include <asm/cpu.h>
  39. #include <asm/bootinfo.h>
  40. #include <asm/irq.h>
  41. #include <asm/keyboard.h>
  42. #include <asm/mipsregs.h>
  43. #include <asm/reboot.h>
  44. #include <asm/pgtable.h>
  45. #include <asm/au1000.h>
  46. #include <asm/pb1000.h>
  47. #ifdef CONFIG_USB_OHCI
  48. // Enable the workaround for the OHCI DoneHead
  49. // register corruption problem.
  50. #define CONFIG_AU1000_OHCI_FIX
  51. #endif
  52. #if defined(CONFIG_AU1000_SERIAL_CONSOLE)
  53. extern void console_setup(char *, int *);
  54. char serial_console[20];
  55. #endif
  56. #ifdef CONFIG_BLK_DEV_INITRD
  57. extern unsigned long initrd_start, initrd_end;
  58. extern void * __rd_start, * __rd_end;
  59. #endif
  60. #ifdef CONFIG_BLK_DEV_IDE
  61. extern struct ide_ops std_ide_ops;
  62. extern struct ide_ops *ide_ops;
  63. #endif
  64. extern struct rtc_ops no_rtc_ops;
  65. extern char * __init prom_getcmdline(void);
  66. extern void au1000_restart(char *);
  67. extern void au1000_halt(void);
  68. extern void au1000_power_off(void);
  69. extern struct resource ioport_resource;
  70. extern struct resource iomem_resource;
  71. void __init bus_error_init(void) { /* nothing */ }
  72. void __init au1000_setup(void)
  73. {
  74. char *argptr;
  75. u32 pin_func, static_cfg0;
  76. u32 sys_freqctrl, sys_clksrc;
  77. u32 prid = read_32bit_cp0_register(CP0_PRID);
  78. argptr = prom_getcmdline();
  79. /* Various early Au1000 Errata corrected by this */
  80. set_cp0_config(1<<19); /* Config[OD] */
  81. #ifdef CONFIG_AU1000_SERIAL_CONSOLE
  82. if ((argptr = strstr(argptr, "console=")) == NULL) {
  83. argptr = prom_getcmdline();
  84. strcat(argptr, " console=ttyS0,115200");
  85. }
  86. #endif
  87. rtc_ops = &no_rtc_ops;
  88. _machine_restart = au1000_restart;
  89. _machine_halt = au1000_halt;
  90. _machine_power_off = au1000_power_off;
  91. // IO/MEM resources.
  92. set_io_port_base(0);
  93. ioport_resource.start = 0x10000000;
  94. ioport_resource.end = 0xffffffff;
  95. iomem_resource.start = 0x10000000;
  96. iomem_resource.end = 0xffffffff;
  97. #ifdef CONFIG_BLK_DEV_INITRD
  98. ROOT_DEV = MKDEV(RAMDISK_MAJOR, 0);
  99. initrd_start = (unsigned long)&__rd_start;
  100. initrd_end = (unsigned long)&__rd_end;
  101. #endif
  102. // set AUX clock to 12MHz * 8 = 96 MHz
  103. au_writel(8, SYS_AUXPLL);
  104. au_writel(0, SYS_PINSTATERD);
  105. udelay(100);
  106. #if defined (CONFIG_USB_OHCI) || defined (CONFIG_AU1000_USB_DEVICE)
  107. #ifdef CONFIG_USB_OHCI
  108. if ((argptr = strstr(argptr, "usb_ohci=")) == NULL) {
  109.         char usb_args[80];
  110. argptr = prom_getcmdline();
  111. memset(usb_args, 0, sizeof(usb_args));
  112. sprintf(usb_args, " usb_ohci=base:0x%x,len:0x%x,irq:%d",
  113. USB_OHCI_BASE, USB_OHCI_LEN, AU1000_USB_HOST_INT);
  114. strcat(argptr, usb_args);
  115. }
  116. #endif
  117. /* zero and disable FREQ2 */
  118. sys_freqctrl = au_readl(SYS_FREQCTRL0);
  119. sys_freqctrl &= ~0xFFF00000;
  120. au_writel(sys_freqctrl, SYS_FREQCTRL0);
  121. /* zero and disable USBH/USBD clocks */
  122. sys_clksrc = au_readl(SYS_CLKSRC);
  123. sys_clksrc &= ~0x00007FE0;
  124. au_writel(sys_clksrc, SYS_CLKSRC);
  125. sys_freqctrl = au_readl(SYS_FREQCTRL0);
  126. sys_freqctrl &= ~0xFFF00000;
  127. sys_clksrc = au_readl(SYS_CLKSRC);
  128. sys_clksrc &= ~0x00007FE0;
  129. switch (prid & 0x000000FF)
  130. {
  131. case 0x00: /* DA */
  132. case 0x01: /* HA */
  133. case 0x02: /* HB */
  134. /* CPU core freq to 48MHz to slow it way down... */
  135. au_writel(4, SYS_CPUPLL);
  136. /*
  137.  * Setup 48MHz FREQ2 from CPUPLL for USB Host
  138.  */
  139. /* FRDIV2=3 -> div by 8 of 384MHz -> 48MHz */
  140. sys_freqctrl |= ((3<<22) | (1<<21) | (0<<20));
  141. au_writel(sys_freqctrl, SYS_FREQCTRL0);
  142. /* CPU core freq to 384MHz */
  143. au_writel(0x20, SYS_CPUPLL);
  144. printk("Au1000: 48MHz OHCI workaround enabledn");
  145. break;
  146. default:  /* HC and newer */
  147. // FREQ2 = aux/2 = 48 MHz
  148. sys_freqctrl |= ((0<<22) | (1<<21) | (1<<20));
  149. au_writel(sys_freqctrl, SYS_FREQCTRL0);
  150. break;
  151. }
  152. /*
  153.  * Route 48MHz FREQ2 into USB Host and/or Device
  154.  */
  155. #ifdef CONFIG_USB_OHCI
  156. sys_clksrc |= ((4<<12) | (0<<11) | (0<<10));
  157. #endif
  158. #ifdef CONFIG_AU1000_USB_DEVICE
  159. sys_clksrc |= ((4<<7) | (0<<6) | (0<<5));
  160. #endif
  161. au_writel(sys_clksrc, SYS_CLKSRC);
  162. #ifdef CONFIG_USB_OHCI
  163. // enable host controller and wait for reset done
  164. au_writel(0x08, USB_HOST_CONFIG);
  165. udelay(1000);
  166. au_writel(0x0E, USB_HOST_CONFIG);
  167. udelay(1000);
  168. au_readl(USB_HOST_CONFIG); // throw away first read
  169. while (!(au_readl(USB_HOST_CONFIG) & 0x10))
  170. au_readl(USB_HOST_CONFIG);
  171. #endif
  172. // configure pins GPIO[14:9] as GPIO
  173. pin_func = au_readl(SYS_PINFUNC) & (u32)(~0x8080);
  174. #ifndef CONFIG_AU1000_USB_DEVICE
  175. // 2nd USB port is USB host
  176. pin_func |= 0x8000;
  177. #endif
  178. au_writel(pin_func, SYS_PINFUNC);
  179. au_writel(0x2800, SYS_TRIOUTCLR);
  180. au_writel(0x0030, SYS_OUTPUTCLR);
  181. #endif // defined (CONFIG_USB_OHCI) || defined (CONFIG_AU1000_USB_DEVICE)
  182. // make gpio 15 an input (for interrupt line)
  183. pin_func = au_readl(SYS_PINFUNC) & (u32)(~0x100);
  184. // we don't need I2S, so make it available for GPIO[31:29]
  185. pin_func |= (1<<5);
  186. au_writel(pin_func, SYS_PINFUNC);
  187. au_writel(0x8000, SYS_TRIOUTCLR);
  188. #ifdef CONFIG_FB
  189. conswitchp = &dummy_con;
  190. #endif
  191. static_cfg0 = au_readl(MEM_STCFG0) & (u32)(~0xc00);
  192. au_writel(static_cfg0, MEM_STCFG0);
  193. // configure RCE2* for LCD
  194. au_writel(0x00000004, MEM_STCFG2);
  195. // MEM_STTIME2
  196. au_writel(0x09000000, MEM_STTIME2);
  197. // Set 32-bit base address decoding for RCE2*
  198. au_writel(0x10003ff0, MEM_STADDR2);
  199. // PCI CPLD setup
  200. // expand CE0 to cover PCI
  201. au_writel(0x11803e40, MEM_STADDR1);
  202. // burst visibility on
  203. au_writel(au_readl(MEM_STCFG0) | 0x1000, MEM_STCFG0);
  204. au_writel(0x83, MEM_STCFG1);         // ewait enabled, flash timing
  205. au_writel(0x33030a10, MEM_STTIME1);   // slower timing for FPGA
  206. /* setup the static bus controller */
  207. au_writel(0x00000002, MEM_STCFG3);  /* type = PCMCIA */
  208. au_writel(0x280E3D07, MEM_STTIME3); /* 250ns cycle time */
  209. au_writel(0x10000000, MEM_STADDR3); /* any PCMCIA select */
  210. #ifdef CONFIG_FB_E1356
  211. if ((argptr = strstr(argptr, "video=")) == NULL) {
  212. argptr = prom_getcmdline();
  213. strcat(argptr, " video=e1356fb:system:pb1000,mmunalign:1");
  214. }
  215. #endif // CONFIG_FB_E1356
  216. #ifdef CONFIG_PCI
  217. au_writel(0, PCI_BRIDGE_CONFIG); // set extend byte to 0
  218. au_writel(0, SDRAM_MBAR);        // set mbar to 0
  219. au_writel(0x2, SDRAM_CMD);       // enable memory accesses
  220. au_sync_delay(1);
  221. #endif
  222. #ifndef CONFIG_SERIAL_NONSTANDARD
  223. /* don't touch the default serial console */
  224. au_writel(0, UART0_ADDR + UART_CLK);
  225. #endif
  226. au_writel(0, UART1_ADDR + UART_CLK);
  227. au_writel(0, UART2_ADDR + UART_CLK);
  228. au_writel(0, UART3_ADDR + UART_CLK);
  229. #ifdef CONFIG_BLK_DEV_IDE
  230. ide_ops = &std_ide_ops;
  231. #endif
  232. // setup irda clocks
  233. // aux clock, divide by 2, clock from 2/4 divider
  234. au_writel(au_readl(SYS_CLKSRC) | 0x7, SYS_CLKSRC);
  235. pin_func = au_readl(SYS_PINFUNC) & (u32)(~(1<<2)); // clear IRTXD
  236. au_writel(pin_func, SYS_PINFUNC);
  237. while (au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_E0S);
  238. au_writel(SYS_CNTRL_E0 | SYS_CNTRL_EN0, SYS_COUNTER_CNTRL);
  239. au_sync();
  240. while (au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_T0S);
  241. au_writel(0, SYS_TOYTRIM);
  242. /* Enable Au1000 BCLK switching - note: sed1356 must not use
  243.  * its BCLK (Au1000 LCLK) for any timings */
  244. switch (prid & 0x000000FF)
  245. {
  246. case 0x00: /* DA */
  247. case 0x01: /* HA */
  248. case 0x02: /* HB */
  249. break;
  250. default:  /* HC and newer */
  251. au_writel(0x00000060, 0xb190003c);
  252. break;
  253. }
  254. }