Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
0004  */
0005 
0006 #ifndef _LINUX_QCOM_GENI_SE
0007 #define _LINUX_QCOM_GENI_SE
0008 
0009 #include <linux/interconnect.h>
0010 
0011 /**
0012  * enum geni_se_xfer_mode: Transfer modes supported by Serial Engines
0013  *
0014  * @GENI_SE_INVALID: Invalid mode
0015  * @GENI_SE_FIFO: FIFO mode. Data is transferred with SE FIFO
0016  * by programmed IO method
0017  * @GENI_SE_DMA: Serial Engine DMA mode. Data is transferred
0018  * with SE by DMAengine internal to SE
0019  * @GENI_GPI_DMA: GPI DMA mode. Data is transferred using a DMAengine
0020  * configured by a firmware residing on a GSI engine. This DMA name is
0021  * interchangeably used as GSI or GPI which seem to imply the same DMAengine
0022  */
0023 
0024 enum geni_se_xfer_mode {
0025     GENI_SE_INVALID,
0026     GENI_SE_FIFO,
0027     GENI_SE_DMA,
0028     GENI_GPI_DMA,
0029 };
0030 
0031 /* Protocols supported by GENI Serial Engines */
0032 enum geni_se_protocol_type {
0033     GENI_SE_NONE,
0034     GENI_SE_SPI,
0035     GENI_SE_UART,
0036     GENI_SE_I2C,
0037     GENI_SE_I3C,
0038 };
0039 
0040 struct geni_wrapper;
0041 struct clk;
0042 
0043 enum geni_icc_path_index {
0044     GENI_TO_CORE,
0045     CPU_TO_GENI,
0046     GENI_TO_DDR
0047 };
0048 
0049 struct geni_icc_path {
0050     struct icc_path *path;
0051     unsigned int avg_bw;
0052 };
0053 
0054 /**
0055  * struct geni_se - GENI Serial Engine
0056  * @base:       Base Address of the Serial Engine's register block
0057  * @dev:        Pointer to the Serial Engine device
0058  * @wrapper:        Pointer to the parent QUP Wrapper core
0059  * @clk:        Handle to the core serial engine clock
0060  * @num_clk_levels: Number of valid clock levels in clk_perf_tbl
0061  * @clk_perf_tbl:   Table of clock frequency input to serial engine clock
0062  * @icc_paths:      Array of ICC paths for SE
0063  */
0064 struct geni_se {
0065     void __iomem *base;
0066     struct device *dev;
0067     struct geni_wrapper *wrapper;
0068     struct clk *clk;
0069     unsigned int num_clk_levels;
0070     unsigned long *clk_perf_tbl;
0071     struct geni_icc_path icc_paths[3];
0072 };
0073 
0074 /* Common SE registers */
0075 #define GENI_FORCE_DEFAULT_REG      0x20
0076 #define SE_GENI_STATUS          0x40
0077 #define GENI_SER_M_CLK_CFG      0x48
0078 #define GENI_SER_S_CLK_CFG      0x4c
0079 #define GENI_IF_DISABLE_RO      0x64
0080 #define GENI_FW_REVISION_RO     0x68
0081 #define SE_GENI_CLK_SEL         0x7c
0082 #define SE_GENI_DMA_MODE_EN     0x258
0083 #define SE_GENI_M_CMD0          0x600
0084 #define SE_GENI_M_CMD_CTRL_REG      0x604
0085 #define SE_GENI_M_IRQ_STATUS        0x610
0086 #define SE_GENI_M_IRQ_EN        0x614
0087 #define SE_GENI_M_IRQ_CLEAR     0x618
0088 #define SE_GENI_S_CMD0          0x630
0089 #define SE_GENI_S_CMD_CTRL_REG      0x634
0090 #define SE_GENI_S_IRQ_STATUS        0x640
0091 #define SE_GENI_S_IRQ_EN        0x644
0092 #define SE_GENI_S_IRQ_CLEAR     0x648
0093 #define SE_GENI_TX_FIFOn        0x700
0094 #define SE_GENI_RX_FIFOn        0x780
0095 #define SE_GENI_TX_FIFO_STATUS      0x800
0096 #define SE_GENI_RX_FIFO_STATUS      0x804
0097 #define SE_GENI_TX_WATERMARK_REG    0x80c
0098 #define SE_GENI_RX_WATERMARK_REG    0x810
0099 #define SE_GENI_RX_RFR_WATERMARK_REG    0x814
0100 #define SE_GENI_IOS         0x908
0101 #define SE_DMA_TX_IRQ_STAT      0xc40
0102 #define SE_DMA_TX_IRQ_CLR       0xc44
0103 #define SE_DMA_TX_FSM_RST       0xc58
0104 #define SE_DMA_RX_IRQ_STAT      0xd40
0105 #define SE_DMA_RX_IRQ_CLR       0xd44
0106 #define SE_DMA_RX_FSM_RST       0xd58
0107 #define SE_HW_PARAM_0           0xe24
0108 #define SE_HW_PARAM_1           0xe28
0109 
0110 /* GENI_FORCE_DEFAULT_REG fields */
0111 #define FORCE_DEFAULT   BIT(0)
0112 
0113 /* GENI_STATUS fields */
0114 #define M_GENI_CMD_ACTIVE       BIT(0)
0115 #define S_GENI_CMD_ACTIVE       BIT(12)
0116 
0117 /* GENI_SER_M_CLK_CFG/GENI_SER_S_CLK_CFG */
0118 #define SER_CLK_EN          BIT(0)
0119 #define CLK_DIV_MSK         GENMASK(15, 4)
0120 #define CLK_DIV_SHFT            4
0121 
0122 /* GENI_IF_DISABLE_RO fields */
0123 #define FIFO_IF_DISABLE         (BIT(0))
0124 
0125 /* GENI_FW_REVISION_RO fields */
0126 #define FW_REV_PROTOCOL_MSK     GENMASK(15, 8)
0127 #define FW_REV_PROTOCOL_SHFT        8
0128 
0129 /* GENI_CLK_SEL fields */
0130 #define CLK_SEL_MSK         GENMASK(2, 0)
0131 
0132 /* SE_GENI_DMA_MODE_EN */
0133 #define GENI_DMA_MODE_EN        BIT(0)
0134 
0135 /* GENI_M_CMD0 fields */
0136 #define M_OPCODE_MSK            GENMASK(31, 27)
0137 #define M_OPCODE_SHFT           27
0138 #define M_PARAMS_MSK            GENMASK(26, 0)
0139 
0140 /* GENI_M_CMD_CTRL_REG */
0141 #define M_GENI_CMD_CANCEL       BIT(2)
0142 #define M_GENI_CMD_ABORT        BIT(1)
0143 #define M_GENI_DISABLE          BIT(0)
0144 
0145 /* GENI_S_CMD0 fields */
0146 #define S_OPCODE_MSK            GENMASK(31, 27)
0147 #define S_OPCODE_SHFT           27
0148 #define S_PARAMS_MSK            GENMASK(26, 0)
0149 
0150 /* GENI_S_CMD_CTRL_REG */
0151 #define S_GENI_CMD_CANCEL       BIT(2)
0152 #define S_GENI_CMD_ABORT        BIT(1)
0153 #define S_GENI_DISABLE          BIT(0)
0154 
0155 /* GENI_M_IRQ_EN fields */
0156 #define M_CMD_DONE_EN           BIT(0)
0157 #define M_CMD_OVERRUN_EN        BIT(1)
0158 #define M_ILLEGAL_CMD_EN        BIT(2)
0159 #define M_CMD_FAILURE_EN        BIT(3)
0160 #define M_CMD_CANCEL_EN         BIT(4)
0161 #define M_CMD_ABORT_EN          BIT(5)
0162 #define M_TIMESTAMP_EN          BIT(6)
0163 #define M_RX_IRQ_EN         BIT(7)
0164 #define M_GP_SYNC_IRQ_0_EN      BIT(8)
0165 #define M_GP_IRQ_0_EN           BIT(9)
0166 #define M_GP_IRQ_1_EN           BIT(10)
0167 #define M_GP_IRQ_2_EN           BIT(11)
0168 #define M_GP_IRQ_3_EN           BIT(12)
0169 #define M_GP_IRQ_4_EN           BIT(13)
0170 #define M_GP_IRQ_5_EN           BIT(14)
0171 #define M_IO_DATA_DEASSERT_EN       BIT(22)
0172 #define M_IO_DATA_ASSERT_EN     BIT(23)
0173 #define M_RX_FIFO_RD_ERR_EN     BIT(24)
0174 #define M_RX_FIFO_WR_ERR_EN     BIT(25)
0175 #define M_RX_FIFO_WATERMARK_EN      BIT(26)
0176 #define M_RX_FIFO_LAST_EN       BIT(27)
0177 #define M_TX_FIFO_RD_ERR_EN     BIT(28)
0178 #define M_TX_FIFO_WR_ERR_EN     BIT(29)
0179 #define M_TX_FIFO_WATERMARK_EN      BIT(30)
0180 #define M_SEC_IRQ_EN            BIT(31)
0181 #define M_COMMON_GENI_M_IRQ_EN  (GENMASK(6, 1) | \
0182                 M_IO_DATA_DEASSERT_EN | \
0183                 M_IO_DATA_ASSERT_EN | M_RX_FIFO_RD_ERR_EN | \
0184                 M_RX_FIFO_WR_ERR_EN | M_TX_FIFO_RD_ERR_EN | \
0185                 M_TX_FIFO_WR_ERR_EN)
0186 
0187 /* GENI_S_IRQ_EN fields */
0188 #define S_CMD_DONE_EN           BIT(0)
0189 #define S_CMD_OVERRUN_EN        BIT(1)
0190 #define S_ILLEGAL_CMD_EN        BIT(2)
0191 #define S_CMD_FAILURE_EN        BIT(3)
0192 #define S_CMD_CANCEL_EN         BIT(4)
0193 #define S_CMD_ABORT_EN          BIT(5)
0194 #define S_GP_SYNC_IRQ_0_EN      BIT(8)
0195 #define S_GP_IRQ_0_EN           BIT(9)
0196 #define S_GP_IRQ_1_EN           BIT(10)
0197 #define S_GP_IRQ_2_EN           BIT(11)
0198 #define S_GP_IRQ_3_EN           BIT(12)
0199 #define S_GP_IRQ_4_EN           BIT(13)
0200 #define S_GP_IRQ_5_EN           BIT(14)
0201 #define S_IO_DATA_DEASSERT_EN       BIT(22)
0202 #define S_IO_DATA_ASSERT_EN     BIT(23)
0203 #define S_RX_FIFO_RD_ERR_EN     BIT(24)
0204 #define S_RX_FIFO_WR_ERR_EN     BIT(25)
0205 #define S_RX_FIFO_WATERMARK_EN      BIT(26)
0206 #define S_RX_FIFO_LAST_EN       BIT(27)
0207 #define S_COMMON_GENI_S_IRQ_EN  (GENMASK(5, 1) | GENMASK(13, 9) | \
0208                  S_RX_FIFO_RD_ERR_EN | S_RX_FIFO_WR_ERR_EN)
0209 
0210 /*  GENI_/TX/RX/RX_RFR/_WATERMARK_REG fields */
0211 #define WATERMARK_MSK           GENMASK(5, 0)
0212 
0213 /* GENI_TX_FIFO_STATUS fields */
0214 #define TX_FIFO_WC          GENMASK(27, 0)
0215 
0216 /*  GENI_RX_FIFO_STATUS fields */
0217 #define RX_LAST             BIT(31)
0218 #define RX_LAST_BYTE_VALID_MSK      GENMASK(30, 28)
0219 #define RX_LAST_BYTE_VALID_SHFT     28
0220 #define RX_FIFO_WC_MSK          GENMASK(24, 0)
0221 
0222 /* SE_GENI_IOS fields */
0223 #define IO2_DATA_IN         BIT(1)
0224 #define RX_DATA_IN          BIT(0)
0225 
0226 /* SE_DMA_TX_IRQ_STAT Register fields */
0227 #define TX_DMA_DONE         BIT(0)
0228 #define TX_EOT              BIT(1)
0229 #define TX_SBE              BIT(2)
0230 #define TX_RESET_DONE           BIT(3)
0231 
0232 /* SE_DMA_RX_IRQ_STAT Register fields */
0233 #define RX_DMA_DONE         BIT(0)
0234 #define RX_EOT              BIT(1)
0235 #define RX_SBE              BIT(2)
0236 #define RX_RESET_DONE           BIT(3)
0237 #define RX_FLUSH_DONE           BIT(4)
0238 #define RX_GENI_GP_IRQ          GENMASK(10, 5)
0239 #define RX_GENI_CANCEL_IRQ      BIT(11)
0240 #define RX_GENI_GP_IRQ_EXT      GENMASK(13, 12)
0241 
0242 /* SE_HW_PARAM_0 fields */
0243 #define TX_FIFO_WIDTH_MSK       GENMASK(29, 24)
0244 #define TX_FIFO_WIDTH_SHFT      24
0245 #define TX_FIFO_DEPTH_MSK       GENMASK(21, 16)
0246 #define TX_FIFO_DEPTH_SHFT      16
0247 
0248 /* SE_HW_PARAM_1 fields */
0249 #define RX_FIFO_WIDTH_MSK       GENMASK(29, 24)
0250 #define RX_FIFO_WIDTH_SHFT      24
0251 #define RX_FIFO_DEPTH_MSK       GENMASK(21, 16)
0252 #define RX_FIFO_DEPTH_SHFT      16
0253 
0254 #define HW_VER_MAJOR_MASK       GENMASK(31, 28)
0255 #define HW_VER_MAJOR_SHFT       28
0256 #define HW_VER_MINOR_MASK       GENMASK(27, 16)
0257 #define HW_VER_MINOR_SHFT       16
0258 #define HW_VER_STEP_MASK        GENMASK(15, 0)
0259 
0260 #define GENI_SE_VERSION_MAJOR(ver) ((ver & HW_VER_MAJOR_MASK) >> HW_VER_MAJOR_SHFT)
0261 #define GENI_SE_VERSION_MINOR(ver) ((ver & HW_VER_MINOR_MASK) >> HW_VER_MINOR_SHFT)
0262 #define GENI_SE_VERSION_STEP(ver) (ver & HW_VER_STEP_MASK)
0263 
0264 /* QUP SE VERSION value for major number 2 and minor number 5 */
0265 #define QUP_SE_VERSION_2_5                  0x20050000
0266 
0267 /*
0268  * Define bandwidth thresholds that cause the underlying Core 2X interconnect
0269  * clock to run at the named frequency. These baseline values are recommended
0270  * by the hardware team, and are not dynamically scaled with GENI bandwidth
0271  * beyond basic on/off.
0272  */
0273 #define CORE_2X_19_2_MHZ        960
0274 #define CORE_2X_50_MHZ          2500
0275 #define CORE_2X_100_MHZ         5000
0276 #define CORE_2X_150_MHZ         7500
0277 #define CORE_2X_200_MHZ         10000
0278 #define CORE_2X_236_MHZ         16383
0279 
0280 #define GENI_DEFAULT_BW         Bps_to_icc(1000)
0281 
0282 #if IS_ENABLED(CONFIG_QCOM_GENI_SE)
0283 
0284 u32 geni_se_get_qup_hw_version(struct geni_se *se);
0285 
0286 /**
0287  * geni_se_read_proto() - Read the protocol configured for a serial engine
0288  * @se:     Pointer to the concerned serial engine.
0289  *
0290  * Return: Protocol value as configured in the serial engine.
0291  */
0292 static inline u32 geni_se_read_proto(struct geni_se *se)
0293 {
0294     u32 val;
0295 
0296     val = readl_relaxed(se->base + GENI_FW_REVISION_RO);
0297 
0298     return (val & FW_REV_PROTOCOL_MSK) >> FW_REV_PROTOCOL_SHFT;
0299 }
0300 
0301 /**
0302  * geni_se_setup_m_cmd() - Setup the primary sequencer
0303  * @se:     Pointer to the concerned serial engine.
0304  * @cmd:    Command/Operation to setup in the primary sequencer.
0305  * @params: Parameter for the sequencer command.
0306  *
0307  * This function is used to configure the primary sequencer with the
0308  * command and its associated parameters.
0309  */
0310 static inline void geni_se_setup_m_cmd(struct geni_se *se, u32 cmd, u32 params)
0311 {
0312     u32 m_cmd;
0313 
0314     m_cmd = (cmd << M_OPCODE_SHFT) | (params & M_PARAMS_MSK);
0315     writel(m_cmd, se->base + SE_GENI_M_CMD0);
0316 }
0317 
0318 /**
0319  * geni_se_setup_s_cmd() - Setup the secondary sequencer
0320  * @se:     Pointer to the concerned serial engine.
0321  * @cmd:    Command/Operation to setup in the secondary sequencer.
0322  * @params: Parameter for the sequencer command.
0323  *
0324  * This function is used to configure the secondary sequencer with the
0325  * command and its associated parameters.
0326  */
0327 static inline void geni_se_setup_s_cmd(struct geni_se *se, u32 cmd, u32 params)
0328 {
0329     u32 s_cmd;
0330 
0331     s_cmd = readl_relaxed(se->base + SE_GENI_S_CMD0);
0332     s_cmd &= ~(S_OPCODE_MSK | S_PARAMS_MSK);
0333     s_cmd |= (cmd << S_OPCODE_SHFT);
0334     s_cmd |= (params & S_PARAMS_MSK);
0335     writel(s_cmd, se->base + SE_GENI_S_CMD0);
0336 }
0337 
0338 /**
0339  * geni_se_cancel_m_cmd() - Cancel the command configured in the primary
0340  *                          sequencer
0341  * @se: Pointer to the concerned serial engine.
0342  *
0343  * This function is used to cancel the currently configured command in the
0344  * primary sequencer.
0345  */
0346 static inline void geni_se_cancel_m_cmd(struct geni_se *se)
0347 {
0348     writel_relaxed(M_GENI_CMD_CANCEL, se->base + SE_GENI_M_CMD_CTRL_REG);
0349 }
0350 
0351 /**
0352  * geni_se_cancel_s_cmd() - Cancel the command configured in the secondary
0353  *                          sequencer
0354  * @se: Pointer to the concerned serial engine.
0355  *
0356  * This function is used to cancel the currently configured command in the
0357  * secondary sequencer.
0358  */
0359 static inline void geni_se_cancel_s_cmd(struct geni_se *se)
0360 {
0361     writel_relaxed(S_GENI_CMD_CANCEL, se->base + SE_GENI_S_CMD_CTRL_REG);
0362 }
0363 
0364 /**
0365  * geni_se_abort_m_cmd() - Abort the command configured in the primary sequencer
0366  * @se: Pointer to the concerned serial engine.
0367  *
0368  * This function is used to force abort the currently configured command in the
0369  * primary sequencer.
0370  */
0371 static inline void geni_se_abort_m_cmd(struct geni_se *se)
0372 {
0373     writel_relaxed(M_GENI_CMD_ABORT, se->base + SE_GENI_M_CMD_CTRL_REG);
0374 }
0375 
0376 /**
0377  * geni_se_abort_s_cmd() - Abort the command configured in the secondary
0378  *                         sequencer
0379  * @se: Pointer to the concerned serial engine.
0380  *
0381  * This function is used to force abort the currently configured command in the
0382  * secondary sequencer.
0383  */
0384 static inline void geni_se_abort_s_cmd(struct geni_se *se)
0385 {
0386     writel_relaxed(S_GENI_CMD_ABORT, se->base + SE_GENI_S_CMD_CTRL_REG);
0387 }
0388 
0389 /**
0390  * geni_se_get_tx_fifo_depth() - Get the TX fifo depth of the serial engine
0391  * @se: Pointer to the concerned serial engine.
0392  *
0393  * This function is used to get the depth i.e. number of elements in the
0394  * TX fifo of the serial engine.
0395  *
0396  * Return: TX fifo depth in units of FIFO words.
0397  */
0398 static inline u32 geni_se_get_tx_fifo_depth(struct geni_se *se)
0399 {
0400     u32 val;
0401 
0402     val = readl_relaxed(se->base + SE_HW_PARAM_0);
0403 
0404     return (val & TX_FIFO_DEPTH_MSK) >> TX_FIFO_DEPTH_SHFT;
0405 }
0406 
0407 /**
0408  * geni_se_get_tx_fifo_width() - Get the TX fifo width of the serial engine
0409  * @se: Pointer to the concerned serial engine.
0410  *
0411  * This function is used to get the width i.e. word size per element in the
0412  * TX fifo of the serial engine.
0413  *
0414  * Return: TX fifo width in bits
0415  */
0416 static inline u32 geni_se_get_tx_fifo_width(struct geni_se *se)
0417 {
0418     u32 val;
0419 
0420     val = readl_relaxed(se->base + SE_HW_PARAM_0);
0421 
0422     return (val & TX_FIFO_WIDTH_MSK) >> TX_FIFO_WIDTH_SHFT;
0423 }
0424 
0425 /**
0426  * geni_se_get_rx_fifo_depth() - Get the RX fifo depth of the serial engine
0427  * @se: Pointer to the concerned serial engine.
0428  *
0429  * This function is used to get the depth i.e. number of elements in the
0430  * RX fifo of the serial engine.
0431  *
0432  * Return: RX fifo depth in units of FIFO words
0433  */
0434 static inline u32 geni_se_get_rx_fifo_depth(struct geni_se *se)
0435 {
0436     u32 val;
0437 
0438     val = readl_relaxed(se->base + SE_HW_PARAM_1);
0439 
0440     return (val & RX_FIFO_DEPTH_MSK) >> RX_FIFO_DEPTH_SHFT;
0441 }
0442 
0443 void geni_se_init(struct geni_se *se, u32 rx_wm, u32 rx_rfr);
0444 
0445 void geni_se_select_mode(struct geni_se *se, enum geni_se_xfer_mode mode);
0446 
0447 void geni_se_config_packing(struct geni_se *se, int bpw, int pack_words,
0448                 bool msb_to_lsb, bool tx_cfg, bool rx_cfg);
0449 
0450 int geni_se_resources_off(struct geni_se *se);
0451 
0452 int geni_se_resources_on(struct geni_se *se);
0453 
0454 int geni_se_clk_tbl_get(struct geni_se *se, unsigned long **tbl);
0455 
0456 int geni_se_clk_freq_match(struct geni_se *se, unsigned long req_freq,
0457                unsigned int *index, unsigned long *res_freq,
0458                bool exact);
0459 
0460 int geni_se_tx_dma_prep(struct geni_se *se, void *buf, size_t len,
0461             dma_addr_t *iova);
0462 
0463 int geni_se_rx_dma_prep(struct geni_se *se, void *buf, size_t len,
0464             dma_addr_t *iova);
0465 
0466 void geni_se_tx_dma_unprep(struct geni_se *se, dma_addr_t iova, size_t len);
0467 
0468 void geni_se_rx_dma_unprep(struct geni_se *se, dma_addr_t iova, size_t len);
0469 
0470 int geni_icc_get(struct geni_se *se, const char *icc_ddr);
0471 
0472 int geni_icc_set_bw(struct geni_se *se);
0473 void geni_icc_set_tag(struct geni_se *se, u32 tag);
0474 
0475 int geni_icc_enable(struct geni_se *se);
0476 
0477 int geni_icc_disable(struct geni_se *se);
0478 #endif
0479 #endif