18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2016-2019, The Linux Foundation. All rights reserved.
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#ifndef __SOC_QCOM_TCS_H__
78c2ecf20Sopenharmony_ci#define __SOC_QCOM_TCS_H__
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#define MAX_RPMH_PAYLOAD	16
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci/**
128c2ecf20Sopenharmony_ci * rpmh_state: state for the request
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * RPMH_SLEEP_STATE:       State of the resource when the processor subsystem
158c2ecf20Sopenharmony_ci *                         is powered down. There is no client using the
168c2ecf20Sopenharmony_ci *                         resource actively.
178c2ecf20Sopenharmony_ci * RPMH_WAKE_ONLY_STATE:   Resume resource state to the value previously
188c2ecf20Sopenharmony_ci *                         requested before the processor was powered down.
198c2ecf20Sopenharmony_ci * RPMH_ACTIVE_ONLY_STATE: Active or AMC mode requests. Resource state
208c2ecf20Sopenharmony_ci *                         is aggregated immediately.
218c2ecf20Sopenharmony_ci */
228c2ecf20Sopenharmony_cienum rpmh_state {
238c2ecf20Sopenharmony_ci	RPMH_SLEEP_STATE,
248c2ecf20Sopenharmony_ci	RPMH_WAKE_ONLY_STATE,
258c2ecf20Sopenharmony_ci	RPMH_ACTIVE_ONLY_STATE,
268c2ecf20Sopenharmony_ci};
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci/**
298c2ecf20Sopenharmony_ci * struct tcs_cmd: an individual request to RPMH.
308c2ecf20Sopenharmony_ci *
318c2ecf20Sopenharmony_ci * @addr: the address of the resource slv_id:18:16 | offset:0:15
328c2ecf20Sopenharmony_ci * @data: the resource state request
338c2ecf20Sopenharmony_ci * @wait: wait for this request to be complete before sending the next
348c2ecf20Sopenharmony_ci */
358c2ecf20Sopenharmony_cistruct tcs_cmd {
368c2ecf20Sopenharmony_ci	u32 addr;
378c2ecf20Sopenharmony_ci	u32 data;
388c2ecf20Sopenharmony_ci	u32 wait;
398c2ecf20Sopenharmony_ci};
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci/**
428c2ecf20Sopenharmony_ci * struct tcs_request: A set of tcs_cmds sent together in a TCS
438c2ecf20Sopenharmony_ci *
448c2ecf20Sopenharmony_ci * @state:          state for the request.
458c2ecf20Sopenharmony_ci * @wait_for_compl: wait until we get a response from the h/w accelerator
468c2ecf20Sopenharmony_ci * @num_cmds:       the number of @cmds in this request
478c2ecf20Sopenharmony_ci * @cmds:           an array of tcs_cmds
488c2ecf20Sopenharmony_ci */
498c2ecf20Sopenharmony_cistruct tcs_request {
508c2ecf20Sopenharmony_ci	enum rpmh_state state;
518c2ecf20Sopenharmony_ci	u32 wait_for_compl;
528c2ecf20Sopenharmony_ci	u32 num_cmds;
538c2ecf20Sopenharmony_ci	struct tcs_cmd *cmds;
548c2ecf20Sopenharmony_ci};
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci#define BCM_TCS_CMD_COMMIT_SHFT		30
578c2ecf20Sopenharmony_ci#define BCM_TCS_CMD_COMMIT_MASK		0x40000000
588c2ecf20Sopenharmony_ci#define BCM_TCS_CMD_VALID_SHFT		29
598c2ecf20Sopenharmony_ci#define BCM_TCS_CMD_VALID_MASK		0x20000000
608c2ecf20Sopenharmony_ci#define BCM_TCS_CMD_VOTE_X_SHFT		14
618c2ecf20Sopenharmony_ci#define BCM_TCS_CMD_VOTE_MASK		0x3fff
628c2ecf20Sopenharmony_ci#define BCM_TCS_CMD_VOTE_Y_SHFT		0
638c2ecf20Sopenharmony_ci#define BCM_TCS_CMD_VOTE_Y_MASK		0xfffc000
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci/* Construct a Bus Clock Manager (BCM) specific TCS command */
668c2ecf20Sopenharmony_ci#define BCM_TCS_CMD(commit, valid, vote_x, vote_y)		\
678c2ecf20Sopenharmony_ci	(((commit) << BCM_TCS_CMD_COMMIT_SHFT) |		\
688c2ecf20Sopenharmony_ci	((valid) << BCM_TCS_CMD_VALID_SHFT) |			\
698c2ecf20Sopenharmony_ci	((cpu_to_le32(vote_x) &					\
708c2ecf20Sopenharmony_ci	BCM_TCS_CMD_VOTE_MASK) << BCM_TCS_CMD_VOTE_X_SHFT) |	\
718c2ecf20Sopenharmony_ci	((cpu_to_le32(vote_y) &					\
728c2ecf20Sopenharmony_ci	BCM_TCS_CMD_VOTE_MASK) << BCM_TCS_CMD_VOTE_Y_SHFT))
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci#endif /* __SOC_QCOM_TCS_H__ */
75