USB: serial: ftdi_sio: make process-packet buffer unsigned
[linux/fpc-iii.git] / drivers / cpufreq / s3c2412-cpufreq.c
blob53385a9ab957b8465e1cb3305d9a62d475446517
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright 2008 Simtec Electronics
4 * http://armlinux.simtec.co.uk/
5 * Ben Dooks <ben@simtec.co.uk>
7 * S3C2412 CPU Frequency scalling
8 */
10 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12 #include <linux/init.h>
13 #include <linux/module.h>
14 #include <linux/interrupt.h>
15 #include <linux/ioport.h>
16 #include <linux/cpufreq.h>
17 #include <linux/device.h>
18 #include <linux/delay.h>
19 #include <linux/clk.h>
20 #include <linux/err.h>
21 #include <linux/io.h>
23 #include <asm/mach/arch.h>
24 #include <asm/mach/map.h>
26 #include <mach/regs-clock.h>
27 #include <mach/s3c2412.h>
29 #include <plat/cpu.h>
30 #include <plat/cpu-freq-core.h>
32 /* our clock resources. */
33 static struct clk *xtal;
34 static struct clk *fclk;
35 static struct clk *hclk;
36 static struct clk *armclk;
38 /* HDIV: 1, 2, 3, 4, 6, 8 */
40 static int s3c2412_cpufreq_calcdivs(struct s3c_cpufreq_config *cfg)
42 unsigned int hdiv, pdiv, armdiv, dvs;
43 unsigned long hclk, fclk, armclk, armdiv_clk;
44 unsigned long hclk_max;
46 fclk = cfg->freq.fclk;
47 armclk = cfg->freq.armclk;
48 hclk_max = cfg->max.hclk;
50 /* We can't run hclk above armclk as at the best we have to
51 * have armclk and hclk in dvs mode. */
53 if (hclk_max > armclk)
54 hclk_max = armclk;
56 s3c_freq_dbg("%s: fclk=%lu, armclk=%lu, hclk_max=%lu\n",
57 __func__, fclk, armclk, hclk_max);
58 s3c_freq_dbg("%s: want f=%lu, arm=%lu, h=%lu, p=%lu\n",
59 __func__, cfg->freq.fclk, cfg->freq.armclk,
60 cfg->freq.hclk, cfg->freq.pclk);
62 armdiv = fclk / armclk;
64 if (armdiv < 1)
65 armdiv = 1;
66 if (armdiv > 2)
67 armdiv = 2;
69 cfg->divs.arm_divisor = armdiv;
70 armdiv_clk = fclk / armdiv;
72 hdiv = armdiv_clk / hclk_max;
73 if (hdiv < 1)
74 hdiv = 1;
76 cfg->freq.hclk = hclk = armdiv_clk / hdiv;
78 /* set dvs depending on whether we reached armclk or not. */
79 cfg->divs.dvs = dvs = armclk < armdiv_clk;
81 /* update the actual armclk we achieved. */
82 cfg->freq.armclk = dvs ? hclk : armdiv_clk;
84 s3c_freq_dbg("%s: armclk %lu, hclk %lu, armdiv %d, hdiv %d, dvs %d\n",
85 __func__, armclk, hclk, armdiv, hdiv, cfg->divs.dvs);
87 if (hdiv > 4)
88 goto invalid;
90 pdiv = (hclk > cfg->max.pclk) ? 2 : 1;
92 if ((hclk / pdiv) > cfg->max.pclk)
93 pdiv++;
95 cfg->freq.pclk = hclk / pdiv;
97 s3c_freq_dbg("%s: pdiv %d\n", __func__, pdiv);
99 if (pdiv > 2)
100 goto invalid;
102 pdiv *= hdiv;
104 /* store the result, and then return */
106 cfg->divs.h_divisor = hdiv * armdiv;
107 cfg->divs.p_divisor = pdiv * armdiv;
109 return 0;
111 invalid:
112 return -EINVAL;
115 static void s3c2412_cpufreq_setdivs(struct s3c_cpufreq_config *cfg)
117 unsigned long clkdiv;
118 unsigned long olddiv;
120 olddiv = clkdiv = __raw_readl(S3C2410_CLKDIVN);
122 /* clear off current clock info */
124 clkdiv &= ~S3C2412_CLKDIVN_ARMDIVN;
125 clkdiv &= ~S3C2412_CLKDIVN_HDIVN_MASK;
126 clkdiv &= ~S3C2412_CLKDIVN_PDIVN;
128 if (cfg->divs.arm_divisor == 2)
129 clkdiv |= S3C2412_CLKDIVN_ARMDIVN;
131 clkdiv |= ((cfg->divs.h_divisor / cfg->divs.arm_divisor) - 1);
133 if (cfg->divs.p_divisor != cfg->divs.h_divisor)
134 clkdiv |= S3C2412_CLKDIVN_PDIVN;
136 s3c_freq_dbg("%s: div %08lx => %08lx\n", __func__, olddiv, clkdiv);
137 __raw_writel(clkdiv, S3C2410_CLKDIVN);
139 clk_set_parent(armclk, cfg->divs.dvs ? hclk : fclk);
142 static void s3c2412_cpufreq_setrefresh(struct s3c_cpufreq_config *cfg)
144 struct s3c_cpufreq_board *board = cfg->board;
145 unsigned long refresh;
147 s3c_freq_dbg("%s: refresh %u ns, hclk %lu\n", __func__,
148 board->refresh, cfg->freq.hclk);
150 /* Reduce both the refresh time (in ns) and the frequency (in MHz)
151 * by 10 each to ensure that we do not overflow 32 bit numbers. This
152 * should work for HCLK up to 133MHz and refresh period up to 30usec.
155 refresh = (board->refresh / 10);
156 refresh *= (cfg->freq.hclk / 100);
157 refresh /= (1 * 1000 * 1000); /* 10^6 */
159 s3c_freq_dbg("%s: setting refresh 0x%08lx\n", __func__, refresh);
160 __raw_writel(refresh, S3C2412_REFRESH);
163 /* set the default cpu frequency information, based on an 200MHz part
164 * as we have no other way of detecting the speed rating in software.
167 static struct s3c_cpufreq_info s3c2412_cpufreq_info = {
168 .max = {
169 .fclk = 200000000,
170 .hclk = 100000000,
171 .pclk = 50000000,
174 .latency = 5000000, /* 5ms */
176 .locktime_m = 150,
177 .locktime_u = 150,
178 .locktime_bits = 16,
180 .name = "s3c2412",
181 .set_refresh = s3c2412_cpufreq_setrefresh,
182 .set_divs = s3c2412_cpufreq_setdivs,
183 .calc_divs = s3c2412_cpufreq_calcdivs,
185 .calc_iotiming = s3c2412_iotiming_calc,
186 .set_iotiming = s3c2412_iotiming_set,
187 .get_iotiming = s3c2412_iotiming_get,
189 .debug_io_show = s3c_cpufreq_debugfs_call(s3c2412_iotiming_debugfs),
192 static int s3c2412_cpufreq_add(struct device *dev,
193 struct subsys_interface *sif)
195 unsigned long fclk_rate;
197 hclk = clk_get(NULL, "hclk");
198 if (IS_ERR(hclk)) {
199 pr_err("cannot find hclk clock\n");
200 return -ENOENT;
203 fclk = clk_get(NULL, "fclk");
204 if (IS_ERR(fclk)) {
205 pr_err("cannot find fclk clock\n");
206 goto err_fclk;
209 fclk_rate = clk_get_rate(fclk);
210 if (fclk_rate > 200000000) {
211 pr_info("fclk %ld MHz, assuming 266MHz capable part\n",
212 fclk_rate / 1000000);
213 s3c2412_cpufreq_info.max.fclk = 266000000;
214 s3c2412_cpufreq_info.max.hclk = 133000000;
215 s3c2412_cpufreq_info.max.pclk = 66000000;
218 armclk = clk_get(NULL, "armclk");
219 if (IS_ERR(armclk)) {
220 pr_err("cannot find arm clock\n");
221 goto err_armclk;
224 xtal = clk_get(NULL, "xtal");
225 if (IS_ERR(xtal)) {
226 pr_err("cannot find xtal clock\n");
227 goto err_xtal;
230 return s3c_cpufreq_register(&s3c2412_cpufreq_info);
232 err_xtal:
233 clk_put(armclk);
234 err_armclk:
235 clk_put(fclk);
236 err_fclk:
237 clk_put(hclk);
239 return -ENOENT;
242 static struct subsys_interface s3c2412_cpufreq_interface = {
243 .name = "s3c2412_cpufreq",
244 .subsys = &s3c2412_subsys,
245 .add_dev = s3c2412_cpufreq_add,
248 static int s3c2412_cpufreq_init(void)
250 return subsys_interface_register(&s3c2412_cpufreq_interface);
252 arch_initcall(s3c2412_cpufreq_init);