4 * Copyright (C) 2006-2008 Andrzej Zaborowski <balrog@zabor.org>
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,
32 #define ALWAYS_ENABLED (1 << 0)
33 #define CLOCK_IN_OMAP310 (1 << 10)
34 #define CLOCK_IN_OMAP730 (1 << 11)
35 #define CLOCK_IN_OMAP1510 (1 << 12)
36 #define CLOCK_IN_OMAP16XX (1 << 13)
37 #define CLOCK_IN_OMAP242X (1 << 14)
38 #define CLOCK_IN_OMAP243X (1 << 15)
39 #define CLOCK_IN_OMAP343X (1 << 16)
43 int running; /* Is currently ticking */
44 int enabled; /* Is enabled, regardless of its input clk */
45 unsigned long rate; /* Current rate (if .running) */
46 unsigned int divisor; /* Rate relative to input (if .enabled) */
47 unsigned int multiplier; /* Rate relative to input (if .enabled) */
48 qemu_irq users[16]; /* Who to notify on change */
49 int usecount; /* Automatically idle when unused */
52 static struct clk xtal_osc12m = {
53 .name = "xtal_osc_12m",
55 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310,
58 static struct clk xtal_osc32k = {
59 .name = "xtal_osc_32k",
61 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310 |
62 CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
65 static struct clk ck_ref = {
68 .parent = &xtal_osc12m,
69 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310 |
73 /* If a dpll is disabled it becomes a bypass, child clocks don't stop */
74 static struct clk dpll1 = {
77 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310 |
81 static struct clk dpll2 = {
84 .flags = CLOCK_IN_OMAP310 | ALWAYS_ENABLED,
87 static struct clk dpll3 = {
90 .flags = CLOCK_IN_OMAP310 | ALWAYS_ENABLED,
93 static struct clk dpll4 = {
97 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310,
100 static struct clk apll = {
105 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310,
108 static struct clk ck_48m = {
110 .parent = &dpll4, /* either dpll4 or apll */
111 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310,
114 static struct clk ck_dpll1out = {
115 .name = "ck_dpll1out",
117 .flags = CLOCK_IN_OMAP16XX,
120 static struct clk sossi_ck = {
122 .parent = &ck_dpll1out,
123 .flags = CLOCK_IN_OMAP16XX,
126 static struct clk clkm1 = {
130 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310 |
134 static struct clk clkm2 = {
138 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310 |
142 static struct clk clkm3 = {
145 .parent = &dpll1, /* either dpll1 or ck_ref */
146 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310 |
150 static struct clk arm_ck = {
154 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310 |
158 static struct clk armper_ck = {
160 .alias = "mpuper_ck",
162 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310,
165 static struct clk arm_gpio_ck = {
166 .name = "arm_gpio_ck",
167 .alias = "mpu_gpio_ck",
170 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP310,
173 static struct clk armxor_ck = {
175 .alias = "mpuxor_ck",
177 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310,
180 static struct clk armtim_ck = {
182 .alias = "mputim_ck",
183 .parent = &ck_ref, /* either CLKIN or DPLL1 */
184 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310,
187 static struct clk armwdt_ck = {
192 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310 |
196 static struct clk arminth_ck16xx = {
197 .name = "arminth_ck",
199 .flags = CLOCK_IN_OMAP16XX | ALWAYS_ENABLED,
200 /* Note: On 16xx the frequency can be divided by 2 by programming
201 * ARM_CKCTL:ARM_INTHCK_SEL(14) to 1
203 * 1510 version is in TC clocks.
207 static struct clk dsp_ck = {
210 .flags = CLOCK_IN_OMAP310 | CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX,
213 static struct clk dspmmu_ck = {
216 .flags = CLOCK_IN_OMAP310 | CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX |
220 static struct clk dspper_ck = {
223 .flags = CLOCK_IN_OMAP310 | CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX,
226 static struct clk dspxor_ck = {
229 .flags = CLOCK_IN_OMAP310 | CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX,
232 static struct clk dsptim_ck = {
235 .flags = CLOCK_IN_OMAP310 | CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX,
238 static struct clk tc_ck = {
241 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX |
242 CLOCK_IN_OMAP730 | CLOCK_IN_OMAP310 |
246 static struct clk arminth_ck15xx = {
247 .name = "arminth_ck",
249 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP310 | ALWAYS_ENABLED,
250 /* Note: On 1510 the frequency follows TC_CK
252 * 16xx version is in MPU clocks.
256 static struct clk tipb_ck = {
257 /* No-idle controlled by "tc_ck" */
260 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP310 | ALWAYS_ENABLED,
263 static struct clk l3_ocpi_ck = {
264 /* No-idle controlled by "tc_ck" */
265 .name = "l3_ocpi_ck",
267 .flags = CLOCK_IN_OMAP16XX,
270 static struct clk tc1_ck = {
273 .flags = CLOCK_IN_OMAP16XX,
276 static struct clk tc2_ck = {
279 .flags = CLOCK_IN_OMAP16XX,
282 static struct clk dma_ck = {
283 /* No-idle controlled by "tc_ck" */
286 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310 |
290 static struct clk dma_lcdfree_ck = {
291 .name = "dma_lcdfree_ck",
293 .flags = CLOCK_IN_OMAP16XX | ALWAYS_ENABLED,
296 static struct clk api_ck = {
300 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310,
303 static struct clk lb_ck = {
306 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP310,
309 static struct clk lbfree_ck = {
312 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP310,
315 static struct clk hsab_ck = {
318 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP310,
321 static struct clk rhea1_ck = {
324 .flags = CLOCK_IN_OMAP16XX | ALWAYS_ENABLED,
327 static struct clk rhea2_ck = {
330 .flags = CLOCK_IN_OMAP16XX | ALWAYS_ENABLED,
333 static struct clk lcd_ck_16xx = {
336 .flags = CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP730,
339 static struct clk lcd_ck_1510 = {
342 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP310,
345 static struct clk uart1_1510 = {
347 /* Direct from ULPD, no real parent */
348 .parent = &armper_ck, /* either armper_ck or dpll4 */
350 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP310 | ALWAYS_ENABLED,
353 static struct clk uart1_16xx = {
355 /* Direct from ULPD, no real parent */
356 .parent = &armper_ck,
358 .flags = CLOCK_IN_OMAP16XX,
361 static struct clk uart2_ck = {
363 /* Direct from ULPD, no real parent */
364 .parent = &armper_ck, /* either armper_ck or dpll4 */
366 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310 |
370 static struct clk uart3_1510 = {
372 /* Direct from ULPD, no real parent */
373 .parent = &armper_ck, /* either armper_ck or dpll4 */
375 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP310 | ALWAYS_ENABLED,
378 static struct clk uart3_16xx = {
380 /* Direct from ULPD, no real parent */
381 .parent = &armper_ck,
383 .flags = CLOCK_IN_OMAP16XX,
386 static struct clk usb_clk0 = { /* 6 MHz output on W4_USB_CLK0 */
389 /* Direct from ULPD, no parent */
391 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310,
394 static struct clk usb_hhc_ck1510 = {
395 .name = "usb_hhc_ck",
396 /* Direct from ULPD, no parent */
397 .rate = 48000000, /* Actually 2 clocks, 12MHz and 48MHz */
398 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP310,
401 static struct clk usb_hhc_ck16xx = {
402 .name = "usb_hhc_ck",
403 /* Direct from ULPD, no parent */
405 /* OTG_SYSCON_2.OTG_PADEN == 0 (not 1510-compatible) */
406 .flags = CLOCK_IN_OMAP16XX,
409 static struct clk usb_w2fc_mclk = {
410 .name = "usb_w2fc_mclk",
411 .alias = "usb_w2fc_ck",
414 .flags = CLOCK_IN_OMAP310 | CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX,
417 static struct clk mclk_1510 = {
419 /* Direct from ULPD, no parent. May be enabled by ext hardware. */
421 .flags = CLOCK_IN_OMAP1510,
424 static struct clk bclk_310 = {
425 .name = "bt_mclk_out", /* Alias midi_mclk_out? */
426 .parent = &armper_ck,
427 .flags = CLOCK_IN_OMAP310,
430 static struct clk mclk_310 = {
431 .name = "com_mclk_out",
432 .parent = &armper_ck,
433 .flags = CLOCK_IN_OMAP310,
436 static struct clk mclk_16xx = {
438 /* Direct from ULPD, no parent. May be enabled by ext hardware. */
439 .flags = CLOCK_IN_OMAP16XX,
442 static struct clk bclk_1510 = {
444 /* Direct from ULPD, no parent. May be enabled by ext hardware. */
446 .flags = CLOCK_IN_OMAP1510,
449 static struct clk bclk_16xx = {
451 /* Direct from ULPD, no parent. May be enabled by ext hardware. */
452 .flags = CLOCK_IN_OMAP16XX,
455 static struct clk mmc1_ck = {
458 /* Functional clock is direct from ULPD, interface clock is ARMPER */
459 .parent = &armper_ck, /* either armper_ck or dpll4 */
461 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310,
464 static struct clk mmc2_ck = {
467 /* Functional clock is direct from ULPD, interface clock is ARMPER */
468 .parent = &armper_ck,
470 .flags = CLOCK_IN_OMAP16XX,
473 static struct clk cam_mclk = {
475 .flags = CLOCK_IN_OMAP310 | CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX,
479 static struct clk cam_exclk = {
481 .flags = CLOCK_IN_OMAP310 | CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX,
482 /* Either 12M from cam.mclk or 48M from dpll4 */
486 static struct clk cam_lclk = {
488 .flags = CLOCK_IN_OMAP310 | CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX,
491 static struct clk i2c_fck = {
494 .flags = CLOCK_IN_OMAP310 | CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX |
496 .parent = &armxor_ck,
499 static struct clk i2c_ick = {
502 .flags = CLOCK_IN_OMAP16XX | ALWAYS_ENABLED,
503 .parent = &armper_ck,
506 static struct clk clk32k = {
508 .flags = CLOCK_IN_OMAP310 | CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX |
509 CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X | ALWAYS_ENABLED,
510 .parent = &xtal_osc32k,
513 static struct clk ref_clk = {
515 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X | ALWAYS_ENABLED,
516 .rate = 12000000, /* 12 MHz or 13 MHz or 19.2 MHz */
517 /*.parent = sys.xtalin */
520 static struct clk apll_96m = {
522 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X | ALWAYS_ENABLED,
524 /*.parent = ref_clk */
527 static struct clk apll_54m = {
529 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X | ALWAYS_ENABLED,
531 /*.parent = ref_clk */
534 static struct clk sys_clk = {
536 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X | ALWAYS_ENABLED,
538 /*.parent = sys.xtalin */
541 static struct clk sleep_clk = {
543 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X | ALWAYS_ENABLED,
545 /*.parent = sys.xtalin */
548 static struct clk dpll_ck = {
550 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X | ALWAYS_ENABLED,
554 static struct clk dpll_x2_ck = {
556 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X | ALWAYS_ENABLED,
560 static struct clk wdt1_sys_clk = {
561 .name = "wdt1_sys_clk",
562 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X | ALWAYS_ENABLED,
564 /*.parent = sys.xtalin */
567 static struct clk func_96m_clk = {
568 .name = "func_96m_clk",
569 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
574 static struct clk func_48m_clk = {
575 .name = "func_48m_clk",
576 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
581 static struct clk func_12m_clk = {
582 .name = "func_12m_clk",
583 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
588 static struct clk func_54m_clk = {
589 .name = "func_54m_clk",
590 .flags = CLOCK_IN_OMAP242X,
595 static struct clk sys_clkout = {
597 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
601 static struct clk sys_clkout2 = {
603 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
607 static struct clk core_clk = {
609 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
610 .parent = &dpll_x2_ck, /* Switchable between dpll_ck and clk32k */
613 static struct clk l3_clk = {
615 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
619 static struct clk core_l4_iclk = {
620 .name = "core_l4_iclk",
621 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
625 static struct clk wu_l4_iclk = {
626 .name = "wu_l4_iclk",
627 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
631 static struct clk core_l3_iclk = {
632 .name = "core_l3_iclk",
633 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
637 static struct clk core_l4_usb_clk = {
638 .name = "core_l4_usb_clk",
639 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
643 static struct clk wu_gpt1_clk = {
644 .name = "wu_gpt1_clk",
645 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
649 static struct clk wu_32k_clk = {
650 .name = "wu_32k_clk",
651 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
655 static struct clk uart1_fclk = {
656 .name = "uart1_fclk",
657 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
658 .parent = &func_48m_clk,
661 static struct clk uart1_iclk = {
662 .name = "uart1_iclk",
663 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
664 .parent = &core_l4_iclk,
667 static struct clk uart2_fclk = {
668 .name = "uart2_fclk",
669 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
670 .parent = &func_48m_clk,
673 static struct clk uart2_iclk = {
674 .name = "uart2_iclk",
675 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
676 .parent = &core_l4_iclk,
679 static struct clk uart3_fclk = {
680 .name = "uart3_fclk",
681 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
682 .parent = &func_48m_clk,
685 static struct clk uart3_iclk = {
686 .name = "uart3_iclk",
687 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
688 .parent = &core_l4_iclk,
691 static struct clk mpu_fclk = {
693 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
697 static struct clk mpu_iclk = {
699 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
703 static struct clk int_m_fclk = {
704 .name = "int_m_fclk",
705 .alias = "mpu_intc_fclk",
706 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
710 static struct clk int_m_iclk = {
711 .name = "int_m_iclk",
712 .alias = "mpu_intc_iclk",
713 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
717 static struct clk core_gpt2_clk = {
718 .name = "core_gpt2_clk",
719 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
723 static struct clk core_gpt3_clk = {
724 .name = "core_gpt3_clk",
725 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
729 static struct clk core_gpt4_clk = {
730 .name = "core_gpt4_clk",
731 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
735 static struct clk core_gpt5_clk = {
736 .name = "core_gpt5_clk",
737 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
741 static struct clk core_gpt6_clk = {
742 .name = "core_gpt6_clk",
743 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
747 static struct clk core_gpt7_clk = {
748 .name = "core_gpt7_clk",
749 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
753 static struct clk core_gpt8_clk = {
754 .name = "core_gpt8_clk",
755 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
759 static struct clk core_gpt9_clk = {
760 .name = "core_gpt9_clk",
761 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
765 static struct clk core_gpt10_clk = {
766 .name = "core_gpt10_clk",
767 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
771 static struct clk core_gpt11_clk = {
772 .name = "core_gpt11_clk",
773 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
777 static struct clk core_gpt12_clk = {
778 .name = "core_gpt12_clk",
779 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
783 static struct clk mcbsp1_clk = {
785 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
787 .parent = &func_96m_clk,
790 static struct clk mcbsp2_clk = {
792 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
794 .parent = &func_96m_clk,
797 static struct clk emul_clk = {
799 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
800 .parent = &func_54m_clk,
803 static struct clk sdma_fclk = {
805 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
809 static struct clk sdma_iclk = {
811 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
812 .parent = &core_l3_iclk, /* core_l4_iclk for the configuration port */
815 static struct clk i2c1_fclk = {
817 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
818 .parent = &func_12m_clk,
822 static struct clk i2c1_iclk = {
824 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
825 .parent = &core_l4_iclk,
828 static struct clk i2c2_fclk = {
830 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
831 .parent = &func_12m_clk,
835 static struct clk i2c2_iclk = {
837 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
838 .parent = &core_l4_iclk,
841 static struct clk gpio_dbclk[4] = {
843 .name = "gpio1_dbclk",
844 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
845 .parent = &wu_32k_clk,
847 .name = "gpio2_dbclk",
848 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
849 .parent = &wu_32k_clk,
851 .name = "gpio3_dbclk",
852 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
853 .parent = &wu_32k_clk,
855 .name = "gpio4_dbclk",
856 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
857 .parent = &wu_32k_clk,
861 static struct clk gpio_iclk = {
863 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
864 .parent = &wu_l4_iclk,
867 static struct clk mmc_fck = {
869 .flags = CLOCK_IN_OMAP242X,
870 .parent = &func_96m_clk,
873 static struct clk mmc_ick = {
875 .flags = CLOCK_IN_OMAP242X,
876 .parent = &core_l4_iclk,
879 static struct clk spi_fclk[3] = {
882 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
883 .parent = &func_48m_clk,
886 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
887 .parent = &func_48m_clk,
890 .flags = CLOCK_IN_OMAP243X,
891 .parent = &func_48m_clk,
895 static struct clk dss_clk[2] = {
898 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
902 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
907 static struct clk dss_54m_clk = {
908 .name = "dss_54m_clk",
909 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
910 .parent = &func_54m_clk,
913 static struct clk dss_l3_iclk = {
914 .name = "dss_l3_iclk",
915 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
916 .parent = &core_l3_iclk,
919 static struct clk dss_l4_iclk = {
920 .name = "dss_l4_iclk",
921 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
922 .parent = &core_l4_iclk,
925 static struct clk spi_iclk[3] = {
928 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
929 .parent = &core_l4_iclk,
932 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
933 .parent = &core_l4_iclk,
936 .flags = CLOCK_IN_OMAP243X,
937 .parent = &core_l4_iclk,
941 static struct clk omapctrl_clk = {
942 .name = "omapctrl_iclk",
943 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
944 /* XXX Should be in WKUP domain */
945 .parent = &core_l4_iclk,
948 static struct clk *onchip_clks[] = {
951 /* non-ULPD clocks */
971 &arminth_ck15xx, &arminth_ck16xx,
1003 &usb_hhc_ck1510, &usb_hhc_ck16xx,
1004 &mclk_1510, &mclk_16xx, &mclk_310,
1005 &bclk_1510, &bclk_16xx, &bclk_310,
1013 /* Virtual clocks */
1094 void omap_clk_adduser(struct clk *clk, qemu_irq user)
1098 for (i = clk->users; *i; i ++);
1102 /* If a clock is allowed to idle, it is disabled automatically when
1103 * all of clock domains using it are disabled. */
1104 static int omap_clk_is_idle(struct clk *clk)
1108 if (!clk->enabled && (!clk->usecount || !(clk->flags && ALWAYS_ENABLED)))
1113 for (chld = clk->child1; chld; chld = chld->sibling)
1114 if (!omap_clk_is_idle(chld))
1119 struct clk *omap_findclk(struct omap_mpu_state_s *mpu, const char *name)
1123 for (i = mpu->clks; i->name; i ++)
1124 if (!strcmp(i->name, name) || (i->alias && !strcmp(i->alias, name)))
1126 cpu_abort(mpu->env, "%s: %s not found\n", __FUNCTION__, name);
1129 void omap_clk_get(struct clk *clk)
1134 void omap_clk_put(struct clk *clk)
1136 if (!(clk->usecount --))
1137 cpu_abort(cpu_single_env, "%s: %s is not in use\n",
1138 __FUNCTION__, clk->name);
1141 static void omap_clk_update(struct clk *clk)
1143 int parent, running;
1148 parent = clk->parent->running;
1152 running = parent && (clk->enabled ||
1153 ((clk->flags & ALWAYS_ENABLED) && clk->usecount));
1154 if (clk->running != running) {
1155 clk->running = running;
1156 for (user = clk->users; *user; user ++)
1157 qemu_set_irq(*user, running);
1158 for (i = clk->child1; i; i = i->sibling)
1163 static void omap_clk_rate_update_full(struct clk *clk, unsigned long int rate,
1164 unsigned long int div, unsigned long int mult)
1169 clk->rate = muldiv64(rate, mult, div);
1171 for (user = clk->users; *user; user ++)
1172 qemu_irq_raise(*user);
1173 for (i = clk->child1; i; i = i->sibling)
1174 omap_clk_rate_update_full(i, rate,
1175 div * i->divisor, mult * i->multiplier);
1178 static void omap_clk_rate_update(struct clk *clk)
1181 unsigned long int div, mult = div = 1;
1183 for (i = clk; i->parent; i = i->parent) {
1185 mult *= i->multiplier;
1188 omap_clk_rate_update_full(clk, i->rate, div, mult);
1191 void omap_clk_reparent(struct clk *clk, struct clk *parent)
1196 for (p = &clk->parent->child1; *p != clk; p = &(*p)->sibling);
1200 clk->parent = parent;
1202 clk->sibling = parent->child1;
1203 parent->child1 = clk;
1204 omap_clk_update(clk);
1205 omap_clk_rate_update(clk);
1210 void omap_clk_onoff(struct clk *clk, int on)
1213 omap_clk_update(clk);
1216 void omap_clk_canidle(struct clk *clk, int can)
1224 void omap_clk_setrate(struct clk *clk, int divide, int multiply)
1226 clk->divisor = divide;
1227 clk->multiplier = multiply;
1228 omap_clk_rate_update(clk);
1231 int64_t omap_clk_getrate(omap_clk clk)
1236 void omap_clk_init(struct omap_mpu_state_s *mpu)
1238 struct clk **i, *j, *k;
1242 if (cpu_is_omap310(mpu))
1243 flag = CLOCK_IN_OMAP310;
1244 else if (cpu_is_omap1510(mpu))
1245 flag = CLOCK_IN_OMAP1510;
1246 else if (cpu_is_omap2410(mpu) || cpu_is_omap2420(mpu))
1247 flag = CLOCK_IN_OMAP242X;
1248 else if (cpu_is_omap2430(mpu))
1249 flag = CLOCK_IN_OMAP243X;
1250 else if (cpu_is_omap3430(mpu))
1251 flag = CLOCK_IN_OMAP243X;
1255 for (i = onchip_clks, count = 0; *i; i ++)
1256 if ((*i)->flags & flag)
1258 mpu->clks = (struct clk *) qemu_mallocz(sizeof(struct clk) * (count + 1));
1259 for (i = onchip_clks, j = mpu->clks; *i; i ++)
1260 if ((*i)->flags & flag) {
1261 memcpy(j, *i, sizeof(struct clk));
1262 for (k = mpu->clks; k < j; k ++)
1263 if (j->parent && !strcmp(j->parent->name, k->name)) {
1265 j->sibling = k->child1;
1267 } else if (k->parent && !strcmp(k->parent->name, j->name)) {
1269 k->sibling = j->child1;
1272 j->divisor = j->divisor ?: 1;
1273 j->multiplier = j->multiplier ?: 1;
1276 for (j = mpu->clks; count --; j ++) {
1278 omap_clk_rate_update(j);