host.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * linux/include/linux/mmc/host.h
  4. *
  5. * Host driver specific definitions.
  6. */
  7. #ifndef LINUX_MMC_HOST_H
  8. #define LINUX_MMC_HOST_H
  9. #include <linux/sched.h>
  10. #include <linux/device.h>
  11. #include <linux/fault-inject.h>
  12. #include <linux/mmc/core.h>
  13. #include <linux/mmc/card.h>
  14. #include <linux/mmc/pm.h>
  15. #include <linux/dma-direction.h>
  16. #include <linux/blk-crypto-profile.h>
  17. #include <linux/android_kabi.h>
  18. struct mmc_ios {
  19. unsigned int clock; /* clock rate */
  20. unsigned short vdd;
  21. unsigned int power_delay_ms; /* waiting for stable power */
  22. /* vdd stores the bit number of the selected voltage range from below. */
  23. unsigned char bus_mode; /* command output mode */
  24. #define MMC_BUSMODE_OPENDRAIN 1
  25. #define MMC_BUSMODE_PUSHPULL 2
  26. unsigned char chip_select; /* SPI chip select */
  27. #define MMC_CS_DONTCARE 0
  28. #define MMC_CS_HIGH 1
  29. #define MMC_CS_LOW 2
  30. unsigned char power_mode; /* power supply mode */
  31. #define MMC_POWER_OFF 0
  32. #define MMC_POWER_UP 1
  33. #define MMC_POWER_ON 2
  34. #define MMC_POWER_UNDEFINED 3
  35. unsigned char bus_width; /* data bus width */
  36. #define MMC_BUS_WIDTH_1 0
  37. #define MMC_BUS_WIDTH_4 2
  38. #define MMC_BUS_WIDTH_8 3
  39. unsigned char timing; /* timing specification used */
  40. #define MMC_TIMING_LEGACY 0
  41. #define MMC_TIMING_MMC_HS 1
  42. #define MMC_TIMING_SD_HS 2
  43. #define MMC_TIMING_UHS_SDR12 3
  44. #define MMC_TIMING_UHS_SDR25 4
  45. #define MMC_TIMING_UHS_SDR50 5
  46. #define MMC_TIMING_UHS_SDR104 6
  47. #define MMC_TIMING_UHS_DDR50 7
  48. #define MMC_TIMING_MMC_DDR52 8
  49. #define MMC_TIMING_MMC_HS200 9
  50. #define MMC_TIMING_MMC_HS400 10
  51. #define MMC_TIMING_SD_EXP 11
  52. #define MMC_TIMING_SD_EXP_1_2V 12
  53. unsigned char signal_voltage; /* signalling voltage (1.8V or 3.3V) */
  54. #define MMC_SIGNAL_VOLTAGE_330 0
  55. #define MMC_SIGNAL_VOLTAGE_180 1
  56. #define MMC_SIGNAL_VOLTAGE_120 2
  57. unsigned char drv_type; /* driver type (A, B, C, D) */
  58. #define MMC_SET_DRIVER_TYPE_B 0
  59. #define MMC_SET_DRIVER_TYPE_A 1
  60. #define MMC_SET_DRIVER_TYPE_C 2
  61. #define MMC_SET_DRIVER_TYPE_D 3
  62. bool enhanced_strobe; /* hs400es selection */
  63. };
  64. struct mmc_clk_phase {
  65. bool valid;
  66. u16 in_deg;
  67. u16 out_deg;
  68. };
  69. #define MMC_NUM_CLK_PHASES (MMC_TIMING_MMC_HS400 + 1)
  70. struct mmc_clk_phase_map {
  71. struct mmc_clk_phase phase[MMC_NUM_CLK_PHASES];
  72. };
  73. struct mmc_host;
  74. enum mmc_err_stat {
  75. MMC_ERR_CMD_TIMEOUT,
  76. MMC_ERR_CMD_CRC,
  77. MMC_ERR_DAT_TIMEOUT,
  78. MMC_ERR_DAT_CRC,
  79. MMC_ERR_AUTO_CMD,
  80. MMC_ERR_ADMA,
  81. MMC_ERR_TUNING,
  82. MMC_ERR_CMDQ_RED,
  83. MMC_ERR_CMDQ_GCE,
  84. MMC_ERR_CMDQ_ICCE,
  85. MMC_ERR_REQ_TIMEOUT,
  86. MMC_ERR_CMDQ_REQ_TIMEOUT,
  87. MMC_ERR_ICE_CFG,
  88. MMC_ERR_CTRL_TIMEOUT,
  89. MMC_ERR_UNEXPECTED_IRQ,
  90. MMC_ERR_MAX,
  91. };
  92. struct mmc_host_ops {
  93. /*
  94. * It is optional for the host to implement pre_req and post_req in
  95. * order to support double buffering of requests (prepare one
  96. * request while another request is active).
  97. * pre_req() must always be followed by a post_req().
  98. * To undo a call made to pre_req(), call post_req() with
  99. * a nonzero err condition.
  100. */
  101. void (*post_req)(struct mmc_host *host, struct mmc_request *req,
  102. int err);
  103. void (*pre_req)(struct mmc_host *host, struct mmc_request *req);
  104. void (*request)(struct mmc_host *host, struct mmc_request *req);
  105. /* Submit one request to host in atomic context. */
  106. int (*request_atomic)(struct mmc_host *host,
  107. struct mmc_request *req);
  108. /*
  109. * Avoid calling the next three functions too often or in a "fast
  110. * path", since underlaying controller might implement them in an
  111. * expensive and/or slow way. Also note that these functions might
  112. * sleep, so don't call them in the atomic contexts!
  113. */
  114. /*
  115. * Notes to the set_ios callback:
  116. * ios->clock might be 0. For some controllers, setting 0Hz
  117. * as any other frequency works. However, some controllers
  118. * explicitly need to disable the clock. Otherwise e.g. voltage
  119. * switching might fail because the SDCLK is not really quiet.
  120. */
  121. void (*set_ios)(struct mmc_host *host, struct mmc_ios *ios);
  122. /*
  123. * Return values for the get_ro callback should be:
  124. * 0 for a read/write card
  125. * 1 for a read-only card
  126. * -ENOSYS when not supported (equal to NULL callback)
  127. * or a negative errno value when something bad happened
  128. */
  129. int (*get_ro)(struct mmc_host *host);
  130. /*
  131. * Return values for the get_cd callback should be:
  132. * 0 for a absent card
  133. * 1 for a present card
  134. * -ENOSYS when not supported (equal to NULL callback)
  135. * or a negative errno value when something bad happened
  136. */
  137. int (*get_cd)(struct mmc_host *host);
  138. void (*enable_sdio_irq)(struct mmc_host *host, int enable);
  139. /* Mandatory callback when using MMC_CAP2_SDIO_IRQ_NOTHREAD. */
  140. void (*ack_sdio_irq)(struct mmc_host *host);
  141. /* optional callback for HC quirks */
  142. void (*init_card)(struct mmc_host *host, struct mmc_card *card);
  143. int (*start_signal_voltage_switch)(struct mmc_host *host, struct mmc_ios *ios);
  144. /* Check if the card is pulling dat[0] low */
  145. int (*card_busy)(struct mmc_host *host);
  146. /* The tuning command opcode value is different for SD and eMMC cards */
  147. int (*execute_tuning)(struct mmc_host *host, u32 opcode);
  148. /* Prepare HS400 target operating frequency depending host driver */
  149. int (*prepare_hs400_tuning)(struct mmc_host *host, struct mmc_ios *ios);
  150. /* Execute HS400 tuning depending host driver */
  151. int (*execute_hs400_tuning)(struct mmc_host *host, struct mmc_card *card);
  152. /* Prepare switch to DDR during the HS400 init sequence */
  153. int (*hs400_prepare_ddr)(struct mmc_host *host);
  154. /* Prepare for switching from HS400 to HS200 */
  155. void (*hs400_downgrade)(struct mmc_host *host);
  156. /* Complete selection of HS400 */
  157. void (*hs400_complete)(struct mmc_host *host);
  158. /* Prepare enhanced strobe depending host driver */
  159. void (*hs400_enhanced_strobe)(struct mmc_host *host,
  160. struct mmc_ios *ios);
  161. int (*select_drive_strength)(struct mmc_card *card,
  162. unsigned int max_dtr, int host_drv,
  163. int card_drv, int *drv_type);
  164. /* Reset the eMMC card via RST_n */
  165. void (*card_hw_reset)(struct mmc_host *host);
  166. void (*card_event)(struct mmc_host *host);
  167. /*
  168. * Optional callback to support controllers with HW issues for multiple
  169. * I/O. Returns the number of supported blocks for the request.
  170. */
  171. int (*multi_io_quirk)(struct mmc_card *card,
  172. unsigned int direction, int blk_size);
  173. /* Initialize an SD express card, mandatory for MMC_CAP2_SD_EXP. */
  174. int (*init_sd_express)(struct mmc_host *host, struct mmc_ios *ios);
  175. ANDROID_KABI_RESERVE(1);
  176. ANDROID_KABI_RESERVE(2);
  177. };
  178. struct mmc_cqe_ops {
  179. /* Allocate resources, and make the CQE operational */
  180. int (*cqe_enable)(struct mmc_host *host, struct mmc_card *card);
  181. /* Free resources, and make the CQE non-operational */
  182. void (*cqe_disable)(struct mmc_host *host);
  183. /*
  184. * Issue a read, write or DCMD request to the CQE. Also deal with the
  185. * effect of ->cqe_off().
  186. */
  187. int (*cqe_request)(struct mmc_host *host, struct mmc_request *mrq);
  188. /* Free resources (e.g. DMA mapping) associated with the request */
  189. void (*cqe_post_req)(struct mmc_host *host, struct mmc_request *mrq);
  190. /*
  191. * Prepare the CQE and host controller to accept non-CQ commands. There
  192. * is no corresponding ->cqe_on(), instead ->cqe_request() is required
  193. * to deal with that.
  194. */
  195. void (*cqe_off)(struct mmc_host *host);
  196. /*
  197. * Wait for all CQE tasks to complete. Return an error if recovery
  198. * becomes necessary.
  199. */
  200. int (*cqe_wait_for_idle)(struct mmc_host *host);
  201. /*
  202. * Notify CQE that a request has timed out. Return false if the request
  203. * completed or true if a timeout happened in which case indicate if
  204. * recovery is needed.
  205. */
  206. bool (*cqe_timeout)(struct mmc_host *host, struct mmc_request *mrq,
  207. bool *recovery_needed);
  208. /*
  209. * Stop all CQE activity and prepare the CQE and host controller to
  210. * accept recovery commands.
  211. */
  212. void (*cqe_recovery_start)(struct mmc_host *host);
  213. /*
  214. * Clear the queue and call mmc_cqe_request_done() on all requests.
  215. * Requests that errored will have the error set on the mmc_request
  216. * (data->error or cmd->error for DCMD). Requests that did not error
  217. * will have zero data bytes transferred.
  218. */
  219. void (*cqe_recovery_finish)(struct mmc_host *host);
  220. ANDROID_KABI_RESERVE(1);
  221. ANDROID_KABI_RESERVE(2);
  222. };
  223. struct mmc_async_req {
  224. /* active mmc request */
  225. struct mmc_request *mrq;
  226. /*
  227. * Check error status of completed mmc request.
  228. * Returns 0 if success otherwise non zero.
  229. */
  230. enum mmc_blk_status (*err_check)(struct mmc_card *, struct mmc_async_req *);
  231. };
  232. /**
  233. * struct mmc_slot - MMC slot functions
  234. *
  235. * @cd_irq: MMC/SD-card slot hotplug detection IRQ or -EINVAL
  236. * @handler_priv: MMC/SD-card slot context
  237. *
  238. * Some MMC/SD host controllers implement slot-functions like card and
  239. * write-protect detection natively. However, a large number of controllers
  240. * leave these functions to the CPU. This struct provides a hook to attach
  241. * such slot-function drivers.
  242. */
  243. struct mmc_slot {
  244. int cd_irq;
  245. bool cd_wake_enabled;
  246. void *handler_priv;
  247. };
  248. /**
  249. * mmc_context_info - synchronization details for mmc context
  250. * @is_done_rcv wake up reason was done request
  251. * @is_new_req wake up reason was new request
  252. * @is_waiting_last_req mmc context waiting for single running request
  253. * @wait wait queue
  254. */
  255. struct mmc_context_info {
  256. bool is_done_rcv;
  257. bool is_new_req;
  258. bool is_waiting_last_req;
  259. wait_queue_head_t wait;
  260. };
  261. struct regulator;
  262. struct mmc_pwrseq;
  263. struct mmc_supply {
  264. struct regulator *vmmc; /* Card power supply */
  265. struct regulator *vqmmc; /* Optional Vccq supply */
  266. };
  267. struct mmc_ctx {
  268. struct task_struct *task;
  269. };
  270. struct mmc_host {
  271. struct device *parent;
  272. struct device class_dev;
  273. int index;
  274. const struct mmc_host_ops *ops;
  275. struct mmc_pwrseq *pwrseq;
  276. unsigned int f_min;
  277. unsigned int f_max;
  278. unsigned int f_init;
  279. u32 ocr_avail;
  280. u32 ocr_avail_sdio; /* SDIO-specific OCR */
  281. u32 ocr_avail_sd; /* SD-specific OCR */
  282. u32 ocr_avail_mmc; /* MMC-specific OCR */
  283. struct wakeup_source *ws; /* Enable consume of uevents */
  284. u32 max_current_330;
  285. u32 max_current_300;
  286. u32 max_current_180;
  287. #define MMC_VDD_165_195 0x00000080 /* VDD voltage 1.65 - 1.95 */
  288. #define MMC_VDD_20_21 0x00000100 /* VDD voltage 2.0 ~ 2.1 */
  289. #define MMC_VDD_21_22 0x00000200 /* VDD voltage 2.1 ~ 2.2 */
  290. #define MMC_VDD_22_23 0x00000400 /* VDD voltage 2.2 ~ 2.3 */
  291. #define MMC_VDD_23_24 0x00000800 /* VDD voltage 2.3 ~ 2.4 */
  292. #define MMC_VDD_24_25 0x00001000 /* VDD voltage 2.4 ~ 2.5 */
  293. #define MMC_VDD_25_26 0x00002000 /* VDD voltage 2.5 ~ 2.6 */
  294. #define MMC_VDD_26_27 0x00004000 /* VDD voltage 2.6 ~ 2.7 */
  295. #define MMC_VDD_27_28 0x00008000 /* VDD voltage 2.7 ~ 2.8 */
  296. #define MMC_VDD_28_29 0x00010000 /* VDD voltage 2.8 ~ 2.9 */
  297. #define MMC_VDD_29_30 0x00020000 /* VDD voltage 2.9 ~ 3.0 */
  298. #define MMC_VDD_30_31 0x00040000 /* VDD voltage 3.0 ~ 3.1 */
  299. #define MMC_VDD_31_32 0x00080000 /* VDD voltage 3.1 ~ 3.2 */
  300. #define MMC_VDD_32_33 0x00100000 /* VDD voltage 3.2 ~ 3.3 */
  301. #define MMC_VDD_33_34 0x00200000 /* VDD voltage 3.3 ~ 3.4 */
  302. #define MMC_VDD_34_35 0x00400000 /* VDD voltage 3.4 ~ 3.5 */
  303. #define MMC_VDD_35_36 0x00800000 /* VDD voltage 3.5 ~ 3.6 */
  304. u32 caps; /* Host capabilities */
  305. #define MMC_CAP_4_BIT_DATA (1 << 0) /* Can the host do 4 bit transfers */
  306. #define MMC_CAP_MMC_HIGHSPEED (1 << 1) /* Can do MMC high-speed timing */
  307. #define MMC_CAP_SD_HIGHSPEED (1 << 2) /* Can do SD high-speed timing */
  308. #define MMC_CAP_SDIO_IRQ (1 << 3) /* Can signal pending SDIO IRQs */
  309. #define MMC_CAP_SPI (1 << 4) /* Talks only SPI protocols */
  310. #define MMC_CAP_NEEDS_POLL (1 << 5) /* Needs polling for card-detection */
  311. #define MMC_CAP_8_BIT_DATA (1 << 6) /* Can the host do 8 bit transfers */
  312. #define MMC_CAP_AGGRESSIVE_PM (1 << 7) /* Suspend (e)MMC/SD at idle */
  313. #define MMC_CAP_NONREMOVABLE (1 << 8) /* Nonremovable e.g. eMMC */
  314. #define MMC_CAP_WAIT_WHILE_BUSY (1 << 9) /* Waits while card is busy */
  315. #define MMC_CAP_3_3V_DDR (1 << 11) /* Host supports eMMC DDR 3.3V */
  316. #define MMC_CAP_1_8V_DDR (1 << 12) /* Host supports eMMC DDR 1.8V */
  317. #define MMC_CAP_1_2V_DDR (1 << 13) /* Host supports eMMC DDR 1.2V */
  318. #define MMC_CAP_DDR (MMC_CAP_3_3V_DDR | MMC_CAP_1_8V_DDR | \
  319. MMC_CAP_1_2V_DDR)
  320. #define MMC_CAP_POWER_OFF_CARD (1 << 14) /* Can power off after boot */
  321. #define MMC_CAP_BUS_WIDTH_TEST (1 << 15) /* CMD14/CMD19 bus width ok */
  322. #define MMC_CAP_UHS_SDR12 (1 << 16) /* Host supports UHS SDR12 mode */
  323. #define MMC_CAP_UHS_SDR25 (1 << 17) /* Host supports UHS SDR25 mode */
  324. #define MMC_CAP_UHS_SDR50 (1 << 18) /* Host supports UHS SDR50 mode */
  325. #define MMC_CAP_UHS_SDR104 (1 << 19) /* Host supports UHS SDR104 mode */
  326. #define MMC_CAP_UHS_DDR50 (1 << 20) /* Host supports UHS DDR50 mode */
  327. #define MMC_CAP_UHS (MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 | \
  328. MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 | \
  329. MMC_CAP_UHS_DDR50)
  330. #define MMC_CAP_SYNC_RUNTIME_PM (1 << 21) /* Synced runtime PM suspends. */
  331. #define MMC_CAP_NEED_RSP_BUSY (1 << 22) /* Commands with R1B can't use R1. */
  332. #define MMC_CAP_DRIVER_TYPE_A (1 << 23) /* Host supports Driver Type A */
  333. #define MMC_CAP_DRIVER_TYPE_C (1 << 24) /* Host supports Driver Type C */
  334. #define MMC_CAP_DRIVER_TYPE_D (1 << 25) /* Host supports Driver Type D */
  335. #define MMC_CAP_DONE_COMPLETE (1 << 27) /* RW reqs can be completed within mmc_request_done() */
  336. #define MMC_CAP_CD_WAKE (1 << 28) /* Enable card detect wake */
  337. #define MMC_CAP_CMD_DURING_TFR (1 << 29) /* Commands during data transfer */
  338. #define MMC_CAP_CMD23 (1 << 30) /* CMD23 supported. */
  339. #define MMC_CAP_HW_RESET (1 << 31) /* Reset the eMMC card via RST_n */
  340. u32 caps2; /* More host capabilities */
  341. #define MMC_CAP2_BOOTPART_NOACC (1 << 0) /* Boot partition no access */
  342. #define MMC_CAP2_FULL_PWR_CYCLE (1 << 2) /* Can do full power cycle */
  343. #define MMC_CAP2_FULL_PWR_CYCLE_IN_SUSPEND (1 << 3) /* Can do full power cycle in suspend */
  344. #define MMC_CAP2_HS200_1_8V_SDR (1 << 5) /* can support */
  345. #define MMC_CAP2_HS200_1_2V_SDR (1 << 6) /* can support */
  346. #define MMC_CAP2_HS200 (MMC_CAP2_HS200_1_8V_SDR | \
  347. MMC_CAP2_HS200_1_2V_SDR)
  348. #define MMC_CAP2_SD_EXP (1 << 7) /* SD express via PCIe */
  349. #define MMC_CAP2_SD_EXP_1_2V (1 << 8) /* SD express 1.2V */
  350. #define MMC_CAP2_CD_ACTIVE_HIGH (1 << 10) /* Card-detect signal active high */
  351. #define MMC_CAP2_RO_ACTIVE_HIGH (1 << 11) /* Write-protect signal active high */
  352. #define MMC_CAP2_NO_PRESCAN_POWERUP (1 << 14) /* Don't power up before scan */
  353. #define MMC_CAP2_HS400_1_8V (1 << 15) /* Can support HS400 1.8V */
  354. #define MMC_CAP2_HS400_1_2V (1 << 16) /* Can support HS400 1.2V */
  355. #define MMC_CAP2_HS400 (MMC_CAP2_HS400_1_8V | \
  356. MMC_CAP2_HS400_1_2V)
  357. #define MMC_CAP2_HSX00_1_8V (MMC_CAP2_HS200_1_8V_SDR | MMC_CAP2_HS400_1_8V)
  358. #define MMC_CAP2_HSX00_1_2V (MMC_CAP2_HS200_1_2V_SDR | MMC_CAP2_HS400_1_2V)
  359. #define MMC_CAP2_SDIO_IRQ_NOTHREAD (1 << 17)
  360. #define MMC_CAP2_NO_WRITE_PROTECT (1 << 18) /* No physical write protect pin, assume that card is always read-write */
  361. #define MMC_CAP2_NO_SDIO (1 << 19) /* Do not send SDIO commands during initialization */
  362. #define MMC_CAP2_HS400_ES (1 << 20) /* Host supports enhanced strobe */
  363. #define MMC_CAP2_NO_SD (1 << 21) /* Do not send SD commands during initialization */
  364. #define MMC_CAP2_NO_MMC (1 << 22) /* Do not send (e)MMC commands during initialization */
  365. #define MMC_CAP2_CQE (1 << 23) /* Has eMMC command queue engine */
  366. #define MMC_CAP2_CQE_DCMD (1 << 24) /* CQE can issue a direct command */
  367. #define MMC_CAP2_AVOID_3_3V (1 << 25) /* Host must negotiate down from 3.3V */
  368. #define MMC_CAP2_MERGE_CAPABLE (1 << 26) /* Host can merge a segment over the segment size */
  369. #ifdef CONFIG_MMC_CRYPTO
  370. #define MMC_CAP2_CRYPTO (1 << 27) /* Host supports inline encryption */
  371. #else
  372. #define MMC_CAP2_CRYPTO 0
  373. #endif
  374. #define MMC_CAP2_ALT_GPT_TEGRA (1 << 28) /* Host with eMMC that has GPT entry at a non-standard location */
  375. int fixed_drv_type; /* fixed driver type for non-removable media */
  376. mmc_pm_flag_t pm_caps; /* supported pm features */
  377. /* host specific block data */
  378. unsigned int max_seg_size; /* see blk_queue_max_segment_size */
  379. unsigned short max_segs; /* see blk_queue_max_segments */
  380. unsigned short unused;
  381. unsigned int max_req_size; /* maximum number of bytes in one req */
  382. unsigned int max_blk_size; /* maximum size of one mmc block */
  383. unsigned int max_blk_count; /* maximum number of blocks in one req */
  384. unsigned int max_busy_timeout; /* max busy timeout in ms */
  385. /* private data */
  386. spinlock_t lock; /* lock for claim and bus ops */
  387. struct mmc_ios ios; /* current io bus settings */
  388. /* group bitfields together to minimize padding */
  389. unsigned int use_spi_crc:1;
  390. unsigned int claimed:1; /* host exclusively claimed */
  391. unsigned int doing_init_tune:1; /* initial tuning in progress */
  392. unsigned int can_retune:1; /* re-tuning can be used */
  393. unsigned int doing_retune:1; /* re-tuning in progress */
  394. unsigned int retune_now:1; /* do re-tuning at next req */
  395. unsigned int retune_paused:1; /* re-tuning is temporarily disabled */
  396. unsigned int retune_crc_disable:1; /* don't trigger retune upon crc */
  397. unsigned int can_dma_map_merge:1; /* merging can be used */
  398. int rescan_disable; /* disable card detection */
  399. int rescan_entered; /* used with nonremovable devices */
  400. int need_retune; /* re-tuning is needed */
  401. int hold_retune; /* hold off re-tuning */
  402. unsigned int retune_period; /* re-tuning period in secs */
  403. struct timer_list retune_timer; /* for periodic re-tuning */
  404. bool trigger_card_event; /* card_event necessary */
  405. struct mmc_card *card; /* device attached to this host */
  406. wait_queue_head_t wq;
  407. struct mmc_ctx *claimer; /* context that has host claimed */
  408. int claim_cnt; /* "claim" nesting count */
  409. struct mmc_ctx default_ctx; /* default context */
  410. struct delayed_work detect;
  411. int detect_change; /* card detect flag */
  412. struct mmc_slot slot;
  413. const struct mmc_bus_ops *bus_ops; /* current bus driver */
  414. unsigned int sdio_irqs;
  415. struct task_struct *sdio_irq_thread;
  416. struct work_struct sdio_irq_work;
  417. bool sdio_irq_pending;
  418. atomic_t sdio_irq_thread_abort;
  419. mmc_pm_flag_t pm_flags; /* requested pm features */
  420. struct led_trigger *led; /* activity led */
  421. #ifdef CONFIG_REGULATOR
  422. bool regulator_enabled; /* regulator state */
  423. #endif
  424. struct mmc_supply supply;
  425. struct dentry *debugfs_root;
  426. /* Ongoing data transfer that allows commands during transfer */
  427. struct mmc_request *ongoing_mrq;
  428. #ifdef CONFIG_FAIL_MMC_REQUEST
  429. struct fault_attr fail_mmc_request;
  430. #endif
  431. unsigned int actual_clock; /* Actual HC clock rate */
  432. unsigned int slotno; /* used for sdio acpi binding */
  433. int dsr_req; /* DSR value is valid */
  434. u32 dsr; /* optional driver stage (DSR) value */
  435. /* Command Queue Engine (CQE) support */
  436. const struct mmc_cqe_ops *cqe_ops;
  437. void *cqe_private;
  438. int cqe_qdepth;
  439. bool cqe_enabled;
  440. bool cqe_on;
  441. /* Inline encryption support */
  442. #ifdef CONFIG_MMC_CRYPTO
  443. struct blk_crypto_profile crypto_profile;
  444. #endif
  445. /* Host Software Queue support */
  446. bool hsq_enabled;
  447. u32 err_stats[MMC_ERR_MAX];
  448. ANDROID_KABI_RESERVE(1);
  449. ANDROID_KABI_RESERVE(2);
  450. unsigned long private[] ____cacheline_aligned;
  451. };
  452. struct device_node;
  453. struct mmc_host *mmc_alloc_host(int extra, struct device *);
  454. int mmc_add_host(struct mmc_host *);
  455. void mmc_remove_host(struct mmc_host *);
  456. void mmc_free_host(struct mmc_host *);
  457. void mmc_of_parse_clk_phase(struct mmc_host *host,
  458. struct mmc_clk_phase_map *map);
  459. int mmc_of_parse(struct mmc_host *host);
  460. int mmc_of_parse_voltage(struct mmc_host *host, u32 *mask);
  461. static inline void *mmc_priv(struct mmc_host *host)
  462. {
  463. return (void *)host->private;
  464. }
  465. static inline struct mmc_host *mmc_from_priv(void *priv)
  466. {
  467. return container_of(priv, struct mmc_host, private);
  468. }
  469. #define mmc_host_is_spi(host) ((host)->caps & MMC_CAP_SPI)
  470. #define mmc_dev(x) ((x)->parent)
  471. #define mmc_classdev(x) (&(x)->class_dev)
  472. #define mmc_hostname(x) (dev_name(&(x)->class_dev))
  473. void mmc_detect_change(struct mmc_host *, unsigned long delay);
  474. void mmc_request_done(struct mmc_host *, struct mmc_request *);
  475. void mmc_command_done(struct mmc_host *host, struct mmc_request *mrq);
  476. void mmc_cqe_request_done(struct mmc_host *host, struct mmc_request *mrq);
  477. /*
  478. * May be called from host driver's system/runtime suspend/resume callbacks,
  479. * to know if SDIO IRQs has been claimed.
  480. */
  481. static inline bool sdio_irq_claimed(struct mmc_host *host)
  482. {
  483. return host->sdio_irqs > 0;
  484. }
  485. static inline void mmc_signal_sdio_irq(struct mmc_host *host)
  486. {
  487. host->ops->enable_sdio_irq(host, 0);
  488. host->sdio_irq_pending = true;
  489. if (host->sdio_irq_thread)
  490. wake_up_process(host->sdio_irq_thread);
  491. }
  492. void sdio_signal_irq(struct mmc_host *host);
  493. #ifdef CONFIG_REGULATOR
  494. int mmc_regulator_set_ocr(struct mmc_host *mmc,
  495. struct regulator *supply,
  496. unsigned short vdd_bit);
  497. int mmc_regulator_set_vqmmc(struct mmc_host *mmc, struct mmc_ios *ios);
  498. #else
  499. static inline int mmc_regulator_set_ocr(struct mmc_host *mmc,
  500. struct regulator *supply,
  501. unsigned short vdd_bit)
  502. {
  503. return 0;
  504. }
  505. static inline int mmc_regulator_set_vqmmc(struct mmc_host *mmc,
  506. struct mmc_ios *ios)
  507. {
  508. return -EINVAL;
  509. }
  510. #endif
  511. int mmc_regulator_get_supply(struct mmc_host *mmc);
  512. static inline int mmc_card_is_removable(struct mmc_host *host)
  513. {
  514. return !(host->caps & MMC_CAP_NONREMOVABLE);
  515. }
  516. static inline int mmc_card_keep_power(struct mmc_host *host)
  517. {
  518. return host->pm_flags & MMC_PM_KEEP_POWER;
  519. }
  520. static inline int mmc_card_wake_sdio_irq(struct mmc_host *host)
  521. {
  522. return host->pm_flags & MMC_PM_WAKE_SDIO_IRQ;
  523. }
  524. /* TODO: Move to private header */
  525. static inline int mmc_card_hs(struct mmc_card *card)
  526. {
  527. return card->host->ios.timing == MMC_TIMING_SD_HS ||
  528. card->host->ios.timing == MMC_TIMING_MMC_HS;
  529. }
  530. /* TODO: Move to private header */
  531. static inline int mmc_card_uhs(struct mmc_card *card)
  532. {
  533. return card->host->ios.timing >= MMC_TIMING_UHS_SDR12 &&
  534. card->host->ios.timing <= MMC_TIMING_UHS_DDR50;
  535. }
  536. void mmc_retune_timer_stop(struct mmc_host *host);
  537. static inline void mmc_retune_needed(struct mmc_host *host)
  538. {
  539. if (host->can_retune)
  540. host->need_retune = 1;
  541. }
  542. static inline bool mmc_can_retune(struct mmc_host *host)
  543. {
  544. return host->can_retune == 1;
  545. }
  546. static inline bool mmc_doing_retune(struct mmc_host *host)
  547. {
  548. return host->doing_retune == 1;
  549. }
  550. static inline bool mmc_doing_tune(struct mmc_host *host)
  551. {
  552. return host->doing_retune == 1 || host->doing_init_tune == 1;
  553. }
  554. static inline enum dma_data_direction mmc_get_dma_dir(struct mmc_data *data)
  555. {
  556. return data->flags & MMC_DATA_WRITE ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
  557. }
  558. static inline void mmc_debugfs_err_stats_inc(struct mmc_host *host,
  559. enum mmc_err_stat stat)
  560. {
  561. host->err_stats[stat] += 1;
  562. }
  563. int mmc_send_tuning(struct mmc_host *host, u32 opcode, int *cmd_error);
  564. int mmc_send_abort_tuning(struct mmc_host *host, u32 opcode);
  565. int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd);
  566. #endif /* LINUX_MMC_HOST_H */