eprtc.c revision 1.1
11.1Shamajima/* $NetBSD: eprtc.c,v 1.1 2005/11/12 05:33:23 hamajima 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.1Shamajima__KERNEL_RCSID(0, "$NetBSD: eprtc.c,v 1.1 2005/11/12 05:33:23 hamajima 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.1Shamajima#include <machine/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.1Shamajimastatic int eprtc_gettime(struct todr_chip_handle *, 551.1Shamajima volatile struct timeval *); 561.1Shamajimastatic int eprtc_settime(struct todr_chip_handle *, 571.1Shamajima volatile struct timeval *); 581.1Shamajimastatic int eprtc_getcal(struct todr_chip_handle *, int *); 591.1Shamajimastatic int eprtc_setcal(struct todr_chip_handle *, int); 601.1Shamajima 611.1Shamajimastatic int 621.1Shamajimaeprtc_match(struct device *parent, struct cfdata *match, void *aux) 631.1Shamajima{ 641.1Shamajima return 1; 651.1Shamajima} 661.1Shamajima 671.1Shamajimastatic void 681.1Shamajimaeprtc_attach(struct device *parent, struct device *self, void *aux) 691.1Shamajima{ 701.1Shamajima struct eprtc_softc *sc = (struct eprtc_softc*)self; 711.1Shamajima struct epsoc_attach_args *sa = aux; 721.1Shamajima 731.1Shamajima printf("\n"); 741.1Shamajima sc->sc_iot = sa->sa_iot; 751.1Shamajima 761.1Shamajima if (bus_space_map(sa->sa_iot, sa->sa_addr, 771.1Shamajima sa->sa_size, 0, &sc->sc_ioh)){ 781.1Shamajima printf("%s: Cannot map registers", self->dv_xname); 791.1Shamajima return; 801.1Shamajima } 811.1Shamajima 821.1Shamajima sc->sc_todr.cookie = sc; 831.1Shamajima sc->sc_todr.todr_gettime = eprtc_gettime; 841.1Shamajima sc->sc_todr.todr_settime = eprtc_settime; 851.1Shamajima sc->sc_todr.todr_getcal = eprtc_getcal; 861.1Shamajima sc->sc_todr.todr_setcal = eprtc_setcal; 871.1Shamajima sc->sc_todr.todr_setwen = NULL; 881.1Shamajima todr_attach(&sc->sc_todr); 891.1Shamajima} 901.1Shamajima 911.1Shamajimastatic int 921.1Shamajimaeprtc_gettime(struct todr_chip_handle *ch, volatile struct timeval *tv) 931.1Shamajima{ 941.1Shamajima struct eprtc_softc *sc = ch->cookie;; 951.1Shamajima 961.1Shamajima tv->tv_sec = bus_space_read_4(sc->sc_iot, sc->sc_ioh, EP93XX_RTC_Data); 971.1Shamajima tv->tv_usec = 0; 981.1Shamajima return 0; 991.1Shamajima} 1001.1Shamajima 1011.1Shamajimastatic int 1021.1Shamajimaeprtc_settime(struct todr_chip_handle *ch, volatile struct timeval *tv) 1031.1Shamajima{ 1041.1Shamajima struct eprtc_softc *sc = ch->cookie;; 1051.1Shamajima 1061.1Shamajima bus_space_write_4(sc->sc_iot, sc->sc_ioh, EP93XX_RTC_Load, tv->tv_sec); 1071.1Shamajima return 0; 1081.1Shamajima} 1091.1Shamajima 1101.1Shamajimastatic int 1111.1Shamajimaeprtc_setcal(struct todr_chip_handle *ch, int cal) 1121.1Shamajima{ 1131.1Shamajima return (EOPNOTSUPP); 1141.1Shamajima} 1151.1Shamajima 1161.1Shamajimastatic int 1171.1Shamajimaeprtc_getcal(struct todr_chip_handle *ch, int *cal) 1181.1Shamajima{ 1191.1Shamajima return (EOPNOTSUPP); 1201.1Shamajima} 121