Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /* leon_pmc.c: LEON Power-down cpu_idle() handler
0003  *
0004  * Copyright (C) 2011 Daniel Hellstrom (daniel@gaisler.com) Aeroflex Gaisler AB
0005  */
0006 
0007 #include <linux/init.h>
0008 #include <linux/pm.h>
0009 
0010 #include <asm/leon_amba.h>
0011 #include <asm/cpu_type.h>
0012 #include <asm/leon.h>
0013 #include <asm/processor.h>
0014 
0015 /* List of Systems that need fixup instructions around power-down instruction */
0016 static unsigned int pmc_leon_fixup_ids[] = {
0017     AEROFLEX_UT699,
0018     GAISLER_GR712RC,
0019     LEON4_NEXTREME1,
0020     0
0021 };
0022 
0023 static int pmc_leon_need_fixup(void)
0024 {
0025     unsigned int systemid = amba_system_id >> 16;
0026     unsigned int *id;
0027 
0028     id = &pmc_leon_fixup_ids[0];
0029     while (*id != 0) {
0030         if (*id == systemid)
0031             return 1;
0032         id++;
0033     }
0034 
0035     return 0;
0036 }
0037 
0038 /*
0039  * CPU idle callback function for systems that need some extra handling
0040  * See .../arch/sparc/kernel/process.c
0041  */
0042 static void pmc_leon_idle_fixup(void)
0043 {
0044     /* Prepare an address to a non-cachable region. APB is always
0045      * none-cachable. One instruction is executed after the Sleep
0046      * instruction, we make sure to read the bus and throw away the
0047      * value by accessing a non-cachable area, also we make sure the
0048      * MMU does not get a TLB miss here by using the MMU BYPASS ASI.
0049      */
0050     register unsigned int address = (unsigned int)leon3_irqctrl_regs;
0051 
0052     /* Interrupts need to be enabled to not hang the CPU */
0053     raw_local_irq_enable();
0054 
0055     __asm__ __volatile__ (
0056         "wr %%g0, %%asr19\n"
0057         "lda    [%0] %1, %%g0\n"
0058         :
0059         : "r"(address), "i"(ASI_LEON_BYPASS));
0060 }
0061 
0062 /*
0063  * CPU idle callback function
0064  * See .../arch/sparc/kernel/process.c
0065  */
0066 static void pmc_leon_idle(void)
0067 {
0068     /* Interrupts need to be enabled to not hang the CPU */
0069     raw_local_irq_enable();
0070 
0071     /* For systems without power-down, this will be no-op */
0072     __asm__ __volatile__ ("wr   %g0, %asr19\n\t");
0073 }
0074 
0075 /* Install LEON Power Down function */
0076 static int __init leon_pmc_install(void)
0077 {
0078     if (sparc_cpu_model == sparc_leon) {
0079         /* Assign power management IDLE handler */
0080         if (pmc_leon_need_fixup())
0081             sparc_idle = pmc_leon_idle_fixup;
0082         else
0083             sparc_idle = pmc_leon_idle;
0084 
0085         printk(KERN_INFO "leon: power management initialized\n");
0086     }
0087 
0088     return 0;
0089 }
0090 
0091 /* This driver is not critical to the boot process, don't care
0092  * if initialized late.
0093  */
0094 late_initcall(leon_pmc_install);