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 along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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)
36 #define CLOCK_IN_OMAP242X (1 << 14)
37 #define CLOCK_IN_OMAP243X (1 << 15)
38 #define CLOCK_IN_OMAP343X (1 << 16)
42 int running; /* Is currently ticking */
43 int enabled; /* Is enabled, regardless of its input clk */
44 unsigned long rate; /* Current rate (if .running) */
45 unsigned int divisor; /* Rate relative to input (if .enabled) */
46 unsigned int multiplier; /* Rate relative to input (if .enabled) */
47 qemu_irq users[16]; /* Who to notify on change */
48 int usecount; /* Automatically idle when unused */
51 static struct clk xtal_osc12m = {
52 .name = "xtal_osc_12m",
54 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310,
57 static struct clk xtal_osc32k = {
58 .name = "xtal_osc_32k",
60 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310 |
61 CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
64 static struct clk ck_ref = {
67 .parent = &xtal_osc12m,
68 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310 |
72 /* If a dpll is disabled it becomes a bypass, child clocks don't stop */
73 static struct clk dpll1 = {
76 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310 |
80 static struct clk dpll2 = {
83 .flags = CLOCK_IN_OMAP310 | ALWAYS_ENABLED,
86 static struct clk dpll3 = {
89 .flags = CLOCK_IN_OMAP310 | ALWAYS_ENABLED,
92 static struct clk dpll4 = {
96 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310,
99 static struct clk apll = {
104 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310,
107 static struct clk ck_48m = {
109 .parent = &dpll4, /* either dpll4 or apll */
110 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310,
113 static struct clk ck_dpll1out = {
114 .name = "ck_dpll1out",
116 .flags = CLOCK_IN_OMAP16XX,
119 static struct clk sossi_ck = {
121 .parent = &ck_dpll1out,
122 .flags = CLOCK_IN_OMAP16XX,
125 static struct clk clkm1 = {
129 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310 |
133 static struct clk clkm2 = {
137 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310 |
141 static struct clk clkm3 = {
144 .parent = &dpll1, /* either dpll1 or ck_ref */
145 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310 |
149 static struct clk arm_ck = {
153 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310 |
157 static struct clk armper_ck = {
159 .alias = "mpuper_ck",
161 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310,
164 static struct clk arm_gpio_ck = {
165 .name = "arm_gpio_ck",
166 .alias = "mpu_gpio_ck",
169 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP310,
172 static struct clk armxor_ck = {
174 .alias = "mpuxor_ck",
176 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310,
179 static struct clk armtim_ck = {
181 .alias = "mputim_ck",
182 .parent = &ck_ref, /* either CLKIN or DPLL1 */
183 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310,
186 static struct clk armwdt_ck = {
191 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310 |
195 static struct clk arminth_ck16xx = {
196 .name = "arminth_ck",
198 .flags = CLOCK_IN_OMAP16XX | ALWAYS_ENABLED,
199 /* Note: On 16xx the frequency can be divided by 2 by programming
200 * ARM_CKCTL:ARM_INTHCK_SEL(14) to 1
202 * 1510 version is in TC clocks.
206 static struct clk dsp_ck = {
209 .flags = CLOCK_IN_OMAP310 | CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX,
212 static struct clk dspmmu_ck = {
215 .flags = CLOCK_IN_OMAP310 | CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX |
219 static struct clk dspper_ck = {
222 .flags = CLOCK_IN_OMAP310 | CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX,
225 static struct clk dspxor_ck = {
228 .flags = CLOCK_IN_OMAP310 | CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX,
231 static struct clk dsptim_ck = {
234 .flags = CLOCK_IN_OMAP310 | CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX,
237 static struct clk tc_ck = {
240 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX |
241 CLOCK_IN_OMAP730 | CLOCK_IN_OMAP310 |
245 static struct clk arminth_ck15xx = {
246 .name = "arminth_ck",
248 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP310 | ALWAYS_ENABLED,
249 /* Note: On 1510 the frequency follows TC_CK
251 * 16xx version is in MPU clocks.
255 static struct clk tipb_ck = {
256 /* No-idle controlled by "tc_ck" */
259 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP310 | ALWAYS_ENABLED,
262 static struct clk l3_ocpi_ck = {
263 /* No-idle controlled by "tc_ck" */
264 .name = "l3_ocpi_ck",
266 .flags = CLOCK_IN_OMAP16XX,
269 static struct clk tc1_ck = {
272 .flags = CLOCK_IN_OMAP16XX,
275 static struct clk tc2_ck = {
278 .flags = CLOCK_IN_OMAP16XX,
281 static struct clk dma_ck = {
282 /* No-idle controlled by "tc_ck" */
285 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310 |
289 static struct clk dma_lcdfree_ck = {
290 .name = "dma_lcdfree_ck",
292 .flags = CLOCK_IN_OMAP16XX | ALWAYS_ENABLED,
295 static struct clk api_ck = {
299 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310,
302 static struct clk lb_ck = {
305 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP310,
308 static struct clk lbfree_ck = {
311 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP310,
314 static struct clk hsab_ck = {
317 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP310,
320 static struct clk rhea1_ck = {
323 .flags = CLOCK_IN_OMAP16XX | ALWAYS_ENABLED,
326 static struct clk rhea2_ck = {
329 .flags = CLOCK_IN_OMAP16XX | ALWAYS_ENABLED,
332 static struct clk lcd_ck_16xx = {
335 .flags = CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP730,
338 static struct clk lcd_ck_1510 = {
341 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP310,
344 static struct clk uart1_1510 = {
346 /* Direct from ULPD, no real parent */
347 .parent = &armper_ck, /* either armper_ck or dpll4 */
349 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP310 | ALWAYS_ENABLED,
352 static struct clk uart1_16xx = {
354 /* Direct from ULPD, no real parent */
355 .parent = &armper_ck,
357 .flags = CLOCK_IN_OMAP16XX,
360 static struct clk uart2_ck = {
362 /* Direct from ULPD, no real parent */
363 .parent = &armper_ck, /* either armper_ck or dpll4 */
365 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310 |
369 static struct clk uart3_1510 = {
371 /* Direct from ULPD, no real parent */
372 .parent = &armper_ck, /* either armper_ck or dpll4 */
374 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP310 | ALWAYS_ENABLED,
377 static struct clk uart3_16xx = {
379 /* Direct from ULPD, no real parent */
380 .parent = &armper_ck,
382 .flags = CLOCK_IN_OMAP16XX,
385 static struct clk usb_clk0 = { /* 6 MHz output on W4_USB_CLK0 */
388 /* Direct from ULPD, no parent */
390 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310,
393 static struct clk usb_hhc_ck1510 = {
394 .name = "usb_hhc_ck",
395 /* Direct from ULPD, no parent */
396 .rate = 48000000, /* Actually 2 clocks, 12MHz and 48MHz */
397 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP310,
400 static struct clk usb_hhc_ck16xx = {
401 .name = "usb_hhc_ck",
402 /* Direct from ULPD, no parent */
404 /* OTG_SYSCON_2.OTG_PADEN == 0 (not 1510-compatible) */
405 .flags = CLOCK_IN_OMAP16XX,
408 static struct clk usb_w2fc_mclk = {
409 .name = "usb_w2fc_mclk",
410 .alias = "usb_w2fc_ck",
413 .flags = CLOCK_IN_OMAP310 | CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX,
416 static struct clk mclk_1510 = {
418 /* Direct from ULPD, no parent. May be enabled by ext hardware. */
420 .flags = CLOCK_IN_OMAP1510,
423 static struct clk bclk_310 = {
424 .name = "bt_mclk_out", /* Alias midi_mclk_out? */
425 .parent = &armper_ck,
426 .flags = CLOCK_IN_OMAP310,
429 static struct clk mclk_310 = {
430 .name = "com_mclk_out",
431 .parent = &armper_ck,
432 .flags = CLOCK_IN_OMAP310,
435 static struct clk mclk_16xx = {
437 /* Direct from ULPD, no parent. May be enabled by ext hardware. */
438 .flags = CLOCK_IN_OMAP16XX,
441 static struct clk bclk_1510 = {
443 /* Direct from ULPD, no parent. May be enabled by ext hardware. */
445 .flags = CLOCK_IN_OMAP1510,
448 static struct clk bclk_16xx = {
450 /* Direct from ULPD, no parent. May be enabled by ext hardware. */
451 .flags = CLOCK_IN_OMAP16XX,
454 static struct clk mmc1_ck = {
457 /* Functional clock is direct from ULPD, interface clock is ARMPER */
458 .parent = &armper_ck, /* either armper_ck or dpll4 */
460 .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP310,
463 static struct clk mmc2_ck = {
466 /* Functional clock is direct from ULPD, interface clock is ARMPER */
467 .parent = &armper_ck,
469 .flags = CLOCK_IN_OMAP16XX,
472 static struct clk cam_mclk = {
474 .flags = CLOCK_IN_OMAP310 | CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX,
478 static struct clk cam_exclk = {
480 .flags = CLOCK_IN_OMAP310 | CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX,
481 /* Either 12M from cam.mclk or 48M from dpll4 */
485 static struct clk cam_lclk = {
487 .flags = CLOCK_IN_OMAP310 | CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX,
490 static struct clk i2c_fck = {
493 .flags = CLOCK_IN_OMAP310 | CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX |
495 .parent = &armxor_ck,
498 static struct clk i2c_ick = {
501 .flags = CLOCK_IN_OMAP16XX | ALWAYS_ENABLED,
502 .parent = &armper_ck,
505 static struct clk clk32k = {
507 .flags = CLOCK_IN_OMAP310 | CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX |
508 CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X | ALWAYS_ENABLED,
509 .parent = &xtal_osc32k,
512 static struct clk ref_clk = {
514 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X | ALWAYS_ENABLED,
515 .rate = 12000000, /* 12 MHz or 13 MHz or 19.2 MHz */
516 /*.parent = sys.xtalin */
519 static struct clk apll_96m = {
521 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X | ALWAYS_ENABLED,
523 /*.parent = ref_clk */
526 static struct clk apll_54m = {
528 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X | ALWAYS_ENABLED,
530 /*.parent = ref_clk */
533 static struct clk sys_clk = {
535 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X | ALWAYS_ENABLED,
537 /*.parent = sys.xtalin */
540 static struct clk sleep_clk = {
542 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X | ALWAYS_ENABLED,
544 /*.parent = sys.xtalin */
547 static struct clk dpll_ck = {
549 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X | ALWAYS_ENABLED,
553 static struct clk dpll_x2_ck = {
555 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X | ALWAYS_ENABLED,
559 static struct clk wdt1_sys_clk = {
560 .name = "wdt1_sys_clk",
561 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X | ALWAYS_ENABLED,
563 /*.parent = sys.xtalin */
566 static struct clk func_96m_clk = {
567 .name = "func_96m_clk",
568 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
573 static struct clk func_48m_clk = {
574 .name = "func_48m_clk",
575 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
580 static struct clk func_12m_clk = {
581 .name = "func_12m_clk",
582 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
587 static struct clk func_54m_clk = {
588 .name = "func_54m_clk",
589 .flags = CLOCK_IN_OMAP242X,
594 static struct clk sys_clkout = {
596 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
600 static struct clk sys_clkout2 = {
602 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
606 static struct clk core_clk = {
608 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
609 .parent = &dpll_x2_ck, /* Switchable between dpll_ck and clk32k */
612 static struct clk l3_clk = {
614 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
618 static struct clk core_l4_iclk = {
619 .name = "core_l4_iclk",
620 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
624 static struct clk wu_l4_iclk = {
625 .name = "wu_l4_iclk",
626 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
630 static struct clk core_l3_iclk = {
631 .name = "core_l3_iclk",
632 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
636 static struct clk core_l4_usb_clk = {
637 .name = "core_l4_usb_clk",
638 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
642 static struct clk wu_gpt1_clk = {
643 .name = "wu_gpt1_clk",
644 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
648 static struct clk wu_32k_clk = {
649 .name = "wu_32k_clk",
650 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
654 static struct clk uart1_fclk = {
655 .name = "uart1_fclk",
656 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
657 .parent = &func_48m_clk,
660 static struct clk uart1_iclk = {
661 .name = "uart1_iclk",
662 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
663 .parent = &core_l4_iclk,
666 static struct clk uart2_fclk = {
667 .name = "uart2_fclk",
668 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
669 .parent = &func_48m_clk,
672 static struct clk uart2_iclk = {
673 .name = "uart2_iclk",
674 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
675 .parent = &core_l4_iclk,
678 static struct clk uart3_fclk = {
679 .name = "uart3_fclk",
680 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
681 .parent = &func_48m_clk,
684 static struct clk uart3_iclk = {
685 .name = "uart3_iclk",
686 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
687 .parent = &core_l4_iclk,
690 static struct clk mpu_fclk = {
692 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
696 static struct clk mpu_iclk = {
698 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
702 static struct clk int_m_fclk = {
703 .name = "int_m_fclk",
704 .alias = "mpu_intc_fclk",
705 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
709 static struct clk int_m_iclk = {
710 .name = "int_m_iclk",
711 .alias = "mpu_intc_iclk",
712 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
716 static struct clk core_gpt2_clk = {
717 .name = "core_gpt2_clk",
718 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
722 static struct clk core_gpt3_clk = {
723 .name = "core_gpt3_clk",
724 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
728 static struct clk core_gpt4_clk = {
729 .name = "core_gpt4_clk",
730 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
734 static struct clk core_gpt5_clk = {
735 .name = "core_gpt5_clk",
736 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
740 static struct clk core_gpt6_clk = {
741 .name = "core_gpt6_clk",
742 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
746 static struct clk core_gpt7_clk = {
747 .name = "core_gpt7_clk",
748 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
752 static struct clk core_gpt8_clk = {
753 .name = "core_gpt8_clk",
754 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
758 static struct clk core_gpt9_clk = {
759 .name = "core_gpt9_clk",
760 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
764 static struct clk core_gpt10_clk = {
765 .name = "core_gpt10_clk",
766 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
770 static struct clk core_gpt11_clk = {
771 .name = "core_gpt11_clk",
772 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
776 static struct clk core_gpt12_clk = {
777 .name = "core_gpt12_clk",
778 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
782 static struct clk mcbsp1_clk = {
784 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
786 .parent = &func_96m_clk,
789 static struct clk mcbsp2_clk = {
791 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
793 .parent = &func_96m_clk,
796 static struct clk emul_clk = {
798 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
799 .parent = &func_54m_clk,
802 static struct clk sdma_fclk = {
804 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
808 static struct clk sdma_iclk = {
810 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
811 .parent = &core_l3_iclk, /* core_l4_iclk for the configuration port */
814 static struct clk i2c1_fclk = {
816 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
817 .parent = &func_12m_clk,
821 static struct clk i2c1_iclk = {
823 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
824 .parent = &core_l4_iclk,
827 static struct clk i2c2_fclk = {
829 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
830 .parent = &func_12m_clk,
834 static struct clk i2c2_iclk = {
836 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
837 .parent = &core_l4_iclk,
840 static struct clk gpio_dbclk[4] = {
842 .name = "gpio1_dbclk",
843 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
844 .parent = &wu_32k_clk,
846 .name = "gpio2_dbclk",
847 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
848 .parent = &wu_32k_clk,
850 .name = "gpio3_dbclk",
851 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
852 .parent = &wu_32k_clk,
854 .name = "gpio4_dbclk",
855 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
856 .parent = &wu_32k_clk,
860 static struct clk gpio_iclk = {
862 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
863 .parent = &wu_l4_iclk,
866 static struct clk mmc_fck = {
868 .flags = CLOCK_IN_OMAP242X,
869 .parent = &func_96m_clk,
872 static struct clk mmc_ick = {
874 .flags = CLOCK_IN_OMAP242X,
875 .parent = &core_l4_iclk,
878 static struct clk spi_fclk[3] = {
881 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
882 .parent = &func_48m_clk,
885 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
886 .parent = &func_48m_clk,
889 .flags = CLOCK_IN_OMAP243X,
890 .parent = &func_48m_clk,
894 static struct clk dss_clk[2] = {
897 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
901 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
906 static struct clk dss_54m_clk = {
907 .name = "dss_54m_clk",
908 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
909 .parent = &func_54m_clk,
912 static struct clk dss_l3_iclk = {
913 .name = "dss_l3_iclk",
914 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
915 .parent = &core_l3_iclk,
918 static struct clk dss_l4_iclk = {
919 .name = "dss_l4_iclk",
920 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
921 .parent = &core_l4_iclk,
924 static struct clk spi_iclk[3] = {
927 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
928 .parent = &core_l4_iclk,
931 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
932 .parent = &core_l4_iclk,
935 .flags = CLOCK_IN_OMAP243X,
936 .parent = &core_l4_iclk,
940 static struct clk omapctrl_clk = {
941 .name = "omapctrl_iclk",
942 .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
943 /* XXX Should be in WKUP domain */
944 .parent = &core_l4_iclk,
947 static struct clk *onchip_clks[] = {
950 /* non-ULPD clocks */
970 &arminth_ck15xx, &arminth_ck16xx,
1002 &usb_hhc_ck1510, &usb_hhc_ck16xx,
1003 &mclk_1510, &mclk_16xx, &mclk_310,
1004 &bclk_1510, &bclk_16xx, &bclk_310,
1012 /* Virtual clocks */
1093 void omap_clk_adduser(struct clk *clk, qemu_irq user)
1097 for (i = clk->users; *i; i ++);
1101 /* If a clock is allowed to idle, it is disabled automatically when
1102 * all of clock domains using it are disabled. */
1103 static int omap_clk_is_idle(struct clk *clk)
1107 if (!clk->enabled && (!clk->usecount || !(clk->flags && ALWAYS_ENABLED)))
1112 for (chld = clk->child1; chld; chld = chld->sibling)
1113 if (!omap_clk_is_idle(chld))
1118 struct clk *omap_findclk(struct omap_mpu_state_s *mpu, const char *name)
1122 for (i = mpu->clks; i->name; i ++)
1123 if (!strcmp(i->name, name) || (i->alias && !strcmp(i->alias, name)))
1125 cpu_abort(mpu->env, "%s: %s not found\n", __FUNCTION__, name);
1128 void omap_clk_get(struct clk *clk)
1133 void omap_clk_put(struct clk *clk)
1135 if (!(clk->usecount --))
1136 cpu_abort(cpu_single_env, "%s: %s is not in use\n",
1137 __FUNCTION__, clk->name);
1140 static void omap_clk_update(struct clk *clk)
1142 int parent, running;
1147 parent = clk->parent->running;
1151 running = parent && (clk->enabled ||
1152 ((clk->flags & ALWAYS_ENABLED) && clk->usecount));
1153 if (clk->running != running) {
1154 clk->running = running;
1155 for (user = clk->users; *user; user ++)
1156 qemu_set_irq(*user, running);
1157 for (i = clk->child1; i; i = i->sibling)
1162 static void omap_clk_rate_update_full(struct clk *clk, unsigned long int rate,
1163 unsigned long int div, unsigned long int mult)
1168 clk->rate = muldiv64(rate, mult, div);
1170 for (user = clk->users; *user; user ++)
1171 qemu_irq_raise(*user);
1172 for (i = clk->child1; i; i = i->sibling)
1173 omap_clk_rate_update_full(i, rate,
1174 div * i->divisor, mult * i->multiplier);
1177 static void omap_clk_rate_update(struct clk *clk)
1180 unsigned long int div, mult = div = 1;
1182 for (i = clk; i->parent; i = i->parent) {
1184 mult *= i->multiplier;
1187 omap_clk_rate_update_full(clk, i->rate, div, mult);
1190 void omap_clk_reparent(struct clk *clk, struct clk *parent)
1195 for (p = &clk->parent->child1; *p != clk; p = &(*p)->sibling);
1199 clk->parent = parent;
1201 clk->sibling = parent->child1;
1202 parent->child1 = clk;
1203 omap_clk_update(clk);
1204 omap_clk_rate_update(clk);
1209 void omap_clk_onoff(struct clk *clk, int on)
1212 omap_clk_update(clk);
1215 void omap_clk_canidle(struct clk *clk, int can)
1223 void omap_clk_setrate(struct clk *clk, int divide, int multiply)
1225 clk->divisor = divide;
1226 clk->multiplier = multiply;
1227 omap_clk_rate_update(clk);
1230 int64_t omap_clk_getrate(omap_clk clk)
1235 void omap_clk_init(struct omap_mpu_state_s *mpu)
1237 struct clk **i, *j, *k;
1241 if (cpu_is_omap310(mpu))
1242 flag = CLOCK_IN_OMAP310;
1243 else if (cpu_is_omap1510(mpu))
1244 flag = CLOCK_IN_OMAP1510;
1245 else if (cpu_is_omap2410(mpu) || cpu_is_omap2420(mpu))
1246 flag = CLOCK_IN_OMAP242X;
1247 else if (cpu_is_omap2430(mpu))
1248 flag = CLOCK_IN_OMAP243X;
1249 else if (cpu_is_omap3430(mpu))
1250 flag = CLOCK_IN_OMAP243X;
1254 for (i = onchip_clks, count = 0; *i; i ++)
1255 if ((*i)->flags & flag)
1257 mpu->clks = (struct clk *) qemu_mallocz(sizeof(struct clk) * (count + 1));
1258 for (i = onchip_clks, j = mpu->clks; *i; i ++)
1259 if ((*i)->flags & flag) {
1260 memcpy(j, *i, sizeof(struct clk));
1261 for (k = mpu->clks; k < j; k ++)
1262 if (j->parent && !strcmp(j->parent->name, k->name)) {
1264 j->sibling = k->child1;
1266 } else if (k->parent && !strcmp(k->parent->name, j->name)) {
1268 k->sibling = j->child1;
1271 j->divisor = j->divisor ?: 1;
1272 j->multiplier = j->multiplier ?: 1;
1275 for (j = mpu->clks; count --; j ++) {
1277 omap_clk_rate_update(j);