1 // SPDX-License-Identifier: GPL-2.0
3 * System Control and Management Interface (SCMI) System Power Protocol
5 * Copyright (C) 2020-2021 ARM Ltd.
8 #define pr_fmt(fmt) "SCMI Notifications SYSTEM - " fmt
10 #include <linux/module.h>
11 #include <linux/scmi_protocol.h>
16 #define SCMI_SYSTEM_NUM_SOURCES 1
18 enum scmi_system_protocol_cmd {
19 SYSTEM_POWER_STATE_NOTIFY = 0x5,
22 struct scmi_system_power_state_notify {
26 struct scmi_system_power_state_notifier_payld {
32 struct scmi_system_info {
36 static int scmi_system_request_notify(const struct scmi_protocol_handle *ph,
41 struct scmi_system_power_state_notify *notify;
43 ret = ph->xops->xfer_get_init(ph, SYSTEM_POWER_STATE_NOTIFY,
44 sizeof(*notify), 0, &t);
49 notify->notify_enable = enable ? cpu_to_le32(BIT(0)) : 0;
51 ret = ph->xops->do_xfer(ph, t);
53 ph->xops->xfer_put(ph, t);
57 static int scmi_system_set_notify_enabled(const struct scmi_protocol_handle *ph,
58 u8 evt_id, u32 src_id, bool enable)
62 ret = scmi_system_request_notify(ph, enable);
64 pr_debug("FAIL_ENABLE - evt[%X] - ret:%d\n", evt_id, ret);
70 scmi_system_fill_custom_report(const struct scmi_protocol_handle *ph,
71 u8 evt_id, ktime_t timestamp,
72 const void *payld, size_t payld_sz,
73 void *report, u32 *src_id)
75 const struct scmi_system_power_state_notifier_payld *p = payld;
76 struct scmi_system_power_state_notifier_report *r = report;
78 if (evt_id != SCMI_EVENT_SYSTEM_POWER_STATE_NOTIFIER ||
79 sizeof(*p) != payld_sz)
82 r->timestamp = timestamp;
83 r->agent_id = le32_to_cpu(p->agent_id);
84 r->flags = le32_to_cpu(p->flags);
85 r->system_state = le32_to_cpu(p->system_state);
91 static const struct scmi_event system_events[] = {
93 .id = SCMI_EVENT_SYSTEM_POWER_STATE_NOTIFIER,
95 sizeof(struct scmi_system_power_state_notifier_payld),
97 sizeof(struct scmi_system_power_state_notifier_report),
101 static const struct scmi_event_ops system_event_ops = {
102 .set_notify_enabled = scmi_system_set_notify_enabled,
103 .fill_custom_report = scmi_system_fill_custom_report,
106 static const struct scmi_protocol_events system_protocol_events = {
107 .queue_sz = SCMI_PROTO_QUEUE_SZ,
108 .ops = &system_event_ops,
109 .evts = system_events,
110 .num_events = ARRAY_SIZE(system_events),
111 .num_sources = SCMI_SYSTEM_NUM_SOURCES,
114 static int scmi_system_protocol_init(const struct scmi_protocol_handle *ph)
118 struct scmi_system_info *pinfo;
120 ret = ph->xops->version_get(ph, &version);
124 dev_dbg(ph->dev, "System Power Version %d.%d\n",
125 PROTOCOL_REV_MAJOR(version), PROTOCOL_REV_MINOR(version));
127 pinfo = devm_kzalloc(ph->dev, sizeof(*pinfo), GFP_KERNEL);
131 pinfo->version = version;
132 return ph->set_priv(ph, pinfo);
135 static const struct scmi_protocol scmi_system = {
136 .id = SCMI_PROTOCOL_SYSTEM,
137 .owner = THIS_MODULE,
138 .instance_init = &scmi_system_protocol_init,
140 .events = &system_protocol_events,
143 DEFINE_SCMI_PROTOCOL_REGISTER_UNREGISTER(system, scmi_system)