dw_mmc-bluefield.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2018 Mellanox Technologies.
  4. */
  5. #include <linux/arm-smccc.h>
  6. #include <linux/bitfield.h>
  7. #include <linux/bitops.h>
  8. #include <linux/mmc/host.h>
  9. #include <linux/mmc/mmc.h>
  10. #include <linux/module.h>
  11. #include <linux/of.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/pm_runtime.h>
  14. #include "dw_mmc.h"
  15. #include "dw_mmc-pltfm.h"
  16. #define UHS_REG_EXT_SAMPLE_MASK GENMASK(22, 16)
  17. #define UHS_REG_EXT_DRIVE_MASK GENMASK(29, 23)
  18. #define BLUEFIELD_UHS_REG_EXT_SAMPLE 2
  19. #define BLUEFIELD_UHS_REG_EXT_DRIVE 4
  20. /* SMC call for RST_N */
  21. #define BLUEFIELD_SMC_SET_EMMC_RST_N 0x82000007
  22. static void dw_mci_bluefield_set_ios(struct dw_mci *host, struct mmc_ios *ios)
  23. {
  24. u32 reg;
  25. /* Update the Drive and Sample fields in register UHS_REG_EXT. */
  26. reg = mci_readl(host, UHS_REG_EXT);
  27. reg &= ~UHS_REG_EXT_SAMPLE_MASK;
  28. reg |= FIELD_PREP(UHS_REG_EXT_SAMPLE_MASK,
  29. BLUEFIELD_UHS_REG_EXT_SAMPLE);
  30. reg &= ~UHS_REG_EXT_DRIVE_MASK;
  31. reg |= FIELD_PREP(UHS_REG_EXT_DRIVE_MASK, BLUEFIELD_UHS_REG_EXT_DRIVE);
  32. mci_writel(host, UHS_REG_EXT, reg);
  33. }
  34. static void dw_mci_bluefield_hw_reset(struct dw_mci *host)
  35. {
  36. struct arm_smccc_res res = { 0 };
  37. arm_smccc_smc(BLUEFIELD_SMC_SET_EMMC_RST_N, 0, 0, 0, 0, 0, 0, 0,
  38. &res);
  39. if (res.a0)
  40. pr_err("RST_N failed.\n");
  41. }
  42. static const struct dw_mci_drv_data bluefield_drv_data = {
  43. .set_ios = dw_mci_bluefield_set_ios,
  44. .hw_reset = dw_mci_bluefield_hw_reset
  45. };
  46. static const struct of_device_id dw_mci_bluefield_match[] = {
  47. { .compatible = "mellanox,bluefield-dw-mshc",
  48. .data = &bluefield_drv_data },
  49. {},
  50. };
  51. MODULE_DEVICE_TABLE(of, dw_mci_bluefield_match);
  52. static int dw_mci_bluefield_probe(struct platform_device *pdev)
  53. {
  54. return dw_mci_pltfm_register(pdev, &bluefield_drv_data);
  55. }
  56. static struct platform_driver dw_mci_bluefield_pltfm_driver = {
  57. .probe = dw_mci_bluefield_probe,
  58. .remove = dw_mci_pltfm_remove,
  59. .driver = {
  60. .name = "dwmmc_bluefield",
  61. .probe_type = PROBE_PREFER_ASYNCHRONOUS,
  62. .of_match_table = dw_mci_bluefield_match,
  63. .pm = &dw_mci_pltfm_pmops,
  64. },
  65. };
  66. module_platform_driver(dw_mci_bluefield_pltfm_driver);
  67. MODULE_DESCRIPTION("BlueField DW Multimedia Card driver");
  68. MODULE_AUTHOR("Mellanox Technologies");
  69. MODULE_LICENSE("GPL v2");