1*977001aaSXing Zheng /* 2*977001aaSXing Zheng * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved. 3*977001aaSXing Zheng * 4*977001aaSXing Zheng * Redistribution and use in source and binary forms, with or without 5*977001aaSXing Zheng * modification, are permitted provided that the following conditions are met: 6*977001aaSXing Zheng * 7*977001aaSXing Zheng * Redistributions of source code must retain the above copyright notice, this 8*977001aaSXing Zheng * list of conditions and the following disclaimer. 9*977001aaSXing Zheng * 10*977001aaSXing Zheng * Redistributions in binary form must reproduce the above copyright notice, 11*977001aaSXing Zheng * this list of conditions and the following disclaimer in the documentation 12*977001aaSXing Zheng * and/or other materials provided with the distribution. 13*977001aaSXing Zheng * 14*977001aaSXing Zheng * Neither the name of ARM nor the names of its contributors may be used 15*977001aaSXing Zheng * to endorse or promote products derived from this software without specific 16*977001aaSXing Zheng * prior written permission. 17*977001aaSXing Zheng * 18*977001aaSXing Zheng * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19*977001aaSXing Zheng * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20*977001aaSXing Zheng * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21*977001aaSXing Zheng * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22*977001aaSXing Zheng * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23*977001aaSXing Zheng * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24*977001aaSXing Zheng * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25*977001aaSXing Zheng * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26*977001aaSXing Zheng * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27*977001aaSXing Zheng * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28*977001aaSXing Zheng * POSSIBILITY OF SUCH DAMAGE. 29*977001aaSXing Zheng */ 30*977001aaSXing Zheng 31*977001aaSXing Zheng #include <arch_helpers.h> 32*977001aaSXing Zheng #include <assert.h> 33*977001aaSXing Zheng #include <debug.h> 34*977001aaSXing Zheng #include <mmio.h> 35*977001aaSXing Zheng #include <m0_ctl.h> 36*977001aaSXing Zheng #include <plat_private.h> 37*977001aaSXing Zheng #include <rk3399_def.h> 38*977001aaSXing Zheng #include <soc.h> 39*977001aaSXing Zheng 40*977001aaSXing Zheng void m0_init(void) 41*977001aaSXing Zheng { 42*977001aaSXing Zheng /* secure config for M0 */ 43*977001aaSXing Zheng mmio_write_32(SGRF_BASE + SGRF_PMU_CON(0), WMSK_BIT(7)); 44*977001aaSXing Zheng mmio_write_32(SGRF_BASE + SGRF_SOC_CON6, WMSK_BIT(12)); 45*977001aaSXing Zheng 46*977001aaSXing Zheng /* set the execute address for M0 */ 47*977001aaSXing Zheng mmio_write_32(SGRF_BASE + SGRF_PMU_CON(3), 48*977001aaSXing Zheng BITS_WITH_WMASK((M0_BINCODE_BASE >> 12) & 0xffff, 49*977001aaSXing Zheng 0xffff, 0)); 50*977001aaSXing Zheng mmio_write_32(SGRF_BASE + SGRF_PMU_CON(7), 51*977001aaSXing Zheng BITS_WITH_WMASK((M0_BINCODE_BASE >> 28) & 0xf, 52*977001aaSXing Zheng 0xf, 0)); 53*977001aaSXing Zheng 54*977001aaSXing Zheng /* gating disable for M0 */ 55*977001aaSXing Zheng mmio_write_32(PMUCRU_BASE + PMUCRU_GATEDIS_CON0, BIT_WITH_WMSK(1)); 56*977001aaSXing Zheng 57*977001aaSXing Zheng /* 58*977001aaSXing Zheng * To switch the parent to xin24M and div == 1, 59*977001aaSXing Zheng * 60*977001aaSXing Zheng * We need to close most of the PLLs and clocks except the OSC 24MHz 61*977001aaSXing Zheng * durning suspend, and this should be enough to supplies the ddrfreq, 62*977001aaSXing Zheng * For the simple handle, we just keep the fixed 24MHz to supply the 63*977001aaSXing Zheng * suspend and ddrfreq directly. 64*977001aaSXing Zheng */ 65*977001aaSXing Zheng mmio_write_32(PMUCRU_BASE + PMUCRU_CLKSEL_CON0, 66*977001aaSXing Zheng BIT_WITH_WMSK(15) | BITS_WITH_WMASK(0x0, 0x1f, 8)); 67*977001aaSXing Zheng } 68*977001aaSXing Zheng 69*977001aaSXing Zheng void m0_start(void) 70*977001aaSXing Zheng { 71*977001aaSXing Zheng /* clean the PARAM_M0_DONE flag, mean that M0 will start working */ 72*977001aaSXing Zheng mmio_write_32(M0_PARAM_ADDR + PARAM_M0_DONE, 0); 73*977001aaSXing Zheng 74*977001aaSXing Zheng /* enable clocks for M0 */ 75*977001aaSXing Zheng mmio_write_32(PMUCRU_BASE + PMUCRU_CLKGATE_CON2, 76*977001aaSXing Zheng BITS_WITH_WMASK(0x0, 0x2f, 0)); 77*977001aaSXing Zheng 78*977001aaSXing Zheng /* start M0 */ 79*977001aaSXing Zheng mmio_write_32(PMUCRU_BASE + PMUCRU_SOFTRST_CON0, 80*977001aaSXing Zheng BITS_WITH_WMASK(0x0, 0x24, 0)); 81*977001aaSXing Zheng } 82*977001aaSXing Zheng 83*977001aaSXing Zheng void m0_stop(void) 84*977001aaSXing Zheng { 85*977001aaSXing Zheng /* stop M0 */ 86*977001aaSXing Zheng mmio_write_32(PMUCRU_BASE + PMUCRU_SOFTRST_CON0, 87*977001aaSXing Zheng BITS_WITH_WMASK(0x24, 0x24, 0)); 88*977001aaSXing Zheng 89*977001aaSXing Zheng /* disable clocks for M0 */ 90*977001aaSXing Zheng mmio_write_32(PMUCRU_BASE + PMUCRU_CLKGATE_CON2, 91*977001aaSXing Zheng BITS_WITH_WMASK(0x2f, 0x2f, 0)); 92*977001aaSXing Zheng } 93*977001aaSXing Zheng 94*977001aaSXing Zheng void m0_wait_done(void) 95*977001aaSXing Zheng { 96*977001aaSXing Zheng while (mmio_read_32(M0_PARAM_ADDR + PARAM_M0_DONE) != M0_DONE_FLAG) 97*977001aaSXing Zheng dsb(); 98*977001aaSXing Zheng } 99