WIP FPC-III support
[linux/fpc-iii.git] / drivers / bus / fsl-mc / dpcon.c
blob97b6fa605e627f36e1e553388211e6577d0b8749
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 * dpcon_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 * @dpcon_id: DPCON 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 dpcon_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 dpcon_open(struct fsl_mc_io *mc_io,
29 u32 cmd_flags,
30 int dpcon_id,
31 u16 *token)
33 struct fsl_mc_command cmd = { 0 };
34 struct dpcon_cmd_open *dpcon_cmd;
35 int err;
37 /* prepare command */
38 cmd.header = mc_encode_cmd_header(DPCON_CMDID_OPEN,
39 cmd_flags,
40 0);
41 dpcon_cmd = (struct dpcon_cmd_open *)cmd.params;
42 dpcon_cmd->dpcon_id = cpu_to_le32(dpcon_id);
44 /* send command to mc*/
45 err = mc_send_command(mc_io, &cmd);
46 if (err)
47 return err;
49 /* retrieve response parameters */
50 *token = mc_cmd_hdr_read_token(&cmd);
52 return 0;
54 EXPORT_SYMBOL_GPL(dpcon_open);
56 /**
57 * dpcon_close() - Close the control session of the object
58 * @mc_io: Pointer to MC portal's I/O object
59 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
60 * @token: Token of DPCON object
62 * After this function is called, no further operations are
63 * allowed on the object without opening a new control session.
65 * Return: '0' on Success; Error code otherwise.
67 int dpcon_close(struct fsl_mc_io *mc_io,
68 u32 cmd_flags,
69 u16 token)
71 struct fsl_mc_command cmd = { 0 };
73 /* prepare command */
74 cmd.header = mc_encode_cmd_header(DPCON_CMDID_CLOSE,
75 cmd_flags,
76 token);
78 /* send command to mc*/
79 return mc_send_command(mc_io, &cmd);
81 EXPORT_SYMBOL_GPL(dpcon_close);
83 /**
84 * dpcon_enable() - Enable the DPCON
85 * @mc_io: Pointer to MC portal's I/O object
86 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
87 * @token: Token of DPCON object
89 * Return: '0' on Success; Error code otherwise
91 int dpcon_enable(struct fsl_mc_io *mc_io,
92 u32 cmd_flags,
93 u16 token)
95 struct fsl_mc_command cmd = { 0 };
97 /* prepare command */
98 cmd.header = mc_encode_cmd_header(DPCON_CMDID_ENABLE,
99 cmd_flags,
100 token);
102 /* send command to mc*/
103 return mc_send_command(mc_io, &cmd);
105 EXPORT_SYMBOL_GPL(dpcon_enable);
108 * dpcon_disable() - Disable the DPCON
109 * @mc_io: Pointer to MC portal's I/O object
110 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
111 * @token: Token of DPCON object
113 * Return: '0' on Success; Error code otherwise
115 int dpcon_disable(struct fsl_mc_io *mc_io,
116 u32 cmd_flags,
117 u16 token)
119 struct fsl_mc_command cmd = { 0 };
121 /* prepare command */
122 cmd.header = mc_encode_cmd_header(DPCON_CMDID_DISABLE,
123 cmd_flags,
124 token);
126 /* send command to mc*/
127 return mc_send_command(mc_io, &cmd);
129 EXPORT_SYMBOL_GPL(dpcon_disable);
132 * dpcon_reset() - Reset the DPCON, returns the object to initial state.
133 * @mc_io: Pointer to MC portal's I/O object
134 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
135 * @token: Token of DPCON object
137 * Return: '0' on Success; Error code otherwise.
139 int dpcon_reset(struct fsl_mc_io *mc_io,
140 u32 cmd_flags,
141 u16 token)
143 struct fsl_mc_command cmd = { 0 };
145 /* prepare command */
146 cmd.header = mc_encode_cmd_header(DPCON_CMDID_RESET,
147 cmd_flags, token);
149 /* send command to mc*/
150 return mc_send_command(mc_io, &cmd);
152 EXPORT_SYMBOL_GPL(dpcon_reset);
155 * dpcon_get_attributes() - Retrieve DPCON attributes.
156 * @mc_io: Pointer to MC portal's I/O object
157 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
158 * @token: Token of DPCON object
159 * @attr: Object's attributes
161 * Return: '0' on Success; Error code otherwise.
163 int dpcon_get_attributes(struct fsl_mc_io *mc_io,
164 u32 cmd_flags,
165 u16 token,
166 struct dpcon_attr *attr)
168 struct fsl_mc_command cmd = { 0 };
169 struct dpcon_rsp_get_attr *dpcon_rsp;
170 int err;
172 /* prepare command */
173 cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_ATTR,
174 cmd_flags,
175 token);
177 /* send command to mc*/
178 err = mc_send_command(mc_io, &cmd);
179 if (err)
180 return err;
182 /* retrieve response parameters */
183 dpcon_rsp = (struct dpcon_rsp_get_attr *)cmd.params;
184 attr->id = le32_to_cpu(dpcon_rsp->id);
185 attr->qbman_ch_id = le16_to_cpu(dpcon_rsp->qbman_ch_id);
186 attr->num_priorities = dpcon_rsp->num_priorities;
188 return 0;
190 EXPORT_SYMBOL_GPL(dpcon_get_attributes);
193 * dpcon_set_notification() - Set DPCON notification destination
194 * @mc_io: Pointer to MC portal's I/O object
195 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
196 * @token: Token of DPCON object
197 * @cfg: Notification parameters
199 * Return: '0' on Success; Error code otherwise
201 int dpcon_set_notification(struct fsl_mc_io *mc_io,
202 u32 cmd_flags,
203 u16 token,
204 struct dpcon_notification_cfg *cfg)
206 struct fsl_mc_command cmd = { 0 };
207 struct dpcon_cmd_set_notification *dpcon_cmd;
209 /* prepare command */
210 cmd.header = mc_encode_cmd_header(DPCON_CMDID_SET_NOTIFICATION,
211 cmd_flags,
212 token);
213 dpcon_cmd = (struct dpcon_cmd_set_notification *)cmd.params;
214 dpcon_cmd->dpio_id = cpu_to_le32(cfg->dpio_id);
215 dpcon_cmd->priority = cfg->priority;
216 dpcon_cmd->user_ctx = cpu_to_le64(cfg->user_ctx);
218 /* send command to mc*/
219 return mc_send_command(mc_io, &cmd);
221 EXPORT_SYMBOL_GPL(dpcon_set_notification);