blob: be9de2f3dc48ee1da88283072e49a28890329122 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#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
27#include <asm/io.h>
28#include <asm/rtc.h>
29#include <asm/bootinfo.h>
30#include <asm/system.h>
31#include <asm/pgtable.h>
32#include <asm/setup.h>
33#include <asm/irq.h>
34#include <asm/traps.h>
35#include <asm/machdep.h>
36#include <asm/q40_master.h>
37
Roman Zippel6ff58012007-05-01 22:32:43 +020038extern irqreturn_t q40_process_int(int level, struct pt_regs *regs);
39extern void q40_init_IRQ(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040static void q40_get_model(char *model);
41static int q40_get_hardware_list(char *buffer);
David Howells40220c12006-10-09 12:19:47 +010042extern void q40_sched_init(irq_handler_t handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Adrian Bunk22deb522008-07-17 21:16:26 +020044static unsigned long q40_gettimeoffset(void);
45static int q40_hwclk(int, struct rtc_time *);
46static unsigned int q40_get_ss(void);
47static int q40_set_clock_mmss(unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048static int q40_get_rtc_pll(struct rtc_pll_info *pll);
49static int q40_set_rtc_pll(struct rtc_pll_info *pll);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050extern void q40_waitbut(void);
Roman Zippel6ff58012007-05-01 22:32:43 +020051void q40_set_vectors(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Roman Zippel6ff58012007-05-01 22:32:43 +020053extern void q40_mksound(unsigned int /*freq*/, unsigned int /*ticks*/);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Linus Torvalds1da177e2005-04-16 15:20:36 -070055static void q40_mem_console_write(struct console *co, const char *b,
Roman Zippel6ff58012007-05-01 22:32:43 +020056 unsigned int count);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58extern int ql_ticks;
59
60static struct console q40_console_driver = {
Roman Zippel6ff58012007-05-01 22:32:43 +020061 .name = "debug",
Roman Zippeld6713b42007-05-01 22:32:45 +020062 .write = q40_mem_console_write,
Roman Zippel6ff58012007-05-01 22:32:43 +020063 .flags = CON_PRINTBUFFER,
64 .index = -1,
Linus Torvalds1da177e2005-04-16 15:20:36 -070065};
66
67
68/* early debugging function:*/
69extern char *q40_mem_cptr; /*=(char *)0xff020000;*/
70static int _cpleft;
71
72static void q40_mem_console_write(struct console *co, const char *s,
73 unsigned int count)
74{
Roman Zippel6ff58012007-05-01 22:32:43 +020075 const char *p = s;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Roman Zippel6ff58012007-05-01 22:32:43 +020077 if (count < _cpleft) {
78 while (count-- > 0) {
79 *q40_mem_cptr = *p++;
80 q40_mem_cptr += 4;
81 _cpleft--;
82 }
83 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070084}
Roman Zippel6ff58012007-05-01 22:32:43 +020085
Roman Zippeld6713b42007-05-01 22:32:45 +020086static int __init q40_debug_setup(char *arg)
87{
88 /* useful for early debugging stages - writes kernel messages into SRAM */
89 if (MACH_IS_Q40 && !strncmp(arg, "mem", 3)) {
90 /*printk("using NVRAM debug, q40_mem_cptr=%p\n",q40_mem_cptr);*/
91 _cpleft = 2000 - ((long)q40_mem_cptr-0xff020000) / 4;
92 register_console(&q40_console_driver);
93 }
94 return 0;
95}
96
97early_param("debug", q40_debug_setup);
98
Linus Torvalds1da177e2005-04-16 15:20:36 -070099#if 0
100void printq40(char *str)
101{
Roman Zippel6ff58012007-05-01 22:32:43 +0200102 int l = strlen(str);
103 char *p = q40_mem_cptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
Roman Zippel6ff58012007-05-01 22:32:43 +0200105 while (l-- > 0 && _cpleft-- > 0) {
106 *p = *str++;
107 p += 4;
108 }
109 q40_mem_cptr = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110}
111#endif
112
Roman Zippel6ff58012007-05-01 22:32:43 +0200113static int halted;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115#ifdef CONFIG_HEARTBEAT
116static void q40_heartbeat(int on)
117{
Roman Zippel6ff58012007-05-01 22:32:43 +0200118 if (halted)
119 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
Roman Zippel6ff58012007-05-01 22:32:43 +0200121 if (on)
122 Q40_LED_ON();
123 else
124 Q40_LED_OFF();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125}
126#endif
127
Adrian Bunk22deb522008-07-17 21:16:26 +0200128static void q40_reset(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129{
Roman Zippel6ff58012007-05-01 22:32:43 +0200130 halted = 1;
131 printk("\n\n*******************************************\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 "Called q40_reset : press the RESET button!! \n"
133 "*******************************************\n");
134 Q40_LED_ON();
Roman Zippel6ff58012007-05-01 22:32:43 +0200135 while (1)
136 ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137}
Adrian Bunk22deb522008-07-17 21:16:26 +0200138
139static void q40_halt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140{
Roman Zippel6ff58012007-05-01 22:32:43 +0200141 halted = 1;
142 printk("\n\n*******************\n"
143 " Called q40_halt\n"
144 "*******************\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 Q40_LED_ON();
Roman Zippel6ff58012007-05-01 22:32:43 +0200146 while (1)
147 ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148}
149
150static void q40_get_model(char *model)
151{
Roman Zippel6ff58012007-05-01 22:32:43 +0200152 sprintf(model, "Q40");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153}
154
155/* No hardware options on Q40? */
156
157static int q40_get_hardware_list(char *buffer)
158{
Roman Zippel6ff58012007-05-01 22:32:43 +0200159 *buffer = '\0';
160 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161}
162
Roman Zippel6ff58012007-05-01 22:32:43 +0200163static unsigned int serports[] =
164{
165 0x3f8,0x2f8,0x3e8,0x2e8,0
166};
Adrian Bunk22deb522008-07-17 21:16:26 +0200167
168static void q40_disable_irqs(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169{
Roman Zippel6ff58012007-05-01 22:32:43 +0200170 unsigned i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
Roman Zippel6ff58012007-05-01 22:32:43 +0200172 j = 0;
173 while ((i = serports[j++]))
174 outb(0, i + UART_IER);
175 master_outb(0, EXT_ENABLE_REG);
176 master_outb(0, KEY_IRQ_ENABLE_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177}
178
179void __init config_q40(void)
180{
Roman Zippel6ff58012007-05-01 22:32:43 +0200181 mach_sched_init = q40_sched_init;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
Roman Zippel6ff58012007-05-01 22:32:43 +0200183 mach_init_IRQ = q40_init_IRQ;
184 mach_gettimeoffset = q40_gettimeoffset;
185 mach_hwclk = q40_hwclk;
186 mach_get_ss = q40_get_ss;
187 mach_get_rtc_pll = q40_get_rtc_pll;
188 mach_set_rtc_pll = q40_set_rtc_pll;
189 mach_set_clock_mmss = q40_set_clock_mmss;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
Roman Zippel6ff58012007-05-01 22:32:43 +0200191 mach_reset = q40_reset;
192 mach_get_model = q40_get_model;
193 mach_get_hardware_list = q40_get_hardware_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
195#if defined(CONFIG_INPUT_M68K_BEEP) || defined(CONFIG_INPUT_M68K_BEEP_MODULE)
Roman Zippel6ff58012007-05-01 22:32:43 +0200196 mach_beep = q40_mksound;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197#endif
198#ifdef CONFIG_HEARTBEAT
Roman Zippel6ff58012007-05-01 22:32:43 +0200199 mach_heartbeat = q40_heartbeat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200#endif
Roman Zippel6ff58012007-05-01 22:32:43 +0200201 mach_halt = q40_halt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
Roman Zippel6ff58012007-05-01 22:32:43 +0200203 /* disable a few things that SMSQ might have left enabled */
204 q40_disable_irqs();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
Roman Zippel6ff58012007-05-01 22:32:43 +0200206 /* no DMA at all, but ide-scsi requires it.. make sure
207 * all physical RAM fits into the boundary - otherwise
208 * allocator may play costly and useless tricks */
209 mach_max_dma_address = 1024*1024*1024;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210}
211
212
213int q40_parse_bootinfo(const struct bi_record *rec)
214{
Roman Zippel6ff58012007-05-01 22:32:43 +0200215 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216}
217
218
Roman Zippel6ff58012007-05-01 22:32:43 +0200219static inline unsigned char bcd2bin(unsigned char b)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
Roman Zippel6ff58012007-05-01 22:32:43 +0200221 return (b >> 4) * 10 + (b & 15);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222}
223
Roman Zippel6ff58012007-05-01 22:32:43 +0200224static inline unsigned char bin2bcd(unsigned char b)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225{
Roman Zippel6ff58012007-05-01 22:32:43 +0200226 return (b / 10) * 16 + (b % 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227}
228
229
Adrian Bunk22deb522008-07-17 21:16:26 +0200230static unsigned long q40_gettimeoffset(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231{
Roman Zippel6ff58012007-05-01 22:32:43 +0200232 return 5000 * (ql_ticks != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233}
234
235
236/*
237 * Looks like op is non-zero for setting the clock, and zero for
238 * reading the clock.
239 *
240 * struct hwclk_time {
241 * unsigned sec; 0..59
242 * unsigned min; 0..59
243 * unsigned hour; 0..23
244 * unsigned day; 1..31
245 * unsigned mon; 0..11
246 * unsigned year; 00...
247 * int wday; 0..6, 0 is Sunday, -1 means unknown/don't set
248 * };
249 */
250
Adrian Bunk22deb522008-07-17 21:16:26 +0200251static int q40_hwclk(int op, struct rtc_time *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252{
Roman Zippel6ff58012007-05-01 22:32:43 +0200253 if (op) {
254 /* Write.... */
255 Q40_RTC_CTRL |= Q40_RTC_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
257 Q40_RTC_SECS = bin2bcd(t->tm_sec);
258 Q40_RTC_MINS = bin2bcd(t->tm_min);
259 Q40_RTC_HOUR = bin2bcd(t->tm_hour);
260 Q40_RTC_DATE = bin2bcd(t->tm_mday);
261 Q40_RTC_MNTH = bin2bcd(t->tm_mon + 1);
262 Q40_RTC_YEAR = bin2bcd(t->tm_year%100);
263 if (t->tm_wday >= 0)
264 Q40_RTC_DOW = bin2bcd(t->tm_wday+1);
265
Roman Zippel6ff58012007-05-01 22:32:43 +0200266 Q40_RTC_CTRL &= ~(Q40_RTC_WRITE);
267 } else {
268 /* Read.... */
269 Q40_RTC_CTRL |= Q40_RTC_READ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
Roman Zippel6ff58012007-05-01 22:32:43 +0200271 t->tm_year = bcd2bin (Q40_RTC_YEAR);
272 t->tm_mon = bcd2bin (Q40_RTC_MNTH)-1;
273 t->tm_mday = bcd2bin (Q40_RTC_DATE);
274 t->tm_hour = bcd2bin (Q40_RTC_HOUR);
275 t->tm_min = bcd2bin (Q40_RTC_MINS);
276 t->tm_sec = bcd2bin (Q40_RTC_SECS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
Roman Zippel6ff58012007-05-01 22:32:43 +0200278 Q40_RTC_CTRL &= ~(Q40_RTC_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
Roman Zippel6ff58012007-05-01 22:32:43 +0200280 if (t->tm_year < 70)
281 t->tm_year += 100;
282 t->tm_wday = bcd2bin(Q40_RTC_DOW)-1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 }
284
285 return 0;
286}
287
Adrian Bunk22deb522008-07-17 21:16:26 +0200288static unsigned int q40_get_ss(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289{
290 return bcd2bin(Q40_RTC_SECS);
291}
292
293/*
294 * Set the minutes and seconds from seconds value 'nowtime'. Fail if
295 * clock is out by > 30 minutes. Logic lifted from atari code.
296 */
297
Adrian Bunk22deb522008-07-17 21:16:26 +0200298static int q40_set_clock_mmss(unsigned long nowtime)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299{
300 int retval = 0;
301 short real_seconds = nowtime % 60, real_minutes = (nowtime / 60) % 60;
302
303 int rtc_minutes;
304
Roman Zippel6ff58012007-05-01 22:32:43 +0200305 rtc_minutes = bcd2bin(Q40_RTC_MINS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
Roman Zippel6ff58012007-05-01 22:32:43 +0200307 if ((rtc_minutes < real_minutes ?
308 real_minutes - rtc_minutes :
309 rtc_minutes - real_minutes) < 30) {
310 Q40_RTC_CTRL |= Q40_RTC_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 Q40_RTC_MINS = bin2bcd(real_minutes);
312 Q40_RTC_SECS = bin2bcd(real_seconds);
313 Q40_RTC_CTRL &= ~(Q40_RTC_WRITE);
Roman Zippel6ff58012007-05-01 22:32:43 +0200314 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 retval = -1;
316
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 return retval;
318}
319
320
321/* get and set PLL calibration of RTC clock */
322#define Q40_RTC_PLL_MASK ((1<<5)-1)
323#define Q40_RTC_PLL_SIGN (1<<5)
324
325static int q40_get_rtc_pll(struct rtc_pll_info *pll)
326{
Roman Zippel6ff58012007-05-01 22:32:43 +0200327 int tmp = Q40_RTC_CTRL;
328
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 pll->pll_value = tmp & Q40_RTC_PLL_MASK;
330 if (tmp & Q40_RTC_PLL_SIGN)
331 pll->pll_value = -pll->pll_value;
Roman Zippel6ff58012007-05-01 22:32:43 +0200332 pll->pll_max = 31;
333 pll->pll_min = -31;
334 pll->pll_posmult = 512;
335 pll->pll_negmult = 256;
336 pll->pll_clock = 125829120;
337
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 return 0;
339}
340
341static int q40_set_rtc_pll(struct rtc_pll_info *pll)
342{
Roman Zippel6ff58012007-05-01 22:32:43 +0200343 if (!pll->pll_ctrl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 /* the docs are a bit unclear so I am doublesetting */
345 /* RTC_WRITE here ... */
346 int tmp = (pll->pll_value & 31) | (pll->pll_value<0 ? 32 : 0) |
347 Q40_RTC_WRITE;
348 Q40_RTC_CTRL |= Q40_RTC_WRITE;
349 Q40_RTC_CTRL = tmp;
350 Q40_RTC_CTRL &= ~(Q40_RTC_WRITE);
351 return 0;
352 } else
353 return -EINVAL;
354}