sdhci-of-esdhc.c 17 KB

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