Skip to content

Commit 38a1bdc

Browse files
punitagrawalsudeep-holla
authored andcommitted
firmware: arm_scpi: Extend to support sensors
ARM System Control Processor (SCP) provides an API to query and use the sensors available in the system. Extend the SCPI driver to support sensor messages. Signed-off-by: Punit Agrawal <[email protected]> Acked-by: Sudeep Holla <[email protected]>
1 parent d8a44fe commit 38a1bdc

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

drivers/firmware/arm_scpi.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,21 @@ struct dvfs_set {
219219
u8 index;
220220
} __packed;
221221

222+
struct sensor_capabilities {
223+
__le16 sensors;
224+
} __packed;
225+
226+
struct _scpi_sensor_info {
227+
__le16 sensor_id;
228+
u8 class;
229+
u8 trigger_type;
230+
char name[20];
231+
};
232+
233+
struct sensor_value {
234+
__le32 val;
235+
} __packed;
236+
222237
static struct scpi_drvinfo *scpi_info;
223238

224239
static int scpi_linux_errmap[SCPI_ERR_MAX] = {
@@ -481,6 +496,48 @@ static struct scpi_dvfs_info *scpi_dvfs_get_info(u8 domain)
481496
return info;
482497
}
483498

499+
static int scpi_sensor_get_capability(u16 *sensors)
500+
{
501+
struct sensor_capabilities cap_buf;
502+
int ret;
503+
504+
ret = scpi_send_message(SCPI_CMD_SENSOR_CAPABILITIES, NULL, 0, &cap_buf,
505+
sizeof(cap_buf));
506+
if (!ret)
507+
*sensors = le16_to_cpu(cap_buf.sensors);
508+
509+
return ret;
510+
}
511+
512+
static int scpi_sensor_get_info(u16 sensor_id, struct scpi_sensor_info *info)
513+
{
514+
__le16 id = cpu_to_le16(sensor_id);
515+
struct _scpi_sensor_info _info;
516+
int ret;
517+
518+
ret = scpi_send_message(SCPI_CMD_SENSOR_INFO, &id, sizeof(id),
519+
&_info, sizeof(_info));
520+
if (!ret) {
521+
memcpy(info, &_info, sizeof(*info));
522+
info->sensor_id = le16_to_cpu(_info.sensor_id);
523+
}
524+
525+
return ret;
526+
}
527+
528+
int scpi_sensor_get_value(u16 sensor, u32 *val)
529+
{
530+
struct sensor_value buf;
531+
int ret;
532+
533+
ret = scpi_send_message(SCPI_CMD_SENSOR_VALUE, &sensor, sizeof(sensor),
534+
&buf, sizeof(buf));
535+
if (!ret)
536+
*val = le32_to_cpu(buf.val);
537+
538+
return ret;
539+
}
540+
484541
static struct scpi_ops scpi_ops = {
485542
.get_version = scpi_get_version,
486543
.clk_get_range = scpi_clk_get_range,
@@ -489,6 +546,9 @@ static struct scpi_ops scpi_ops = {
489546
.dvfs_get_idx = scpi_dvfs_get_idx,
490547
.dvfs_set_idx = scpi_dvfs_set_idx,
491548
.dvfs_get_info = scpi_dvfs_get_info,
549+
.sensor_get_capability = scpi_sensor_get_capability,
550+
.sensor_get_info = scpi_sensor_get_info,
551+
.sensor_get_value = scpi_sensor_get_value,
492552
};
493553

494554
struct scpi_ops *get_scpi_ops(void)

include/linux/scpi_protocol.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ struct scpi_dvfs_info {
2828
struct scpi_opp *opps;
2929
};
3030

31+
enum scpi_sensor_class {
32+
TEMPERATURE,
33+
VOLTAGE,
34+
CURRENT,
35+
POWER,
36+
};
37+
38+
struct scpi_sensor_info {
39+
u16 sensor_id;
40+
u8 class;
41+
u8 trigger_type;
42+
char name[20];
43+
} __packed;
44+
3145
/**
3246
* struct scpi_ops - represents the various operations provided
3347
* by SCP through SCPI message protocol
@@ -52,6 +66,9 @@ struct scpi_ops {
5266
int (*dvfs_get_idx)(u8);
5367
int (*dvfs_set_idx)(u8, u8);
5468
struct scpi_dvfs_info *(*dvfs_get_info)(u8);
69+
int (*sensor_get_capability)(u16 *sensors);
70+
int (*sensor_get_info)(u16 sensor_id, struct scpi_sensor_info *);
71+
int (*sensor_get_value)(u16, u32 *);
5572
};
5673

5774
#if IS_ENABLED(CONFIG_ARM_SCPI_PROTOCOL)

0 commit comments

Comments
 (0)