2007-04-27 13:46:01 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 PA Semi, Inc
|
|
|
|
*
|
|
|
|
* Authors: Egor Martovetsky <egor@pasemi.com>
|
|
|
|
* Olof Johansson <olof@lixom.net>
|
|
|
|
*
|
|
|
|
* Maintained by: Olof Johansson <olof@lixom.net>
|
|
|
|
*
|
|
|
|
* Based on arch/powerpc/platforms/cell/cbe_cpufreq.c:
|
|
|
|
* (C) Copyright IBM Deutschland Entwicklung GmbH 2005
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/cpufreq.h>
|
|
|
|
#include <linux/timer.h>
|
2011-05-28 01:23:32 +08:00
|
|
|
#include <linux/module.h>
|
2013-09-18 03:28:33 +08:00
|
|
|
#include <linux/of_address.h>
|
2007-04-27 13:46:01 +08:00
|
|
|
|
|
|
|
#include <asm/hw_irq.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/prom.h>
|
2007-05-04 12:39:21 +08:00
|
|
|
#include <asm/time.h>
|
2007-11-07 23:26:06 +08:00
|
|
|
#include <asm/smp.h>
|
2007-04-27 13:46:01 +08:00
|
|
|
|
|
|
|
#define SDCASR_REG 0x0100
|
|
|
|
#define SDCASR_REG_STRIDE 0x1000
|
|
|
|
#define SDCPWR_CFGA0_REG 0x0100
|
|
|
|
#define SDCPWR_PWST0_REG 0x0000
|
|
|
|
#define SDCPWR_GIZTIME_REG 0x0440
|
|
|
|
|
|
|
|
/* SDCPWR_GIZTIME_REG fields */
|
|
|
|
#define SDCPWR_GIZTIME_GR 0x80000000
|
|
|
|
#define SDCPWR_GIZTIME_LONGLOCK 0x000000ff
|
|
|
|
|
|
|
|
/* Offset of ASR registers from SDC base */
|
|
|
|
#define SDCASR_OFFSET 0x120000
|
|
|
|
|
|
|
|
static void __iomem *sdcpwr_mapbase;
|
|
|
|
static void __iomem *sdcasr_mapbase;
|
|
|
|
|
|
|
|
/* Current astate, is used when waking up from power savings on
|
|
|
|
* one core, in case the other core has switched states during
|
|
|
|
* the idle time.
|
|
|
|
*/
|
|
|
|
static int current_astate;
|
|
|
|
|
|
|
|
/* We support 5(A0-A4) power states excluding turbo(A5-A6) modes */
|
|
|
|
static struct cpufreq_frequency_table pas_freqs[] = {
|
2014-03-28 21:41:47 +08:00
|
|
|
{0, 0, 0},
|
|
|
|
{0, 1, 0},
|
|
|
|
{0, 2, 0},
|
|
|
|
{0, 3, 0},
|
|
|
|
{0, 4, 0},
|
|
|
|
{0, 0, CPUFREQ_TABLE_END},
|
2007-04-27 13:46:01 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* hardware specific functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int get_astate_freq(int astate)
|
|
|
|
{
|
|
|
|
u32 ret;
|
|
|
|
ret = in_le32(sdcpwr_mapbase + SDCPWR_CFGA0_REG + (astate * 0x10));
|
|
|
|
|
|
|
|
return ret & 0x3f;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_cur_astate(int cpu)
|
|
|
|
{
|
|
|
|
u32 ret;
|
|
|
|
|
|
|
|
ret = in_le32(sdcpwr_mapbase + SDCPWR_PWST0_REG);
|
|
|
|
ret = (ret >> (cpu * 4)) & 0x7;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_gizmo_latency(void)
|
|
|
|
{
|
|
|
|
u32 giztime, ret;
|
|
|
|
|
|
|
|
giztime = in_le32(sdcpwr_mapbase + SDCPWR_GIZTIME_REG);
|
|
|
|
|
|
|
|
/* just provide the upper bound */
|
|
|
|
if (giztime & SDCPWR_GIZTIME_GR)
|
|
|
|
ret = (giztime & SDCPWR_GIZTIME_LONGLOCK) * 128000;
|
|
|
|
else
|
|
|
|
ret = (giztime & SDCPWR_GIZTIME_LONGLOCK) * 1000;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_astate(int cpu, unsigned int astate)
|
|
|
|
{
|
2009-01-06 22:06:28 +08:00
|
|
|
unsigned long flags;
|
2007-04-27 13:46:01 +08:00
|
|
|
|
|
|
|
/* Return if called before init has run */
|
|
|
|
if (unlikely(!sdcasr_mapbase))
|
|
|
|
return;
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
|
|
|
|
out_le32(sdcasr_mapbase + SDCASR_REG + SDCASR_REG_STRIDE*cpu, astate);
|
|
|
|
|
|
|
|
local_irq_restore(flags);
|
|
|
|
}
|
|
|
|
|
2007-11-07 23:26:06 +08:00
|
|
|
int check_astate(void)
|
|
|
|
{
|
|
|
|
return get_cur_astate(hard_smp_processor_id());
|
|
|
|
}
|
|
|
|
|
2007-04-27 13:46:01 +08:00
|
|
|
void restore_astate(int cpu)
|
|
|
|
{
|
|
|
|
set_astate(cpu, current_astate);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cpufreq functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int pas_cpufreq_cpu_init(struct cpufreq_policy *policy)
|
|
|
|
{
|
2014-04-26 04:15:38 +08:00
|
|
|
struct cpufreq_frequency_table *pos;
|
2007-04-29 14:29:08 +08:00
|
|
|
const u32 *max_freqp;
|
|
|
|
u32 max_freq;
|
2018-01-30 13:42:37 +08:00
|
|
|
int cur_astate, idx;
|
2007-04-27 13:46:01 +08:00
|
|
|
struct resource res;
|
|
|
|
struct device_node *cpu, *dn;
|
|
|
|
int err = -ENODEV;
|
|
|
|
|
|
|
|
cpu = of_get_cpu_node(policy->cpu, NULL);
|
|
|
|
|
|
|
|
if (!cpu)
|
|
|
|
goto out;
|
|
|
|
|
2007-11-05 10:57:45 +08:00
|
|
|
dn = of_find_compatible_node(NULL, NULL, "1682m-sdc");
|
|
|
|
if (!dn)
|
|
|
|
dn = of_find_compatible_node(NULL, NULL,
|
|
|
|
"pasemi,pwrficient-sdc");
|
2007-04-27 13:46:01 +08:00
|
|
|
if (!dn)
|
|
|
|
goto out;
|
|
|
|
err = of_address_to_resource(dn, 0, &res);
|
|
|
|
of_node_put(dn);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
sdcasr_mapbase = ioremap(res.start + SDCASR_OFFSET, 0x2000);
|
|
|
|
if (!sdcasr_mapbase) {
|
|
|
|
err = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2007-11-05 10:57:45 +08:00
|
|
|
dn = of_find_compatible_node(NULL, NULL, "1682m-gizmo");
|
|
|
|
if (!dn)
|
|
|
|
dn = of_find_compatible_node(NULL, NULL,
|
|
|
|
"pasemi,pwrficient-gizmo");
|
2007-04-27 13:46:01 +08:00
|
|
|
if (!dn) {
|
|
|
|
err = -ENODEV;
|
|
|
|
goto out_unmap_sdcasr;
|
|
|
|
}
|
|
|
|
err = of_address_to_resource(dn, 0, &res);
|
|
|
|
of_node_put(dn);
|
|
|
|
if (err)
|
|
|
|
goto out_unmap_sdcasr;
|
|
|
|
sdcpwr_mapbase = ioremap(res.start, 0x1000);
|
|
|
|
if (!sdcpwr_mapbase) {
|
|
|
|
err = -EINVAL;
|
|
|
|
goto out_unmap_sdcasr;
|
|
|
|
}
|
|
|
|
|
|
|
|
pr_debug("init cpufreq on CPU %d\n", policy->cpu);
|
|
|
|
|
2007-04-29 14:29:08 +08:00
|
|
|
max_freqp = of_get_property(cpu, "clock-frequency", NULL);
|
|
|
|
if (!max_freqp) {
|
2007-04-27 13:46:01 +08:00
|
|
|
err = -EINVAL;
|
|
|
|
goto out_unmap_sdcpwr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we need the freq in kHz */
|
2007-04-29 14:29:08 +08:00
|
|
|
max_freq = *max_freqp / 1000;
|
2007-04-27 13:46:01 +08:00
|
|
|
|
2007-04-29 14:29:08 +08:00
|
|
|
pr_debug("max clock-frequency is at %u kHz\n", max_freq);
|
2007-04-27 13:46:01 +08:00
|
|
|
pr_debug("initializing frequency table\n");
|
|
|
|
|
|
|
|
/* initialize frequency table */
|
2018-01-30 13:42:37 +08:00
|
|
|
cpufreq_for_each_entry_idx(pos, pas_freqs, idx) {
|
2014-04-26 04:15:38 +08:00
|
|
|
pos->frequency = get_astate_freq(pos->driver_data) * 100000;
|
2018-01-30 13:42:37 +08:00
|
|
|
pr_debug("%d: %d\n", idx, pos->frequency);
|
2007-04-27 13:46:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cur_astate = get_cur_astate(policy->cpu);
|
|
|
|
pr_debug("current astate is at %d\n",cur_astate);
|
|
|
|
|
|
|
|
policy->cur = pas_freqs[cur_astate].frequency;
|
2007-05-04 12:39:21 +08:00
|
|
|
ppc_proc_freq = policy->cur * 1000ul;
|
|
|
|
|
2013-10-03 22:59:19 +08:00
|
|
|
return cpufreq_generic_init(policy, pas_freqs, get_gizmo_latency());
|
2007-04-27 13:46:01 +08:00
|
|
|
|
|
|
|
out_unmap_sdcpwr:
|
|
|
|
iounmap(sdcpwr_mapbase);
|
|
|
|
|
|
|
|
out_unmap_sdcasr:
|
|
|
|
iounmap(sdcasr_mapbase);
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pas_cpufreq_cpu_exit(struct cpufreq_policy *policy)
|
|
|
|
{
|
powerpc/pasemi: Fix crash on reboot
commit f96972f2dc "kernel/sys.c: call disable_nonboot_cpus() in
kernel_restart()"
added a call to disable_nonboot_cpus() on kernel_restart(), which tries
to shutdown all the CPUs except the first one. The issue with the PA
Semi, is that it does not support CPU hotplug.
When the call is made to __cpu_down(), it calls the notifiers
CPU_DOWN_PREPARE, and then tries to take the CPU down.
One of the notifiers to the CPU hotplug code, is the cpufreq. The
DOWN_PREPARE will call __cpufreq_remove_dev() which calls
cpufreq_driver->exit. The PA Semi exit handler unmaps regions of I/O
that is used by an interrupt that goes off constantly
(system_reset_common, but it goes off during normal system operations
too). I'm not sure exactly what this interrupt does.
Running a simple function trace, you can see it goes off quite a bit:
# tracer: function
#
# TASK-PID CPU# TIMESTAMP FUNCTION
# | | | | |
<idle>-0 [001] 1558.859363: .pasemi_system_reset_exception <-.system_reset_exception
<idle>-0 [000] 1558.860112: .pasemi_system_reset_exception <-.system_reset_exception
<idle>-0 [000] 1558.861109: .pasemi_system_reset_exception <-.system_reset_exception
<idle>-0 [001] 1558.861361: .pasemi_system_reset_exception <-.system_reset_exception
<idle>-0 [000] 1558.861437: .pasemi_system_reset_exception <-.system_reset_exception
When the region is unmapped, the system crashes with:
Disabling non-boot CPUs ...
Error taking CPU1 down: -38
Unable to handle kernel paging request for data at address 0xd0000800903a0100
Faulting instruction address: 0xc000000000055fcc
Oops: Kernel access of bad area, sig: 11 [#1]
PREEMPT SMP NR_CPUS=64 NUMA PA Semi PWRficient
Modules linked in: shpchp
NIP: c000000000055fcc LR: c000000000055fb4 CTR: c0000000000df1fc
REGS: c0000000012175d0 TRAP: 0300 Not tainted (3.8.0-rc4-test-dirty)
MSR: 9000000000009032 <SF,HV,EE,ME,IR,DR,RI> CR: 24000088 XER: 00000000
SOFTE: 0
DAR: d0000800903a0100, DSISR: 42000000
TASK = c0000000010e9008[0] 'swapper/0' THREAD: c000000001214000 CPU: 0
GPR00: d0000800903a0000 c000000001217850 c0000000012167e0 0000000000000000
GPR04: 0000000000000000 0000000000000724 0000000000000724 0000000000000000
GPR08: 0000000000000000 0000000000000000 0000000000000001 0000000000a70000
GPR12: 0000000024000080 c00000000fff0000 ffffffffffffffff 000000003ffffae0
GPR16: ffffffffffffffff 0000000000a21198 0000000000000060 0000000000000000
GPR20: 00000000008fdd35 0000000000a21258 000000003ffffaf0 0000000000000417
GPR24: 0000000000a226d0 c000000000000000 0000000000000000 0000000000000000
GPR28: c00000000138b358 0000000000000000 c000000001144818 d0000800903a0100
NIP [c000000000055fcc] .set_astate+0x5c/0xa4
LR [c000000000055fb4] .set_astate+0x44/0xa4
Call Trace:
[c000000001217850] [c000000000055fb4] .set_astate+0x44/0xa4 (unreliable)
[c0000000012178f0] [c00000000005647c] .restore_astate+0x2c/0x34
[c000000001217980] [c000000000054668] .pasemi_system_reset_exception+0x6c/0x88
[c000000001217a00] [c000000000019ef0] .system_reset_exception+0x48/0x84
[c000000001217a80] [c000000000001e40] system_reset_common+0x140/0x180
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2013-01-22 01:23:26 +08:00
|
|
|
/*
|
|
|
|
* We don't support CPU hotplug. Don't unmap after the system
|
|
|
|
* has already made it to a running state.
|
|
|
|
*/
|
2017-05-17 02:42:40 +08:00
|
|
|
if (system_state >= SYSTEM_RUNNING)
|
powerpc/pasemi: Fix crash on reboot
commit f96972f2dc "kernel/sys.c: call disable_nonboot_cpus() in
kernel_restart()"
added a call to disable_nonboot_cpus() on kernel_restart(), which tries
to shutdown all the CPUs except the first one. The issue with the PA
Semi, is that it does not support CPU hotplug.
When the call is made to __cpu_down(), it calls the notifiers
CPU_DOWN_PREPARE, and then tries to take the CPU down.
One of the notifiers to the CPU hotplug code, is the cpufreq. The
DOWN_PREPARE will call __cpufreq_remove_dev() which calls
cpufreq_driver->exit. The PA Semi exit handler unmaps regions of I/O
that is used by an interrupt that goes off constantly
(system_reset_common, but it goes off during normal system operations
too). I'm not sure exactly what this interrupt does.
Running a simple function trace, you can see it goes off quite a bit:
# tracer: function
#
# TASK-PID CPU# TIMESTAMP FUNCTION
# | | | | |
<idle>-0 [001] 1558.859363: .pasemi_system_reset_exception <-.system_reset_exception
<idle>-0 [000] 1558.860112: .pasemi_system_reset_exception <-.system_reset_exception
<idle>-0 [000] 1558.861109: .pasemi_system_reset_exception <-.system_reset_exception
<idle>-0 [001] 1558.861361: .pasemi_system_reset_exception <-.system_reset_exception
<idle>-0 [000] 1558.861437: .pasemi_system_reset_exception <-.system_reset_exception
When the region is unmapped, the system crashes with:
Disabling non-boot CPUs ...
Error taking CPU1 down: -38
Unable to handle kernel paging request for data at address 0xd0000800903a0100
Faulting instruction address: 0xc000000000055fcc
Oops: Kernel access of bad area, sig: 11 [#1]
PREEMPT SMP NR_CPUS=64 NUMA PA Semi PWRficient
Modules linked in: shpchp
NIP: c000000000055fcc LR: c000000000055fb4 CTR: c0000000000df1fc
REGS: c0000000012175d0 TRAP: 0300 Not tainted (3.8.0-rc4-test-dirty)
MSR: 9000000000009032 <SF,HV,EE,ME,IR,DR,RI> CR: 24000088 XER: 00000000
SOFTE: 0
DAR: d0000800903a0100, DSISR: 42000000
TASK = c0000000010e9008[0] 'swapper/0' THREAD: c000000001214000 CPU: 0
GPR00: d0000800903a0000 c000000001217850 c0000000012167e0 0000000000000000
GPR04: 0000000000000000 0000000000000724 0000000000000724 0000000000000000
GPR08: 0000000000000000 0000000000000000 0000000000000001 0000000000a70000
GPR12: 0000000024000080 c00000000fff0000 ffffffffffffffff 000000003ffffae0
GPR16: ffffffffffffffff 0000000000a21198 0000000000000060 0000000000000000
GPR20: 00000000008fdd35 0000000000a21258 000000003ffffaf0 0000000000000417
GPR24: 0000000000a226d0 c000000000000000 0000000000000000 0000000000000000
GPR28: c00000000138b358 0000000000000000 c000000001144818 d0000800903a0100
NIP [c000000000055fcc] .set_astate+0x5c/0xa4
LR [c000000000055fb4] .set_astate+0x44/0xa4
Call Trace:
[c000000001217850] [c000000000055fb4] .set_astate+0x44/0xa4 (unreliable)
[c0000000012178f0] [c00000000005647c] .restore_astate+0x2c/0x34
[c000000001217980] [c000000000054668] .pasemi_system_reset_exception+0x6c/0x88
[c000000001217a00] [c000000000019ef0] .system_reset_exception+0x48/0x84
[c000000001217a80] [c000000000001e40] system_reset_common+0x140/0x180
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2013-01-22 01:23:26 +08:00
|
|
|
return 0;
|
|
|
|
|
2007-04-27 13:46:01 +08:00
|
|
|
if (sdcasr_mapbase)
|
|
|
|
iounmap(sdcasr_mapbase);
|
|
|
|
if (sdcpwr_mapbase)
|
|
|
|
iounmap(sdcpwr_mapbase);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pas_cpufreq_target(struct cpufreq_policy *policy,
|
2013-10-25 22:15:48 +08:00
|
|
|
unsigned int pas_astate_new)
|
2007-04-27 13:46:01 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
pr_debug("setting frequency for cpu %d to %d kHz, 1/%d of max frequency\n",
|
|
|
|
policy->cpu,
|
|
|
|
pas_freqs[pas_astate_new].frequency,
|
2013-03-30 18:55:15 +08:00
|
|
|
pas_freqs[pas_astate_new].driver_data);
|
2007-04-27 13:46:01 +08:00
|
|
|
|
|
|
|
current_astate = pas_astate_new;
|
|
|
|
|
|
|
|
for_each_online_cpu(i)
|
|
|
|
set_astate(i, pas_astate_new);
|
|
|
|
|
2013-08-14 22:08:24 +08:00
|
|
|
ppc_proc_freq = pas_freqs[pas_astate_new].frequency * 1000ul;
|
2007-04-27 13:46:01 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct cpufreq_driver pas_cpufreq_driver = {
|
|
|
|
.name = "pas-cpufreq",
|
|
|
|
.flags = CPUFREQ_CONST_LOOPS,
|
|
|
|
.init = pas_cpufreq_cpu_init,
|
|
|
|
.exit = pas_cpufreq_cpu_exit,
|
2013-10-03 22:58:15 +08:00
|
|
|
.verify = cpufreq_generic_frequency_table_verify,
|
2013-10-25 22:15:48 +08:00
|
|
|
.target_index = pas_cpufreq_target,
|
2013-10-03 22:58:15 +08:00
|
|
|
.attr = cpufreq_generic_attr,
|
2007-04-27 13:46:01 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* module init and destoy
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int __init pas_cpufreq_init(void)
|
|
|
|
{
|
2010-02-02 12:34:14 +08:00
|
|
|
if (!of_machine_is_compatible("PA6T-1682M") &&
|
|
|
|
!of_machine_is_compatible("pasemi,pwrficient"))
|
2007-04-27 13:46:01 +08:00
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
return cpufreq_register_driver(&pas_cpufreq_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit pas_cpufreq_exit(void)
|
|
|
|
{
|
|
|
|
cpufreq_unregister_driver(&pas_cpufreq_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(pas_cpufreq_init);
|
|
|
|
module_exit(pas_cpufreq_exit);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Egor Martovetsky <egor@pasemi.com>, Olof Johansson <olof@lixom.net>");
|