config.c 11 KB

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