config.c 7.4 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/errno.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 <linux/bcd.h>
  27. #include <linux/platform_device.h>
  28. #include <asm/io.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/machdep.h>
  35. #include <asm/q40_master.h>
  36. extern void q40_init_IRQ(void);
  37. static void q40_get_model(char *model);
  38. extern void q40_sched_init(irq_handler_t handler);
  39. static u32 q40_gettimeoffset(void);
  40. static int q40_hwclk(int, struct rtc_time *);
  41. static unsigned int q40_get_ss(void);
  42. static int q40_set_clock_mmss(unsigned long);
  43. static int q40_get_rtc_pll(struct rtc_pll_info *pll);
  44. static int q40_set_rtc_pll(struct rtc_pll_info *pll);
  45. extern void q40_mksound(unsigned int /*freq*/, unsigned int /*ticks*/);
  46. static void q40_mem_console_write(struct console *co, const char *b,
  47. unsigned int count);
  48. extern int ql_ticks;
  49. static struct console q40_console_driver = {
  50. .name = "debug",
  51. .write = q40_mem_console_write,
  52. .flags = CON_PRINTBUFFER,
  53. .index = -1,
  54. };
  55. /* early debugging function:*/
  56. extern char *q40_mem_cptr; /*=(char *)0xff020000;*/
  57. static int _cpleft;
  58. static void q40_mem_console_write(struct console *co, const char *s,
  59. unsigned int count)
  60. {
  61. const char *p = s;
  62. if (count < _cpleft) {
  63. while (count-- > 0) {
  64. *q40_mem_cptr = *p++;
  65. q40_mem_cptr += 4;
  66. _cpleft--;
  67. }
  68. }
  69. }
  70. static int __init q40_debug_setup(char *arg)
  71. {
  72. /* useful for early debugging stages - writes kernel messages into SRAM */
  73. if (MACH_IS_Q40 && !strncmp(arg, "mem", 3)) {
  74. /*printk("using NVRAM debug, q40_mem_cptr=%p\n",q40_mem_cptr);*/
  75. _cpleft = 2000 - ((long)q40_mem_cptr-0xff020000) / 4;
  76. register_console(&q40_console_driver);
  77. }
  78. return 0;
  79. }
  80. early_param("debug", q40_debug_setup);
  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. *p = *str++;
  88. p += 4;
  89. }
  90. q40_mem_cptr = p;
  91. }
  92. #endif
  93. static int halted;
  94. #ifdef CONFIG_HEARTBEAT
  95. static void q40_heartbeat(int on)
  96. {
  97. if (halted)
  98. return;
  99. if (on)
  100. Q40_LED_ON();
  101. else
  102. Q40_LED_OFF();
  103. }
  104. #endif
  105. static 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. }
  115. static 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. }
  125. static void q40_get_model(char *model)
  126. {
  127. sprintf(model, "Q40");
  128. }
  129. static unsigned int serports[] =
  130. {
  131. 0x3f8,0x2f8,0x3e8,0x2e8,0
  132. };
  133. static void __init q40_disable_irqs(void)
  134. {
  135. unsigned i, j;
  136. j = 0;
  137. while ((i = serports[j++]))
  138. 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. arch_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_get_model = q40_get_model;
  154. #if IS_ENABLED(CONFIG_INPUT_M68K_BEEP)
  155. mach_beep = q40_mksound;
  156. #endif
  157. #ifdef CONFIG_HEARTBEAT
  158. mach_heartbeat = q40_heartbeat;
  159. #endif
  160. mach_halt = q40_halt;
  161. /* disable a few things that SMSQ might have left enabled */
  162. q40_disable_irqs();
  163. /* no DMA at all, but ide-scsi requires it.. make sure
  164. * all physical RAM fits into the boundary - otherwise
  165. * allocator may play costly and useless tricks */
  166. mach_max_dma_address = 1024*1024*1024;
  167. }
  168. int __init q40_parse_bootinfo(const struct bi_record *rec)
  169. {
  170. return 1;
  171. }
  172. static u32 q40_gettimeoffset(void)
  173. {
  174. return 5000 * (ql_ticks != 0) * 1000;
  175. }
  176. /*
  177. * Looks like op is non-zero for setting the clock, and zero for
  178. * reading the clock.
  179. *
  180. * struct hwclk_time {
  181. * unsigned sec; 0..59
  182. * unsigned min; 0..59
  183. * unsigned hour; 0..23
  184. * unsigned day; 1..31
  185. * unsigned mon; 0..11
  186. * unsigned year; 00...
  187. * int wday; 0..6, 0 is Sunday, -1 means unknown/don't set
  188. * };
  189. */
  190. static int q40_hwclk(int op, struct rtc_time *t)
  191. {
  192. if (op) {
  193. /* Write.... */
  194. Q40_RTC_CTRL |= Q40_RTC_WRITE;
  195. Q40_RTC_SECS = bin2bcd(t->tm_sec);
  196. Q40_RTC_MINS = bin2bcd(t->tm_min);
  197. Q40_RTC_HOUR = bin2bcd(t->tm_hour);
  198. Q40_RTC_DATE = bin2bcd(t->tm_mday);
  199. Q40_RTC_MNTH = bin2bcd(t->tm_mon + 1);
  200. Q40_RTC_YEAR = bin2bcd(t->tm_year%100);
  201. if (t->tm_wday >= 0)
  202. Q40_RTC_DOW = bin2bcd(t->tm_wday+1);
  203. Q40_RTC_CTRL &= ~(Q40_RTC_WRITE);
  204. } else {
  205. /* Read.... */
  206. Q40_RTC_CTRL |= Q40_RTC_READ;
  207. t->tm_year = bcd2bin (Q40_RTC_YEAR);
  208. t->tm_mon = bcd2bin (Q40_RTC_MNTH)-1;
  209. t->tm_mday = bcd2bin (Q40_RTC_DATE);
  210. t->tm_hour = bcd2bin (Q40_RTC_HOUR);
  211. t->tm_min = bcd2bin (Q40_RTC_MINS);
  212. t->tm_sec = bcd2bin (Q40_RTC_SECS);
  213. Q40_RTC_CTRL &= ~(Q40_RTC_READ);
  214. if (t->tm_year < 70)
  215. t->tm_year += 100;
  216. t->tm_wday = bcd2bin(Q40_RTC_DOW)-1;
  217. }
  218. return 0;
  219. }
  220. static unsigned int q40_get_ss(void)
  221. {
  222. return bcd2bin(Q40_RTC_SECS);
  223. }
  224. /*
  225. * Set the minutes and seconds from seconds value 'nowtime'. Fail if
  226. * clock is out by > 30 minutes. Logic lifted from atari code.
  227. */
  228. static int q40_set_clock_mmss(unsigned long nowtime)
  229. {
  230. int retval = 0;
  231. short real_seconds = nowtime % 60, real_minutes = (nowtime / 60) % 60;
  232. int rtc_minutes;
  233. rtc_minutes = bcd2bin(Q40_RTC_MINS);
  234. if ((rtc_minutes < real_minutes ?
  235. real_minutes - rtc_minutes :
  236. rtc_minutes - real_minutes) < 30) {
  237. Q40_RTC_CTRL |= Q40_RTC_WRITE;
  238. Q40_RTC_MINS = bin2bcd(real_minutes);
  239. Q40_RTC_SECS = bin2bcd(real_seconds);
  240. Q40_RTC_CTRL &= ~(Q40_RTC_WRITE);
  241. } else
  242. retval = -1;
  243. return retval;
  244. }
  245. /* get and set PLL calibration of RTC clock */
  246. #define Q40_RTC_PLL_MASK ((1<<5)-1)
  247. #define Q40_RTC_PLL_SIGN (1<<5)
  248. static int q40_get_rtc_pll(struct rtc_pll_info *pll)
  249. {
  250. int tmp = Q40_RTC_CTRL;
  251. pll->pll_value = tmp & Q40_RTC_PLL_MASK;
  252. if (tmp & Q40_RTC_PLL_SIGN)
  253. pll->pll_value = -pll->pll_value;
  254. pll->pll_max = 31;
  255. pll->pll_min = -31;
  256. pll->pll_posmult = 512;
  257. pll->pll_negmult = 256;
  258. pll->pll_clock = 125829120;
  259. return 0;
  260. }
  261. static int q40_set_rtc_pll(struct rtc_pll_info *pll)
  262. {
  263. if (!pll->pll_ctrl) {
  264. /* the docs are a bit unclear so I am doublesetting */
  265. /* RTC_WRITE here ... */
  266. int tmp = (pll->pll_value & 31) | (pll->pll_value<0 ? 32 : 0) |
  267. Q40_RTC_WRITE;
  268. Q40_RTC_CTRL |= Q40_RTC_WRITE;
  269. Q40_RTC_CTRL = tmp;
  270. Q40_RTC_CTRL &= ~(Q40_RTC_WRITE);
  271. return 0;
  272. } else
  273. return -EINVAL;
  274. }
  275. static __init int q40_add_kbd_device(void)
  276. {
  277. struct platform_device *pdev;
  278. if (!MACH_IS_Q40)
  279. return -ENODEV;
  280. pdev = platform_device_register_simple("q40kbd", -1, NULL, 0);
  281. return PTR_ERR_OR_ZERO(pdev);
  282. }
  283. arch_initcall(q40_add_kbd_device);