blob: 778558abcdcc53cf02b503e2cce2146c464a9470 [file] [log] [blame]
Suman Annacf7acb42020-07-21 17:36:14 -05001/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Texas Instruments TI-SCI Processor Controller Helper Functions
4 *
5 * Copyright (C) 2018-2020 Texas Instruments Incorporated - https://www.ti.com/
6 * Suman Anna <s-anna@ti.com>
7 */
8
9#ifndef REMOTEPROC_TI_SCI_PROC_H
10#define REMOTEPROC_TI_SCI_PROC_H
11
12#include <linux/soc/ti/ti_sci_protocol.h>
13
14/**
15 * struct ti_sci_proc - structure representing a processor control client
16 * @sci: cached TI-SCI protocol handle
17 * @ops: cached TI-SCI proc ops
18 * @dev: cached client device pointer
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
22 */
23struct ti_sci_proc {
24 const struct ti_sci_handle *sci;
25 const struct ti_sci_proc_ops *ops;
26 struct device *dev;
27 u8 proc_id;
28 u8 host_id;
29};
30
31static inline int ti_sci_proc_request(struct ti_sci_proc *tsp)
32{
33 int ret;
34
35 ret = tsp->ops->request(tsp->sci, tsp->proc_id);
36 if (ret)
37 dev_err(tsp->dev, "ti-sci processor request failed: %d\n",
38 ret);
39 return ret;
40}
41
42static inline int ti_sci_proc_release(struct ti_sci_proc *tsp)
43{
44 int ret;
45
46 ret = tsp->ops->release(tsp->sci, tsp->proc_id);
47 if (ret)
48 dev_err(tsp->dev, "ti-sci processor release failed: %d\n",
49 ret);
50 return ret;
51}
52
53static inline int ti_sci_proc_handover(struct ti_sci_proc *tsp)
54{
55 int ret;
56
57 ret = tsp->ops->handover(tsp->sci, tsp->proc_id, tsp->host_id);
58 if (ret)
59 dev_err(tsp->dev, "ti-sci processor handover of %d to %d failed: %d\n",
60 tsp->proc_id, tsp->host_id, ret);
61 return ret;
62}
63
64static inline int ti_sci_proc_set_config(struct ti_sci_proc *tsp,
65 u64 boot_vector,
66 u32 cfg_set, u32 cfg_clr)
67{
68 int ret;
69
70 ret = tsp->ops->set_config(tsp->sci, tsp->proc_id, boot_vector,
71 cfg_set, cfg_clr);
72 if (ret)
73 dev_err(tsp->dev, "ti-sci processor set_config failed: %d\n",
74 ret);
75 return ret;
76}
77
78static inline int ti_sci_proc_set_control(struct ti_sci_proc *tsp,
79 u32 ctrl_set, u32 ctrl_clr)
80{
81 int ret;
82
83 ret = tsp->ops->set_control(tsp->sci, tsp->proc_id, ctrl_set, ctrl_clr);
84 if (ret)
85 dev_err(tsp->dev, "ti-sci processor set_control failed: %d\n",
86 ret);
87 return ret;
88}
89
90static inline int ti_sci_proc_get_status(struct ti_sci_proc *tsp,
91 u64 *boot_vector, u32 *cfg_flags,
92 u32 *ctrl_flags, u32 *status_flags)
93{
94 int ret;
95
96 ret = tsp->ops->get_status(tsp->sci, tsp->proc_id, boot_vector,
97 cfg_flags, ctrl_flags, status_flags);
98 if (ret)
99 dev_err(tsp->dev, "ti-sci processor get_status failed: %d\n",
100 ret);
101 return ret;
102}
103
104#endif /* REMOTEPROC_TI_SCI_PROC_H */