sdhci_f_sdh30.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*
  2. * linux/drivers/mmc/host/sdhci_f_sdh30.c
  3. *
  4. * Copyright (C) 2013 - 2015 Fujitsu Semiconductor, Ltd
  5. * Vincent Yang <vincent.yang@tw.fujitsu.com>
  6. * Copyright (C) 2015 Linaro Ltd Andy Green <andy.green@linaro.org>
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, version 2 of the License.
  11. */
  12. #include <linux/err.h>
  13. #include <linux/delay.h>
  14. #include <linux/module.h>
  15. #include <linux/clk.h>
  16. #include "sdhci-pltfm.h"
  17. /* F_SDH30 extended Controller registers */
  18. #define F_SDH30_AHB_CONFIG 0x100
  19. #define F_SDH30_AHB_BIGED 0x00000040
  20. #define F_SDH30_BUSLOCK_DMA 0x00000020
  21. #define F_SDH30_BUSLOCK_EN 0x00000010
  22. #define F_SDH30_SIN 0x00000008
  23. #define F_SDH30_AHB_INCR_16 0x00000004
  24. #define F_SDH30_AHB_INCR_8 0x00000002
  25. #define F_SDH30_AHB_INCR_4 0x00000001
  26. #define F_SDH30_TUNING_SETTING 0x108
  27. #define F_SDH30_CMD_CHK_DIS 0x00010000
  28. #define F_SDH30_IO_CONTROL2 0x114
  29. #define F_SDH30_CRES_O_DN 0x00080000
  30. #define F_SDH30_MSEL_O_1_8 0x00040000
  31. #define F_SDH30_ESD_CONTROL 0x124
  32. #define F_SDH30_EMMC_RST 0x00000002
  33. #define F_SDH30_EMMC_HS200 0x01000000
  34. #define F_SDH30_CMD_DAT_DELAY 0x200
  35. #define F_SDH30_MIN_CLOCK 400000
  36. struct f_sdhost_priv {
  37. struct clk *clk_iface;
  38. struct clk *clk;
  39. u32 vendor_hs200;
  40. struct device *dev;
  41. };
  42. static void sdhci_f_sdh30_soft_voltage_switch(struct sdhci_host *host)
  43. {
  44. struct f_sdhost_priv *priv = sdhci_priv(host);
  45. u32 ctrl = 0;
  46. usleep_range(2500, 3000);
  47. ctrl = sdhci_readl(host, F_SDH30_IO_CONTROL2);
  48. ctrl |= F_SDH30_CRES_O_DN;
  49. sdhci_writel(host, ctrl, F_SDH30_IO_CONTROL2);
  50. ctrl |= F_SDH30_MSEL_O_1_8;
  51. sdhci_writel(host, ctrl, F_SDH30_IO_CONTROL2);
  52. ctrl &= ~F_SDH30_CRES_O_DN;
  53. sdhci_writel(host, ctrl, F_SDH30_IO_CONTROL2);
  54. usleep_range(2500, 3000);
  55. if (priv->vendor_hs200) {
  56. dev_info(priv->dev, "%s: setting hs200\n", __func__);
  57. ctrl = sdhci_readl(host, F_SDH30_ESD_CONTROL);
  58. ctrl |= priv->vendor_hs200;
  59. sdhci_writel(host, ctrl, F_SDH30_ESD_CONTROL);
  60. }
  61. ctrl = sdhci_readl(host, F_SDH30_TUNING_SETTING);
  62. ctrl |= F_SDH30_CMD_CHK_DIS;
  63. sdhci_writel(host, ctrl, F_SDH30_TUNING_SETTING);
  64. }
  65. static unsigned int sdhci_f_sdh30_get_min_clock(struct sdhci_host *host)
  66. {
  67. return F_SDH30_MIN_CLOCK;
  68. }
  69. static void sdhci_f_sdh30_reset(struct sdhci_host *host, u8 mask)
  70. {
  71. if (sdhci_readw(host, SDHCI_CLOCK_CONTROL) == 0)
  72. sdhci_writew(host, 0xBC01, SDHCI_CLOCK_CONTROL);
  73. sdhci_reset(host, mask);
  74. }
  75. static const struct sdhci_ops sdhci_f_sdh30_ops = {
  76. .voltage_switch = sdhci_f_sdh30_soft_voltage_switch,
  77. .get_min_clock = sdhci_f_sdh30_get_min_clock,
  78. .reset = sdhci_f_sdh30_reset,
  79. .set_clock = sdhci_set_clock,
  80. .set_bus_width = sdhci_set_bus_width,
  81. .set_uhs_signaling = sdhci_set_uhs_signaling,
  82. };
  83. static int sdhci_f_sdh30_probe(struct platform_device *pdev)
  84. {
  85. struct sdhci_host *host;
  86. struct device *dev = &pdev->dev;
  87. struct resource *res;
  88. int irq, ctrl = 0, ret = 0;
  89. struct f_sdhost_priv *priv;
  90. u32 reg = 0;
  91. irq = platform_get_irq(pdev, 0);
  92. if (irq < 0) {
  93. dev_err(dev, "%s: no irq specified\n", __func__);
  94. return irq;
  95. }
  96. host = sdhci_alloc_host(dev, sizeof(struct f_sdhost_priv));
  97. if (IS_ERR(host))
  98. return PTR_ERR(host);
  99. priv = sdhci_priv(host);
  100. priv->dev = dev;
  101. host->quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC |
  102. SDHCI_QUIRK_INVERTED_WRITE_PROTECT;
  103. host->quirks2 = SDHCI_QUIRK2_SUPPORT_SINGLE |
  104. SDHCI_QUIRK2_TUNING_WORK_AROUND;
  105. ret = mmc_of_parse(host->mmc);
  106. if (ret)
  107. goto err;
  108. platform_set_drvdata(pdev, host);
  109. sdhci_get_of_property(pdev);
  110. host->hw_name = "f_sdh30";
  111. host->ops = &sdhci_f_sdh30_ops;
  112. host->irq = irq;
  113. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  114. host->ioaddr = devm_ioremap_resource(&pdev->dev, res);
  115. if (IS_ERR(host->ioaddr)) {
  116. ret = PTR_ERR(host->ioaddr);
  117. goto err;
  118. }
  119. priv->clk_iface = devm_clk_get(&pdev->dev, "iface");
  120. if (IS_ERR(priv->clk_iface)) {
  121. ret = PTR_ERR(priv->clk_iface);
  122. goto err;
  123. }
  124. ret = clk_prepare_enable(priv->clk_iface);
  125. if (ret)
  126. goto err;
  127. priv->clk = devm_clk_get(&pdev->dev, "core");
  128. if (IS_ERR(priv->clk)) {
  129. ret = PTR_ERR(priv->clk);
  130. goto err_clk;
  131. }
  132. ret = clk_prepare_enable(priv->clk);
  133. if (ret)
  134. goto err_clk;
  135. /* init vendor specific regs */
  136. ctrl = sdhci_readw(host, F_SDH30_AHB_CONFIG);
  137. ctrl |= F_SDH30_SIN | F_SDH30_AHB_INCR_16 | F_SDH30_AHB_INCR_8 |
  138. F_SDH30_AHB_INCR_4;
  139. ctrl &= ~(F_SDH30_AHB_BIGED | F_SDH30_BUSLOCK_EN);
  140. sdhci_writew(host, ctrl, F_SDH30_AHB_CONFIG);
  141. reg = sdhci_readl(host, F_SDH30_ESD_CONTROL);
  142. sdhci_writel(host, reg & ~F_SDH30_EMMC_RST, F_SDH30_ESD_CONTROL);
  143. msleep(20);
  144. sdhci_writel(host, reg | F_SDH30_EMMC_RST, F_SDH30_ESD_CONTROL);
  145. reg = sdhci_readl(host, SDHCI_CAPABILITIES);
  146. if (reg & SDHCI_CAN_DO_8BIT)
  147. priv->vendor_hs200 = F_SDH30_EMMC_HS200;
  148. ret = sdhci_add_host(host);
  149. if (ret)
  150. goto err_add_host;
  151. return 0;
  152. err_add_host:
  153. clk_disable_unprepare(priv->clk);
  154. err_clk:
  155. clk_disable_unprepare(priv->clk_iface);
  156. err:
  157. sdhci_free_host(host);
  158. return ret;
  159. }
  160. static int sdhci_f_sdh30_remove(struct platform_device *pdev)
  161. {
  162. struct sdhci_host *host = platform_get_drvdata(pdev);
  163. struct f_sdhost_priv *priv = sdhci_priv(host);
  164. sdhci_remove_host(host, readl(host->ioaddr + SDHCI_INT_STATUS) ==
  165. 0xffffffff);
  166. clk_disable_unprepare(priv->clk_iface);
  167. clk_disable_unprepare(priv->clk);
  168. sdhci_free_host(host);
  169. platform_set_drvdata(pdev, NULL);
  170. return 0;
  171. }
  172. static const struct of_device_id f_sdh30_dt_ids[] = {
  173. { .compatible = "fujitsu,mb86s70-sdhci-3.0" },
  174. { /* sentinel */ }
  175. };
  176. MODULE_DEVICE_TABLE(of, f_sdh30_dt_ids);
  177. static struct platform_driver sdhci_f_sdh30_driver = {
  178. .driver = {
  179. .name = "f_sdh30",
  180. .of_match_table = f_sdh30_dt_ids,
  181. .pm = &sdhci_pltfm_pmops,
  182. },
  183. .probe = sdhci_f_sdh30_probe,
  184. .remove = sdhci_f_sdh30_remove,
  185. };
  186. module_platform_driver(sdhci_f_sdh30_driver);
  187. MODULE_DESCRIPTION("F_SDH30 SD Card Controller driver");
  188. MODULE_LICENSE("GPL v2");
  189. MODULE_AUTHOR("FUJITSU SEMICONDUCTOR LTD.");
  190. MODULE_ALIAS("platform:f_sdh30");