sdhci-esdhc-imx.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110
  1. /*
  2. * Freescale eSDHC i.MX controller driver for the platform bus.
  3. *
  4. * derived from the OF-version.
  5. *
  6. * Copyright (c) 2010 Pengutronix e.K.
  7. * Author: Wolfram Sang <w.sang@pengutronix.de>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License.
  12. */
  13. #include <linux/io.h>
  14. #include <linux/delay.h>
  15. #include <linux/err.h>
  16. #include <linux/clk.h>
  17. #include <linux/gpio.h>
  18. #include <linux/module.h>
  19. #include <linux/slab.h>
  20. #include <linux/mmc/host.h>
  21. #include <linux/mmc/mmc.h>
  22. #include <linux/mmc/sdio.h>
  23. #include <linux/mmc/slot-gpio.h>
  24. #include <linux/of.h>
  25. #include <linux/of_device.h>
  26. #include <linux/of_gpio.h>
  27. #include <linux/pinctrl/consumer.h>
  28. #include <linux/platform_data/mmc-esdhc-imx.h>
  29. #include "sdhci-pltfm.h"
  30. #include "sdhci-esdhc.h"
  31. #define ESDHC_CTRL_D3CD 0x08
  32. /* VENDOR SPEC register */
  33. #define ESDHC_VENDOR_SPEC 0xc0
  34. #define ESDHC_VENDOR_SPEC_SDIO_QUIRK (1 << 1)
  35. #define ESDHC_VENDOR_SPEC_VSELECT (1 << 1)
  36. #define ESDHC_VENDOR_SPEC_FRC_SDCLK_ON (1 << 8)
  37. #define ESDHC_WTMK_LVL 0x44
  38. #define ESDHC_MIX_CTRL 0x48
  39. #define ESDHC_MIX_CTRL_AC23EN (1 << 7)
  40. #define ESDHC_MIX_CTRL_EXE_TUNE (1 << 22)
  41. #define ESDHC_MIX_CTRL_SMPCLK_SEL (1 << 23)
  42. #define ESDHC_MIX_CTRL_FBCLK_SEL (1 << 25)
  43. /* Bits 3 and 6 are not SDHCI standard definitions */
  44. #define ESDHC_MIX_CTRL_SDHCI_MASK 0xb7
  45. /* tune control register */
  46. #define ESDHC_TUNE_CTRL_STATUS 0x68
  47. #define ESDHC_TUNE_CTRL_STEP 1
  48. #define ESDHC_TUNE_CTRL_MIN 0
  49. #define ESDHC_TUNE_CTRL_MAX ((1 << 7) - 1)
  50. #define ESDHC_TUNING_CTRL 0xcc
  51. #define ESDHC_STD_TUNING_EN (1 << 24)
  52. /* NOTE: the minimum valid tuning start tap for mx6sl is 1 */
  53. #define ESDHC_TUNING_START_TAP 0x1
  54. #define ESDHC_TUNING_BLOCK_PATTERN_LEN 64
  55. /* pinctrl state */
  56. #define ESDHC_PINCTRL_STATE_100MHZ "state_100mhz"
  57. #define ESDHC_PINCTRL_STATE_200MHZ "state_200mhz"
  58. /*
  59. * Our interpretation of the SDHCI_HOST_CONTROL register
  60. */
  61. #define ESDHC_CTRL_4BITBUS (0x1 << 1)
  62. #define ESDHC_CTRL_8BITBUS (0x2 << 1)
  63. #define ESDHC_CTRL_BUSWIDTH_MASK (0x3 << 1)
  64. /*
  65. * There is an INT DMA ERR mis-match between eSDHC and STD SDHC SPEC:
  66. * Bit25 is used in STD SPEC, and is reserved in fsl eSDHC design,
  67. * but bit28 is used as the INT DMA ERR in fsl eSDHC design.
  68. * Define this macro DMA error INT for fsl eSDHC
  69. */
  70. #define ESDHC_INT_VENDOR_SPEC_DMA_ERR (1 << 28)
  71. /*
  72. * The CMDTYPE of the CMD register (offset 0xE) should be set to
  73. * "11" when the STOP CMD12 is issued on imx53 to abort one
  74. * open ended multi-blk IO. Otherwise the TC INT wouldn't
  75. * be generated.
  76. * In exact block transfer, the controller doesn't complete the
  77. * operations automatically as required at the end of the
  78. * transfer and remains on hold if the abort command is not sent.
  79. * As a result, the TC flag is not asserted and SW received timeout
  80. * exeception. Bit1 of Vendor Spec registor is used to fix it.
  81. */
  82. #define ESDHC_FLAG_MULTIBLK_NO_INT BIT(1)
  83. /*
  84. * The flag enables the workaround for ESDHC errata ENGcm07207 which
  85. * affects i.MX25 and i.MX35.
  86. */
  87. #define ESDHC_FLAG_ENGCM07207 BIT(2)
  88. /*
  89. * The flag tells that the ESDHC controller is an USDHC block that is
  90. * integrated on the i.MX6 series.
  91. */
  92. #define ESDHC_FLAG_USDHC BIT(3)
  93. /* The IP supports manual tuning process */
  94. #define ESDHC_FLAG_MAN_TUNING BIT(4)
  95. /* The IP supports standard tuning process */
  96. #define ESDHC_FLAG_STD_TUNING BIT(5)
  97. /* The IP has SDHCI_CAPABILITIES_1 register */
  98. #define ESDHC_FLAG_HAVE_CAP1 BIT(6)
  99. struct esdhc_soc_data {
  100. u32 flags;
  101. };
  102. static struct esdhc_soc_data esdhc_imx25_data = {
  103. .flags = ESDHC_FLAG_ENGCM07207,
  104. };
  105. static struct esdhc_soc_data esdhc_imx35_data = {
  106. .flags = ESDHC_FLAG_ENGCM07207,
  107. };
  108. static struct esdhc_soc_data esdhc_imx51_data = {
  109. .flags = 0,
  110. };
  111. static struct esdhc_soc_data esdhc_imx53_data = {
  112. .flags = ESDHC_FLAG_MULTIBLK_NO_INT,
  113. };
  114. static struct esdhc_soc_data usdhc_imx6q_data = {
  115. .flags = ESDHC_FLAG_USDHC | ESDHC_FLAG_MAN_TUNING,
  116. };
  117. static struct esdhc_soc_data usdhc_imx6sl_data = {
  118. .flags = ESDHC_FLAG_USDHC | ESDHC_FLAG_STD_TUNING
  119. | ESDHC_FLAG_HAVE_CAP1,
  120. };
  121. struct pltfm_imx_data {
  122. u32 scratchpad;
  123. struct pinctrl *pinctrl;
  124. struct pinctrl_state *pins_default;
  125. struct pinctrl_state *pins_100mhz;
  126. struct pinctrl_state *pins_200mhz;
  127. const struct esdhc_soc_data *socdata;
  128. struct esdhc_platform_data boarddata;
  129. struct clk *clk_ipg;
  130. struct clk *clk_ahb;
  131. struct clk *clk_per;
  132. enum {
  133. NO_CMD_PENDING, /* no multiblock command pending*/
  134. MULTIBLK_IN_PROCESS, /* exact multiblock cmd in process */
  135. WAIT_FOR_INT, /* sent CMD12, waiting for response INT */
  136. } multiblock_status;
  137. u32 uhs_mode;
  138. };
  139. static struct platform_device_id imx_esdhc_devtype[] = {
  140. {
  141. .name = "sdhci-esdhc-imx25",
  142. .driver_data = (kernel_ulong_t) &esdhc_imx25_data,
  143. }, {
  144. .name = "sdhci-esdhc-imx35",
  145. .driver_data = (kernel_ulong_t) &esdhc_imx35_data,
  146. }, {
  147. .name = "sdhci-esdhc-imx51",
  148. .driver_data = (kernel_ulong_t) &esdhc_imx51_data,
  149. }, {
  150. /* sentinel */
  151. }
  152. };
  153. MODULE_DEVICE_TABLE(platform, imx_esdhc_devtype);
  154. static const struct of_device_id imx_esdhc_dt_ids[] = {
  155. { .compatible = "fsl,imx25-esdhc", .data = &esdhc_imx25_data, },
  156. { .compatible = "fsl,imx35-esdhc", .data = &esdhc_imx35_data, },
  157. { .compatible = "fsl,imx51-esdhc", .data = &esdhc_imx51_data, },
  158. { .compatible = "fsl,imx53-esdhc", .data = &esdhc_imx53_data, },
  159. { .compatible = "fsl,imx6sl-usdhc", .data = &usdhc_imx6sl_data, },
  160. { .compatible = "fsl,imx6q-usdhc", .data = &usdhc_imx6q_data, },
  161. { /* sentinel */ }
  162. };
  163. MODULE_DEVICE_TABLE(of, imx_esdhc_dt_ids);
  164. static inline int is_imx25_esdhc(struct pltfm_imx_data *data)
  165. {
  166. return data->socdata == &esdhc_imx25_data;
  167. }
  168. static inline int is_imx53_esdhc(struct pltfm_imx_data *data)
  169. {
  170. return data->socdata == &esdhc_imx53_data;
  171. }
  172. static inline int is_imx6q_usdhc(struct pltfm_imx_data *data)
  173. {
  174. return data->socdata == &usdhc_imx6q_data;
  175. }
  176. static inline int esdhc_is_usdhc(struct pltfm_imx_data *data)
  177. {
  178. return !!(data->socdata->flags & ESDHC_FLAG_USDHC);
  179. }
  180. static inline void esdhc_clrset_le(struct sdhci_host *host, u32 mask, u32 val, int reg)
  181. {
  182. void __iomem *base = host->ioaddr + (reg & ~0x3);
  183. u32 shift = (reg & 0x3) * 8;
  184. writel(((readl(base) & ~(mask << shift)) | (val << shift)), base);
  185. }
  186. static u32 esdhc_readl_le(struct sdhci_host *host, int reg)
  187. {
  188. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  189. struct pltfm_imx_data *imx_data = pltfm_host->priv;
  190. u32 val = readl(host->ioaddr + reg);
  191. if (unlikely(reg == SDHCI_PRESENT_STATE)) {
  192. u32 fsl_prss = val;
  193. /* save the least 20 bits */
  194. val = fsl_prss & 0x000FFFFF;
  195. /* move dat[0-3] bits */
  196. val |= (fsl_prss & 0x0F000000) >> 4;
  197. /* move cmd line bit */
  198. val |= (fsl_prss & 0x00800000) << 1;
  199. }
  200. if (unlikely(reg == SDHCI_CAPABILITIES)) {
  201. /* ignore bit[0-15] as it stores cap_1 register val for mx6sl */
  202. if (imx_data->socdata->flags & ESDHC_FLAG_HAVE_CAP1)
  203. val &= 0xffff0000;
  204. /* In FSL esdhc IC module, only bit20 is used to indicate the
  205. * ADMA2 capability of esdhc, but this bit is messed up on
  206. * some SOCs (e.g. on MX25, MX35 this bit is set, but they
  207. * don't actually support ADMA2). So set the BROKEN_ADMA
  208. * uirk on MX25/35 platforms.
  209. */
  210. if (val & SDHCI_CAN_DO_ADMA1) {
  211. val &= ~SDHCI_CAN_DO_ADMA1;
  212. val |= SDHCI_CAN_DO_ADMA2;
  213. }
  214. }
  215. if (unlikely(reg == SDHCI_CAPABILITIES_1)) {
  216. if (esdhc_is_usdhc(imx_data)) {
  217. if (imx_data->socdata->flags & ESDHC_FLAG_HAVE_CAP1)
  218. val = readl(host->ioaddr + SDHCI_CAPABILITIES) & 0xFFFF;
  219. else
  220. /* imx6q/dl does not have cap_1 register, fake one */
  221. val = SDHCI_SUPPORT_DDR50 | SDHCI_SUPPORT_SDR104
  222. | SDHCI_SUPPORT_SDR50;
  223. }
  224. }
  225. if (unlikely(reg == SDHCI_MAX_CURRENT) && esdhc_is_usdhc(imx_data)) {
  226. val = 0;
  227. val |= 0xFF << SDHCI_MAX_CURRENT_330_SHIFT;
  228. val |= 0xFF << SDHCI_MAX_CURRENT_300_SHIFT;
  229. val |= 0xFF << SDHCI_MAX_CURRENT_180_SHIFT;
  230. }
  231. if (unlikely(reg == SDHCI_INT_STATUS)) {
  232. if (val & ESDHC_INT_VENDOR_SPEC_DMA_ERR) {
  233. val &= ~ESDHC_INT_VENDOR_SPEC_DMA_ERR;
  234. val |= SDHCI_INT_ADMA_ERROR;
  235. }
  236. /*
  237. * mask off the interrupt we get in response to the manually
  238. * sent CMD12
  239. */
  240. if ((imx_data->multiblock_status == WAIT_FOR_INT) &&
  241. ((val & SDHCI_INT_RESPONSE) == SDHCI_INT_RESPONSE)) {
  242. val &= ~SDHCI_INT_RESPONSE;
  243. writel(SDHCI_INT_RESPONSE, host->ioaddr +
  244. SDHCI_INT_STATUS);
  245. imx_data->multiblock_status = NO_CMD_PENDING;
  246. }
  247. }
  248. return val;
  249. }
  250. static void esdhc_writel_le(struct sdhci_host *host, u32 val, int reg)
  251. {
  252. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  253. struct pltfm_imx_data *imx_data = pltfm_host->priv;
  254. u32 data;
  255. if (unlikely(reg == SDHCI_INT_ENABLE || reg == SDHCI_SIGNAL_ENABLE)) {
  256. if (val & SDHCI_INT_CARD_INT) {
  257. /*
  258. * Clear and then set D3CD bit to avoid missing the
  259. * card interrupt. This is a eSDHC controller problem
  260. * so we need to apply the following workaround: clear
  261. * and set D3CD bit will make eSDHC re-sample the card
  262. * interrupt. In case a card interrupt was lost,
  263. * re-sample it by the following steps.
  264. */
  265. data = readl(host->ioaddr + SDHCI_HOST_CONTROL);
  266. data &= ~ESDHC_CTRL_D3CD;
  267. writel(data, host->ioaddr + SDHCI_HOST_CONTROL);
  268. data |= ESDHC_CTRL_D3CD;
  269. writel(data, host->ioaddr + SDHCI_HOST_CONTROL);
  270. }
  271. }
  272. if (unlikely((imx_data->socdata->flags & ESDHC_FLAG_MULTIBLK_NO_INT)
  273. && (reg == SDHCI_INT_STATUS)
  274. && (val & SDHCI_INT_DATA_END))) {
  275. u32 v;
  276. v = readl(host->ioaddr + ESDHC_VENDOR_SPEC);
  277. v &= ~ESDHC_VENDOR_SPEC_SDIO_QUIRK;
  278. writel(v, host->ioaddr + ESDHC_VENDOR_SPEC);
  279. if (imx_data->multiblock_status == MULTIBLK_IN_PROCESS)
  280. {
  281. /* send a manual CMD12 with RESPTYP=none */
  282. data = MMC_STOP_TRANSMISSION << 24 |
  283. SDHCI_CMD_ABORTCMD << 16;
  284. writel(data, host->ioaddr + SDHCI_TRANSFER_MODE);
  285. imx_data->multiblock_status = WAIT_FOR_INT;
  286. }
  287. }
  288. if (unlikely(reg == SDHCI_INT_ENABLE || reg == SDHCI_SIGNAL_ENABLE)) {
  289. if (val & SDHCI_INT_ADMA_ERROR) {
  290. val &= ~SDHCI_INT_ADMA_ERROR;
  291. val |= ESDHC_INT_VENDOR_SPEC_DMA_ERR;
  292. }
  293. }
  294. writel(val, host->ioaddr + reg);
  295. }
  296. static u16 esdhc_readw_le(struct sdhci_host *host, int reg)
  297. {
  298. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  299. struct pltfm_imx_data *imx_data = pltfm_host->priv;
  300. u16 ret = 0;
  301. u32 val;
  302. if (unlikely(reg == SDHCI_HOST_VERSION)) {
  303. reg ^= 2;
  304. if (esdhc_is_usdhc(imx_data)) {
  305. /*
  306. * The usdhc register returns a wrong host version.
  307. * Correct it here.
  308. */
  309. return SDHCI_SPEC_300;
  310. }
  311. }
  312. if (unlikely(reg == SDHCI_HOST_CONTROL2)) {
  313. val = readl(host->ioaddr + ESDHC_VENDOR_SPEC);
  314. if (val & ESDHC_VENDOR_SPEC_VSELECT)
  315. ret |= SDHCI_CTRL_VDD_180;
  316. if (esdhc_is_usdhc(imx_data)) {
  317. if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
  318. val = readl(host->ioaddr + ESDHC_MIX_CTRL);
  319. else if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
  320. /* the std tuning bits is in ACMD12_ERR for imx6sl */
  321. val = readl(host->ioaddr + SDHCI_ACMD12_ERR);
  322. }
  323. if (val & ESDHC_MIX_CTRL_EXE_TUNE)
  324. ret |= SDHCI_CTRL_EXEC_TUNING;
  325. if (val & ESDHC_MIX_CTRL_SMPCLK_SEL)
  326. ret |= SDHCI_CTRL_TUNED_CLK;
  327. ret |= (imx_data->uhs_mode & SDHCI_CTRL_UHS_MASK);
  328. ret &= ~SDHCI_CTRL_PRESET_VAL_ENABLE;
  329. return ret;
  330. }
  331. return readw(host->ioaddr + reg);
  332. }
  333. static void esdhc_writew_le(struct sdhci_host *host, u16 val, int reg)
  334. {
  335. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  336. struct pltfm_imx_data *imx_data = pltfm_host->priv;
  337. u32 new_val = 0;
  338. switch (reg) {
  339. case SDHCI_CLOCK_CONTROL:
  340. new_val = readl(host->ioaddr + ESDHC_VENDOR_SPEC);
  341. if (val & SDHCI_CLOCK_CARD_EN)
  342. new_val |= ESDHC_VENDOR_SPEC_FRC_SDCLK_ON;
  343. else
  344. new_val &= ~ESDHC_VENDOR_SPEC_FRC_SDCLK_ON;
  345. writel(new_val, host->ioaddr + ESDHC_VENDOR_SPEC);
  346. return;
  347. case SDHCI_HOST_CONTROL2:
  348. new_val = readl(host->ioaddr + ESDHC_VENDOR_SPEC);
  349. if (val & SDHCI_CTRL_VDD_180)
  350. new_val |= ESDHC_VENDOR_SPEC_VSELECT;
  351. else
  352. new_val &= ~ESDHC_VENDOR_SPEC_VSELECT;
  353. writel(new_val, host->ioaddr + ESDHC_VENDOR_SPEC);
  354. imx_data->uhs_mode = val & SDHCI_CTRL_UHS_MASK;
  355. if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
  356. new_val = readl(host->ioaddr + ESDHC_MIX_CTRL);
  357. if (val & SDHCI_CTRL_TUNED_CLK)
  358. new_val |= ESDHC_MIX_CTRL_SMPCLK_SEL;
  359. else
  360. new_val &= ~ESDHC_MIX_CTRL_SMPCLK_SEL;
  361. writel(new_val , host->ioaddr + ESDHC_MIX_CTRL);
  362. } else if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING) {
  363. u32 v = readl(host->ioaddr + SDHCI_ACMD12_ERR);
  364. u32 m = readl(host->ioaddr + ESDHC_MIX_CTRL);
  365. new_val = readl(host->ioaddr + ESDHC_TUNING_CTRL);
  366. if (val & SDHCI_CTRL_EXEC_TUNING) {
  367. new_val |= ESDHC_STD_TUNING_EN |
  368. ESDHC_TUNING_START_TAP;
  369. v |= ESDHC_MIX_CTRL_EXE_TUNE;
  370. m |= ESDHC_MIX_CTRL_FBCLK_SEL;
  371. } else {
  372. new_val &= ~ESDHC_STD_TUNING_EN;
  373. v &= ~ESDHC_MIX_CTRL_EXE_TUNE;
  374. m &= ~ESDHC_MIX_CTRL_FBCLK_SEL;
  375. }
  376. if (val & SDHCI_CTRL_TUNED_CLK)
  377. v |= ESDHC_MIX_CTRL_SMPCLK_SEL;
  378. else
  379. v &= ~ESDHC_MIX_CTRL_SMPCLK_SEL;
  380. writel(new_val, host->ioaddr + ESDHC_TUNING_CTRL);
  381. writel(v, host->ioaddr + SDHCI_ACMD12_ERR);
  382. writel(m, host->ioaddr + ESDHC_MIX_CTRL);
  383. }
  384. return;
  385. case SDHCI_TRANSFER_MODE:
  386. if ((imx_data->socdata->flags & ESDHC_FLAG_MULTIBLK_NO_INT)
  387. && (host->cmd->opcode == SD_IO_RW_EXTENDED)
  388. && (host->cmd->data->blocks > 1)
  389. && (host->cmd->data->flags & MMC_DATA_READ)) {
  390. u32 v;
  391. v = readl(host->ioaddr + ESDHC_VENDOR_SPEC);
  392. v |= ESDHC_VENDOR_SPEC_SDIO_QUIRK;
  393. writel(v, host->ioaddr + ESDHC_VENDOR_SPEC);
  394. }
  395. if (esdhc_is_usdhc(imx_data)) {
  396. u32 m = readl(host->ioaddr + ESDHC_MIX_CTRL);
  397. /* Swap AC23 bit */
  398. if (val & SDHCI_TRNS_AUTO_CMD23) {
  399. val &= ~SDHCI_TRNS_AUTO_CMD23;
  400. val |= ESDHC_MIX_CTRL_AC23EN;
  401. }
  402. m = val | (m & ~ESDHC_MIX_CTRL_SDHCI_MASK);
  403. writel(m, host->ioaddr + ESDHC_MIX_CTRL);
  404. } else {
  405. /*
  406. * Postpone this write, we must do it together with a
  407. * command write that is down below.
  408. */
  409. imx_data->scratchpad = val;
  410. }
  411. return;
  412. case SDHCI_COMMAND:
  413. if (host->cmd->opcode == MMC_STOP_TRANSMISSION)
  414. val |= SDHCI_CMD_ABORTCMD;
  415. if ((host->cmd->opcode == MMC_SET_BLOCK_COUNT) &&
  416. (imx_data->socdata->flags & ESDHC_FLAG_MULTIBLK_NO_INT))
  417. imx_data->multiblock_status = MULTIBLK_IN_PROCESS;
  418. if (esdhc_is_usdhc(imx_data))
  419. writel(val << 16,
  420. host->ioaddr + SDHCI_TRANSFER_MODE);
  421. else
  422. writel(val << 16 | imx_data->scratchpad,
  423. host->ioaddr + SDHCI_TRANSFER_MODE);
  424. return;
  425. case SDHCI_BLOCK_SIZE:
  426. val &= ~SDHCI_MAKE_BLKSZ(0x7, 0);
  427. break;
  428. }
  429. esdhc_clrset_le(host, 0xffff, val, reg);
  430. }
  431. static void esdhc_writeb_le(struct sdhci_host *host, u8 val, int reg)
  432. {
  433. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  434. struct pltfm_imx_data *imx_data = pltfm_host->priv;
  435. u32 new_val;
  436. u32 mask;
  437. switch (reg) {
  438. case SDHCI_POWER_CONTROL:
  439. /*
  440. * FSL put some DMA bits here
  441. * If your board has a regulator, code should be here
  442. */
  443. return;
  444. case SDHCI_HOST_CONTROL:
  445. /* FSL messed up here, so we need to manually compose it. */
  446. new_val = val & SDHCI_CTRL_LED;
  447. /* ensure the endianness */
  448. new_val |= ESDHC_HOST_CONTROL_LE;
  449. /* bits 8&9 are reserved on mx25 */
  450. if (!is_imx25_esdhc(imx_data)) {
  451. /* DMA mode bits are shifted */
  452. new_val |= (val & SDHCI_CTRL_DMA_MASK) << 5;
  453. }
  454. /*
  455. * Do not touch buswidth bits here. This is done in
  456. * esdhc_pltfm_bus_width.
  457. * Do not touch the D3CD bit either which is used for the
  458. * SDIO interrupt errata workaround.
  459. */
  460. mask = 0xffff & ~(ESDHC_CTRL_BUSWIDTH_MASK | ESDHC_CTRL_D3CD);
  461. esdhc_clrset_le(host, mask, new_val, reg);
  462. return;
  463. }
  464. esdhc_clrset_le(host, 0xff, val, reg);
  465. /*
  466. * The esdhc has a design violation to SDHC spec which tells
  467. * that software reset should not affect card detection circuit.
  468. * But esdhc clears its SYSCTL register bits [0..2] during the
  469. * software reset. This will stop those clocks that card detection
  470. * circuit relies on. To work around it, we turn the clocks on back
  471. * to keep card detection circuit functional.
  472. */
  473. if ((reg == SDHCI_SOFTWARE_RESET) && (val & 1)) {
  474. esdhc_clrset_le(host, 0x7, 0x7, ESDHC_SYSTEM_CONTROL);
  475. /*
  476. * The reset on usdhc fails to clear MIX_CTRL register.
  477. * Do it manually here.
  478. */
  479. if (esdhc_is_usdhc(imx_data))
  480. writel(0, host->ioaddr + ESDHC_MIX_CTRL);
  481. }
  482. }
  483. static unsigned int esdhc_pltfm_get_max_clock(struct sdhci_host *host)
  484. {
  485. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  486. struct pltfm_imx_data *imx_data = pltfm_host->priv;
  487. struct esdhc_platform_data *boarddata = &imx_data->boarddata;
  488. u32 f_host = clk_get_rate(pltfm_host->clk);
  489. if (boarddata->f_max && (boarddata->f_max < f_host))
  490. return boarddata->f_max;
  491. else
  492. return f_host;
  493. }
  494. static unsigned int esdhc_pltfm_get_min_clock(struct sdhci_host *host)
  495. {
  496. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  497. return clk_get_rate(pltfm_host->clk) / 256 / 16;
  498. }
  499. static inline void esdhc_pltfm_set_clock(struct sdhci_host *host,
  500. unsigned int clock)
  501. {
  502. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  503. struct pltfm_imx_data *imx_data = pltfm_host->priv;
  504. unsigned int host_clock = clk_get_rate(pltfm_host->clk);
  505. int pre_div = 2;
  506. int div = 1;
  507. u32 temp, val;
  508. if (clock == 0) {
  509. if (esdhc_is_usdhc(imx_data)) {
  510. val = readl(host->ioaddr + ESDHC_VENDOR_SPEC);
  511. writel(val & ~ESDHC_VENDOR_SPEC_FRC_SDCLK_ON,
  512. host->ioaddr + ESDHC_VENDOR_SPEC);
  513. }
  514. goto out;
  515. }
  516. if (esdhc_is_usdhc(imx_data))
  517. pre_div = 1;
  518. temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL);
  519. temp &= ~(ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN
  520. | ESDHC_CLOCK_MASK);
  521. sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
  522. while (host_clock / pre_div / 16 > clock && pre_div < 256)
  523. pre_div *= 2;
  524. while (host_clock / pre_div / div > clock && div < 16)
  525. div++;
  526. host->mmc->actual_clock = host_clock / pre_div / div;
  527. dev_dbg(mmc_dev(host->mmc), "desired SD clock: %d, actual: %d\n",
  528. clock, host->mmc->actual_clock);
  529. pre_div >>= 1;
  530. div--;
  531. temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL);
  532. temp |= (ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN
  533. | (div << ESDHC_DIVIDER_SHIFT)
  534. | (pre_div << ESDHC_PREDIV_SHIFT));
  535. sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
  536. if (esdhc_is_usdhc(imx_data)) {
  537. val = readl(host->ioaddr + ESDHC_VENDOR_SPEC);
  538. writel(val | ESDHC_VENDOR_SPEC_FRC_SDCLK_ON,
  539. host->ioaddr + ESDHC_VENDOR_SPEC);
  540. }
  541. mdelay(1);
  542. out:
  543. host->clock = clock;
  544. }
  545. static unsigned int esdhc_pltfm_get_ro(struct sdhci_host *host)
  546. {
  547. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  548. struct pltfm_imx_data *imx_data = pltfm_host->priv;
  549. struct esdhc_platform_data *boarddata = &imx_data->boarddata;
  550. switch (boarddata->wp_type) {
  551. case ESDHC_WP_GPIO:
  552. return mmc_gpio_get_ro(host->mmc);
  553. case ESDHC_WP_CONTROLLER:
  554. return !(readl(host->ioaddr + SDHCI_PRESENT_STATE) &
  555. SDHCI_WRITE_PROTECT);
  556. case ESDHC_WP_NONE:
  557. break;
  558. }
  559. return -ENOSYS;
  560. }
  561. static int esdhc_pltfm_bus_width(struct sdhci_host *host, int width)
  562. {
  563. u32 ctrl;
  564. switch (width) {
  565. case MMC_BUS_WIDTH_8:
  566. ctrl = ESDHC_CTRL_8BITBUS;
  567. break;
  568. case MMC_BUS_WIDTH_4:
  569. ctrl = ESDHC_CTRL_4BITBUS;
  570. break;
  571. default:
  572. ctrl = 0;
  573. break;
  574. }
  575. esdhc_clrset_le(host, ESDHC_CTRL_BUSWIDTH_MASK, ctrl,
  576. SDHCI_HOST_CONTROL);
  577. return 0;
  578. }
  579. static void esdhc_prepare_tuning(struct sdhci_host *host, u32 val)
  580. {
  581. u32 reg;
  582. /* FIXME: delay a bit for card to be ready for next tuning due to errors */
  583. mdelay(1);
  584. reg = readl(host->ioaddr + ESDHC_MIX_CTRL);
  585. reg |= ESDHC_MIX_CTRL_EXE_TUNE | ESDHC_MIX_CTRL_SMPCLK_SEL |
  586. ESDHC_MIX_CTRL_FBCLK_SEL;
  587. writel(reg, host->ioaddr + ESDHC_MIX_CTRL);
  588. writel(val << 8, host->ioaddr + ESDHC_TUNE_CTRL_STATUS);
  589. dev_dbg(mmc_dev(host->mmc),
  590. "tunning with delay 0x%x ESDHC_TUNE_CTRL_STATUS 0x%x\n",
  591. val, readl(host->ioaddr + ESDHC_TUNE_CTRL_STATUS));
  592. }
  593. static void esdhc_request_done(struct mmc_request *mrq)
  594. {
  595. complete(&mrq->completion);
  596. }
  597. static int esdhc_send_tuning_cmd(struct sdhci_host *host, u32 opcode)
  598. {
  599. struct mmc_command cmd = {0};
  600. struct mmc_request mrq = {0};
  601. struct mmc_data data = {0};
  602. struct scatterlist sg;
  603. char tuning_pattern[ESDHC_TUNING_BLOCK_PATTERN_LEN];
  604. cmd.opcode = opcode;
  605. cmd.arg = 0;
  606. cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
  607. data.blksz = ESDHC_TUNING_BLOCK_PATTERN_LEN;
  608. data.blocks = 1;
  609. data.flags = MMC_DATA_READ;
  610. data.sg = &sg;
  611. data.sg_len = 1;
  612. sg_init_one(&sg, tuning_pattern, sizeof(tuning_pattern));
  613. mrq.cmd = &cmd;
  614. mrq.cmd->mrq = &mrq;
  615. mrq.data = &data;
  616. mrq.data->mrq = &mrq;
  617. mrq.cmd->data = mrq.data;
  618. mrq.done = esdhc_request_done;
  619. init_completion(&(mrq.completion));
  620. disable_irq(host->irq);
  621. spin_lock(&host->lock);
  622. host->mrq = &mrq;
  623. sdhci_send_command(host, mrq.cmd);
  624. spin_unlock(&host->lock);
  625. enable_irq(host->irq);
  626. wait_for_completion(&mrq.completion);
  627. if (cmd.error)
  628. return cmd.error;
  629. if (data.error)
  630. return data.error;
  631. return 0;
  632. }
  633. static void esdhc_post_tuning(struct sdhci_host *host)
  634. {
  635. u32 reg;
  636. reg = readl(host->ioaddr + ESDHC_MIX_CTRL);
  637. reg &= ~ESDHC_MIX_CTRL_EXE_TUNE;
  638. writel(reg, host->ioaddr + ESDHC_MIX_CTRL);
  639. }
  640. static int esdhc_executing_tuning(struct sdhci_host *host, u32 opcode)
  641. {
  642. int min, max, avg, ret;
  643. /* find the mininum delay first which can pass tuning */
  644. min = ESDHC_TUNE_CTRL_MIN;
  645. while (min < ESDHC_TUNE_CTRL_MAX) {
  646. esdhc_prepare_tuning(host, min);
  647. if (!esdhc_send_tuning_cmd(host, opcode))
  648. break;
  649. min += ESDHC_TUNE_CTRL_STEP;
  650. }
  651. /* find the maxinum delay which can not pass tuning */
  652. max = min + ESDHC_TUNE_CTRL_STEP;
  653. while (max < ESDHC_TUNE_CTRL_MAX) {
  654. esdhc_prepare_tuning(host, max);
  655. if (esdhc_send_tuning_cmd(host, opcode)) {
  656. max -= ESDHC_TUNE_CTRL_STEP;
  657. break;
  658. }
  659. max += ESDHC_TUNE_CTRL_STEP;
  660. }
  661. /* use average delay to get the best timing */
  662. avg = (min + max) / 2;
  663. esdhc_prepare_tuning(host, avg);
  664. ret = esdhc_send_tuning_cmd(host, opcode);
  665. esdhc_post_tuning(host);
  666. dev_dbg(mmc_dev(host->mmc), "tunning %s at 0x%x ret %d\n",
  667. ret ? "failed" : "passed", avg, ret);
  668. return ret;
  669. }
  670. static int esdhc_change_pinstate(struct sdhci_host *host,
  671. unsigned int uhs)
  672. {
  673. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  674. struct pltfm_imx_data *imx_data = pltfm_host->priv;
  675. struct pinctrl_state *pinctrl;
  676. dev_dbg(mmc_dev(host->mmc), "change pinctrl state for uhs %d\n", uhs);
  677. if (IS_ERR(imx_data->pinctrl) ||
  678. IS_ERR(imx_data->pins_default) ||
  679. IS_ERR(imx_data->pins_100mhz) ||
  680. IS_ERR(imx_data->pins_200mhz))
  681. return -EINVAL;
  682. switch (uhs) {
  683. case MMC_TIMING_UHS_SDR50:
  684. pinctrl = imx_data->pins_100mhz;
  685. break;
  686. case MMC_TIMING_UHS_SDR104:
  687. pinctrl = imx_data->pins_200mhz;
  688. break;
  689. default:
  690. /* back to default state for other legacy timing */
  691. pinctrl = imx_data->pins_default;
  692. }
  693. return pinctrl_select_state(imx_data->pinctrl, pinctrl);
  694. }
  695. static int esdhc_set_uhs_signaling(struct sdhci_host *host, unsigned int uhs)
  696. {
  697. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  698. struct pltfm_imx_data *imx_data = pltfm_host->priv;
  699. switch (uhs) {
  700. case MMC_TIMING_UHS_SDR12:
  701. imx_data->uhs_mode = SDHCI_CTRL_UHS_SDR12;
  702. break;
  703. case MMC_TIMING_UHS_SDR25:
  704. imx_data->uhs_mode = SDHCI_CTRL_UHS_SDR25;
  705. break;
  706. case MMC_TIMING_UHS_SDR50:
  707. imx_data->uhs_mode = SDHCI_CTRL_UHS_SDR50;
  708. break;
  709. case MMC_TIMING_UHS_SDR104:
  710. imx_data->uhs_mode = SDHCI_CTRL_UHS_SDR104;
  711. break;
  712. case MMC_TIMING_UHS_DDR50:
  713. imx_data->uhs_mode = SDHCI_CTRL_UHS_DDR50;
  714. break;
  715. }
  716. return esdhc_change_pinstate(host, uhs);
  717. }
  718. static struct sdhci_ops sdhci_esdhc_ops = {
  719. .read_l = esdhc_readl_le,
  720. .read_w = esdhc_readw_le,
  721. .write_l = esdhc_writel_le,
  722. .write_w = esdhc_writew_le,
  723. .write_b = esdhc_writeb_le,
  724. .set_clock = esdhc_pltfm_set_clock,
  725. .get_max_clock = esdhc_pltfm_get_max_clock,
  726. .get_min_clock = esdhc_pltfm_get_min_clock,
  727. .get_ro = esdhc_pltfm_get_ro,
  728. .platform_bus_width = esdhc_pltfm_bus_width,
  729. .set_uhs_signaling = esdhc_set_uhs_signaling,
  730. };
  731. static const struct sdhci_pltfm_data sdhci_esdhc_imx_pdata = {
  732. .quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_NO_HISPD_BIT
  733. | SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
  734. | SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC
  735. | SDHCI_QUIRK_BROKEN_CARD_DETECTION,
  736. .ops = &sdhci_esdhc_ops,
  737. };
  738. #ifdef CONFIG_OF
  739. static int
  740. sdhci_esdhc_imx_probe_dt(struct platform_device *pdev,
  741. struct esdhc_platform_data *boarddata)
  742. {
  743. struct device_node *np = pdev->dev.of_node;
  744. if (!np)
  745. return -ENODEV;
  746. if (of_get_property(np, "non-removable", NULL))
  747. boarddata->cd_type = ESDHC_CD_PERMANENT;
  748. if (of_get_property(np, "fsl,cd-controller", NULL))
  749. boarddata->cd_type = ESDHC_CD_CONTROLLER;
  750. if (of_get_property(np, "fsl,wp-controller", NULL))
  751. boarddata->wp_type = ESDHC_WP_CONTROLLER;
  752. boarddata->cd_gpio = of_get_named_gpio(np, "cd-gpios", 0);
  753. if (gpio_is_valid(boarddata->cd_gpio))
  754. boarddata->cd_type = ESDHC_CD_GPIO;
  755. boarddata->wp_gpio = of_get_named_gpio(np, "wp-gpios", 0);
  756. if (gpio_is_valid(boarddata->wp_gpio))
  757. boarddata->wp_type = ESDHC_WP_GPIO;
  758. of_property_read_u32(np, "bus-width", &boarddata->max_bus_width);
  759. of_property_read_u32(np, "max-frequency", &boarddata->f_max);
  760. if (of_find_property(np, "no-1-8-v", NULL))
  761. boarddata->support_vsel = false;
  762. else
  763. boarddata->support_vsel = true;
  764. return 0;
  765. }
  766. #else
  767. static inline int
  768. sdhci_esdhc_imx_probe_dt(struct platform_device *pdev,
  769. struct esdhc_platform_data *boarddata)
  770. {
  771. return -ENODEV;
  772. }
  773. #endif
  774. static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
  775. {
  776. const struct of_device_id *of_id =
  777. of_match_device(imx_esdhc_dt_ids, &pdev->dev);
  778. struct sdhci_pltfm_host *pltfm_host;
  779. struct sdhci_host *host;
  780. struct esdhc_platform_data *boarddata;
  781. int err;
  782. struct pltfm_imx_data *imx_data;
  783. host = sdhci_pltfm_init(pdev, &sdhci_esdhc_imx_pdata, 0);
  784. if (IS_ERR(host))
  785. return PTR_ERR(host);
  786. pltfm_host = sdhci_priv(host);
  787. imx_data = devm_kzalloc(&pdev->dev, sizeof(*imx_data), GFP_KERNEL);
  788. if (!imx_data) {
  789. err = -ENOMEM;
  790. goto free_sdhci;
  791. }
  792. imx_data->socdata = of_id ? of_id->data : (struct esdhc_soc_data *)
  793. pdev->id_entry->driver_data;
  794. pltfm_host->priv = imx_data;
  795. imx_data->clk_ipg = devm_clk_get(&pdev->dev, "ipg");
  796. if (IS_ERR(imx_data->clk_ipg)) {
  797. err = PTR_ERR(imx_data->clk_ipg);
  798. goto free_sdhci;
  799. }
  800. imx_data->clk_ahb = devm_clk_get(&pdev->dev, "ahb");
  801. if (IS_ERR(imx_data->clk_ahb)) {
  802. err = PTR_ERR(imx_data->clk_ahb);
  803. goto free_sdhci;
  804. }
  805. imx_data->clk_per = devm_clk_get(&pdev->dev, "per");
  806. if (IS_ERR(imx_data->clk_per)) {
  807. err = PTR_ERR(imx_data->clk_per);
  808. goto free_sdhci;
  809. }
  810. pltfm_host->clk = imx_data->clk_per;
  811. clk_prepare_enable(imx_data->clk_per);
  812. clk_prepare_enable(imx_data->clk_ipg);
  813. clk_prepare_enable(imx_data->clk_ahb);
  814. imx_data->pinctrl = devm_pinctrl_get(&pdev->dev);
  815. if (IS_ERR(imx_data->pinctrl)) {
  816. err = PTR_ERR(imx_data->pinctrl);
  817. goto disable_clk;
  818. }
  819. imx_data->pins_default = pinctrl_lookup_state(imx_data->pinctrl,
  820. PINCTRL_STATE_DEFAULT);
  821. if (IS_ERR(imx_data->pins_default)) {
  822. err = PTR_ERR(imx_data->pins_default);
  823. dev_err(mmc_dev(host->mmc), "could not get default state\n");
  824. goto disable_clk;
  825. }
  826. host->quirks |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL;
  827. if (imx_data->socdata->flags & ESDHC_FLAG_ENGCM07207)
  828. /* Fix errata ENGcm07207 present on i.MX25 and i.MX35 */
  829. host->quirks |= SDHCI_QUIRK_NO_MULTIBLOCK
  830. | SDHCI_QUIRK_BROKEN_ADMA;
  831. /*
  832. * The imx6q ROM code will change the default watermark level setting
  833. * to something insane. Change it back here.
  834. */
  835. if (esdhc_is_usdhc(imx_data))
  836. writel(0x08100810, host->ioaddr + ESDHC_WTMK_LVL);
  837. if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
  838. sdhci_esdhc_ops.platform_execute_tuning =
  839. esdhc_executing_tuning;
  840. boarddata = &imx_data->boarddata;
  841. if (sdhci_esdhc_imx_probe_dt(pdev, boarddata) < 0) {
  842. if (!host->mmc->parent->platform_data) {
  843. dev_err(mmc_dev(host->mmc), "no board data!\n");
  844. err = -EINVAL;
  845. goto disable_clk;
  846. }
  847. imx_data->boarddata = *((struct esdhc_platform_data *)
  848. host->mmc->parent->platform_data);
  849. }
  850. /* write_protect */
  851. if (boarddata->wp_type == ESDHC_WP_GPIO) {
  852. err = mmc_gpio_request_ro(host->mmc, boarddata->wp_gpio);
  853. if (err) {
  854. dev_err(mmc_dev(host->mmc),
  855. "failed to request write-protect gpio!\n");
  856. goto disable_clk;
  857. }
  858. host->mmc->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH;
  859. }
  860. /* card_detect */
  861. switch (boarddata->cd_type) {
  862. case ESDHC_CD_GPIO:
  863. err = mmc_gpio_request_cd(host->mmc, boarddata->cd_gpio, 0);
  864. if (err) {
  865. dev_err(mmc_dev(host->mmc),
  866. "failed to request card-detect gpio!\n");
  867. goto disable_clk;
  868. }
  869. /* fall through */
  870. case ESDHC_CD_CONTROLLER:
  871. /* we have a working card_detect back */
  872. host->quirks &= ~SDHCI_QUIRK_BROKEN_CARD_DETECTION;
  873. break;
  874. case ESDHC_CD_PERMANENT:
  875. host->mmc->caps = MMC_CAP_NONREMOVABLE;
  876. break;
  877. case ESDHC_CD_NONE:
  878. break;
  879. }
  880. switch (boarddata->max_bus_width) {
  881. case 8:
  882. host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_4_BIT_DATA;
  883. break;
  884. case 4:
  885. host->mmc->caps |= MMC_CAP_4_BIT_DATA;
  886. break;
  887. case 1:
  888. default:
  889. host->quirks |= SDHCI_QUIRK_FORCE_1_BIT_DATA;
  890. break;
  891. }
  892. /* sdr50 and sdr104 needs work on 1.8v signal voltage */
  893. if ((boarddata->support_vsel) && esdhc_is_usdhc(imx_data)) {
  894. imx_data->pins_100mhz = pinctrl_lookup_state(imx_data->pinctrl,
  895. ESDHC_PINCTRL_STATE_100MHZ);
  896. imx_data->pins_200mhz = pinctrl_lookup_state(imx_data->pinctrl,
  897. ESDHC_PINCTRL_STATE_200MHZ);
  898. if (IS_ERR(imx_data->pins_100mhz) ||
  899. IS_ERR(imx_data->pins_200mhz)) {
  900. dev_warn(mmc_dev(host->mmc),
  901. "could not get ultra high speed state, work on normal mode\n");
  902. /* fall back to not support uhs by specify no 1.8v quirk */
  903. host->quirks2 |= SDHCI_QUIRK2_NO_1_8_V;
  904. }
  905. } else {
  906. host->quirks2 |= SDHCI_QUIRK2_NO_1_8_V;
  907. }
  908. err = sdhci_add_host(host);
  909. if (err)
  910. goto disable_clk;
  911. return 0;
  912. disable_clk:
  913. clk_disable_unprepare(imx_data->clk_per);
  914. clk_disable_unprepare(imx_data->clk_ipg);
  915. clk_disable_unprepare(imx_data->clk_ahb);
  916. free_sdhci:
  917. sdhci_pltfm_free(pdev);
  918. return err;
  919. }
  920. static int sdhci_esdhc_imx_remove(struct platform_device *pdev)
  921. {
  922. struct sdhci_host *host = platform_get_drvdata(pdev);
  923. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  924. struct pltfm_imx_data *imx_data = pltfm_host->priv;
  925. int dead = (readl(host->ioaddr + SDHCI_INT_STATUS) == 0xffffffff);
  926. sdhci_remove_host(host, dead);
  927. clk_disable_unprepare(imx_data->clk_per);
  928. clk_disable_unprepare(imx_data->clk_ipg);
  929. clk_disable_unprepare(imx_data->clk_ahb);
  930. sdhci_pltfm_free(pdev);
  931. return 0;
  932. }
  933. static struct platform_driver sdhci_esdhc_imx_driver = {
  934. .driver = {
  935. .name = "sdhci-esdhc-imx",
  936. .owner = THIS_MODULE,
  937. .of_match_table = imx_esdhc_dt_ids,
  938. .pm = SDHCI_PLTFM_PMOPS,
  939. },
  940. .id_table = imx_esdhc_devtype,
  941. .probe = sdhci_esdhc_imx_probe,
  942. .remove = sdhci_esdhc_imx_remove,
  943. };
  944. module_platform_driver(sdhci_esdhc_imx_driver);
  945. MODULE_DESCRIPTION("SDHCI driver for Freescale i.MX eSDHC");
  946. MODULE_AUTHOR("Wolfram Sang <w.sang@pengutronix.de>");
  947. MODULE_LICENSE("GPL v2");