aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/arm/mach-omap2/cclock3xxx_data.c111
-rw-r--r--arch/arm/mach-omap2/clock.h11
-rw-r--r--arch/arm/mach-omap2/clock_common_data.c5
-rw-r--r--arch/arm/mach-omap2/dpll3xxx.c11
-rw-r--r--drivers/clk/clk.c631
-rw-r--r--drivers/clk/clk.h5
-rw-r--r--drivers/clk/clkdev.c84
-rw-r--r--include/linux/clk-private.h35
-rw-r--r--include/linux/clk-provider.h12
9 files changed, 602 insertions, 303 deletions
diff --git a/arch/arm/mach-omap2/cclock3xxx_data.c b/arch/arm/mach-omap2/cclock3xxx_data.c
index 644ff3231bb8..adb4e6437204 100644
--- a/arch/arm/mach-omap2/cclock3xxx_data.c
+++ b/arch/arm/mach-omap2/cclock3xxx_data.c
@@ -82,7 +82,7 @@ DEFINE_CLK_MUX(osc_sys_ck, osc_sys_ck_parent_names, NULL, 0x0,
82 OMAP3430_PRM_CLKSEL, OMAP3430_SYS_CLKIN_SEL_SHIFT, 82 OMAP3430_PRM_CLKSEL, OMAP3430_SYS_CLKIN_SEL_SHIFT,
83 OMAP3430_SYS_CLKIN_SEL_WIDTH, 0x0, NULL); 83 OMAP3430_SYS_CLKIN_SEL_WIDTH, 0x0, NULL);
84 84
85DEFINE_CLK_DIVIDER(sys_ck, "osc_sys_ck", &osc_sys_ck, 0x0, 85DEFINE_CLK_DIVIDER(sys_ck, "osc_sys_ck", &osc_sys_ck_core, 0x0,
86 OMAP3430_PRM_CLKSRC_CTRL, OMAP_SYSCLKDIV_SHIFT, 86 OMAP3430_PRM_CLKSRC_CTRL, OMAP_SYSCLKDIV_SHIFT,
87 OMAP_SYSCLKDIV_WIDTH, CLK_DIVIDER_ONE_BASED, NULL); 87 OMAP_SYSCLKDIV_WIDTH, CLK_DIVIDER_ONE_BASED, NULL);
88 88
@@ -132,7 +132,7 @@ static struct clk_hw_omap dpll3_ck_hw = {
132 132
133DEFINE_STRUCT_CLK(dpll3_ck, dpll3_ck_parent_names, dpll3_ck_ops); 133DEFINE_STRUCT_CLK(dpll3_ck, dpll3_ck_parent_names, dpll3_ck_ops);
134 134
135DEFINE_CLK_DIVIDER(dpll3_m2_ck, "dpll3_ck", &dpll3_ck, 0x0, 135DEFINE_CLK_DIVIDER(dpll3_m2_ck, "dpll3_ck", &dpll3_ck_core, 0x0,
136 OMAP_CM_REGADDR(PLL_MOD, CM_CLKSEL1), 136 OMAP_CM_REGADDR(PLL_MOD, CM_CLKSEL1),
137 OMAP3430_CORE_DPLL_CLKOUT_DIV_SHIFT, 137 OMAP3430_CORE_DPLL_CLKOUT_DIV_SHIFT,
138 OMAP3430_CORE_DPLL_CLKOUT_DIV_WIDTH, 138 OMAP3430_CORE_DPLL_CLKOUT_DIV_WIDTH,
@@ -149,12 +149,12 @@ static const struct clk_ops core_ck_ops = {};
149DEFINE_STRUCT_CLK_HW_OMAP(core_ck, NULL); 149DEFINE_STRUCT_CLK_HW_OMAP(core_ck, NULL);
150DEFINE_STRUCT_CLK(core_ck, core_ck_parent_names, core_ck_ops); 150DEFINE_STRUCT_CLK(core_ck, core_ck_parent_names, core_ck_ops);
151 151
152DEFINE_CLK_DIVIDER(l3_ick, "core_ck", &core_ck, 0x0, 152DEFINE_CLK_DIVIDER(l3_ick, "core_ck", &core_ck_core, 0x0,
153 OMAP_CM_REGADDR(CORE_MOD, CM_CLKSEL), 153 OMAP_CM_REGADDR(CORE_MOD, CM_CLKSEL),
154 OMAP3430_CLKSEL_L3_SHIFT, OMAP3430_CLKSEL_L3_WIDTH, 154 OMAP3430_CLKSEL_L3_SHIFT, OMAP3430_CLKSEL_L3_WIDTH,
155 CLK_DIVIDER_ONE_BASED, NULL); 155 CLK_DIVIDER_ONE_BASED, NULL);
156 156
157DEFINE_CLK_DIVIDER(l4_ick, "l3_ick", &l3_ick, 0x0, 157DEFINE_CLK_DIVIDER(l4_ick, "l3_ick", &l3_ick_core, 0x0,
158 OMAP_CM_REGADDR(CORE_MOD, CM_CLKSEL), 158 OMAP_CM_REGADDR(CORE_MOD, CM_CLKSEL),
159 OMAP3430_CLKSEL_L4_SHIFT, OMAP3430_CLKSEL_L4_WIDTH, 159 OMAP3430_CLKSEL_L4_SHIFT, OMAP3430_CLKSEL_L4_WIDTH,
160 CLK_DIVIDER_ONE_BASED, NULL); 160 CLK_DIVIDER_ONE_BASED, NULL);
@@ -275,9 +275,9 @@ static struct clk_hw_omap dpll1_ck_hw = {
275 275
276DEFINE_STRUCT_CLK(dpll1_ck, dpll3_ck_parent_names, dpll1_ck_ops); 276DEFINE_STRUCT_CLK(dpll1_ck, dpll3_ck_parent_names, dpll1_ck_ops);
277 277
278DEFINE_CLK_FIXED_FACTOR(dpll1_x2_ck, "dpll1_ck", &dpll1_ck, 0x0, 2, 1); 278DEFINE_CLK_FIXED_FACTOR(dpll1_x2_ck, "dpll1_ck", &dpll1_ck_core, 0x0, 2, 1);
279 279
280DEFINE_CLK_DIVIDER(dpll1_x2m2_ck, "dpll1_x2_ck", &dpll1_x2_ck, 0x0, 280DEFINE_CLK_DIVIDER(dpll1_x2m2_ck, "dpll1_x2_ck", &dpll1_x2_ck_core, 0x0,
281 OMAP_CM_REGADDR(MPU_MOD, OMAP3430_CM_CLKSEL2_PLL), 281 OMAP_CM_REGADDR(MPU_MOD, OMAP3430_CM_CLKSEL2_PLL),
282 OMAP3430_MPU_DPLL_CLKOUT_DIV_SHIFT, 282 OMAP3430_MPU_DPLL_CLKOUT_DIV_SHIFT,
283 OMAP3430_MPU_DPLL_CLKOUT_DIV_WIDTH, 283 OMAP3430_MPU_DPLL_CLKOUT_DIV_WIDTH,
@@ -292,7 +292,7 @@ static const char *mpu_ck_parent_names[] = {
292DEFINE_STRUCT_CLK_HW_OMAP(mpu_ck, "mpu_clkdm"); 292DEFINE_STRUCT_CLK_HW_OMAP(mpu_ck, "mpu_clkdm");
293DEFINE_STRUCT_CLK(mpu_ck, mpu_ck_parent_names, core_l4_ick_ops); 293DEFINE_STRUCT_CLK(mpu_ck, mpu_ck_parent_names, core_l4_ick_ops);
294 294
295DEFINE_CLK_DIVIDER(arm_fck, "mpu_ck", &mpu_ck, 0x0, 295DEFINE_CLK_DIVIDER(arm_fck, "mpu_ck", &mpu_ck_core, 0x0,
296 OMAP_CM_REGADDR(MPU_MOD, OMAP3430_CM_IDLEST_PLL), 296 OMAP_CM_REGADDR(MPU_MOD, OMAP3430_CM_IDLEST_PLL),
297 OMAP3430_ST_MPU_CLK_SHIFT, OMAP3430_ST_MPU_CLK_WIDTH, 297 OMAP3430_ST_MPU_CLK_SHIFT, OMAP3430_ST_MPU_CLK_WIDTH,
298 0x0, NULL); 298 0x0, NULL);
@@ -424,7 +424,7 @@ static const struct clk_div_table dpll4_mx_ck_div_table[] = {
424 { .div = 0 }, 424 { .div = 0 },
425}; 425};
426 426
427DEFINE_CLK_DIVIDER(dpll4_m5_ck, "dpll4_ck", &dpll4_ck, 0x0, 427DEFINE_CLK_DIVIDER(dpll4_m5_ck, "dpll4_ck", &dpll4_ck_core, 0x0,
428 OMAP_CM_REGADDR(OMAP3430_CAM_MOD, CM_CLKSEL), 428 OMAP_CM_REGADDR(OMAP3430_CAM_MOD, CM_CLKSEL),
429 OMAP3430_CLKSEL_CAM_SHIFT, OMAP3630_CLKSEL_CAM_WIDTH, 429 OMAP3430_CLKSEL_CAM_SHIFT, OMAP3630_CLKSEL_CAM_WIDTH,
430 CLK_DIVIDER_ONE_BASED, NULL); 430 CLK_DIVIDER_ONE_BASED, NULL);
@@ -466,7 +466,7 @@ static struct clk_hw_omap dpll4_m5x2_ck_hw = {
466DEFINE_STRUCT_CLK_FLAGS(dpll4_m5x2_ck, dpll4_m5x2_ck_parent_names, 466DEFINE_STRUCT_CLK_FLAGS(dpll4_m5x2_ck, dpll4_m5x2_ck_parent_names,
467 dpll4_m5x2_ck_ops, CLK_SET_RATE_PARENT); 467 dpll4_m5x2_ck_ops, CLK_SET_RATE_PARENT);
468 468
469static struct clk dpll4_m5x2_ck_3630 = { 469static struct clk_core dpll4_m5x2_ck_3630_core = {
470 .name = "dpll4_m5x2_ck", 470 .name = "dpll4_m5x2_ck",
471 .hw = &dpll4_m5x2_ck_hw.hw, 471 .hw = &dpll4_m5x2_ck_hw.hw,
472 .parent_names = dpll4_m5x2_ck_parent_names, 472 .parent_names = dpll4_m5x2_ck_parent_names,
@@ -475,6 +475,10 @@ static struct clk dpll4_m5x2_ck_3630 = {
475 .flags = CLK_SET_RATE_PARENT, 475 .flags = CLK_SET_RATE_PARENT,
476}; 476};
477 477
478static struct clk dpll4_m5x2_ck_3630 = {
479 .core = &dpll4_m5x2_ck_3630_core,
480};
481
478static struct clk cam_mclk; 482static struct clk cam_mclk;
479 483
480static const char *cam_mclk_parent_names[] = { 484static const char *cam_mclk_parent_names[] = {
@@ -490,7 +494,7 @@ static struct clk_hw_omap cam_mclk_hw = {
490 .clkdm_name = "cam_clkdm", 494 .clkdm_name = "cam_clkdm",
491}; 495};
492 496
493static struct clk cam_mclk = { 497static struct clk_core cam_mclk_core = {
494 .name = "cam_mclk", 498 .name = "cam_mclk",
495 .hw = &cam_mclk_hw.hw, 499 .hw = &cam_mclk_hw.hw,
496 .parent_names = cam_mclk_parent_names, 500 .parent_names = cam_mclk_parent_names,
@@ -499,6 +503,10 @@ static struct clk cam_mclk = {
499 .flags = CLK_SET_RATE_PARENT, 503 .flags = CLK_SET_RATE_PARENT,
500}; 504};
501 505
506static struct clk cam_mclk = {
507 .core = &cam_mclk_core,
508};
509
502static const struct clksel_rate clkout2_src_core_rates[] = { 510static const struct clksel_rate clkout2_src_core_rates[] = {
503 { .div = 1, .val = 0, .flags = RATE_IN_3XXX }, 511 { .div = 1, .val = 0, .flags = RATE_IN_3XXX },
504 { .div = 0 } 512 { .div = 0 }
@@ -514,7 +522,7 @@ static const struct clksel_rate clkout2_src_96m_rates[] = {
514 { .div = 0 } 522 { .div = 0 }
515}; 523};
516 524
517DEFINE_CLK_DIVIDER(dpll4_m2_ck, "dpll4_ck", &dpll4_ck, 0x0, 525DEFINE_CLK_DIVIDER(dpll4_m2_ck, "dpll4_ck", &dpll4_ck_core, 0x0,
518 OMAP_CM_REGADDR(PLL_MOD, OMAP3430_CM_CLKSEL3), 526 OMAP_CM_REGADDR(PLL_MOD, OMAP3430_CM_CLKSEL3),
519 OMAP3430_DIV_96M_SHIFT, OMAP3630_DIV_96M_WIDTH, 527 OMAP3430_DIV_96M_SHIFT, OMAP3630_DIV_96M_WIDTH,
520 CLK_DIVIDER_ONE_BASED, NULL); 528 CLK_DIVIDER_ONE_BASED, NULL);
@@ -538,7 +546,7 @@ static struct clk_hw_omap dpll4_m2x2_ck_hw = {
538 546
539DEFINE_STRUCT_CLK(dpll4_m2x2_ck, dpll4_m2x2_ck_parent_names, dpll4_m5x2_ck_ops); 547DEFINE_STRUCT_CLK(dpll4_m2x2_ck, dpll4_m2x2_ck_parent_names, dpll4_m5x2_ck_ops);
540 548
541static struct clk dpll4_m2x2_ck_3630 = { 549static struct clk_core dpll4_m2x2_ck_3630_core = {
542 .name = "dpll4_m2x2_ck", 550 .name = "dpll4_m2x2_ck",
543 .hw = &dpll4_m2x2_ck_hw.hw, 551 .hw = &dpll4_m2x2_ck_hw.hw,
544 .parent_names = dpll4_m2x2_ck_parent_names, 552 .parent_names = dpll4_m2x2_ck_parent_names,
@@ -546,6 +554,10 @@ static struct clk dpll4_m2x2_ck_3630 = {
546 .ops = &dpll4_m5x2_ck_3630_ops, 554 .ops = &dpll4_m5x2_ck_3630_ops,
547}; 555};
548 556
557static struct clk dpll4_m2x2_ck_3630 = {
558 .core = &dpll4_m2x2_ck_3630_core,
559};
560
549static struct clk omap_96m_alwon_fck; 561static struct clk omap_96m_alwon_fck;
550 562
551static const char *omap_96m_alwon_fck_parent_names[] = { 563static const char *omap_96m_alwon_fck_parent_names[] = {
@@ -570,7 +582,7 @@ static const struct clksel_rate clkout2_src_54m_rates[] = {
570 { .div = 0 } 582 { .div = 0 }
571}; 583};
572 584
573DEFINE_CLK_DIVIDER_TABLE(dpll4_m3_ck, "dpll4_ck", &dpll4_ck, 0x0, 585DEFINE_CLK_DIVIDER_TABLE(dpll4_m3_ck, "dpll4_ck", &dpll4_ck_core, 0x0,
574 OMAP_CM_REGADDR(OMAP3430_DSS_MOD, CM_CLKSEL), 586 OMAP_CM_REGADDR(OMAP3430_DSS_MOD, CM_CLKSEL),
575 OMAP3430_CLKSEL_TV_SHIFT, OMAP3630_CLKSEL_TV_WIDTH, 587 OMAP3430_CLKSEL_TV_SHIFT, OMAP3630_CLKSEL_TV_WIDTH,
576 0, dpll4_mx_ck_div_table, NULL); 588 0, dpll4_mx_ck_div_table, NULL);
@@ -594,7 +606,7 @@ static struct clk_hw_omap dpll4_m3x2_ck_hw = {
594 606
595DEFINE_STRUCT_CLK(dpll4_m3x2_ck, dpll4_m3x2_ck_parent_names, dpll4_m5x2_ck_ops); 607DEFINE_STRUCT_CLK(dpll4_m3x2_ck, dpll4_m3x2_ck_parent_names, dpll4_m5x2_ck_ops);
596 608
597static struct clk dpll4_m3x2_ck_3630 = { 609static struct clk_core dpll4_m3x2_ck_3630_core = {
598 .name = "dpll4_m3x2_ck", 610 .name = "dpll4_m3x2_ck",
599 .hw = &dpll4_m3x2_ck_hw.hw, 611 .hw = &dpll4_m3x2_ck_hw.hw,
600 .parent_names = dpll4_m3x2_ck_parent_names, 612 .parent_names = dpll4_m3x2_ck_parent_names,
@@ -602,6 +614,10 @@ static struct clk dpll4_m3x2_ck_3630 = {
602 .ops = &dpll4_m5x2_ck_3630_ops, 614 .ops = &dpll4_m5x2_ck_3630_ops,
603}; 615};
604 616
617static struct clk dpll4_m3x2_ck_3630 = {
618 .core = &dpll4_m3x2_ck_3630_core,
619};
620
605static const char *omap_54m_fck_parent_names[] = { 621static const char *omap_54m_fck_parent_names[] = {
606 "dpll4_m3x2_ck", "sys_altclk", 622 "dpll4_m3x2_ck", "sys_altclk",
607}; 623};
@@ -677,7 +693,8 @@ static struct clk_hw_omap omap_48m_fck_hw = {
677 693
678DEFINE_STRUCT_CLK(omap_48m_fck, omap_48m_fck_parent_names, omap_48m_fck_ops); 694DEFINE_STRUCT_CLK(omap_48m_fck, omap_48m_fck_parent_names, omap_48m_fck_ops);
679 695
680DEFINE_CLK_FIXED_FACTOR(omap_12m_fck, "omap_48m_fck", &omap_48m_fck, 0x0, 1, 4); 696DEFINE_CLK_FIXED_FACTOR(omap_12m_fck, "omap_48m_fck", &omap_48m_fck_core, 0x0,
697 1, 4);
681 698
682static struct clk core_12m_fck; 699static struct clk core_12m_fck;
683 700
@@ -723,7 +740,8 @@ static const char *core_l3_ick_parent_names[] = {
723DEFINE_STRUCT_CLK_HW_OMAP(core_l3_ick, "core_l3_clkdm"); 740DEFINE_STRUCT_CLK_HW_OMAP(core_l3_ick, "core_l3_clkdm");
724DEFINE_STRUCT_CLK(core_l3_ick, core_l3_ick_parent_names, core_l4_ick_ops); 741DEFINE_STRUCT_CLK(core_l3_ick, core_l3_ick_parent_names, core_l4_ick_ops);
725 742
726DEFINE_CLK_FIXED_FACTOR(dpll3_m2x2_ck, "dpll3_m2_ck", &dpll3_m2_ck, 0x0, 2, 1); 743DEFINE_CLK_FIXED_FACTOR(dpll3_m2x2_ck, "dpll3_m2_ck", &dpll3_m2_ck_core, 0x0,
744 2, 1);
727 745
728static struct clk corex2_fck; 746static struct clk corex2_fck;
729 747
@@ -809,7 +827,7 @@ static struct clk_hw_omap des2_ick_hw = {
809 827
810DEFINE_STRUCT_CLK(des2_ick, aes2_ick_parent_names, aes2_ick_ops); 828DEFINE_STRUCT_CLK(des2_ick, aes2_ick_parent_names, aes2_ick_ops);
811 829
812DEFINE_CLK_DIVIDER(dpll1_fck, "core_ck", &core_ck, 0x0, 830DEFINE_CLK_DIVIDER(dpll1_fck, "core_ck", &core_ck_core, 0x0,
813 OMAP_CM_REGADDR(MPU_MOD, OMAP3430_CM_CLKSEL1_PLL), 831 OMAP_CM_REGADDR(MPU_MOD, OMAP3430_CM_CLKSEL1_PLL),
814 OMAP3430_MPU_CLK_SRC_SHIFT, OMAP3430_MPU_CLK_SRC_WIDTH, 832 OMAP3430_MPU_CLK_SRC_SHIFT, OMAP3430_MPU_CLK_SRC_WIDTH,
815 CLK_DIVIDER_ONE_BASED, NULL); 833 CLK_DIVIDER_ONE_BASED, NULL);
@@ -852,18 +870,18 @@ static struct clk_hw_omap dpll2_ck_hw = {
852 870
853DEFINE_STRUCT_CLK(dpll2_ck, dpll3_ck_parent_names, dpll1_ck_ops); 871DEFINE_STRUCT_CLK(dpll2_ck, dpll3_ck_parent_names, dpll1_ck_ops);
854 872
855DEFINE_CLK_DIVIDER(dpll2_fck, "core_ck", &core_ck, 0x0, 873DEFINE_CLK_DIVIDER(dpll2_fck, "core_ck", &core_ck_core, 0x0,
856 OMAP_CM_REGADDR(OMAP3430_IVA2_MOD, OMAP3430_CM_CLKSEL1_PLL), 874 OMAP_CM_REGADDR(OMAP3430_IVA2_MOD, OMAP3430_CM_CLKSEL1_PLL),
857 OMAP3430_IVA2_CLK_SRC_SHIFT, OMAP3430_IVA2_CLK_SRC_WIDTH, 875 OMAP3430_IVA2_CLK_SRC_SHIFT, OMAP3430_IVA2_CLK_SRC_WIDTH,
858 CLK_DIVIDER_ONE_BASED, NULL); 876 CLK_DIVIDER_ONE_BASED, NULL);
859 877
860DEFINE_CLK_DIVIDER(dpll2_m2_ck, "dpll2_ck", &dpll2_ck, 0x0, 878DEFINE_CLK_DIVIDER(dpll2_m2_ck, "dpll2_ck", &dpll2_ck_core, 0x0,
861 OMAP_CM_REGADDR(OMAP3430_IVA2_MOD, OMAP3430_CM_CLKSEL2_PLL), 879 OMAP_CM_REGADDR(OMAP3430_IVA2_MOD, OMAP3430_CM_CLKSEL2_PLL),
862 OMAP3430_IVA2_DPLL_CLKOUT_DIV_SHIFT, 880 OMAP3430_IVA2_DPLL_CLKOUT_DIV_SHIFT,
863 OMAP3430_IVA2_DPLL_CLKOUT_DIV_WIDTH, 881 OMAP3430_IVA2_DPLL_CLKOUT_DIV_WIDTH,
864 CLK_DIVIDER_ONE_BASED, NULL); 882 CLK_DIVIDER_ONE_BASED, NULL);
865 883
866DEFINE_CLK_DIVIDER(dpll3_m3_ck, "dpll3_ck", &dpll3_ck, 0x0, 884DEFINE_CLK_DIVIDER(dpll3_m3_ck, "dpll3_ck", &dpll3_ck_core, 0x0,
867 OMAP_CM_REGADDR(OMAP3430_EMU_MOD, CM_CLKSEL1), 885 OMAP_CM_REGADDR(OMAP3430_EMU_MOD, CM_CLKSEL1),
868 OMAP3430_DIV_DPLL3_SHIFT, OMAP3430_DIV_DPLL3_WIDTH, 886 OMAP3430_DIV_DPLL3_SHIFT, OMAP3430_DIV_DPLL3_WIDTH,
869 CLK_DIVIDER_ONE_BASED, NULL); 887 CLK_DIVIDER_ONE_BASED, NULL);
@@ -887,7 +905,7 @@ static struct clk_hw_omap dpll3_m3x2_ck_hw = {
887 905
888DEFINE_STRUCT_CLK(dpll3_m3x2_ck, dpll3_m3x2_ck_parent_names, dpll4_m5x2_ck_ops); 906DEFINE_STRUCT_CLK(dpll3_m3x2_ck, dpll3_m3x2_ck_parent_names, dpll4_m5x2_ck_ops);
889 907
890static struct clk dpll3_m3x2_ck_3630 = { 908static struct clk_core dpll3_m3x2_ck_3630_core = {
891 .name = "dpll3_m3x2_ck", 909 .name = "dpll3_m3x2_ck",
892 .hw = &dpll3_m3x2_ck_hw.hw, 910 .hw = &dpll3_m3x2_ck_hw.hw,
893 .parent_names = dpll3_m3x2_ck_parent_names, 911 .parent_names = dpll3_m3x2_ck_parent_names,
@@ -895,9 +913,13 @@ static struct clk dpll3_m3x2_ck_3630 = {
895 .ops = &dpll4_m5x2_ck_3630_ops, 913 .ops = &dpll4_m5x2_ck_3630_ops,
896}; 914};
897 915
898DEFINE_CLK_FIXED_FACTOR(dpll3_x2_ck, "dpll3_ck", &dpll3_ck, 0x0, 2, 1); 916static struct clk dpll3_m3x2_ck_3630 = {
917 .core = &dpll3_m3x2_ck_3630_core,
918};
919
920DEFINE_CLK_FIXED_FACTOR(dpll3_x2_ck, "dpll3_ck", &dpll3_ck_core, 0x0, 2, 1);
899 921
900DEFINE_CLK_DIVIDER_TABLE(dpll4_m4_ck, "dpll4_ck", &dpll4_ck, 0x0, 922DEFINE_CLK_DIVIDER_TABLE(dpll4_m4_ck, "dpll4_ck", &dpll4_ck_core, 0x0,
901 OMAP_CM_REGADDR(OMAP3430_DSS_MOD, CM_CLKSEL), 923 OMAP_CM_REGADDR(OMAP3430_DSS_MOD, CM_CLKSEL),
902 OMAP3430_CLKSEL_DSS1_SHIFT, OMAP3630_CLKSEL_DSS1_WIDTH, 924 OMAP3430_CLKSEL_DSS1_SHIFT, OMAP3630_CLKSEL_DSS1_WIDTH,
903 0, dpll4_mx_ck_div_table, NULL); 925 0, dpll4_mx_ck_div_table, NULL);
@@ -922,7 +944,7 @@ static struct clk_hw_omap dpll4_m4x2_ck_hw = {
922DEFINE_STRUCT_CLK_FLAGS(dpll4_m4x2_ck, dpll4_m4x2_ck_parent_names, 944DEFINE_STRUCT_CLK_FLAGS(dpll4_m4x2_ck, dpll4_m4x2_ck_parent_names,
923 dpll4_m5x2_ck_ops, CLK_SET_RATE_PARENT); 945 dpll4_m5x2_ck_ops, CLK_SET_RATE_PARENT);
924 946
925static struct clk dpll4_m4x2_ck_3630 = { 947static struct clk_core dpll4_m4x2_ck_3630_core = {
926 .name = "dpll4_m4x2_ck", 948 .name = "dpll4_m4x2_ck",
927 .hw = &dpll4_m4x2_ck_hw.hw, 949 .hw = &dpll4_m4x2_ck_hw.hw,
928 .parent_names = dpll4_m4x2_ck_parent_names, 950 .parent_names = dpll4_m4x2_ck_parent_names,
@@ -931,7 +953,11 @@ static struct clk dpll4_m4x2_ck_3630 = {
931 .flags = CLK_SET_RATE_PARENT, 953 .flags = CLK_SET_RATE_PARENT,
932}; 954};
933 955
934DEFINE_CLK_DIVIDER(dpll4_m6_ck, "dpll4_ck", &dpll4_ck, 0x0, 956static struct clk dpll4_m4x2_ck_3630 = {
957 .core = &dpll4_m4x2_ck_3630_core,
958};
959
960DEFINE_CLK_DIVIDER(dpll4_m6_ck, "dpll4_ck", &dpll4_ck_core, 0x0,
935 OMAP_CM_REGADDR(OMAP3430_EMU_MOD, CM_CLKSEL1), 961 OMAP_CM_REGADDR(OMAP3430_EMU_MOD, CM_CLKSEL1),
936 OMAP3430_DIV_DPLL4_SHIFT, OMAP3630_DIV_DPLL4_WIDTH, 962 OMAP3430_DIV_DPLL4_SHIFT, OMAP3630_DIV_DPLL4_WIDTH,
937 CLK_DIVIDER_ONE_BASED, NULL); 963 CLK_DIVIDER_ONE_BASED, NULL);
@@ -955,7 +981,7 @@ static struct clk_hw_omap dpll4_m6x2_ck_hw = {
955 981
956DEFINE_STRUCT_CLK(dpll4_m6x2_ck, dpll4_m6x2_ck_parent_names, dpll4_m5x2_ck_ops); 982DEFINE_STRUCT_CLK(dpll4_m6x2_ck, dpll4_m6x2_ck_parent_names, dpll4_m5x2_ck_ops);
957 983
958static struct clk dpll4_m6x2_ck_3630 = { 984static struct clk_core dpll4_m6x2_ck_3630_core = {
959 .name = "dpll4_m6x2_ck", 985 .name = "dpll4_m6x2_ck",
960 .hw = &dpll4_m6x2_ck_hw.hw, 986 .hw = &dpll4_m6x2_ck_hw.hw,
961 .parent_names = dpll4_m6x2_ck_parent_names, 987 .parent_names = dpll4_m6x2_ck_parent_names,
@@ -963,7 +989,11 @@ static struct clk dpll4_m6x2_ck_3630 = {
963 .ops = &dpll4_m5x2_ck_3630_ops, 989 .ops = &dpll4_m5x2_ck_3630_ops,
964}; 990};
965 991
966DEFINE_CLK_FIXED_FACTOR(dpll4_x2_ck, "dpll4_ck", &dpll4_ck, 0x0, 2, 1); 992static struct clk dpll4_m6x2_ck_3630 = {
993 .core = &dpll4_m6x2_ck_3630_core,
994};
995
996DEFINE_CLK_FIXED_FACTOR(dpll4_x2_ck, "dpll4_ck", &dpll4_ck_core, 0x0, 2, 1);
967 997
968static struct dpll_data dpll5_dd = { 998static struct dpll_data dpll5_dd = {
969 .mult_div1_reg = OMAP_CM_REGADDR(PLL_MOD, OMAP3430ES2_CM_CLKSEL4), 999 .mult_div1_reg = OMAP_CM_REGADDR(PLL_MOD, OMAP3430ES2_CM_CLKSEL4),
@@ -1000,7 +1030,7 @@ static struct clk_hw_omap dpll5_ck_hw = {
1000 1030
1001DEFINE_STRUCT_CLK(dpll5_ck, dpll3_ck_parent_names, dpll1_ck_ops); 1031DEFINE_STRUCT_CLK(dpll5_ck, dpll3_ck_parent_names, dpll1_ck_ops);
1002 1032
1003DEFINE_CLK_DIVIDER(dpll5_m2_ck, "dpll5_ck", &dpll5_ck, 0x0, 1033DEFINE_CLK_DIVIDER(dpll5_m2_ck, "dpll5_ck", &dpll5_ck_core, 0x0,
1004 OMAP_CM_REGADDR(PLL_MOD, OMAP3430ES2_CM_CLKSEL5), 1034 OMAP_CM_REGADDR(PLL_MOD, OMAP3430ES2_CM_CLKSEL5),
1005 OMAP3430ES2_DIV_120M_SHIFT, OMAP3430ES2_DIV_120M_WIDTH, 1035 OMAP3430ES2_DIV_120M_SHIFT, OMAP3430ES2_DIV_120M_WIDTH,
1006 CLK_DIVIDER_ONE_BASED, NULL); 1036 CLK_DIVIDER_ONE_BASED, NULL);
@@ -1247,7 +1277,7 @@ static struct clk_hw_omap emu_src_ck_hw = {
1247 1277
1248DEFINE_STRUCT_CLK(emu_src_ck, emu_src_ck_parent_names, emu_src_ck_ops); 1278DEFINE_STRUCT_CLK(emu_src_ck, emu_src_ck_parent_names, emu_src_ck_ops);
1249 1279
1250DEFINE_CLK_DIVIDER(atclk_fck, "emu_src_ck", &emu_src_ck, 0x0, 1280DEFINE_CLK_DIVIDER(atclk_fck, "emu_src_ck", &emu_src_ck_core, 0x0,
1251 OMAP_CM_REGADDR(OMAP3430_EMU_MOD, CM_CLKSEL1), 1281 OMAP_CM_REGADDR(OMAP3430_EMU_MOD, CM_CLKSEL1),
1252 OMAP3430_CLKSEL_ATCLK_SHIFT, OMAP3430_CLKSEL_ATCLK_WIDTH, 1282 OMAP3430_CLKSEL_ATCLK_SHIFT, OMAP3430_CLKSEL_ATCLK_WIDTH,
1253 CLK_DIVIDER_ONE_BASED, NULL); 1283 CLK_DIVIDER_ONE_BASED, NULL);
@@ -1298,7 +1328,7 @@ static struct clk_hw_omap gfx_l3_ck_hw = {
1298 1328
1299DEFINE_STRUCT_CLK(gfx_l3_ck, core_l3_ick_parent_names, aes1_ick_ops); 1329DEFINE_STRUCT_CLK(gfx_l3_ck, core_l3_ick_parent_names, aes1_ick_ops);
1300 1330
1301DEFINE_CLK_DIVIDER(gfx_l3_fck, "l3_ick", &l3_ick, 0x0, 1331DEFINE_CLK_DIVIDER(gfx_l3_fck, "l3_ick", &l3_ick_core, 0x0,
1302 OMAP_CM_REGADDR(GFX_MOD, CM_CLKSEL), 1332 OMAP_CM_REGADDR(GFX_MOD, CM_CLKSEL),
1303 OMAP_CLKSEL_GFX_SHIFT, OMAP_CLKSEL_GFX_WIDTH, 1333 OMAP_CLKSEL_GFX_SHIFT, OMAP_CLKSEL_GFX_WIDTH,
1304 CLK_DIVIDER_ONE_BASED, NULL); 1334 CLK_DIVIDER_ONE_BASED, NULL);
@@ -2498,7 +2528,7 @@ static struct clk_hw_omap omap_96m_alwon_fck_3630_hw = {
2498 .clksel_mask = OMAP3630_CLKSEL_96M_MASK, 2528 .clksel_mask = OMAP3630_CLKSEL_96M_MASK,
2499}; 2529};
2500 2530
2501static struct clk omap_96m_alwon_fck_3630 = { 2531static struct clk_core omap_96m_alwon_fck_3630_core = {
2502 .name = "omap_96m_alwon_fck", 2532 .name = "omap_96m_alwon_fck",
2503 .hw = &omap_96m_alwon_fck_3630_hw.hw, 2533 .hw = &omap_96m_alwon_fck_3630_hw.hw,
2504 .parent_names = omap_96m_alwon_fck_3630_parent_names, 2534 .parent_names = omap_96m_alwon_fck_3630_parent_names,
@@ -2506,6 +2536,10 @@ static struct clk omap_96m_alwon_fck_3630 = {
2506 .ops = &omap_96m_alwon_fck_3630_ops, 2536 .ops = &omap_96m_alwon_fck_3630_ops,
2507}; 2537};
2508 2538
2539static struct clk omap_96m_alwon_fck_3630 = {
2540 .core = &omap_96m_alwon_fck_3630_core,
2541};
2542
2509static struct clk omapctrl_ick; 2543static struct clk omapctrl_ick;
2510 2544
2511static struct clk_hw_omap omapctrl_ick_hw = { 2545static struct clk_hw_omap omapctrl_ick_hw = {
@@ -2521,12 +2555,12 @@ static struct clk_hw_omap omapctrl_ick_hw = {
2521 2555
2522DEFINE_STRUCT_CLK(omapctrl_ick, aes2_ick_parent_names, aes2_ick_ops); 2556DEFINE_STRUCT_CLK(omapctrl_ick, aes2_ick_parent_names, aes2_ick_ops);
2523 2557
2524DEFINE_CLK_DIVIDER(pclk_fck, "emu_src_ck", &emu_src_ck, 0x0, 2558DEFINE_CLK_DIVIDER(pclk_fck, "emu_src_ck", &emu_src_ck_core, 0x0,
2525 OMAP_CM_REGADDR(OMAP3430_EMU_MOD, CM_CLKSEL1), 2559 OMAP_CM_REGADDR(OMAP3430_EMU_MOD, CM_CLKSEL1),
2526 OMAP3430_CLKSEL_PCLK_SHIFT, OMAP3430_CLKSEL_PCLK_WIDTH, 2560 OMAP3430_CLKSEL_PCLK_SHIFT, OMAP3430_CLKSEL_PCLK_WIDTH,
2527 CLK_DIVIDER_ONE_BASED, NULL); 2561 CLK_DIVIDER_ONE_BASED, NULL);
2528 2562
2529DEFINE_CLK_DIVIDER(pclkx2_fck, "emu_src_ck", &emu_src_ck, 0x0, 2563DEFINE_CLK_DIVIDER(pclkx2_fck, "emu_src_ck", &emu_src_ck_core, 0x0,
2530 OMAP_CM_REGADDR(OMAP3430_EMU_MOD, CM_CLKSEL1), 2564 OMAP_CM_REGADDR(OMAP3430_EMU_MOD, CM_CLKSEL1),
2531 OMAP3430_CLKSEL_PCLKX2_SHIFT, OMAP3430_CLKSEL_PCLKX2_WIDTH, 2565 OMAP3430_CLKSEL_PCLKX2_SHIFT, OMAP3430_CLKSEL_PCLKX2_WIDTH,
2532 CLK_DIVIDER_ONE_BASED, NULL); 2566 CLK_DIVIDER_ONE_BASED, NULL);
@@ -2558,7 +2592,7 @@ static struct clk_hw_omap pka_ick_hw = {
2558 2592
2559DEFINE_STRUCT_CLK(pka_ick, pka_ick_parent_names, aes1_ick_ops); 2593DEFINE_STRUCT_CLK(pka_ick, pka_ick_parent_names, aes1_ick_ops);
2560 2594
2561DEFINE_CLK_DIVIDER(rm_ick, "l4_ick", &l4_ick, 0x0, 2595DEFINE_CLK_DIVIDER(rm_ick, "l4_ick", &l4_ick_core, 0x0,
2562 OMAP_CM_REGADDR(WKUP_MOD, CM_CLKSEL), 2596 OMAP_CM_REGADDR(WKUP_MOD, CM_CLKSEL),
2563 OMAP3430_CLKSEL_RM_SHIFT, OMAP3430_CLKSEL_RM_WIDTH, 2597 OMAP3430_CLKSEL_RM_SHIFT, OMAP3430_CLKSEL_RM_WIDTH,
2564 CLK_DIVIDER_ONE_BASED, NULL); 2598 CLK_DIVIDER_ONE_BASED, NULL);
@@ -2819,10 +2853,10 @@ DEFINE_CLK_OMAP_MUX_GATE(ssi_ssr_fck_3430es2, "core_l4_clkdm",
2819 ssi_ssr_fck_3430es1_ops); 2853 ssi_ssr_fck_3430es1_ops);
2820 2854
2821DEFINE_CLK_FIXED_FACTOR(ssi_sst_fck_3430es1, "ssi_ssr_fck_3430es1", 2855DEFINE_CLK_FIXED_FACTOR(ssi_sst_fck_3430es1, "ssi_ssr_fck_3430es1",
2822 &ssi_ssr_fck_3430es1, 0x0, 1, 2); 2856 &ssi_ssr_fck_3430es1_core, 0x0, 1, 2);
2823 2857
2824DEFINE_CLK_FIXED_FACTOR(ssi_sst_fck_3430es2, "ssi_ssr_fck_3430es2", 2858DEFINE_CLK_FIXED_FACTOR(ssi_sst_fck_3430es2, "ssi_ssr_fck_3430es2",
2825 &ssi_ssr_fck_3430es2, 0x0, 1, 2); 2859 &ssi_ssr_fck_3430es2_core, 0x0, 1, 2);
2826 2860
2827static struct clk sys_clkout1; 2861static struct clk sys_clkout1;
2828 2862
@@ -2840,7 +2874,7 @@ static struct clk_hw_omap sys_clkout1_hw = {
2840 2874
2841DEFINE_STRUCT_CLK(sys_clkout1, sys_clkout1_parent_names, aes1_ick_ops); 2875DEFINE_STRUCT_CLK(sys_clkout1, sys_clkout1_parent_names, aes1_ick_ops);
2842 2876
2843DEFINE_CLK_DIVIDER(sys_clkout2, "clkout2_src_ck", &clkout2_src_ck, 0x0, 2877DEFINE_CLK_DIVIDER(sys_clkout2, "clkout2_src_ck", &clkout2_src_ck_core, 0x0,
2844 OMAP3430_CM_CLKOUT_CTRL, OMAP3430_CLKOUT2_DIV_SHIFT, 2878 OMAP3430_CM_CLKOUT_CTRL, OMAP3430_CLKOUT2_DIV_SHIFT,
2845 OMAP3430_CLKOUT2_DIV_WIDTH, CLK_DIVIDER_POWER_OF_TWO, NULL); 2879 OMAP3430_CLKOUT2_DIV_WIDTH, CLK_DIVIDER_POWER_OF_TWO, NULL);
2846 2880
@@ -2849,7 +2883,8 @@ DEFINE_CLK_MUX(traceclk_src_fck, emu_src_ck_parent_names, NULL, 0x0,
2849 OMAP3430_TRACE_MUX_CTRL_SHIFT, OMAP3430_TRACE_MUX_CTRL_WIDTH, 2883 OMAP3430_TRACE_MUX_CTRL_SHIFT, OMAP3430_TRACE_MUX_CTRL_WIDTH,
2850 0x0, NULL); 2884 0x0, NULL);
2851 2885
2852DEFINE_CLK_DIVIDER(traceclk_fck, "traceclk_src_fck", &traceclk_src_fck, 0x0, 2886DEFINE_CLK_DIVIDER(traceclk_fck, "traceclk_src_fck", &traceclk_src_fck_core,
2887 0x0,
2853 OMAP_CM_REGADDR(OMAP3430_EMU_MOD, CM_CLKSEL1), 2888 OMAP_CM_REGADDR(OMAP3430_EMU_MOD, CM_CLKSEL1),
2854 OMAP3430_CLKSEL_TRACECLK_SHIFT, 2889 OMAP3430_CLKSEL_TRACECLK_SHIFT,
2855 OMAP3430_CLKSEL_TRACECLK_WIDTH, CLK_DIVIDER_ONE_BASED, NULL); 2890 OMAP3430_CLKSEL_TRACECLK_WIDTH, CLK_DIVIDER_ONE_BASED, NULL);
diff --git a/arch/arm/mach-omap2/clock.h b/arch/arm/mach-omap2/clock.h
index a4282e79143e..c5b3a7f3e41d 100644
--- a/arch/arm/mach-omap2/clock.h
+++ b/arch/arm/mach-omap2/clock.h
@@ -40,23 +40,29 @@ struct omap_clk {
40struct clockdomain; 40struct clockdomain;
41 41
42#define DEFINE_STRUCT_CLK(_name, _parent_array_name, _clkops_name) \ 42#define DEFINE_STRUCT_CLK(_name, _parent_array_name, _clkops_name) \
43 static struct clk _name = { \ 43 static struct clk_core _name##_core = { \
44 .name = #_name, \ 44 .name = #_name, \
45 .hw = &_name##_hw.hw, \ 45 .hw = &_name##_hw.hw, \
46 .parent_names = _parent_array_name, \ 46 .parent_names = _parent_array_name, \
47 .num_parents = ARRAY_SIZE(_parent_array_name), \ 47 .num_parents = ARRAY_SIZE(_parent_array_name), \
48 .ops = &_clkops_name, \ 48 .ops = &_clkops_name, \
49 }; \
50 static struct clk _name = { \
51 .core = &_name##_core, \
49 }; 52 };
50 53
51#define DEFINE_STRUCT_CLK_FLAGS(_name, _parent_array_name, \ 54#define DEFINE_STRUCT_CLK_FLAGS(_name, _parent_array_name, \
52 _clkops_name, _flags) \ 55 _clkops_name, _flags) \
53 static struct clk _name = { \ 56 static struct clk_core _name##_core = { \
54 .name = #_name, \ 57 .name = #_name, \
55 .hw = &_name##_hw.hw, \ 58 .hw = &_name##_hw.hw, \
56 .parent_names = _parent_array_name, \ 59 .parent_names = _parent_array_name, \
57 .num_parents = ARRAY_SIZE(_parent_array_name), \ 60 .num_parents = ARRAY_SIZE(_parent_array_name), \
58 .ops = &_clkops_name, \ 61 .ops = &_clkops_name, \
59 .flags = _flags, \ 62 .flags = _flags, \
63 }; \
64 static struct clk _name = { \
65 .core = &_name##_core, \
60 }; 66 };
61 67
62#define DEFINE_STRUCT_CLK_HW_OMAP(_name, _clkdm_name) \ 68#define DEFINE_STRUCT_CLK_HW_OMAP(_name, _clkdm_name) \
@@ -248,6 +254,7 @@ extern const struct clksel_rate gpt_32k_rates[];
248extern const struct clksel_rate gpt_sys_rates[]; 254extern const struct clksel_rate gpt_sys_rates[];
249extern const struct clksel_rate gfx_l3_rates[]; 255extern const struct clksel_rate gfx_l3_rates[];
250extern const struct clksel_rate dsp_ick_rates[]; 256extern const struct clksel_rate dsp_ick_rates[];
257extern struct clk_core dummy_ck_core;
251extern struct clk dummy_ck; 258extern struct clk dummy_ck;
252 259
253extern const struct clk_hw_omap_ops clkhwops_iclk_wait; 260extern const struct clk_hw_omap_ops clkhwops_iclk_wait;
diff --git a/arch/arm/mach-omap2/clock_common_data.c b/arch/arm/mach-omap2/clock_common_data.c
index ef4d21bfb964..febd0a279224 100644
--- a/arch/arm/mach-omap2/clock_common_data.c
+++ b/arch/arm/mach-omap2/clock_common_data.c
@@ -119,8 +119,11 @@ const struct clksel_rate div31_1to31_rates[] = {
119 119
120static struct clk_ops dummy_ck_ops = {}; 120static struct clk_ops dummy_ck_ops = {};
121 121
122struct clk dummy_ck = { 122struct clk_core dummy_ck_core = {
123 .name = "dummy_clk", 123 .name = "dummy_clk",
124 .ops = &dummy_ck_ops, 124 .ops = &dummy_ck_ops,
125 .flags = CLK_IS_BASIC, 125 .flags = CLK_IS_BASIC,
126}; 126};
127struct clk dummy_ck = {
128 .core = &dummy_ck_core,
129};
diff --git a/arch/arm/mach-omap2/dpll3xxx.c b/arch/arm/mach-omap2/dpll3xxx.c
index c2da2a0fe5ad..49752d77f5bc 100644
--- a/arch/arm/mach-omap2/dpll3xxx.c
+++ b/arch/arm/mach-omap2/dpll3xxx.c
@@ -410,7 +410,7 @@ int omap3_noncore_dpll_enable(struct clk_hw *hw)
410 struct clk_hw_omap *clk = to_clk_hw_omap(hw); 410 struct clk_hw_omap *clk = to_clk_hw_omap(hw);
411 int r; 411 int r;
412 struct dpll_data *dd; 412 struct dpll_data *dd;
413 struct clk *parent; 413 struct clk_hw *parent;
414 414
415 dd = clk->dpll_data; 415 dd = clk->dpll_data;
416 if (!dd) 416 if (!dd)
@@ -427,13 +427,13 @@ int omap3_noncore_dpll_enable(struct clk_hw *hw)
427 } 427 }
428 } 428 }
429 429
430 parent = __clk_get_parent(hw->clk); 430 parent = __clk_get_hw(__clk_get_parent(hw->clk));
431 431
432 if (__clk_get_rate(hw->clk) == __clk_get_rate(dd->clk_bypass)) { 432 if (__clk_get_rate(hw->clk) == __clk_get_rate(dd->clk_bypass)) {
433 WARN_ON(parent != dd->clk_bypass); 433 WARN_ON(parent != __clk_get_hw(dd->clk_bypass));
434 r = _omap3_noncore_dpll_bypass(clk); 434 r = _omap3_noncore_dpll_bypass(clk);
435 } else { 435 } else {
436 WARN_ON(parent != dd->clk_ref); 436 WARN_ON(parent != __clk_get_hw(dd->clk_ref));
437 r = _omap3_noncore_dpll_lock(clk); 437 r = _omap3_noncore_dpll_lock(clk);
438 } 438 }
439 439
@@ -549,7 +549,8 @@ int omap3_noncore_dpll_set_rate(struct clk_hw *hw, unsigned long rate,
549 if (!dd) 549 if (!dd)
550 return -EINVAL; 550 return -EINVAL;
551 551
552 if (__clk_get_parent(hw->clk) != dd->clk_ref) 552 if (__clk_get_hw(__clk_get_parent(hw->clk)) !=
553 __clk_get_hw(dd->clk_ref))
553 return -EINVAL; 554 return -EINVAL;
554 555
555 if (dd->last_rounded_rate == 0) 556 if (dd->last_rounded_rate == 0)
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index b701e7c195e4..d60c193b81aa 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -37,6 +37,15 @@ static HLIST_HEAD(clk_root_list);
37static HLIST_HEAD(clk_orphan_list); 37static HLIST_HEAD(clk_orphan_list);
38static LIST_HEAD(clk_notifier_list); 38static LIST_HEAD(clk_notifier_list);
39 39
40static long clk_core_get_accuracy(struct clk_core *clk);
41static unsigned long clk_core_get_rate(struct clk_core *clk);
42static int clk_core_get_phase(struct clk_core *clk);
43static bool clk_core_is_prepared(struct clk_core *clk);
44static bool clk_core_is_enabled(struct clk_core *clk);
45static unsigned long clk_core_round_rate_nolock(struct clk_core *clk,
46 unsigned long rate);
47static struct clk_core *clk_core_lookup(const char *name);
48
40/*** locking ***/ 49/*** locking ***/
41static void clk_prepare_lock(void) 50static void clk_prepare_lock(void)
42{ 51{
@@ -114,7 +123,8 @@ static struct hlist_head *orphan_list[] = {
114 NULL, 123 NULL,
115}; 124};
116 125
117static void clk_summary_show_one(struct seq_file *s, struct clk *c, int level) 126static void clk_summary_show_one(struct seq_file *s, struct clk_core *c,
127 int level)
118{ 128{
119 if (!c) 129 if (!c)
120 return; 130 return;
@@ -122,14 +132,14 @@ static void clk_summary_show_one(struct seq_file *s, struct clk *c, int level)
122 seq_printf(s, "%*s%-*s %11d %12d %11lu %10lu %-3d\n", 132 seq_printf(s, "%*s%-*s %11d %12d %11lu %10lu %-3d\n",
123 level * 3 + 1, "", 133 level * 3 + 1, "",
124 30 - level * 3, c->name, 134 30 - level * 3, c->name,
125 c->enable_count, c->prepare_count, clk_get_rate(c), 135 c->enable_count, c->prepare_count, clk_core_get_rate(c),
126 clk_get_accuracy(c), clk_get_phase(c)); 136 clk_core_get_accuracy(c), clk_core_get_phase(c));
127} 137}
128 138
129static void clk_summary_show_subtree(struct seq_file *s, struct clk *c, 139static void clk_summary_show_subtree(struct seq_file *s, struct clk_core *c,
130 int level) 140 int level)
131{ 141{
132 struct clk *child; 142 struct clk_core *child;
133 143
134 if (!c) 144 if (!c)
135 return; 145 return;
@@ -142,7 +152,7 @@ static void clk_summary_show_subtree(struct seq_file *s, struct clk *c,
142 152
143static int clk_summary_show(struct seq_file *s, void *data) 153static int clk_summary_show(struct seq_file *s, void *data)
144{ 154{
145 struct clk *c; 155 struct clk_core *c;
146 struct hlist_head **lists = (struct hlist_head **)s->private; 156 struct hlist_head **lists = (struct hlist_head **)s->private;
147 157
148 seq_puts(s, " clock enable_cnt prepare_cnt rate accuracy phase\n"); 158 seq_puts(s, " clock enable_cnt prepare_cnt rate accuracy phase\n");
@@ -172,7 +182,7 @@ static const struct file_operations clk_summary_fops = {
172 .release = single_release, 182 .release = single_release,
173}; 183};
174 184
175static void clk_dump_one(struct seq_file *s, struct clk *c, int level) 185static void clk_dump_one(struct seq_file *s, struct clk_core *c, int level)
176{ 186{
177 if (!c) 187 if (!c)
178 return; 188 return;
@@ -180,14 +190,14 @@ static void clk_dump_one(struct seq_file *s, struct clk *c, int level)
180 seq_printf(s, "\"%s\": { ", c->name); 190 seq_printf(s, "\"%s\": { ", c->name);
181 seq_printf(s, "\"enable_count\": %d,", c->enable_count); 191 seq_printf(s, "\"enable_count\": %d,", c->enable_count);
182 seq_printf(s, "\"prepare_count\": %d,", c->prepare_count); 192 seq_printf(s, "\"prepare_count\": %d,", c->prepare_count);
183 seq_printf(s, "\"rate\": %lu", clk_get_rate(c)); 193 seq_printf(s, "\"rate\": %lu", clk_core_get_rate(c));
184 seq_printf(s, "\"accuracy\": %lu", clk_get_accuracy(c)); 194 seq_printf(s, "\"accuracy\": %lu", clk_core_get_accuracy(c));
185 seq_printf(s, "\"phase\": %d", clk_get_phase(c)); 195 seq_printf(s, "\"phase\": %d", clk_core_get_phase(c));
186} 196}
187 197
188static void clk_dump_subtree(struct seq_file *s, struct clk *c, int level) 198static void clk_dump_subtree(struct seq_file *s, struct clk_core *c, int level)
189{ 199{
190 struct clk *child; 200 struct clk_core *child;
191 201
192 if (!c) 202 if (!c)
193 return; 203 return;
@@ -204,7 +214,7 @@ static void clk_dump_subtree(struct seq_file *s, struct clk *c, int level)
204 214
205static int clk_dump(struct seq_file *s, void *data) 215static int clk_dump(struct seq_file *s, void *data)
206{ 216{
207 struct clk *c; 217 struct clk_core *c;
208 bool first_node = true; 218 bool first_node = true;
209 struct hlist_head **lists = (struct hlist_head **)s->private; 219 struct hlist_head **lists = (struct hlist_head **)s->private;
210 220
@@ -240,7 +250,7 @@ static const struct file_operations clk_dump_fops = {
240 .release = single_release, 250 .release = single_release,
241}; 251};
242 252
243static int clk_debug_create_one(struct clk *clk, struct dentry *pdentry) 253static int clk_debug_create_one(struct clk_core *clk, struct dentry *pdentry)
244{ 254{
245 struct dentry *d; 255 struct dentry *d;
246 int ret = -ENOMEM; 256 int ret = -ENOMEM;
@@ -315,7 +325,7 @@ out:
315 * initialized. Otherwise it bails out early since the debugfs clk tree 325 * initialized. Otherwise it bails out early since the debugfs clk tree
316 * will be created lazily by clk_debug_init as part of a late_initcall. 326 * will be created lazily by clk_debug_init as part of a late_initcall.
317 */ 327 */
318static int clk_debug_register(struct clk *clk) 328static int clk_debug_register(struct clk_core *clk)
319{ 329{
320 int ret = 0; 330 int ret = 0;
321 331
@@ -340,7 +350,7 @@ unlock:
340 * debugfs clk tree if clk->dentry points to debugfs created by 350 * debugfs clk tree if clk->dentry points to debugfs created by
341 * clk_debug_register in __clk_init. 351 * clk_debug_register in __clk_init.
342 */ 352 */
343static void clk_debug_unregister(struct clk *clk) 353static void clk_debug_unregister(struct clk_core *clk)
344{ 354{
345 mutex_lock(&clk_debug_lock); 355 mutex_lock(&clk_debug_lock);
346 hlist_del_init(&clk->debug_node); 356 hlist_del_init(&clk->debug_node);
@@ -354,8 +364,9 @@ struct dentry *clk_debugfs_add_file(struct clk_hw *hw, char *name, umode_t mode,
354{ 364{
355 struct dentry *d = NULL; 365 struct dentry *d = NULL;
356 366
357 if (hw->clk->dentry) 367 if (hw->core->dentry)
358 d = debugfs_create_file(name, mode, hw->clk->dentry, data, fops); 368 d = debugfs_create_file(name, mode, hw->core->dentry, data,
369 fops);
359 370
360 return d; 371 return d;
361} 372}
@@ -375,7 +386,7 @@ EXPORT_SYMBOL_GPL(clk_debugfs_add_file);
375 */ 386 */
376static int __init clk_debug_init(void) 387static int __init clk_debug_init(void)
377{ 388{
378 struct clk *clk; 389 struct clk_core *clk;
379 struct dentry *d; 390 struct dentry *d;
380 391
381 rootdir = debugfs_create_dir("clk", NULL); 392 rootdir = debugfs_create_dir("clk", NULL);
@@ -414,19 +425,20 @@ static int __init clk_debug_init(void)
414} 425}
415late_initcall(clk_debug_init); 426late_initcall(clk_debug_init);
416#else 427#else
417static inline int clk_debug_register(struct clk *clk) { return 0; } 428static inline int clk_debug_register(struct clk_core *clk) { return 0; }
418static inline void clk_debug_reparent(struct clk *clk, struct clk *new_parent) 429static inline void clk_debug_reparent(struct clk_core *clk,
430 struct clk_core *new_parent)
419{ 431{
420} 432}
421static inline void clk_debug_unregister(struct clk *clk) 433static inline void clk_debug_unregister(struct clk_core *clk)
422{ 434{
423} 435}
424#endif 436#endif
425 437
426/* caller must hold prepare_lock */ 438/* caller must hold prepare_lock */
427static void clk_unprepare_unused_subtree(struct clk *clk) 439static void clk_unprepare_unused_subtree(struct clk_core *clk)
428{ 440{
429 struct clk *child; 441 struct clk_core *child;
430 442
431 hlist_for_each_entry(child, &clk->children, child_node) 443 hlist_for_each_entry(child, &clk->children, child_node)
432 clk_unprepare_unused_subtree(child); 444 clk_unprepare_unused_subtree(child);
@@ -437,7 +449,7 @@ static void clk_unprepare_unused_subtree(struct clk *clk)
437 if (clk->flags & CLK_IGNORE_UNUSED) 449 if (clk->flags & CLK_IGNORE_UNUSED)
438 return; 450 return;
439 451
440 if (__clk_is_prepared(clk)) { 452 if (clk_core_is_prepared(clk)) {
441 if (clk->ops->unprepare_unused) 453 if (clk->ops->unprepare_unused)
442 clk->ops->unprepare_unused(clk->hw); 454 clk->ops->unprepare_unused(clk->hw);
443 else if (clk->ops->unprepare) 455 else if (clk->ops->unprepare)
@@ -446,9 +458,9 @@ static void clk_unprepare_unused_subtree(struct clk *clk)
446} 458}
447 459
448/* caller must hold prepare_lock */ 460/* caller must hold prepare_lock */
449static void clk_disable_unused_subtree(struct clk *clk) 461static void clk_disable_unused_subtree(struct clk_core *clk)
450{ 462{
451 struct clk *child; 463 struct clk_core *child;
452 unsigned long flags; 464 unsigned long flags;
453 465
454 hlist_for_each_entry(child, &clk->children, child_node) 466 hlist_for_each_entry(child, &clk->children, child_node)
@@ -467,7 +479,7 @@ static void clk_disable_unused_subtree(struct clk *clk)
467 * sequence. call .disable_unused if available, otherwise fall 479 * sequence. call .disable_unused if available, otherwise fall
468 * back to .disable 480 * back to .disable
469 */ 481 */
470 if (__clk_is_enabled(clk)) { 482 if (clk_core_is_enabled(clk)) {
471 if (clk->ops->disable_unused) 483 if (clk->ops->disable_unused)
472 clk->ops->disable_unused(clk->hw); 484 clk->ops->disable_unused(clk->hw);
473 else if (clk->ops->disable) 485 else if (clk->ops->disable)
@@ -488,7 +500,7 @@ __setup("clk_ignore_unused", clk_ignore_unused_setup);
488 500
489static int clk_disable_unused(void) 501static int clk_disable_unused(void)
490{ 502{
491 struct clk *clk; 503 struct clk_core *clk;
492 504
493 if (clk_ignore_unused) { 505 if (clk_ignore_unused) {
494 pr_warn("clk: Not disabling unused clocks\n"); 506 pr_warn("clk: Not disabling unused clocks\n");
@@ -519,48 +531,65 @@ late_initcall_sync(clk_disable_unused);
519 531
520const char *__clk_get_name(struct clk *clk) 532const char *__clk_get_name(struct clk *clk)
521{ 533{
522 return !clk ? NULL : clk->name; 534 return !clk ? NULL : clk->core->name;
523} 535}
524EXPORT_SYMBOL_GPL(__clk_get_name); 536EXPORT_SYMBOL_GPL(__clk_get_name);
525 537
526struct clk_hw *__clk_get_hw(struct clk *clk) 538struct clk_hw *__clk_get_hw(struct clk *clk)
527{ 539{
528 return !clk ? NULL : clk->hw; 540 return !clk ? NULL : clk->core->hw;
529} 541}
530EXPORT_SYMBOL_GPL(__clk_get_hw); 542EXPORT_SYMBOL_GPL(__clk_get_hw);
531 543
532u8 __clk_get_num_parents(struct clk *clk) 544u8 __clk_get_num_parents(struct clk *clk)
533{ 545{
534 return !clk ? 0 : clk->num_parents; 546 return !clk ? 0 : clk->core->num_parents;
535} 547}
536EXPORT_SYMBOL_GPL(__clk_get_num_parents); 548EXPORT_SYMBOL_GPL(__clk_get_num_parents);
537 549
538struct clk *__clk_get_parent(struct clk *clk) 550struct clk *__clk_get_parent(struct clk *clk)
539{ 551{
540 return !clk ? NULL : clk->parent; 552 if (!clk)
553 return NULL;
554
555 /* TODO: Create a per-user clk and change callers to call clk_put */
556 return !clk->core->parent ? NULL : clk->core->parent->hw->clk;
541} 557}
542EXPORT_SYMBOL_GPL(__clk_get_parent); 558EXPORT_SYMBOL_GPL(__clk_get_parent);
543 559
544struct clk *clk_get_parent_by_index(struct clk *clk, u8 index) 560static struct clk_core *clk_core_get_parent_by_index(struct clk_core *clk,
561 u8 index)
545{ 562{
546 if (!clk || index >= clk->num_parents) 563 if (!clk || index >= clk->num_parents)
547 return NULL; 564 return NULL;
548 else if (!clk->parents) 565 else if (!clk->parents)
549 return __clk_lookup(clk->parent_names[index]); 566 return clk_core_lookup(clk->parent_names[index]);
550 else if (!clk->parents[index]) 567 else if (!clk->parents[index])
551 return clk->parents[index] = 568 return clk->parents[index] =
552 __clk_lookup(clk->parent_names[index]); 569 clk_core_lookup(clk->parent_names[index]);
553 else 570 else
554 return clk->parents[index]; 571 return clk->parents[index];
555} 572}
573
574struct clk *clk_get_parent_by_index(struct clk *clk, u8 index)
575{
576 struct clk_core *parent;
577
578 if (!clk)
579 return NULL;
580
581 parent = clk_core_get_parent_by_index(clk->core, index);
582
583 return !parent ? NULL : parent->hw->clk;
584}
556EXPORT_SYMBOL_GPL(clk_get_parent_by_index); 585EXPORT_SYMBOL_GPL(clk_get_parent_by_index);
557 586
558unsigned int __clk_get_enable_count(struct clk *clk) 587unsigned int __clk_get_enable_count(struct clk *clk)
559{ 588{
560 return !clk ? 0 : clk->enable_count; 589 return !clk ? 0 : clk->core->enable_count;
561} 590}
562 591
563unsigned long __clk_get_rate(struct clk *clk) 592static unsigned long clk_core_get_rate_nolock(struct clk_core *clk)
564{ 593{
565 unsigned long ret; 594 unsigned long ret;
566 595
@@ -580,9 +609,17 @@ unsigned long __clk_get_rate(struct clk *clk)
580out: 609out:
581 return ret; 610 return ret;
582} 611}
612
613unsigned long __clk_get_rate(struct clk *clk)
614{
615 if (!clk)
616 return 0;
617
618 return clk_core_get_rate_nolock(clk->core);
619}
583EXPORT_SYMBOL_GPL(__clk_get_rate); 620EXPORT_SYMBOL_GPL(__clk_get_rate);
584 621
585static unsigned long __clk_get_accuracy(struct clk *clk) 622static unsigned long __clk_get_accuracy(struct clk_core *clk)
586{ 623{
587 if (!clk) 624 if (!clk)
588 return 0; 625 return 0;
@@ -592,11 +629,11 @@ static unsigned long __clk_get_accuracy(struct clk *clk)
592 629
593unsigned long __clk_get_flags(struct clk *clk) 630unsigned long __clk_get_flags(struct clk *clk)
594{ 631{
595 return !clk ? 0 : clk->flags; 632 return !clk ? 0 : clk->core->flags;
596} 633}
597EXPORT_SYMBOL_GPL(__clk_get_flags); 634EXPORT_SYMBOL_GPL(__clk_get_flags);
598 635
599bool __clk_is_prepared(struct clk *clk) 636static bool clk_core_is_prepared(struct clk_core *clk)
600{ 637{
601 int ret; 638 int ret;
602 639
@@ -617,7 +654,15 @@ out:
617 return !!ret; 654 return !!ret;
618} 655}
619 656
620bool __clk_is_enabled(struct clk *clk) 657bool __clk_is_prepared(struct clk *clk)
658{
659 if (!clk)
660 return false;
661
662 return clk_core_is_prepared(clk->core);
663}
664
665static bool clk_core_is_enabled(struct clk_core *clk)
621{ 666{
622 int ret; 667 int ret;
623 668
@@ -637,12 +682,21 @@ bool __clk_is_enabled(struct clk *clk)
637out: 682out:
638 return !!ret; 683 return !!ret;
639} 684}
685
686bool __clk_is_enabled(struct clk *clk)
687{
688 if (!clk)
689 return false;
690
691 return clk_core_is_enabled(clk->core);
692}
640EXPORT_SYMBOL_GPL(__clk_is_enabled); 693EXPORT_SYMBOL_GPL(__clk_is_enabled);
641 694
642static struct clk *__clk_lookup_subtree(const char *name, struct clk *clk) 695static struct clk_core *__clk_lookup_subtree(const char *name,
696 struct clk_core *clk)
643{ 697{
644 struct clk *child; 698 struct clk_core *child;
645 struct clk *ret; 699 struct clk_core *ret;
646 700
647 if (!strcmp(clk->name, name)) 701 if (!strcmp(clk->name, name))
648 return clk; 702 return clk;
@@ -656,10 +710,10 @@ static struct clk *__clk_lookup_subtree(const char *name, struct clk *clk)
656 return NULL; 710 return NULL;
657} 711}
658 712
659struct clk *__clk_lookup(const char *name) 713static struct clk_core *clk_core_lookup(const char *name)
660{ 714{
661 struct clk *root_clk; 715 struct clk_core *root_clk;
662 struct clk *ret; 716 struct clk_core *ret;
663 717
664 if (!name) 718 if (!name)
665 return NULL; 719 return NULL;
@@ -696,32 +750,32 @@ clk_mux_determine_rate_flags(struct clk_hw *hw, unsigned long rate,
696 struct clk_hw **best_parent_p, 750 struct clk_hw **best_parent_p,
697 unsigned long flags) 751 unsigned long flags)
698{ 752{
699 struct clk *clk = hw->clk, *parent, *best_parent = NULL; 753 struct clk_core *core = hw->core, *parent, *best_parent = NULL;
700 int i, num_parents; 754 int i, num_parents;
701 unsigned long parent_rate, best = 0; 755 unsigned long parent_rate, best = 0;
702 756
703 /* if NO_REPARENT flag set, pass through to current parent */ 757 /* if NO_REPARENT flag set, pass through to current parent */
704 if (clk->flags & CLK_SET_RATE_NO_REPARENT) { 758 if (core->flags & CLK_SET_RATE_NO_REPARENT) {
705 parent = clk->parent; 759 parent = core->parent;
706 if (clk->flags & CLK_SET_RATE_PARENT) 760 if (core->flags & CLK_SET_RATE_PARENT)
707 best = __clk_round_rate(parent, rate); 761 best = clk_core_round_rate_nolock(parent, rate);
708 else if (parent) 762 else if (parent)
709 best = __clk_get_rate(parent); 763 best = clk_core_get_rate_nolock(parent);
710 else 764 else
711 best = __clk_get_rate(clk); 765 best = clk_core_get_rate_nolock(core);
712 goto out; 766 goto out;
713 } 767 }
714 768
715 /* find the parent that can provide the fastest rate <= rate */ 769 /* find the parent that can provide the fastest rate <= rate */
716 num_parents = clk->num_parents; 770 num_parents = core->num_parents;
717 for (i = 0; i < num_parents; i++) { 771 for (i = 0; i < num_parents; i++) {
718 parent = clk_get_parent_by_index(clk, i); 772 parent = clk_core_get_parent_by_index(core, i);
719 if (!parent) 773 if (!parent)
720 continue; 774 continue;
721 if (clk->flags & CLK_SET_RATE_PARENT) 775 if (core->flags & CLK_SET_RATE_PARENT)
722 parent_rate = __clk_round_rate(parent, rate); 776 parent_rate = clk_core_round_rate_nolock(parent, rate);
723 else 777 else
724 parent_rate = __clk_get_rate(parent); 778 parent_rate = clk_core_get_rate_nolock(parent);
725 if (mux_is_better_rate(rate, parent_rate, best, flags)) { 779 if (mux_is_better_rate(rate, parent_rate, best, flags)) {
726 best_parent = parent; 780 best_parent = parent;
727 best = parent_rate; 781 best = parent_rate;
@@ -736,6 +790,13 @@ out:
736 return best; 790 return best;
737} 791}
738 792
793struct clk *__clk_lookup(const char *name)
794{
795 struct clk_core *core = clk_core_lookup(name);
796
797 return !core ? NULL : core->hw->clk;
798}
799
739/* 800/*
740 * Helper for finding best parent to provide a given frequency. This can be used 801 * Helper for finding best parent to provide a given frequency. This can be used
741 * directly as a determine_rate callback (e.g. for a mux), or from a more 802 * directly as a determine_rate callback (e.g. for a mux), or from a more
@@ -762,7 +823,7 @@ EXPORT_SYMBOL_GPL(__clk_mux_determine_rate_closest);
762 823
763/*** clk api ***/ 824/*** clk api ***/
764 825
765void __clk_unprepare(struct clk *clk) 826static void clk_core_unprepare(struct clk_core *clk)
766{ 827{
767 if (!clk) 828 if (!clk)
768 return; 829 return;
@@ -778,7 +839,7 @@ void __clk_unprepare(struct clk *clk)
778 if (clk->ops->unprepare) 839 if (clk->ops->unprepare)
779 clk->ops->unprepare(clk->hw); 840 clk->ops->unprepare(clk->hw);
780 841
781 __clk_unprepare(clk->parent); 842 clk_core_unprepare(clk->parent);
782} 843}
783 844
784/** 845/**
@@ -798,12 +859,12 @@ void clk_unprepare(struct clk *clk)
798 return; 859 return;
799 860
800 clk_prepare_lock(); 861 clk_prepare_lock();
801 __clk_unprepare(clk); 862 clk_core_unprepare(clk->core);
802 clk_prepare_unlock(); 863 clk_prepare_unlock();
803} 864}
804EXPORT_SYMBOL_GPL(clk_unprepare); 865EXPORT_SYMBOL_GPL(clk_unprepare);
805 866
806int __clk_prepare(struct clk *clk) 867static int clk_core_prepare(struct clk_core *clk)
807{ 868{
808 int ret = 0; 869 int ret = 0;
809 870
@@ -811,14 +872,14 @@ int __clk_prepare(struct clk *clk)
811 return 0; 872 return 0;
812 873
813 if (clk->prepare_count == 0) { 874 if (clk->prepare_count == 0) {
814 ret = __clk_prepare(clk->parent); 875 ret = clk_core_prepare(clk->parent);
815 if (ret) 876 if (ret)
816 return ret; 877 return ret;
817 878
818 if (clk->ops->prepare) { 879 if (clk->ops->prepare) {
819 ret = clk->ops->prepare(clk->hw); 880 ret = clk->ops->prepare(clk->hw);
820 if (ret) { 881 if (ret) {
821 __clk_unprepare(clk->parent); 882 clk_core_unprepare(clk->parent);
822 return ret; 883 return ret;
823 } 884 }
824 } 885 }
@@ -845,15 +906,18 @@ int clk_prepare(struct clk *clk)
845{ 906{
846 int ret; 907 int ret;
847 908
909 if (!clk)
910 return 0;
911
848 clk_prepare_lock(); 912 clk_prepare_lock();
849 ret = __clk_prepare(clk); 913 ret = clk_core_prepare(clk->core);
850 clk_prepare_unlock(); 914 clk_prepare_unlock();
851 915
852 return ret; 916 return ret;
853} 917}
854EXPORT_SYMBOL_GPL(clk_prepare); 918EXPORT_SYMBOL_GPL(clk_prepare);
855 919
856static void __clk_disable(struct clk *clk) 920static void clk_core_disable(struct clk_core *clk)
857{ 921{
858 if (!clk) 922 if (!clk)
859 return; 923 return;
@@ -867,7 +931,15 @@ static void __clk_disable(struct clk *clk)
867 if (clk->ops->disable) 931 if (clk->ops->disable)
868 clk->ops->disable(clk->hw); 932 clk->ops->disable(clk->hw);
869 933
870 __clk_disable(clk->parent); 934 clk_core_disable(clk->parent);
935}
936
937static void __clk_disable(struct clk *clk)
938{
939 if (!clk)
940 return;
941
942 clk_core_disable(clk->core);
871} 943}
872 944
873/** 945/**
@@ -895,7 +967,7 @@ void clk_disable(struct clk *clk)
895} 967}
896EXPORT_SYMBOL_GPL(clk_disable); 968EXPORT_SYMBOL_GPL(clk_disable);
897 969
898static int __clk_enable(struct clk *clk) 970static int clk_core_enable(struct clk_core *clk)
899{ 971{
900 int ret = 0; 972 int ret = 0;
901 973
@@ -906,7 +978,7 @@ static int __clk_enable(struct clk *clk)
906 return -ESHUTDOWN; 978 return -ESHUTDOWN;
907 979
908 if (clk->enable_count == 0) { 980 if (clk->enable_count == 0) {
909 ret = __clk_enable(clk->parent); 981 ret = clk_core_enable(clk->parent);
910 982
911 if (ret) 983 if (ret)
912 return ret; 984 return ret;
@@ -914,7 +986,7 @@ static int __clk_enable(struct clk *clk)
914 if (clk->ops->enable) { 986 if (clk->ops->enable) {
915 ret = clk->ops->enable(clk->hw); 987 ret = clk->ops->enable(clk->hw);
916 if (ret) { 988 if (ret) {
917 __clk_disable(clk->parent); 989 clk_core_disable(clk->parent);
918 return ret; 990 return ret;
919 } 991 }
920 } 992 }
@@ -924,6 +996,14 @@ static int __clk_enable(struct clk *clk)
924 return 0; 996 return 0;
925} 997}
926 998
999static int __clk_enable(struct clk *clk)
1000{
1001 if (!clk)
1002 return 0;
1003
1004 return clk_core_enable(clk->core);
1005}
1006
927/** 1007/**
928 * clk_enable - ungate a clock 1008 * clk_enable - ungate a clock
929 * @clk: the clk being ungated 1009 * @clk: the clk being ungated
@@ -950,17 +1030,11 @@ int clk_enable(struct clk *clk)
950} 1030}
951EXPORT_SYMBOL_GPL(clk_enable); 1031EXPORT_SYMBOL_GPL(clk_enable);
952 1032
953/** 1033static unsigned long clk_core_round_rate_nolock(struct clk_core *clk,
954 * __clk_round_rate - round the given rate for a clk 1034 unsigned long rate)
955 * @clk: round the rate of this clock
956 * @rate: the rate which is to be rounded
957 *
958 * Caller must hold prepare_lock. Useful for clk_ops such as .set_rate
959 */
960unsigned long __clk_round_rate(struct clk *clk, unsigned long rate)
961{ 1035{
962 unsigned long parent_rate = 0; 1036 unsigned long parent_rate = 0;
963 struct clk *parent; 1037 struct clk_core *parent;
964 struct clk_hw *parent_hw; 1038 struct clk_hw *parent_hw;
965 1039
966 if (!clk) 1040 if (!clk)
@@ -977,10 +1051,25 @@ unsigned long __clk_round_rate(struct clk *clk, unsigned long rate)
977 } else if (clk->ops->round_rate) 1051 } else if (clk->ops->round_rate)
978 return clk->ops->round_rate(clk->hw, rate, &parent_rate); 1052 return clk->ops->round_rate(clk->hw, rate, &parent_rate);
979 else if (clk->flags & CLK_SET_RATE_PARENT) 1053 else if (clk->flags & CLK_SET_RATE_PARENT)
980 return __clk_round_rate(clk->parent, rate); 1054 return clk_core_round_rate_nolock(clk->parent, rate);
981 else 1055 else
982 return clk->rate; 1056 return clk->rate;
983} 1057}
1058
1059/**
1060 * __clk_round_rate - round the given rate for a clk
1061 * @clk: round the rate of this clock
1062 * @rate: the rate which is to be rounded
1063 *
1064 * Caller must hold prepare_lock. Useful for clk_ops such as .set_rate
1065 */
1066unsigned long __clk_round_rate(struct clk *clk, unsigned long rate)
1067{
1068 if (!clk)
1069 return 0;
1070
1071 return clk_core_round_rate_nolock(clk->core, rate);
1072}
984EXPORT_SYMBOL_GPL(__clk_round_rate); 1073EXPORT_SYMBOL_GPL(__clk_round_rate);
985 1074
986/** 1075/**
@@ -996,8 +1085,11 @@ long clk_round_rate(struct clk *clk, unsigned long rate)
996{ 1085{
997 unsigned long ret; 1086 unsigned long ret;
998 1087
1088 if (!clk)
1089 return 0;
1090
999 clk_prepare_lock(); 1091 clk_prepare_lock();
1000 ret = __clk_round_rate(clk, rate); 1092 ret = clk_core_round_rate_nolock(clk->core, rate);
1001 clk_prepare_unlock(); 1093 clk_prepare_unlock();
1002 1094
1003 return ret; 1095 return ret;
@@ -1018,22 +1110,21 @@ EXPORT_SYMBOL_GPL(clk_round_rate);
1018 * called if all went well, or NOTIFY_STOP or NOTIFY_BAD immediately if 1110 * called if all went well, or NOTIFY_STOP or NOTIFY_BAD immediately if
1019 * a driver returns that. 1111 * a driver returns that.
1020 */ 1112 */
1021static int __clk_notify(struct clk *clk, unsigned long msg, 1113static int __clk_notify(struct clk_core *clk, unsigned long msg,
1022 unsigned long old_rate, unsigned long new_rate) 1114 unsigned long old_rate, unsigned long new_rate)
1023{ 1115{
1024 struct clk_notifier *cn; 1116 struct clk_notifier *cn;
1025 struct clk_notifier_data cnd; 1117 struct clk_notifier_data cnd;
1026 int ret = NOTIFY_DONE; 1118 int ret = NOTIFY_DONE;
1027 1119
1028 cnd.clk = clk;
1029 cnd.old_rate = old_rate; 1120 cnd.old_rate = old_rate;
1030 cnd.new_rate = new_rate; 1121 cnd.new_rate = new_rate;
1031 1122
1032 list_for_each_entry(cn, &clk_notifier_list, node) { 1123 list_for_each_entry(cn, &clk_notifier_list, node) {
1033 if (cn->clk == clk) { 1124 if (cn->clk->core == clk) {
1125 cnd.clk = cn->clk;
1034 ret = srcu_notifier_call_chain(&cn->notifier_head, msg, 1126 ret = srcu_notifier_call_chain(&cn->notifier_head, msg,
1035 &cnd); 1127 &cnd);
1036 break;
1037 } 1128 }
1038 } 1129 }
1039 1130
@@ -1051,10 +1142,10 @@ static int __clk_notify(struct clk *clk, unsigned long msg,
1051 * 1142 *
1052 * Caller must hold prepare_lock. 1143 * Caller must hold prepare_lock.
1053 */ 1144 */
1054static void __clk_recalc_accuracies(struct clk *clk) 1145static void __clk_recalc_accuracies(struct clk_core *clk)
1055{ 1146{
1056 unsigned long parent_accuracy = 0; 1147 unsigned long parent_accuracy = 0;
1057 struct clk *child; 1148 struct clk_core *child;
1058 1149
1059 if (clk->parent) 1150 if (clk->parent)
1060 parent_accuracy = clk->parent->accuracy; 1151 parent_accuracy = clk->parent->accuracy;
@@ -1069,6 +1160,20 @@ static void __clk_recalc_accuracies(struct clk *clk)
1069 __clk_recalc_accuracies(child); 1160 __clk_recalc_accuracies(child);
1070} 1161}
1071 1162
1163static long clk_core_get_accuracy(struct clk_core *clk)
1164{
1165 unsigned long accuracy;
1166
1167 clk_prepare_lock();
1168 if (clk && (clk->flags & CLK_GET_ACCURACY_NOCACHE))
1169 __clk_recalc_accuracies(clk);
1170
1171 accuracy = __clk_get_accuracy(clk);
1172 clk_prepare_unlock();
1173
1174 return accuracy;
1175}
1176
1072/** 1177/**
1073 * clk_get_accuracy - return the accuracy of clk 1178 * clk_get_accuracy - return the accuracy of clk
1074 * @clk: the clk whose accuracy is being returned 1179 * @clk: the clk whose accuracy is being returned
@@ -1080,20 +1185,15 @@ static void __clk_recalc_accuracies(struct clk *clk)
1080 */ 1185 */
1081long clk_get_accuracy(struct clk *clk) 1186long clk_get_accuracy(struct clk *clk)
1082{ 1187{
1083 unsigned long accuracy; 1188 if (!clk)
1084 1189 return 0;
1085 clk_prepare_lock();
1086 if (clk && (clk->flags & CLK_GET_ACCURACY_NOCACHE))
1087 __clk_recalc_accuracies(clk);
1088
1089 accuracy = __clk_get_accuracy(clk);
1090 clk_prepare_unlock();
1091 1190
1092 return accuracy; 1191 return clk_core_get_accuracy(clk->core);
1093} 1192}
1094EXPORT_SYMBOL_GPL(clk_get_accuracy); 1193EXPORT_SYMBOL_GPL(clk_get_accuracy);
1095 1194
1096static unsigned long clk_recalc(struct clk *clk, unsigned long parent_rate) 1195static unsigned long clk_recalc(struct clk_core *clk,
1196 unsigned long parent_rate)
1097{ 1197{
1098 if (clk->ops->recalc_rate) 1198 if (clk->ops->recalc_rate)
1099 return clk->ops->recalc_rate(clk->hw, parent_rate); 1199 return clk->ops->recalc_rate(clk->hw, parent_rate);
@@ -1114,11 +1214,11 @@ static unsigned long clk_recalc(struct clk *clk, unsigned long parent_rate)
1114 * 1214 *
1115 * Caller must hold prepare_lock. 1215 * Caller must hold prepare_lock.
1116 */ 1216 */
1117static void __clk_recalc_rates(struct clk *clk, unsigned long msg) 1217static void __clk_recalc_rates(struct clk_core *clk, unsigned long msg)
1118{ 1218{
1119 unsigned long old_rate; 1219 unsigned long old_rate;
1120 unsigned long parent_rate = 0; 1220 unsigned long parent_rate = 0;
1121 struct clk *child; 1221 struct clk_core *child;
1122 1222
1123 old_rate = clk->rate; 1223 old_rate = clk->rate;
1124 1224
@@ -1138,15 +1238,7 @@ static void __clk_recalc_rates(struct clk *clk, unsigned long msg)
1138 __clk_recalc_rates(child, msg); 1238 __clk_recalc_rates(child, msg);
1139} 1239}
1140 1240
1141/** 1241static unsigned long clk_core_get_rate(struct clk_core *clk)
1142 * clk_get_rate - return the rate of clk
1143 * @clk: the clk whose rate is being returned
1144 *
1145 * Simply returns the cached rate of the clk, unless CLK_GET_RATE_NOCACHE flag
1146 * is set, which means a recalc_rate will be issued.
1147 * If clk is NULL then returns 0.
1148 */
1149unsigned long clk_get_rate(struct clk *clk)
1150{ 1242{
1151 unsigned long rate; 1243 unsigned long rate;
1152 1244
@@ -1155,14 +1247,32 @@ unsigned long clk_get_rate(struct clk *clk)
1155 if (clk && (clk->flags & CLK_GET_RATE_NOCACHE)) 1247 if (clk && (clk->flags & CLK_GET_RATE_NOCACHE))
1156 __clk_recalc_rates(clk, 0); 1248 __clk_recalc_rates(clk, 0);
1157 1249
1158 rate = __clk_get_rate(clk); 1250 rate = clk_core_get_rate_nolock(clk);
1159 clk_prepare_unlock(); 1251 clk_prepare_unlock();
1160 1252
1161 return rate; 1253 return rate;
1162} 1254}
1255EXPORT_SYMBOL_GPL(clk_core_get_rate);
1256
1257/**
1258 * clk_get_rate - return the rate of clk
1259 * @clk: the clk whose rate is being returned
1260 *
1261 * Simply returns the cached rate of the clk, unless CLK_GET_RATE_NOCACHE flag
1262 * is set, which means a recalc_rate will be issued.
1263 * If clk is NULL then returns 0.
1264 */
1265unsigned long clk_get_rate(struct clk *clk)
1266{
1267 if (!clk)
1268 return 0;
1269
1270 return clk_core_get_rate(clk->core);
1271}
1163EXPORT_SYMBOL_GPL(clk_get_rate); 1272EXPORT_SYMBOL_GPL(clk_get_rate);
1164 1273
1165static int clk_fetch_parent_index(struct clk *clk, struct clk *parent) 1274static int clk_fetch_parent_index(struct clk_core *clk,
1275 struct clk_core *parent)
1166{ 1276{
1167 int i; 1277 int i;
1168 1278
@@ -1176,7 +1286,7 @@ static int clk_fetch_parent_index(struct clk *clk, struct clk *parent)
1176 /* 1286 /*
1177 * find index of new parent clock using cached parent ptrs, 1287 * find index of new parent clock using cached parent ptrs,
1178 * or if not yet cached, use string name comparison and cache 1288 * or if not yet cached, use string name comparison and cache
1179 * them now to avoid future calls to __clk_lookup. 1289 * them now to avoid future calls to clk_core_lookup.
1180 */ 1290 */
1181 for (i = 0; i < clk->num_parents; i++) { 1291 for (i = 0; i < clk->num_parents; i++) {
1182 if (clk->parents[i] == parent) 1292 if (clk->parents[i] == parent)
@@ -1186,7 +1296,7 @@ static int clk_fetch_parent_index(struct clk *clk, struct clk *parent)
1186 continue; 1296 continue;
1187 1297
1188 if (!strcmp(clk->parent_names[i], parent->name)) { 1298 if (!strcmp(clk->parent_names[i], parent->name)) {
1189 clk->parents[i] = __clk_lookup(parent->name); 1299 clk->parents[i] = clk_core_lookup(parent->name);
1190 return i; 1300 return i;
1191 } 1301 }
1192 } 1302 }
@@ -1194,7 +1304,7 @@ static int clk_fetch_parent_index(struct clk *clk, struct clk *parent)
1194 return -EINVAL; 1304 return -EINVAL;
1195} 1305}
1196 1306
1197static void clk_reparent(struct clk *clk, struct clk *new_parent) 1307static void clk_reparent(struct clk_core *clk, struct clk_core *new_parent)
1198{ 1308{
1199 hlist_del(&clk->child_node); 1309 hlist_del(&clk->child_node);
1200 1310
@@ -1211,10 +1321,11 @@ static void clk_reparent(struct clk *clk, struct clk *new_parent)
1211 clk->parent = new_parent; 1321 clk->parent = new_parent;
1212} 1322}
1213 1323
1214static struct clk *__clk_set_parent_before(struct clk *clk, struct clk *parent) 1324static struct clk_core *__clk_set_parent_before(struct clk_core *clk,
1325 struct clk_core *parent)
1215{ 1326{
1216 unsigned long flags; 1327 unsigned long flags;
1217 struct clk *old_parent = clk->parent; 1328 struct clk_core *old_parent = clk->parent;
1218 1329
1219 /* 1330 /*
1220 * Migrate prepare state between parents and prevent race with 1331 * Migrate prepare state between parents and prevent race with
@@ -1234,9 +1345,9 @@ static struct clk *__clk_set_parent_before(struct clk *clk, struct clk *parent)
1234 * See also: Comment for clk_set_parent() below. 1345 * See also: Comment for clk_set_parent() below.
1235 */ 1346 */
1236 if (clk->prepare_count) { 1347 if (clk->prepare_count) {
1237 __clk_prepare(parent); 1348 clk_core_prepare(parent);
1238 clk_enable(parent); 1349 clk_core_enable(parent);
1239 clk_enable(clk); 1350 clk_core_enable(clk);
1240 } 1351 }
1241 1352
1242 /* update the clk tree topology */ 1353 /* update the clk tree topology */
@@ -1247,25 +1358,27 @@ static struct clk *__clk_set_parent_before(struct clk *clk, struct clk *parent)
1247 return old_parent; 1358 return old_parent;
1248} 1359}
1249 1360
1250static void __clk_set_parent_after(struct clk *clk, struct clk *parent, 1361static void __clk_set_parent_after(struct clk_core *core,
1251 struct clk *old_parent) 1362 struct clk_core *parent,
1363 struct clk_core *old_parent)
1252{ 1364{
1253 /* 1365 /*
1254 * Finish the migration of prepare state and undo the changes done 1366 * Finish the migration of prepare state and undo the changes done
1255 * for preventing a race with clk_enable(). 1367 * for preventing a race with clk_enable().
1256 */ 1368 */
1257 if (clk->prepare_count) { 1369 if (core->prepare_count) {
1258 clk_disable(clk); 1370 clk_core_disable(core);
1259 clk_disable(old_parent); 1371 clk_core_disable(old_parent);
1260 __clk_unprepare(old_parent); 1372 clk_core_unprepare(old_parent);
1261 } 1373 }
1262} 1374}
1263 1375
1264static int __clk_set_parent(struct clk *clk, struct clk *parent, u8 p_index) 1376static int __clk_set_parent(struct clk_core *clk, struct clk_core *parent,
1377 u8 p_index)
1265{ 1378{
1266 unsigned long flags; 1379 unsigned long flags;
1267 int ret = 0; 1380 int ret = 0;
1268 struct clk *old_parent; 1381 struct clk_core *old_parent;
1269 1382
1270 old_parent = __clk_set_parent_before(clk, parent); 1383 old_parent = __clk_set_parent_before(clk, parent);
1271 1384
@@ -1279,9 +1392,9 @@ static int __clk_set_parent(struct clk *clk, struct clk *parent, u8 p_index)
1279 clk_enable_unlock(flags); 1392 clk_enable_unlock(flags);
1280 1393
1281 if (clk->prepare_count) { 1394 if (clk->prepare_count) {
1282 clk_disable(clk); 1395 clk_core_disable(clk);
1283 clk_disable(parent); 1396 clk_core_disable(parent);
1284 __clk_unprepare(parent); 1397 clk_core_unprepare(parent);
1285 } 1398 }
1286 return ret; 1399 return ret;
1287 } 1400 }
@@ -1307,9 +1420,10 @@ static int __clk_set_parent(struct clk *clk, struct clk *parent, u8 p_index)
1307 * 1420 *
1308 * Caller must hold prepare_lock. 1421 * Caller must hold prepare_lock.
1309 */ 1422 */
1310static int __clk_speculate_rates(struct clk *clk, unsigned long parent_rate) 1423static int __clk_speculate_rates(struct clk_core *clk,
1424 unsigned long parent_rate)
1311{ 1425{
1312 struct clk *child; 1426 struct clk_core *child;
1313 unsigned long new_rate; 1427 unsigned long new_rate;
1314 int ret = NOTIFY_DONE; 1428 int ret = NOTIFY_DONE;
1315 1429
@@ -1335,10 +1449,10 @@ out:
1335 return ret; 1449 return ret;
1336} 1450}
1337 1451
1338static void clk_calc_subtree(struct clk *clk, unsigned long new_rate, 1452static void clk_calc_subtree(struct clk_core *clk, unsigned long new_rate,
1339 struct clk *new_parent, u8 p_index) 1453 struct clk_core *new_parent, u8 p_index)
1340{ 1454{
1341 struct clk *child; 1455 struct clk_core *child;
1342 1456
1343 clk->new_rate = new_rate; 1457 clk->new_rate = new_rate;
1344 clk->new_parent = new_parent; 1458 clk->new_parent = new_parent;
@@ -1358,10 +1472,11 @@ static void clk_calc_subtree(struct clk *clk, unsigned long new_rate,
1358 * calculate the new rates returning the topmost clock that has to be 1472 * calculate the new rates returning the topmost clock that has to be
1359 * changed. 1473 * changed.
1360 */ 1474 */
1361static struct clk *clk_calc_new_rates(struct clk *clk, unsigned long rate) 1475static struct clk_core *clk_calc_new_rates(struct clk_core *clk,
1476 unsigned long rate)
1362{ 1477{
1363 struct clk *top = clk; 1478 struct clk_core *top = clk;
1364 struct clk *old_parent, *parent; 1479 struct clk_core *old_parent, *parent;
1365 struct clk_hw *parent_hw; 1480 struct clk_hw *parent_hw;
1366 unsigned long best_parent_rate = 0; 1481 unsigned long best_parent_rate = 0;
1367 unsigned long new_rate; 1482 unsigned long new_rate;
@@ -1382,7 +1497,7 @@ static struct clk *clk_calc_new_rates(struct clk *clk, unsigned long rate)
1382 new_rate = clk->ops->determine_rate(clk->hw, rate, 1497 new_rate = clk->ops->determine_rate(clk->hw, rate,
1383 &best_parent_rate, 1498 &best_parent_rate,
1384 &parent_hw); 1499 &parent_hw);
1385 parent = parent_hw ? parent_hw->clk : NULL; 1500 parent = parent_hw ? parent_hw->core : NULL;
1386 } else if (clk->ops->round_rate) { 1501 } else if (clk->ops->round_rate) {
1387 new_rate = clk->ops->round_rate(clk->hw, rate, 1502 new_rate = clk->ops->round_rate(clk->hw, rate,
1388 &best_parent_rate); 1503 &best_parent_rate);
@@ -1430,9 +1545,10 @@ out:
1430 * so that in case of an error we can walk down the whole tree again and 1545 * so that in case of an error we can walk down the whole tree again and
1431 * abort the change. 1546 * abort the change.
1432 */ 1547 */
1433static struct clk *clk_propagate_rate_change(struct clk *clk, unsigned long event) 1548static struct clk_core *clk_propagate_rate_change(struct clk_core *clk,
1549 unsigned long event)
1434{ 1550{
1435 struct clk *child, *tmp_clk, *fail_clk = NULL; 1551 struct clk_core *child, *tmp_clk, *fail_clk = NULL;
1436 int ret = NOTIFY_DONE; 1552 int ret = NOTIFY_DONE;
1437 1553
1438 if (clk->rate == clk->new_rate) 1554 if (clk->rate == clk->new_rate)
@@ -1467,14 +1583,14 @@ static struct clk *clk_propagate_rate_change(struct clk *clk, unsigned long even
1467 * walk down a subtree and set the new rates notifying the rate 1583 * walk down a subtree and set the new rates notifying the rate
1468 * change on the way 1584 * change on the way
1469 */ 1585 */
1470static void clk_change_rate(struct clk *clk) 1586static void clk_change_rate(struct clk_core *clk)
1471{ 1587{
1472 struct clk *child; 1588 struct clk_core *child;
1473 struct hlist_node *tmp; 1589 struct hlist_node *tmp;
1474 unsigned long old_rate; 1590 unsigned long old_rate;
1475 unsigned long best_parent_rate = 0; 1591 unsigned long best_parent_rate = 0;
1476 bool skip_set_rate = false; 1592 bool skip_set_rate = false;
1477 struct clk *old_parent; 1593 struct clk_core *old_parent;
1478 1594
1479 old_rate = clk->rate; 1595 old_rate = clk->rate;
1480 1596
@@ -1545,7 +1661,7 @@ static void clk_change_rate(struct clk *clk)
1545 */ 1661 */
1546int clk_set_rate(struct clk *clk, unsigned long rate) 1662int clk_set_rate(struct clk *clk, unsigned long rate)
1547{ 1663{
1548 struct clk *top, *fail_clk; 1664 struct clk_core *top, *fail_clk;
1549 int ret = 0; 1665 int ret = 0;
1550 1666
1551 if (!clk) 1667 if (!clk)
@@ -1558,13 +1674,14 @@ int clk_set_rate(struct clk *clk, unsigned long rate)
1558 if (rate == clk_get_rate(clk)) 1674 if (rate == clk_get_rate(clk))
1559 goto out; 1675 goto out;
1560 1676
1561 if ((clk->flags & CLK_SET_RATE_GATE) && clk->prepare_count) { 1677 if ((clk->core->flags & CLK_SET_RATE_GATE) &&
1678 clk->core->prepare_count) {
1562 ret = -EBUSY; 1679 ret = -EBUSY;
1563 goto out; 1680 goto out;
1564 } 1681 }
1565 1682
1566 /* calculate new rates and get the topmost changed clock */ 1683 /* calculate new rates and get the topmost changed clock */
1567 top = clk_calc_new_rates(clk, rate); 1684 top = clk_calc_new_rates(clk->core, rate);
1568 if (!top) { 1685 if (!top) {
1569 ret = -EINVAL; 1686 ret = -EINVAL;
1570 goto out; 1687 goto out;
@@ -1615,11 +1732,11 @@ EXPORT_SYMBOL_GPL(clk_get_parent);
1615 * 1732 *
1616 * For single-parent clocks without .get_parent, first check to see if the 1733 * For single-parent clocks without .get_parent, first check to see if the
1617 * .parents array exists, and if so use it to avoid an expensive tree 1734 * .parents array exists, and if so use it to avoid an expensive tree
1618 * traversal. If .parents does not exist then walk the tree with __clk_lookup. 1735 * traversal. If .parents does not exist then walk the tree.
1619 */ 1736 */
1620static struct clk *__clk_init_parent(struct clk *clk) 1737static struct clk_core *__clk_init_parent(struct clk_core *clk)
1621{ 1738{
1622 struct clk *ret = NULL; 1739 struct clk_core *ret = NULL;
1623 u8 index; 1740 u8 index;
1624 1741
1625 /* handle the trivial cases */ 1742 /* handle the trivial cases */
@@ -1629,7 +1746,7 @@ static struct clk *__clk_init_parent(struct clk *clk)
1629 1746
1630 if (clk->num_parents == 1) { 1747 if (clk->num_parents == 1) {
1631 if (IS_ERR_OR_NULL(clk->parent)) 1748 if (IS_ERR_OR_NULL(clk->parent))
1632 clk->parent = __clk_lookup(clk->parent_names[0]); 1749 clk->parent = clk_core_lookup(clk->parent_names[0]);
1633 ret = clk->parent; 1750 ret = clk->parent;
1634 goto out; 1751 goto out;
1635 } 1752 }
@@ -1643,8 +1760,8 @@ static struct clk *__clk_init_parent(struct clk *clk)
1643 1760
1644 /* 1761 /*
1645 * Do our best to cache parent clocks in clk->parents. This prevents 1762 * Do our best to cache parent clocks in clk->parents. This prevents
1646 * unnecessary and expensive calls to __clk_lookup. We don't set 1763 * unnecessary and expensive lookups. We don't set clk->parent here;
1647 * clk->parent here; that is done by the calling function 1764 * that is done by the calling function.
1648 */ 1765 */
1649 1766
1650 index = clk->ops->get_parent(clk->hw); 1767 index = clk->ops->get_parent(clk->hw);
@@ -1654,13 +1771,14 @@ static struct clk *__clk_init_parent(struct clk *clk)
1654 kcalloc(clk->num_parents, sizeof(struct clk *), 1771 kcalloc(clk->num_parents, sizeof(struct clk *),
1655 GFP_KERNEL); 1772 GFP_KERNEL);
1656 1773
1657 ret = clk_get_parent_by_index(clk, index); 1774 ret = clk_core_get_parent_by_index(clk, index);
1658 1775
1659out: 1776out:
1660 return ret; 1777 return ret;
1661} 1778}
1662 1779
1663void __clk_reparent(struct clk *clk, struct clk *new_parent) 1780static void clk_core_reparent(struct clk_core *clk,
1781 struct clk_core *new_parent)
1664{ 1782{
1665 clk_reparent(clk, new_parent); 1783 clk_reparent(clk, new_parent);
1666 __clk_recalc_accuracies(clk); 1784 __clk_recalc_accuracies(clk);
@@ -1679,42 +1797,29 @@ void __clk_reparent(struct clk *clk, struct clk *new_parent)
1679 */ 1797 */
1680bool clk_has_parent(struct clk *clk, struct clk *parent) 1798bool clk_has_parent(struct clk *clk, struct clk *parent)
1681{ 1799{
1800 struct clk_core *core, *parent_core;
1682 unsigned int i; 1801 unsigned int i;
1683 1802
1684 /* NULL clocks should be nops, so return success if either is NULL. */ 1803 /* NULL clocks should be nops, so return success if either is NULL. */
1685 if (!clk || !parent) 1804 if (!clk || !parent)
1686 return true; 1805 return true;
1687 1806
1807 core = clk->core;
1808 parent_core = parent->core;
1809
1688 /* Optimize for the case where the parent is already the parent. */ 1810 /* Optimize for the case where the parent is already the parent. */
1689 if (clk->parent == parent) 1811 if (core->parent == parent_core)
1690 return true; 1812 return true;
1691 1813
1692 for (i = 0; i < clk->num_parents; i++) 1814 for (i = 0; i < core->num_parents; i++)
1693 if (strcmp(clk->parent_names[i], parent->name) == 0) 1815 if (strcmp(core->parent_names[i], parent_core->name) == 0)
1694 return true; 1816 return true;
1695 1817
1696 return false; 1818 return false;
1697} 1819}
1698EXPORT_SYMBOL_GPL(clk_has_parent); 1820EXPORT_SYMBOL_GPL(clk_has_parent);
1699 1821
1700/** 1822static int clk_core_set_parent(struct clk_core *clk, struct clk_core *parent)
1701 * clk_set_parent - switch the parent of a mux clk
1702 * @clk: the mux clk whose input we are switching
1703 * @parent: the new input to clk
1704 *
1705 * Re-parent clk to use parent as its new input source. If clk is in
1706 * prepared state, the clk will get enabled for the duration of this call. If
1707 * that's not acceptable for a specific clk (Eg: the consumer can't handle
1708 * that, the reparenting is glitchy in hardware, etc), use the
1709 * CLK_SET_PARENT_GATE flag to allow reparenting only when clk is unprepared.
1710 *
1711 * After successfully changing clk's parent clk_set_parent will update the
1712 * clk topology, sysfs topology and propagate rate recalculation via
1713 * __clk_recalc_rates.
1714 *
1715 * Returns 0 on success, -EERROR otherwise.
1716 */
1717int clk_set_parent(struct clk *clk, struct clk *parent)
1718{ 1823{
1719 int ret = 0; 1824 int ret = 0;
1720 int p_index = 0; 1825 int p_index = 0;
@@ -1774,6 +1879,31 @@ out:
1774 1879
1775 return ret; 1880 return ret;
1776} 1881}
1882
1883/**
1884 * clk_set_parent - switch the parent of a mux clk
1885 * @clk: the mux clk whose input we are switching
1886 * @parent: the new input to clk
1887 *
1888 * Re-parent clk to use parent as its new input source. If clk is in
1889 * prepared state, the clk will get enabled for the duration of this call. If
1890 * that's not acceptable for a specific clk (Eg: the consumer can't handle
1891 * that, the reparenting is glitchy in hardware, etc), use the
1892 * CLK_SET_PARENT_GATE flag to allow reparenting only when clk is unprepared.
1893 *
1894 * After successfully changing clk's parent clk_set_parent will update the
1895 * clk topology, sysfs topology and propagate rate recalculation via
1896 * __clk_recalc_rates.
1897 *
1898 * Returns 0 on success, -EERROR otherwise.
1899 */
1900int clk_set_parent(struct clk *clk, struct clk *parent)
1901{
1902 if (!clk)
1903 return 0;
1904
1905 return clk_core_set_parent(clk->core, parent ? parent->core : NULL);
1906}
1777EXPORT_SYMBOL_GPL(clk_set_parent); 1907EXPORT_SYMBOL_GPL(clk_set_parent);
1778 1908
1779/** 1909/**
@@ -1810,13 +1940,13 @@ int clk_set_phase(struct clk *clk, int degrees)
1810 1940
1811 clk_prepare_lock(); 1941 clk_prepare_lock();
1812 1942
1813 if (!clk->ops->set_phase) 1943 if (!clk->core->ops->set_phase)
1814 goto out_unlock; 1944 goto out_unlock;
1815 1945
1816 ret = clk->ops->set_phase(clk->hw, degrees); 1946 ret = clk->core->ops->set_phase(clk->core->hw, degrees);
1817 1947
1818 if (!ret) 1948 if (!ret)
1819 clk->phase = degrees; 1949 clk->core->phase = degrees;
1820 1950
1821out_unlock: 1951out_unlock:
1822 clk_prepare_unlock(); 1952 clk_prepare_unlock();
@@ -1826,14 +1956,7 @@ out:
1826} 1956}
1827EXPORT_SYMBOL_GPL(clk_set_phase); 1957EXPORT_SYMBOL_GPL(clk_set_phase);
1828 1958
1829/** 1959static int clk_core_get_phase(struct clk_core *clk)
1830 * clk_get_phase - return the phase shift of a clock signal
1831 * @clk: clock signal source
1832 *
1833 * Returns the phase shift of a clock node in degrees, otherwise returns
1834 * -EERROR.
1835 */
1836int clk_get_phase(struct clk *clk)
1837{ 1960{
1838 int ret = 0; 1961 int ret = 0;
1839 1962
@@ -1850,26 +1973,44 @@ out:
1850EXPORT_SYMBOL_GPL(clk_get_phase); 1973EXPORT_SYMBOL_GPL(clk_get_phase);
1851 1974
1852/** 1975/**
1976 * clk_get_phase - return the phase shift of a clock signal
1977 * @clk: clock signal source
1978 *
1979 * Returns the phase shift of a clock node in degrees, otherwise returns
1980 * -EERROR.
1981 */
1982int clk_get_phase(struct clk *clk)
1983{
1984 if (!clk)
1985 return 0;
1986
1987 return clk_core_get_phase(clk->core);
1988}
1989
1990/**
1853 * __clk_init - initialize the data structures in a struct clk 1991 * __clk_init - initialize the data structures in a struct clk
1854 * @dev: device initializing this clk, placeholder for now 1992 * @dev: device initializing this clk, placeholder for now
1855 * @clk: clk being initialized 1993 * @clk: clk being initialized
1856 * 1994 *
1857 * Initializes the lists in struct clk, queries the hardware for the 1995 * Initializes the lists in struct clk_core, queries the hardware for the
1858 * parent and rate and sets them both. 1996 * parent and rate and sets them both.
1859 */ 1997 */
1860int __clk_init(struct device *dev, struct clk *clk) 1998int __clk_init(struct device *dev, struct clk *clk_user)
1861{ 1999{
1862 int i, ret = 0; 2000 int i, ret = 0;
1863 struct clk *orphan; 2001 struct clk_core *orphan;
1864 struct hlist_node *tmp2; 2002 struct hlist_node *tmp2;
2003 struct clk_core *clk;
1865 2004
1866 if (!clk) 2005 if (!clk_user)
1867 return -EINVAL; 2006 return -EINVAL;
1868 2007
2008 clk = clk_user->core;
2009
1869 clk_prepare_lock(); 2010 clk_prepare_lock();
1870 2011
1871 /* check to see if a clock with this name is already registered */ 2012 /* check to see if a clock with this name is already registered */
1872 if (__clk_lookup(clk->name)) { 2013 if (clk_core_lookup(clk->name)) {
1873 pr_debug("%s: clk %s already initialized\n", 2014 pr_debug("%s: clk %s already initialized\n",
1874 __func__, clk->name); 2015 __func__, clk->name);
1875 ret = -EEXIST; 2016 ret = -EEXIST;
@@ -1921,7 +2062,7 @@ int __clk_init(struct device *dev, struct clk *clk)
1921 clk->parents = kcalloc(clk->num_parents, sizeof(struct clk *), 2062 clk->parents = kcalloc(clk->num_parents, sizeof(struct clk *),
1922 GFP_KERNEL); 2063 GFP_KERNEL);
1923 /* 2064 /*
1924 * __clk_lookup returns NULL for parents that have not been 2065 * clk_core_lookup returns NULL for parents that have not been
1925 * clk_init'd; thus any access to clk->parents[] must check 2066 * clk_init'd; thus any access to clk->parents[] must check
1926 * for a NULL pointer. We can always perform lazy lookups for 2067 * for a NULL pointer. We can always perform lazy lookups for
1927 * missing parents later on. 2068 * missing parents later on.
@@ -1929,7 +2070,7 @@ int __clk_init(struct device *dev, struct clk *clk)
1929 if (clk->parents) 2070 if (clk->parents)
1930 for (i = 0; i < clk->num_parents; i++) 2071 for (i = 0; i < clk->num_parents; i++)
1931 clk->parents[i] = 2072 clk->parents[i] =
1932 __clk_lookup(clk->parent_names[i]); 2073 clk_core_lookup(clk->parent_names[i]);
1933 } 2074 }
1934 2075
1935 clk->parent = __clk_init_parent(clk); 2076 clk->parent = __clk_init_parent(clk);
@@ -1985,7 +2126,7 @@ int __clk_init(struct device *dev, struct clk *clk)
1985 */ 2126 */
1986 if (clk->ops->recalc_rate) 2127 if (clk->ops->recalc_rate)
1987 clk->rate = clk->ops->recalc_rate(clk->hw, 2128 clk->rate = clk->ops->recalc_rate(clk->hw,
1988 __clk_get_rate(clk->parent)); 2129 clk_core_get_rate_nolock(clk->parent));
1989 else if (clk->parent) 2130 else if (clk->parent)
1990 clk->rate = clk->parent->rate; 2131 clk->rate = clk->parent->rate;
1991 else 2132 else
@@ -1999,13 +2140,13 @@ int __clk_init(struct device *dev, struct clk *clk)
1999 if (orphan->num_parents && orphan->ops->get_parent) { 2140 if (orphan->num_parents && orphan->ops->get_parent) {
2000 i = orphan->ops->get_parent(orphan->hw); 2141 i = orphan->ops->get_parent(orphan->hw);
2001 if (!strcmp(clk->name, orphan->parent_names[i])) 2142 if (!strcmp(clk->name, orphan->parent_names[i]))
2002 __clk_reparent(orphan, clk); 2143 clk_core_reparent(orphan, clk);
2003 continue; 2144 continue;
2004 } 2145 }
2005 2146
2006 for (i = 0; i < orphan->num_parents; i++) 2147 for (i = 0; i < orphan->num_parents; i++)
2007 if (!strcmp(clk->name, orphan->parent_names[i])) { 2148 if (!strcmp(clk->name, orphan->parent_names[i])) {
2008 __clk_reparent(orphan, clk); 2149 clk_core_reparent(orphan, clk);
2009 break; 2150 break;
2010 } 2151 }
2011 } 2152 }
@@ -2031,6 +2172,26 @@ out:
2031 return ret; 2172 return ret;
2032} 2173}
2033 2174
2175struct clk *__clk_create_clk(struct clk_hw *hw, const char *dev_id,
2176 const char *con_id)
2177{
2178 struct clk *clk;
2179
2180 /* This is to allow this function to be chained to others */
2181 if (!hw || IS_ERR(hw))
2182 return (struct clk *) hw;
2183
2184 clk = kzalloc(sizeof(*clk), GFP_KERNEL);
2185 if (!clk)
2186 return ERR_PTR(-ENOMEM);
2187
2188 clk->core = hw->core;
2189 clk->dev_id = dev_id;
2190 clk->con_id = con_id;
2191
2192 return clk;
2193}
2194
2034/** 2195/**
2035 * clk_register - allocate a new clock, register it and return an opaque cookie 2196 * clk_register - allocate a new clock, register it and return an opaque cookie
2036 * @dev: device that is registering this clock 2197 * @dev: device that is registering this clock
@@ -2045,7 +2206,7 @@ out:
2045struct clk *clk_register(struct device *dev, struct clk_hw *hw) 2206struct clk *clk_register(struct device *dev, struct clk_hw *hw)
2046{ 2207{
2047 int i, ret; 2208 int i, ret;
2048 struct clk *clk; 2209 struct clk_core *clk;
2049 2210
2050 clk = kzalloc(sizeof(*clk), GFP_KERNEL); 2211 clk = kzalloc(sizeof(*clk), GFP_KERNEL);
2051 if (!clk) { 2212 if (!clk) {
@@ -2066,7 +2227,7 @@ struct clk *clk_register(struct device *dev, struct clk_hw *hw)
2066 clk->hw = hw; 2227 clk->hw = hw;
2067 clk->flags = hw->init->flags; 2228 clk->flags = hw->init->flags;
2068 clk->num_parents = hw->init->num_parents; 2229 clk->num_parents = hw->init->num_parents;
2069 hw->clk = clk; 2230 hw->core = clk;
2070 2231
2071 /* allocate local copy in case parent_names is __initdata */ 2232 /* allocate local copy in case parent_names is __initdata */
2072 clk->parent_names = kcalloc(clk->num_parents, sizeof(char *), 2233 clk->parent_names = kcalloc(clk->num_parents, sizeof(char *),
@@ -2090,10 +2251,19 @@ struct clk *clk_register(struct device *dev, struct clk_hw *hw)
2090 } 2251 }
2091 } 2252 }
2092 2253
2093 ret = __clk_init(dev, clk); 2254 hw->clk = __clk_create_clk(hw, NULL, NULL);
2255 if (IS_ERR(hw->clk)) {
2256 pr_err("%s: could not allocate per-user clk\n", __func__);
2257 ret = PTR_ERR(hw->clk);
2258 goto fail_parent_names_copy;
2259 }
2260
2261 ret = __clk_init(dev, hw->clk);
2094 if (!ret) 2262 if (!ret)
2095 return clk; 2263 return hw->clk;
2096 2264
2265 kfree(hw->clk);
2266 hw->clk = NULL;
2097fail_parent_names_copy: 2267fail_parent_names_copy:
2098 while (--i >= 0) 2268 while (--i >= 0)
2099 kfree(clk->parent_names[i]); 2269 kfree(clk->parent_names[i]);
@@ -2113,7 +2283,7 @@ EXPORT_SYMBOL_GPL(clk_register);
2113 */ 2283 */
2114static void __clk_release(struct kref *ref) 2284static void __clk_release(struct kref *ref)
2115{ 2285{
2116 struct clk *clk = container_of(ref, struct clk, ref); 2286 struct clk_core *clk = container_of(ref, struct clk_core, ref);
2117 int i = clk->num_parents; 2287 int i = clk->num_parents;
2118 2288
2119 kfree(clk->parents); 2289 kfree(clk->parents);
@@ -2171,12 +2341,13 @@ void clk_unregister(struct clk *clk)
2171 if (!clk || WARN_ON_ONCE(IS_ERR(clk))) 2341 if (!clk || WARN_ON_ONCE(IS_ERR(clk)))
2172 return; 2342 return;
2173 2343
2174 clk_debug_unregister(clk); 2344 clk_debug_unregister(clk->core);
2175 2345
2176 clk_prepare_lock(); 2346 clk_prepare_lock();
2177 2347
2178 if (clk->ops == &clk_nodrv_ops) { 2348 if (clk->core->ops == &clk_nodrv_ops) {
2179 pr_err("%s: unregistered clock: %s\n", __func__, clk->name); 2349 pr_err("%s: unregistered clock: %s\n", __func__,
2350 clk->core->name);
2180 return; 2351 return;
2181 } 2352 }
2182 /* 2353 /*
@@ -2184,24 +2355,25 @@ void clk_unregister(struct clk *clk)
2184 * a reference to this clock. 2355 * a reference to this clock.
2185 */ 2356 */
2186 flags = clk_enable_lock(); 2357 flags = clk_enable_lock();
2187 clk->ops = &clk_nodrv_ops; 2358 clk->core->ops = &clk_nodrv_ops;
2188 clk_enable_unlock(flags); 2359 clk_enable_unlock(flags);
2189 2360
2190 if (!hlist_empty(&clk->children)) { 2361 if (!hlist_empty(&clk->core->children)) {
2191 struct clk *child; 2362 struct clk_core *child;
2192 struct hlist_node *t; 2363 struct hlist_node *t;
2193 2364
2194 /* Reparent all children to the orphan list. */ 2365 /* Reparent all children to the orphan list. */
2195 hlist_for_each_entry_safe(child, t, &clk->children, child_node) 2366 hlist_for_each_entry_safe(child, t, &clk->core->children,
2196 clk_set_parent(child, NULL); 2367 child_node)
2368 clk_core_set_parent(child, NULL);
2197 } 2369 }
2198 2370
2199 hlist_del_init(&clk->child_node); 2371 hlist_del_init(&clk->core->child_node);
2200 2372
2201 if (clk->prepare_count) 2373 if (clk->core->prepare_count)
2202 pr_warn("%s: unregistering prepared clock: %s\n", 2374 pr_warn("%s: unregistering prepared clock: %s\n",
2203 __func__, clk->name); 2375 __func__, clk->core->name);
2204 kref_put(&clk->ref, __clk_release); 2376 kref_put(&clk->core->ref, __clk_release);
2205 2377
2206 clk_prepare_unlock(); 2378 clk_prepare_unlock();
2207} 2379}
@@ -2269,30 +2441,39 @@ EXPORT_SYMBOL_GPL(devm_clk_unregister);
2269 */ 2441 */
2270int __clk_get(struct clk *clk) 2442int __clk_get(struct clk *clk)
2271{ 2443{
2272 if (clk) { 2444 struct clk_core *core = !clk ? NULL : clk->core;
2273 if (!try_module_get(clk->owner)) 2445
2446 if (core) {
2447 if (!try_module_get(core->owner))
2274 return 0; 2448 return 0;
2275 2449
2276 kref_get(&clk->ref); 2450 kref_get(&core->ref);
2277 } 2451 }
2278 return 1; 2452 return 1;
2279} 2453}
2280 2454
2281void __clk_put(struct clk *clk) 2455static void clk_core_put(struct clk_core *core)
2282{ 2456{
2283 struct module *owner; 2457 struct module *owner;
2284 2458
2285 if (!clk || WARN_ON_ONCE(IS_ERR(clk))) 2459 owner = core->owner;
2286 return;
2287 2460
2288 clk_prepare_lock(); 2461 clk_prepare_lock();
2289 owner = clk->owner; 2462 kref_put(&core->ref, __clk_release);
2290 kref_put(&clk->ref, __clk_release);
2291 clk_prepare_unlock(); 2463 clk_prepare_unlock();
2292 2464
2293 module_put(owner); 2465 module_put(owner);
2294} 2466}
2295 2467
2468void __clk_put(struct clk *clk)
2469{
2470 if (!clk || WARN_ON_ONCE(IS_ERR(clk)))
2471 return;
2472
2473 clk_core_put(clk->core);
2474 kfree(clk);
2475}
2476
2296/*** clk rate change notifiers ***/ 2477/*** clk rate change notifiers ***/
2297 2478
2298/** 2479/**
@@ -2345,7 +2526,7 @@ int clk_notifier_register(struct clk *clk, struct notifier_block *nb)
2345 2526
2346 ret = srcu_notifier_chain_register(&cn->notifier_head, nb); 2527 ret = srcu_notifier_chain_register(&cn->notifier_head, nb);
2347 2528
2348 clk->notifier_count++; 2529 clk->core->notifier_count++;
2349 2530
2350out: 2531out:
2351 clk_prepare_unlock(); 2532 clk_prepare_unlock();
@@ -2382,7 +2563,7 @@ int clk_notifier_unregister(struct clk *clk, struct notifier_block *nb)
2382 if (cn->clk == clk) { 2563 if (cn->clk == clk) {
2383 ret = srcu_notifier_chain_unregister(&cn->notifier_head, nb); 2564 ret = srcu_notifier_chain_unregister(&cn->notifier_head, nb);
2384 2565
2385 clk->notifier_count--; 2566 clk->core->notifier_count--;
2386 2567
2387 /* XXX the notifier code should handle this better */ 2568 /* XXX the notifier code should handle this better */
2388 if (!cn->notifier_head.head) { 2569 if (!cn->notifier_head.head) {
diff --git a/drivers/clk/clk.h b/drivers/clk/clk.h
index c798138f023f..23c44e51df69 100644
--- a/drivers/clk/clk.h
+++ b/drivers/clk/clk.h
@@ -9,9 +9,14 @@
9 * published by the Free Software Foundation. 9 * published by the Free Software Foundation.
10 */ 10 */
11 11
12struct clk_hw;
13
12#if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK) 14#if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK)
13struct clk *of_clk_get_by_clkspec(struct of_phandle_args *clkspec); 15struct clk *of_clk_get_by_clkspec(struct of_phandle_args *clkspec);
14struct clk *__of_clk_get_from_provider(struct of_phandle_args *clkspec); 16struct clk *__of_clk_get_from_provider(struct of_phandle_args *clkspec);
15void of_clk_lock(void); 17void of_clk_lock(void);
16void of_clk_unlock(void); 18void of_clk_unlock(void);
17#endif 19#endif
20
21struct clk *__clk_create_clk(struct clk_hw *hw, const char *dev_id,
22 const char *con_id);
diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c
index da4bda8b7fc7..901d242f38ea 100644
--- a/drivers/clk/clkdev.c
+++ b/drivers/clk/clkdev.c
@@ -19,6 +19,7 @@
19#include <linux/mutex.h> 19#include <linux/mutex.h>
20#include <linux/clk.h> 20#include <linux/clk.h>
21#include <linux/clkdev.h> 21#include <linux/clkdev.h>
22#include <linux/clk-provider.h>
22#include <linux/of.h> 23#include <linux/of.h>
23 24
24#include "clk.h" 25#include "clk.h"
@@ -53,7 +54,7 @@ struct clk *of_clk_get_by_clkspec(struct of_phandle_args *clkspec)
53 return clk; 54 return clk;
54} 55}
55 56
56struct clk *of_clk_get(struct device_node *np, int index) 57static struct clk *__of_clk_get(struct device_node *np, int index)
57{ 58{
58 struct of_phandle_args clkspec; 59 struct of_phandle_args clkspec;
59 struct clk *clk; 60 struct clk *clk;
@@ -69,20 +70,24 @@ struct clk *of_clk_get(struct device_node *np, int index)
69 70
70 clk = of_clk_get_by_clkspec(&clkspec); 71 clk = of_clk_get_by_clkspec(&clkspec);
71 of_node_put(clkspec.np); 72 of_node_put(clkspec.np);
73
74 return clk;
75}
76
77struct clk *of_clk_get(struct device_node *np, int index)
78{
79 struct clk *clk = __of_clk_get(np, index);
80
81 if (!IS_ERR(clk))
82 clk = __clk_create_clk(__clk_get_hw(clk), np->full_name, NULL);
83
72 return clk; 84 return clk;
73} 85}
74EXPORT_SYMBOL(of_clk_get); 86EXPORT_SYMBOL(of_clk_get);
75 87
76/** 88static struct clk *__of_clk_get_by_name(struct device_node *np,
77 * of_clk_get_by_name() - Parse and lookup a clock referenced by a device node 89 const char *dev_id,
78 * @np: pointer to clock consumer node 90 const char *name)
79 * @name: name of consumer's clock input, or NULL for the first clock reference
80 *
81 * This function parses the clocks and clock-names properties,
82 * and uses them to look up the struct clk from the registered list of clock
83 * providers.
84 */
85struct clk *of_clk_get_by_name(struct device_node *np, const char *name)
86{ 91{
87 struct clk *clk = ERR_PTR(-ENOENT); 92 struct clk *clk = ERR_PTR(-ENOENT);
88 93
@@ -97,9 +102,11 @@ struct clk *of_clk_get_by_name(struct device_node *np, const char *name)
97 */ 102 */
98 if (name) 103 if (name)
99 index = of_property_match_string(np, "clock-names", name); 104 index = of_property_match_string(np, "clock-names", name);
100 clk = of_clk_get(np, index); 105 clk = __of_clk_get(np, index);
101 if (!IS_ERR(clk)) 106 if (!IS_ERR(clk)) {
107 clk = __clk_create_clk(__clk_get_hw(clk), dev_id, name);
102 break; 108 break;
109 }
103 else if (name && index >= 0) { 110 else if (name && index >= 0) {
104 if (PTR_ERR(clk) != -EPROBE_DEFER) 111 if (PTR_ERR(clk) != -EPROBE_DEFER)
105 pr_err("ERROR: could not get clock %s:%s(%i)\n", 112 pr_err("ERROR: could not get clock %s:%s(%i)\n",
@@ -119,7 +126,33 @@ struct clk *of_clk_get_by_name(struct device_node *np, const char *name)
119 126
120 return clk; 127 return clk;
121} 128}
129
130/**
131 * of_clk_get_by_name() - Parse and lookup a clock referenced by a device node
132 * @np: pointer to clock consumer node
133 * @name: name of consumer's clock input, or NULL for the first clock reference
134 *
135 * This function parses the clocks and clock-names properties,
136 * and uses them to look up the struct clk from the registered list of clock
137 * providers.
138 */
139struct clk *of_clk_get_by_name(struct device_node *np, const char *name)
140{
141 if (!np)
142 return ERR_PTR(-ENOENT);
143
144 return __of_clk_get_by_name(np, np->full_name, name);
145}
122EXPORT_SYMBOL(of_clk_get_by_name); 146EXPORT_SYMBOL(of_clk_get_by_name);
147
148#else /* defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK) */
149
150static struct clk *__of_clk_get_by_name(struct device_node *np,
151 const char *dev_id,
152 const char *name)
153{
154 return ERR_PTR(-ENOENT);
155}
123#endif 156#endif
124 157
125/* 158/*
@@ -168,14 +201,29 @@ static struct clk_lookup *clk_find(const char *dev_id, const char *con_id)
168struct clk *clk_get_sys(const char *dev_id, const char *con_id) 201struct clk *clk_get_sys(const char *dev_id, const char *con_id)
169{ 202{
170 struct clk_lookup *cl; 203 struct clk_lookup *cl;
204 struct clk *clk = NULL;
171 205
172 mutex_lock(&clocks_mutex); 206 mutex_lock(&clocks_mutex);
207
173 cl = clk_find(dev_id, con_id); 208 cl = clk_find(dev_id, con_id);
174 if (cl && !__clk_get(cl->clk)) 209 if (!cl)
210 goto out;
211
212 if (!__clk_get(cl->clk)) {
175 cl = NULL; 213 cl = NULL;
214 goto out;
215 }
216
217#if defined(CONFIG_COMMON_CLK)
218 clk = __clk_create_clk(__clk_get_hw(cl->clk), dev_id, con_id);
219#else
220 clk = cl->clk;
221#endif
222
223out:
176 mutex_unlock(&clocks_mutex); 224 mutex_unlock(&clocks_mutex);
177 225
178 return cl ? cl->clk : ERR_PTR(-ENOENT); 226 return cl ? clk : ERR_PTR(-ENOENT);
179} 227}
180EXPORT_SYMBOL(clk_get_sys); 228EXPORT_SYMBOL(clk_get_sys);
181 229
@@ -185,10 +233,8 @@ struct clk *clk_get(struct device *dev, const char *con_id)
185 struct clk *clk; 233 struct clk *clk;
186 234
187 if (dev) { 235 if (dev) {
188 clk = of_clk_get_by_name(dev->of_node, con_id); 236 clk = __of_clk_get_by_name(dev->of_node, dev_id, con_id);
189 if (!IS_ERR(clk)) 237 if (!IS_ERR(clk) || PTR_ERR(clk) == -EPROBE_DEFER)
190 return clk;
191 if (PTR_ERR(clk) == -EPROBE_DEFER)
192 return clk; 238 return clk;
193 } 239 }
194 240
diff --git a/include/linux/clk-private.h b/include/linux/clk-private.h
index c5f40d07686c..ae55d99a2313 100644
--- a/include/linux/clk-private.h
+++ b/include/linux/clk-private.h
@@ -28,20 +28,20 @@
28 28
29struct module; 29struct module;
30 30
31struct clk { 31struct clk_core {
32 const char *name; 32 const char *name;
33 const struct clk_ops *ops; 33 const struct clk_ops *ops;
34 struct clk_hw *hw; 34 struct clk_hw *hw;
35 struct module *owner; 35 struct module *owner;
36 struct clk *parent; 36 struct clk_core *parent;
37 const char **parent_names; 37 const char **parent_names;
38 struct clk **parents; 38 struct clk_core **parents;
39 u8 num_parents; 39 u8 num_parents;
40 u8 new_parent_index; 40 u8 new_parent_index;
41 unsigned long rate; 41 unsigned long rate;
42 unsigned long new_rate; 42 unsigned long new_rate;
43 struct clk *new_parent; 43 struct clk_core *new_parent;
44 struct clk *new_child; 44 struct clk_core *new_child;
45 unsigned long flags; 45 unsigned long flags;
46 unsigned int enable_count; 46 unsigned int enable_count;
47 unsigned int prepare_count; 47 unsigned int prepare_count;
@@ -57,6 +57,12 @@ struct clk {
57 struct kref ref; 57 struct kref ref;
58}; 58};
59 59
60struct clk {
61 struct clk_core *core;
62 const char *dev_id;
63 const char *con_id;
64};
65
60/* 66/*
61 * DOC: Basic clock implementations common to many platforms 67 * DOC: Basic clock implementations common to many platforms
62 * 68 *
@@ -69,6 +75,9 @@ struct clk {
69#define DEFINE_CLK(_name, _ops, _flags, _parent_names, \ 75#define DEFINE_CLK(_name, _ops, _flags, _parent_names, \
70 _parents) \ 76 _parents) \
71 static struct clk _name = { \ 77 static struct clk _name = { \
78 .core = &_name##_core \
79 }; \
80 static struct clk_core _name##_core = { \
72 .name = #_name, \ 81 .name = #_name, \
73 .ops = &_ops, \ 82 .ops = &_ops, \
74 .hw = &_name##_hw.hw, \ 83 .hw = &_name##_hw.hw, \
@@ -81,9 +90,11 @@ struct clk {
81#define DEFINE_CLK_FIXED_RATE(_name, _flags, _rate, \ 90#define DEFINE_CLK_FIXED_RATE(_name, _flags, _rate, \
82 _fixed_rate_flags) \ 91 _fixed_rate_flags) \
83 static struct clk _name; \ 92 static struct clk _name; \
93 static struct clk_core _name##_core; \
84 static const char *_name##_parent_names[] = {}; \ 94 static const char *_name##_parent_names[] = {}; \
85 static struct clk_fixed_rate _name##_hw = { \ 95 static struct clk_fixed_rate _name##_hw = { \
86 .hw = { \ 96 .hw = { \
97 .core = &_name##_core, \
87 .clk = &_name, \ 98 .clk = &_name, \
88 }, \ 99 }, \
89 .fixed_rate = _rate, \ 100 .fixed_rate = _rate, \
@@ -96,14 +107,16 @@ struct clk {
96 _flags, _reg, _bit_idx, \ 107 _flags, _reg, _bit_idx, \
97 _gate_flags, _lock) \ 108 _gate_flags, _lock) \
98 static struct clk _name; \ 109 static struct clk _name; \
110 static struct clk_core _name##_core; \
99 static const char *_name##_parent_names[] = { \ 111 static const char *_name##_parent_names[] = { \
100 _parent_name, \ 112 _parent_name, \
101 }; \ 113 }; \
102 static struct clk *_name##_parents[] = { \ 114 static struct clk_core *_name##_parents[] = { \
103 _parent_ptr, \ 115 _parent_ptr, \
104 }; \ 116 }; \
105 static struct clk_gate _name##_hw = { \ 117 static struct clk_gate _name##_hw = { \
106 .hw = { \ 118 .hw = { \
119 .core = &_name##_core, \
107 .clk = &_name, \ 120 .clk = &_name, \
108 }, \ 121 }, \
109 .reg = _reg, \ 122 .reg = _reg, \
@@ -118,14 +131,16 @@ struct clk {
118 _flags, _reg, _shift, _width, \ 131 _flags, _reg, _shift, _width, \
119 _divider_flags, _table, _lock) \ 132 _divider_flags, _table, _lock) \
120 static struct clk _name; \ 133 static struct clk _name; \
134 static struct clk_core _name##_core; \
121 static const char *_name##_parent_names[] = { \ 135 static const char *_name##_parent_names[] = { \
122 _parent_name, \ 136 _parent_name, \
123 }; \ 137 }; \
124 static struct clk *_name##_parents[] = { \ 138 static struct clk_core *_name##_parents[] = { \
125 _parent_ptr, \ 139 _parent_ptr, \
126 }; \ 140 }; \
127 static struct clk_divider _name##_hw = { \ 141 static struct clk_divider _name##_hw = { \
128 .hw = { \ 142 .hw = { \
143 .core = &_name##_core, \
129 .clk = &_name, \ 144 .clk = &_name, \
130 }, \ 145 }, \
131 .reg = _reg, \ 146 .reg = _reg, \
@@ -157,8 +172,10 @@ struct clk {
157 _reg, _shift, _width, \ 172 _reg, _shift, _width, \
158 _mux_flags, _lock) \ 173 _mux_flags, _lock) \
159 static struct clk _name; \ 174 static struct clk _name; \
175 static struct clk_core _name##_core; \
160 static struct clk_mux _name##_hw = { \ 176 static struct clk_mux _name##_hw = { \
161 .hw = { \ 177 .hw = { \
178 .core = &_name##_core, \
162 .clk = &_name, \ 179 .clk = &_name, \
163 }, \ 180 }, \
164 .reg = _reg, \ 181 .reg = _reg, \
@@ -174,14 +191,16 @@ struct clk {
174 _parent_ptr, _flags, \ 191 _parent_ptr, _flags, \
175 _mult, _div) \ 192 _mult, _div) \
176 static struct clk _name; \ 193 static struct clk _name; \
194 static struct clk_core _name##_core; \
177 static const char *_name##_parent_names[] = { \ 195 static const char *_name##_parent_names[] = { \
178 _parent_name, \ 196 _parent_name, \
179 }; \ 197 }; \
180 static struct clk *_name##_parents[] = { \ 198 static struct clk_core *_name##_parents[] = { \
181 _parent_ptr, \ 199 _parent_ptr, \
182 }; \ 200 }; \
183 static struct clk_fixed_factor _name##_hw = { \ 201 static struct clk_fixed_factor _name##_hw = { \
184 .hw = { \ 202 .hw = { \
203 .core = &_name##_core, \
185 .clk = &_name, \ 204 .clk = &_name, \
186 }, \ 205 }, \
187 .mult = _mult, \ 206 .mult = _mult, \
diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
index 0ed5bf2209ad..12f13b0673af 100644
--- a/include/linux/clk-provider.h
+++ b/include/linux/clk-provider.h
@@ -33,6 +33,7 @@
33#define CLK_GET_ACCURACY_NOCACHE BIT(8) /* do not use the cached clk accuracy */ 33#define CLK_GET_ACCURACY_NOCACHE BIT(8) /* do not use the cached clk accuracy */
34 34
35struct clk_hw; 35struct clk_hw;
36struct clk_core;
36struct dentry; 37struct dentry;
37 38
38/** 39/**
@@ -216,13 +217,17 @@ struct clk_init_data {
216 * clk_foo and then referenced by the struct clk instance that uses struct 217 * clk_foo and then referenced by the struct clk instance that uses struct
217 * clk_foo's clk_ops 218 * clk_foo's clk_ops
218 * 219 *
219 * @clk: pointer to the struct clk instance that points back to this struct 220 * @core: pointer to the struct clk_core instance that points back to this
220 * clk_hw instance 221 * struct clk_hw instance
222 *
223 * @clk: pointer to the per-user struct clk instance that can be used to call
224 * into the clk API
221 * 225 *
222 * @init: pointer to struct clk_init_data that contains the init data shared 226 * @init: pointer to struct clk_init_data that contains the init data shared
223 * with the common clock framework. 227 * with the common clock framework.
224 */ 228 */
225struct clk_hw { 229struct clk_hw {
230 struct clk_core *core;
226 struct clk *clk; 231 struct clk *clk;
227 const struct clk_init_data *init; 232 const struct clk_init_data *init;
228}; 233};
@@ -577,9 +582,6 @@ long __clk_mux_determine_rate_closest(struct clk_hw *hw, unsigned long rate,
577/* 582/*
578 * FIXME clock api without lock protection 583 * FIXME clock api without lock protection
579 */ 584 */
580int __clk_prepare(struct clk *clk);
581void __clk_unprepare(struct clk *clk);
582void __clk_reparent(struct clk *clk, struct clk *new_parent);
583unsigned long __clk_round_rate(struct clk *clk, unsigned long rate); 585unsigned long __clk_round_rate(struct clk *clk, unsigned long rate);
584 586
585struct of_device_id; 587struct of_device_id;