1 /* $NetBSD: tod.c,v 1.14 2008/07/06 13:29:50 tsutsui Exp $ */ 2 3 /* 4 * Copyright (c) 1982, 1990, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * the Systems Programming Group of the University of Utah Computer 9 * Science Department. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 * from: Utah Hdr: clock.c 1.18 91/01/21$ 36 * from: @(#)clock.c 8.2 (Berkeley) 1/12/94 37 */ 38 39 /* 40 * Copyright (c) 2001 Matthew Fredette 41 * Copyright (c) 1994 Gordon W. Ross 42 * Copyright (c) 1993 Adam Glass 43 * Copyright (c) 1988 University of Utah. 44 * 45 * This code is derived from software contributed to Berkeley by 46 * the Systems Programming Group of the University of Utah Computer 47 * Science Department. 48 * 49 * Redistribution and use in source and binary forms, with or without 50 * modification, are permitted provided that the following conditions 51 * are met: 52 * 1. Redistributions of source code must retain the above copyright 53 * notice, this list of conditions and the following disclaimer. 54 * 2. Redistributions in binary form must reproduce the above copyright 55 * notice, this list of conditions and the following disclaimer in the 56 * documentation and/or other materials provided with the distribution. 57 * 3. All advertising materials mentioning features or use of this software 58 * must display the following acknowledgement: 59 * This product includes software developed by the University of 60 * California, Berkeley and its contributors. 61 * 4. Neither the name of the University nor the names of its contributors 62 * may be used to endorse or promote products derived from this software 63 * without specific prior written permission. 64 * 65 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 66 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 67 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 68 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 69 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 70 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 71 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 72 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 73 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 74 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 75 * SUCH DAMAGE. 76 * 77 * from: Utah Hdr: clock.c 1.18 91/01/21$ 78 * from: @(#)clock.c 8.2 (Berkeley) 1/12/94 79 */ 80 81 /* 82 * Machine-dependent clock routines for the NS mm58167 time-of-day chip. 83 * Written by Matthew Fredette, based on the sun3 clock.c by 84 * Adam Glass and Gordon Ross. 85 */ 86 87 #include <sys/cdefs.h> 88 __KERNEL_RCSID(0, "$NetBSD: tod.c,v 1.14 2008/07/06 13:29:50 tsutsui Exp $"); 89 90 #include <sys/param.h> 91 #include <sys/systm.h> 92 #include <sys/time.h> 93 #include <sys/kernel.h> 94 #include <sys/device.h> 95 96 #include <m68k/asm_single.h> 97 98 #include <machine/autoconf.h> 99 #include <machine/bus.h> 100 #include <machine/cpu.h> 101 102 #include <sun2/sun2/machdep.h> 103 #include <sun2/sun2/tod.h> 104 105 #include <dev/vme/vmereg.h> 106 #include <dev/vme/vmevar.h> 107 108 #include <dev/clock_subr.h> 109 #include <dev/ic/mm58167var.h> 110 111 static int tod_obio_match(device_t, cfdata_t, void *args); 112 static void tod_obio_attach(device_t, device_t, void *); 113 static int tod_vme_match(device_t, cfdata_t, void *args); 114 static void tod_vme_attach(device_t, device_t, void *); 115 static void tod_attach(struct mm58167_softc *); 116 117 CFATTACH_DECL_NEW(tod_obio, sizeof(struct mm58167_softc), 118 tod_obio_match, tod_obio_attach, NULL, NULL); 119 120 CFATTACH_DECL_NEW(tod_vme, sizeof(struct mm58167_softc), 121 tod_vme_match, tod_vme_attach, NULL, NULL); 122 123 static int tod_attached; 124 125 static int 126 tod_obio_match(device_t parent, cfdata_t cf, void *args) 127 { 128 struct obio_attach_args *oba = args; 129 bus_space_handle_t bh; 130 int matched; 131 132 /* This driver only supports one unit. */ 133 if (tod_attached) 134 return 0; 135 136 /* Make sure there is something there... */ 137 if (bus_space_map(oba->oba_bustag, oba->oba_paddr, MM58167REG_BANK_SZ, 138 0, &bh)) 139 return 0; 140 matched = (bus_space_peek_1(oba->oba_bustag, bh, 0, NULL) == 0); 141 bus_space_unmap(oba->oba_bustag, bh, MM58167REG_BANK_SZ); 142 return matched; 143 } 144 145 static void 146 tod_obio_attach(device_t parent, device_t self, void *args) 147 { 148 struct obio_attach_args *oba = args; 149 struct mm58167_softc *sc; 150 151 tod_attached = 1; 152 153 sc = device_private(self); 154 sc->mm58167_dev = self; 155 156 /* Map the device. */ 157 sc->mm58167_regt = oba->oba_bustag; 158 if (bus_space_map(oba->oba_bustag, oba->oba_paddr, MM58167REG_BANK_SZ, 159 0, &sc->mm58167_regh)) 160 panic("%s: can't map", __func__); 161 162 tod_attach(sc); 163 } 164 165 static int 166 tod_vme_match(device_t parent, cfdata_t cf, void *aux) 167 { 168 struct vme_attach_args *va = aux; 169 vme_chipset_tag_t ct = va->va_vct; 170 vme_am_t mod; 171 vme_addr_t vme_addr; 172 173 /* Make sure there is something there... */ 174 mod = VME_AM_A24 | VME_AM_MBO | VME_AM_SUPER | VME_AM_DATA; 175 vme_addr = va->r[0].offset; 176 177 if (vme_probe(ct, vme_addr, 1, mod, VME_D8, NULL, 0) != 0) 178 return 0; 179 180 return 1; 181 } 182 183 static void 184 tod_vme_attach(device_t parent, device_t self, void *aux) 185 { 186 struct mm58167_softc *sc; 187 struct vme_attach_args *va = aux; 188 vme_chipset_tag_t ct = va->va_vct; 189 bus_space_tag_t bt; 190 bus_space_handle_t bh; 191 vme_am_t mod; 192 vme_mapresc_t resc; 193 194 sc = device_private(self); 195 sc->mm58167_dev = self; 196 197 mod = VME_AM_A24 | VME_AM_MBO | VME_AM_SUPER | VME_AM_DATA; 198 199 if (vme_space_map(ct, va->r[0].offset, MM58167REG_BANK_SZ, 200 mod, VME_D8, 0, &bt, &bh, &resc) != 0) 201 panic("%s: can't map", __func__); 202 203 sc->mm58167_regt = bt; 204 sc->mm58167_regh = bh; 205 206 tod_attach(sc); 207 } 208 209 static void 210 tod_attach(struct mm58167_softc *sc) 211 { 212 todr_chip_handle_t tch; 213 214 /* Call the IC attach code. */ 215 sc->mm58167_msec_xxx = MM58167REG_MSEC_XXX; 216 sc->mm58167_csec = MM58167REG_CSEC; 217 sc->mm58167_sec = MM58167REG_SEC; 218 sc->mm58167_min = MM58167REG_MIN; 219 sc->mm58167_hour = MM58167REG_HOUR; 220 sc->mm58167_wday = MM58167REG_WDAY; 221 sc->mm58167_day = MM58167REG_DAY; 222 sc->mm58167_mon = MM58167REG_MON; 223 sc->mm58167_status = MM58167REG_STATUS; 224 sc->mm58167_go = MM58167REG_GO; 225 if ((tch = mm58167_attach(sc)) == NULL) 226 panic("%s: can't attach ic", __func__); 227 228 todr_attach(tch); 229 aprint_normal("\n"); 230 } 231