Linux 4.18.10
[linux/fpc-iii.git] / drivers / bus / fsl-mc / dpbp.c
blob17e3c5d2f22ef3632df9d6af3ccb4fc32f3f4988
1 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
2 /*
3 * Copyright 2013-2016 Freescale Semiconductor Inc.
5 */
6 #include <linux/kernel.h>
7 #include <linux/fsl/mc.h>
8 #include <linux/fsl/mc.h>
10 #include "fsl-mc-private.h"
12 /**
13 * dpbp_open() - Open a control session for the specified object.
14 * @mc_io: Pointer to MC portal's I/O object
15 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
16 * @dpbp_id: DPBP unique ID
17 * @token: Returned token; use in subsequent API calls
19 * This function can be used to open a control session for an
20 * already created object; an object may have been declared in
21 * the DPL or by calling the dpbp_create function.
22 * This function returns a unique authentication token,
23 * associated with the specific object ID and the specific MC
24 * portal; this token must be used in all subsequent commands for
25 * this specific object
27 * Return: '0' on Success; Error code otherwise.
29 int dpbp_open(struct fsl_mc_io *mc_io,
30 u32 cmd_flags,
31 int dpbp_id,
32 u16 *token)
34 struct fsl_mc_command cmd = { 0 };
35 struct dpbp_cmd_open *cmd_params;
36 int err;
38 /* prepare command */
39 cmd.header = mc_encode_cmd_header(DPBP_CMDID_OPEN,
40 cmd_flags, 0);
41 cmd_params = (struct dpbp_cmd_open *)cmd.params;
42 cmd_params->dpbp_id = cpu_to_le32(dpbp_id);
44 /* send command to mc*/
45 err = mc_send_command(mc_io, &cmd);
46 if (err)
47 return err;
49 /* retrieve response parameters */
50 *token = mc_cmd_hdr_read_token(&cmd);
52 return err;
54 EXPORT_SYMBOL_GPL(dpbp_open);
56 /**
57 * dpbp_close() - Close the control session of the object
58 * @mc_io: Pointer to MC portal's I/O object
59 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
60 * @token: Token of DPBP object
62 * After this function is called, no further operations are
63 * allowed on the object without opening a new control session.
65 * Return: '0' on Success; Error code otherwise.
67 int dpbp_close(struct fsl_mc_io *mc_io,
68 u32 cmd_flags,
69 u16 token)
71 struct fsl_mc_command cmd = { 0 };
73 /* prepare command */
74 cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLOSE, cmd_flags,
75 token);
77 /* send command to mc*/
78 return mc_send_command(mc_io, &cmd);
80 EXPORT_SYMBOL_GPL(dpbp_close);
82 /**
83 * dpbp_enable() - Enable the DPBP.
84 * @mc_io: Pointer to MC portal's I/O object
85 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
86 * @token: Token of DPBP object
88 * Return: '0' on Success; Error code otherwise.
90 int dpbp_enable(struct fsl_mc_io *mc_io,
91 u32 cmd_flags,
92 u16 token)
94 struct fsl_mc_command cmd = { 0 };
96 /* prepare command */
97 cmd.header = mc_encode_cmd_header(DPBP_CMDID_ENABLE, cmd_flags,
98 token);
100 /* send command to mc*/
101 return mc_send_command(mc_io, &cmd);
103 EXPORT_SYMBOL_GPL(dpbp_enable);
106 * dpbp_disable() - Disable the DPBP.
107 * @mc_io: Pointer to MC portal's I/O object
108 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
109 * @token: Token of DPBP object
111 * Return: '0' on Success; Error code otherwise.
113 int dpbp_disable(struct fsl_mc_io *mc_io,
114 u32 cmd_flags,
115 u16 token)
117 struct fsl_mc_command cmd = { 0 };
119 /* prepare command */
120 cmd.header = mc_encode_cmd_header(DPBP_CMDID_DISABLE,
121 cmd_flags, token);
123 /* send command to mc*/
124 return mc_send_command(mc_io, &cmd);
126 EXPORT_SYMBOL_GPL(dpbp_disable);
129 * dpbp_reset() - Reset the DPBP, returns the object to initial state.
130 * @mc_io: Pointer to MC portal's I/O object
131 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
132 * @token: Token of DPBP object
134 * Return: '0' on Success; Error code otherwise.
136 int dpbp_reset(struct fsl_mc_io *mc_io,
137 u32 cmd_flags,
138 u16 token)
140 struct fsl_mc_command cmd = { 0 };
142 /* prepare command */
143 cmd.header = mc_encode_cmd_header(DPBP_CMDID_RESET,
144 cmd_flags, token);
146 /* send command to mc*/
147 return mc_send_command(mc_io, &cmd);
149 EXPORT_SYMBOL_GPL(dpbp_reset);
152 * dpbp_get_attributes - Retrieve DPBP attributes.
154 * @mc_io: Pointer to MC portal's I/O object
155 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
156 * @token: Token of DPBP object
157 * @attr: Returned object's attributes
159 * Return: '0' on Success; Error code otherwise.
161 int dpbp_get_attributes(struct fsl_mc_io *mc_io,
162 u32 cmd_flags,
163 u16 token,
164 struct dpbp_attr *attr)
166 struct fsl_mc_command cmd = { 0 };
167 struct dpbp_rsp_get_attributes *rsp_params;
168 int err;
170 /* prepare command */
171 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_ATTR,
172 cmd_flags, token);
174 /* send command to mc*/
175 err = mc_send_command(mc_io, &cmd);
176 if (err)
177 return err;
179 /* retrieve response parameters */
180 rsp_params = (struct dpbp_rsp_get_attributes *)cmd.params;
181 attr->bpid = le16_to_cpu(rsp_params->bpid);
182 attr->id = le32_to_cpu(rsp_params->id);
184 return 0;
186 EXPORT_SYMBOL_GPL(dpbp_get_attributes);