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,
42 struct mc_command cmd = { 0 };
46 cmd.header = mc_encode_cmd_header(DPBP_CMDID_OPEN,
48 cmd.params[0] |= mc_enc(0, 32, dpbp_id);
50 /* send command to mc*/
51 err = mc_send_command(mc_io, &cmd);
55 /* retrieve response parameters */
56 *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
60 EXPORT_SYMBOL(dpbp_open);
62 int dpbp_close(struct fsl_mc_io *mc_io,
66 struct mc_command cmd = { 0 };
69 cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLOSE, cmd_flags,
72 /* send command to mc*/
73 return mc_send_command(mc_io, &cmd);
75 EXPORT_SYMBOL(dpbp_close);
77 int dpbp_create(struct fsl_mc_io *mc_io,
79 const struct dpbp_cfg *cfg,
82 struct mc_command cmd = { 0 };
85 (void)(cfg); /* unused */
88 cmd.header = mc_encode_cmd_header(DPBP_CMDID_CREATE,
91 /* send command to mc*/
92 err = mc_send_command(mc_io, &cmd);
96 /* retrieve response parameters */
97 *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
102 int dpbp_destroy(struct fsl_mc_io *mc_io,
106 struct mc_command cmd = { 0 };
108 /* prepare command */
109 cmd.header = mc_encode_cmd_header(DPBP_CMDID_DESTROY,
112 /* send command to mc*/
113 return mc_send_command(mc_io, &cmd);
116 int dpbp_enable(struct fsl_mc_io *mc_io,
120 struct mc_command cmd = { 0 };
122 /* prepare command */
123 cmd.header = mc_encode_cmd_header(DPBP_CMDID_ENABLE, cmd_flags,
126 /* send command to mc*/
127 return mc_send_command(mc_io, &cmd);
129 EXPORT_SYMBOL(dpbp_enable);
131 int dpbp_disable(struct fsl_mc_io *mc_io,
135 struct mc_command cmd = { 0 };
137 /* prepare command */
138 cmd.header = mc_encode_cmd_header(DPBP_CMDID_DISABLE,
141 /* send command to mc*/
142 return mc_send_command(mc_io, &cmd);
144 EXPORT_SYMBOL(dpbp_disable);
146 int dpbp_is_enabled(struct fsl_mc_io *mc_io,
151 struct mc_command cmd = { 0 };
153 /* prepare command */
154 cmd.header = mc_encode_cmd_header(DPBP_CMDID_IS_ENABLED, cmd_flags,
157 /* send command to mc*/
158 err = mc_send_command(mc_io, &cmd);
162 /* retrieve response parameters */
163 *en = (int)mc_dec(cmd.params[0], 0, 1);
168 int dpbp_reset(struct fsl_mc_io *mc_io,
172 struct mc_command cmd = { 0 };
174 /* prepare command */
175 cmd.header = mc_encode_cmd_header(DPBP_CMDID_RESET,
178 /* send command to mc*/
179 return mc_send_command(mc_io, &cmd);
182 int dpbp_set_irq(struct fsl_mc_io *mc_io,
186 struct dpbp_irq_cfg *irq_cfg)
188 struct mc_command cmd = { 0 };
190 /* prepare command */
191 cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_IRQ,
193 cmd.params[0] |= mc_enc(0, 8, irq_index);
194 cmd.params[0] |= mc_enc(32, 32, irq_cfg->val);
195 cmd.params[1] |= mc_enc(0, 64, irq_cfg->addr);
196 cmd.params[2] |= mc_enc(0, 32, irq_cfg->user_irq_id);
198 /* send command to mc*/
199 return mc_send_command(mc_io, &cmd);
202 int dpbp_get_irq(struct fsl_mc_io *mc_io,
207 struct dpbp_irq_cfg *irq_cfg)
209 struct mc_command cmd = { 0 };
212 /* prepare command */
213 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ,
215 cmd.params[0] |= mc_enc(32, 8, irq_index);
217 /* send command to mc*/
218 err = mc_send_command(mc_io, &cmd);
222 /* retrieve response parameters */
223 irq_cfg->val = (uint32_t)mc_dec(cmd.params[0], 0, 32);
224 irq_cfg->addr = (uint64_t)mc_dec(cmd.params[1], 0, 64);
225 irq_cfg->user_irq_id = (int)mc_dec(cmd.params[2], 0, 32);
226 *type = (int)mc_dec(cmd.params[2], 32, 32);
230 int dpbp_set_irq_enable(struct fsl_mc_io *mc_io,
236 struct mc_command cmd = { 0 };
238 /* prepare command */
239 cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_IRQ_ENABLE,
241 cmd.params[0] |= mc_enc(0, 8, en);
242 cmd.params[0] |= mc_enc(32, 8, irq_index);
244 /* send command to mc*/
245 return mc_send_command(mc_io, &cmd);
248 int dpbp_get_irq_enable(struct fsl_mc_io *mc_io,
254 struct mc_command cmd = { 0 };
257 /* prepare command */
258 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ_ENABLE,
260 cmd.params[0] |= mc_enc(32, 8, irq_index);
262 /* send command to mc*/
263 err = mc_send_command(mc_io, &cmd);
267 /* retrieve response parameters */
268 *en = (uint8_t)mc_dec(cmd.params[0], 0, 8);
272 int dpbp_set_irq_mask(struct fsl_mc_io *mc_io,
278 struct mc_command cmd = { 0 };
280 /* prepare command */
281 cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_IRQ_MASK,
283 cmd.params[0] |= mc_enc(0, 32, mask);
284 cmd.params[0] |= mc_enc(32, 8, irq_index);
286 /* send command to mc*/
287 return mc_send_command(mc_io, &cmd);
290 int dpbp_get_irq_mask(struct fsl_mc_io *mc_io,
296 struct mc_command cmd = { 0 };
299 /* prepare command */
300 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ_MASK,
302 cmd.params[0] |= mc_enc(32, 8, irq_index);
304 /* send command to mc*/
305 err = mc_send_command(mc_io, &cmd);
309 /* retrieve response parameters */
310 *mask = (uint32_t)mc_dec(cmd.params[0], 0, 32);
314 int dpbp_get_irq_status(struct fsl_mc_io *mc_io,
320 struct mc_command cmd = { 0 };
323 /* prepare command */
324 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ_STATUS,
326 cmd.params[0] |= mc_enc(32, 8, irq_index);
328 /* send command to mc*/
329 err = mc_send_command(mc_io, &cmd);
333 /* retrieve response parameters */
334 *status = (uint32_t)mc_dec(cmd.params[0], 0, 32);
338 int dpbp_clear_irq_status(struct fsl_mc_io *mc_io,
344 struct mc_command cmd = { 0 };
346 /* prepare command */
347 cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLEAR_IRQ_STATUS,
349 cmd.params[0] |= mc_enc(0, 32, status);
350 cmd.params[0] |= mc_enc(32, 8, irq_index);
352 /* send command to mc*/
353 return mc_send_command(mc_io, &cmd);
356 int dpbp_get_attributes(struct fsl_mc_io *mc_io,
359 struct dpbp_attr *attr)
361 struct mc_command cmd = { 0 };
364 /* prepare command */
365 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_ATTR,
368 /* send command to mc*/
369 err = mc_send_command(mc_io, &cmd);
373 /* retrieve response parameters */
374 attr->bpid = (uint16_t)mc_dec(cmd.params[0], 16, 16);
375 attr->id = (int)mc_dec(cmd.params[0], 32, 32);
376 attr->version.major = (uint16_t)mc_dec(cmd.params[1], 0, 16);
377 attr->version.minor = (uint16_t)mc_dec(cmd.params[1], 16, 16);
380 EXPORT_SYMBOL(dpbp_get_attributes);