rtsx_pci.h 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367
  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/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_MODE_SELECT_MASK 0x0C
  185. #define SD_CFG2 0xFDA1
  186. #define SD_CALCULATE_CRC7 0x00
  187. #define SD_NO_CALCULATE_CRC7 0x80
  188. #define SD_CHECK_CRC16 0x00
  189. #define SD_NO_CHECK_CRC16 0x40
  190. #define SD_NO_CHECK_WAIT_CRC_TO 0x20
  191. #define SD_WAIT_BUSY_END 0x08
  192. #define SD_NO_WAIT_BUSY_END 0x00
  193. #define SD_CHECK_CRC7 0x00
  194. #define SD_NO_CHECK_CRC7 0x04
  195. #define SD_RSP_LEN_0 0x00
  196. #define SD_RSP_LEN_6 0x01
  197. #define SD_RSP_LEN_17 0x02
  198. #define SD_RSP_TYPE_R0 0x04
  199. #define SD_RSP_TYPE_R1 0x01
  200. #define SD_RSP_TYPE_R1b 0x09
  201. #define SD_RSP_TYPE_R2 0x02
  202. #define SD_RSP_TYPE_R3 0x05
  203. #define SD_RSP_TYPE_R4 0x05
  204. #define SD_RSP_TYPE_R5 0x01
  205. #define SD_RSP_TYPE_R6 0x01
  206. #define SD_RSP_TYPE_R7 0x01
  207. #define SD_CFG3 0xFDA2
  208. #define SD30_CLK_END_EN 0x10
  209. #define SD_RSP_80CLK_TIMEOUT_EN 0x01
  210. #define SD_STAT1 0xFDA3
  211. #define SD_CRC7_ERR 0x80
  212. #define SD_CRC16_ERR 0x40
  213. #define SD_CRC_WRITE_ERR 0x20
  214. #define SD_CRC_WRITE_ERR_MASK 0x1C
  215. #define GET_CRC_TIME_OUT 0x02
  216. #define SD_TUNING_COMPARE_ERR 0x01
  217. #define SD_STAT2 0xFDA4
  218. #define SD_RSP_80CLK_TIMEOUT 0x01
  219. #define SD_BUS_STAT 0xFDA5
  220. #define SD_CLK_TOGGLE_EN 0x80
  221. #define SD_CLK_FORCE_STOP 0x40
  222. #define SD_DAT3_STATUS 0x10
  223. #define SD_DAT2_STATUS 0x08
  224. #define SD_DAT1_STATUS 0x04
  225. #define SD_DAT0_STATUS 0x02
  226. #define SD_CMD_STATUS 0x01
  227. #define SD_PAD_CTL 0xFDA6
  228. #define SD_IO_USING_1V8 0x80
  229. #define SD_IO_USING_3V3 0x7F
  230. #define TYPE_A_DRIVING 0x00
  231. #define TYPE_B_DRIVING 0x01
  232. #define TYPE_C_DRIVING 0x02
  233. #define TYPE_D_DRIVING 0x03
  234. #define SD_SAMPLE_POINT_CTL 0xFDA7
  235. #define DDR_FIX_RX_DAT 0x00
  236. #define DDR_VAR_RX_DAT 0x80
  237. #define DDR_FIX_RX_DAT_EDGE 0x00
  238. #define DDR_FIX_RX_DAT_14_DELAY 0x40
  239. #define DDR_FIX_RX_CMD 0x00
  240. #define DDR_VAR_RX_CMD 0x20
  241. #define DDR_FIX_RX_CMD_POS_EDGE 0x00
  242. #define DDR_FIX_RX_CMD_14_DELAY 0x10
  243. #define SD20_RX_POS_EDGE 0x00
  244. #define SD20_RX_14_DELAY 0x08
  245. #define SD20_RX_SEL_MASK 0x08
  246. #define SD_PUSH_POINT_CTL 0xFDA8
  247. #define DDR_FIX_TX_CMD_DAT 0x00
  248. #define DDR_VAR_TX_CMD_DAT 0x80
  249. #define DDR_FIX_TX_DAT_14_TSU 0x00
  250. #define DDR_FIX_TX_DAT_12_TSU 0x40
  251. #define DDR_FIX_TX_CMD_NEG_EDGE 0x00
  252. #define DDR_FIX_TX_CMD_14_AHEAD 0x20
  253. #define SD20_TX_NEG_EDGE 0x00
  254. #define SD20_TX_14_AHEAD 0x10
  255. #define SD20_TX_SEL_MASK 0x10
  256. #define DDR_VAR_SDCLK_POL_SWAP 0x01
  257. #define SD_CMD0 0xFDA9
  258. #define SD_CMD_START 0x40
  259. #define SD_CMD1 0xFDAA
  260. #define SD_CMD2 0xFDAB
  261. #define SD_CMD3 0xFDAC
  262. #define SD_CMD4 0xFDAD
  263. #define SD_CMD5 0xFDAE
  264. #define SD_BYTE_CNT_L 0xFDAF
  265. #define SD_BYTE_CNT_H 0xFDB0
  266. #define SD_BLOCK_CNT_L 0xFDB1
  267. #define SD_BLOCK_CNT_H 0xFDB2
  268. #define SD_TRANSFER 0xFDB3
  269. #define SD_TRANSFER_START 0x80
  270. #define SD_TRANSFER_END 0x40
  271. #define SD_STAT_IDLE 0x20
  272. #define SD_TRANSFER_ERR 0x10
  273. #define SD_TM_NORMAL_WRITE 0x00
  274. #define SD_TM_AUTO_WRITE_3 0x01
  275. #define SD_TM_AUTO_WRITE_4 0x02
  276. #define SD_TM_AUTO_READ_3 0x05
  277. #define SD_TM_AUTO_READ_4 0x06
  278. #define SD_TM_CMD_RSP 0x08
  279. #define SD_TM_AUTO_WRITE_1 0x09
  280. #define SD_TM_AUTO_WRITE_2 0x0A
  281. #define SD_TM_NORMAL_READ 0x0C
  282. #define SD_TM_AUTO_READ_1 0x0D
  283. #define SD_TM_AUTO_READ_2 0x0E
  284. #define SD_TM_AUTO_TUNING 0x0F
  285. #define SD_CMD_STATE 0xFDB5
  286. #define SD_CMD_IDLE 0x80
  287. #define SD_DATA_STATE 0xFDB6
  288. #define SD_DATA_IDLE 0x80
  289. #define REG_SD_STOP_SDCLK_CFG 0xFDB8
  290. #define SD30_CLK_STOP_CFG_EN 0x04
  291. #define SD30_CLK_STOP_CFG1 0x02
  292. #define SD30_CLK_STOP_CFG0 0x01
  293. #define REG_PRE_RW_MODE 0xFD70
  294. #define EN_INFINITE_MODE 0x01
  295. #define SRCTL 0xFC13
  296. #define DCM_DRP_CTL 0xFC23
  297. #define DCM_RESET 0x08
  298. #define DCM_LOCKED 0x04
  299. #define DCM_208M 0x00
  300. #define DCM_TX 0x01
  301. #define DCM_RX 0x02
  302. #define DCM_DRP_TRIG 0xFC24
  303. #define DRP_START 0x80
  304. #define DRP_DONE 0x40
  305. #define DCM_DRP_CFG 0xFC25
  306. #define DRP_WRITE 0x80
  307. #define DRP_READ 0x00
  308. #define DCM_WRITE_ADDRESS_50 0x50
  309. #define DCM_WRITE_ADDRESS_51 0x51
  310. #define DCM_READ_ADDRESS_00 0x00
  311. #define DCM_READ_ADDRESS_51 0x51
  312. #define DCM_DRP_WR_DATA_L 0xFC26
  313. #define DCM_DRP_WR_DATA_H 0xFC27
  314. #define DCM_DRP_RD_DATA_L 0xFC28
  315. #define DCM_DRP_RD_DATA_H 0xFC29
  316. #define SD_VPCLK0_CTL 0xFC2A
  317. #define SD_VPCLK1_CTL 0xFC2B
  318. #define PHASE_SELECT_MASK 0x1F
  319. #define SD_DCMPS0_CTL 0xFC2C
  320. #define SD_DCMPS1_CTL 0xFC2D
  321. #define SD_VPTX_CTL SD_VPCLK0_CTL
  322. #define SD_VPRX_CTL SD_VPCLK1_CTL
  323. #define PHASE_CHANGE 0x80
  324. #define PHASE_NOT_RESET 0x40
  325. #define SD_DCMPS_TX_CTL SD_DCMPS0_CTL
  326. #define SD_DCMPS_RX_CTL SD_DCMPS1_CTL
  327. #define DCMPS_CHANGE 0x80
  328. #define DCMPS_CHANGE_DONE 0x40
  329. #define DCMPS_ERROR 0x20
  330. #define DCMPS_CURRENT_PHASE 0x1F
  331. #define CARD_CLK_SOURCE 0xFC2E
  332. #define CRC_FIX_CLK (0x00 << 0)
  333. #define CRC_VAR_CLK0 (0x01 << 0)
  334. #define CRC_VAR_CLK1 (0x02 << 0)
  335. #define SD30_FIX_CLK (0x00 << 2)
  336. #define SD30_VAR_CLK0 (0x01 << 2)
  337. #define SD30_VAR_CLK1 (0x02 << 2)
  338. #define SAMPLE_FIX_CLK (0x00 << 4)
  339. #define SAMPLE_VAR_CLK0 (0x01 << 4)
  340. #define SAMPLE_VAR_CLK1 (0x02 << 4)
  341. #define CARD_PWR_CTL 0xFD50
  342. #define PMOS_STRG_MASK 0x10
  343. #define PMOS_STRG_800mA 0x10
  344. #define PMOS_STRG_400mA 0x00
  345. #define SD_POWER_OFF 0x03
  346. #define SD_PARTIAL_POWER_ON 0x01
  347. #define SD_POWER_ON 0x00
  348. #define SD_POWER_MASK 0x03
  349. #define MS_POWER_OFF 0x0C
  350. #define MS_PARTIAL_POWER_ON 0x04
  351. #define MS_POWER_ON 0x00
  352. #define MS_POWER_MASK 0x0C
  353. #define BPP_POWER_OFF 0x0F
  354. #define BPP_POWER_5_PERCENT_ON 0x0E
  355. #define BPP_POWER_10_PERCENT_ON 0x0C
  356. #define BPP_POWER_15_PERCENT_ON 0x08
  357. #define BPP_POWER_ON 0x00
  358. #define BPP_POWER_MASK 0x0F
  359. #define SD_VCC_PARTIAL_POWER_ON 0x02
  360. #define SD_VCC_POWER_ON 0x00
  361. #define CARD_CLK_SWITCH 0xFD51
  362. #define RTL8411B_PACKAGE_MODE 0xFD51
  363. #define CARD_SHARE_MODE 0xFD52
  364. #define CARD_SHARE_MASK 0x0F
  365. #define CARD_SHARE_MULTI_LUN 0x00
  366. #define CARD_SHARE_NORMAL 0x00
  367. #define CARD_SHARE_48_SD 0x04
  368. #define CARD_SHARE_48_MS 0x08
  369. #define CARD_SHARE_BAROSSA_SD 0x01
  370. #define CARD_SHARE_BAROSSA_MS 0x02
  371. #define CARD_DRIVE_SEL 0xFD53
  372. #define MS_DRIVE_8mA (0x01 << 6)
  373. #define MMC_DRIVE_8mA (0x01 << 4)
  374. #define XD_DRIVE_8mA (0x01 << 2)
  375. #define GPIO_DRIVE_8mA 0x01
  376. #define RTS5209_CARD_DRIVE_DEFAULT (MS_DRIVE_8mA | MMC_DRIVE_8mA |\
  377. XD_DRIVE_8mA | GPIO_DRIVE_8mA)
  378. #define RTL8411_CARD_DRIVE_DEFAULT (MS_DRIVE_8mA | MMC_DRIVE_8mA |\
  379. XD_DRIVE_8mA)
  380. #define RTSX_CARD_DRIVE_DEFAULT (MS_DRIVE_8mA | GPIO_DRIVE_8mA)
  381. #define CARD_STOP 0xFD54
  382. #define SPI_STOP 0x01
  383. #define XD_STOP 0x02
  384. #define SD_STOP 0x04
  385. #define MS_STOP 0x08
  386. #define SPI_CLR_ERR 0x10
  387. #define XD_CLR_ERR 0x20
  388. #define SD_CLR_ERR 0x40
  389. #define MS_CLR_ERR 0x80
  390. #define CARD_OE 0xFD55
  391. #define SD_OUTPUT_EN 0x04
  392. #define MS_OUTPUT_EN 0x08
  393. #define CARD_AUTO_BLINK 0xFD56
  394. #define CARD_GPIO_DIR 0xFD57
  395. #define CARD_GPIO 0xFD58
  396. #define CARD_DATA_SOURCE 0xFD5B
  397. #define PINGPONG_BUFFER 0x01
  398. #define RING_BUFFER 0x00
  399. #define SD30_CLK_DRIVE_SEL 0xFD5A
  400. #define DRIVER_TYPE_A 0x05
  401. #define DRIVER_TYPE_B 0x03
  402. #define DRIVER_TYPE_C 0x02
  403. #define DRIVER_TYPE_D 0x01
  404. #define CARD_SELECT 0xFD5C
  405. #define SD_MOD_SEL 2
  406. #define MS_MOD_SEL 3
  407. #define SD30_DRIVE_SEL 0xFD5E
  408. #define CFG_DRIVER_TYPE_A 0x02
  409. #define CFG_DRIVER_TYPE_B 0x03
  410. #define CFG_DRIVER_TYPE_C 0x01
  411. #define CFG_DRIVER_TYPE_D 0x00
  412. #define SD30_CMD_DRIVE_SEL 0xFD5E
  413. #define SD30_DAT_DRIVE_SEL 0xFD5F
  414. #define CARD_CLK_EN 0xFD69
  415. #define SD_CLK_EN 0x04
  416. #define MS_CLK_EN 0x08
  417. #define SD40_CLK_EN 0x10
  418. #define SDIO_CTRL 0xFD6B
  419. #define CD_PAD_CTL 0xFD73
  420. #define CD_DISABLE_MASK 0x07
  421. #define MS_CD_DISABLE 0x04
  422. #define SD_CD_DISABLE 0x02
  423. #define XD_CD_DISABLE 0x01
  424. #define CD_DISABLE 0x07
  425. #define CD_ENABLE 0x00
  426. #define MS_CD_EN_ONLY 0x03
  427. #define SD_CD_EN_ONLY 0x05
  428. #define XD_CD_EN_ONLY 0x06
  429. #define FORCE_CD_LOW_MASK 0x38
  430. #define FORCE_CD_XD_LOW 0x08
  431. #define FORCE_CD_SD_LOW 0x10
  432. #define FORCE_CD_MS_LOW 0x20
  433. #define CD_AUTO_DISABLE 0x40
  434. #define FPDCTL 0xFC00
  435. #define SSC_POWER_DOWN 0x01
  436. #define SD_OC_POWER_DOWN 0x02
  437. #define ALL_POWER_DOWN 0x03
  438. #define OC_POWER_DOWN 0x02
  439. #define PDINFO 0xFC01
  440. #define CLK_CTL 0xFC02
  441. #define CHANGE_CLK 0x01
  442. #define CLK_LOW_FREQ 0x01
  443. #define CLK_DIV 0xFC03
  444. #define CLK_DIV_1 0x01
  445. #define CLK_DIV_2 0x02
  446. #define CLK_DIV_4 0x03
  447. #define CLK_DIV_8 0x04
  448. #define CLK_SEL 0xFC04
  449. #define SSC_DIV_N_0 0xFC0F
  450. #define SSC_DIV_N_1 0xFC10
  451. #define SSC_CTL1 0xFC11
  452. #define SSC_RSTB 0x80
  453. #define SSC_8X_EN 0x40
  454. #define SSC_FIX_FRAC 0x20
  455. #define SSC_SEL_1M 0x00
  456. #define SSC_SEL_2M 0x08
  457. #define SSC_SEL_4M 0x10
  458. #define SSC_SEL_8M 0x18
  459. #define SSC_CTL2 0xFC12
  460. #define SSC_DEPTH_MASK 0x07
  461. #define SSC_DEPTH_DISALBE 0x00
  462. #define SSC_DEPTH_4M 0x01
  463. #define SSC_DEPTH_2M 0x02
  464. #define SSC_DEPTH_1M 0x03
  465. #define SSC_DEPTH_500K 0x04
  466. #define SSC_DEPTH_250K 0x05
  467. #define RCCTL 0xFC14
  468. #define FPGA_PULL_CTL 0xFC1D
  469. #define OLT_LED_CTL 0xFC1E
  470. #define LED_SHINE_MASK 0x08
  471. #define LED_SHINE_EN 0x08
  472. #define LED_SHINE_DISABLE 0x00
  473. #define GPIO_CTL 0xFC1F
  474. #define LDO_CTL 0xFC1E
  475. #define BPP_ASIC_1V7 0x00
  476. #define BPP_ASIC_1V8 0x01
  477. #define BPP_ASIC_1V9 0x02
  478. #define BPP_ASIC_2V0 0x03
  479. #define BPP_ASIC_2V7 0x04
  480. #define BPP_ASIC_2V8 0x05
  481. #define BPP_ASIC_3V2 0x06
  482. #define BPP_ASIC_3V3 0x07
  483. #define BPP_REG_TUNED18 0x07
  484. #define BPP_TUNED18_SHIFT_8402 5
  485. #define BPP_TUNED18_SHIFT_8411 4
  486. #define BPP_PAD_MASK 0x04
  487. #define BPP_PAD_3V3 0x04
  488. #define BPP_PAD_1V8 0x00
  489. #define BPP_LDO_POWB 0x03
  490. #define BPP_LDO_ON 0x00
  491. #define BPP_LDO_SUSPEND 0x02
  492. #define BPP_LDO_OFF 0x03
  493. #define EFUSE_CTL 0xFC30
  494. #define EFUSE_ADD 0xFC31
  495. #define SYS_VER 0xFC32
  496. #define EFUSE_DATAL 0xFC34
  497. #define EFUSE_DATAH 0xFC35
  498. #define CARD_PULL_CTL1 0xFD60
  499. #define CARD_PULL_CTL2 0xFD61
  500. #define CARD_PULL_CTL3 0xFD62
  501. #define CARD_PULL_CTL4 0xFD63
  502. #define CARD_PULL_CTL5 0xFD64
  503. #define CARD_PULL_CTL6 0xFD65
  504. /* PCI Express Related Registers */
  505. #define IRQEN0 0xFE20
  506. #define IRQSTAT0 0xFE21
  507. #define DMA_DONE_INT 0x80
  508. #define SUSPEND_INT 0x40
  509. #define LINK_RDY_INT 0x20
  510. #define LINK_DOWN_INT 0x10
  511. #define IRQEN1 0xFE22
  512. #define IRQSTAT1 0xFE23
  513. #define TLPRIEN 0xFE24
  514. #define TLPRISTAT 0xFE25
  515. #define TLPTIEN 0xFE26
  516. #define TLPTISTAT 0xFE27
  517. #define DMATC0 0xFE28
  518. #define DMATC1 0xFE29
  519. #define DMATC2 0xFE2A
  520. #define DMATC3 0xFE2B
  521. #define DMACTL 0xFE2C
  522. #define DMA_RST 0x80
  523. #define DMA_BUSY 0x04
  524. #define DMA_DIR_TO_CARD 0x00
  525. #define DMA_DIR_FROM_CARD 0x02
  526. #define DMA_EN 0x01
  527. #define DMA_128 (0 << 4)
  528. #define DMA_256 (1 << 4)
  529. #define DMA_512 (2 << 4)
  530. #define DMA_1024 (3 << 4)
  531. #define DMA_PACK_SIZE_MASK 0x30
  532. #define BCTL 0xFE2D
  533. #define RBBC0 0xFE2E
  534. #define RBBC1 0xFE2F
  535. #define RBDAT 0xFE30
  536. #define RBCTL 0xFE34
  537. #define U_AUTO_DMA_EN_MASK 0x20
  538. #define U_AUTO_DMA_DISABLE 0x00
  539. #define RB_FLUSH 0x80
  540. #define CFGADDR0 0xFE35
  541. #define CFGADDR1 0xFE36
  542. #define CFGDATA0 0xFE37
  543. #define CFGDATA1 0xFE38
  544. #define CFGDATA2 0xFE39
  545. #define CFGDATA3 0xFE3A
  546. #define CFGRWCTL 0xFE3B
  547. #define PHYRWCTL 0xFE3C
  548. #define PHYDATA0 0xFE3D
  549. #define PHYDATA1 0xFE3E
  550. #define PHYADDR 0xFE3F
  551. #define MSGRXDATA0 0xFE40
  552. #define MSGRXDATA1 0xFE41
  553. #define MSGRXDATA2 0xFE42
  554. #define MSGRXDATA3 0xFE43
  555. #define MSGTXDATA0 0xFE44
  556. #define MSGTXDATA1 0xFE45
  557. #define MSGTXDATA2 0xFE46
  558. #define MSGTXDATA3 0xFE47
  559. #define MSGTXCTL 0xFE48
  560. #define LTR_CTL 0xFE4A
  561. #define LTR_TX_EN_MASK BIT(7)
  562. #define LTR_TX_EN_1 BIT(7)
  563. #define LTR_TX_EN_0 0
  564. #define LTR_LATENCY_MODE_MASK BIT(6)
  565. #define LTR_LATENCY_MODE_HW 0
  566. #define LTR_LATENCY_MODE_SW BIT(6)
  567. #define OBFF_CFG 0xFE4C
  568. #define OBFF_EN_MASK 0x03
  569. #define OBFF_DISABLE 0x00
  570. #define CDRESUMECTL 0xFE52
  571. #define WAKE_SEL_CTL 0xFE54
  572. #define PCLK_CTL 0xFE55
  573. #define PCLK_MODE_SEL 0x20
  574. #define PME_FORCE_CTL 0xFE56
  575. #define ASPM_FORCE_CTL 0xFE57
  576. #define FORCE_ASPM_CTL0 0x10
  577. #define FORCE_ASPM_VAL_MASK 0x03
  578. #define FORCE_ASPM_L1_EN 0x02
  579. #define FORCE_ASPM_L0_EN 0x01
  580. #define FORCE_ASPM_NO_ASPM 0x00
  581. #define PM_CLK_FORCE_CTL 0xFE58
  582. #define CLK_PM_EN 0x01
  583. #define FUNC_FORCE_CTL 0xFE59
  584. #define FUNC_FORCE_UPME_XMT_DBG 0x02
  585. #define PERST_GLITCH_WIDTH 0xFE5C
  586. #define CHANGE_LINK_STATE 0xFE5B
  587. #define RESET_LOAD_REG 0xFE5E
  588. #define EFUSE_CONTENT 0xFE5F
  589. #define HOST_SLEEP_STATE 0xFE60
  590. #define HOST_ENTER_S1 1
  591. #define HOST_ENTER_S3 2
  592. #define SDIO_CFG 0xFE70
  593. #define PM_EVENT_DEBUG 0xFE71
  594. #define PME_DEBUG_0 0x08
  595. #define NFTS_TX_CTRL 0xFE72
  596. #define PWR_GATE_CTRL 0xFE75
  597. #define PWR_GATE_EN 0x01
  598. #define LDO3318_PWR_MASK 0x06
  599. #define LDO_ON 0x00
  600. #define LDO_SUSPEND 0x04
  601. #define LDO_OFF 0x06
  602. #define PWD_SUSPEND_EN 0xFE76
  603. #define LDO_PWR_SEL 0xFE78
  604. #define L1SUB_CONFIG1 0xFE8D
  605. #define AUX_CLK_ACTIVE_SEL_MASK 0x01
  606. #define MAC_CKSW_DONE 0x00
  607. #define L1SUB_CONFIG2 0xFE8E
  608. #define L1SUB_AUTO_CFG 0x02
  609. #define L1SUB_CONFIG3 0xFE8F
  610. #define L1OFF_MBIAS2_EN_5250 BIT(7)
  611. #define DUMMY_REG_RESET_0 0xFE90
  612. #define IC_VERSION_MASK 0x0F
  613. #define REG_VREF 0xFE97
  614. #define PWD_SUSPND_EN 0x10
  615. #define RTS5260_DMA_RST_CTL_0 0xFEBF
  616. #define RTS5260_DMA_RST 0x80
  617. #define RTS5260_ADMA3_RST 0x40
  618. #define AUTOLOAD_CFG_BASE 0xFF00
  619. #define RELINK_TIME_MASK 0x01
  620. #define PETXCFG 0xFF03
  621. #define FORCE_CLKREQ_DELINK_MASK BIT(7)
  622. #define FORCE_CLKREQ_LOW 0x80
  623. #define FORCE_CLKREQ_HIGH 0x00
  624. #define PM_CTRL1 0xFF44
  625. #define CD_RESUME_EN_MASK 0xF0
  626. #define PM_CTRL2 0xFF45
  627. #define PM_CTRL3 0xFF46
  628. #define SDIO_SEND_PME_EN 0x80
  629. #define FORCE_RC_MODE_ON 0x40
  630. #define FORCE_RX50_LINK_ON 0x20
  631. #define D3_DELINK_MODE_EN 0x10
  632. #define USE_PESRTB_CTL_DELINK 0x08
  633. #define DELAY_PIN_WAKE 0x04
  634. #define RESET_PIN_WAKE 0x02
  635. #define PM_WAKE_EN 0x01
  636. #define PM_CTRL4 0xFF47
  637. /* Memory mapping */
  638. #define SRAM_BASE 0xE600
  639. #define RBUF_BASE 0xF400
  640. #define PPBUF_BASE1 0xF800
  641. #define PPBUF_BASE2 0xFA00
  642. #define IMAGE_FLAG_ADDR0 0xCE80
  643. #define IMAGE_FLAG_ADDR1 0xCE81
  644. #define RREF_CFG 0xFF6C
  645. #define RREF_VBGSEL_MASK 0x38
  646. #define RREF_VBGSEL_1V25 0x28
  647. #define OOBS_CONFIG 0xFF6E
  648. #define OOBS_AUTOK_DIS 0x80
  649. #define OOBS_VAL_MASK 0x1F
  650. #define LDO_DV18_CFG 0xFF70
  651. #define LDO_DV18_SR_MASK 0xC0
  652. #define LDO_DV18_SR_DF 0x40
  653. #define DV331812_MASK 0x70
  654. #define DV331812_33 0x70
  655. #define DV331812_17 0x30
  656. #define LDO_CONFIG2 0xFF71
  657. #define LDO_D3318_MASK 0x07
  658. #define LDO_D3318_33V 0x07
  659. #define LDO_D3318_18V 0x02
  660. #define DV331812_VDD1 0x04
  661. #define DV331812_POWERON 0x08
  662. #define DV331812_POWEROFF 0x00
  663. #define LDO_VCC_CFG0 0xFF72
  664. #define LDO_VCC_LMTVTH_MASK 0x30
  665. #define LDO_VCC_LMTVTH_2A 0x10
  666. /*RTS5260*/
  667. #define RTS5260_DVCC_TUNE_MASK 0x70
  668. #define RTS5260_DVCC_33 0x70
  669. #define LDO_VCC_CFG1 0xFF73
  670. #define LDO_VCC_REF_TUNE_MASK 0x30
  671. #define LDO_VCC_REF_1V2 0x20
  672. #define LDO_VCC_TUNE_MASK 0x07
  673. #define LDO_VCC_1V8 0x04
  674. #define LDO_VCC_3V3 0x07
  675. #define LDO_VCC_LMT_EN 0x08
  676. /*RTS5260*/
  677. #define LDO_POW_SDVDD1_MASK 0x08
  678. #define LDO_POW_SDVDD1_ON 0x08
  679. #define LDO_POW_SDVDD1_OFF 0x00
  680. #define LDO_VIO_CFG 0xFF75
  681. #define LDO_VIO_SR_MASK 0xC0
  682. #define LDO_VIO_SR_DF 0x40
  683. #define LDO_VIO_REF_TUNE_MASK 0x30
  684. #define LDO_VIO_REF_1V2 0x20
  685. #define LDO_VIO_TUNE_MASK 0x07
  686. #define LDO_VIO_1V7 0x03
  687. #define LDO_VIO_1V8 0x04
  688. #define LDO_VIO_3V3 0x07
  689. #define LDO_DV12S_CFG 0xFF76
  690. #define LDO_REF12_TUNE_MASK 0x18
  691. #define LDO_REF12_TUNE_DF 0x10
  692. #define LDO_D12_TUNE_MASK 0x07
  693. #define LDO_D12_TUNE_DF 0x04
  694. #define LDO_AV12S_CFG 0xFF77
  695. #define LDO_AV12S_TUNE_MASK 0x07
  696. #define LDO_AV12S_TUNE_DF 0x04
  697. #define SD40_LDO_CTL1 0xFE7D
  698. #define SD40_VIO_TUNE_MASK 0x70
  699. #define SD40_VIO_TUNE_1V7 0x30
  700. #define SD_VIO_LDO_1V8 0x40
  701. #define SD_VIO_LDO_3V3 0x70
  702. #define RTS5260_AUTOLOAD_CFG4 0xFF7F
  703. #define RTS5260_MIMO_DISABLE 0x8A
  704. #define RTS5260_REG_GPIO_CTL0 0xFC1A
  705. #define RTS5260_REG_GPIO_MASK 0x01
  706. #define RTS5260_REG_GPIO_ON 0x01
  707. #define RTS5260_REG_GPIO_OFF 0x00
  708. #define PWR_GLOBAL_CTRL 0xF200
  709. #define PCIE_L1_2_EN 0x0C
  710. #define PCIE_L1_1_EN 0x0A
  711. #define PCIE_L1_0_EN 0x09
  712. #define PWR_FE_CTL 0xF201
  713. #define PCIE_L1_2_PD_FE_EN 0x0C
  714. #define PCIE_L1_1_PD_FE_EN 0x0A
  715. #define PCIE_L1_0_PD_FE_EN 0x09
  716. #define CFG_PCIE_APHY_OFF_0 0xF204
  717. #define CFG_PCIE_APHY_OFF_0_DEFAULT 0xBF
  718. #define CFG_PCIE_APHY_OFF_1 0xF205
  719. #define CFG_PCIE_APHY_OFF_1_DEFAULT 0xFF
  720. #define CFG_PCIE_APHY_OFF_2 0xF206
  721. #define CFG_PCIE_APHY_OFF_2_DEFAULT 0x01
  722. #define CFG_PCIE_APHY_OFF_3 0xF207
  723. #define CFG_PCIE_APHY_OFF_3_DEFAULT 0x00
  724. #define CFG_L1_0_PCIE_MAC_RET_VALUE 0xF20C
  725. #define CFG_L1_0_PCIE_DPHY_RET_VALUE 0xF20E
  726. #define CFG_L1_0_SYS_RET_VALUE 0xF210
  727. #define CFG_L1_0_CRC_MISC_RET_VALUE 0xF212
  728. #define CFG_L1_0_CRC_SD30_RET_VALUE 0xF214
  729. #define CFG_L1_0_CRC_SD40_RET_VALUE 0xF216
  730. #define CFG_LP_FPWM_VALUE 0xF219
  731. #define CFG_LP_FPWM_VALUE_DEFAULT 0x18
  732. #define PWC_CDR 0xF253
  733. #define PWC_CDR_DEFAULT 0x03
  734. #define CFG_L1_0_RET_VALUE_DEFAULT 0x1B
  735. #define CFG_L1_0_CRC_MISC_RET_VALUE_DEFAULT 0x0C
  736. /* OCPCTL */
  737. #define SD_DETECT_EN 0x08
  738. #define SD_OCP_INT_EN 0x04
  739. #define SD_OCP_INT_CLR 0x02
  740. #define SD_OC_CLR 0x01
  741. #define SDVIO_DETECT_EN (1 << 7)
  742. #define SDVIO_OCP_INT_EN (1 << 6)
  743. #define SDVIO_OCP_INT_CLR (1 << 5)
  744. #define SDVIO_OC_CLR (1 << 4)
  745. /* OCPSTAT */
  746. #define SD_OCP_DETECT 0x08
  747. #define SD_OC_NOW 0x04
  748. #define SD_OC_EVER 0x02
  749. #define SDVIO_OC_NOW (1 << 6)
  750. #define SDVIO_OC_EVER (1 << 5)
  751. #define REG_OCPCTL 0xFD6A
  752. #define REG_OCPSTAT 0xFD6E
  753. #define REG_OCPGLITCH 0xFD6C
  754. #define REG_OCPPARA1 0xFD6B
  755. #define REG_OCPPARA2 0xFD6D
  756. /* rts5260 DV3318 OCP-related registers */
  757. #define REG_DV3318_OCPCTL 0xFD89
  758. #define DV3318_OCP_TIME_MASK 0xF0
  759. #define DV3318_DETECT_EN 0x08
  760. #define DV3318_OCP_INT_EN 0x04
  761. #define DV3318_OCP_INT_CLR 0x02
  762. #define DV3318_OCP_CLR 0x01
  763. #define REG_DV3318_OCPSTAT 0xFD8A
  764. #define DV3318_OCP_GlITCH_TIME_MASK 0xF0
  765. #define DV3318_OCP_DETECT 0x08
  766. #define DV3318_OCP_NOW 0x04
  767. #define DV3318_OCP_EVER 0x02
  768. #define SD_OCP_GLITCH_MASK 0x0F
  769. /* OCPPARA1 */
  770. #define SDVIO_OCP_TIME_60 0x00
  771. #define SDVIO_OCP_TIME_100 0x10
  772. #define SDVIO_OCP_TIME_200 0x20
  773. #define SDVIO_OCP_TIME_400 0x30
  774. #define SDVIO_OCP_TIME_600 0x40
  775. #define SDVIO_OCP_TIME_800 0x50
  776. #define SDVIO_OCP_TIME_1100 0x60
  777. #define SDVIO_OCP_TIME_MASK 0x70
  778. #define SD_OCP_TIME_60 0x00
  779. #define SD_OCP_TIME_100 0x01
  780. #define SD_OCP_TIME_200 0x02
  781. #define SD_OCP_TIME_400 0x03
  782. #define SD_OCP_TIME_600 0x04
  783. #define SD_OCP_TIME_800 0x05
  784. #define SD_OCP_TIME_1100 0x06
  785. #define SD_OCP_TIME_MASK 0x07
  786. /* OCPPARA2 */
  787. #define SDVIO_OCP_THD_190 0x00
  788. #define SDVIO_OCP_THD_250 0x10
  789. #define SDVIO_OCP_THD_320 0x20
  790. #define SDVIO_OCP_THD_380 0x30
  791. #define SDVIO_OCP_THD_440 0x40
  792. #define SDVIO_OCP_THD_500 0x50
  793. #define SDVIO_OCP_THD_570 0x60
  794. #define SDVIO_OCP_THD_630 0x70
  795. #define SDVIO_OCP_THD_MASK 0x70
  796. #define SD_OCP_THD_450 0x00
  797. #define SD_OCP_THD_550 0x01
  798. #define SD_OCP_THD_650 0x02
  799. #define SD_OCP_THD_750 0x03
  800. #define SD_OCP_THD_850 0x04
  801. #define SD_OCP_THD_950 0x05
  802. #define SD_OCP_THD_1050 0x06
  803. #define SD_OCP_THD_1150 0x07
  804. #define SD_OCP_THD_MASK 0x07
  805. #define SDVIO_OCP_GLITCH_MASK 0xF0
  806. #define SDVIO_OCP_GLITCH_NONE 0x00
  807. #define SDVIO_OCP_GLITCH_50U 0x10
  808. #define SDVIO_OCP_GLITCH_100U 0x20
  809. #define SDVIO_OCP_GLITCH_200U 0x30
  810. #define SDVIO_OCP_GLITCH_600U 0x40
  811. #define SDVIO_OCP_GLITCH_800U 0x50
  812. #define SDVIO_OCP_GLITCH_1M 0x60
  813. #define SDVIO_OCP_GLITCH_2M 0x70
  814. #define SDVIO_OCP_GLITCH_3M 0x80
  815. #define SDVIO_OCP_GLITCH_4M 0x90
  816. #define SDVIO_OCP_GLIVCH_5M 0xA0
  817. #define SDVIO_OCP_GLITCH_6M 0xB0
  818. #define SDVIO_OCP_GLITCH_7M 0xC0
  819. #define SDVIO_OCP_GLITCH_8M 0xD0
  820. #define SDVIO_OCP_GLITCH_9M 0xE0
  821. #define SDVIO_OCP_GLITCH_10M 0xF0
  822. #define SD_OCP_GLITCH_MASK 0x0F
  823. #define SD_OCP_GLITCH_NONE 0x00
  824. #define SD_OCP_GLITCH_50U 0x01
  825. #define SD_OCP_GLITCH_100U 0x02
  826. #define SD_OCP_GLITCH_200U 0x03
  827. #define SD_OCP_GLITCH_600U 0x04
  828. #define SD_OCP_GLITCH_800U 0x05
  829. #define SD_OCP_GLITCH_1M 0x06
  830. #define SD_OCP_GLITCH_2M 0x07
  831. #define SD_OCP_GLITCH_3M 0x08
  832. #define SD_OCP_GLITCH_4M 0x09
  833. #define SD_OCP_GLIVCH_5M 0x0A
  834. #define SD_OCP_GLITCH_6M 0x0B
  835. #define SD_OCP_GLITCH_7M 0x0C
  836. #define SD_OCP_GLITCH_8M 0x0D
  837. #define SD_OCP_GLITCH_9M 0x0E
  838. #define SD_OCP_GLITCH_10M 0x0F
  839. /* Phy register */
  840. #define PHY_PCR 0x00
  841. #define PHY_PCR_FORCE_CODE 0xB000
  842. #define PHY_PCR_OOBS_CALI_50 0x0800
  843. #define PHY_PCR_OOBS_VCM_08 0x0200
  844. #define PHY_PCR_OOBS_SEN_90 0x0040
  845. #define PHY_PCR_RSSI_EN 0x0002
  846. #define PHY_PCR_RX10K 0x0001
  847. #define PHY_RCR0 0x01
  848. #define PHY_RCR1 0x02
  849. #define PHY_RCR1_ADP_TIME_4 0x0400
  850. #define PHY_RCR1_VCO_COARSE 0x001F
  851. #define PHY_RCR1_INIT_27S 0x0A1F
  852. #define PHY_SSCCR2 0x02
  853. #define PHY_SSCCR2_PLL_NCODE 0x0A00
  854. #define PHY_SSCCR2_TIME0 0x001C
  855. #define PHY_SSCCR2_TIME2_WIDTH 0x0003
  856. #define PHY_RCR2 0x03
  857. #define PHY_RCR2_EMPHASE_EN 0x8000
  858. #define PHY_RCR2_NADJR 0x4000
  859. #define PHY_RCR2_CDR_SR_2 0x0100
  860. #define PHY_RCR2_FREQSEL_12 0x0040
  861. #define PHY_RCR2_CDR_SC_12P 0x0010
  862. #define PHY_RCR2_CALIB_LATE 0x0002
  863. #define PHY_RCR2_INIT_27S 0xC152
  864. #define PHY_SSCCR3 0x03
  865. #define PHY_SSCCR3_STEP_IN 0x2740
  866. #define PHY_SSCCR3_CHECK_DELAY 0x0008
  867. #define _PHY_ANA03 0x03
  868. #define _PHY_ANA03_TIMER_MAX 0x2700
  869. #define _PHY_ANA03_OOBS_DEB_EN 0x0040
  870. #define _PHY_CMU_DEBUG_EN 0x0008
  871. #define PHY_RTCR 0x04
  872. #define PHY_RDR 0x05
  873. #define PHY_RDR_RXDSEL_1_9 0x4000
  874. #define PHY_SSC_AUTO_PWD 0x0600
  875. #define PHY_TCR0 0x06
  876. #define PHY_TCR1 0x07
  877. #define PHY_TUNE 0x08
  878. #define PHY_TUNE_TUNEREF_1_0 0x4000
  879. #define PHY_TUNE_VBGSEL_1252 0x0C00
  880. #define PHY_TUNE_SDBUS_33 0x0200
  881. #define PHY_TUNE_TUNED18 0x01C0
  882. #define PHY_TUNE_TUNED12 0X0020
  883. #define PHY_TUNE_TUNEA12 0x0004
  884. #define PHY_TUNE_VOLTAGE_MASK 0xFC3F
  885. #define PHY_TUNE_VOLTAGE_3V3 0x03C0
  886. #define PHY_TUNE_D18_1V8 0x0100
  887. #define PHY_TUNE_D18_1V7 0x0080
  888. #define PHY_ANA08 0x08
  889. #define PHY_ANA08_RX_EQ_DCGAIN 0x5000
  890. #define PHY_ANA08_SEL_RX_EN 0x0400
  891. #define PHY_ANA08_RX_EQ_VAL 0x03C0
  892. #define PHY_ANA08_SCP 0x0020
  893. #define PHY_ANA08_SEL_IPI 0x0004
  894. #define PHY_IMR 0x09
  895. #define PHY_BPCR 0x0A
  896. #define PHY_BPCR_IBRXSEL 0x0400
  897. #define PHY_BPCR_IBTXSEL 0x0100
  898. #define PHY_BPCR_IB_FILTER 0x0080
  899. #define PHY_BPCR_CMIRROR_EN 0x0040
  900. #define PHY_BIST 0x0B
  901. #define PHY_RAW_L 0x0C
  902. #define PHY_RAW_H 0x0D
  903. #define PHY_RAW_DATA 0x0E
  904. #define PHY_HOST_CLK_CTRL 0x0F
  905. #define PHY_DMR 0x10
  906. #define PHY_BACR 0x11
  907. #define PHY_BACR_BASIC_MASK 0xFFF3
  908. #define PHY_IER 0x12
  909. #define PHY_BCSR 0x13
  910. #define PHY_BPR 0x14
  911. #define PHY_BPNR2 0x15
  912. #define PHY_BPNR 0x16
  913. #define PHY_BRNR2 0x17
  914. #define PHY_BENR 0x18
  915. #define PHY_REV 0x19
  916. #define PHY_REV_RESV 0xE000
  917. #define PHY_REV_RXIDLE_LATCHED 0x1000
  918. #define PHY_REV_P1_EN 0x0800
  919. #define PHY_REV_RXIDLE_EN 0x0400
  920. #define PHY_REV_CLKREQ_TX_EN 0x0200
  921. #define PHY_REV_CLKREQ_RX_EN 0x0100
  922. #define PHY_REV_CLKREQ_DT_1_0 0x0040
  923. #define PHY_REV_STOP_CLKRD 0x0020
  924. #define PHY_REV_RX_PWST 0x0008
  925. #define PHY_REV_STOP_CLKWR 0x0004
  926. #define _PHY_REV0 0x19
  927. #define _PHY_REV0_FILTER_OUT 0x3800
  928. #define _PHY_REV0_CDR_BYPASS_PFD 0x0100
  929. #define _PHY_REV0_CDR_RX_IDLE_BYPASS 0x0002
  930. #define PHY_FLD0 0x1A
  931. #define PHY_ANA1A 0x1A
  932. #define PHY_ANA1A_TXR_LOOPBACK 0x2000
  933. #define PHY_ANA1A_RXT_BIST 0x0500
  934. #define PHY_ANA1A_TXR_BIST 0x0040
  935. #define PHY_ANA1A_REV 0x0006
  936. #define PHY_FLD0_INIT_27S 0x2546
  937. #define PHY_FLD1 0x1B
  938. #define PHY_FLD2 0x1C
  939. #define PHY_FLD3 0x1D
  940. #define PHY_FLD3_TIMER_4 0x0800
  941. #define PHY_FLD3_TIMER_6 0x0020
  942. #define PHY_FLD3_RXDELINK 0x0004
  943. #define PHY_FLD3_INIT_27S 0x0004
  944. #define PHY_ANA1D 0x1D
  945. #define PHY_ANA1D_DEBUG_ADDR 0x0004
  946. #define _PHY_FLD0 0x1D
  947. #define _PHY_FLD0_CLK_REQ_20C 0x8000
  948. #define _PHY_FLD0_RX_IDLE_EN 0x1000
  949. #define _PHY_FLD0_BIT_ERR_RSTN 0x0800
  950. #define _PHY_FLD0_BER_COUNT 0x01E0
  951. #define _PHY_FLD0_BER_TIMER 0x001E
  952. #define _PHY_FLD0_CHECK_EN 0x0001
  953. #define PHY_FLD4 0x1E
  954. #define PHY_FLD4_FLDEN_SEL 0x4000
  955. #define PHY_FLD4_REQ_REF 0x2000
  956. #define PHY_FLD4_RXAMP_OFF 0x1000
  957. #define PHY_FLD4_REQ_ADDA 0x0800
  958. #define PHY_FLD4_BER_COUNT 0x00E0
  959. #define PHY_FLD4_BER_TIMER 0x000A
  960. #define PHY_FLD4_BER_CHK_EN 0x0001
  961. #define PHY_FLD4_INIT_27S 0x5C7F
  962. #define PHY_DIG1E 0x1E
  963. #define PHY_DIG1E_REV 0x4000
  964. #define PHY_DIG1E_D0_X_D1 0x1000
  965. #define PHY_DIG1E_RX_ON_HOST 0x0800
  966. #define PHY_DIG1E_RCLK_REF_HOST 0x0400
  967. #define PHY_DIG1E_RCLK_TX_EN_KEEP 0x0040
  968. #define PHY_DIG1E_RCLK_TX_TERM_KEEP 0x0020
  969. #define PHY_DIG1E_RCLK_RX_EIDLE_ON 0x0010
  970. #define PHY_DIG1E_TX_TERM_KEEP 0x0008
  971. #define PHY_DIG1E_RX_TERM_KEEP 0x0004
  972. #define PHY_DIG1E_TX_EN_KEEP 0x0002
  973. #define PHY_DIG1E_RX_EN_KEEP 0x0001
  974. #define PHY_DUM_REG 0x1F
  975. #define PCR_ASPM_SETTING_REG1 0x160
  976. #define PCR_ASPM_SETTING_REG2 0x168
  977. #define PCR_ASPM_SETTING_5260 0x178
  978. #define PCR_SETTING_REG1 0x724
  979. #define PCR_SETTING_REG2 0x814
  980. #define PCR_SETTING_REG3 0x747
  981. #define rtsx_pci_init_cmd(pcr) ((pcr)->ci = 0)
  982. #define RTS5227_DEVICE_ID 0x5227
  983. #define RTS_MAX_TIMES_FREQ_REDUCTION 8
  984. struct rtsx_pcr;
  985. struct pcr_handle {
  986. struct rtsx_pcr *pcr;
  987. };
  988. struct pcr_ops {
  989. int (*write_phy)(struct rtsx_pcr *pcr, u8 addr, u16 val);
  990. int (*read_phy)(struct rtsx_pcr *pcr, u8 addr, u16 *val);
  991. int (*extra_init_hw)(struct rtsx_pcr *pcr);
  992. int (*optimize_phy)(struct rtsx_pcr *pcr);
  993. int (*turn_on_led)(struct rtsx_pcr *pcr);
  994. int (*turn_off_led)(struct rtsx_pcr *pcr);
  995. int (*enable_auto_blink)(struct rtsx_pcr *pcr);
  996. int (*disable_auto_blink)(struct rtsx_pcr *pcr);
  997. int (*card_power_on)(struct rtsx_pcr *pcr, int card);
  998. int (*card_power_off)(struct rtsx_pcr *pcr, int card);
  999. int (*switch_output_voltage)(struct rtsx_pcr *pcr,
  1000. u8 voltage);
  1001. unsigned int (*cd_deglitch)(struct rtsx_pcr *pcr);
  1002. int (*conv_clk_and_div_n)(int clk, int dir);
  1003. void (*fetch_vendor_settings)(struct rtsx_pcr *pcr);
  1004. void (*force_power_down)(struct rtsx_pcr *pcr, u8 pm_state);
  1005. void (*stop_cmd)(struct rtsx_pcr *pcr);
  1006. void (*set_aspm)(struct rtsx_pcr *pcr, bool enable);
  1007. int (*set_ltr_latency)(struct rtsx_pcr *pcr, u32 latency);
  1008. int (*set_l1off_sub)(struct rtsx_pcr *pcr, u8 val);
  1009. void (*set_l1off_cfg_sub_d0)(struct rtsx_pcr *pcr, int active);
  1010. void (*full_on)(struct rtsx_pcr *pcr);
  1011. void (*power_saving)(struct rtsx_pcr *pcr);
  1012. void (*enable_ocp)(struct rtsx_pcr *pcr);
  1013. void (*disable_ocp)(struct rtsx_pcr *pcr);
  1014. void (*init_ocp)(struct rtsx_pcr *pcr);
  1015. void (*process_ocp)(struct rtsx_pcr *pcr);
  1016. int (*get_ocpstat)(struct rtsx_pcr *pcr, u8 *val);
  1017. void (*clear_ocpstat)(struct rtsx_pcr *pcr);
  1018. };
  1019. enum PDEV_STAT {PDEV_STAT_IDLE, PDEV_STAT_RUN};
  1020. #define ASPM_L1_1_EN_MASK BIT(3)
  1021. #define ASPM_L1_2_EN_MASK BIT(2)
  1022. #define PM_L1_1_EN_MASK BIT(1)
  1023. #define PM_L1_2_EN_MASK BIT(0)
  1024. #define ASPM_L1_1_EN BIT(0)
  1025. #define ASPM_L1_2_EN BIT(1)
  1026. #define PM_L1_1_EN BIT(2)
  1027. #define PM_L1_2_EN BIT(3)
  1028. #define LTR_L1SS_PWR_GATE_EN BIT(4)
  1029. #define L1_SNOOZE_TEST_EN BIT(5)
  1030. #define LTR_L1SS_PWR_GATE_CHECK_CARD_EN BIT(6)
  1031. enum dev_aspm_mode {
  1032. DEV_ASPM_DISABLE = 0,
  1033. DEV_ASPM_DYNAMIC,
  1034. DEV_ASPM_BACKDOOR,
  1035. DEV_ASPM_STATIC,
  1036. };
  1037. /*
  1038. * struct rtsx_cr_option - card reader option
  1039. * @dev_flags: device flags
  1040. * @force_clkreq_0: force clock request
  1041. * @ltr_en: enable ltr mode flag
  1042. * @ltr_enabled: ltr mode in configure space flag
  1043. * @ltr_active: ltr mode status
  1044. * @ltr_active_latency: ltr mode active latency
  1045. * @ltr_idle_latency: ltr mode idle latency
  1046. * @ltr_l1off_latency: ltr mode l1off latency
  1047. * @dev_aspm_mode: device aspm mode
  1048. * @l1_snooze_delay: l1 snooze delay
  1049. * @ltr_l1off_sspwrgate: ltr l1off sspwrgate
  1050. * @ltr_l1off_snooze_sspwrgate: ltr l1off snooze sspwrgate
  1051. * @ocp_en: enable ocp flag
  1052. * @sd_400mA_ocp_thd: 400mA ocp thd
  1053. * @sd_800mA_ocp_thd: 800mA ocp thd
  1054. */
  1055. struct rtsx_cr_option {
  1056. u32 dev_flags;
  1057. bool force_clkreq_0;
  1058. bool ltr_en;
  1059. bool ltr_enabled;
  1060. bool ltr_active;
  1061. u32 ltr_active_latency;
  1062. u32 ltr_idle_latency;
  1063. u32 ltr_l1off_latency;
  1064. enum dev_aspm_mode dev_aspm_mode;
  1065. u32 l1_snooze_delay;
  1066. u8 ltr_l1off_sspwrgate;
  1067. u8 ltr_l1off_snooze_sspwrgate;
  1068. bool ocp_en;
  1069. u8 sd_400mA_ocp_thd;
  1070. u8 sd_800mA_ocp_thd;
  1071. };
  1072. /*
  1073. * struct rtsx_hw_param - card reader hardware param
  1074. * @interrupt_en: indicate which interrutp enable
  1075. * @ocp_glitch: ocp glitch time
  1076. */
  1077. struct rtsx_hw_param {
  1078. u32 interrupt_en;
  1079. u8 ocp_glitch;
  1080. };
  1081. #define rtsx_set_dev_flag(cr, flag) \
  1082. ((cr)->option.dev_flags |= (flag))
  1083. #define rtsx_clear_dev_flag(cr, flag) \
  1084. ((cr)->option.dev_flags &= ~(flag))
  1085. #define rtsx_check_dev_flag(cr, flag) \
  1086. ((cr)->option.dev_flags & (flag))
  1087. struct rtsx_pcr {
  1088. struct pci_dev *pci;
  1089. unsigned int id;
  1090. int pcie_cap;
  1091. struct rtsx_cr_option option;
  1092. struct rtsx_hw_param hw_param;
  1093. /* pci resources */
  1094. unsigned long addr;
  1095. void __iomem *remap_addr;
  1096. int irq;
  1097. /* host reserved buffer */
  1098. void *rtsx_resv_buf;
  1099. dma_addr_t rtsx_resv_buf_addr;
  1100. void *host_cmds_ptr;
  1101. dma_addr_t host_cmds_addr;
  1102. int ci;
  1103. void *host_sg_tbl_ptr;
  1104. dma_addr_t host_sg_tbl_addr;
  1105. int sgi;
  1106. u32 bier;
  1107. char trans_result;
  1108. unsigned int card_inserted;
  1109. unsigned int card_removed;
  1110. unsigned int card_exist;
  1111. struct delayed_work carddet_work;
  1112. struct delayed_work idle_work;
  1113. spinlock_t lock;
  1114. struct mutex pcr_mutex;
  1115. struct completion *done;
  1116. struct completion *finish_me;
  1117. unsigned int cur_clock;
  1118. bool remove_pci;
  1119. bool msi_en;
  1120. #define EXTRA_CAPS_SD_SDR50 (1 << 0)
  1121. #define EXTRA_CAPS_SD_SDR104 (1 << 1)
  1122. #define EXTRA_CAPS_SD_DDR50 (1 << 2)
  1123. #define EXTRA_CAPS_MMC_HSDDR (1 << 3)
  1124. #define EXTRA_CAPS_MMC_HS200 (1 << 4)
  1125. #define EXTRA_CAPS_MMC_8BIT (1 << 5)
  1126. u32 extra_caps;
  1127. #define IC_VER_A 0
  1128. #define IC_VER_B 1
  1129. #define IC_VER_C 2
  1130. #define IC_VER_D 3
  1131. u8 ic_version;
  1132. u8 sd30_drive_sel_1v8;
  1133. u8 sd30_drive_sel_3v3;
  1134. u8 card_drive_sel;
  1135. #define ASPM_L1_EN 0x02
  1136. u8 aspm_en;
  1137. bool aspm_enabled;
  1138. #define PCR_MS_PMOS (1 << 0)
  1139. #define PCR_REVERSE_SOCKET (1 << 1)
  1140. u32 flags;
  1141. u32 tx_initial_phase;
  1142. u32 rx_initial_phase;
  1143. const u32 *sd_pull_ctl_enable_tbl;
  1144. const u32 *sd_pull_ctl_disable_tbl;
  1145. const u32 *ms_pull_ctl_enable_tbl;
  1146. const u32 *ms_pull_ctl_disable_tbl;
  1147. const struct pcr_ops *ops;
  1148. enum PDEV_STAT state;
  1149. u16 reg_pm_ctrl3;
  1150. int num_slots;
  1151. struct rtsx_slot *slots;
  1152. u8 dma_error_count;
  1153. u8 ocp_stat;
  1154. u8 ocp_stat2;
  1155. };
  1156. #define PID_524A 0x524A
  1157. #define PID_5249 0x5249
  1158. #define PID_5250 0x5250
  1159. #define PID_525A 0x525A
  1160. #define PID_5260 0x5260
  1161. #define CHK_PCI_PID(pcr, pid) ((pcr)->pci->device == (pid))
  1162. #define PCI_VID(pcr) ((pcr)->pci->vendor)
  1163. #define PCI_PID(pcr) ((pcr)->pci->device)
  1164. #define is_version(pcr, pid, ver) \
  1165. (CHK_PCI_PID(pcr, pid) && (pcr)->ic_version == (ver))
  1166. #define pcr_dbg(pcr, fmt, arg...) \
  1167. dev_dbg(&(pcr)->pci->dev, fmt, ##arg)
  1168. #define SDR104_PHASE(val) ((val) & 0xFF)
  1169. #define SDR50_PHASE(val) (((val) >> 8) & 0xFF)
  1170. #define DDR50_PHASE(val) (((val) >> 16) & 0xFF)
  1171. #define SDR104_TX_PHASE(pcr) SDR104_PHASE((pcr)->tx_initial_phase)
  1172. #define SDR50_TX_PHASE(pcr) SDR50_PHASE((pcr)->tx_initial_phase)
  1173. #define DDR50_TX_PHASE(pcr) DDR50_PHASE((pcr)->tx_initial_phase)
  1174. #define SDR104_RX_PHASE(pcr) SDR104_PHASE((pcr)->rx_initial_phase)
  1175. #define SDR50_RX_PHASE(pcr) SDR50_PHASE((pcr)->rx_initial_phase)
  1176. #define DDR50_RX_PHASE(pcr) DDR50_PHASE((pcr)->rx_initial_phase)
  1177. #define SET_CLOCK_PHASE(sdr104, sdr50, ddr50) \
  1178. (((ddr50) << 16) | ((sdr50) << 8) | (sdr104))
  1179. void rtsx_pci_start_run(struct rtsx_pcr *pcr);
  1180. int rtsx_pci_write_register(struct rtsx_pcr *pcr, u16 addr, u8 mask, u8 data);
  1181. int rtsx_pci_read_register(struct rtsx_pcr *pcr, u16 addr, u8 *data);
  1182. int rtsx_pci_write_phy_register(struct rtsx_pcr *pcr, u8 addr, u16 val);
  1183. int rtsx_pci_read_phy_register(struct rtsx_pcr *pcr, u8 addr, u16 *val);
  1184. void rtsx_pci_stop_cmd(struct rtsx_pcr *pcr);
  1185. void rtsx_pci_add_cmd(struct rtsx_pcr *pcr,
  1186. u8 cmd_type, u16 reg_addr, u8 mask, u8 data);
  1187. void rtsx_pci_send_cmd_no_wait(struct rtsx_pcr *pcr);
  1188. int rtsx_pci_send_cmd(struct rtsx_pcr *pcr, int timeout);
  1189. int rtsx_pci_transfer_data(struct rtsx_pcr *pcr, struct scatterlist *sglist,
  1190. int num_sg, bool read, int timeout);
  1191. int rtsx_pci_dma_map_sg(struct rtsx_pcr *pcr, struct scatterlist *sglist,
  1192. int num_sg, bool read);
  1193. void rtsx_pci_dma_unmap_sg(struct rtsx_pcr *pcr, struct scatterlist *sglist,
  1194. int num_sg, bool read);
  1195. int rtsx_pci_dma_transfer(struct rtsx_pcr *pcr, struct scatterlist *sglist,
  1196. int count, bool read, int timeout);
  1197. int rtsx_pci_read_ppbuf(struct rtsx_pcr *pcr, u8 *buf, int buf_len);
  1198. int rtsx_pci_write_ppbuf(struct rtsx_pcr *pcr, u8 *buf, int buf_len);
  1199. int rtsx_pci_card_pull_ctl_enable(struct rtsx_pcr *pcr, int card);
  1200. int rtsx_pci_card_pull_ctl_disable(struct rtsx_pcr *pcr, int card);
  1201. int rtsx_pci_switch_clock(struct rtsx_pcr *pcr, unsigned int card_clock,
  1202. u8 ssc_depth, bool initial_mode, bool double_clk, bool vpclk);
  1203. int rtsx_pci_card_power_on(struct rtsx_pcr *pcr, int card);
  1204. int rtsx_pci_card_power_off(struct rtsx_pcr *pcr, int card);
  1205. int rtsx_pci_card_exclusive_check(struct rtsx_pcr *pcr, int card);
  1206. int rtsx_pci_switch_output_voltage(struct rtsx_pcr *pcr, u8 voltage);
  1207. unsigned int rtsx_pci_card_exist(struct rtsx_pcr *pcr);
  1208. void rtsx_pci_complete_unfinished_transfer(struct rtsx_pcr *pcr);
  1209. static inline u8 *rtsx_pci_get_cmd_data(struct rtsx_pcr *pcr)
  1210. {
  1211. return (u8 *)(pcr->host_cmds_ptr);
  1212. }
  1213. static inline int rtsx_pci_update_cfg_byte(struct rtsx_pcr *pcr, int addr,
  1214. u8 mask, u8 append)
  1215. {
  1216. int err;
  1217. u8 val;
  1218. err = pci_read_config_byte(pcr->pci, addr, &val);
  1219. if (err < 0)
  1220. return err;
  1221. return pci_write_config_byte(pcr->pci, addr, (val & mask) | append);
  1222. }
  1223. static inline void rtsx_pci_write_be32(struct rtsx_pcr *pcr, u16 reg, u32 val)
  1224. {
  1225. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, reg, 0xFF, val >> 24);
  1226. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, reg + 1, 0xFF, val >> 16);
  1227. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, reg + 2, 0xFF, val >> 8);
  1228. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, reg + 3, 0xFF, val);
  1229. }
  1230. static inline int rtsx_pci_update_phy(struct rtsx_pcr *pcr, u8 addr,
  1231. u16 mask, u16 append)
  1232. {
  1233. int err;
  1234. u16 val;
  1235. err = rtsx_pci_read_phy_register(pcr, addr, &val);
  1236. if (err < 0)
  1237. return err;
  1238. return rtsx_pci_write_phy_register(pcr, addr, (val & mask) | append);
  1239. }
  1240. #endif