mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-26 22:24:09 +08:00
f991fae5c6
- Hotplug changes allowing device hot-removal operations to fail gracefully (instead of crashing the kernel) if they cannot be carried out completely. From Rafael J Wysocki and Toshi Kani. - Freezer update from Colin Cross and Mandeep Singh Baines targeted at making the freezing of tasks a bit less heavy weight operation. - cpufreq resume fix from Srivatsa S Bhat for a regression introduced during the 3.10 cycle causing some cpufreq sysfs attributes to return wrong values to user space after resume. - New freqdomain_cpus sysfs attribute for the acpi-cpufreq driver to provide information previously available via related_cpus from Lan Tianyu. - cpufreq fixes and cleanups from Viresh Kumar, Jacob Shin, Heiko Stübner, Xiaoguang Chen, Ezequiel Garcia, Arnd Bergmann, and Tang Yuantian. - Fix for an ACPICA regression causing suspend/resume issues to appear on some systems introduced during the 3.4 development cycle from Lv Zheng. - ACPICA fixes and cleanups from Bob Moore, Tomasz Nowicki, Lv Zheng, Chao Guan, and Zhang Rui. - New cupidle driver for Xilinx Zynq processors from Michal Simek. - cpuidle fixes and cleanups from Daniel Lezcano. - Changes to make suspend/resume work correctly in Xen guests from Konrad Rzeszutek Wilk. - ACPI device power management fixes and cleanups from Fengguang Wu and Rafael J Wysocki. - ACPI documentation updates from Lv Zheng, Aaron Lu and Hanjun Guo. - Fix for the IA-64 issue that was the reason for reverting commit9f29ab1
and updates of the ACPI scan code from Rafael J Wysocki. - Mechanism for adding CMOS RTC address space handlers from Lan Tianyu (to allow some EC-related breakage to be fixed on some systems). - Spec-compliant implementation of acpi_os_get_timer() from Mika Westerberg. - Modification of do_acpi_find_child() to execute _STA in order to to avoid situations in which a pointer to a disabled device object is returned instead of an enabled one with the same _ADR value. From Jeff Wu. - Intel BayTrail PCH (Platform Controller Hub) support for the ACPI Intel Low-Power Subsystems (LPSS) driver and modificaions of that driver to work around a couple of known BIOS issues from Mika Westerberg and Heikki Krogerus. - EC driver fix from Vasiliy Kulikov to make it use get_user() and put_user() instead of dereferencing user space pointers blindly. - Assorted ACPI code cleanups from Bjorn Helgaas, Nicholas Mazzuca and Toshi Kani. - Modification of the "runtime idle" helper routine to take the return values of the callbacks executed by it into account and to call rpm_suspend() if they return 0, which allows some code bloat reduction to be done, from Rafael J Wysocki and Alan Stern. - New trace points for PM QoS from Sahara <keun-o.park@windriver.com>. - PM QoS documentation update from Lan Tianyu. - Assorted core PM code cleanups and changes from Bernie Thompson, Bjorn Helgaas, Julius Werner, and Shuah Khan. - New devfreq driver for the Exynos5-bus device from Abhilash Kesavan. - Minor devfreq cleanups, fixes and MAINTAINERS update from MyungJoo Ham, Abhilash Kesavan, Paul Bolle, Rajagopal Venkat, and Wei Yongjun. - OMAP Adaptive Voltage Scaling (AVS) SmartReflex voltage control driver updates from Andrii Tseglytskyi and Nishanth Menon. / -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) iQIcBAABAgAGBQJR0ZNOAAoJEKhOf7ml8uNsDLYP/0EU4rmvw0TWTITfp6RS1KDE 9GwBn96ZR4Q5bJd9gBCTPSqhHOYMqxWEUp99sn/M2wehG1pk/jw5LO56+2IhM3UZ g1HDcJ7te2nVT/iXsKiAGTVhU9Rk0aYwoVSknwk27qpIBGxW9w/s5tLX8pY3Q3Zq wL/7aTPjyL+PFFFEaxgH7qLqsl3DhbtYW5AriUBTkXout/tJ4eO1b7MNBncLDh8X VQ/0DNCKE95VEJfkO4rk9RKUyVp9GDn0i+HXCD/FS4IA5oYzePdVdNDmXf7g+swe CGlTZq8pB+oBpDiHl4lxzbNrKQjRNbGnDUkoRcWqn0nAw56xK+vmYnWJhW99gQ/I fKnvxeLca5po1aiqmC4VSJxZIatFZqLrZAI4dzoCLWY+bGeTnCKmj0/F8ytFnZA2 8IuLLs7/dFOaHXV/pKmpg6FAlFa9CPxoqRFoyqb4M0GjEarADyalXUWsPtG+6xCp R/p0CISpwk+guKZR/qPhL7M654S7SHrPwd2DPF0KgGsvk+G2GhoB8EzvD8BVp98Z 9siCGCdgKQfJQVI6R0k9aFmn/4gRQIAgyPhkhv9tqULUUkiaXki+/t8kPfnb8O/d zep+CA57E2G8MYLkDJfpFeKS7GpPD6TIdgFdGmOUC0Y6sl9iTdiw4yTx8O2JM37z rHBZfYGkJBrbGRu+Q1gs =VBBq -----END PGP SIGNATURE----- Merge tag 'pm+acpi-3.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm Pull power management and ACPI updates from Rafael Wysocki: "This time the total number of ACPI commits is slightly greater than the number of cpufreq commits, but Viresh Kumar (who works on cpufreq) remains the most active patch submitter. To me, the most significant change is the addition of offline/online device operations to the driver core (with the Greg's blessing) and the related modifications of the ACPI core hotplug code. Next are the freezer updates from Colin Cross that should make the freezing of tasks a bit less heavy weight. We also have a couple of regression fixes, a number of fixes for issues that have not been identified as regressions, two new drivers and a bunch of cleanups all over. Highlights: - Hotplug changes to support graceful hot-removal failures. It sometimes is necessary to fail device hot-removal operations gracefully if they cannot be carried out completely. For example, if memory from a memory module being hot-removed has been allocated for the kernel's own use and cannot be moved elsewhere, it's desirable to fail the hot-removal operation in a graceful way rather than to crash the kernel, but currenty a success or a kernel crash are the only possible outcomes of an attempted memory hot-removal. Needless to say, that is not a very attractive alternative and it had to be addressed. However, in order to make it work for memory, I first had to make it work for CPUs and for this purpose I needed to modify the ACPI processor driver. It's been split into two parts, a resident one handling the low-level initialization/cleanup and a modular one playing the actual driver's role (but it binds to the CPU system device objects rather than to the ACPI device objects representing processors). That's been sort of like a live brain surgery on a patient who's riding a bike. So this is a little scary, but since we found and fixed a couple of regressions it caused to happen during the early linux-next testing (a month ago), nobody has complained. As a bonus we remove some duplicated ACPI hotplug code, because the ACPI-based CPU hotplug is now going to use the common ACPI hotplug code. - Lighter weight freezing of tasks. These changes from Colin Cross and Mandeep Singh Baines are targeted at making the freezing of tasks a bit less heavy weight operation. They reduce the number of tasks woken up every time during the freezing, by using the observation that the freezer simply doesn't need to wake up some of them and wait for them all to call refrigerator(). The time needed for the freezer to decide to report a failure is reduced too. Also reintroduced is the check causing a lockdep warining to trigger when try_to_freeze() is called with locks held (which is generally unsafe and shouldn't happen). - cpufreq updates First off, a commit from Srivatsa S Bhat fixes a resume regression introduced during the 3.10 cycle causing some cpufreq sysfs attributes to return wrong values to user space after resume. The fix is kind of fresh, but also it's pretty obvious once Srivatsa has identified the root cause. Second, we have a new freqdomain_cpus sysfs attribute for the acpi-cpufreq driver to provide information previously available via related_cpus. From Lan Tianyu. Finally, we fix a number of issues, mostly related to the CPUFREQ_POSTCHANGE notifier and cpufreq Kconfig options and clean up some code. The majority of changes from Viresh Kumar with bits from Jacob Shin, Heiko Stübner, Xiaoguang Chen, Ezequiel Garcia, Arnd Bergmann, and Tang Yuantian. - ACPICA update A usual bunch of updates from the ACPICA upstream. During the 3.4 cycle we introduced support for ACPI 5 extended sleep registers, but they are only supposed to be used if the HW-reduced mode bit is set in the FADT flags and the code attempted to use them without checking that bit. That caused suspend/resume regressions to happen on some systems. Fix from Lv Zheng causes those registers to be used only if the HW-reduced mode bit is set. Apart from this some other ACPICA bugs are fixed and code cleanups are made by Bob Moore, Tomasz Nowicki, Lv Zheng, Chao Guan, and Zhang Rui. - cpuidle updates New driver for Xilinx Zynq processors is added by Michal Simek. Multidriver support simplification, addition of some missing kerneldoc comments and Kconfig-related fixes come from Daniel Lezcano. - ACPI power management updates Changes to make suspend/resume work correctly in Xen guests from Konrad Rzeszutek Wilk, sparse warning fix from Fengguang Wu and cleanups and fixes of the ACPI device power state selection routine. - ACPI documentation updates Some previously missing pieces of ACPI documentation are added by Lv Zheng and Aaron Lu (hopefully, that will help people to uderstand how the ACPI subsystem works) and one outdated doc is updated by Hanjun Guo. - Assorted ACPI updates We finally nailed down the IA-64 issue that was the reason for reverting commit9f29ab11dd
("ACPI / scan: do not match drivers against objects having scan handlers"), so we can fix it and move the ACPI scan handler check added to the ACPI video driver back to the core. A mechanism for adding CMOS RTC address space handlers is introduced by Lan Tianyu to allow some EC-related breakage to be fixed on some systems. A spec-compliant implementation of acpi_os_get_timer() is added by Mika Westerberg. The evaluation of _STA is added to do_acpi_find_child() to avoid situations in which a pointer to a disabled device object is returned instead of an enabled one with the same _ADR value. From Jeff Wu. Intel BayTrail PCH (Platform Controller Hub) support is added to the ACPI driver for Intel Low-Power Subsystems (LPSS) and that driver is modified to work around a couple of known BIOS issues. Changes from Mika Westerberg and Heikki Krogerus. The EC driver is fixed by Vasiliy Kulikov to use get_user() and put_user() instead of dereferencing user space pointers blindly. Code cleanups are made by Bjorn Helgaas, Nicholas Mazzuca and Toshi Kani. - Assorted power management updates The "runtime idle" helper routine is changed to take the return values of the callbacks executed by it into account and to call rpm_suspend() if they return 0, which allows us to reduce the overall code bloat a bit (by dropping some code that's not necessary any more after that modification). The runtime PM documentation is updated by Alan Stern (to reflect the "runtime idle" behavior change). New trace points for PM QoS are added by Sahara (<keun-o.park@windriver.com>). PM QoS documentation is updated by Lan Tianyu. Code cleanups are made and minor issues are addressed by Bernie Thompson, Bjorn Helgaas, Julius Werner, and Shuah Khan. - devfreq updates New driver for the Exynos5-bus device from Abhilash Kesavan. Minor cleanups, fixes and MAINTAINERS update from MyungJoo Ham, Abhilash Kesavan, Paul Bolle, Rajagopal Venkat, and Wei Yongjun. - OMAP power management updates Adaptive Voltage Scaling (AVS) SmartReflex voltage control driver updates from Andrii Tseglytskyi and Nishanth Menon." * tag 'pm+acpi-3.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: (162 commits) cpufreq: Fix cpufreq regression after suspend/resume ACPI / PM: Fix possible NULL pointer deref in acpi_pm_device_sleep_state() PM / Sleep: Warn about system time after resume with pm_trace cpufreq: don't leave stale policy pointer in cdbs->cur_policy acpi-cpufreq: Add new sysfs attribute freqdomain_cpus cpufreq: make sure frequency transitions are serialized ACPI: implement acpi_os_get_timer() according the spec ACPI / EC: Add HP Folio 13 to ec_dmi_table in order to skip DSDT scan ACPI: Add CMOS RTC Operation Region handler support ACPI / processor: Drop unused variable from processor_perflib.c cpufreq: tegra: call CPUFREQ_POSTCHANGE notfier in error cases cpufreq: s3c64xx: call CPUFREQ_POSTCHANGE notfier in error cases cpufreq: omap: call CPUFREQ_POSTCHANGE notfier in error cases cpufreq: imx6q: call CPUFREQ_POSTCHANGE notfier in error cases cpufreq: exynos: call CPUFREQ_POSTCHANGE notfier in error cases cpufreq: dbx500: call CPUFREQ_POSTCHANGE notfier in error cases cpufreq: davinci: call CPUFREQ_POSTCHANGE notfier in error cases cpufreq: arm-big-little: call CPUFREQ_POSTCHANGE notfier in error cases cpufreq: powernow-k8: call CPUFREQ_POSTCHANGE notfier in error cases cpufreq: pcc: call CPUFREQ_POSTCHANGE notfier in error cases ...
712 lines
17 KiB
C
712 lines
17 KiB
C
/*
|
|
* Copyright (c) 2006-2008 Simtec Electronics
|
|
* http://armlinux.simtec.co.uk/
|
|
* Ben Dooks <ben@simtec.co.uk>
|
|
*
|
|
* S3C24XX CPU Frequency scaling
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation.
|
|
*/
|
|
|
|
#include <linux/init.h>
|
|
#include <linux/module.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/ioport.h>
|
|
#include <linux/cpufreq.h>
|
|
#include <linux/cpu.h>
|
|
#include <linux/clk.h>
|
|
#include <linux/err.h>
|
|
#include <linux/io.h>
|
|
#include <linux/device.h>
|
|
#include <linux/sysfs.h>
|
|
#include <linux/slab.h>
|
|
|
|
#include <asm/mach/arch.h>
|
|
#include <asm/mach/map.h>
|
|
|
|
#include <plat/cpu.h>
|
|
#include <plat/clock.h>
|
|
#include <plat/cpu-freq-core.h>
|
|
|
|
#include <mach/regs-clock.h>
|
|
|
|
/* note, cpufreq support deals in kHz, no Hz */
|
|
|
|
static struct cpufreq_driver s3c24xx_driver;
|
|
static struct s3c_cpufreq_config cpu_cur;
|
|
static struct s3c_iotimings s3c24xx_iotiming;
|
|
static struct cpufreq_frequency_table *pll_reg;
|
|
static unsigned int last_target = ~0;
|
|
static unsigned int ftab_size;
|
|
static struct cpufreq_frequency_table *ftab;
|
|
|
|
static struct clk *_clk_mpll;
|
|
static struct clk *_clk_xtal;
|
|
static struct clk *clk_fclk;
|
|
static struct clk *clk_hclk;
|
|
static struct clk *clk_pclk;
|
|
static struct clk *clk_arm;
|
|
|
|
#ifdef CONFIG_CPU_FREQ_S3C24XX_DEBUGFS
|
|
struct s3c_cpufreq_config *s3c_cpufreq_getconfig(void)
|
|
{
|
|
return &cpu_cur;
|
|
}
|
|
|
|
struct s3c_iotimings *s3c_cpufreq_getiotimings(void)
|
|
{
|
|
return &s3c24xx_iotiming;
|
|
}
|
|
#endif /* CONFIG_CPU_FREQ_S3C24XX_DEBUGFS */
|
|
|
|
static void s3c_cpufreq_getcur(struct s3c_cpufreq_config *cfg)
|
|
{
|
|
unsigned long fclk, pclk, hclk, armclk;
|
|
|
|
cfg->freq.fclk = fclk = clk_get_rate(clk_fclk);
|
|
cfg->freq.hclk = hclk = clk_get_rate(clk_hclk);
|
|
cfg->freq.pclk = pclk = clk_get_rate(clk_pclk);
|
|
cfg->freq.armclk = armclk = clk_get_rate(clk_arm);
|
|
|
|
cfg->pll.driver_data = __raw_readl(S3C2410_MPLLCON);
|
|
cfg->pll.frequency = fclk;
|
|
|
|
cfg->freq.hclk_tns = 1000000000 / (cfg->freq.hclk / 10);
|
|
|
|
cfg->divs.h_divisor = fclk / hclk;
|
|
cfg->divs.p_divisor = fclk / pclk;
|
|
}
|
|
|
|
static inline void s3c_cpufreq_calc(struct s3c_cpufreq_config *cfg)
|
|
{
|
|
unsigned long pll = cfg->pll.frequency;
|
|
|
|
cfg->freq.fclk = pll;
|
|
cfg->freq.hclk = pll / cfg->divs.h_divisor;
|
|
cfg->freq.pclk = pll / cfg->divs.p_divisor;
|
|
|
|
/* convert hclk into 10ths of nanoseconds for io calcs */
|
|
cfg->freq.hclk_tns = 1000000000 / (cfg->freq.hclk / 10);
|
|
}
|
|
|
|
static inline int closer(unsigned int target, unsigned int n, unsigned int c)
|
|
{
|
|
int diff_cur = abs(target - c);
|
|
int diff_new = abs(target - n);
|
|
|
|
return (diff_new < diff_cur);
|
|
}
|
|
|
|
static void s3c_cpufreq_show(const char *pfx,
|
|
struct s3c_cpufreq_config *cfg)
|
|
{
|
|
s3c_freq_dbg("%s: Fvco=%u, F=%lu, A=%lu, H=%lu (%u), P=%lu (%u)\n",
|
|
pfx, cfg->pll.frequency, cfg->freq.fclk, cfg->freq.armclk,
|
|
cfg->freq.hclk, cfg->divs.h_divisor,
|
|
cfg->freq.pclk, cfg->divs.p_divisor);
|
|
}
|
|
|
|
/* functions to wrapper the driver info calls to do the cpu specific work */
|
|
|
|
static void s3c_cpufreq_setio(struct s3c_cpufreq_config *cfg)
|
|
{
|
|
if (cfg->info->set_iotiming)
|
|
(cfg->info->set_iotiming)(cfg, &s3c24xx_iotiming);
|
|
}
|
|
|
|
static int s3c_cpufreq_calcio(struct s3c_cpufreq_config *cfg)
|
|
{
|
|
if (cfg->info->calc_iotiming)
|
|
return (cfg->info->calc_iotiming)(cfg, &s3c24xx_iotiming);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void s3c_cpufreq_setrefresh(struct s3c_cpufreq_config *cfg)
|
|
{
|
|
(cfg->info->set_refresh)(cfg);
|
|
}
|
|
|
|
static void s3c_cpufreq_setdivs(struct s3c_cpufreq_config *cfg)
|
|
{
|
|
(cfg->info->set_divs)(cfg);
|
|
}
|
|
|
|
static int s3c_cpufreq_calcdivs(struct s3c_cpufreq_config *cfg)
|
|
{
|
|
return (cfg->info->calc_divs)(cfg);
|
|
}
|
|
|
|
static void s3c_cpufreq_setfvco(struct s3c_cpufreq_config *cfg)
|
|
{
|
|
(cfg->info->set_fvco)(cfg);
|
|
}
|
|
|
|
static inline void s3c_cpufreq_resume_clocks(void)
|
|
{
|
|
cpu_cur.info->resume_clocks();
|
|
}
|
|
|
|
static inline void s3c_cpufreq_updateclk(struct clk *clk,
|
|
unsigned int freq)
|
|
{
|
|
clk_set_rate(clk, freq);
|
|
}
|
|
|
|
static int s3c_cpufreq_settarget(struct cpufreq_policy *policy,
|
|
unsigned int target_freq,
|
|
struct cpufreq_frequency_table *pll)
|
|
{
|
|
struct s3c_cpufreq_freqs freqs;
|
|
struct s3c_cpufreq_config cpu_new;
|
|
unsigned long flags;
|
|
|
|
cpu_new = cpu_cur; /* copy new from current */
|
|
|
|
s3c_cpufreq_show("cur", &cpu_cur);
|
|
|
|
/* TODO - check for DMA currently outstanding */
|
|
|
|
cpu_new.pll = pll ? *pll : cpu_cur.pll;
|
|
|
|
if (pll)
|
|
freqs.pll_changing = 1;
|
|
|
|
/* update our frequencies */
|
|
|
|
cpu_new.freq.armclk = target_freq;
|
|
cpu_new.freq.fclk = cpu_new.pll.frequency;
|
|
|
|
if (s3c_cpufreq_calcdivs(&cpu_new) < 0) {
|
|
printk(KERN_ERR "no divisors for %d\n", target_freq);
|
|
goto err_notpossible;
|
|
}
|
|
|
|
s3c_freq_dbg("%s: got divs\n", __func__);
|
|
|
|
s3c_cpufreq_calc(&cpu_new);
|
|
|
|
s3c_freq_dbg("%s: calculated frequencies for new\n", __func__);
|
|
|
|
if (cpu_new.freq.hclk != cpu_cur.freq.hclk) {
|
|
if (s3c_cpufreq_calcio(&cpu_new) < 0) {
|
|
printk(KERN_ERR "%s: no IO timings\n", __func__);
|
|
goto err_notpossible;
|
|
}
|
|
}
|
|
|
|
s3c_cpufreq_show("new", &cpu_new);
|
|
|
|
/* setup our cpufreq parameters */
|
|
|
|
freqs.old = cpu_cur.freq;
|
|
freqs.new = cpu_new.freq;
|
|
|
|
freqs.freqs.old = cpu_cur.freq.armclk / 1000;
|
|
freqs.freqs.new = cpu_new.freq.armclk / 1000;
|
|
|
|
/* update f/h/p clock settings before we issue the change
|
|
* notification, so that drivers do not need to do anything
|
|
* special if they want to recalculate on CPUFREQ_PRECHANGE. */
|
|
|
|
s3c_cpufreq_updateclk(_clk_mpll, cpu_new.pll.frequency);
|
|
s3c_cpufreq_updateclk(clk_fclk, cpu_new.freq.fclk);
|
|
s3c_cpufreq_updateclk(clk_hclk, cpu_new.freq.hclk);
|
|
s3c_cpufreq_updateclk(clk_pclk, cpu_new.freq.pclk);
|
|
|
|
/* start the frequency change */
|
|
cpufreq_notify_transition(policy, &freqs.freqs, CPUFREQ_PRECHANGE);
|
|
|
|
/* If hclk is staying the same, then we do not need to
|
|
* re-write the IO or the refresh timings whilst we are changing
|
|
* speed. */
|
|
|
|
local_irq_save(flags);
|
|
|
|
/* is our memory clock slowing down? */
|
|
if (cpu_new.freq.hclk < cpu_cur.freq.hclk) {
|
|
s3c_cpufreq_setrefresh(&cpu_new);
|
|
s3c_cpufreq_setio(&cpu_new);
|
|
}
|
|
|
|
if (cpu_new.freq.fclk == cpu_cur.freq.fclk) {
|
|
/* not changing PLL, just set the divisors */
|
|
|
|
s3c_cpufreq_setdivs(&cpu_new);
|
|
} else {
|
|
if (cpu_new.freq.fclk < cpu_cur.freq.fclk) {
|
|
/* slow the cpu down, then set divisors */
|
|
|
|
s3c_cpufreq_setfvco(&cpu_new);
|
|
s3c_cpufreq_setdivs(&cpu_new);
|
|
} else {
|
|
/* set the divisors, then speed up */
|
|
|
|
s3c_cpufreq_setdivs(&cpu_new);
|
|
s3c_cpufreq_setfvco(&cpu_new);
|
|
}
|
|
}
|
|
|
|
/* did our memory clock speed up */
|
|
if (cpu_new.freq.hclk > cpu_cur.freq.hclk) {
|
|
s3c_cpufreq_setrefresh(&cpu_new);
|
|
s3c_cpufreq_setio(&cpu_new);
|
|
}
|
|
|
|
/* update our current settings */
|
|
cpu_cur = cpu_new;
|
|
|
|
local_irq_restore(flags);
|
|
|
|
/* notify everyone we've done this */
|
|
cpufreq_notify_transition(policy, &freqs.freqs, CPUFREQ_POSTCHANGE);
|
|
|
|
s3c_freq_dbg("%s: finished\n", __func__);
|
|
return 0;
|
|
|
|
err_notpossible:
|
|
printk(KERN_ERR "no compatible settings for %d\n", target_freq);
|
|
return -EINVAL;
|
|
}
|
|
|
|
/* s3c_cpufreq_target
|
|
*
|
|
* called by the cpufreq core to adjust the frequency that the CPU
|
|
* is currently running at.
|
|
*/
|
|
|
|
static int s3c_cpufreq_target(struct cpufreq_policy *policy,
|
|
unsigned int target_freq,
|
|
unsigned int relation)
|
|
{
|
|
struct cpufreq_frequency_table *pll;
|
|
unsigned int index;
|
|
|
|
/* avoid repeated calls which cause a needless amout of duplicated
|
|
* logging output (and CPU time as the calculation process is
|
|
* done) */
|
|
if (target_freq == last_target)
|
|
return 0;
|
|
|
|
last_target = target_freq;
|
|
|
|
s3c_freq_dbg("%s: policy %p, target %u, relation %u\n",
|
|
__func__, policy, target_freq, relation);
|
|
|
|
if (ftab) {
|
|
if (cpufreq_frequency_table_target(policy, ftab,
|
|
target_freq, relation,
|
|
&index)) {
|
|
s3c_freq_dbg("%s: table failed\n", __func__);
|
|
return -EINVAL;
|
|
}
|
|
|
|
s3c_freq_dbg("%s: adjust %d to entry %d (%u)\n", __func__,
|
|
target_freq, index, ftab[index].frequency);
|
|
target_freq = ftab[index].frequency;
|
|
}
|
|
|
|
target_freq *= 1000; /* convert target to Hz */
|
|
|
|
/* find the settings for our new frequency */
|
|
|
|
if (!pll_reg || cpu_cur.lock_pll) {
|
|
/* either we've not got any PLL values, or we've locked
|
|
* to the current one. */
|
|
pll = NULL;
|
|
} else {
|
|
struct cpufreq_policy tmp_policy;
|
|
int ret;
|
|
|
|
/* we keep the cpu pll table in Hz, to ensure we get an
|
|
* accurate value for the PLL output. */
|
|
|
|
tmp_policy.min = policy->min * 1000;
|
|
tmp_policy.max = policy->max * 1000;
|
|
tmp_policy.cpu = policy->cpu;
|
|
|
|
/* cpufreq_frequency_table_target uses a pointer to 'index'
|
|
* which is the number of the table entry, not the value of
|
|
* the table entry's index field. */
|
|
|
|
ret = cpufreq_frequency_table_target(&tmp_policy, pll_reg,
|
|
target_freq, relation,
|
|
&index);
|
|
|
|
if (ret < 0) {
|
|
printk(KERN_ERR "%s: no PLL available\n", __func__);
|
|
goto err_notpossible;
|
|
}
|
|
|
|
pll = pll_reg + index;
|
|
|
|
s3c_freq_dbg("%s: target %u => %u\n",
|
|
__func__, target_freq, pll->frequency);
|
|
|
|
target_freq = pll->frequency;
|
|
}
|
|
|
|
return s3c_cpufreq_settarget(policy, target_freq, pll);
|
|
|
|
err_notpossible:
|
|
printk(KERN_ERR "no compatible settings for %d\n", target_freq);
|
|
return -EINVAL;
|
|
}
|
|
|
|
static unsigned int s3c_cpufreq_get(unsigned int cpu)
|
|
{
|
|
return clk_get_rate(clk_arm) / 1000;
|
|
}
|
|
|
|
struct clk *s3c_cpufreq_clk_get(struct device *dev, const char *name)
|
|
{
|
|
struct clk *clk;
|
|
|
|
clk = clk_get(dev, name);
|
|
if (IS_ERR(clk))
|
|
printk(KERN_ERR "cpufreq: failed to get clock '%s'\n", name);
|
|
|
|
return clk;
|
|
}
|
|
|
|
static int s3c_cpufreq_init(struct cpufreq_policy *policy)
|
|
{
|
|
printk(KERN_INFO "%s: initialising policy %p\n", __func__, policy);
|
|
|
|
if (policy->cpu != 0)
|
|
return -EINVAL;
|
|
|
|
policy->cur = s3c_cpufreq_get(0);
|
|
policy->min = policy->cpuinfo.min_freq = 0;
|
|
policy->max = policy->cpuinfo.max_freq = cpu_cur.info->max.fclk / 1000;
|
|
policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
|
|
|
|
/* feed the latency information from the cpu driver */
|
|
policy->cpuinfo.transition_latency = cpu_cur.info->latency;
|
|
|
|
if (ftab)
|
|
cpufreq_frequency_table_cpuinfo(policy, ftab);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static __init int s3c_cpufreq_initclks(void)
|
|
{
|
|
_clk_mpll = s3c_cpufreq_clk_get(NULL, "mpll");
|
|
_clk_xtal = s3c_cpufreq_clk_get(NULL, "xtal");
|
|
clk_fclk = s3c_cpufreq_clk_get(NULL, "fclk");
|
|
clk_hclk = s3c_cpufreq_clk_get(NULL, "hclk");
|
|
clk_pclk = s3c_cpufreq_clk_get(NULL, "pclk");
|
|
clk_arm = s3c_cpufreq_clk_get(NULL, "armclk");
|
|
|
|
if (IS_ERR(clk_fclk) || IS_ERR(clk_hclk) || IS_ERR(clk_pclk) ||
|
|
IS_ERR(_clk_mpll) || IS_ERR(clk_arm) || IS_ERR(_clk_xtal)) {
|
|
printk(KERN_ERR "%s: could not get clock(s)\n", __func__);
|
|
return -ENOENT;
|
|
}
|
|
|
|
printk(KERN_INFO "%s: clocks f=%lu,h=%lu,p=%lu,a=%lu\n", __func__,
|
|
clk_get_rate(clk_fclk) / 1000,
|
|
clk_get_rate(clk_hclk) / 1000,
|
|
clk_get_rate(clk_pclk) / 1000,
|
|
clk_get_rate(clk_arm) / 1000);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int s3c_cpufreq_verify(struct cpufreq_policy *policy)
|
|
{
|
|
if (policy->cpu != 0)
|
|
return -EINVAL;
|
|
|
|
return 0;
|
|
}
|
|
|
|
#ifdef CONFIG_PM
|
|
static struct cpufreq_frequency_table suspend_pll;
|
|
static unsigned int suspend_freq;
|
|
|
|
static int s3c_cpufreq_suspend(struct cpufreq_policy *policy)
|
|
{
|
|
suspend_pll.frequency = clk_get_rate(_clk_mpll);
|
|
suspend_pll.driver_data = __raw_readl(S3C2410_MPLLCON);
|
|
suspend_freq = s3c_cpufreq_get(0) * 1000;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int s3c_cpufreq_resume(struct cpufreq_policy *policy)
|
|
{
|
|
int ret;
|
|
|
|
s3c_freq_dbg("%s: resuming with policy %p\n", __func__, policy);
|
|
|
|
last_target = ~0; /* invalidate last_target setting */
|
|
|
|
/* first, find out what speed we resumed at. */
|
|
s3c_cpufreq_resume_clocks();
|
|
|
|
/* whilst we will be called later on, we try and re-set the
|
|
* cpu frequencies as soon as possible so that we do not end
|
|
* up resuming devices and then immediately having to re-set
|
|
* a number of settings once these devices have restarted.
|
|
*
|
|
* as a note, it is expected devices are not used until they
|
|
* have been un-suspended and at that time they should have
|
|
* used the updated clock settings.
|
|
*/
|
|
|
|
ret = s3c_cpufreq_settarget(NULL, suspend_freq, &suspend_pll);
|
|
if (ret) {
|
|
printk(KERN_ERR "%s: failed to reset pll/freq\n", __func__);
|
|
return ret;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
#else
|
|
#define s3c_cpufreq_resume NULL
|
|
#define s3c_cpufreq_suspend NULL
|
|
#endif
|
|
|
|
static struct cpufreq_driver s3c24xx_driver = {
|
|
.flags = CPUFREQ_STICKY,
|
|
.verify = s3c_cpufreq_verify,
|
|
.target = s3c_cpufreq_target,
|
|
.get = s3c_cpufreq_get,
|
|
.init = s3c_cpufreq_init,
|
|
.suspend = s3c_cpufreq_suspend,
|
|
.resume = s3c_cpufreq_resume,
|
|
.name = "s3c24xx",
|
|
};
|
|
|
|
|
|
int __init s3c_cpufreq_register(struct s3c_cpufreq_info *info)
|
|
{
|
|
if (!info || !info->name) {
|
|
printk(KERN_ERR "%s: failed to pass valid information\n",
|
|
__func__);
|
|
return -EINVAL;
|
|
}
|
|
|
|
printk(KERN_INFO "S3C24XX CPU Frequency driver, %s cpu support\n",
|
|
info->name);
|
|
|
|
/* check our driver info has valid data */
|
|
|
|
BUG_ON(info->set_refresh == NULL);
|
|
BUG_ON(info->set_divs == NULL);
|
|
BUG_ON(info->calc_divs == NULL);
|
|
|
|
/* info->set_fvco is optional, depending on whether there
|
|
* is a need to set the clock code. */
|
|
|
|
cpu_cur.info = info;
|
|
|
|
/* Note, driver registering should probably update locktime */
|
|
|
|
return 0;
|
|
}
|
|
|
|
int __init s3c_cpufreq_setboard(struct s3c_cpufreq_board *board)
|
|
{
|
|
struct s3c_cpufreq_board *ours;
|
|
|
|
if (!board) {
|
|
printk(KERN_INFO "%s: no board data\n", __func__);
|
|
return -EINVAL;
|
|
}
|
|
|
|
/* Copy the board information so that each board can make this
|
|
* initdata. */
|
|
|
|
ours = kzalloc(sizeof(struct s3c_cpufreq_board), GFP_KERNEL);
|
|
if (ours == NULL) {
|
|
printk(KERN_ERR "%s: no memory\n", __func__);
|
|
return -ENOMEM;
|
|
}
|
|
|
|
*ours = *board;
|
|
cpu_cur.board = ours;
|
|
|
|
return 0;
|
|
}
|
|
|
|
int __init s3c_cpufreq_auto_io(void)
|
|
{
|
|
int ret;
|
|
|
|
if (!cpu_cur.info->get_iotiming) {
|
|
printk(KERN_ERR "%s: get_iotiming undefined\n", __func__);
|
|
return -ENOENT;
|
|
}
|
|
|
|
printk(KERN_INFO "%s: working out IO settings\n", __func__);
|
|
|
|
ret = (cpu_cur.info->get_iotiming)(&cpu_cur, &s3c24xx_iotiming);
|
|
if (ret)
|
|
printk(KERN_ERR "%s: failed to get timings\n", __func__);
|
|
|
|
return ret;
|
|
}
|
|
|
|
/* if one or is zero, then return the other, otherwise return the min */
|
|
#define do_min(_a, _b) ((_a) == 0 ? (_b) : (_b) == 0 ? (_a) : min(_a, _b))
|
|
|
|
/**
|
|
* s3c_cpufreq_freq_min - find the minimum settings for the given freq.
|
|
* @dst: The destination structure
|
|
* @a: One argument.
|
|
* @b: The other argument.
|
|
*
|
|
* Create a minimum of each frequency entry in the 'struct s3c_freq',
|
|
* unless the entry is zero when it is ignored and the non-zero argument
|
|
* used.
|
|
*/
|
|
static void s3c_cpufreq_freq_min(struct s3c_freq *dst,
|
|
struct s3c_freq *a, struct s3c_freq *b)
|
|
{
|
|
dst->fclk = do_min(a->fclk, b->fclk);
|
|
dst->hclk = do_min(a->hclk, b->hclk);
|
|
dst->pclk = do_min(a->pclk, b->pclk);
|
|
dst->armclk = do_min(a->armclk, b->armclk);
|
|
}
|
|
|
|
static inline u32 calc_locktime(u32 freq, u32 time_us)
|
|
{
|
|
u32 result;
|
|
|
|
result = freq * time_us;
|
|
result = DIV_ROUND_UP(result, 1000 * 1000);
|
|
|
|
return result;
|
|
}
|
|
|
|
static void s3c_cpufreq_update_loctkime(void)
|
|
{
|
|
unsigned int bits = cpu_cur.info->locktime_bits;
|
|
u32 rate = (u32)clk_get_rate(_clk_xtal);
|
|
u32 val;
|
|
|
|
if (bits == 0) {
|
|
WARN_ON(1);
|
|
return;
|
|
}
|
|
|
|
val = calc_locktime(rate, cpu_cur.info->locktime_u) << bits;
|
|
val |= calc_locktime(rate, cpu_cur.info->locktime_m);
|
|
|
|
printk(KERN_INFO "%s: new locktime is 0x%08x\n", __func__, val);
|
|
__raw_writel(val, S3C2410_LOCKTIME);
|
|
}
|
|
|
|
static int s3c_cpufreq_build_freq(void)
|
|
{
|
|
int size, ret;
|
|
|
|
if (!cpu_cur.info->calc_freqtable)
|
|
return -EINVAL;
|
|
|
|
kfree(ftab);
|
|
ftab = NULL;
|
|
|
|
size = cpu_cur.info->calc_freqtable(&cpu_cur, NULL, 0);
|
|
size++;
|
|
|
|
ftab = kmalloc(sizeof(struct cpufreq_frequency_table) * size, GFP_KERNEL);
|
|
if (!ftab) {
|
|
printk(KERN_ERR "%s: no memory for tables\n", __func__);
|
|
return -ENOMEM;
|
|
}
|
|
|
|
ftab_size = size;
|
|
|
|
ret = cpu_cur.info->calc_freqtable(&cpu_cur, ftab, size);
|
|
s3c_cpufreq_addfreq(ftab, ret, size, CPUFREQ_TABLE_END);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int __init s3c_cpufreq_initcall(void)
|
|
{
|
|
int ret = 0;
|
|
|
|
if (cpu_cur.info && cpu_cur.board) {
|
|
ret = s3c_cpufreq_initclks();
|
|
if (ret)
|
|
goto out;
|
|
|
|
/* get current settings */
|
|
s3c_cpufreq_getcur(&cpu_cur);
|
|
s3c_cpufreq_show("cur", &cpu_cur);
|
|
|
|
if (cpu_cur.board->auto_io) {
|
|
ret = s3c_cpufreq_auto_io();
|
|
if (ret) {
|
|
printk(KERN_ERR "%s: failed to get io timing\n",
|
|
__func__);
|
|
goto out;
|
|
}
|
|
}
|
|
|
|
if (cpu_cur.board->need_io && !cpu_cur.info->set_iotiming) {
|
|
printk(KERN_ERR "%s: no IO support registered\n",
|
|
__func__);
|
|
ret = -EINVAL;
|
|
goto out;
|
|
}
|
|
|
|
if (!cpu_cur.info->need_pll)
|
|
cpu_cur.lock_pll = 1;
|
|
|
|
s3c_cpufreq_update_loctkime();
|
|
|
|
s3c_cpufreq_freq_min(&cpu_cur.max, &cpu_cur.board->max,
|
|
&cpu_cur.info->max);
|
|
|
|
if (cpu_cur.info->calc_freqtable)
|
|
s3c_cpufreq_build_freq();
|
|
|
|
ret = cpufreq_register_driver(&s3c24xx_driver);
|
|
}
|
|
|
|
out:
|
|
return ret;
|
|
}
|
|
|
|
late_initcall(s3c_cpufreq_initcall);
|
|
|
|
/**
|
|
* s3c_plltab_register - register CPU PLL table.
|
|
* @plls: The list of PLL entries.
|
|
* @plls_no: The size of the PLL entries @plls.
|
|
*
|
|
* Register the given set of PLLs with the system.
|
|
*/
|
|
int __init s3c_plltab_register(struct cpufreq_frequency_table *plls,
|
|
unsigned int plls_no)
|
|
{
|
|
struct cpufreq_frequency_table *vals;
|
|
unsigned int size;
|
|
|
|
size = sizeof(struct cpufreq_frequency_table) * (plls_no + 1);
|
|
|
|
vals = kmalloc(size, GFP_KERNEL);
|
|
if (vals) {
|
|
memcpy(vals, plls, size);
|
|
pll_reg = vals;
|
|
|
|
/* write a terminating entry, we don't store it in the
|
|
* table that is stored in the kernel */
|
|
vals += plls_no;
|
|
vals->frequency = CPUFREQ_TABLE_END;
|
|
|
|
printk(KERN_INFO "cpufreq: %d PLL entries\n", plls_no);
|
|
} else
|
|
printk(KERN_ERR "cpufreq: no memory for PLL tables\n");
|
|
|
|
return vals ? 0 : -ENOMEM;
|
|
}
|