i2c: gpio: fault-injector: refactor incomplete transfer
[linux/fpc-iii.git] / drivers / bus / fsl-mc / dpcon.c
blob760555d7946e16bd130a11bfe686f0d66edca0e9
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>
8 #include <linux/fsl/mc.h>
10 #include "fsl-mc-private.h"
12 /**
13 * dpcon_open() - Open a control session for the specified object
14 * @mc_io: Pointer to MC portal's I/O object
15 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
16 * @dpcon_id: DPCON unique ID
17 * @token: Returned token; use in subsequent API calls
19 * This function can be used to open a control session for an
20 * already created object; an object may have been declared in
21 * the DPL or by calling the dpcon_create() function.
22 * This function returns a unique authentication token,
23 * associated with the specific object ID and the specific MC
24 * portal; this token must be used in all subsequent commands for
25 * this specific object.
27 * Return: '0' on Success; Error code otherwise.
29 int dpcon_open(struct fsl_mc_io *mc_io,
30 u32 cmd_flags,
31 int dpcon_id,
32 u16 *token)
34 struct fsl_mc_command cmd = { 0 };
35 struct dpcon_cmd_open *dpcon_cmd;
36 int err;
38 /* prepare command */
39 cmd.header = mc_encode_cmd_header(DPCON_CMDID_OPEN,
40 cmd_flags,
41 0);
42 dpcon_cmd = (struct dpcon_cmd_open *)cmd.params;
43 dpcon_cmd->dpcon_id = cpu_to_le32(dpcon_id);
45 /* send command to mc*/
46 err = mc_send_command(mc_io, &cmd);
47 if (err)
48 return err;
50 /* retrieve response parameters */
51 *token = mc_cmd_hdr_read_token(&cmd);
53 return 0;
55 EXPORT_SYMBOL_GPL(dpcon_open);
57 /**
58 * dpcon_close() - Close the control session of the object
59 * @mc_io: Pointer to MC portal's I/O object
60 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
61 * @token: Token of DPCON object
63 * After this function is called, no further operations are
64 * allowed on the object without opening a new control session.
66 * Return: '0' on Success; Error code otherwise.
68 int dpcon_close(struct fsl_mc_io *mc_io,
69 u32 cmd_flags,
70 u16 token)
72 struct fsl_mc_command cmd = { 0 };
74 /* prepare command */
75 cmd.header = mc_encode_cmd_header(DPCON_CMDID_CLOSE,
76 cmd_flags,
77 token);
79 /* send command to mc*/
80 return mc_send_command(mc_io, &cmd);
82 EXPORT_SYMBOL_GPL(dpcon_close);
84 /**
85 * dpcon_enable() - Enable the DPCON
86 * @mc_io: Pointer to MC portal's I/O object
87 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
88 * @token: Token of DPCON object
90 * Return: '0' on Success; Error code otherwise
92 int dpcon_enable(struct fsl_mc_io *mc_io,
93 u32 cmd_flags,
94 u16 token)
96 struct fsl_mc_command cmd = { 0 };
98 /* prepare command */
99 cmd.header = mc_encode_cmd_header(DPCON_CMDID_ENABLE,
100 cmd_flags,
101 token);
103 /* send command to mc*/
104 return mc_send_command(mc_io, &cmd);
106 EXPORT_SYMBOL_GPL(dpcon_enable);
109 * dpcon_disable() - Disable the DPCON
110 * @mc_io: Pointer to MC portal's I/O object
111 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
112 * @token: Token of DPCON object
114 * Return: '0' on Success; Error code otherwise
116 int dpcon_disable(struct fsl_mc_io *mc_io,
117 u32 cmd_flags,
118 u16 token)
120 struct fsl_mc_command cmd = { 0 };
122 /* prepare command */
123 cmd.header = mc_encode_cmd_header(DPCON_CMDID_DISABLE,
124 cmd_flags,
125 token);
127 /* send command to mc*/
128 return mc_send_command(mc_io, &cmd);
130 EXPORT_SYMBOL_GPL(dpcon_disable);
133 * dpcon_reset() - Reset the DPCON, returns the object to initial state.
134 * @mc_io: Pointer to MC portal's I/O object
135 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
136 * @token: Token of DPCON object
138 * Return: '0' on Success; Error code otherwise.
140 int dpcon_reset(struct fsl_mc_io *mc_io,
141 u32 cmd_flags,
142 u16 token)
144 struct fsl_mc_command cmd = { 0 };
146 /* prepare command */
147 cmd.header = mc_encode_cmd_header(DPCON_CMDID_RESET,
148 cmd_flags, token);
150 /* send command to mc*/
151 return mc_send_command(mc_io, &cmd);
153 EXPORT_SYMBOL_GPL(dpcon_reset);
156 * dpcon_get_attributes() - Retrieve DPCON attributes.
157 * @mc_io: Pointer to MC portal's I/O object
158 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
159 * @token: Token of DPCON object
160 * @attr: Object's attributes
162 * Return: '0' on Success; Error code otherwise.
164 int dpcon_get_attributes(struct fsl_mc_io *mc_io,
165 u32 cmd_flags,
166 u16 token,
167 struct dpcon_attr *attr)
169 struct fsl_mc_command cmd = { 0 };
170 struct dpcon_rsp_get_attr *dpcon_rsp;
171 int err;
173 /* prepare command */
174 cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_ATTR,
175 cmd_flags,
176 token);
178 /* send command to mc*/
179 err = mc_send_command(mc_io, &cmd);
180 if (err)
181 return err;
183 /* retrieve response parameters */
184 dpcon_rsp = (struct dpcon_rsp_get_attr *)cmd.params;
185 attr->id = le32_to_cpu(dpcon_rsp->id);
186 attr->qbman_ch_id = le16_to_cpu(dpcon_rsp->qbman_ch_id);
187 attr->num_priorities = dpcon_rsp->num_priorities;
189 return 0;
191 EXPORT_SYMBOL_GPL(dpcon_get_attributes);
194 * dpcon_set_notification() - Set DPCON notification destination
195 * @mc_io: Pointer to MC portal's I/O object
196 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
197 * @token: Token of DPCON object
198 * @cfg: Notification parameters
200 * Return: '0' on Success; Error code otherwise
202 int dpcon_set_notification(struct fsl_mc_io *mc_io,
203 u32 cmd_flags,
204 u16 token,
205 struct dpcon_notification_cfg *cfg)
207 struct fsl_mc_command cmd = { 0 };
208 struct dpcon_cmd_set_notification *dpcon_cmd;
210 /* prepare command */
211 cmd.header = mc_encode_cmd_header(DPCON_CMDID_SET_NOTIFICATION,
212 cmd_flags,
213 token);
214 dpcon_cmd = (struct dpcon_cmd_set_notification *)cmd.params;
215 dpcon_cmd->dpio_id = cpu_to_le32(cfg->dpio_id);
216 dpcon_cmd->priority = cfg->priority;
217 dpcon_cmd->user_ctx = cpu_to_le64(cfg->user_ctx);
219 /* send command to mc*/
220 return mc_send_command(mc_io, &cmd);
222 EXPORT_SYMBOL_GPL(dpcon_set_notification);