Home | History | Annotate | Line # | Download | only in ifpga
pl030_rtc.c revision 1.7.24.1
      1  1.7.24.1    bouyer /*	$NetBSD: pl030_rtc.c,v 1.7.24.1 2007/03/04 12:15:38 bouyer Exp $ */
      2       1.1  rearnsha 
      3       1.1  rearnsha /*
      4       1.1  rearnsha  * Copyright (c) 2001 ARM Ltd
      5       1.1  rearnsha  * All rights reserved.
      6       1.1  rearnsha  *
      7       1.1  rearnsha  * Redistribution and use in source and binary forms, with or without
      8       1.1  rearnsha  * modification, are permitted provided that the following conditions
      9       1.1  rearnsha  * are met:
     10       1.1  rearnsha  * 1. Redistributions of source code must retain the above copyright
     11       1.1  rearnsha  *    notice, this list of conditions and the following disclaimer.
     12       1.1  rearnsha  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1  rearnsha  *    notice, this list of conditions and the following disclaimer in the
     14       1.1  rearnsha  *    documentation and/or other materials provided with the distribution.
     15       1.1  rearnsha  * 3. The name of the company may not be used to endorse or promote
     16       1.1  rearnsha  *    products derived from this software without specific prior written
     17       1.1  rearnsha  *    permission.
     18       1.1  rearnsha  *
     19       1.1  rearnsha  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     20       1.1  rearnsha  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     21       1.1  rearnsha  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     22       1.1  rearnsha  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     23       1.1  rearnsha  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     24       1.1  rearnsha  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     25       1.1  rearnsha  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26       1.1  rearnsha  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27       1.1  rearnsha  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28       1.1  rearnsha  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29       1.1  rearnsha  * SUCH DAMAGE.
     30       1.1  rearnsha  */
     31       1.1  rearnsha 
     32       1.1  rearnsha /* Include header files */
     33       1.6     lukem 
     34       1.6     lukem #include <sys/cdefs.h>
     35  1.7.24.1    bouyer __KERNEL_RCSID(0, "$NetBSD: pl030_rtc.c,v 1.7.24.1 2007/03/04 12:15:38 bouyer Exp $");
     36       1.1  rearnsha 
     37       1.1  rearnsha #include <sys/types.h>
     38       1.1  rearnsha #include <sys/param.h>
     39       1.1  rearnsha #include <sys/systm.h>
     40       1.1  rearnsha #include <sys/kernel.h>
     41       1.1  rearnsha #include <sys/time.h>
     42       1.1  rearnsha #include <sys/device.h>
     43       1.1  rearnsha 
     44  1.7.24.1    bouyer #include <dev/clock_subr.h>
     45  1.7.24.1    bouyer 
     46       1.2   thorpej #include <arm/cpufunc.h>
     47       1.1  rearnsha #include <machine/intr.h>
     48       1.1  rearnsha #include <evbarm/ifpga/ifpgavar.h>
     49       1.1  rearnsha #include <evbarm/ifpga/ifpgamem.h>
     50       1.1  rearnsha #include <evbarm/ifpga/ifpgareg.h>
     51       1.1  rearnsha 
     52       1.1  rearnsha #define PL030_RTC_SIZE	0x14
     53       1.1  rearnsha 
     54       1.1  rearnsha struct plrtc_softc {
     55       1.1  rearnsha 	struct device		    sc_dev;
     56       1.1  rearnsha 	bus_space_tag_t		    sc_iot;
     57       1.1  rearnsha 	bus_space_handle_t	    sc_ioh;
     58  1.7.24.1    bouyer 	struct todr_chip_handle     sc_todr;
     59       1.1  rearnsha };
     60       1.1  rearnsha 
     61       1.1  rearnsha static int  plrtc_probe  (struct device *, struct cfdata *, void *);
     62       1.1  rearnsha static void plrtc_attach (struct device *, struct device *, void *);
     63       1.1  rearnsha 
     64       1.5   thorpej CFATTACH_DECL(plrtc, sizeof(struct plrtc_softc),
     65       1.5   thorpej     plrtc_probe, plrtc_attach, NULL, NULL);
     66       1.1  rearnsha 
     67  1.7.24.1    bouyer static int
     68  1.7.24.1    bouyer plrtc_gettime(todr_chip_handle_t todr, volatile struct timeval *tv)
     69  1.7.24.1    bouyer {
     70  1.7.24.1    bouyer 	struct plrtc_softc *sc;
     71  1.7.24.1    bouyer 
     72  1.7.24.1    bouyer  	sc = (struct plrtc_softc *)todr->cookie;
     73  1.7.24.1    bouyer 	tv->tv_sec = bus_space_read_4(sc->sc_iot, sc->sc_ioh, IFPGA_RTC_DR);
     74  1.7.24.1    bouyer 	/* initialize tv_usec? */
     75  1.7.24.1    bouyer 	return 0;
     76  1.7.24.1    bouyer }
     77  1.7.24.1    bouyer 
     78  1.7.24.1    bouyer static int
     79  1.7.24.1    bouyer plrtc_settime(todr_chip_handle_t todr, volatile struct timeval *tv)
     80  1.7.24.1    bouyer {
     81  1.7.24.1    bouyer 	struct plrtc_softc *sc;
     82       1.1  rearnsha 
     83  1.7.24.1    bouyer  	sc = (struct plrtc_softc *)todr->cookie;
     84  1.7.24.1    bouyer 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, IFPGA_RTC_LR, tv->tv_sec);
     85  1.7.24.1    bouyer 	return 0;
     86  1.7.24.1    bouyer }
     87       1.1  rearnsha 
     88       1.1  rearnsha static int
     89       1.1  rearnsha plrtc_probe(struct device *parent, struct cfdata *cf, void *aux)
     90       1.1  rearnsha {
     91       1.3   thorpej 	return 1;
     92       1.1  rearnsha }
     93       1.1  rearnsha 
     94       1.1  rearnsha static void
     95       1.1  rearnsha plrtc_attach(struct device *parent, struct device *self, void *aux)
     96       1.1  rearnsha {
     97       1.1  rearnsha 	struct ifpga_attach_args *ifa = aux;
     98       1.1  rearnsha 	struct plrtc_softc *sc = (struct plrtc_softc *)self;
     99       1.1  rearnsha 
    100       1.1  rearnsha 	sc->sc_iot = ifa->ifa_iot;
    101       1.1  rearnsha 	if (bus_space_map(ifa->ifa_iot, ifa->ifa_addr, PL030_RTC_SIZE, 0,
    102       1.1  rearnsha 	    &sc->sc_ioh)) {
    103       1.1  rearnsha 		printf("%s: unable to map device\n", sc->sc_dev.dv_xname);
    104       1.1  rearnsha 		return;
    105       1.1  rearnsha 	}
    106       1.1  rearnsha 
    107  1.7.24.1    bouyer 	memset(&sc->sc_todr, 0, sizeof(struct todr_chip_handle));
    108  1.7.24.1    bouyer 	sc->sc_todr.cookie = sc;
    109  1.7.24.1    bouyer 	sc->sc_todr.todr_gettime = plrtc_gettime;
    110  1.7.24.1    bouyer 	sc->sc_todr.todr_settime = plrtc_settime;
    111       1.1  rearnsha 
    112  1.7.24.1    bouyer 	todr_attach( &sc->sc_todr );
    113       1.1  rearnsha 
    114  1.7.24.1    bouyer 	printf("\n");
    115       1.1  rearnsha }
    116