1 /* $NetBSD: vrtc.c,v 1.5 2025/09/07 21:45:15 thorpej Exp $ */ 2 /* $OpenBSD: vrtc.c,v 1.1 2008/03/08 19:19:43 kettenis Exp $ */ 3 /* 4 * Copyright (c) 2008 Mark Kettenis 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #include <sys/param.h> 20 #include <sys/device.h> 21 #include <sys/kmem.h> 22 #include <sys/systm.h> 23 24 #include <machine/autoconf.h> 25 #include <machine/hypervisor.h> 26 #include <machine/openfirm.h> 27 28 #include <dev/clock_subr.h> 29 #include <sparc64/dev/vbusvar.h> 30 31 static int vrtc_match(device_t, cfdata_t, void *); 32 static void vrtc_attach(device_t, device_t, void *); 33 34 struct vrtc_softc { 35 device_t sc_dev; 36 struct todr_chip_handle sc_todr; 37 }; 38 39 CFATTACH_DECL_NEW(vrtc, sizeof(struct vrtc_softc), 40 vrtc_match, vrtc_attach, NULL, NULL); 41 42 static int vrtc_gettime(todr_chip_handle_t, struct timeval *); 43 static int vrtc_settime(todr_chip_handle_t, struct timeval *); 44 45 static int 46 vrtc_match(device_t parent, cfdata_t match, void *aux) 47 { 48 struct vbus_attach_args *va = aux; 49 50 if (strcmp(va->va_name, "rtc") == 0) 51 return (1); 52 53 return (0); 54 } 55 56 static void 57 vrtc_attach(device_t parent, device_t self, void *aux) 58 { 59 struct vrtc_softc *sc = device_private(self); 60 61 printf("\n"); 62 63 sc->sc_dev = self; 64 sc->sc_todr.todr_gettime = vrtc_gettime; 65 sc->sc_todr.todr_settime = vrtc_settime; 66 67 todr_attach(&sc->sc_todr); 68 } 69 70 static int 71 vrtc_gettime(todr_chip_handle_t handle, struct timeval *tv) 72 { 73 u_int64_t tod; 74 75 if (hv_tod_get(&tod) != H_EOK) 76 return (1); 77 78 tv->tv_sec = tod; 79 tv->tv_usec = 0; 80 return (0); 81 } 82 83 static int 84 vrtc_settime(todr_chip_handle_t handle, struct timeval *tv) 85 { 86 if (hv_tod_set(tv->tv_sec) != H_EOK) 87 return (1); 88 89 return (0); 90 } 91