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