Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Copyright 2013-2016 Freescale Semiconductor Inc.
0004  * Copyright 2016-2018 NXP
0005  */
0006 
0007 #include <linux/fsl/mc.h>
0008 
0009 #include "dprtc.h"
0010 #include "dprtc-cmd.h"
0011 
0012 /**
0013  * dprtc_open() - Open a control session for the specified object.
0014  * @mc_io:  Pointer to MC portal's I/O object
0015  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0016  * @dprtc_id:   DPRTC unique ID
0017  * @token:  Returned token; use in subsequent API calls
0018  *
0019  * This function can be used to open a control session for an
0020  * already created object; an object may have been declared in
0021  * the DPL or by calling the dprtc_create function.
0022  * This function returns a unique authentication token,
0023  * associated with the specific object ID and the specific MC
0024  * portal; this token must be used in all subsequent commands for
0025  * this specific object
0026  *
0027  * Return:  '0' on Success; Error code otherwise.
0028  */
0029 int dprtc_open(struct fsl_mc_io *mc_io,
0030            u32 cmd_flags,
0031            int dprtc_id,
0032            u16 *token)
0033 {
0034     struct dprtc_cmd_open *cmd_params;
0035     struct fsl_mc_command cmd = { 0 };
0036     int err;
0037 
0038     cmd.header = mc_encode_cmd_header(DPRTC_CMDID_OPEN,
0039                       cmd_flags,
0040                       0);
0041     cmd_params = (struct dprtc_cmd_open *)cmd.params;
0042     cmd_params->dprtc_id = cpu_to_le32(dprtc_id);
0043 
0044     err = mc_send_command(mc_io, &cmd);
0045     if (err)
0046         return err;
0047 
0048     *token = mc_cmd_hdr_read_token(&cmd);
0049 
0050     return 0;
0051 }
0052 
0053 /**
0054  * dprtc_close() - Close the control session of the object
0055  * @mc_io:  Pointer to MC portal's I/O object
0056  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0057  * @token:  Token of DPRTC object
0058  *
0059  * After this function is called, no further operations are
0060  * allowed on the object without opening a new control session.
0061  *
0062  * Return:  '0' on Success; Error code otherwise.
0063  */
0064 int dprtc_close(struct fsl_mc_io *mc_io,
0065         u32 cmd_flags,
0066         u16 token)
0067 {
0068     struct fsl_mc_command cmd = { 0 };
0069 
0070     cmd.header = mc_encode_cmd_header(DPRTC_CMDID_CLOSE, cmd_flags,
0071                       token);
0072 
0073     return mc_send_command(mc_io, &cmd);
0074 }
0075 
0076 /**
0077  * dprtc_set_irq_enable() - Set overall interrupt state.
0078  * @mc_io:  Pointer to MC portal's I/O object
0079  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0080  * @token:  Token of DPRTC object
0081  * @irq_index:  The interrupt index to configure
0082  * @en:     Interrupt state - enable = 1, disable = 0
0083  *
0084  * Allows GPP software to control when interrupts are generated.
0085  * Each interrupt can have up to 32 causes.  The enable/disable control's the
0086  * overall interrupt state. if the interrupt is disabled no causes will cause
0087  * an interrupt.
0088  *
0089  * Return:  '0' on Success; Error code otherwise.
0090  */
0091 int dprtc_set_irq_enable(struct fsl_mc_io *mc_io,
0092              u32 cmd_flags,
0093              u16 token,
0094              u8 irq_index,
0095              u8 en)
0096 {
0097     struct dprtc_cmd_set_irq_enable *cmd_params;
0098     struct fsl_mc_command cmd = { 0 };
0099 
0100     cmd.header = mc_encode_cmd_header(DPRTC_CMDID_SET_IRQ_ENABLE,
0101                       cmd_flags,
0102                       token);
0103     cmd_params = (struct dprtc_cmd_set_irq_enable *)cmd.params;
0104     cmd_params->irq_index = irq_index;
0105     cmd_params->en = en;
0106 
0107     return mc_send_command(mc_io, &cmd);
0108 }
0109 
0110 /**
0111  * dprtc_get_irq_enable() - Get overall interrupt state
0112  * @mc_io:  Pointer to MC portal's I/O object
0113  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0114  * @token:  Token of DPRTC object
0115  * @irq_index:  The interrupt index to configure
0116  * @en:     Returned interrupt state - enable = 1, disable = 0
0117  *
0118  * Return:  '0' on Success; Error code otherwise.
0119  */
0120 int dprtc_get_irq_enable(struct fsl_mc_io *mc_io,
0121              u32 cmd_flags,
0122              u16 token,
0123              u8 irq_index,
0124              u8 *en)
0125 {
0126     struct dprtc_rsp_get_irq_enable *rsp_params;
0127     struct dprtc_cmd_get_irq *cmd_params;
0128     struct fsl_mc_command cmd = { 0 };
0129     int err;
0130 
0131     cmd.header = mc_encode_cmd_header(DPRTC_CMDID_GET_IRQ_ENABLE,
0132                       cmd_flags,
0133                       token);
0134     cmd_params = (struct dprtc_cmd_get_irq *)cmd.params;
0135     cmd_params->irq_index = irq_index;
0136 
0137     err = mc_send_command(mc_io, &cmd);
0138     if (err)
0139         return err;
0140 
0141     rsp_params = (struct dprtc_rsp_get_irq_enable *)cmd.params;
0142     *en = rsp_params->en;
0143 
0144     return 0;
0145 }
0146 
0147 /**
0148  * dprtc_set_irq_mask() - Set interrupt mask.
0149  * @mc_io:  Pointer to MC portal's I/O object
0150  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0151  * @token:  Token of DPRTC object
0152  * @irq_index:  The interrupt index to configure
0153  * @mask:   Event mask to trigger interrupt;
0154  *      each bit:
0155  *          0 = ignore event
0156  *          1 = consider event for asserting IRQ
0157  *
0158  * Every interrupt can have up to 32 causes and the interrupt model supports
0159  * masking/unmasking each cause independently
0160  *
0161  * Return:  '0' on Success; Error code otherwise.
0162  */
0163 int dprtc_set_irq_mask(struct fsl_mc_io *mc_io,
0164                u32 cmd_flags,
0165                u16 token,
0166                u8 irq_index,
0167                u32 mask)
0168 {
0169     struct dprtc_cmd_set_irq_mask *cmd_params;
0170     struct fsl_mc_command cmd = { 0 };
0171 
0172     cmd.header = mc_encode_cmd_header(DPRTC_CMDID_SET_IRQ_MASK,
0173                       cmd_flags,
0174                       token);
0175     cmd_params = (struct dprtc_cmd_set_irq_mask *)cmd.params;
0176     cmd_params->mask = cpu_to_le32(mask);
0177     cmd_params->irq_index = irq_index;
0178 
0179     return mc_send_command(mc_io, &cmd);
0180 }
0181 
0182 /**
0183  * dprtc_get_irq_mask() - Get interrupt mask.
0184  * @mc_io:  Pointer to MC portal's I/O object
0185  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0186  * @token:  Token of DPRTC object
0187  * @irq_index:  The interrupt index to configure
0188  * @mask:   Returned event mask to trigger interrupt
0189  *
0190  * Every interrupt can have up to 32 causes and the interrupt model supports
0191  * masking/unmasking each cause independently
0192  *
0193  * Return:  '0' on Success; Error code otherwise.
0194  */
0195 int dprtc_get_irq_mask(struct fsl_mc_io *mc_io,
0196                u32 cmd_flags,
0197                u16 token,
0198                u8 irq_index,
0199                u32 *mask)
0200 {
0201     struct dprtc_rsp_get_irq_mask *rsp_params;
0202     struct dprtc_cmd_get_irq *cmd_params;
0203     struct fsl_mc_command cmd = { 0 };
0204     int err;
0205 
0206     cmd.header = mc_encode_cmd_header(DPRTC_CMDID_GET_IRQ_MASK,
0207                       cmd_flags,
0208                       token);
0209     cmd_params = (struct dprtc_cmd_get_irq *)cmd.params;
0210     cmd_params->irq_index = irq_index;
0211 
0212     err = mc_send_command(mc_io, &cmd);
0213     if (err)
0214         return err;
0215 
0216     rsp_params = (struct dprtc_rsp_get_irq_mask *)cmd.params;
0217     *mask = le32_to_cpu(rsp_params->mask);
0218 
0219     return 0;
0220 }
0221 
0222 /**
0223  * dprtc_get_irq_status() - Get the current status of any pending interrupts.
0224  *
0225  * @mc_io:  Pointer to MC portal's I/O object
0226  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0227  * @token:  Token of DPRTC object
0228  * @irq_index:  The interrupt index to configure
0229  * @status: Returned interrupts status - one bit per cause:
0230  *          0 = no interrupt pending
0231  *          1 = interrupt pending
0232  *
0233  * Return:  '0' on Success; Error code otherwise.
0234  */
0235 int dprtc_get_irq_status(struct fsl_mc_io *mc_io,
0236              u32 cmd_flags,
0237              u16 token,
0238              u8 irq_index,
0239              u32 *status)
0240 {
0241     struct dprtc_cmd_get_irq_status *cmd_params;
0242     struct dprtc_rsp_get_irq_status *rsp_params;
0243     struct fsl_mc_command cmd = { 0 };
0244     int err;
0245 
0246     cmd.header = mc_encode_cmd_header(DPRTC_CMDID_GET_IRQ_STATUS,
0247                       cmd_flags,
0248                       token);
0249     cmd_params = (struct dprtc_cmd_get_irq_status *)cmd.params;
0250     cmd_params->status = cpu_to_le32(*status);
0251     cmd_params->irq_index = irq_index;
0252 
0253     err = mc_send_command(mc_io, &cmd);
0254     if (err)
0255         return err;
0256 
0257     rsp_params = (struct dprtc_rsp_get_irq_status *)cmd.params;
0258     *status = le32_to_cpu(rsp_params->status);
0259 
0260     return 0;
0261 }
0262 
0263 /**
0264  * dprtc_clear_irq_status() - Clear a pending interrupt's status
0265  *
0266  * @mc_io:  Pointer to MC portal's I/O object
0267  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0268  * @token:  Token of DPRTC object
0269  * @irq_index:  The interrupt index to configure
0270  * @status: Bits to clear (W1C) - one bit per cause:
0271  *          0 = don't change
0272  *          1 = clear status bit
0273  *
0274  * Return:  '0' on Success; Error code otherwise.
0275  */
0276 int dprtc_clear_irq_status(struct fsl_mc_io *mc_io,
0277                u32 cmd_flags,
0278                u16 token,
0279                u8 irq_index,
0280                u32 status)
0281 {
0282     struct dprtc_cmd_clear_irq_status *cmd_params;
0283     struct fsl_mc_command cmd = { 0 };
0284 
0285     cmd.header = mc_encode_cmd_header(DPRTC_CMDID_CLEAR_IRQ_STATUS,
0286                       cmd_flags,
0287                       token);
0288     cmd_params = (struct dprtc_cmd_clear_irq_status *)cmd.params;
0289     cmd_params->irq_index = irq_index;
0290     cmd_params->status = cpu_to_le32(status);
0291 
0292     return mc_send_command(mc_io, &cmd);
0293 }