scmi_sensor.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright 2021-2024 NXP
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <lib/libc/errno.h>
  7. #include <stdint.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include "../../../drivers/scmi-msg/sensor.h"
  11. #include <common/debug.h>
  12. #include <drivers/scmi.h>
  13. #include <lib/mmio.h>
  14. #include <lib/utils_def.h>
  15. #include <scmi.h>
  16. #include <upower_api.h>
  17. /* Only Temperature now */
  18. static uint16_t imx_scmi_sensor_count(unsigned int agent_id __unused)
  19. {
  20. return 1U;
  21. }
  22. uint8_t imx_scmi_sensor_max_requests(unsigned int agent_id __unused)
  23. {
  24. return 1U;
  25. }
  26. extern int upower_read_temperature(uint32_t sensor_id, int32_t *temperature);
  27. int imx_scmi_sensor_reading_get(uint32_t agent_id __unused, uint16_t sensor_id __unused,
  28. uint32_t *val)
  29. {
  30. int32_t temperature;
  31. int ret;
  32. ret = upower_read_temperature(1, &temperature);
  33. if (ret != 0U) {
  34. val[0] = 0xFFFFFFFF;
  35. } else {
  36. val[0] = temperature;
  37. }
  38. val[1] = 0;
  39. val[2] = 0;
  40. val[3] = 0;
  41. return ret;
  42. }
  43. #define SCMI_SENSOR_NAME_LENGTH_MAX 16U
  44. uint32_t imx_scmi_sensor_state(uint32_t agent_id __unused, uint16_t sensor_id __unused)
  45. {
  46. return 1U;
  47. }
  48. uint32_t imx_scmi_sensor_description_get(uint32_t agent_id __unused, uint16_t desc_index __unused,
  49. struct scmi_sensor_desc *desc __unused)
  50. {
  51. desc->id = 0;
  52. desc->attr_low = 0;
  53. desc->attr_high = 2;
  54. strlcpy((char *)desc->name, "UPOWER-TEMP", 12);
  55. desc->power = 0;
  56. desc->resolution = 0;
  57. desc->min_range_low = 0;
  58. desc->min_range_high = 0x80000000;
  59. desc->max_range_low = 0xffffffff;
  60. desc->max_range_high = 0x7fffffff;
  61. return 1U;
  62. }
  63. REGISTER_SCMI_SENSOR_OPS(imx_scmi_sensor_count,
  64. imx_scmi_sensor_max_requests,
  65. NULL,
  66. imx_scmi_sensor_reading_get,
  67. imx_scmi_sensor_description_get,
  68. NULL,
  69. imx_scmi_sensor_state,
  70. NULL);