dw_mmc-socfpga.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Altera SoCFPGA Specific Extensions for Synopsys DW Multimedia Card Interface
  3. * driver
  4. *
  5. * Copyright (C) 2012, Samsung Electronics Co., Ltd.
  6. * Copyright (C) 2013 Altera Corporation
  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; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * Taken from dw_mmc-exynos.c
  14. */
  15. #include <linux/clk.h>
  16. #include <linux/mfd/syscon.h>
  17. #include <linux/mmc/host.h>
  18. #include <linux/mmc/dw_mmc.h>
  19. #include <linux/module.h>
  20. #include <linux/of.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/regmap.h>
  23. #include "dw_mmc.h"
  24. #include "dw_mmc-pltfm.h"
  25. #define SYSMGR_SDMMCGRP_CTRL_OFFSET 0x108
  26. #define DRV_CLK_PHASE_SHIFT_SEL_MASK 0x7
  27. #define SYSMGR_SDMMC_CTRL_SET(smplsel, drvsel) \
  28. ((((smplsel) & 0x7) << 3) | (((drvsel) & 0x7) << 0))
  29. /* SOCFPGA implementation specific driver private data */
  30. struct dw_mci_socfpga_priv_data {
  31. u8 ciu_div; /* card interface unit divisor */
  32. u32 hs_timing; /* bitmask for CIU clock phase shift */
  33. struct regmap *sysreg; /* regmap for system manager register */
  34. };
  35. static int dw_mci_socfpga_priv_init(struct dw_mci *host)
  36. {
  37. return 0;
  38. }
  39. static int dw_mci_socfpga_setup_clock(struct dw_mci *host)
  40. {
  41. struct dw_mci_socfpga_priv_data *priv = host->priv;
  42. clk_disable_unprepare(host->ciu_clk);
  43. regmap_write(priv->sysreg, SYSMGR_SDMMCGRP_CTRL_OFFSET,
  44. priv->hs_timing);
  45. clk_prepare_enable(host->ciu_clk);
  46. host->bus_hz /= (priv->ciu_div + 1);
  47. return 0;
  48. }
  49. static void dw_mci_socfpga_prepare_command(struct dw_mci *host, u32 *cmdr)
  50. {
  51. struct dw_mci_socfpga_priv_data *priv = host->priv;
  52. if (priv->hs_timing & DRV_CLK_PHASE_SHIFT_SEL_MASK)
  53. *cmdr |= SDMMC_CMD_USE_HOLD_REG;
  54. }
  55. static int dw_mci_socfpga_parse_dt(struct dw_mci *host)
  56. {
  57. struct dw_mci_socfpga_priv_data *priv;
  58. struct device_node *np = host->dev->of_node;
  59. u32 timing[2];
  60. u32 div = 0;
  61. int ret;
  62. priv = devm_kzalloc(host->dev, sizeof(*priv), GFP_KERNEL);
  63. if (!priv) {
  64. dev_err(host->dev, "mem alloc failed for private data\n");
  65. return -ENOMEM;
  66. }
  67. priv->sysreg = syscon_regmap_lookup_by_compatible("altr,sys-mgr");
  68. if (IS_ERR(priv->sysreg)) {
  69. dev_err(host->dev, "regmap for altr,sys-mgr lookup failed.\n");
  70. return PTR_ERR(priv->sysreg);
  71. }
  72. ret = of_property_read_u32(np, "altr,dw-mshc-ciu-div", &div);
  73. if (ret)
  74. dev_info(host->dev, "No dw-mshc-ciu-div specified, assuming 1");
  75. priv->ciu_div = div;
  76. ret = of_property_read_u32_array(np,
  77. "altr,dw-mshc-sdr-timing", timing, 2);
  78. if (ret)
  79. return ret;
  80. priv->hs_timing = SYSMGR_SDMMC_CTRL_SET(timing[0], timing[1]);
  81. host->priv = priv;
  82. return 0;
  83. }
  84. static const struct dw_mci_drv_data socfpga_drv_data = {
  85. .init = dw_mci_socfpga_priv_init,
  86. .setup_clock = dw_mci_socfpga_setup_clock,
  87. .prepare_command = dw_mci_socfpga_prepare_command,
  88. .parse_dt = dw_mci_socfpga_parse_dt,
  89. };
  90. static const struct of_device_id dw_mci_socfpga_match[] = {
  91. { .compatible = "altr,socfpga-dw-mshc",
  92. .data = &socfpga_drv_data, },
  93. {},
  94. };
  95. MODULE_DEVICE_TABLE(of, dw_mci_socfpga_match);
  96. static int dw_mci_socfpga_probe(struct platform_device *pdev)
  97. {
  98. const struct dw_mci_drv_data *drv_data;
  99. const struct of_device_id *match;
  100. match = of_match_node(dw_mci_socfpga_match, pdev->dev.of_node);
  101. drv_data = match->data;
  102. return dw_mci_pltfm_register(pdev, drv_data);
  103. }
  104. static struct platform_driver dw_mci_socfpga_pltfm_driver = {
  105. .probe = dw_mci_socfpga_probe,
  106. .remove = __exit_p(dw_mci_pltfm_remove),
  107. .driver = {
  108. .name = "dwmmc_socfpga",
  109. .of_match_table = dw_mci_socfpga_match,
  110. .pm = &dw_mci_pltfm_pmops,
  111. },
  112. };
  113. module_platform_driver(dw_mci_socfpga_pltfm_driver);
  114. MODULE_DESCRIPTION("Altera SOCFPGA Specific DW-MSHC Driver Extension");
  115. MODULE_LICENSE("GPL v2");
  116. MODULE_ALIAS("platform:dwmmc-socfpga");