blob: c44a254e8a8c385a2a0cd9795b1521eb9aa3665e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/m68k/mvme147/config.c
3 *
4 * Copyright (C) 1996 Dave Frascone [chaos@mindspring.com]
5 * Cloned from Richard Hirst [richard@sleepie.demon.co.uk]
6 *
7 * Based on:
8 *
9 * Copyright (C) 1993 Hamish Macdonald
10 *
11 * This file is subject to the terms and conditions of the GNU General Public
12 * License. See the file README.legal in the main directory of this archive
13 * for more details.
14 */
15
16#include <linux/types.h>
17#include <linux/kernel.h>
18#include <linux/mm.h>
19#include <linux/tty.h>
Finn Thainfc4c47b2018-12-01 11:53:10 +110020#include <linux/clocksource.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/console.h>
22#include <linux/linkage.h>
23#include <linux/init.h>
24#include <linux/major.h>
25#include <linux/genhd.h>
26#include <linux/rtc.h>
27#include <linux/interrupt.h>
28
29#include <asm/bootinfo.h>
Geert Uytterhoeven4c3c5222013-10-02 11:37:33 +020030#include <asm/bootinfo-vme.h>
Geert Uytterhoevenabe48102013-10-04 11:41:24 +020031#include <asm/byteorder.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <asm/pgtable.h>
33#include <asm/setup.h>
34#include <asm/irq.h>
35#include <asm/traps.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <asm/machdep.h>
37#include <asm/mvme147hw.h>
38
39
Linus Torvalds1da177e2005-04-16 15:20:36 -070040static void mvme147_get_model(char *model);
David Howells40220c12006-10-09 12:19:47 +010041extern void mvme147_sched_init(irq_handler_t handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042extern int mvme147_hwclk (int, struct rtc_time *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043extern void mvme147_reset (void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45
46static int bcd2int (unsigned char b);
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Geert Uytterhoevena4df02a2013-06-25 21:15:24 +020049int __init mvme147_parse_bootinfo(const struct bi_record *bi)
Linus Torvalds1da177e2005-04-16 15:20:36 -070050{
Geert Uytterhoevenabe48102013-10-04 11:41:24 +020051 uint16_t tag = be16_to_cpu(bi->tag);
52 if (tag == BI_VME_TYPE || tag == BI_VME_BRDINFO)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 return 0;
54 else
55 return 1;
56}
57
58void mvme147_reset(void)
59{
Geert Uytterhoeven0c29d752016-12-06 17:09:58 +010060 pr_info("\r\n\nCalled mvme147_reset\r\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 m147_pcc->watchdog = 0x0a; /* Clear timer */
62 m147_pcc->watchdog = 0xa5; /* Enable watchdog - 100ms to reset */
63 while (1)
64 ;
65}
66
67static void mvme147_get_model(char *model)
68{
69 sprintf(model, "Motorola MVME147");
70}
71
Roman Zippel200a3d32006-06-25 05:47:06 -070072/*
73 * This function is called during kernel startup to initialize
74 * the mvme147 IRQ handling routines.
75 */
76
Al Viro66a3f822007-07-20 04:33:28 +010077void __init mvme147_init_IRQ(void)
Roman Zippel200a3d32006-06-25 05:47:06 -070078{
Geert Uytterhoevenf30a6482011-09-11 11:54:50 +020079 m68k_setup_user_interrupt(VEC_USER, 192);
Roman Zippel200a3d32006-06-25 05:47:06 -070080}
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82void __init config_mvme147(void)
83{
84 mach_max_dma_address = 0x01000000;
85 mach_sched_init = mvme147_sched_init;
86 mach_init_IRQ = mvme147_init_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 mach_hwclk = mvme147_hwclk;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 mach_reset = mvme147_reset;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 mach_get_model = mvme147_get_model;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91 /* Board type is only set by newer versions of vmelilo/tftplilo */
92 if (!vme_brdtype)
93 vme_brdtype = VME_TYPE_MVME147;
94}
95
Finn Thainfc4c47b2018-12-01 11:53:10 +110096static u64 mvme147_read_clk(struct clocksource *cs);
97
98static struct clocksource mvme147_clk = {
99 .name = "pcc",
100 .rating = 250,
101 .read = mvme147_read_clk,
102 .mask = CLOCKSOURCE_MASK(32),
103 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
104};
105
106static u32 clk_total;
107
108#define PCC_TIMER_CLOCK_FREQ 160000
109#define PCC_TIMER_CYCLES (PCC_TIMER_CLOCK_FREQ / HZ)
110#define PCC_TIMER_PRELOAD (0x10000 - PCC_TIMER_CYCLES)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
112/* Using pcc tick timer 1 */
113
Al Viro2850bc22006-10-07 14:16:45 +0100114static irqreturn_t mvme147_timer_int (int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115{
Finn Thain1efdd4b2018-12-01 11:53:10 +1100116 irq_handler_t timer_routine = dev_id;
117 unsigned long flags;
118
119 local_irq_save(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 m147_pcc->t1_int_cntrl = PCC_TIMER_INT_CLR;
121 m147_pcc->t1_int_cntrl = PCC_INT_ENAB|PCC_LEVEL_TIMER1;
Finn Thainfc4c47b2018-12-01 11:53:10 +1100122 clk_total += PCC_TIMER_CYCLES;
Finn Thain1efdd4b2018-12-01 11:53:10 +1100123 timer_routine(0, NULL);
124 local_irq_restore(flags);
125
126 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127}
128
129
David Howells40220c12006-10-09 12:19:47 +0100130void mvme147_sched_init (irq_handler_t timer_routine)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131{
Finn Thainfc4c47b2018-12-01 11:53:10 +1100132 if (request_irq(PCC_IRQ_TIMER1, mvme147_timer_int, IRQF_TIMER,
133 "timer 1", timer_routine))
Geert Uytterhoeven41904f82008-12-30 14:03:28 +0100134 pr_err("Couldn't register timer interrupt\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136 /* Init the clock with a value */
Finn Thainfc4c47b2018-12-01 11:53:10 +1100137 /* The clock counter increments until 0xFFFF then reloads */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 m147_pcc->t1_preload = PCC_TIMER_PRELOAD;
139 m147_pcc->t1_cntrl = 0x0; /* clear timer */
140 m147_pcc->t1_cntrl = 0x3; /* start timer */
141 m147_pcc->t1_int_cntrl = PCC_TIMER_INT_CLR; /* clear pending ints */
142 m147_pcc->t1_int_cntrl = PCC_INT_ENAB|PCC_LEVEL_TIMER1;
Finn Thainfc4c47b2018-12-01 11:53:10 +1100143
144 clocksource_register_hz(&mvme147_clk, PCC_TIMER_CLOCK_FREQ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145}
146
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147/* XXX There are race hazards in this code XXX */
Finn Thainfc4c47b2018-12-01 11:53:10 +1100148static u64 mvme147_read_clk(struct clocksource *cs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149{
Finn Thainfc4c47b2018-12-01 11:53:10 +1100150 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 volatile unsigned short *cp = (volatile unsigned short *)0xfffe1012;
152 unsigned short n;
Finn Thainfc4c47b2018-12-01 11:53:10 +1100153 u32 ticks;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
Finn Thainfc4c47b2018-12-01 11:53:10 +1100155 local_irq_save(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 n = *cp;
157 while (n != *cp)
158 n = *cp;
159
160 n -= PCC_TIMER_PRELOAD;
Finn Thainfc4c47b2018-12-01 11:53:10 +1100161 ticks = clk_total + n;
162 local_irq_restore(flags);
163
164 return ticks;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165}
166
167static int bcd2int (unsigned char b)
168{
169 return ((b>>4)*10 + (b&15));
170}
171
172int mvme147_hwclk(int op, struct rtc_time *t)
173{
174#warning check me!
175 if (!op) {
176 m147_rtc->ctrl = RTC_READ;
177 t->tm_year = bcd2int (m147_rtc->bcd_year);
Finn Thainb65769f2018-04-23 11:02:57 +1000178 t->tm_mon = bcd2int(m147_rtc->bcd_mth) - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 t->tm_mday = bcd2int (m147_rtc->bcd_dom);
180 t->tm_hour = bcd2int (m147_rtc->bcd_hr);
181 t->tm_min = bcd2int (m147_rtc->bcd_min);
182 t->tm_sec = bcd2int (m147_rtc->bcd_sec);
183 m147_rtc->ctrl = 0;
Finn Thainb65769f2018-04-23 11:02:57 +1000184 if (t->tm_year < 70)
185 t->tm_year += 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 }
187 return 0;
188}