rtsx_pci.h 24 KB

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