sm-lmm.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright 2025 NXP
  4. */
  5. #include <linux/firmware/imx/sm.h>
  6. #include <linux/module.h>
  7. #include <linux/of.h>
  8. #include <linux/platform_device.h>
  9. #include <linux/scmi_protocol.h>
  10. #include <linux/scmi_imx_protocol.h>
  11. static const struct scmi_imx_lmm_proto_ops *imx_lmm_ops;
  12. static struct scmi_protocol_handle *ph;
  13. int scmi_imx_lmm_info(u32 lmid, struct scmi_imx_lmm_info *info)
  14. {
  15. if (!ph)
  16. return -EPROBE_DEFER;
  17. if (!info)
  18. return -EINVAL;
  19. return imx_lmm_ops->lmm_info(ph, lmid, info);
  20. };
  21. EXPORT_SYMBOL(scmi_imx_lmm_info);
  22. int scmi_imx_lmm_reset_vector_set(u32 lmid, u32 cpuid, u32 flags, u64 vector)
  23. {
  24. if (!ph)
  25. return -EPROBE_DEFER;
  26. return imx_lmm_ops->lmm_reset_vector_set(ph, lmid, cpuid, flags, vector);
  27. }
  28. EXPORT_SYMBOL(scmi_imx_lmm_reset_vector_set);
  29. int scmi_imx_lmm_operation(u32 lmid, enum scmi_imx_lmm_op op, u32 flags)
  30. {
  31. if (!ph)
  32. return -EPROBE_DEFER;
  33. switch (op) {
  34. case SCMI_IMX_LMM_BOOT:
  35. return imx_lmm_ops->lmm_power_boot(ph, lmid, true);
  36. case SCMI_IMX_LMM_POWER_ON:
  37. return imx_lmm_ops->lmm_power_boot(ph, lmid, false);
  38. case SCMI_IMX_LMM_SHUTDOWN:
  39. return imx_lmm_ops->lmm_shutdown(ph, lmid, flags);
  40. default:
  41. break;
  42. }
  43. return -EINVAL;
  44. }
  45. EXPORT_SYMBOL(scmi_imx_lmm_operation);
  46. static int scmi_imx_lmm_probe(struct scmi_device *sdev)
  47. {
  48. const struct scmi_handle *handle = sdev->handle;
  49. if (!handle)
  50. return -ENODEV;
  51. if (imx_lmm_ops) {
  52. dev_err(&sdev->dev, "lmm already initialized\n");
  53. return -EEXIST;
  54. }
  55. imx_lmm_ops = handle->devm_protocol_get(sdev, SCMI_PROTOCOL_IMX_LMM, &ph);
  56. if (IS_ERR(imx_lmm_ops))
  57. return PTR_ERR(imx_lmm_ops);
  58. return 0;
  59. }
  60. static const struct scmi_device_id scmi_id_table[] = {
  61. { SCMI_PROTOCOL_IMX_LMM, "imx-lmm" },
  62. { },
  63. };
  64. MODULE_DEVICE_TABLE(scmi, scmi_id_table);
  65. static struct scmi_driver scmi_imx_lmm_driver = {
  66. .name = "scmi-imx-lmm",
  67. .probe = scmi_imx_lmm_probe,
  68. .id_table = scmi_id_table,
  69. };
  70. module_scmi_driver(scmi_imx_lmm_driver);
  71. MODULE_AUTHOR("Peng Fan <peng.fan@nxp.com>");
  72. MODULE_DESCRIPTION("IMX SM LMM driver");
  73. MODULE_LICENSE("GPL");