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"
38 * dpmcp_open() - Open a control session for the specified object.
39 * @mc_io: Pointer to MC portal's I/O object
40 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
41 * @dpmcp_id: DPMCP unique ID
42 * @token: Returned token; use in subsequent API calls
44 * This function can be used to open a control session for an
45 * already created object; an object may have been declared in
46 * the DPL or by calling the dpmcp_create function.
47 * This function returns a unique authentication token,
48 * associated with the specific object ID and the specific MC
49 * portal; this token must be used in all subsequent commands for
50 * this specific object
52 * Return: '0' on Success; Error code otherwise.
54 int dpmcp_open(struct fsl_mc_io *mc_io,
59 struct mc_command cmd = { 0 };
63 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_OPEN,
65 cmd.params[0] |= mc_enc(0, 32, dpmcp_id);
67 /* send command to mc*/
68 err = mc_send_command(mc_io, &cmd);
72 /* retrieve response parameters */
73 *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
79 * dpmcp_close() - Close the control session of the object
80 * @mc_io: Pointer to MC portal's I/O object
81 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
82 * @token: Token of DPMCP object
84 * After this function is called, no further operations are
85 * allowed on the object without opening a new control session.
87 * Return: '0' on Success; Error code otherwise.
89 int dpmcp_close(struct fsl_mc_io *mc_io,
93 struct mc_command cmd = { 0 };
96 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_CLOSE,
99 /* send command to mc*/
100 return mc_send_command(mc_io, &cmd);
104 * dpmcp_create() - Create the DPMCP object.
105 * @mc_io: Pointer to MC portal's I/O object
106 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
107 * @cfg: Configuration structure
108 * @token: Returned token; use in subsequent API calls
110 * Create the DPMCP object, allocate required resources and
111 * perform required initialization.
113 * The object can be created either by declaring it in the
114 * DPL file, or by calling this function.
115 * This function returns a unique authentication token,
116 * associated with the specific object ID and the specific MC
117 * portal; this token must be used in all subsequent calls to
118 * this specific object. For objects that are created using the
119 * DPL file, call dpmcp_open function to get an authentication
122 * Return: '0' on Success; Error code otherwise.
124 int dpmcp_create(struct fsl_mc_io *mc_io,
126 const struct dpmcp_cfg *cfg,
129 struct mc_command cmd = { 0 };
132 /* prepare command */
133 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_CREATE,
135 cmd.params[0] |= mc_enc(0, 32, cfg->portal_id);
137 /* send command to mc*/
138 err = mc_send_command(mc_io, &cmd);
142 /* retrieve response parameters */
143 *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
149 * dpmcp_destroy() - Destroy the DPMCP object and release all its resources.
150 * @mc_io: Pointer to MC portal's I/O object
151 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
152 * @token: Token of DPMCP object
154 * Return: '0' on Success; error code otherwise.
156 int dpmcp_destroy(struct fsl_mc_io *mc_io,
160 struct mc_command cmd = { 0 };
162 /* prepare command */
163 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_DESTROY,
166 /* send command to mc*/
167 return mc_send_command(mc_io, &cmd);
171 * dpmcp_reset() - Reset the DPMCP, returns the object to initial state.
172 * @mc_io: Pointer to MC portal's I/O object
173 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
174 * @token: Token of DPMCP object
176 * Return: '0' on Success; Error code otherwise.
178 int dpmcp_reset(struct fsl_mc_io *mc_io,
182 struct mc_command cmd = { 0 };
184 /* prepare command */
185 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_RESET,
188 /* send command to mc*/
189 return mc_send_command(mc_io, &cmd);
193 * dpmcp_set_irq() - Set IRQ information for the DPMCP to trigger an interrupt.
194 * @mc_io: Pointer to MC portal's I/O object
195 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
196 * @token: Token of DPMCP object
197 * @irq_index: Identifies the interrupt index to configure
198 * @irq_cfg: IRQ configuration
200 * Return: '0' on Success; Error code otherwise.
202 int dpmcp_set_irq(struct fsl_mc_io *mc_io,
206 struct dpmcp_irq_cfg *irq_cfg)
208 struct mc_command cmd = { 0 };
210 /* prepare command */
211 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_SET_IRQ,
213 cmd.params[0] |= mc_enc(0, 8, irq_index);
214 cmd.params[0] |= mc_enc(32, 32, irq_cfg->val);
215 cmd.params[1] |= mc_enc(0, 64, irq_cfg->paddr);
216 cmd.params[2] |= mc_enc(0, 32, irq_cfg->user_irq_id);
218 /* send command to mc*/
219 return mc_send_command(mc_io, &cmd);
223 * dpmcp_get_irq() - Get IRQ information from the DPMCP.
224 * @mc_io: Pointer to MC portal's I/O object
225 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
226 * @token: Token of DPMCP object
227 * @irq_index: The interrupt index to configure
228 * @type: Interrupt type: 0 represents message interrupt
229 * type (both irq_addr and irq_val are valid)
230 * @irq_cfg: IRQ attributes
232 * Return: '0' on Success; Error code otherwise.
234 int dpmcp_get_irq(struct fsl_mc_io *mc_io,
239 struct dpmcp_irq_cfg *irq_cfg)
241 struct mc_command cmd = { 0 };
244 /* prepare command */
245 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ,
247 cmd.params[0] |= mc_enc(32, 8, irq_index);
249 /* send command to mc*/
250 err = mc_send_command(mc_io, &cmd);
254 /* retrieve response parameters */
255 irq_cfg->val = (u32)mc_dec(cmd.params[0], 0, 32);
256 irq_cfg->paddr = (u64)mc_dec(cmd.params[1], 0, 64);
257 irq_cfg->user_irq_id = (int)mc_dec(cmd.params[2], 0, 32);
258 *type = (int)mc_dec(cmd.params[2], 32, 32);
263 * dpmcp_set_irq_enable() - Set overall interrupt state.
264 * @mc_io: Pointer to MC portal's I/O object
265 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
266 * @token: Token of DPMCP object
267 * @irq_index: The interrupt index to configure
268 * @en: Interrupt state - enable = 1, disable = 0
270 * Allows GPP software to control when interrupts are generated.
271 * Each interrupt can have up to 32 causes. The enable/disable control's the
272 * overall interrupt state. if the interrupt is disabled no causes will cause
275 * Return: '0' on Success; Error code otherwise.
277 int dpmcp_set_irq_enable(struct fsl_mc_io *mc_io,
283 struct mc_command cmd = { 0 };
285 /* prepare command */
286 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_SET_IRQ_ENABLE,
288 cmd.params[0] |= mc_enc(0, 8, en);
289 cmd.params[0] |= mc_enc(32, 8, irq_index);
291 /* send command to mc*/
292 return mc_send_command(mc_io, &cmd);
296 * dpmcp_get_irq_enable() - Get overall interrupt state
297 * @mc_io: Pointer to MC portal's I/O object
298 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
299 * @token: Token of DPMCP object
300 * @irq_index: The interrupt index to configure
301 * @en: Returned interrupt state - enable = 1, disable = 0
303 * Return: '0' on Success; Error code otherwise.
305 int dpmcp_get_irq_enable(struct fsl_mc_io *mc_io,
311 struct mc_command cmd = { 0 };
314 /* prepare command */
315 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ_ENABLE,
317 cmd.params[0] |= mc_enc(32, 8, irq_index);
319 /* send command to mc*/
320 err = mc_send_command(mc_io, &cmd);
324 /* retrieve response parameters */
325 *en = (u8)mc_dec(cmd.params[0], 0, 8);
330 * dpmcp_set_irq_mask() - Set interrupt mask.
331 * @mc_io: Pointer to MC portal's I/O object
332 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
333 * @token: Token of DPMCP object
334 * @irq_index: The interrupt index to configure
335 * @mask: Event mask to trigger interrupt;
338 * 1 = consider event for asserting IRQ
340 * Every interrupt can have up to 32 causes and the interrupt model supports
341 * masking/unmasking each cause independently
343 * Return: '0' on Success; Error code otherwise.
345 int dpmcp_set_irq_mask(struct fsl_mc_io *mc_io,
351 struct mc_command cmd = { 0 };
353 /* prepare command */
354 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_SET_IRQ_MASK,
356 cmd.params[0] |= mc_enc(0, 32, mask);
357 cmd.params[0] |= mc_enc(32, 8, irq_index);
359 /* send command to mc*/
360 return mc_send_command(mc_io, &cmd);
364 * dpmcp_get_irq_mask() - Get interrupt mask.
365 * @mc_io: Pointer to MC portal's I/O object
366 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
367 * @token: Token of DPMCP object
368 * @irq_index: The interrupt index to configure
369 * @mask: Returned event mask to trigger interrupt
371 * Every interrupt can have up to 32 causes and the interrupt model supports
372 * masking/unmasking each cause independently
374 * Return: '0' on Success; Error code otherwise.
376 int dpmcp_get_irq_mask(struct fsl_mc_io *mc_io,
382 struct mc_command cmd = { 0 };
385 /* prepare command */
386 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ_MASK,
388 cmd.params[0] |= mc_enc(32, 8, irq_index);
390 /* send command to mc*/
391 err = mc_send_command(mc_io, &cmd);
395 /* retrieve response parameters */
396 *mask = (u32)mc_dec(cmd.params[0], 0, 32);
401 * dpmcp_get_irq_status() - Get the current status of any pending interrupts.
403 * @mc_io: Pointer to MC portal's I/O object
404 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
405 * @token: Token of DPMCP object
406 * @irq_index: The interrupt index to configure
407 * @status: Returned interrupts status - one bit per cause:
408 * 0 = no interrupt pending
409 * 1 = interrupt pending
411 * Return: '0' on Success; Error code otherwise.
413 int dpmcp_get_irq_status(struct fsl_mc_io *mc_io,
419 struct mc_command cmd = { 0 };
422 /* prepare command */
423 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ_STATUS,
425 cmd.params[0] |= mc_enc(32, 8, irq_index);
427 /* send command to mc*/
428 err = mc_send_command(mc_io, &cmd);
432 /* retrieve response parameters */
433 *status = (u32)mc_dec(cmd.params[0], 0, 32);
438 * dpmcp_clear_irq_status() - Clear a pending interrupt's status
440 * @mc_io: Pointer to MC portal's I/O object
441 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
442 * @token: Token of DPMCP object
443 * @irq_index: The interrupt index to configure
444 * @status: Bits to clear (W1C) - one bit per cause:
446 * 1 = clear status bit
448 * Return: '0' on Success; Error code otherwise.
450 int dpmcp_clear_irq_status(struct fsl_mc_io *mc_io,
456 struct mc_command cmd = { 0 };
458 /* prepare command */
459 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_CLEAR_IRQ_STATUS,
461 cmd.params[0] |= mc_enc(0, 32, status);
462 cmd.params[0] |= mc_enc(32, 8, irq_index);
464 /* send command to mc*/
465 return mc_send_command(mc_io, &cmd);
469 * dpmcp_get_attributes - Retrieve DPMCP attributes.
471 * @mc_io: Pointer to MC portal's I/O object
472 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
473 * @token: Token of DPMCP object
474 * @attr: Returned object's attributes
476 * Return: '0' on Success; Error code otherwise.
478 int dpmcp_get_attributes(struct fsl_mc_io *mc_io,
481 struct dpmcp_attr *attr)
483 struct mc_command cmd = { 0 };
486 /* prepare command */
487 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_ATTR,
490 /* send command to mc*/
491 err = mc_send_command(mc_io, &cmd);
495 /* retrieve response parameters */
496 attr->id = (int)mc_dec(cmd.params[0], 32, 32);
497 attr->version.major = (u16)mc_dec(cmd.params[1], 0, 16);
498 attr->version.minor = (u16)mc_dec(cmd.params[1], 16, 16);