config.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * arch/m68k/q40/config.c
  4. *
  5. * Copyright (C) 1999 Richard Zidlicky
  6. *
  7. * originally based on:
  8. *
  9. * linux/bvme/config.c
  10. */
  11. #include <linux/errno.h>
  12. #include <linux/types.h>
  13. #include <linux/kernel.h>
  14. #include <linux/mm.h>
  15. #include <linux/tty.h>
  16. #include <linux/console.h>
  17. #include <linux/linkage.h>
  18. #include <linux/init.h>
  19. #include <linux/major.h>
  20. #include <linux/serial_reg.h>
  21. #include <linux/rtc.h>
  22. #include <linux/vt_kern.h>
  23. #include <linux/bcd.h>
  24. #include <linux/platform_device.h>
  25. #include <asm/io.h>
  26. #include <asm/bootinfo.h>
  27. #include <asm/setup.h>
  28. #include <asm/irq.h>
  29. #include <asm/traps.h>
  30. #include <asm/machdep.h>
  31. #include <asm/q40_master.h>
  32. #include <asm/config.h>
  33. #include "q40.h"
  34. static void q40_get_model(char *model);
  35. static int q40_hwclk(int, struct rtc_time *);
  36. static int q40_get_rtc_pll(struct rtc_pll_info *pll);
  37. static int q40_set_rtc_pll(struct rtc_pll_info *pll);
  38. static void q40_mem_console_write(struct console *co, const char *b,
  39. unsigned int count);
  40. extern int ql_ticks;
  41. static struct console q40_console_driver = {
  42. .name = "debug",
  43. .write = q40_mem_console_write,
  44. .flags = CON_PRINTBUFFER,
  45. .index = -1,
  46. };
  47. /* early debugging function:*/
  48. extern char *q40_mem_cptr; /*=(char *)0xff020000;*/
  49. static int _cpleft;
  50. static void q40_mem_console_write(struct console *co, const char *s,
  51. unsigned int count)
  52. {
  53. const char *p = s;
  54. if (count < _cpleft) {
  55. while (count-- > 0) {
  56. *q40_mem_cptr = *p++;
  57. q40_mem_cptr += 4;
  58. _cpleft--;
  59. }
  60. }
  61. }
  62. static int __init q40_debug_setup(char *arg)
  63. {
  64. /* useful for early debugging stages - writes kernel messages into SRAM */
  65. if (MACH_IS_Q40 && !strncmp(arg, "mem", 3)) {
  66. /*pr_info("using NVRAM debug, q40_mem_cptr=%p\n",q40_mem_cptr);*/
  67. _cpleft = 2000 - ((long)q40_mem_cptr-0xff020000) / 4;
  68. register_console(&q40_console_driver);
  69. }
  70. return 0;
  71. }
  72. early_param("debug", q40_debug_setup);
  73. #if 0
  74. void printq40(char *str)
  75. {
  76. int l = strlen(str);
  77. char *p = q40_mem_cptr;
  78. while (l-- > 0 && _cpleft-- > 0) {
  79. *p = *str++;
  80. p += 4;
  81. }
  82. q40_mem_cptr = p;
  83. }
  84. #endif
  85. static int halted;
  86. #ifdef CONFIG_HEARTBEAT
  87. static void q40_heartbeat(int on)
  88. {
  89. if (halted)
  90. return;
  91. if (on)
  92. Q40_LED_ON();
  93. else
  94. Q40_LED_OFF();
  95. }
  96. #endif
  97. static void q40_reset(void)
  98. {
  99. halted = 1;
  100. pr_info("*******************************************\n"
  101. "Called q40_reset : press the RESET button!!\n"
  102. "*******************************************\n");
  103. Q40_LED_ON();
  104. while (1)
  105. ;
  106. }
  107. static void q40_halt(void)
  108. {
  109. halted = 1;
  110. pr_info("*******************\n"
  111. " Called q40_halt\n"
  112. "*******************\n");
  113. Q40_LED_ON();
  114. while (1)
  115. ;
  116. }
  117. static void q40_get_model(char *model)
  118. {
  119. sprintf(model, "Q40");
  120. }
  121. static unsigned int serports[] =
  122. {
  123. 0x3f8,0x2f8,0x3e8,0x2e8,0
  124. };
  125. static void __init q40_disable_irqs(void)
  126. {
  127. unsigned i, j;
  128. j = 0;
  129. while ((i = serports[j++]))
  130. outb(0, i + UART_IER);
  131. master_outb(0, EXT_ENABLE_REG);
  132. master_outb(0, KEY_IRQ_ENABLE_REG);
  133. }
  134. void __init config_q40(void)
  135. {
  136. mach_sched_init = q40_sched_init;
  137. mach_init_IRQ = q40_init_IRQ;
  138. mach_hwclk = q40_hwclk;
  139. mach_get_rtc_pll = q40_get_rtc_pll;
  140. mach_set_rtc_pll = q40_set_rtc_pll;
  141. mach_reset = q40_reset;
  142. mach_get_model = q40_get_model;
  143. #if IS_ENABLED(CONFIG_INPUT_M68K_BEEP)
  144. mach_beep = q40_mksound;
  145. #endif
  146. #ifdef CONFIG_HEARTBEAT
  147. mach_heartbeat = q40_heartbeat;
  148. #endif
  149. mach_halt = q40_halt;
  150. /* disable a few things that SMSQ might have left enabled */
  151. q40_disable_irqs();
  152. }
  153. int __init q40_parse_bootinfo(const struct bi_record *rec)
  154. {
  155. return 1;
  156. }
  157. /*
  158. * Looks like op is non-zero for setting the clock, and zero for
  159. * reading the clock.
  160. *
  161. * struct hwclk_time {
  162. * unsigned sec; 0..59
  163. * unsigned min; 0..59
  164. * unsigned hour; 0..23
  165. * unsigned day; 1..31
  166. * unsigned mon; 0..11
  167. * unsigned year; 00...
  168. * int wday; 0..6, 0 is Sunday, -1 means unknown/don't set
  169. * };
  170. */
  171. static int q40_hwclk(int op, struct rtc_time *t)
  172. {
  173. if (op) {
  174. /* Write.... */
  175. Q40_RTC_CTRL |= Q40_RTC_WRITE;
  176. Q40_RTC_SECS = bin2bcd(t->tm_sec);
  177. Q40_RTC_MINS = bin2bcd(t->tm_min);
  178. Q40_RTC_HOUR = bin2bcd(t->tm_hour);
  179. Q40_RTC_DATE = bin2bcd(t->tm_mday);
  180. Q40_RTC_MNTH = bin2bcd(t->tm_mon + 1);
  181. Q40_RTC_YEAR = bin2bcd(t->tm_year%100);
  182. if (t->tm_wday >= 0)
  183. Q40_RTC_DOW = bin2bcd(t->tm_wday+1);
  184. Q40_RTC_CTRL &= ~(Q40_RTC_WRITE);
  185. } else {
  186. /* Read.... */
  187. Q40_RTC_CTRL |= Q40_RTC_READ;
  188. t->tm_year = bcd2bin (Q40_RTC_YEAR);
  189. t->tm_mon = bcd2bin (Q40_RTC_MNTH)-1;
  190. t->tm_mday = bcd2bin (Q40_RTC_DATE);
  191. t->tm_hour = bcd2bin (Q40_RTC_HOUR);
  192. t->tm_min = bcd2bin (Q40_RTC_MINS);
  193. t->tm_sec = bcd2bin (Q40_RTC_SECS);
  194. Q40_RTC_CTRL &= ~(Q40_RTC_READ);
  195. if (t->tm_year < 70)
  196. t->tm_year += 100;
  197. t->tm_wday = bcd2bin(Q40_RTC_DOW)-1;
  198. }
  199. return 0;
  200. }
  201. /* get and set PLL calibration of RTC clock */
  202. #define Q40_RTC_PLL_MASK ((1<<5)-1)
  203. #define Q40_RTC_PLL_SIGN (1<<5)
  204. static int q40_get_rtc_pll(struct rtc_pll_info *pll)
  205. {
  206. int tmp = Q40_RTC_CTRL;
  207. pll->pll_ctrl = 0;
  208. pll->pll_value = tmp & Q40_RTC_PLL_MASK;
  209. if (tmp & Q40_RTC_PLL_SIGN)
  210. pll->pll_value = -pll->pll_value;
  211. pll->pll_max = 31;
  212. pll->pll_min = -31;
  213. pll->pll_posmult = 512;
  214. pll->pll_negmult = 256;
  215. pll->pll_clock = 125829120;
  216. return 0;
  217. }
  218. static int q40_set_rtc_pll(struct rtc_pll_info *pll)
  219. {
  220. if (!pll->pll_ctrl) {
  221. /* the docs are a bit unclear so I am doublesetting */
  222. /* RTC_WRITE here ... */
  223. int tmp = (pll->pll_value & 31) | (pll->pll_value<0 ? 32 : 0) |
  224. Q40_RTC_WRITE;
  225. Q40_RTC_CTRL |= Q40_RTC_WRITE;
  226. Q40_RTC_CTRL = tmp;
  227. Q40_RTC_CTRL &= ~(Q40_RTC_WRITE);
  228. return 0;
  229. } else
  230. return -EINVAL;
  231. }
  232. #define PCIDE_BASE1 0x1f0
  233. #define PCIDE_BASE2 0x170
  234. #define PCIDE_CTL 0x206
  235. static const struct resource q40_pata_rsrc_0[] __initconst = {
  236. DEFINE_RES_MEM(q40_isa_io_base + PCIDE_BASE1 * 4, 0x38),
  237. DEFINE_RES_MEM(q40_isa_io_base + (PCIDE_BASE1 + PCIDE_CTL) * 4, 2),
  238. DEFINE_RES_IO(PCIDE_BASE1, 8),
  239. DEFINE_RES_IO(PCIDE_BASE1 + PCIDE_CTL, 1),
  240. DEFINE_RES_IRQ(14),
  241. };
  242. static const struct resource q40_pata_rsrc_1[] __initconst = {
  243. DEFINE_RES_MEM(q40_isa_io_base + PCIDE_BASE2 * 4, 0x38),
  244. DEFINE_RES_MEM(q40_isa_io_base + (PCIDE_BASE2 + PCIDE_CTL) * 4, 2),
  245. DEFINE_RES_IO(PCIDE_BASE2, 8),
  246. DEFINE_RES_IO(PCIDE_BASE2 + PCIDE_CTL, 1),
  247. DEFINE_RES_IRQ(15),
  248. };
  249. static __init int q40_platform_init(void)
  250. {
  251. if (!MACH_IS_Q40)
  252. return -ENODEV;
  253. platform_device_register_simple("q40kbd", -1, NULL, 0);
  254. platform_device_register_simple("atari-falcon-ide", 0, q40_pata_rsrc_0,
  255. ARRAY_SIZE(q40_pata_rsrc_0));
  256. platform_device_register_simple("atari-falcon-ide", 1, q40_pata_rsrc_1,
  257. ARRAY_SIZE(q40_pata_rsrc_1));
  258. return 0;
  259. }
  260. arch_initcall(q40_platform_init);