rtsx_pci.h 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051
  1. /* Driver for Realtek PCI-Express card reader
  2. *
  3. * Copyright(c) 2009-2013 Realtek Semiconductor Corp. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2, or (at your option) any
  8. * later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * Author:
  19. * Wei WANG <wei_wang@realsil.com.cn>
  20. */
  21. #ifndef __RTSX_PCI_H
  22. #define __RTSX_PCI_H
  23. #include <linux/sched.h>
  24. #include <linux/pci.h>
  25. #include <linux/mfd/rtsx_common.h>
  26. #define MAX_RW_REG_CNT 1024
  27. #define RTSX_HCBAR 0x00
  28. #define RTSX_HCBCTLR 0x04
  29. #define STOP_CMD (0x01 << 28)
  30. #define READ_REG_CMD 0
  31. #define WRITE_REG_CMD 1
  32. #define CHECK_REG_CMD 2
  33. #define RTSX_HDBAR 0x08
  34. #define SG_INT 0x04
  35. #define SG_END 0x02
  36. #define SG_VALID 0x01
  37. #define SG_NO_OP 0x00
  38. #define SG_TRANS_DATA (0x02 << 4)
  39. #define SG_LINK_DESC (0x03 << 4)
  40. #define RTSX_HDBCTLR 0x0C
  41. #define SDMA_MODE 0x00
  42. #define ADMA_MODE (0x02 << 26)
  43. #define STOP_DMA (0x01 << 28)
  44. #define TRIG_DMA (0x01 << 31)
  45. #define RTSX_HAIMR 0x10
  46. #define HAIMR_TRANS_START (0x01 << 31)
  47. #define HAIMR_READ 0x00
  48. #define HAIMR_WRITE (0x01 << 30)
  49. #define HAIMR_READ_START (HAIMR_TRANS_START | HAIMR_READ)
  50. #define HAIMR_WRITE_START (HAIMR_TRANS_START | HAIMR_WRITE)
  51. #define HAIMR_TRANS_END (HAIMR_TRANS_START)
  52. #define RTSX_BIPR 0x14
  53. #define CMD_DONE_INT (1 << 31)
  54. #define DATA_DONE_INT (1 << 30)
  55. #define TRANS_OK_INT (1 << 29)
  56. #define TRANS_FAIL_INT (1 << 28)
  57. #define XD_INT (1 << 27)
  58. #define MS_INT (1 << 26)
  59. #define SD_INT (1 << 25)
  60. #define GPIO0_INT (1 << 24)
  61. #define OC_INT (1 << 23)
  62. #define SD_WRITE_PROTECT (1 << 19)
  63. #define XD_EXIST (1 << 18)
  64. #define MS_EXIST (1 << 17)
  65. #define SD_EXIST (1 << 16)
  66. #define DELINK_INT GPIO0_INT
  67. #define MS_OC_INT (1 << 23)
  68. #define SD_OC_INT (1 << 22)
  69. #define CARD_INT (XD_INT | MS_INT | SD_INT)
  70. #define NEED_COMPLETE_INT (DATA_DONE_INT | TRANS_OK_INT | TRANS_FAIL_INT)
  71. #define RTSX_INT (CMD_DONE_INT | NEED_COMPLETE_INT | \
  72. CARD_INT | GPIO0_INT | OC_INT)
  73. #define CARD_EXIST (XD_EXIST | MS_EXIST | SD_EXIST)
  74. #define RTSX_BIER 0x18
  75. #define CMD_DONE_INT_EN (1 << 31)
  76. #define DATA_DONE_INT_EN (1 << 30)
  77. #define TRANS_OK_INT_EN (1 << 29)
  78. #define TRANS_FAIL_INT_EN (1 << 28)
  79. #define XD_INT_EN (1 << 27)
  80. #define MS_INT_EN (1 << 26)
  81. #define SD_INT_EN (1 << 25)
  82. #define GPIO0_INT_EN (1 << 24)
  83. #define OC_INT_EN (1 << 23)
  84. #define DELINK_INT_EN GPIO0_INT_EN
  85. #define MS_OC_INT_EN (1 << 23)
  86. #define SD_OC_INT_EN (1 << 22)
  87. /*
  88. * macros for easy use
  89. */
  90. #define rtsx_pci_writel(pcr, reg, value) \
  91. iowrite32(value, (pcr)->remap_addr + reg)
  92. #define rtsx_pci_readl(pcr, reg) \
  93. ioread32((pcr)->remap_addr + reg)
  94. #define rtsx_pci_writew(pcr, reg, value) \
  95. iowrite16(value, (pcr)->remap_addr + reg)
  96. #define rtsx_pci_readw(pcr, reg) \
  97. ioread16((pcr)->remap_addr + reg)
  98. #define rtsx_pci_writeb(pcr, reg, value) \
  99. iowrite8(value, (pcr)->remap_addr + reg)
  100. #define rtsx_pci_readb(pcr, reg) \
  101. ioread8((pcr)->remap_addr + reg)
  102. #define rtsx_pci_read_config_byte(pcr, where, val) \
  103. pci_read_config_byte((pcr)->pci, where, val)
  104. #define rtsx_pci_write_config_byte(pcr, where, val) \
  105. pci_write_config_byte((pcr)->pci, where, val)
  106. #define rtsx_pci_read_config_dword(pcr, where, val) \
  107. pci_read_config_dword((pcr)->pci, where, val)
  108. #define rtsx_pci_write_config_dword(pcr, where, val) \
  109. pci_write_config_dword((pcr)->pci, where, val)
  110. #define STATE_TRANS_NONE 0
  111. #define STATE_TRANS_CMD 1
  112. #define STATE_TRANS_BUF 2
  113. #define STATE_TRANS_SG 3
  114. #define TRANS_NOT_READY 0
  115. #define TRANS_RESULT_OK 1
  116. #define TRANS_RESULT_FAIL 2
  117. #define TRANS_NO_DEVICE 3
  118. #define RTSX_RESV_BUF_LEN 4096
  119. #define HOST_CMDS_BUF_LEN 1024
  120. #define HOST_SG_TBL_BUF_LEN (RTSX_RESV_BUF_LEN - HOST_CMDS_BUF_LEN)
  121. #define HOST_SG_TBL_ITEMS (HOST_SG_TBL_BUF_LEN / 8)
  122. #define MAX_SG_ITEM_LEN 0x80000
  123. #define HOST_TO_DEVICE 0
  124. #define DEVICE_TO_HOST 1
  125. #define OUTPUT_3V3 0
  126. #define OUTPUT_1V8 1
  127. #define RTSX_PHASE_MAX 32
  128. #define RX_TUNING_CNT 3
  129. #define MS_CFG 0xFD40
  130. #define SAMPLE_TIME_RISING 0x00
  131. #define SAMPLE_TIME_FALLING 0x80
  132. #define PUSH_TIME_DEFAULT 0x00
  133. #define PUSH_TIME_ODD 0x40
  134. #define NO_EXTEND_TOGGLE 0x00
  135. #define EXTEND_TOGGLE_CHK 0x20
  136. #define MS_BUS_WIDTH_1 0x00
  137. #define MS_BUS_WIDTH_4 0x10
  138. #define MS_BUS_WIDTH_8 0x18
  139. #define MS_2K_SECTOR_MODE 0x04
  140. #define MS_512_SECTOR_MODE 0x00
  141. #define MS_TOGGLE_TIMEOUT_EN 0x00
  142. #define MS_TOGGLE_TIMEOUT_DISEN 0x01
  143. #define MS_NO_CHECK_INT 0x02
  144. #define MS_TPC 0xFD41
  145. #define MS_TRANS_CFG 0xFD42
  146. #define WAIT_INT 0x80
  147. #define NO_WAIT_INT 0x00
  148. #define NO_AUTO_READ_INT_REG 0x00
  149. #define AUTO_READ_INT_REG 0x40
  150. #define MS_CRC16_ERR 0x20
  151. #define MS_RDY_TIMEOUT 0x10
  152. #define MS_INT_CMDNK 0x08
  153. #define MS_INT_BREQ 0x04
  154. #define MS_INT_ERR 0x02
  155. #define MS_INT_CED 0x01
  156. #define MS_TRANSFER 0xFD43
  157. #define MS_TRANSFER_START 0x80
  158. #define MS_TRANSFER_END 0x40
  159. #define MS_TRANSFER_ERR 0x20
  160. #define MS_BS_STATE 0x10
  161. #define MS_TM_READ_BYTES 0x00
  162. #define MS_TM_NORMAL_READ 0x01
  163. #define MS_TM_WRITE_BYTES 0x04
  164. #define MS_TM_NORMAL_WRITE 0x05
  165. #define MS_TM_AUTO_READ 0x08
  166. #define MS_TM_AUTO_WRITE 0x0C
  167. #define MS_INT_REG 0xFD44
  168. #define MS_BYTE_CNT 0xFD45
  169. #define MS_SECTOR_CNT_L 0xFD46
  170. #define MS_SECTOR_CNT_H 0xFD47
  171. #define MS_DBUS_H 0xFD48
  172. #define SD_CFG1 0xFDA0
  173. #define SD_CLK_DIVIDE_0 0x00
  174. #define SD_CLK_DIVIDE_256 0xC0
  175. #define SD_CLK_DIVIDE_128 0x80
  176. #define SD_BUS_WIDTH_1BIT 0x00
  177. #define SD_BUS_WIDTH_4BIT 0x01
  178. #define SD_BUS_WIDTH_8BIT 0x02
  179. #define SD_ASYNC_FIFO_NOT_RST 0x10
  180. #define SD_20_MODE 0x00
  181. #define SD_DDR_MODE 0x04
  182. #define SD_30_MODE 0x08
  183. #define SD_CLK_DIVIDE_MASK 0xC0
  184. #define SD_CFG2 0xFDA1
  185. #define SD_CALCULATE_CRC7 0x00
  186. #define SD_NO_CALCULATE_CRC7 0x80
  187. #define SD_CHECK_CRC16 0x00
  188. #define SD_NO_CHECK_CRC16 0x40
  189. #define SD_NO_CHECK_WAIT_CRC_TO 0x20
  190. #define SD_WAIT_BUSY_END 0x08
  191. #define SD_NO_WAIT_BUSY_END 0x00
  192. #define SD_CHECK_CRC7 0x00
  193. #define SD_NO_CHECK_CRC7 0x04
  194. #define SD_RSP_LEN_0 0x00
  195. #define SD_RSP_LEN_6 0x01
  196. #define SD_RSP_LEN_17 0x02
  197. #define SD_RSP_TYPE_R0 0x04
  198. #define SD_RSP_TYPE_R1 0x01
  199. #define SD_RSP_TYPE_R1b 0x09
  200. #define SD_RSP_TYPE_R2 0x02
  201. #define SD_RSP_TYPE_R3 0x05
  202. #define SD_RSP_TYPE_R4 0x05
  203. #define SD_RSP_TYPE_R5 0x01
  204. #define SD_RSP_TYPE_R6 0x01
  205. #define SD_RSP_TYPE_R7 0x01
  206. #define SD_CFG3 0xFDA2
  207. #define SD_RSP_80CLK_TIMEOUT_EN 0x01
  208. #define SD_STAT1 0xFDA3
  209. #define SD_CRC7_ERR 0x80
  210. #define SD_CRC16_ERR 0x40
  211. #define SD_CRC_WRITE_ERR 0x20
  212. #define SD_CRC_WRITE_ERR_MASK 0x1C
  213. #define GET_CRC_TIME_OUT 0x02
  214. #define SD_TUNING_COMPARE_ERR 0x01
  215. #define SD_STAT2 0xFDA4
  216. #define SD_RSP_80CLK_TIMEOUT 0x01
  217. #define SD_BUS_STAT 0xFDA5
  218. #define SD_CLK_TOGGLE_EN 0x80
  219. #define SD_CLK_FORCE_STOP 0x40
  220. #define SD_DAT3_STATUS 0x10
  221. #define SD_DAT2_STATUS 0x08
  222. #define SD_DAT1_STATUS 0x04
  223. #define SD_DAT0_STATUS 0x02
  224. #define SD_CMD_STATUS 0x01
  225. #define SD_PAD_CTL 0xFDA6
  226. #define SD_IO_USING_1V8 0x80
  227. #define SD_IO_USING_3V3 0x7F
  228. #define TYPE_A_DRIVING 0x00
  229. #define TYPE_B_DRIVING 0x01
  230. #define TYPE_C_DRIVING 0x02
  231. #define TYPE_D_DRIVING 0x03
  232. #define SD_SAMPLE_POINT_CTL 0xFDA7
  233. #define DDR_FIX_RX_DAT 0x00
  234. #define DDR_VAR_RX_DAT 0x80
  235. #define DDR_FIX_RX_DAT_EDGE 0x00
  236. #define DDR_FIX_RX_DAT_14_DELAY 0x40
  237. #define DDR_FIX_RX_CMD 0x00
  238. #define DDR_VAR_RX_CMD 0x20
  239. #define DDR_FIX_RX_CMD_POS_EDGE 0x00
  240. #define DDR_FIX_RX_CMD_14_DELAY 0x10
  241. #define SD20_RX_POS_EDGE 0x00
  242. #define SD20_RX_14_DELAY 0x08
  243. #define SD20_RX_SEL_MASK 0x08
  244. #define SD_PUSH_POINT_CTL 0xFDA8
  245. #define DDR_FIX_TX_CMD_DAT 0x00
  246. #define DDR_VAR_TX_CMD_DAT 0x80
  247. #define DDR_FIX_TX_DAT_14_TSU 0x00
  248. #define DDR_FIX_TX_DAT_12_TSU 0x40
  249. #define DDR_FIX_TX_CMD_NEG_EDGE 0x00
  250. #define DDR_FIX_TX_CMD_14_AHEAD 0x20
  251. #define SD20_TX_NEG_EDGE 0x00
  252. #define SD20_TX_14_AHEAD 0x10
  253. #define SD20_TX_SEL_MASK 0x10
  254. #define DDR_VAR_SDCLK_POL_SWAP 0x01
  255. #define SD_CMD0 0xFDA9
  256. #define SD_CMD_START 0x40
  257. #define SD_CMD1 0xFDAA
  258. #define SD_CMD2 0xFDAB
  259. #define SD_CMD3 0xFDAC
  260. #define SD_CMD4 0xFDAD
  261. #define SD_CMD5 0xFDAE
  262. #define SD_BYTE_CNT_L 0xFDAF
  263. #define SD_BYTE_CNT_H 0xFDB0
  264. #define SD_BLOCK_CNT_L 0xFDB1
  265. #define SD_BLOCK_CNT_H 0xFDB2
  266. #define SD_TRANSFER 0xFDB3
  267. #define SD_TRANSFER_START 0x80
  268. #define SD_TRANSFER_END 0x40
  269. #define SD_STAT_IDLE 0x20
  270. #define SD_TRANSFER_ERR 0x10
  271. #define SD_TM_NORMAL_WRITE 0x00
  272. #define SD_TM_AUTO_WRITE_3 0x01
  273. #define SD_TM_AUTO_WRITE_4 0x02
  274. #define SD_TM_AUTO_READ_3 0x05
  275. #define SD_TM_AUTO_READ_4 0x06
  276. #define SD_TM_CMD_RSP 0x08
  277. #define SD_TM_AUTO_WRITE_1 0x09
  278. #define SD_TM_AUTO_WRITE_2 0x0A
  279. #define SD_TM_NORMAL_READ 0x0C
  280. #define SD_TM_AUTO_READ_1 0x0D
  281. #define SD_TM_AUTO_READ_2 0x0E
  282. #define SD_TM_AUTO_TUNING 0x0F
  283. #define SD_CMD_STATE 0xFDB5
  284. #define SD_CMD_IDLE 0x80
  285. #define SD_DATA_STATE 0xFDB6
  286. #define SD_DATA_IDLE 0x80
  287. #define SRCTL 0xFC13
  288. #define DCM_DRP_CTL 0xFC23
  289. #define DCM_RESET 0x08
  290. #define DCM_LOCKED 0x04
  291. #define DCM_208M 0x00
  292. #define DCM_TX 0x01
  293. #define DCM_RX 0x02
  294. #define DCM_DRP_TRIG 0xFC24
  295. #define DRP_START 0x80
  296. #define DRP_DONE 0x40
  297. #define DCM_DRP_CFG 0xFC25
  298. #define DRP_WRITE 0x80
  299. #define DRP_READ 0x00
  300. #define DCM_WRITE_ADDRESS_50 0x50
  301. #define DCM_WRITE_ADDRESS_51 0x51
  302. #define DCM_READ_ADDRESS_00 0x00
  303. #define DCM_READ_ADDRESS_51 0x51
  304. #define DCM_DRP_WR_DATA_L 0xFC26
  305. #define DCM_DRP_WR_DATA_H 0xFC27
  306. #define DCM_DRP_RD_DATA_L 0xFC28
  307. #define DCM_DRP_RD_DATA_H 0xFC29
  308. #define SD_VPCLK0_CTL 0xFC2A
  309. #define SD_VPCLK1_CTL 0xFC2B
  310. #define SD_DCMPS0_CTL 0xFC2C
  311. #define SD_DCMPS1_CTL 0xFC2D
  312. #define SD_VPTX_CTL SD_VPCLK0_CTL
  313. #define SD_VPRX_CTL SD_VPCLK1_CTL
  314. #define PHASE_CHANGE 0x80
  315. #define PHASE_NOT_RESET 0x40
  316. #define SD_DCMPS_TX_CTL SD_DCMPS0_CTL
  317. #define SD_DCMPS_RX_CTL SD_DCMPS1_CTL
  318. #define DCMPS_CHANGE 0x80
  319. #define DCMPS_CHANGE_DONE 0x40
  320. #define DCMPS_ERROR 0x20
  321. #define DCMPS_CURRENT_PHASE 0x1F
  322. #define CARD_CLK_SOURCE 0xFC2E
  323. #define CRC_FIX_CLK (0x00 << 0)
  324. #define CRC_VAR_CLK0 (0x01 << 0)
  325. #define CRC_VAR_CLK1 (0x02 << 0)
  326. #define SD30_FIX_CLK (0x00 << 2)
  327. #define SD30_VAR_CLK0 (0x01 << 2)
  328. #define SD30_VAR_CLK1 (0x02 << 2)
  329. #define SAMPLE_FIX_CLK (0x00 << 4)
  330. #define SAMPLE_VAR_CLK0 (0x01 << 4)
  331. #define SAMPLE_VAR_CLK1 (0x02 << 4)
  332. #define CARD_PWR_CTL 0xFD50
  333. #define PMOS_STRG_MASK 0x10
  334. #define PMOS_STRG_800mA 0x10
  335. #define PMOS_STRG_400mA 0x00
  336. #define SD_POWER_OFF 0x03
  337. #define SD_PARTIAL_POWER_ON 0x01
  338. #define SD_POWER_ON 0x00
  339. #define SD_POWER_MASK 0x03
  340. #define MS_POWER_OFF 0x0C
  341. #define MS_PARTIAL_POWER_ON 0x04
  342. #define MS_POWER_ON 0x00
  343. #define MS_POWER_MASK 0x0C
  344. #define BPP_POWER_OFF 0x0F
  345. #define BPP_POWER_5_PERCENT_ON 0x0E
  346. #define BPP_POWER_10_PERCENT_ON 0x0C
  347. #define BPP_POWER_15_PERCENT_ON 0x08
  348. #define BPP_POWER_ON 0x00
  349. #define BPP_POWER_MASK 0x0F
  350. #define SD_VCC_PARTIAL_POWER_ON 0x02
  351. #define SD_VCC_POWER_ON 0x00
  352. #define CARD_CLK_SWITCH 0xFD51
  353. #define RTL8411B_PACKAGE_MODE 0xFD51
  354. #define CARD_SHARE_MODE 0xFD52
  355. #define CARD_SHARE_MASK 0x0F
  356. #define CARD_SHARE_MULTI_LUN 0x00
  357. #define CARD_SHARE_NORMAL 0x00
  358. #define CARD_SHARE_48_SD 0x04
  359. #define CARD_SHARE_48_MS 0x08
  360. #define CARD_SHARE_BAROSSA_SD 0x01
  361. #define CARD_SHARE_BAROSSA_MS 0x02
  362. #define CARD_DRIVE_SEL 0xFD53
  363. #define MS_DRIVE_8mA (0x01 << 6)
  364. #define MMC_DRIVE_8mA (0x01 << 4)
  365. #define XD_DRIVE_8mA (0x01 << 2)
  366. #define GPIO_DRIVE_8mA 0x01
  367. #define RTS5209_CARD_DRIVE_DEFAULT (MS_DRIVE_8mA | MMC_DRIVE_8mA |\
  368. XD_DRIVE_8mA | GPIO_DRIVE_8mA)
  369. #define RTL8411_CARD_DRIVE_DEFAULT (MS_DRIVE_8mA | MMC_DRIVE_8mA |\
  370. XD_DRIVE_8mA)
  371. #define RTSX_CARD_DRIVE_DEFAULT (MS_DRIVE_8mA | GPIO_DRIVE_8mA)
  372. #define CARD_STOP 0xFD54
  373. #define SPI_STOP 0x01
  374. #define XD_STOP 0x02
  375. #define SD_STOP 0x04
  376. #define MS_STOP 0x08
  377. #define SPI_CLR_ERR 0x10
  378. #define XD_CLR_ERR 0x20
  379. #define SD_CLR_ERR 0x40
  380. #define MS_CLR_ERR 0x80
  381. #define CARD_OE 0xFD55
  382. #define SD_OUTPUT_EN 0x04
  383. #define MS_OUTPUT_EN 0x08
  384. #define CARD_AUTO_BLINK 0xFD56
  385. #define CARD_GPIO_DIR 0xFD57
  386. #define CARD_GPIO 0xFD58
  387. #define CARD_DATA_SOURCE 0xFD5B
  388. #define PINGPONG_BUFFER 0x01
  389. #define RING_BUFFER 0x00
  390. #define SD30_CLK_DRIVE_SEL 0xFD5A
  391. #define DRIVER_TYPE_A 0x05
  392. #define DRIVER_TYPE_B 0x03
  393. #define DRIVER_TYPE_C 0x02
  394. #define DRIVER_TYPE_D 0x01
  395. #define CARD_SELECT 0xFD5C
  396. #define SD_MOD_SEL 2
  397. #define MS_MOD_SEL 3
  398. #define SD30_DRIVE_SEL 0xFD5E
  399. #define CFG_DRIVER_TYPE_A 0x02
  400. #define CFG_DRIVER_TYPE_B 0x03
  401. #define CFG_DRIVER_TYPE_C 0x01
  402. #define CFG_DRIVER_TYPE_D 0x00
  403. #define SD30_CMD_DRIVE_SEL 0xFD5E
  404. #define SD30_DAT_DRIVE_SEL 0xFD5F
  405. #define CARD_CLK_EN 0xFD69
  406. #define SD_CLK_EN 0x04
  407. #define MS_CLK_EN 0x08
  408. #define SDIO_CTRL 0xFD6B
  409. #define CD_PAD_CTL 0xFD73
  410. #define CD_DISABLE_MASK 0x07
  411. #define MS_CD_DISABLE 0x04
  412. #define SD_CD_DISABLE 0x02
  413. #define XD_CD_DISABLE 0x01
  414. #define CD_DISABLE 0x07
  415. #define CD_ENABLE 0x00
  416. #define MS_CD_EN_ONLY 0x03
  417. #define SD_CD_EN_ONLY 0x05
  418. #define XD_CD_EN_ONLY 0x06
  419. #define FORCE_CD_LOW_MASK 0x38
  420. #define FORCE_CD_XD_LOW 0x08
  421. #define FORCE_CD_SD_LOW 0x10
  422. #define FORCE_CD_MS_LOW 0x20
  423. #define CD_AUTO_DISABLE 0x40
  424. #define FPDCTL 0xFC00
  425. #define SSC_POWER_DOWN 0x01
  426. #define SD_OC_POWER_DOWN 0x02
  427. #define ALL_POWER_DOWN 0x07
  428. #define OC_POWER_DOWN 0x06
  429. #define PDINFO 0xFC01
  430. #define CLK_CTL 0xFC02
  431. #define CHANGE_CLK 0x01
  432. #define CLK_LOW_FREQ 0x01
  433. #define CLK_DIV 0xFC03
  434. #define CLK_DIV_1 0x01
  435. #define CLK_DIV_2 0x02
  436. #define CLK_DIV_4 0x03
  437. #define CLK_DIV_8 0x04
  438. #define CLK_SEL 0xFC04
  439. #define SSC_DIV_N_0 0xFC0F
  440. #define SSC_DIV_N_1 0xFC10
  441. #define SSC_CTL1 0xFC11
  442. #define SSC_RSTB 0x80
  443. #define SSC_8X_EN 0x40
  444. #define SSC_FIX_FRAC 0x20
  445. #define SSC_SEL_1M 0x00
  446. #define SSC_SEL_2M 0x08
  447. #define SSC_SEL_4M 0x10
  448. #define SSC_SEL_8M 0x18
  449. #define SSC_CTL2 0xFC12
  450. #define SSC_DEPTH_MASK 0x07
  451. #define SSC_DEPTH_DISALBE 0x00
  452. #define SSC_DEPTH_4M 0x01
  453. #define SSC_DEPTH_2M 0x02
  454. #define SSC_DEPTH_1M 0x03
  455. #define SSC_DEPTH_500K 0x04
  456. #define SSC_DEPTH_250K 0x05
  457. #define RCCTL 0xFC14
  458. #define FPGA_PULL_CTL 0xFC1D
  459. #define OLT_LED_CTL 0xFC1E
  460. #define GPIO_CTL 0xFC1F
  461. #define LDO_CTL 0xFC1E
  462. #define BPP_ASIC_1V7 0x00
  463. #define BPP_ASIC_1V8 0x01
  464. #define BPP_ASIC_1V9 0x02
  465. #define BPP_ASIC_2V0 0x03
  466. #define BPP_ASIC_2V7 0x04
  467. #define BPP_ASIC_2V8 0x05
  468. #define BPP_ASIC_3V2 0x06
  469. #define BPP_ASIC_3V3 0x07
  470. #define BPP_REG_TUNED18 0x07
  471. #define BPP_TUNED18_SHIFT_8402 5
  472. #define BPP_TUNED18_SHIFT_8411 4
  473. #define BPP_PAD_MASK 0x04
  474. #define BPP_PAD_3V3 0x04
  475. #define BPP_PAD_1V8 0x00
  476. #define BPP_LDO_POWB 0x03
  477. #define BPP_LDO_ON 0x00
  478. #define BPP_LDO_SUSPEND 0x02
  479. #define BPP_LDO_OFF 0x03
  480. #define SYS_VER 0xFC32
  481. #define CARD_PULL_CTL1 0xFD60
  482. #define CARD_PULL_CTL2 0xFD61
  483. #define CARD_PULL_CTL3 0xFD62
  484. #define CARD_PULL_CTL4 0xFD63
  485. #define CARD_PULL_CTL5 0xFD64
  486. #define CARD_PULL_CTL6 0xFD65
  487. /* PCI Express Related Registers */
  488. #define IRQEN0 0xFE20
  489. #define IRQSTAT0 0xFE21
  490. #define DMA_DONE_INT 0x80
  491. #define SUSPEND_INT 0x40
  492. #define LINK_RDY_INT 0x20
  493. #define LINK_DOWN_INT 0x10
  494. #define IRQEN1 0xFE22
  495. #define IRQSTAT1 0xFE23
  496. #define TLPRIEN 0xFE24
  497. #define TLPRISTAT 0xFE25
  498. #define TLPTIEN 0xFE26
  499. #define TLPTISTAT 0xFE27
  500. #define DMATC0 0xFE28
  501. #define DMATC1 0xFE29
  502. #define DMATC2 0xFE2A
  503. #define DMATC3 0xFE2B
  504. #define DMACTL 0xFE2C
  505. #define DMA_RST 0x80
  506. #define DMA_BUSY 0x04
  507. #define DMA_DIR_TO_CARD 0x00
  508. #define DMA_DIR_FROM_CARD 0x02
  509. #define DMA_EN 0x01
  510. #define DMA_128 (0 << 4)
  511. #define DMA_256 (1 << 4)
  512. #define DMA_512 (2 << 4)
  513. #define DMA_1024 (3 << 4)
  514. #define DMA_PACK_SIZE_MASK 0x30
  515. #define BCTL 0xFE2D
  516. #define RBBC0 0xFE2E
  517. #define RBBC1 0xFE2F
  518. #define RBDAT 0xFE30
  519. #define RBCTL 0xFE34
  520. #define CFGADDR0 0xFE35
  521. #define CFGADDR1 0xFE36
  522. #define CFGDATA0 0xFE37
  523. #define CFGDATA1 0xFE38
  524. #define CFGDATA2 0xFE39
  525. #define CFGDATA3 0xFE3A
  526. #define CFGRWCTL 0xFE3B
  527. #define PHYRWCTL 0xFE3C
  528. #define PHYDATA0 0xFE3D
  529. #define PHYDATA1 0xFE3E
  530. #define PHYADDR 0xFE3F
  531. #define MSGRXDATA0 0xFE40
  532. #define MSGRXDATA1 0xFE41
  533. #define MSGRXDATA2 0xFE42
  534. #define MSGRXDATA3 0xFE43
  535. #define MSGTXDATA0 0xFE44
  536. #define MSGTXDATA1 0xFE45
  537. #define MSGTXDATA2 0xFE46
  538. #define MSGTXDATA3 0xFE47
  539. #define MSGTXCTL 0xFE48
  540. #define LTR_CTL 0xFE4A
  541. #define OBFF_CFG 0xFE4C
  542. #define CDRESUMECTL 0xFE52
  543. #define WAKE_SEL_CTL 0xFE54
  544. #define PCLK_CTL 0xFE55
  545. #define PCLK_MODE_SEL 0x20
  546. #define PME_FORCE_CTL 0xFE56
  547. #define ASPM_FORCE_CTL 0xFE57
  548. #define FORCE_ASPM_CTL0 0x10
  549. #define FORCE_ASPM_VAL_MASK 0x03
  550. #define FORCE_ASPM_L1_EN 0x02
  551. #define FORCE_ASPM_L0_EN 0x01
  552. #define FORCE_ASPM_NO_ASPM 0x00
  553. #define PM_CLK_FORCE_CTL 0xFE58
  554. #define FUNC_FORCE_CTL 0xFE59
  555. #define FUNC_FORCE_UPME_XMT_DBG 0x02
  556. #define PERST_GLITCH_WIDTH 0xFE5C
  557. #define CHANGE_LINK_STATE 0xFE5B
  558. #define RESET_LOAD_REG 0xFE5E
  559. #define EFUSE_CONTENT 0xFE5F
  560. #define HOST_SLEEP_STATE 0xFE60
  561. #define HOST_ENTER_S1 1
  562. #define HOST_ENTER_S3 2
  563. #define SDIO_CFG 0xFE70
  564. #define PM_EVENT_DEBUG 0xFE71
  565. #define PME_DEBUG_0 0x08
  566. #define NFTS_TX_CTRL 0xFE72
  567. #define PWR_GATE_CTRL 0xFE75
  568. #define PWR_GATE_EN 0x01
  569. #define LDO3318_PWR_MASK 0x06
  570. #define LDO_ON 0x00
  571. #define LDO_SUSPEND 0x04
  572. #define LDO_OFF 0x06
  573. #define PWD_SUSPEND_EN 0xFE76
  574. #define LDO_PWR_SEL 0xFE78
  575. #define L1SUB_CONFIG1 0xFE8D
  576. #define L1SUB_CONFIG2 0xFE8E
  577. #define L1SUB_AUTO_CFG 0x02
  578. #define L1SUB_CONFIG3 0xFE8F
  579. #define DUMMY_REG_RESET_0 0xFE90
  580. #define AUTOLOAD_CFG_BASE 0xFF00
  581. #define PETXCFG 0xFF03
  582. #define PM_CTRL1 0xFF44
  583. #define CD_RESUME_EN_MASK 0xF0
  584. #define PM_CTRL2 0xFF45
  585. #define PM_CTRL3 0xFF46
  586. #define SDIO_SEND_PME_EN 0x80
  587. #define FORCE_RC_MODE_ON 0x40
  588. #define FORCE_RX50_LINK_ON 0x20
  589. #define D3_DELINK_MODE_EN 0x10
  590. #define USE_PESRTB_CTL_DELINK 0x08
  591. #define DELAY_PIN_WAKE 0x04
  592. #define RESET_PIN_WAKE 0x02
  593. #define PM_WAKE_EN 0x01
  594. #define PM_CTRL4 0xFF47
  595. /* Memory mapping */
  596. #define SRAM_BASE 0xE600
  597. #define RBUF_BASE 0xF400
  598. #define PPBUF_BASE1 0xF800
  599. #define PPBUF_BASE2 0xFA00
  600. #define IMAGE_FLAG_ADDR0 0xCE80
  601. #define IMAGE_FLAG_ADDR1 0xCE81
  602. #define RREF_CFG 0xFF6C
  603. #define RREF_VBGSEL_MASK 0x38
  604. #define RREF_VBGSEL_1V25 0x28
  605. #define OOBS_CONFIG 0xFF6E
  606. #define OOBS_AUTOK_DIS 0x80
  607. #define OOBS_VAL_MASK 0x1F
  608. #define LDO_DV18_CFG 0xFF70
  609. #define LDO_DV18_SR_MASK 0xC0
  610. #define LDO_DV18_SR_DF 0x40
  611. #define LDO_CONFIG2 0xFF71
  612. #define LDO_D3318_MASK 0x07
  613. #define LDO_D3318_33V 0x07
  614. #define LDO_D3318_18V 0x02
  615. #define LDO_VCC_CFG0 0xFF72
  616. #define LDO_VCC_LMTVTH_MASK 0x30
  617. #define LDO_VCC_LMTVTH_2A 0x10
  618. #define LDO_VCC_CFG1 0xFF73
  619. #define LDO_VCC_REF_TUNE_MASK 0x30
  620. #define LDO_VCC_REF_1V2 0x20
  621. #define LDO_VCC_TUNE_MASK 0x07
  622. #define LDO_VCC_1V8 0x04
  623. #define LDO_VCC_3V3 0x07
  624. #define LDO_VCC_LMT_EN 0x08
  625. #define LDO_VIO_CFG 0xFF75
  626. #define LDO_VIO_SR_MASK 0xC0
  627. #define LDO_VIO_SR_DF 0x40
  628. #define LDO_VIO_REF_TUNE_MASK 0x30
  629. #define LDO_VIO_REF_1V2 0x20
  630. #define LDO_VIO_TUNE_MASK 0x07
  631. #define LDO_VIO_1V7 0x03
  632. #define LDO_VIO_1V8 0x04
  633. #define LDO_VIO_3V3 0x07
  634. #define LDO_DV12S_CFG 0xFF76
  635. #define LDO_REF12_TUNE_MASK 0x18
  636. #define LDO_REF12_TUNE_DF 0x10
  637. #define LDO_D12_TUNE_MASK 0x07
  638. #define LDO_D12_TUNE_DF 0x04
  639. #define LDO_AV12S_CFG 0xFF77
  640. #define LDO_AV12S_TUNE_MASK 0x07
  641. #define LDO_AV12S_TUNE_DF 0x04
  642. #define SD40_LDO_CTL1 0xFE7D
  643. #define SD40_VIO_TUNE_MASK 0x70
  644. #define SD40_VIO_TUNE_1V7 0x30
  645. #define SD_VIO_LDO_1V8 0x40
  646. #define SD_VIO_LDO_3V3 0x70
  647. /* Phy register */
  648. #define PHY_PCR 0x00
  649. #define PHY_PCR_FORCE_CODE 0xB000
  650. #define PHY_PCR_OOBS_CALI_50 0x0800
  651. #define PHY_PCR_OOBS_VCM_08 0x0200
  652. #define PHY_PCR_OOBS_SEN_90 0x0040
  653. #define PHY_PCR_RSSI_EN 0x0002
  654. #define PHY_PCR_RX10K 0x0001
  655. #define PHY_RCR0 0x01
  656. #define PHY_RCR1 0x02
  657. #define PHY_RCR1_ADP_TIME_4 0x0400
  658. #define PHY_RCR1_VCO_COARSE 0x001F
  659. #define PHY_RCR1_INIT_27S 0x0A1F
  660. #define PHY_SSCCR2 0x02
  661. #define PHY_SSCCR2_PLL_NCODE 0x0A00
  662. #define PHY_SSCCR2_TIME0 0x001C
  663. #define PHY_SSCCR2_TIME2_WIDTH 0x0003
  664. #define PHY_RCR2 0x03
  665. #define PHY_RCR2_EMPHASE_EN 0x8000
  666. #define PHY_RCR2_NADJR 0x4000
  667. #define PHY_RCR2_CDR_SR_2 0x0100
  668. #define PHY_RCR2_FREQSEL_12 0x0040
  669. #define PHY_RCR2_CDR_SC_12P 0x0010
  670. #define PHY_RCR2_CALIB_LATE 0x0002
  671. #define PHY_RCR2_INIT_27S 0xC152
  672. #define PHY_SSCCR3 0x03
  673. #define PHY_SSCCR3_STEP_IN 0x2740
  674. #define PHY_SSCCR3_CHECK_DELAY 0x0008
  675. #define _PHY_ANA03 0x03
  676. #define _PHY_ANA03_TIMER_MAX 0x2700
  677. #define _PHY_ANA03_OOBS_DEB_EN 0x0040
  678. #define _PHY_CMU_DEBUG_EN 0x0008
  679. #define PHY_RTCR 0x04
  680. #define PHY_RDR 0x05
  681. #define PHY_RDR_RXDSEL_1_9 0x4000
  682. #define PHY_SSC_AUTO_PWD 0x0600
  683. #define PHY_TCR0 0x06
  684. #define PHY_TCR1 0x07
  685. #define PHY_TUNE 0x08
  686. #define PHY_TUNE_TUNEREF_1_0 0x4000
  687. #define PHY_TUNE_VBGSEL_1252 0x0C00
  688. #define PHY_TUNE_SDBUS_33 0x0200
  689. #define PHY_TUNE_TUNED18 0x01C0
  690. #define PHY_TUNE_TUNED12 0X0020
  691. #define PHY_TUNE_TUNEA12 0x0004
  692. #define PHY_TUNE_VOLTAGE_MASK 0xFC3F
  693. #define PHY_TUNE_VOLTAGE_3V3 0x03C0
  694. #define PHY_TUNE_D18_1V8 0x0100
  695. #define PHY_TUNE_D18_1V7 0x0080
  696. #define PHY_ANA08 0x08
  697. #define PHY_ANA08_RX_EQ_DCGAIN 0x5000
  698. #define PHY_ANA08_SEL_RX_EN 0x0400
  699. #define PHY_ANA08_RX_EQ_VAL 0x03C0
  700. #define PHY_ANA08_SCP 0x0020
  701. #define PHY_ANA08_SEL_IPI 0x0004
  702. #define PHY_IMR 0x09
  703. #define PHY_BPCR 0x0A
  704. #define PHY_BPCR_IBRXSEL 0x0400
  705. #define PHY_BPCR_IBTXSEL 0x0100
  706. #define PHY_BPCR_IB_FILTER 0x0080
  707. #define PHY_BPCR_CMIRROR_EN 0x0040
  708. #define PHY_BIST 0x0B
  709. #define PHY_RAW_L 0x0C
  710. #define PHY_RAW_H 0x0D
  711. #define PHY_RAW_DATA 0x0E
  712. #define PHY_HOST_CLK_CTRL 0x0F
  713. #define PHY_DMR 0x10
  714. #define PHY_BACR 0x11
  715. #define PHY_BACR_BASIC_MASK 0xFFF3
  716. #define PHY_IER 0x12
  717. #define PHY_BCSR 0x13
  718. #define PHY_BPR 0x14
  719. #define PHY_BPNR2 0x15
  720. #define PHY_BPNR 0x16
  721. #define PHY_BRNR2 0x17
  722. #define PHY_BENR 0x18
  723. #define PHY_REV 0x19
  724. #define PHY_REV_RESV 0xE000
  725. #define PHY_REV_RXIDLE_LATCHED 0x1000
  726. #define PHY_REV_P1_EN 0x0800
  727. #define PHY_REV_RXIDLE_EN 0x0400
  728. #define PHY_REV_CLKREQ_TX_EN 0x0200
  729. #define PHY_REV_CLKREQ_RX_EN 0x0100
  730. #define PHY_REV_CLKREQ_DT_1_0 0x0040
  731. #define PHY_REV_STOP_CLKRD 0x0020
  732. #define PHY_REV_RX_PWST 0x0008
  733. #define PHY_REV_STOP_CLKWR 0x0004
  734. #define _PHY_REV0 0x19
  735. #define _PHY_REV0_FILTER_OUT 0x3800
  736. #define _PHY_REV0_CDR_BYPASS_PFD 0x0100
  737. #define _PHY_REV0_CDR_RX_IDLE_BYPASS 0x0002
  738. #define PHY_FLD0 0x1A
  739. #define PHY_ANA1A 0x1A
  740. #define PHY_ANA1A_TXR_LOOPBACK 0x2000
  741. #define PHY_ANA1A_RXT_BIST 0x0500
  742. #define PHY_ANA1A_TXR_BIST 0x0040
  743. #define PHY_ANA1A_REV 0x0006
  744. #define PHY_FLD0_INIT_27S 0x2546
  745. #define PHY_FLD1 0x1B
  746. #define PHY_FLD2 0x1C
  747. #define PHY_FLD3 0x1D
  748. #define PHY_FLD3_TIMER_4 0x0800
  749. #define PHY_FLD3_TIMER_6 0x0020
  750. #define PHY_FLD3_RXDELINK 0x0004
  751. #define PHY_FLD3_INIT_27S 0x0004
  752. #define PHY_ANA1D 0x1D
  753. #define PHY_ANA1D_DEBUG_ADDR 0x0004
  754. #define _PHY_FLD0 0x1D
  755. #define _PHY_FLD0_CLK_REQ_20C 0x8000
  756. #define _PHY_FLD0_RX_IDLE_EN 0x1000
  757. #define _PHY_FLD0_BIT_ERR_RSTN 0x0800
  758. #define _PHY_FLD0_BER_COUNT 0x01E0
  759. #define _PHY_FLD0_BER_TIMER 0x001E
  760. #define _PHY_FLD0_CHECK_EN 0x0001
  761. #define PHY_FLD4 0x1E
  762. #define PHY_FLD4_FLDEN_SEL 0x4000
  763. #define PHY_FLD4_REQ_REF 0x2000
  764. #define PHY_FLD4_RXAMP_OFF 0x1000
  765. #define PHY_FLD4_REQ_ADDA 0x0800
  766. #define PHY_FLD4_BER_COUNT 0x00E0
  767. #define PHY_FLD4_BER_TIMER 0x000A
  768. #define PHY_FLD4_BER_CHK_EN 0x0001
  769. #define PHY_FLD4_INIT_27S 0x5C7F
  770. #define PHY_DIG1E 0x1E
  771. #define PHY_DIG1E_REV 0x4000
  772. #define PHY_DIG1E_D0_X_D1 0x1000
  773. #define PHY_DIG1E_RX_ON_HOST 0x0800
  774. #define PHY_DIG1E_RCLK_REF_HOST 0x0400
  775. #define PHY_DIG1E_RCLK_TX_EN_KEEP 0x0040
  776. #define PHY_DIG1E_RCLK_TX_TERM_KEEP 0x0020
  777. #define PHY_DIG1E_RCLK_RX_EIDLE_ON 0x0010
  778. #define PHY_DIG1E_TX_TERM_KEEP 0x0008
  779. #define PHY_DIG1E_RX_TERM_KEEP 0x0004
  780. #define PHY_DIG1E_TX_EN_KEEP 0x0002
  781. #define PHY_DIG1E_RX_EN_KEEP 0x0001
  782. #define PHY_DUM_REG 0x1F
  783. #define PCR_SETTING_REG1 0x724
  784. #define PCR_SETTING_REG2 0x814
  785. #define PCR_SETTING_REG3 0x747
  786. #define rtsx_pci_init_cmd(pcr) ((pcr)->ci = 0)
  787. struct rtsx_pcr;
  788. struct pcr_handle {
  789. struct rtsx_pcr *pcr;
  790. };
  791. struct pcr_ops {
  792. int (*write_phy)(struct rtsx_pcr *pcr, u8 addr, u16 val);
  793. int (*read_phy)(struct rtsx_pcr *pcr, u8 addr, u16 *val);
  794. int (*extra_init_hw)(struct rtsx_pcr *pcr);
  795. int (*optimize_phy)(struct rtsx_pcr *pcr);
  796. int (*turn_on_led)(struct rtsx_pcr *pcr);
  797. int (*turn_off_led)(struct rtsx_pcr *pcr);
  798. int (*enable_auto_blink)(struct rtsx_pcr *pcr);
  799. int (*disable_auto_blink)(struct rtsx_pcr *pcr);
  800. int (*card_power_on)(struct rtsx_pcr *pcr, int card);
  801. int (*card_power_off)(struct rtsx_pcr *pcr, int card);
  802. int (*switch_output_voltage)(struct rtsx_pcr *pcr,
  803. u8 voltage);
  804. unsigned int (*cd_deglitch)(struct rtsx_pcr *pcr);
  805. int (*conv_clk_and_div_n)(int clk, int dir);
  806. void (*fetch_vendor_settings)(struct rtsx_pcr *pcr);
  807. void (*force_power_down)(struct rtsx_pcr *pcr, u8 pm_state);
  808. };
  809. enum PDEV_STAT {PDEV_STAT_IDLE, PDEV_STAT_RUN};
  810. struct rtsx_pcr {
  811. struct pci_dev *pci;
  812. unsigned int id;
  813. int pcie_cap;
  814. /* pci resources */
  815. unsigned long addr;
  816. void __iomem *remap_addr;
  817. int irq;
  818. /* host reserved buffer */
  819. void *rtsx_resv_buf;
  820. dma_addr_t rtsx_resv_buf_addr;
  821. void *host_cmds_ptr;
  822. dma_addr_t host_cmds_addr;
  823. int ci;
  824. void *host_sg_tbl_ptr;
  825. dma_addr_t host_sg_tbl_addr;
  826. int sgi;
  827. u32 bier;
  828. char trans_result;
  829. unsigned int card_inserted;
  830. unsigned int card_removed;
  831. unsigned int card_exist;
  832. struct delayed_work carddet_work;
  833. struct delayed_work idle_work;
  834. spinlock_t lock;
  835. struct mutex pcr_mutex;
  836. struct completion *done;
  837. struct completion *finish_me;
  838. unsigned int cur_clock;
  839. bool remove_pci;
  840. bool msi_en;
  841. #define EXTRA_CAPS_SD_SDR50 (1 << 0)
  842. #define EXTRA_CAPS_SD_SDR104 (1 << 1)
  843. #define EXTRA_CAPS_SD_DDR50 (1 << 2)
  844. #define EXTRA_CAPS_MMC_HSDDR (1 << 3)
  845. #define EXTRA_CAPS_MMC_HS200 (1 << 4)
  846. #define EXTRA_CAPS_MMC_8BIT (1 << 5)
  847. u32 extra_caps;
  848. #define IC_VER_A 0
  849. #define IC_VER_B 1
  850. #define IC_VER_C 2
  851. #define IC_VER_D 3
  852. u8 ic_version;
  853. u8 sd30_drive_sel_1v8;
  854. u8 sd30_drive_sel_3v3;
  855. u8 card_drive_sel;
  856. #define ASPM_L1_EN 0x02
  857. u8 aspm_en;
  858. #define PCR_MS_PMOS (1 << 0)
  859. #define PCR_REVERSE_SOCKET (1 << 1)
  860. u32 flags;
  861. u32 tx_initial_phase;
  862. u32 rx_initial_phase;
  863. const u32 *sd_pull_ctl_enable_tbl;
  864. const u32 *sd_pull_ctl_disable_tbl;
  865. const u32 *ms_pull_ctl_enable_tbl;
  866. const u32 *ms_pull_ctl_disable_tbl;
  867. const struct pcr_ops *ops;
  868. enum PDEV_STAT state;
  869. u16 reg_pm_ctrl3;
  870. int num_slots;
  871. struct rtsx_slot *slots;
  872. };
  873. #define CHK_PCI_PID(pcr, pid) ((pcr)->pci->device == (pid))
  874. #define PCI_VID(pcr) ((pcr)->pci->vendor)
  875. #define PCI_PID(pcr) ((pcr)->pci->device)
  876. #define is_version(pcr, pid, ver) \
  877. (CHK_PCI_PID(pcr, pid) && (pcr)->ic_version == (ver))
  878. #define pcr_dbg(pcr, fmt, arg...) \
  879. dev_dbg(&(pcr)->pci->dev, fmt, ##arg)
  880. #define SDR104_PHASE(val) ((val) & 0xFF)
  881. #define SDR50_PHASE(val) (((val) >> 8) & 0xFF)
  882. #define DDR50_PHASE(val) (((val) >> 16) & 0xFF)
  883. #define SDR104_TX_PHASE(pcr) SDR104_PHASE((pcr)->tx_initial_phase)
  884. #define SDR50_TX_PHASE(pcr) SDR50_PHASE((pcr)->tx_initial_phase)
  885. #define DDR50_TX_PHASE(pcr) DDR50_PHASE((pcr)->tx_initial_phase)
  886. #define SDR104_RX_PHASE(pcr) SDR104_PHASE((pcr)->rx_initial_phase)
  887. #define SDR50_RX_PHASE(pcr) SDR50_PHASE((pcr)->rx_initial_phase)
  888. #define DDR50_RX_PHASE(pcr) DDR50_PHASE((pcr)->rx_initial_phase)
  889. #define SET_CLOCK_PHASE(sdr104, sdr50, ddr50) \
  890. (((ddr50) << 16) | ((sdr50) << 8) | (sdr104))
  891. void rtsx_pci_start_run(struct rtsx_pcr *pcr);
  892. int rtsx_pci_write_register(struct rtsx_pcr *pcr, u16 addr, u8 mask, u8 data);
  893. int rtsx_pci_read_register(struct rtsx_pcr *pcr, u16 addr, u8 *data);
  894. int rtsx_pci_write_phy_register(struct rtsx_pcr *pcr, u8 addr, u16 val);
  895. int rtsx_pci_read_phy_register(struct rtsx_pcr *pcr, u8 addr, u16 *val);
  896. void rtsx_pci_stop_cmd(struct rtsx_pcr *pcr);
  897. void rtsx_pci_add_cmd(struct rtsx_pcr *pcr,
  898. u8 cmd_type, u16 reg_addr, u8 mask, u8 data);
  899. void rtsx_pci_send_cmd_no_wait(struct rtsx_pcr *pcr);
  900. int rtsx_pci_send_cmd(struct rtsx_pcr *pcr, int timeout);
  901. int rtsx_pci_transfer_data(struct rtsx_pcr *pcr, struct scatterlist *sglist,
  902. int num_sg, bool read, int timeout);
  903. int rtsx_pci_dma_map_sg(struct rtsx_pcr *pcr, struct scatterlist *sglist,
  904. int num_sg, bool read);
  905. void rtsx_pci_dma_unmap_sg(struct rtsx_pcr *pcr, struct scatterlist *sglist,
  906. int num_sg, bool read);
  907. int rtsx_pci_dma_transfer(struct rtsx_pcr *pcr, struct scatterlist *sglist,
  908. int count, bool read, int timeout);
  909. int rtsx_pci_read_ppbuf(struct rtsx_pcr *pcr, u8 *buf, int buf_len);
  910. int rtsx_pci_write_ppbuf(struct rtsx_pcr *pcr, u8 *buf, int buf_len);
  911. int rtsx_pci_card_pull_ctl_enable(struct rtsx_pcr *pcr, int card);
  912. int rtsx_pci_card_pull_ctl_disable(struct rtsx_pcr *pcr, int card);
  913. int rtsx_pci_switch_clock(struct rtsx_pcr *pcr, unsigned int card_clock,
  914. u8 ssc_depth, bool initial_mode, bool double_clk, bool vpclk);
  915. int rtsx_pci_card_power_on(struct rtsx_pcr *pcr, int card);
  916. int rtsx_pci_card_power_off(struct rtsx_pcr *pcr, int card);
  917. int rtsx_pci_card_exclusive_check(struct rtsx_pcr *pcr, int card);
  918. int rtsx_pci_switch_output_voltage(struct rtsx_pcr *pcr, u8 voltage);
  919. unsigned int rtsx_pci_card_exist(struct rtsx_pcr *pcr);
  920. void rtsx_pci_complete_unfinished_transfer(struct rtsx_pcr *pcr);
  921. static inline u8 *rtsx_pci_get_cmd_data(struct rtsx_pcr *pcr)
  922. {
  923. return (u8 *)(pcr->host_cmds_ptr);
  924. }
  925. static inline int rtsx_pci_update_cfg_byte(struct rtsx_pcr *pcr, int addr,
  926. u8 mask, u8 append)
  927. {
  928. int err;
  929. u8 val;
  930. err = pci_read_config_byte(pcr->pci, addr, &val);
  931. if (err < 0)
  932. return err;
  933. return pci_write_config_byte(pcr->pci, addr, (val & mask) | append);
  934. }
  935. static inline void rtsx_pci_write_be32(struct rtsx_pcr *pcr, u16 reg, u32 val)
  936. {
  937. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, reg, 0xFF, val >> 24);
  938. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, reg + 1, 0xFF, val >> 16);
  939. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, reg + 2, 0xFF, val >> 8);
  940. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, reg + 3, 0xFF, val);
  941. }
  942. static inline int rtsx_pci_update_phy(struct rtsx_pcr *pcr, u8 addr,
  943. u16 mask, u16 append)
  944. {
  945. int err;
  946. u16 val;
  947. err = rtsx_pci_read_phy_register(pcr, addr, &val);
  948. if (err < 0)
  949. return err;
  950. return rtsx_pci_write_phy_register(pcr, addr, (val & mask) | append);
  951. }
  952. #endif