ti-j721e-ufs.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // SPDX-License-Identifier: GPL-2.0
  2. //
  3. // Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
  4. //
  5. #include <linux/clk.h>
  6. #include <linux/io.h>
  7. #include <linux/kernel.h>
  8. #include <linux/module.h>
  9. #include <linux/of_platform.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/pm_runtime.h>
  12. #define TI_UFS_SS_CTRL 0x4
  13. #define TI_UFS_SS_RST_N_PCS BIT(0)
  14. #define TI_UFS_SS_CLK_26MHZ BIT(4)
  15. static int ti_j721e_ufs_probe(struct platform_device *pdev)
  16. {
  17. struct device *dev = &pdev->dev;
  18. unsigned long clk_rate;
  19. void __iomem *regbase;
  20. struct clk *clk;
  21. u32 reg = 0;
  22. int ret;
  23. regbase = devm_platform_ioremap_resource(pdev, 0);
  24. if (IS_ERR(regbase))
  25. return PTR_ERR(regbase);
  26. pm_runtime_enable(dev);
  27. ret = pm_runtime_resume_and_get(dev);
  28. if (ret < 0)
  29. goto disable_pm;
  30. /* Select MPHY refclk frequency */
  31. clk = devm_clk_get(dev, NULL);
  32. if (IS_ERR(clk)) {
  33. ret = PTR_ERR(clk);
  34. dev_err(dev, "Cannot claim MPHY clock.\n");
  35. goto clk_err;
  36. }
  37. clk_rate = clk_get_rate(clk);
  38. if (clk_rate == 26000000)
  39. reg |= TI_UFS_SS_CLK_26MHZ;
  40. devm_clk_put(dev, clk);
  41. /* Take UFS slave device out of reset */
  42. reg |= TI_UFS_SS_RST_N_PCS;
  43. writel(reg, regbase + TI_UFS_SS_CTRL);
  44. ret = of_platform_populate(pdev->dev.of_node, NULL, NULL,
  45. dev);
  46. if (ret) {
  47. dev_err(dev, "failed to populate child nodes %d\n", ret);
  48. goto clk_err;
  49. }
  50. return ret;
  51. clk_err:
  52. pm_runtime_put_sync(dev);
  53. disable_pm:
  54. pm_runtime_disable(dev);
  55. return ret;
  56. }
  57. static int ti_j721e_ufs_remove(struct platform_device *pdev)
  58. {
  59. of_platform_depopulate(&pdev->dev);
  60. pm_runtime_put_sync(&pdev->dev);
  61. pm_runtime_disable(&pdev->dev);
  62. return 0;
  63. }
  64. static const struct of_device_id ti_j721e_ufs_of_match[] = {
  65. {
  66. .compatible = "ti,j721e-ufs",
  67. },
  68. { },
  69. };
  70. static struct platform_driver ti_j721e_ufs_driver = {
  71. .probe = ti_j721e_ufs_probe,
  72. .remove = ti_j721e_ufs_remove,
  73. .driver = {
  74. .name = "ti-j721e-ufs",
  75. .of_match_table = ti_j721e_ufs_of_match,
  76. },
  77. };
  78. module_platform_driver(ti_j721e_ufs_driver);
  79. MODULE_AUTHOR("Vignesh Raghavendra <[email protected]>");
  80. MODULE_DESCRIPTION("TI UFS host controller glue driver");
  81. MODULE_LICENSE("GPL v2");