config.c 7.7 KB

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