Home | History | Annotate | Line # | Download | only in imx
imx31_clock.c revision 1.3.2.2
      1  1.3.2.2    yamt /*	$NetBSD: imx31_clock.c,v 1.3.2.2 2012/10/30 17:19:03 yamt Exp $ */
      2      1.1     bsh /*
      3      1.1     bsh  * Copyright (c) 2009,2010  Genetec corp.  All rights reserved.
      4      1.1     bsh  * Written by Hashimoto Kenichi for Genetec corp.
      5      1.1     bsh  *
      6      1.1     bsh  * Redistribution and use in source and binary forms, with or without
      7      1.1     bsh  * modification, are permitted provided that the following conditions
      8      1.1     bsh  * are met:
      9      1.1     bsh  * 1. Redistributions of source code must retain the above copyright
     10      1.1     bsh  *    notice, this list of conditions and the following disclaimer.
     11      1.1     bsh  * 2. Redistributions in binary form must reproduce the above copyright
     12      1.1     bsh  *    notice, this list of conditions and the following disclaimer in the
     13      1.1     bsh  *    documentation and/or other materials provided with the distribution.
     14      1.1     bsh  *
     15      1.1     bsh  * THIS SOFTWARE IS PROVIDED BY GENETEC CORP. ``AS IS'' AND
     16      1.1     bsh  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     17      1.1     bsh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     18      1.1     bsh  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORP.
     19      1.1     bsh  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     20      1.1     bsh  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     21      1.1     bsh  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     22      1.1     bsh  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     23      1.1     bsh  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     24      1.1     bsh  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25      1.1     bsh  * POSSIBILITY OF SUCH DAMAGE.
     26      1.1     bsh  */
     27      1.1     bsh 
     28      1.1     bsh #include <sys/param.h>
     29      1.1     bsh #include <sys/systm.h>
     30      1.1     bsh #include <sys/kernel.h>
     31      1.1     bsh #include <sys/evcnt.h>
     32      1.1     bsh #include <sys/atomic.h>
     33      1.1     bsh #include <sys/time.h>
     34      1.1     bsh #include <sys/timetc.h>
     35      1.1     bsh 
     36      1.1     bsh #include <sys/types.h>
     37      1.1     bsh #include <sys/device.h>
     38      1.1     bsh 
     39      1.1     bsh #include <machine/intr.h>
     40      1.3  dyoung #include <sys/bus.h>
     41      1.1     bsh 
     42      1.1     bsh #include <arm/cpu.h>
     43      1.1     bsh #include <arm/armreg.h>
     44      1.1     bsh #include <arm/cpufunc.h>
     45      1.1     bsh 
     46      1.1     bsh #include <arm/imx/imx31reg.h>
     47      1.1     bsh #include <arm/imx/imx31var.h>
     48      1.2     bsh #if 0 /* notyet */
     49      1.1     bsh #include <arm/imx/imx31_ccmvar.h>
     50      1.2     bsh #endif
     51      1.1     bsh #include <arm/imx/imxclockvar.h>
     52      1.2     bsh #include <arm/imx/imxepitreg.h>
     53      1.2     bsh 
     54      1.2     bsh #include "imxccm.h"	/* if CCM driver is configured into the kernel */
     55      1.2     bsh #include "opt_imx31clk.h"
     56      1.1     bsh 
     57      1.1     bsh static int imxclock_match(device_t, struct cfdata *, void *);
     58      1.1     bsh static void imxclock_attach(device_t, device_t, void *);
     59      1.1     bsh 
     60      1.1     bsh struct imxclock_softc *epit1_sc = NULL;
     61      1.1     bsh struct imxclock_softc *epit2_sc = NULL;
     62      1.1     bsh 
     63      1.1     bsh CFATTACH_DECL_NEW(imxclock, sizeof(struct imxclock_softc),
     64      1.1     bsh     imxclock_match, imxclock_attach, NULL, NULL);
     65      1.1     bsh 
     66      1.1     bsh static int
     67      1.1     bsh imxclock_match(device_t parent, struct cfdata *match, void *aux)
     68      1.1     bsh {
     69      1.1     bsh 	struct aips_attach_args *aipsa = aux;
     70      1.1     bsh 
     71      1.1     bsh 	if ( (aipsa->aipsa_addr != EPIT1_BASE) &&
     72      1.1     bsh 	     (aipsa->aipsa_addr != EPIT2_BASE) ) {
     73      1.1     bsh 		return 0;
     74      1.1     bsh 	}
     75      1.1     bsh 
     76      1.1     bsh 	return 2;
     77      1.1     bsh }
     78      1.1     bsh 
     79      1.1     bsh static void
     80      1.1     bsh imxclock_attach(device_t parent, device_t self, void *aux)
     81      1.1     bsh {
     82      1.1     bsh 	struct imxclock_softc *sc = device_private(self);
     83      1.1     bsh 	struct aips_attach_args *aipsa = aux;
     84      1.1     bsh 
     85      1.1     bsh 	aprint_normal("\n");
     86      1.1     bsh 
     87      1.1     bsh 	sc->sc_dev = self;
     88      1.1     bsh 	sc->sc_iot = aipsa->aipsa_memt;
     89      1.1     bsh 	sc->sc_intr = aipsa->aipsa_intr;
     90      1.1     bsh 
     91      1.1     bsh 	KASSERT((sc->sc_intr == IRQ_EPIT1) || (sc->sc_intr == IRQ_EPIT2));
     92      1.1     bsh 
     93      1.1     bsh 	switch ( aipsa->aipsa_addr ) {
     94      1.1     bsh 	case EPIT1_BASE:
     95      1.1     bsh 		epit1_sc = sc;
     96      1.1     bsh 		break;
     97      1.1     bsh 	case EPIT2_BASE:
     98      1.1     bsh 		epit2_sc = sc;
     99      1.1     bsh 		break;
    100      1.1     bsh 	default:
    101  1.3.2.2    yamt 		panic("%s: invalid address %p", device_xname(self), (void *)aipsa->aipsa_addr);
    102      1.1     bsh 		break;
    103      1.1     bsh 	}
    104      1.1     bsh 
    105      1.1     bsh 	if (bus_space_map(aipsa->aipsa_memt, aipsa->aipsa_addr,
    106      1.1     bsh 		aipsa->aipsa_size, 0, &sc->sc_ioh)) {
    107      1.1     bsh 		panic("%s: Cannot map registers", device_xname(self));
    108      1.1     bsh 	}
    109  1.3.2.1    yamt 
    110  1.3.2.1    yamt 	sc->sc_clksrc = EPITCR_CLKSRC_HIGH;
    111      1.1     bsh }
    112      1.1     bsh 
    113      1.1     bsh int
    114      1.1     bsh imxclock_get_timerfreq(struct imxclock_softc *sc)
    115      1.1     bsh {
    116      1.2     bsh #if NIMXCCM > 0
    117      1.1     bsh 	struct imx31_clocks clk;
    118      1.1     bsh 	imx31_get_clocks(&clk);
    119      1.1     bsh 
    120      1.1     bsh 	return clk.ipg_clk;
    121      1.2     bsh #else
    122      1.2     bsh #ifndef	IMX31_IPGCLK_FREQ
    123      1.2     bsh #error	IMX31_IPGCLK_FREQ need to be defined.
    124      1.2     bsh #endif
    125      1.2     bsh 	return IMX31_IPGCLK_FREQ;
    126      1.2     bsh 
    127      1.2     bsh #endif
    128      1.1     bsh }
    129      1.1     bsh 
    130      1.1     bsh 
    131