xref: /arm-trusted-firmware/plat/brcm/common/brcm_scpi.h (revision 91f16700b400a8c0651d24a598fc48ee2997a0d7)
1*91f16700Schasinglulu /*
2*91f16700Schasinglulu  * Copyright (c) 2019-2020, ARM Limited and Contributors. All rights reserved.
3*91f16700Schasinglulu  *
4*91f16700Schasinglulu  * SPDX-License-Identifier: BSD-3-Clause
5*91f16700Schasinglulu  */
6*91f16700Schasinglulu 
7*91f16700Schasinglulu #ifndef BRCM_SCPI_H
8*91f16700Schasinglulu #define BRCM_SCPI_H
9*91f16700Schasinglulu 
10*91f16700Schasinglulu #include <stddef.h>
11*91f16700Schasinglulu #include <stdint.h>
12*91f16700Schasinglulu 
13*91f16700Schasinglulu /*
14*91f16700Schasinglulu  * An SCPI command consists of a header and a payload.
15*91f16700Schasinglulu  * The following structure describes the header. It is 64-bit long.
16*91f16700Schasinglulu  */
17*91f16700Schasinglulu typedef struct {
18*91f16700Schasinglulu 	/* Command ID */
19*91f16700Schasinglulu 	uint32_t id		: 7;
20*91f16700Schasinglulu 	/* Set ID. Identifies whether this is a standard or extended command. */
21*91f16700Schasinglulu 	uint32_t set		: 1;
22*91f16700Schasinglulu 	/* Sender ID to match a reply. The value is sender specific. */
23*91f16700Schasinglulu 	uint32_t sender		: 8;
24*91f16700Schasinglulu 	/* Size of the payload in bytes (0 - 511) */
25*91f16700Schasinglulu 	uint32_t size		: 9;
26*91f16700Schasinglulu 	uint32_t reserved	: 7;
27*91f16700Schasinglulu 	/*
28*91f16700Schasinglulu 	 * Status indicating the success of a command.
29*91f16700Schasinglulu 	 * See the enum below.
30*91f16700Schasinglulu 	 */
31*91f16700Schasinglulu 	uint32_t status;
32*91f16700Schasinglulu } scpi_cmd_t;
33*91f16700Schasinglulu 
34*91f16700Schasinglulu typedef enum {
35*91f16700Schasinglulu 	SCPI_SET_NORMAL = 0,	/* Normal SCPI commands */
36*91f16700Schasinglulu 	SCPI_SET_EXTENDED	/* Extended SCPI commands */
37*91f16700Schasinglulu } scpi_set_t;
38*91f16700Schasinglulu 
39*91f16700Schasinglulu enum {
40*91f16700Schasinglulu 	SCP_OK = 0,	/* Success */
41*91f16700Schasinglulu 	SCP_E_PARAM,	/* Invalid parameter(s) */
42*91f16700Schasinglulu 	SCP_E_ALIGN,	/* Invalid alignment */
43*91f16700Schasinglulu 	SCP_E_SIZE,	/* Invalid size */
44*91f16700Schasinglulu 	SCP_E_HANDLER,	/* Invalid handler or callback */
45*91f16700Schasinglulu 	SCP_E_ACCESS,	/* Invalid access or permission denied */
46*91f16700Schasinglulu 	SCP_E_RANGE,	/* Value out of range */
47*91f16700Schasinglulu 	SCP_E_TIMEOUT,	/* Time out has ocurred */
48*91f16700Schasinglulu 	SCP_E_NOMEM,	/* Invalid memory area or pointer */
49*91f16700Schasinglulu 	SCP_E_PWRSTATE,	/* Invalid power state */
50*91f16700Schasinglulu 	SCP_E_SUPPORT,	/* Feature not supported or disabled */
51*91f16700Schasinglulu 	SCPI_E_DEVICE,	/* Device error */
52*91f16700Schasinglulu 	SCPI_E_BUSY,	/* Device is busy */
53*91f16700Schasinglulu };
54*91f16700Schasinglulu 
55*91f16700Schasinglulu typedef uint32_t scpi_status_t;
56*91f16700Schasinglulu typedef enum {
57*91f16700Schasinglulu 	SCPI_CMD_SCP_READY = 0x01,
58*91f16700Schasinglulu 	SCPI_CMD_SET_POWER_STATE = 0x03,
59*91f16700Schasinglulu 	SCPI_CMD_GET_POWER_STATE = 0x04,
60*91f16700Schasinglulu 	SCPI_CMD_SYS_POWER_STATE = 0x05
61*91f16700Schasinglulu } scpi_command_t;
62*91f16700Schasinglulu 
63*91f16700Schasinglulu /*
64*91f16700Schasinglulu  * Macros to parse SCP response to GET_POWER_STATE command
65*91f16700Schasinglulu  *
66*91f16700Schasinglulu  *   [3:0] : cluster ID
67*91f16700Schasinglulu  *   [7:4] : cluster state: 0 = on; 3 = off; rest are reserved
68*91f16700Schasinglulu  *   [15:8]: on/off state for individual CPUs in the cluster
69*91f16700Schasinglulu  *
70*91f16700Schasinglulu  * Payload is in little-endian
71*91f16700Schasinglulu  */
72*91f16700Schasinglulu #define CLUSTER_ID(_resp)		((_resp) & 0xf)
73*91f16700Schasinglulu #define CLUSTER_POWER_STATE(_resp)	(((_resp) >> 4) & 0xf)
74*91f16700Schasinglulu 
75*91f16700Schasinglulu /* Result is a bit mask of CPU on/off states in the cluster */
76*91f16700Schasinglulu #define CPU_POWER_STATE(_resp)		(((_resp) >> 8) & 0xff)
77*91f16700Schasinglulu 
78*91f16700Schasinglulu /*
79*91f16700Schasinglulu  * For GET_POWER_STATE, SCP returns the power states of every cluster. The
80*91f16700Schasinglulu  * size of response depends on the number of clusters in the system. The
81*91f16700Schasinglulu  * SCP-to-AP payload contains 2 bytes per cluster. Make sure the response is
82*91f16700Schasinglulu  * large enough to contain power states of a given cluster
83*91f16700Schasinglulu  */
84*91f16700Schasinglulu #define CHECK_RESPONSE(_resp, _clus)  (_resp.size >= (((_clus) + 1) * 2))
85*91f16700Schasinglulu 
86*91f16700Schasinglulu typedef enum {
87*91f16700Schasinglulu 	scpi_power_on = 0,
88*91f16700Schasinglulu 	scpi_power_retention = 1,
89*91f16700Schasinglulu 	scpi_power_off = 3,
90*91f16700Schasinglulu } scpi_power_state_t;
91*91f16700Schasinglulu 
92*91f16700Schasinglulu typedef enum {
93*91f16700Schasinglulu 	scpi_system_shutdown = 0,
94*91f16700Schasinglulu 	scpi_system_reboot = 1,
95*91f16700Schasinglulu 	scpi_system_reset = 2
96*91f16700Schasinglulu } scpi_system_state_t;
97*91f16700Schasinglulu 
98*91f16700Schasinglulu extern int scpi_wait_ready(void);
99*91f16700Schasinglulu extern void scpi_set_brcm_power_state(unsigned int mpidr,
100*91f16700Schasinglulu 				      scpi_power_state_t cpu_state,
101*91f16700Schasinglulu 				      scpi_power_state_t cluster_state,
102*91f16700Schasinglulu 				      scpi_power_state_t css_state);
103*91f16700Schasinglulu int scpi_get_brcm_power_state(unsigned int mpidr, unsigned int *cpu_state_p,
104*91f16700Schasinglulu 			      unsigned int *cluster_state_p);
105*91f16700Schasinglulu uint32_t scpi_sys_power_state(scpi_system_state_t system_state);
106*91f16700Schasinglulu 
107*91f16700Schasinglulu #endif	/* BRCM_SCPI_H */
108