setup.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. /*
  2. * linux/arch/sh/board/mpc1211/setup.c
  3. *
  4. * Copyright (C) 2002 Saito.K & Jeanne, Fujii.Y
  5. *
  6. */
  7. #include <linux/config.h>
  8. #include <linux/init.h>
  9. #include <linux/irq.h>
  10. #include <linux/hdreg.h>
  11. #include <linux/ide.h>
  12. #include <linux/interrupt.h>
  13. #include <asm/io.h>
  14. #include <asm/machvec.h>
  15. #include <asm/mpc1211/mpc1211.h>
  16. #include <asm/mpc1211/pci.h>
  17. #include <asm/mpc1211/m1543c.h>
  18. /* ALI15X3 SMBus address offsets */
  19. #define SMBHSTSTS (0 + 0x3100)
  20. #define SMBHSTCNT (1 + 0x3100)
  21. #define SMBHSTSTART (2 + 0x3100)
  22. #define SMBHSTCMD (7 + 0x3100)
  23. #define SMBHSTADD (3 + 0x3100)
  24. #define SMBHSTDAT0 (4 + 0x3100)
  25. #define SMBHSTDAT1 (5 + 0x3100)
  26. #define SMBBLKDAT (6 + 0x3100)
  27. /* Other settings */
  28. #define MAX_TIMEOUT 500 /* times 1/100 sec */
  29. /* ALI15X3 command constants */
  30. #define ALI15X3_ABORT 0x04
  31. #define ALI15X3_T_OUT 0x08
  32. #define ALI15X3_QUICK 0x00
  33. #define ALI15X3_BYTE 0x10
  34. #define ALI15X3_BYTE_DATA 0x20
  35. #define ALI15X3_WORD_DATA 0x30
  36. #define ALI15X3_BLOCK_DATA 0x40
  37. #define ALI15X3_BLOCK_CLR 0x80
  38. /* ALI15X3 status register bits */
  39. #define ALI15X3_STS_IDLE 0x04
  40. #define ALI15X3_STS_BUSY 0x08
  41. #define ALI15X3_STS_DONE 0x10
  42. #define ALI15X3_STS_DEV 0x20 /* device error */
  43. #define ALI15X3_STS_COLL 0x40 /* collision or no response */
  44. #define ALI15X3_STS_TERM 0x80 /* terminated by abort */
  45. #define ALI15X3_STS_ERR 0xE0 /* all the bad error bits */
  46. const char *get_system_type(void)
  47. {
  48. return "Interface MPC-1211(CTP/PCI/MPC-SH02)";
  49. }
  50. static void __init pci_write_config(unsigned long busNo,
  51. unsigned long devNo,
  52. unsigned long fncNo,
  53. unsigned long cnfAdd,
  54. unsigned long cnfData)
  55. {
  56. ctrl_outl((0x80000000
  57. + ((busNo & 0xff) << 16)
  58. + ((devNo & 0x1f) << 11)
  59. + ((fncNo & 0x07) << 8)
  60. + (cnfAdd & 0xfc)), PCIPAR);
  61. ctrl_outl(cnfData, PCIPDR);
  62. }
  63. /*
  64. Initialize IRQ setting
  65. */
  66. static unsigned char m_irq_mask = 0xfb;
  67. static unsigned char s_irq_mask = 0xff;
  68. volatile unsigned long irq_err_count;
  69. static void disable_mpc1211_irq(unsigned int irq)
  70. {
  71. unsigned long flags;
  72. save_and_cli(flags);
  73. if( irq < 8) {
  74. m_irq_mask |= (1 << irq);
  75. outb(m_irq_mask,I8259_M_MR);
  76. } else {
  77. s_irq_mask |= (1 << (irq - 8));
  78. outb(s_irq_mask,I8259_S_MR);
  79. }
  80. restore_flags(flags);
  81. }
  82. static void enable_mpc1211_irq(unsigned int irq)
  83. {
  84. unsigned long flags;
  85. save_and_cli(flags);
  86. if( irq < 8) {
  87. m_irq_mask &= ~(1 << irq);
  88. outb(m_irq_mask,I8259_M_MR);
  89. } else {
  90. s_irq_mask &= ~(1 << (irq - 8));
  91. outb(s_irq_mask,I8259_S_MR);
  92. }
  93. restore_flags(flags);
  94. }
  95. static inline int mpc1211_irq_real(unsigned int irq)
  96. {
  97. int value;
  98. int irqmask;
  99. if ( irq < 8) {
  100. irqmask = 1<<irq;
  101. outb(0x0b,I8259_M_CR); /* ISR register */
  102. value = inb(I8259_M_CR) & irqmask;
  103. outb(0x0a,I8259_M_CR); /* back ro the IPR reg */
  104. return value;
  105. }
  106. irqmask = 1<<(irq - 8);
  107. outb(0x0b,I8259_S_CR); /* ISR register */
  108. value = inb(I8259_S_CR) & irqmask;
  109. outb(0x0a,I8259_S_CR); /* back ro the IPR reg */
  110. return value;
  111. }
  112. static void mask_and_ack_mpc1211(unsigned int irq)
  113. {
  114. unsigned long flags;
  115. save_and_cli(flags);
  116. if(irq < 8) {
  117. if(m_irq_mask & (1<<irq)){
  118. if(!mpc1211_irq_real(irq)){
  119. irq_err_count++;
  120. printk("spurious 8259A interrupt: IRQ %x\n",irq);
  121. }
  122. } else {
  123. m_irq_mask |= (1<<irq);
  124. }
  125. inb(I8259_M_MR); /* DUMMY */
  126. outb(m_irq_mask,I8259_M_MR); /* disable */
  127. outb(0x60+irq,I8259_M_CR); /* EOI */
  128. } else {
  129. if(s_irq_mask & (1<<(irq - 8))){
  130. if(!mpc1211_irq_real(irq)){
  131. irq_err_count++;
  132. printk("spurious 8259A interrupt: IRQ %x\n",irq);
  133. }
  134. } else {
  135. s_irq_mask |= (1<<(irq - 8));
  136. }
  137. inb(I8259_S_MR); /* DUMMY */
  138. outb(s_irq_mask,I8259_S_MR); /* disable */
  139. outb(0x60+(irq-8),I8259_S_CR); /* EOI */
  140. outb(0x60+2,I8259_M_CR);
  141. }
  142. restore_flags(flags);
  143. }
  144. static void end_mpc1211_irq(unsigned int irq)
  145. {
  146. enable_mpc1211_irq(irq);
  147. }
  148. static unsigned int startup_mpc1211_irq(unsigned int irq)
  149. {
  150. enable_mpc1211_irq(irq);
  151. return 0;
  152. }
  153. static void shutdown_mpc1211_irq(unsigned int irq)
  154. {
  155. disable_mpc1211_irq(irq);
  156. }
  157. static struct hw_interrupt_type mpc1211_irq_type = {
  158. .typename = "MPC1211-IRQ",
  159. .startup = startup_mpc1211_irq,
  160. .shutdown = shutdown_mpc1211_irq,
  161. .enable = enable_mpc1211_irq,
  162. .disable = disable_mpc1211_irq,
  163. .ack = mask_and_ack_mpc1211,
  164. .end = end_mpc1211_irq
  165. };
  166. static void make_mpc1211_irq(unsigned int irq)
  167. {
  168. irq_desc[irq].handler = &mpc1211_irq_type;
  169. irq_desc[irq].status = IRQ_DISABLED;
  170. irq_desc[irq].action = 0;
  171. irq_desc[irq].depth = 1;
  172. disable_mpc1211_irq(irq);
  173. }
  174. int mpc1211_irq_demux(int irq)
  175. {
  176. unsigned int poll;
  177. if( irq == 2 ) {
  178. outb(0x0c,I8259_M_CR);
  179. poll = inb(I8259_M_CR);
  180. if(poll & 0x80) {
  181. irq = (poll & 0x07);
  182. }
  183. if( irq == 2) {
  184. outb(0x0c,I8259_S_CR);
  185. poll = inb(I8259_S_CR);
  186. irq = (poll & 0x07) + 8;
  187. }
  188. }
  189. return irq;
  190. }
  191. void __init init_mpc1211_IRQ(void)
  192. {
  193. int i;
  194. /*
  195. * Super I/O (Just mimic PC):
  196. * 1: keyboard
  197. * 3: serial 1
  198. * 4: serial 0
  199. * 5: printer
  200. * 6: floppy
  201. * 8: rtc
  202. * 10: lan
  203. * 12: mouse
  204. * 14: ide0
  205. * 15: ide1
  206. */
  207. pci_write_config(0,0,0,0x54, 0xb0b0002d);
  208. outb(0x11, I8259_M_CR); /* mater icw1 edge trigger */
  209. outb(0x11, I8259_S_CR); /* slave icw1 edge trigger */
  210. outb(0x20, I8259_M_MR); /* m icw2 base vec 0x08 */
  211. outb(0x28, I8259_S_MR); /* s icw2 base vec 0x70 */
  212. outb(0x04, I8259_M_MR); /* m icw3 slave irq2 */
  213. outb(0x02, I8259_S_MR); /* s icw3 slave id */
  214. outb(0x01, I8259_M_MR); /* m icw4 non buf normal eoi*/
  215. outb(0x01, I8259_S_MR); /* s icw4 non buf normal eo1*/
  216. outb(0xfb, I8259_M_MR); /* disable irq0--irq7 */
  217. outb(0xff, I8259_S_MR); /* disable irq8--irq15 */
  218. for ( i=0; i < 16; i++) {
  219. if(i != 2) {
  220. make_mpc1211_irq(i);
  221. }
  222. }
  223. }
  224. /*
  225. Initialize the board
  226. */
  227. static void delay (void)
  228. {
  229. volatile unsigned short tmp;
  230. tmp = *(volatile unsigned short *) 0xa0000000;
  231. }
  232. static void delay1000 (void)
  233. {
  234. int i;
  235. for (i=0; i<1000; i++)
  236. delay ();
  237. }
  238. static int put_smb_blk(unsigned char *p, int address, int command, int no)
  239. {
  240. int temp;
  241. int timeout;
  242. int i;
  243. outb(0xff, SMBHSTSTS);
  244. temp = inb(SMBHSTSTS);
  245. for (timeout = 0; (timeout < MAX_TIMEOUT) && !(temp & ALI15X3_STS_IDLE); timeout++) {
  246. delay1000();
  247. temp = inb(SMBHSTSTS);
  248. }
  249. if (timeout >= MAX_TIMEOUT){
  250. return -1;
  251. }
  252. outb(((address & 0x7f) << 1), SMBHSTADD);
  253. outb(0xc0, SMBHSTCNT);
  254. outb(command & 0xff, SMBHSTCMD);
  255. outb(no & 0x1f, SMBHSTDAT0);
  256. for(i = 1; i <= no; i++) {
  257. outb(*p++, SMBBLKDAT);
  258. }
  259. outb(0xff, SMBHSTSTART);
  260. temp = inb(SMBHSTSTS);
  261. for (timeout = 0; (timeout < MAX_TIMEOUT) && !(temp & (ALI15X3_STS_ERR | ALI15X3_STS_DONE)); timeout++) {
  262. delay1000();
  263. temp = inb(SMBHSTSTS);
  264. }
  265. if (timeout >= MAX_TIMEOUT) {
  266. return -2;
  267. }
  268. if ( temp & ALI15X3_STS_ERR ){
  269. return -3;
  270. }
  271. return 0;
  272. }
  273. /*
  274. * The Machine Vector
  275. */
  276. struct sh_machine_vector mv_mpc1211 __initmv = {
  277. .mv_nr_irqs = 48,
  278. .mv_irq_demux = mpc1211_irq_demux,
  279. .mv_init_irq = init_mpc1211_IRQ,
  280. #ifdef CONFIG_HEARTBEAT
  281. .mv_heartbeat = heartbeat_mpc1211,
  282. #endif
  283. };
  284. ALIAS_MV(mpc1211)
  285. /* arch/sh/boards/mpc1211/rtc.c */
  286. void mpc1211_time_init(void);
  287. int __init platform_setup(void)
  288. {
  289. unsigned char spd_buf[128];
  290. __set_io_port_base(PA_PCI_IO);
  291. pci_write_config(0,0,0,0x54, 0xb0b00000);
  292. do {
  293. outb(ALI15X3_ABORT, SMBHSTCNT);
  294. spd_buf[0] = 0x0c;
  295. spd_buf[1] = 0x43;
  296. spd_buf[2] = 0x7f;
  297. spd_buf[3] = 0x03;
  298. spd_buf[4] = 0x00;
  299. spd_buf[5] = 0x03;
  300. spd_buf[6] = 0x00;
  301. } while (put_smb_blk(spd_buf, 0x69, 0, 7) < 0);
  302. board_time_init = mpc1211_time_init;
  303. return 0;
  304. }