sdhci-of-esdhc.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  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. /*
  373. * Limit SD clock to 167MHz for ls1046a according to its datasheet
  374. */
  375. if (clock > 167000000 &&
  376. of_find_compatible_node(NULL, NULL, "fsl,ls1046a-esdhc"))
  377. clock = 167000000;
  378. /*
  379. * Limit SD clock to 125MHz for ls1012a according to its datasheet
  380. */
  381. if (clock > 125000000 &&
  382. of_find_compatible_node(NULL, NULL, "fsl,ls1012a-esdhc"))
  383. clock = 125000000;
  384. /* Workaround to reduce the clock frequency for p1010 esdhc */
  385. if (of_find_compatible_node(NULL, NULL, "fsl,p1010-esdhc")) {
  386. if (clock > 20000000)
  387. clock -= 5000000;
  388. if (clock > 40000000)
  389. clock -= 5000000;
  390. }
  391. temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL);
  392. temp &= ~(ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN
  393. | ESDHC_CLOCK_MASK);
  394. sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
  395. while (host->max_clk / pre_div / 16 > clock && pre_div < 256)
  396. pre_div *= 2;
  397. while (host->max_clk / pre_div / div > clock && div < 16)
  398. div++;
  399. dev_dbg(mmc_dev(host->mmc), "desired SD clock: %d, actual: %d\n",
  400. clock, host->max_clk / pre_div / div);
  401. host->mmc->actual_clock = host->max_clk / pre_div / div;
  402. pre_div >>= 1;
  403. div--;
  404. temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL);
  405. temp |= (ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN
  406. | (div << ESDHC_DIVIDER_SHIFT)
  407. | (pre_div << ESDHC_PREDIV_SHIFT));
  408. sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
  409. mdelay(1);
  410. }
  411. static void esdhc_pltfm_set_bus_width(struct sdhci_host *host, int width)
  412. {
  413. u32 ctrl;
  414. ctrl = sdhci_readl(host, ESDHC_PROCTL);
  415. ctrl &= (~ESDHC_CTRL_BUSWIDTH_MASK);
  416. switch (width) {
  417. case MMC_BUS_WIDTH_8:
  418. ctrl |= ESDHC_CTRL_8BITBUS;
  419. break;
  420. case MMC_BUS_WIDTH_4:
  421. ctrl |= ESDHC_CTRL_4BITBUS;
  422. break;
  423. default:
  424. break;
  425. }
  426. sdhci_writel(host, ctrl, ESDHC_PROCTL);
  427. }
  428. static void esdhc_reset(struct sdhci_host *host, u8 mask)
  429. {
  430. sdhci_reset(host, mask);
  431. sdhci_writel(host, host->ier, SDHCI_INT_ENABLE);
  432. sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE);
  433. }
  434. #ifdef CONFIG_PM_SLEEP
  435. static u32 esdhc_proctl;
  436. static int esdhc_of_suspend(struct device *dev)
  437. {
  438. struct sdhci_host *host = dev_get_drvdata(dev);
  439. esdhc_proctl = sdhci_readl(host, SDHCI_HOST_CONTROL);
  440. return sdhci_suspend_host(host);
  441. }
  442. static int esdhc_of_resume(struct device *dev)
  443. {
  444. struct sdhci_host *host = dev_get_drvdata(dev);
  445. int ret = sdhci_resume_host(host);
  446. if (ret == 0) {
  447. /* Isn't this already done by sdhci_resume_host() ? --rmk */
  448. esdhc_of_enable_dma(host);
  449. sdhci_writel(host, esdhc_proctl, SDHCI_HOST_CONTROL);
  450. }
  451. return ret;
  452. }
  453. #endif
  454. static SIMPLE_DEV_PM_OPS(esdhc_of_dev_pm_ops,
  455. esdhc_of_suspend,
  456. esdhc_of_resume);
  457. static const struct sdhci_ops sdhci_esdhc_be_ops = {
  458. .read_l = esdhc_be_readl,
  459. .read_w = esdhc_be_readw,
  460. .read_b = esdhc_be_readb,
  461. .write_l = esdhc_be_writel,
  462. .write_w = esdhc_be_writew,
  463. .write_b = esdhc_be_writeb,
  464. .set_clock = esdhc_of_set_clock,
  465. .enable_dma = esdhc_of_enable_dma,
  466. .get_max_clock = esdhc_of_get_max_clock,
  467. .get_min_clock = esdhc_of_get_min_clock,
  468. .adma_workaround = esdhc_of_adma_workaround,
  469. .set_bus_width = esdhc_pltfm_set_bus_width,
  470. .reset = esdhc_reset,
  471. .set_uhs_signaling = sdhci_set_uhs_signaling,
  472. };
  473. static const struct sdhci_ops sdhci_esdhc_le_ops = {
  474. .read_l = esdhc_le_readl,
  475. .read_w = esdhc_le_readw,
  476. .read_b = esdhc_le_readb,
  477. .write_l = esdhc_le_writel,
  478. .write_w = esdhc_le_writew,
  479. .write_b = esdhc_le_writeb,
  480. .set_clock = esdhc_of_set_clock,
  481. .enable_dma = esdhc_of_enable_dma,
  482. .get_max_clock = esdhc_of_get_max_clock,
  483. .get_min_clock = esdhc_of_get_min_clock,
  484. .adma_workaround = esdhc_of_adma_workaround,
  485. .set_bus_width = esdhc_pltfm_set_bus_width,
  486. .reset = esdhc_reset,
  487. .set_uhs_signaling = sdhci_set_uhs_signaling,
  488. };
  489. static const struct sdhci_pltfm_data sdhci_esdhc_be_pdata = {
  490. .quirks = ESDHC_DEFAULT_QUIRKS |
  491. #ifdef CONFIG_PPC
  492. SDHCI_QUIRK_BROKEN_CARD_DETECTION |
  493. #endif
  494. SDHCI_QUIRK_NO_CARD_NO_RESET |
  495. SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
  496. .ops = &sdhci_esdhc_be_ops,
  497. };
  498. static const struct sdhci_pltfm_data sdhci_esdhc_le_pdata = {
  499. .quirks = ESDHC_DEFAULT_QUIRKS |
  500. SDHCI_QUIRK_NO_CARD_NO_RESET |
  501. SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
  502. .ops = &sdhci_esdhc_le_ops,
  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. }
  516. static int sdhci_esdhc_probe(struct platform_device *pdev)
  517. {
  518. struct sdhci_host *host;
  519. struct device_node *np;
  520. struct sdhci_pltfm_host *pltfm_host;
  521. struct sdhci_esdhc *esdhc;
  522. int ret;
  523. np = pdev->dev.of_node;
  524. if (of_property_read_bool(np, "little-endian"))
  525. host = sdhci_pltfm_init(pdev, &sdhci_esdhc_le_pdata,
  526. sizeof(struct sdhci_esdhc));
  527. else
  528. host = sdhci_pltfm_init(pdev, &sdhci_esdhc_be_pdata,
  529. sizeof(struct sdhci_esdhc));
  530. if (IS_ERR(host))
  531. return PTR_ERR(host);
  532. esdhc_init(pdev, host);
  533. sdhci_get_of_property(pdev);
  534. pltfm_host = sdhci_priv(host);
  535. esdhc = sdhci_pltfm_priv(pltfm_host);
  536. if (esdhc->vendor_ver == VENDOR_V_22)
  537. host->quirks2 |= SDHCI_QUIRK2_HOST_NO_CMD23;
  538. if (esdhc->vendor_ver > VENDOR_V_22)
  539. host->quirks &= ~SDHCI_QUIRK_NO_BUSY_IRQ;
  540. if (of_device_is_compatible(np, "fsl,p5040-esdhc") ||
  541. of_device_is_compatible(np, "fsl,p5020-esdhc") ||
  542. of_device_is_compatible(np, "fsl,p4080-esdhc") ||
  543. of_device_is_compatible(np, "fsl,p1020-esdhc") ||
  544. of_device_is_compatible(np, "fsl,t1040-esdhc"))
  545. host->quirks &= ~SDHCI_QUIRK_BROKEN_CARD_DETECTION;
  546. if (of_device_is_compatible(np, "fsl,ls1021a-esdhc"))
  547. host->quirks |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL;
  548. if (of_device_is_compatible(np, "fsl,p2020-esdhc")) {
  549. /*
  550. * Freescale messed up with P2020 as it has a non-standard
  551. * host control register
  552. */
  553. host->quirks2 |= SDHCI_QUIRK2_BROKEN_HOST_CONTROL;
  554. }
  555. /* call to generic mmc_of_parse to support additional capabilities */
  556. ret = mmc_of_parse(host->mmc);
  557. if (ret)
  558. goto err;
  559. mmc_of_parse_voltage(np, &host->ocr_mask);
  560. ret = sdhci_add_host(host);
  561. if (ret)
  562. goto err;
  563. return 0;
  564. err:
  565. sdhci_pltfm_free(pdev);
  566. return ret;
  567. }
  568. static const struct of_device_id sdhci_esdhc_of_match[] = {
  569. { .compatible = "fsl,mpc8379-esdhc" },
  570. { .compatible = "fsl,mpc8536-esdhc" },
  571. { .compatible = "fsl,esdhc" },
  572. { }
  573. };
  574. MODULE_DEVICE_TABLE(of, sdhci_esdhc_of_match);
  575. static struct platform_driver sdhci_esdhc_driver = {
  576. .driver = {
  577. .name = "sdhci-esdhc",
  578. .of_match_table = sdhci_esdhc_of_match,
  579. .pm = &esdhc_of_dev_pm_ops,
  580. },
  581. .probe = sdhci_esdhc_probe,
  582. .remove = sdhci_pltfm_unregister,
  583. };
  584. module_platform_driver(sdhci_esdhc_driver);
  585. MODULE_DESCRIPTION("SDHCI OF driver for Freescale MPC eSDHC");
  586. MODULE_AUTHOR("Xiaobo Xie <X.Xie@freescale.com>, "
  587. "Anton Vorontsov <avorontsov@ru.mvista.com>");
  588. MODULE_LICENSE("GPL v2");