Merge tag 'kvmarm-fixes-for-5.3' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-block.git] / drivers / bus / fsl-mc / dpmcp.c
CommitLineData
203e2de3 1// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
363b0cbf
SY
2/*
3 * Copyright 2013-2016 Freescale Semiconductor Inc.
197f4d6a 4 *
197f4d6a 5 */
409acdd0 6#include <linux/kernel.h>
6bd067c4 7#include <linux/fsl/mc.h>
d4e75132 8
39d14e4e 9#include "fsl-mc-private.h"
197f4d6a 10
e9bf3f20
GR
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
17 *
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
25 *
26 * Return: '0' on Success; Error code otherwise.
27 */
7a9a56be 28int dpmcp_open(struct fsl_mc_io *mc_io,
ba72f25b 29 u32 cmd_flags,
7a9a56be 30 int dpmcp_id,
ba72f25b 31 u16 *token)
197f4d6a 32{
5b04cede 33 struct fsl_mc_command cmd = { 0 };
9989b599 34 struct dpmcp_cmd_open *cmd_params;
197f4d6a
GR
35 int err;
36
37 /* prepare command */
38 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_OPEN,
7a9a56be 39 cmd_flags, 0);
9989b599
IR
40 cmd_params = (struct dpmcp_cmd_open *)cmd.params;
41 cmd_params->dpmcp_id = cpu_to_le32(dpmcp_id);
197f4d6a
GR
42
43 /* send command to mc*/
44 err = mc_send_command(mc_io, &cmd);
45 if (err)
46 return err;
47
48 /* retrieve response parameters */
9989b599 49 *token = mc_cmd_hdr_read_token(&cmd);
197f4d6a
GR
50
51 return err;
52}
53
e9bf3f20
GR
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
59 *
60 * After this function is called, no further operations are
61 * allowed on the object without opening a new control session.
62 *
63 * Return: '0' on Success; Error code otherwise.
64 */
7a9a56be 65int dpmcp_close(struct fsl_mc_io *mc_io,
ba72f25b
GR
66 u32 cmd_flags,
67 u16 token)
197f4d6a 68{
5b04cede 69 struct fsl_mc_command cmd = { 0 };
197f4d6a
GR
70
71 /* prepare command */
7a9a56be
GR
72 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_CLOSE,
73 cmd_flags, token);
197f4d6a
GR
74
75 /* send command to mc*/
76 return mc_send_command(mc_io, &cmd);
77}
78
e9bf3f20
GR
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
84 *
85 * Return: '0' on Success; Error code otherwise.
86 */
7a9a56be 87int dpmcp_reset(struct fsl_mc_io *mc_io,
ba72f25b
GR
88 u32 cmd_flags,
89 u16 token)
197f4d6a 90{
5b04cede 91 struct fsl_mc_command cmd = { 0 };
197f4d6a
GR
92
93 /* prepare command */
94 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_RESET,
7a9a56be 95 cmd_flags, token);
197f4d6a
GR
96
97 /* send command to mc*/
98 return mc_send_command(mc_io, &cmd);
99}