config.c 6.9 KB

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