blob: 36351da63fcc6c09702a622a8587335c36e2dec0 [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
Simon Glass1e94b462023-09-14 18:21:46 -060013#include <linux/printk.h>
Lokesh Vutla4fa23eb2019-06-07 19:25:57 +053014#define TISCI_INVALID_HOST 0xff
15
16/**
17 * struct ti_sci_proc - structure representing a processor control client
18 * @sci: cached TI-SCI protocol handle
19 * @ops: cached TI-SCI proc ops
20 * @proc_id: processor id for the consumer remoteproc device
21 * @host_id: host id to pass the control over for this consumer remoteproc
22 * device
Lokesh Vutlaf7954822019-09-04 16:01:32 +053023 * @dev_id: Device ID as identified by system controller.
Lokesh Vutla4fa23eb2019-06-07 19:25:57 +053024 */
25struct ti_sci_proc {
26 const struct ti_sci_handle *sci;
27 const struct ti_sci_proc_ops *ops;
28 u8 proc_id;
29 u8 host_id;
Lokesh Vutlaf7954822019-09-04 16:01:32 +053030 u16 dev_id;
Lokesh Vutla4fa23eb2019-06-07 19:25:57 +053031};
32
33static inline int ti_sci_proc_request(struct ti_sci_proc *tsp)
34{
35 int ret;
36
37 debug("%s: proc_id = %d\n", __func__, tsp->proc_id);
38
39 ret = tsp->ops->proc_request(tsp->sci, tsp->proc_id);
40 if (ret)
41 pr_err("ti-sci processor request failed: %d\n", ret);
42 return ret;
43}
44
45static inline int ti_sci_proc_release(struct ti_sci_proc *tsp)
46{
47 int ret;
48
49 debug("%s: proc_id = %d\n", __func__, tsp->proc_id);
50
51 if (tsp->host_id != TISCI_INVALID_HOST)
52 ret = tsp->ops->proc_handover(tsp->sci, tsp->proc_id,
53 tsp->host_id);
54 else
55 ret = tsp->ops->proc_release(tsp->sci, tsp->proc_id);
56
57 if (ret)
58 pr_err("ti-sci processor release failed: %d\n", ret);
59 return ret;
60}
61
62static inline int ti_sci_proc_handover(struct ti_sci_proc *tsp)
63{
64 int ret;
65
66 debug("%s: proc_id = %d\n", __func__, tsp->proc_id);
67
68 ret = tsp->ops->proc_handover(tsp->sci, tsp->proc_id, tsp->host_id);
69 if (ret)
70 pr_err("ti-sci processor handover of %d to %d failed: %d\n",
71 tsp->proc_id, tsp->host_id, ret);
72 return ret;
73}
74
75static inline int ti_sci_proc_get_status(struct ti_sci_proc *tsp,
76 u64 *boot_vector, u32 *cfg_flags,
77 u32 *ctrl_flags, u32 *status_flags)
78{
79 int ret;
80
81 ret = tsp->ops->get_proc_boot_status(tsp->sci, tsp->proc_id,
82 boot_vector, cfg_flags, ctrl_flags,
83 status_flags);
84 if (ret)
85 pr_err("ti-sci processor get_status failed: %d\n", ret);
86
87 debug("%s: proc_id = %d, boot_vector = 0x%llx, cfg_flags = 0x%x, ctrl_flags = 0x%x, sts = 0x%x\n",
88 __func__, tsp->proc_id, *boot_vector, *cfg_flags, *ctrl_flags,
89 *status_flags);
90 return ret;
91}
92
93static inline int ti_sci_proc_set_config(struct ti_sci_proc *tsp,
94 u64 boot_vector,
95 u32 cfg_set, u32 cfg_clr)
96{
97 int ret;
98
99 debug("%s: proc_id = %d, boot_vector = 0x%llx, cfg_set = 0x%x, cfg_clr = 0x%x\n",
100 __func__, tsp->proc_id, boot_vector, cfg_set, cfg_clr);
101
102 ret = tsp->ops->set_proc_boot_cfg(tsp->sci, tsp->proc_id, boot_vector,
103 cfg_set, cfg_clr);
104 if (ret)
105 pr_err("ti-sci processor set_config failed: %d\n", ret);
106 return ret;
107}
108
109static inline int ti_sci_proc_set_control(struct ti_sci_proc *tsp,
110 u32 ctrl_set, u32 ctrl_clr)
111{
112 int ret;
113
114 debug("%s: proc_id = %d, ctrl_set = 0x%x, ctrl_clr = 0x%x\n", __func__,
115 tsp->proc_id, ctrl_set, ctrl_clr);
116
117 ret = tsp->ops->set_proc_boot_ctrl(tsp->sci, tsp->proc_id, ctrl_set,
118 ctrl_clr);
119 if (ret)
120 pr_err("ti-sci processor set_control failed: %d\n", ret);
121 return ret;
122}
123
Lokesh Vutlaf7954822019-09-04 16:01:32 +0530124static inline int ti_sci_proc_power_domain_on(struct ti_sci_proc *tsp)
125{
126 int ret;
127
128 debug("%s: dev_id = %d\n", __func__, tsp->dev_id);
129
130 ret = tsp->sci->ops.dev_ops.get_device_exclusive(tsp->sci, tsp->dev_id);
131 if (ret)
132 pr_err("Power-domain on failed for dev = %d\n", tsp->dev_id);
133
134 return ret;
135}
136
137static inline int ti_sci_proc_power_domain_off(struct ti_sci_proc *tsp)
138{
139 int ret;
140
141 debug("%s: dev_id = %d\n", __func__, tsp->dev_id);
142
143 ret = tsp->sci->ops.dev_ops.put_device(tsp->sci, tsp->dev_id);
144 if (ret)
145 pr_err("Power-domain off failed for dev = %d\n", tsp->dev_id);
146
147 return ret;
148}
Lokesh Vutla4fa23eb2019-06-07 19:25:57 +0530149#endif /* REMOTEPROC_TI_SCI_PROC_H */