qcom-apcs-ipc-mailbox.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Copyright (c) 2017, Linaro Ltd
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 and
  6. * only version 2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <linux/io.h>
  16. #include <linux/slab.h>
  17. #include <linux/of.h>
  18. #include <linux/of_platform.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/mailbox_controller.h>
  21. #define QCOM_APCS_IPC_BITS 32
  22. struct qcom_apcs_ipc {
  23. struct mbox_controller mbox;
  24. struct mbox_chan mbox_chans[QCOM_APCS_IPC_BITS];
  25. void __iomem *reg;
  26. unsigned long offset;
  27. };
  28. static int qcom_apcs_ipc_send_data(struct mbox_chan *chan, void *data)
  29. {
  30. struct qcom_apcs_ipc *apcs = container_of(chan->mbox,
  31. struct qcom_apcs_ipc, mbox);
  32. unsigned long idx = (unsigned long)chan->con_priv;
  33. writel(BIT(idx), apcs->reg);
  34. return 0;
  35. }
  36. static const struct mbox_chan_ops qcom_apcs_ipc_ops = {
  37. .send_data = qcom_apcs_ipc_send_data,
  38. };
  39. static int qcom_apcs_ipc_probe(struct platform_device *pdev)
  40. {
  41. struct qcom_apcs_ipc *apcs;
  42. struct resource *res;
  43. unsigned long offset;
  44. void __iomem *base;
  45. unsigned long i;
  46. int ret;
  47. apcs = devm_kzalloc(&pdev->dev, sizeof(*apcs), GFP_KERNEL);
  48. if (!apcs)
  49. return -ENOMEM;
  50. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  51. base = devm_ioremap_resource(&pdev->dev, res);
  52. if (IS_ERR(base))
  53. return PTR_ERR(base);
  54. offset = (unsigned long)of_device_get_match_data(&pdev->dev);
  55. apcs->reg = base + offset;
  56. /* Initialize channel identifiers */
  57. for (i = 0; i < ARRAY_SIZE(apcs->mbox_chans); i++)
  58. apcs->mbox_chans[i].con_priv = (void *)i;
  59. apcs->mbox.dev = &pdev->dev;
  60. apcs->mbox.ops = &qcom_apcs_ipc_ops;
  61. apcs->mbox.chans = apcs->mbox_chans;
  62. apcs->mbox.num_chans = ARRAY_SIZE(apcs->mbox_chans);
  63. ret = mbox_controller_register(&apcs->mbox);
  64. if (ret) {
  65. dev_err(&pdev->dev, "failed to register APCS IPC controller\n");
  66. return ret;
  67. }
  68. platform_set_drvdata(pdev, apcs);
  69. return 0;
  70. }
  71. static int qcom_apcs_ipc_remove(struct platform_device *pdev)
  72. {
  73. struct qcom_apcs_ipc *apcs = platform_get_drvdata(pdev);
  74. mbox_controller_unregister(&apcs->mbox);
  75. return 0;
  76. }
  77. /* .data is the offset of the ipc register within the global block */
  78. static const struct of_device_id qcom_apcs_ipc_of_match[] = {
  79. { .compatible = "qcom,msm8916-apcs-kpss-global", .data = (void *)8 },
  80. { .compatible = "qcom,msm8996-apcs-hmss-global", .data = (void *)16 },
  81. {}
  82. };
  83. MODULE_DEVICE_TABLE(of, qcom_apcs_ipc_of_match);
  84. static struct platform_driver qcom_apcs_ipc_driver = {
  85. .probe = qcom_apcs_ipc_probe,
  86. .remove = qcom_apcs_ipc_remove,
  87. .driver = {
  88. .name = "qcom_apcs_ipc",
  89. .of_match_table = qcom_apcs_ipc_of_match,
  90. },
  91. };
  92. static int __init qcom_apcs_ipc_init(void)
  93. {
  94. return platform_driver_register(&qcom_apcs_ipc_driver);
  95. }
  96. postcore_initcall(qcom_apcs_ipc_init);
  97. static void __exit qcom_apcs_ipc_exit(void)
  98. {
  99. platform_driver_unregister(&qcom_apcs_ipc_driver);
  100. }
  101. module_exit(qcom_apcs_ipc_exit);
  102. MODULE_LICENSE("GPL v2");
  103. MODULE_DESCRIPTION("Qualcomm APCS IPC driver");