xref: /openbmc/linux/arch/sparc/kernel/leon_pmc.c (revision 556626adf1dc1ee88183b7ba267912b87b063a57)
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>
10*556626adSSam Ravnborg #include <asm/cpu_type.h>
117279b82cSDaniel Hellstrom #include <asm/leon.h>
127279b82cSDaniel Hellstrom 
137279b82cSDaniel Hellstrom /* List of Systems that need fixup instructions around power-down instruction */
147279b82cSDaniel Hellstrom unsigned int pmc_leon_fixup_ids[] = {
157279b82cSDaniel Hellstrom 	AEROFLEX_UT699,
167279b82cSDaniel Hellstrom 	GAISLER_GR712RC,
177279b82cSDaniel Hellstrom 	LEON4_NEXTREME1,
187279b82cSDaniel Hellstrom 	0
197279b82cSDaniel Hellstrom };
207279b82cSDaniel Hellstrom 
217279b82cSDaniel Hellstrom int pmc_leon_need_fixup(void)
227279b82cSDaniel Hellstrom {
237279b82cSDaniel Hellstrom 	unsigned int systemid = amba_system_id >> 16;
247279b82cSDaniel Hellstrom 	unsigned int *id;
257279b82cSDaniel Hellstrom 
267279b82cSDaniel Hellstrom 	id = &pmc_leon_fixup_ids[0];
277279b82cSDaniel Hellstrom 	while (*id != 0) {
287279b82cSDaniel Hellstrom 		if (*id == systemid)
297279b82cSDaniel Hellstrom 			return 1;
307279b82cSDaniel Hellstrom 		id++;
317279b82cSDaniel Hellstrom 	}
327279b82cSDaniel Hellstrom 
337279b82cSDaniel Hellstrom 	return 0;
347279b82cSDaniel Hellstrom }
357279b82cSDaniel Hellstrom 
367279b82cSDaniel Hellstrom /*
377279b82cSDaniel Hellstrom  * CPU idle callback function for systems that need some extra handling
387279b82cSDaniel Hellstrom  * See .../arch/sparc/kernel/process.c
397279b82cSDaniel Hellstrom  */
407279b82cSDaniel Hellstrom void pmc_leon_idle_fixup(void)
417279b82cSDaniel Hellstrom {
427279b82cSDaniel Hellstrom 	/* Prepare an address to a non-cachable region. APB is always
437279b82cSDaniel Hellstrom 	 * none-cachable. One instruction is executed after the Sleep
447279b82cSDaniel Hellstrom 	 * instruction, we make sure to read the bus and throw away the
457279b82cSDaniel Hellstrom 	 * value by accessing a non-cachable area, also we make sure the
467279b82cSDaniel Hellstrom 	 * MMU does not get a TLB miss here by using the MMU BYPASS ASI.
477279b82cSDaniel Hellstrom 	 */
487279b82cSDaniel Hellstrom 	register unsigned int address = (unsigned int)leon3_irqctrl_regs;
497279b82cSDaniel Hellstrom 	__asm__ __volatile__ (
507279b82cSDaniel Hellstrom 		"mov	%%g0, %%asr19\n"
517279b82cSDaniel Hellstrom 		"lda	[%0] %1, %%g0\n"
527279b82cSDaniel Hellstrom 		:
537279b82cSDaniel Hellstrom 		: "r"(address), "i"(ASI_LEON_BYPASS));
547279b82cSDaniel Hellstrom }
557279b82cSDaniel Hellstrom 
567279b82cSDaniel Hellstrom /*
577279b82cSDaniel Hellstrom  * CPU idle callback function
587279b82cSDaniel Hellstrom  * See .../arch/sparc/kernel/process.c
597279b82cSDaniel Hellstrom  */
607279b82cSDaniel Hellstrom void pmc_leon_idle(void)
617279b82cSDaniel Hellstrom {
627279b82cSDaniel Hellstrom 	/* For systems without power-down, this will be no-op */
637279b82cSDaniel Hellstrom 	__asm__ __volatile__ ("mov	%g0, %asr19\n\t");
647279b82cSDaniel Hellstrom }
657279b82cSDaniel Hellstrom 
667279b82cSDaniel Hellstrom /* Install LEON Power Down function */
677279b82cSDaniel Hellstrom static int __init leon_pmc_install(void)
687279b82cSDaniel Hellstrom {
69*556626adSSam Ravnborg 	if (sparc_cpu_model == sparc_leon) {
707279b82cSDaniel Hellstrom 		/* Assign power management IDLE handler */
717279b82cSDaniel Hellstrom 		if (pmc_leon_need_fixup())
727279b82cSDaniel Hellstrom 			pm_idle = pmc_leon_idle_fixup;
737279b82cSDaniel Hellstrom 		else
747279b82cSDaniel Hellstrom 			pm_idle = pmc_leon_idle;
757279b82cSDaniel Hellstrom 
767279b82cSDaniel Hellstrom 		printk(KERN_INFO "leon: power management initialized\n");
77*556626adSSam Ravnborg 	}
787279b82cSDaniel Hellstrom 
797279b82cSDaniel Hellstrom 	return 0;
807279b82cSDaniel Hellstrom }
817279b82cSDaniel Hellstrom 
827279b82cSDaniel Hellstrom /* This driver is not critical to the boot process, don't care
837279b82cSDaniel Hellstrom  * if initialized late.
847279b82cSDaniel Hellstrom  */
857279b82cSDaniel Hellstrom late_initcall(leon_pmc_install);
86