meta-flutter updates
[AGL/meta-agl-devel.git] / meta-egvirt / recipes-kernel / linux / linux-yocto / scmi / 0002-firmware-arm_scmi-add-SCMIv3.0-Sensors-descriptors-e.patch
1 From 994102ee967232e7565887d2a5fb83384b550bd8 Mon Sep 17 00:00:00 2001
2 From: Cristian Marussi <cristian.marussi@arm.com>
3 Date: Thu, 19 Nov 2020 17:49:02 +0000
4 Subject: [PATCH] firmware: arm_scmi: add SCMIv3.0 Sensors descriptors
5  extensions
6
7 Add support for new SCMIv3.0 Sensors extensions related to new sensors'
8 features, like multiple axis and update intervals, while keeping
9 compatibility with SCMIv2.0 features.
10 While at that, refactor and simplify all the internal helpers macros and
11 move struct scmi_sensor_info to use only non-fixed-size typing.
12
13 Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
14 Signed-off-by: Vasyl Vavrychuk <vasyl.vavrychuk@opensynergy.com>
15 ---
16  drivers/firmware/arm_scmi/sensors.c | 390 ++++++++++++++++++++++++++--
17  include/linux/scmi_protocol.h       | 220 +++++++++++++++-
18  2 files changed, 585 insertions(+), 25 deletions(-)
19
20 diff --git a/drivers/firmware/arm_scmi/sensors.c b/drivers/firmware/arm_scmi/sensors.c
21 index 6aaff478d032..a85827f60a02 100644
22 --- a/drivers/firmware/arm_scmi/sensors.c
23 +++ b/drivers/firmware/arm_scmi/sensors.c
24 @@ -7,16 +7,22 @@
25  
26  #define pr_fmt(fmt) "SCMI Notifications SENSOR - " fmt
27  
28 +#include <linux/bitfield.h>
29  #include <linux/scmi_protocol.h>
30  
31  #include "common.h"
32  #include "notify.h"
33  
34 +#define SCMI_MAX_NUM_SENSOR_AXIS       63
35 +#define        SCMIv2_SENSOR_PROTOCOL          0x10000
36 +
37  enum scmi_sensor_protocol_cmd {
38         SENSOR_DESCRIPTION_GET = 0x3,
39         SENSOR_TRIP_POINT_NOTIFY = 0x4,
40         SENSOR_TRIP_POINT_CONFIG = 0x5,
41         SENSOR_READING_GET = 0x6,
42 +       SENSOR_AXIS_DESCRIPTION_GET = 0x7,
43 +       SENSOR_LIST_UPDATE_INTERVALS = 0x8,
44  };
45  
46  struct scmi_msg_resp_sensor_attributes {
47 @@ -28,23 +34,100 @@ struct scmi_msg_resp_sensor_attributes {
48         __le32 reg_size;
49  };
50  
51 +/* v3 attributes_low macros */
52 +#define SUPPORTS_UPDATE_NOTIFY(x)      FIELD_GET(BIT(30), (x))
53 +#define SENSOR_TSTAMP_EXP(x)           FIELD_GET(GENMASK(14, 10), (x))
54 +#define SUPPORTS_TIMESTAMP(x)          FIELD_GET(BIT(9), (x))
55 +#define SUPPORTS_EXTEND_ATTRS(x)       FIELD_GET(BIT(8), (x))
56 +
57 +/* v2 attributes_high macros */
58 +#define SENSOR_UPDATE_BASE(x)          FIELD_GET(GENMASK(31, 27), (x))
59 +#define SENSOR_UPDATE_SCALE(x)         FIELD_GET(GENMASK(26, 22), (x))
60 +
61 +/* v3 attributes_high macros */
62 +#define SENSOR_AXIS_NUMBER(x)          FIELD_GET(GENMASK(21, 16), (x))
63 +#define SUPPORTS_AXIS(x)               FIELD_GET(BIT(8), (x))
64 +
65 +/* v3 resolution macros */
66 +#define SENSOR_RES(x)                  FIELD_GET(GENMASK(26, 0), (x))
67 +#define SENSOR_RES_EXP(x)              FIELD_GET(GENMASK(31, 27), (x))
68 +
69 +struct scmi_msg_resp_attrs {
70 +       __le32 min_range_low;
71 +       __le32 min_range_high;
72 +       __le32 max_range_low;
73 +       __le32 max_range_high;
74 +};
75 +
76  struct scmi_msg_resp_sensor_description {
77         __le16 num_returned;
78         __le16 num_remaining;
79 -       struct {
80 +       struct scmi_sensor_descriptor {
81 +               __le32 id;
82 +               __le32 attributes_low;
83 +/* Common attributes_low macros */
84 +#define SUPPORTS_ASYNC_READ(x)         FIELD_GET(BIT(31), (x))
85 +#define NUM_TRIP_POINTS(x)             FIELD_GET(GENMASK(7, 0), (x))
86 +               __le32 attributes_high;
87 +/* Common attributes_high macros */
88 +#define SENSOR_SCALE(x)                        FIELD_GET(GENMASK(15, 11), (x))
89 +#define SENSOR_SCALE_SIGN              BIT(4)
90 +#define SENSOR_SCALE_EXTEND            GENMASK(31, 5)
91 +#define SENSOR_TYPE(x)                 FIELD_GET(GENMASK(7, 0), (x))
92 +               u8 name[SCMI_MAX_STR_SIZE];
93 +               /* only for version > 2.0 */
94 +               __le32 power;
95 +               __le32 resolution;
96 +               struct scmi_msg_resp_attrs scalar_attrs;
97 +       } desc[];
98 +};
99 +
100 +/* Base scmi_sensor_descriptor size excluding extended attrs after name */
101 +#define SCMI_MSG_RESP_SENS_DESCR_BASE_SZ       28
102 +
103 +/* Sign extend to a full s32 */
104 +#define        S32_EXT(v)                                                      \
105 +       ({                                                              \
106 +               int __v = (v);                                          \
107 +                                                                       \
108 +               if (__v & SENSOR_SCALE_SIGN)                            \
109 +                       __v |= SENSOR_SCALE_EXTEND;                     \
110 +               __v;                                                    \
111 +       })
112 +
113 +struct scmi_msg_sensor_axis_description_get {
114 +       __le32 id;
115 +       __le32 axis_desc_index;
116 +};
117 +
118 +struct scmi_msg_resp_sensor_axis_description {
119 +       __le32 num_axis_flags;
120 +#define NUM_AXIS_RETURNED(x)           FIELD_GET(GENMASK(5, 0), (x))
121 +#define NUM_AXIS_REMAINING(x)          FIELD_GET(GENMASK(31, 26), (x))
122 +       struct scmi_axis_descriptor {
123                 __le32 id;
124                 __le32 attributes_low;
125 -#define SUPPORTS_ASYNC_READ(x) ((x) & BIT(31))
126 -#define NUM_TRIP_POINTS(x)     ((x) & 0xff)
127                 __le32 attributes_high;
128 -#define SENSOR_TYPE(x)         ((x) & 0xff)
129 -#define SENSOR_SCALE(x)                (((x) >> 11) & 0x1f)
130 -#define SENSOR_SCALE_SIGN      BIT(4)
131 -#define SENSOR_SCALE_EXTEND    GENMASK(7, 5)
132 -#define SENSOR_UPDATE_SCALE(x) (((x) >> 22) & 0x1f)
133 -#define SENSOR_UPDATE_BASE(x)  (((x) >> 27) & 0x1f)
134 -                   u8 name[SCMI_MAX_STR_SIZE];
135 -       } desc[0];
136 +               u8 name[SCMI_MAX_STR_SIZE];
137 +               __le32 resolution;
138 +               struct scmi_msg_resp_attrs attrs;
139 +       } desc[];
140 +};
141 +
142 +/* Base scmi_axis_descriptor size excluding extended attrs after name */
143 +#define SCMI_MSG_RESP_AXIS_DESCR_BASE_SZ       28
144 +
145 +struct scmi_msg_sensor_list_update_intervals {
146 +       __le32 id;
147 +       __le32 index;
148 +};
149 +
150 +struct scmi_msg_resp_sensor_list_update_intervals {
151 +       __le32 num_intervals_flags;
152 +#define NUM_INTERVALS_RETURNED(x)      FIELD_GET(GENMASK(11, 0), (x))
153 +#define SEGMENTED_INTVL_FORMAT(x)      FIELD_GET(BIT(12), (x))
154 +#define NUM_INTERVALS_REMAINING(x)     FIELD_GET(GENMASK(31, 16), (x))
155 +       __le32 intervals[];
156  };
157  
158  struct scmi_msg_sensor_trip_point_notify {
159 @@ -114,6 +197,194 @@ static int scmi_sensor_attributes_get(const struct scmi_handle *handle,
160         return ret;
161  }
162  
163 +static inline void scmi_parse_range_attrs(struct scmi_range_attrs *out,
164 +                                         struct scmi_msg_resp_attrs *in)
165 +{
166 +       out->min_range = get_unaligned_le64((void *)&in->min_range_low);
167 +       out->max_range = get_unaligned_le64((void *)&in->max_range_low);
168 +}
169 +
170 +static int scmi_sensor_update_intervals(const struct scmi_handle *handle,
171 +                                       struct scmi_sensor_info *s)
172 +{
173 +       int ret, cnt;
174 +       u32 desc_index = 0;
175 +       u16 num_returned, num_remaining;
176 +       struct scmi_xfer *ti;
177 +       struct scmi_msg_resp_sensor_list_update_intervals *buf;
178 +       struct scmi_msg_sensor_list_update_intervals *msg;
179 +
180 +       ret = scmi_xfer_get_init(handle, SENSOR_LIST_UPDATE_INTERVALS,
181 +                                SCMI_PROTOCOL_SENSOR, sizeof(*msg), 0, &ti);
182 +       if (ret)
183 +               return ret;
184 +
185 +       buf = ti->rx.buf;
186 +       do {
187 +               u32 flags;
188 +
189 +               msg = ti->tx.buf;
190 +               /* Set the number of sensors to be skipped/already read */
191 +               msg->id = cpu_to_le32(s->id);
192 +               msg->index = cpu_to_le32(desc_index);
193 +
194 +               ret = scmi_do_xfer(handle, ti);
195 +               if (ret)
196 +                       break;
197 +
198 +               flags = le32_to_cpu(buf->num_intervals_flags);
199 +               num_returned = NUM_INTERVALS_RETURNED(flags);
200 +               num_remaining = NUM_INTERVALS_REMAINING(flags);
201 +
202 +               /*
203 +                * Max intervals is not declared previously anywhere so we
204 +                * assume it's returned+remaining.
205 +                */
206 +               if (!s->intervals.count) {
207 +                       s->intervals.segmented = SEGMENTED_INTVL_FORMAT(flags);
208 +                       s->intervals.count = num_returned + num_remaining;
209 +                       /* segmented intervals are reported in one triplet */
210 +                       if (s->intervals.segmented &&
211 +                           (num_remaining || num_returned != 3)) {
212 +                               dev_err(handle->dev,
213 +                                       "Sensor ID:%d advertises an invalid segmented interval (%d)\n",
214 +                                       s->id, s->intervals.count);
215 +                               s->intervals.segmented = false;
216 +                               s->intervals.count = 0;
217 +                               ret = -EINVAL;
218 +                               break;
219 +                       }
220 +                       /* Direct allocation when exceeding pre-allocated */
221 +                       if (s->intervals.count >= SCMI_MAX_PREALLOC_POOL) {
222 +                               s->intervals.desc =
223 +                                       devm_kcalloc(handle->dev,
224 +                                                    s->intervals.count,
225 +                                                    sizeof(*s->intervals.desc),
226 +                                                    GFP_KERNEL);
227 +                               if (!s->intervals.desc) {
228 +                                       s->intervals.segmented = false;
229 +                                       s->intervals.count = 0;
230 +                                       ret = -ENOMEM;
231 +                                       break;
232 +                               }
233 +                       }
234 +               } else if (desc_index + num_returned > s->intervals.count) {
235 +                       dev_err(handle->dev,
236 +                               "No. of update intervals can't exceed %d\n",
237 +                               s->intervals.count);
238 +                       ret = -EINVAL;
239 +                       break;
240 +               }
241 +
242 +               for (cnt = 0; cnt < num_returned; cnt++)
243 +                       s->intervals.desc[desc_index + cnt] =
244 +                                       le32_to_cpu(buf->intervals[cnt]);
245 +
246 +               desc_index += num_returned;
247 +
248 +               scmi_reset_rx_to_maxsz(handle, ti);
249 +               /*
250 +                * check for both returned and remaining to avoid infinite
251 +                * loop due to buggy firmware
252 +                */
253 +       } while (num_returned && num_remaining);
254 +
255 +       scmi_xfer_put(handle, ti);
256 +       return ret;
257 +}
258 +
259 +static int scmi_sensor_axis_description(const struct scmi_handle *handle,
260 +                                       struct scmi_sensor_info *s)
261 +{
262 +       int ret, cnt;
263 +       u32 desc_index = 0;
264 +       u16 num_returned, num_remaining;
265 +       struct scmi_xfer *te;
266 +       struct scmi_msg_resp_sensor_axis_description *buf;
267 +       struct scmi_msg_sensor_axis_description_get *msg;
268 +
269 +       s->axis = devm_kcalloc(handle->dev, s->num_axis,
270 +                              sizeof(*s->axis), GFP_KERNEL);
271 +       if (!s->axis)
272 +               return -ENOMEM;
273 +
274 +       ret = scmi_xfer_get_init(handle, SENSOR_AXIS_DESCRIPTION_GET,
275 +                                SCMI_PROTOCOL_SENSOR, sizeof(*msg), 0, &te);
276 +       if (ret)
277 +               return ret;
278 +
279 +       buf = te->rx.buf;
280 +       do {
281 +               u32 flags;
282 +               struct scmi_axis_descriptor *adesc;
283 +
284 +               msg = te->tx.buf;
285 +               /* Set the number of sensors to be skipped/already read */
286 +               msg->id = cpu_to_le32(s->id);
287 +               msg->axis_desc_index = cpu_to_le32(desc_index);
288 +
289 +               ret = scmi_do_xfer(handle, te);
290 +               if (ret)
291 +                       break;
292 +
293 +               flags = le32_to_cpu(buf->num_axis_flags);
294 +               num_returned = NUM_AXIS_RETURNED(flags);
295 +               num_remaining = NUM_AXIS_REMAINING(flags);
296 +
297 +               if (desc_index + num_returned > s->num_axis) {
298 +                       dev_err(handle->dev, "No. of axis can't exceed %d\n",
299 +                               s->num_axis);
300 +                       break;
301 +               }
302 +
303 +               adesc = &buf->desc[0];
304 +               for (cnt = 0; cnt < num_returned; cnt++) {
305 +                       u32 attrh, attrl;
306 +                       struct scmi_sensor_axis_info *a;
307 +                       size_t dsize = SCMI_MSG_RESP_AXIS_DESCR_BASE_SZ;
308 +
309 +                       attrl = le32_to_cpu(adesc->attributes_low);
310 +
311 +                       a = &s->axis[desc_index + cnt];
312 +
313 +                       a->id = le32_to_cpu(adesc->id);
314 +                       a->extended_attrs = SUPPORTS_EXTEND_ATTRS(attrl);
315 +
316 +                       attrh = le32_to_cpu(adesc->attributes_high);
317 +                       a->scale = S32_EXT(SENSOR_SCALE(attrh));
318 +                       a->type = SENSOR_TYPE(attrh);
319 +                       strlcpy(a->name, adesc->name, SCMI_MAX_STR_SIZE);
320 +
321 +                       if (a->extended_attrs) {
322 +                               unsigned int ares =
323 +                                       le32_to_cpu(adesc->resolution);
324 +
325 +                               a->resolution = SENSOR_RES(ares);
326 +                               a->exponent =
327 +                                       S32_EXT(SENSOR_RES_EXP(ares));
328 +                               dsize += sizeof(adesc->resolution);
329 +
330 +                               scmi_parse_range_attrs(&a->attrs,
331 +                                                      &adesc->attrs);
332 +                               dsize += sizeof(adesc->attrs);
333 +                       }
334 +
335 +                       adesc = (typeof(adesc))((u8 *)adesc + dsize);
336 +               }
337 +
338 +               desc_index += num_returned;
339 +
340 +               scmi_reset_rx_to_maxsz(handle, te);
341 +               /*
342 +                * check for both returned and remaining to avoid infinite
343 +                * loop due to buggy firmware
344 +                */
345 +       } while (num_returned && num_remaining);
346 +
347 +       scmi_xfer_put(handle, te);
348 +       return ret;
349 +}
350 +
351  static int scmi_sensor_description_get(const struct scmi_handle *handle,
352                                        struct sensors_info *si)
353  {
354 @@ -131,9 +402,10 @@ static int scmi_sensor_description_get(const struct scmi_handle *handle,
355         buf = t->rx.buf;
356  
357         do {
358 +               struct scmi_sensor_descriptor *sdesc;
359 +
360                 /* Set the number of sensors to be skipped/already read */
361                 put_unaligned_le32(desc_index, t->tx.buf);
362 -
363                 ret = scmi_do_xfer(handle, t);
364                 if (ret)
365                         break;
366 @@ -147,22 +419,97 @@ static int scmi_sensor_description_get(const struct scmi_handle *handle,
367                         break;
368                 }
369  
370 +               sdesc = &buf->desc[0];
371                 for (cnt = 0; cnt < num_returned; cnt++) {
372                         u32 attrh, attrl;
373                         struct scmi_sensor_info *s;
374 +                       size_t dsize = SCMI_MSG_RESP_SENS_DESCR_BASE_SZ;
375  
376 -                       attrl = le32_to_cpu(buf->desc[cnt].attributes_low);
377 -                       attrh = le32_to_cpu(buf->desc[cnt].attributes_high);
378                         s = &si->sensors[desc_index + cnt];
379 -                       s->id = le32_to_cpu(buf->desc[cnt].id);
380 -                       s->type = SENSOR_TYPE(attrh);
381 -                       s->scale = SENSOR_SCALE(attrh);
382 -                       /* Sign extend to a full s8 */
383 -                       if (s->scale & SENSOR_SCALE_SIGN)
384 -                               s->scale |= SENSOR_SCALE_EXTEND;
385 +                       s->id = le32_to_cpu(sdesc->id);
386 +
387 +                       attrl = le32_to_cpu(sdesc->attributes_low);
388 +                       /* common bitfields parsing */
389                         s->async = SUPPORTS_ASYNC_READ(attrl);
390                         s->num_trip_points = NUM_TRIP_POINTS(attrl);
391 -                       strlcpy(s->name, buf->desc[cnt].name, SCMI_MAX_STR_SIZE);
392 +                       /**
393 +                        * only SCMIv3.0 specific bitfield below.
394 +                        * Such bitfields are assumed to be zeroed on non
395 +                        * relevant fw versions...assuming fw not buggy !
396 +                        */
397 +                       s->update = SUPPORTS_UPDATE_NOTIFY(attrl);
398 +                       s->timestamped = SUPPORTS_TIMESTAMP(attrl);
399 +                       if (s->timestamped)
400 +                               s->tstamp_scale =
401 +                                       S32_EXT(SENSOR_TSTAMP_EXP(attrl));
402 +                       s->extended_scalar_attrs =
403 +                               SUPPORTS_EXTEND_ATTRS(attrl);
404 +
405 +                       attrh = le32_to_cpu(sdesc->attributes_high);
406 +                       /* common bitfields parsing */
407 +                       s->scale = S32_EXT(SENSOR_SCALE(attrh));
408 +                       s->type = SENSOR_TYPE(attrh);
409 +                       /* Use pre-allocated pool wherever possible */
410 +                       s->intervals.desc = s->intervals.prealloc_pool;
411 +                       if (si->version == SCMIv2_SENSOR_PROTOCOL) {
412 +                               s->intervals.segmented = false;
413 +                               s->intervals.count = 1;
414 +                               /*
415 +                                * Convert SCMIv2.0 update interval format to
416 +                                * SCMIv3.0 to be used as the common exposed
417 +                                * descriptor, accessible via common macros.
418 +                                */
419 +                               s->intervals.desc[0] =
420 +                                       (SENSOR_UPDATE_BASE(attrh) << 5) |
421 +                                        SENSOR_UPDATE_SCALE(attrh);
422 +                       } else {
423 +                               /*
424 +                                * From SCMIv3.0 update intervals are retrieved
425 +                                * via a dedicated (optional) command.
426 +                                * Since the command is optional, on error carry
427 +                                * on without any update interval.
428 +                                */
429 +                               if (scmi_sensor_update_intervals(handle, s))
430 +                                       dev_dbg(handle->dev,
431 +                                               "Update Intervals not available for sensor ID:%d\n",
432 +                                               s->id);
433 +                       }
434 +                       /**
435 +                        * only > SCMIv2.0 specific bitfield below.
436 +                        * Such bitfields are assumed to be zeroed on non
437 +                        * relevant fw versions...assuming fw not buggy !
438 +                        */
439 +                       s->num_axis = min_t(unsigned int,
440 +                                           SUPPORTS_AXIS(attrh) ?
441 +                                           SENSOR_AXIS_NUMBER(attrh) : 0,
442 +                                           SCMI_MAX_NUM_SENSOR_AXIS);
443 +                       strlcpy(s->name, sdesc->name, SCMI_MAX_STR_SIZE);
444 +
445 +                       if (s->extended_scalar_attrs) {
446 +                               s->sensor_power = le32_to_cpu(sdesc->power);
447 +                               dsize += sizeof(sdesc->power);
448 +                               /* Only for sensors reporting scalar values */
449 +                               if (s->num_axis == 0) {
450 +                                       unsigned int sres =
451 +                                               le32_to_cpu(sdesc->resolution);
452 +
453 +                                       s->resolution = SENSOR_RES(sres);
454 +                                       s->exponent =
455 +                                               S32_EXT(SENSOR_RES_EXP(sres));
456 +                                       dsize += sizeof(sdesc->resolution);
457 +
458 +                                       scmi_parse_range_attrs(&s->scalar_attrs,
459 +                                                              &sdesc->scalar_attrs);
460 +                                       dsize += sizeof(sdesc->scalar_attrs);
461 +                               }
462 +                       }
463 +                       if (s->num_axis > 0) {
464 +                               ret = scmi_sensor_axis_description(handle, s);
465 +                               if (ret)
466 +                                       goto out;
467 +                       }
468 +
469 +                       sdesc = (typeof(sdesc))((u8 *)sdesc + dsize);
470                 }
471  
472                 desc_index += num_returned;
473 @@ -174,6 +521,7 @@ static int scmi_sensor_description_get(const struct scmi_handle *handle,
474                  */
475         } while (num_returned && num_remaining);
476  
477 +out:
478         scmi_xfer_put(handle, t);
479         return ret;
480  }
481 diff --git a/include/linux/scmi_protocol.h b/include/linux/scmi_protocol.h
482 index 9cd312a1ff92..0792b0be25a3 100644
483 --- a/include/linux/scmi_protocol.h
484 +++ b/include/linux/scmi_protocol.h
485 @@ -8,6 +8,7 @@
486  #ifndef _LINUX_SCMI_PROTOCOL_H
487  #define _LINUX_SCMI_PROTOCOL_H
488  
489 +#include <linux/bitfield.h>
490  #include <linux/device.h>
491  #include <linux/notifier.h>
492  #include <linux/types.h>
493 @@ -148,13 +149,135 @@ struct scmi_power_ops {
494                          u32 *state);
495  };
496  
497 +/**
498 + * scmi_range_attrs  - specifies a sensor or axis values' range
499 + * @min_range: The minimum value which can be represented by the sensor/axis.
500 + * @max_range: The maximum value which can be represented by the sensor/axis.
501 + */
502 +struct scmi_range_attrs {
503 +       long long min_range;
504 +       long long max_range;
505 +};
506 +
507 +/**
508 + * scmi_sensor_axis_info  - describes one sensor axes
509 + * @id: The axes ID.
510 + * @type: Axes type. Chosen amongst one of @enum scmi_sensor_class.
511 + * @scale: Power-of-10 multiplier applied to the axis unit.
512 + * @name: NULL-terminated string representing axes name as advertised by
513 + *       SCMI platform.
514 + * @extended_attrs: Flag to indicate the presence of additional extended
515 + *                 attributes for this axes.
516 + * @resolution: Extended attribute representing the resolution of the axes.
517 + *             Set to 0 if not reported by this axes.
518 + * @exponent: Extended attribute representing the power-of-10 multiplier that
519 + *           is applied to the resolution field. Set to 0 if not reported by
520 + *           this axes.
521 + * @attrs: Extended attributes representing minimum and maximum values
522 + *        measurable by this axes. Set to 0 if not reported by this sensor.
523 + */
524 +struct scmi_sensor_axis_info {
525 +       unsigned int id;
526 +       unsigned int type;
527 +       int scale;
528 +       char name[SCMI_MAX_STR_SIZE];
529 +       bool extended_attrs;
530 +       unsigned int resolution;
531 +       int exponent;
532 +       struct scmi_range_attrs attrs;
533 +};
534 +
535 +/**
536 + * scmi_sensor_intervals_info  - describes number and type of available update
537 + * intervals
538 + * @segmented: Flag for segmented intervals' representation. When True there
539 + *            will be exactly 3 intervals in @desc, with each entry
540 + *            representing a member of a segment in this order:
541 + *            {lowest update interval, highest update interval, step size}
542 + * @count: Number of intervals described in @desc.
543 + * @desc: Array of @count interval descriptor bitmask represented as detailed in
544 + *       the SCMI specification: it can be accessed using the accompanying
545 + *       macros.
546 + * @prealloc_pool: A minimal preallocated pool of desc entries used to avoid
547 + *                lesser-than-64-bytes dynamic allocation for small @count
548 + *                values.
549 + */
550 +struct scmi_sensor_intervals_info {
551 +       bool segmented;
552 +       unsigned int count;
553 +#define SCMI_SENS_INTVL_SEGMENT_LOW    0
554 +#define SCMI_SENS_INTVL_SEGMENT_HIGH   1
555 +#define SCMI_SENS_INTVL_SEGMENT_STEP   2
556 +       unsigned int *desc;
557 +#define SCMI_SENS_INTVL_GET_SECS(x)            FIELD_GET(GENMASK(20, 5), (x))
558 +#define SCMI_SENS_INTVL_GET_EXP(x)                                     \
559 +       ({                                                              \
560 +               int __signed_exp = FIELD_GET(GENMASK(4, 0), (x));       \
561 +                                                                       \
562 +               if (__signed_exp & BIT(4))                              \
563 +                       __signed_exp |= GENMASK(31, 5);                 \
564 +               __signed_exp;                                           \
565 +       })
566 +#define SCMI_MAX_PREALLOC_POOL                 16
567 +       unsigned int prealloc_pool[SCMI_MAX_PREALLOC_POOL];
568 +};
569 +
570 +/**
571 + * struct scmi_sensor_info - represents information related to one of the
572 + * available sensors.
573 + * @id: Sensor ID.
574 + * @type: Sensor type. Chosen amongst one of @enum scmi_sensor_class.
575 + * @scale: Power-of-10 multiplier applied to the sensor unit.
576 + * @num_trip_points: Number of maximum configurable trip points.
577 + * @async: Flag for asynchronous read support.
578 + * @update: Flag for continuouos update notification support.
579 + * @timestamped: Flag for timestamped read support.
580 + * @tstamp_scale: Power-of-10 multiplier applied to the sensor timestamps to
581 + *               represent it in seconds.
582 + * @num_axis: Number of supported axis if any. Reported as 0 for scalar sensors.
583 + * @axis: Pointer to an array of @num_axis descriptors.
584 + * @intervals: Descriptor of available update intervals.
585 + * @sensor_config: A bitmask reporting the current sensor configuration as
586 + *                detailed in the SCMI specification: it can accessed and
587 + *                modified through the accompanying macros.
588 + * @name: NULL-terminated string representing sensor name as advertised by
589 + *       SCMI platform.
590 + * @extended_scalar_attrs: Flag to indicate the presence of additional extended
591 + *                        attributes for this sensor.
592 + * @sensor_power: Extended attribute representing the average power
593 + *               consumed by the sensor in microwatts (uW) when it is active.
594 + *               Reported here only for scalar sensors.
595 + *               Set to 0 if not reported by this sensor.
596 + * @resolution: Extended attribute representing the resolution of the sensor.
597 + *             Reported here only for scalar sensors.
598 + *             Set to 0 if not reported by this sensor.
599 + * @exponent: Extended attribute representing the power-of-10 multiplier that is
600 + *           applied to the resolution field.
601 + *           Reported here only for scalar sensors.
602 + *           Set to 0 if not reported by this sensor.
603 + * @scalar_attrs: Extended attributes representing minimum and maximum
604 + *               measurable values by this sensor.
605 + *               Reported here only for scalar sensors.
606 + *               Set to 0 if not reported by this sensor.
607 + */
608  struct scmi_sensor_info {
609 -       u32 id;
610 -       u8 type;
611 -       s8 scale;
612 -       u8 num_trip_points;
613 +       unsigned int id;
614 +       unsigned int type;
615 +       int scale;
616 +       unsigned int num_trip_points;
617         bool async;
618 +       bool update;
619 +       bool timestamped;
620 +       int tstamp_scale;
621 +       unsigned int num_axis;
622 +       struct scmi_sensor_axis_info *axis;
623 +       struct scmi_sensor_intervals_info intervals;
624         char name[SCMI_MAX_STR_SIZE];
625 +       bool extended_scalar_attrs;
626 +       unsigned int sensor_power;
627 +       unsigned int resolution;
628 +       int exponent;
629 +       struct scmi_range_attrs scalar_attrs;
630  };
631  
632  /*
633 @@ -163,11 +286,100 @@ struct scmi_sensor_info {
634   */
635  enum scmi_sensor_class {
636         NONE = 0x0,
637 +       UNSPEC = 0x1,
638         TEMPERATURE_C = 0x2,
639 +       TEMPERATURE_F = 0x3,
640 +       TEMPERATURE_K = 0x4,
641         VOLTAGE = 0x5,
642         CURRENT = 0x6,
643         POWER = 0x7,
644         ENERGY = 0x8,
645 +       CHARGE = 0x9,
646 +       VOLTAMPERE = 0xA,
647 +       NITS = 0xB,
648 +       LUMENS = 0xC,
649 +       LUX = 0xD,
650 +       CANDELAS = 0xE,
651 +       KPA = 0xF,
652 +       PSI = 0x10,
653 +       NEWTON = 0x11,
654 +       CFM = 0x12,
655 +       RPM = 0x13,
656 +       HERTZ = 0x14,
657 +       SECS = 0x15,
658 +       MINS = 0x16,
659 +       HOURS = 0x17,
660 +       DAYS = 0x18,
661 +       WEEKS = 0x19,
662 +       MILS = 0x1A,
663 +       INCHES = 0x1B,
664 +       FEET = 0x1C,
665 +       CUBIC_INCHES = 0x1D,
666 +       CUBIC_FEET = 0x1E,
667 +       METERS = 0x1F,
668 +       CUBIC_CM = 0x20,
669 +       CUBIC_METERS = 0x21,
670 +       LITERS = 0x22,
671 +       FLUID_OUNCES = 0x23,
672 +       RADIANS = 0x24,
673 +       STERADIANS = 0x25,
674 +       REVOLUTIONS = 0x26,
675 +       CYCLES = 0x27,
676 +       GRAVITIES = 0x28,
677 +       OUNCES = 0x29,
678 +       POUNDS = 0x2A,
679 +       FOOT_POUNDS = 0x2B,
680 +       OUNCE_INCHES = 0x2C,
681 +       GAUSS = 0x2D,
682 +       GILBERTS = 0x2E,
683 +       HENRIES = 0x2F,
684 +       FARADS = 0x30,
685 +       OHMS = 0x31,
686 +       SIEMENS = 0x32,
687 +       MOLES = 0x33,
688 +       BECQUERELS = 0x34,
689 +       PPM = 0x35,
690 +       DECIBELS = 0x36,
691 +       DBA = 0x37,
692 +       DBC = 0x38,
693 +       GRAYS = 0x39,
694 +       SIEVERTS = 0x3A,
695 +       COLOR_TEMP_K = 0x3B,
696 +       BITS = 0x3C,
697 +       BYTES = 0x3D,
698 +       WORDS = 0x3E,
699 +       DWORDS = 0x3F,
700 +       QWORDS = 0x40,
701 +       PERCENTAGE = 0x41,
702 +       PASCALS = 0x42,
703 +       COUNTS = 0x43,
704 +       GRAMS = 0x44,
705 +       NEWTON_METERS = 0x45,
706 +       HITS = 0x46,
707 +       MISSES = 0x47,
708 +       RETRIES = 0x48,
709 +       OVERRUNS = 0x49,
710 +       UNDERRUNS = 0x4A,
711 +       COLLISIONS = 0x4B,
712 +       PACKETS = 0x4C,
713 +       MESSAGES = 0x4D,
714 +       CHARS = 0x4E,
715 +       ERRORS = 0x4F,
716 +       CORRECTED_ERRS = 0x50,
717 +       UNCORRECTABLE_ERRS = 0x51,
718 +       SQ_MILS = 0x52,
719 +       SQ_INCHES = 0x53,
720 +       SQ_FEET = 0x54,
721 +       SQ_CM = 0x55,
722 +       SQ_METERS = 0x56,
723 +       RADIANS_SEC = 0x57,
724 +       BPM = 0x58,
725 +       METERS_SEC_SQUARED = 0x59,
726 +       METERS_SEC = 0x5A,
727 +       CUBIC_METERS_SEC = 0x5B,
728 +       MM_MERCURY = 0x5C,
729 +       RADIANS_SEC_SQUARED = 0x5D,
730 +       OEM_UNIT = 0xFF
731  };
732  
733  /**