11.3Sthorpej/* $NetBSD: clpsrtc.c,v 1.3 2025/09/07 21:45:11 thorpej Exp $ */ 21.1Skiyohara/* 31.1Skiyohara * Copyright (c) 2013 KIYOHARA Takashi 41.1Skiyohara * All rights reserved. 51.1Skiyohara * 61.1Skiyohara * Redistribution and use in source and binary forms, with or without 71.1Skiyohara * modification, are permitted provided that the following conditions 81.1Skiyohara * are met: 91.1Skiyohara * 1. Redistributions of source code must retain the above copyright 101.1Skiyohara * notice, this list of conditions and the following disclaimer. 111.1Skiyohara * 2. Redistributions in binary form must reproduce the above copyright 121.1Skiyohara * notice, this list of conditions and the following disclaimer in the 131.1Skiyohara * documentation and/or other materials provided with the distribution. 141.1Skiyohara * 151.1Skiyohara * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 161.1Skiyohara * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 171.1Skiyohara * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 181.1Skiyohara * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 191.1Skiyohara * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 201.1Skiyohara * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 211.1Skiyohara * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 221.1Skiyohara * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 231.1Skiyohara * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 241.1Skiyohara * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 251.1Skiyohara * POSSIBILITY OF SUCH DAMAGE. 261.1Skiyohara */ 271.1Skiyohara#include <sys/cdefs.h> 281.3Sthorpej__KERNEL_RCSID(0, "$NetBSD: clpsrtc.c,v 1.3 2025/09/07 21:45:11 thorpej Exp $"); 291.1Skiyohara 301.1Skiyohara#include <sys/param.h> 311.1Skiyohara#include <sys/bus.h> 321.1Skiyohara#include <sys/device.h> 331.1Skiyohara#include <sys/errno.h> 341.1Skiyohara 351.1Skiyohara#include <dev/clock_subr.h> 361.1Skiyohara 371.1Skiyohara#include <arm/clps711x/clps711xreg.h> 381.1Skiyohara#include <arm/clps711x/clpssocvar.h> 391.1Skiyohara 401.1Skiyohara#include "locators.h" 411.1Skiyohara 421.1Skiyoharastruct clpsrtc_softc { 431.1Skiyohara device_t sc_dev; 441.1Skiyohara bus_space_tag_t sc_iot; 451.1Skiyohara bus_space_handle_t sc_ioh; 461.1Skiyohara 471.1Skiyohara struct todr_chip_handle sc_todr; 481.1Skiyohara}; 491.1Skiyohara 501.1Skiyoharastatic int clpsrtc_match(device_t, cfdata_t, void *); 511.1Skiyoharastatic void clpsrtc_attach(device_t, device_t, void *); 521.1Skiyohara 531.1Skiyohara/* todr(9) interfaces */ 541.1Skiyoharastatic int clpsrtc_todr_gettime(todr_chip_handle_t, struct timeval *); 551.1Skiyoharastatic int clpsrtc_todr_settime(todr_chip_handle_t, struct timeval *); 561.1Skiyohara 571.1SkiyoharaCFATTACH_DECL_NEW(clpsrtc, sizeof(struct clpsrtc_softc), 581.1Skiyohara clpsrtc_match, clpsrtc_attach, NULL, NULL); 591.1Skiyohara 601.1Skiyohara 611.1Skiyohara/* ARGSUSED */ 621.1Skiyoharastatic int 631.1Skiyoharaclpsrtc_match(device_t parent, cfdata_t match, void *aux) 641.1Skiyohara{ 651.1Skiyohara 661.1Skiyohara return 1; 671.1Skiyohara} 681.1Skiyohara 691.1Skiyohara/* ARGSUSED */ 701.1Skiyoharastatic void 711.1Skiyoharaclpsrtc_attach(device_t parent, device_t self, void *aux) 721.1Skiyohara{ 731.1Skiyohara struct clpsrtc_softc *sc = device_private(self); 741.1Skiyohara struct clpssoc_attach_args *aa = aux; 751.1Skiyohara 761.1Skiyohara aprint_naive("\n"); 771.1Skiyohara aprint_normal("\n"); 781.1Skiyohara 791.1Skiyohara sc->sc_dev = self; 801.1Skiyohara sc->sc_iot = aa->aa_iot; 811.1Skiyohara sc->sc_ioh = *aa->aa_ioh; 821.1Skiyohara 831.1Skiyohara /* XXXX: reset to compare registers */ 841.1Skiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, PS711X_RTCMR, 0); 851.1Skiyohara 861.3Sthorpej sc->sc_todr.todr_dev = self; 871.1Skiyohara sc->sc_todr.todr_gettime = clpsrtc_todr_gettime; 881.1Skiyohara sc->sc_todr.todr_settime = clpsrtc_todr_settime; 891.1Skiyohara todr_attach(&sc->sc_todr); 901.1Skiyohara} 911.1Skiyohara 921.1Skiyoharastatic int 931.1Skiyoharaclpsrtc_todr_gettime(todr_chip_handle_t ch, struct timeval *tv) 941.1Skiyohara{ 951.3Sthorpej struct clpsrtc_softc *sc = device_private(ch->todr_dev); 961.1Skiyohara 971.1Skiyohara tv->tv_sec = bus_space_read_4(sc->sc_iot, sc->sc_ioh, PS711X_RTCDR); 981.1Skiyohara tv->tv_usec = 0; 991.1Skiyohara return 0; 1001.1Skiyohara} 1011.1Skiyohara 1021.1Skiyoharastatic int 1031.1Skiyoharaclpsrtc_todr_settime(todr_chip_handle_t ch, struct timeval *tv) 1041.1Skiyohara{ 1051.3Sthorpej struct clpsrtc_softc *sc = device_private(ch->todr_dev); 1061.1Skiyohara 1071.1Skiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, PS711X_RTCDR, tv->tv_sec); 1081.1Skiyohara return 0; 1091.1Skiyohara} 110