Daniel Hellstrom | 7279b82 | 2011-01-27 01:26:58 +0000 | [diff] [blame] | 1 | /* leon_pmc.c: LEON Power-down cpu_idle() handler |
| 2 | * |
| 3 | * Copyright (C) 2011 Daniel Hellstrom (daniel@gaisler.com) Aeroflex Gaisler AB |
| 4 | */ |
| 5 | |
| 6 | #include <linux/init.h> |
| 7 | #include <linux/pm.h> |
| 8 | |
| 9 | #include <asm/leon_amba.h> |
Sam Ravnborg | 556626a | 2012-05-26 04:43:27 +0000 | [diff] [blame] | 10 | #include <asm/cpu_type.h> |
Daniel Hellstrom | 7279b82 | 2011-01-27 01:26:58 +0000 | [diff] [blame] | 11 | #include <asm/leon.h> |
Len Brown | d472ba8 | 2013-02-09 23:27:26 -0500 | [diff] [blame] | 12 | #include <asm/processor.h> |
Daniel Hellstrom | 7279b82 | 2011-01-27 01:26:58 +0000 | [diff] [blame] | 13 | |
| 14 | /* List of Systems that need fixup instructions around power-down instruction */ |
Sam Ravnborg | 8b45c79 | 2014-04-21 21:39:41 +0200 | [diff] [blame] | 15 | static unsigned int pmc_leon_fixup_ids[] = { |
Daniel Hellstrom | 7279b82 | 2011-01-27 01:26:58 +0000 | [diff] [blame] | 16 | AEROFLEX_UT699, |
| 17 | GAISLER_GR712RC, |
| 18 | LEON4_NEXTREME1, |
| 19 | 0 |
| 20 | }; |
| 21 | |
Sam Ravnborg | 8b45c79 | 2014-04-21 21:39:41 +0200 | [diff] [blame] | 22 | static int pmc_leon_need_fixup(void) |
Daniel Hellstrom | 7279b82 | 2011-01-27 01:26:58 +0000 | [diff] [blame] | 23 | { |
| 24 | unsigned int systemid = amba_system_id >> 16; |
| 25 | unsigned int *id; |
| 26 | |
| 27 | id = &pmc_leon_fixup_ids[0]; |
| 28 | while (*id != 0) { |
| 29 | if (*id == systemid) |
| 30 | return 1; |
| 31 | id++; |
| 32 | } |
| 33 | |
| 34 | return 0; |
| 35 | } |
| 36 | |
| 37 | /* |
| 38 | * CPU idle callback function for systems that need some extra handling |
| 39 | * See .../arch/sparc/kernel/process.c |
| 40 | */ |
Sam Ravnborg | 8b45c79 | 2014-04-21 21:39:41 +0200 | [diff] [blame] | 41 | static void pmc_leon_idle_fixup(void) |
Daniel Hellstrom | 7279b82 | 2011-01-27 01:26:58 +0000 | [diff] [blame] | 42 | { |
| 43 | /* Prepare an address to a non-cachable region. APB is always |
| 44 | * none-cachable. One instruction is executed after the Sleep |
| 45 | * instruction, we make sure to read the bus and throw away the |
| 46 | * value by accessing a non-cachable area, also we make sure the |
| 47 | * MMU does not get a TLB miss here by using the MMU BYPASS ASI. |
| 48 | */ |
| 49 | register unsigned int address = (unsigned int)leon3_irqctrl_regs; |
Andreas Larsson | d72ee6b | 2013-06-10 08:56:41 +0200 | [diff] [blame] | 50 | |
| 51 | /* Interrupts need to be enabled to not hang the CPU */ |
| 52 | local_irq_enable(); |
| 53 | |
Daniel Hellstrom | 7279b82 | 2011-01-27 01:26:58 +0000 | [diff] [blame] | 54 | __asm__ __volatile__ ( |
David S. Miller | 598ec97 | 2013-04-06 17:51:48 -0400 | [diff] [blame] | 55 | "wr %%g0, %%asr19\n" |
Daniel Hellstrom | 7279b82 | 2011-01-27 01:26:58 +0000 | [diff] [blame] | 56 | "lda [%0] %1, %%g0\n" |
| 57 | : |
| 58 | : "r"(address), "i"(ASI_LEON_BYPASS)); |
| 59 | } |
| 60 | |
| 61 | /* |
| 62 | * CPU idle callback function |
| 63 | * See .../arch/sparc/kernel/process.c |
| 64 | */ |
Sam Ravnborg | 8b45c79 | 2014-04-21 21:39:41 +0200 | [diff] [blame] | 65 | static void pmc_leon_idle(void) |
Daniel Hellstrom | 7279b82 | 2011-01-27 01:26:58 +0000 | [diff] [blame] | 66 | { |
Andreas Larsson | d72ee6b | 2013-06-10 08:56:41 +0200 | [diff] [blame] | 67 | /* Interrupts need to be enabled to not hang the CPU */ |
| 68 | local_irq_enable(); |
| 69 | |
Daniel Hellstrom | 7279b82 | 2011-01-27 01:26:58 +0000 | [diff] [blame] | 70 | /* For systems without power-down, this will be no-op */ |
David S. Miller | 598ec97 | 2013-04-06 17:51:48 -0400 | [diff] [blame] | 71 | __asm__ __volatile__ ("wr %g0, %asr19\n\t"); |
Daniel Hellstrom | 7279b82 | 2011-01-27 01:26:58 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | /* Install LEON Power Down function */ |
| 75 | static int __init leon_pmc_install(void) |
| 76 | { |
Sam Ravnborg | 556626a | 2012-05-26 04:43:27 +0000 | [diff] [blame] | 77 | if (sparc_cpu_model == sparc_leon) { |
| 78 | /* Assign power management IDLE handler */ |
| 79 | if (pmc_leon_need_fixup()) |
Len Brown | d472ba8 | 2013-02-09 23:27:26 -0500 | [diff] [blame] | 80 | sparc_idle = pmc_leon_idle_fixup; |
Sam Ravnborg | 556626a | 2012-05-26 04:43:27 +0000 | [diff] [blame] | 81 | else |
Len Brown | d472ba8 | 2013-02-09 23:27:26 -0500 | [diff] [blame] | 82 | sparc_idle = pmc_leon_idle; |
Daniel Hellstrom | 7279b82 | 2011-01-27 01:26:58 +0000 | [diff] [blame] | 83 | |
Sam Ravnborg | 556626a | 2012-05-26 04:43:27 +0000 | [diff] [blame] | 84 | printk(KERN_INFO "leon: power management initialized\n"); |
| 85 | } |
Daniel Hellstrom | 7279b82 | 2011-01-27 01:26:58 +0000 | [diff] [blame] | 86 | |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | /* This driver is not critical to the boot process, don't care |
| 91 | * if initialized late. |
| 92 | */ |
| 93 | late_initcall(leon_pmc_install); |