it8172_setup.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /*
  2. * BRIEF MODULE DESCRIPTION
  3. * IT8172/QED5231 board setup.
  4. *
  5. * Copyright 2000 MontaVista Software Inc.
  6. * Author: MontaVista Software, Inc.
  7. * ppopov@mvista.com or source@mvista.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/serial_reg.h>
  34. #include <linux/major.h>
  35. #include <linux/kdev_t.h>
  36. #include <linux/root_dev.h>
  37. #include <linux/pm.h>
  38. #include <asm/cpu.h>
  39. #include <asm/time.h>
  40. #include <asm/io.h>
  41. #include <asm/bootinfo.h>
  42. #include <asm/irq.h>
  43. #include <asm/mipsregs.h>
  44. #include <asm/reboot.h>
  45. #include <asm/traps.h>
  46. #include <asm/it8172/it8172.h>
  47. #include <asm/it8712.h>
  48. extern struct resource ioport_resource;
  49. #ifdef CONFIG_SERIO_I8042
  50. int init_8712_keyboard(void);
  51. #endif
  52. extern int SearchIT8712(void);
  53. extern void InitLPCInterface(void);
  54. extern char * __init prom_getcmdline(void);
  55. extern void it8172_restart(char *command);
  56. extern void it8172_halt(void);
  57. extern void it8172_power_off(void);
  58. extern void (*board_time_init)(void);
  59. extern void (*board_timer_setup)(struct irqaction *irq);
  60. extern void it8172_time_init(void);
  61. extern void it8172_timer_setup(struct irqaction *irq);
  62. #ifdef CONFIG_IT8172_REVC
  63. struct {
  64. struct resource ram;
  65. struct resource pci_mem;
  66. struct resource pci_io;
  67. struct resource flash;
  68. struct resource boot;
  69. } it8172_resources = {
  70. { "RAM", 0, 0, IORESOURCE_MEM }, /* to be initted */
  71. { "PCI Mem", 0x10000000, 0x13FFFFFF, IORESOURCE_MEM },
  72. { "PCI I/O", 0x14000000, 0x17FFFFFF },
  73. { "Flash", 0x08000000, 0x0CFFFFFF },
  74. { "Boot ROM", 0x1FC00000, 0x1FFFFFFF }
  75. };
  76. #else
  77. struct {
  78. struct resource ram;
  79. struct resource pci_mem0;
  80. struct resource pci_mem1;
  81. struct resource pci_io;
  82. struct resource pci_mem2;
  83. struct resource pci_mem3;
  84. struct resource flash;
  85. struct resource boot;
  86. } it8172_resources = {
  87. { "RAM", 0, 0, IORESOURCE_MEM }, /* to be initted */
  88. { "PCI Mem0", 0x0C000000, 0x0FFFFFFF, IORESOURCE_MEM },
  89. { "PCI Mem1", 0x10000000, 0x13FFFFFF, IORESOURCE_MEM },
  90. { "PCI I/O", 0x14000000, 0x17FFFFFF },
  91. { "PCI Mem2", 0x1A000000, 0x1BFFFFFF, IORESOURCE_MEM },
  92. { "PCI Mem3", 0x1C000000, 0x1FBFFFFF, IORESOURCE_MEM },
  93. { "Flash", 0x08000000, 0x0CFFFFFF },
  94. { "Boot ROM", 0x1FC00000, 0x1FFFFFFF }
  95. };
  96. #endif
  97. void __init it8172_init_ram_resource(unsigned long memsize)
  98. {
  99. it8172_resources.ram.end = memsize;
  100. }
  101. void __init plat_setup(void)
  102. {
  103. unsigned short dsr;
  104. char *argptr;
  105. argptr = prom_getcmdline();
  106. #ifdef CONFIG_SERIAL_CONSOLE
  107. if ((argptr = strstr(argptr, "console=")) == NULL) {
  108. argptr = prom_getcmdline();
  109. strcat(argptr, " console=ttyS0,115200");
  110. }
  111. #endif
  112. clear_c0_status(ST0_FR);
  113. board_time_init = it8172_time_init;
  114. board_timer_setup = it8172_timer_setup;
  115. _machine_restart = it8172_restart;
  116. _machine_halt = it8172_halt;
  117. pm_power_off = it8172_power_off;
  118. /*
  119. * IO/MEM resources.
  120. *
  121. * revisit this area.
  122. */
  123. set_io_port_base(KSEG1);
  124. ioport_resource.start = it8172_resources.pci_io.start;
  125. ioport_resource.end = it8172_resources.pci_io.end;
  126. #ifdef CONFIG_IT8172_REVC
  127. iomem_resource.start = it8172_resources.pci_mem.start;
  128. iomem_resource.end = it8172_resources.pci_mem.end;
  129. #else
  130. iomem_resource.start = it8172_resources.pci_mem0.start;
  131. iomem_resource.end = it8172_resources.pci_mem3.end;
  132. #endif
  133. #ifdef CONFIG_BLK_DEV_INITRD
  134. ROOT_DEV = Root_RAM0;
  135. #endif
  136. /*
  137. * Pull enabled devices out of standby
  138. */
  139. IT_IO_READ16(IT_PM_DSR, dsr);
  140. /*
  141. * Fixme: This breaks when these drivers are modules!!!
  142. */
  143. #ifdef CONFIG_SOUND_IT8172
  144. dsr &= ~IT_PM_DSR_ACSB;
  145. #else
  146. dsr |= IT_PM_DSR_ACSB;
  147. #endif
  148. #ifdef CONFIG_BLK_DEV_IT8172
  149. dsr &= ~IT_PM_DSR_IDESB;
  150. #else
  151. dsr |= IT_PM_DSR_IDESB;
  152. #endif
  153. IT_IO_WRITE16(IT_PM_DSR, dsr);
  154. InitLPCInterface();
  155. #ifdef CONFIG_MIPS_ITE8172
  156. if (SearchIT8712()) {
  157. printk("Found IT8712 Super IO\n");
  158. /* enable IT8712 serial port */
  159. LPCSetConfig(LDN_SERIAL1, 0x30, 0x01); /* enable */
  160. LPCSetConfig(LDN_SERIAL1, 0x23, 0x01); /* clock selection */
  161. #ifdef CONFIG_SERIO_I8042
  162. if (init_8712_keyboard()) {
  163. printk("Unable to initialize keyboard\n");
  164. LPCSetConfig(LDN_KEYBOARD, 0x30, 0x0); /* disable keyboard */
  165. } else {
  166. LPCSetConfig(LDN_KEYBOARD, 0x30, 0x1); /* enable keyboard */
  167. LPCSetConfig(LDN_KEYBOARD, 0xf0, 0x2);
  168. LPCSetConfig(LDN_KEYBOARD, 0x71, 0x3);
  169. LPCSetConfig(LDN_MOUSE, 0x30, 0x1); /* enable mouse */
  170. LPCSetConfig(0x4, 0x30, 0x1);
  171. LPCSetConfig(0x4, 0xf4, LPCGetConfig(0x4, 0xf4) | 0x80);
  172. if ((LPCGetConfig(LDN_KEYBOARD, 0x30) == 0) ||
  173. (LPCGetConfig(LDN_MOUSE, 0x30) == 0))
  174. printk("Error: keyboard or mouse not enabled\n");
  175. }
  176. #endif
  177. }
  178. else {
  179. printk("IT8712 Super IO not found\n");
  180. }
  181. #endif
  182. #ifdef CONFIG_IT8172_CIR
  183. {
  184. unsigned long data;
  185. //printk("Enabling CIR0\n");
  186. IT_IO_READ16(IT_PM_DSR, data);
  187. data &= ~IT_PM_DSR_CIR0SB;
  188. IT_IO_WRITE16(IT_PM_DSR, data);
  189. //printk("DSR register: %x\n", (unsigned)IT_IO_READ16(IT_PM_DSR, data));
  190. }
  191. #endif
  192. #ifdef CONFIG_IT8172_SCR0
  193. {
  194. unsigned i;
  195. /* Enable Smart Card Reader 0 */
  196. /* First power it up */
  197. IT_IO_READ16(IT_PM_DSR, i);
  198. i &= ~IT_PM_DSR_SCR0SB;
  199. IT_IO_WRITE16(IT_PM_DSR, i);
  200. /* Then initialize its registers */
  201. outb(( IT_SCR_SFR_GATE_UART_OFF << IT_SCR_SFR_GATE_UART_BIT
  202. |IT_SCR_SFR_FET_CHARGE_213_US << IT_SCR_SFR_FET_CHARGE_BIT
  203. |IT_SCR_SFR_CARD_FREQ_3_5_MHZ << IT_SCR_SFR_CARD_FREQ_BIT
  204. |IT_SCR_SFR_FET_ACTIVE_INVERT << IT_SCR_SFR_FET_ACTIVE_BIT
  205. |IT_SCR_SFR_ENABLE_ON << IT_SCR_SFR_ENABLE_BIT),
  206. IT8172_PCI_IO_BASE + IT_SCR0_BASE + IT_SCR_SFR);
  207. outb(IT_SCR_SCDR_RESET_MODE_ASYNC << IT_SCR_SCDR_RESET_MODE_BIT,
  208. IT8172_PCI_IO_BASE + IT_SCR0_BASE + IT_SCR_SCDR);
  209. }
  210. #endif /* CONFIG_IT8172_SCR0 */
  211. #ifdef CONFIG_IT8172_SCR1
  212. {
  213. unsigned i;
  214. /* Enable Smart Card Reader 1 */
  215. /* First power it up */
  216. IT_IO_READ16(IT_PM_DSR, i);
  217. i &= ~IT_PM_DSR_SCR1SB;
  218. IT_IO_WRITE16(IT_PM_DSR, i);
  219. /* Then initialize its registers */
  220. outb(( IT_SCR_SFR_GATE_UART_OFF << IT_SCR_SFR_GATE_UART_BIT
  221. |IT_SCR_SFR_FET_CHARGE_213_US << IT_SCR_SFR_FET_CHARGE_BIT
  222. |IT_SCR_SFR_CARD_FREQ_3_5_MHZ << IT_SCR_SFR_CARD_FREQ_BIT
  223. |IT_SCR_SFR_FET_ACTIVE_INVERT << IT_SCR_SFR_FET_ACTIVE_BIT
  224. |IT_SCR_SFR_ENABLE_ON << IT_SCR_SFR_ENABLE_BIT),
  225. IT8172_PCI_IO_BASE + IT_SCR1_BASE + IT_SCR_SFR);
  226. outb(IT_SCR_SCDR_RESET_MODE_ASYNC << IT_SCR_SCDR_RESET_MODE_BIT,
  227. IT8172_PCI_IO_BASE + IT_SCR1_BASE + IT_SCR_SCDR);
  228. }
  229. #endif /* CONFIG_IT8172_SCR1 */
  230. }
  231. #ifdef CONFIG_SERIO_I8042
  232. /*
  233. * According to the ITE Special BIOS Note for waking up the
  234. * keyboard controller...
  235. */
  236. static int init_8712_keyboard(void)
  237. {
  238. unsigned int cmd_port = 0x14000064;
  239. unsigned int data_port = 0x14000060;
  240. ^^^^^^^^^^^
  241. Somebody here doesn't grok the concept of io ports.
  242. unsigned char data;
  243. int i;
  244. outb(0xaa, cmd_port); /* send self-test cmd */
  245. i = 0;
  246. while (!(inb(cmd_port) & 0x1)) { /* wait output buffer full */
  247. i++;
  248. if (i > 0xffffff)
  249. return 1;
  250. }
  251. data = inb(data_port);
  252. outb(0xcb, cmd_port); /* set ps2 mode */
  253. while (inb(cmd_port) & 0x2) { /* wait while input buffer full */
  254. i++;
  255. if (i > 0xffffff)
  256. return 1;
  257. }
  258. outb(0x01, data_port);
  259. while (inb(cmd_port) & 0x2) { /* wait while input buffer full */
  260. i++;
  261. if (i > 0xffffff)
  262. return 1;
  263. }
  264. outb(0x60, cmd_port); /* write 8042 command byte */
  265. while (inb(cmd_port) & 0x2) { /* wait while input buffer full */
  266. i++;
  267. if (i > 0xffffff)
  268. return 1;
  269. }
  270. outb(0x45, data_port); /* at interface, keyboard enabled, system flag */
  271. while (inb(cmd_port) & 0x2) { /* wait while input buffer full */
  272. i++;
  273. if (i > 0xffffff)
  274. return 1;
  275. }
  276. outb(0xae, cmd_port); /* enable interface */
  277. return 0;
  278. }
  279. #endif