1 /* Copyright 2013-2014 Freescale Semiconductor Inc.
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.
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
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.
32 #include "../include/mc-sys.h"
33 #include "../include/mc-cmd.h"
34 #include "../include/dpbp.h"
35 #include "../include/dpbp-cmd.h"
37 int dpbp_open(struct fsl_mc_io *mc_io, int dpbp_id, uint16_t *token)
39 struct mc_command cmd = { 0 };
43 cmd.header = mc_encode_cmd_header(DPBP_CMDID_OPEN,
45 cmd.params[0] |= mc_enc(0, 32, dpbp_id);
47 /* send command to mc*/
48 err = mc_send_command(mc_io, &cmd);
52 /* retrieve response parameters */
53 *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
57 EXPORT_SYMBOL(dpbp_open);
59 int dpbp_close(struct fsl_mc_io *mc_io, uint16_t token)
61 struct mc_command cmd = { 0 };
64 cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLOSE, MC_CMD_PRI_HIGH,
67 /* send command to mc*/
68 return mc_send_command(mc_io, &cmd);
70 EXPORT_SYMBOL(dpbp_close);
72 int dpbp_create(struct fsl_mc_io *mc_io,
73 const struct dpbp_cfg *cfg,
76 struct mc_command cmd = { 0 };
79 (void)(cfg); /* unused */
82 cmd.header = mc_encode_cmd_header(DPBP_CMDID_CREATE,
85 /* send command to mc*/
86 err = mc_send_command(mc_io, &cmd);
90 /* retrieve response parameters */
91 *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
96 int dpbp_destroy(struct fsl_mc_io *mc_io, uint16_t token)
98 struct mc_command cmd = { 0 };
100 /* prepare command */
101 cmd.header = mc_encode_cmd_header(DPBP_CMDID_DESTROY,
102 MC_CMD_PRI_LOW, token);
104 /* send command to mc*/
105 return mc_send_command(mc_io, &cmd);
108 int dpbp_enable(struct fsl_mc_io *mc_io, uint16_t token)
110 struct mc_command cmd = { 0 };
112 /* prepare command */
113 cmd.header = mc_encode_cmd_header(DPBP_CMDID_ENABLE, MC_CMD_PRI_LOW,
116 /* send command to mc*/
117 return mc_send_command(mc_io, &cmd);
119 EXPORT_SYMBOL(dpbp_enable);
121 int dpbp_disable(struct fsl_mc_io *mc_io, uint16_t token)
123 struct mc_command cmd = { 0 };
125 /* prepare command */
126 cmd.header = mc_encode_cmd_header(DPBP_CMDID_DISABLE,
127 MC_CMD_PRI_LOW, token);
129 /* send command to mc*/
130 return mc_send_command(mc_io, &cmd);
132 EXPORT_SYMBOL(dpbp_disable);
134 int dpbp_is_enabled(struct fsl_mc_io *mc_io, uint16_t token, int *en)
136 struct mc_command cmd = { 0 };
138 /* prepare command */
139 cmd.header = mc_encode_cmd_header(DPBP_CMDID_IS_ENABLED, MC_CMD_PRI_LOW,
142 /* send command to mc*/
143 err = mc_send_command(mc_io, &cmd);
147 /* retrieve response parameters */
148 *en = (int)mc_dec(cmd.params[0], 0, 1);
153 int dpbp_reset(struct fsl_mc_io *mc_io, uint16_t token)
155 struct mc_command cmd = { 0 };
157 /* prepare command */
158 cmd.header = mc_encode_cmd_header(DPBP_CMDID_RESET,
159 MC_CMD_PRI_LOW, token);
161 /* send command to mc*/
162 return mc_send_command(mc_io, &cmd);
165 int dpbp_set_irq(struct fsl_mc_io *mc_io,
172 struct mc_command cmd = { 0 };
174 /* prepare command */
175 cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_IRQ,
176 MC_CMD_PRI_LOW, token);
177 cmd.params[0] |= mc_enc(0, 8, irq_index);
178 cmd.params[0] |= mc_enc(32, 32, irq_val);
179 cmd.params[1] |= mc_enc(0, 64, irq_paddr);
180 cmd.params[2] |= mc_enc(0, 32, user_irq_id);
182 /* send command to mc*/
183 return mc_send_command(mc_io, &cmd);
186 int dpbp_get_irq(struct fsl_mc_io *mc_io,
194 struct mc_command cmd = { 0 };
197 /* prepare command */
198 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ,
199 MC_CMD_PRI_LOW, token);
200 cmd.params[0] |= mc_enc(32, 8, irq_index);
202 /* send command to mc*/
203 err = mc_send_command(mc_io, &cmd);
207 /* retrieve response parameters */
208 *irq_val = (uint32_t)mc_dec(cmd.params[0], 0, 32);
209 *irq_paddr = (uint64_t)mc_dec(cmd.params[1], 0, 64);
210 *user_irq_id = (int)mc_dec(cmd.params[2], 0, 32);
211 *type = (int)mc_dec(cmd.params[2], 32, 32);
215 int dpbp_set_irq_enable(struct fsl_mc_io *mc_io,
220 struct mc_command cmd = { 0 };
222 /* prepare command */
223 cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_IRQ_ENABLE,
224 MC_CMD_PRI_LOW, token);
225 cmd.params[0] |= mc_enc(0, 8, en);
226 cmd.params[0] |= mc_enc(32, 8, irq_index);
228 /* send command to mc*/
229 return mc_send_command(mc_io, &cmd);
232 int dpbp_get_irq_enable(struct fsl_mc_io *mc_io,
237 struct mc_command cmd = { 0 };
240 /* prepare command */
241 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ_ENABLE,
242 MC_CMD_PRI_LOW, token);
243 cmd.params[0] |= mc_enc(32, 8, irq_index);
245 /* send command to mc*/
246 err = mc_send_command(mc_io, &cmd);
250 /* retrieve response parameters */
251 *en = (uint8_t)mc_dec(cmd.params[0], 0, 8);
255 int dpbp_set_irq_mask(struct fsl_mc_io *mc_io,
260 struct mc_command cmd = { 0 };
262 /* prepare command */
263 cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_IRQ_MASK,
264 MC_CMD_PRI_LOW, token);
265 cmd.params[0] |= mc_enc(0, 32, mask);
266 cmd.params[0] |= mc_enc(32, 8, irq_index);
268 /* send command to mc*/
269 return mc_send_command(mc_io, &cmd);
272 int dpbp_get_irq_mask(struct fsl_mc_io *mc_io,
277 struct mc_command cmd = { 0 };
280 /* prepare command */
281 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ_MASK,
282 MC_CMD_PRI_LOW, token);
283 cmd.params[0] |= mc_enc(32, 8, irq_index);
285 /* send command to mc*/
286 err = mc_send_command(mc_io, &cmd);
290 /* retrieve response parameters */
291 *mask = (uint32_t)mc_dec(cmd.params[0], 0, 32);
295 int dpbp_get_irq_status(struct fsl_mc_io *mc_io,
300 struct mc_command cmd = { 0 };
303 /* prepare command */
304 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ_STATUS,
305 MC_CMD_PRI_LOW, token);
306 cmd.params[0] |= mc_enc(32, 8, irq_index);
308 /* send command to mc*/
309 err = mc_send_command(mc_io, &cmd);
313 /* retrieve response parameters */
314 *status = (uint32_t)mc_dec(cmd.params[0], 0, 32);
318 int dpbp_clear_irq_status(struct fsl_mc_io *mc_io,
323 struct mc_command cmd = { 0 };
325 /* prepare command */
326 cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLEAR_IRQ_STATUS,
327 MC_CMD_PRI_LOW, token);
328 cmd.params[0] |= mc_enc(0, 32, status);
329 cmd.params[0] |= mc_enc(32, 8, irq_index);
331 /* send command to mc*/
332 return mc_send_command(mc_io, &cmd);
335 int dpbp_get_attributes(struct fsl_mc_io *mc_io,
337 struct dpbp_attr *attr)
339 struct mc_command cmd = { 0 };
342 /* prepare command */
343 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_ATTR,
344 MC_CMD_PRI_LOW, token);
346 /* send command to mc*/
347 err = mc_send_command(mc_io, &cmd);
351 /* retrieve response parameters */
352 attr->bpid = (uint16_t)mc_dec(cmd.params[0], 16, 16);
353 attr->id = (int)mc_dec(cmd.params[0], 32, 32);
354 attr->version.major = (uint16_t)mc_dec(cmd.params[1], 0, 16);
355 attr->version.minor = (uint16_t)mc_dec(cmd.params[1], 16, 16);
358 EXPORT_SYMBOL(dpbp_get_attributes);