xref: /OK3568_Linux_fs/kernel/drivers/bus/fsl-mc/dpmcp.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright 2013-2016 Freescale Semiconductor Inc.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun #include <linux/kernel.h>
7*4882a593Smuzhiyun #include <linux/fsl/mc.h>
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #include "fsl-mc-private.h"
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun /**
12*4882a593Smuzhiyun  * dpmcp_open() - Open a control session for the specified object.
13*4882a593Smuzhiyun  * @mc_io:	Pointer to MC portal's I/O object
14*4882a593Smuzhiyun  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
15*4882a593Smuzhiyun  * @dpmcp_id:	DPMCP unique ID
16*4882a593Smuzhiyun  * @token:	Returned token; use in subsequent API calls
17*4882a593Smuzhiyun  *
18*4882a593Smuzhiyun  * This function can be used to open a control session for an
19*4882a593Smuzhiyun  * already created object; an object may have been declared in
20*4882a593Smuzhiyun  * the DPL or by calling the dpmcp_create function.
21*4882a593Smuzhiyun  * This function returns a unique authentication token,
22*4882a593Smuzhiyun  * associated with the specific object ID and the specific MC
23*4882a593Smuzhiyun  * portal; this token must be used in all subsequent commands for
24*4882a593Smuzhiyun  * this specific object
25*4882a593Smuzhiyun  *
26*4882a593Smuzhiyun  * Return:	'0' on Success; Error code otherwise.
27*4882a593Smuzhiyun  */
dpmcp_open(struct fsl_mc_io * mc_io,u32 cmd_flags,int dpmcp_id,u16 * token)28*4882a593Smuzhiyun int dpmcp_open(struct fsl_mc_io *mc_io,
29*4882a593Smuzhiyun 	       u32 cmd_flags,
30*4882a593Smuzhiyun 	       int dpmcp_id,
31*4882a593Smuzhiyun 	       u16 *token)
32*4882a593Smuzhiyun {
33*4882a593Smuzhiyun 	struct fsl_mc_command cmd = { 0 };
34*4882a593Smuzhiyun 	struct dpmcp_cmd_open *cmd_params;
35*4882a593Smuzhiyun 	int err;
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun 	/* prepare command */
38*4882a593Smuzhiyun 	cmd.header = mc_encode_cmd_header(DPMCP_CMDID_OPEN,
39*4882a593Smuzhiyun 					  cmd_flags, 0);
40*4882a593Smuzhiyun 	cmd_params = (struct dpmcp_cmd_open *)cmd.params;
41*4882a593Smuzhiyun 	cmd_params->dpmcp_id = cpu_to_le32(dpmcp_id);
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun 	/* send command to mc*/
44*4882a593Smuzhiyun 	err = mc_send_command(mc_io, &cmd);
45*4882a593Smuzhiyun 	if (err)
46*4882a593Smuzhiyun 		return err;
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun 	/* retrieve response parameters */
49*4882a593Smuzhiyun 	*token = mc_cmd_hdr_read_token(&cmd);
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun 	return err;
52*4882a593Smuzhiyun }
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun /**
55*4882a593Smuzhiyun  * dpmcp_close() - Close the control session of the object
56*4882a593Smuzhiyun  * @mc_io:	Pointer to MC portal's I/O object
57*4882a593Smuzhiyun  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
58*4882a593Smuzhiyun  * @token:	Token of DPMCP object
59*4882a593Smuzhiyun  *
60*4882a593Smuzhiyun  * After this function is called, no further operations are
61*4882a593Smuzhiyun  * allowed on the object without opening a new control session.
62*4882a593Smuzhiyun  *
63*4882a593Smuzhiyun  * Return:	'0' on Success; Error code otherwise.
64*4882a593Smuzhiyun  */
dpmcp_close(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token)65*4882a593Smuzhiyun int dpmcp_close(struct fsl_mc_io *mc_io,
66*4882a593Smuzhiyun 		u32 cmd_flags,
67*4882a593Smuzhiyun 		u16 token)
68*4882a593Smuzhiyun {
69*4882a593Smuzhiyun 	struct fsl_mc_command cmd = { 0 };
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun 	/* prepare command */
72*4882a593Smuzhiyun 	cmd.header = mc_encode_cmd_header(DPMCP_CMDID_CLOSE,
73*4882a593Smuzhiyun 					  cmd_flags, token);
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun 	/* send command to mc*/
76*4882a593Smuzhiyun 	return mc_send_command(mc_io, &cmd);
77*4882a593Smuzhiyun }
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun /**
80*4882a593Smuzhiyun  * dpmcp_reset() - Reset the DPMCP, returns the object to initial state.
81*4882a593Smuzhiyun  * @mc_io:	Pointer to MC portal's I/O object
82*4882a593Smuzhiyun  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
83*4882a593Smuzhiyun  * @token:	Token of DPMCP object
84*4882a593Smuzhiyun  *
85*4882a593Smuzhiyun  * Return:	'0' on Success; Error code otherwise.
86*4882a593Smuzhiyun  */
dpmcp_reset(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token)87*4882a593Smuzhiyun int dpmcp_reset(struct fsl_mc_io *mc_io,
88*4882a593Smuzhiyun 		u32 cmd_flags,
89*4882a593Smuzhiyun 		u16 token)
90*4882a593Smuzhiyun {
91*4882a593Smuzhiyun 	struct fsl_mc_command cmd = { 0 };
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun 	/* prepare command */
94*4882a593Smuzhiyun 	cmd.header = mc_encode_cmd_header(DPMCP_CMDID_RESET,
95*4882a593Smuzhiyun 					  cmd_flags, token);
96*4882a593Smuzhiyun 
97*4882a593Smuzhiyun 	/* send command to mc*/
98*4882a593Smuzhiyun 	return mc_send_command(mc_io, &cmd);
99*4882a593Smuzhiyun }
100