6 * Clocks data comes in part from arch/arm/mach-omap1/clock.h in Linux.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31 #define ALWAYS_ENABLED (1 << 0)
32 #define CLOCK_IN_OMAP310 (1 << 10)
33 #define CLOCK_IN_OMAP730 (1 << 11)
34 #define CLOCK_IN_OMAP1510 (1 << 12)
35 #define CLOCK_IN_OMAP16XX (1 << 13)
39 int running; /* Is currently ticking */
40 int enabled; /* Is enabled, regardless of its input clk */
41 unsigned long rate; /* Current rate (if .running) */
42 unsigned int divisor; /* Rate relative to input (if .enabled) */
43 unsigned int multiplier; /* Rate relative to input (if .enabled) */
44 qemu_irq users[16]; /* Who to notify on change */
45 int usecount; /* Automatically idle when unused */
48 static struct clk xtal_osc12m = {
49 .name = "xtal_osc_12m",
51 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310,
54 static struct clk xtal_osc32k = {
55 .name = "xtal_osc_32k",
57 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310,
60 static struct clk ck_ref = {
63 .parent = &xtal_osc12m,
64 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310 |
68 /* If a dpll is disabled it becomes a bypass, child clocks don't stop */
69 static struct clk dpll1 = {
72 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310 |
76 static struct clk dpll2 = {
79 .flags = CLOCK_IN_OMAP310 | ALWAYS_ENABLED,
82 static struct clk dpll3 = {
85 .flags = CLOCK_IN_OMAP310 | ALWAYS_ENABLED,
88 static struct clk dpll4 = {
92 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310,
95 static struct clk apll = {
100 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310,
103 static struct clk ck_48m = {
105 .parent = &dpll4, /* either dpll4 or apll */
106 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310,
109 static struct clk ck_dpll1out = {
110 .name = "ck_dpll1out",
112 .flags = CLOCK_IN_OMAP16XX,
115 static struct clk sossi_ck = {
117 .parent = &ck_dpll1out,
118 .flags = CLOCK_IN_OMAP16XX,
121 static struct clk clkm1 = {
125 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310 |
129 static struct clk clkm2 = {
133 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310 |
137 static struct clk clkm3 = {
140 .parent = &dpll1, /* either dpll1 or ck_ref */
141 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310 |
145 static struct clk arm_ck = {
149 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310 |
153 static struct clk armper_ck = {
155 .alias = "mpuper_ck",
157 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310,
160 static struct clk arm_gpio_ck = {
161 .name = "arm_gpio_ck",
162 .alias = "mpu_gpio_ck",
165 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP310,
168 static struct clk armxor_ck = {
170 .alias = "mpuxor_ck",
172 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310,
175 static struct clk armtim_ck = {
177 .alias = "mputim_ck",
178 .parent = &ck_ref, /* either CLKIN or DPLL1 */
179 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310,
182 static struct clk armwdt_ck = {
187 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310 |
191 static struct clk arminth_ck16xx = {
192 .name = "arminth_ck",
194 .flags = CLOCK_IN_OMAP16XX | ALWAYS_ENABLED,
195 /* Note: On 16xx the frequency can be divided by 2 by programming
196 * ARM_CKCTL:ARM_INTHCK_SEL(14) to 1
198 * 1510 version is in TC clocks.
202 static struct clk dsp_ck = {
205 .flags = CLOCK_IN_OMAP310 | CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX,
208 static struct clk dspmmu_ck = {
211 .flags = CLOCK_IN_OMAP310 | CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX |
215 static struct clk dspper_ck = {
218 .flags = CLOCK_IN_OMAP310 | CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX,
221 static struct clk dspxor_ck = {
224 .flags = CLOCK_IN_OMAP310 | CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX,
227 static struct clk dsptim_ck = {
230 .flags = CLOCK_IN_OMAP310 | CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX,
233 static struct clk tc_ck = {
236 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX |
237 CLOCK_IN_OMAP730 | CLOCK_IN_OMAP310 |
241 static struct clk arminth_ck15xx = {
242 .name = "arminth_ck",
244 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP310 | ALWAYS_ENABLED,
245 /* Note: On 1510 the frequency follows TC_CK
247 * 16xx version is in MPU clocks.
251 static struct clk tipb_ck = {
252 /* No-idle controlled by "tc_ck" */
255 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP310 | ALWAYS_ENABLED,
258 static struct clk l3_ocpi_ck = {
259 /* No-idle controlled by "tc_ck" */
260 .name = "l3_ocpi_ck",
262 .flags = CLOCK_IN_OMAP16XX,
265 static struct clk tc1_ck = {
268 .flags = CLOCK_IN_OMAP16XX,
271 static struct clk tc2_ck = {
274 .flags = CLOCK_IN_OMAP16XX,
277 static struct clk dma_ck = {
278 /* No-idle controlled by "tc_ck" */
281 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310 |
285 static struct clk dma_lcdfree_ck = {
286 .name = "dma_lcdfree_ck",
288 .flags = CLOCK_IN_OMAP16XX | ALWAYS_ENABLED,
291 static struct clk api_ck = {
295 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310,
298 static struct clk lb_ck = {
301 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP310,
304 static struct clk lbfree_ck = {
307 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP310,
310 static struct clk rhea1_ck = {
313 .flags = CLOCK_IN_OMAP16XX | ALWAYS_ENABLED,
316 static struct clk rhea2_ck = {
319 .flags = CLOCK_IN_OMAP16XX | ALWAYS_ENABLED,
322 static struct clk lcd_ck_16xx = {
325 .flags = CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP730,
328 static struct clk lcd_ck_1510 = {
331 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP310,
334 static struct clk uart1_1510 = {
336 /* Direct from ULPD, no real parent */
337 .parent = &armper_ck, /* either armper_ck or dpll4 */
339 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP310 | ALWAYS_ENABLED,
342 static struct clk uart1_16xx = {
344 /* Direct from ULPD, no real parent */
345 .parent = &armper_ck,
347 .flags = CLOCK_IN_OMAP16XX,
350 static struct clk uart2_ck = {
352 /* Direct from ULPD, no real parent */
353 .parent = &armper_ck, /* either armper_ck or dpll4 */
355 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310 |
359 static struct clk uart3_1510 = {
361 /* Direct from ULPD, no real parent */
362 .parent = &armper_ck,/* either armper_ck or dpll4 */
364 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP310 | ALWAYS_ENABLED,
367 static struct clk uart3_16xx = {
369 /* Direct from ULPD, no real parent */
370 .parent = &armper_ck,
372 .flags = CLOCK_IN_OMAP16XX,
375 static struct clk usb_clk0 = { /* 6 MHz output on W4_USB_CLK0 */
378 /* Direct from ULPD, no parent */
380 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310,
383 static struct clk usb_hhc_ck1510 = {
384 .name = "usb_hhc_ck",
385 /* Direct from ULPD, no parent */
386 .rate = 48000000, /* Actually 2 clocks, 12MHz and 48MHz */
387 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP310,
390 static struct clk usb_hhc_ck16xx = {
391 .name = "usb_hhc_ck",
392 /* Direct from ULPD, no parent */
394 /* OTG_SYSCON_2.OTG_PADEN == 0 (not 1510-compatible) */
395 .flags = CLOCK_IN_OMAP16XX,
398 static struct clk usb_dc_ck = {
400 /* Direct from ULPD, no parent */
402 .flags = CLOCK_IN_OMAP16XX,
405 static struct clk mclk_1510 = {
407 /* Direct from ULPD, no parent. May be enabled by ext hardware. */
409 .flags = CLOCK_IN_OMAP1510,
412 static struct clk bclk_310 = {
413 .name = "bt_mclk_out", /* Alias midi_mclk_out? */
414 .parent = &armper_ck,
415 .flags = CLOCK_IN_OMAP310,
418 static struct clk mclk_310 = {
419 .name = "com_mclk_out",
420 .parent = &armper_ck,
421 .flags = CLOCK_IN_OMAP310,
424 static struct clk mclk_16xx = {
426 /* Direct from ULPD, no parent. May be enabled by ext hardware. */
427 .flags = CLOCK_IN_OMAP16XX,
430 static struct clk bclk_1510 = {
432 /* Direct from ULPD, no parent. May be enabled by ext hardware. */
434 .flags = CLOCK_IN_OMAP1510,
437 static struct clk bclk_16xx = {
439 /* Direct from ULPD, no parent. May be enabled by ext hardware. */
440 .flags = CLOCK_IN_OMAP16XX,
443 static struct clk mmc1_ck = {
446 /* Functional clock is direct from ULPD, interface clock is ARMPER */
447 .parent = &armper_ck, /* either armper_ck or dpll4 */
449 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310,
452 static struct clk mmc2_ck = {
455 /* Functional clock is direct from ULPD, interface clock is ARMPER */
456 .parent = &armper_ck,
458 .flags = CLOCK_IN_OMAP16XX,
461 static struct clk cam_mclk = {
463 .flags = CLOCK_IN_OMAP310 | CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX,
467 static struct clk cam_exclk = {
469 .flags = CLOCK_IN_OMAP310 | CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX,
470 /* Either 12M from cam.mclk or 48M from dpll4 */
474 static struct clk cam_lclk = {
476 .flags = CLOCK_IN_OMAP310 | CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX,
479 static struct clk i2c_fck = {
482 .flags = CLOCK_IN_OMAP310 | CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX |
484 .parent = &armxor_ck,
487 static struct clk i2c_ick = {
490 .flags = CLOCK_IN_OMAP16XX | ALWAYS_ENABLED,
491 .parent = &armper_ck,
494 static struct clk clk32k = {
496 .flags = CLOCK_IN_OMAP310 | CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX |
498 .parent = &xtal_osc32k,
501 static struct clk *onchip_clks[] = {
502 /* non-ULPD clocks */
522 &arminth_ck15xx, &arminth_ck16xx,
553 &usb_hhc_ck1510, &usb_hhc_ck16xx,
555 &mclk_1510, &mclk_16xx, &mclk_310,
556 &bclk_1510, &bclk_16xx, &bclk_310,
569 void omap_clk_adduser(struct clk *clk, qemu_irq user)
573 for (i = clk->users; *i; i ++);
577 /* If a clock is allowed to idle, it is disabled automatically when
578 * all of clock domains using it are disabled. */
579 int omap_clk_is_idle(struct clk *clk)
583 if (!clk->enabled && (!clk->usecount || !(clk->flags && ALWAYS_ENABLED)))
588 for (chld = clk->child1; chld; chld = chld->sibling)
589 if (!omap_clk_is_idle(chld))
594 struct clk *omap_findclk(struct omap_mpu_state_s *mpu, const char *name)
598 for (i = mpu->clks; i->name; i ++)
599 if (!strcmp(i->name, name) || (i->alias && !strcmp(i->alias, name)))
601 cpu_abort(mpu->env, "%s: %s not found\n", __FUNCTION__, name);
604 void omap_clk_get(struct clk *clk)
609 void omap_clk_put(struct clk *clk)
611 if (!(clk->usecount --))
612 cpu_abort(cpu_single_env, "%s: %s is not in use\n",
613 __FUNCTION__, clk->name);
616 static void omap_clk_update(struct clk *clk)
623 parent = clk->parent->running;
627 running = parent && (clk->enabled ||
628 ((clk->flags & ALWAYS_ENABLED) && clk->usecount));
629 if (clk->running != running) {
630 clk->running = running;
631 for (user = clk->users; *user; user ++)
632 qemu_set_irq(*user, running);
633 for (i = clk->child1; i; i = i->sibling)
638 static void omap_clk_rate_update_full(struct clk *clk, unsigned long int rate,
639 unsigned long int div, unsigned long int mult)
644 clk->rate = muldiv64(rate, mult, div);
646 for (user = clk->users; *user; user ++)
647 qemu_irq_raise(*user);
648 for (i = clk->child1; i; i = i->sibling)
649 omap_clk_rate_update_full(i, rate,
650 div * i->divisor, mult * i->multiplier);
653 static void omap_clk_rate_update(struct clk *clk)
656 unsigned long int div, mult = div = 1;
658 for (i = clk; i->parent; i = i->parent) {
660 mult *= i->multiplier;
663 omap_clk_rate_update_full(clk, i->rate, div, mult);
666 void omap_clk_reparent(struct clk *clk, struct clk *parent)
671 for (p = &clk->parent->child1; *p != clk; p = &(*p)->sibling);
675 clk->parent = parent;
677 clk->sibling = parent->child1;
678 parent->child1 = clk;
679 omap_clk_update(clk);
680 omap_clk_rate_update(clk);
685 void omap_clk_onoff(struct clk *clk, int on)
688 omap_clk_update(clk);
691 void omap_clk_canidle(struct clk *clk, int can)
699 void omap_clk_setrate(struct clk *clk, int divide, int multiply)
701 clk->divisor = divide;
702 clk->multiplier = multiply;
703 omap_clk_rate_update(clk);
706 int64_t omap_clk_getrate(omap_clk clk)
711 void omap_clk_init(struct omap_mpu_state_s *mpu)
713 struct clk **i, *j, *k;
717 if (cpu_is_omap310(mpu))
718 flag = CLOCK_IN_OMAP310;
719 else if (cpu_is_omap1510(mpu))
720 flag = CLOCK_IN_OMAP1510;
724 for (i = onchip_clks, count = 0; *i; i ++)
725 if ((*i)->flags & flag)
727 mpu->clks = (struct clk *) qemu_mallocz(sizeof(struct clk) * (count + 1));
728 for (i = onchip_clks, j = mpu->clks; *i; i ++)
729 if ((*i)->flags & flag) {
730 memcpy(j, *i, sizeof(struct clk));
731 for (k = mpu->clks; k < j; k ++)
732 if (j->parent && !strcmp(j->parent->name, k->name)) {
734 j->sibling = k->child1;
736 } else if (k->parent && !strcmp(k->parent->name, j->name)) {
738 k->sibling = j->child1;
741 j->divisor = j->divisor ?: 1;
742 j->multiplier = j->multiplier ?: 1;