3 * Ben Gray <ben.r.gray@gmail.com>.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Ben Gray.
17 * 4. The name of the company nor the name of the author may be used to
18 * endorse or promote products derived from this software without specific
19 * prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY BEN GRAY ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL BEN GRAY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
30 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 * Power, Reset and Clock Managment Module
36 * This is a very simple driver wrapper around the PRCM set of registers in
37 * the OMAP3 chip. It allows you to turn on and off things like the functional
38 * and interface clocks to the various on-chip modules.
41 #include <sys/cdefs.h>
42 __FBSDID("$FreeBSD$");
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/kernel.h>
47 #include <sys/module.h>
49 #include <sys/resource.h>
52 #include <sys/mutex.h>
54 #include <machine/bus.h>
55 #include <machine/cpu.h>
56 #include <machine/cpufunc.h>
57 #include <machine/frame.h>
58 #include <machine/resource.h>
59 #include <machine/intr.h>
61 #include <arm/ti/ti_prcm.h>
64 * ti_clk_devmap - Array of clock devices, should be defined one per SoC
66 * This array is typically defined in one of the targeted *_prcm_clk.c
67 * files and is specific to the given SoC platform. Each entry in the array
68 * corresponds to an individual clock device.
70 extern struct ti_clock_dev ti_clk_devmap[];
73 * ti_prcm_clk_dev - returns a pointer to the clock device with given id
74 * @clk: the ID of the clock device to get
76 * Simply iterates through the clk_devmap global array and returns a pointer
77 * to the clock device if found.
83 * The pointer to the clock device on success, on failure NULL is returned.
85 static struct ti_clock_dev *
86 ti_prcm_clk_dev(clk_ident_t clk)
88 struct ti_clock_dev *clk_dev;
90 /* Find the clock within the devmap - it's a bit inefficent having a for
91 * loop for this, but this function should only called when a driver is
92 * being activated so IMHO not a big issue.
94 clk_dev = &(ti_clk_devmap[0]);
95 while (clk_dev->id != INVALID_CLK_IDENT) {
96 if (clk_dev->id == clk) {
102 /* Sanity check we managed to find the clock */
103 printf("ti_prcm: Failed to find clock device (%d)\n", clk);
108 * ti_prcm_clk_valid - enables a clock for a particular module
109 * @clk: identifier for the module to enable, see ti_prcm.h for a list
110 * of possible modules.
111 * Example: OMAP3_MODULE_MMC1_ICLK or OMAP3_MODULE_GPTIMER10_FCLK.
113 * This function can enable either a functional or interface clock.
115 * The real work done to enable the clock is really done in the callback
116 * function associated with the clock, this function is simply a wrapper
120 * Internally locks the driver context.
123 * Returns 0 on success or positive error code on failure.
126 ti_prcm_clk_valid(clk_ident_t clk)
130 if (ti_prcm_clk_dev(clk) == NULL)
138 * ti_prcm_clk_enable - enables a clock for a particular module
139 * @clk: identifier for the module to enable, see ti_prcm.h for a list
140 * of possible modules.
141 * Example: OMAP3_MODULE_MMC1_ICLK or OMAP3_MODULE_GPTIMER10_FCLK.
143 * This function can enable either a functional or interface clock.
145 * The real work done to enable the clock is really done in the callback
146 * function associated with the clock, this function is simply a wrapper
150 * Internally locks the driver context.
153 * Returns 0 on success or positive error code on failure.
156 ti_prcm_clk_enable(clk_ident_t clk)
158 struct ti_clock_dev *clk_dev;
161 /* Find the clock within the devmap - it's a bit inefficent having a for
162 * loop for this, but this function should only called when a driver is
163 * being activated so IMHO not a big issue.
165 clk_dev = ti_prcm_clk_dev(clk);
167 /* Sanity check we managed to find the clock */
171 /* Activate the clock */
172 if (clk_dev->clk_activate)
173 ret = clk_dev->clk_activate(clk_dev);
182 * ti_prcm_clk_disable - disables a clock for a particular module
183 * @clk: identifier for the module to enable, see ti_prcm.h for a list
184 * of possible modules.
185 * Example: OMAP3_MODULE_MMC1_ICLK or OMAP3_MODULE_GPTIMER10_FCLK.
187 * This function can enable either a functional or interface clock.
189 * The real work done to enable the clock is really done in the callback
190 * function associated with the clock, this function is simply a wrapper
194 * Internally locks the driver context.
197 * Returns 0 on success or positive error code on failure.
200 ti_prcm_clk_disable(clk_ident_t clk)
202 struct ti_clock_dev *clk_dev;
205 /* Find the clock within the devmap - it's a bit inefficent having a for
206 * loop for this, but this function should only called when a driver is
207 * being activated so IMHO not a big issue.
209 clk_dev = ti_prcm_clk_dev(clk);
211 /* Sanity check we managed to find the clock */
215 /* Activate the clock */
216 if (clk_dev->clk_deactivate)
217 ret = clk_dev->clk_deactivate(clk_dev);
225 * ti_prcm_clk_set_source - sets the source
226 * @clk: identifier for the module to enable, see ti_prcm.h for a list
227 * of possible modules.
228 * Example: OMAP3_MODULE_MMC1_ICLK or OMAP3_MODULE_GPTIMER10_FCLK.
230 * This function can enable either a functional or interface clock.
232 * The real work done to enable the clock is really done in the callback
233 * function associated with the clock, this function is simply a wrapper
237 * Internally locks the driver context.
240 * Returns 0 on success or positive error code on failure.
243 ti_prcm_clk_set_source(clk_ident_t clk, clk_src_t clksrc)
245 struct ti_clock_dev *clk_dev;
248 /* Find the clock within the devmap - it's a bit inefficent having a for
249 * loop for this, but this function should only called when a driver is
250 * being activated so IMHO not a big issue.
252 clk_dev = ti_prcm_clk_dev(clk);
254 /* Sanity check we managed to find the clock */
258 /* Activate the clock */
259 if (clk_dev->clk_set_source)
260 ret = clk_dev->clk_set_source(clk_dev, clksrc);
269 * ti_prcm_clk_get_source_freq - gets the source clock frequency
270 * @clk: identifier for the module to enable, see ti_prcm.h for a list
271 * of possible modules.
272 * @freq: pointer to an integer that upon return will contain the src freq
274 * This function returns the frequency of the source clock.
276 * The real work done to enable the clock is really done in the callback
277 * function associated with the clock, this function is simply a wrapper
281 * Internally locks the driver context.
284 * Returns 0 on success or positive error code on failure.
287 ti_prcm_clk_get_source_freq(clk_ident_t clk, unsigned int *freq)
289 struct ti_clock_dev *clk_dev;
292 /* Find the clock within the devmap - it's a bit inefficent having a for
293 * loop for this, but this function should only called when a driver is
294 * being activated so IMHO not a big issue.
296 clk_dev = ti_prcm_clk_dev(clk);
298 /* Sanity check we managed to find the clock */
302 /* Get the source frequency of the clock */
303 if (clk_dev->clk_get_source_freq)
304 ret = clk_dev->clk_get_source_freq(clk_dev, freq);