diff options
Diffstat (limited to 'arch/arm/mach-pnx4008/clock.c')
-rw-r--r-- | arch/arm/mach-pnx4008/clock.c | 173 |
1 files changed, 91 insertions, 82 deletions
diff --git a/arch/arm/mach-pnx4008/clock.c b/arch/arm/mach-pnx4008/clock.c index 898c0e88acbc..9d1975fa4d9f 100644 --- a/arch/arm/mach-pnx4008/clock.c +++ b/arch/arm/mach-pnx4008/clock.c | |||
@@ -22,8 +22,9 @@ | |||
22 | #include <linux/delay.h> | 22 | #include <linux/delay.h> |
23 | #include <linux/io.h> | 23 | #include <linux/io.h> |
24 | 24 | ||
25 | #include <mach/hardware.h> | 25 | #include <asm/clkdev.h> |
26 | 26 | ||
27 | #include <mach/hardware.h> | ||
27 | #include <mach/clock.h> | 28 | #include <mach/clock.h> |
28 | #include "clock.h" | 29 | #include "clock.h" |
29 | 30 | ||
@@ -56,18 +57,19 @@ static void propagate_rate(struct clk *clk) | |||
56 | } | 57 | } |
57 | } | 58 | } |
58 | 59 | ||
59 | static inline void clk_reg_disable(struct clk *clk) | 60 | static void clk_reg_disable(struct clk *clk) |
60 | { | 61 | { |
61 | if (clk->enable_reg) | 62 | if (clk->enable_reg) |
62 | __raw_writel(__raw_readl(clk->enable_reg) & | 63 | __raw_writel(__raw_readl(clk->enable_reg) & |
63 | ~(1 << clk->enable_shift), clk->enable_reg); | 64 | ~(1 << clk->enable_shift), clk->enable_reg); |
64 | } | 65 | } |
65 | 66 | ||
66 | static inline void clk_reg_enable(struct clk *clk) | 67 | static int clk_reg_enable(struct clk *clk) |
67 | { | 68 | { |
68 | if (clk->enable_reg) | 69 | if (clk->enable_reg) |
69 | __raw_writel(__raw_readl(clk->enable_reg) | | 70 | __raw_writel(__raw_readl(clk->enable_reg) | |
70 | (1 << clk->enable_shift), clk->enable_reg); | 71 | (1 << clk->enable_shift), clk->enable_reg); |
72 | return 0; | ||
71 | } | 73 | } |
72 | 74 | ||
73 | static inline void clk_reg_disable1(struct clk *clk) | 75 | static inline void clk_reg_disable1(struct clk *clk) |
@@ -636,31 +638,34 @@ static struct clk flash_ck = { | |||
636 | static struct clk i2c0_ck = { | 638 | static struct clk i2c0_ck = { |
637 | .name = "i2c0_ck", | 639 | .name = "i2c0_ck", |
638 | .parent = &per_ck, | 640 | .parent = &per_ck, |
639 | .flags = NEEDS_INITIALIZATION, | 641 | .flags = NEEDS_INITIALIZATION | FIXED_RATE, |
640 | .round_rate = &on_off_round_rate, | ||
641 | .set_rate = &on_off_set_rate, | ||
642 | .enable_shift = 0, | 642 | .enable_shift = 0, |
643 | .enable_reg = I2CCLKCTRL_REG, | 643 | .enable_reg = I2CCLKCTRL_REG, |
644 | .rate = 13000000, | ||
645 | .enable = clk_reg_enable, | ||
646 | .disable = clk_reg_disable, | ||
644 | }; | 647 | }; |
645 | 648 | ||
646 | static struct clk i2c1_ck = { | 649 | static struct clk i2c1_ck = { |
647 | .name = "i2c1_ck", | 650 | .name = "i2c1_ck", |
648 | .parent = &per_ck, | 651 | .parent = &per_ck, |
649 | .flags = NEEDS_INITIALIZATION, | 652 | .flags = NEEDS_INITIALIZATION | FIXED_RATE, |
650 | .round_rate = &on_off_round_rate, | ||
651 | .set_rate = &on_off_set_rate, | ||
652 | .enable_shift = 1, | 653 | .enable_shift = 1, |
653 | .enable_reg = I2CCLKCTRL_REG, | 654 | .enable_reg = I2CCLKCTRL_REG, |
655 | .rate = 13000000, | ||
656 | .enable = clk_reg_enable, | ||
657 | .disable = clk_reg_disable, | ||
654 | }; | 658 | }; |
655 | 659 | ||
656 | static struct clk i2c2_ck = { | 660 | static struct clk i2c2_ck = { |
657 | .name = "i2c2_ck", | 661 | .name = "i2c2_ck", |
658 | .parent = &per_ck, | 662 | .parent = &per_ck, |
659 | .flags = NEEDS_INITIALIZATION, | 663 | .flags = NEEDS_INITIALIZATION | FIXED_RATE, |
660 | .round_rate = &on_off_round_rate, | ||
661 | .set_rate = &on_off_set_rate, | ||
662 | .enable_shift = 2, | 664 | .enable_shift = 2, |
663 | .enable_reg = USB_OTG_CLKCTRL_REG, | 665 | .enable_reg = USB_OTG_CLKCTRL_REG, |
666 | .rate = 13000000, | ||
667 | .enable = clk_reg_enable, | ||
668 | .disable = clk_reg_disable, | ||
664 | }; | 669 | }; |
665 | 670 | ||
666 | static struct clk spi0_ck = { | 671 | static struct clk spi0_ck = { |
@@ -738,16 +743,16 @@ static struct clk wdt_ck = { | |||
738 | .name = "wdt_ck", | 743 | .name = "wdt_ck", |
739 | .parent = &per_ck, | 744 | .parent = &per_ck, |
740 | .flags = NEEDS_INITIALIZATION, | 745 | .flags = NEEDS_INITIALIZATION, |
741 | .round_rate = &on_off_round_rate, | ||
742 | .set_rate = &on_off_set_rate, | ||
743 | .enable_shift = 0, | 746 | .enable_shift = 0, |
744 | .enable_reg = TIMCLKCTRL_REG, | 747 | .enable_reg = TIMCLKCTRL_REG, |
748 | .enable = clk_reg_enable, | ||
749 | .disable = clk_reg_disable, | ||
745 | }; | 750 | }; |
746 | 751 | ||
747 | /* These clocks are visible outside this module | 752 | /* These clocks are visible outside this module |
748 | * and can be initialized | 753 | * and can be initialized |
749 | */ | 754 | */ |
750 | static struct clk *onchip_clks[] = { | 755 | static struct clk *onchip_clks[] __initdata = { |
751 | &ck_13MHz, | 756 | &ck_13MHz, |
752 | &ck_pll1, | 757 | &ck_pll1, |
753 | &ck_pll4, | 758 | &ck_pll4, |
@@ -777,49 +782,74 @@ static struct clk *onchip_clks[] = { | |||
777 | &wdt_ck, | 782 | &wdt_ck, |
778 | }; | 783 | }; |
779 | 784 | ||
780 | static int local_clk_enable(struct clk *clk) | 785 | static struct clk_lookup onchip_clkreg[] = { |
781 | { | 786 | { .clk = &ck_13MHz, .con_id = "ck_13MHz" }, |
782 | int ret = 0; | 787 | { .clk = &ck_pll1, .con_id = "ck_pll1" }, |
783 | 788 | { .clk = &ck_pll4, .con_id = "ck_pll4" }, | |
784 | if (!(clk->flags & FIXED_RATE) && !clk->rate && clk->set_rate | 789 | { .clk = &ck_pll5, .con_id = "ck_pll5" }, |
785 | && clk->user_rate) | 790 | { .clk = &ck_pll3, .con_id = "ck_pll3" }, |
786 | ret = clk->set_rate(clk, clk->user_rate); | 791 | { .clk = &vfp9_ck, .con_id = "vfp9_ck" }, |
787 | return ret; | 792 | { .clk = &m2hclk_ck, .con_id = "m2hclk_ck" }, |
788 | } | 793 | { .clk = &hclk_ck, .con_id = "hclk_ck" }, |
794 | { .clk = &dma_ck, .con_id = "dma_ck" }, | ||
795 | { .clk = &flash_ck, .con_id = "flash_ck" }, | ||
796 | { .clk = &dum_ck, .con_id = "dum_ck" }, | ||
797 | { .clk = &keyscan_ck, .con_id = "keyscan_ck" }, | ||
798 | { .clk = &pwm1_ck, .con_id = "pwm1_ck" }, | ||
799 | { .clk = &pwm2_ck, .con_id = "pwm2_ck" }, | ||
800 | { .clk = &jpeg_ck, .con_id = "jpeg_ck" }, | ||
801 | { .clk = &ms_ck, .con_id = "ms_ck" }, | ||
802 | { .clk = &touch_ck, .con_id = "touch_ck" }, | ||
803 | { .clk = &i2c0_ck, .dev_id = "pnx-i2c.0" }, | ||
804 | { .clk = &i2c1_ck, .dev_id = "pnx-i2c.1" }, | ||
805 | { .clk = &i2c2_ck, .dev_id = "pnx-i2c.2" }, | ||
806 | { .clk = &spi0_ck, .con_id = "spi0_ck" }, | ||
807 | { .clk = &spi1_ck, .con_id = "spi1_ck" }, | ||
808 | { .clk = &uart3_ck, .con_id = "uart3_ck" }, | ||
809 | { .clk = &uart4_ck, .con_id = "uart4_ck" }, | ||
810 | { .clk = &uart5_ck, .con_id = "uart5_ck" }, | ||
811 | { .clk = &uart6_ck, .con_id = "uart6_ck" }, | ||
812 | { .clk = &wdt_ck, .dev_id = "pnx4008-watchdog" }, | ||
813 | }; | ||
789 | 814 | ||
790 | static void local_clk_disable(struct clk *clk) | 815 | static void local_clk_disable(struct clk *clk) |
791 | { | 816 | { |
792 | if (!(clk->flags & FIXED_RATE) && clk->rate && clk->set_rate) | 817 | if (WARN_ON(clk->usecount == 0)) |
793 | clk->set_rate(clk, 0); | 818 | return; |
794 | } | ||
795 | 819 | ||
796 | static void local_clk_unuse(struct clk *clk) | 820 | if (!(--clk->usecount)) { |
797 | { | 821 | if (clk->disable) |
798 | if (clk->usecount > 0 && !(--clk->usecount)) { | 822 | clk->disable(clk); |
799 | local_clk_disable(clk); | 823 | else if (!(clk->flags & FIXED_RATE) && clk->rate && clk->set_rate) |
824 | clk->set_rate(clk, 0); | ||
800 | if (clk->parent) | 825 | if (clk->parent) |
801 | local_clk_unuse(clk->parent); | 826 | local_clk_disable(clk->parent); |
802 | } | 827 | } |
803 | } | 828 | } |
804 | 829 | ||
805 | static int local_clk_use(struct clk *clk) | 830 | static int local_clk_enable(struct clk *clk) |
806 | { | 831 | { |
807 | int ret = 0; | 832 | int ret = 0; |
808 | if (clk->usecount++ == 0) { | ||
809 | if (clk->parent) | ||
810 | ret = local_clk_use(clk->parent); | ||
811 | 833 | ||
812 | if (ret != 0) { | 834 | if (clk->usecount == 0) { |
813 | clk->usecount--; | 835 | if (clk->parent) { |
814 | goto out; | 836 | ret = local_clk_enable(clk->parent); |
837 | if (ret != 0) | ||
838 | goto out; | ||
815 | } | 839 | } |
816 | 840 | ||
817 | ret = local_clk_enable(clk); | 841 | if (clk->enable) |
842 | ret = clk->enable(clk); | ||
843 | else if (!(clk->flags & FIXED_RATE) && !clk->rate && clk->set_rate | ||
844 | && clk->user_rate) | ||
845 | ret = clk->set_rate(clk, clk->user_rate); | ||
818 | 846 | ||
819 | if (ret != 0 && clk->parent) { | 847 | if (ret != 0 && clk->parent) { |
820 | local_clk_unuse(clk->parent); | 848 | local_clk_disable(clk->parent); |
821 | clk->usecount--; | 849 | goto out; |
822 | } | 850 | } |
851 | |||
852 | clk->usecount++; | ||
823 | } | 853 | } |
824 | out: | 854 | out: |
825 | return ret; | 855 | return ret; |
@@ -866,35 +896,6 @@ out: | |||
866 | 896 | ||
867 | EXPORT_SYMBOL(clk_set_rate); | 897 | EXPORT_SYMBOL(clk_set_rate); |
868 | 898 | ||
869 | struct clk *clk_get(struct device *dev, const char *id) | ||
870 | { | ||
871 | struct clk *clk = ERR_PTR(-ENOENT); | ||
872 | struct clk **clkp; | ||
873 | |||
874 | clock_lock(); | ||
875 | for (clkp = onchip_clks; clkp < onchip_clks + ARRAY_SIZE(onchip_clks); | ||
876 | clkp++) { | ||
877 | if (strcmp(id, (*clkp)->name) == 0 | ||
878 | && try_module_get((*clkp)->owner)) { | ||
879 | clk = (*clkp); | ||
880 | break; | ||
881 | } | ||
882 | } | ||
883 | clock_unlock(); | ||
884 | |||
885 | return clk; | ||
886 | } | ||
887 | EXPORT_SYMBOL(clk_get); | ||
888 | |||
889 | void clk_put(struct clk *clk) | ||
890 | { | ||
891 | clock_lock(); | ||
892 | if (clk && !IS_ERR(clk)) | ||
893 | module_put(clk->owner); | ||
894 | clock_unlock(); | ||
895 | } | ||
896 | EXPORT_SYMBOL(clk_put); | ||
897 | |||
898 | unsigned long clk_get_rate(struct clk *clk) | 899 | unsigned long clk_get_rate(struct clk *clk) |
899 | { | 900 | { |
900 | unsigned long ret; | 901 | unsigned long ret; |
@@ -907,10 +908,10 @@ EXPORT_SYMBOL(clk_get_rate); | |||
907 | 908 | ||
908 | int clk_enable(struct clk *clk) | 909 | int clk_enable(struct clk *clk) |
909 | { | 910 | { |
910 | int ret = 0; | 911 | int ret; |
911 | 912 | ||
912 | clock_lock(); | 913 | clock_lock(); |
913 | ret = local_clk_use(clk); | 914 | ret = local_clk_enable(clk); |
914 | clock_unlock(); | 915 | clock_unlock(); |
915 | return ret; | 916 | return ret; |
916 | } | 917 | } |
@@ -920,7 +921,7 @@ EXPORT_SYMBOL(clk_enable); | |||
920 | void clk_disable(struct clk *clk) | 921 | void clk_disable(struct clk *clk) |
921 | { | 922 | { |
922 | clock_lock(); | 923 | clock_lock(); |
923 | local_clk_unuse(clk); | 924 | local_clk_disable(clk); |
924 | clock_unlock(); | 925 | clock_unlock(); |
925 | } | 926 | } |
926 | 927 | ||
@@ -967,18 +968,24 @@ static int __init clk_init(void) | |||
967 | 968 | ||
968 | for (clkp = onchip_clks; clkp < onchip_clks + ARRAY_SIZE(onchip_clks); | 969 | for (clkp = onchip_clks; clkp < onchip_clks + ARRAY_SIZE(onchip_clks); |
969 | clkp++) { | 970 | clkp++) { |
970 | if (((*clkp)->flags & NEEDS_INITIALIZATION) | 971 | struct clk *clk = *clkp; |
971 | && ((*clkp)->set_rate)) { | 972 | if (clk->flags & NEEDS_INITIALIZATION) { |
972 | (*clkp)->user_rate = (*clkp)->rate; | 973 | if (clk->set_rate) { |
973 | local_set_rate((*clkp), (*clkp)->user_rate); | 974 | clk->user_rate = clk->rate; |
974 | if ((*clkp)->set_parent) | 975 | local_set_rate(clk, clk->user_rate); |
975 | (*clkp)->set_parent((*clkp), (*clkp)->parent); | 976 | if (clk->set_parent) |
977 | clk->set_parent(clk, clk->parent); | ||
978 | } | ||
979 | if (clk->enable && clk->usecount) | ||
980 | clk->enable(clk); | ||
981 | if (clk->disable && !clk->usecount) | ||
982 | clk->disable(clk); | ||
976 | } | 983 | } |
977 | pr_debug("%s: clock %s, rate %ld\n", | 984 | pr_debug("%s: clock %s, rate %ld\n", |
978 | __func__, (*clkp)->name, (*clkp)->rate); | 985 | __func__, clk->name, clk->rate); |
979 | } | 986 | } |
980 | 987 | ||
981 | local_clk_use(&ck_pll4); | 988 | local_clk_enable(&ck_pll4); |
982 | 989 | ||
983 | /* if ck_13MHz is not used, disable it. */ | 990 | /* if ck_13MHz is not used, disable it. */ |
984 | if (ck_13MHz.usecount == 0) | 991 | if (ck_13MHz.usecount == 0) |
@@ -987,6 +994,8 @@ static int __init clk_init(void) | |||
987 | /* Disable autoclocking */ | 994 | /* Disable autoclocking */ |
988 | __raw_writeb(0xff, AUTOCLK_CTRL); | 995 | __raw_writeb(0xff, AUTOCLK_CTRL); |
989 | 996 | ||
997 | clkdev_add_table(onchip_clkreg, ARRAY_SIZE(onchip_clkreg)); | ||
998 | |||
990 | return 0; | 999 | return 0; |
991 | } | 1000 | } |
992 | 1001 | ||