sm-cpu.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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_cpu_proto_ops *imx_cpu_ops;
  12. static struct scmi_protocol_handle *ph;
  13. int scmi_imx_cpu_reset_vector_set(u32 cpuid, u64 vector, bool start, bool boot,
  14. bool resume)
  15. {
  16. if (!ph)
  17. return -EPROBE_DEFER;
  18. return imx_cpu_ops->cpu_reset_vector_set(ph, cpuid, vector, start,
  19. boot, resume);
  20. }
  21. EXPORT_SYMBOL(scmi_imx_cpu_reset_vector_set);
  22. int scmi_imx_cpu_start(u32 cpuid, bool start)
  23. {
  24. if (!ph)
  25. return -EPROBE_DEFER;
  26. if (start)
  27. return imx_cpu_ops->cpu_start(ph, cpuid, true);
  28. return imx_cpu_ops->cpu_start(ph, cpuid, false);
  29. };
  30. EXPORT_SYMBOL(scmi_imx_cpu_start);
  31. int scmi_imx_cpu_started(u32 cpuid, bool *started)
  32. {
  33. if (!ph)
  34. return -EPROBE_DEFER;
  35. if (!started)
  36. return -EINVAL;
  37. return imx_cpu_ops->cpu_started(ph, cpuid, started);
  38. };
  39. EXPORT_SYMBOL(scmi_imx_cpu_started);
  40. static int scmi_imx_cpu_probe(struct scmi_device *sdev)
  41. {
  42. const struct scmi_handle *handle = sdev->handle;
  43. if (!handle)
  44. return -ENODEV;
  45. if (imx_cpu_ops) {
  46. dev_err(&sdev->dev, "sm cpu already initialized\n");
  47. return -EEXIST;
  48. }
  49. imx_cpu_ops = handle->devm_protocol_get(sdev, SCMI_PROTOCOL_IMX_CPU, &ph);
  50. if (IS_ERR(imx_cpu_ops))
  51. return PTR_ERR(imx_cpu_ops);
  52. return 0;
  53. }
  54. static const struct scmi_device_id scmi_id_table[] = {
  55. { SCMI_PROTOCOL_IMX_CPU, "imx-cpu" },
  56. { },
  57. };
  58. MODULE_DEVICE_TABLE(scmi, scmi_id_table);
  59. static struct scmi_driver scmi_imx_cpu_driver = {
  60. .name = "scmi-imx-cpu",
  61. .probe = scmi_imx_cpu_probe,
  62. .id_table = scmi_id_table,
  63. };
  64. module_scmi_driver(scmi_imx_cpu_driver);
  65. MODULE_AUTHOR("Peng Fan <peng.fan@nxp.com>");
  66. MODULE_DESCRIPTION("IMX SM CPU driver");
  67. MODULE_LICENSE("GPL");