blob: 4627de3c0603577a4dc3d7c799f9d3a086a33e30 [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
Arnd Bergmann084b3602016-05-30 20:57:59 +020015#include <linux/errno.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/types.h>
17#include <linux/kernel.h>
18#include <linux/mm.h>
19#include <linux/tty.h>
20#include <linux/console.h>
21#include <linux/linkage.h>
22#include <linux/init.h>
23#include <linux/major.h>
24#include <linux/serial_reg.h>
25#include <linux/rtc.h>
26#include <linux/vt_kern.h>
Adrian Bunk5b1d5f92008-10-13 21:58:47 +020027#include <linux/bcd.h>
Dmitry Torokhov409e1542012-01-22 23:27:54 -080028#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <asm/bootinfo.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#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 void q40_init_IRQ(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039static void q40_get_model(char *model);
David Howells40220c12006-10-09 12:19:47 +010040extern void q40_sched_init(irq_handler_t handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Adrian Bunk22deb522008-07-17 21:16:26 +020042static int q40_hwclk(int, struct rtc_time *);
43static unsigned int q40_get_ss(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070044static int q40_get_rtc_pll(struct rtc_pll_info *pll);
45static int q40_set_rtc_pll(struct rtc_pll_info *pll);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Roman Zippel6ff58012007-05-01 22:32:43 +020047extern void q40_mksound(unsigned int /*freq*/, unsigned int /*ticks*/);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Linus Torvalds1da177e2005-04-16 15:20:36 -070049static void q40_mem_console_write(struct console *co, const char *b,
Roman Zippel6ff58012007-05-01 22:32:43 +020050 unsigned int count);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52extern int ql_ticks;
53
54static struct console q40_console_driver = {
Roman Zippel6ff58012007-05-01 22:32:43 +020055 .name = "debug",
Roman Zippeld6713b42007-05-01 22:32:45 +020056 .write = q40_mem_console_write,
Roman Zippel6ff58012007-05-01 22:32:43 +020057 .flags = CON_PRINTBUFFER,
58 .index = -1,
Linus Torvalds1da177e2005-04-16 15:20:36 -070059};
60
61
62/* early debugging function:*/
63extern char *q40_mem_cptr; /*=(char *)0xff020000;*/
64static int _cpleft;
65
66static void q40_mem_console_write(struct console *co, const char *s,
67 unsigned int count)
68{
Roman Zippel6ff58012007-05-01 22:32:43 +020069 const char *p = s;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Roman Zippel6ff58012007-05-01 22:32:43 +020071 if (count < _cpleft) {
72 while (count-- > 0) {
73 *q40_mem_cptr = *p++;
74 q40_mem_cptr += 4;
75 _cpleft--;
76 }
77 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070078}
Roman Zippel6ff58012007-05-01 22:32:43 +020079
Roman Zippeld6713b42007-05-01 22:32:45 +020080static int __init q40_debug_setup(char *arg)
81{
82 /* useful for early debugging stages - writes kernel messages into SRAM */
83 if (MACH_IS_Q40 && !strncmp(arg, "mem", 3)) {
Geert Uytterhoeven446926f2016-12-06 17:11:01 +010084 /*pr_info("using NVRAM debug, q40_mem_cptr=%p\n",q40_mem_cptr);*/
Roman Zippeld6713b42007-05-01 22:32:45 +020085 _cpleft = 2000 - ((long)q40_mem_cptr-0xff020000) / 4;
86 register_console(&q40_console_driver);
87 }
88 return 0;
89}
90
91early_param("debug", q40_debug_setup);
92
Linus Torvalds1da177e2005-04-16 15:20:36 -070093#if 0
94void printq40(char *str)
95{
Roman Zippel6ff58012007-05-01 22:32:43 +020096 int l = strlen(str);
97 char *p = q40_mem_cptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Roman Zippel6ff58012007-05-01 22:32:43 +020099 while (l-- > 0 && _cpleft-- > 0) {
100 *p = *str++;
101 p += 4;
102 }
103 q40_mem_cptr = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104}
105#endif
106
Roman Zippel6ff58012007-05-01 22:32:43 +0200107static int halted;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
109#ifdef CONFIG_HEARTBEAT
110static void q40_heartbeat(int on)
111{
Roman Zippel6ff58012007-05-01 22:32:43 +0200112 if (halted)
113 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Roman Zippel6ff58012007-05-01 22:32:43 +0200115 if (on)
116 Q40_LED_ON();
117 else
118 Q40_LED_OFF();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119}
120#endif
121
Adrian Bunk22deb522008-07-17 21:16:26 +0200122static void q40_reset(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123{
Geert Uytterhoeven446926f2016-12-06 17:11:01 +0100124 halted = 1;
125 pr_info("*******************************************\n"
Frans Popb9b0d8b2010-02-06 18:47:11 +0100126 "Called q40_reset : press the RESET button!!\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 "*******************************************\n");
128 Q40_LED_ON();
Roman Zippel6ff58012007-05-01 22:32:43 +0200129 while (1)
130 ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131}
Adrian Bunk22deb522008-07-17 21:16:26 +0200132
133static void q40_halt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134{
Geert Uytterhoeven446926f2016-12-06 17:11:01 +0100135 halted = 1;
136 pr_info("*******************\n"
137 " Called q40_halt\n"
138 "*******************\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 Q40_LED_ON();
Roman Zippel6ff58012007-05-01 22:32:43 +0200140 while (1)
141 ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142}
143
144static void q40_get_model(char *model)
145{
Roman Zippel6ff58012007-05-01 22:32:43 +0200146 sprintf(model, "Q40");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147}
148
Roman Zippel6ff58012007-05-01 22:32:43 +0200149static unsigned int serports[] =
150{
151 0x3f8,0x2f8,0x3e8,0x2e8,0
152};
Adrian Bunk22deb522008-07-17 21:16:26 +0200153
Geert Uytterhoevena4df02a2013-06-25 21:15:24 +0200154static void __init q40_disable_irqs(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155{
Roman Zippel6ff58012007-05-01 22:32:43 +0200156 unsigned i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
Roman Zippel6ff58012007-05-01 22:32:43 +0200158 j = 0;
159 while ((i = serports[j++]))
160 outb(0, i + UART_IER);
161 master_outb(0, EXT_ENABLE_REG);
162 master_outb(0, KEY_IRQ_ENABLE_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163}
164
165void __init config_q40(void)
166{
Roman Zippel6ff58012007-05-01 22:32:43 +0200167 mach_sched_init = q40_sched_init;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
Roman Zippel6ff58012007-05-01 22:32:43 +0200169 mach_init_IRQ = q40_init_IRQ;
Roman Zippel6ff58012007-05-01 22:32:43 +0200170 mach_hwclk = q40_hwclk;
171 mach_get_ss = q40_get_ss;
172 mach_get_rtc_pll = q40_get_rtc_pll;
173 mach_set_rtc_pll = q40_set_rtc_pll;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
Roman Zippel6ff58012007-05-01 22:32:43 +0200175 mach_reset = q40_reset;
176 mach_get_model = q40_get_model;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
Geert Uytterhoevena1a9e882016-09-05 13:18:15 +0200178#if IS_ENABLED(CONFIG_INPUT_M68K_BEEP)
Roman Zippel6ff58012007-05-01 22:32:43 +0200179 mach_beep = q40_mksound;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180#endif
181#ifdef CONFIG_HEARTBEAT
Roman Zippel6ff58012007-05-01 22:32:43 +0200182 mach_heartbeat = q40_heartbeat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183#endif
Roman Zippel6ff58012007-05-01 22:32:43 +0200184 mach_halt = q40_halt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
Roman Zippel6ff58012007-05-01 22:32:43 +0200186 /* disable a few things that SMSQ might have left enabled */
187 q40_disable_irqs();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
Roman Zippel6ff58012007-05-01 22:32:43 +0200189 /* no DMA at all, but ide-scsi requires it.. make sure
190 * all physical RAM fits into the boundary - otherwise
191 * allocator may play costly and useless tricks */
192 mach_max_dma_address = 1024*1024*1024;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193}
194
195
Geert Uytterhoevena4df02a2013-06-25 21:15:24 +0200196int __init q40_parse_bootinfo(const struct bi_record *rec)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197{
Roman Zippel6ff58012007-05-01 22:32:43 +0200198 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199}
200
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201/*
202 * Looks like op is non-zero for setting the clock, and zero for
203 * reading the clock.
204 *
205 * struct hwclk_time {
206 * unsigned sec; 0..59
207 * unsigned min; 0..59
208 * unsigned hour; 0..23
209 * unsigned day; 1..31
210 * unsigned mon; 0..11
211 * unsigned year; 00...
212 * int wday; 0..6, 0 is Sunday, -1 means unknown/don't set
213 * };
214 */
215
Adrian Bunk22deb522008-07-17 21:16:26 +0200216static int q40_hwclk(int op, struct rtc_time *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217{
Roman Zippel6ff58012007-05-01 22:32:43 +0200218 if (op) {
219 /* Write.... */
220 Q40_RTC_CTRL |= Q40_RTC_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
222 Q40_RTC_SECS = bin2bcd(t->tm_sec);
223 Q40_RTC_MINS = bin2bcd(t->tm_min);
224 Q40_RTC_HOUR = bin2bcd(t->tm_hour);
225 Q40_RTC_DATE = bin2bcd(t->tm_mday);
226 Q40_RTC_MNTH = bin2bcd(t->tm_mon + 1);
227 Q40_RTC_YEAR = bin2bcd(t->tm_year%100);
228 if (t->tm_wday >= 0)
229 Q40_RTC_DOW = bin2bcd(t->tm_wday+1);
230
Roman Zippel6ff58012007-05-01 22:32:43 +0200231 Q40_RTC_CTRL &= ~(Q40_RTC_WRITE);
232 } else {
233 /* Read.... */
234 Q40_RTC_CTRL |= Q40_RTC_READ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
Roman Zippel6ff58012007-05-01 22:32:43 +0200236 t->tm_year = bcd2bin (Q40_RTC_YEAR);
237 t->tm_mon = bcd2bin (Q40_RTC_MNTH)-1;
238 t->tm_mday = bcd2bin (Q40_RTC_DATE);
239 t->tm_hour = bcd2bin (Q40_RTC_HOUR);
240 t->tm_min = bcd2bin (Q40_RTC_MINS);
241 t->tm_sec = bcd2bin (Q40_RTC_SECS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
Roman Zippel6ff58012007-05-01 22:32:43 +0200243 Q40_RTC_CTRL &= ~(Q40_RTC_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
Roman Zippel6ff58012007-05-01 22:32:43 +0200245 if (t->tm_year < 70)
246 t->tm_year += 100;
247 t->tm_wday = bcd2bin(Q40_RTC_DOW)-1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 }
249
250 return 0;
251}
252
Adrian Bunk22deb522008-07-17 21:16:26 +0200253static unsigned int q40_get_ss(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254{
255 return bcd2bin(Q40_RTC_SECS);
256}
257
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258/* get and set PLL calibration of RTC clock */
259#define Q40_RTC_PLL_MASK ((1<<5)-1)
260#define Q40_RTC_PLL_SIGN (1<<5)
261
262static int q40_get_rtc_pll(struct rtc_pll_info *pll)
263{
Roman Zippel6ff58012007-05-01 22:32:43 +0200264 int tmp = Q40_RTC_CTRL;
265
Fuqian Huang7cf78b62019-09-27 20:15:44 +0800266 pll->pll_ctrl = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 pll->pll_value = tmp & Q40_RTC_PLL_MASK;
268 if (tmp & Q40_RTC_PLL_SIGN)
269 pll->pll_value = -pll->pll_value;
Roman Zippel6ff58012007-05-01 22:32:43 +0200270 pll->pll_max = 31;
271 pll->pll_min = -31;
272 pll->pll_posmult = 512;
273 pll->pll_negmult = 256;
274 pll->pll_clock = 125829120;
275
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 return 0;
277}
278
279static int q40_set_rtc_pll(struct rtc_pll_info *pll)
280{
Roman Zippel6ff58012007-05-01 22:32:43 +0200281 if (!pll->pll_ctrl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 /* the docs are a bit unclear so I am doublesetting */
283 /* RTC_WRITE here ... */
284 int tmp = (pll->pll_value & 31) | (pll->pll_value<0 ? 32 : 0) |
285 Q40_RTC_WRITE;
286 Q40_RTC_CTRL |= Q40_RTC_WRITE;
287 Q40_RTC_CTRL = tmp;
288 Q40_RTC_CTRL &= ~(Q40_RTC_WRITE);
289 return 0;
290 } else
291 return -EINVAL;
292}
Dmitry Torokhov409e1542012-01-22 23:27:54 -0800293
294static __init int q40_add_kbd_device(void)
295{
296 struct platform_device *pdev;
297
Geert Uytterhoeven450aed72012-03-18 13:20:27 +0100298 if (!MACH_IS_Q40)
299 return -ENODEV;
300
Dmitry Torokhov409e1542012-01-22 23:27:54 -0800301 pdev = platform_device_register_simple("q40kbd", -1, NULL, 0);
Rusty Russell8c6ffba2013-07-15 11:20:32 +0930302 return PTR_ERR_OR_ZERO(pdev);
Dmitry Torokhov409e1542012-01-22 23:27:54 -0800303}
304arch_initcall(q40_add_kbd_device);