xref: /openbmc/linux/arch/sparc/kernel/leon_pmc.c (revision 598ec971)
17279b82cSDaniel Hellstrom /* leon_pmc.c: LEON Power-down cpu_idle() handler
27279b82cSDaniel Hellstrom  *
37279b82cSDaniel Hellstrom  * Copyright (C) 2011 Daniel Hellstrom (daniel@gaisler.com) Aeroflex Gaisler AB
47279b82cSDaniel Hellstrom  */
57279b82cSDaniel Hellstrom 
67279b82cSDaniel Hellstrom #include <linux/init.h>
77279b82cSDaniel Hellstrom #include <linux/pm.h>
87279b82cSDaniel Hellstrom 
97279b82cSDaniel Hellstrom #include <asm/leon_amba.h>
10556626adSSam Ravnborg #include <asm/cpu_type.h>
117279b82cSDaniel Hellstrom #include <asm/leon.h>
12d472ba84SLen Brown #include <asm/processor.h>
137279b82cSDaniel Hellstrom 
147279b82cSDaniel Hellstrom /* List of Systems that need fixup instructions around power-down instruction */
157279b82cSDaniel Hellstrom unsigned int pmc_leon_fixup_ids[] = {
167279b82cSDaniel Hellstrom 	AEROFLEX_UT699,
177279b82cSDaniel Hellstrom 	GAISLER_GR712RC,
187279b82cSDaniel Hellstrom 	LEON4_NEXTREME1,
197279b82cSDaniel Hellstrom 	0
207279b82cSDaniel Hellstrom };
217279b82cSDaniel Hellstrom 
227279b82cSDaniel Hellstrom int pmc_leon_need_fixup(void)
237279b82cSDaniel Hellstrom {
247279b82cSDaniel Hellstrom 	unsigned int systemid = amba_system_id >> 16;
257279b82cSDaniel Hellstrom 	unsigned int *id;
267279b82cSDaniel Hellstrom 
277279b82cSDaniel Hellstrom 	id = &pmc_leon_fixup_ids[0];
287279b82cSDaniel Hellstrom 	while (*id != 0) {
297279b82cSDaniel Hellstrom 		if (*id == systemid)
307279b82cSDaniel Hellstrom 			return 1;
317279b82cSDaniel Hellstrom 		id++;
327279b82cSDaniel Hellstrom 	}
337279b82cSDaniel Hellstrom 
347279b82cSDaniel Hellstrom 	return 0;
357279b82cSDaniel Hellstrom }
367279b82cSDaniel Hellstrom 
377279b82cSDaniel Hellstrom /*
387279b82cSDaniel Hellstrom  * CPU idle callback function for systems that need some extra handling
397279b82cSDaniel Hellstrom  * See .../arch/sparc/kernel/process.c
407279b82cSDaniel Hellstrom  */
417279b82cSDaniel Hellstrom void pmc_leon_idle_fixup(void)
427279b82cSDaniel Hellstrom {
437279b82cSDaniel Hellstrom 	/* Prepare an address to a non-cachable region. APB is always
447279b82cSDaniel Hellstrom 	 * none-cachable. One instruction is executed after the Sleep
457279b82cSDaniel Hellstrom 	 * instruction, we make sure to read the bus and throw away the
467279b82cSDaniel Hellstrom 	 * value by accessing a non-cachable area, also we make sure the
477279b82cSDaniel Hellstrom 	 * MMU does not get a TLB miss here by using the MMU BYPASS ASI.
487279b82cSDaniel Hellstrom 	 */
497279b82cSDaniel Hellstrom 	register unsigned int address = (unsigned int)leon3_irqctrl_regs;
507279b82cSDaniel Hellstrom 	__asm__ __volatile__ (
51598ec971SDavid S. Miller 		"wr	%%g0, %%asr19\n"
527279b82cSDaniel Hellstrom 		"lda	[%0] %1, %%g0\n"
537279b82cSDaniel Hellstrom 		:
547279b82cSDaniel Hellstrom 		: "r"(address), "i"(ASI_LEON_BYPASS));
557279b82cSDaniel Hellstrom }
567279b82cSDaniel Hellstrom 
577279b82cSDaniel Hellstrom /*
587279b82cSDaniel Hellstrom  * CPU idle callback function
597279b82cSDaniel Hellstrom  * See .../arch/sparc/kernel/process.c
607279b82cSDaniel Hellstrom  */
617279b82cSDaniel Hellstrom void pmc_leon_idle(void)
627279b82cSDaniel Hellstrom {
637279b82cSDaniel Hellstrom 	/* For systems without power-down, this will be no-op */
64598ec971SDavid S. Miller 	__asm__ __volatile__ ("wr	%g0, %asr19\n\t");
657279b82cSDaniel Hellstrom }
667279b82cSDaniel Hellstrom 
677279b82cSDaniel Hellstrom /* Install LEON Power Down function */
687279b82cSDaniel Hellstrom static int __init leon_pmc_install(void)
697279b82cSDaniel Hellstrom {
70556626adSSam Ravnborg 	if (sparc_cpu_model == sparc_leon) {
717279b82cSDaniel Hellstrom 		/* Assign power management IDLE handler */
727279b82cSDaniel Hellstrom 		if (pmc_leon_need_fixup())
73d472ba84SLen Brown 			sparc_idle = pmc_leon_idle_fixup;
747279b82cSDaniel Hellstrom 		else
75d472ba84SLen Brown 			sparc_idle = pmc_leon_idle;
767279b82cSDaniel Hellstrom 
777279b82cSDaniel Hellstrom 		printk(KERN_INFO "leon: power management initialized\n");
78556626adSSam Ravnborg 	}
797279b82cSDaniel Hellstrom 
807279b82cSDaniel Hellstrom 	return 0;
817279b82cSDaniel Hellstrom }
827279b82cSDaniel Hellstrom 
837279b82cSDaniel Hellstrom /* This driver is not critical to the boot process, don't care
847279b82cSDaniel Hellstrom  * if initialized late.
857279b82cSDaniel Hellstrom  */
867279b82cSDaniel Hellstrom late_initcall(leon_pmc_install);
87