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
pmc_leon_need_fixup(void)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 */
pmc_leon_idle_fixup(void)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 */
5358c644baSPeter Zijlstra raw_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));
60*89b30987SPeter Zijlstra
61*89b30987SPeter Zijlstra raw_local_irq_disable();
627279b82cSDaniel Hellstrom }
637279b82cSDaniel Hellstrom
647279b82cSDaniel Hellstrom /*
657279b82cSDaniel Hellstrom * CPU idle callback function
667279b82cSDaniel Hellstrom * See .../arch/sparc/kernel/process.c
677279b82cSDaniel Hellstrom */
pmc_leon_idle(void)688b45c796SSam Ravnborg static void pmc_leon_idle(void)
697279b82cSDaniel Hellstrom {
70d72ee6beSAndreas Larsson /* Interrupts need to be enabled to not hang the CPU */
7158c644baSPeter Zijlstra raw_local_irq_enable();
72d72ee6beSAndreas Larsson
737279b82cSDaniel Hellstrom /* For systems without power-down, this will be no-op */
74598ec971SDavid S. Miller __asm__ __volatile__ ("wr %g0, %asr19\n\t");
75*89b30987SPeter Zijlstra
76*89b30987SPeter Zijlstra raw_local_irq_disable();
777279b82cSDaniel Hellstrom }
787279b82cSDaniel Hellstrom
797279b82cSDaniel Hellstrom /* Install LEON Power Down function */
leon_pmc_install(void)807279b82cSDaniel Hellstrom static int __init leon_pmc_install(void)
817279b82cSDaniel Hellstrom {
82556626adSSam Ravnborg if (sparc_cpu_model == sparc_leon) {
837279b82cSDaniel Hellstrom /* Assign power management IDLE handler */
847279b82cSDaniel Hellstrom if (pmc_leon_need_fixup())
85d472ba84SLen Brown sparc_idle = pmc_leon_idle_fixup;
867279b82cSDaniel Hellstrom else
87d472ba84SLen Brown sparc_idle = pmc_leon_idle;
887279b82cSDaniel Hellstrom
897279b82cSDaniel Hellstrom printk(KERN_INFO "leon: power management initialized\n");
90556626adSSam Ravnborg }
917279b82cSDaniel Hellstrom
927279b82cSDaniel Hellstrom return 0;
937279b82cSDaniel Hellstrom }
947279b82cSDaniel Hellstrom
957279b82cSDaniel Hellstrom /* This driver is not critical to the boot process, don't care
967279b82cSDaniel Hellstrom * if initialized late.
977279b82cSDaniel Hellstrom */
987279b82cSDaniel Hellstrom late_initcall(leon_pmc_install);
99