Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3 *  arch/m68k/mvme147/config.c
  4 *
  5 *  Copyright (C) 1996 Dave Frascone [chaos@mindspring.com]
  6 *  Cloned from        Richard Hirst [richard@sleepie.demon.co.uk]
  7 *
  8 * Based on:
  9 *
 10 *  Copyright (C) 1993 Hamish Macdonald
 
 
 
 
 11 */
 12
 13#include <linux/types.h>
 14#include <linux/kernel.h>
 15#include <linux/mm.h>
 16#include <linux/tty.h>
 17#include <linux/clocksource.h>
 18#include <linux/console.h>
 19#include <linux/linkage.h>
 20#include <linux/init.h>
 21#include <linux/major.h>
 
 22#include <linux/rtc.h>
 23#include <linux/interrupt.h>
 24
 25#include <asm/bootinfo.h>
 26#include <asm/bootinfo-vme.h>
 27#include <asm/byteorder.h>
 
 28#include <asm/setup.h>
 29#include <asm/irq.h>
 30#include <asm/traps.h>
 
 31#include <asm/machdep.h>
 32#include <asm/mvme147hw.h>
 33#include <asm/config.h>
 34
 35
 36static void mvme147_get_model(char *model);
 37extern void mvme147_sched_init(void);
 
 38extern int mvme147_hwclk (int, struct rtc_time *);
 
 39extern void mvme147_reset (void);
 40
 41
 42static int bcd2int (unsigned char b);
 43
 
 
 
 
 
 44
 45int __init mvme147_parse_bootinfo(const struct bi_record *bi)
 46{
 47	uint16_t tag = be16_to_cpu(bi->tag);
 48	if (tag == BI_VME_TYPE || tag == BI_VME_BRDINFO)
 49		return 0;
 50	else
 51		return 1;
 52}
 53
 54void mvme147_reset(void)
 55{
 56	pr_info("\r\n\nCalled mvme147_reset\r\n");
 57	m147_pcc->watchdog = 0x0a;	/* Clear timer */
 58	m147_pcc->watchdog = 0xa5;	/* Enable watchdog - 100ms to reset */
 59	while (1)
 60		;
 61}
 62
 63static void mvme147_get_model(char *model)
 64{
 65	sprintf(model, "Motorola MVME147");
 66}
 67
 68/*
 69 * This function is called during kernel startup to initialize
 70 * the mvme147 IRQ handling routines.
 71 */
 72
 73static void __init mvme147_init_IRQ(void)
 74{
 75	m68k_setup_user_interrupt(VEC_USER, 192);
 76}
 77
 78void __init config_mvme147(void)
 79{
 
 80	mach_sched_init		= mvme147_sched_init;
 81	mach_init_IRQ		= mvme147_init_IRQ;
 
 82	mach_hwclk		= mvme147_hwclk;
 
 83	mach_reset		= mvme147_reset;
 84	mach_get_model		= mvme147_get_model;
 85
 86	/* Board type is only set by newer versions of vmelilo/tftplilo */
 87	if (!vme_brdtype)
 88		vme_brdtype = VME_TYPE_MVME147;
 89}
 90
 91static u64 mvme147_read_clk(struct clocksource *cs);
 92
 93static struct clocksource mvme147_clk = {
 94	.name   = "pcc",
 95	.rating = 250,
 96	.read   = mvme147_read_clk,
 97	.mask   = CLOCKSOURCE_MASK(32),
 98	.flags  = CLOCK_SOURCE_IS_CONTINUOUS,
 99};
