m1535plus.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*
  2. * arch/mips/vr41xx/nec-cmbvr4133/m1535plus.c
  3. *
  4. * Initialize for ALi M1535+(included M5229 and M5237).
  5. *
  6. * Author: Yoichi Yuasa <yyuasa@mvista.com, or source@mvista.com> and
  7. * Alex Sapkov <asapkov@ru.mvista.com>
  8. *
  9. * 2003-2004 (c) MontaVista, Software, Inc. This file is licensed under
  10. * the terms of the GNU General Public License version 2. This program
  11. * is licensed "as is" without any warranty of any kind, whether express
  12. * or implied.
  13. *
  14. * Support for NEC-CMBVR4133 in 2.6
  15. * Author: Manish Lachwani (mlachwani@mvista.com)
  16. */
  17. #include <linux/config.h>
  18. #include <linux/init.h>
  19. #include <linux/types.h>
  20. #include <linux/serial.h>
  21. #include <asm/vr41xx/cmbvr4133.h>
  22. #include <linux/pci.h>
  23. #include <asm/io.h>
  24. #define CONFIG_PORT(port) ((port) ? 0x3f0 : 0x370)
  25. #define DATA_PORT(port) ((port) ? 0x3f1 : 0x371)
  26. #define INDEX_PORT(port) CONFIG_PORT(port)
  27. #define ENTER_CONFIG_MODE(port) \
  28. do { \
  29. outb_p(0x51, CONFIG_PORT(port)); \
  30. outb_p(0x23, CONFIG_PORT(port)); \
  31. } while(0)
  32. #define SELECT_LOGICAL_DEVICE(port, dev_no) \
  33. do { \
  34. outb_p(0x07, INDEX_PORT(port)); \
  35. outb_p((dev_no), DATA_PORT(port)); \
  36. } while(0)
  37. #define WRITE_CONFIG_DATA(port,index,data) \
  38. do { \
  39. outb_p((index), INDEX_PORT(port)); \
  40. outb_p((data), DATA_PORT(port)); \
  41. } while(0)
  42. #define EXIT_CONFIG_MODE(port) outb(0xbb, CONFIG_PORT(port))
  43. #define PCI_CONFIG_ADDR KSEG1ADDR(0x0f000c18)
  44. #define PCI_CONFIG_DATA KSEG1ADDR(0x0f000c14)
  45. #ifdef CONFIG_BLK_DEV_FD
  46. void __devinit ali_m1535plus_fdc_init(int port)
  47. {
  48. ENTER_CONFIG_MODE(port);
  49. SELECT_LOGICAL_DEVICE(port, 0); /* FDC */
  50. WRITE_CONFIG_DATA(port, 0x30, 0x01); /* FDC: enable */
  51. WRITE_CONFIG_DATA(port, 0x60, 0x03); /* I/O port base: 0x3f0 */
  52. WRITE_CONFIG_DATA(port, 0x61, 0xf0);
  53. WRITE_CONFIG_DATA(port, 0x70, 0x06); /* IRQ: 6 */
  54. WRITE_CONFIG_DATA(port, 0x74, 0x02); /* DMA: channel 2 */
  55. WRITE_CONFIG_DATA(port, 0xf0, 0x08);
  56. WRITE_CONFIG_DATA(port, 0xf1, 0x00);
  57. WRITE_CONFIG_DATA(port, 0xf2, 0xff);
  58. WRITE_CONFIG_DATA(port, 0xf4, 0x00);
  59. EXIT_CONFIG_MODE(port);
  60. }
  61. #endif
  62. void __devinit ali_m1535plus_parport_init(int port)
  63. {
  64. ENTER_CONFIG_MODE(port);
  65. SELECT_LOGICAL_DEVICE(port, 3); /* Parallel Port */
  66. WRITE_CONFIG_DATA(port, 0x30, 0x01);
  67. WRITE_CONFIG_DATA(port, 0x60, 0x03); /* I/O port base: 0x378 */
  68. WRITE_CONFIG_DATA(port, 0x61, 0x78);
  69. WRITE_CONFIG_DATA(port, 0x70, 0x07); /* IRQ: 7 */
  70. WRITE_CONFIG_DATA(port, 0x74, 0x04); /* DMA: None */
  71. WRITE_CONFIG_DATA(port, 0xf0, 0x8c); /* IRQ polarity: Active Low */
  72. WRITE_CONFIG_DATA(port, 0xf1, 0xc5);
  73. EXIT_CONFIG_MODE(port);
  74. }
  75. void __devinit ali_m1535plus_keyboard_init(int port)
  76. {
  77. ENTER_CONFIG_MODE(port);
  78. SELECT_LOGICAL_DEVICE(port, 7); /* KEYBOARD */
  79. WRITE_CONFIG_DATA(port, 0x30, 0x01); /* KEYBOARD: eable */
  80. WRITE_CONFIG_DATA(port, 0x70, 0x01); /* IRQ: 1 */
  81. WRITE_CONFIG_DATA(port, 0x72, 0x0c); /* PS/2 Mouse IRQ: 12 */
  82. WRITE_CONFIG_DATA(port, 0xf0, 0x00);
  83. EXIT_CONFIG_MODE(port);
  84. }
  85. void __devinit ali_m1535plus_hotkey_init(int port)
  86. {
  87. ENTER_CONFIG_MODE(port);
  88. SELECT_LOGICAL_DEVICE(port, 0xc); /* HOTKEY */
  89. WRITE_CONFIG_DATA(port, 0x30, 0x00);
  90. WRITE_CONFIG_DATA(port, 0xf0, 0x35);
  91. WRITE_CONFIG_DATA(port, 0xf1, 0x14);
  92. WRITE_CONFIG_DATA(port, 0xf2, 0x11);
  93. WRITE_CONFIG_DATA(port, 0xf3, 0x71);
  94. WRITE_CONFIG_DATA(port, 0xf5, 0x05);
  95. EXIT_CONFIG_MODE(port);
  96. }
  97. void ali_m1535plus_init(struct pci_dev *dev)
  98. {
  99. pci_write_config_byte(dev, 0x40, 0x18); /* PCI Interface Control */
  100. pci_write_config_byte(dev, 0x41, 0xc0); /* PS2 keyb & mouse enable */
  101. pci_write_config_byte(dev, 0x42, 0x41); /* ISA bus cycle control */
  102. pci_write_config_byte(dev, 0x43, 0x00); /* ISA bus cycle control 2 */
  103. pci_write_config_byte(dev, 0x44, 0x5d); /* IDE enable & IRQ 14 */
  104. pci_write_config_byte(dev, 0x45, 0x0b); /* PCI int polling mode */
  105. pci_write_config_byte(dev, 0x47, 0x00); /* BIOS chip select control */
  106. /* IRQ routing */
  107. pci_write_config_byte(dev, 0x48, 0x03); /* INTA IRQ10, INTB disable */
  108. pci_write_config_byte(dev, 0x49, 0x00); /* INTC and INTD disable */
  109. pci_write_config_byte(dev, 0x4a, 0x00); /* INTE and INTF disable */
  110. pci_write_config_byte(dev, 0x4b, 0x90); /* Audio IRQ11, Modem disable */
  111. pci_write_config_word(dev, 0x50, 0x4000); /* Parity check IDE enable */
  112. pci_write_config_word(dev, 0x52, 0x0000); /* USB & RTC disable */
  113. pci_write_config_word(dev, 0x54, 0x0002); /* ??? no info */
  114. pci_write_config_word(dev, 0x56, 0x0002); /* PCS1J signal disable */
  115. pci_write_config_byte(dev, 0x59, 0x00); /* PCSDS */
  116. pci_write_config_byte(dev, 0x5a, 0x00);
  117. pci_write_config_byte(dev, 0x5b, 0x00);
  118. pci_write_config_word(dev, 0x5c, 0x0000);
  119. pci_write_config_byte(dev, 0x5e, 0x00);
  120. pci_write_config_byte(dev, 0x5f, 0x00);
  121. pci_write_config_word(dev, 0x60, 0x0000);
  122. pci_write_config_byte(dev, 0x6c, 0x00);
  123. pci_write_config_byte(dev, 0x6d, 0x48); /* ROM address mapping */
  124. pci_write_config_byte(dev, 0x6e, 0x00); /* ??? what for? */
  125. pci_write_config_byte(dev, 0x70, 0x12); /* Serial IRQ control */
  126. pci_write_config_byte(dev, 0x71, 0xEF); /* DMA channel select */
  127. pci_write_config_byte(dev, 0x72, 0x03); /* USB IDSEL */
  128. pci_write_config_byte(dev, 0x73, 0x00); /* ??? no info */
  129. /*
  130. * IRQ setup ALi M5237 USB Host Controller
  131. * IRQ: 9
  132. */
  133. pci_write_config_byte(dev, 0x74, 0x01); /* USB IRQ9 */
  134. pci_write_config_byte(dev, 0x75, 0x1f); /* IDE2 IRQ 15 */
  135. pci_write_config_byte(dev, 0x76, 0x80); /* ACPI disable */
  136. pci_write_config_byte(dev, 0x77, 0x40); /* Modem disable */
  137. pci_write_config_dword(dev, 0x78, 0x20000000); /* Pin select 2 */
  138. pci_write_config_byte(dev, 0x7c, 0x00); /* Pin select 3 */
  139. pci_write_config_byte(dev, 0x81, 0x00); /* ID read/write control */
  140. pci_write_config_byte(dev, 0x90, 0x00); /* PCI PM block control */
  141. pci_write_config_word(dev, 0xa4, 0x0000); /* PMSCR */
  142. #ifdef CONFIG_BLK_DEV_FD
  143. ali_m1535plus_fdc_init(1);
  144. #endif
  145. ali_m1535plus_keyboard_init(1);
  146. ali_m1535plus_hotkey_init(1);
  147. }
  148. static inline void ali_config_writeb(u8 reg, u8 val, int devfn)
  149. {
  150. u32 data;
  151. int shift;
  152. writel((1 << 16) | (devfn << 8) | (reg & 0xfc) | 1UL, PCI_CONFIG_ADDR);
  153. data = readl(PCI_CONFIG_DATA);
  154. shift = (reg & 3) << 3;
  155. data &= ~(0xff << shift);
  156. data |= (((u32)val) << shift);
  157. writel(data, PCI_CONFIG_DATA);
  158. }
  159. static inline u8 ali_config_readb(u8 reg, int devfn)
  160. {
  161. u32 data;
  162. writel((1 << 16) | (devfn << 8) | (reg & 0xfc) | 1UL, PCI_CONFIG_ADDR);
  163. data = readl(PCI_CONFIG_DATA);
  164. return (u8)(data >> ((reg & 3) << 3));
  165. }
  166. static inline u16 ali_config_readw(u8 reg, int devfn)
  167. {
  168. u32 data;
  169. writel((1 << 16) | (devfn << 8) | (reg & 0xfc) | 1UL, PCI_CONFIG_ADDR);
  170. data = readl(PCI_CONFIG_DATA);
  171. return (u16)(data >> ((reg & 2) << 3));
  172. }
  173. int vr4133_rockhopper = 0;
  174. void __init ali_m5229_preinit(void)
  175. {
  176. if (ali_config_readw(PCI_VENDOR_ID,16) == PCI_VENDOR_ID_AL &&
  177. ali_config_readw(PCI_DEVICE_ID,16) == PCI_DEVICE_ID_AL_M1533) {
  178. printk(KERN_INFO "Found an NEC Rockhopper \n");
  179. vr4133_rockhopper = 1;
  180. /*
  181. * Enable ALi M5229 IDE Controller (both channels)
  182. * IDSEL: A27
  183. */
  184. ali_config_writeb(0x58, 0x4c, 16);
  185. }
  186. }
  187. void __init ali_m5229_init(struct pci_dev *dev)
  188. {
  189. /*
  190. * Enable Primary/Secondary Channel Cable Detect 40-Pin
  191. */
  192. pci_write_config_word(dev, 0x4a, 0xc023);
  193. /*
  194. * Set only the 3rd byteis for the master IDE's cycle and
  195. * enable Internal IDE Function
  196. */
  197. pci_write_config_byte(dev, 0x50, 0x23); /* Class code attr register */
  198. pci_write_config_byte(dev, 0x09, 0xff); /* Set native mode & stuff */
  199. pci_write_config_byte(dev, 0x52, 0x00); /* use timing registers */
  200. pci_write_config_byte(dev, 0x58, 0x02); /* Primary addr setup timing */
  201. pci_write_config_byte(dev, 0x59, 0x22); /* Primary cmd block timing */
  202. pci_write_config_byte(dev, 0x5a, 0x22); /* Pr drv 0 R/W timing */
  203. pci_write_config_byte(dev, 0x5b, 0x22); /* Pr drv 1 R/W timing */
  204. pci_write_config_byte(dev, 0x5c, 0x02); /* Sec addr setup timing */
  205. pci_write_config_byte(dev, 0x5d, 0x22); /* Sec cmd block timing */
  206. pci_write_config_byte(dev, 0x5e, 0x22); /* Sec drv 0 R/W timing */
  207. pci_write_config_byte(dev, 0x5f, 0x22); /* Sec drv 1 R/W timing */
  208. pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x20);
  209. pci_write_config_word(dev, PCI_COMMAND,
  210. PCI_COMMAND_PARITY | PCI_COMMAND_MASTER |
  211. PCI_COMMAND_IO);
  212. }