developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * |
| 7 | * Redistributions of source code must retain the above copyright notice, this |
| 8 | * list of conditions and the following disclaimer. |
| 9 | * |
| 10 | * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * Neither the name of ARM nor the names of its contributors may be used |
| 15 | * to endorse or promote products derived from this software without specific |
| 16 | * prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | * POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | #include <bakery_lock.h> |
| 31 | #include <debug.h> |
developer | e3ae6d0 | 2015-11-16 13:44:31 +0800 | [diff] [blame] | 32 | #include <delay_timer.h> |
| 33 | #include <mmio.h> |
| 34 | #include <mt8173_def.h> |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 35 | #include <spm.h> |
| 36 | #include <spm_suspend.h> |
| 37 | |
| 38 | /* |
| 39 | * System Power Manager (SPM) is a hardware module, which controls cpu or |
| 40 | * system power for different power scenarios using different firmware. |
| 41 | * This driver controls the system power in system suspend flow. |
| 42 | */ |
| 43 | |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 44 | #define WAKE_SRC_FOR_SUSPEND \ |
| 45 | (WAKE_SRC_KP | WAKE_SRC_EINT | WAKE_SRC_MD32 | \ |
| 46 | WAKE_SRC_USB_CD | WAKE_SRC_USB_PDN | WAKE_SRC_THERM | \ |
developer | 2cdc217 | 2015-08-11 19:01:42 +0800 | [diff] [blame] | 47 | WAKE_SRC_SYSPWREQ | WAKE_SRC_ALL_MD32) |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 48 | |
| 49 | #define WAKE_SRC_FOR_MD32 0 |
| 50 | |
| 51 | #define spm_is_wakesrc_invalid(wakesrc) \ |
| 52 | (!!((unsigned int)(wakesrc) & 0xc0003803)) |
| 53 | |
developer | e3ae6d0 | 2015-11-16 13:44:31 +0800 | [diff] [blame] | 54 | #define ARMCA15PLL_CON0 (APMIXED_BASE + 0x200) |
| 55 | #define ARMCA15PLL_CON1 (APMIXED_BASE + 0x204) |
| 56 | #define ARMCA15PLL_PWR_CON0 (APMIXED_BASE + 0x20c) |
| 57 | #define ARMCA15PLL_PWR_ON (1U << 0) |
| 58 | #define ARMCA15PLL_ISO_EN (1U << 1) |
| 59 | #define ARMCA15PLL_EN (1U << 0) |
| 60 | |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 61 | const unsigned int spm_flags = |
| 62 | SPM_DUALVCORE_PDN_DIS | SPM_PASR_DIS | SPM_DPD_DIS | |
| 63 | SPM_CPU_DVS_DIS | SPM_OPT | SPM_INFRA_PDN_DIS; |
| 64 | |
| 65 | enum wake_reason_t spm_wake_reason = WR_NONE; |
| 66 | |
| 67 | /********************************************************** |
| 68 | * PCM sequence for cpu suspend |
| 69 | **********************************************************/ |
| 70 | static const unsigned int suspend_binary_ca7[] = { |
| 71 | 0x81f58407, 0x81f68407, 0x803a0400, 0x803a8400, 0x1b80001f, 0x20000000, |
developer | 4a7822a | 2015-11-16 14:22:32 +0800 | [diff] [blame] | 72 | 0x80300400, 0x80318400, 0x80328400, 0xa1d28407, 0x81f20407, 0x81009801, |
| 73 | 0xd8000244, 0x17c07c1f, 0x18c0001f, 0x10006234, 0xc0c032e0, 0x1200041f, |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 74 | 0x80310400, 0x1b80001f, 0x2000000a, 0xa0110400, 0x18c0001f, 0x100062c8, |
| 75 | 0xe0e00010, 0xe0e00030, 0xe0e00070, 0xe0e000f0, 0x1b80001f, 0x2000001a, |
| 76 | 0xe0e00ff0, 0xe8208000, 0x10006354, 0xfffe7fff, 0xe8208000, 0x10006834, |
developer | 4a7822a | 2015-11-16 14:22:32 +0800 | [diff] [blame] | 77 | 0x00000010, 0x81f00407, 0xa1dd0407, 0x81fd0407, 0xc2803800, 0x1290041f, |
| 78 | 0x8880000c, 0x2f7be75f, 0xd8200722, 0x17c07c1f, 0xd82006a9, 0x17c07c1f, |
| 79 | 0xe8208000, 0x10006814, 0x00000001, 0xc2803800, 0x1293841f, 0x1b00001f, |
| 80 | 0x7fffe7ff, 0xd0000760, 0x17c07c1f, 0x1b00001f, 0x7ffff7ff, 0xf0000000, |
| 81 | 0x17c07c1f, 0x80880001, 0xd8000842, 0x17c07c1f, 0xd00028e0, 0x1200041f, |
| 82 | 0xe8208000, 0x10006834, 0x00000000, 0x1b00001f, 0x3fffe7ff, 0x1b80001f, |
| 83 | 0x20000004, 0xd8200a0c, 0x17c07c1f, 0xe8208000, 0x10006834, 0x00000010, |
| 84 | 0xd0001280, 0x17c07c1f, 0x18c0001f, 0x10006608, 0x1910001f, 0x10006608, |
| 85 | 0x813b0404, 0xe0c00004, 0x1880001f, 0x10006320, 0xc0c03760, 0xe080000f, |
| 86 | 0xd8200c03, 0x17c07c1f, 0x1b00001f, 0x7ffff7ff, 0xd0001280, 0x17c07c1f, |
| 87 | 0xe080001f, 0xe8208000, 0x10006354, 0xffffffff, 0x18c0001f, 0x100062c8, |
| 88 | 0xe0e000f0, 0xe0e00030, 0xe0e00000, 0x81009801, 0xd80010c4, 0x17c07c1f, |
| 89 | 0x18c0001f, 0x10004094, 0x1910001f, 0x1020e374, 0xe0c00004, 0x18c0001f, |
| 90 | 0x10004098, 0x1910001f, 0x1020e378, 0xe0c00004, 0x18c0001f, 0x10011094, |
| 91 | 0x1910001f, 0x10213374, 0xe0c00004, 0x18c0001f, 0x10011098, 0x1910001f, |
| 92 | 0x10213378, 0xe0c00004, 0x1910001f, 0x10213378, 0x18c0001f, 0x10006234, |
| 93 | 0xc0c034a0, 0x17c07c1f, 0xc2803800, 0x1290841f, 0xa1d20407, 0x81f28407, |
| 94 | 0xa1d68407, 0xa0128400, 0xa0118400, 0xa0100400, 0xa01a8400, 0xa01a0400, |
| 95 | 0x19c0001f, 0x001c239f, 0x1b00001f, 0x3fffefff, 0xf0000000, 0x17c07c1f, |
| 96 | 0x808d8001, 0xd8201502, 0x17c07c1f, 0x803d8400, 0x1b80001f, 0x2000001a, |
| 97 | 0x80340400, 0x17c07c1f, 0x17c07c1f, 0x80310400, 0x81fa0407, 0x81f18407, |
| 98 | 0x81f08407, 0xa1dc0407, 0x1b80001f, 0x200000b6, 0xd0002220, 0x17c07c1f, |
| 99 | 0x1880001f, 0x20000208, 0x81011801, 0xd80016e4, 0x17c07c1f, 0xe8208000, |
| 100 | 0x1000f600, 0xd2000000, 0x1380081f, 0x18c0001f, 0x10006240, 0xe0e00016, |
| 101 | 0xe0e0001e, 0xe0e0000e, 0xe0e0000f, 0x80368400, 0x1380081f, 0x80370400, |
| 102 | 0x1380081f, 0x80360400, 0x803e0400, 0x1380081f, 0x80380400, 0x803b0400, |
| 103 | 0xa01d8400, 0x1b80001f, 0x20000034, 0x803d8400, 0x1b80001f, 0x20000152, |
| 104 | 0x803d0400, 0x1380081f, 0x18c0001f, 0x1000f5c8, 0x1910001f, 0x1000f5c8, |
| 105 | 0xa1000404, 0xe0c00004, 0x18c0001f, 0x100125c8, 0x1910001f, 0x100125c8, |
| 106 | 0xa1000404, 0xe0c00004, 0x1910001f, 0x100125c8, 0x80340400, 0x17c07c1f, |
| 107 | 0x17c07c1f, 0x80310400, 0xe8208000, 0x10000044, 0x00000100, 0x1b80001f, |
| 108 | 0x20000068, 0x1b80001f, 0x2000000a, 0x18c0001f, 0x10006240, 0xe0e0000d, |
| 109 | 0x81011801, 0xd8001f64, 0x17c07c1f, 0x18c0001f, 0x100040f4, 0x1910001f, |
| 110 | 0x100040f4, 0xa11c8404, 0xe0c00004, 0x1b80001f, 0x2000000a, 0x813c8404, |
| 111 | 0xe0c00004, 0x18c0001f, 0x100110f4, 0x1910001f, 0x100110f4, 0xa11c8404, |
| 112 | 0xe0c00004, 0x1b80001f, 0x2000000a, 0x813c8404, 0xe0c00004, 0x1b80001f, |
| 113 | 0x20000100, 0x81fa0407, 0x81f18407, 0x81f08407, 0xe8208000, 0x10006354, |
| 114 | 0xfffe7b47, 0x18c0001f, 0x65930003, 0xc0c031c0, 0x17c07c1f, 0xc2803800, |
| 115 | 0x1293041f, 0xa1d80407, 0xa1dc0407, 0x18c0001f, 0x10006608, 0x1910001f, |
| 116 | 0x10006608, 0xa11b0404, 0xe0c00004, 0xc2803800, 0x1291041f, 0x8880000c, |
| 117 | 0x2f7be75f, 0xd8202362, 0x17c07c1f, 0x1b00001f, 0x3fffe7ff, 0xd00023a0, |
| 118 | 0x17c07c1f, 0x1b00001f, 0xbfffe7ff, 0xf0000000, 0x17c07c1f, 0x1890001f, |
| 119 | 0x10006608, 0x808b0801, 0xd8202642, 0x17c07c1f, 0x1880001f, 0x10006320, |
| 120 | 0xc0c03540, 0xe080000f, 0xd80027a3, 0x17c07c1f, 0xe080001f, 0xa1da0407, |
| 121 | 0x81fc0407, 0xa0110400, 0xa0140400, 0xa01d8400, 0xd0003100, 0x17c07c1f, |
| 122 | 0x1b80001f, 0x20000fdf, 0x1890001f, 0x10006608, 0x80c98801, 0x810a8801, |
| 123 | 0x10918c1f, 0xa0939002, 0x8080080d, 0xd82028e2, 0x12007c1f, 0x1b00001f, |
| 124 | 0x3fffe7ff, 0x1b80001f, 0x20000004, 0xd800318c, 0x17c07c1f, 0x1b00001f, |
| 125 | 0xbfffe7ff, 0xd0003180, 0x17c07c1f, 0x81f80407, 0x81fc0407, 0x18c0001f, |
| 126 | 0x65930006, 0xc0c031c0, 0x17c07c1f, 0x18c0001f, 0x65930007, 0xc0c031c0, |
| 127 | 0x17c07c1f, 0x1880001f, 0x10006320, 0xc0c03540, 0xe080000f, 0xd80027a3, |
| 128 | 0x17c07c1f, 0xe080001f, 0x18c0001f, 0x65930005, 0xc0c031c0, 0x17c07c1f, |
| 129 | 0xa1da0407, 0xe8208000, 0x10000048, 0x00000100, 0x1b80001f, 0x20000068, |
| 130 | 0xa0110400, 0xa0140400, 0x18c0001f, 0x1000f5c8, 0x1910001f, 0x1000f5c8, |
| 131 | 0x81200404, 0xe0c00004, 0x18c0001f, 0x100125c8, 0x1910001f, 0x100125c8, |
| 132 | 0x81200404, 0xe0c00004, 0x1910001f, 0x100125c8, 0xa01d0400, 0xa01b0400, |
| 133 | 0xa0180400, 0x803d8400, 0xa01e0400, 0xa0160400, 0xa0170400, 0xa0168400, |
| 134 | 0x1b80001f, 0x20000104, 0x81011801, 0xd80030c4, 0x17c07c1f, 0x18c0001f, |
| 135 | 0x10006240, 0xc0c034a0, 0x17c07c1f, 0xe8208000, 0x1000f600, 0xd2000001, |
| 136 | 0xd8000848, 0x17c07c1f, 0xc2803800, 0x1291841f, 0x1b00001f, 0x7ffff7ff, |
| 137 | 0xf0000000, 0x17c07c1f, 0x1900001f, 0x10006830, 0xe1000003, 0x18c0001f, |
| 138 | 0x10006834, 0xe0e00000, 0xe0e00001, 0xf0000000, 0x17c07c1f, 0xe0f07f16, |
| 139 | 0x1380201f, 0xe0f07f1e, 0x1380201f, 0xe0f07f0e, 0x1b80001f, 0x20000104, |
| 140 | 0xe0f07f0c, 0xe0f07f0d, 0xe0f07e0d, 0xe0f07c0d, 0xe0f0780d, 0xf0000000, |
| 141 | 0xe0f0700d, 0xe0f07f0d, 0xe0f07f0f, 0xe0f07f1e, 0xf0000000, 0xe0f07f12, |
| 142 | 0x11407c1f, 0x81f08407, 0x81f18407, 0x1b80001f, 0x20000001, 0xa1d08407, |
| 143 | 0xa1d18407, 0x1392841f, 0x812ab401, 0x80ebb401, 0xa0c00c04, 0xd8203743, |
| 144 | 0x17c07c1f, 0x80c01403, 0xd8203563, 0x01400405, 0xf0000000, 0xa1d00407, |
| 145 | 0x1b80001f, 0x20000208, 0x80ea3401, 0xf0000000, 0x18c0001f, 0x10006b6c, |
| 146 | 0x1910001f, 0x10006b6c, 0xa1002804, 0xf0000000, 0xe0c00004, 0x17c07c1f, |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 147 | 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, |
| 148 | 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, |
| 149 | 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, |
| 150 | 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, |
| 151 | 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, |
| 152 | 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, |
| 153 | 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, |
| 154 | 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, |
| 155 | 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, 0x17c07c1f, |
| 156 | 0x17c07c1f, 0x17c07c1f, 0x1840001f, 0x00000001, 0xa1d48407, 0x1990001f, |
| 157 | 0x10006b08, 0x1a50001f, 0x10006610, 0x8246a401, 0xe8208000, 0x10006b6c, |
| 158 | 0x00000000, 0x1b00001f, 0x2f7be75f, 0x81469801, 0xd8004305, 0x17c07c1f, |
developer | 4a7822a | 2015-11-16 14:22:32 +0800 | [diff] [blame] | 159 | 0x1b80001f, 0xd00f0000, 0x8880000c, 0x2f7be75f, 0xd8005fa2, 0x17c07c1f, |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 160 | 0xd0004340, 0x17c07c1f, 0x1b80001f, 0x500f0000, 0xe8208000, 0x10006354, |
developer | 4a7822a | 2015-11-16 14:22:32 +0800 | [diff] [blame] | 161 | 0xfffe7b47, 0xc0c06c00, 0x81401801, 0xd80048e5, 0x17c07c1f, 0x81f60407, |
| 162 | 0x18c0001f, 0x10006200, 0xc0c06060, 0x12807c1f, 0xe8208000, 0x1000625c, |
| 163 | 0x00000001, 0x1b80001f, 0x20000080, 0xc0c06060, 0x1280041f, 0x18c0001f, |
| 164 | 0x10006204, 0xc0c06400, 0x1280041f, 0x18c0001f, 0x10006208, 0xc0c06060, |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 165 | 0x12807c1f, 0xe8208000, 0x10006244, 0x00000001, 0x1b80001f, 0x20000080, |
developer | 4a7822a | 2015-11-16 14:22:32 +0800 | [diff] [blame] | 166 | 0xc0c06060, 0x1280041f, 0x18d0001f, 0x10200200, 0x18c0001f, 0x10006290, |
| 167 | 0xc0c06060, 0x1280041f, 0xe8208000, 0x10006404, 0x00003101, 0xc2803800, |
developer | 99ecd88 | 2015-08-20 16:01:15 +0800 | [diff] [blame] | 168 | 0x1292041f, 0x81469801, 0xd8204a45, 0x17c07c1f, 0x1b00001f, 0x2f7be75f, |
developer | 4a7822a | 2015-11-16 14:22:32 +0800 | [diff] [blame] | 169 | 0x1b80001f, 0x30000004, 0x8880000c, 0x2f7be75f, 0xd8005a02, 0x17c07c1f, |
| 170 | 0xc0c06780, 0x17c07c1f, 0x18c0001f, 0x10006294, 0xe0f07fff, 0xe0e00fff, |
developer | 99ecd88 | 2015-08-20 16:01:15 +0800 | [diff] [blame] | 171 | 0xe0e000ff, 0x81449801, 0xd8004c85, 0x17c07c1f, 0x1a00001f, 0x10006604, |
developer | 4a7822a | 2015-11-16 14:22:32 +0800 | [diff] [blame] | 172 | 0xe2200003, 0xc0c06840, 0x17c07c1f, 0xe2200005, 0xc0c06840, 0x17c07c1f, |
developer | 99ecd88 | 2015-08-20 16:01:15 +0800 | [diff] [blame] | 173 | 0xa1d38407, 0xa1d98407, 0x1800001f, 0x00000012, 0x1800001f, 0x00000e12, |
| 174 | 0x1800001f, 0x03800e12, 0x1800001f, 0x038e0e12, 0xe8208000, 0x10006310, |
developer | 4a7822a | 2015-11-16 14:22:32 +0800 | [diff] [blame] | 175 | 0x0b1600f8, 0x1940001f, 0x00000000, 0x12407c1f, 0x1b00001f, 0xbfffe7ff, |
| 176 | 0x1b80001f, 0x90100000, 0x17c07c1f, 0xd8004fc5, 0x17c07c1f, 0x8247b001, |
| 177 | 0x1940001f, 0xffffffff, 0x80c00400, 0xd82050c3, 0xa1d58407, 0xa1dd8407, |
| 178 | 0x1b00001f, 0x3fffefff, 0xd0004ec0, 0x17c07c1f, 0x1890001f, 0x100063e8, |
| 179 | 0x88c0000c, 0x2f7be75f, 0xd80052e3, 0x17c07c1f, 0x80c40001, 0xd8005263, |
| 180 | 0x17c07c1f, 0x1b00001f, 0xbfffe7ff, 0xd00052a0, 0x17c07c1f, 0x1b00001f, |
| 181 | 0x7ffff7ff, 0xd0004ec0, 0x17c07c1f, 0x80c40001, 0xd82053e3, 0x17c07c1f, |
| 182 | 0xa1de0407, 0x1b00001f, 0x7fffe7ff, 0xd0004ec0, 0x17c07c1f, 0xe8208000, |
| 183 | 0x10006814, 0x00000000, 0x18c0001f, 0x10006b00, 0xe0e00000, 0xe0c00009, |
| 184 | 0x18c0001f, 0x10006294, 0xe0e001fe, 0xe0e003fc, 0xe0e007f8, 0xe0e00ff0, |
| 185 | 0x1b80001f, 0x20000020, 0xe0f07ff0, 0xe0f07f00, 0x81449801, 0xd80057a5, |
| 186 | 0x17c07c1f, 0x1a00001f, 0x10006604, 0xe2200002, 0xc0c06840, 0x17c07c1f, |
| 187 | 0xe2200004, 0xc0c06840, 0x17c07c1f, 0x1b80001f, 0x200016a8, 0x1800001f, |
| 188 | 0x03800e12, 0x1b80001f, 0x20000300, 0x1800001f, 0x00000e12, 0x1b80001f, |
| 189 | 0x20000300, 0x1800001f, 0x00000012, 0x1b80001f, 0x20000104, 0x10007c1f, |
| 190 | 0x81f38407, 0x81f98407, 0x81f90407, 0x81f40407, 0x1b80001f, 0x200016a8, |
| 191 | 0x81401801, 0xd8005fa5, 0x17c07c1f, 0xe8208000, 0x10006404, 0x00002101, |
| 192 | 0x18c0001f, 0x10006290, 0x1212841f, 0xc0c061e0, 0x12807c1f, 0xc0c061e0, |
| 193 | 0x1280041f, 0x18c0001f, 0x10006208, 0x1212841f, 0xc0c061e0, 0x12807c1f, |
| 194 | 0xe8208000, 0x10006244, 0x00000000, 0x1b80001f, 0x20000080, 0xc0c061e0, |
| 195 | 0x1280041f, 0xe8208000, 0x10200268, 0x000ffffe, 0x18c0001f, 0x10006204, |
| 196 | 0x1212841f, 0xc0c065a0, 0x1280041f, 0x18c0001f, 0x10006200, 0x1212841f, |
| 197 | 0xc0c061e0, 0x12807c1f, 0xe8208000, 0x1000625c, 0x00000000, 0x1b80001f, |
| 198 | 0x20000080, 0xc0c061e0, 0x1280041f, 0x19c0001f, 0x01411820, 0x1ac0001f, |
| 199 | 0x55aa55aa, 0x10007c1f, 0xf0000000, 0xd800610a, 0x17c07c1f, 0xe2e0004f, |
| 200 | 0xe2e0006f, 0xe2e0002f, 0xd82061aa, 0x17c07c1f, 0xe2e0002e, 0xe2e0003e, |
| 201 | 0xe2e00032, 0xf0000000, 0x17c07c1f, 0xd80062aa, 0x17c07c1f, 0xe2e00036, |
| 202 | 0xe2e0003e, 0x1380201f, 0xe2e0003c, 0xd82063ca, 0x17c07c1f, 0x1380201f, |
| 203 | 0xe2e0007c, 0x1b80001f, 0x20000003, 0xe2e0005c, 0xe2e0004c, 0xe2e0004d, |
| 204 | 0xf0000000, 0x17c07c1f, 0x1a50001f, 0x10006610, 0x8246a401, 0xd8206569, |
| 205 | 0x17c07c1f, 0xe2e0000d, 0xe2e0000c, 0xe2e0001c, 0xe2e0001e, 0xe2e00016, |
| 206 | 0xe2e00012, 0xf0000000, 0x17c07c1f, 0x1a50001f, 0x10006610, 0x8246a401, |
| 207 | 0xd8206749, 0x17c07c1f, 0xe2e00016, 0x1380201f, 0xe2e0001e, 0x1380201f, |
| 208 | 0xe2e0001c, 0x1380201f, 0xe2e0000c, 0xe2e0000d, 0xf0000000, 0x17c07c1f, |
| 209 | 0xa1d40407, 0x1391841f, 0xa1d90407, 0x1393041f, 0xf0000000, 0x17c07c1f, |
| 210 | 0x18d0001f, 0x10006604, 0x10cf8c1f, 0xd8206843, 0x17c07c1f, 0xf0000000, |
| 211 | 0x17c07c1f, 0xe8208000, 0x11008014, 0x00000002, 0xe8208000, 0x11008020, |
| 212 | 0x00000101, 0xe8208000, 0x11008004, 0x000000d0, 0x1a00001f, 0x11008000, |
| 213 | 0xd8006b0a, 0xe220005d, 0xd8206b2a, 0xe2200000, 0xe2200001, 0xe8208000, |
| 214 | 0x11008024, 0x00000001, 0x1b80001f, 0x20000424, 0xf0000000, 0x17c07c1f, |
| 215 | 0xa1d10407, 0x1b80001f, 0x20000020, 0xf0000000, 0x17c07c1f |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 216 | }; |
| 217 | |
| 218 | /* |
| 219 | * PCM binary for suspend scenario |
| 220 | */ |
| 221 | static const struct pcm_desc suspend_pcm_ca7 = { |
developer | 4a7822a | 2015-11-16 14:22:32 +0800 | [diff] [blame] | 222 | .version = "pcm_suspend_20150917_V4", |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 223 | .base = suspend_binary_ca7, |
developer | 4a7822a | 2015-11-16 14:22:32 +0800 | [diff] [blame] | 224 | .size = 869, |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 225 | .sess = 2, |
| 226 | .replace = 0, |
| 227 | .vec0 = EVENT_VEC(11, 1, 0, 0), |
developer | 4a7822a | 2015-11-16 14:22:32 +0800 | [diff] [blame] | 228 | .vec1 = EVENT_VEC(12, 1, 0, 61), |
| 229 | .vec2 = EVENT_VEC(30, 1, 0, 150), |
| 230 | .vec3 = EVENT_VEC(31, 1, 0, 287), |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 231 | }; |
| 232 | |
| 233 | /* |
| 234 | * SPM settings for suspend scenario |
| 235 | */ |
| 236 | static struct pwr_ctrl spm_ctrl = { |
| 237 | .wake_src = WAKE_SRC_FOR_SUSPEND, |
| 238 | .wake_src_md32 = WAKE_SRC_FOR_MD32, |
| 239 | .r0_ctrl_en = 1, |
| 240 | .r7_ctrl_en = 1, |
| 241 | .infra_dcm_lock = 1, |
| 242 | .wfi_op = WFI_OP_AND, |
| 243 | .pcm_apsrc_req = 0, |
| 244 | .ca7top_idle_mask = 0, |
| 245 | .ca15top_idle_mask = 0, |
| 246 | .mcusys_idle_mask = 0, |
| 247 | .disp_req_mask = 0, |
| 248 | .mfg_req_mask = 0, |
| 249 | .md32_req_mask = 1, |
| 250 | .srclkenai_mask = 1, |
| 251 | .ca7_wfi0_en = 1, |
| 252 | .ca7_wfi1_en = 1, |
| 253 | .ca7_wfi2_en = 1, |
| 254 | .ca7_wfi3_en = 1, |
| 255 | .ca15_wfi0_en = 1, |
| 256 | .ca15_wfi1_en = 1, |
| 257 | .ca15_wfi2_en = 1, |
| 258 | .ca15_wfi3_en = 1, |
| 259 | }; |
| 260 | |
| 261 | /* |
| 262 | * go_to_sleep_before_wfi() - trigger SPM to enter suspend scenario |
| 263 | */ |
| 264 | static void go_to_sleep_before_wfi(const unsigned int spm_flags) |
| 265 | { |
| 266 | struct pwr_ctrl *pwrctrl; |
| 267 | |
| 268 | pwrctrl = &spm_ctrl; |
| 269 | |
| 270 | set_pwrctrl_pcm_flags(pwrctrl, spm_flags); |
| 271 | |
| 272 | spm_set_sysclk_settle(); |
| 273 | |
| 274 | INFO("sec = %u, wakesrc = 0x%x (%u)(%u)\n", |
| 275 | pwrctrl->timer_val, pwrctrl->wake_src, |
| 276 | is_cpu_pdn(pwrctrl->pcm_flags), |
| 277 | is_infra_pdn(pwrctrl->pcm_flags)); |
| 278 | |
| 279 | spm_reset_and_init_pcm(); |
| 280 | spm_init_pcm_register(); |
| 281 | spm_set_power_control(pwrctrl); |
| 282 | spm_set_wakeup_event(pwrctrl); |
| 283 | spm_kick_pcm_to_run(pwrctrl); |
| 284 | spm_init_event_vector(&suspend_pcm_ca7); |
| 285 | spm_kick_im_to_fetch(&suspend_pcm_ca7); |
| 286 | } |
| 287 | |
| 288 | /* |
| 289 | * go_to_sleep_after_wfi() - get wakeup reason after |
| 290 | * leaving suspend scenario and clean up SPM settings |
| 291 | */ |
| 292 | static enum wake_reason_t go_to_sleep_after_wfi(void) |
| 293 | { |
| 294 | struct wake_status wakesta; |
| 295 | static enum wake_reason_t last_wr = WR_NONE; |
| 296 | |
| 297 | spm_get_wakeup_status(&wakesta); |
| 298 | spm_clean_after_wakeup(); |
| 299 | last_wr = spm_output_wake_reason(&wakesta); |
| 300 | |
| 301 | return last_wr; |
| 302 | } |
| 303 | |
developer | e3ae6d0 | 2015-11-16 13:44:31 +0800 | [diff] [blame] | 304 | static void bigcore_pll_on(void) |
| 305 | { |
| 306 | mmio_setbits_32(ARMCA15PLL_PWR_CON0, ARMCA15PLL_PWR_ON); |
| 307 | mmio_clrbits_32(ARMCA15PLL_PWR_CON0, ARMCA15PLL_ISO_EN); |
| 308 | mmio_setbits_32(ARMCA15PLL_CON0, ARMCA15PLL_EN); |
| 309 | } |
| 310 | |
| 311 | static void bigcore_pll_off(void) |
| 312 | { |
| 313 | mmio_clrbits_32(ARMCA15PLL_CON0, ARMCA15PLL_EN); |
| 314 | mmio_setbits_32(ARMCA15PLL_PWR_CON0, ARMCA15PLL_ISO_EN); |
| 315 | mmio_clrbits_32(ARMCA15PLL_PWR_CON0, ARMCA15PLL_PWR_ON); |
| 316 | } |
| 317 | |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 318 | void spm_system_suspend(void) |
| 319 | { |
developer | e3ae6d0 | 2015-11-16 13:44:31 +0800 | [diff] [blame] | 320 | bigcore_pll_off(); |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 321 | spm_lock_get(); |
| 322 | go_to_sleep_before_wfi(spm_flags); |
| 323 | set_suspend_ready(); |
| 324 | spm_lock_release(); |
| 325 | } |
| 326 | |
| 327 | void spm_system_suspend_finish(void) |
| 328 | { |
| 329 | spm_lock_get(); |
| 330 | spm_wake_reason = go_to_sleep_after_wfi(); |
| 331 | INFO("spm_wake_reason=%d\n", spm_wake_reason); |
| 332 | clear_all_ready(); |
| 333 | spm_lock_release(); |
developer | e3ae6d0 | 2015-11-16 13:44:31 +0800 | [diff] [blame] | 334 | bigcore_pll_on(); |
| 335 | /* Add 20us delay for turning on PLL*/ |
| 336 | udelay(20); |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 337 | } |