100
101static u32 clk_total;
102
103#define PCC_TIMER_CLOCK_FREQ 160000
104#define PCC_TIMER_CYCLES     (PCC_TIMER_CLOCK_FREQ / HZ)
105#define PCC_TIMER_PRELOAD    (0x10000 - PCC_TIMER_CYCLES)
106
107/* Using pcc tick timer 1 */
108
109static irqreturn_t mvme147_timer_int (int irq, void *dev_id)
110{
111	unsigned long flags;
112
113	local_irq_save(flags);
114	m147_pcc->t1_cntrl = PCC_TIMER_CLR_OVF | PCC_TIMER_COC_EN |
115			     PCC_TIMER_TIC_EN;
116	m147_pcc->t1_int_cntrl = PCC_INT_ENAB | PCC_TIMER_INT_CLR |
117				 PCC_LEVEL_TIMER1;
118	clk_total += PCC_TIMER_CYCLES;
119	legacy_timer_tick(1);
120	local_irq_restore(flags);
121
122	return IRQ_HANDLED;
123}
124
125
126void mvme147_sched_init (void)
127{
128	if (request_irq(PCC_IRQ_TIMER1, mvme147_timer_int, IRQF_TIMER,
129			"timer 1", NULL))
130		pr_err("Couldn't register timer interrupt\n");
131
132	/* Init the clock with a value */
133	/* The clock counter increments until 0xFFFF then reloads */
134	m147_pcc->t1_preload = PCC_TIMER_PRELOAD;
135	m147_pcc->t1_cntrl = PCC_TIMER_CLR_OVF | PCC_TIMER_COC_EN |
136			     PCC_TIMER_TIC_EN;
137	m147_pcc->t1_int_cntrl = PCC_INT_ENAB | PCC_TIMER_INT_CLR |
138				 PCC_LEVEL_TIMER1;
139
140	clocksource_register_hz(&mvme147_clk, PCC_TIMER_CLOCK_FREQ);
141}
142
143static u64 mvme147_read_clk(struct clocksource *cs)
144{
145	unsigned long flags;
146	u8 overflow, tmp;
147	u16 count;
148	u32 ticks;
149
150	local_irq_save(flags);
151	tmp = m147_pcc->t1_cntrl >> 4;
152	count = m147_pcc->t1_count;
153	overflow = m147_pcc->t1_cntrl >> 4;
154	if (overflow != tmp)
155		count = m147_pcc->t1_count;
156	count -= PCC_TIMER_PRELOAD;
157	ticks = count + overflow * PCC_TIMER_CYCLES;
158	ticks += clk_total;
159	local_irq_restore(flags);
160
161	return ticks;
 
 
 
 
 
 
 
 
 
 
 
 
162}
163
164static int bcd2int (unsigned char b)
165{
166	return ((b>>4)*10 + (b&15));
167}
168
169int mvme147_hwclk(int op, struct rtc_time *t)
170{
 
171	if (!op) {
172		m147_rtc->ctrl = RTC_READ;
173		t->tm_year = bcd2int (m147_rtc->bcd_year);
174		t->tm_mon  = bcd2int(m147_rtc->bcd_mth) - 1;
175		t->tm_mday = bcd2int (m147_rtc->bcd_dom);
176		t->tm_hour = bcd2int (m147_rtc->bcd_hr);
177		t->tm_min  = bcd2int (m147_rtc->bcd_min);
178		t->tm_sec  = bcd2int (m147_rtc->bcd_sec);
179		m147_rtc->ctrl = 0;
180		if (t->tm_year < 70)
181			t->tm_year += 100;
182	} else {
183		/* FIXME Setting the time is not yet supported */
184		return -EOPNOTSUPP;
185	}
 
 
 
 
 
186	return 0;
187}
v4.6
 
  1/*
  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>
 
 20#include <linux/console.h>
 21#include <linux/linkage.h>
 22#include <linux/init.h>
 23#include <linux/major.h>
 24#include <linux/genhd.h>
 25#include <linux/rtc.h>
 26#include <linux/interrupt.h>
 27
 28#include <asm/bootinfo.h>
 29#include <asm/bootinfo-vme.h>
 30#include <asm/byteorder.h>
 31#include <asm/pgtable.h>
 32#include <asm/setup.h>
 33#include <asm/irq.h>
 34#include <asm/traps.h>
 35#include <asm/rtc.h>
 36#include <asm/machdep.h>
 37#include <asm/mvme147hw.h>
 
 38
 39
 40static void mvme147_get_model(char *model);
 41extern void mvme147_sched_init(irq_handler_t handler);
 42extern u32 mvme147_gettimeoffset(void);
 43extern int mvme147_hwclk (int, struct rtc_time *);
 44extern int mvme147_set_clock_mmss (unsigned long);
 45extern void mvme147_reset (void);
 46
 47
 48static int bcd2int (unsigned char b);
 49
 50/* Save tick handler routine pointer, will point to xtime_update() in
 51 * kernel/time/timekeeping.c, called via mvme147_process_int() */
 52
 53irq_handler_t tick_handler;
 54
 55
 56int __init mvme147_parse_bootinfo(const struct bi_record *bi)
 57{
 58	uint16_t tag = be16_to_cpu(bi->tag);
 59	if (tag == BI_VME_TYPE || tag == BI_VME_BRDINFO)
 60		return 0;
 61	else
 62		return 1;
 63}
 64
 65void mvme147_reset(void)
 66{
 67	printk ("\r\n\nCalled mvme147_reset\r\n");
 68	m147_pcc->watchdog = 0x0a;	/* Clear timer */
 69	m147_pcc->watchdog = 0xa5;	/* Enable watchdog - 100ms to reset */
 70	while (1)
 71		;
 72}
 73
 74static void mvme147_get_model(char *model)
 75{
 76	sprintf(model, "Motorola MVME147");
 77}
 78
 79/*
 80 * This function is called during kernel startup to initialize
 81 * the mvme147 IRQ handling routines.
 82 */
 83
 84void __init mvme147_init_IRQ(void)
 85{
 86	m68k_setup_user_interrupt(VEC_USER, 192);
 87}
 88
 89void __init config_mvme147(void)
 90{
 91	mach_max_dma_address	= 0x01000000;
 92	mach_sched_init		= mvme147_sched_init;
 93	mach_init_IRQ		= mvme147_init_IRQ;
 94	arch_gettimeoffset	= mvme147_gettimeoffset;
 95	mach_hwclk		= mvme147_hwclk;
 96	mach_set_clock_mmss	= mvme147_set_clock_mmss;
 97	mach_reset		= mvme147_reset;
 98	mach_get_model		= mvme147_get_model;
 99
100	/* Board type is only set by newer versions of vmelilo/tftplilo */
101	if (!vme_brdtype)
102		vme_brdtype = VME_TYPE_MVME147;
103}
104
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
106/* Using pcc tick timer 1 */
107
108static irqreturn_t mvme147_timer_int (int irq, void *dev_id)
109{
110	m147_pcc->t1_int_cntrl = PCC_TIMER_INT_CLR;
111	m147_pcc->t1_int_cntrl = PCC_INT_ENAB|PCC_LEVEL_TIMER1;
112	return tick_handler(irq, dev_id);
 
 
 
 
 
 
 
 
 
113}
114
115
116void mvme147_sched_init (irq_handler_t timer_routine)
117{
118	tick_handler = timer_routine;
119	if (request_irq(PCC_IRQ_TIMER1, mvme147_timer_int, 0, "timer 1", NULL))
120		pr_err("Couldn't register timer interrupt\n");
121
122	/* Init the clock with a value */
123	/* our clock goes off every 6.25us */
124	m147_pcc->t1_preload = PCC_TIMER_PRELOAD;
125	m147_pcc->t1_cntrl = 0x0;	/* clear timer */
126	m147_pcc->t1_cntrl = 0x3;	/* start timer */
127	m147_pcc->t1_int_cntrl = PCC_TIMER_INT_CLR;  /* clear pending ints */
128	m147_pcc->t1_int_cntrl = PCC_INT_ENAB|PCC_LEVEL_TIMER1;
129}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
131/* This is always executed with interrupts disabled.  */
132/* XXX There are race hazards in this code XXX */
133u32 mvme147_gettimeoffset(void)
134{
135	volatile unsigned short *cp = (volatile unsigned short *)0xfffe1012;
136	unsigned short n;
137
138	n = *cp;
139	while (n != *cp)
140		n = *cp;
141
142	n -= PCC_TIMER_PRELOAD;
143	return ((unsigned long)n * 25 / 4) * 1000;
144}
145
146static int bcd2int (unsigned char b)
147{
148	return ((b>>4)*10 + (b&15));
149}
150
151int mvme147_hwclk(int op, struct rtc_time *t)
152{
153#warning check me!
154	if (!op) {
155		m147_rtc->ctrl = RTC_READ;
156		t->tm_year = bcd2int (m147_rtc->bcd_year);
157		t->tm_mon  = bcd2int (m147_rtc->bcd_mth);
158		t->tm_mday = bcd2int (m147_rtc->bcd_dom);
159		t->tm_hour = bcd2int (m147_rtc->bcd_hr);
160		t->tm_min  = bcd2int (m147_rtc->bcd_min);
161		t->tm_sec  = bcd2int (m147_rtc->bcd_sec);
162		m147_rtc->ctrl = 0;
 
 
 
 
 
163	}
164	return 0;
165}
166
167int mvme147_set_clock_mmss (unsigned long nowtime)
168{
169	return 0;
170}