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; 50*d72ee6beSAndreas Larsson 51*d72ee6beSAndreas Larsson /* Interrupts need to be enabled to not hang the CPU */ 52*d72ee6beSAndreas Larsson local_irq_enable(); 53*d72ee6beSAndreas Larsson 547279b82cSDaniel Hellstrom __asm__ __volatile__ ( 55598ec971SDavid S. Miller "wr %%g0, %%asr19\n" 567279b82cSDaniel Hellstrom "lda [%0] %1, %%g0\n" 577279b82cSDaniel Hellstrom : 587279b82cSDaniel Hellstrom : "r"(address), "i"(ASI_LEON_BYPASS)); 597279b82cSDaniel Hellstrom } 607279b82cSDaniel Hellstrom 617279b82cSDaniel Hellstrom /* 627279b82cSDaniel Hellstrom * CPU idle callback function 637279b82cSDaniel Hellstrom * See .../arch/sparc/kernel/process.c 647279b82cSDaniel Hellstrom */ 657279b82cSDaniel Hellstrom void pmc_leon_idle(void) 667279b82cSDaniel Hellstrom { 67*d72ee6beSAndreas Larsson /* Interrupts need to be enabled to not hang the CPU */ 68*d72ee6beSAndreas Larsson local_irq_enable(); 69*d72ee6beSAndreas Larsson 707279b82cSDaniel Hellstrom /* For systems without power-down, this will be no-op */ 71598ec971SDavid S. Miller __asm__ __volatile__ ("wr %g0, %asr19\n\t"); 727279b82cSDaniel Hellstrom } 737279b82cSDaniel Hellstrom 747279b82cSDaniel Hellstrom /* Install LEON Power Down function */ 757279b82cSDaniel Hellstrom static int __init leon_pmc_install(void) 767279b82cSDaniel Hellstrom { 77556626adSSam Ravnborg if (sparc_cpu_model == sparc_leon) { 787279b82cSDaniel Hellstrom /* Assign power management IDLE handler */ 797279b82cSDaniel Hellstrom if (pmc_leon_need_fixup()) 80d472ba84SLen Brown sparc_idle = pmc_leon_idle_fixup; 817279b82cSDaniel Hellstrom else 82d472ba84SLen Brown sparc_idle = pmc_leon_idle; 837279b82cSDaniel Hellstrom 847279b82cSDaniel Hellstrom printk(KERN_INFO "leon: power management initialized\n"); 85556626adSSam Ravnborg } 867279b82cSDaniel Hellstrom 877279b82cSDaniel Hellstrom return 0; 887279b82cSDaniel Hellstrom } 897279b82cSDaniel Hellstrom 907279b82cSDaniel Hellstrom /* This driver is not critical to the boot process, don't care 917279b82cSDaniel Hellstrom * if initialized late. 927279b82cSDaniel Hellstrom */ 937279b82cSDaniel Hellstrom late_initcall(leon_pmc_install); 94