blob: f8299d1aff92f2c297ddee19b49d2919e2f5adf6 [file] [log] [blame]
Lokesh Vutla4fa23eb2019-06-07 19:25:57 +05301/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Texas Instruments TI-SCI Processor Controller Helper Functions
4 *
5 * Copyright (C) 2018-2019 Texas Instruments Incorporated - http://www.ti.com/
6 * Lokesh Vutla <lokeshvutla@ti.com>
7 * Suman Anna <s-anna@ti.com>
8 */
9
10#ifndef REMOTEPROC_TI_SCI_PROC_H
11#define REMOTEPROC_TI_SCI_PROC_H
12
13#define TISCI_INVALID_HOST 0xff
14
15/**
16 * struct ti_sci_proc - structure representing a processor control client
17 * @sci: cached TI-SCI protocol handle
18 * @ops: cached TI-SCI proc ops
19 * @proc_id: processor id for the consumer remoteproc device
20 * @host_id: host id to pass the control over for this consumer remoteproc
21 * device
Lokesh Vutlaf7954822019-09-04 16:01:32 +053022 * @dev_id: Device ID as identified by system controller.
Lokesh Vutla4fa23eb2019-06-07 19:25:57 +053023 */
24struct ti_sci_proc {
25 const struct ti_sci_handle *sci;
26 const struct ti_sci_proc_ops *ops;
27 u8 proc_id;
28 u8 host_id;
Lokesh Vutlaf7954822019-09-04 16:01:32 +053029 u16 dev_id;
Lokesh Vutla4fa23eb2019-06-07 19:25:57 +053030};
31
32static inline int ti_sci_proc_request(struct ti_sci_proc *tsp)
33{
34 int ret;
35
36 debug("%s: proc_id = %d\n", __func__, tsp->proc_id);
37
38 ret = tsp->ops->proc_request(tsp->sci, tsp->proc_id);
39 if (ret)
40 pr_err("ti-sci processor request failed: %d\n", ret);
41 return ret;
42}
43
44static inline int ti_sci_proc_release(struct ti_sci_proc *tsp)
45{
46 int ret;
47
48 debug("%s: proc_id = %d\n", __func__, tsp->proc_id);
49
50 if (tsp->host_id != TISCI_INVALID_HOST)
51 ret = tsp->ops->proc_handover(tsp->sci, tsp->proc_id,
52 tsp->host_id);
53 else
54 ret = tsp->ops->proc_release(tsp->sci, tsp->proc_id);
55
56 if (ret)
57 pr_err("ti-sci processor release failed: %d\n", ret);
58 return ret;
59}
60
61static inline int ti_sci_proc_handover(struct ti_sci_proc *tsp)
62{
63 int ret;
64
65 debug("%s: proc_id = %d\n", __func__, tsp->proc_id);
66
67 ret = tsp->ops->proc_handover(tsp->sci, tsp->proc_id, tsp->host_id);
68 if (ret)
69 pr_err("ti-sci processor handover of %d to %d failed: %d\n",
70 tsp->proc_id, tsp->host_id, ret);
71 return ret;
72}
73
74static inline int ti_sci_proc_get_status(struct ti_sci_proc *tsp,
75 u64 *boot_vector, u32 *cfg_flags,
76 u32 *ctrl_flags, u32 *status_flags)
77{
78 int ret;
79
80 ret = tsp->ops->get_proc_boot_status(tsp->sci, tsp->proc_id,
81 boot_vector, cfg_flags, ctrl_flags,
82 status_flags);
83 if (ret)
84 pr_err("ti-sci processor get_status failed: %d\n", ret);
85
86 debug("%s: proc_id = %d, boot_vector = 0x%llx, cfg_flags = 0x%x, ctrl_flags = 0x%x, sts = 0x%x\n",
87 __func__, tsp->proc_id, *boot_vector, *cfg_flags, *ctrl_flags,
88 *status_flags);
89 return ret;
90}
91
92static inline int ti_sci_proc_set_config(struct ti_sci_proc *tsp,
93 u64 boot_vector,
94 u32 cfg_set, u32 cfg_clr)
95{
96 int ret;
97
98 debug("%s: proc_id = %d, boot_vector = 0x%llx, cfg_set = 0x%x, cfg_clr = 0x%x\n",
99 __func__, tsp->proc_id, boot_vector, cfg_set, cfg_clr);
100
101 ret = tsp->ops->set_proc_boot_cfg(tsp->sci, tsp->proc_id, boot_vector,
102 cfg_set, cfg_clr);
103 if (ret)
104 pr_err("ti-sci processor set_config failed: %d\n", ret);
105 return ret;
106}
107
108static inline int ti_sci_proc_set_control(struct ti_sci_proc *tsp,
109 u32 ctrl_set, u32 ctrl_clr)
110{
111 int ret;
112
113 debug("%s: proc_id = %d, ctrl_set = 0x%x, ctrl_clr = 0x%x\n", __func__,
114 tsp->proc_id, ctrl_set, ctrl_clr);
115
116 ret = tsp->ops->set_proc_boot_ctrl(tsp->sci, tsp->proc_id, ctrl_set,
117 ctrl_clr);
118 if (ret)
119 pr_err("ti-sci processor set_control failed: %d\n", ret);
120 return ret;
121}
122
Lokesh Vutlaf7954822019-09-04 16:01:32 +0530123static inline int ti_sci_proc_power_domain_on(struct ti_sci_proc *tsp)
124{
125 int ret;
126
127 debug("%s: dev_id = %d\n", __func__, tsp->dev_id);
128
129 ret = tsp->sci->ops.dev_ops.get_device_exclusive(tsp->sci, tsp->dev_id);
130 if (ret)
131 pr_err("Power-domain on failed for dev = %d\n", tsp->dev_id);
132
133 return ret;
134}
135
136static inline int ti_sci_proc_power_domain_off(struct ti_sci_proc *tsp)
137{
138 int ret;
139
140 debug("%s: dev_id = %d\n", __func__, tsp->dev_id);
141
142 ret = tsp->sci->ops.dev_ops.put_device(tsp->sci, tsp->dev_id);
143 if (ret)
144 pr_err("Power-domain off failed for dev = %d\n", tsp->dev_id);
145
146 return ret;
147}
Lokesh Vutla4fa23eb2019-06-07 19:25:57 +0530148#endif /* REMOTEPROC_TI_SCI_PROC_H */