]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/staging/fsl-mc/bus/dpcon.c
iio: imu: inv_mpu6050: test whoami first and against all known values
[mirror_ubuntu-artful-kernel.git] / drivers / staging / fsl-mc / bus / dpcon.c
1 /* Copyright 2013-2016 Freescale Semiconductor Inc.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are met:
5 * * Redistributions of source code must retain the above copyright
6 * notice, this list of conditions and the following disclaimer.
7 * * Redistributions in binary form must reproduce the above copyright
8 * notice, this list of conditions and the following disclaimer in the
9 * documentation and/or other materials provided with the distribution.
10 * * Neither the name of the above-listed copyright holders nor the
11 * names of any contributors may be used to endorse or promote products
12 * derived from this software without specific prior written permission.
13 *
14 *
15 * ALTERNATIVELY, this software may be distributed under the terms of the
16 * GNU General Public License ("GPL") as published by the Free Software
17 * Foundation, either version 2 of that License or (at your option) any
18 * later version.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32 #include "../include/mc-sys.h"
33 #include "../include/mc-cmd.h"
34 #include "../include/dpcon.h"
35
36 #include "dpcon-cmd.h"
37
38 /**
39 * dpcon_open() - Open a control session for the specified object
40 * @mc_io: Pointer to MC portal's I/O object
41 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
42 * @dpcon_id: DPCON unique ID
43 * @token: Returned token; use in subsequent API calls
44 *
45 * This function can be used to open a control session for an
46 * already created object; an object may have been declared in
47 * the DPL or by calling the dpcon_create() function.
48 * This function returns a unique authentication token,
49 * associated with the specific object ID and the specific MC
50 * portal; this token must be used in all subsequent commands for
51 * this specific object.
52 *
53 * Return: '0' on Success; Error code otherwise.
54 */
55 int dpcon_open(struct fsl_mc_io *mc_io,
56 u32 cmd_flags,
57 int dpcon_id,
58 u16 *token)
59 {
60 struct mc_command cmd = { 0 };
61 struct dpcon_cmd_open *dpcon_cmd;
62 int err;
63
64 /* prepare command */
65 cmd.header = mc_encode_cmd_header(DPCON_CMDID_OPEN,
66 cmd_flags,
67 0);
68 dpcon_cmd = (struct dpcon_cmd_open *)cmd.params;
69 dpcon_cmd->dpcon_id = cpu_to_le32(dpcon_id);
70
71 /* send command to mc*/
72 err = mc_send_command(mc_io, &cmd);
73 if (err)
74 return err;
75
76 /* retrieve response parameters */
77 *token = mc_cmd_hdr_read_token(&cmd);
78
79 return 0;
80 }
81 EXPORT_SYMBOL(dpcon_open);
82
83 /**
84 * dpcon_close() - Close the control session of the object
85 * @mc_io: Pointer to MC portal's I/O object
86 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
87 * @token: Token of DPCON object
88 *
89 * After this function is called, no further operations are
90 * allowed on the object without opening a new control session.
91 *
92 * Return: '0' on Success; Error code otherwise.
93 */
94 int dpcon_close(struct fsl_mc_io *mc_io,
95 u32 cmd_flags,
96 u16 token)
97 {
98 struct mc_command cmd = { 0 };
99
100 /* prepare command */
101 cmd.header = mc_encode_cmd_header(DPCON_CMDID_CLOSE,
102 cmd_flags,
103 token);
104
105 /* send command to mc*/
106 return mc_send_command(mc_io, &cmd);
107 }
108 EXPORT_SYMBOL(dpcon_close);
109
110 /**
111 * dpcon_enable() - Enable the DPCON
112 * @mc_io: Pointer to MC portal's I/O object
113 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
114 * @token: Token of DPCON object
115 *
116 * Return: '0' on Success; Error code otherwise
117 */
118 int dpcon_enable(struct fsl_mc_io *mc_io,
119 u32 cmd_flags,
120 u16 token)
121 {
122 struct mc_command cmd = { 0 };
123
124 /* prepare command */
125 cmd.header = mc_encode_cmd_header(DPCON_CMDID_ENABLE,
126 cmd_flags,
127 token);
128
129 /* send command to mc*/
130 return mc_send_command(mc_io, &cmd);
131 }
132 EXPORT_SYMBOL(dpcon_enable);
133
134 /**
135 * dpcon_disable() - Disable the DPCON
136 * @mc_io: Pointer to MC portal's I/O object
137 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
138 * @token: Token of DPCON object
139 *
140 * Return: '0' on Success; Error code otherwise
141 */
142 int dpcon_disable(struct fsl_mc_io *mc_io,
143 u32 cmd_flags,
144 u16 token)
145 {
146 struct mc_command cmd = { 0 };
147
148 /* prepare command */
149 cmd.header = mc_encode_cmd_header(DPCON_CMDID_DISABLE,
150 cmd_flags,
151 token);
152
153 /* send command to mc*/
154 return mc_send_command(mc_io, &cmd);
155 }
156 EXPORT_SYMBOL(dpcon_disable);
157
158 /**
159 * dpcon_is_enabled() - Check if the DPCON is enabled.
160 * @mc_io: Pointer to MC portal's I/O object
161 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
162 * @token: Token of DPCON object
163 * @en: Returns '1' if object is enabled; '0' otherwise
164 *
165 * Return: '0' on Success; Error code otherwise.
166 */
167 int dpcon_is_enabled(struct fsl_mc_io *mc_io,
168 u32 cmd_flags,
169 u16 token,
170 int *en)
171 {
172 struct mc_command cmd = { 0 };
173 struct dpcon_rsp_is_enabled *dpcon_rsp;
174 int err;
175
176 /* prepare command */
177 cmd.header = mc_encode_cmd_header(DPCON_CMDID_IS_ENABLED,
178 cmd_flags,
179 token);
180
181 /* send command to mc*/
182 err = mc_send_command(mc_io, &cmd);
183 if (err)
184 return err;
185
186 /* retrieve response parameters */
187 dpcon_rsp = (struct dpcon_rsp_is_enabled *)cmd.params;
188 *en = dpcon_rsp->enabled & DPCON_ENABLE;
189
190 return 0;
191 }
192 EXPORT_SYMBOL(dpcon_is_enabled);
193
194 /**
195 * dpcon_reset() - Reset the DPCON, returns the object to initial state.
196 * @mc_io: Pointer to MC portal's I/O object
197 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
198 * @token: Token of DPCON object
199 *
200 * Return: '0' on Success; Error code otherwise.
201 */
202 int dpcon_reset(struct fsl_mc_io *mc_io,
203 u32 cmd_flags,
204 u16 token)
205 {
206 struct mc_command cmd = { 0 };
207
208 /* prepare command */
209 cmd.header = mc_encode_cmd_header(DPCON_CMDID_RESET,
210 cmd_flags, token);
211
212 /* send command to mc*/
213 return mc_send_command(mc_io, &cmd);
214 }
215 EXPORT_SYMBOL(dpcon_reset);
216
217 /**
218 * dpcon_get_attributes() - Retrieve DPCON attributes.
219 * @mc_io: Pointer to MC portal's I/O object
220 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
221 * @token: Token of DPCON object
222 * @attr: Object's attributes
223 *
224 * Return: '0' on Success; Error code otherwise.
225 */
226 int dpcon_get_attributes(struct fsl_mc_io *mc_io,
227 u32 cmd_flags,
228 u16 token,
229 struct dpcon_attr *attr)
230 {
231 struct mc_command cmd = { 0 };
232 struct dpcon_rsp_get_attr *dpcon_rsp;
233 int err;
234
235 /* prepare command */
236 cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_ATTR,
237 cmd_flags,
238 token);
239
240 /* send command to mc*/
241 err = mc_send_command(mc_io, &cmd);
242 if (err)
243 return err;
244
245 /* retrieve response parameters */
246 dpcon_rsp = (struct dpcon_rsp_get_attr *)cmd.params;
247 attr->id = le32_to_cpu(dpcon_rsp->id);
248 attr->qbman_ch_id = le16_to_cpu(dpcon_rsp->qbman_ch_id);
249 attr->num_priorities = dpcon_rsp->num_priorities;
250
251 return 0;
252 }
253 EXPORT_SYMBOL(dpcon_get_attributes);
254
255 /**
256 * dpcon_set_notification() - Set DPCON notification destination
257 * @mc_io: Pointer to MC portal's I/O object
258 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
259 * @token: Token of DPCON object
260 * @cfg: Notification parameters
261 *
262 * Return: '0' on Success; Error code otherwise
263 */
264 int dpcon_set_notification(struct fsl_mc_io *mc_io,
265 u32 cmd_flags,
266 u16 token,
267 struct dpcon_notification_cfg *cfg)
268 {
269 struct mc_command cmd = { 0 };
270 struct dpcon_cmd_set_notification *dpcon_cmd;
271
272 /* prepare command */
273 cmd.header = mc_encode_cmd_header(DPCON_CMDID_SET_NOTIFICATION,
274 cmd_flags,
275 token);
276 dpcon_cmd = (struct dpcon_cmd_set_notification *)cmd.params;
277 dpcon_cmd->dpio_id = cpu_to_le32(cfg->dpio_id);
278 dpcon_cmd->priority = cfg->priority;
279 dpcon_cmd->user_ctx = cpu_to_le64(cfg->user_ctx);
280
281 /* send command to mc*/
282 return mc_send_command(mc_io, &cmd);
283 }
284 EXPORT_SYMBOL(dpcon_set_notification);
285
286 /**
287 * dpcon_get_api_version - Get Data Path Concentrator API version
288 * @mc_io: Pointer to MC portal's DPCON object
289 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
290 * @major_ver: Major version of DPCON API
291 * @minor_ver: Minor version of DPCON API
292 *
293 * Return: '0' on Success; Error code otherwise
294 */
295 int dpcon_get_api_version(struct fsl_mc_io *mc_io,
296 u32 cmd_flags,
297 u16 *major_ver,
298 u16 *minor_ver)
299 {
300 struct mc_command cmd = { 0 };
301 int err;
302
303 /* prepare command */
304 cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_API_VERSION,
305 cmd_flags, 0);
306
307 /* send command to mc */
308 err = mc_send_command(mc_io, &cmd);
309 if (err)
310 return err;
311
312 /* retrieve response parameters */
313 mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
314
315 return 0;
316 }
317 EXPORT_SYMBOL(dpcon_get_api_version);