mmci.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. /*
  2. * linux/drivers/mmc/host/mmci.h - ARM PrimeCell MMCI PL180/1 driver
  3. *
  4. * Copyright (C) 2003 Deep Blue Solutions, Ltd, All Rights Reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #define MMCIPOWER 0x000
  11. #define MCI_PWR_OFF 0x00
  12. #define MCI_PWR_UP 0x02
  13. #define MCI_PWR_ON 0x03
  14. #define MCI_OD (1 << 6)
  15. #define MCI_ROD (1 << 7)
  16. /*
  17. * The ST Micro version does not have ROD and reuse the voltage registers for
  18. * direction settings.
  19. */
  20. #define MCI_ST_DATA2DIREN (1 << 2)
  21. #define MCI_ST_CMDDIREN (1 << 3)
  22. #define MCI_ST_DATA0DIREN (1 << 4)
  23. #define MCI_ST_DATA31DIREN (1 << 5)
  24. #define MCI_ST_FBCLKEN (1 << 7)
  25. #define MCI_ST_DATA74DIREN (1 << 8)
  26. /*
  27. * The STM32 sdmmc does not have PWR_UP/OD/ROD
  28. * and uses the power register for
  29. */
  30. #define MCI_STM32_PWR_CYC 0x02
  31. #define MCI_STM32_VSWITCH BIT(2)
  32. #define MCI_STM32_VSWITCHEN BIT(3)
  33. #define MCI_STM32_DIRPOL BIT(4)
  34. #define MMCICLOCK 0x004
  35. #define MCI_CLK_ENABLE (1 << 8)
  36. #define MCI_CLK_PWRSAVE (1 << 9)
  37. #define MCI_CLK_BYPASS (1 << 10)
  38. #define MCI_4BIT_BUS (1 << 11)
  39. /*
  40. * 8bit wide buses, hardware flow contronl, negative edges and clock inversion
  41. * supported in ST Micro U300 and Ux500 versions
  42. */
  43. #define MCI_ST_8BIT_BUS (1 << 12)
  44. #define MCI_ST_U300_HWFCEN (1 << 13)
  45. #define MCI_ST_UX500_NEG_EDGE (1 << 13)
  46. #define MCI_ST_UX500_HWFCEN (1 << 14)
  47. #define MCI_ST_UX500_CLK_INV (1 << 15)
  48. /* Modified PL180 on Versatile Express platform */
  49. #define MCI_ARM_HWFCEN (1 << 12)
  50. /* Modified on Qualcomm Integrations */
  51. #define MCI_QCOM_CLK_WIDEBUS_8 (BIT(10) | BIT(11))
  52. #define MCI_QCOM_CLK_FLOWENA BIT(12)
  53. #define MCI_QCOM_CLK_INVERTOUT BIT(13)
  54. /* select in latch data and command in */
  55. #define MCI_QCOM_CLK_SELECT_IN_FBCLK BIT(15)
  56. #define MCI_QCOM_CLK_SELECT_IN_DDR_MODE (BIT(14) | BIT(15))
  57. /* Modified on STM32 sdmmc */
  58. #define MCI_STM32_CLK_CLKDIV_MSK GENMASK(9, 0)
  59. #define MCI_STM32_CLK_WIDEBUS_4 BIT(14)
  60. #define MCI_STM32_CLK_WIDEBUS_8 BIT(15)
  61. #define MCI_STM32_CLK_NEGEDGE BIT(16)
  62. #define MCI_STM32_CLK_HWFCEN BIT(17)
  63. #define MCI_STM32_CLK_DDR BIT(18)
  64. #define MCI_STM32_CLK_BUSSPEED BIT(19)
  65. #define MCI_STM32_CLK_SEL_MSK GENMASK(21, 20)
  66. #define MCI_STM32_CLK_SELCK (0 << 20)
  67. #define MCI_STM32_CLK_SELCKIN (1 << 20)
  68. #define MCI_STM32_CLK_SELFBCK (2 << 20)
  69. #define MMCIARGUMENT 0x008
  70. /* The command register controls the Command Path State Machine (CPSM) */
  71. #define MMCICOMMAND 0x00c
  72. #define MCI_CPSM_RESPONSE BIT(6)
  73. #define MCI_CPSM_LONGRSP BIT(7)
  74. #define MCI_CPSM_INTERRUPT BIT(8)
  75. #define MCI_CPSM_PENDING BIT(9)
  76. #define MCI_CPSM_ENABLE BIT(10)
  77. /* Command register flag extenstions in the ST Micro versions */
  78. #define MCI_CPSM_ST_SDIO_SUSP BIT(11)
  79. #define MCI_CPSM_ST_ENCMD_COMPL BIT(12)
  80. #define MCI_CPSM_ST_NIEN BIT(13)
  81. #define MCI_CPSM_ST_CE_ATACMD BIT(14)
  82. /* Command register flag extensions in the Qualcomm versions */
  83. #define MCI_CPSM_QCOM_PROGENA BIT(11)
  84. #define MCI_CPSM_QCOM_DATCMD BIT(12)
  85. #define MCI_CPSM_QCOM_MCIABORT BIT(13)
  86. #define MCI_CPSM_QCOM_CCSENABLE BIT(14)
  87. #define MCI_CPSM_QCOM_CCSDISABLE BIT(15)
  88. #define MCI_CPSM_QCOM_AUTO_CMD19 BIT(16)
  89. #define MCI_CPSM_QCOM_AUTO_CMD21 BIT(21)
  90. /* Command register in STM32 sdmmc versions */
  91. #define MCI_CPSM_STM32_CMDTRANS BIT(6)
  92. #define MCI_CPSM_STM32_CMDSTOP BIT(7)
  93. #define MCI_CPSM_STM32_WAITRESP_MASK GENMASK(9, 8)
  94. #define MCI_CPSM_STM32_NORSP (0 << 8)
  95. #define MCI_CPSM_STM32_SRSP_CRC (1 << 8)
  96. #define MCI_CPSM_STM32_SRSP (2 << 8)
  97. #define MCI_CPSM_STM32_LRSP_CRC (3 << 8)
  98. #define MCI_CPSM_STM32_ENABLE BIT(12)
  99. #define MMCIRESPCMD 0x010
  100. #define MMCIRESPONSE0 0x014
  101. #define MMCIRESPONSE1 0x018
  102. #define MMCIRESPONSE2 0x01c
  103. #define MMCIRESPONSE3 0x020
  104. #define MMCIDATATIMER 0x024
  105. #define MMCIDATALENGTH 0x028
  106. /* The data control register controls the Data Path State Machine (DPSM) */
  107. #define MMCIDATACTRL 0x02c
  108. #define MCI_DPSM_ENABLE BIT(0)
  109. #define MCI_DPSM_DIRECTION BIT(1)
  110. #define MCI_DPSM_MODE BIT(2)
  111. #define MCI_DPSM_DMAENABLE BIT(3)
  112. #define MCI_DPSM_BLOCKSIZE BIT(4)
  113. /* Control register extensions in the ST Micro U300 and Ux500 versions */
  114. #define MCI_DPSM_ST_RWSTART BIT(8)
  115. #define MCI_DPSM_ST_RWSTOP BIT(9)
  116. #define MCI_DPSM_ST_RWMOD BIT(10)
  117. #define MCI_DPSM_ST_SDIOEN BIT(11)
  118. /* Control register extensions in the ST Micro Ux500 versions */
  119. #define MCI_DPSM_ST_DMAREQCTL BIT(12)
  120. #define MCI_DPSM_ST_DBOOTMODEEN BIT(13)
  121. #define MCI_DPSM_ST_BUSYMODE BIT(14)
  122. #define MCI_DPSM_ST_DDRMODE BIT(15)
  123. /* Control register extensions in the Qualcomm versions */
  124. #define MCI_DPSM_QCOM_DATA_PEND BIT(17)
  125. #define MCI_DPSM_QCOM_RX_DATA_PEND BIT(20)
  126. #define MMCIDATACNT 0x030
  127. #define MMCISTATUS 0x034
  128. #define MCI_CMDCRCFAIL (1 << 0)
  129. #define MCI_DATACRCFAIL (1 << 1)
  130. #define MCI_CMDTIMEOUT (1 << 2)
  131. #define MCI_DATATIMEOUT (1 << 3)
  132. #define MCI_TXUNDERRUN (1 << 4)
  133. #define MCI_RXOVERRUN (1 << 5)
  134. #define MCI_CMDRESPEND (1 << 6)
  135. #define MCI_CMDSENT (1 << 7)
  136. #define MCI_DATAEND (1 << 8)
  137. #define MCI_STARTBITERR (1 << 9)
  138. #define MCI_DATABLOCKEND (1 << 10)
  139. #define MCI_CMDACTIVE (1 << 11)
  140. #define MCI_TXACTIVE (1 << 12)
  141. #define MCI_RXACTIVE (1 << 13)
  142. #define MCI_TXFIFOHALFEMPTY (1 << 14)
  143. #define MCI_RXFIFOHALFFULL (1 << 15)
  144. #define MCI_TXFIFOFULL (1 << 16)
  145. #define MCI_RXFIFOFULL (1 << 17)
  146. #define MCI_TXFIFOEMPTY (1 << 18)
  147. #define MCI_RXFIFOEMPTY (1 << 19)
  148. #define MCI_TXDATAAVLBL (1 << 20)
  149. #define MCI_RXDATAAVLBL (1 << 21)
  150. /* Extended status bits for the ST Micro variants */
  151. #define MCI_ST_SDIOIT (1 << 22)
  152. #define MCI_ST_CEATAEND (1 << 23)
  153. #define MCI_ST_CARDBUSY (1 << 24)
  154. /* Extended status bits for the STM32 variants */
  155. #define MCI_STM32_BUSYD0 BIT(20)
  156. #define MMCICLEAR 0x038
  157. #define MCI_CMDCRCFAILCLR (1 << 0)
  158. #define MCI_DATACRCFAILCLR (1 << 1)
  159. #define MCI_CMDTIMEOUTCLR (1 << 2)
  160. #define MCI_DATATIMEOUTCLR (1 << 3)
  161. #define MCI_TXUNDERRUNCLR (1 << 4)
  162. #define MCI_RXOVERRUNCLR (1 << 5)
  163. #define MCI_CMDRESPENDCLR (1 << 6)
  164. #define MCI_CMDSENTCLR (1 << 7)
  165. #define MCI_DATAENDCLR (1 << 8)
  166. #define MCI_STARTBITERRCLR (1 << 9)
  167. #define MCI_DATABLOCKENDCLR (1 << 10)
  168. /* Extended status bits for the ST Micro variants */
  169. #define MCI_ST_SDIOITC (1 << 22)
  170. #define MCI_ST_CEATAENDC (1 << 23)
  171. #define MCI_ST_BUSYENDC (1 << 24)
  172. #define MMCIMASK0 0x03c
  173. #define MCI_CMDCRCFAILMASK (1 << 0)
  174. #define MCI_DATACRCFAILMASK (1 << 1)
  175. #define MCI_CMDTIMEOUTMASK (1 << 2)
  176. #define MCI_DATATIMEOUTMASK (1 << 3)
  177. #define MCI_TXUNDERRUNMASK (1 << 4)
  178. #define MCI_RXOVERRUNMASK (1 << 5)
  179. #define MCI_CMDRESPENDMASK (1 << 6)
  180. #define MCI_CMDSENTMASK (1 << 7)
  181. #define MCI_DATAENDMASK (1 << 8)
  182. #define MCI_STARTBITERRMASK (1 << 9)
  183. #define MCI_DATABLOCKENDMASK (1 << 10)
  184. #define MCI_CMDACTIVEMASK (1 << 11)
  185. #define MCI_TXACTIVEMASK (1 << 12)
  186. #define MCI_RXACTIVEMASK (1 << 13)
  187. #define MCI_TXFIFOHALFEMPTYMASK (1 << 14)
  188. #define MCI_RXFIFOHALFFULLMASK (1 << 15)
  189. #define MCI_TXFIFOFULLMASK (1 << 16)
  190. #define MCI_RXFIFOFULLMASK (1 << 17)
  191. #define MCI_TXFIFOEMPTYMASK (1 << 18)
  192. #define MCI_RXFIFOEMPTYMASK (1 << 19)
  193. #define MCI_TXDATAAVLBLMASK (1 << 20)
  194. #define MCI_RXDATAAVLBLMASK (1 << 21)
  195. /* Extended status bits for the ST Micro variants */
  196. #define MCI_ST_SDIOITMASK (1 << 22)
  197. #define MCI_ST_CEATAENDMASK (1 << 23)
  198. #define MCI_ST_BUSYENDMASK (1 << 24)
  199. /* Extended status bits for the STM32 variants */
  200. #define MCI_STM32_BUSYD0ENDMASK BIT(21)
  201. #define MMCIMASK1 0x040
  202. #define MMCIFIFOCNT 0x048
  203. #define MMCIFIFO 0x080 /* to 0x0bc */
  204. /* STM32 sdmmc registers for IDMA (Internal DMA) */
  205. #define MMCI_STM32_IDMACTRLR 0x050
  206. #define MMCI_STM32_IDMAEN BIT(0)
  207. #define MMCI_STM32_IDMALLIEN BIT(1)
  208. #define MMCI_STM32_IDMABSIZER 0x054
  209. #define MMCI_STM32_IDMABNDT_SHIFT 5
  210. #define MMCI_STM32_IDMABNDT_MASK GENMASK(12, 5)
  211. #define MMCI_STM32_IDMABASE0R 0x058
  212. #define MMCI_STM32_IDMALAR 0x64
  213. #define MMCI_STM32_IDMALA_MASK GENMASK(13, 0)
  214. #define MMCI_STM32_ABR BIT(29)
  215. #define MMCI_STM32_ULS BIT(30)
  216. #define MMCI_STM32_ULA BIT(31)
  217. #define MMCI_STM32_IDMABAR 0x68
  218. #define MCI_IRQENABLE \
  219. (MCI_CMDCRCFAILMASK | MCI_DATACRCFAILMASK | MCI_CMDTIMEOUTMASK | \
  220. MCI_DATATIMEOUTMASK | MCI_TXUNDERRUNMASK | MCI_RXOVERRUNMASK | \
  221. MCI_CMDRESPENDMASK | MCI_CMDSENTMASK)
  222. /* These interrupts are directed to IRQ1 when two IRQ lines are available */
  223. #define MCI_IRQ_PIO_MASK \
  224. (MCI_RXFIFOHALFFULLMASK | MCI_RXDATAAVLBLMASK | \
  225. MCI_TXFIFOHALFEMPTYMASK)
  226. #define MCI_IRQ_PIO_STM32_MASK \
  227. (MCI_RXFIFOHALFFULLMASK | MCI_TXFIFOHALFEMPTYMASK)
  228. #define NR_SG 128
  229. #define MMCI_PINCTRL_STATE_OPENDRAIN "opendrain"
  230. struct clk;
  231. struct dma_chan;
  232. struct mmci_host;
  233. /**
  234. * struct variant_data - MMCI variant-specific quirks
  235. * @clkreg: default value for MCICLOCK register
  236. * @clkreg_enable: enable value for MMCICLOCK register
  237. * @clkreg_8bit_bus_enable: enable value for 8 bit bus
  238. * @clkreg_neg_edge_enable: enable value for inverted data/cmd output
  239. * @cmdreg_cpsm_enable: enable value for CPSM
  240. * @cmdreg_lrsp_crc: enable value for long response with crc
  241. * @cmdreg_srsp_crc: enable value for short response with crc
  242. * @cmdreg_srsp: enable value for short response without crc
  243. * @datalength_bits: number of bits in the MMCIDATALENGTH register
  244. * @fifosize: number of bytes that can be written when MMCI_TXFIFOEMPTY
  245. * is asserted (likewise for RX)
  246. * @fifohalfsize: number of bytes that can be written when MCI_TXFIFOHALFEMPTY
  247. * is asserted (likewise for RX)
  248. * @data_cmd_enable: enable value for data commands.
  249. * @st_sdio: enable ST specific SDIO logic
  250. * @st_clkdiv: true if using a ST-specific clock divider algorithm
  251. * @stm32_clkdiv: true if using a STM32-specific clock divider algorithm
  252. * @datactrl_mask_ddrmode: ddr mode mask in datactrl register.
  253. * @blksz_datactrl16: true if Block size is at b16..b30 position in datactrl register
  254. * @blksz_datactrl4: true if Block size is at b4..b16 position in datactrl
  255. * register
  256. * @datactrl_mask_sdio: SDIO enable mask in datactrl register
  257. * @datactrl_blksz: block size in power of two
  258. * @datactrl_dpsm_enable: enable value for DPSM
  259. * @datactrl_first: true if data must be setup before send command
  260. * @datacnt_useless: true if you could not use datacnt register to read
  261. * remaining data
  262. * @pwrreg_powerup: power up value for MMCIPOWER register
  263. * @f_max: maximum clk frequency supported by the controller.
  264. * @signal_direction: input/out direction of bus signals can be indicated
  265. * @pwrreg_clkgate: MMCIPOWER register must be used to gate the clock
  266. * @busy_detect: true if the variant supports busy detection on DAT0.
  267. * @busy_dpsm_flag: bitmask enabling busy detection in the DPSM
  268. * @busy_detect_flag: bitmask identifying the bit in the MMCISTATUS register
  269. * indicating that the card is busy
  270. * @busy_detect_mask: bitmask identifying the bit in the MMCIMASK0 to mask for
  271. * getting busy end detection interrupts
  272. * @pwrreg_nopower: bits in MMCIPOWER don't controls ext. power supply
  273. * @explicit_mclk_control: enable explicit mclk control in driver.
  274. * @qcom_fifo: enables qcom specific fifo pio read logic.
  275. * @qcom_dml: enables qcom specific dma glue for dma transfers.
  276. * @reversed_irq_handling: handle data irq before cmd irq.
  277. * @mmcimask1: true if variant have a MMCIMASK1 register.
  278. * @irq_pio_mask: bitmask used to manage interrupt pio transfert in mmcimask
  279. * register
  280. * @start_err: bitmask identifying the STARTBITERR bit inside MMCISTATUS
  281. * register.
  282. * @opendrain: bitmask identifying the OPENDRAIN bit inside MMCIPOWER register
  283. * @dma_lli: true if variant has dma link list feature.
  284. * @stm32_idmabsize_mask: stm32 sdmmc idma buffer size.
  285. */
  286. struct variant_data {
  287. unsigned int clkreg;
  288. unsigned int clkreg_enable;
  289. unsigned int clkreg_8bit_bus_enable;
  290. unsigned int clkreg_neg_edge_enable;
  291. unsigned int cmdreg_cpsm_enable;
  292. unsigned int cmdreg_lrsp_crc;
  293. unsigned int cmdreg_srsp_crc;
  294. unsigned int cmdreg_srsp;
  295. unsigned int datalength_bits;
  296. unsigned int fifosize;
  297. unsigned int fifohalfsize;
  298. unsigned int data_cmd_enable;
  299. unsigned int datactrl_mask_ddrmode;
  300. unsigned int datactrl_mask_sdio;
  301. unsigned int datactrl_blocksz;
  302. unsigned int datactrl_dpsm_enable;
  303. u8 datactrl_first:1;
  304. u8 datacnt_useless:1;
  305. u8 st_sdio:1;
  306. u8 st_clkdiv:1;
  307. u8 stm32_clkdiv:1;
  308. u8 blksz_datactrl16:1;
  309. u8 blksz_datactrl4:1;
  310. u32 pwrreg_powerup;
  311. u32 f_max;
  312. u8 signal_direction:1;
  313. u8 pwrreg_clkgate:1;
  314. u8 busy_detect:1;
  315. u32 busy_dpsm_flag;
  316. u32 busy_detect_flag;
  317. u32 busy_detect_mask;
  318. u8 pwrreg_nopower:1;
  319. u8 explicit_mclk_control:1;
  320. u8 qcom_fifo:1;
  321. u8 qcom_dml:1;
  322. u8 reversed_irq_handling:1;
  323. u8 mmcimask1:1;
  324. unsigned int irq_pio_mask;
  325. u32 start_err;
  326. u32 opendrain;
  327. u8 dma_lli:1;
  328. u32 stm32_idmabsize_mask;
  329. void (*init)(struct mmci_host *host);
  330. };
  331. /* mmci variant callbacks */
  332. struct mmci_host_ops {
  333. int (*validate_data)(struct mmci_host *host, struct mmc_data *data);
  334. int (*prep_data)(struct mmci_host *host, struct mmc_data *data,
  335. bool next);
  336. void (*unprep_data)(struct mmci_host *host, struct mmc_data *data,
  337. int err);
  338. void (*get_next_data)(struct mmci_host *host, struct mmc_data *data);
  339. int (*dma_setup)(struct mmci_host *host);
  340. void (*dma_release)(struct mmci_host *host);
  341. int (*dma_start)(struct mmci_host *host, unsigned int *datactrl);
  342. void (*dma_finalize)(struct mmci_host *host, struct mmc_data *data);
  343. void (*dma_error)(struct mmci_host *host);
  344. void (*set_clkreg)(struct mmci_host *host, unsigned int desired);
  345. void (*set_pwrreg)(struct mmci_host *host, unsigned int pwr);
  346. };
  347. struct mmci_host {
  348. phys_addr_t phybase;
  349. void __iomem *base;
  350. struct mmc_request *mrq;
  351. struct mmc_command *cmd;
  352. struct mmc_data *data;
  353. struct mmc_host *mmc;
  354. struct clk *clk;
  355. u8 singleirq:1;
  356. struct reset_control *rst;
  357. spinlock_t lock;
  358. unsigned int mclk;
  359. /* cached value of requested clk in set_ios */
  360. unsigned int clock_cache;
  361. unsigned int cclk;
  362. u32 pwr_reg;
  363. u32 pwr_reg_add;
  364. u32 clk_reg;
  365. u32 clk_reg_add;
  366. u32 datactrl_reg;
  367. u32 busy_status;
  368. u32 mask1_reg;
  369. u8 vqmmc_enabled:1;
  370. struct mmci_platform_data *plat;
  371. struct mmci_host_ops *ops;
  372. struct variant_data *variant;
  373. struct pinctrl *pinctrl;
  374. struct pinctrl_state *pins_default;
  375. struct pinctrl_state *pins_opendrain;
  376. u8 hw_designer;
  377. u8 hw_revision:4;
  378. struct timer_list timer;
  379. unsigned int oldstat;
  380. /* pio stuff */
  381. struct sg_mapping_iter sg_miter;
  382. unsigned int size;
  383. int (*get_rx_fifocnt)(struct mmci_host *h, u32 status, int remain);
  384. u8 use_dma:1;
  385. u8 dma_in_progress:1;
  386. void *dma_priv;
  387. s32 next_cookie;
  388. };
  389. #define dma_inprogress(host) ((host)->dma_in_progress)
  390. void mmci_write_clkreg(struct mmci_host *host, u32 clk);
  391. void mmci_write_pwrreg(struct mmci_host *host, u32 pwr);
  392. int mmci_dmae_prep_data(struct mmci_host *host, struct mmc_data *data,
  393. bool next);
  394. void mmci_dmae_unprep_data(struct mmci_host *host, struct mmc_data *data,
  395. int err);
  396. void mmci_dmae_get_next_data(struct mmci_host *host, struct mmc_data *data);
  397. int mmci_dmae_setup(struct mmci_host *host);
  398. void mmci_dmae_release(struct mmci_host *host);
  399. int mmci_dmae_start(struct mmci_host *host, unsigned int *datactrl);
  400. void mmci_dmae_finalize(struct mmci_host *host, struct mmc_data *data);
  401. void mmci_dmae_error(struct mmci_host *host);