qcom_common.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Qualcomm Peripheral Image Loader helpers
  3. *
  4. * Copyright (C) 2016 Linaro Ltd
  5. * Copyright (C) 2015 Sony Mobile Communications Inc
  6. * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #include <linux/firmware.h>
  18. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/remoteproc.h>
  21. #include <linux/rpmsg/qcom_smd.h>
  22. #include "remoteproc_internal.h"
  23. #include "qcom_common.h"
  24. #define to_smd_subdev(d) container_of(d, struct qcom_rproc_subdev, subdev)
  25. /**
  26. * qcom_mdt_find_rsc_table() - provide dummy resource table for remoteproc
  27. * @rproc: remoteproc handle
  28. * @fw: firmware header
  29. * @tablesz: outgoing size of the table
  30. *
  31. * Returns a dummy table.
  32. */
  33. struct resource_table *qcom_mdt_find_rsc_table(struct rproc *rproc,
  34. const struct firmware *fw,
  35. int *tablesz)
  36. {
  37. static struct resource_table table = { .ver = 1, };
  38. *tablesz = sizeof(table);
  39. return &table;
  40. }
  41. EXPORT_SYMBOL_GPL(qcom_mdt_find_rsc_table);
  42. static int smd_subdev_probe(struct rproc_subdev *subdev)
  43. {
  44. struct qcom_rproc_subdev *smd = to_smd_subdev(subdev);
  45. smd->edge = qcom_smd_register_edge(smd->dev, smd->node);
  46. return IS_ERR(smd->edge) ? PTR_ERR(smd->edge) : 0;
  47. }
  48. static void smd_subdev_remove(struct rproc_subdev *subdev)
  49. {
  50. struct qcom_rproc_subdev *smd = to_smd_subdev(subdev);
  51. qcom_smd_unregister_edge(smd->edge);
  52. smd->edge = NULL;
  53. }
  54. /**
  55. * qcom_add_smd_subdev() - try to add a SMD subdevice to rproc
  56. * @rproc: rproc handle to parent the subdevice
  57. * @smd: reference to a Qualcomm subdev context
  58. */
  59. void qcom_add_smd_subdev(struct rproc *rproc, struct qcom_rproc_subdev *smd)
  60. {
  61. struct device *dev = &rproc->dev;
  62. smd->node = of_get_child_by_name(dev->parent->of_node, "smd-edge");
  63. if (!smd->node)
  64. return;
  65. smd->dev = dev;
  66. rproc_add_subdev(rproc, &smd->subdev, smd_subdev_probe, smd_subdev_remove);
  67. }
  68. EXPORT_SYMBOL_GPL(qcom_add_smd_subdev);
  69. /**
  70. * qcom_remove_smd_subdev() - remove the smd subdevice from rproc
  71. * @rproc: rproc handle
  72. * @smd: the SMD subdevice to remove
  73. */
  74. void qcom_remove_smd_subdev(struct rproc *rproc, struct qcom_rproc_subdev *smd)
  75. {
  76. rproc_remove_subdev(rproc, &smd->subdev);
  77. of_node_put(smd->node);
  78. }
  79. EXPORT_SYMBOL_GPL(qcom_remove_smd_subdev);
  80. MODULE_DESCRIPTION("Qualcomm Remoteproc helper driver");
  81. MODULE_LICENSE("GPL v2");