1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright 2013-2016 Freescale Semiconductor Inc.
4 * Copyright 2016-2018 NXP
7 #include <linux/fsl/mc.h>
10 #include "dprtc-cmd.h"
13 * dprtc_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 * @dprtc_id: DPRTC 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 dprtc_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 dprtc_open(struct fsl_mc_io
*mc_io
,
34 struct dprtc_cmd_open
*cmd_params
;
35 struct fsl_mc_command cmd
= { 0 };
38 cmd
.header
= mc_encode_cmd_header(DPRTC_CMDID_OPEN
,
41 cmd_params
= (struct dprtc_cmd_open
*)cmd
.params
;
42 cmd_params
->dprtc_id
= cpu_to_le32(dprtc_id
);
44 err
= mc_send_command(mc_io
, &cmd
);
48 *token
= mc_cmd_hdr_read_token(&cmd
);
54 * dprtc_close() - Close the control session of the object
55 * @mc_io: Pointer to MC portal's I/O object
56 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
57 * @token: Token of DPRTC object
59 * After this function is called, no further operations are
60 * allowed on the object without opening a new control session.
62 * Return: '0' on Success; Error code otherwise.
64 int dprtc_close(struct fsl_mc_io
*mc_io
,
68 struct fsl_mc_command cmd
= { 0 };
70 cmd
.header
= mc_encode_cmd_header(DPRTC_CMDID_CLOSE
, cmd_flags
,
73 return mc_send_command(mc_io
, &cmd
);
77 * dprtc_set_irq_enable() - Set overall interrupt state.
78 * @mc_io: Pointer to MC portal's I/O object
79 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
80 * @token: Token of DPRTC object
81 * @irq_index: The interrupt index to configure
82 * @en: Interrupt state - enable = 1, disable = 0
84 * Allows GPP software to control when interrupts are generated.
85 * Each interrupt can have up to 32 causes. The enable/disable control's the
86 * overall interrupt state. if the interrupt is disabled no causes will cause
89 * Return: '0' on Success; Error code otherwise.
91 int dprtc_set_irq_enable(struct fsl_mc_io
*mc_io
,
97 struct dprtc_cmd_set_irq_enable
*cmd_params
;
98 struct fsl_mc_command cmd
= { 0 };
100 cmd
.header
= mc_encode_cmd_header(DPRTC_CMDID_SET_IRQ_ENABLE
,
103 cmd_params
= (struct dprtc_cmd_set_irq_enable
*)cmd
.params
;
104 cmd_params
->irq_index
= irq_index
;
107 return mc_send_command(mc_io
, &cmd
);
111 * dprtc_get_irq_enable() - Get overall interrupt state
112 * @mc_io: Pointer to MC portal's I/O object
113 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
114 * @token: Token of DPRTC object
115 * @irq_index: The interrupt index to configure
116 * @en: Returned interrupt state - enable = 1, disable = 0
118 * Return: '0' on Success; Error code otherwise.
120 int dprtc_get_irq_enable(struct fsl_mc_io
*mc_io
,
126 struct dprtc_rsp_get_irq_enable
*rsp_params
;
127 struct dprtc_cmd_get_irq
*cmd_params
;
128 struct fsl_mc_command cmd
= { 0 };
131 cmd
.header
= mc_encode_cmd_header(DPRTC_CMDID_GET_IRQ_ENABLE
,
134 cmd_params
= (struct dprtc_cmd_get_irq
*)cmd
.params
;
135 cmd_params
->irq_index
= irq_index
;
137 err
= mc_send_command(mc_io
, &cmd
);
141 rsp_params
= (struct dprtc_rsp_get_irq_enable
*)cmd
.params
;
142 *en
= rsp_params
->en
;
148 * dprtc_set_irq_mask() - Set interrupt mask.
149 * @mc_io: Pointer to MC portal's I/O object
150 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
151 * @token: Token of DPRTC object
152 * @irq_index: The interrupt index to configure
153 * @mask: Event mask to trigger interrupt;
156 * 1 = consider event for asserting IRQ
158 * Every interrupt can have up to 32 causes and the interrupt model supports
159 * masking/unmasking each cause independently
161 * Return: '0' on Success; Error code otherwise.
163 int dprtc_set_irq_mask(struct fsl_mc_io
*mc_io
,
169 struct dprtc_cmd_set_irq_mask
*cmd_params
;
170 struct fsl_mc_command cmd
= { 0 };
172 cmd
.header
= mc_encode_cmd_header(DPRTC_CMDID_SET_IRQ_MASK
,
175 cmd_params
= (struct dprtc_cmd_set_irq_mask
*)cmd
.params
;
176 cmd_params
->mask
= cpu_to_le32(mask
);
177 cmd_params
->irq_index
= irq_index
;
179 return mc_send_command(mc_io
, &cmd
);
183 * dprtc_get_irq_mask() - Get interrupt mask.
184 * @mc_io: Pointer to MC portal's I/O object
185 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
186 * @token: Token of DPRTC object
187 * @irq_index: The interrupt index to configure
188 * @mask: Returned event mask to trigger interrupt
190 * Every interrupt can have up to 32 causes and the interrupt model supports
191 * masking/unmasking each cause independently
193 * Return: '0' on Success; Error code otherwise.
195 int dprtc_get_irq_mask(struct fsl_mc_io
*mc_io
,
201 struct dprtc_rsp_get_irq_mask
*rsp_params
;
202 struct dprtc_cmd_get_irq
*cmd_params
;
203 struct fsl_mc_command cmd
= { 0 };
206 cmd
.header
= mc_encode_cmd_header(DPRTC_CMDID_GET_IRQ_MASK
,
209 cmd_params
= (struct dprtc_cmd_get_irq
*)cmd
.params
;
210 cmd_params
->irq_index
= irq_index
;
212 err
= mc_send_command(mc_io
, &cmd
);
216 rsp_params
= (struct dprtc_rsp_get_irq_mask
*)cmd
.params
;
217 *mask
= le32_to_cpu(rsp_params
->mask
);
223 * dprtc_get_irq_status() - Get the current status of any pending interrupts.
225 * @mc_io: Pointer to MC portal's I/O object
226 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
227 * @token: Token of DPRTC object
228 * @irq_index: The interrupt index to configure
229 * @status: Returned interrupts status - one bit per cause:
230 * 0 = no interrupt pending
231 * 1 = interrupt pending
233 * Return: '0' on Success; Error code otherwise.
235 int dprtc_get_irq_status(struct fsl_mc_io
*mc_io
,
241 struct dprtc_cmd_get_irq_status
*cmd_params
;
242 struct dprtc_rsp_get_irq_status
*rsp_params
;
243 struct fsl_mc_command cmd
= { 0 };
246 cmd
.header
= mc_encode_cmd_header(DPRTC_CMDID_GET_IRQ_STATUS
,
249 cmd_params
= (struct dprtc_cmd_get_irq_status
*)cmd
.params
;
250 cmd_params
->status
= cpu_to_le32(*status
);
251 cmd_params
->irq_index
= irq_index
;
253 err
= mc_send_command(mc_io
, &cmd
);
257 rsp_params
= (struct dprtc_rsp_get_irq_status
*)cmd
.params
;
258 *status
= le32_to_cpu(rsp_params
->status
);
264 * dprtc_clear_irq_status() - Clear a pending interrupt's status
266 * @mc_io: Pointer to MC portal's I/O object
267 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
268 * @token: Token of DPRTC object
269 * @irq_index: The interrupt index to configure
270 * @status: Bits to clear (W1C) - one bit per cause:
272 * 1 = clear status bit
274 * Return: '0' on Success; Error code otherwise.
276 int dprtc_clear_irq_status(struct fsl_mc_io
*mc_io
,
282 struct dprtc_cmd_clear_irq_status
*cmd_params
;
283 struct fsl_mc_command cmd
= { 0 };
285 cmd
.header
= mc_encode_cmd_header(DPRTC_CMDID_CLEAR_IRQ_STATUS
,
288 cmd_params
= (struct dprtc_cmd_clear_irq_status
*)cmd
.params
;
289 cmd_params
->irq_index
= irq_index
;
290 cmd_params
->status
= cpu_to_le32(status
);
292 return mc_send_command(mc_io
, &cmd
);