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