config.c 7.5 KB

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