Linux Audio

Check our new training course

Loading...
  1/*
  2 * Copyright 2013-2016 Freescale Semiconductor Inc.
  3 *
  4 * Redistribution and use in source and binary forms, with or without
  5 * modification, are permitted provided that the following conditions are met:
  6 * * Redistributions of source code must retain the above copyright
  7 * notice, this list of conditions and the following disclaimer.
  8 * * Redistributions in binary form must reproduce the above copyright
  9 * notice, this list of conditions and the following disclaimer in the
 10 * documentation and/or other materials provided with the distribution.
 11 * * Neither the name of the above-listed copyright holders nor the
 12 * names of any contributors may be used to endorse or promote products
 13 * derived from this software without specific prior written permission.
 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
 35#include "dpmcp.h"
 36#include "dpmcp-cmd.h"
 37
 38/**
 39 * dpmcp_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 * @dpmcp_id:	DPMCP 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 dpmcp_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 */
 55int dpmcp_open(struct fsl_mc_io *mc_io,
 56	       u32 cmd_flags,
 57	       int dpmcp_id,
 58	       u16 *token)
 59{
 60	struct mc_command cmd = { 0 };
 61	struct dpmcp_cmd_open *cmd_params;
 62	int err;
 63
 64	/* prepare command */
 65	cmd.header = mc_encode_cmd_header(DPMCP_CMDID_OPEN,
 66					  cmd_flags, 0);
 67	cmd_params = (struct dpmcp_cmd_open *)cmd.params;
 68	cmd_params->dpmcp_id = cpu_to_le32(dpmcp_id);
 69
 70	/* send command to mc*/
 71	err = mc_send_command(mc_io, &cmd);
 72	if (err)
 73		return err;
 74
 75	/* retrieve response parameters */
 76	*token = mc_cmd_hdr_read_token(&cmd);
 77
 78	return err;
 79}
 80
 81/**
 82 * dpmcp_close() - Close the control session of the object
 83 * @mc_io:	Pointer to MC portal's I/O object
 84 * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
 85 * @token:	Token of DPMCP object
 86 *
 87 * After this function is called, no further operations are
 88 * allowed on the object without opening a new control session.
 89 *
 90 * Return:	'0' on Success; Error code otherwise.
 91 */
 92int dpmcp_close(struct fsl_mc_io *mc_io,
 93		u32 cmd_flags,
 94		u16 token)
 95{
 96	struct mc_command cmd = { 0 };
 97
 98	/* prepare command */
 99	cmd.header = mc_encode_cmd_header(DPMCP_CMDID_CLOSE,
100					  cmd_flags, token);
101
102	/* send command to mc*/
103	return mc_send_command(mc_io, &cmd);
104}
105
106/**
107 * dpmcp_create() - Create the DPMCP object.
108 * @mc_io:	Pointer to MC portal's I/O object
109 * @dprc_token:	Parent container token; '0' for default container
110 * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
111 * @cfg:	Configuration structure
112 * @obj_id:	Returned object id; use in subsequent API calls
113 *
114 * Create the DPMCP object, allocate required resources and
115 * perform required initialization.
116 *
117 * The object can be created either by declaring it in the
118 * DPL file, or by calling this function.
119
120 * This function accepts an authentication token of a parent
121 * container that this object should be assigned to and returns
122 * an object id. This object_id will be used in all subsequent calls to
123 * this specific object.
124 *
125 * Return:	'0' on Success; Error code otherwise.
126 */
127int dpmcp_create(struct fsl_mc_io *mc_io,
128		 u16 dprc_token,
129		 u32 cmd_flags,
130		 const struct dpmcp_cfg *cfg,
131		 u32 *obj_id)
132{
133	struct mc_command cmd = { 0 };
134	struct dpmcp_cmd_create *cmd_params;
135
136	int err;
137
138	/* prepare command */
139	cmd.header = mc_encode_cmd_header(DPMCP_CMDID_CREATE,
140					  cmd_flags, dprc_token);
141	cmd_params = (struct dpmcp_cmd_create *)cmd.params;
142	cmd_params->portal_id = cpu_to_le32(cfg->portal_id);
143
144	/* send command to mc*/
145	err = mc_send_command(mc_io, &cmd);
146	if (err)
147		return err;
148
149	/* retrieve response parameters */
150	*obj_id = mc_cmd_read_object_id(&cmd);
151
152	return 0;
153}
154
155/**
156 * dpmcp_destroy() - Destroy the DPMCP object and release all its resources.
157 * @mc_io:	Pointer to MC portal's I/O object
158 * @dprc_token:	Parent container token; '0' for default container
159 * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
160 * @obj_id:	ID of DPMCP object
161 *
162 * Return:	'0' on Success; error code otherwise.
163 */
164int dpmcp_destroy(struct fsl_mc_io *mc_io,
165		  u16 dprc_token,
166		  u32 cmd_flags,
167		  u32 obj_id)
168{
169	struct mc_command cmd = { 0 };
170	struct dpmcp_cmd_destroy *cmd_params;
171
172	/* prepare command */
173	cmd.header = mc_encode_cmd_header(DPMCP_CMDID_DESTROY,
174					  cmd_flags, dprc_token);
175	cmd_params = (struct dpmcp_cmd_destroy *)cmd.params;
176	cmd_params->object_id = cpu_to_le32(obj_id);
177
178	/* send command to mc*/
179	return mc_send_command(mc_io, &cmd);
180}
181
182/**
183 * dpmcp_reset() - Reset the DPMCP, returns the object to initial state.
184 * @mc_io:	Pointer to MC portal's I/O object
185 * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
186 * @token:	Token of DPMCP object
187 *
188 * Return:	'0' on Success; Error code otherwise.
189 */
190int dpmcp_reset(struct fsl_mc_io *mc_io,
191		u32 cmd_flags,
192		u16 token)
193{
194	struct mc_command cmd = { 0 };
195
196	/* prepare command */
197	cmd.header = mc_encode_cmd_header(DPMCP_CMDID_RESET,
198					  cmd_flags, token);
199
200	/* send command to mc*/
201	return mc_send_command(mc_io, &cmd);
202}
203
204/**
205 * dpmcp_set_irq() - Set IRQ information for the DPMCP to trigger an interrupt.
206 * @mc_io:	Pointer to MC portal's I/O object
207 * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
208 * @token:	Token of DPMCP object
209 * @irq_index:	Identifies the interrupt index to configure
210 * @irq_cfg:	IRQ configuration
211 *
212 * Return:	'0' on Success; Error code otherwise.
213 */
214int dpmcp_set_irq(struct fsl_mc_io *mc_io,
215		  u32 cmd_flags,
216		  u16 token,
217		  u8 irq_index,
218		  struct dpmcp_irq_cfg	*irq_cfg)
219{
220	struct mc_command cmd = { 0 };
221	struct dpmcp_cmd_set_irq *cmd_params;
222
223	/* prepare command */
224	cmd.header = mc_encode_cmd_header(DPMCP_CMDID_SET_IRQ,
225					  cmd_flags, token);
226	cmd_params = (struct dpmcp_cmd_set_irq *)cmd.params;
227	cmd_params->irq_index = irq_index;
228	cmd_params->irq_val = cpu_to_le32(irq_cfg->val);
229	cmd_params->irq_addr = cpu_to_le64(irq_cfg->paddr);
230	cmd_params->irq_num = cpu_to_le32(irq_cfg->irq_num);
231
232	/* send command to mc*/
233	return mc_send_command(mc_io, &cmd);
234}
235
236/**
237 * dpmcp_get_irq() - Get IRQ information from the DPMCP.
238 * @mc_io:	Pointer to MC portal's I/O object
239 * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
240 * @token:	Token of DPMCP object
241 * @irq_index:	The interrupt index to configure
242 * @type:	Interrupt type: 0 represents message interrupt
243 *		type (both irq_addr and irq_val are valid)
244 * @irq_cfg:	IRQ attributes
245 *
246 * Return:	'0' on Success; Error code otherwise.
247 */
248int dpmcp_get_irq(struct fsl_mc_io *mc_io,
249		  u32 cmd_flags,
250		  u16 token,
251		  u8 irq_index,
252		  int *type,
253		  struct dpmcp_irq_cfg	*irq_cfg)
254{
255	struct mc_command cmd = { 0 };
256	struct dpmcp_cmd_get_irq *cmd_params;
257	struct dpmcp_rsp_get_irq *rsp_params;
258	int err;
259
260	/* prepare command */
261	cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ,
262					  cmd_flags, token);
263	cmd_params = (struct dpmcp_cmd_get_irq *)cmd.params;
264	cmd_params->irq_index = irq_index;
265
266	/* send command to mc*/
267	err = mc_send_command(mc_io, &cmd);
268	if (err)
269		return err;
270
271	/* retrieve response parameters */
272	rsp_params = (struct dpmcp_rsp_get_irq *)cmd.params;
273	irq_cfg->val = le32_to_cpu(rsp_params->irq_val);
274	irq_cfg->paddr = le64_to_cpu(rsp_params->irq_paddr);
275	irq_cfg->irq_num = le32_to_cpu(rsp_params->irq_num);
276	*type = le32_to_cpu(rsp_params->type);
277	return 0;
278}
279
280/**
281 * dpmcp_set_irq_enable() - Set overall interrupt state.
282 * @mc_io:	Pointer to MC portal's I/O object
283 * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
284 * @token:	Token of DPMCP object
285 * @irq_index:	The interrupt index to configure
286 * @en:	Interrupt state - enable = 1, disable = 0
287 *
288 * Allows GPP software to control when interrupts are generated.
289 * Each interrupt can have up to 32 causes.  The enable/disable control's the
290 * overall interrupt state. if the interrupt is disabled no causes will cause
291 * an interrupt.
292 *
293 * Return:	'0' on Success; Error code otherwise.
294 */
295int dpmcp_set_irq_enable(struct fsl_mc_io *mc_io,
296			 u32 cmd_flags,
297			 u16 token,
298			 u8 irq_index,
299			 u8 en)
300{
301	struct mc_command cmd = { 0 };
302	struct dpmcp_cmd_set_irq_enable *cmd_params;
303
304	/* prepare command */
305	cmd.header = mc_encode_cmd_header(DPMCP_CMDID_SET_IRQ_ENABLE,
306					  cmd_flags, token);
307	cmd_params = (struct dpmcp_cmd_set_irq_enable *)cmd.params;
308	cmd_params->enable = en & DPMCP_ENABLE;
309	cmd_params->irq_index = irq_index;
310
311	/* send command to mc*/
312	return mc_send_command(mc_io, &cmd);
313}
314
315/**
316 * dpmcp_get_irq_enable() - Get overall interrupt state
317 * @mc_io:	Pointer to MC portal's I/O object
318 * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
319 * @token:	Token of DPMCP object
320 * @irq_index:	The interrupt index to configure
321 * @en:		Returned interrupt state - enable = 1, disable = 0
322 *
323 * Return:	'0' on Success; Error code otherwise.
324 */
325int dpmcp_get_irq_enable(struct fsl_mc_io *mc_io,
326			 u32 cmd_flags,
327			 u16 token,
328			 u8 irq_index,
329			 u8 *en)
330{
331	struct mc_command cmd = { 0 };
332	struct dpmcp_cmd_get_irq_enable *cmd_params;
333	struct dpmcp_rsp_get_irq_enable *rsp_params;
334	int err;
335
336	/* prepare command */
337	cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ_ENABLE,
338					  cmd_flags, token);
339	cmd_params = (struct dpmcp_cmd_get_irq_enable *)cmd.params;
340	cmd_params->irq_index = irq_index;
341
342	/* send command to mc*/
343	err = mc_send_command(mc_io, &cmd);
344	if (err)
345		return err;
346
347	/* retrieve response parameters */
348	rsp_params = (struct dpmcp_rsp_get_irq_enable *)cmd.params;
349	*en = rsp_params->enabled & DPMCP_ENABLE;
350	return 0;
351}
352
353/**
354 * dpmcp_set_irq_mask() - Set interrupt mask.
355 * @mc_io:	Pointer to MC portal's I/O object
356 * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
357 * @token:	Token of DPMCP object
358 * @irq_index:	The interrupt index to configure
359 * @mask:	Event mask to trigger interrupt;
360 *			each bit:
361 *				0 = ignore event
362 *				1 = consider event for asserting IRQ
363 *
364 * Every interrupt can have up to 32 causes and the interrupt model supports
365 * masking/unmasking each cause independently
366 *
367 * Return:	'0' on Success; Error code otherwise.
368 */
369int dpmcp_set_irq_mask(struct fsl_mc_io *mc_io,
370		       u32 cmd_flags,
371		       u16 token,
372		       u8 irq_index,
373		       u32 mask)
374{
375	struct mc_command cmd = { 0 };
376	struct dpmcp_cmd_set_irq_mask *cmd_params;
377
378	/* prepare command */
379	cmd.header = mc_encode_cmd_header(DPMCP_CMDID_SET_IRQ_MASK,
380					  cmd_flags, token);
381	cmd_params = (struct dpmcp_cmd_set_irq_mask *)cmd.params;
382	cmd_params->mask = cpu_to_le32(mask);
383	cmd_params->irq_index = irq_index;
384
385	/* send command to mc*/
386	return mc_send_command(mc_io, &cmd);
387}
388
389/**
390 * dpmcp_get_irq_mask() - Get interrupt mask.
391 * @mc_io:	Pointer to MC portal's I/O object
392 * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
393 * @token:	Token of DPMCP object
394 * @irq_index:	The interrupt index to configure
395 * @mask:	Returned event mask to trigger interrupt
396 *
397 * Every interrupt can have up to 32 causes and the interrupt model supports
398 * masking/unmasking each cause independently
399 *
400 * Return:	'0' on Success; Error code otherwise.
401 */
402int dpmcp_get_irq_mask(struct fsl_mc_io *mc_io,
403		       u32 cmd_flags,
404		       u16 token,
405		       u8 irq_index,
406		       u32 *mask)
407{
408	struct mc_command cmd = { 0 };
409	struct dpmcp_cmd_get_irq_mask *cmd_params;
410	struct dpmcp_rsp_get_irq_mask *rsp_params;
411
412	int err;
413
414	/* prepare command */
415	cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ_MASK,
416					  cmd_flags, token);
417	cmd_params = (struct dpmcp_cmd_get_irq_mask *)cmd.params;
418	cmd_params->irq_index = irq_index;
419
420	/* send command to mc*/
421	err = mc_send_command(mc_io, &cmd);
422	if (err)
423		return err;
424
425	/* retrieve response parameters */
426	rsp_params = (struct dpmcp_rsp_get_irq_mask *)cmd.params;
427	*mask = le32_to_cpu(rsp_params->mask);
428
429	return 0;
430}
431
432/**
433 * dpmcp_get_irq_status() - Get the current status of any pending interrupts.
434 *
435 * @mc_io:	Pointer to MC portal's I/O object
436 * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
437 * @token:	Token of DPMCP object
438 * @irq_index:	The interrupt index to configure
439 * @status:	Returned interrupts status - one bit per cause:
440 *			0 = no interrupt pending
441 *			1 = interrupt pending
442 *
443 * Return:	'0' on Success; Error code otherwise.
444 */
445int dpmcp_get_irq_status(struct fsl_mc_io *mc_io,
446			 u32 cmd_flags,
447			 u16 token,
448			 u8 irq_index,
449			 u32 *status)
450{
451	struct mc_command cmd = { 0 };
452	struct dpmcp_cmd_get_irq_status *cmd_params;
453	struct dpmcp_rsp_get_irq_status *rsp_params;
454	int err;
455
456	/* prepare command */
457	cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ_STATUS,
458					  cmd_flags, token);
459	cmd_params = (struct dpmcp_cmd_get_irq_status *)cmd.params;
460	cmd_params->status = cpu_to_le32(*status);
461	cmd_params->irq_index = irq_index;
462
463	/* send command to mc*/
464	err = mc_send_command(mc_io, &cmd);
465	if (err)
466		return err;
467
468	/* retrieve response parameters */
469	rsp_params = (struct dpmcp_rsp_get_irq_status *)cmd.params;
470	*status = le32_to_cpu(rsp_params->status);
471
472	return 0;
473}
474
475/**
476 * dpmcp_get_attributes - Retrieve DPMCP attributes.
477 *
478 * @mc_io:	Pointer to MC portal's I/O object
479 * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
480 * @token:	Token of DPMCP object
481 * @attr:	Returned object's attributes
482 *
483 * Return:	'0' on Success; Error code otherwise.
484 */
485int dpmcp_get_attributes(struct fsl_mc_io *mc_io,
486			 u32 cmd_flags,
487			 u16 token,
488			 struct dpmcp_attr *attr)
489{
490	struct mc_command cmd = { 0 };
491	struct dpmcp_rsp_get_attributes *rsp_params;
492	int err;
493
494	/* prepare command */
495	cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_ATTR,
496					  cmd_flags, token);
497
498	/* send command to mc*/
499	err = mc_send_command(mc_io, &cmd);
500	if (err)
501		return err;
502
503	/* retrieve response parameters */
504	rsp_params = (struct dpmcp_rsp_get_attributes *)cmd.params;
505	attr->id = le32_to_cpu(rsp_params->id);
506
507	return 0;
508}
509
510/**
511 * dpmcp_get_api_version - Get Data Path Management Command Portal API version
512 * @mc_io:	Pointer to Mc portal's I/O object
513 * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
514 * @major_ver:	Major version of Data Path Management Command Portal API
515 * @minor_ver:	Minor version of Data Path Management Command Portal API
516 *
517 * Return:	'0' on Success; Error code otherwise.
518 */
519int dpmcp_get_api_version(struct fsl_mc_io *mc_io,
520			  u32 cmd_flags,
521			  u16 *major_ver,
522			  u16 *minor_ver)
523{
524	struct mc_command cmd = { 0 };
525	int err;
526
527	/* prepare command */
528	cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_API_VERSION,
529					  cmd_flags, 0);
530
531	/* send command to mc */
532	err = mc_send_command(mc_io, &cmd);
533	if (err)
534		return err;
535
536	/* retrieve response parameters */
537	mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
538
539	return 0;
540}