Skip to content

Commit 7279b82

Browse files
daniel-hellstromdavem330
authored andcommitted
SPARC/LEON: power down instruction different of different LEONs
The way a LEON is powered down is implemented differently depending on CHIP type. The AMBA Plug&Play system ID tells revision of GRLIB and CHIP. This is for example needed by the GR-LEON4-ITX board and the UT699. Previously the power down support for LEON was limited to SMP, now both SMP and UP systems use the instruction. Signed-off-by: Daniel Hellstrom <daniel@gaisler.com> Acked-by: Sam Ravnborg <sam@ravnborg.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 684151a commit 7279b82

5 files changed

Lines changed: 97 additions & 17 deletions

File tree

‎arch/sparc/include/asm/leon_amba.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ struct amba_ahb_device {
180180
struct device_node;
181181
void _amba_init(struct device_node *dp, struct device_node ***nextp);
182182

183+
extern unsigned long amba_system_id;
183184
extern struct leon3_irqctrl_regs_map *leon3_irqctrl_regs;
184185
extern struct leon3_gptimer_regs_map *leon3_gptimer_regs;
185186
extern struct amba_apb_device leon_percpu_timer_dev[16];
@@ -254,6 +255,11 @@ extern unsigned int sparc_leon_eirq;
254255
#define GAISLER_L2C 0xffe /* internal device: leon2compat */
255256
#define GAISLER_PLUGPLAY 0xfff /* internal device: plug & play configarea */
256257

258+
/* Chip IDs */
259+
#define AEROFLEX_UT699 0x0699
260+
#define LEON4_NEXTREME1 0x0102
261+
#define GAISLER_GR712RC 0x0712
262+
257263
#define amba_vendor(x) (((x) >> 24) & 0xff)
258264

259265
#define amba_device(x) (((x) >> 12) & 0xfff)

‎arch/sparc/kernel/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ obj-y += of_device_$(BITS).o
5454
obj-$(CONFIG_SPARC64) += prom_irqtrans.o
5555

5656
obj-$(CONFIG_SPARC_LEON)+= leon_kernel.o
57+
obj-$(CONFIG_SPARC_LEON)+= leon_pmc.o
5758

5859
obj-$(CONFIG_SPARC64) += reboot.o
5960
obj-$(CONFIG_SPARC64) += sysfs.o

‎arch/sparc/kernel/leon_kernel.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ struct amba_apb_device leon_percpu_timer_dev[16];
3030
int leondebug_irq_disable;
3131
int leon_debug_irqout;
3232
static int dummy_master_l10_counter;
33+
unsigned long amba_system_id;
3334

3435
unsigned long leon3_gptimer_irq; /* interrupt controller irq number */
3536
unsigned long leon3_gptimer_idx; /* Timer Index (0..6) within Timer Core */
@@ -117,10 +118,16 @@ void __init leon_init_timers(irq_handler_t counter_fn)
117118
master_l10_counter = (unsigned int *)&dummy_master_l10_counter;
118119
dummy_master_l10_counter = 0;
119120

120-
/*Find IRQMP IRQ Controller Registers base address otherwise bail out.*/
121121
rootnp = of_find_node_by_path("/ambapp0");
122122
if (!rootnp)
123123
goto bad;
124+
125+
/* Find System ID: GRLIB build ID and optional CHIP ID */
126+
pp = of_find_property(rootnp, "systemid", &len);
127+
if (pp)
128+
amba_system_id = *(unsigned long *)pp->value;
129+
130+
/* Find IRQMP IRQ Controller Registers base adr otherwise bail out */
124131
np = of_find_node_by_name(rootnp, "GAISLER_IRQMP");
125132
if (!np) {
126133
np = of_find_node_by_name(rootnp, "01_00d");

‎arch/sparc/kernel/leon_pmc.c‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/* leon_pmc.c: LEON Power-down cpu_idle() handler
2+
*
3+
* Copyright (C) 2011 Daniel Hellstrom (daniel@gaisler.com) Aeroflex Gaisler AB
4+
*/
5+
6+
#include <linux/init.h>
7+
#include <linux/pm.h>
8+
9+
#include <asm/leon_amba.h>
10+
#include <asm/leon.h>
11+
12+
/* List of Systems that need fixup instructions around power-down instruction */
13+
unsigned int pmc_leon_fixup_ids[] = {
14+
AEROFLEX_UT699,
15+
GAISLER_GR712RC,
16+
LEON4_NEXTREME1,
17+
0
18+
};
19+
20+
int pmc_leon_need_fixup(void)
21+
{
22+
unsigned int systemid = amba_system_id >> 16;
23+
unsigned int *id;
24+
25+
id = &pmc_leon_fixup_ids[0];
26+
while (*id != 0) {
27+
if (*id == systemid)
28+
return 1;
29+
id++;
30+
}
31+
32+
return 0;
33+
}
34+
35+
/*
36+
* CPU idle callback function for systems that need some extra handling
37+
* See .../arch/sparc/kernel/process.c
38+
*/
39+
void pmc_leon_idle_fixup(void)
40+
{
41+
/* Prepare an address to a non-cachable region. APB is always
42+
* none-cachable. One instruction is executed after the Sleep
43+
* instruction, we make sure to read the bus and throw away the
44+
* value by accessing a non-cachable area, also we make sure the
45+
* MMU does not get a TLB miss here by using the MMU BYPASS ASI.
46+
*/
47+
register unsigned int address = (unsigned int)leon3_irqctrl_regs;
48+
__asm__ __volatile__ (
49+
"mov %%g0, %%asr19\n"
50+
"lda [%0] %1, %%g0\n"
51+
:
52+
: "r"(address), "i"(ASI_LEON_BYPASS));
53+
}
54+
55+
/*
56+
* CPU idle callback function
57+
* See .../arch/sparc/kernel/process.c
58+
*/
59+
void pmc_leon_idle(void)
60+
{
61+
/* For systems without power-down, this will be no-op */
62+
__asm__ __volatile__ ("mov %g0, %asr19\n\t");
63+
}
64+
65+
/* Install LEON Power Down function */
66+
static int __init leon_pmc_install(void)
67+
{
68+
/* Assign power management IDLE handler */
69+
if (pmc_leon_need_fixup())
70+
pm_idle = pmc_leon_idle_fixup;
71+
else
72+
pm_idle = pmc_leon_idle;
73+
74+
printk(KERN_INFO "leon: power management initialized\n");
75+
76+
return 0;
77+
}
78+
79+
/* This driver is not critical to the boot process, don't care
80+
* if initialized late.
81+
*/
82+
late_initcall(leon_pmc_install);

‎arch/sparc/kernel/leon_smp.c‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -437,15 +437,6 @@ void __init leon_blackbox_current(unsigned *addr)
437437

438438
}
439439

440-
/*
441-
* CPU idle callback function
442-
* See .../arch/sparc/kernel/process.c
443-
*/
444-
void pmc_leon_idle(void)
445-
{
446-
__asm__ volatile ("mov %g0, %asr19");
447-
}
448-
449440
void __init leon_init_smp(void)
450441
{
451442
/* Patch ipi15 trap table */
@@ -456,13 +447,6 @@ void __init leon_init_smp(void)
456447
BTFIXUPSET_CALL(smp_cross_call, leon_cross_call, BTFIXUPCALL_NORM);
457448
BTFIXUPSET_CALL(__hard_smp_processor_id, __leon_processor_id,
458449
BTFIXUPCALL_NORM);
459-
460-
#ifndef PMC_NO_IDLE
461-
/* Assign power management IDLE handler */
462-
pm_idle = pmc_leon_idle;
463-
printk(KERN_INFO "leon: power management initialized\n");
464-
#endif
465-
466450
}
467451

468452
#endif /* CONFIG_SPARC_LEON */

0 commit comments

Comments
 (0)