blob: f31562131445d8c5f8ab00684be9627cfc8ae5e1 [file] [log] [blame]
Soby Mathewea26bad2016-11-14 12:25:45 +00001/*
2 * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Soby Mathewea26bad2016-11-14 12:25:45 +00007#include <assert.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008
9#include <arch_helpers.h>
10#include <common/debug.h>
11
Soby Mathewea26bad2016-11-14 12:25:45 +000012#include "scmi.h"
13#include "scmi_private.h"
14
15/*
16 * API to set the SCMI power domain power state.
17 */
18int scmi_pwr_state_set(void *p, uint32_t domain_id,
19 uint32_t scmi_pwr_state)
20{
21 mailbox_mem_t *mbx_mem;
22 int token = 0, ret;
23
24 /*
25 * Only asynchronous mode of `set power state` command is allowed on
26 * application processors.
27 */
28 uint32_t pwr_state_set_msg_flag = SCMI_PWR_STATE_SET_FLAG_ASYNC;
29 scmi_channel_t *ch = (scmi_channel_t *)p;
30
31 validate_scmi_channel(ch);
32
33 scmi_get_channel(ch);
34
35 mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem);
36 mbx_mem->msg_header = SCMI_MSG_CREATE(SCMI_PWR_DMN_PROTO_ID,
37 SCMI_PWR_STATE_SET_MSG, token);
38 mbx_mem->len = SCMI_PWR_STATE_SET_MSG_LEN;
39 mbx_mem->flags = SCMI_FLAG_RESP_POLL;
40 SCMI_PAYLOAD_ARG3(mbx_mem->payload, pwr_state_set_msg_flag,
41 domain_id, scmi_pwr_state);
42
43 scmi_send_sync_command(ch);
44
45 /* Get the return values */
46 SCMI_PAYLOAD_RET_VAL1(mbx_mem->payload, ret);
47 assert(mbx_mem->len == SCMI_PWR_STATE_SET_RESP_LEN);
48 assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header));
49
50 scmi_put_channel(ch);
51
52 return ret;
53}
54
55/*
56 * API to get the SCMI power domain power state.
57 */
58int scmi_pwr_state_get(void *p, uint32_t domain_id,
59 uint32_t *scmi_pwr_state)
60{
61 mailbox_mem_t *mbx_mem;
62 int token = 0, ret;
63 scmi_channel_t *ch = (scmi_channel_t *)p;
64
65 validate_scmi_channel(ch);
66
67 scmi_get_channel(ch);
68
69 mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem);
70 mbx_mem->msg_header = SCMI_MSG_CREATE(SCMI_PWR_DMN_PROTO_ID,
71 SCMI_PWR_STATE_GET_MSG, token);
72 mbx_mem->len = SCMI_PWR_STATE_GET_MSG_LEN;
73 mbx_mem->flags = SCMI_FLAG_RESP_POLL;
74 SCMI_PAYLOAD_ARG1(mbx_mem->payload, domain_id);
75
76 scmi_send_sync_command(ch);
77
78 /* Get the return values */
79 SCMI_PAYLOAD_RET_VAL2(mbx_mem->payload, ret, *scmi_pwr_state);
80 assert(mbx_mem->len == SCMI_PWR_STATE_GET_RESP_LEN);
81 assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header));
82
83 scmi_put_channel(ch);
84
85 return ret;
86}