eprtc.c revision 1.5
11.5Sdyoung/* $NetBSD: eprtc.c,v 1.5 2011/07/01 19:31:17 dyoung Exp $ */ 21.1Shamajima 31.1Shamajima/* 41.1Shamajima * Copyright (c) 2005 HAMAJIMA Katsuomi. All rights reserved. 51.1Shamajima * 61.1Shamajima * Redistribution and use in source and binary forms, with or without 71.1Shamajima * modification, are permitted provided that the following conditions 81.1Shamajima * are met: 91.1Shamajima * 1. Redistributions of source code must retain the above copyright 101.1Shamajima * notice, this list of conditions and the following disclaimer. 111.1Shamajima * 2. Redistributions in binary form must reproduce the above copyright 121.1Shamajima * notice, this list of conditions and the following disclaimer in the 131.1Shamajima * documentation and/or other materials provided with the distribution. 141.1Shamajima * 151.1Shamajima * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 161.1Shamajima * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 171.1Shamajima * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 181.1Shamajima * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 191.1Shamajima * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 201.1Shamajima * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 211.1Shamajima * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 221.1Shamajima * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 231.1Shamajima * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 241.1Shamajima * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 251.1Shamajima * SUCH DAMAGE. 261.1Shamajima */ 271.1Shamajima 281.1Shamajima#include <sys/cdefs.h> 291.5Sdyoung__KERNEL_RCSID(0, "$NetBSD: eprtc.c,v 1.5 2011/07/01 19:31:17 dyoung Exp $"); 301.1Shamajima 311.1Shamajima#include <sys/param.h> 321.1Shamajima#include <sys/systm.h> 331.1Shamajima#include <sys/kernel.h> 341.1Shamajima#include <sys/device.h> 351.1Shamajima#include <dev/clock_subr.h> 361.5Sdyoung#include <sys/bus.h> 371.1Shamajima#include <arm/ep93xx/ep93xxvar.h> 381.1Shamajima#include <arm/ep93xx/epsocvar.h> 391.1Shamajima#include <arm/ep93xx/eprtcreg.h> 401.1Shamajima 411.1Shamajimastruct eprtc_softc { 421.1Shamajima struct device sc_dev; 431.1Shamajima bus_space_tag_t sc_iot; 441.1Shamajima bus_space_handle_t sc_ioh; 451.1Shamajima struct todr_chip_handle sc_todr; 461.1Shamajima}; 471.1Shamajima 481.1Shamajimastatic int eprtc_match(struct device *, struct cfdata *, void *); 491.1Shamajimastatic void eprtc_attach(struct device *, struct device *, void *); 501.1Shamajima 511.1ShamajimaCFATTACH_DECL(eprtc, sizeof(struct eprtc_softc), 521.1Shamajima eprtc_match, eprtc_attach, NULL, NULL); 531.1Shamajima 541.3Stsutsuistatic int eprtc_gettime(struct todr_chip_handle *, struct timeval *); 551.3Stsutsuistatic int eprtc_settime(struct todr_chip_handle *, struct timeval *); 561.1Shamajima 571.1Shamajimastatic int 581.1Shamajimaeprtc_match(struct device *parent, struct cfdata *match, void *aux) 591.1Shamajima{ 601.1Shamajima return 1; 611.1Shamajima} 621.1Shamajima 631.1Shamajimastatic void 641.1Shamajimaeprtc_attach(struct device *parent, struct device *self, void *aux) 651.1Shamajima{ 661.1Shamajima struct eprtc_softc *sc = (struct eprtc_softc*)self; 671.1Shamajima struct epsoc_attach_args *sa = aux; 681.1Shamajima 691.1Shamajima printf("\n"); 701.1Shamajima sc->sc_iot = sa->sa_iot; 711.1Shamajima 721.1Shamajima if (bus_space_map(sa->sa_iot, sa->sa_addr, 731.1Shamajima sa->sa_size, 0, &sc->sc_ioh)){ 741.1Shamajima printf("%s: Cannot map registers", self->dv_xname); 751.1Shamajima return; 761.1Shamajima } 771.1Shamajima 781.1Shamajima sc->sc_todr.cookie = sc; 791.1Shamajima sc->sc_todr.todr_gettime = eprtc_gettime; 801.1Shamajima sc->sc_todr.todr_settime = eprtc_settime; 811.1Shamajima sc->sc_todr.todr_setwen = NULL; 821.1Shamajima todr_attach(&sc->sc_todr); 831.1Shamajima} 841.1Shamajima 851.1Shamajimastatic int 861.3Stsutsuieprtc_gettime(struct todr_chip_handle *ch, struct timeval *tv) 871.1Shamajima{ 881.4Smbalmer struct eprtc_softc *sc = ch->cookie; 891.1Shamajima 901.1Shamajima tv->tv_sec = bus_space_read_4(sc->sc_iot, sc->sc_ioh, EP93XX_RTC_Data); 911.1Shamajima tv->tv_usec = 0; 921.1Shamajima return 0; 931.1Shamajima} 941.1Shamajima 951.1Shamajimastatic int 961.3Stsutsuieprtc_settime(struct todr_chip_handle *ch, struct timeval *tv) 971.1Shamajima{ 981.4Smbalmer struct eprtc_softc *sc = ch->cookie; 991.1Shamajima 1001.1Shamajima bus_space_write_4(sc->sc_iot, sc->sc_ioh, EP93XX_RTC_Load, tv->tv_sec); 1011.1Shamajima return 0; 1021.1Shamajima} 103