pl353-smc.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * ARM PL353 SMC driver
  4. *
  5. * Copyright (C) 2012 - 2018 Xilinx, Inc
  6. * Author: Punnaiah Choudary Kalluri <punnaiah@xilinx.com>
  7. * Author: Naga Sureshkumar Relli <nagasure@xilinx.com>
  8. */
  9. #include <linux/clk.h>
  10. #include <linux/kernel.h>
  11. #include <linux/module.h>
  12. #include <linux/of.h>
  13. #include <linux/of_platform.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/amba/bus.h>
  16. /**
  17. * struct pl353_smc_data - Private smc driver structure
  18. * @memclk: Pointer to the peripheral clock
  19. * @aclk: Pointer to the AXI peripheral clock
  20. */
  21. struct pl353_smc_data {
  22. struct clk *memclk;
  23. struct clk *aclk;
  24. };
  25. static int __maybe_unused pl353_smc_suspend(struct device *dev)
  26. {
  27. struct pl353_smc_data *pl353_smc = dev_get_drvdata(dev);
  28. clk_disable(pl353_smc->memclk);
  29. clk_disable(pl353_smc->aclk);
  30. return 0;
  31. }
  32. static int __maybe_unused pl353_smc_resume(struct device *dev)
  33. {
  34. struct pl353_smc_data *pl353_smc = dev_get_drvdata(dev);
  35. int ret;
  36. ret = clk_enable(pl353_smc->aclk);
  37. if (ret) {
  38. dev_err(dev, "Cannot enable axi domain clock.\n");
  39. return ret;
  40. }
  41. ret = clk_enable(pl353_smc->memclk);
  42. if (ret) {
  43. dev_err(dev, "Cannot enable memory clock.\n");
  44. clk_disable(pl353_smc->aclk);
  45. return ret;
  46. }
  47. return ret;
  48. }
  49. static SIMPLE_DEV_PM_OPS(pl353_smc_dev_pm_ops, pl353_smc_suspend,
  50. pl353_smc_resume);
  51. static const struct of_device_id pl353_smc_supported_children[] = {
  52. {
  53. .compatible = "cfi-flash"
  54. },
  55. {
  56. .compatible = "arm,pl353-nand-r2p1",
  57. },
  58. {}
  59. };
  60. static int pl353_smc_probe(struct amba_device *adev, const struct amba_id *id)
  61. {
  62. struct device_node *of_node = adev->dev.of_node;
  63. const struct of_device_id *match = NULL;
  64. struct pl353_smc_data *pl353_smc;
  65. pl353_smc = devm_kzalloc(&adev->dev, sizeof(*pl353_smc), GFP_KERNEL);
  66. if (!pl353_smc)
  67. return -ENOMEM;
  68. pl353_smc->aclk = devm_clk_get_enabled(&adev->dev, "apb_pclk");
  69. if (IS_ERR(pl353_smc->aclk))
  70. return dev_err_probe(&adev->dev, PTR_ERR(pl353_smc->aclk),
  71. "aclk clock not found.\n");
  72. pl353_smc->memclk = devm_clk_get_enabled(&adev->dev, "memclk");
  73. if (IS_ERR(pl353_smc->memclk))
  74. return dev_err_probe(&adev->dev, PTR_ERR(pl353_smc->memclk),
  75. "memclk clock not found.\n");
  76. amba_set_drvdata(adev, pl353_smc);
  77. /* Find compatible children. Only a single child is supported */
  78. for_each_available_child_of_node_scoped(of_node, child) {
  79. match = of_match_node(pl353_smc_supported_children, child);
  80. if (!match) {
  81. dev_warn(&adev->dev, "unsupported child node\n");
  82. continue;
  83. }
  84. of_platform_device_create(child, NULL, &adev->dev);
  85. break;
  86. }
  87. if (!match) {
  88. dev_err(&adev->dev, "no matching children\n");
  89. return -ENODEV;
  90. }
  91. return 0;
  92. }
  93. static const struct amba_id pl353_ids[] = {
  94. {
  95. .id = 0x00041353,
  96. .mask = 0x000fffff,
  97. },
  98. { 0, 0 },
  99. };
  100. MODULE_DEVICE_TABLE(amba, pl353_ids);
  101. static struct amba_driver pl353_smc_driver = {
  102. .drv = {
  103. .name = "pl353-smc",
  104. .pm = &pl353_smc_dev_pm_ops,
  105. },
  106. .id_table = pl353_ids,
  107. .probe = pl353_smc_probe,
  108. };
  109. module_amba_driver(pl353_smc_driver);
  110. MODULE_AUTHOR("Xilinx, Inc.");
  111. MODULE_DESCRIPTION("ARM PL353 SMC Driver");
  112. MODULE_LICENSE("GPL");