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