Merge branch 'next' of git://git.monstr.eu/linux-2.6-microblaze
[sfrench/cifs-2.6.git] / arch / arm / mach-exynos / clock-exynos4212.c
1 /*
2  * Copyright (c) 2011-2012 Samsung Electronics Co., Ltd.
3  *              http://www.samsung.com
4  *
5  * EXYNOS4212 - Clock support
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10 */
11
12 #include <linux/kernel.h>
13 #include <linux/err.h>
14 #include <linux/clk.h>
15 #include <linux/io.h>
16 #include <linux/syscore_ops.h>
17
18 #include <plat/cpu-freq.h>
19 #include <plat/clock.h>
20 #include <plat/cpu.h>
21 #include <plat/pll.h>
22 #include <plat/s5p-clock.h>
23 #include <plat/clock-clksrc.h>
24 #include <plat/pm.h>
25
26 #include <mach/hardware.h>
27 #include <mach/map.h>
28 #include <mach/regs-clock.h>
29 #include <mach/sysmmu.h>
30
31 #include "common.h"
32 #include "clock-exynos4.h"
33
34 #ifdef CONFIG_PM_SLEEP
35 static struct sleep_save exynos4212_clock_save[] = {
36         SAVE_ITEM(EXYNOS4_CLKSRC_IMAGE),
37         SAVE_ITEM(EXYNOS4_CLKDIV_IMAGE),
38         SAVE_ITEM(EXYNOS4212_CLKGATE_IP_IMAGE),
39         SAVE_ITEM(EXYNOS4212_CLKGATE_IP_PERIR),
40 };
41 #endif
42
43 static int exynos4212_clk_ip_isp0_ctrl(struct clk *clk, int enable)
44 {
45         return s5p_gatectrl(EXYNOS4_CLKGATE_IP_ISP0, clk, enable);
46 }
47
48 static int exynos4212_clk_ip_isp1_ctrl(struct clk *clk, int enable)
49 {
50         return s5p_gatectrl(EXYNOS4_CLKGATE_IP_ISP1, clk, enable);
51 }
52
53 static struct clk *clk_src_mpll_user_list[] = {
54         [0] = &clk_fin_mpll,
55         [1] = &exynos4_clk_mout_mpll.clk,
56 };
57
58 static struct clksrc_sources clk_src_mpll_user = {
59         .sources        = clk_src_mpll_user_list,
60         .nr_sources     = ARRAY_SIZE(clk_src_mpll_user_list),
61 };
62
63 static struct clksrc_clk clk_mout_mpll_user = {
64         .clk = {
65                 .name           = "mout_mpll_user",
66         },
67         .sources        = &clk_src_mpll_user,
68         .reg_src        = { .reg = EXYNOS4_CLKSRC_CPU, .shift = 24, .size = 1 },
69 };
70
71 static struct clksrc_clk *sysclks[] = {
72         &clk_mout_mpll_user,
73 };
74
75 static struct clksrc_clk clksrcs[] = {
76         /* nothing here yet */
77 };
78
79 static struct clk init_clocks_off[] = {
80         {
81                 .name           = SYSMMU_CLOCK_NAME,
82                 .devname        = SYSMMU_CLOCK_DEVNAME(2d, 14),
83                 .enable         = exynos4_clk_ip_dmc_ctrl,
84                 .ctrlbit        = (1 << 24),
85         }, {
86                 .name           = SYSMMU_CLOCK_NAME,
87                 .devname        = SYSMMU_CLOCK_DEVNAME(isp, 9),
88                 .enable         = exynos4212_clk_ip_isp0_ctrl,
89                 .ctrlbit        = (7 << 8),
90         }, {
91                 .name           = SYSMMU_CLOCK_NAME2,
92                 .devname        = SYSMMU_CLOCK_DEVNAME(isp, 9),
93                 .enable         = exynos4212_clk_ip_isp1_ctrl,
94                 .ctrlbit        = (1 << 4),
95         }, {
96                 .name           = "flite",
97                 .devname        = "exynos-fimc-lite.0",
98                 .enable         = exynos4212_clk_ip_isp0_ctrl,
99                 .ctrlbit        = (1 << 4),
100         }, {
101                 .name           = "flite",
102                 .devname        = "exynos-fimc-lite.1",
103                 .enable         = exynos4212_clk_ip_isp0_ctrl,
104                 .ctrlbit        = (1 << 3),
105         }
106 };
107
108 #ifdef CONFIG_PM_SLEEP
109 static int exynos4212_clock_suspend(void)
110 {
111         s3c_pm_do_save(exynos4212_clock_save, ARRAY_SIZE(exynos4212_clock_save));
112
113         return 0;
114 }
115
116 static void exynos4212_clock_resume(void)
117 {
118         s3c_pm_do_restore_core(exynos4212_clock_save, ARRAY_SIZE(exynos4212_clock_save));
119 }
120
121 #else
122 #define exynos4212_clock_suspend NULL
123 #define exynos4212_clock_resume NULL
124 #endif
125
126 static struct syscore_ops exynos4212_clock_syscore_ops = {
127         .suspend        = exynos4212_clock_suspend,
128         .resume         = exynos4212_clock_resume,
129 };
130
131 void __init exynos4212_register_clocks(void)
132 {
133         int ptr;
134
135         /* usbphy1 is removed */
136         exynos4_clkset_group_list[4] = NULL;
137
138         /* mout_mpll_user is used */
139         exynos4_clkset_group_list[6] = &clk_mout_mpll_user.clk;
140         exynos4_clkset_aclk_top_list[0] = &clk_mout_mpll_user.clk;
141
142         exynos4_clk_mout_mpll.reg_src.reg = EXYNOS4_CLKSRC_DMC;
143         exynos4_clk_mout_mpll.reg_src.shift = 12;
144         exynos4_clk_mout_mpll.reg_src.size = 1;
145
146         for (ptr = 0; ptr < ARRAY_SIZE(sysclks); ptr++)
147                 s3c_register_clksrc(sysclks[ptr], 1);
148
149         s3c_register_clksrc(clksrcs, ARRAY_SIZE(clksrcs));
150
151         s3c_register_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
152         s3c_disable_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
153
154         register_syscore_ops(&exynos4212_clock_syscore_ops);
155 }