config.c 8.7 KB

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