setup.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. * arch/mips/ddb5074/setup.c -- NEC DDB Vrc-5074 setup routines
  3. *
  4. * Copyright (C) 2000 Geert Uytterhoeven <geert@sonycom.com>
  5. * Sony Software Development Center Europe (SDCE), Brussels
  6. */
  7. #include <linux/init.h>
  8. #include <linux/kbd_ll.h>
  9. #include <linux/kernel.h>
  10. #include <linux/kdev_t.h>
  11. #include <linux/types.h>
  12. #include <linux/sched.h>
  13. #include <linux/pci.h>
  14. #include <linux/ide.h>
  15. #include <linux/ioport.h>
  16. #include <linux/irq.h>
  17. #include <asm/addrspace.h>
  18. #include <asm/bcache.h>
  19. #include <asm/irq.h>
  20. #include <asm/reboot.h>
  21. #include <asm/gdb-stub.h>
  22. #include <asm/time.h>
  23. #include <asm/nile4.h>
  24. #include <asm/ddb5xxx/ddb5074.h>
  25. #include <asm/ddb5xxx/ddb5xxx.h>
  26. static void (*back_to_prom) (void) = (void (*)(void)) 0xbfc00000;
  27. static void ddb_machine_restart(char *command)
  28. {
  29. u32 t;
  30. /* PCI cold reset */
  31. t = nile4_in32(NILE4_PCICTRL + 4);
  32. t |= 0x40000000;
  33. nile4_out32(NILE4_PCICTRL + 4, t);
  34. /* CPU cold reset */
  35. t = nile4_in32(NILE4_CPUSTAT);
  36. t |= 1;
  37. nile4_out32(NILE4_CPUSTAT, t);
  38. /* Call the PROM */
  39. back_to_prom();
  40. }
  41. static void ddb_machine_halt(void)
  42. {
  43. printk("DDB Vrc-5074 halted.\n");
  44. do {
  45. } while (1);
  46. }
  47. static void ddb_machine_power_off(void)
  48. {
  49. printk("DDB Vrc-5074 halted. Please turn off the power.\n");
  50. do {
  51. } while (1);
  52. }
  53. extern void rtc_ds1386_init(unsigned long base);
  54. extern void (*board_timer_setup) (struct irqaction * irq);
  55. static void __init ddb_timer_init(struct irqaction *irq)
  56. {
  57. /* set the clock to 1 Hz */
  58. nile4_out32(NILE4_T2CTRL, 1000000);
  59. /* enable the General-Purpose Timer */
  60. nile4_out32(NILE4_T2CTRL + 4, 0x00000001);
  61. /* reset timer */
  62. nile4_out32(NILE4_T2CNTR, 0);
  63. /* enable interrupt */
  64. setup_irq(nile4_to_irq(NILE4_INT_GPT), irq);
  65. nile4_enable_irq(nile4_to_irq(NILE4_INT_GPT));
  66. change_c0_status(ST0_IM,
  67. IE_IRQ0 | IE_IRQ1 | IE_IRQ2 | IE_IRQ3 | IE_IRQ4);
  68. }
  69. static void __init ddb_time_init(void)
  70. {
  71. /* we have ds1396 RTC chip */
  72. rtc_ds1386_init(KSEG1ADDR(DDB_PCI_MEM_BASE));
  73. }
  74. static void __init ddb5074_setup(void)
  75. {
  76. set_io_port_base(NILE4_PCI_IO_BASE);
  77. isa_slot_offset = NILE4_PCI_MEM_BASE;
  78. board_timer_setup = ddb_timer_init;
  79. board_time_init = ddb_time_init;
  80. _machine_restart = ddb_machine_restart;
  81. _machine_halt = ddb_machine_halt;
  82. _machine_power_off = ddb_machine_power_off;
  83. ddb_out32(DDB_BAR0, 0);
  84. ddb_set_pmr(DDB_PCIINIT0, DDB_PCICMD_IO, 0, 0x10);
  85. ddb_set_pmr(DDB_PCIINIT1, DDB_PCICMD_MEM, DDB_PCI_MEM_BASE , 0x10);
  86. /* Reboot on panic */
  87. panic_timeout = 180;
  88. }
  89. early_initcall(ddb5074_setup);
  90. #define USE_NILE4_SERIAL 0
  91. #if USE_NILE4_SERIAL
  92. #define ns16550_in(reg) nile4_in8((reg)*8)
  93. #define ns16550_out(reg, val) nile4_out8((reg)*8, (val))
  94. #else
  95. #define NS16550_BASE (NILE4_PCI_IO_BASE+0x03f8)
  96. static inline u8 ns16550_in(u32 reg)
  97. {
  98. return *(volatile u8 *) (NS16550_BASE + reg);
  99. }
  100. static inline void ns16550_out(u32 reg, u8 val)
  101. {
  102. *(volatile u8 *) (NS16550_BASE + reg) = val;
  103. }
  104. #endif
  105. #define NS16550_RBR 0
  106. #define NS16550_THR 0
  107. #define NS16550_DLL 0
  108. #define NS16550_IER 1
  109. #define NS16550_DLM 1
  110. #define NS16550_FCR 2
  111. #define NS16550_IIR 2
  112. #define NS16550_LCR 3
  113. #define NS16550_MCR 4
  114. #define NS16550_LSR 5
  115. #define NS16550_MSR 6
  116. #define NS16550_SCR 7
  117. #define NS16550_LSR_DR 0x01 /* Data ready */
  118. #define NS16550_LSR_OE 0x02 /* Overrun */
  119. #define NS16550_LSR_PE 0x04 /* Parity error */
  120. #define NS16550_LSR_FE 0x08 /* Framing error */
  121. #define NS16550_LSR_BI 0x10 /* Break */
  122. #define NS16550_LSR_THRE 0x20 /* Xmit holding register empty */
  123. #define NS16550_LSR_TEMT 0x40 /* Xmitter empty */
  124. #define NS16550_LSR_ERR 0x80 /* Error */
  125. void _serinit(void)
  126. {
  127. #if USE_NILE4_SERIAL
  128. ns16550_out(NS16550_LCR, 0x80);
  129. ns16550_out(NS16550_DLM, 0x00);
  130. ns16550_out(NS16550_DLL, 0x36); /* 9600 baud */
  131. ns16550_out(NS16550_LCR, 0x00);
  132. ns16550_out(NS16550_LCR, 0x03);
  133. ns16550_out(NS16550_FCR, 0x47);
  134. #else
  135. /* done by PMON */
  136. #endif
  137. }
  138. void _putc(char c)
  139. {
  140. while (!(ns16550_in(NS16550_LSR) & NS16550_LSR_THRE));
  141. ns16550_out(NS16550_THR, c);
  142. if (c == '\n') {
  143. while (!(ns16550_in(NS16550_LSR) & NS16550_LSR_THRE));
  144. ns16550_out(NS16550_THR, '\r');
  145. }
  146. }
  147. void _puts(const char *s)
  148. {
  149. char c;
  150. while ((c = *s++))
  151. _putc(c);
  152. }
  153. char _getc(void)
  154. {
  155. while (!(ns16550_in(NS16550_LSR) & NS16550_LSR_DR));
  156. return ns16550_in(NS16550_RBR);
  157. }
  158. int _testc(void)
  159. {
  160. return (ns16550_in(NS16550_LSR) & NS16550_LSR_DR) != 0;
  161. }
  162. /*
  163. * Hexadecimal 7-segment LED
  164. */
  165. void ddb5074_led_hex(int hex)
  166. {
  167. outb(hex, 0x80);
  168. }
  169. /*
  170. * LEDs D2 and D3, connected to the GPIO pins of the PMU in the ALi M1543
  171. */
  172. struct pci_dev *pci_pmu = NULL;
  173. void ddb5074_led_d2(int on)
  174. {
  175. u8 t;
  176. if (pci_pmu) {
  177. pci_read_config_byte(pci_pmu, 0x7e, &t);
  178. if (on)
  179. t &= 0x7f;
  180. else
  181. t |= 0x80;
  182. pci_write_config_byte(pci_pmu, 0x7e, t);
  183. }
  184. }
  185. void ddb5074_led_d3(int on)
  186. {
  187. u8 t;
  188. if (pci_pmu) {
  189. pci_read_config_byte(pci_pmu, 0x7e, &t);
  190. if (on)
  191. t &= 0xbf;
  192. else
  193. t |= 0x40;
  194. pci_write_config_byte(pci_pmu, 0x7e, t);
  195. }
  196. }