meta-flutter updates
[AGL/meta-agl-devel.git] / meta-egvirt / recipes-kernel / linux / linux-yocto / scmi / 0006-firmware-arm_scmi-add-SCMIv3.0-Sensor-notifications.patch
1 From 53a49c0e12be913ecb81c55e6ee1f214704043cc Mon Sep 17 00:00:00 2001
2 From: Cristian Marussi <cristian.marussi@arm.com>
3 Date: Thu, 19 Nov 2020 17:49:06 +0000
4 Subject: [PATCH] firmware: arm_scmi: add SCMIv3.0 Sensor notifications
5
6 Add support for new SCMIv3.0 SENSOR_UPDATE notification.
7
8 Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
9 Signed-off-by: Vasyl Vavrychuk <vasyl.vavrychuk@opensynergy.com>
10 ---
11  drivers/firmware/arm_scmi/sensors.c | 124 +++++++++++++++++++++++-----
12  include/linux/scmi_protocol.h       |   9 ++
13  2 files changed, 114 insertions(+), 19 deletions(-)
14
15 diff --git a/drivers/firmware/arm_scmi/sensors.c b/drivers/firmware/arm_scmi/sensors.c
16 index 10c271d430e7..b3d7c08c09a0 100644
17 --- a/drivers/firmware/arm_scmi/sensors.c
18 +++ b/drivers/firmware/arm_scmi/sensors.c
19 @@ -25,6 +25,7 @@ enum scmi_sensor_protocol_cmd {
20         SENSOR_LIST_UPDATE_INTERVALS = 0x8,
21         SENSOR_CONFIG_GET = 0x9,
22         SENSOR_CONFIG_SET = 0xA,
23 +       SENSOR_CONTINUOUS_UPDATE_NOTIFY = 0xB,
24  };
25  
26  struct scmi_msg_resp_sensor_attributes {
27 @@ -132,10 +133,10 @@ struct scmi_msg_resp_sensor_list_update_intervals {
28         __le32 intervals[];
29  };
30  
31 -struct scmi_msg_sensor_trip_point_notify {
32 +struct scmi_msg_sensor_request_notify {
33         __le32 id;
34         __le32 event_control;
35 -#define SENSOR_TP_NOTIFY_ALL   BIT(0)
36 +#define SENSOR_NOTIFY_ALL      BIT(0)
37  };
38  
39  struct scmi_msg_set_sensor_trip_point {
40 @@ -185,6 +186,12 @@ struct scmi_sensor_trip_notify_payld {
41         __le32 trip_point_desc;
42  };
43  
44 +struct scmi_sensor_update_notify_payld {
45 +       __le32 agent_id;
46 +       __le32 sensor_id;
47 +       struct scmi_sensor_reading_le readings[];
48 +};
49 +
50  struct sensors_info {
51         u32 version;
52         int num_sensors;
53 @@ -550,15 +557,16 @@ static int scmi_sensor_description_get(const struct scmi_handle *handle,
54         return ret;
55  }
56  
57 -static int scmi_sensor_trip_point_notify(const struct scmi_handle *handle,
58 -                                        u32 sensor_id, bool enable)
59 +static inline int
60 +scmi_sensor_request_notify(const struct scmi_handle *handle, u32 sensor_id,
61 +                          u8 message_id, bool enable)
62  {
63         int ret;
64 -       u32 evt_cntl = enable ? SENSOR_TP_NOTIFY_ALL : 0;
65 +       u32 evt_cntl = enable ? SENSOR_NOTIFY_ALL : 0;
66         struct scmi_xfer *t;
67 -       struct scmi_msg_sensor_trip_point_notify *cfg;
68 +       struct scmi_msg_sensor_request_notify *cfg;
69  
70 -       ret = scmi_xfer_get_init(handle, SENSOR_TRIP_POINT_NOTIFY,
71 +       ret = scmi_xfer_get_init(handle, message_id,
72                                  SCMI_PROTOCOL_SENSOR, sizeof(*cfg), 0, &t);
73         if (ret)
74                 return ret;
75 @@ -573,6 +581,23 @@ static int scmi_sensor_trip_point_notify(const struct scmi_handle *handle,
76         return ret;
77  }
78  
79 +static int scmi_sensor_trip_point_notify(const struct scmi_handle *handle,
80 +                                        u32 sensor_id, bool enable)
81 +{
82 +       return scmi_sensor_request_notify(handle, sensor_id,
83 +                                         SENSOR_TRIP_POINT_NOTIFY,
84 +                                         enable);
85 +}
86 +
87 +static int
88 +scmi_sensor_continuous_update_notify(const struct scmi_handle *handle,
89 +                                    u32 sensor_id, bool enable)
90 +{
91 +       return scmi_sensor_request_notify(handle, sensor_id,
92 +                                         SENSOR_CONTINUOUS_UPDATE_NOTIFY,
93 +                                         enable);
94 +}
95 +
96  static int
97  scmi_sensor_trip_point_config(const struct scmi_handle *handle, u32 sensor_id,
98                               u8 trip_id, u64 trip_value)
99 @@ -815,7 +840,19 @@ static int scmi_sensor_set_notify_enabled(const struct scmi_handle *handle,
100  {
101         int ret;
102  
103 -       ret = scmi_sensor_trip_point_notify(handle, src_id, enable);
104 +       switch (evt_id) {
105 +       case SCMI_EVENT_SENSOR_TRIP_POINT_EVENT:
106 +               ret = scmi_sensor_trip_point_notify(handle, src_id, enable);
107 +               break;
108 +       case SCMI_EVENT_SENSOR_UPDATE:
109 +               ret = scmi_sensor_continuous_update_notify(handle, src_id,
110 +                                                          enable);
111 +               break;
112 +       default:
113 +               ret = -EINVAL;
114 +               break;
115 +       }
116 +
117         if (ret)
118                 pr_debug("FAIL_ENABLED - evt[%X] dom[%d] - ret:%d\n",
119                          evt_id, src_id, ret);
120 @@ -828,20 +865,59 @@ static void *scmi_sensor_fill_custom_report(const struct scmi_handle *handle,
121                                             const void *payld, size_t payld_sz,
122                                             void *report, u32 *src_id)
123  {
124 -       const struct scmi_sensor_trip_notify_payld *p = payld;
125 -       struct scmi_sensor_trip_point_report *r = report;
126 +       void *rep = NULL;
127  
128 -       if (evt_id != SCMI_EVENT_SENSOR_TRIP_POINT_EVENT ||
129 -           sizeof(*p) != payld_sz)
130 -               return NULL;
131 +       switch (evt_id) {
132 +       case SCMI_EVENT_SENSOR_TRIP_POINT_EVENT:
133 +       {
134 +               const struct scmi_sensor_trip_notify_payld *p = payld;
135 +               struct scmi_sensor_trip_point_report *r = report;
136  
137 -       r->timestamp = timestamp;
138 -       r->agent_id = le32_to_cpu(p->agent_id);
139 -       r->sensor_id = le32_to_cpu(p->sensor_id);
140 -       r->trip_point_desc = le32_to_cpu(p->trip_point_desc);
141 -       *src_id = r->sensor_id;
142 +               if (sizeof(*p) != payld_sz)
143 +                       break;
144  
145 -       return r;
146 +               r->timestamp = timestamp;
147 +               r->agent_id = le32_to_cpu(p->agent_id);
148 +               r->sensor_id = le32_to_cpu(p->sensor_id);
149 +               r->trip_point_desc = le32_to_cpu(p->trip_point_desc);
150 +               *src_id = r->sensor_id;
151 +               rep = r;
152 +               break;
153 +       }
154 +       case SCMI_EVENT_SENSOR_UPDATE:
155 +       {
156 +               int i;
157 +               struct scmi_sensor_info *s;
158 +               const struct scmi_sensor_update_notify_payld *p = payld;
159 +               struct scmi_sensor_update_report *r = report;
160 +               struct sensors_info *sinfo = handle->sensor_priv;
161 +
162 +               /* payld_sz is variable for this event */
163 +               r->sensor_id = le32_to_cpu(p->sensor_id);
164 +               if (r->sensor_id >= sinfo->num_sensors)
165 +                       break;
166 +               r->timestamp = timestamp;
167 +               r->agent_id = le32_to_cpu(p->agent_id);
168 +               s = &sinfo->sensors[r->sensor_id];
169 +               /*
170 +                * The generated report r (@struct scmi_sensor_update_report)
171 +                * was pre-allocated to contain up to SCMI_MAX_NUM_SENSOR_AXIS
172 +                * readings: here it is filled with the effective @num_axis
173 +                * readings defined for this sensor or 1 for scalar sensors.
174 +                */
175 +               r->readings_count = s->num_axis ?: 1;
176 +               for (i = 0; i < r->readings_count; i++)
177 +                       scmi_parse_sensor_readings(&r->readings[i],
178 +                                                  &p->readings[i]);
179 +               *src_id = r->sensor_id;
180 +               rep = r;
181 +               break;
182 +       }
183 +       default:
184 +               break;
185 +       }
186 +
187 +       return rep;
188  }
189  
190  static const struct scmi_event sensor_events[] = {
191 @@ -850,6 +926,16 @@ static const struct scmi_event sensor_events[] = {
192                 .max_payld_sz = sizeof(struct scmi_sensor_trip_notify_payld),
193                 .max_report_sz = sizeof(struct scmi_sensor_trip_point_report),
194         },
195 +       {
196 +               .id = SCMI_EVENT_SENSOR_UPDATE,
197 +               .max_payld_sz =
198 +                       sizeof(struct scmi_sensor_update_notify_payld) +
199 +                        SCMI_MAX_NUM_SENSOR_AXIS *
200 +                        sizeof(struct scmi_sensor_reading_le),
201 +               .max_report_sz = sizeof(struct scmi_sensor_update_report) +
202 +                                 SCMI_MAX_NUM_SENSOR_AXIS *
203 +                                 sizeof(struct scmi_sensor_reading),
204 +       },
205  };
206  
207  static const struct scmi_event_ops sensor_event_ops = {
208 diff --git a/include/linux/scmi_protocol.h b/include/linux/scmi_protocol.h
209 index 7e9e2cd3d46b..be0be5ff7514 100644
210 --- a/include/linux/scmi_protocol.h
211 +++ b/include/linux/scmi_protocol.h
212 @@ -657,6 +657,7 @@ enum scmi_notification_events {
213         SCMI_EVENT_PERFORMANCE_LIMITS_CHANGED = 0x0,
214         SCMI_EVENT_PERFORMANCE_LEVEL_CHANGED = 0x1,
215         SCMI_EVENT_SENSOR_TRIP_POINT_EVENT = 0x0,
216 +       SCMI_EVENT_SENSOR_UPDATE = 0x1,
217         SCMI_EVENT_RESET_ISSUED = 0x0,
218         SCMI_EVENT_BASE_ERROR_EVENT = 0x0,
219         SCMI_EVENT_SYSTEM_POWER_STATE_NOTIFIER = 0x0,
220 @@ -698,6 +699,14 @@ struct scmi_sensor_trip_point_report {
221         unsigned int    trip_point_desc;
222  };
223  
224 +struct scmi_sensor_update_report {
225 +       ktime_t                         timestamp;
226 +       unsigned int                    agent_id;
227 +       unsigned int                    sensor_id;
228 +       unsigned int                    readings_count;
229 +       struct scmi_sensor_reading      readings[];
230 +};
231 +
232  struct scmi_reset_issued_report {
233         ktime_t         timestamp;
234         unsigned int    agent_id;