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