sdhci.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * linux/drivers/mmc/host/sdhci.h - Secure Digital Host Controller Interface driver
  4. *
  5. * Header file for Host Controller registers and I/O accessors.
  6. *
  7. * Copyright (C) 2005-2008 Pierre Ossman, All Rights Reserved.
  8. */
  9. #ifndef __SDHCI_HW_H
  10. #define __SDHCI_HW_H
  11. #include <linux/bits.h>
  12. #include <linux/scatterlist.h>
  13. #include <linux/compiler.h>
  14. #include <linux/types.h>
  15. #include <linux/io.h>
  16. #include <linux/leds.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/mmc/host.h>
  19. /*
  20. * Controller registers
  21. */
  22. #define SDHCI_DMA_ADDRESS 0x00
  23. #define SDHCI_ARGUMENT2 SDHCI_DMA_ADDRESS
  24. #define SDHCI_32BIT_BLK_CNT SDHCI_DMA_ADDRESS
  25. #define SDHCI_BLOCK_SIZE 0x04
  26. #define SDHCI_MAKE_BLKSZ(dma, blksz) (((dma & 0x7) << 12) | (blksz & 0xFFF))
  27. #define SDHCI_BLOCK_COUNT 0x06
  28. #define SDHCI_ARGUMENT 0x08
  29. #define SDHCI_TRANSFER_MODE 0x0C
  30. #define SDHCI_TRNS_DMA 0x01
  31. #define SDHCI_TRNS_BLK_CNT_EN 0x02
  32. #define SDHCI_TRNS_AUTO_CMD12 0x04
  33. #define SDHCI_TRNS_AUTO_CMD23 0x08
  34. #define SDHCI_TRNS_AUTO_SEL 0x0C
  35. #define SDHCI_TRNS_READ 0x10
  36. #define SDHCI_TRNS_MULTI 0x20
  37. /*
  38. * Defined in Host Version 4.0.
  39. */
  40. #define SDHCI_TRNS_RES_TYPE 0x40
  41. #define SDHCI_TRNS_RES_ERR_CHECK 0x80
  42. #define SDHCI_TRNS_RES_INT_DIS 0x0100
  43. #define SDHCI_COMMAND 0x0E
  44. #define SDHCI_CMD_RESP_MASK 0x03
  45. /*
  46. * Host Version 4.10 adds this bit to distinguish a main command or
  47. * sub command.
  48. * For example with SDIO, CMD52 (sub command) issued during CMD53 (main command).
  49. */
  50. #define SDHCI_CMD_SUB_CMD 0x04
  51. #define SDHCI_CMD_CRC 0x08
  52. #define SDHCI_CMD_INDEX 0x10
  53. #define SDHCI_CMD_DATA 0x20
  54. #define SDHCI_CMD_ABORTCMD 0xC0
  55. #define SDHCI_CMD_RESP_NONE 0x00
  56. #define SDHCI_CMD_RESP_LONG 0x01
  57. #define SDHCI_CMD_RESP_SHORT 0x02
  58. #define SDHCI_CMD_RESP_SHORT_BUSY 0x03
  59. #define SDHCI_MAKE_CMD(c, f) (((c & 0xff) << 8) | (f & 0xff))
  60. #define SDHCI_GET_CMD(c) ((c>>8) & 0x3f)
  61. #define SDHCI_RESPONSE 0x10
  62. #define SDHCI_BUFFER 0x20
  63. #define SDHCI_PRESENT_STATE 0x24
  64. #define SDHCI_CMD_INHIBIT 0x00000001
  65. #define SDHCI_DATA_INHIBIT 0x00000002
  66. #define SDHCI_DAT_4_TO_7_LVL_MASK 0x000000F0
  67. #define SDHCI_DOING_WRITE 0x00000100
  68. #define SDHCI_DOING_READ 0x00000200
  69. #define SDHCI_SPACE_AVAILABLE 0x00000400
  70. #define SDHCI_DATA_AVAILABLE 0x00000800
  71. #define SDHCI_CARD_PRESENT 0x00010000
  72. #define SDHCI_CARD_PRES_SHIFT 16
  73. #define SDHCI_CD_STABLE 0x00020000
  74. #define SDHCI_CD_LVL 0x00040000
  75. #define SDHCI_CD_LVL_SHIFT 18
  76. #define SDHCI_WRITE_PROTECT 0x00080000
  77. #define SDHCI_DATA_LVL_MASK 0x00F00000
  78. #define SDHCI_DATA_LVL_SHIFT 20
  79. #define SDHCI_DATA_0_LVL_MASK 0x00100000
  80. #define SDHCI_CMD_LVL 0x01000000
  81. /* Host Version 4.10 */
  82. #define SDHCI_HOST_REGULATOR_STABLE 0x02000000
  83. #define SDHCI_CMD_NOT_ISSUED_ERR 0x08000000
  84. #define SDHCI_SUB_CMD_STATUS 0x10000000
  85. #define SDHCI_UHS2_IN_DORMANT_STATE 0x20000000
  86. #define SDHCI_UHS2_LANE_SYNC 0x40000000
  87. #define SDHCI_UHS2_IF_DETECT 0x80000000
  88. #define SDHCI_HOST_CONTROL 0x28
  89. #define SDHCI_CTRL_LED 0x01
  90. #define SDHCI_CTRL_4BITBUS 0x02
  91. #define SDHCI_CTRL_HISPD 0x04
  92. #define SDHCI_CTRL_DMA_MASK 0x18
  93. #define SDHCI_CTRL_SDMA 0x00
  94. #define SDHCI_CTRL_ADMA1 0x08
  95. #define SDHCI_CTRL_ADMA32 0x10
  96. #define SDHCI_CTRL_ADMA64 0x18
  97. #define SDHCI_CTRL_ADMA3 0x18
  98. #define SDHCI_CTRL_8BITBUS 0x20
  99. #define SDHCI_CTRL_CDTEST_INS 0x40
  100. #define SDHCI_CTRL_CDTEST_EN 0x80
  101. #define SDHCI_POWER_CONTROL 0x29
  102. #define SDHCI_POWER_ON 0x01
  103. #define SDHCI_POWER_180 0x0A
  104. #define SDHCI_POWER_300 0x0C
  105. #define SDHCI_POWER_330 0x0E
  106. /*
  107. * VDD2 - UHS2 or PCIe/NVMe
  108. * VDD2 power on/off and voltage select
  109. */
  110. #define SDHCI_VDD2_POWER_ON 0x10
  111. #define SDHCI_VDD2_POWER_120 0x80
  112. #define SDHCI_VDD2_POWER_180 0xA0
  113. #define SDHCI_BLOCK_GAP_CONTROL 0x2A
  114. #define SDHCI_WAKE_UP_CONTROL 0x2B
  115. #define SDHCI_WAKE_ON_INT 0x01
  116. #define SDHCI_WAKE_ON_INSERT 0x02
  117. #define SDHCI_WAKE_ON_REMOVE 0x04
  118. #define SDHCI_CLOCK_CONTROL 0x2C
  119. #define SDHCI_DIVIDER_SHIFT 8
  120. #define SDHCI_DIVIDER_HI_SHIFT 6
  121. #define SDHCI_DIV_MASK 0xFF
  122. #define SDHCI_DIV_MASK_LEN 8
  123. #define SDHCI_DIV_HI_MASK 0x300
  124. #define SDHCI_PROG_CLOCK_MODE 0x0020
  125. #define SDHCI_CLOCK_CARD_EN 0x0004
  126. #define SDHCI_CLOCK_PLL_EN 0x0008
  127. #define SDHCI_CLOCK_INT_STABLE 0x0002
  128. #define SDHCI_CLOCK_INT_EN 0x0001
  129. #define SDHCI_TIMEOUT_CONTROL 0x2E
  130. #define SDHCI_SOFTWARE_RESET 0x2F
  131. #define SDHCI_RESET_ALL 0x01
  132. #define SDHCI_RESET_CMD 0x02
  133. #define SDHCI_RESET_DATA 0x04
  134. #define SDHCI_INT_STATUS 0x30
  135. #define SDHCI_INT_ENABLE 0x34
  136. #define SDHCI_SIGNAL_ENABLE 0x38
  137. #define SDHCI_INT_RESPONSE 0x00000001
  138. #define SDHCI_INT_DATA_END 0x00000002
  139. #define SDHCI_INT_BLK_GAP 0x00000004
  140. #define SDHCI_INT_DMA_END 0x00000008
  141. #define SDHCI_INT_SPACE_AVAIL 0x00000010
  142. #define SDHCI_INT_DATA_AVAIL 0x00000020
  143. #define SDHCI_INT_CARD_INSERT 0x00000040
  144. #define SDHCI_INT_CARD_REMOVE 0x00000080
  145. #define SDHCI_INT_CARD_INT 0x00000100
  146. #define SDHCI_INT_RETUNE 0x00001000
  147. /* Host Version 4.10 */
  148. #define SDHCI_INT_FX_EVENT 0x00002000
  149. #define SDHCI_INT_CQE 0x00004000
  150. #define SDHCI_INT_ERROR 0x00008000
  151. #define SDHCI_INT_TIMEOUT 0x00010000
  152. #define SDHCI_INT_CRC 0x00020000
  153. #define SDHCI_INT_END_BIT 0x00040000
  154. #define SDHCI_INT_INDEX 0x00080000
  155. #define SDHCI_INT_DATA_TIMEOUT 0x00100000
  156. #define SDHCI_INT_DATA_CRC 0x00200000
  157. #define SDHCI_INT_DATA_END_BIT 0x00400000
  158. #define SDHCI_INT_BUS_POWER 0x00800000
  159. #define SDHCI_INT_AUTO_CMD_ERR 0x01000000
  160. #define SDHCI_INT_ADMA_ERROR 0x02000000
  161. #define SDHCI_INT_TUNING_ERROR 0x04000000
  162. /* Host Version 4.0 */
  163. #define SDHCI_INT_RESP_ERR 0x08000000
  164. #define SDHCI_INT_NORMAL_MASK 0x00007FFF
  165. #define SDHCI_INT_ERROR_MASK 0xFFFF8000
  166. #define SDHCI_INT_CMD_MASK (SDHCI_INT_RESPONSE | SDHCI_INT_TIMEOUT | \
  167. SDHCI_INT_CRC | SDHCI_INT_END_BIT | SDHCI_INT_INDEX | \
  168. SDHCI_INT_AUTO_CMD_ERR)
  169. #define SDHCI_INT_DATA_MASK (SDHCI_INT_DATA_END | SDHCI_INT_DMA_END | \
  170. SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL | \
  171. SDHCI_INT_DATA_TIMEOUT | SDHCI_INT_DATA_CRC | \
  172. SDHCI_INT_DATA_END_BIT | SDHCI_INT_ADMA_ERROR | \
  173. SDHCI_INT_BLK_GAP | SDHCI_INT_TUNING_ERROR)
  174. #define SDHCI_INT_ALL_MASK ((unsigned int)-1)
  175. #define SDHCI_CQE_INT_ERR_MASK ( \
  176. SDHCI_INT_ADMA_ERROR | SDHCI_INT_BUS_POWER | SDHCI_INT_DATA_END_BIT | \
  177. SDHCI_INT_DATA_CRC | SDHCI_INT_DATA_TIMEOUT | SDHCI_INT_INDEX | \
  178. SDHCI_INT_END_BIT | SDHCI_INT_CRC | SDHCI_INT_TIMEOUT)
  179. #define SDHCI_CQE_INT_MASK (SDHCI_CQE_INT_ERR_MASK | SDHCI_INT_CQE)
  180. #define SDHCI_AUTO_CMD_STATUS 0x3C
  181. #define SDHCI_AUTO_CMD_TIMEOUT 0x00000002
  182. #define SDHCI_AUTO_CMD_CRC 0x00000004
  183. #define SDHCI_AUTO_CMD_END_BIT 0x00000008
  184. #define SDHCI_AUTO_CMD_INDEX 0x00000010
  185. /* Host Version 4.10 */
  186. #define SDHCI_AUTO_CMD_RESP_ERR 0x0020
  187. #define SDHCI_HOST_CONTROL2 0x3E
  188. #define SDHCI_CTRL_UHS_MASK 0x0007
  189. #define SDHCI_CTRL_UHS_SDR12 0x0000
  190. #define SDHCI_CTRL_UHS_SDR25 0x0001
  191. #define SDHCI_CTRL_UHS_SDR50 0x0002
  192. #define SDHCI_CTRL_UHS_SDR104 0x0003
  193. #define SDHCI_CTRL_UHS_DDR50 0x0004
  194. #define SDHCI_CTRL_HS400 0x0005 /* Non-standard */
  195. #define SDHCI_CTRL_UHS2 0x0007
  196. #define SDHCI_CTRL_VDD_180 0x0008
  197. #define SDHCI_CTRL_DRV_TYPE_MASK 0x0030
  198. #define SDHCI_CTRL_DRV_TYPE_B 0x0000
  199. #define SDHCI_CTRL_DRV_TYPE_A 0x0010
  200. #define SDHCI_CTRL_DRV_TYPE_C 0x0020
  201. #define SDHCI_CTRL_DRV_TYPE_D 0x0030
  202. #define SDHCI_CTRL_EXEC_TUNING 0x0040
  203. #define SDHCI_CTRL_TUNED_CLK 0x0080
  204. #define SDHCI_CTRL_UHS2_ENABLE 0x0100
  205. #define SDHCI_CTRL_ADMA2_LEN_MODE 0x0400
  206. #define SDHCI_CMD23_ENABLE 0x0800
  207. #define SDHCI_CTRL_V4_MODE 0x1000
  208. #define SDHCI_CTRL_64BIT_ADDR 0x2000
  209. #define SDHCI_CTRL_ASYNC_INT_ENABLE 0x4000
  210. #define SDHCI_CTRL_PRESET_VAL_ENABLE 0x8000
  211. #define SDHCI_CAPABILITIES 0x40
  212. #define SDHCI_TIMEOUT_CLK_MASK GENMASK(5, 0)
  213. #define SDHCI_TIMEOUT_CLK_SHIFT 0
  214. #define SDHCI_TIMEOUT_CLK_UNIT 0x00000080
  215. #define SDHCI_CLOCK_BASE_MASK GENMASK(13, 8)
  216. #define SDHCI_CLOCK_BASE_SHIFT 8
  217. #define SDHCI_CLOCK_V3_BASE_MASK GENMASK(15, 8)
  218. #define SDHCI_MAX_BLOCK_MASK 0x00030000
  219. #define SDHCI_MAX_BLOCK_SHIFT 16
  220. #define SDHCI_CAN_DO_8BIT 0x00040000
  221. #define SDHCI_CAN_DO_ADMA2 0x00080000
  222. #define SDHCI_CAN_DO_ADMA1 0x00100000
  223. #define SDHCI_CAN_DO_HISPD 0x00200000
  224. #define SDHCI_CAN_DO_SDMA 0x00400000
  225. #define SDHCI_CAN_DO_SUSPEND 0x00800000
  226. #define SDHCI_CAN_VDD_330 0x01000000
  227. #define SDHCI_CAN_VDD_300 0x02000000
  228. #define SDHCI_CAN_VDD_180 0x04000000
  229. #define SDHCI_CAN_64BIT_V4 0x08000000
  230. #define SDHCI_CAN_64BIT 0x10000000
  231. #define SDHCI_CAN_ASYNC_INT 0x20000000
  232. #define SDHCI_CAPABILITIES_1 0x44
  233. #define SDHCI_SUPPORT_SDR50 0x00000001
  234. #define SDHCI_SUPPORT_SDR104 0x00000002
  235. #define SDHCI_SUPPORT_DDR50 0x00000004
  236. #define SDHCI_SUPPORT_UHS2 0x00000008
  237. #define SDHCI_DRIVER_TYPE_A 0x00000010
  238. #define SDHCI_DRIVER_TYPE_C 0x00000020
  239. #define SDHCI_DRIVER_TYPE_D 0x00000040
  240. #define SDHCI_RETUNING_TIMER_COUNT_MASK GENMASK(11, 8)
  241. #define SDHCI_USE_SDR50_TUNING 0x00002000
  242. #define SDHCI_RETUNING_MODE_MASK GENMASK(15, 14)
  243. #define SDHCI_CLOCK_MUL_MASK GENMASK(23, 16)
  244. #define SDHCI_CAN_DO_ADMA3 0x08000000
  245. #define SDHCI_CAN_VDD2_180 0x10000000 /* UHS-2 1.8V VDD2 */
  246. #define SDHCI_SUPPORT_HS400 0x80000000 /* Non-standard */
  247. #define SDHCI_MAX_CURRENT 0x48
  248. #define SDHCI_MAX_CURRENT_LIMIT GENMASK(7, 0)
  249. #define SDHCI_MAX_CURRENT_330_MASK GENMASK(7, 0)
  250. #define SDHCI_MAX_CURRENT_300_MASK GENMASK(15, 8)
  251. #define SDHCI_MAX_CURRENT_180_MASK GENMASK(23, 16)
  252. #define SDHCI_MAX_CURRENT_1 0x4C
  253. #define SDHCI_MAX_CURRENT_VDD2_180_MASK GENMASK(7, 0) /* UHS2 */
  254. #define SDHCI_MAX_CURRENT_MULTIPLIER 4
  255. /* 4C-4F reserved for more max current */
  256. #define SDHCI_SET_ACMD12_ERROR 0x50
  257. /* Host Version 4.10 */
  258. #define SDHCI_SET_INT_ERROR 0x52
  259. #define SDHCI_ADMA_ERROR 0x54
  260. /* 55-57 reserved */
  261. #define SDHCI_ADMA_ADDRESS 0x58
  262. #define SDHCI_ADMA_ADDRESS_HI 0x5C
  263. /* 60-FB reserved */
  264. #define SDHCI_PRESET_FOR_HIGH_SPEED 0x64
  265. #define SDHCI_PRESET_FOR_SDR12 0x66
  266. #define SDHCI_PRESET_FOR_SDR25 0x68
  267. #define SDHCI_PRESET_FOR_SDR50 0x6A
  268. #define SDHCI_PRESET_FOR_SDR104 0x6C
  269. #define SDHCI_PRESET_FOR_DDR50 0x6E
  270. #define SDHCI_PRESET_FOR_HS400 0x74 /* Non-standard */
  271. /* UHS2 */
  272. #define SDHCI_PRESET_FOR_UHS2 0x74
  273. #define SDHCI_PRESET_DRV_MASK GENMASK(15, 14)
  274. #define SDHCI_PRESET_CLKGEN_SEL BIT(10)
  275. #define SDHCI_PRESET_SDCLK_FREQ_MASK GENMASK(9, 0)
  276. #define SDHCI_ADMA3_ADDRESS 0x78
  277. #define SDHCI_SLOT_INT_STATUS 0xFC
  278. #define SDHCI_HOST_VERSION 0xFE
  279. #define SDHCI_VENDOR_VER_MASK 0xFF00
  280. #define SDHCI_VENDOR_VER_SHIFT 8
  281. #define SDHCI_SPEC_VER_MASK 0x00FF
  282. #define SDHCI_SPEC_VER_SHIFT 0
  283. #define SDHCI_SPEC_100 0
  284. #define SDHCI_SPEC_200 1
  285. #define SDHCI_SPEC_300 2
  286. #define SDHCI_SPEC_400 3
  287. #define SDHCI_SPEC_410 4
  288. #define SDHCI_SPEC_420 5
  289. /*
  290. * End of controller registers.
  291. */
  292. #define SDHCI_MAX_DIV_SPEC_200 256
  293. #define SDHCI_MAX_DIV_SPEC_300 2046
  294. /*
  295. * Host SDMA buffer boundary. Valid values from 4K to 512K in powers of 2.
  296. */
  297. #define SDHCI_DEFAULT_BOUNDARY_SIZE (512 * 1024)
  298. #define SDHCI_DEFAULT_BOUNDARY_ARG (ilog2(SDHCI_DEFAULT_BOUNDARY_SIZE) - 12)
  299. /* ADMA2 32-bit DMA descriptor size */
  300. #define SDHCI_ADMA2_32_DESC_SZ 8
  301. /* ADMA2 32-bit descriptor */
  302. struct sdhci_adma2_32_desc {
  303. __le16 cmd;
  304. __le16 len;
  305. __le32 addr;
  306. } __packed __aligned(4);
  307. /* ADMA2 data alignment */
  308. #define SDHCI_ADMA2_ALIGN 4
  309. #define SDHCI_ADMA2_MASK (SDHCI_ADMA2_ALIGN - 1)
  310. /*
  311. * ADMA2 descriptor alignment. Some controllers (e.g. Intel) require 8 byte
  312. * alignment for the descriptor table even in 32-bit DMA mode. Memory
  313. * allocation is at least 8 byte aligned anyway, so just stipulate 8 always.
  314. */
  315. #define SDHCI_ADMA2_DESC_ALIGN 8
  316. /*
  317. * ADMA2 64-bit DMA descriptor size
  318. * According to SD Host Controller spec v4.10, there are two kinds of
  319. * descriptors for 64-bit addressing mode: 96-bit Descriptor and 128-bit
  320. * Descriptor, if Host Version 4 Enable is set in the Host Control 2
  321. * register, 128-bit Descriptor will be selected.
  322. */
  323. #define SDHCI_ADMA2_64_DESC_SZ(host) ((host)->v4_mode ? 16 : 12)
  324. /*
  325. * ADMA2 64-bit descriptor. Note 12-byte descriptor can't always be 8-byte
  326. * aligned.
  327. */
  328. struct sdhci_adma2_64_desc {
  329. __le16 cmd;
  330. __le16 len;
  331. __le32 addr_lo;
  332. __le32 addr_hi;
  333. } __packed __aligned(4);
  334. #define ADMA2_TRAN_VALID 0x21
  335. #define ADMA2_NOP_END_VALID 0x3
  336. #define ADMA2_END 0x2
  337. /*
  338. * Maximum segments assuming a 512KiB maximum requisition size and a minimum
  339. * 4KiB page size. Note this also allows enough for multiple descriptors in
  340. * case of PAGE_SIZE >= 64KiB.
  341. */
  342. #define SDHCI_MAX_SEGS 128
  343. /* Allow for a command request and a data request at the same time */
  344. #define SDHCI_MAX_MRQS 2
  345. /*
  346. * 48bit command and 136 bit response in 100KHz clock could take upto 2.48ms.
  347. * However since the start time of the command, the time between
  348. * command and response, and the time between response and start of data is
  349. * not known, set the command transfer time to 10ms.
  350. */
  351. #define MMC_CMD_TRANSFER_TIME (10 * NSEC_PER_MSEC) /* max 10 ms */
  352. #define sdhci_err_stats_inc(host, err_name) \
  353. mmc_debugfs_err_stats_inc((host)->mmc, MMC_ERR_##err_name)
  354. enum sdhci_cookie {
  355. COOKIE_UNMAPPED,
  356. COOKIE_PRE_MAPPED, /* mapped by sdhci_pre_req() */
  357. COOKIE_MAPPED, /* mapped by sdhci_prepare_data() */
  358. };
  359. struct sdhci_host {
  360. /* Data set by hardware interface driver */
  361. const char *hw_name; /* Hardware bus name */
  362. unsigned int quirks; /* Deviations from spec. */
  363. /* Controller doesn't honor resets unless we touch the clock register */
  364. #define SDHCI_QUIRK_CLOCK_BEFORE_RESET (1<<0)
  365. /* Controller has bad caps bits, but really supports DMA */
  366. #define SDHCI_QUIRK_FORCE_DMA (1<<1)
  367. /* Controller doesn't like to be reset when there is no card inserted. */
  368. #define SDHCI_QUIRK_NO_CARD_NO_RESET (1<<2)
  369. /* Controller doesn't like clearing the power reg before a change */
  370. #define SDHCI_QUIRK_SINGLE_POWER_WRITE (1<<3)
  371. /* Controller has an unusable DMA engine */
  372. #define SDHCI_QUIRK_BROKEN_DMA (1<<5)
  373. /* Controller has an unusable ADMA engine */
  374. #define SDHCI_QUIRK_BROKEN_ADMA (1<<6)
  375. /* Controller can only DMA from 32-bit aligned addresses */
  376. #define SDHCI_QUIRK_32BIT_DMA_ADDR (1<<7)
  377. /* Controller can only DMA chunk sizes that are a multiple of 32 bits */
  378. #define SDHCI_QUIRK_32BIT_DMA_SIZE (1<<8)
  379. /* Controller can only ADMA chunks that are a multiple of 32 bits */
  380. #define SDHCI_QUIRK_32BIT_ADMA_SIZE (1<<9)
  381. /* Controller needs to be reset after each request to stay stable */
  382. #define SDHCI_QUIRK_RESET_AFTER_REQUEST (1<<10)
  383. /* Controller needs voltage and power writes to happen separately */
  384. #define SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER (1<<11)
  385. /* Controller provides an incorrect timeout value for transfers */
  386. #define SDHCI_QUIRK_BROKEN_TIMEOUT_VAL (1<<12)
  387. /* Controller has an issue with buffer bits for small transfers */
  388. #define SDHCI_QUIRK_BROKEN_SMALL_PIO (1<<13)
  389. /* Controller does not provide transfer-complete interrupt when not busy */
  390. #define SDHCI_QUIRK_NO_BUSY_IRQ (1<<14)
  391. /* Controller has unreliable card detection */
  392. #define SDHCI_QUIRK_BROKEN_CARD_DETECTION (1<<15)
  393. /* Controller reports inverted write-protect state */
  394. #define SDHCI_QUIRK_INVERTED_WRITE_PROTECT (1<<16)
  395. /* Controller has unusable command queue engine */
  396. #define SDHCI_QUIRK_BROKEN_CQE (1<<17)
  397. /* Controller does not like fast PIO transfers */
  398. #define SDHCI_QUIRK_PIO_NEEDS_DELAY (1<<18)
  399. /* Controller does not have a LED */
  400. #define SDHCI_QUIRK_NO_LED (1<<19)
  401. /* Controller has to be forced to use block size of 2048 bytes */
  402. #define SDHCI_QUIRK_FORCE_BLK_SZ_2048 (1<<20)
  403. /* Controller cannot do multi-block transfers */
  404. #define SDHCI_QUIRK_NO_MULTIBLOCK (1<<21)
  405. /* Controller can only handle 1-bit data transfers */
  406. #define SDHCI_QUIRK_FORCE_1_BIT_DATA (1<<22)
  407. /* Controller needs 10ms delay between applying power and clock */
  408. #define SDHCI_QUIRK_DELAY_AFTER_POWER (1<<23)
  409. /* Controller uses SDCLK instead of TMCLK for data timeouts */
  410. #define SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK (1<<24)
  411. /* Controller reports wrong base clock capability */
  412. #define SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN (1<<25)
  413. /* Controller cannot support End Attribute in NOP ADMA descriptor */
  414. #define SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC (1<<26)
  415. /* Controller uses Auto CMD12 command to stop the transfer */
  416. #define SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12 (1<<28)
  417. /* Controller doesn't have HISPD bit field in HI-SPEED SD card */
  418. #define SDHCI_QUIRK_NO_HISPD_BIT (1<<29)
  419. /* Controller treats ADMA descriptors with length 0000h incorrectly */
  420. #define SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC (1<<30)
  421. unsigned int quirks2; /* More deviations from spec. */
  422. #define SDHCI_QUIRK2_HOST_OFF_CARD_ON (1<<0)
  423. #define SDHCI_QUIRK2_HOST_NO_CMD23 (1<<1)
  424. /* The system physically doesn't support 1.8v, even if the host does */
  425. #define SDHCI_QUIRK2_NO_1_8_V (1<<2)
  426. #define SDHCI_QUIRK2_PRESET_VALUE_BROKEN (1<<3)
  427. #define SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON (1<<4)
  428. /* Controller has a non-standard host control register */
  429. #define SDHCI_QUIRK2_BROKEN_HOST_CONTROL (1<<5)
  430. /* Controller does not support HS200 */
  431. #define SDHCI_QUIRK2_BROKEN_HS200 (1<<6)
  432. /* Controller does not support DDR50 */
  433. #define SDHCI_QUIRK2_BROKEN_DDR50 (1<<7)
  434. /* Stop command (CMD12) can set Transfer Complete when not using MMC_RSP_BUSY */
  435. #define SDHCI_QUIRK2_STOP_WITH_TC (1<<8)
  436. /* Controller does not support 64-bit DMA */
  437. #define SDHCI_QUIRK2_BROKEN_64_BIT_DMA (1<<9)
  438. /* need clear transfer mode register before send cmd */
  439. #define SDHCI_QUIRK2_CLEAR_TRANSFERMODE_REG_BEFORE_CMD (1<<10)
  440. /* Capability register bit-63 indicates HS400 support */
  441. #define SDHCI_QUIRK2_CAPS_BIT63_FOR_HS400 (1<<11)
  442. /* forced tuned clock */
  443. #define SDHCI_QUIRK2_TUNING_WORK_AROUND (1<<12)
  444. /* disable the block count for single block transactions */
  445. #define SDHCI_QUIRK2_SUPPORT_SINGLE (1<<13)
  446. /* Controller broken with using ACMD23 */
  447. #define SDHCI_QUIRK2_ACMD23_BROKEN (1<<14)
  448. /* Broken Clock divider zero in controller */
  449. #define SDHCI_QUIRK2_CLOCK_DIV_ZERO_BROKEN (1<<15)
  450. /* Controller has CRC in 136 bit Command Response */
  451. #define SDHCI_QUIRK2_RSP_136_HAS_CRC (1<<16)
  452. /*
  453. * Disable HW timeout if the requested timeout is more than the maximum
  454. * obtainable timeout.
  455. */
  456. #define SDHCI_QUIRK2_DISABLE_HW_TIMEOUT (1<<17)
  457. /*
  458. * 32-bit block count may not support eMMC where upper bits of CMD23 are used
  459. * for other purposes. Consequently we support 16-bit block count by default.
  460. * Otherwise, SDHCI_QUIRK2_USE_32BIT_BLK_CNT can be selected to use 32-bit
  461. * block count.
  462. */
  463. #define SDHCI_QUIRK2_USE_32BIT_BLK_CNT (1<<18)
  464. /* Issue CMD and DATA reset together */
  465. #define SDHCI_QUIRK2_ISSUE_CMD_DAT_RESET_TOGETHER (1<<19)
  466. int irq; /* Device IRQ */
  467. void __iomem *ioaddr; /* Mapped address */
  468. phys_addr_t mapbase; /* physical address base */
  469. char *bounce_buffer; /* For packing SDMA reads/writes */
  470. dma_addr_t bounce_addr;
  471. unsigned int bounce_buffer_size;
  472. const struct sdhci_ops *ops; /* Low level hw interface */
  473. /* Internal data */
  474. struct mmc_host *mmc; /* MMC structure */
  475. struct mmc_host_ops mmc_host_ops; /* MMC host ops */
  476. u64 dma_mask; /* custom DMA mask */
  477. #if IS_ENABLED(CONFIG_LEDS_CLASS)
  478. struct led_classdev led; /* LED control */
  479. char led_name[32];
  480. #endif
  481. spinlock_t lock; /* Mutex */
  482. int flags; /* Host attributes */
  483. #define SDHCI_USE_SDMA (1<<0) /* Host is SDMA capable */
  484. #define SDHCI_USE_ADMA (1<<1) /* Host is ADMA capable */
  485. #define SDHCI_REQ_USE_DMA (1<<2) /* Use DMA for this req. */
  486. #define SDHCI_DEVICE_DEAD (1<<3) /* Device unresponsive */
  487. #define SDHCI_SDR50_NEEDS_TUNING (1<<4) /* SDR50 needs tuning */
  488. #define SDHCI_AUTO_CMD12 (1<<6) /* Auto CMD12 support */
  489. #define SDHCI_AUTO_CMD23 (1<<7) /* Auto CMD23 support */
  490. #define SDHCI_PV_ENABLED (1<<8) /* Preset value enabled */
  491. #define SDHCI_USE_64_BIT_DMA (1<<12) /* Use 64-bit DMA */
  492. #define SDHCI_HS400_TUNING (1<<13) /* Tuning for HS400 */
  493. #define SDHCI_SIGNALING_330 (1<<14) /* Host is capable of 3.3V signaling */
  494. #define SDHCI_SIGNALING_180 (1<<15) /* Host is capable of 1.8V signaling */
  495. #define SDHCI_SIGNALING_120 (1<<16) /* Host is capable of 1.2V signaling */
  496. unsigned int version; /* SDHCI spec. version */
  497. unsigned int max_clk; /* Max possible freq (MHz) */
  498. unsigned int timeout_clk; /* Timeout freq (KHz) */
  499. u8 max_timeout_count; /* Vendor specific max timeout count */
  500. unsigned int clk_mul; /* Clock Muliplier value */
  501. unsigned int clock; /* Current clock (MHz) */
  502. u8 pwr; /* Current voltage */
  503. u8 drv_type; /* Current UHS-I driver type */
  504. bool reinit_uhs; /* Force UHS-related re-initialization */
  505. bool runtime_suspended; /* Host is runtime suspended */
  506. bool bus_on; /* Bus power prevents runtime suspend */
  507. bool preset_enabled; /* Preset is enabled */
  508. bool pending_reset; /* Cmd/data reset is pending */
  509. bool irq_wake_enabled; /* IRQ wakeup is enabled */
  510. bool v4_mode; /* Host Version 4 Enable */
  511. bool use_external_dma; /* Host selects to use external DMA */
  512. bool always_defer_done; /* Always defer to complete requests */
  513. struct mmc_request *mrqs_done[SDHCI_MAX_MRQS]; /* Requests done */
  514. struct mmc_command *cmd; /* Current command */
  515. struct mmc_command *data_cmd; /* Current data command */
  516. struct mmc_command *deferred_cmd; /* Deferred command */
  517. struct mmc_data *data; /* Current data request */
  518. unsigned int data_early:1; /* Data finished before cmd */
  519. struct sg_mapping_iter sg_miter; /* SG state for PIO */
  520. unsigned int blocks; /* remaining PIO blocks */
  521. int sg_count; /* Mapped sg entries */
  522. int max_adma; /* Max. length in ADMA descriptor */
  523. void *adma_table; /* ADMA descriptor table */
  524. void *align_buffer; /* Bounce buffer */
  525. size_t adma_table_sz; /* ADMA descriptor table size */
  526. size_t align_buffer_sz; /* Bounce buffer size */
  527. dma_addr_t adma_addr; /* Mapped ADMA descr. table */
  528. dma_addr_t align_addr; /* Mapped bounce buffer */
  529. unsigned int desc_sz; /* ADMA current descriptor size */
  530. unsigned int alloc_desc_sz; /* ADMA descr. max size host supports */
  531. struct workqueue_struct *complete_wq; /* Request completion wq */
  532. struct work_struct complete_work; /* Request completion work */
  533. struct timer_list timer; /* Timer for timeouts */
  534. struct timer_list data_timer; /* Timer for data timeouts */
  535. void (*complete_work_fn)(struct work_struct *work);
  536. irqreturn_t (*thread_irq_fn)(int irq, void *dev_id);
  537. #if IS_ENABLED(CONFIG_MMC_SDHCI_EXTERNAL_DMA)
  538. struct dma_chan *rx_chan;
  539. struct dma_chan *tx_chan;
  540. #endif
  541. u32 caps; /* CAPABILITY_0 */
  542. u32 caps1; /* CAPABILITY_1 */
  543. bool read_caps; /* Capability flags have been read */
  544. bool sdhci_core_to_disable_vqmmc; /* sdhci core can disable vqmmc */
  545. unsigned int ocr_avail_sdio; /* OCR bit masks */
  546. unsigned int ocr_avail_sd;
  547. unsigned int ocr_avail_mmc;
  548. u32 ocr_mask; /* available voltages */
  549. unsigned timing; /* Current timing */
  550. u32 thread_isr;
  551. /* cached registers */
  552. u32 ier;
  553. bool cqe_on; /* CQE is operating */
  554. u32 cqe_ier; /* CQE interrupt mask */
  555. u32 cqe_err_ier; /* CQE error interrupt mask */
  556. wait_queue_head_t buf_ready_int; /* Waitqueue for Buffer Read Ready interrupt */
  557. unsigned int tuning_done; /* Condition flag set when CMD19 succeeds */
  558. unsigned int tuning_count; /* Timer count for re-tuning */
  559. unsigned int tuning_mode; /* Re-tuning mode supported by host */
  560. unsigned int tuning_err; /* Error code for re-tuning */
  561. #define SDHCI_TUNING_MODE_1 0
  562. #define SDHCI_TUNING_MODE_2 1
  563. #define SDHCI_TUNING_MODE_3 2
  564. /* Delay (ms) between tuning commands */
  565. int tuning_delay;
  566. int tuning_loop_count;
  567. /* Host SDMA buffer boundary. */
  568. u32 sdma_boundary;
  569. /* Host ADMA table count */
  570. u32 adma_table_cnt;
  571. u64 data_timeout;
  572. unsigned long private[] ____cacheline_aligned;
  573. };
  574. struct sdhci_ops {
  575. #ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS
  576. u32 (*read_l)(struct sdhci_host *host, int reg);
  577. u16 (*read_w)(struct sdhci_host *host, int reg);
  578. u8 (*read_b)(struct sdhci_host *host, int reg);
  579. void (*write_l)(struct sdhci_host *host, u32 val, int reg);
  580. void (*write_w)(struct sdhci_host *host, u16 val, int reg);
  581. void (*write_b)(struct sdhci_host *host, u8 val, int reg);
  582. #endif
  583. void (*set_clock)(struct sdhci_host *host, unsigned int clock);
  584. void (*set_power)(struct sdhci_host *host, unsigned char mode,
  585. unsigned short vdd);
  586. u32 (*irq)(struct sdhci_host *host, u32 intmask);
  587. int (*set_dma_mask)(struct sdhci_host *host);
  588. int (*enable_dma)(struct sdhci_host *host);
  589. unsigned int (*get_max_clock)(struct sdhci_host *host);
  590. unsigned int (*get_min_clock)(struct sdhci_host *host);
  591. /* get_timeout_clock should return clk rate in unit of Hz */
  592. unsigned int (*get_timeout_clock)(struct sdhci_host *host);
  593. unsigned int (*get_max_timeout_count)(struct sdhci_host *host);
  594. void (*set_timeout)(struct sdhci_host *host,
  595. struct mmc_command *cmd);
  596. void (*set_bus_width)(struct sdhci_host *host, int width);
  597. void (*platform_send_init_74_clocks)(struct sdhci_host *host,
  598. u8 power_mode);
  599. unsigned int (*get_ro)(struct sdhci_host *host);
  600. void (*reset)(struct sdhci_host *host, u8 mask);
  601. int (*platform_execute_tuning)(struct sdhci_host *host, u32 opcode);
  602. void (*set_uhs_signaling)(struct sdhci_host *host, unsigned int uhs);
  603. void (*hw_reset)(struct sdhci_host *host);
  604. void (*adma_workaround)(struct sdhci_host *host, u32 intmask);
  605. void (*card_event)(struct sdhci_host *host);
  606. void (*voltage_switch)(struct sdhci_host *host);
  607. void (*adma_write_desc)(struct sdhci_host *host, void **desc,
  608. dma_addr_t addr, int len, unsigned int cmd);
  609. void (*copy_to_bounce_buffer)(struct sdhci_host *host,
  610. struct mmc_data *data,
  611. unsigned int length);
  612. void (*request_done)(struct sdhci_host *host,
  613. struct mmc_request *mrq);
  614. void (*dump_vendor_regs)(struct sdhci_host *host);
  615. void (*dump_uhs2_regs)(struct sdhci_host *host);
  616. void (*uhs2_pre_detect_init)(struct sdhci_host *host);
  617. };
  618. #ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS
  619. static inline void sdhci_writel(struct sdhci_host *host, u32 val, int reg)
  620. {
  621. if (unlikely(host->ops->write_l))
  622. host->ops->write_l(host, val, reg);
  623. else
  624. writel(val, host->ioaddr + reg);
  625. }
  626. static inline void sdhci_writew(struct sdhci_host *host, u16 val, int reg)
  627. {
  628. if (unlikely(host->ops->write_w))
  629. host->ops->write_w(host, val, reg);
  630. else
  631. writew(val, host->ioaddr + reg);
  632. }
  633. static inline void sdhci_writeb(struct sdhci_host *host, u8 val, int reg)
  634. {
  635. if (unlikely(host->ops->write_b))
  636. host->ops->write_b(host, val, reg);
  637. else
  638. writeb(val, host->ioaddr + reg);
  639. }
  640. static inline u32 sdhci_readl(struct sdhci_host *host, int reg)
  641. {
  642. if (unlikely(host->ops->read_l))
  643. return host->ops->read_l(host, reg);
  644. else
  645. return readl(host->ioaddr + reg);
  646. }
  647. static inline u16 sdhci_readw(struct sdhci_host *host, int reg)
  648. {
  649. if (unlikely(host->ops->read_w))
  650. return host->ops->read_w(host, reg);
  651. else
  652. return readw(host->ioaddr + reg);
  653. }
  654. static inline u8 sdhci_readb(struct sdhci_host *host, int reg)
  655. {
  656. if (unlikely(host->ops->read_b))
  657. return host->ops->read_b(host, reg);
  658. else
  659. return readb(host->ioaddr + reg);
  660. }
  661. #else
  662. static inline void sdhci_writel(struct sdhci_host *host, u32 val, int reg)
  663. {
  664. writel(val, host->ioaddr + reg);
  665. }
  666. static inline void sdhci_writew(struct sdhci_host *host, u16 val, int reg)
  667. {
  668. writew(val, host->ioaddr + reg);
  669. }
  670. static inline void sdhci_writeb(struct sdhci_host *host, u8 val, int reg)
  671. {
  672. writeb(val, host->ioaddr + reg);
  673. }
  674. static inline u32 sdhci_readl(struct sdhci_host *host, int reg)
  675. {
  676. return readl(host->ioaddr + reg);
  677. }
  678. static inline u16 sdhci_readw(struct sdhci_host *host, int reg)
  679. {
  680. return readw(host->ioaddr + reg);
  681. }
  682. static inline u8 sdhci_readb(struct sdhci_host *host, int reg)
  683. {
  684. return readb(host->ioaddr + reg);
  685. }
  686. #endif /* CONFIG_MMC_SDHCI_IO_ACCESSORS */
  687. struct sdhci_host *sdhci_alloc_host(struct device *dev, size_t priv_size);
  688. static inline void *sdhci_priv(struct sdhci_host *host)
  689. {
  690. return host->private;
  691. }
  692. void __sdhci_read_caps(struct sdhci_host *host, const u16 *ver,
  693. const u32 *caps, const u32 *caps1);
  694. int sdhci_setup_host(struct sdhci_host *host);
  695. void sdhci_cleanup_host(struct sdhci_host *host);
  696. int __sdhci_add_host(struct sdhci_host *host);
  697. int sdhci_add_host(struct sdhci_host *host);
  698. void sdhci_remove_host(struct sdhci_host *host, int dead);
  699. static inline void sdhci_read_caps(struct sdhci_host *host)
  700. {
  701. __sdhci_read_caps(host, NULL, NULL, NULL);
  702. }
  703. bool sdhci_needs_reset(struct sdhci_host *host, struct mmc_request *mrq);
  704. bool sdhci_data_line_cmd(struct mmc_command *cmd);
  705. void sdhci_mod_timer(struct sdhci_host *host, struct mmc_request *mrq, unsigned long timeout);
  706. void sdhci_initialize_data(struct sdhci_host *host, struct mmc_data *data);
  707. void sdhci_prepare_dma(struct sdhci_host *host, struct mmc_data *data);
  708. void __sdhci_finish_mrq(struct sdhci_host *host, struct mmc_request *mrq);
  709. void sdhci_finish_mrq(struct sdhci_host *host, struct mmc_request *mrq);
  710. void __sdhci_finish_data_common(struct sdhci_host *host, bool defer_reset);
  711. bool sdhci_present_error(struct sdhci_host *host, struct mmc_command *cmd, bool present);
  712. u16 sdhci_calc_clk(struct sdhci_host *host, unsigned int clock,
  713. unsigned int *actual_clock);
  714. void sdhci_set_clock(struct sdhci_host *host, unsigned int clock);
  715. void sdhci_enable_clk(struct sdhci_host *host, u16 clk);
  716. void sdhci_set_power(struct sdhci_host *host, unsigned char mode,
  717. unsigned short vdd);
  718. void sdhci_set_power_and_bus_voltage(struct sdhci_host *host,
  719. unsigned char mode,
  720. unsigned short vdd);
  721. unsigned short sdhci_get_vdd_value(unsigned short vdd);
  722. void sdhci_set_power_noreg(struct sdhci_host *host, unsigned char mode,
  723. unsigned short vdd);
  724. int sdhci_get_cd_nogpio(struct mmc_host *mmc);
  725. int sdhci_get_ro(struct mmc_host *mmc);
  726. void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq);
  727. int sdhci_request_atomic(struct mmc_host *mmc, struct mmc_request *mrq);
  728. void sdhci_set_bus_width(struct sdhci_host *host, int width);
  729. void sdhci_reset(struct sdhci_host *host, u8 mask);
  730. bool sdhci_do_reset(struct sdhci_host *host, u8 mask);
  731. void sdhci_set_uhs_signaling(struct sdhci_host *host, unsigned timing);
  732. int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode);
  733. int __sdhci_execute_tuning(struct sdhci_host *host, u32 opcode);
  734. void sdhci_enable_preset_value(struct sdhci_host *host, bool enable);
  735. void sdhci_set_ios_common(struct mmc_host *mmc, struct mmc_ios *ios);
  736. void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios);
  737. int sdhci_start_signal_voltage_switch(struct mmc_host *mmc,
  738. struct mmc_ios *ios);
  739. void sdhci_enable_sdio_irq(struct mmc_host *mmc, int enable);
  740. void sdhci_request_done_dma(struct sdhci_host *host, struct mmc_request *mrq);
  741. void sdhci_complete_work(struct work_struct *work);
  742. irqreturn_t sdhci_thread_irq(int irq, void *dev_id);
  743. void sdhci_adma_write_desc(struct sdhci_host *host, void **desc,
  744. dma_addr_t addr, int len, unsigned int cmd);
  745. #ifdef CONFIG_PM
  746. bool sdhci_enable_irq_wakeups(struct sdhci_host *host);
  747. void sdhci_disable_irq_wakeups(struct sdhci_host *host);
  748. int sdhci_suspend_host(struct sdhci_host *host);
  749. int sdhci_resume_host(struct sdhci_host *host);
  750. void sdhci_runtime_suspend_host(struct sdhci_host *host);
  751. void sdhci_runtime_resume_host(struct sdhci_host *host, int soft_reset);
  752. #else
  753. static inline bool sdhci_enable_irq_wakeups(struct sdhci_host *host) { return false; }
  754. static inline void sdhci_disable_irq_wakeups(struct sdhci_host *host) {}
  755. static inline int sdhci_suspend_host(struct sdhci_host *host) { return -EOPNOTSUPP; }
  756. static inline int sdhci_resume_host(struct sdhci_host *host) { return -EOPNOTSUPP; }
  757. static inline void sdhci_runtime_suspend_host(struct sdhci_host *host) {}
  758. static inline void sdhci_runtime_resume_host(struct sdhci_host *host, int soft_reset) {}
  759. #endif
  760. void sdhci_cqe_enable(struct mmc_host *mmc);
  761. void sdhci_cqe_disable(struct mmc_host *mmc, bool recovery);
  762. bool sdhci_cqe_irq(struct sdhci_host *host, u32 intmask, int *cmd_error,
  763. int *data_error);
  764. void sdhci_dumpregs(struct sdhci_host *host);
  765. void sdhci_enable_v4_mode(struct sdhci_host *host);
  766. void sdhci_start_tuning(struct sdhci_host *host);
  767. void sdhci_end_tuning(struct sdhci_host *host);
  768. void sdhci_reset_tuning(struct sdhci_host *host);
  769. void sdhci_send_tuning(struct sdhci_host *host, u32 opcode);
  770. void sdhci_abort_tuning(struct sdhci_host *host, u32 opcode);
  771. void sdhci_switch_external_dma(struct sdhci_host *host, bool en);
  772. void sdhci_set_data_timeout_irq(struct sdhci_host *host, bool enable);
  773. void __sdhci_set_timeout(struct sdhci_host *host, struct mmc_command *cmd);
  774. #if defined(CONFIG_DYNAMIC_DEBUG) || \
  775. (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
  776. #define SDHCI_DBG_ANYWAY 0
  777. #elif defined(DEBUG)
  778. #define SDHCI_DBG_ANYWAY 1
  779. #else
  780. #define SDHCI_DBG_ANYWAY 0
  781. #endif
  782. #define sdhci_dbg_dumpregs(host, fmt) \
  783. do { \
  784. DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
  785. if (DYNAMIC_DEBUG_BRANCH(descriptor) || SDHCI_DBG_ANYWAY) \
  786. sdhci_dumpregs(host); \
  787. } while (0)
  788. #endif /* __SDHCI_HW_H */