1*91f16700Schasinglulu /* 2*91f16700Schasinglulu * Copyright (c) 2017-2020, Broadcom 3*91f16700Schasinglulu * 4*91f16700Schasinglulu * SPDX-License-Identifier: BSD-3-Clause 5*91f16700Schasinglulu */ 6*91f16700Schasinglulu 7*91f16700Schasinglulu #include <arch_helpers.h> 8*91f16700Schasinglulu #include <common/bl_common.h> 9*91f16700Schasinglulu #include <drivers/delay_timer.h> 10*91f16700Schasinglulu 11*91f16700Schasinglulu #include <platform_def.h> 12*91f16700Schasinglulu #include <scp.h> 13*91f16700Schasinglulu #include <scp_cmd.h> 14*91f16700Schasinglulu 15*91f16700Schasinglulu #include "m0_ipc.h" 16*91f16700Schasinglulu 17*91f16700Schasinglulu /* 18*91f16700Schasinglulu * Reads a response from CRMU MAILBOX 19*91f16700Schasinglulu * Assumes that access has been granted and locked. 20*91f16700Schasinglulu * Note that this is just a temporary implementation until 21*91f16700Schasinglulu * channels are introduced 22*91f16700Schasinglulu */ 23*91f16700Schasinglulu static void scp_read_response(crmu_response_t *resp) 24*91f16700Schasinglulu { 25*91f16700Schasinglulu uint32_t code; 26*91f16700Schasinglulu 27*91f16700Schasinglulu code = mmio_read_32(CRMU_MAIL_BOX0); 28*91f16700Schasinglulu resp->completed = code & MCU_IPC_CMD_DONE_MASK; 29*91f16700Schasinglulu resp->cmd = code & SCP_CMD_MASK; 30*91f16700Schasinglulu resp->ret = (code & MCU_IPC_CMD_REPLY_MASK) >> MCU_IPC_CMD_REPLY_SHIFT; 31*91f16700Schasinglulu } 32*91f16700Schasinglulu 33*91f16700Schasinglulu /* 34*91f16700Schasinglulu * Send a command to SCP and wait for timeout us. 35*91f16700Schasinglulu * Return: 0 on success 36*91f16700Schasinglulu * -1 if there was no proper reply from SCP 37*91f16700Schasinglulu * >0 if there was a response from MCU, but 38*91f16700Schasinglulu * command completed with an error. 39*91f16700Schasinglulu */ 40*91f16700Schasinglulu int scp_send_cmd(uint32_t cmd, uint32_t param, uint32_t timeout) 41*91f16700Schasinglulu { 42*91f16700Schasinglulu int ret = -1; 43*91f16700Schasinglulu 44*91f16700Schasinglulu mmio_write_32(CRMU_MAIL_BOX0, cmd); 45*91f16700Schasinglulu mmio_write_32(CRMU_MAIL_BOX1, param); 46*91f16700Schasinglulu do { 47*91f16700Schasinglulu crmu_response_t scp_resp; 48*91f16700Schasinglulu 49*91f16700Schasinglulu udelay(1); 50*91f16700Schasinglulu scp_read_response(&scp_resp); 51*91f16700Schasinglulu if (scp_resp.completed && 52*91f16700Schasinglulu (scp_resp.cmd == cmd)) { 53*91f16700Schasinglulu /* This command has completed */ 54*91f16700Schasinglulu ret = scp_resp.ret; 55*91f16700Schasinglulu break; 56*91f16700Schasinglulu } 57*91f16700Schasinglulu } while (--timeout); 58*91f16700Schasinglulu 59*91f16700Schasinglulu return ret; 60*91f16700Schasinglulu } 61