xref: /netbsd-src/sys/arch/alpha/jensenio/mcclock_jensenio.c (revision e3581e4323ccbad4eeb5e63d79ee110e40136cbf)
1 /* $NetBSD: mcclock_jensenio.c,v 1.12 2024/03/06 06:30:49 thorpej Exp $ */
2 
3 /*-
4  * Copyright (c) 1999 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Jason R. Thorpe.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /*
33  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
34  * All rights reserved.
35  *
36  * Author: Chris G. Demetriou
37  *
38  * Permission to use, copy, modify and distribute this software and
39  * its documentation is hereby granted, provided that both the copyright
40  * notice and this permission notice appear in all copies of the
41  * software, derivative works or modified versions, and any portions
42  * thereof, and that both notices appear in supporting documentation.
43  *
44  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
45  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
46  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
47  *
48  * Carnegie Mellon requests users of this software to return to
49  *
50  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
51  *  School of Computer Science
52  *  Carnegie Mellon University
53  *  Pittsburgh PA 15213-3890
54  *
55  * any improvements or extensions that they make and grant Carnegie the
56  * rights to redistribute these changes.
57  */
58 
59 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
60 
61 __KERNEL_RCSID(0, "$NetBSD: mcclock_jensenio.c,v 1.12 2024/03/06 06:30:49 thorpej Exp $");
62 
63 #include <sys/param.h>
64 #include <sys/kernel.h>
65 #include <sys/systm.h>
66 #include <sys/device.h>
67 
68 #include <sys/bus.h>
69 
70 #include <dev/clock_subr.h>
71 
72 #include <dev/ic/mc146818reg.h>
73 #include <dev/ic/mc146818var.h>
74 #include <dev/eisa/eisavar.h>
75 #include <dev/isa/isavar.h>
76 #include <alpha/jensenio/jenseniovar.h>
77 #include <alpha/alpha/mcclockvar.h>
78 
79 struct mcclock_jensenio_softc {
80 	struct mcclock_softc	sc_mcclock;
81 
82 	bus_space_handle_t	sc_std_rtc_ioh;
83 };
84 
85 static int	mcclock_jensenio_match(device_t, cfdata_t, void *);
86 static void	mcclock_jensenio_attach(device_t, device_t, void *);
87 
88 CFATTACH_DECL_NEW(mcclock_jensenio, sizeof(struct mcclock_jensenio_softc),
89     mcclock_jensenio_match, mcclock_jensenio_attach, NULL, NULL);
90 
91 static void	mcclock_jensenio_write(struct mc146818_softc *, u_int, u_int);
92 static u_int	mcclock_jensenio_read(struct mc146818_softc *, u_int);
93 
94 
95 static int
mcclock_jensenio_match(device_t parent,cfdata_t cf,void * aux)96 mcclock_jensenio_match(device_t parent, cfdata_t cf, void *aux)
97 {
98 	struct jensenio_attach_args *ja = aux;
99 
100 	/* Always present. */
101 	if (strcmp(ja->ja_name, cf->cf_name) == 0)
102 		return (1);
103 
104 	return (0);
105 }
106 
107 static void
mcclock_jensenio_attach(device_t parent,device_t self,void * aux)108 mcclock_jensenio_attach(device_t parent, device_t self, void *aux)
109 {
110 	struct mcclock_jensenio_softc *jsc = device_private(self);
111 	struct jensenio_attach_args *ja = aux;
112 	struct mc146818_softc *sc = &jsc->sc_mcclock.sc_mc146818;
113 
114 	sc->sc_dev = self;
115 	sc->sc_bst = ja->ja_iot;
116 	if (bus_space_map(sc->sc_bst, ja->ja_ioaddr, 0x02, 0,
117 	    &sc->sc_bsh))
118 		panic("mcclock_jensenio_attach: couldn't map clock I/O space");
119 
120 	/*
121 	 * Map the I/O space normally used by the ISA RTC (port 0x70) so
122 	 * as to avoid a false match at that address, as well.
123 	 */
124 	(void)bus_space_map(sc->sc_bst, 0x70, 0x02, 0,
125 	    &jsc->sc_std_rtc_ioh);
126 
127 	sc->sc_mcread  = mcclock_jensenio_read;
128 	sc->sc_mcwrite = mcclock_jensenio_write;
129 
130 	mcclock_attach(&jsc->sc_mcclock);
131 }
132 
133 static void
mcclock_jensenio_write(struct mc146818_softc * sc,u_int reg,u_int datum)134 mcclock_jensenio_write(struct mc146818_softc *sc, u_int reg, u_int datum)
135 {
136 	bus_space_tag_t iot = sc->sc_bst;
137 	bus_space_handle_t ioh = sc->sc_bsh;
138 
139 	bus_space_write_1(iot, ioh, 0, reg);
140 	bus_space_write_1(iot, ioh, 1, datum);
141 }
142 
143 static u_int
mcclock_jensenio_read(struct mc146818_softc * sc,u_int reg)144 mcclock_jensenio_read(struct mc146818_softc *sc, u_int reg)
145 {
146 	bus_space_tag_t iot = sc->sc_bst;
147 	bus_space_handle_t ioh = sc->sc_bsh;
148 
149 	bus_space_write_1(iot, ioh, 0, reg);
150 	return bus_space_read_1(iot, ioh, 1);
151 }
152