rtsx_pci.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911
  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. /* PCI Operation Register Address */
  28. #define RTSX_HCBAR 0x00
  29. #define RTSX_HCBCTLR 0x04
  30. #define RTSX_HDBAR 0x08
  31. #define RTSX_HDBCTLR 0x0C
  32. #define RTSX_HAIMR 0x10
  33. #define RTSX_BIPR 0x14
  34. #define RTSX_BIER 0x18
  35. /* Host command buffer control register */
  36. #define STOP_CMD (0x01 << 28)
  37. /* Host data buffer control register */
  38. #define SDMA_MODE 0x00
  39. #define ADMA_MODE (0x02 << 26)
  40. #define STOP_DMA (0x01 << 28)
  41. #define TRIG_DMA (0x01 << 31)
  42. /* Host access internal memory register */
  43. #define HAIMR_TRANS_START (0x01 << 31)
  44. #define HAIMR_READ 0x00
  45. #define HAIMR_WRITE (0x01 << 30)
  46. #define HAIMR_READ_START (HAIMR_TRANS_START | HAIMR_READ)
  47. #define HAIMR_WRITE_START (HAIMR_TRANS_START | HAIMR_WRITE)
  48. #define HAIMR_TRANS_END (HAIMR_TRANS_START)
  49. /* Bus interrupt pending register */
  50. #define CMD_DONE_INT (1 << 31)
  51. #define DATA_DONE_INT (1 << 30)
  52. #define TRANS_OK_INT (1 << 29)
  53. #define TRANS_FAIL_INT (1 << 28)
  54. #define XD_INT (1 << 27)
  55. #define MS_INT (1 << 26)
  56. #define SD_INT (1 << 25)
  57. #define GPIO0_INT (1 << 24)
  58. #define OC_INT (1 << 23)
  59. #define SD_WRITE_PROTECT (1 << 19)
  60. #define XD_EXIST (1 << 18)
  61. #define MS_EXIST (1 << 17)
  62. #define SD_EXIST (1 << 16)
  63. #define DELINK_INT GPIO0_INT
  64. #define MS_OC_INT (1 << 23)
  65. #define SD_OC_INT (1 << 22)
  66. #define CARD_INT (XD_INT | MS_INT | SD_INT)
  67. #define NEED_COMPLETE_INT (DATA_DONE_INT | TRANS_OK_INT | TRANS_FAIL_INT)
  68. #define RTSX_INT (CMD_DONE_INT | NEED_COMPLETE_INT | \
  69. CARD_INT | GPIO0_INT | OC_INT)
  70. #define CARD_EXIST (XD_EXIST | MS_EXIST | SD_EXIST)
  71. /* Bus interrupt enable register */
  72. #define CMD_DONE_INT_EN (1 << 31)
  73. #define DATA_DONE_INT_EN (1 << 30)
  74. #define TRANS_OK_INT_EN (1 << 29)
  75. #define TRANS_FAIL_INT_EN (1 << 28)
  76. #define XD_INT_EN (1 << 27)
  77. #define MS_INT_EN (1 << 26)
  78. #define SD_INT_EN (1 << 25)
  79. #define GPIO0_INT_EN (1 << 24)
  80. #define OC_INT_EN (1 << 23)
  81. #define DELINK_INT_EN GPIO0_INT_EN
  82. #define MS_OC_INT_EN (1 << 23)
  83. #define SD_OC_INT_EN (1 << 22)
  84. #define READ_REG_CMD 0
  85. #define WRITE_REG_CMD 1
  86. #define CHECK_REG_CMD 2
  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 MAX_PHASE 31
  126. #define RX_TUNING_CNT 3
  127. /* SG descriptor */
  128. #define SG_INT 0x04
  129. #define SG_END 0x02
  130. #define SG_VALID 0x01
  131. #define SG_NO_OP 0x00
  132. #define SG_TRANS_DATA (0x02 << 4)
  133. #define SG_LINK_DESC (0x03 << 4)
  134. /* Output voltage */
  135. #define OUTPUT_3V3 0
  136. #define OUTPUT_1V8 1
  137. /* Card Clock Enable Register */
  138. #define SD_CLK_EN 0x04
  139. #define MS_CLK_EN 0x08
  140. /* Card Select Register */
  141. #define SD_MOD_SEL 2
  142. #define MS_MOD_SEL 3
  143. /* Card Output Enable Register */
  144. #define SD_OUTPUT_EN 0x04
  145. #define MS_OUTPUT_EN 0x08
  146. /* CARD_SHARE_MODE */
  147. #define CARD_SHARE_MASK 0x0F
  148. #define CARD_SHARE_MULTI_LUN 0x00
  149. #define CARD_SHARE_NORMAL 0x00
  150. #define CARD_SHARE_48_SD 0x04
  151. #define CARD_SHARE_48_MS 0x08
  152. /* CARD_SHARE_MODE for barossa */
  153. #define CARD_SHARE_BAROSSA_SD 0x01
  154. #define CARD_SHARE_BAROSSA_MS 0x02
  155. /* CARD_DRIVE_SEL */
  156. #define MS_DRIVE_8mA (0x01 << 6)
  157. #define MMC_DRIVE_8mA (0x01 << 4)
  158. #define XD_DRIVE_8mA (0x01 << 2)
  159. #define GPIO_DRIVE_8mA 0x01
  160. #define RTS5209_CARD_DRIVE_DEFAULT (MS_DRIVE_8mA | MMC_DRIVE_8mA |\
  161. XD_DRIVE_8mA | GPIO_DRIVE_8mA)
  162. #define RTL8411_CARD_DRIVE_DEFAULT (MS_DRIVE_8mA | MMC_DRIVE_8mA |\
  163. XD_DRIVE_8mA)
  164. #define RTSX_CARD_DRIVE_DEFAULT (MS_DRIVE_8mA | GPIO_DRIVE_8mA)
  165. /* SD30_DRIVE_SEL */
  166. #define DRIVER_TYPE_A 0x05
  167. #define DRIVER_TYPE_B 0x03
  168. #define DRIVER_TYPE_C 0x02
  169. #define DRIVER_TYPE_D 0x01
  170. #define CFG_DRIVER_TYPE_A 0x02
  171. #define CFG_DRIVER_TYPE_B 0x03
  172. #define CFG_DRIVER_TYPE_C 0x01
  173. #define CFG_DRIVER_TYPE_D 0x00
  174. /* FPDCTL */
  175. #define SSC_POWER_DOWN 0x01
  176. #define SD_OC_POWER_DOWN 0x02
  177. #define ALL_POWER_DOWN 0x07
  178. #define OC_POWER_DOWN 0x06
  179. /* CLK_CTL */
  180. #define CHANGE_CLK 0x01
  181. /* LDO_CTL */
  182. #define BPP_ASIC_1V7 0x00
  183. #define BPP_ASIC_1V8 0x01
  184. #define BPP_ASIC_1V9 0x02
  185. #define BPP_ASIC_2V0 0x03
  186. #define BPP_ASIC_2V7 0x04
  187. #define BPP_ASIC_2V8 0x05
  188. #define BPP_ASIC_3V2 0x06
  189. #define BPP_ASIC_3V3 0x07
  190. #define BPP_REG_TUNED18 0x07
  191. #define BPP_TUNED18_SHIFT_8402 5
  192. #define BPP_TUNED18_SHIFT_8411 4
  193. #define BPP_PAD_MASK 0x04
  194. #define BPP_PAD_3V3 0x04
  195. #define BPP_PAD_1V8 0x00
  196. #define BPP_LDO_POWB 0x03
  197. #define BPP_LDO_ON 0x00
  198. #define BPP_LDO_SUSPEND 0x02
  199. #define BPP_LDO_OFF 0x03
  200. /* CD_PAD_CTL */
  201. #define CD_DISABLE_MASK 0x07
  202. #define MS_CD_DISABLE 0x04
  203. #define SD_CD_DISABLE 0x02
  204. #define XD_CD_DISABLE 0x01
  205. #define CD_DISABLE 0x07
  206. #define CD_ENABLE 0x00
  207. #define MS_CD_EN_ONLY 0x03
  208. #define SD_CD_EN_ONLY 0x05
  209. #define XD_CD_EN_ONLY 0x06
  210. #define FORCE_CD_LOW_MASK 0x38
  211. #define FORCE_CD_XD_LOW 0x08
  212. #define FORCE_CD_SD_LOW 0x10
  213. #define FORCE_CD_MS_LOW 0x20
  214. #define CD_AUTO_DISABLE 0x40
  215. /* SD_STAT1 */
  216. #define SD_CRC7_ERR 0x80
  217. #define SD_CRC16_ERR 0x40
  218. #define SD_CRC_WRITE_ERR 0x20
  219. #define SD_CRC_WRITE_ERR_MASK 0x1C
  220. #define GET_CRC_TIME_OUT 0x02
  221. #define SD_TUNING_COMPARE_ERR 0x01
  222. /* SD_STAT2 */
  223. #define SD_RSP_80CLK_TIMEOUT 0x01
  224. /* SD_BUS_STAT */
  225. #define SD_CLK_TOGGLE_EN 0x80
  226. #define SD_CLK_FORCE_STOP 0x40
  227. #define SD_DAT3_STATUS 0x10
  228. #define SD_DAT2_STATUS 0x08
  229. #define SD_DAT1_STATUS 0x04
  230. #define SD_DAT0_STATUS 0x02
  231. #define SD_CMD_STATUS 0x01
  232. /* SD_PAD_CTL */
  233. #define SD_IO_USING_1V8 0x80
  234. #define SD_IO_USING_3V3 0x7F
  235. #define TYPE_A_DRIVING 0x00
  236. #define TYPE_B_DRIVING 0x01
  237. #define TYPE_C_DRIVING 0x02
  238. #define TYPE_D_DRIVING 0x03
  239. /* SD_SAMPLE_POINT_CTL */
  240. #define DDR_FIX_RX_DAT 0x00
  241. #define DDR_VAR_RX_DAT 0x80
  242. #define DDR_FIX_RX_DAT_EDGE 0x00
  243. #define DDR_FIX_RX_DAT_14_DELAY 0x40
  244. #define DDR_FIX_RX_CMD 0x00
  245. #define DDR_VAR_RX_CMD 0x20
  246. #define DDR_FIX_RX_CMD_POS_EDGE 0x00
  247. #define DDR_FIX_RX_CMD_14_DELAY 0x10
  248. #define SD20_RX_POS_EDGE 0x00
  249. #define SD20_RX_14_DELAY 0x08
  250. #define SD20_RX_SEL_MASK 0x08
  251. /* SD_PUSH_POINT_CTL */
  252. #define DDR_FIX_TX_CMD_DAT 0x00
  253. #define DDR_VAR_TX_CMD_DAT 0x80
  254. #define DDR_FIX_TX_DAT_14_TSU 0x00
  255. #define DDR_FIX_TX_DAT_12_TSU 0x40
  256. #define DDR_FIX_TX_CMD_NEG_EDGE 0x00
  257. #define DDR_FIX_TX_CMD_14_AHEAD 0x20
  258. #define SD20_TX_NEG_EDGE 0x00
  259. #define SD20_TX_14_AHEAD 0x10
  260. #define SD20_TX_SEL_MASK 0x10
  261. #define DDR_VAR_SDCLK_POL_SWAP 0x01
  262. /* SD_TRANSFER */
  263. #define SD_TRANSFER_START 0x80
  264. #define SD_TRANSFER_END 0x40
  265. #define SD_STAT_IDLE 0x20
  266. #define SD_TRANSFER_ERR 0x10
  267. /* SD Transfer Mode definition */
  268. #define SD_TM_NORMAL_WRITE 0x00
  269. #define SD_TM_AUTO_WRITE_3 0x01
  270. #define SD_TM_AUTO_WRITE_4 0x02
  271. #define SD_TM_AUTO_READ_3 0x05
  272. #define SD_TM_AUTO_READ_4 0x06
  273. #define SD_TM_CMD_RSP 0x08
  274. #define SD_TM_AUTO_WRITE_1 0x09
  275. #define SD_TM_AUTO_WRITE_2 0x0A
  276. #define SD_TM_NORMAL_READ 0x0C
  277. #define SD_TM_AUTO_READ_1 0x0D
  278. #define SD_TM_AUTO_READ_2 0x0E
  279. #define SD_TM_AUTO_TUNING 0x0F
  280. /* SD_VPTX_CTL / SD_VPRX_CTL */
  281. #define PHASE_CHANGE 0x80
  282. #define PHASE_NOT_RESET 0x40
  283. /* SD_DCMPS_TX_CTL / SD_DCMPS_RX_CTL */
  284. #define DCMPS_CHANGE 0x80
  285. #define DCMPS_CHANGE_DONE 0x40
  286. #define DCMPS_ERROR 0x20
  287. #define DCMPS_CURRENT_PHASE 0x1F
  288. /* SD Configure 1 Register */
  289. #define SD_CLK_DIVIDE_0 0x00
  290. #define SD_CLK_DIVIDE_256 0xC0
  291. #define SD_CLK_DIVIDE_128 0x80
  292. #define SD_BUS_WIDTH_1BIT 0x00
  293. #define SD_BUS_WIDTH_4BIT 0x01
  294. #define SD_BUS_WIDTH_8BIT 0x02
  295. #define SD_ASYNC_FIFO_NOT_RST 0x10
  296. #define SD_20_MODE 0x00
  297. #define SD_DDR_MODE 0x04
  298. #define SD_30_MODE 0x08
  299. #define SD_CLK_DIVIDE_MASK 0xC0
  300. /* SD_CMD_STATE */
  301. #define SD_CMD_IDLE 0x80
  302. /* SD_DATA_STATE */
  303. #define SD_DATA_IDLE 0x80
  304. /* DCM_DRP_CTL */
  305. #define DCM_RESET 0x08
  306. #define DCM_LOCKED 0x04
  307. #define DCM_208M 0x00
  308. #define DCM_TX 0x01
  309. #define DCM_RX 0x02
  310. /* DCM_DRP_TRIG */
  311. #define DRP_START 0x80
  312. #define DRP_DONE 0x40
  313. /* DCM_DRP_CFG */
  314. #define DRP_WRITE 0x80
  315. #define DRP_READ 0x00
  316. #define DCM_WRITE_ADDRESS_50 0x50
  317. #define DCM_WRITE_ADDRESS_51 0x51
  318. #define DCM_READ_ADDRESS_00 0x00
  319. #define DCM_READ_ADDRESS_51 0x51
  320. /* IRQSTAT0 */
  321. #define DMA_DONE_INT 0x80
  322. #define SUSPEND_INT 0x40
  323. #define LINK_RDY_INT 0x20
  324. #define LINK_DOWN_INT 0x10
  325. /* DMACTL */
  326. #define DMA_RST 0x80
  327. #define DMA_BUSY 0x04
  328. #define DMA_DIR_TO_CARD 0x00
  329. #define DMA_DIR_FROM_CARD 0x02
  330. #define DMA_EN 0x01
  331. #define DMA_128 (0 << 4)
  332. #define DMA_256 (1 << 4)
  333. #define DMA_512 (2 << 4)
  334. #define DMA_1024 (3 << 4)
  335. #define DMA_PACK_SIZE_MASK 0x30
  336. /* SSC_CTL1 */
  337. #define SSC_RSTB 0x80
  338. #define SSC_8X_EN 0x40
  339. #define SSC_FIX_FRAC 0x20
  340. #define SSC_SEL_1M 0x00
  341. #define SSC_SEL_2M 0x08
  342. #define SSC_SEL_4M 0x10
  343. #define SSC_SEL_8M 0x18
  344. /* SSC_CTL2 */
  345. #define SSC_DEPTH_MASK 0x07
  346. #define SSC_DEPTH_DISALBE 0x00
  347. #define SSC_DEPTH_4M 0x01
  348. #define SSC_DEPTH_2M 0x02
  349. #define SSC_DEPTH_1M 0x03
  350. #define SSC_DEPTH_500K 0x04
  351. #define SSC_DEPTH_250K 0x05
  352. /* System Clock Control Register */
  353. #define CLK_LOW_FREQ 0x01
  354. /* System Clock Divider Register */
  355. #define CLK_DIV_1 0x01
  356. #define CLK_DIV_2 0x02
  357. #define CLK_DIV_4 0x03
  358. #define CLK_DIV_8 0x04
  359. /* MS_CFG */
  360. #define SAMPLE_TIME_RISING 0x00
  361. #define SAMPLE_TIME_FALLING 0x80
  362. #define PUSH_TIME_DEFAULT 0x00
  363. #define PUSH_TIME_ODD 0x40
  364. #define NO_EXTEND_TOGGLE 0x00
  365. #define EXTEND_TOGGLE_CHK 0x20
  366. #define MS_BUS_WIDTH_1 0x00
  367. #define MS_BUS_WIDTH_4 0x10
  368. #define MS_BUS_WIDTH_8 0x18
  369. #define MS_2K_SECTOR_MODE 0x04
  370. #define MS_512_SECTOR_MODE 0x00
  371. #define MS_TOGGLE_TIMEOUT_EN 0x00
  372. #define MS_TOGGLE_TIMEOUT_DISEN 0x01
  373. #define MS_NO_CHECK_INT 0x02
  374. /* MS_TRANS_CFG */
  375. #define WAIT_INT 0x80
  376. #define NO_WAIT_INT 0x00
  377. #define NO_AUTO_READ_INT_REG 0x00
  378. #define AUTO_READ_INT_REG 0x40
  379. #define MS_CRC16_ERR 0x20
  380. #define MS_RDY_TIMEOUT 0x10
  381. #define MS_INT_CMDNK 0x08
  382. #define MS_INT_BREQ 0x04
  383. #define MS_INT_ERR 0x02
  384. #define MS_INT_CED 0x01
  385. /* MS_TRANSFER */
  386. #define MS_TRANSFER_START 0x80
  387. #define MS_TRANSFER_END 0x40
  388. #define MS_TRANSFER_ERR 0x20
  389. #define MS_BS_STATE 0x10
  390. #define MS_TM_READ_BYTES 0x00
  391. #define MS_TM_NORMAL_READ 0x01
  392. #define MS_TM_WRITE_BYTES 0x04
  393. #define MS_TM_NORMAL_WRITE 0x05
  394. #define MS_TM_AUTO_READ 0x08
  395. #define MS_TM_AUTO_WRITE 0x0C
  396. /* SD Configure 2 Register */
  397. #define SD_CALCULATE_CRC7 0x00
  398. #define SD_NO_CALCULATE_CRC7 0x80
  399. #define SD_CHECK_CRC16 0x00
  400. #define SD_NO_CHECK_CRC16 0x40
  401. #define SD_NO_CHECK_WAIT_CRC_TO 0x20
  402. #define SD_WAIT_BUSY_END 0x08
  403. #define SD_NO_WAIT_BUSY_END 0x00
  404. #define SD_CHECK_CRC7 0x00
  405. #define SD_NO_CHECK_CRC7 0x04
  406. #define SD_RSP_LEN_0 0x00
  407. #define SD_RSP_LEN_6 0x01
  408. #define SD_RSP_LEN_17 0x02
  409. /* SD/MMC Response Type Definition */
  410. #define SD_RSP_TYPE_R0 0x04
  411. #define SD_RSP_TYPE_R1 0x01
  412. #define SD_RSP_TYPE_R1b 0x09
  413. #define SD_RSP_TYPE_R2 0x02
  414. #define SD_RSP_TYPE_R3 0x05
  415. #define SD_RSP_TYPE_R4 0x05
  416. #define SD_RSP_TYPE_R5 0x01
  417. #define SD_RSP_TYPE_R6 0x01
  418. #define SD_RSP_TYPE_R7 0x01
  419. /* SD_CONFIGURE3 */
  420. #define SD_RSP_80CLK_TIMEOUT_EN 0x01
  421. /* Card Transfer Reset Register */
  422. #define SPI_STOP 0x01
  423. #define XD_STOP 0x02
  424. #define SD_STOP 0x04
  425. #define MS_STOP 0x08
  426. #define SPI_CLR_ERR 0x10
  427. #define XD_CLR_ERR 0x20
  428. #define SD_CLR_ERR 0x40
  429. #define MS_CLR_ERR 0x80
  430. /* Card Data Source Register */
  431. #define PINGPONG_BUFFER 0x01
  432. #define RING_BUFFER 0x00
  433. /* Card Power Control Register */
  434. #define PMOS_STRG_MASK 0x10
  435. #define PMOS_STRG_800mA 0x10
  436. #define PMOS_STRG_400mA 0x00
  437. #define SD_POWER_OFF 0x03
  438. #define SD_PARTIAL_POWER_ON 0x01
  439. #define SD_POWER_ON 0x00
  440. #define SD_POWER_MASK 0x03
  441. #define MS_POWER_OFF 0x0C
  442. #define MS_PARTIAL_POWER_ON 0x04
  443. #define MS_POWER_ON 0x00
  444. #define MS_POWER_MASK 0x0C
  445. #define BPP_POWER_OFF 0x0F
  446. #define BPP_POWER_5_PERCENT_ON 0x0E
  447. #define BPP_POWER_10_PERCENT_ON 0x0C
  448. #define BPP_POWER_15_PERCENT_ON 0x08
  449. #define BPP_POWER_ON 0x00
  450. #define BPP_POWER_MASK 0x0F
  451. #define SD_VCC_PARTIAL_POWER_ON 0x02
  452. #define SD_VCC_POWER_ON 0x00
  453. /* PWR_GATE_CTRL */
  454. #define PWR_GATE_EN 0x01
  455. #define LDO3318_PWR_MASK 0x06
  456. #define LDO_ON 0x00
  457. #define LDO_SUSPEND 0x04
  458. #define LDO_OFF 0x06
  459. /* CARD_CLK_SOURCE */
  460. #define CRC_FIX_CLK (0x00 << 0)
  461. #define CRC_VAR_CLK0 (0x01 << 0)
  462. #define CRC_VAR_CLK1 (0x02 << 0)
  463. #define SD30_FIX_CLK (0x00 << 2)
  464. #define SD30_VAR_CLK0 (0x01 << 2)
  465. #define SD30_VAR_CLK1 (0x02 << 2)
  466. #define SAMPLE_FIX_CLK (0x00 << 4)
  467. #define SAMPLE_VAR_CLK0 (0x01 << 4)
  468. #define SAMPLE_VAR_CLK1 (0x02 << 4)
  469. /* HOST_SLEEP_STATE */
  470. #define HOST_ENTER_S1 1
  471. #define HOST_ENTER_S3 2
  472. #define MS_CFG 0xFD40
  473. #define MS_TPC 0xFD41
  474. #define MS_TRANS_CFG 0xFD42
  475. #define MS_TRANSFER 0xFD43
  476. #define MS_INT_REG 0xFD44
  477. #define MS_BYTE_CNT 0xFD45
  478. #define MS_SECTOR_CNT_L 0xFD46
  479. #define MS_SECTOR_CNT_H 0xFD47
  480. #define MS_DBUS_H 0xFD48
  481. #define SD_CFG1 0xFDA0
  482. #define SD_CFG2 0xFDA1
  483. #define SD_CFG3 0xFDA2
  484. #define SD_STAT1 0xFDA3
  485. #define SD_STAT2 0xFDA4
  486. #define SD_BUS_STAT 0xFDA5
  487. #define SD_PAD_CTL 0xFDA6
  488. #define SD_SAMPLE_POINT_CTL 0xFDA7
  489. #define SD_PUSH_POINT_CTL 0xFDA8
  490. #define SD_CMD0 0xFDA9
  491. #define SD_CMD1 0xFDAA
  492. #define SD_CMD2 0xFDAB
  493. #define SD_CMD3 0xFDAC
  494. #define SD_CMD4 0xFDAD
  495. #define SD_CMD5 0xFDAE
  496. #define SD_BYTE_CNT_L 0xFDAF
  497. #define SD_BYTE_CNT_H 0xFDB0
  498. #define SD_BLOCK_CNT_L 0xFDB1
  499. #define SD_BLOCK_CNT_H 0xFDB2
  500. #define SD_TRANSFER 0xFDB3
  501. #define SD_CMD_STATE 0xFDB5
  502. #define SD_DATA_STATE 0xFDB6
  503. #define SRCTL 0xFC13
  504. #define DCM_DRP_CTL 0xFC23
  505. #define DCM_DRP_TRIG 0xFC24
  506. #define DCM_DRP_CFG 0xFC25
  507. #define DCM_DRP_WR_DATA_L 0xFC26
  508. #define DCM_DRP_WR_DATA_H 0xFC27
  509. #define DCM_DRP_RD_DATA_L 0xFC28
  510. #define DCM_DRP_RD_DATA_H 0xFC29
  511. #define SD_VPCLK0_CTL 0xFC2A
  512. #define SD_VPCLK1_CTL 0xFC2B
  513. #define SD_DCMPS0_CTL 0xFC2C
  514. #define SD_DCMPS1_CTL 0xFC2D
  515. #define SD_VPTX_CTL SD_VPCLK0_CTL
  516. #define SD_VPRX_CTL SD_VPCLK1_CTL
  517. #define SD_DCMPS_TX_CTL SD_DCMPS0_CTL
  518. #define SD_DCMPS_RX_CTL SD_DCMPS1_CTL
  519. #define CARD_CLK_SOURCE 0xFC2E
  520. #define CARD_PWR_CTL 0xFD50
  521. #define CARD_CLK_SWITCH 0xFD51
  522. #define RTL8411B_PACKAGE_MODE 0xFD51
  523. #define CARD_SHARE_MODE 0xFD52
  524. #define CARD_DRIVE_SEL 0xFD53
  525. #define CARD_STOP 0xFD54
  526. #define CARD_OE 0xFD55
  527. #define CARD_AUTO_BLINK 0xFD56
  528. #define CARD_GPIO_DIR 0xFD57
  529. #define CARD_GPIO 0xFD58
  530. #define CARD_DATA_SOURCE 0xFD5B
  531. #define SD30_CLK_DRIVE_SEL 0xFD5A
  532. #define CARD_SELECT 0xFD5C
  533. #define SD30_DRIVE_SEL 0xFD5E
  534. #define SD30_CMD_DRIVE_SEL 0xFD5E
  535. #define SD30_DAT_DRIVE_SEL 0xFD5F
  536. #define CARD_CLK_EN 0xFD69
  537. #define SDIO_CTRL 0xFD6B
  538. #define CD_PAD_CTL 0xFD73
  539. #define FPDCTL 0xFC00
  540. #define PDINFO 0xFC01
  541. #define CLK_CTL 0xFC02
  542. #define CLK_DIV 0xFC03
  543. #define CLK_SEL 0xFC04
  544. #define SSC_DIV_N_0 0xFC0F
  545. #define SSC_DIV_N_1 0xFC10
  546. #define SSC_CTL1 0xFC11
  547. #define SSC_CTL2 0xFC12
  548. #define RCCTL 0xFC14
  549. #define FPGA_PULL_CTL 0xFC1D
  550. #define OLT_LED_CTL 0xFC1E
  551. #define GPIO_CTL 0xFC1F
  552. #define LDO_CTL 0xFC1E
  553. #define SYS_VER 0xFC32
  554. #define CARD_PULL_CTL1 0xFD60
  555. #define CARD_PULL_CTL2 0xFD61
  556. #define CARD_PULL_CTL3 0xFD62
  557. #define CARD_PULL_CTL4 0xFD63
  558. #define CARD_PULL_CTL5 0xFD64
  559. #define CARD_PULL_CTL6 0xFD65
  560. /* PCI Express Related Registers */
  561. #define IRQEN0 0xFE20
  562. #define IRQSTAT0 0xFE21
  563. #define IRQEN1 0xFE22
  564. #define IRQSTAT1 0xFE23
  565. #define TLPRIEN 0xFE24
  566. #define TLPRISTAT 0xFE25
  567. #define TLPTIEN 0xFE26
  568. #define TLPTISTAT 0xFE27
  569. #define DMATC0 0xFE28
  570. #define DMATC1 0xFE29
  571. #define DMATC2 0xFE2A
  572. #define DMATC3 0xFE2B
  573. #define DMACTL 0xFE2C
  574. #define BCTL 0xFE2D
  575. #define RBBC0 0xFE2E
  576. #define RBBC1 0xFE2F
  577. #define RBDAT 0xFE30
  578. #define RBCTL 0xFE34
  579. #define CFGADDR0 0xFE35
  580. #define CFGADDR1 0xFE36
  581. #define CFGDATA0 0xFE37
  582. #define CFGDATA1 0xFE38
  583. #define CFGDATA2 0xFE39
  584. #define CFGDATA3 0xFE3A
  585. #define CFGRWCTL 0xFE3B
  586. #define PHYRWCTL 0xFE3C
  587. #define PHYDATA0 0xFE3D
  588. #define PHYDATA1 0xFE3E
  589. #define PHYADDR 0xFE3F
  590. #define MSGRXDATA0 0xFE40
  591. #define MSGRXDATA1 0xFE41
  592. #define MSGRXDATA2 0xFE42
  593. #define MSGRXDATA3 0xFE43
  594. #define MSGTXDATA0 0xFE44
  595. #define MSGTXDATA1 0xFE45
  596. #define MSGTXDATA2 0xFE46
  597. #define MSGTXDATA3 0xFE47
  598. #define MSGTXCTL 0xFE48
  599. #define PETXCFG 0xFE49
  600. #define LTR_CTL 0xFE4A
  601. #define OBFF_CFG 0xFE4C
  602. #define CDRESUMECTL 0xFE52
  603. #define WAKE_SEL_CTL 0xFE54
  604. #define PME_FORCE_CTL 0xFE56
  605. #define ASPM_FORCE_CTL 0xFE57
  606. #define PM_CLK_FORCE_CTL 0xFE58
  607. #define FUNC_FORCE_CTL 0xFE59
  608. #define PERST_GLITCH_WIDTH 0xFE5C
  609. #define CHANGE_LINK_STATE 0xFE5B
  610. #define RESET_LOAD_REG 0xFE5E
  611. #define EFUSE_CONTENT 0xFE5F
  612. #define HOST_SLEEP_STATE 0xFE60
  613. #define SDIO_CFG 0xFE70
  614. #define NFTS_TX_CTRL 0xFE72
  615. #define PWR_GATE_CTRL 0xFE75
  616. #define PWD_SUSPEND_EN 0xFE76
  617. #define LDO_PWR_SEL 0xFE78
  618. #define DUMMY_REG_RESET_0 0xFE90
  619. #define AUTOLOAD_CFG_BASE 0xFF00
  620. #define PM_CTRL1 0xFF44
  621. #define PM_CTRL2 0xFF45
  622. #define PM_CTRL3 0xFF46
  623. #define PM_CTRL4 0xFF47
  624. /* Memory mapping */
  625. #define SRAM_BASE 0xE600
  626. #define RBUF_BASE 0xF400
  627. #define PPBUF_BASE1 0xF800
  628. #define PPBUF_BASE2 0xFA00
  629. #define IMAGE_FLAG_ADDR0 0xCE80
  630. #define IMAGE_FLAG_ADDR1 0xCE81
  631. /* Phy register */
  632. #define PHY_PCR 0x00
  633. #define PHY_RCR0 0x01
  634. #define PHY_RCR1 0x02
  635. #define PHY_RCR2 0x03
  636. #define PHY_RTCR 0x04
  637. #define PHY_RDR 0x05
  638. #define PHY_TCR0 0x06
  639. #define PHY_TCR1 0x07
  640. #define PHY_TUNE 0x08
  641. #define PHY_IMR 0x09
  642. #define PHY_BPCR 0x0A
  643. #define PHY_BIST 0x0B
  644. #define PHY_RAW_L 0x0C
  645. #define PHY_RAW_H 0x0D
  646. #define PHY_RAW_DATA 0x0E
  647. #define PHY_HOST_CLK_CTRL 0x0F
  648. #define PHY_DMR 0x10
  649. #define PHY_BACR 0x11
  650. #define PHY_IER 0x12
  651. #define PHY_BCSR 0x13
  652. #define PHY_BPR 0x14
  653. #define PHY_BPNR2 0x15
  654. #define PHY_BPNR 0x16
  655. #define PHY_BRNR2 0x17
  656. #define PHY_BENR 0x18
  657. #define PHY_REG_REV 0x19
  658. #define PHY_FLD0 0x1A
  659. #define PHY_FLD1 0x1B
  660. #define PHY_FLD2 0x1C
  661. #define PHY_FLD3 0x1D
  662. #define PHY_FLD4 0x1E
  663. #define PHY_DUM_REG 0x1F
  664. #define LCTLR 0x80
  665. #define PCR_SETTING_REG1 0x724
  666. #define PCR_SETTING_REG2 0x814
  667. #define PCR_SETTING_REG3 0x747
  668. #define rtsx_pci_init_cmd(pcr) ((pcr)->ci = 0)
  669. struct rtsx_pcr;
  670. struct pcr_handle {
  671. struct rtsx_pcr *pcr;
  672. };
  673. struct pcr_ops {
  674. int (*extra_init_hw)(struct rtsx_pcr *pcr);
  675. int (*optimize_phy)(struct rtsx_pcr *pcr);
  676. int (*turn_on_led)(struct rtsx_pcr *pcr);
  677. int (*turn_off_led)(struct rtsx_pcr *pcr);
  678. int (*enable_auto_blink)(struct rtsx_pcr *pcr);
  679. int (*disable_auto_blink)(struct rtsx_pcr *pcr);
  680. int (*card_power_on)(struct rtsx_pcr *pcr, int card);
  681. int (*card_power_off)(struct rtsx_pcr *pcr, int card);
  682. int (*switch_output_voltage)(struct rtsx_pcr *pcr,
  683. u8 voltage);
  684. unsigned int (*cd_deglitch)(struct rtsx_pcr *pcr);
  685. int (*conv_clk_and_div_n)(int clk, int dir);
  686. void (*fetch_vendor_settings)(struct rtsx_pcr *pcr);
  687. void (*force_power_down)(struct rtsx_pcr *pcr, u8 pm_state);
  688. };
  689. enum PDEV_STAT {PDEV_STAT_IDLE, PDEV_STAT_RUN};
  690. struct rtsx_pcr {
  691. struct pci_dev *pci;
  692. unsigned int id;
  693. /* pci resources */
  694. unsigned long addr;
  695. void __iomem *remap_addr;
  696. int irq;
  697. /* host reserved buffer */
  698. void *rtsx_resv_buf;
  699. dma_addr_t rtsx_resv_buf_addr;
  700. void *host_cmds_ptr;
  701. dma_addr_t host_cmds_addr;
  702. int ci;
  703. void *host_sg_tbl_ptr;
  704. dma_addr_t host_sg_tbl_addr;
  705. int sgi;
  706. u32 bier;
  707. char trans_result;
  708. unsigned int card_inserted;
  709. unsigned int card_removed;
  710. unsigned int card_exist;
  711. struct delayed_work carddet_work;
  712. struct delayed_work idle_work;
  713. spinlock_t lock;
  714. struct mutex pcr_mutex;
  715. struct completion *done;
  716. struct completion *finish_me;
  717. unsigned int cur_clock;
  718. bool remove_pci;
  719. bool msi_en;
  720. #define EXTRA_CAPS_SD_SDR50 (1 << 0)
  721. #define EXTRA_CAPS_SD_SDR104 (1 << 1)
  722. #define EXTRA_CAPS_SD_DDR50 (1 << 2)
  723. #define EXTRA_CAPS_MMC_HSDDR (1 << 3)
  724. #define EXTRA_CAPS_MMC_HS200 (1 << 4)
  725. #define EXTRA_CAPS_MMC_8BIT (1 << 5)
  726. u32 extra_caps;
  727. #define IC_VER_A 0
  728. #define IC_VER_B 1
  729. #define IC_VER_C 2
  730. #define IC_VER_D 3
  731. u8 ic_version;
  732. u8 sd30_drive_sel_1v8;
  733. u8 sd30_drive_sel_3v3;
  734. u8 card_drive_sel;
  735. #define ASPM_L1_EN 0x02
  736. u8 aspm_en;
  737. #define PCR_MS_PMOS (1 << 0)
  738. #define PCR_REVERSE_SOCKET (1 << 1)
  739. u32 flags;
  740. u32 tx_initial_phase;
  741. u32 rx_initial_phase;
  742. const u32 *sd_pull_ctl_enable_tbl;
  743. const u32 *sd_pull_ctl_disable_tbl;
  744. const u32 *ms_pull_ctl_enable_tbl;
  745. const u32 *ms_pull_ctl_disable_tbl;
  746. const struct pcr_ops *ops;
  747. enum PDEV_STAT state;
  748. int num_slots;
  749. struct rtsx_slot *slots;
  750. };
  751. #define CHK_PCI_PID(pcr, pid) ((pcr)->pci->device == (pid))
  752. #define PCI_VID(pcr) ((pcr)->pci->vendor)
  753. #define PCI_PID(pcr) ((pcr)->pci->device)
  754. #define SDR104_PHASE(val) ((val) & 0xFF)
  755. #define SDR50_PHASE(val) (((val) >> 8) & 0xFF)
  756. #define DDR50_PHASE(val) (((val) >> 16) & 0xFF)
  757. #define SDR104_TX_PHASE(pcr) SDR104_PHASE((pcr)->tx_initial_phase)
  758. #define SDR50_TX_PHASE(pcr) SDR50_PHASE((pcr)->tx_initial_phase)
  759. #define DDR50_TX_PHASE(pcr) DDR50_PHASE((pcr)->tx_initial_phase)
  760. #define SDR104_RX_PHASE(pcr) SDR104_PHASE((pcr)->rx_initial_phase)
  761. #define SDR50_RX_PHASE(pcr) SDR50_PHASE((pcr)->rx_initial_phase)
  762. #define DDR50_RX_PHASE(pcr) DDR50_PHASE((pcr)->rx_initial_phase)
  763. #define SET_CLOCK_PHASE(sdr104, sdr50, ddr50) \
  764. (((ddr50) << 16) | ((sdr50) << 8) | (sdr104))
  765. void rtsx_pci_start_run(struct rtsx_pcr *pcr);
  766. int rtsx_pci_write_register(struct rtsx_pcr *pcr, u16 addr, u8 mask, u8 data);
  767. int rtsx_pci_read_register(struct rtsx_pcr *pcr, u16 addr, u8 *data);
  768. int rtsx_pci_write_phy_register(struct rtsx_pcr *pcr, u8 addr, u16 val);
  769. int rtsx_pci_read_phy_register(struct rtsx_pcr *pcr, u8 addr, u16 *val);
  770. void rtsx_pci_stop_cmd(struct rtsx_pcr *pcr);
  771. void rtsx_pci_add_cmd(struct rtsx_pcr *pcr,
  772. u8 cmd_type, u16 reg_addr, u8 mask, u8 data);
  773. void rtsx_pci_send_cmd_no_wait(struct rtsx_pcr *pcr);
  774. int rtsx_pci_send_cmd(struct rtsx_pcr *pcr, int timeout);
  775. int rtsx_pci_transfer_data(struct rtsx_pcr *pcr, struct scatterlist *sglist,
  776. int num_sg, bool read, int timeout);
  777. int rtsx_pci_read_ppbuf(struct rtsx_pcr *pcr, u8 *buf, int buf_len);
  778. int rtsx_pci_write_ppbuf(struct rtsx_pcr *pcr, u8 *buf, int buf_len);
  779. int rtsx_pci_card_pull_ctl_enable(struct rtsx_pcr *pcr, int card);
  780. int rtsx_pci_card_pull_ctl_disable(struct rtsx_pcr *pcr, int card);
  781. int rtsx_pci_switch_clock(struct rtsx_pcr *pcr, unsigned int card_clock,
  782. u8 ssc_depth, bool initial_mode, bool double_clk, bool vpclk);
  783. int rtsx_pci_card_power_on(struct rtsx_pcr *pcr, int card);
  784. int rtsx_pci_card_power_off(struct rtsx_pcr *pcr, int card);
  785. int rtsx_pci_card_exclusive_check(struct rtsx_pcr *pcr, int card);
  786. int rtsx_pci_switch_output_voltage(struct rtsx_pcr *pcr, u8 voltage);
  787. unsigned int rtsx_pci_card_exist(struct rtsx_pcr *pcr);
  788. void rtsx_pci_complete_unfinished_transfer(struct rtsx_pcr *pcr);
  789. static inline u8 *rtsx_pci_get_cmd_data(struct rtsx_pcr *pcr)
  790. {
  791. return (u8 *)(pcr->host_cmds_ptr);
  792. }
  793. #endif