xref: /openbmc/linux/arch/sparc/kernel/leon_pmc.c (revision b2441318)
1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
27279b82cSDaniel Hellstrom /* leon_pmc.c: LEON Power-down cpu_idle() handler
37279b82cSDaniel Hellstrom  *
47279b82cSDaniel Hellstrom  * Copyright (C) 2011 Daniel Hellstrom (daniel@gaisler.com) Aeroflex Gaisler AB
57279b82cSDaniel Hellstrom  */
67279b82cSDaniel Hellstrom 
77279b82cSDaniel Hellstrom #include <linux/init.h>
87279b82cSDaniel Hellstrom #include <linux/pm.h>
97279b82cSDaniel Hellstrom 
107279b82cSDaniel Hellstrom #include <asm/leon_amba.h>
11556626adSSam Ravnborg #include <asm/cpu_type.h>
127279b82cSDaniel Hellstrom #include <asm/leon.h>
13d472ba84SLen Brown #include <asm/processor.h>
147279b82cSDaniel Hellstrom 
157279b82cSDaniel Hellstrom /* List of Systems that need fixup instructions around power-down instruction */
168b45c796SSam Ravnborg static unsigned int pmc_leon_fixup_ids[] = {
177279b82cSDaniel Hellstrom 	AEROFLEX_UT699,
187279b82cSDaniel Hellstrom 	GAISLER_GR712RC,
197279b82cSDaniel Hellstrom 	LEON4_NEXTREME1,
207279b82cSDaniel Hellstrom 	0
217279b82cSDaniel Hellstrom };
227279b82cSDaniel Hellstrom 
238b45c796SSam Ravnborg static int pmc_leon_need_fixup(void)
247279b82cSDaniel Hellstrom {
257279b82cSDaniel Hellstrom 	unsigned int systemid = amba_system_id >> 16;
267279b82cSDaniel Hellstrom 	unsigned int *id;
277279b82cSDaniel Hellstrom 
287279b82cSDaniel Hellstrom 	id = &pmc_leon_fixup_ids[0];
297279b82cSDaniel Hellstrom 	while (*id != 0) {
307279b82cSDaniel Hellstrom 		if (*id == systemid)
317279b82cSDaniel Hellstrom 			return 1;
327279b82cSDaniel Hellstrom 		id++;
337279b82cSDaniel Hellstrom 	}
347279b82cSDaniel Hellstrom 
357279b82cSDaniel Hellstrom 	return 0;
367279b82cSDaniel Hellstrom }
377279b82cSDaniel Hellstrom 
387279b82cSDaniel Hellstrom /*
397279b82cSDaniel Hellstrom  * CPU idle callback function for systems that need some extra handling
407279b82cSDaniel Hellstrom  * See .../arch/sparc/kernel/process.c
417279b82cSDaniel Hellstrom  */
428b45c796SSam Ravnborg static void pmc_leon_idle_fixup(void)
437279b82cSDaniel Hellstrom {
447279b82cSDaniel Hellstrom 	/* Prepare an address to a non-cachable region. APB is always
457279b82cSDaniel Hellstrom 	 * none-cachable. One instruction is executed after the Sleep
467279b82cSDaniel Hellstrom 	 * instruction, we make sure to read the bus and throw away the
477279b82cSDaniel Hellstrom 	 * value by accessing a non-cachable area, also we make sure the
487279b82cSDaniel Hellstrom 	 * MMU does not get a TLB miss here by using the MMU BYPASS ASI.
497279b82cSDaniel Hellstrom 	 */
507279b82cSDaniel Hellstrom 	register unsigned int address = (unsigned int)leon3_irqctrl_regs;
51d72ee6beSAndreas Larsson 
52d72ee6beSAndreas Larsson 	/* Interrupts need to be enabled to not hang the CPU */
53d72ee6beSAndreas Larsson 	local_irq_enable();
54d72ee6beSAndreas Larsson 
557279b82cSDaniel Hellstrom 	__asm__ __volatile__ (
56598ec971SDavid S. Miller 		"wr	%%g0, %%asr19\n"
577279b82cSDaniel Hellstrom 		"lda	[%0] %1, %%g0\n"
587279b82cSDaniel Hellstrom 		:
597279b82cSDaniel Hellstrom 		: "r"(address), "i"(ASI_LEON_BYPASS));
607279b82cSDaniel Hellstrom }
617279b82cSDaniel Hellstrom 
627279b82cSDaniel Hellstrom /*
637279b82cSDaniel Hellstrom  * CPU idle callback function
647279b82cSDaniel Hellstrom  * See .../arch/sparc/kernel/process.c
657279b82cSDaniel Hellstrom  */
668b45c796SSam Ravnborg static void pmc_leon_idle(void)
677279b82cSDaniel Hellstrom {
68d72ee6beSAndreas Larsson 	/* Interrupts need to be enabled to not hang the CPU */
69d72ee6beSAndreas Larsson 	local_irq_enable();
70d72ee6beSAndreas Larsson 
717279b82cSDaniel Hellstrom 	/* For systems without power-down, this will be no-op */
72598ec971SDavid S. Miller 	__asm__ __volatile__ ("wr	%g0, %asr19\n\t");
737279b82cSDaniel Hellstrom }
747279b82cSDaniel Hellstrom 
757279b82cSDaniel Hellstrom /* Install LEON Power Down function */
767279b82cSDaniel Hellstrom static int __init leon_pmc_install(void)
777279b82cSDaniel Hellstrom {
78556626adSSam Ravnborg 	if (sparc_cpu_model == sparc_leon) {
797279b82cSDaniel Hellstrom 		/* Assign power management IDLE handler */
807279b82cSDaniel Hellstrom 		if (pmc_leon_need_fixup())
81d472ba84SLen Brown 			sparc_idle = pmc_leon_idle_fixup;
827279b82cSDaniel Hellstrom 		else
83d472ba84SLen Brown 			sparc_idle = pmc_leon_idle;
847279b82cSDaniel Hellstrom 
857279b82cSDaniel Hellstrom 		printk(KERN_INFO "leon: power management initialized\n");
86556626adSSam Ravnborg 	}
877279b82cSDaniel Hellstrom 
887279b82cSDaniel Hellstrom 	return 0;
897279b82cSDaniel Hellstrom }
907279b82cSDaniel Hellstrom 
917279b82cSDaniel Hellstrom /* This driver is not critical to the boot process, don't care
927279b82cSDaniel Hellstrom  * if initialized late.
937279b82cSDaniel Hellstrom  */
947279b82cSDaniel Hellstrom late_initcall(leon_pmc_install);
95