mc146818.c (170844) | mc146818.c (201008) |
---|---|
1/*- 2 * Copyright (c) 2003 Izumi Tsutsui. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. --- 13 unchanged lines hidden (view full) --- 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * 26 * from: NetBSD: mc146818.c,v 1.4 2003/11/24 06:20:40 tsutsui Exp 27 */ 28 29#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2003 Izumi Tsutsui. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. --- 13 unchanged lines hidden (view full) --- 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * 26 * from: NetBSD: mc146818.c,v 1.4 2003/11/24 06:20:40 tsutsui Exp 27 */ 28 29#include <sys/cdefs.h> |
30__FBSDID("$FreeBSD: head/sys/dev/mc146818/mc146818.c 170844 2007-06-16 23:10:00Z marius $"); | 30__FBSDID("$FreeBSD: head/sys/dev/mc146818/mc146818.c 201008 2009-12-25 22:53:46Z marius $"); |
31 32/* 33 * mc146818 and compatible time of day chip subroutines 34 */ 35 36#include <sys/param.h> 37#include <sys/systm.h> 38#include <sys/bus.h> --- 50 unchanged lines hidden (view full) --- 89 (*sc->sc_mcwrite)(dev, MC_REGA, sc->sc_rega); 90 91 sc->sc_regb = 0; 92 sc->sc_regb |= (sc->sc_flag & MC146818_BCD) ? 0 : MC_REGB_BINARY; 93 sc->sc_regb |= (sc->sc_flag & MC146818_12HR) ? 0 : MC_REGB_24HR; 94 (*sc->sc_mcwrite)(dev, MC_REGB, sc->sc_regb); 95 mtx_unlock_spin(&sc->sc_mtx); 96 | 31 32/* 33 * mc146818 and compatible time of day chip subroutines 34 */ 35 36#include <sys/param.h> 37#include <sys/systm.h> 38#include <sys/bus.h> --- 50 unchanged lines hidden (view full) --- 89 (*sc->sc_mcwrite)(dev, MC_REGA, sc->sc_rega); 90 91 sc->sc_regb = 0; 92 sc->sc_regb |= (sc->sc_flag & MC146818_BCD) ? 0 : MC_REGB_BINARY; 93 sc->sc_regb |= (sc->sc_flag & MC146818_12HR) ? 0 : MC_REGB_24HR; 94 (*sc->sc_mcwrite)(dev, MC_REGB, sc->sc_regb); 95 mtx_unlock_spin(&sc->sc_mtx); 96 |
97 clock_register(dev, 1000000); /* 1 second resolution. */ | 97 clock_register(dev, 1000000); /* 1 second resolution */ |
98 99 return (0); 100} 101 102/* 103 * Get time of day and convert it to a struct timespec. 104 * Return 0 on success, an error number otherwise. 105 */ --- 5 unchanged lines hidden (view full) --- 111 int timeout, cent, year; 112 113 sc = device_get_softc(dev); 114 115 timeout = 1000000; /* XXX how long should we wait? */ 116 117 /* 118 * If MC_REGA_UIP is 0 we have at least 244us before the next | 98 99 return (0); 100} 101 102/* 103 * Get time of day and convert it to a struct timespec. 104 * Return 0 on success, an error number otherwise. 105 */ --- 5 unchanged lines hidden (view full) --- 111 int timeout, cent, year; 112 113 sc = device_get_softc(dev); 114 115 timeout = 1000000; /* XXX how long should we wait? */ 116 117 /* 118 * If MC_REGA_UIP is 0 we have at least 244us before the next |
119 * update. If it's 1 an update is imminent. | 119 * update. If it's 1 an update is imminent. |
120 */ 121 for (;;) { 122 mtx_lock_spin(&sc->sc_mtx); 123 if (!((*sc->sc_mcread)(dev, MC_REGA) & MC_REGA_UIP)) 124 break; 125 mtx_unlock_spin(&sc->sc_mtx); 126 if (--timeout < 0) { 127 device_printf(dev, "%s: timeout\n", __func__); --- 127 unchanged lines hidden (view full) --- 255{ 256 struct mc146818_softc *sc; 257 258 sc = device_get_softc(dev); 259 bus_space_write_1(sc->sc_bst, sc->sc_bsh, MC_ADDR, reg); 260 bus_space_write_1(sc->sc_bst, sc->sc_bsh, MC_DATA, val); 261} 262 | 120 */ 121 for (;;) { 122 mtx_lock_spin(&sc->sc_mtx); 123 if (!((*sc->sc_mcread)(dev, MC_REGA) & MC_REGA_UIP)) 124 break; 125 mtx_unlock_spin(&sc->sc_mtx); 126 if (--timeout < 0) { 127 device_printf(dev, "%s: timeout\n", __func__); --- 127 unchanged lines hidden (view full) --- 255{ 256 struct mc146818_softc *sc; 257 258 sc = device_get_softc(dev); 259 bus_space_write_1(sc->sc_bst, sc->sc_bsh, MC_ADDR, reg); 260 bus_space_write_1(sc->sc_bst, sc->sc_bsh, MC_DATA, val); 261} 262 |
263#undef MC_ADDR 264#undef MC_DATA 265 |
|
263/* 264 * Looks like it's common even across platforms to store the century at 265 * 0x32 in the NVRAM of the mc146818. 266 */ 267#define MC_CENT 0x32 268 269static u_int 270mc146818_def_getcent(device_t dev) --- 7 unchanged lines hidden (view full) --- 278static void 279mc146818_def_setcent(device_t dev, u_int cent) 280{ 281 struct mc146818_softc *sc; 282 283 sc = device_get_softc(dev); 284 (*sc->sc_mcwrite)(dev, MC_CENT, cent); 285} | 266/* 267 * Looks like it's common even across platforms to store the century at 268 * 0x32 in the NVRAM of the mc146818. 269 */ 270#define MC_CENT 0x32 271 272static u_int 273mc146818_def_getcent(device_t dev) --- 7 unchanged lines hidden (view full) --- 281static void 282mc146818_def_setcent(device_t dev, u_int cent) 283{ 284 struct mc146818_softc *sc; 285 286 sc = device_get_softc(dev); 287 (*sc->sc_mcwrite)(dev, MC_CENT, cent); 288} |
289 290#undef MC_CENT |
|