WIP FPC-III support
[linux/fpc-iii.git] / drivers / bus / fsl-mc / dpbp.c
blob9003cd3698a57d0bb22d07d665bd13dced6547a3
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 * dpbp_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 * @dpbp_id: DPBP 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 dpbp_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 dpbp_open(struct fsl_mc_io *mc_io,
29 u32 cmd_flags,
30 int dpbp_id,
31 u16 *token)
33 struct fsl_mc_command cmd = { 0 };
34 struct dpbp_cmd_open *cmd_params;
35 int err;
37 /* prepare command */
38 cmd.header = mc_encode_cmd_header(DPBP_CMDID_OPEN,
39 cmd_flags, 0);
40 cmd_params = (struct dpbp_cmd_open *)cmd.params;
41 cmd_params->dpbp_id = cpu_to_le32(dpbp_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;
53 EXPORT_SYMBOL_GPL(dpbp_open);
55 /**
56 * dpbp_close() - Close the control session of the object
57 * @mc_io: Pointer to MC portal's I/O object
58 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
59 * @token: Token of DPBP object
61 * After this function is called, no further operations are
62 * allowed on the object without opening a new control session.
64 * Return: '0' on Success; Error code otherwise.
66 int dpbp_close(struct fsl_mc_io *mc_io,
67 u32 cmd_flags,
68 u16 token)
70 struct fsl_mc_command cmd = { 0 };
72 /* prepare command */
73 cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLOSE, cmd_flags,
74 token);
76 /* send command to mc*/
77 return mc_send_command(mc_io, &cmd);
79 EXPORT_SYMBOL_GPL(dpbp_close);
81 /**
82 * dpbp_enable() - Enable the DPBP.
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 DPBP object
87 * Return: '0' on Success; Error code otherwise.
89 int dpbp_enable(struct fsl_mc_io *mc_io,
90 u32 cmd_flags,
91 u16 token)
93 struct fsl_mc_command cmd = { 0 };
95 /* prepare command */
96 cmd.header = mc_encode_cmd_header(DPBP_CMDID_ENABLE, cmd_flags,
97 token);
99 /* send command to mc*/
100 return mc_send_command(mc_io, &cmd);
102 EXPORT_SYMBOL_GPL(dpbp_enable);
105 * dpbp_disable() - Disable the DPBP.
106 * @mc_io: Pointer to MC portal's I/O object
107 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
108 * @token: Token of DPBP object
110 * Return: '0' on Success; Error code otherwise.
112 int dpbp_disable(struct fsl_mc_io *mc_io,
113 u32 cmd_flags,
114 u16 token)
116 struct fsl_mc_command cmd = { 0 };
118 /* prepare command */
119 cmd.header = mc_encode_cmd_header(DPBP_CMDID_DISABLE,
120 cmd_flags, token);
122 /* send command to mc*/
123 return mc_send_command(mc_io, &cmd);
125 EXPORT_SYMBOL_GPL(dpbp_disable);
128 * dpbp_reset() - Reset the DPBP, returns the object to initial state.
129 * @mc_io: Pointer to MC portal's I/O object
130 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
131 * @token: Token of DPBP object
133 * Return: '0' on Success; Error code otherwise.
135 int dpbp_reset(struct fsl_mc_io *mc_io,
136 u32 cmd_flags,
137 u16 token)
139 struct fsl_mc_command cmd = { 0 };
141 /* prepare command */
142 cmd.header = mc_encode_cmd_header(DPBP_CMDID_RESET,
143 cmd_flags, token);
145 /* send command to mc*/
146 return mc_send_command(mc_io, &cmd);
148 EXPORT_SYMBOL_GPL(dpbp_reset);
151 * dpbp_get_attributes - Retrieve DPBP attributes.
153 * @mc_io: Pointer to MC portal's I/O object
154 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
155 * @token: Token of DPBP object
156 * @attr: Returned object's attributes
158 * Return: '0' on Success; Error code otherwise.
160 int dpbp_get_attributes(struct fsl_mc_io *mc_io,
161 u32 cmd_flags,
162 u16 token,
163 struct dpbp_attr *attr)
165 struct fsl_mc_command cmd = { 0 };
166 struct dpbp_rsp_get_attributes *rsp_params;
167 int err;
169 /* prepare command */
170 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_ATTR,
171 cmd_flags, token);
173 /* send command to mc*/
174 err = mc_send_command(mc_io, &cmd);
175 if (err)
176 return err;
178 /* retrieve response parameters */
179 rsp_params = (struct dpbp_rsp_get_attributes *)cmd.params;
180 attr->bpid = le16_to_cpu(rsp_params->bpid);
181 attr->id = le32_to_cpu(rsp_params->id);
183 return 0;
185 EXPORT_SYMBOL_GPL(dpbp_get_attributes);