#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: clpsrtc.c,v 1.3 2025/09/07 21:45:11 thorpej Exp $");
#include <sys/param.h>
#include <sys/bus.h>
#include <sys/device.h>
#include <sys/errno.h>
#include <dev/clock_subr.h>
#include <arm/clps711x/clps711xreg.h>
#include <arm/clps711x/clpssocvar.h>
#include "locators.h"
struct clpsrtc_softc {
device_t sc_dev;
bus_space_tag_t sc_iot;
bus_space_handle_t sc_ioh;
struct todr_chip_handle sc_todr;
};
static int clpsrtc_match(device_t, cfdata_t, void *);
static void clpsrtc_attach(device_t, device_t, void *);
static int clpsrtc_todr_gettime(todr_chip_handle_t, struct timeval *);
static int clpsrtc_todr_settime(todr_chip_handle_t, struct timeval *);
CFATTACH_DECL_NEW(clpsrtc, sizeof(struct clpsrtc_softc),
clpsrtc_match, clpsrtc_attach, NULL, NULL);
static int
clpsrtc_match(device_t parent, cfdata_t match, void *aux)
{
return 1;
}
static void
clpsrtc_attach(device_t parent, device_t self, void *aux)
{
struct clpsrtc_softc *sc = device_private(self);
struct clpssoc_attach_args *aa = aux;
aprint_naive("\n");
aprint_normal("\n");
sc->sc_dev = self;
sc->sc_iot = aa->aa_iot;
sc->sc_ioh = *aa->aa_ioh;
bus_space_write_4(sc->sc_iot, sc->sc_ioh, PS711X_RTCMR, 0);
sc->sc_todr.todr_dev = self;
sc->sc_todr.todr_gettime = clpsrtc_todr_gettime;
sc->sc_todr.todr_settime = clpsrtc_todr_settime;
todr_attach(&sc->sc_todr);
}
static int
clpsrtc_todr_gettime(todr_chip_handle_t ch, struct timeval *tv)
{
struct clpsrtc_softc *sc = device_private(ch->todr_dev);
tv->tv_sec = bus_space_read_4(sc->sc_iot, sc->sc_ioh, PS711X_RTCDR);
tv->tv_usec = 0;
return 0;
}
static int
clpsrtc_todr_settime(todr_chip_handle_t ch, struct timeval *tv)
{
struct clpsrtc_softc *sc = device_private(ch->todr_dev);
bus_space_write_4(sc->sc_iot, sc->sc_ioh, PS711X_RTCDR, tv->tv_sec);
return 0;
}