blob: be936480b964811a83af2ae293d79a244442a6a0 [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>
Adrian Bunk5b1d5f92008-10-13 21:58:47 +020026#include <linux/bcd.h>
Dmitry Torokhov409e1542012-01-22 23:27:54 -080027#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29#include <asm/io.h>
30#include <asm/rtc.h>
31#include <asm/bootinfo.h>
32#include <asm/system.h>
33#include <asm/pgtable.h>
34#include <asm/setup.h>
35#include <asm/irq.h>
36#include <asm/traps.h>
37#include <asm/machdep.h>
38#include <asm/q40_master.h>
39
Roman Zippel6ff58012007-05-01 22:32:43 +020040extern void q40_init_IRQ(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041static void q40_get_model(char *model);
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 -070050
Roman Zippel6ff58012007-05-01 22:32:43 +020051extern void q40_mksound(unsigned int /*freq*/, unsigned int /*ticks*/);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Linus Torvalds1da177e2005-04-16 15:20:36 -070053static void q40_mem_console_write(struct console *co, const char *b,
Roman Zippel6ff58012007-05-01 22:32:43 +020054 unsigned int count);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56extern int ql_ticks;
57
58static struct console q40_console_driver = {
Roman Zippel6ff58012007-05-01 22:32:43 +020059 .name = "debug",
Roman Zippeld6713b42007-05-01 22:32:45 +020060 .write = q40_mem_console_write,
Roman Zippel6ff58012007-05-01 22:32:43 +020061 .flags = CON_PRINTBUFFER,
62 .index = -1,
Linus Torvalds1da177e2005-04-16 15:20:36 -070063};
64
65
66/* early debugging function:*/
67extern char *q40_mem_cptr; /*=(char *)0xff020000;*/
68static int _cpleft;
69
70static void q40_mem_console_write(struct console *co, const char *s,
71 unsigned int count)
72{
Roman Zippel6ff58012007-05-01 22:32:43 +020073 const char *p = s;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Roman Zippel6ff58012007-05-01 22:32:43 +020075 if (count < _cpleft) {
76 while (count-- > 0) {
77 *q40_mem_cptr = *p++;
78 q40_mem_cptr += 4;
79 _cpleft--;
80 }
81 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070082}
Roman Zippel6ff58012007-05-01 22:32:43 +020083
Roman Zippeld6713b42007-05-01 22:32:45 +020084static int __init q40_debug_setup(char *arg)
85{
86 /* useful for early debugging stages - writes kernel messages into SRAM */
87 if (MACH_IS_Q40 && !strncmp(arg, "mem", 3)) {
88 /*printk("using NVRAM debug, q40_mem_cptr=%p\n",q40_mem_cptr);*/
89 _cpleft = 2000 - ((long)q40_mem_cptr-0xff020000) / 4;
90 register_console(&q40_console_driver);
91 }
92 return 0;
93}
94
95early_param("debug", q40_debug_setup);
96
Linus Torvalds1da177e2005-04-16 15:20:36 -070097#if 0
98void printq40(char *str)
99{
Roman Zippel6ff58012007-05-01 22:32:43 +0200100 int l = strlen(str);
101 char *p = q40_mem_cptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
Roman Zippel6ff58012007-05-01 22:32:43 +0200103 while (l-- > 0 && _cpleft-- > 0) {
104 *p = *str++;
105 p += 4;
106 }
107 q40_mem_cptr = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108}
109#endif
110
Roman Zippel6ff58012007-05-01 22:32:43 +0200111static int halted;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
113#ifdef CONFIG_HEARTBEAT
114static void q40_heartbeat(int on)
115{
Roman Zippel6ff58012007-05-01 22:32:43 +0200116 if (halted)
117 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Roman Zippel6ff58012007-05-01 22:32:43 +0200119 if (on)
120 Q40_LED_ON();
121 else
122 Q40_LED_OFF();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123}
124#endif
125
Adrian Bunk22deb522008-07-17 21:16:26 +0200126static void q40_reset(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127{
Roman Zippel6ff58012007-05-01 22:32:43 +0200128 halted = 1;
129 printk("\n\n*******************************************\n"
Frans Popb9b0d8b2010-02-06 18:47:11 +0100130 "Called q40_reset : press the RESET button!!\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 "*******************************************\n");
132 Q40_LED_ON();
Roman Zippel6ff58012007-05-01 22:32:43 +0200133 while (1)
134 ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135}
Adrian Bunk22deb522008-07-17 21:16:26 +0200136
137static void q40_halt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138{
Roman Zippel6ff58012007-05-01 22:32:43 +0200139 halted = 1;
140 printk("\n\n*******************\n"
141 " Called q40_halt\n"
142 "*******************\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 Q40_LED_ON();
Roman Zippel6ff58012007-05-01 22:32:43 +0200144 while (1)
145 ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146}
147
148static void q40_get_model(char *model)
149{
Roman Zippel6ff58012007-05-01 22:32:43 +0200150 sprintf(model, "Q40");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151}
152
Roman Zippel6ff58012007-05-01 22:32:43 +0200153static unsigned int serports[] =
154{
155 0x3f8,0x2f8,0x3e8,0x2e8,0
156};
Adrian Bunk22deb522008-07-17 21:16:26 +0200157
158static void q40_disable_irqs(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159{
Roman Zippel6ff58012007-05-01 22:32:43 +0200160 unsigned i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Roman Zippel6ff58012007-05-01 22:32:43 +0200162 j = 0;
163 while ((i = serports[j++]))
164 outb(0, i + UART_IER);
165 master_outb(0, EXT_ENABLE_REG);
166 master_outb(0, KEY_IRQ_ENABLE_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167}
168
169void __init config_q40(void)
170{
Roman Zippel6ff58012007-05-01 22:32:43 +0200171 mach_sched_init = q40_sched_init;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
Roman Zippel6ff58012007-05-01 22:32:43 +0200173 mach_init_IRQ = q40_init_IRQ;
174 mach_gettimeoffset = q40_gettimeoffset;
175 mach_hwclk = q40_hwclk;
176 mach_get_ss = q40_get_ss;
177 mach_get_rtc_pll = q40_get_rtc_pll;
178 mach_set_rtc_pll = q40_set_rtc_pll;
179 mach_set_clock_mmss = q40_set_clock_mmss;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
Roman Zippel6ff58012007-05-01 22:32:43 +0200181 mach_reset = q40_reset;
182 mach_get_model = q40_get_model;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
184#if defined(CONFIG_INPUT_M68K_BEEP) || defined(CONFIG_INPUT_M68K_BEEP_MODULE)
Roman Zippel6ff58012007-05-01 22:32:43 +0200185 mach_beep = q40_mksound;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186#endif
187#ifdef CONFIG_HEARTBEAT
Roman Zippel6ff58012007-05-01 22:32:43 +0200188 mach_heartbeat = q40_heartbeat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189#endif
Roman Zippel6ff58012007-05-01 22:32:43 +0200190 mach_halt = q40_halt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Roman Zippel6ff58012007-05-01 22:32:43 +0200192 /* disable a few things that SMSQ might have left enabled */
193 q40_disable_irqs();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
Roman Zippel6ff58012007-05-01 22:32:43 +0200195 /* no DMA at all, but ide-scsi requires it.. make sure
196 * all physical RAM fits into the boundary - otherwise
197 * allocator may play costly and useless tricks */
198 mach_max_dma_address = 1024*1024*1024;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199}
200
201
202int q40_parse_bootinfo(const struct bi_record *rec)
203{
Roman Zippel6ff58012007-05-01 22:32:43 +0200204 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205}
206
207
Adrian Bunk22deb522008-07-17 21:16:26 +0200208static unsigned long q40_gettimeoffset(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209{
Roman Zippel6ff58012007-05-01 22:32:43 +0200210 return 5000 * (ql_ticks != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211}
212
213
214/*
215 * Looks like op is non-zero for setting the clock, and zero for
216 * reading the clock.
217 *
218 * struct hwclk_time {
219 * unsigned sec; 0..59
220 * unsigned min; 0..59
221 * unsigned hour; 0..23
222 * unsigned day; 1..31
223 * unsigned mon; 0..11
224 * unsigned year; 00...
225 * int wday; 0..6, 0 is Sunday, -1 means unknown/don't set
226 * };
227 */
228
Adrian Bunk22deb522008-07-17 21:16:26 +0200229static int q40_hwclk(int op, struct rtc_time *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230{
Roman Zippel6ff58012007-05-01 22:32:43 +0200231 if (op) {
232 /* Write.... */
233 Q40_RTC_CTRL |= Q40_RTC_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
235 Q40_RTC_SECS = bin2bcd(t->tm_sec);
236 Q40_RTC_MINS = bin2bcd(t->tm_min);
237 Q40_RTC_HOUR = bin2bcd(t->tm_hour);
238 Q40_RTC_DATE = bin2bcd(t->tm_mday);
239 Q40_RTC_MNTH = bin2bcd(t->tm_mon + 1);
240 Q40_RTC_YEAR = bin2bcd(t->tm_year%100);
241 if (t->tm_wday >= 0)
242 Q40_RTC_DOW = bin2bcd(t->tm_wday+1);
243
Roman Zippel6ff58012007-05-01 22:32:43 +0200244 Q40_RTC_CTRL &= ~(Q40_RTC_WRITE);
245 } else {
246 /* Read.... */
247 Q40_RTC_CTRL |= Q40_RTC_READ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
Roman Zippel6ff58012007-05-01 22:32:43 +0200249 t->tm_year = bcd2bin (Q40_RTC_YEAR);
250 t->tm_mon = bcd2bin (Q40_RTC_MNTH)-1;
251 t->tm_mday = bcd2bin (Q40_RTC_DATE);
252 t->tm_hour = bcd2bin (Q40_RTC_HOUR);
253 t->tm_min = bcd2bin (Q40_RTC_MINS);
254 t->tm_sec = bcd2bin (Q40_RTC_SECS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
Roman Zippel6ff58012007-05-01 22:32:43 +0200256 Q40_RTC_CTRL &= ~(Q40_RTC_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
Roman Zippel6ff58012007-05-01 22:32:43 +0200258 if (t->tm_year < 70)
259 t->tm_year += 100;
260 t->tm_wday = bcd2bin(Q40_RTC_DOW)-1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 }
262
263 return 0;
264}
265
Adrian Bunk22deb522008-07-17 21:16:26 +0200266static unsigned int q40_get_ss(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267{
268 return bcd2bin(Q40_RTC_SECS);
269}
270
271/*
272 * Set the minutes and seconds from seconds value 'nowtime'. Fail if
273 * clock is out by > 30 minutes. Logic lifted from atari code.
274 */
275
Adrian Bunk22deb522008-07-17 21:16:26 +0200276static int q40_set_clock_mmss(unsigned long nowtime)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277{
278 int retval = 0;
279 short real_seconds = nowtime % 60, real_minutes = (nowtime / 60) % 60;
280
281 int rtc_minutes;
282
Roman Zippel6ff58012007-05-01 22:32:43 +0200283 rtc_minutes = bcd2bin(Q40_RTC_MINS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
Roman Zippel6ff58012007-05-01 22:32:43 +0200285 if ((rtc_minutes < real_minutes ?
286 real_minutes - rtc_minutes :
287 rtc_minutes - real_minutes) < 30) {
288 Q40_RTC_CTRL |= Q40_RTC_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 Q40_RTC_MINS = bin2bcd(real_minutes);
290 Q40_RTC_SECS = bin2bcd(real_seconds);
291 Q40_RTC_CTRL &= ~(Q40_RTC_WRITE);
Roman Zippel6ff58012007-05-01 22:32:43 +0200292 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 retval = -1;
294
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 return retval;
296}
297
298
299/* get and set PLL calibration of RTC clock */
300#define Q40_RTC_PLL_MASK ((1<<5)-1)
301#define Q40_RTC_PLL_SIGN (1<<5)
302
303static int q40_get_rtc_pll(struct rtc_pll_info *pll)
304{
Roman Zippel6ff58012007-05-01 22:32:43 +0200305 int tmp = Q40_RTC_CTRL;
306
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 pll->pll_value = tmp & Q40_RTC_PLL_MASK;
308 if (tmp & Q40_RTC_PLL_SIGN)
309 pll->pll_value = -pll->pll_value;
Roman Zippel6ff58012007-05-01 22:32:43 +0200310 pll->pll_max = 31;
311 pll->pll_min = -31;
312 pll->pll_posmult = 512;
313 pll->pll_negmult = 256;
314 pll->pll_clock = 125829120;
315
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 return 0;
317}
318
319static int q40_set_rtc_pll(struct rtc_pll_info *pll)
320{
Roman Zippel6ff58012007-05-01 22:32:43 +0200321 if (!pll->pll_ctrl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 /* the docs are a bit unclear so I am doublesetting */
323 /* RTC_WRITE here ... */
324 int tmp = (pll->pll_value & 31) | (pll->pll_value<0 ? 32 : 0) |
325 Q40_RTC_WRITE;
326 Q40_RTC_CTRL |= Q40_RTC_WRITE;
327 Q40_RTC_CTRL = tmp;
328 Q40_RTC_CTRL &= ~(Q40_RTC_WRITE);
329 return 0;
330 } else
331 return -EINVAL;
332}
Dmitry Torokhov409e1542012-01-22 23:27:54 -0800333
334static __init int q40_add_kbd_device(void)
335{
336 struct platform_device *pdev;
337
338 pdev = platform_device_register_simple("q40kbd", -1, NULL, 0);
339 if (IS_ERR(pdev))
340 return PTR_ERR(pdev);
341
342 return 0;
343}
344arch_initcall(q40_add_kbd_device);