xref: /netbsd-src/sys/arch/alpha/tc/mcclock_ioasic.c (revision e3581e4323ccbad4eeb5e63d79ee110e40136cbf)
1*e3581e43Sthorpej /* $NetBSD: mcclock_ioasic.c,v 1.19 2024/03/06 06:30:49 thorpej Exp $ */
217731baaScgd 
317731baaScgd /*
417731baaScgd  * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
517731baaScgd  * All rights reserved.
617731baaScgd  *
717731baaScgd  * Author: Chris G. Demetriou
817731baaScgd  *
917731baaScgd  * Permission to use, copy, modify and distribute this software and
1017731baaScgd  * its documentation is hereby granted, provided that both the copyright
1117731baaScgd  * notice and this permission notice appear in all copies of the
1217731baaScgd  * software, derivative works or modified versions, and any portions
1317731baaScgd  * thereof, and that both notices appear in supporting documentation.
1417731baaScgd  *
1517731baaScgd  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
1617731baaScgd  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
1717731baaScgd  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
1817731baaScgd  *
1917731baaScgd  * Carnegie Mellon requests users of this software to return to
2017731baaScgd  *
2117731baaScgd  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
2217731baaScgd  *  School of Computer Science
2317731baaScgd  *  Carnegie Mellon University
2417731baaScgd  *  Pittsburgh PA 15213-3890
2517731baaScgd  *
2617731baaScgd  * any improvements or extensions that they make and grant Carnegie the
2717731baaScgd  * rights to redistribute these changes.
2817731baaScgd  */
2971c79240Scgd 
3090789b53Scgd #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
3190789b53Scgd 
32*e3581e43Sthorpej __KERNEL_RCSID(0, "$NetBSD: mcclock_ioasic.c,v 1.19 2024/03/06 06:30:49 thorpej Exp $");
33059aaeddScgd 
3471c79240Scgd #include <sys/param.h>
3571c79240Scgd #include <sys/kernel.h>
3671c79240Scgd #include <sys/systm.h>
3771c79240Scgd #include <sys/device.h>
3871c79240Scgd 
39cf10107dSdyoung #include <sys/bus.h>
4013084fc8Stsutsui 
4113084fc8Stsutsui #include <dev/clock_subr.h>
4213084fc8Stsutsui 
4371c79240Scgd #include <dev/ic/mc146818reg.h>
4413084fc8Stsutsui #include <dev/ic/mc146818var.h>
4571c79240Scgd #include <dev/tc/tcvar.h>
4671c79240Scgd #include <dev/tc/ioasicvar.h>                   /* XXX */
4771c79240Scgd 
4813084fc8Stsutsui #include <alpha/alpha/mcclockvar.h>
4913084fc8Stsutsui 
5071c79240Scgd struct mcclock_ioasic_clockdatum {
5171c79240Scgd 	u_char	datum;
5271c79240Scgd 	char	pad[3];
5371c79240Scgd };
5471c79240Scgd 
5571c79240Scgd struct mcclock_ioasic_softc {
56*e3581e43Sthorpej 	struct mcclock_softc	sc_mcclock;
5771c79240Scgd 
5871c79240Scgd 	struct mcclock_ioasic_clockdatum *sc_dp;
5971c79240Scgd };
6071c79240Scgd 
61b7b2b8a3Sthorpej static int	mcclock_ioasic_match(device_t, cfdata_t, void *);
62b7b2b8a3Sthorpej static void	mcclock_ioasic_attach(device_t, device_t, void *);
6371c79240Scgd 
64048fb884Stsutsui CFATTACH_DECL_NEW(mcclock_ioasic, sizeof(struct mcclock_ioasic_softc),
65b96bc0d7Sthorpej     mcclock_ioasic_match, mcclock_ioasic_attach, NULL, NULL);
6671c79240Scgd 
67b7b2b8a3Sthorpej static void	mcclock_ioasic_write(struct mc146818_softc *, u_int, u_int);
68b7b2b8a3Sthorpej static u_int	mcclock_ioasic_read(struct mc146818_softc *, u_int);
6971c79240Scgd 
70b7b2b8a3Sthorpej static int
mcclock_ioasic_match(device_t parent,cfdata_t cf,void * aux)71048fb884Stsutsui mcclock_ioasic_match(device_t parent, cfdata_t cf, void *aux)
7271c79240Scgd {
7371c79240Scgd 	struct ioasicdev_attach_args *d = aux;
7471c79240Scgd 
7571c79240Scgd 	if (strncmp("TOY_RTC ", d->iada_modname, TC_ROM_LLEN))
7671c79240Scgd 		return (0);
7771c79240Scgd 
7871c79240Scgd 	return (1);
7971c79240Scgd }
8071c79240Scgd 
81b7b2b8a3Sthorpej static void
mcclock_ioasic_attach(device_t parent,device_t self,void * aux)82048fb884Stsutsui mcclock_ioasic_attach(device_t parent, device_t self, void *aux)
8371c79240Scgd {
84048fb884Stsutsui 	struct mcclock_ioasic_softc *isc = device_private(self);
8571c79240Scgd 	struct ioasicdev_attach_args *ioasicdev = aux;
86*e3581e43Sthorpej 	struct mc146818_softc *sc = &isc->sc_mcclock.sc_mc146818;
8771c79240Scgd 
8813084fc8Stsutsui 	/* XXX no bus_space(9) for TURBOchannel yet */
8913084fc8Stsutsui 	isc->sc_dp = (void *)ioasicdev->iada_addr;
9071c79240Scgd 
914090172bStsutsui 	sc->sc_dev = self;
9213084fc8Stsutsui 	sc->sc_mcread = mcclock_ioasic_read;
9313084fc8Stsutsui 	sc->sc_mcwrite = mcclock_ioasic_write;
9413084fc8Stsutsui 
9513084fc8Stsutsui 	/* call alpha common mcclock attachment */
96*e3581e43Sthorpej 	mcclock_attach(&isc->sc_mcclock);
9771c79240Scgd }
9871c79240Scgd 
99b7b2b8a3Sthorpej static void
mcclock_ioasic_write(struct mc146818_softc * sc,u_int reg,u_int datum)10013084fc8Stsutsui mcclock_ioasic_write(struct mc146818_softc *sc, u_int reg, u_int datum)
10171c79240Scgd {
10213084fc8Stsutsui 	struct mcclock_ioasic_softc *isc = (void *)sc;
10371c79240Scgd 
10413084fc8Stsutsui 	isc->sc_dp[reg].datum = datum;
10571c79240Scgd }
10671c79240Scgd 
107b7b2b8a3Sthorpej static u_int
mcclock_ioasic_read(struct mc146818_softc * sc,u_int reg)10813084fc8Stsutsui mcclock_ioasic_read(struct mc146818_softc *sc, u_int reg)
10971c79240Scgd {
11013084fc8Stsutsui 	struct mcclock_ioasic_softc *isc = (void *)sc;
11171c79240Scgd 
11213084fc8Stsutsui 	return isc->sc_dp[reg].datum;
11371c79240Scgd }
114