Home | History | Annotate | Line # | Download | only in imx
      1 /*	$NetBSD: imx51_clock.c,v 1.5 2014/07/25 07:49:56 hkenken 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.5 2014/07/25 07:49:56 hkenken Exp $");
     29 
     30 #include "opt_imx.h"
     31 #include "opt_imx51clk.h"
     32 
     33 #include <sys/param.h>
     34 #include <sys/systm.h>
     35 #include <sys/kernel.h>
     36 #include <sys/evcnt.h>
     37 #include <sys/atomic.h>
     38 #include <sys/time.h>
     39 #include <sys/timetc.h>
     40 
     41 #include <sys/types.h>
     42 #include <sys/device.h>
     43 
     44 #include <dev/clock_subr.h>
     45 
     46 #include <machine/intr.h>
     47 #include <sys/bus.h>
     48 
     49 #include <arm/cpufunc.h>
     50 
     51 #include <arm/imx/imx51reg.h>
     52 #include <arm/imx/imx51var.h>
     53 #include <arm/imx/imxepitreg.h>
     54 #include <arm/imx/imx51_ccmvar.h>
     55 #include <arm/imx/imxclockvar.h>
     56 
     57 #include "imxccm.h"	/* if CCM driver is configured into the kernel */
     58 
     59 
     60 
     61 static int imxclock_match(device_t, struct cfdata *, void *);
     62 static void imxclock_attach(device_t, device_t, void *);
     63 
     64 struct imxclock_softc *epit1_sc = NULL;
     65 struct imxclock_softc *epit2_sc = NULL;
     66 
     67 CFATTACH_DECL_NEW(imxclock, sizeof(struct imxclock_softc),
     68     imxclock_match, imxclock_attach, NULL, NULL);
     69 
     70 static int
     71 imxclock_match(device_t parent, struct cfdata *match, void *aux)
     72 {
     73 	struct axi_attach_args *aa = aux;
     74 
     75 	if ( (aa->aa_addr != EPIT1_BASE) &&
     76 	     (aa->aa_addr != EPIT2_BASE) ) {
     77 		return 0;
     78 	}
     79 
     80 	return 2;
     81 }
     82 
     83 static void
     84 imxclock_attach(device_t parent, device_t self, void *aux)
     85 {
     86 	struct imxclock_softc *sc = device_private(self);
     87 	struct axi_attach_args *aa = aux;
     88 
     89 	aprint_normal("\n");
     90 
     91 	sc->sc_dev = self;
     92 	sc->sc_iot = aa->aa_iot;
     93 	sc->sc_intr = aa->aa_irq;
     94 
     95 	switch ( aa->aa_addr ) {
     96 	case EPIT1_BASE:
     97 		epit1_sc = sc;
     98 		break;
     99 	case EPIT2_BASE:
    100 		epit2_sc = sc;
    101 		break;
    102 	default:
    103 		panic("%s: invalid address %p", device_xname(self), (void *)aa->aa_addr);
    104 		break;
    105 	}
    106 
    107 	if (bus_space_map(aa->aa_iot, aa->aa_addr, aa->aa_size, 0, &sc->sc_ioh))
    108 		panic("%s: Cannot map registers", device_xname(self));
    109 
    110 	sc->sc_clksrc = EPITCR_CLKSRC_IPG;
    111 }
    112 
    113 int
    114 imxclock_get_timerfreq(struct imxclock_softc *sc)
    115 {
    116 	unsigned int ipg_freq;
    117 #if NIMXCCM > 0
    118 	ipg_freq = imx51_get_clock(IMX51CLK_IPG_CLK_ROOT);
    119 #else
    120 #ifndef	IMX51_IPGCLK_FREQ
    121 #error	IMX51_IPGCLK_FREQ need to be defined.
    122 #endif
    123 	ipg_freq = IMX51_IPGCLK_FREQ;
    124 #endif
    125 
    126 	return ipg_freq;
    127 }
    128 
    129