Path: blob/main/sys/arm/qualcomm/qcom_cpu_kpssv2.c
39507 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2021 Adrian Chadd <[email protected]>4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8* 1. Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10* 2. Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in the12* documentation and/or other materials provided with the distribution.13*14* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND15* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE16* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE17* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE18* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL19* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS20* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)21* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT22* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY23* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF24* SUCH DAMAGE.25*/2627#include "opt_platform.h"2829#include <sys/param.h>30#include <sys/systm.h>31#include <sys/bus.h>32#include <sys/reboot.h>33#include <sys/smp.h>3435#include <vm/vm.h>3637#include <machine/cpu.h>38#include <machine/bus.h>39#include <machine/intr.h>40#include <machine/machdep.h>41#include <machine/platformvar.h>42#include <machine/smp.h>4344#include <dev/fdt/fdt_common.h>45#include <dev/ofw/openfirm.h>46#include <dev/ofw/ofw_cpu.h>4748#include <arm/qualcomm/qcom_cpu_kpssv2_reg.h>49#include <arm/qualcomm/qcom_cpu_kpssv2.h>5051#include "platform_if.h"5253/*54* Since DELAY() hangs this early, we need some way to55* delay things to settle.56*/57static inline void58loop_delay(int usec)59{60int lcount = usec * 100000;6162for (volatile int i = 0; i < lcount; i++)63;64}6566/*67* This is the KPSSv2 (eg IPQ4018) regulator path for CPU68* and shared L2 cache power-on.69*/70bool71qcom_cpu_kpssv2_regulator_start(u_int id, phandle_t node)72{73phandle_t acc_phandle, l2_phandle, saw_phandle;74bus_space_tag_t acc_tag, saw_tag;75bus_space_handle_t acc_handle, saw_handle;76bus_size_t acc_sz, saw_sz;77ssize_t sret;78int ret;79uint32_t reg_val;8081/*82* We don't need to power up CPU 0! This will power it83* down first and ... then everything hangs.84*/85if (id == 0)86return true;8788/*89* Walk the qcom,acc and next-level-cache entries to find their90* child phandles and thus regulators.91*92* The qcom,acc is a phandle to a node.93*94* The next-level-cache actually is a phandle through to a qcom,saw95* entry.96*/97sret = OF_getencprop(node, "qcom,acc", (void *) &acc_phandle,98sizeof(acc_phandle));99if (sret != sizeof(acc_phandle))100panic("***couldn't get phandle for qcom,acc");101acc_phandle = OF_node_from_xref(acc_phandle);102103sret = OF_getencprop(node, "next-level-cache", (void *) &l2_phandle,104sizeof(l2_phandle));105if (sret != sizeof(l2_phandle))106panic("***couldn't get phandle for next-level-cache");107l2_phandle = OF_node_from_xref(l2_phandle);108109sret = OF_getencprop(l2_phandle, "qcom,saw", (void *) &saw_phandle,110sizeof(saw_phandle));111if (sret != sizeof(saw_phandle))112panic("***couldn't get phandle for qcom,saw");113l2_phandle = OF_node_from_xref(l2_phandle);114115/*116* Now that we have the phandles referencing the correct locations,117* do some KVA mappings so we can go access the registers.118*/119ret = OF_decode_addr(acc_phandle, 0, &acc_tag, &acc_handle, &acc_sz);120if (ret != 0)121panic("*** couldn't map qcom,acc space (%d)", ret);122ret = OF_decode_addr(saw_phandle, 0, &saw_tag, &saw_handle, &saw_sz);123if (ret != 0)124panic("*** couldn't map next-level-cache -> "125"qcom,saw space (%d)", ret);126127/*128* Power sequencing to ensure the cores are off, then power them on129* and bring them out of reset.130*/131132/*133* BHS: off134* LDO: bypassed, powered off135*/136reg_val = (64 << QCOM_APC_PWR_GATE_CTL_BHS_CNT_SHIFT)137| (0x3f << QCOM_APC_PWR_GATE_CTL_LDO_PWR_DWN_SHIFT)138| QCOM_APC_PWR_GATE_CTL_BHS_EN;139bus_space_write_4(acc_tag, acc_handle, QCOM_APC_PWR_GATE_CTL, reg_val);140mb();141/* Settle time */142loop_delay(1);143144/*145* Start up BHS segments.146*/147reg_val |= 0x3f << QCOM_APC_PWR_GATE_CTL_BHS_SEG_SHIFT;148bus_space_write_4(acc_tag, acc_handle, QCOM_APC_PWR_GATE_CTL, reg_val);149mb();150/* Settle time */151loop_delay(1);152153/*154* Switch on the LDO bypass; BHS will now supply power.155*/156reg_val |= 0x3f << QCOM_APC_PWR_GATE_CTL_LDO_BYP_SHIFT;157bus_space_write_4(acc_tag, acc_handle, QCOM_APC_PWR_GATE_CTL, reg_val);158159/*160* Shared L2 regulator control.161*/162bus_space_write_4(saw_tag, saw_handle, QCOM_APCS_SAW2_2_VCTL, 0x10003);163mb();164/* Settle time */165loop_delay(50);166167/*168* Put the core in reset.169*/170reg_val = QCOM_APCS_CPU_PWR_CTL_COREPOR_RST171| QCOM_APCS_CPU_PWR_CTL_CLAMP;172bus_space_write_4(acc_tag, acc_handle, QCOM_APCS_CPU_PWR_CTL, reg_val);173mb();174loop_delay(2);175176/*177* Remove power-down clamp.178*/179reg_val &= ~QCOM_APCS_CPU_PWR_CTL_CLAMP;180bus_space_write_4(acc_tag, acc_handle, QCOM_APCS_CPU_PWR_CTL, reg_val);181mb();182loop_delay(2);183184/*185* Clear core power reset.186*/187reg_val &= ~QCOM_APCS_CPU_PWR_CTL_COREPOR_RST;188bus_space_write_4(acc_tag, acc_handle, QCOM_APCS_CPU_PWR_CTL, reg_val);189mb();190191/*192* The power is ready, the core is out of reset, signal the core193* to power up.194*/195reg_val |= QCOM_APCS_CPU_PWR_CTL_CORE_PWRD_UP;196bus_space_write_4(acc_tag, acc_handle, QCOM_APCS_CPU_PWR_CTL, reg_val);197mb();198199/*200* Finished with these KVA mappings, so release them.201*/202bus_space_unmap(acc_tag, acc_handle, acc_sz);203bus_space_unmap(saw_tag, saw_handle, saw_sz);204205return true;206}207208209