qcom-apcs-ipc-mailbox.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2017, Linaro Ltd
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/module.h>
  7. #include <linux/io.h>
  8. #include <linux/slab.h>
  9. #include <linux/of.h>
  10. #include <linux/of_platform.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/regmap.h>
  13. #include <linux/mailbox_controller.h>
  14. #define QCOM_APCS_IPC_BITS 32
  15. struct qcom_apcs_ipc {
  16. struct mbox_controller mbox;
  17. struct mbox_chan mbox_chans[QCOM_APCS_IPC_BITS];
  18. struct regmap *regmap;
  19. unsigned long offset;
  20. struct platform_device *clk;
  21. };
  22. struct qcom_apcs_ipc_data {
  23. int offset;
  24. char *clk_name;
  25. };
  26. static const struct qcom_apcs_ipc_data ipq6018_apcs_data = {
  27. .offset = 8, .clk_name = "qcom,apss-ipq6018-clk"
  28. };
  29. static const struct qcom_apcs_ipc_data ipq8074_apcs_data = {
  30. .offset = 8, .clk_name = NULL
  31. };
  32. static const struct qcom_apcs_ipc_data msm8916_apcs_data = {
  33. .offset = 8, .clk_name = "qcom-apcs-msm8916-clk"
  34. };
  35. static const struct qcom_apcs_ipc_data msm8994_apcs_data = {
  36. .offset = 8, .clk_name = NULL
  37. };
  38. static const struct qcom_apcs_ipc_data msm8996_apcs_data = {
  39. .offset = 16, .clk_name = NULL
  40. };
  41. static const struct qcom_apcs_ipc_data msm8998_apcs_data = {
  42. .offset = 8, .clk_name = NULL
  43. };
  44. static const struct qcom_apcs_ipc_data sdm660_apcs_data = {
  45. .offset = 8, .clk_name = NULL
  46. };
  47. static const struct qcom_apcs_ipc_data apps_shared_apcs_data = {
  48. .offset = 12, .clk_name = NULL
  49. };
  50. static const struct regmap_config apcs_regmap_config = {
  51. .reg_bits = 32,
  52. .reg_stride = 4,
  53. .val_bits = 32,
  54. .max_register = 0xFFC,
  55. .fast_io = true,
  56. };
  57. static int qcom_apcs_ipc_send_data(struct mbox_chan *chan, void *data)
  58. {
  59. struct qcom_apcs_ipc *apcs = container_of(chan->mbox,
  60. struct qcom_apcs_ipc, mbox);
  61. unsigned long idx = (unsigned long)chan->con_priv;
  62. return regmap_write(apcs->regmap, apcs->offset, BIT(idx));
  63. }
  64. static const struct mbox_chan_ops qcom_apcs_ipc_ops = {
  65. .send_data = qcom_apcs_ipc_send_data,
  66. };
  67. static int qcom_apcs_ipc_probe(struct platform_device *pdev)
  68. {
  69. struct qcom_apcs_ipc *apcs;
  70. const struct qcom_apcs_ipc_data *apcs_data;
  71. struct regmap *regmap;
  72. struct resource *res;
  73. void __iomem *base;
  74. unsigned long i;
  75. int ret;
  76. apcs = devm_kzalloc(&pdev->dev, sizeof(*apcs), GFP_KERNEL);
  77. if (!apcs)
  78. return -ENOMEM;
  79. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  80. base = devm_ioremap_resource(&pdev->dev, res);
  81. if (IS_ERR(base))
  82. return PTR_ERR(base);
  83. regmap = devm_regmap_init_mmio(&pdev->dev, base, &apcs_regmap_config);
  84. if (IS_ERR(regmap))
  85. return PTR_ERR(regmap);
  86. apcs_data = of_device_get_match_data(&pdev->dev);
  87. apcs->regmap = regmap;
  88. apcs->offset = apcs_data->offset;
  89. /* Initialize channel identifiers */
  90. for (i = 0; i < ARRAY_SIZE(apcs->mbox_chans); i++)
  91. apcs->mbox_chans[i].con_priv = (void *)i;
  92. apcs->mbox.dev = &pdev->dev;
  93. apcs->mbox.ops = &qcom_apcs_ipc_ops;
  94. apcs->mbox.chans = apcs->mbox_chans;
  95. apcs->mbox.num_chans = ARRAY_SIZE(apcs->mbox_chans);
  96. ret = devm_mbox_controller_register(&pdev->dev, &apcs->mbox);
  97. if (ret) {
  98. dev_err(&pdev->dev, "failed to register APCS IPC controller\n");
  99. return ret;
  100. }
  101. if (apcs_data->clk_name) {
  102. apcs->clk = platform_device_register_data(&pdev->dev,
  103. apcs_data->clk_name,
  104. PLATFORM_DEVID_AUTO,
  105. NULL, 0);
  106. if (IS_ERR(apcs->clk))
  107. dev_err(&pdev->dev, "failed to register APCS clk\n");
  108. }
  109. platform_set_drvdata(pdev, apcs);
  110. return 0;
  111. }
  112. static int qcom_apcs_ipc_remove(struct platform_device *pdev)
  113. {
  114. struct qcom_apcs_ipc *apcs = platform_get_drvdata(pdev);
  115. struct platform_device *clk = apcs->clk;
  116. platform_device_unregister(clk);
  117. return 0;
  118. }
  119. /* .data is the offset of the ipc register within the global block */
  120. static const struct of_device_id qcom_apcs_ipc_of_match[] = {
  121. { .compatible = "qcom,ipq6018-apcs-apps-global", .data = &ipq6018_apcs_data },
  122. { .compatible = "qcom,ipq8074-apcs-apps-global", .data = &ipq8074_apcs_data },
  123. { .compatible = "qcom,msm8916-apcs-kpss-global", .data = &msm8916_apcs_data },
  124. { .compatible = "qcom,msm8994-apcs-kpss-global", .data = &msm8994_apcs_data },
  125. { .compatible = "qcom,msm8996-apcs-hmss-global", .data = &msm8996_apcs_data },
  126. { .compatible = "qcom,msm8998-apcs-hmss-global", .data = &msm8998_apcs_data },
  127. { .compatible = "qcom,qcs404-apcs-apps-global", .data = &msm8916_apcs_data },
  128. { .compatible = "qcom,sc7180-apss-shared", .data = &apps_shared_apcs_data },
  129. { .compatible = "qcom,sdm660-apcs-hmss-global", .data = &sdm660_apcs_data },
  130. { .compatible = "qcom,sdm845-apss-shared", .data = &apps_shared_apcs_data },
  131. { .compatible = "qcom,sm8150-apss-shared", .data = &apps_shared_apcs_data },
  132. {}
  133. };
  134. MODULE_DEVICE_TABLE(of, qcom_apcs_ipc_of_match);
  135. static struct platform_driver qcom_apcs_ipc_driver = {
  136. .probe = qcom_apcs_ipc_probe,
  137. .remove = qcom_apcs_ipc_remove,
  138. .driver = {
  139. .name = "qcom_apcs_ipc",
  140. .of_match_table = qcom_apcs_ipc_of_match,
  141. },
  142. };
  143. static int __init qcom_apcs_ipc_init(void)
  144. {
  145. return platform_driver_register(&qcom_apcs_ipc_driver);
  146. }
  147. postcore_initcall(qcom_apcs_ipc_init);
  148. static void __exit qcom_apcs_ipc_exit(void)
  149. {
  150. platform_driver_unregister(&qcom_apcs_ipc_driver);
  151. }
  152. module_exit(qcom_apcs_ipc_exit);
  153. MODULE_LICENSE("GPL v2");
  154. MODULE_DESCRIPTION("Qualcomm APCS IPC driver");