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

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  *
  3.  * BRIEF MODULE DESCRIPTION
  4.  * Alchemy Pb1100 board setup.
  5.  *
  6.  * Copyright 2002 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/pb1100.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. #ifdef CONFIG_RTC
  65. extern struct rtc_ops pb1500_rtc_ops;
  66. #endif
  67. extern char * __init prom_getcmdline(void);
  68. extern void au1000_restart(char *);
  69. extern void au1000_halt(void);
  70. extern void au1000_power_off(void);
  71. extern struct resource ioport_resource;
  72. extern struct resource iomem_resource;
  73. void __init bus_error_init(void) { /* nothing */ }
  74. void __init au1100_setup(void)
  75. {
  76. char *argptr;
  77. u32 pin_func, static_cfg0;
  78. u32 sys_freqctrl, sys_clksrc;
  79. argptr = prom_getcmdline();
  80. /* NOTE: The memory map is established by YAMON 2.08+ */
  81. /* Various early Au1000 Errata corrected by this */
  82. set_cp0_config(1<<19); /* Config[OD] */
  83. #ifdef CONFIG_AU1000_SERIAL_CONSOLE
  84. if ((argptr = strstr(argptr, "console=")) == NULL) {
  85. argptr = prom_getcmdline();
  86. strcat(argptr, " console=ttyS0,115200");
  87. }
  88. #endif
  89. #ifdef CONFIG_SOUND_AU1000
  90. strcat(argptr, " au1000_audio=vra");
  91. argptr = prom_getcmdline();
  92. #endif
  93. _machine_restart = au1000_restart;
  94. _machine_halt = au1000_halt;
  95. _machine_power_off = au1000_power_off;
  96. // IO/MEM resources.
  97. set_io_port_base(0);
  98. ioport_resource.start = 0x10000000;
  99. ioport_resource.end = 0xffffffff;
  100. iomem_resource.start = 0x10000000;
  101. iomem_resource.end = 0xffffffff;
  102. #ifdef CONFIG_BLK_DEV_INITRD
  103. ROOT_DEV = MKDEV(RAMDISK_MAJOR, 0);
  104. initrd_start = (unsigned long)&__rd_start;
  105. initrd_end = (unsigned long)&__rd_end;
  106. #endif
  107. // set AUX clock to 12MHz * 8 = 96 MHz
  108. au_writel(8, SYS_AUXPLL);
  109. au_writel(0, SYS_PININPUTEN);
  110. udelay(100);
  111. #if defined (CONFIG_USB_OHCI) || defined (CONFIG_AU1000_USB_DEVICE)
  112. #ifdef CONFIG_USB_OHCI
  113. if ((argptr = strstr(argptr, "usb_ohci=")) == NULL) {
  114.         char usb_args[80];
  115. argptr = prom_getcmdline();
  116. memset(usb_args, 0, sizeof(usb_args));
  117. sprintf(usb_args, " usb_ohci=base:0x%x,len:0x%x,irq:%d",
  118. USB_OHCI_BASE, USB_OHCI_LEN, AU1000_USB_HOST_INT);
  119. strcat(argptr, usb_args);
  120. }
  121. #endif
  122. // configure pins GPIO[14:9] as GPIO
  123. pin_func = au_readl(SYS_PINFUNC) & (u32)(~0x80);
  124. /* zero and disable FREQ2 */
  125. sys_freqctrl = au_readl(SYS_FREQCTRL0);
  126. sys_freqctrl &= ~0xFFF00000;
  127. au_writel(sys_freqctrl, SYS_FREQCTRL0);
  128. /* zero and disable USBH/USBD/IrDA clock */
  129. sys_clksrc = au_readl(SYS_CLKSRC);
  130. sys_clksrc &= ~0x0000001F;
  131. au_writel(sys_clksrc, SYS_CLKSRC);
  132. sys_freqctrl = au_readl(SYS_FREQCTRL0);
  133. sys_freqctrl &= ~0xFFF00000;
  134. sys_clksrc = au_readl(SYS_CLKSRC);
  135. sys_clksrc &= ~0x0000001F;
  136. // FREQ2 = aux/2 = 48 MHz
  137. sys_freqctrl |= ((0<<22) | (1<<21) | (1<<20));
  138. au_writel(sys_freqctrl, SYS_FREQCTRL0);
  139. /*
  140.  * Route 48MHz FREQ2 into USBH/USBD/IrDA
  141.  */
  142. sys_clksrc |= ((4<<2) | (0<<1) | 0 );
  143. au_writel(sys_clksrc, SYS_CLKSRC);
  144. /* setup the static bus controller */
  145. au_writel(0x00000002, MEM_STCFG3);  /* type = PCMCIA */
  146. au_writel(0x280E3D07, MEM_STTIME3); /* 250ns cycle time */
  147. au_writel(0x10000000, MEM_STADDR3); /* any PCMCIA select */
  148. // get USB Functionality pin state (device vs host drive pins)
  149. pin_func = au_readl(SYS_PINFUNC) & (u32)(~0x8000);
  150. #ifndef CONFIG_AU1000_USB_DEVICE
  151. // 2nd USB port is USB host
  152. pin_func |= 0x8000;
  153. #endif
  154. au_writel(pin_func, SYS_PINFUNC);
  155. #endif // defined (CONFIG_USB_OHCI) || defined (CONFIG_AU1000_USB_DEVICE)
  156. #ifdef CONFIG_USB_OHCI
  157. // enable host controller and wait for reset done
  158. au_writel(0x08, USB_HOST_CONFIG);
  159. udelay(1000);
  160. au_writel(0x0c, USB_HOST_CONFIG);
  161. udelay(1000);
  162. au_readl(USB_HOST_CONFIG);
  163. while (!(au_readl(USB_HOST_CONFIG) & 0x10))
  164.     ;
  165. au_readl(USB_HOST_CONFIG);
  166. #endif
  167. #ifdef CONFIG_FB
  168. conswitchp = &dummy_con;
  169. #endif
  170. #ifdef CONFIG_FB_AU1100
  171. if ((argptr = strstr(argptr, "video=")) == NULL) {
  172. argptr = prom_getcmdline();
  173. /* default panel */
  174. strcat(argptr, " video=au1100fb:panel:Sharp_320x240_16");
  175. }
  176. #endif
  177. #ifdef CONFIG_FB_E1356
  178. if ((argptr = strstr(argptr, "video=")) == NULL) {
  179. argptr = prom_getcmdline();
  180. strcat(argptr, " video=e1356fb:system:pb1500");
  181. }
  182. #endif
  183. #ifndef CONFIG_SERIAL_NONSTANDARD
  184. /* don't touch the default serial console */
  185. au_writel(0, UART0_ADDR + UART_CLK);
  186. #endif
  187. au_writel(0, UART1_ADDR + UART_CLK);
  188. au_writel(0, UART3_ADDR + UART_CLK);
  189. #ifdef CONFIG_BLK_DEV_IDE
  190. ide_ops = &std_ide_ops;
  191. #endif
  192. while (au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_E0S);
  193. au_writel(SYS_CNTRL_E0 | SYS_CNTRL_EN0, SYS_COUNTER_CNTRL);
  194. au_sync();
  195. while (au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_T0S);
  196. au_writel(0, SYS_TOYTRIM);
  197. au_writel(0x00000060, 0xb190003c);
  198. #ifdef CONFIG_RTC
  199. rtc_ops = &pb1500_rtc_ops;
  200. // Enable the RTC if not already enabled
  201. if (!(readb(0xac000028) & 0x20)) {
  202. writeb(readb(0xac000028) | 0x20, 0xac000028);
  203. au_sync();
  204. }
  205. // Put the clock in BCD mode
  206. if (readb(0xac00002C) & 0x4) { /* reg B */
  207. writeb(readb(0xac00002c) & ~0x4, 0xac00002c);
  208. au_sync();
  209. }
  210. #endif
  211. }