Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /* Driver for Realtek PCI-Express card reader
0003  *
0004  * Copyright(c) 2009-2013 Realtek Semiconductor Corp. All rights reserved.
0005  *
0006  * Author:
0007  *   Wei WANG <wei_wang@realsil.com.cn>
0008  */
0009 
0010 #ifndef __RTSX_PCI_H
0011 #define __RTSX_PCI_H
0012 
0013 #include <linux/sched.h>
0014 #include <linux/pci.h>
0015 #include <linux/rtsx_common.h>
0016 
0017 #define MAX_RW_REG_CNT          1024
0018 
0019 #define RTSX_HCBAR          0x00
0020 #define RTSX_HCBCTLR            0x04
0021 #define   STOP_CMD          (0x01 << 28)
0022 #define   READ_REG_CMD          0
0023 #define   WRITE_REG_CMD         1
0024 #define   CHECK_REG_CMD         2
0025 
0026 #define RTSX_HDBAR          0x08
0027 #define   RTSX_SG_INT           0x04
0028 #define   RTSX_SG_END           0x02
0029 #define   RTSX_SG_VALID         0x01
0030 #define   RTSX_SG_NO_OP         0x00
0031 #define   RTSX_SG_TRANS_DATA        (0x02 << 4)
0032 #define   RTSX_SG_LINK_DESC     (0x03 << 4)
0033 #define RTSX_HDBCTLR            0x0C
0034 #define   SDMA_MODE         0x00
0035 #define   ADMA_MODE         (0x02 << 26)
0036 #define   STOP_DMA          (0x01 << 28)
0037 #define   TRIG_DMA          (0x01 << 31)
0038 
0039 #define RTSX_HAIMR          0x10
0040 #define   HAIMR_TRANS_START     (0x01 << 31)
0041 #define   HAIMR_READ            0x00
0042 #define   HAIMR_WRITE           (0x01 << 30)
0043 #define   HAIMR_READ_START      (HAIMR_TRANS_START | HAIMR_READ)
0044 #define   HAIMR_WRITE_START     (HAIMR_TRANS_START | HAIMR_WRITE)
0045 #define   HAIMR_TRANS_END           (HAIMR_TRANS_START)
0046 
0047 #define RTSX_BIPR           0x14
0048 #define   CMD_DONE_INT          (1 << 31)
0049 #define   DATA_DONE_INT         (1 << 30)
0050 #define   TRANS_OK_INT          (1 << 29)
0051 #define   TRANS_FAIL_INT        (1 << 28)
0052 #define   XD_INT            (1 << 27)
0053 #define   MS_INT            (1 << 26)
0054 #define   SD_INT            (1 << 25)
0055 #define   GPIO0_INT         (1 << 24)
0056 #define   OC_INT            (1 << 23)
0057 #define   SD_WRITE_PROTECT      (1 << 19)
0058 #define   XD_EXIST          (1 << 18)
0059 #define   MS_EXIST          (1 << 17)
0060 #define   SD_EXIST          (1 << 16)
0061 #define   DELINK_INT            GPIO0_INT
0062 #define   MS_OC_INT         (1 << 23)
0063 #define   SD_OC_INT         (1 << 22)
0064 
0065 #define CARD_INT        (XD_INT | MS_INT | SD_INT)
0066 #define NEED_COMPLETE_INT   (DATA_DONE_INT | TRANS_OK_INT | TRANS_FAIL_INT)
0067 #define RTSX_INT        (CMD_DONE_INT | NEED_COMPLETE_INT | \
0068                     CARD_INT | GPIO0_INT | OC_INT)
0069 #define CARD_EXIST      (XD_EXIST | MS_EXIST | SD_EXIST)
0070 
0071 #define RTSX_BIER           0x18
0072 #define   CMD_DONE_INT_EN       (1 << 31)
0073 #define   DATA_DONE_INT_EN      (1 << 30)
0074 #define   TRANS_OK_INT_EN       (1 << 29)
0075 #define   TRANS_FAIL_INT_EN     (1 << 28)
0076 #define   XD_INT_EN         (1 << 27)
0077 #define   MS_INT_EN         (1 << 26)
0078 #define   SD_INT_EN         (1 << 25)
0079 #define   GPIO0_INT_EN          (1 << 24)
0080 #define   OC_INT_EN         (1 << 23)
0081 #define   DELINK_INT_EN         GPIO0_INT_EN
0082 #define   MS_OC_INT_EN          (1 << 23)
0083 #define   SD_OC_INT_EN          (1 << 22)
0084 
0085 #define RTSX_DUM_REG            0x1C
0086 
0087 /*
0088  * macros for easy use
0089  */
0090 #define rtsx_pci_writel(pcr, reg, value) \
0091     iowrite32(value, (pcr)->remap_addr + reg)
0092 #define rtsx_pci_readl(pcr, reg) \
0093     ioread32((pcr)->remap_addr + reg)
0094 #define rtsx_pci_writew(pcr, reg, value) \
0095     iowrite16(value, (pcr)->remap_addr + reg)
0096 #define rtsx_pci_readw(pcr, reg) \
0097     ioread16((pcr)->remap_addr + reg)
0098 #define rtsx_pci_writeb(pcr, reg, value) \
0099     iowrite8(value, (pcr)->remap_addr + reg)
0100 #define rtsx_pci_readb(pcr, reg) \
0101     ioread8((pcr)->remap_addr + reg)
0102 
0103 #define STATE_TRANS_NONE        0
0104 #define STATE_TRANS_CMD         1
0105 #define STATE_TRANS_BUF         2
0106 #define STATE_TRANS_SG          3
0107 
0108 #define TRANS_NOT_READY         0
0109 #define TRANS_RESULT_OK         1
0110 #define TRANS_RESULT_FAIL       2
0111 #define TRANS_NO_DEVICE         3
0112 
0113 #define RTSX_RESV_BUF_LEN       4096
0114 #define HOST_CMDS_BUF_LEN       1024
0115 #define HOST_SG_TBL_BUF_LEN     (RTSX_RESV_BUF_LEN - HOST_CMDS_BUF_LEN)
0116 #define HOST_SG_TBL_ITEMS       (HOST_SG_TBL_BUF_LEN / 8)
0117 #define MAX_SG_ITEM_LEN         0x80000
0118 #define HOST_TO_DEVICE          0
0119 #define DEVICE_TO_HOST          1
0120 
0121 #define OUTPUT_3V3          0
0122 #define OUTPUT_1V8          1
0123 
0124 #define RTSX_PHASE_MAX          32
0125 #define RX_TUNING_CNT           3
0126 
0127 #define MS_CFG              0xFD40
0128 #define   SAMPLE_TIME_RISING        0x00
0129 #define   SAMPLE_TIME_FALLING       0x80
0130 #define   PUSH_TIME_DEFAULT     0x00
0131 #define   PUSH_TIME_ODD         0x40
0132 #define   NO_EXTEND_TOGGLE      0x00
0133 #define   EXTEND_TOGGLE_CHK     0x20
0134 #define   MS_BUS_WIDTH_1        0x00
0135 #define   MS_BUS_WIDTH_4        0x10
0136 #define   MS_BUS_WIDTH_8        0x18
0137 #define   MS_2K_SECTOR_MODE     0x04
0138 #define   MS_512_SECTOR_MODE        0x00
0139 #define   MS_TOGGLE_TIMEOUT_EN      0x00
0140 #define   MS_TOGGLE_TIMEOUT_DISEN   0x01
0141 #define MS_NO_CHECK_INT         0x02
0142 #define MS_TPC              0xFD41
0143 #define MS_TRANS_CFG            0xFD42
0144 #define   WAIT_INT          0x80
0145 #define   NO_WAIT_INT           0x00
0146 #define   NO_AUTO_READ_INT_REG      0x00
0147 #define   AUTO_READ_INT_REG     0x40
0148 #define   MS_CRC16_ERR          0x20
0149 #define   MS_RDY_TIMEOUT        0x10
0150 #define   MS_INT_CMDNK          0x08
0151 #define   MS_INT_BREQ           0x04
0152 #define   MS_INT_ERR            0x02
0153 #define   MS_INT_CED            0x01
0154 #define MS_TRANSFER         0xFD43
0155 #define   MS_TRANSFER_START     0x80
0156 #define   MS_TRANSFER_END       0x40
0157 #define   MS_TRANSFER_ERR       0x20
0158 #define   MS_BS_STATE           0x10
0159 #define   MS_TM_READ_BYTES      0x00
0160 #define   MS_TM_NORMAL_READ     0x01
0161 #define   MS_TM_WRITE_BYTES     0x04
0162 #define   MS_TM_NORMAL_WRITE        0x05
0163 #define   MS_TM_AUTO_READ       0x08
0164 #define   MS_TM_AUTO_WRITE      0x0C
0165 #define MS_INT_REG          0xFD44
0166 #define MS_BYTE_CNT         0xFD45
0167 #define MS_SECTOR_CNT_L         0xFD46
0168 #define MS_SECTOR_CNT_H         0xFD47
0169 #define MS_DBUS_H           0xFD48
0170 
0171 #define SD_CFG1             0xFDA0
0172 #define   SD_CLK_DIVIDE_0       0x00
0173 #define   SD_CLK_DIVIDE_256     0xC0
0174 #define   SD_CLK_DIVIDE_128     0x80
0175 #define   SD_BUS_WIDTH_1BIT     0x00
0176 #define   SD_BUS_WIDTH_4BIT     0x01
0177 #define   SD_BUS_WIDTH_8BIT     0x02
0178 #define   SD_ASYNC_FIFO_NOT_RST     0x10
0179 #define   SD_20_MODE            0x00
0180 #define   SD_DDR_MODE           0x04
0181 #define   SD_30_MODE            0x08
0182 #define   SD_CLK_DIVIDE_MASK        0xC0
0183 #define   SD_MODE_SELECT_MASK       0x0C
0184 #define SD_CFG2             0xFDA1
0185 #define   SD_CALCULATE_CRC7     0x00
0186 #define   SD_NO_CALCULATE_CRC7      0x80
0187 #define   SD_CHECK_CRC16        0x00
0188 #define   SD_NO_CHECK_CRC16     0x40
0189 #define   SD_NO_CHECK_WAIT_CRC_TO   0x20
0190 #define   SD_WAIT_BUSY_END      0x08
0191 #define   SD_NO_WAIT_BUSY_END       0x00
0192 #define   SD_CHECK_CRC7         0x00
0193 #define   SD_NO_CHECK_CRC7      0x04
0194 #define   SD_RSP_LEN_0          0x00
0195 #define   SD_RSP_LEN_6          0x01
0196 #define   SD_RSP_LEN_17         0x02
0197 #define   SD_RSP_TYPE_R0        0x04
0198 #define   SD_RSP_TYPE_R1        0x01
0199 #define   SD_RSP_TYPE_R1b       0x09
0200 #define   SD_RSP_TYPE_R2        0x02
0201 #define   SD_RSP_TYPE_R3        0x05
0202 #define   SD_RSP_TYPE_R4        0x05
0203 #define   SD_RSP_TYPE_R5        0x01
0204 #define   SD_RSP_TYPE_R6        0x01
0205 #define   SD_RSP_TYPE_R7        0x01
0206 #define SD_CFG3             0xFDA2
0207 #define   SD30_CLK_END_EN       0x10
0208 #define   SD_RSP_80CLK_TIMEOUT_EN   0x01
0209 
0210 #define SD_STAT1            0xFDA3
0211 #define   SD_CRC7_ERR           0x80
0212 #define   SD_CRC16_ERR          0x40
0213 #define   SD_CRC_WRITE_ERR      0x20
0214 #define   SD_CRC_WRITE_ERR_MASK     0x1C
0215 #define   GET_CRC_TIME_OUT      0x02
0216 #define   SD_TUNING_COMPARE_ERR     0x01
0217 #define SD_STAT2            0xFDA4
0218 #define   SD_RSP_80CLK_TIMEOUT      0x01
0219 
0220 #define SD_BUS_STAT         0xFDA5
0221 #define   SD_CLK_TOGGLE_EN      0x80
0222 #define   SD_CLK_FORCE_STOP     0x40
0223 #define   SD_DAT3_STATUS        0x10
0224 #define   SD_DAT2_STATUS        0x08
0225 #define   SD_DAT1_STATUS        0x04
0226 #define   SD_DAT0_STATUS        0x02
0227 #define   SD_CMD_STATUS         0x01
0228 #define SD_PAD_CTL          0xFDA6
0229 #define   SD_IO_USING_1V8       0x80
0230 #define   SD_IO_USING_3V3       0x7F
0231 #define   TYPE_A_DRIVING        0x00
0232 #define   TYPE_B_DRIVING        0x01
0233 #define   TYPE_C_DRIVING        0x02
0234 #define   TYPE_D_DRIVING        0x03
0235 #define SD_SAMPLE_POINT_CTL     0xFDA7
0236 #define   DDR_FIX_RX_DAT        0x00
0237 #define   DDR_VAR_RX_DAT        0x80
0238 #define   DDR_FIX_RX_DAT_EDGE       0x00
0239 #define   DDR_FIX_RX_DAT_14_DELAY   0x40
0240 #define   DDR_FIX_RX_CMD        0x00
0241 #define   DDR_VAR_RX_CMD        0x20
0242 #define   DDR_FIX_RX_CMD_POS_EDGE   0x00
0243 #define   DDR_FIX_RX_CMD_14_DELAY   0x10
0244 #define   SD20_RX_POS_EDGE      0x00
0245 #define   SD20_RX_14_DELAY      0x08
0246 #define SD20_RX_SEL_MASK        0x08
0247 #define SD_PUSH_POINT_CTL       0xFDA8
0248 #define   DDR_FIX_TX_CMD_DAT        0x00
0249 #define   DDR_VAR_TX_CMD_DAT        0x80
0250 #define   DDR_FIX_TX_DAT_14_TSU     0x00
0251 #define   DDR_FIX_TX_DAT_12_TSU     0x40
0252 #define   DDR_FIX_TX_CMD_NEG_EDGE   0x00
0253 #define   DDR_FIX_TX_CMD_14_AHEAD   0x20
0254 #define   SD20_TX_NEG_EDGE      0x00
0255 #define   SD20_TX_14_AHEAD      0x10
0256 #define   SD20_TX_SEL_MASK      0x10
0257 #define   DDR_VAR_SDCLK_POL_SWAP    0x01
0258 #define SD_CMD0             0xFDA9
0259 #define   SD_CMD_START          0x40
0260 #define SD_CMD1             0xFDAA
0261 #define SD_CMD2             0xFDAB
0262 #define SD_CMD3             0xFDAC
0263 #define SD_CMD4             0xFDAD
0264 #define SD_CMD5             0xFDAE
0265 #define SD_BYTE_CNT_L           0xFDAF
0266 #define SD_BYTE_CNT_H           0xFDB0
0267 #define SD_BLOCK_CNT_L          0xFDB1
0268 #define SD_BLOCK_CNT_H          0xFDB2
0269 #define SD_TRANSFER         0xFDB3
0270 #define   SD_TRANSFER_START     0x80
0271 #define   SD_TRANSFER_END       0x40
0272 #define   SD_STAT_IDLE          0x20
0273 #define   SD_TRANSFER_ERR       0x10
0274 #define   SD_TM_NORMAL_WRITE        0x00
0275 #define   SD_TM_AUTO_WRITE_3        0x01
0276 #define   SD_TM_AUTO_WRITE_4        0x02
0277 #define   SD_TM_AUTO_READ_3     0x05
0278 #define   SD_TM_AUTO_READ_4     0x06
0279 #define   SD_TM_CMD_RSP         0x08
0280 #define   SD_TM_AUTO_WRITE_1        0x09
0281 #define   SD_TM_AUTO_WRITE_2        0x0A
0282 #define   SD_TM_NORMAL_READ     0x0C
0283 #define   SD_TM_AUTO_READ_1     0x0D
0284 #define   SD_TM_AUTO_READ_2     0x0E
0285 #define   SD_TM_AUTO_TUNING     0x0F
0286 #define SD_CMD_STATE            0xFDB5
0287 #define   SD_CMD_IDLE           0x80
0288 
0289 #define SD_DATA_STATE           0xFDB6
0290 #define   SD_DATA_IDLE          0x80
0291 #define REG_SD_STOP_SDCLK_CFG       0xFDB8
0292 #define   SD30_CLK_STOP_CFG_EN      0x04
0293 #define   SD30_CLK_STOP_CFG1        0x02
0294 #define   SD30_CLK_STOP_CFG0        0x01
0295 #define REG_PRE_RW_MODE         0xFD70
0296 #define EN_INFINITE_MODE        0x01
0297 #define REG_CRC_DUMMY_0     0xFD71
0298 #define CFG_SD_POW_AUTO_PD      (1<<0)
0299 
0300 #define SRCTL               0xFC13
0301 
0302 #define DCM_DRP_CTL         0xFC23
0303 #define   DCM_RESET         0x08
0304 #define   DCM_LOCKED            0x04
0305 #define   DCM_208M          0x00
0306 #define   DCM_TX            0x01
0307 #define   DCM_RX            0x02
0308 #define DCM_DRP_TRIG            0xFC24
0309 #define   DRP_START         0x80
0310 #define   DRP_DONE          0x40
0311 #define DCM_DRP_CFG         0xFC25
0312 #define   DRP_WRITE         0x80
0313 #define   DRP_READ          0x00
0314 #define   DCM_WRITE_ADDRESS_50      0x50
0315 #define   DCM_WRITE_ADDRESS_51      0x51
0316 #define   DCM_READ_ADDRESS_00       0x00
0317 #define   DCM_READ_ADDRESS_51       0x51
0318 #define DCM_DRP_WR_DATA_L       0xFC26
0319 #define DCM_DRP_WR_DATA_H       0xFC27
0320 #define DCM_DRP_RD_DATA_L       0xFC28
0321 #define DCM_DRP_RD_DATA_H       0xFC29
0322 #define SD_VPCLK0_CTL           0xFC2A
0323 #define SD_VPCLK1_CTL           0xFC2B
0324 #define   PHASE_SELECT_MASK     0x1F
0325 #define SD_DCMPS0_CTL           0xFC2C
0326 #define SD_DCMPS1_CTL           0xFC2D
0327 #define SD_VPTX_CTL         SD_VPCLK0_CTL
0328 #define SD_VPRX_CTL         SD_VPCLK1_CTL
0329 #define   PHASE_CHANGE          0x80
0330 #define   PHASE_NOT_RESET       0x40
0331 #define SD_DCMPS_TX_CTL         SD_DCMPS0_CTL
0332 #define SD_DCMPS_RX_CTL         SD_DCMPS1_CTL
0333 #define   DCMPS_CHANGE          0x80
0334 #define   DCMPS_CHANGE_DONE     0x40
0335 #define   DCMPS_ERROR           0x20
0336 #define   DCMPS_CURRENT_PHASE       0x1F
0337 #define CARD_CLK_SOURCE         0xFC2E
0338 #define   CRC_FIX_CLK           (0x00 << 0)
0339 #define   CRC_VAR_CLK0          (0x01 << 0)
0340 #define   CRC_VAR_CLK1          (0x02 << 0)
0341 #define   SD30_FIX_CLK          (0x00 << 2)
0342 #define   SD30_VAR_CLK0         (0x01 << 2)
0343 #define   SD30_VAR_CLK1         (0x02 << 2)
0344 #define   SAMPLE_FIX_CLK        (0x00 << 4)
0345 #define   SAMPLE_VAR_CLK0       (0x01 << 4)
0346 #define   SAMPLE_VAR_CLK1       (0x02 << 4)
0347 #define CARD_PWR_CTL            0xFD50
0348 #define   PMOS_STRG_MASK        0x10
0349 #define   PMOS_STRG_800mA       0x10
0350 #define   PMOS_STRG_400mA       0x00
0351 #define   SD_POWER_OFF          0x03
0352 #define   SD_PARTIAL_POWER_ON       0x01
0353 #define   SD_POWER_ON           0x00
0354 #define   SD_POWER_MASK         0x03
0355 #define   MS_POWER_OFF          0x0C
0356 #define   MS_PARTIAL_POWER_ON       0x04
0357 #define   MS_POWER_ON           0x00
0358 #define   MS_POWER_MASK         0x0C
0359 #define   BPP_POWER_OFF         0x0F
0360 #define   BPP_POWER_5_PERCENT_ON    0x0E
0361 #define   BPP_POWER_10_PERCENT_ON   0x0C
0362 #define   BPP_POWER_15_PERCENT_ON   0x08
0363 #define   BPP_POWER_ON          0x00
0364 #define   BPP_POWER_MASK        0x0F
0365 #define   SD_VCC_PARTIAL_POWER_ON   0x02
0366 #define   SD_VCC_POWER_ON       0x00
0367 #define CARD_CLK_SWITCH         0xFD51
0368 #define RTL8411B_PACKAGE_MODE       0xFD51
0369 #define CARD_SHARE_MODE         0xFD52
0370 #define   CARD_SHARE_MASK       0x0F
0371 #define   CARD_SHARE_MULTI_LUN      0x00
0372 #define   CARD_SHARE_NORMAL     0x00
0373 #define   CARD_SHARE_48_SD      0x04
0374 #define   CARD_SHARE_48_MS      0x08
0375 #define   CARD_SHARE_BAROSSA_SD     0x01
0376 #define   CARD_SHARE_BAROSSA_MS     0x02
0377 #define CARD_DRIVE_SEL          0xFD53
0378 #define   MS_DRIVE_8mA          (0x01 << 6)
0379 #define   MMC_DRIVE_8mA         (0x01 << 4)
0380 #define   XD_DRIVE_8mA          (0x01 << 2)
0381 #define   GPIO_DRIVE_8mA        0x01
0382 #define RTS5209_CARD_DRIVE_DEFAULT  (MS_DRIVE_8mA | MMC_DRIVE_8mA |\
0383                     XD_DRIVE_8mA | GPIO_DRIVE_8mA)
0384 #define RTL8411_CARD_DRIVE_DEFAULT  (MS_DRIVE_8mA | MMC_DRIVE_8mA |\
0385                     XD_DRIVE_8mA)
0386 #define RTSX_CARD_DRIVE_DEFAULT     (MS_DRIVE_8mA | GPIO_DRIVE_8mA)
0387 
0388 #define CARD_STOP           0xFD54
0389 #define   SPI_STOP          0x01
0390 #define   XD_STOP           0x02
0391 #define   SD_STOP           0x04
0392 #define   MS_STOP           0x08
0393 #define   SPI_CLR_ERR           0x10
0394 #define   XD_CLR_ERR            0x20
0395 #define   SD_CLR_ERR            0x40
0396 #define   MS_CLR_ERR            0x80
0397 #define CARD_OE             0xFD55
0398 #define   SD_OUTPUT_EN          0x04
0399 #define   MS_OUTPUT_EN          0x08
0400 #define CARD_AUTO_BLINK         0xFD56
0401 #define CARD_GPIO_DIR           0xFD57
0402 #define CARD_GPIO           0xFD58
0403 #define CARD_DATA_SOURCE        0xFD5B
0404 #define   PINGPONG_BUFFER       0x01
0405 #define   RING_BUFFER           0x00
0406 #define SD30_CLK_DRIVE_SEL      0xFD5A
0407 #define   DRIVER_TYPE_A         0x05
0408 #define   DRIVER_TYPE_B         0x03
0409 #define   DRIVER_TYPE_C         0x02
0410 #define   DRIVER_TYPE_D         0x01
0411 #define CARD_SELECT         0xFD5C
0412 #define   SD_MOD_SEL            2
0413 #define   MS_MOD_SEL            3
0414 #define SD30_DRIVE_SEL          0xFD5E
0415 #define   CFG_DRIVER_TYPE_A     0x02
0416 #define   CFG_DRIVER_TYPE_B     0x03
0417 #define   CFG_DRIVER_TYPE_C     0x01
0418 #define   CFG_DRIVER_TYPE_D     0x00
0419 #define SD30_CMD_DRIVE_SEL      0xFD5E
0420 #define SD30_DAT_DRIVE_SEL      0xFD5F
0421 #define CARD_CLK_EN         0xFD69
0422 #define   SD_CLK_EN         0x04
0423 #define   MS_CLK_EN         0x08
0424 #define   SD40_CLK_EN       0x10
0425 #define SDIO_CTRL           0xFD6B
0426 #define CD_PAD_CTL          0xFD73
0427 #define   CD_DISABLE_MASK       0x07
0428 #define   MS_CD_DISABLE         0x04
0429 #define   SD_CD_DISABLE         0x02
0430 #define   XD_CD_DISABLE         0x01
0431 #define   CD_DISABLE            0x07
0432 #define   CD_ENABLE         0x00
0433 #define   MS_CD_EN_ONLY         0x03
0434 #define   SD_CD_EN_ONLY         0x05
0435 #define   XD_CD_EN_ONLY         0x06
0436 #define   FORCE_CD_LOW_MASK     0x38
0437 #define   FORCE_CD_XD_LOW       0x08
0438 #define   FORCE_CD_SD_LOW       0x10
0439 #define   FORCE_CD_MS_LOW       0x20
0440 #define   CD_AUTO_DISABLE       0x40
0441 #define FPDCTL              0xFC00
0442 #define   SSC_POWER_DOWN        0x01
0443 #define   SD_OC_POWER_DOWN      0x02
0444 #define   ALL_POWER_DOWN        0x03
0445 #define   OC_POWER_DOWN         0x02
0446 #define PDINFO              0xFC01
0447 
0448 #define CLK_CTL             0xFC02
0449 #define   CHANGE_CLK            0x01
0450 #define   CLK_LOW_FREQ          0x01
0451 
0452 #define CLK_DIV             0xFC03
0453 #define   CLK_DIV_1         0x01
0454 #define   CLK_DIV_2         0x02
0455 #define   CLK_DIV_4         0x03
0456 #define   CLK_DIV_8         0x04
0457 #define CLK_SEL             0xFC04
0458 
0459 #define SSC_DIV_N_0         0xFC0F
0460 #define SSC_DIV_N_1         0xFC10
0461 #define SSC_CTL1            0xFC11
0462 #define    SSC_RSTB         0x80
0463 #define    SSC_8X_EN            0x40
0464 #define    SSC_FIX_FRAC         0x20
0465 #define    SSC_SEL_1M           0x00
0466 #define    SSC_SEL_2M           0x08
0467 #define    SSC_SEL_4M           0x10
0468 #define    SSC_SEL_8M           0x18
0469 #define SSC_CTL2            0xFC12
0470 #define    SSC_DEPTH_MASK       0x07
0471 #define    SSC_DEPTH_DISALBE        0x00
0472 #define    SSC_DEPTH_4M         0x01
0473 #define    SSC_DEPTH_2M         0x02
0474 #define    SSC_DEPTH_1M         0x03
0475 #define    SSC_DEPTH_500K       0x04
0476 #define    SSC_DEPTH_250K       0x05
0477 #define RCCTL               0xFC14
0478 
0479 #define FPGA_PULL_CTL           0xFC1D
0480 #define OLT_LED_CTL         0xFC1E
0481 #define   LED_SHINE_MASK        0x08
0482 #define   LED_SHINE_EN          0x08
0483 #define   LED_SHINE_DISABLE     0x00
0484 #define GPIO_CTL            0xFC1F
0485 
0486 #define LDO_CTL             0xFC1E
0487 #define   BPP_ASIC_1V7          0x00
0488 #define   BPP_ASIC_1V8          0x01
0489 #define   BPP_ASIC_1V9          0x02
0490 #define   BPP_ASIC_2V0          0x03
0491 #define   BPP_ASIC_2V7          0x04
0492 #define   BPP_ASIC_2V8          0x05
0493 #define   BPP_ASIC_3V2          0x06
0494 #define   BPP_ASIC_3V3          0x07
0495 #define   BPP_REG_TUNED18       0x07
0496 #define   BPP_TUNED18_SHIFT_8402    5
0497 #define   BPP_TUNED18_SHIFT_8411    4
0498 #define   BPP_PAD_MASK          0x04
0499 #define   BPP_PAD_3V3           0x04
0500 #define   BPP_PAD_1V8           0x00
0501 #define   BPP_LDO_POWB          0x03
0502 #define   BPP_LDO_ON            0x00
0503 #define   BPP_LDO_SUSPEND       0x02
0504 #define   BPP_LDO_OFF           0x03
0505 #define EFUSE_CTL           0xFC30
0506 #define EFUSE_ADD           0xFC31
0507 #define SYS_VER             0xFC32
0508 #define EFUSE_DATAL         0xFC34
0509 #define EFUSE_DATAH         0xFC35
0510 
0511 #define CARD_PULL_CTL1          0xFD60
0512 #define CARD_PULL_CTL2          0xFD61
0513 #define CARD_PULL_CTL3          0xFD62
0514 #define CARD_PULL_CTL4          0xFD63
0515 #define CARD_PULL_CTL5          0xFD64
0516 #define CARD_PULL_CTL6          0xFD65
0517 
0518 /* PCI Express Related Registers */
0519 #define IRQEN0              0xFE20
0520 #define IRQSTAT0            0xFE21
0521 #define    DMA_DONE_INT         0x80
0522 #define    SUSPEND_INT          0x40
0523 #define    LINK_RDY_INT         0x20
0524 #define    LINK_DOWN_INT        0x10
0525 #define IRQEN1              0xFE22
0526 #define IRQSTAT1            0xFE23
0527 #define TLPRIEN             0xFE24
0528 #define TLPRISTAT           0xFE25
0529 #define TLPTIEN             0xFE26
0530 #define TLPTISTAT           0xFE27
0531 #define DMATC0              0xFE28
0532 #define DMATC1              0xFE29
0533 #define DMATC2              0xFE2A
0534 #define DMATC3              0xFE2B
0535 #define DMACTL              0xFE2C
0536 #define   DMA_RST           0x80
0537 #define   DMA_BUSY          0x04
0538 #define   DMA_DIR_TO_CARD       0x00
0539 #define   DMA_DIR_FROM_CARD     0x02
0540 #define   DMA_EN            0x01
0541 #define   DMA_128           (0 << 4)
0542 #define   DMA_256           (1 << 4)
0543 #define   DMA_512           (2 << 4)
0544 #define   DMA_1024          (3 << 4)
0545 #define   DMA_PACK_SIZE_MASK        0x30
0546 #define BCTL                0xFE2D
0547 #define RBBC0               0xFE2E
0548 #define RBBC1               0xFE2F
0549 #define RBDAT               0xFE30
0550 #define RBCTL               0xFE34
0551 #define   U_AUTO_DMA_EN_MASK        0x20
0552 #define   U_AUTO_DMA_DISABLE        0x00
0553 #define   RB_FLUSH          0x80
0554 #define CFGADDR0            0xFE35
0555 #define CFGADDR1            0xFE36
0556 #define CFGDATA0            0xFE37
0557 #define CFGDATA1            0xFE38
0558 #define CFGDATA2            0xFE39
0559 #define CFGDATA3            0xFE3A
0560 #define CFGRWCTL            0xFE3B
0561 #define PHYRWCTL            0xFE3C
0562 #define PHYDATA0            0xFE3D
0563 #define PHYDATA1            0xFE3E
0564 #define PHYADDR             0xFE3F
0565 #define MSGRXDATA0          0xFE40
0566 #define MSGRXDATA1          0xFE41
0567 #define MSGRXDATA2          0xFE42
0568 #define MSGRXDATA3          0xFE43
0569 #define MSGTXDATA0          0xFE44
0570 #define MSGTXDATA1          0xFE45
0571 #define MSGTXDATA2          0xFE46
0572 #define MSGTXDATA3          0xFE47
0573 #define MSGTXCTL            0xFE48
0574 #define LTR_CTL             0xFE4A
0575 #define LTR_TX_EN_MASK      BIT(7)
0576 #define LTR_TX_EN_1         BIT(7)
0577 #define LTR_TX_EN_0         0
0578 #define LTR_LATENCY_MODE_MASK       BIT(6)
0579 #define LTR_LATENCY_MODE_HW     0
0580 #define LTR_LATENCY_MODE_SW     BIT(6)
0581 #define OBFF_CFG            0xFE4C
0582 #define   OBFF_EN_MASK          0x03
0583 #define   OBFF_DISABLE          0x00
0584 
0585 #define CDRESUMECTL         0xFE52
0586 #define WAKE_SEL_CTL            0xFE54
0587 #define PCLK_CTL            0xFE55
0588 #define   PCLK_MODE_SEL         0x20
0589 #define PME_FORCE_CTL           0xFE56
0590 
0591 #define ASPM_FORCE_CTL          0xFE57
0592 #define   FORCE_ASPM_CTL0       0x10
0593 #define   FORCE_ASPM_CTL1       0x20
0594 #define   FORCE_ASPM_VAL_MASK       0x03
0595 #define   FORCE_ASPM_L1_EN      0x02
0596 #define   FORCE_ASPM_L0_EN      0x01
0597 #define   FORCE_ASPM_NO_ASPM        0x00
0598 #define PM_CLK_FORCE_CTL        0xFE58
0599 #define   CLK_PM_EN         0x01
0600 #define FUNC_FORCE_CTL          0xFE59
0601 #define   FUNC_FORCE_UPME_XMT_DBG   0x02
0602 #define PERST_GLITCH_WIDTH      0xFE5C
0603 #define CHANGE_LINK_STATE       0xFE5B
0604 #define RESET_LOAD_REG          0xFE5E
0605 #define EFUSE_CONTENT           0xFE5F
0606 #define HOST_SLEEP_STATE        0xFE60
0607 #define   HOST_ENTER_S1         1
0608 #define   HOST_ENTER_S3         2
0609 
0610 #define SDIO_CFG            0xFE70
0611 #define PM_EVENT_DEBUG          0xFE71
0612 #define   PME_DEBUG_0           0x08
0613 #define NFTS_TX_CTRL            0xFE72
0614 
0615 #define PWR_GATE_CTRL           0xFE75
0616 #define   PWR_GATE_EN           0x01
0617 #define   LDO3318_PWR_MASK      0x06
0618 #define   LDO_ON            0x00
0619 #define   LDO_SUSPEND           0x04
0620 #define   LDO_OFF           0x06
0621 #define PWD_SUSPEND_EN          0xFE76
0622 #define LDO_PWR_SEL         0xFE78
0623 
0624 #define L1SUB_CONFIG1           0xFE8D
0625 #define   AUX_CLK_ACTIVE_SEL_MASK   0x01
0626 #define   MAC_CKSW_DONE         0x00
0627 #define L1SUB_CONFIG2           0xFE8E
0628 #define   L1SUB_AUTO_CFG        0x02
0629 #define L1SUB_CONFIG3           0xFE8F
0630 #define   L1OFF_MBIAS2_EN_5250      BIT(7)
0631 
0632 #define DUMMY_REG_RESET_0       0xFE90
0633 #define   IC_VERSION_MASK       0x0F
0634 
0635 #define REG_VREF            0xFE97
0636 #define   PWD_SUSPND_EN         0x10
0637 #define RTS5260_DMA_RST_CTL_0       0xFEBF
0638 #define   RTS5260_DMA_RST       0x80
0639 #define   RTS5260_ADMA3_RST     0x40
0640 #define AUTOLOAD_CFG_BASE       0xFF00
0641 #define RELINK_TIME_MASK        0x01
0642 #define PETXCFG             0xFF03
0643 #define FORCE_CLKREQ_DELINK_MASK    BIT(7)
0644 #define FORCE_CLKREQ_LOW    0x80
0645 #define FORCE_CLKREQ_HIGH   0x00
0646 
0647 #define PM_CTRL1            0xFF44
0648 #define   CD_RESUME_EN_MASK     0xF0
0649 
0650 #define PM_CTRL2            0xFF45
0651 #define PM_CTRL3            0xFF46
0652 #define   SDIO_SEND_PME_EN      0x80
0653 #define   FORCE_RC_MODE_ON      0x40
0654 #define   FORCE_RX50_LINK_ON        0x20
0655 #define   D3_DELINK_MODE_EN     0x10
0656 #define   USE_PESRTB_CTL_DELINK     0x08
0657 #define   DELAY_PIN_WAKE        0x04
0658 #define   RESET_PIN_WAKE        0x02
0659 #define   PM_WAKE_EN            0x01
0660 #define PM_CTRL4            0xFF47
0661 
0662 /* FW config info register */
0663 #define RTS5261_FW_CFG_INFO0        0xFF50
0664 #define   RTS5261_FW_EXPRESS_TEST_MASK  (0x01 << 0)
0665 #define   RTS5261_FW_EA_MODE_MASK   (0x01 << 5)
0666 #define RTS5261_FW_CFG0         0xFF54
0667 #define   RTS5261_FW_ENTER_EXPRESS  (0x01 << 0)
0668 
0669 #define RTS5261_FW_CFG1         0xFF55
0670 #define   RTS5261_SYS_CLK_SEL_MCU_CLK   (0x01 << 7)
0671 #define   RTS5261_CRC_CLK_SEL_MCU_CLK   (0x01 << 6)
0672 #define   RTS5261_FAKE_MCU_CLOCK_GATING (0x01 << 5)
0673 #define   RTS5261_MCU_BUS_SEL_MASK  (0x01 << 4)
0674 #define   RTS5261_MCU_CLOCK_SEL_MASK    (0x03 << 2)
0675 #define   RTS5261_MCU_CLOCK_SEL_16M (0x01 << 2)
0676 #define   RTS5261_MCU_CLOCK_GATING  (0x01 << 1)
0677 #define   RTS5261_DRIVER_ENABLE_FW  (0x01 << 0)
0678 
0679 #define REG_CFG_OOBS_OFF_TIMER 0xFEA6
0680 #define REG_CFG_OOBS_ON_TIMER 0xFEA7
0681 #define REG_CFG_VCM_ON_TIMER 0xFEA8
0682 #define REG_CFG_OOBS_POLLING 0xFEA9
0683 
0684 /* Memory mapping */
0685 #define SRAM_BASE           0xE600
0686 #define RBUF_BASE           0xF400
0687 #define PPBUF_BASE1         0xF800
0688 #define PPBUF_BASE2         0xFA00
0689 #define IMAGE_FLAG_ADDR0        0xCE80
0690 #define IMAGE_FLAG_ADDR1        0xCE81
0691 
0692 #define RREF_CFG            0xFF6C
0693 #define   RREF_VBGSEL_MASK      0x38
0694 #define   RREF_VBGSEL_1V25      0x28
0695 
0696 #define OOBS_CONFIG         0xFF6E
0697 #define   OOBS_AUTOK_DIS        0x80
0698 #define   OOBS_VAL_MASK         0x1F
0699 
0700 #define LDO_DV18_CFG            0xFF70
0701 #define   LDO_DV18_SR_MASK      0xC0
0702 #define   LDO_DV18_SR_DF        0x40
0703 #define   DV331812_MASK         0x70
0704 #define   DV331812_33           0x70
0705 #define   DV331812_17           0x30
0706 
0707 #define LDO_CONFIG2         0xFF71
0708 #define   LDO_D3318_MASK        0x07
0709 #define   LDO_D3318_33V         0x07
0710 #define   LDO_D3318_18V         0x02
0711 #define   DV331812_VDD1         0x04
0712 #define   DV331812_POWERON      0x08
0713 #define   DV331812_POWEROFF     0x00
0714 
0715 #define LDO_VCC_CFG0            0xFF72
0716 #define   LDO_VCC_LMTVTH_MASK       0x30
0717 #define   LDO_VCC_LMTVTH_2A     0x10
0718 /*RTS5260*/
0719 #define   RTS5260_DVCC_TUNE_MASK    0x70
0720 #define   RTS5260_DVCC_33       0x70
0721 
0722 /*RTS5261*/
0723 #define RTS5261_LDO1_CFG0       0xFF72
0724 #define   RTS5261_LDO1_OCP_THD_MASK (0x07 << 5)
0725 #define   RTS5261_LDO1_OCP_EN       (0x01 << 4)
0726 #define   RTS5261_LDO1_OCP_LMT_THD_MASK (0x03 << 2)
0727 #define   RTS5261_LDO1_OCP_LMT_EN   (0x01 << 1)
0728 
0729 #define LDO_VCC_CFG1            0xFF73
0730 #define   LDO_VCC_REF_TUNE_MASK     0x30
0731 #define   LDO_VCC_REF_1V2       0x20
0732 #define   LDO_VCC_TUNE_MASK     0x07
0733 #define   LDO_VCC_1V8           0x04
0734 #define   LDO_VCC_3V3           0x07
0735 #define   LDO_VCC_LMT_EN        0x08
0736 /*RTS5260*/
0737 #define   LDO_POW_SDVDD1_MASK       0x08
0738 #define   LDO_POW_SDVDD1_ON     0x08
0739 #define   LDO_POW_SDVDD1_OFF        0x00
0740 
0741 #define LDO_VIO_CFG         0xFF75
0742 #define   LDO_VIO_SR_MASK       0xC0
0743 #define   LDO_VIO_SR_DF         0x40
0744 #define   LDO_VIO_REF_TUNE_MASK     0x30
0745 #define   LDO_VIO_REF_1V2       0x20
0746 #define   LDO_VIO_TUNE_MASK     0x07
0747 #define   LDO_VIO_1V7           0x03
0748 #define   LDO_VIO_1V8           0x04
0749 #define   LDO_VIO_3V3           0x07
0750 
0751 #define LDO_DV12S_CFG           0xFF76
0752 #define   LDO_REF12_TUNE_MASK       0x18
0753 #define   LDO_REF12_TUNE_DF     0x10
0754 #define   LDO_D12_TUNE_MASK     0x07
0755 #define   LDO_D12_TUNE_DF       0x04
0756 
0757 #define LDO_AV12S_CFG           0xFF77
0758 #define   LDO_AV12S_TUNE_MASK       0x07
0759 #define   LDO_AV12S_TUNE_DF     0x04
0760 
0761 #define SD40_LDO_CTL1           0xFE7D
0762 #define   SD40_VIO_TUNE_MASK        0x70
0763 #define   SD40_VIO_TUNE_1V7     0x30
0764 #define   SD_VIO_LDO_1V8        0x40
0765 #define   SD_VIO_LDO_3V3        0x70
0766 
0767 #define RTS5260_AUTOLOAD_CFG4       0xFF7F
0768 #define   RTS5260_MIMO_DISABLE      0x8A
0769 /*RTS5261*/
0770 #define   RTS5261_AUX_CLK_16M_EN        (1 << 5)
0771 
0772 #define RTS5260_REG_GPIO_CTL0       0xFC1A
0773 #define   RTS5260_REG_GPIO_MASK     0x01
0774 #define   RTS5260_REG_GPIO_ON       0x01
0775 #define   RTS5260_REG_GPIO_OFF      0x00
0776 
0777 #define PWR_GLOBAL_CTRL         0xF200
0778 #define PCIE_L1_2_EN            0x0C
0779 #define PCIE_L1_1_EN            0x0A
0780 #define PCIE_L1_0_EN            0x09
0781 #define PWR_FE_CTL          0xF201
0782 #define PCIE_L1_2_PD_FE_EN      0x0C
0783 #define PCIE_L1_1_PD_FE_EN      0x0A
0784 #define PCIE_L1_0_PD_FE_EN      0x09
0785 #define CFG_PCIE_APHY_OFF_0     0xF204
0786 #define CFG_PCIE_APHY_OFF_0_DEFAULT 0xBF
0787 #define CFG_PCIE_APHY_OFF_1     0xF205
0788 #define CFG_PCIE_APHY_OFF_1_DEFAULT 0xFF
0789 #define CFG_PCIE_APHY_OFF_2     0xF206
0790 #define CFG_PCIE_APHY_OFF_2_DEFAULT 0x01
0791 #define CFG_PCIE_APHY_OFF_3     0xF207
0792 #define CFG_PCIE_APHY_OFF_3_DEFAULT 0x00
0793 #define CFG_L1_0_PCIE_MAC_RET_VALUE 0xF20C
0794 #define CFG_L1_0_PCIE_DPHY_RET_VALUE    0xF20E
0795 #define CFG_L1_0_SYS_RET_VALUE      0xF210
0796 #define CFG_L1_0_CRC_MISC_RET_VALUE 0xF212
0797 #define CFG_L1_0_CRC_SD30_RET_VALUE 0xF214
0798 #define CFG_L1_0_CRC_SD40_RET_VALUE 0xF216
0799 #define CFG_LP_FPWM_VALUE       0xF219
0800 #define CFG_LP_FPWM_VALUE_DEFAULT   0x18
0801 #define PWC_CDR             0xF253
0802 #define PWC_CDR_DEFAULT         0x03
0803 #define CFG_L1_0_RET_VALUE_DEFAULT  0x1B
0804 #define CFG_L1_0_CRC_MISC_RET_VALUE_DEFAULT 0x0C
0805 
0806 /* OCPCTL */
0807 #define SD_DETECT_EN            0x08
0808 #define SD_OCP_INT_EN           0x04
0809 #define SD_OCP_INT_CLR          0x02
0810 #define SD_OC_CLR           0x01
0811 
0812 #define SDVIO_DETECT_EN         (1 << 7)
0813 #define SDVIO_OCP_INT_EN        (1 << 6)
0814 #define SDVIO_OCP_INT_CLR       (1 << 5)
0815 #define SDVIO_OC_CLR            (1 << 4)
0816 
0817 /* OCPSTAT */
0818 #define SD_OCP_DETECT           0x08
0819 #define SD_OC_NOW           0x04
0820 #define SD_OC_EVER          0x02
0821 
0822 #define SDVIO_OC_NOW            (1 << 6)
0823 #define SDVIO_OC_EVER           (1 << 5)
0824 
0825 #define REG_OCPCTL          0xFD6A
0826 #define REG_OCPSTAT         0xFD6E
0827 #define REG_OCPGLITCH           0xFD6C
0828 #define REG_OCPPARA1            0xFD6B
0829 #define REG_OCPPARA2            0xFD6D
0830 
0831 /* rts5260 DV3318 OCP-related registers */
0832 #define REG_DV3318_OCPCTL       0xFD89
0833 #define DV3318_OCP_TIME_MASK    0xF0
0834 #define DV3318_DETECT_EN        0x08
0835 #define DV3318_OCP_INT_EN       0x04
0836 #define DV3318_OCP_INT_CLR      0x02
0837 #define DV3318_OCP_CLR          0x01
0838 
0839 #define REG_DV3318_OCPSTAT      0xFD8A
0840 #define DV3318_OCP_GlITCH_TIME_MASK 0xF0
0841 #define DV3318_OCP_DETECT       0x08
0842 #define DV3318_OCP_NOW          0x04
0843 #define DV3318_OCP_EVER         0x02
0844 
0845 #define SD_OCP_GLITCH_MASK      0x0F
0846 
0847 /* OCPPARA1 */
0848 #define SDVIO_OCP_TIME_60       0x00
0849 #define SDVIO_OCP_TIME_100      0x10
0850 #define SDVIO_OCP_TIME_200      0x20
0851 #define SDVIO_OCP_TIME_400      0x30
0852 #define SDVIO_OCP_TIME_600      0x40
0853 #define SDVIO_OCP_TIME_800      0x50
0854 #define SDVIO_OCP_TIME_1100     0x60
0855 #define SDVIO_OCP_TIME_MASK     0x70
0856 
0857 #define SD_OCP_TIME_60          0x00
0858 #define SD_OCP_TIME_100         0x01
0859 #define SD_OCP_TIME_200         0x02
0860 #define SD_OCP_TIME_400         0x03
0861 #define SD_OCP_TIME_600         0x04
0862 #define SD_OCP_TIME_800         0x05
0863 #define SD_OCP_TIME_1100        0x06
0864 #define SD_OCP_TIME_MASK        0x07
0865 
0866 /* OCPPARA2 */
0867 #define SDVIO_OCP_THD_190       0x00
0868 #define SDVIO_OCP_THD_250       0x10
0869 #define SDVIO_OCP_THD_320       0x20
0870 #define SDVIO_OCP_THD_380       0x30
0871 #define SDVIO_OCP_THD_440       0x40
0872 #define SDVIO_OCP_THD_500       0x50
0873 #define SDVIO_OCP_THD_570       0x60
0874 #define SDVIO_OCP_THD_630       0x70
0875 #define SDVIO_OCP_THD_MASK      0x70
0876 
0877 #define SD_OCP_THD_450          0x00
0878 #define SD_OCP_THD_550          0x01
0879 #define SD_OCP_THD_650          0x02
0880 #define SD_OCP_THD_750          0x03
0881 #define SD_OCP_THD_850          0x04
0882 #define SD_OCP_THD_950          0x05
0883 #define SD_OCP_THD_1050         0x06
0884 #define SD_OCP_THD_1150         0x07
0885 #define SD_OCP_THD_MASK         0x07
0886 
0887 #define SDVIO_OCP_GLITCH_MASK       0xF0
0888 #define SDVIO_OCP_GLITCH_NONE       0x00
0889 #define SDVIO_OCP_GLITCH_50U        0x10
0890 #define SDVIO_OCP_GLITCH_100U       0x20
0891 #define SDVIO_OCP_GLITCH_200U       0x30
0892 #define SDVIO_OCP_GLITCH_600U       0x40
0893 #define SDVIO_OCP_GLITCH_800U       0x50
0894 #define SDVIO_OCP_GLITCH_1M     0x60
0895 #define SDVIO_OCP_GLITCH_2M     0x70
0896 #define SDVIO_OCP_GLITCH_3M     0x80
0897 #define SDVIO_OCP_GLITCH_4M     0x90
0898 #define SDVIO_OCP_GLIVCH_5M     0xA0
0899 #define SDVIO_OCP_GLITCH_6M     0xB0
0900 #define SDVIO_OCP_GLITCH_7M     0xC0
0901 #define SDVIO_OCP_GLITCH_8M     0xD0
0902 #define SDVIO_OCP_GLITCH_9M     0xE0
0903 #define SDVIO_OCP_GLITCH_10M        0xF0
0904 
0905 #define SD_OCP_GLITCH_MASK      0x0F
0906 #define SD_OCP_GLITCH_NONE      0x00
0907 #define SD_OCP_GLITCH_50U       0x01
0908 #define SD_OCP_GLITCH_100U      0x02
0909 #define SD_OCP_GLITCH_200U      0x03
0910 #define SD_OCP_GLITCH_600U      0x04
0911 #define SD_OCP_GLITCH_800U      0x05
0912 #define SD_OCP_GLITCH_1M        0x06
0913 #define SD_OCP_GLITCH_2M        0x07
0914 #define SD_OCP_GLITCH_3M        0x08
0915 #define SD_OCP_GLITCH_4M        0x09
0916 #define SD_OCP_GLIVCH_5M        0x0A
0917 #define SD_OCP_GLITCH_6M        0x0B
0918 #define SD_OCP_GLITCH_7M        0x0C
0919 #define SD_OCP_GLITCH_8M        0x0D
0920 #define SD_OCP_GLITCH_9M        0x0E
0921 #define SD_OCP_GLITCH_10M       0x0F
0922 
0923 /* Phy register */
0924 #define PHY_PCR             0x00
0925 #define   PHY_PCR_FORCE_CODE        0xB000
0926 #define   PHY_PCR_OOBS_CALI_50      0x0800
0927 #define   PHY_PCR_OOBS_VCM_08       0x0200
0928 #define   PHY_PCR_OOBS_SEN_90       0x0040
0929 #define   PHY_PCR_RSSI_EN       0x0002
0930 #define   PHY_PCR_RX10K         0x0001
0931 
0932 #define PHY_RCR0            0x01
0933 #define PHY_RCR1            0x02
0934 #define   PHY_RCR1_ADP_TIME_4       0x0400
0935 #define   PHY_RCR1_VCO_COARSE       0x001F
0936 #define   PHY_RCR1_INIT_27S     0x0A1F
0937 #define PHY_SSCCR2          0x02
0938 #define   PHY_SSCCR2_PLL_NCODE      0x0A00
0939 #define   PHY_SSCCR2_TIME0      0x001C
0940 #define   PHY_SSCCR2_TIME2_WIDTH    0x0003
0941 
0942 #define PHY_RCR2            0x03
0943 #define   PHY_RCR2_EMPHASE_EN       0x8000
0944 #define   PHY_RCR2_NADJR        0x4000
0945 #define   PHY_RCR2_CDR_SR_2     0x0100
0946 #define   PHY_RCR2_FREQSEL_12       0x0040
0947 #define   PHY_RCR2_CDR_SC_12P       0x0010
0948 #define   PHY_RCR2_CALIB_LATE       0x0002
0949 #define   PHY_RCR2_INIT_27S     0xC152
0950 #define PHY_SSCCR3          0x03
0951 #define   PHY_SSCCR3_STEP_IN        0x2740
0952 #define   PHY_SSCCR3_CHECK_DELAY    0x0008
0953 #define _PHY_ANA03          0x03
0954 #define   _PHY_ANA03_TIMER_MAX      0x2700
0955 #define   _PHY_ANA03_OOBS_DEB_EN    0x0040
0956 #define   _PHY_CMU_DEBUG_EN     0x0008
0957 
0958 #define PHY_RTCR            0x04
0959 #define PHY_RDR             0x05
0960 #define   PHY_RDR_RXDSEL_1_9        0x4000
0961 #define   PHY_SSC_AUTO_PWD      0x0600
0962 #define PHY_TCR0            0x06
0963 #define PHY_TCR1            0x07
0964 #define PHY_TUNE            0x08
0965 #define   PHY_TUNE_TUNEREF_1_0      0x4000
0966 #define   PHY_TUNE_VBGSEL_1252      0x0C00
0967 #define   PHY_TUNE_SDBUS_33     0x0200
0968 #define   PHY_TUNE_TUNED18      0x01C0
0969 #define   PHY_TUNE_TUNED12      0X0020
0970 #define   PHY_TUNE_TUNEA12      0x0004
0971 #define   PHY_TUNE_VOLTAGE_MASK     0xFC3F
0972 #define   PHY_TUNE_VOLTAGE_3V3      0x03C0
0973 #define   PHY_TUNE_D18_1V8      0x0100
0974 #define   PHY_TUNE_D18_1V7      0x0080
0975 #define PHY_ANA08           0x08
0976 #define   PHY_ANA08_RX_EQ_DCGAIN    0x5000
0977 #define   PHY_ANA08_SEL_RX_EN       0x0400
0978 #define   PHY_ANA08_RX_EQ_VAL       0x03C0
0979 #define   PHY_ANA08_SCP         0x0020
0980 #define   PHY_ANA08_SEL_IPI     0x0004
0981 
0982 #define PHY_IMR             0x09
0983 #define PHY_BPCR            0x0A
0984 #define   PHY_BPCR_IBRXSEL      0x0400
0985 #define   PHY_BPCR_IBTXSEL      0x0100
0986 #define   PHY_BPCR_IB_FILTER        0x0080
0987 #define   PHY_BPCR_CMIRROR_EN       0x0040
0988 
0989 #define PHY_BIST            0x0B
0990 #define PHY_RAW_L           0x0C
0991 #define PHY_RAW_H           0x0D
0992 #define PHY_RAW_DATA            0x0E
0993 #define PHY_HOST_CLK_CTRL       0x0F
0994 #define PHY_DMR             0x10
0995 #define PHY_BACR            0x11
0996 #define   PHY_BACR_BASIC_MASK       0xFFF3
0997 #define PHY_IER             0x12
0998 #define PHY_BCSR            0x13
0999 #define PHY_BPR             0x14
1000 #define PHY_BPNR2           0x15
1001 #define PHY_BPNR            0x16
1002 #define PHY_BRNR2           0x17
1003 #define PHY_BENR            0x18
1004 #define PHY_REV             0x19
1005 #define   PHY_REV_RESV          0xE000
1006 #define   PHY_REV_RXIDLE_LATCHED    0x1000
1007 #define   PHY_REV_P1_EN         0x0800
1008 #define   PHY_REV_RXIDLE_EN     0x0400
1009 #define   PHY_REV_CLKREQ_TX_EN      0x0200
1010 #define   PHY_REV_CLKREQ_RX_EN      0x0100
1011 #define   PHY_REV_CLKREQ_DT_1_0     0x0040
1012 #define   PHY_REV_STOP_CLKRD        0x0020
1013 #define   PHY_REV_RX_PWST       0x0008
1014 #define   PHY_REV_STOP_CLKWR        0x0004
1015 #define _PHY_REV0           0x19
1016 #define   _PHY_REV0_FILTER_OUT      0x3800
1017 #define   _PHY_REV0_CDR_BYPASS_PFD  0x0100
1018 #define   _PHY_REV0_CDR_RX_IDLE_BYPASS  0x0002
1019 
1020 #define PHY_FLD0            0x1A
1021 #define PHY_ANA1A           0x1A
1022 #define   PHY_ANA1A_TXR_LOOPBACK    0x2000
1023 #define   PHY_ANA1A_RXT_BIST        0x0500
1024 #define   PHY_ANA1A_TXR_BIST        0x0040
1025 #define   PHY_ANA1A_REV         0x0006
1026 #define   PHY_FLD0_INIT_27S     0x2546
1027 #define PHY_FLD1            0x1B
1028 #define PHY_FLD2            0x1C
1029 #define PHY_FLD3            0x1D
1030 #define   PHY_FLD3_TIMER_4      0x0800
1031 #define   PHY_FLD3_TIMER_6      0x0020
1032 #define   PHY_FLD3_RXDELINK     0x0004
1033 #define   PHY_FLD3_INIT_27S     0x0004
1034 #define PHY_ANA1D           0x1D
1035 #define   PHY_ANA1D_DEBUG_ADDR      0x0004
1036 #define _PHY_FLD0           0x1D
1037 #define   _PHY_FLD0_CLK_REQ_20C     0x8000
1038 #define   _PHY_FLD0_RX_IDLE_EN      0x1000
1039 #define   _PHY_FLD0_BIT_ERR_RSTN    0x0800
1040 #define   _PHY_FLD0_BER_COUNT       0x01E0
1041 #define   _PHY_FLD0_BER_TIMER       0x001E
1042 #define   _PHY_FLD0_CHECK_EN        0x0001
1043 
1044 #define PHY_FLD4            0x1E
1045 #define   PHY_FLD4_FLDEN_SEL        0x4000
1046 #define   PHY_FLD4_REQ_REF      0x2000
1047 #define   PHY_FLD4_RXAMP_OFF        0x1000
1048 #define   PHY_FLD4_REQ_ADDA     0x0800
1049 #define   PHY_FLD4_BER_COUNT        0x00E0
1050 #define   PHY_FLD4_BER_TIMER        0x000A
1051 #define   PHY_FLD4_BER_CHK_EN       0x0001
1052 #define   PHY_FLD4_INIT_27S     0x5C7F
1053 #define PHY_DIG1E           0x1E
1054 #define   PHY_DIG1E_REV         0x4000
1055 #define   PHY_DIG1E_D0_X_D1     0x1000
1056 #define   PHY_DIG1E_RX_ON_HOST      0x0800
1057 #define   PHY_DIG1E_RCLK_REF_HOST   0x0400
1058 #define   PHY_DIG1E_RCLK_TX_EN_KEEP 0x0040
1059 #define   PHY_DIG1E_RCLK_TX_TERM_KEEP   0x0020
1060 #define   PHY_DIG1E_RCLK_RX_EIDLE_ON    0x0010
1061 #define   PHY_DIG1E_TX_TERM_KEEP    0x0008
1062 #define   PHY_DIG1E_RX_TERM_KEEP    0x0004
1063 #define   PHY_DIG1E_TX_EN_KEEP      0x0002
1064 #define   PHY_DIG1E_RX_EN_KEEP      0x0001
1065 #define PHY_DUM_REG         0x1F
1066 
1067 #define PCR_SETTING_REG1        0x724
1068 #define PCR_SETTING_REG2        0x814
1069 #define PCR_SETTING_REG3        0x747
1070 #define PCR_SETTING_REG4        0x818
1071 #define PCR_SETTING_REG5        0x81C
1072 
1073 
1074 #define rtsx_pci_init_cmd(pcr)      ((pcr)->ci = 0)
1075 
1076 #define RTS5227_DEVICE_ID       0x5227
1077 #define RTS_MAX_TIMES_FREQ_REDUCTION    8
1078 
1079 struct rtsx_pcr;
1080 
1081 struct pcr_handle {
1082     struct rtsx_pcr         *pcr;
1083 };
1084 
1085 struct pcr_ops {
1086     int (*write_phy)(struct rtsx_pcr *pcr, u8 addr, u16 val);
1087     int (*read_phy)(struct rtsx_pcr *pcr, u8 addr, u16 *val);
1088     int     (*extra_init_hw)(struct rtsx_pcr *pcr);
1089     int     (*optimize_phy)(struct rtsx_pcr *pcr);
1090     int     (*turn_on_led)(struct rtsx_pcr *pcr);
1091     int     (*turn_off_led)(struct rtsx_pcr *pcr);
1092     int     (*enable_auto_blink)(struct rtsx_pcr *pcr);
1093     int     (*disable_auto_blink)(struct rtsx_pcr *pcr);
1094     int     (*card_power_on)(struct rtsx_pcr *pcr, int card);
1095     int     (*card_power_off)(struct rtsx_pcr *pcr, int card);
1096     int     (*switch_output_voltage)(struct rtsx_pcr *pcr,
1097                         u8 voltage);
1098     unsigned int    (*cd_deglitch)(struct rtsx_pcr *pcr);
1099     int     (*conv_clk_and_div_n)(int clk, int dir);
1100     void        (*fetch_vendor_settings)(struct rtsx_pcr *pcr);
1101     void        (*force_power_down)(struct rtsx_pcr *pcr, u8 pm_state, bool runtime);
1102     void        (*stop_cmd)(struct rtsx_pcr *pcr);
1103 
1104     void (*set_aspm)(struct rtsx_pcr *pcr, bool enable);
1105     void (*set_l1off_cfg_sub_d0)(struct rtsx_pcr *pcr, int active);
1106     void (*enable_ocp)(struct rtsx_pcr *pcr);
1107     void (*disable_ocp)(struct rtsx_pcr *pcr);
1108     void (*init_ocp)(struct rtsx_pcr *pcr);
1109     void (*process_ocp)(struct rtsx_pcr *pcr);
1110     int (*get_ocpstat)(struct rtsx_pcr *pcr, u8 *val);
1111     void (*clear_ocpstat)(struct rtsx_pcr *pcr);
1112 };
1113 
1114 enum PDEV_STAT  {PDEV_STAT_IDLE, PDEV_STAT_RUN};
1115 enum ASPM_MODE  {ASPM_MODE_CFG, ASPM_MODE_REG};
1116 
1117 #define ASPM_L1_1_EN            BIT(0)
1118 #define ASPM_L1_2_EN            BIT(1)
1119 #define PM_L1_1_EN              BIT(2)
1120 #define PM_L1_2_EN              BIT(3)
1121 #define LTR_L1SS_PWR_GATE_EN    BIT(4)
1122 #define L1_SNOOZE_TEST_EN       BIT(5)
1123 #define LTR_L1SS_PWR_GATE_CHECK_CARD_EN BIT(6)
1124 
1125 /*
1126  * struct rtsx_cr_option  - card reader option
1127  * @dev_flags: device flags
1128  * @force_clkreq_0: force clock request
1129  * @ltr_en: enable ltr mode flag
1130  * @ltr_enabled: ltr mode in configure space flag
1131  * @ltr_active: ltr mode status
1132  * @ltr_active_latency: ltr mode active latency
1133  * @ltr_idle_latency: ltr mode idle latency
1134  * @ltr_l1off_latency: ltr mode l1off latency
1135  * @l1_snooze_delay: l1 snooze delay
1136  * @ltr_l1off_sspwrgate: ltr l1off sspwrgate
1137  * @ltr_l1off_snooze_sspwrgate: ltr l1off snooze sspwrgate
1138  * @ocp_en: enable ocp flag
1139  * @sd_400mA_ocp_thd: 400mA ocp thd
1140  * @sd_800mA_ocp_thd: 800mA ocp thd
1141  */
1142 struct rtsx_cr_option {
1143     u32 dev_flags;
1144     bool force_clkreq_0;
1145     bool ltr_en;
1146     bool ltr_enabled;
1147     bool ltr_active;
1148     u32 ltr_active_latency;
1149     u32 ltr_idle_latency;
1150     u32 ltr_l1off_latency;
1151     u32 l1_snooze_delay;
1152     u8 ltr_l1off_sspwrgate;
1153     u8 ltr_l1off_snooze_sspwrgate;
1154     bool ocp_en;
1155     u8 sd_400mA_ocp_thd;
1156     u8 sd_800mA_ocp_thd;
1157 };
1158 
1159 /*
1160  * struct rtsx_hw_param  - card reader hardware param
1161  * @interrupt_en: indicate which interrutp enable
1162  * @ocp_glitch: ocp glitch time
1163  */
1164 struct rtsx_hw_param {
1165     u32 interrupt_en;
1166     u8 ocp_glitch;
1167 };
1168 
1169 #define rtsx_set_dev_flag(cr, flag) \
1170     ((cr)->option.dev_flags |= (flag))
1171 #define rtsx_clear_dev_flag(cr, flag) \
1172     ((cr)->option.dev_flags &= ~(flag))
1173 #define rtsx_check_dev_flag(cr, flag) \
1174     ((cr)->option.dev_flags & (flag))
1175 
1176 struct rtsx_pcr {
1177     struct pci_dev          *pci;
1178     unsigned int            id;
1179     struct rtsx_cr_option   option;
1180     struct rtsx_hw_param hw_param;
1181 
1182     /* pci resources */
1183     unsigned long           addr;
1184     void __iomem            *remap_addr;
1185     int             irq;
1186 
1187     /* host reserved buffer */
1188     void                *rtsx_resv_buf;
1189     dma_addr_t          rtsx_resv_buf_addr;
1190 
1191     void                *host_cmds_ptr;
1192     dma_addr_t          host_cmds_addr;
1193     int             ci;
1194 
1195     void                *host_sg_tbl_ptr;
1196     dma_addr_t          host_sg_tbl_addr;
1197     int             sgi;
1198 
1199     u32             bier;
1200     char                trans_result;
1201 
1202     unsigned int            card_inserted;
1203     unsigned int            card_removed;
1204     unsigned int            card_exist;
1205 
1206     struct delayed_work     carddet_work;
1207 
1208     spinlock_t          lock;
1209     struct mutex            pcr_mutex;
1210     struct completion       *done;
1211     struct completion       *finish_me;
1212 
1213     unsigned int            cur_clock;
1214     bool                remove_pci;
1215     bool                msi_en;
1216 
1217 #define EXTRA_CAPS_SD_SDR50     (1 << 0)
1218 #define EXTRA_CAPS_SD_SDR104        (1 << 1)
1219 #define EXTRA_CAPS_SD_DDR50     (1 << 2)
1220 #define EXTRA_CAPS_MMC_HSDDR        (1 << 3)
1221 #define EXTRA_CAPS_MMC_HS200        (1 << 4)
1222 #define EXTRA_CAPS_MMC_8BIT     (1 << 5)
1223 #define EXTRA_CAPS_NO_MMC       (1 << 7)
1224 #define EXTRA_CAPS_SD_EXPRESS       (1 << 8)
1225     u32             extra_caps;
1226 
1227 #define IC_VER_A            0
1228 #define IC_VER_B            1
1229 #define IC_VER_C            2
1230 #define IC_VER_D            3
1231     u8              ic_version;
1232 
1233     u8              sd30_drive_sel_1v8;
1234     u8              sd30_drive_sel_3v3;
1235     u8              card_drive_sel;
1236 #define ASPM_L1_EN          0x02
1237     u8              aspm_en;
1238     enum ASPM_MODE          aspm_mode;
1239     bool                aspm_enabled;
1240 
1241 #define PCR_MS_PMOS         (1 << 0)
1242 #define PCR_REVERSE_SOCKET      (1 << 1)
1243     u32             flags;
1244 
1245     u32             tx_initial_phase;
1246     u32             rx_initial_phase;
1247 
1248     const u32           *sd_pull_ctl_enable_tbl;
1249     const u32           *sd_pull_ctl_disable_tbl;
1250     const u32           *ms_pull_ctl_enable_tbl;
1251     const u32           *ms_pull_ctl_disable_tbl;
1252 
1253     const struct pcr_ops        *ops;
1254     enum PDEV_STAT          state;
1255 
1256     u16             reg_pm_ctrl3;
1257 
1258     int             num_slots;
1259     struct rtsx_slot        *slots;
1260 
1261     u8              dma_error_count;
1262     u8          ocp_stat;
1263     u8          ocp_stat2;
1264     u8          rtd3_en;
1265 };
1266 
1267 #define PID_524A    0x524A
1268 #define PID_5249    0x5249
1269 #define PID_5250    0x5250
1270 #define PID_525A    0x525A
1271 #define PID_5260    0x5260
1272 #define PID_5261    0x5261
1273 #define PID_5228    0x5228
1274 
1275 #define CHK_PCI_PID(pcr, pid)       ((pcr)->pci->device == (pid))
1276 #define PCI_VID(pcr)            ((pcr)->pci->vendor)
1277 #define PCI_PID(pcr)            ((pcr)->pci->device)
1278 #define is_version(pcr, pid, ver)               \
1279     (CHK_PCI_PID(pcr, pid) && (pcr)->ic_version == (ver))
1280 #define is_version_higher_than(pcr, pid, ver)           \
1281     (CHK_PCI_PID(pcr, pid) && (pcr)->ic_version > (ver))
1282 #define pcr_dbg(pcr, fmt, arg...)               \
1283     dev_dbg(&(pcr)->pci->dev, fmt, ##arg)
1284 
1285 #define SDR104_PHASE(val)       ((val) & 0xFF)
1286 #define SDR50_PHASE(val)        (((val) >> 8) & 0xFF)
1287 #define DDR50_PHASE(val)        (((val) >> 16) & 0xFF)
1288 #define SDR104_TX_PHASE(pcr)        SDR104_PHASE((pcr)->tx_initial_phase)
1289 #define SDR50_TX_PHASE(pcr)     SDR50_PHASE((pcr)->tx_initial_phase)
1290 #define DDR50_TX_PHASE(pcr)     DDR50_PHASE((pcr)->tx_initial_phase)
1291 #define SDR104_RX_PHASE(pcr)        SDR104_PHASE((pcr)->rx_initial_phase)
1292 #define SDR50_RX_PHASE(pcr)     SDR50_PHASE((pcr)->rx_initial_phase)
1293 #define DDR50_RX_PHASE(pcr)     DDR50_PHASE((pcr)->rx_initial_phase)
1294 #define SET_CLOCK_PHASE(sdr104, sdr50, ddr50)   \
1295                 (((ddr50) << 16) | ((sdr50) << 8) | (sdr104))
1296 
1297 void rtsx_pci_start_run(struct rtsx_pcr *pcr);
1298 int rtsx_pci_write_register(struct rtsx_pcr *pcr, u16 addr, u8 mask, u8 data);
1299 int rtsx_pci_read_register(struct rtsx_pcr *pcr, u16 addr, u8 *data);
1300 int rtsx_pci_write_phy_register(struct rtsx_pcr *pcr, u8 addr, u16 val);
1301 int rtsx_pci_read_phy_register(struct rtsx_pcr *pcr, u8 addr, u16 *val);
1302 void rtsx_pci_stop_cmd(struct rtsx_pcr *pcr);
1303 void rtsx_pci_add_cmd(struct rtsx_pcr *pcr,
1304         u8 cmd_type, u16 reg_addr, u8 mask, u8 data);
1305 void rtsx_pci_send_cmd_no_wait(struct rtsx_pcr *pcr);
1306 int rtsx_pci_send_cmd(struct rtsx_pcr *pcr, int timeout);
1307 int rtsx_pci_transfer_data(struct rtsx_pcr *pcr, struct scatterlist *sglist,
1308         int num_sg, bool read, int timeout);
1309 int rtsx_pci_dma_map_sg(struct rtsx_pcr *pcr, struct scatterlist *sglist,
1310         int num_sg, bool read);
1311 void rtsx_pci_dma_unmap_sg(struct rtsx_pcr *pcr, struct scatterlist *sglist,
1312         int num_sg, bool read);
1313 int rtsx_pci_dma_transfer(struct rtsx_pcr *pcr, struct scatterlist *sglist,
1314         int count, bool read, int timeout);
1315 int rtsx_pci_read_ppbuf(struct rtsx_pcr *pcr, u8 *buf, int buf_len);
1316 int rtsx_pci_write_ppbuf(struct rtsx_pcr *pcr, u8 *buf, int buf_len);
1317 int rtsx_pci_card_pull_ctl_enable(struct rtsx_pcr *pcr, int card);
1318 int rtsx_pci_card_pull_ctl_disable(struct rtsx_pcr *pcr, int card);
1319 int rtsx_pci_switch_clock(struct rtsx_pcr *pcr, unsigned int card_clock,
1320         u8 ssc_depth, bool initial_mode, bool double_clk, bool vpclk);
1321 int rtsx_pci_card_power_on(struct rtsx_pcr *pcr, int card);
1322 int rtsx_pci_card_power_off(struct rtsx_pcr *pcr, int card);
1323 int rtsx_pci_card_exclusive_check(struct rtsx_pcr *pcr, int card);
1324 int rtsx_pci_switch_output_voltage(struct rtsx_pcr *pcr, u8 voltage);
1325 unsigned int rtsx_pci_card_exist(struct rtsx_pcr *pcr);
1326 void rtsx_pci_complete_unfinished_transfer(struct rtsx_pcr *pcr);
1327 
1328 static inline u8 *rtsx_pci_get_cmd_data(struct rtsx_pcr *pcr)
1329 {
1330     return (u8 *)(pcr->host_cmds_ptr);
1331 }
1332 
1333 static inline void rtsx_pci_write_be32(struct rtsx_pcr *pcr, u16 reg, u32 val)
1334 {
1335     rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, reg,     0xFF, val >> 24);
1336     rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, reg + 1, 0xFF, val >> 16);
1337     rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, reg + 2, 0xFF, val >> 8);
1338     rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, reg + 3, 0xFF, val);
1339 }
1340 
1341 static inline int rtsx_pci_update_phy(struct rtsx_pcr *pcr, u8 addr,
1342     u16 mask, u16 append)
1343 {
1344     int err;
1345     u16 val;
1346 
1347     err = rtsx_pci_read_phy_register(pcr, addr, &val);
1348     if (err < 0)
1349         return err;
1350 
1351     return rtsx_pci_write_phy_register(pcr, addr, (val & mask) | append);
1352 }
1353 
1354 #endif