smc37c93x.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /*
  2. * SMC 37C93X initialization code
  3. */
  4. #include <linux/config.h>
  5. #include <linux/kernel.h>
  6. #include <linux/slab.h>
  7. #include <linux/mm.h>
  8. #include <linux/init.h>
  9. #include <linux/delay.h>
  10. #include <asm/hwrpb.h>
  11. #include <asm/io.h>
  12. #include <asm/segment.h>
  13. #define SMC_DEBUG 0
  14. #if SMC_DEBUG
  15. # define DBG_DEVS(args) printk args
  16. #else
  17. # define DBG_DEVS(args)
  18. #endif
  19. #define KB 1024
  20. #define MB (1024*KB)
  21. #define GB (1024*MB)
  22. /* device "activate" register contents */
  23. #define DEVICE_ON 1
  24. #define DEVICE_OFF 0
  25. /* configuration on/off keys */
  26. #define CONFIG_ON_KEY 0x55
  27. #define CONFIG_OFF_KEY 0xaa
  28. /* configuration space device definitions */
  29. #define FDC 0
  30. #define IDE1 1
  31. #define IDE2 2
  32. #define PARP 3
  33. #define SER1 4
  34. #define SER2 5
  35. #define RTCL 6
  36. #define KYBD 7
  37. #define AUXIO 8
  38. /* Chip register offsets from base */
  39. #define CONFIG_CONTROL 0x02
  40. #define INDEX_ADDRESS 0x03
  41. #define LOGICAL_DEVICE_NUMBER 0x07
  42. #define DEVICE_ID 0x20
  43. #define DEVICE_REV 0x21
  44. #define POWER_CONTROL 0x22
  45. #define POWER_MGMT 0x23
  46. #define OSC 0x24
  47. #define ACTIVATE 0x30
  48. #define ADDR_HI 0x60
  49. #define ADDR_LO 0x61
  50. #define INTERRUPT_SEL 0x70
  51. #define INTERRUPT_SEL_2 0x72 /* KYBD/MOUS only */
  52. #define DMA_CHANNEL_SEL 0x74 /* FDC/PARP only */
  53. #define FDD_MODE_REGISTER 0x90
  54. #define FDD_OPTION_REGISTER 0x91
  55. /* values that we read back that are expected ... */
  56. #define VALID_DEVICE_ID 2
  57. /* default device addresses */
  58. #define KYBD_INTERRUPT 1
  59. #define MOUS_INTERRUPT 12
  60. #define COM2_BASE 0x2f8
  61. #define COM2_INTERRUPT 3
  62. #define COM1_BASE 0x3f8
  63. #define COM1_INTERRUPT 4
  64. #define PARP_BASE 0x3bc
  65. #define PARP_INTERRUPT 7
  66. static unsigned long __init SMCConfigState(unsigned long baseAddr)
  67. {
  68. unsigned char devId;
  69. unsigned char devRev;
  70. unsigned long configPort;
  71. unsigned long indexPort;
  72. unsigned long dataPort;
  73. int i;
  74. configPort = indexPort = baseAddr;
  75. dataPort = configPort + 1;
  76. #define NUM_RETRIES 5
  77. for (i = 0; i < NUM_RETRIES; i++)
  78. {
  79. outb(CONFIG_ON_KEY, configPort);
  80. outb(CONFIG_ON_KEY, configPort);
  81. outb(DEVICE_ID, indexPort);
  82. devId = inb(dataPort);
  83. if (devId == VALID_DEVICE_ID) {
  84. outb(DEVICE_REV, indexPort);
  85. devRev = inb(dataPort);
  86. break;
  87. }
  88. else
  89. udelay(100);
  90. }
  91. return (i != NUM_RETRIES) ? baseAddr : 0L;
  92. }
  93. static void __init SMCRunState(unsigned long baseAddr)
  94. {
  95. outb(CONFIG_OFF_KEY, baseAddr);
  96. }
  97. static unsigned long __init SMCDetectUltraIO(void)
  98. {
  99. unsigned long baseAddr;
  100. baseAddr = 0x3F0;
  101. if ( ( baseAddr = SMCConfigState( baseAddr ) ) == 0x3F0 ) {
  102. return( baseAddr );
  103. }
  104. baseAddr = 0x370;
  105. if ( ( baseAddr = SMCConfigState( baseAddr ) ) == 0x370 ) {
  106. return( baseAddr );
  107. }
  108. return( ( unsigned long )0 );
  109. }
  110. static void __init SMCEnableDevice(unsigned long baseAddr,
  111. unsigned long device,
  112. unsigned long portaddr,
  113. unsigned long interrupt)
  114. {
  115. unsigned long indexPort;
  116. unsigned long dataPort;
  117. indexPort = baseAddr;
  118. dataPort = baseAddr + 1;
  119. outb(LOGICAL_DEVICE_NUMBER, indexPort);
  120. outb(device, dataPort);
  121. outb(ADDR_LO, indexPort);
  122. outb(( portaddr & 0xFF ), dataPort);
  123. outb(ADDR_HI, indexPort);
  124. outb((portaddr >> 8) & 0xFF, dataPort);
  125. outb(INTERRUPT_SEL, indexPort);
  126. outb(interrupt, dataPort);
  127. outb(ACTIVATE, indexPort);
  128. outb(DEVICE_ON, dataPort);
  129. }
  130. static void __init SMCEnableKYBD(unsigned long baseAddr)
  131. {
  132. unsigned long indexPort;
  133. unsigned long dataPort;
  134. indexPort = baseAddr;
  135. dataPort = baseAddr + 1;
  136. outb(LOGICAL_DEVICE_NUMBER, indexPort);
  137. outb(KYBD, dataPort);
  138. outb(INTERRUPT_SEL, indexPort); /* Primary interrupt select */
  139. outb(KYBD_INTERRUPT, dataPort);
  140. outb(INTERRUPT_SEL_2, indexPort); /* Secondary interrupt select */
  141. outb(MOUS_INTERRUPT, dataPort);
  142. outb(ACTIVATE, indexPort);
  143. outb(DEVICE_ON, dataPort);
  144. }
  145. static void __init SMCEnableFDC(unsigned long baseAddr)
  146. {
  147. unsigned long indexPort;
  148. unsigned long dataPort;
  149. unsigned char oldValue;
  150. indexPort = baseAddr;
  151. dataPort = baseAddr + 1;
  152. outb(LOGICAL_DEVICE_NUMBER, indexPort);
  153. outb(FDC, dataPort);
  154. outb(FDD_MODE_REGISTER, indexPort);
  155. oldValue = inb(dataPort);
  156. oldValue |= 0x0E; /* Enable burst mode */
  157. outb(oldValue, dataPort);
  158. outb(INTERRUPT_SEL, indexPort); /* Primary interrupt select */
  159. outb(0x06, dataPort );
  160. outb(DMA_CHANNEL_SEL, indexPort); /* DMA channel select */
  161. outb(0x02, dataPort);
  162. outb(ACTIVATE, indexPort);
  163. outb(DEVICE_ON, dataPort);
  164. }
  165. #if SMC_DEBUG
  166. static void __init SMCReportDeviceStatus(unsigned long baseAddr)
  167. {
  168. unsigned long indexPort;
  169. unsigned long dataPort;
  170. unsigned char currentControl;
  171. indexPort = baseAddr;
  172. dataPort = baseAddr + 1;
  173. outb(POWER_CONTROL, indexPort);
  174. currentControl = inb(dataPort);
  175. printk(currentControl & (1 << FDC)
  176. ? "\t+FDC Enabled\n" : "\t-FDC Disabled\n");
  177. printk(currentControl & (1 << IDE1)
  178. ? "\t+IDE1 Enabled\n" : "\t-IDE1 Disabled\n");
  179. printk(currentControl & (1 << IDE2)
  180. ? "\t+IDE2 Enabled\n" : "\t-IDE2 Disabled\n");
  181. printk(currentControl & (1 << PARP)
  182. ? "\t+PARP Enabled\n" : "\t-PARP Disabled\n");
  183. printk(currentControl & (1 << SER1)
  184. ? "\t+SER1 Enabled\n" : "\t-SER1 Disabled\n");
  185. printk(currentControl & (1 << SER2)
  186. ? "\t+SER2 Enabled\n" : "\t-SER2 Disabled\n");
  187. printk( "\n" );
  188. }
  189. #endif
  190. int __init SMC93x_Init(void)
  191. {
  192. unsigned long SMCUltraBase;
  193. unsigned long flags;
  194. local_irq_save(flags);
  195. if ((SMCUltraBase = SMCDetectUltraIO()) != 0UL) {
  196. #if SMC_DEBUG
  197. SMCReportDeviceStatus(SMCUltraBase);
  198. #endif
  199. SMCEnableDevice(SMCUltraBase, SER1, COM1_BASE, COM1_INTERRUPT);
  200. DBG_DEVS(("SMC FDC37C93X: SER1 done\n"));
  201. SMCEnableDevice(SMCUltraBase, SER2, COM2_BASE, COM2_INTERRUPT);
  202. DBG_DEVS(("SMC FDC37C93X: SER2 done\n"));
  203. SMCEnableDevice(SMCUltraBase, PARP, PARP_BASE, PARP_INTERRUPT);
  204. DBG_DEVS(("SMC FDC37C93X: PARP done\n"));
  205. /* On PC164, IDE on the SMC is not enabled;
  206. CMD646 (PCI) on MB */
  207. SMCEnableKYBD(SMCUltraBase);
  208. DBG_DEVS(("SMC FDC37C93X: KYB done\n"));
  209. SMCEnableFDC(SMCUltraBase);
  210. DBG_DEVS(("SMC FDC37C93X: FDC done\n"));
  211. #if SMC_DEBUG
  212. SMCReportDeviceStatus(SMCUltraBase);
  213. #endif
  214. SMCRunState(SMCUltraBase);
  215. local_irq_restore(flags);
  216. printk("SMC FDC37C93X Ultra I/O Controller found @ 0x%lx\n",
  217. SMCUltraBase);
  218. return 1;
  219. }
  220. else {
  221. local_irq_restore(flags);
  222. DBG_DEVS(("No SMC FDC37C93X Ultra I/O Controller found\n"));
  223. return 0;
  224. }
  225. }