1 /* Copyright 2013-2015 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"
35 #include "dpmcp-cmd.h"
37 int dpmcp_open(struct fsl_mc_io *mc_io, int dpmcp_id, uint16_t *token)
39 struct mc_command cmd = { 0 };
43 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_OPEN,
45 cmd.params[0] |= mc_enc(0, 32, dpmcp_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);
58 int dpmcp_close(struct fsl_mc_io *mc_io, uint16_t token)
60 struct mc_command cmd = { 0 };
63 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_CLOSE, MC_CMD_PRI_HIGH,
66 /* send command to mc*/
67 return mc_send_command(mc_io, &cmd);
70 int dpmcp_create(struct fsl_mc_io *mc_io,
71 const struct dpmcp_cfg *cfg,
74 struct mc_command cmd = { 0 };
78 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_CREATE,
80 cmd.params[0] |= mc_enc(0, 32, cfg->portal_id);
82 /* send command to mc*/
83 err = mc_send_command(mc_io, &cmd);
87 /* retrieve response parameters */
88 *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
93 int dpmcp_destroy(struct fsl_mc_io *mc_io, uint16_t token)
95 struct mc_command cmd = { 0 };
98 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_DESTROY,
99 MC_CMD_PRI_LOW, token);
101 /* send command to mc*/
102 return mc_send_command(mc_io, &cmd);
105 int dpmcp_reset(struct fsl_mc_io *mc_io, uint16_t token)
107 struct mc_command cmd = { 0 };
109 /* prepare command */
110 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_RESET,
111 MC_CMD_PRI_LOW, token);
113 /* send command to mc*/
114 return mc_send_command(mc_io, &cmd);
117 int dpmcp_set_irq(struct fsl_mc_io *mc_io,
124 struct mc_command cmd = { 0 };
126 /* prepare command */
127 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_SET_IRQ,
128 MC_CMD_PRI_LOW, token);
129 cmd.params[0] |= mc_enc(0, 8, irq_index);
130 cmd.params[0] |= mc_enc(32, 32, irq_val);
131 cmd.params[1] |= mc_enc(0, 64, irq_addr);
132 cmd.params[2] |= mc_enc(0, 32, user_irq_id);
134 /* send command to mc*/
135 return mc_send_command(mc_io, &cmd);
138 int dpmcp_get_irq(struct fsl_mc_io *mc_io,
146 struct mc_command cmd = { 0 };
149 /* prepare command */
150 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ,
151 MC_CMD_PRI_LOW, token);
152 cmd.params[0] |= mc_enc(32, 8, irq_index);
154 /* send command to mc*/
155 err = mc_send_command(mc_io, &cmd);
159 /* retrieve response parameters */
160 *irq_val = (uint32_t)mc_dec(cmd.params[0], 0, 32);
161 *irq_addr = (uint64_t)mc_dec(cmd.params[1], 0, 64);
162 *user_irq_id = (int)mc_dec(cmd.params[2], 0, 32);
163 *type = (int)mc_dec(cmd.params[2], 32, 32);
167 int dpmcp_set_irq_enable(struct fsl_mc_io *mc_io,
172 struct mc_command cmd = { 0 };
174 /* prepare command */
175 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_SET_IRQ_ENABLE,
176 MC_CMD_PRI_LOW, token);
177 cmd.params[0] |= mc_enc(0, 8, en);
178 cmd.params[0] |= mc_enc(32, 8, irq_index);
180 /* send command to mc*/
181 return mc_send_command(mc_io, &cmd);
184 int dpmcp_get_irq_enable(struct fsl_mc_io *mc_io,
189 struct mc_command cmd = { 0 };
192 /* prepare command */
193 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ_ENABLE,
194 MC_CMD_PRI_LOW, token);
195 cmd.params[0] |= mc_enc(32, 8, irq_index);
197 /* send command to mc*/
198 err = mc_send_command(mc_io, &cmd);
202 /* retrieve response parameters */
203 *en = (uint8_t)mc_dec(cmd.params[0], 0, 8);
207 int dpmcp_set_irq_mask(struct fsl_mc_io *mc_io,
212 struct mc_command cmd = { 0 };
214 /* prepare command */
215 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_SET_IRQ_MASK,
216 MC_CMD_PRI_LOW, token);
217 cmd.params[0] |= mc_enc(0, 32, mask);
218 cmd.params[0] |= mc_enc(32, 8, irq_index);
220 /* send command to mc*/
221 return mc_send_command(mc_io, &cmd);
224 int dpmcp_get_irq_mask(struct fsl_mc_io *mc_io,
229 struct mc_command cmd = { 0 };
232 /* prepare command */
233 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ_MASK,
234 MC_CMD_PRI_LOW, token);
235 cmd.params[0] |= mc_enc(32, 8, irq_index);
237 /* send command to mc*/
238 err = mc_send_command(mc_io, &cmd);
242 /* retrieve response parameters */
243 *mask = (uint32_t)mc_dec(cmd.params[0], 0, 32);
247 int dpmcp_get_irq_status(struct fsl_mc_io *mc_io,
252 struct mc_command cmd = { 0 };
255 /* prepare command */
256 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ_STATUS,
257 MC_CMD_PRI_LOW, token);
258 cmd.params[0] |= mc_enc(32, 8, irq_index);
260 /* send command to mc*/
261 err = mc_send_command(mc_io, &cmd);
265 /* retrieve response parameters */
266 *status = (uint32_t)mc_dec(cmd.params[0], 0, 32);
270 int dpmcp_clear_irq_status(struct fsl_mc_io *mc_io,
275 struct mc_command cmd = { 0 };
277 /* prepare command */
278 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_CLEAR_IRQ_STATUS,
279 MC_CMD_PRI_LOW, token);
280 cmd.params[0] |= mc_enc(0, 32, status);
281 cmd.params[0] |= mc_enc(32, 8, irq_index);
283 /* send command to mc*/
284 return mc_send_command(mc_io, &cmd);
287 int dpmcp_get_attributes(struct fsl_mc_io *mc_io,
289 struct dpmcp_attr *attr)
291 struct mc_command cmd = { 0 };
294 /* prepare command */
295 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_ATTR,
296 MC_CMD_PRI_LOW, token);
298 /* send command to mc*/
299 err = mc_send_command(mc_io, &cmd);
303 /* retrieve response parameters */
304 attr->id = (int)mc_dec(cmd.params[0], 32, 32);
305 attr->version.major = (uint16_t)mc_dec(cmd.params[1], 0, 16);
306 attr->version.minor = (uint16_t)mc_dec(cmd.params[1], 16, 16);