diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:49:45 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:49:45 +0000 |
commit | 2c3c1048746a4622d8c89a29670120dc8fab93c4 (patch) | |
tree | 848558de17fb3008cdf4d861b01ac7781903ce39 /arch/m68k/bvme6000 | |
parent | Initial commit. (diff) | |
download | linux-2c3c1048746a4622d8c89a29670120dc8fab93c4.tar.xz linux-2c3c1048746a4622d8c89a29670120dc8fab93c4.zip |
Adding upstream version 6.1.76.upstream/6.1.76
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'arch/m68k/bvme6000')
-rw-r--r-- | arch/m68k/bvme6000/Makefile | 6 | ||||
-rw-r--r-- | arch/m68k/bvme6000/config.c | 325 | ||||
-rw-r--r-- | arch/m68k/bvme6000/rtc.c | 175 |
3 files changed, 506 insertions, 0 deletions
diff --git a/arch/m68k/bvme6000/Makefile b/arch/m68k/bvme6000/Makefile new file mode 100644 index 000000000..41bd4fad3 --- /dev/null +++ b/arch/m68k/bvme6000/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Makefile for Linux arch/m68k/bvme6000 source directory +# + +obj-y := config.o rtc.o diff --git a/arch/m68k/bvme6000/config.c b/arch/m68k/bvme6000/config.c new file mode 100644 index 000000000..3a1d90e39 --- /dev/null +++ b/arch/m68k/bvme6000/config.c @@ -0,0 +1,325 @@ +/* + * arch/m68k/bvme6000/config.c + * + * Copyright (C) 1997 Richard Hirst [richard@sleepie.demon.co.uk] + * + * Based on: + * + * linux/amiga/config.c + * + * Copyright (C) 1993 Hamish Macdonald + * + * This file is subject to the terms and conditions of the GNU General Public + * License. See the file README.legal in the main directory of this archive + * for more details. + */ + +#include <linux/types.h> +#include <linux/kernel.h> +#include <linux/mm.h> +#include <linux/tty.h> +#include <linux/clocksource.h> +#include <linux/console.h> +#include <linux/linkage.h> +#include <linux/init.h> +#include <linux/major.h> +#include <linux/rtc.h> +#include <linux/interrupt.h> +#include <linux/bcd.h> + +#include <asm/bootinfo.h> +#include <asm/bootinfo-vme.h> +#include <asm/byteorder.h> +#include <asm/setup.h> +#include <asm/irq.h> +#include <asm/traps.h> +#include <asm/machdep.h> +#include <asm/bvme6000hw.h> +#include <asm/config.h> + +static void bvme6000_get_model(char *model); +extern void bvme6000_sched_init(void); +extern int bvme6000_hwclk (int, struct rtc_time *); +extern void bvme6000_reset (void); +void bvme6000_set_vectors (void); + + +int __init bvme6000_parse_bootinfo(const struct bi_record *bi) +{ + if (be16_to_cpu(bi->tag) == BI_VME_TYPE) + return 0; + else + return 1; +} + +void bvme6000_reset(void) +{ + volatile PitRegsPtr pit = (PitRegsPtr)BVME_PIT_BASE; + + pr_info("\r\n\nCalled bvme6000_reset\r\n" + "\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r"); + /* The string of returns is to delay the reset until the whole + * message is output. */ + /* Enable the watchdog, via PIT port C bit 4 */ + + pit->pcddr |= 0x10; /* WDOG enable */ + + while(1) + ; +} + +static void bvme6000_get_model(char *model) +{ + sprintf(model, "BVME%d000", m68k_cputype == CPU_68060 ? 6 : 4); +} + +/* + * This function is called during kernel startup to initialize + * the bvme6000 IRQ handling routines. + */ +static void __init bvme6000_init_IRQ(void) +{ + m68k_setup_user_interrupt(VEC_USER, 192); +} + +void __init config_bvme6000(void) +{ + volatile PitRegsPtr pit = (PitRegsPtr)BVME_PIT_BASE; + + /* Board type is only set by newer versions of vmelilo/tftplilo */ + if (!vme_brdtype) { + if (m68k_cputype == CPU_68060) + vme_brdtype = VME_TYPE_BVME6000; + else + vme_brdtype = VME_TYPE_BVME4000; + } +#if 0 + /* Call bvme6000_set_vectors() so ABORT will work, along with BVMBug + * debugger. Note trap_init() will splat the abort vector, but + * bvme6000_init_IRQ() will put it back again. Hopefully. */ + + bvme6000_set_vectors(); +#endif + + mach_sched_init = bvme6000_sched_init; + mach_init_IRQ = bvme6000_init_IRQ; + mach_hwclk = bvme6000_hwclk; + mach_reset = bvme6000_reset; + mach_get_model = bvme6000_get_model; + + pr_info("Board is %sconfigured as a System Controller\n", + *config_reg_ptr & BVME_CONFIG_SW1 ? "" : "not "); + + /* Now do the PIT configuration */ + + pit->pgcr = 0x00; /* Unidirectional 8 bit, no handshake for now */ + pit->psrr = 0x18; /* PIACK and PIRQ functions enabled */ + pit->pacr = 0x00; /* Sub Mode 00, H2 i/p, no DMA */ + pit->padr = 0x00; /* Just to be tidy! */ + pit->paddr = 0x00; /* All inputs for now (safest) */ + pit->pbcr = 0x80; /* Sub Mode 1x, H4 i/p, no DMA */ + pit->pbdr = 0xbc | (*config_reg_ptr & BVME_CONFIG_SW1 ? 0 : 0x40); + /* PRI, SYSCON?, Level3, SCC clks from xtal */ + pit->pbddr = 0xf3; /* Mostly outputs */ + pit->pcdr = 0x01; /* PA transceiver disabled */ + pit->pcddr = 0x03; /* WDOG disable */ + + /* Disable snooping for Ethernet and VME accesses */ + + bvme_acr_addrctl = 0; +} + + +irqreturn_t bvme6000_abort_int (int irq, void *dev_id) +{ + unsigned long *new = (unsigned long *)vectors; + unsigned long *old = (unsigned long *)0xf8000000; + + /* Wait for button release */ + while (*(volatile unsigned char *)BVME_LOCAL_IRQ_STAT & BVME_ABORT_STATUS) + ; + + *(new+4) = *(old+4); /* Illegal instruction */ + *(new+9) = *(old+9); /* Trace */ + *(new+47) = *(old+47); /* Trap #15 */ + *(new+0x1f) = *(old+0x1f); /* ABORT switch */ + return IRQ_HANDLED; +} + +static u64 bvme6000_read_clk(struct clocksource *cs); + +static struct clocksource bvme6000_clk = { + .name = "rtc", + .rating = 250, + .read = bvme6000_read_clk, + .mask = CLOCKSOURCE_MASK(32), + .flags = CLOCK_SOURCE_IS_CONTINUOUS, +}; + +static u32 clk_total, clk_offset; + +#define RTC_TIMER_CLOCK_FREQ 8000000 +#define RTC_TIMER_CYCLES (RTC_TIMER_CLOCK_FREQ / HZ) +#define RTC_TIMER_COUNT ((RTC_TIMER_CYCLES / 2) - 1) + +static irqreturn_t bvme6000_timer_int (int irq, void *dev_id) +{ + unsigned long flags; + volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE; + unsigned char msr; + + local_irq_save(flags); + msr = rtc->msr & 0xc0; + rtc->msr = msr | 0x20; /* Ack the interrupt */ + clk_total += RTC_TIMER_CYCLES; + clk_offset = 0; + legacy_timer_tick(1); + local_irq_restore(flags); + + return IRQ_HANDLED; +} + +/* + * Set up the RTC timer 1 to mode 2, so T1 output toggles every 5ms + * (40000 x 125ns). It will interrupt every 10ms, when T1 goes low. + * So, when reading the elapsed time, you should read timer1, + * subtract it from 39999, and then add 40000 if T1 is high. + * That gives you the number of 125ns ticks in to the 10ms period, + * so divide by 8 to get the microsecond result. + */ + +void bvme6000_sched_init (void) +{ + volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE; + unsigned char msr = rtc->msr & 0xc0; + + rtc->msr = 0; /* Ensure timer registers accessible */ + + if (request_irq(BVME_IRQ_RTC, bvme6000_timer_int, IRQF_TIMER, "timer", + NULL)) + panic ("Couldn't register timer int"); + + rtc->t1cr_omr = 0x04; /* Mode 2, ext clk */ + rtc->t1msb = RTC_TIMER_COUNT >> 8; + rtc->t1lsb = RTC_TIMER_COUNT & 0xff; + rtc->irr_icr1 &= 0xef; /* Route timer 1 to INTR pin */ + rtc->msr = 0x40; /* Access int.cntrl, etc */ + rtc->pfr_icr0 = 0x80; /* Just timer 1 ints enabled */ + rtc->irr_icr1 = 0; + rtc->t1cr_omr = 0x0a; /* INTR+T1 active lo, push-pull */ + rtc->t0cr_rtmr &= 0xdf; /* Stop timers in standby */ + rtc->msr = 0; /* Access timer 1 control */ + rtc->t1cr_omr = 0x05; /* Mode 2, ext clk, GO */ + + rtc->msr = msr; + + clocksource_register_hz(&bvme6000_clk, RTC_TIMER_CLOCK_FREQ); + + if (request_irq(BVME_IRQ_ABORT, bvme6000_abort_int, 0, + "abort", bvme6000_abort_int)) + panic ("Couldn't register abort int"); +} + + +/* + * NOTE: Don't accept any readings within 5us of rollover, as + * the T1INT bit may be a little slow getting set. There is also + * a fault in the chip, meaning that reads may produce invalid + * results... + */ + +static u64 bvme6000_read_clk(struct clocksource *cs) +{ + unsigned long flags; + volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE; + volatile PitRegsPtr pit = (PitRegsPtr)BVME_PIT_BASE; + unsigned char msr, msb; + unsigned char t1int, t1op; + u32 v = 800000, ov; + + local_irq_save(flags); + + msr = rtc->msr & 0xc0; + rtc->msr = 0; /* Ensure timer registers accessible */ + + do { + ov = v; + t1int = rtc->msr & 0x20; + t1op = pit->pcdr & 0x04; + rtc->t1cr_omr |= 0x40; /* Latch timer1 */ + msb = rtc->t1msb; /* Read timer1 */ + v = (msb << 8) | rtc->t1lsb; /* Read timer1 */ + } while (t1int != (rtc->msr & 0x20) || + t1op != (pit->pcdr & 0x04) || + abs(ov-v) > 80 || + v > RTC_TIMER_COUNT - (RTC_TIMER_COUNT / 100)); + + v = RTC_TIMER_COUNT - v; + if (!t1op) /* If in second half cycle.. */ + v += RTC_TIMER_CYCLES / 2; + if (msb > 0 && t1int) + clk_offset = RTC_TIMER_CYCLES; + rtc->msr = msr; + + v += clk_offset + clk_total; + + local_irq_restore(flags); + + return v; +} + +/* + * Looks like op is non-zero for setting the clock, and zero for + * reading the clock. + * + * struct hwclk_time { + * unsigned sec; 0..59 + * unsigned min; 0..59 + * unsigned hour; 0..23 + * unsigned day; 1..31 + * unsigned mon; 0..11 + * unsigned year; 00... + * int wday; 0..6, 0 is Sunday, -1 means unknown/don't set + * }; + */ + +int bvme6000_hwclk(int op, struct rtc_time *t) +{ + volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE; + unsigned char msr = rtc->msr & 0xc0; + + rtc->msr = 0x40; /* Ensure clock and real-time-mode-register + * are accessible */ + if (op) + { /* Write.... */ + rtc->t0cr_rtmr = t->tm_year%4; + rtc->bcd_tenms = 0; + rtc->bcd_sec = bin2bcd(t->tm_sec); + rtc->bcd_min = bin2bcd(t->tm_min); + rtc->bcd_hr = bin2bcd(t->tm_hour); + rtc->bcd_dom = bin2bcd(t->tm_mday); + rtc->bcd_mth = bin2bcd(t->tm_mon + 1); + rtc->bcd_year = bin2bcd(t->tm_year%100); + if (t->tm_wday >= 0) + rtc->bcd_dow = bin2bcd(t->tm_wday+1); + rtc->t0cr_rtmr = t->tm_year%4 | 0x08; + } + else + { /* Read.... */ + do { + t->tm_sec = bcd2bin(rtc->bcd_sec); + t->tm_min = bcd2bin(rtc->bcd_min); + t->tm_hour = bcd2bin(rtc->bcd_hr); + t->tm_mday = bcd2bin(rtc->bcd_dom); + t->tm_mon = bcd2bin(rtc->bcd_mth)-1; + t->tm_year = bcd2bin(rtc->bcd_year); + if (t->tm_year < 70) + t->tm_year += 100; + t->tm_wday = bcd2bin(rtc->bcd_dow)-1; + } while (t->tm_sec != bcd2bin(rtc->bcd_sec)); + } + + rtc->msr = msr; + + return 0; +} diff --git a/arch/m68k/bvme6000/rtc.c b/arch/m68k/bvme6000/rtc.c new file mode 100644 index 000000000..b43eeef09 --- /dev/null +++ b/arch/m68k/bvme6000/rtc.c @@ -0,0 +1,175 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Real Time Clock interface for Linux on the BVME6000 + * + * Based on the PC driver by Paul Gortmaker. + */ + +#define RTC_VERSION "1.00" + +#include <linux/types.h> +#include <linux/errno.h> +#include <linux/miscdevice.h> +#include <linux/ioport.h> +#include <linux/capability.h> +#include <linux/fcntl.h> +#include <linux/init.h> +#include <linux/poll.h> +#include <linux/module.h> +#include <linux/rtc.h> /* For struct rtc_time and ioctls, etc */ +#include <linux/bcd.h> +#include <asm/bvme6000hw.h> + +#include <asm/io.h> +#include <linux/uaccess.h> +#include <asm/setup.h> + +/* + * We sponge a minor off of the misc major. No need slurping + * up another valuable major dev number for this. If you add + * an ioctl, make sure you don't conflict with SPARC's RTC + * ioctls. + */ + +static unsigned char days_in_mo[] = +{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + +static atomic_t rtc_status = ATOMIC_INIT(1); + +static long rtc_ioctl(struct file *file, unsigned int cmd, unsigned long arg) +{ + volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE; + unsigned char msr; + unsigned long flags; + struct rtc_time wtime; + void __user *argp = (void __user *)arg; + + switch (cmd) { + case RTC_RD_TIME: /* Read the time/date from RTC */ + { + local_irq_save(flags); + /* Ensure clock and real-time-mode-register are accessible */ + msr = rtc->msr & 0xc0; + rtc->msr = 0x40; + memset(&wtime, 0, sizeof(struct rtc_time)); + do { + wtime.tm_sec = bcd2bin(rtc->bcd_sec); + wtime.tm_min = bcd2bin(rtc->bcd_min); + wtime.tm_hour = bcd2bin(rtc->bcd_hr); + wtime.tm_mday = bcd2bin(rtc->bcd_dom); + wtime.tm_mon = bcd2bin(rtc->bcd_mth)-1; + wtime.tm_year = bcd2bin(rtc->bcd_year); + if (wtime.tm_year < 70) + wtime.tm_year += 100; + wtime.tm_wday = bcd2bin(rtc->bcd_dow)-1; + } while (wtime.tm_sec != bcd2bin(rtc->bcd_sec)); + rtc->msr = msr; + local_irq_restore(flags); + return copy_to_user(argp, &wtime, sizeof wtime) ? + -EFAULT : 0; + } + case RTC_SET_TIME: /* Set the RTC */ + { + struct rtc_time rtc_tm; + unsigned char mon, day, hrs, min, sec, leap_yr; + unsigned int yrs; + + if (!capable(CAP_SYS_ADMIN)) + return -EACCES; + + if (copy_from_user(&rtc_tm, argp, sizeof(struct rtc_time))) + return -EFAULT; + + yrs = rtc_tm.tm_year; + if (yrs < 1900) + yrs += 1900; + mon = rtc_tm.tm_mon + 1; /* tm_mon starts at zero */ + day = rtc_tm.tm_mday; + hrs = rtc_tm.tm_hour; + min = rtc_tm.tm_min; + sec = rtc_tm.tm_sec; + + leap_yr = ((!(yrs % 4) && (yrs % 100)) || !(yrs % 400)); + + if ((mon > 12) || (mon < 1) || (day == 0)) + return -EINVAL; + + if (day > (days_in_mo[mon] + ((mon == 2) && leap_yr))) + return -EINVAL; + + if ((hrs >= 24) || (min >= 60) || (sec >= 60)) + return -EINVAL; + + if (yrs >= 2070) + return -EINVAL; + + local_irq_save(flags); + /* Ensure clock and real-time-mode-register are accessible */ + msr = rtc->msr & 0xc0; + rtc->msr = 0x40; + + rtc->t0cr_rtmr = yrs%4; + rtc->bcd_tenms = 0; + rtc->bcd_sec = bin2bcd(sec); + rtc->bcd_min = bin2bcd(min); + rtc->bcd_hr = bin2bcd(hrs); + rtc->bcd_dom = bin2bcd(day); + rtc->bcd_mth = bin2bcd(mon); + rtc->bcd_year = bin2bcd(yrs%100); + if (rtc_tm.tm_wday >= 0) + rtc->bcd_dow = bin2bcd(rtc_tm.tm_wday+1); + rtc->t0cr_rtmr = yrs%4 | 0x08; + + rtc->msr = msr; + local_irq_restore(flags); + return 0; + } + default: + return -EINVAL; + } +} + +/* + * We enforce only one user at a time here with the open/close. + */ +static int rtc_open(struct inode *inode, struct file *file) +{ + if (!atomic_dec_and_test(&rtc_status)) { + atomic_inc(&rtc_status); + return -EBUSY; + } + return 0; +} + +static int rtc_release(struct inode *inode, struct file *file) +{ + atomic_inc(&rtc_status); + return 0; +} + +/* + * The various file operations we support. + */ + +static const struct file_operations rtc_fops = { + .unlocked_ioctl = rtc_ioctl, + .open = rtc_open, + .release = rtc_release, + .llseek = noop_llseek, +}; + +static struct miscdevice rtc_dev = { + .minor = RTC_MINOR, + .name = "rtc", + .fops = &rtc_fops +}; + +static int __init rtc_DP8570A_init(void) +{ + if (!MACH_IS_BVME6000) + return -ENODEV; + + pr_info("DP8570A Real Time Clock Driver v%s\n", RTC_VERSION); + return misc_register(&rtc_dev); +} +module_init(rtc_DP8570A_init); |