config.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. /*
  2. * arch/m68k/mvme16x/config.c
  3. *
  4. * Copyright (C) 1995 Richard Hirst [richard@sleepie.demon.co.uk]
  5. *
  6. * Based on:
  7. *
  8. * linux/amiga/config.c
  9. *
  10. * Copyright (C) 1993 Hamish Macdonald
  11. *
  12. * This file is subject to the terms and conditions of the GNU General Public
  13. * License. See the file README.legal in the main directory of this archive
  14. * for more details.
  15. */
  16. #include <linux/types.h>
  17. #include <linux/kernel.h>
  18. #include <linux/mm.h>
  19. #include <linux/seq_file.h>
  20. #include <linux/tty.h>
  21. #include <linux/console.h>
  22. #include <linux/linkage.h>
  23. #include <linux/init.h>
  24. #include <linux/major.h>
  25. #include <linux/genhd.h>
  26. #include <linux/rtc.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/module.h>
  29. #include <asm/bootinfo.h>
  30. #include <asm/bootinfo-vme.h>
  31. #include <asm/byteorder.h>
  32. #include <asm/pgtable.h>
  33. #include <asm/setup.h>
  34. #include <asm/irq.h>
  35. #include <asm/traps.h>
  36. #include <asm/rtc.h>
  37. #include <asm/machdep.h>
  38. #include <asm/mvme16xhw.h>
  39. extern t_bdid mvme_bdid;
  40. static MK48T08ptr_t volatile rtc = (MK48T08ptr_t)MVME_RTC_BASE;
  41. static void mvme16x_get_model(char *model);
  42. extern void mvme16x_sched_init(irq_handler_t handler);
  43. extern u32 mvme16x_gettimeoffset(void);
  44. extern int mvme16x_hwclk (int, struct rtc_time *);
  45. extern int mvme16x_set_clock_mmss (unsigned long);
  46. extern void mvme16x_reset (void);
  47. int bcd2int (unsigned char b);
  48. /* Save tick handler routine pointer, will point to xtime_update() in
  49. * kernel/time/timekeeping.c, called via mvme16x_process_int() */
  50. static irq_handler_t tick_handler;
  51. unsigned short mvme16x_config;
  52. EXPORT_SYMBOL(mvme16x_config);
  53. int __init mvme16x_parse_bootinfo(const struct bi_record *bi)
  54. {
  55. uint16_t tag = be16_to_cpu(bi->tag);
  56. if (tag == BI_VME_TYPE || tag == BI_VME_BRDINFO)
  57. return 0;
  58. else
  59. return 1;
  60. }
  61. void mvme16x_reset(void)
  62. {
  63. printk ("\r\n\nCalled mvme16x_reset\r\n"
  64. "\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r");
  65. /* The string of returns is to delay the reset until the whole
  66. * message is output. Assert reset bit in GCSR */
  67. *(volatile char *)0xfff40107 = 0x80;
  68. }
  69. static void mvme16x_get_model(char *model)
  70. {
  71. p_bdid p = &mvme_bdid;
  72. char suf[4];
  73. suf[1] = p->brdsuffix[0];
  74. suf[2] = p->brdsuffix[1];
  75. suf[3] = '\0';
  76. suf[0] = suf[1] ? '-' : '\0';
  77. sprintf(model, "Motorola MVME%x%s", be16_to_cpu(p->brdno), suf);
  78. }
  79. static void mvme16x_get_hardware_list(struct seq_file *m)
  80. {
  81. uint16_t brdno = be16_to_cpu(mvme_bdid.brdno);
  82. if (brdno == 0x0162 || brdno == 0x0172)
  83. {
  84. unsigned char rev = *(unsigned char *)MVME162_VERSION_REG;
  85. seq_printf (m, "VMEchip2 %spresent\n",
  86. rev & MVME16x_CONFIG_NO_VMECHIP2 ? "NOT " : "");
  87. seq_printf (m, "SCSI interface %spresent\n",
  88. rev & MVME16x_CONFIG_NO_SCSICHIP ? "NOT " : "");
  89. seq_printf (m, "Ethernet i/f %spresent\n",
  90. rev & MVME16x_CONFIG_NO_ETHERNET ? "NOT " : "");
  91. }
  92. }
  93. /*
  94. * This function is called during kernel startup to initialize
  95. * the mvme16x IRQ handling routines. Should probably ensure
  96. * that the base vectors for the VMEChip2 and PCCChip2 are valid.
  97. */
  98. static void __init mvme16x_init_IRQ (void)
  99. {
  100. m68k_setup_user_interrupt(VEC_USER, 192);
  101. }
  102. #define pcc2chip ((volatile u_char *)0xfff42000)
  103. #define PccSCCMICR 0x1d
  104. #define PccSCCTICR 0x1e
  105. #define PccSCCRICR 0x1f
  106. #define PccTPIACKR 0x25
  107. #ifdef CONFIG_EARLY_PRINTK
  108. /**** cd2401 registers ****/
  109. #define CD2401_ADDR (0xfff45000)
  110. #define CyGFRCR (0x81)
  111. #define CyCCR (0x13)
  112. #define CyCLR_CHAN (0x40)
  113. #define CyINIT_CHAN (0x20)
  114. #define CyCHIP_RESET (0x10)
  115. #define CyENB_XMTR (0x08)
  116. #define CyDIS_XMTR (0x04)
  117. #define CyENB_RCVR (0x02)
  118. #define CyDIS_RCVR (0x01)
  119. #define CyCAR (0xee)
  120. #define CyIER (0x11)
  121. #define CyMdmCh (0x80)
  122. #define CyRxExc (0x20)
  123. #define CyRxData (0x08)
  124. #define CyTxMpty (0x02)
  125. #define CyTxRdy (0x01)
  126. #define CyLICR (0x26)
  127. #define CyRISR (0x89)
  128. #define CyTIMEOUT (0x80)
  129. #define CySPECHAR (0x70)
  130. #define CyOVERRUN (0x08)
  131. #define CyPARITY (0x04)
  132. #define CyFRAME (0x02)
  133. #define CyBREAK (0x01)
  134. #define CyREOIR (0x84)
  135. #define CyTEOIR (0x85)
  136. #define CyMEOIR (0x86)
  137. #define CyNOTRANS (0x08)
  138. #define CyRFOC (0x30)
  139. #define CyRDR (0xf8)
  140. #define CyTDR (0xf8)
  141. #define CyMISR (0x8b)
  142. #define CyRISR (0x89)
  143. #define CyTISR (0x8a)
  144. #define CyMSVR1 (0xde)
  145. #define CyMSVR2 (0xdf)
  146. #define CyDSR (0x80)
  147. #define CyDCD (0x40)
  148. #define CyCTS (0x20)
  149. #define CyDTR (0x02)
  150. #define CyRTS (0x01)
  151. #define CyRTPRL (0x25)
  152. #define CyRTPRH (0x24)
  153. #define CyCOR1 (0x10)
  154. #define CyPARITY_NONE (0x00)
  155. #define CyPARITY_E (0x40)
  156. #define CyPARITY_O (0xC0)
  157. #define Cy_5_BITS (0x04)
  158. #define Cy_6_BITS (0x05)
  159. #define Cy_7_BITS (0x06)
  160. #define Cy_8_BITS (0x07)
  161. #define CyCOR2 (0x17)
  162. #define CyETC (0x20)
  163. #define CyCtsAE (0x02)
  164. #define CyCOR3 (0x16)
  165. #define Cy_1_STOP (0x02)
  166. #define Cy_2_STOP (0x04)
  167. #define CyCOR4 (0x15)
  168. #define CyREC_FIFO (0x0F) /* Receive FIFO threshold */
  169. #define CyCOR5 (0x14)
  170. #define CyCOR6 (0x18)
  171. #define CyCOR7 (0x07)
  172. #define CyRBPR (0xcb)
  173. #define CyRCOR (0xc8)
  174. #define CyTBPR (0xc3)
  175. #define CyTCOR (0xc0)
  176. #define CySCHR1 (0x1f)
  177. #define CySCHR2 (0x1e)
  178. #define CyTPR (0xda)
  179. #define CyPILR1 (0xe3)
  180. #define CyPILR2 (0xe0)
  181. #define CyPILR3 (0xe1)
  182. #define CyCMR (0x1b)
  183. #define CyASYNC (0x02)
  184. #define CyLICR (0x26)
  185. #define CyLIVR (0x09)
  186. #define CySCRL (0x23)
  187. #define CySCRH (0x22)
  188. #define CyTFTC (0x80)
  189. void mvme16x_cons_write(struct console *co, const char *str, unsigned count)
  190. {
  191. volatile unsigned char *base_addr = (u_char *)CD2401_ADDR;
  192. volatile u_char sink;
  193. u_char ier;
  194. int port;
  195. u_char do_lf = 0;
  196. int i = 0;
  197. /* Ensure transmitter is enabled! */
  198. port = 0;
  199. base_addr[CyCAR] = (u_char)port;
  200. while (base_addr[CyCCR])
  201. ;
  202. base_addr[CyCCR] = CyENB_XMTR;
  203. ier = base_addr[CyIER];
  204. base_addr[CyIER] = CyTxMpty;
  205. while (1) {
  206. if (pcc2chip[PccSCCTICR] & 0x20)
  207. {
  208. /* We have a Tx int. Acknowledge it */
  209. sink = pcc2chip[PccTPIACKR];
  210. if ((base_addr[CyLICR] >> 2) == port) {
  211. if (i == count) {
  212. /* Last char of string is now output */
  213. base_addr[CyTEOIR] = CyNOTRANS;
  214. break;
  215. }
  216. if (do_lf) {
  217. base_addr[CyTDR] = '\n';
  218. str++;
  219. i++;
  220. do_lf = 0;
  221. }
  222. else if (*str == '\n') {
  223. base_addr[CyTDR] = '\r';
  224. do_lf = 1;
  225. }
  226. else {
  227. base_addr[CyTDR] = *str++;
  228. i++;
  229. }
  230. base_addr[CyTEOIR] = 0;
  231. }
  232. else
  233. base_addr[CyTEOIR] = CyNOTRANS;
  234. }
  235. }
  236. base_addr[CyIER] = ier;
  237. }
  238. #endif
  239. void __init config_mvme16x(void)
  240. {
  241. p_bdid p = &mvme_bdid;
  242. char id[40];
  243. uint16_t brdno = be16_to_cpu(p->brdno);
  244. mach_max_dma_address = 0xffffffff;
  245. mach_sched_init = mvme16x_sched_init;
  246. mach_init_IRQ = mvme16x_init_IRQ;
  247. arch_gettimeoffset = mvme16x_gettimeoffset;
  248. mach_hwclk = mvme16x_hwclk;
  249. mach_set_clock_mmss = mvme16x_set_clock_mmss;
  250. mach_reset = mvme16x_reset;
  251. mach_get_model = mvme16x_get_model;
  252. mach_get_hardware_list = mvme16x_get_hardware_list;
  253. /* Report board revision */
  254. if (strncmp("BDID", p->bdid, 4))
  255. {
  256. printk ("\n\nBug call .BRD_ID returned garbage - giving up\n\n");
  257. while (1)
  258. ;
  259. }
  260. /* Board type is only set by newer versions of vmelilo/tftplilo */
  261. if (vme_brdtype == 0)
  262. vme_brdtype = brdno;
  263. mvme16x_get_model(id);
  264. printk ("\nBRD_ID: %s BUG %x.%x %02x/%02x/%02x\n", id, p->rev>>4,
  265. p->rev&0xf, p->yr, p->mth, p->day);
  266. if (brdno == 0x0162 || brdno == 0x172)
  267. {
  268. unsigned char rev = *(unsigned char *)MVME162_VERSION_REG;
  269. mvme16x_config = rev | MVME16x_CONFIG_GOT_SCCA;
  270. printk ("MVME%x Hardware status:\n", brdno);
  271. printk (" CPU Type 68%s040\n",
  272. rev & MVME16x_CONFIG_GOT_FPU ? "" : "LC");
  273. printk (" CPU clock %dMHz\n",
  274. rev & MVME16x_CONFIG_SPEED_32 ? 32 : 25);
  275. printk (" VMEchip2 %spresent\n",
  276. rev & MVME16x_CONFIG_NO_VMECHIP2 ? "NOT " : "");
  277. printk (" SCSI interface %spresent\n",
  278. rev & MVME16x_CONFIG_NO_SCSICHIP ? "NOT " : "");
  279. printk (" Ethernet interface %spresent\n",
  280. rev & MVME16x_CONFIG_NO_ETHERNET ? "NOT " : "");
  281. }
  282. else
  283. {
  284. mvme16x_config = MVME16x_CONFIG_GOT_LP | MVME16x_CONFIG_GOT_CD2401;
  285. }
  286. }
  287. static irqreturn_t mvme16x_abort_int (int irq, void *dev_id)
  288. {
  289. unsigned long *new = (unsigned long *)vectors;
  290. unsigned long *old = (unsigned long *)0xffe00000;
  291. volatile unsigned char uc, *ucp;
  292. uint16_t brdno = be16_to_cpu(mvme_bdid.brdno);
  293. if (brdno == 0x0162 || brdno == 0x172)
  294. {
  295. ucp = (volatile unsigned char *)0xfff42043;
  296. uc = *ucp | 8;
  297. *ucp = uc;
  298. }
  299. else
  300. {
  301. *(volatile unsigned long *)0xfff40074 = 0x40000000;
  302. }
  303. *(new+4) = *(old+4); /* Illegal instruction */
  304. *(new+9) = *(old+9); /* Trace */
  305. *(new+47) = *(old+47); /* Trap #15 */
  306. if (brdno == 0x0162 || brdno == 0x172)
  307. *(new+0x5e) = *(old+0x5e); /* ABORT switch */
  308. else
  309. *(new+0x6e) = *(old+0x6e); /* ABORT switch */
  310. return IRQ_HANDLED;
  311. }
  312. static irqreturn_t mvme16x_timer_int (int irq, void *dev_id)
  313. {
  314. *(volatile unsigned char *)0xfff4201b |= 8;
  315. return tick_handler(irq, dev_id);
  316. }
  317. void mvme16x_sched_init (irq_handler_t timer_routine)
  318. {
  319. uint16_t brdno = be16_to_cpu(mvme_bdid.brdno);
  320. int irq;
  321. tick_handler = timer_routine;
  322. /* Using PCCchip2 or MC2 chip tick timer 1 */
  323. *(volatile unsigned long *)0xfff42008 = 0;
  324. *(volatile unsigned long *)0xfff42004 = 10000; /* 10ms */
  325. *(volatile unsigned char *)0xfff42017 |= 3;
  326. *(volatile unsigned char *)0xfff4201b = 0x16;
  327. if (request_irq(MVME16x_IRQ_TIMER, mvme16x_timer_int, 0,
  328. "timer", mvme16x_timer_int))
  329. panic ("Couldn't register timer int");
  330. if (brdno == 0x0162 || brdno == 0x172)
  331. irq = MVME162_IRQ_ABORT;
  332. else
  333. irq = MVME167_IRQ_ABORT;
  334. if (request_irq(irq, mvme16x_abort_int, 0,
  335. "abort", mvme16x_abort_int))
  336. panic ("Couldn't register abort int");
  337. }
  338. /* This is always executed with interrupts disabled. */
  339. u32 mvme16x_gettimeoffset(void)
  340. {
  341. return (*(volatile u32 *)0xfff42008) * 1000;
  342. }
  343. int bcd2int (unsigned char b)
  344. {
  345. return ((b>>4)*10 + (b&15));
  346. }
  347. int mvme16x_hwclk(int op, struct rtc_time *t)
  348. {
  349. #warning check me!
  350. if (!op) {
  351. rtc->ctrl = RTC_READ;
  352. t->tm_year = bcd2int (rtc->bcd_year);
  353. t->tm_mon = bcd2int (rtc->bcd_mth);
  354. t->tm_mday = bcd2int (rtc->bcd_dom);
  355. t->tm_hour = bcd2int (rtc->bcd_hr);
  356. t->tm_min = bcd2int (rtc->bcd_min);
  357. t->tm_sec = bcd2int (rtc->bcd_sec);
  358. rtc->ctrl = 0;
  359. }
  360. return 0;
  361. }
  362. int mvme16x_set_clock_mmss (unsigned long nowtime)
  363. {
  364. return 0;
  365. }