sdhci-of-esdhc.c 17 KB

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