blob: a342aa89ea2b50b13f4cdaadae4cab92d23d5b12 [file] [log] [blame]
Soby Mathewea26bad2016-11-14 12:25:45 +00001/*
Ambroise Vincenta88a35d2019-02-14 09:48:21 +00002 * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
Soby Mathewea26bad2016-11-14 12:25:45 +00003 *
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>
Antonio Nino Diazc30db5b2019-01-23 20:37:32 +000011#include <drivers/arm/css/scmi.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000012
Soby Mathewea26bad2016-11-14 12:25:45 +000013#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;
Ambroise Vincenta88a35d2019-02-14 09:48:21 +000022 unsigned int token = 0;
23 int ret;
Soby Mathewea26bad2016-11-14 12:25:45 +000024
25 /*
26 * Only asynchronous mode of `set power state` command is allowed on
27 * application processors.
28 */
29 uint32_t pwr_state_set_msg_flag = SCMI_PWR_STATE_SET_FLAG_ASYNC;
30 scmi_channel_t *ch = (scmi_channel_t *)p;
31
32 validate_scmi_channel(ch);
33
34 scmi_get_channel(ch);
35
36 mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem);
37 mbx_mem->msg_header = SCMI_MSG_CREATE(SCMI_PWR_DMN_PROTO_ID,
38 SCMI_PWR_STATE_SET_MSG, token);
39 mbx_mem->len = SCMI_PWR_STATE_SET_MSG_LEN;
40 mbx_mem->flags = SCMI_FLAG_RESP_POLL;
41 SCMI_PAYLOAD_ARG3(mbx_mem->payload, pwr_state_set_msg_flag,
42 domain_id, scmi_pwr_state);
43
44 scmi_send_sync_command(ch);
45
46 /* Get the return values */
47 SCMI_PAYLOAD_RET_VAL1(mbx_mem->payload, ret);
48 assert(mbx_mem->len == SCMI_PWR_STATE_SET_RESP_LEN);
49 assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header));
50
51 scmi_put_channel(ch);
52
53 return ret;
54}
55
56/*
57 * API to get the SCMI power domain power state.
58 */
59int scmi_pwr_state_get(void *p, uint32_t domain_id,
60 uint32_t *scmi_pwr_state)
61{
62 mailbox_mem_t *mbx_mem;
Ambroise Vincenta88a35d2019-02-14 09:48:21 +000063 unsigned int token = 0;
64 int ret;
Soby Mathewea26bad2016-11-14 12:25:45 +000065 scmi_channel_t *ch = (scmi_channel_t *)p;
66
67 validate_scmi_channel(ch);
68
69 scmi_get_channel(ch);
70
71 mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem);
72 mbx_mem->msg_header = SCMI_MSG_CREATE(SCMI_PWR_DMN_PROTO_ID,
73 SCMI_PWR_STATE_GET_MSG, token);
74 mbx_mem->len = SCMI_PWR_STATE_GET_MSG_LEN;
75 mbx_mem->flags = SCMI_FLAG_RESP_POLL;
76 SCMI_PAYLOAD_ARG1(mbx_mem->payload, domain_id);
77
78 scmi_send_sync_command(ch);
79
80 /* Get the return values */
81 SCMI_PAYLOAD_RET_VAL2(mbx_mem->payload, ret, *scmi_pwr_state);
82 assert(mbx_mem->len == SCMI_PWR_STATE_GET_RESP_LEN);
83 assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header));
84
85 scmi_put_channel(ch);
86
87 return ret;
88}