Sagar Dharia | 7c927c0 | 2016-11-23 11:51:43 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2017, The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 and |
| 6 | * only version 2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | */ |
| 14 | |
| 15 | #ifndef _LINUX_QCOM_GENI_SE |
| 16 | #define _LINUX_QCOM_GENI_SE |
| 17 | #include <linux/io.h> |
| 18 | |
| 19 | enum se_xfer_mode { |
| 20 | INVALID, |
| 21 | FIFO_MODE, |
| 22 | GSI_DMA, |
| 23 | }; |
| 24 | |
| 25 | enum se_protocol_types { |
| 26 | NONE, |
| 27 | SPI, |
| 28 | UART, |
| 29 | I2C, |
| 30 | I3C |
| 31 | }; |
| 32 | |
| 33 | #define GENI_INIT_CFG_REVISION (0x0) |
| 34 | #define GENI_S_INIT_CFG_REVISION (0x4) |
| 35 | #define GENI_FORCE_DEFAULT_REG (0x20) |
| 36 | #define GENI_OUTPUT_CTRL (0x24) |
| 37 | #define GENI_CGC_CTRL (0x28) |
| 38 | #define SE_GENI_STATUS (0x40) |
| 39 | #define GENI_SER_M_CLK_CFG (0x48) |
| 40 | #define GENI_SER_S_CLK_CFG (0x4C) |
| 41 | #define GENI_CLK_CTRL_RO (0x60) |
| 42 | #define GENI_IF_DISABLE_RO (0x64) |
| 43 | #define GENI_FW_REVISION_RO (0x68) |
| 44 | #define GENI_FW_S_REVISION_RO (0x6C) |
| 45 | #define SE_GENI_CLK_SEL (0x7C) |
| 46 | #define SE_GENI_DMA_MODE_EN (0x258) |
| 47 | #define SE_GENI_TX_PACKING_CFG0 (0x260) |
| 48 | #define SE_GENI_TX_PACKING_CFG1 (0x264) |
| 49 | #define SE_GENI_RX_PACKING_CFG0 (0x284) |
| 50 | #define SE_GENI_RX_PACKING_CFG1 (0x288) |
| 51 | #define SE_GENI_M_CMD0 (0x600) |
| 52 | #define SE_GENI_M_CMD_CTRL_REG (0x604) |
| 53 | #define SE_GENI_M_IRQ_STATUS (0x610) |
| 54 | #define SE_GENI_M_IRQ_EN (0x614) |
| 55 | #define SE_GENI_M_IRQ_CLEAR (0x618) |
| 56 | #define SE_GENI_S_CMD0 (0x630) |
| 57 | #define SE_GENI_S_CMD_CTRL_REG (0x634) |
| 58 | #define SE_GENI_S_IRQ_STATUS (0x640) |
| 59 | #define SE_GENI_S_IRQ_EN (0x644) |
| 60 | #define SE_GENI_S_IRQ_CLEAR (0x648) |
| 61 | #define SE_GENI_TX_FIFOn (0x700) |
| 62 | #define SE_GENI_RX_FIFOn (0x780) |
| 63 | #define SE_GENI_TX_FIFO_STATUS (0x800) |
| 64 | #define SE_GENI_RX_FIFO_STATUS (0x804) |
| 65 | #define SE_GENI_TX_WATERMARK_REG (0x80C) |
| 66 | #define SE_GENI_RX_WATERMARK_REG (0x810) |
| 67 | #define SE_GENI_RX_RFR_WATERMARK_REG (0x814) |
| 68 | #define SE_GENI_M_GP_LENGTH (0x910) |
| 69 | #define SE_GENI_S_GP_LENGTH (0x914) |
| 70 | #define SE_IRQ_EN (0xE1C) |
| 71 | #define SE_HW_PARAM_0 (0xE24) |
| 72 | #define SE_HW_PARAM_1 (0xE28) |
| 73 | #define SE_DMA_GENERAL_CFG (0xE30) |
| 74 | |
| 75 | /* GENI_OUTPUT_CTRL fields */ |
| 76 | #define DEFAULT_IO_OUTPUT_CTRL_MSK (GENMASK(6, 0)) |
| 77 | |
| 78 | /* GENI_FORCE_DEFAULT_REG fields */ |
| 79 | #define FORCE_DEFAULT (BIT(0)) |
| 80 | |
| 81 | /* GENI_CGC_CTRL fields */ |
| 82 | #define CFG_AHB_CLK_CGC_ON (BIT(0)) |
| 83 | #define CFG_AHB_WR_ACLK_CGC_ON (BIT(1)) |
| 84 | #define DATA_AHB_CLK_CGC_ON (BIT(2)) |
| 85 | #define SCLK_CGC_ON (BIT(3)) |
| 86 | #define TX_CLK_CGC_ON (BIT(4)) |
| 87 | #define RX_CLK_CGC_ON (BIT(5)) |
| 88 | #define EXT_CLK_CGC_ON (BIT(6)) |
| 89 | #define PROG_RAM_HCLK_OFF (BIT(8)) |
| 90 | #define PROG_RAM_SCLK_OFF (BIT(9)) |
| 91 | #define DEFAULT_CGC_EN (GENMASK(6, 0)) |
| 92 | |
| 93 | /* GENI_STATUS fields */ |
| 94 | #define M_GENI_CMD_ACTIVE (BIT(0)) |
| 95 | #define S_GENI_CMD_ACTIVE (BIT(12)) |
| 96 | |
| 97 | /* GENI_SER_M_CLK_CFG/GENI_SER_S_CLK_CFG */ |
| 98 | #define SER_CLK_EN (BIT(0)) |
| 99 | #define CLK_DIV_MSK (GENMASK(15, 4)) |
| 100 | #define CLK_DIV_SHFT (4) |
| 101 | |
| 102 | /* CLK_CTRL_RO fields */ |
| 103 | |
| 104 | /* IF_DISABLE_RO fields */ |
| 105 | |
| 106 | /* FW_REVISION_RO fields */ |
| 107 | #define FW_REV_PROTOCOL_MSK (GENMASK(15, 8)) |
| 108 | #define FW_REV_PROTOCOL_SHFT (8) |
| 109 | |
| 110 | /* SE_GENI_DMA_MODE_EN */ |
| 111 | #define GENI_DMA_MODE_EN (BIT(0)) |
| 112 | |
| 113 | /* GENI_M_CMD0 fields */ |
| 114 | #define M_OPCODE_MSK (GENMASK(31, 27)) |
| 115 | #define M_OPCODE_SHFT (27) |
| 116 | #define M_PARAMS_MSK (GENMASK(26, 0)) |
| 117 | |
| 118 | /* GENI_M_CMD_CTRL_REG */ |
| 119 | #define M_GENI_CMD_CANCEL BIT(2) |
| 120 | #define M_GENI_CMD_ABORT BIT(1) |
| 121 | #define M_GENI_DISABLE BIT(0) |
| 122 | |
| 123 | /* GENI_S_CMD0 fields */ |
| 124 | #define S_OPCODE_MSK (GENMASK(31, 27)) |
| 125 | #define S_OPCODE_SHFT (27) |
| 126 | #define S_PARAMS_MSK (GENMASK(26, 0)) |
| 127 | |
| 128 | /* GENI_S_CMD_CTRL_REG */ |
| 129 | #define S_GENI_CMD_CANCEL (BIT(2)) |
| 130 | #define S_GENI_CMD_ABORT (BIT(1)) |
| 131 | #define S_GENI_DISABLE (BIT(0)) |
| 132 | |
| 133 | /* GENI_M_IRQ_EN fields */ |
| 134 | #define M_CMD_DONE_EN (BIT(0)) |
| 135 | #define M_CMD_OVERRUN_EN (BIT(1)) |
| 136 | #define M_ILLEGAL_CMD_EN (BIT(2)) |
| 137 | #define M_CMD_FAILURE_EN (BIT(3)) |
| 138 | #define M_CMD_CANCEL_EN (BIT(4)) |
| 139 | #define M_CMD_ABORT_EN (BIT(5)) |
| 140 | #define M_TIMESTAMP_EN (BIT(6)) |
| 141 | #define M_RX_IRQ_EN (BIT(7)) |
| 142 | #define M_GP_SYNC_IRQ_0_EN (BIT(8)) |
| 143 | #define M_GP_IRQ_0_EN (BIT(9)) |
| 144 | #define M_GP_IRQ_1_EN (BIT(10)) |
| 145 | #define M_GP_IRQ_2_EN (BIT(11)) |
| 146 | #define M_GP_IRQ_3_EN (BIT(12)) |
| 147 | #define M_GP_IRQ_4_EN (BIT(13)) |
| 148 | #define M_GP_IRQ_5_EN (BIT(14)) |
| 149 | #define M_IO_DATA_DEASSERT_EN (BIT(22)) |
| 150 | #define M_IO_DATA_ASSERT_EN (BIT(23)) |
| 151 | #define M_RX_FIFO_RD_ERR_EN (BIT(24)) |
| 152 | #define M_RX_FIFO_WR_ERR_EN (BIT(25)) |
| 153 | #define M_RX_FIFO_WATERMARK_EN (BIT(26)) |
| 154 | #define M_RX_FIFO_LAST_EN (BIT(27)) |
| 155 | #define M_TX_FIFO_RD_ERR_EN (BIT(28)) |
| 156 | #define M_TX_FIFO_WR_ERR_EN (BIT(29)) |
| 157 | #define M_TX_FIFO_WATERMARK_EN (BIT(30)) |
| 158 | #define M_SEC_IRQ_EN (BIT(31)) |
| 159 | #define M_COMMON_GENI_M_IRQ_EN (GENMASK(3, 0) | M_TIMESTAMP_EN | \ |
| 160 | GENMASK(14, 8) | M_IO_DATA_DEASSERT_EN | \ |
| 161 | M_IO_DATA_ASSERT_EN | M_RX_FIFO_RD_ERR_EN | \ |
| 162 | M_RX_FIFO_WR_ERR_EN | M_TX_FIFO_RD_ERR_EN | \ |
| 163 | M_TX_FIFO_WR_ERR_EN | M_SEC_IRQ_EN) |
| 164 | |
| 165 | /* GENI_S_IRQ_EN fields */ |
| 166 | #define S_CMD_DONE_EN (BIT(0)) |
| 167 | #define S_CMD_OVERRUN_EN (BIT(1)) |
| 168 | #define S_ILLEGAL_CMD_EN (BIT(2)) |
| 169 | #define S_CMD_FAILURE_EN (BIT(3)) |
| 170 | #define S_CMD_CANCEL_EN (BIT(4)) |
| 171 | #define S_CMD_ABORT_EN (BIT(5)) |
| 172 | #define S_GP_SYNC_IRQ_0_EN (BIT(8)) |
| 173 | #define S_GP_IRQ_0_EN (BIT(9)) |
| 174 | #define S_GP_IRQ_1_EN (BIT(10)) |
| 175 | #define S_GP_IRQ_2_EN (BIT(11)) |
| 176 | #define S_GP_IRQ_3_EN (BIT(12)) |
| 177 | #define S_GP_IRQ_4_EN (BIT(13)) |
| 178 | #define S_GP_IRQ_5_EN (BIT(14)) |
| 179 | #define S_IO_DATA_DEASSERT_EN (BIT(22)) |
| 180 | #define S_IO_DATA_ASSERT_EN (BIT(23)) |
| 181 | #define S_RX_FIFO_RD_ERR_EN (BIT(24)) |
| 182 | #define S_RX_FIFO_WR_ERR_EN (BIT(25)) |
| 183 | #define S_RX_FIFO_WATERMARK_EN (BIT(26)) |
| 184 | #define S_RX_FIFO_LAST_EN (BIT(27)) |
| 185 | #define S_COMMON_GENI_S_IRQ_EN (GENMASK(3, 0) | GENMASK(14, 8) | \ |
| 186 | S_RX_FIFO_RD_ERR_EN | S_RX_FIFO_WR_ERR_EN) |
| 187 | |
| 188 | /* GENI_/TX/RX/RX_RFR/_WATERMARK_REG fields */ |
| 189 | #define WATERMARK_MSK (GENMASK(5, 0)) |
| 190 | |
| 191 | /* GENI_TX_FIFO_STATUS fields */ |
| 192 | #define TX_FIFO_WC (GENMASK(27, 0)) |
| 193 | |
| 194 | /* GENI_RX_FIFO_STATUS fields */ |
| 195 | #define RX_LAST (BIT(31)) |
| 196 | #define RX_LAST_BYTE_VALID_MSK (GENMASK(30, 28)) |
| 197 | #define RX_LAST_BYTE_VALID_SHFT (28) |
| 198 | #define RX_FIFO_WC_MSK (GENMASK(24, 0)) |
| 199 | |
| 200 | /* SE_IRQ_EN fields */ |
| 201 | #define DMA_RX_IRQ_EN (BIT(0)) |
| 202 | #define DMA_TX_IRQ_EN (BIT(1)) |
| 203 | #define GENI_M_IRQ_EN (BIT(2)) |
| 204 | #define GENI_S_IRQ_EN (BIT(3)) |
| 205 | |
| 206 | /* SE_HW_PARAM_0 fields */ |
| 207 | #define TX_FIFO_WIDTH_MSK (GENMASK(29, 24)) |
| 208 | #define TX_FIFO_WIDTH_SHFT (24) |
| 209 | #define TX_FIFO_DEPTH_MSK (GENMASK(21, 16)) |
| 210 | #define TX_FIFO_DEPTH_SHFT (16) |
| 211 | |
| 212 | /* SE_HW_PARAM_1 fields */ |
| 213 | #define RX_FIFO_WIDTH_MSK (GENMASK(29, 24)) |
| 214 | #define RX_FIFO_WIDTH_SHFT (24) |
| 215 | #define RX_FIFO_DEPTH_MSK (GENMASK(21, 16)) |
| 216 | #define RX_FIFO_DEPTH_SHFT (16) |
| 217 | |
| 218 | /* SE_DMA_GENERAL_CFG */ |
| 219 | #define DMA_RX_CLK_CGC_ON (BIT(0)) |
| 220 | #define DMA_TX_CLK_CGC_ON (BIT(1)) |
| 221 | #define DMA_AHB_SLV_CFG_ON (BIT(2)) |
| 222 | #define AHB_SEC_SLV_CLK_CGC_ON (BIT(3)) |
| 223 | #define DUMMY_RX_NON_BUFFERABLE (BIT(4)) |
| 224 | #define RX_DMA_ZERO_PADDING_EN (BIT(5)) |
| 225 | #define RX_DMA_IRQ_DELAY_MSK (GENMASK(8, 6)) |
| 226 | #define RX_DMA_IRQ_DELAY_SHFT (6) |
| 227 | |
| 228 | static inline unsigned int geni_read_reg(void __iomem *base, int offset) |
| 229 | { |
| 230 | return readl_relaxed(base + offset); |
| 231 | } |
| 232 | |
| 233 | static inline void geni_write_reg(unsigned int value, void __iomem *base, |
| 234 | int offset) |
| 235 | { |
| 236 | return writel_relaxed(value, (base + offset)); |
| 237 | } |
| 238 | |
| 239 | static inline int get_se_proto(void __iomem *base) |
| 240 | { |
| 241 | int proto = 0; |
| 242 | |
| 243 | proto = ((geni_read_reg(base, GENI_FW_REVISION_RO) |
| 244 | & FW_REV_PROTOCOL_MSK) >> FW_REV_PROTOCOL_SHFT); |
| 245 | return proto; |
| 246 | } |
| 247 | |
| 248 | static inline int se_geni_irq_en(void __iomem *base, int mode) |
| 249 | { |
| 250 | int ret = 0; |
| 251 | unsigned int common_geni_m_irq_en; |
| 252 | unsigned int common_geni_s_irq_en; |
| 253 | int proto = get_se_proto(base); |
| 254 | |
| 255 | common_geni_m_irq_en = geni_read_reg(base, SE_GENI_M_IRQ_EN); |
| 256 | common_geni_s_irq_en = geni_read_reg(base, SE_GENI_S_IRQ_EN); |
| 257 | /* Common to all modes */ |
| 258 | common_geni_m_irq_en |= M_COMMON_GENI_M_IRQ_EN; |
| 259 | common_geni_s_irq_en |= S_COMMON_GENI_S_IRQ_EN; |
| 260 | |
| 261 | switch (mode) { |
| 262 | case FIFO_MODE: |
| 263 | { |
| 264 | if (proto == I2C) { |
| 265 | common_geni_m_irq_en |= |
| 266 | (M_CMD_DONE_EN | M_TX_FIFO_WATERMARK_EN); |
| 267 | common_geni_s_irq_en |= S_CMD_DONE_EN; |
| 268 | } |
| 269 | break; |
| 270 | } |
| 271 | case GSI_DMA: |
| 272 | break; |
| 273 | default: |
| 274 | pr_err("%s: Invalid mode %d\n", __func__, mode); |
| 275 | ret = -ENXIO; |
| 276 | goto exit_irq_en; |
| 277 | } |
| 278 | |
| 279 | |
| 280 | geni_write_reg(common_geni_m_irq_en, base, SE_GENI_M_IRQ_EN); |
| 281 | geni_write_reg(common_geni_s_irq_en, base, SE_GENI_S_IRQ_EN); |
| 282 | exit_irq_en: |
| 283 | return ret; |
| 284 | } |
| 285 | |
| 286 | |
| 287 | static inline void se_set_rx_rfr_wm(void __iomem *base, unsigned int rx_wm, |
| 288 | unsigned int rx_rfr) |
| 289 | { |
| 290 | geni_write_reg(rx_wm, base, SE_GENI_RX_WATERMARK_REG); |
| 291 | geni_write_reg(rx_rfr, base, SE_GENI_RX_RFR_WATERMARK_REG); |
| 292 | } |
| 293 | |
| 294 | static inline int se_io_set_mode(void __iomem *base, int mode) |
| 295 | { |
| 296 | int ret = 0; |
| 297 | unsigned int io_mode = 0; |
| 298 | unsigned int geni_dma_mode = 0; |
| 299 | |
| 300 | io_mode = geni_read_reg(base, SE_IRQ_EN); |
| 301 | geni_dma_mode = geni_read_reg(base, SE_GENI_DMA_MODE_EN); |
| 302 | |
| 303 | switch (mode) { |
| 304 | case FIFO_MODE: |
| 305 | { |
| 306 | io_mode |= (GENI_M_IRQ_EN | GENI_S_IRQ_EN); |
| 307 | io_mode |= (DMA_TX_IRQ_EN | DMA_RX_IRQ_EN); |
| 308 | geni_dma_mode &= ~GENI_DMA_MODE_EN; |
| 309 | break; |
| 310 | |
| 311 | } |
| 312 | default: |
| 313 | ret = -ENXIO; |
| 314 | goto exit_set_mode; |
| 315 | } |
| 316 | geni_write_reg(io_mode, base, SE_IRQ_EN); |
| 317 | geni_write_reg(geni_dma_mode, base, SE_GENI_DMA_MODE_EN); |
| 318 | exit_set_mode: |
| 319 | return ret; |
| 320 | } |
| 321 | |
| 322 | static inline void se_io_init(void __iomem *base) |
| 323 | { |
| 324 | unsigned int io_op_ctrl = 0; |
| 325 | unsigned int geni_cgc_ctrl; |
| 326 | unsigned int dma_general_cfg; |
| 327 | |
| 328 | geni_cgc_ctrl = geni_read_reg(base, GENI_CGC_CTRL); |
| 329 | dma_general_cfg = geni_read_reg(base, SE_DMA_GENERAL_CFG); |
| 330 | geni_cgc_ctrl |= DEFAULT_CGC_EN; |
| 331 | dma_general_cfg |= (AHB_SEC_SLV_CLK_CGC_ON | DMA_AHB_SLV_CFG_ON | |
| 332 | DMA_TX_CLK_CGC_ON | DMA_RX_CLK_CGC_ON); |
| 333 | io_op_ctrl |= DEFAULT_IO_OUTPUT_CTRL_MSK; |
| 334 | geni_write_reg(geni_cgc_ctrl, base, GENI_CGC_CTRL); |
| 335 | geni_write_reg(dma_general_cfg, base, SE_DMA_GENERAL_CFG); |
| 336 | |
| 337 | geni_write_reg(io_op_ctrl, base, GENI_OUTPUT_CTRL); |
| 338 | geni_write_reg(FORCE_DEFAULT, base, GENI_FORCE_DEFAULT_REG); |
| 339 | } |
| 340 | |
| 341 | static inline int geni_se_init(void __iomem *base, int mode, |
| 342 | unsigned int rx_wm, unsigned int rx_rfr) |
| 343 | { |
| 344 | int ret = 0; |
| 345 | |
| 346 | se_io_init(base); |
| 347 | ret = se_io_set_mode(base, mode); |
| 348 | if (ret) |
| 349 | goto exit_geni_se_init; |
| 350 | |
| 351 | se_set_rx_rfr_wm(base, rx_wm, rx_rfr); |
| 352 | ret = se_geni_irq_en(base, mode); |
| 353 | if (ret) |
| 354 | goto exit_geni_se_init; |
| 355 | |
| 356 | exit_geni_se_init: |
| 357 | return ret; |
| 358 | } |
| 359 | |
| 360 | static inline void geni_setup_m_cmd(void __iomem *base, u32 cmd, |
| 361 | u32 params) |
| 362 | { |
| 363 | u32 m_cmd = geni_read_reg(base, SE_GENI_M_CMD0); |
| 364 | |
| 365 | m_cmd &= ~(M_OPCODE_MSK | M_PARAMS_MSK); |
| 366 | m_cmd |= (cmd << M_OPCODE_SHFT); |
| 367 | m_cmd |= (params & M_PARAMS_MSK); |
| 368 | geni_write_reg(m_cmd, base, SE_GENI_M_CMD0); |
| 369 | } |
| 370 | |
| 371 | static inline void geni_setup_s_cmd(void __iomem *base, u32 cmd, |
| 372 | u32 params) |
| 373 | { |
| 374 | u32 s_cmd = geni_read_reg(base, SE_GENI_S_CMD0); |
| 375 | |
| 376 | s_cmd &= ~(S_OPCODE_MSK | S_PARAMS_MSK); |
| 377 | s_cmd |= (cmd << S_OPCODE_SHFT); |
| 378 | s_cmd |= (params & S_PARAMS_MSK); |
| 379 | geni_write_reg(s_cmd, base, SE_GENI_S_CMD0); |
| 380 | } |
| 381 | |
| 382 | static inline void geni_cancel_m_cmd(void __iomem *base) |
| 383 | { |
| 384 | geni_write_reg(M_GENI_CMD_CANCEL, base, SE_GENI_S_CMD_CTRL_REG); |
| 385 | } |
| 386 | |
| 387 | static inline void geni_cancel_s_cmd(void __iomem *base) |
| 388 | { |
| 389 | geni_write_reg(S_GENI_CMD_CANCEL, base, SE_GENI_S_CMD_CTRL_REG); |
| 390 | } |
| 391 | |
| 392 | static inline void geni_abort_m_cmd(void __iomem *base) |
| 393 | { |
| 394 | geni_write_reg(M_GENI_CMD_ABORT, base, SE_GENI_M_CMD_CTRL_REG); |
| 395 | } |
| 396 | |
| 397 | static inline void qcom_geni_abort_s_cmd(void __iomem *base) |
| 398 | { |
| 399 | geni_write_reg(S_GENI_CMD_ABORT, base, SE_GENI_S_CMD_CTRL_REG); |
| 400 | } |
| 401 | |
| 402 | static inline int get_tx_fifo_depth(void __iomem *base) |
| 403 | { |
| 404 | int tx_fifo_depth; |
| 405 | |
| 406 | tx_fifo_depth = ((geni_read_reg(base, SE_HW_PARAM_0) |
| 407 | & TX_FIFO_DEPTH_MSK) >> TX_FIFO_DEPTH_SHFT); |
| 408 | return tx_fifo_depth; |
| 409 | } |
| 410 | |
| 411 | static inline int get_tx_fifo_width(void __iomem *base) |
| 412 | { |
| 413 | int tx_fifo_width; |
| 414 | |
| 415 | tx_fifo_width = ((geni_read_reg(base, SE_HW_PARAM_0) |
| 416 | & TX_FIFO_WIDTH_MSK) >> TX_FIFO_WIDTH_SHFT); |
| 417 | return tx_fifo_width; |
| 418 | } |
| 419 | |
| 420 | static inline int get_rx_fifo_depth(void __iomem *base) |
| 421 | { |
| 422 | int rx_fifo_depth; |
| 423 | |
| 424 | rx_fifo_depth = ((geni_read_reg(base, SE_HW_PARAM_1) |
| 425 | & RX_FIFO_DEPTH_MSK) >> RX_FIFO_DEPTH_SHFT); |
| 426 | return rx_fifo_depth; |
| 427 | } |
| 428 | |
| 429 | static inline void se_config_packing(void __iomem *base, int bpw, |
| 430 | int pack_words, bool msb_to_lsb) |
| 431 | { |
| 432 | u32 cfg[4] = {0}; |
| 433 | unsigned long cfg0, cfg1; |
| 434 | int len = ((bpw < 8) ? (bpw - 1) : 7); |
| 435 | int idx = ((msb_to_lsb == 1) ? len : 0); |
| 436 | int iter = (bpw * pack_words) >> 3; |
| 437 | int i; |
| 438 | |
| 439 | for (i = 0; i < iter; i++) { |
| 440 | cfg[i] = ((idx << 5) | (msb_to_lsb << 4) | (len << 1)); |
| 441 | idx += (len + 1); |
| 442 | if (i == iter - 1) |
| 443 | cfg[i] |= 1; |
| 444 | } |
| 445 | cfg0 = cfg[0] | (cfg[1] << 10); |
| 446 | cfg1 = cfg[2] | (cfg[3] << 10); |
| 447 | geni_write_reg(cfg0, base, SE_GENI_TX_PACKING_CFG0); |
| 448 | geni_write_reg(cfg1, base, SE_GENI_TX_PACKING_CFG1); |
| 449 | geni_write_reg(cfg0, base, SE_GENI_RX_PACKING_CFG0); |
| 450 | geni_write_reg(cfg1, base, SE_GENI_RX_PACKING_CFG1); |
| 451 | } |
| 452 | #endif |