config.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. /*
  2. * arch/m68k/q40/config.c
  3. *
  4. * Copyright (C) 1999 Richard Zidlicky
  5. *
  6. * originally based on:
  7. *
  8. * linux/bvme/config.c
  9. *
  10. * This file is subject to the terms and conditions of the GNU General Public
  11. * License. See the file README.legal in the main directory of this archive
  12. * for more details.
  13. */
  14. #include <linux/config.h>
  15. #include <linux/types.h>
  16. #include <linux/kernel.h>
  17. #include <linux/mm.h>
  18. #include <linux/tty.h>
  19. #include <linux/console.h>
  20. #include <linux/linkage.h>
  21. #include <linux/init.h>
  22. #include <linux/major.h>
  23. #include <linux/serial_reg.h>
  24. #include <linux/rtc.h>
  25. #include <linux/vt_kern.h>
  26. #include <asm/io.h>
  27. #include <asm/rtc.h>
  28. #include <asm/bootinfo.h>
  29. #include <asm/system.h>
  30. #include <asm/pgtable.h>
  31. #include <asm/setup.h>
  32. #include <asm/irq.h>
  33. #include <asm/traps.h>
  34. #include <asm/machdep.h>
  35. #include <asm/q40_master.h>
  36. extern irqreturn_t q40_process_int (int level, struct pt_regs *regs);
  37. extern irqreturn_t (*q40_default_handler[]) (int, void *, struct pt_regs *); /* added just for debugging */
  38. extern void q40_init_IRQ (void);
  39. extern void q40_free_irq (unsigned int, void *);
  40. extern int show_q40_interrupts (struct seq_file *, void *);
  41. extern void q40_enable_irq (unsigned int);
  42. extern void q40_disable_irq (unsigned int);
  43. static void q40_get_model(char *model);
  44. static int q40_get_hardware_list(char *buffer);
  45. extern int q40_request_irq(unsigned int irq, irqreturn_t (*handler)(int, void *, struct pt_regs *), unsigned long flags, const char *devname, void *dev_id);
  46. extern void q40_sched_init(irqreturn_t (*handler)(int, void *, struct pt_regs *));
  47. extern unsigned long q40_gettimeoffset (void);
  48. extern int q40_hwclk (int, struct rtc_time *);
  49. extern unsigned int q40_get_ss (void);
  50. extern int q40_set_clock_mmss (unsigned long);
  51. static int q40_get_rtc_pll(struct rtc_pll_info *pll);
  52. static int q40_set_rtc_pll(struct rtc_pll_info *pll);
  53. extern void q40_reset (void);
  54. void q40_halt(void);
  55. extern void q40_waitbut(void);
  56. void q40_set_vectors (void);
  57. extern void q40_mksound(unsigned int /*freq*/, unsigned int /*ticks*/ );
  58. extern char m68k_debug_device[];
  59. static void q40_mem_console_write(struct console *co, const char *b,
  60. unsigned int count);
  61. extern int ql_ticks;
  62. static struct console q40_console_driver = {
  63. .name = "debug",
  64. .flags = CON_PRINTBUFFER,
  65. .index = -1,
  66. };
  67. /* early debugging function:*/
  68. extern char *q40_mem_cptr; /*=(char *)0xff020000;*/
  69. static int _cpleft;
  70. static void q40_mem_console_write(struct console *co, const char *s,
  71. unsigned int count)
  72. {
  73. char *p=(char *)s;
  74. if (count<_cpleft)
  75. while (count-- >0){
  76. *q40_mem_cptr=*p++;
  77. q40_mem_cptr+=4;
  78. _cpleft--;
  79. }
  80. }
  81. #if 0
  82. void printq40(char *str)
  83. {
  84. int l=strlen(str);
  85. char *p=q40_mem_cptr;
  86. while (l-- >0 && _cpleft-- >0)
  87. {
  88. *p=*str++;
  89. p+=4;
  90. }
  91. q40_mem_cptr=p;
  92. }
  93. #endif
  94. static int halted=0;
  95. #ifdef CONFIG_HEARTBEAT
  96. static void q40_heartbeat(int on)
  97. {
  98. if (halted) return;
  99. if (on)
  100. Q40_LED_ON();
  101. else
  102. Q40_LED_OFF();
  103. }
  104. #endif
  105. void q40_reset(void)
  106. {
  107. halted=1;
  108. printk ("\n\n*******************************************\n"
  109. "Called q40_reset : press the RESET button!! \n"
  110. "*******************************************\n");
  111. Q40_LED_ON();
  112. while(1) ;
  113. }
  114. void q40_halt(void)
  115. {
  116. halted=1;
  117. printk ("\n\n*******************\n"
  118. " Called q40_halt\n"
  119. "*******************\n");
  120. Q40_LED_ON();
  121. while(1) ;
  122. }
  123. static void q40_get_model(char *model)
  124. {
  125. sprintf(model, "Q40");
  126. }
  127. /* No hardware options on Q40? */
  128. static int q40_get_hardware_list(char *buffer)
  129. {
  130. *buffer = '\0';
  131. return 0;
  132. }
  133. static unsigned int serports[]={0x3f8,0x2f8,0x3e8,0x2e8,0};
  134. void q40_disable_irqs(void)
  135. {
  136. unsigned i,j;
  137. j=0;
  138. while((i=serports[j++])) outb(0,i+UART_IER);
  139. master_outb(0,EXT_ENABLE_REG);
  140. master_outb(0,KEY_IRQ_ENABLE_REG);
  141. }
  142. void __init config_q40(void)
  143. {
  144. mach_sched_init = q40_sched_init;
  145. mach_init_IRQ = q40_init_IRQ;
  146. mach_gettimeoffset = q40_gettimeoffset;
  147. mach_hwclk = q40_hwclk;
  148. mach_get_ss = q40_get_ss;
  149. mach_get_rtc_pll = q40_get_rtc_pll;
  150. mach_set_rtc_pll = q40_set_rtc_pll;
  151. mach_set_clock_mmss = q40_set_clock_mmss;
  152. mach_reset = q40_reset;
  153. mach_free_irq = q40_free_irq;
  154. mach_process_int = q40_process_int;
  155. mach_get_irq_list = show_q40_interrupts;
  156. mach_request_irq = q40_request_irq;
  157. enable_irq = q40_enable_irq;
  158. disable_irq = q40_disable_irq;
  159. mach_default_handler = &q40_default_handler;
  160. mach_get_model = q40_get_model;
  161. mach_get_hardware_list = q40_get_hardware_list;
  162. #if defined(CONFIG_INPUT_M68K_BEEP) || defined(CONFIG_INPUT_M68K_BEEP_MODULE)
  163. mach_beep = q40_mksound;
  164. #endif
  165. #ifdef CONFIG_HEARTBEAT
  166. mach_heartbeat = q40_heartbeat;
  167. #endif
  168. mach_halt = q40_halt;
  169. /* disable a few things that SMSQ might have left enabled */
  170. q40_disable_irqs();
  171. /* no DMA at all, but ide-scsi requires it.. make sure
  172. * all physical RAM fits into the boundary - otherwise
  173. * allocator may play costly and useless tricks */
  174. mach_max_dma_address = 1024*1024*1024;
  175. /* useful for early debugging stages - writes kernel messages into SRAM */
  176. if (!strncmp( m68k_debug_device,"mem",3 ))
  177. {
  178. /*printk("using NVRAM debug, q40_mem_cptr=%p\n",q40_mem_cptr);*/
  179. _cpleft=2000-((long)q40_mem_cptr-0xff020000)/4;
  180. q40_console_driver.write = q40_mem_console_write;
  181. register_console(&q40_console_driver);
  182. }
  183. }
  184. int q40_parse_bootinfo(const struct bi_record *rec)
  185. {
  186. return 1;
  187. }
  188. static inline unsigned char bcd2bin (unsigned char b)
  189. {
  190. return ((b>>4)*10 + (b&15));
  191. }
  192. static inline unsigned char bin2bcd (unsigned char b)
  193. {
  194. return (((b/10)*16) + (b%10));
  195. }
  196. unsigned long q40_gettimeoffset (void)
  197. {
  198. return 5000*(ql_ticks!=0);
  199. }
  200. /*
  201. * Looks like op is non-zero for setting the clock, and zero for
  202. * reading the clock.
  203. *
  204. * struct hwclk_time {
  205. * unsigned sec; 0..59
  206. * unsigned min; 0..59
  207. * unsigned hour; 0..23
  208. * unsigned day; 1..31
  209. * unsigned mon; 0..11
  210. * unsigned year; 00...
  211. * int wday; 0..6, 0 is Sunday, -1 means unknown/don't set
  212. * };
  213. */
  214. int q40_hwclk(int op, struct rtc_time *t)
  215. {
  216. if (op)
  217. { /* Write.... */
  218. Q40_RTC_CTRL |= Q40_RTC_WRITE;
  219. Q40_RTC_SECS = bin2bcd(t->tm_sec);
  220. Q40_RTC_MINS = bin2bcd(t->tm_min);
  221. Q40_RTC_HOUR = bin2bcd(t->tm_hour);
  222. Q40_RTC_DATE = bin2bcd(t->tm_mday);
  223. Q40_RTC_MNTH = bin2bcd(t->tm_mon + 1);
  224. Q40_RTC_YEAR = bin2bcd(t->tm_year%100);
  225. if (t->tm_wday >= 0)
  226. Q40_RTC_DOW = bin2bcd(t->tm_wday+1);
  227. Q40_RTC_CTRL &= ~(Q40_RTC_WRITE);
  228. }
  229. else
  230. { /* Read.... */
  231. Q40_RTC_CTRL |= Q40_RTC_READ;
  232. t->tm_year = bcd2bin (Q40_RTC_YEAR);
  233. t->tm_mon = bcd2bin (Q40_RTC_MNTH)-1;
  234. t->tm_mday = bcd2bin (Q40_RTC_DATE);
  235. t->tm_hour = bcd2bin (Q40_RTC_HOUR);
  236. t->tm_min = bcd2bin (Q40_RTC_MINS);
  237. t->tm_sec = bcd2bin (Q40_RTC_SECS);
  238. Q40_RTC_CTRL &= ~(Q40_RTC_READ);
  239. if (t->tm_year < 70)
  240. t->tm_year += 100;
  241. t->tm_wday = bcd2bin(Q40_RTC_DOW)-1;
  242. }
  243. return 0;
  244. }
  245. unsigned int q40_get_ss(void)
  246. {
  247. return bcd2bin(Q40_RTC_SECS);
  248. }
  249. /*
  250. * Set the minutes and seconds from seconds value 'nowtime'. Fail if
  251. * clock is out by > 30 minutes. Logic lifted from atari code.
  252. */
  253. int q40_set_clock_mmss (unsigned long nowtime)
  254. {
  255. int retval = 0;
  256. short real_seconds = nowtime % 60, real_minutes = (nowtime / 60) % 60;
  257. int rtc_minutes;
  258. rtc_minutes = bcd2bin (Q40_RTC_MINS);
  259. if ((rtc_minutes < real_minutes
  260. ? real_minutes - rtc_minutes
  261. : rtc_minutes - real_minutes) < 30)
  262. {
  263. Q40_RTC_CTRL |= Q40_RTC_WRITE;
  264. Q40_RTC_MINS = bin2bcd(real_minutes);
  265. Q40_RTC_SECS = bin2bcd(real_seconds);
  266. Q40_RTC_CTRL &= ~(Q40_RTC_WRITE);
  267. }
  268. else
  269. retval = -1;
  270. return retval;
  271. }
  272. /* get and set PLL calibration of RTC clock */
  273. #define Q40_RTC_PLL_MASK ((1<<5)-1)
  274. #define Q40_RTC_PLL_SIGN (1<<5)
  275. static int q40_get_rtc_pll(struct rtc_pll_info *pll)
  276. {
  277. int tmp=Q40_RTC_CTRL;
  278. pll->pll_value = tmp & Q40_RTC_PLL_MASK;
  279. if (tmp & Q40_RTC_PLL_SIGN)
  280. pll->pll_value = -pll->pll_value;
  281. pll->pll_max=31;
  282. pll->pll_min=-31;
  283. pll->pll_posmult=512;
  284. pll->pll_negmult=256;
  285. pll->pll_clock=125829120;
  286. return 0;
  287. }
  288. static int q40_set_rtc_pll(struct rtc_pll_info *pll)
  289. {
  290. if (!pll->pll_ctrl){
  291. /* the docs are a bit unclear so I am doublesetting */
  292. /* RTC_WRITE here ... */
  293. int tmp = (pll->pll_value & 31) | (pll->pll_value<0 ? 32 : 0) |
  294. Q40_RTC_WRITE;
  295. Q40_RTC_CTRL |= Q40_RTC_WRITE;
  296. Q40_RTC_CTRL = tmp;
  297. Q40_RTC_CTRL &= ~(Q40_RTC_WRITE);
  298. return 0;
  299. } else
  300. return -EINVAL;
  301. }