eprtc.c revision 1.6
11.6Schs/* $NetBSD: eprtc.c,v 1.6 2012/10/27 17:17:37 chs 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.6Schs__KERNEL_RCSID(0, "$NetBSD: eprtc.c,v 1.6 2012/10/27 17:17:37 chs 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 bus_space_tag_t sc_iot; 431.1Shamajima bus_space_handle_t sc_ioh; 441.1Shamajima struct todr_chip_handle sc_todr; 451.1Shamajima}; 461.1Shamajima 471.6Schsstatic int eprtc_match(device_t, cfdata_t, void *); 481.6Schsstatic void eprtc_attach(device_t, device_t, void *); 491.1Shamajima 501.6SchsCFATTACH_DECL_NEW(eprtc, sizeof(struct eprtc_softc), 511.1Shamajima eprtc_match, eprtc_attach, NULL, NULL); 521.1Shamajima 531.3Stsutsuistatic int eprtc_gettime(struct todr_chip_handle *, struct timeval *); 541.3Stsutsuistatic int eprtc_settime(struct todr_chip_handle *, struct timeval *); 551.1Shamajima 561.1Shamajimastatic int 571.6Schseprtc_match(device_t parent, cfdata_t match, void *aux) 581.1Shamajima{ 591.1Shamajima return 1; 601.1Shamajima} 611.1Shamajima 621.1Shamajimastatic void 631.6Schseprtc_attach(device_t parent, device_t self, void *aux) 641.1Shamajima{ 651.6Schs struct eprtc_softc *sc = device_private(self); 661.1Shamajima struct epsoc_attach_args *sa = aux; 671.1Shamajima 681.1Shamajima printf("\n"); 691.1Shamajima sc->sc_iot = sa->sa_iot; 701.1Shamajima 711.1Shamajima if (bus_space_map(sa->sa_iot, sa->sa_addr, 721.6Schs sa->sa_size, 0, &sc->sc_ioh)) { 731.6Schs printf("%s: Cannot map registers", device_xname(self)); 741.1Shamajima return; 751.1Shamajima } 761.1Shamajima 771.1Shamajima sc->sc_todr.cookie = sc; 781.1Shamajima sc->sc_todr.todr_gettime = eprtc_gettime; 791.1Shamajima sc->sc_todr.todr_settime = eprtc_settime; 801.1Shamajima sc->sc_todr.todr_setwen = NULL; 811.1Shamajima todr_attach(&sc->sc_todr); 821.1Shamajima} 831.1Shamajima 841.1Shamajimastatic int 851.3Stsutsuieprtc_gettime(struct todr_chip_handle *ch, struct timeval *tv) 861.1Shamajima{ 871.4Smbalmer struct eprtc_softc *sc = ch->cookie; 881.1Shamajima 891.1Shamajima tv->tv_sec = bus_space_read_4(sc->sc_iot, sc->sc_ioh, EP93XX_RTC_Data); 901.1Shamajima tv->tv_usec = 0; 911.1Shamajima return 0; 921.1Shamajima} 931.1Shamajima 941.1Shamajimastatic int 951.3Stsutsuieprtc_settime(struct todr_chip_handle *ch, struct timeval *tv) 961.1Shamajima{ 971.4Smbalmer struct eprtc_softc *sc = ch->cookie; 981.1Shamajima 991.1Shamajima bus_space_write_4(sc->sc_iot, sc->sc_ioh, EP93XX_RTC_Load, tv->tv_sec); 1001.1Shamajima return 0; 1011.1Shamajima} 102