sdhci-of-esdhc.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. /*
  2. * Freescale eSDHC controller driver.
  3. *
  4. * Copyright (c) 2007, 2010, 2012 Freescale Semiconductor, Inc.
  5. * Copyright (c) 2009 MontaVista Software, Inc.
  6. *
  7. * Authors: Xiaobo Xie <X.Xie@freescale.com>
  8. * Anton Vorontsov <avorontsov@ru.mvista.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or (at
  13. * your option) any later version.
  14. */
  15. #include <linux/err.h>
  16. #include <linux/io.h>
  17. #include <linux/of.h>
  18. #include <linux/delay.h>
  19. #include <linux/module.h>
  20. #include <linux/sys_soc.h>
  21. #include <linux/mmc/host.h>
  22. #include "sdhci-pltfm.h"
  23. #include "sdhci-esdhc.h"
  24. #define VENDOR_V_22 0x12
  25. #define VENDOR_V_23 0x13
  26. struct sdhci_esdhc {
  27. u8 vendor_ver;
  28. u8 spec_ver;
  29. bool quirk_incorrect_hostver;
  30. };
  31. /**
  32. * esdhc_read*_fixup - Fixup the value read from incompatible eSDHC register
  33. * to make it compatible with SD spec.
  34. *
  35. * @host: pointer to sdhci_host
  36. * @spec_reg: SD spec register address
  37. * @value: 32bit eSDHC register value on spec_reg address
  38. *
  39. * In SD spec, there are 8/16/32/64 bits registers, while all of eSDHC
  40. * registers are 32 bits. There are differences in register size, register
  41. * address, register function, bit position and function between eSDHC spec
  42. * and SD spec.
  43. *
  44. * Return a fixed up register value
  45. */
  46. static u32 esdhc_readl_fixup(struct sdhci_host *host,
  47. int spec_reg, u32 value)
  48. {
  49. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  50. struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host);
  51. u32 ret;
  52. /*
  53. * The bit of ADMA flag in eSDHC is not compatible with standard
  54. * SDHC register, so set fake flag SDHCI_CAN_DO_ADMA2 when ADMA is
  55. * supported by eSDHC.
  56. * And for many FSL eSDHC controller, the reset value of field
  57. * SDHCI_CAN_DO_ADMA1 is 1, but some of them can't support ADMA,
  58. * only these vendor version is greater than 2.2/0x12 support ADMA.
  59. */
  60. if ((spec_reg == SDHCI_CAPABILITIES) && (value & SDHCI_CAN_DO_ADMA1)) {
  61. if (esdhc->vendor_ver > VENDOR_V_22) {
  62. ret = value | SDHCI_CAN_DO_ADMA2;
  63. return ret;
  64. }
  65. }
  66. /*
  67. * The DAT[3:0] line signal levels and the CMD line signal level are
  68. * not compatible with standard SDHC register. The line signal levels
  69. * DAT[7:0] are at bits 31:24 and the command line signal level is at
  70. * bit 23. All other bits are the same as in the standard SDHC
  71. * register.
  72. */
  73. if (spec_reg == SDHCI_PRESENT_STATE) {
  74. ret = value & 0x000fffff;
  75. ret |= (value >> 4) & SDHCI_DATA_LVL_MASK;
  76. ret |= (value << 1) & SDHCI_CMD_LVL;
  77. return ret;
  78. }
  79. ret = value;
  80. return ret;
  81. }
  82. static u16 esdhc_readw_fixup(struct sdhci_host *host,
  83. int spec_reg, u32 value)
  84. {
  85. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  86. struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host);
  87. u16 ret;
  88. int shift = (spec_reg & 0x2) * 8;
  89. if (spec_reg == SDHCI_HOST_VERSION)
  90. ret = value & 0xffff;
  91. else
  92. ret = (value >> shift) & 0xffff;
  93. /* Workaround for T4240-R1.0-R2.0 eSDHC which has incorrect
  94. * vendor version and spec version information.
  95. */
  96. if ((spec_reg == SDHCI_HOST_VERSION) &&
  97. (esdhc->quirk_incorrect_hostver))
  98. ret = (VENDOR_V_23 << SDHCI_VENDOR_VER_SHIFT) | SDHCI_SPEC_200;
  99. return ret;
  100. }
  101. static u8 esdhc_readb_fixup(struct sdhci_host *host,
  102. int spec_reg, u32 value)
  103. {
  104. u8 ret;
  105. u8 dma_bits;
  106. int shift = (spec_reg & 0x3) * 8;
  107. ret = (value >> shift) & 0xff;
  108. /*
  109. * "DMA select" locates at offset 0x28 in SD specification, but on
  110. * P5020 or P3041, it locates at 0x29.
  111. */
  112. if (spec_reg == SDHCI_HOST_CONTROL) {
  113. /* DMA select is 22,23 bits in Protocol Control Register */
  114. dma_bits = (value >> 5) & SDHCI_CTRL_DMA_MASK;
  115. /* fixup the result */
  116. ret &= ~SDHCI_CTRL_DMA_MASK;
  117. ret |= dma_bits;
  118. }
  119. return ret;
  120. }
  121. /**
  122. * esdhc_write*_fixup - Fixup the SD spec register value so that it could be
  123. * written into eSDHC register.
  124. *
  125. * @host: pointer to sdhci_host
  126. * @spec_reg: SD spec register address
  127. * @value: 8/16/32bit SD spec register value that would be written
  128. * @old_value: 32bit eSDHC register value on spec_reg address
  129. *
  130. * In SD spec, there are 8/16/32/64 bits registers, while all of eSDHC
  131. * registers are 32 bits. There are differences in register size, register
  132. * address, register function, bit position and function between eSDHC spec
  133. * and SD spec.
  134. *
  135. * Return a fixed up register value
  136. */
  137. static u32 esdhc_writel_fixup(struct sdhci_host *host,
  138. int spec_reg, u32 value, u32 old_value)
  139. {
  140. u32 ret;
  141. /*
  142. * Enabling IRQSTATEN[BGESEN] is just to set IRQSTAT[BGE]
  143. * when SYSCTL[RSTD] is set for some special operations.
  144. * No any impact on other operation.
  145. */
  146. if (spec_reg == SDHCI_INT_ENABLE)
  147. ret = value | SDHCI_INT_BLK_GAP;
  148. else
  149. ret = value;
  150. return ret;
  151. }
  152. static u32 esdhc_writew_fixup(struct sdhci_host *host,
  153. int spec_reg, u16 value, u32 old_value)
  154. {
  155. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  156. int shift = (spec_reg & 0x2) * 8;
  157. u32 ret;
  158. switch (spec_reg) {
  159. case SDHCI_TRANSFER_MODE:
  160. /*
  161. * Postpone this write, we must do it together with a
  162. * command write that is down below. Return old value.
  163. */
  164. pltfm_host->xfer_mode_shadow = value;
  165. return old_value;
  166. case SDHCI_COMMAND:
  167. ret = (value << 16) | pltfm_host->xfer_mode_shadow;
  168. return ret;
  169. }
  170. ret = old_value & (~(0xffff << shift));
  171. ret |= (value << shift);
  172. if (spec_reg == SDHCI_BLOCK_SIZE) {
  173. /*
  174. * Two last DMA bits are reserved, and first one is used for
  175. * non-standard blksz of 4096 bytes that we don't support
  176. * yet. So clear the DMA boundary bits.
  177. */
  178. ret &= (~SDHCI_MAKE_BLKSZ(0x7, 0));
  179. }
  180. return ret;
  181. }
  182. static u32 esdhc_writeb_fixup(struct sdhci_host *host,
  183. int spec_reg, u8 value, u32 old_value)
  184. {
  185. u32 ret;
  186. u32 dma_bits;
  187. u8 tmp;
  188. int shift = (spec_reg & 0x3) * 8;
  189. /*
  190. * eSDHC doesn't have a standard power control register, so we do
  191. * nothing here to avoid incorrect operation.
  192. */
  193. if (spec_reg == SDHCI_POWER_CONTROL)
  194. return old_value;
  195. /*
  196. * "DMA select" location is offset 0x28 in SD specification, but on
  197. * P5020 or P3041, it's located at 0x29.
  198. */
  199. if (spec_reg == SDHCI_HOST_CONTROL) {
  200. /*
  201. * If host control register is not standard, exit
  202. * this function
  203. */
  204. if (host->quirks2 & SDHCI_QUIRK2_BROKEN_HOST_CONTROL)
  205. return old_value;
  206. /* DMA select is 22,23 bits in Protocol Control Register */
  207. dma_bits = (value & SDHCI_CTRL_DMA_MASK) << 5;
  208. ret = (old_value & (~(SDHCI_CTRL_DMA_MASK << 5))) | dma_bits;
  209. tmp = (value & (~SDHCI_CTRL_DMA_MASK)) |
  210. (old_value & SDHCI_CTRL_DMA_MASK);
  211. ret = (ret & (~0xff)) | tmp;
  212. /* Prevent SDHCI core from writing reserved bits (e.g. HISPD) */
  213. ret &= ~ESDHC_HOST_CONTROL_RES;
  214. return ret;
  215. }
  216. ret = (old_value & (~(0xff << shift))) | (value << shift);
  217. return ret;
  218. }
  219. static u32 esdhc_be_readl(struct sdhci_host *host, int reg)
  220. {
  221. u32 ret;
  222. u32 value;
  223. value = ioread32be(host->ioaddr + reg);
  224. ret = esdhc_readl_fixup(host, reg, value);
  225. return ret;
  226. }
  227. static u32 esdhc_le_readl(struct sdhci_host *host, int reg)
  228. {
  229. u32 ret;
  230. u32 value;
  231. value = ioread32(host->ioaddr + reg);
  232. ret = esdhc_readl_fixup(host, reg, value);
  233. return ret;
  234. }
  235. static u16 esdhc_be_readw(struct sdhci_host *host, int reg)
  236. {
  237. u16 ret;
  238. u32 value;
  239. int base = reg & ~0x3;
  240. value = ioread32be(host->ioaddr + base);
  241. ret = esdhc_readw_fixup(host, reg, value);
  242. return ret;
  243. }
  244. static u16 esdhc_le_readw(struct sdhci_host *host, int reg)
  245. {
  246. u16 ret;
  247. u32 value;
  248. int base = reg & ~0x3;
  249. value = ioread32(host->ioaddr + base);
  250. ret = esdhc_readw_fixup(host, reg, value);
  251. return ret;
  252. }
  253. static u8 esdhc_be_readb(struct sdhci_host *host, int reg)
  254. {
  255. u8 ret;
  256. u32 value;
  257. int base = reg & ~0x3;
  258. value = ioread32be(host->ioaddr + base);
  259. ret = esdhc_readb_fixup(host, reg, value);
  260. return ret;
  261. }
  262. static u8 esdhc_le_readb(struct sdhci_host *host, int reg)
  263. {
  264. u8 ret;
  265. u32 value;
  266. int base = reg & ~0x3;
  267. value = ioread32(host->ioaddr + base);
  268. ret = esdhc_readb_fixup(host, reg, value);
  269. return ret;
  270. }
  271. static void esdhc_be_writel(struct sdhci_host *host, u32 val, int reg)
  272. {
  273. u32 value;
  274. value = esdhc_writel_fixup(host, reg, val, 0);
  275. iowrite32be(value, host->ioaddr + reg);
  276. }
  277. static void esdhc_le_writel(struct sdhci_host *host, u32 val, int reg)
  278. {
  279. u32 value;
  280. value = esdhc_writel_fixup(host, reg, val, 0);
  281. iowrite32(value, host->ioaddr + reg);
  282. }
  283. static void esdhc_be_writew(struct sdhci_host *host, u16 val, int reg)
  284. {
  285. int base = reg & ~0x3;
  286. u32 value;
  287. u32 ret;
  288. value = ioread32be(host->ioaddr + base);
  289. ret = esdhc_writew_fixup(host, reg, val, value);
  290. if (reg != SDHCI_TRANSFER_MODE)
  291. iowrite32be(ret, host->ioaddr + base);
  292. }
  293. static void esdhc_le_writew(struct sdhci_host *host, u16 val, int reg)
  294. {
  295. int base = reg & ~0x3;
  296. u32 value;
  297. u32 ret;
  298. value = ioread32(host->ioaddr + base);
  299. ret = esdhc_writew_fixup(host, reg, val, value);
  300. if (reg != SDHCI_TRANSFER_MODE)
  301. iowrite32(ret, host->ioaddr + base);
  302. }
  303. static void esdhc_be_writeb(struct sdhci_host *host, u8 val, int reg)
  304. {
  305. int base = reg & ~0x3;
  306. u32 value;
  307. u32 ret;
  308. value = ioread32be(host->ioaddr + base);
  309. ret = esdhc_writeb_fixup(host, reg, val, value);
  310. iowrite32be(ret, host->ioaddr + base);
  311. }
  312. static void esdhc_le_writeb(struct sdhci_host *host, u8 val, int reg)
  313. {
  314. int base = reg & ~0x3;
  315. u32 value;
  316. u32 ret;
  317. value = ioread32(host->ioaddr + base);
  318. ret = esdhc_writeb_fixup(host, reg, val, value);
  319. iowrite32(ret, host->ioaddr + base);
  320. }
  321. /*
  322. * For Abort or Suspend after Stop at Block Gap, ignore the ADMA
  323. * error(IRQSTAT[ADMAE]) if both Transfer Complete(IRQSTAT[TC])
  324. * and Block Gap Event(IRQSTAT[BGE]) are also set.
  325. * For Continue, apply soft reset for data(SYSCTL[RSTD]);
  326. * and re-issue the entire read transaction from beginning.
  327. */
  328. static void esdhc_of_adma_workaround(struct sdhci_host *host, u32 intmask)
  329. {
  330. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  331. struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host);
  332. bool applicable;
  333. dma_addr_t dmastart;
  334. dma_addr_t dmanow;
  335. applicable = (intmask & SDHCI_INT_DATA_END) &&
  336. (intmask & SDHCI_INT_BLK_GAP) &&
  337. (esdhc->vendor_ver == VENDOR_V_23);
  338. if (!applicable)
  339. return;
  340. host->data->error = 0;
  341. dmastart = sg_dma_address(host->data->sg);
  342. dmanow = dmastart + host->data->bytes_xfered;
  343. /*
  344. * Force update to the next DMA block boundary.
  345. */
  346. dmanow = (dmanow & ~(SDHCI_DEFAULT_BOUNDARY_SIZE - 1)) +
  347. SDHCI_DEFAULT_BOUNDARY_SIZE;
  348. host->data->bytes_xfered = dmanow - dmastart;
  349. sdhci_writel(host, dmanow, SDHCI_DMA_ADDRESS);
  350. }
  351. static int esdhc_of_enable_dma(struct sdhci_host *host)
  352. {
  353. u32 value;
  354. value = sdhci_readl(host, ESDHC_DMA_SYSCTL);
  355. value |= ESDHC_DMA_SNOOP;
  356. sdhci_writel(host, value, ESDHC_DMA_SYSCTL);
  357. return 0;
  358. }
  359. static unsigned int esdhc_of_get_max_clock(struct sdhci_host *host)
  360. {
  361. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  362. return pltfm_host->clock;
  363. }
  364. static unsigned int esdhc_of_get_min_clock(struct sdhci_host *host)
  365. {
  366. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  367. return pltfm_host->clock / 256 / 16;
  368. }
  369. static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock)
  370. {
  371. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  372. struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host);
  373. int pre_div = 1;
  374. int div = 1;
  375. u32 temp;
  376. host->mmc->actual_clock = 0;
  377. if (clock == 0)
  378. return;
  379. /* Workaround to start pre_div at 2 for VNN < VENDOR_V_23 */
  380. if (esdhc->vendor_ver < VENDOR_V_23)
  381. pre_div = 2;
  382. /* Workaround to reduce the clock frequency for p1010 esdhc */
  383. if (of_find_compatible_node(NULL, NULL, "fsl,p1010-esdhc")) {
  384. if (clock > 20000000)
  385. clock -= 5000000;
  386. if (clock > 40000000)
  387. clock -= 5000000;
  388. }
  389. temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL);
  390. temp &= ~(ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN
  391. | ESDHC_CLOCK_MASK);
  392. sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
  393. while (host->max_clk / pre_div / 16 > clock && pre_div < 256)
  394. pre_div *= 2;
  395. while (host->max_clk / pre_div / div > clock && div < 16)
  396. div++;
  397. dev_dbg(mmc_dev(host->mmc), "desired SD clock: %d, actual: %d\n",
  398. clock, host->max_clk / pre_div / div);
  399. host->mmc->actual_clock = host->max_clk / pre_div / div;
  400. pre_div >>= 1;
  401. div--;
  402. temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL);
  403. temp |= (ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN
  404. | (div << ESDHC_DIVIDER_SHIFT)
  405. | (pre_div << ESDHC_PREDIV_SHIFT));
  406. sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
  407. mdelay(1);
  408. }
  409. static void esdhc_pltfm_set_bus_width(struct sdhci_host *host, int width)
  410. {
  411. u32 ctrl;
  412. ctrl = sdhci_readl(host, ESDHC_PROCTL);
  413. ctrl &= (~ESDHC_CTRL_BUSWIDTH_MASK);
  414. switch (width) {
  415. case MMC_BUS_WIDTH_8:
  416. ctrl |= ESDHC_CTRL_8BITBUS;
  417. break;
  418. case MMC_BUS_WIDTH_4:
  419. ctrl |= ESDHC_CTRL_4BITBUS;
  420. break;
  421. default:
  422. break;
  423. }
  424. sdhci_writel(host, ctrl, ESDHC_PROCTL);
  425. }
  426. static void esdhc_reset(struct sdhci_host *host, u8 mask)
  427. {
  428. sdhci_reset(host, mask);
  429. sdhci_writel(host, host->ier, SDHCI_INT_ENABLE);
  430. sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE);
  431. }
  432. #ifdef CONFIG_PM_SLEEP
  433. static u32 esdhc_proctl;
  434. static int esdhc_of_suspend(struct device *dev)
  435. {
  436. struct sdhci_host *host = dev_get_drvdata(dev);
  437. esdhc_proctl = sdhci_readl(host, SDHCI_HOST_CONTROL);
  438. return sdhci_suspend_host(host);
  439. }
  440. static int esdhc_of_resume(struct device *dev)
  441. {
  442. struct sdhci_host *host = dev_get_drvdata(dev);
  443. int ret = sdhci_resume_host(host);
  444. if (ret == 0) {
  445. /* Isn't this already done by sdhci_resume_host() ? --rmk */
  446. esdhc_of_enable_dma(host);
  447. sdhci_writel(host, esdhc_proctl, SDHCI_HOST_CONTROL);
  448. }
  449. return ret;
  450. }
  451. #endif
  452. static SIMPLE_DEV_PM_OPS(esdhc_of_dev_pm_ops,
  453. esdhc_of_suspend,
  454. esdhc_of_resume);
  455. static const struct sdhci_ops sdhci_esdhc_be_ops = {
  456. .read_l = esdhc_be_readl,
  457. .read_w = esdhc_be_readw,
  458. .read_b = esdhc_be_readb,
  459. .write_l = esdhc_be_writel,
  460. .write_w = esdhc_be_writew,
  461. .write_b = esdhc_be_writeb,
  462. .set_clock = esdhc_of_set_clock,
  463. .enable_dma = esdhc_of_enable_dma,
  464. .get_max_clock = esdhc_of_get_max_clock,
  465. .get_min_clock = esdhc_of_get_min_clock,
  466. .adma_workaround = esdhc_of_adma_workaround,
  467. .set_bus_width = esdhc_pltfm_set_bus_width,
  468. .reset = esdhc_reset,
  469. .set_uhs_signaling = sdhci_set_uhs_signaling,
  470. };
  471. static const struct sdhci_ops sdhci_esdhc_le_ops = {
  472. .read_l = esdhc_le_readl,
  473. .read_w = esdhc_le_readw,
  474. .read_b = esdhc_le_readb,
  475. .write_l = esdhc_le_writel,
  476. .write_w = esdhc_le_writew,
  477. .write_b = esdhc_le_writeb,
  478. .set_clock = esdhc_of_set_clock,
  479. .enable_dma = esdhc_of_enable_dma,
  480. .get_max_clock = esdhc_of_get_max_clock,
  481. .get_min_clock = esdhc_of_get_min_clock,
  482. .adma_workaround = esdhc_of_adma_workaround,
  483. .set_bus_width = esdhc_pltfm_set_bus_width,
  484. .reset = esdhc_reset,
  485. .set_uhs_signaling = sdhci_set_uhs_signaling,
  486. };
  487. static const struct sdhci_pltfm_data sdhci_esdhc_be_pdata = {
  488. .quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_BROKEN_CARD_DETECTION
  489. | SDHCI_QUIRK_NO_CARD_NO_RESET
  490. | SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
  491. .ops = &sdhci_esdhc_be_ops,
  492. };
  493. static const struct sdhci_pltfm_data sdhci_esdhc_le_pdata = {
  494. .quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_BROKEN_CARD_DETECTION
  495. | SDHCI_QUIRK_NO_CARD_NO_RESET
  496. | SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
  497. .ops = &sdhci_esdhc_le_ops,
  498. };
  499. static struct soc_device_attribute soc_incorrect_hostver[] = {
  500. { .family = "QorIQ T4240", .revision = "1.0", },
  501. { .family = "QorIQ T4240", .revision = "2.0", },
  502. { },
  503. };
  504. static void esdhc_init(struct platform_device *pdev, struct sdhci_host *host)
  505. {
  506. struct sdhci_pltfm_host *pltfm_host;
  507. struct sdhci_esdhc *esdhc;
  508. u16 host_ver;
  509. pltfm_host = sdhci_priv(host);
  510. esdhc = sdhci_pltfm_priv(pltfm_host);
  511. host_ver = sdhci_readw(host, SDHCI_HOST_VERSION);
  512. esdhc->vendor_ver = (host_ver & SDHCI_VENDOR_VER_MASK) >>
  513. SDHCI_VENDOR_VER_SHIFT;
  514. esdhc->spec_ver = host_ver & SDHCI_SPEC_VER_MASK;
  515. if (soc_device_match(soc_incorrect_hostver))
  516. esdhc->quirk_incorrect_hostver = true;
  517. else
  518. esdhc->quirk_incorrect_hostver = false;
  519. }
  520. static int sdhci_esdhc_probe(struct platform_device *pdev)
  521. {
  522. struct sdhci_host *host;
  523. struct device_node *np;
  524. struct sdhci_pltfm_host *pltfm_host;
  525. struct sdhci_esdhc *esdhc;
  526. int ret;
  527. np = pdev->dev.of_node;
  528. if (of_property_read_bool(np, "little-endian"))
  529. host = sdhci_pltfm_init(pdev, &sdhci_esdhc_le_pdata,
  530. sizeof(struct sdhci_esdhc));
  531. else
  532. host = sdhci_pltfm_init(pdev, &sdhci_esdhc_be_pdata,
  533. sizeof(struct sdhci_esdhc));
  534. if (IS_ERR(host))
  535. return PTR_ERR(host);
  536. esdhc_init(pdev, host);
  537. sdhci_get_of_property(pdev);
  538. pltfm_host = sdhci_priv(host);
  539. esdhc = sdhci_pltfm_priv(pltfm_host);
  540. if (esdhc->vendor_ver == VENDOR_V_22)
  541. host->quirks2 |= SDHCI_QUIRK2_HOST_NO_CMD23;
  542. if (esdhc->vendor_ver > VENDOR_V_22)
  543. host->quirks &= ~SDHCI_QUIRK_NO_BUSY_IRQ;
  544. if (of_device_is_compatible(np, "fsl,p5040-esdhc") ||
  545. of_device_is_compatible(np, "fsl,p5020-esdhc") ||
  546. of_device_is_compatible(np, "fsl,p4080-esdhc") ||
  547. of_device_is_compatible(np, "fsl,p1020-esdhc") ||
  548. of_device_is_compatible(np, "fsl,t1040-esdhc") ||
  549. of_device_is_compatible(np, "fsl,ls1021a-esdhc"))
  550. host->quirks &= ~SDHCI_QUIRK_BROKEN_CARD_DETECTION;
  551. if (of_device_is_compatible(np, "fsl,ls1021a-esdhc"))
  552. host->quirks |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL;
  553. if (of_device_is_compatible(np, "fsl,p2020-esdhc")) {
  554. /*
  555. * Freescale messed up with P2020 as it has a non-standard
  556. * host control register
  557. */
  558. host->quirks2 |= SDHCI_QUIRK2_BROKEN_HOST_CONTROL;
  559. }
  560. /* call to generic mmc_of_parse to support additional capabilities */
  561. ret = mmc_of_parse(host->mmc);
  562. if (ret)
  563. goto err;
  564. mmc_of_parse_voltage(np, &host->ocr_mask);
  565. ret = sdhci_add_host(host);
  566. if (ret)
  567. goto err;
  568. return 0;
  569. err:
  570. sdhci_pltfm_free(pdev);
  571. return ret;
  572. }
  573. static const struct of_device_id sdhci_esdhc_of_match[] = {
  574. { .compatible = "fsl,mpc8379-esdhc" },
  575. { .compatible = "fsl,mpc8536-esdhc" },
  576. { .compatible = "fsl,esdhc" },
  577. { }
  578. };
  579. MODULE_DEVICE_TABLE(of, sdhci_esdhc_of_match);
  580. static struct platform_driver sdhci_esdhc_driver = {
  581. .driver = {
  582. .name = "sdhci-esdhc",
  583. .of_match_table = sdhci_esdhc_of_match,
  584. .pm = &esdhc_of_dev_pm_ops,
  585. },
  586. .probe = sdhci_esdhc_probe,
  587. .remove = sdhci_pltfm_unregister,
  588. };
  589. module_platform_driver(sdhci_esdhc_driver);
  590. MODULE_DESCRIPTION("SDHCI OF driver for Freescale MPC eSDHC");
  591. MODULE_AUTHOR("Xiaobo Xie <X.Xie@freescale.com>, "
  592. "Anton Vorontsov <avorontsov@ru.mvista.com>");
  593. MODULE_LICENSE("GPL v2");