firmware: arm_scpi: improve struct dvfs_info to make code better readable
PATCH 1/3 firmware: arm_scpi: improve struct dvfs_info to make code better readable
Making the header subfields members of struct dvfs_info allows to make the code better readable and avoids some macro magic.
In addition remove a useless statement using info->latency.
--- drivers/firmware/arm_scpi.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/firmware/arm_scpi.c +5 -8
@@ -72,8 +72,6 @@#define MAX_DVFS_DOMAINS 8#define MAX_DVFS_OPPS 16 -#define DVFS_LATENCY (hdr) (le32_to_cpu(hdr) >> 16) -#define DVFS_OPP_COUNT (hdr) ((le32_to_cpu(hdr) >> 8) & 0xff)#define PROTOCOL_REV_MINOR_BITS 16#define PROTOCOL_REV_MINOR_MASK ((1U << PROTOCOL_REV_MINOR_BITS) - 1)
@@ -328,7 +326,9 @@ struct legacy_clk_set_value { } __packed;struct dvfs_info { -__le32 header; +u8 domain; +u8 opp_count; +__le16 latency;struct {__le32 freq;__le32 m_volt;
@@ -667,8 +667,8 @@ static int scpi_dvfs_populate_info(struct device *dev, u8 domain)if (!info)return -ENOMEM ; - info->count =DVFS_OPP_COUNT (buf.header); - info->latency =DVFS_LATENCY (buf.header) *1000 ;/* uS to nS */ + info->count = buf.opp_count; + info->latency =le16_to_cpu (buf.latency) *1000 ;/* uS to nS */ info->opps =devm_kcalloc (dev, info->count,sizeof (*opp),GFP_KERNEL );if (!info->opps)
@@ -721,9 +721,6 @@ static int scpi_dvfs_get_transition_latency(struct device *dev)if (IS_ERR (info))return PTR_ERR (info); -if (!info->latency) -return 0 ; -return info->latency; }
Signature · 1 line
2.14.2
PATCH 2/3 firmware: arm_scpi: improve handling of protocol and firmware version subfields
By using FIELD_GET and proper masks we can avoid quite some shifting and masking macro magic and make the code better readable.
--- drivers/firmware/arm_scpi.c | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-)
drivers/firmware/arm_scpi.c +19 -24
@@ -28,6 +28,7 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt#include <linux/bitmap.h> +#include <linux/bitfield.h> #include <linux/device.h> #include <linux/err.h> #include <linux/export.h>
@@ -73,18 +74,12 @@#define MAX_DVFS_DOMAINS 8#define MAX_DVFS_OPPS 16 -#define PROTOCOL_REV_MINOR_BITS 16 -#define PROTOCOL_REV_MINOR_MASK ((1U << PROTOCOL_REV_MINOR_BITS) - 1) -#define PROTOCOL_REV_MAJOR (x) ((x) >> PROTOCOL_REV_MINOR_BITS) -#define PROTOCOL_REV_MINOR (x) ((x) & PROTOCOL_REV_MINOR_MASK) +#define PROTO_REV_MAJOR_MASK GENMASK(31, 16) +#define PROTO_REV_MINOR_MASK GENMASK(15, 0) -#define FW_REV_MAJOR_BITS 24 -#define FW_REV_MINOR_BITS 16 -#define FW_REV_PATCH_MASK ((1U << FW_REV_MINOR_BITS) - 1) -#define FW_REV_MINOR_MASK ((1U << FW_REV_MAJOR_BITS) - 1) -#define FW_REV_MAJOR (x) ((x) >> FW_REV_MAJOR_BITS) -#define FW_REV_MINOR (x) (((x) & FW_REV_MINOR_MASK) >> FW_REV_MINOR_BITS) -#define FW_REV_PATCH (x) ((x) & FW_REV_PATCH_MASK) +#define FW_REV_MAJOR_MASK GENMASK(31, 24) +#define FW_REV_MINOR_MASK GENMASK(23, 16) +#define FW_REV_PATCH_MASK GENMASK(15, 0)#define MAX_RX_TIMEOUT (msecs_to_jiffies(30))
@@ -867,19 +862,19 @@ static int scpi_init_versions(struct scpi_drvinfo *info)static ssize_t protocol_version_show (struct device *dev,struct device_attribute *attr,char *buf) { -return sprintf (buf,"%d.%d\n" , -PROTOCOL_REV_MAJOR (scpi_info->protocol_version), -PROTOCOL_REV_MINOR (scpi_info->protocol_version)); +return sprintf (buf,"%lu.%lu\n" , +FIELD_GET (PROTO_REV_MAJOR_MASK , scpi_info->protocol_version), +FIELD_GET (PROTO_REV_MINOR_MASK , scpi_info->protocol_version)); }static DEVICE_ATTR_RO (protocol_version);static ssize_t firmware_version_show (struct device *dev,struct device_attribute *attr,char *buf) { -return sprintf (buf,"%d.%d.%d\n" , -FW_REV_MAJOR (scpi_info->firmware_version), -FW_REV_MINOR (scpi_info->firmware_version), -FW_REV_PATCH (scpi_info->firmware_version)); +return sprintf (buf,"%lu.%lu.%lu\n" , +FIELD_GET (FW_REV_MAJOR_MASK , scpi_info->firmware_version), +FIELD_GET (FW_REV_MINOR_MASK , scpi_info->firmware_version), +FIELD_GET (FW_REV_PATCH_MASK , scpi_info->firmware_version)); }static DEVICE_ATTR_RO (firmware_version);
@@ -1021,12 +1016,12 @@ static int scpi_probe(struct platform_device *pdev)scpi_dvfs_populate (dev); -_dev_info (dev,"SCP Protocol %d.%d Firmware %d.%d.%d version\n" , -PROTOCOL_REV_MAJOR (scpi_info->protocol_version), -PROTOCOL_REV_MINOR (scpi_info->protocol_version), -FW_REV_MAJOR (scpi_info->firmware_version), -FW_REV_MINOR (scpi_info->firmware_version), -FW_REV_PATCH (scpi_info->firmware_version)); +_dev_info (dev,"SCP Protocol %lu.%lu Firmware %lu.%lu.%lu version\n" , +FIELD_GET (PROTO_REV_MAJOR_MASK , scpi_info->protocol_version), +FIELD_GET (PROTO_REV_MINOR_MASK , scpi_info->protocol_version), +FIELD_GET (FW_REV_MAJOR_MASK , scpi_info->firmware_version), +FIELD_GET (FW_REV_MINOR_MASK , scpi_info->firmware_version), +FIELD_GET (FW_REV_PATCH_MASK , scpi_info->firmware_version)); ret =devm_device_add_groups (dev, versions_groups);if (ret)
Signature · 1 line
2.14.2
PATCH 3/3 firmware: arm_scpi: improve struct sensor_value
In reply to Heiner Kallweitlo_val and hi_val together in this order are a little endian 64 bit value. Therefore we can simplify struct sensor_value and the code by defining it as a __le64 value and by using le64_to_cpu.
--- drivers/firmware/arm_scpi.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/firmware/arm_scpi.c +5 -7
@@ -347,9 +347,8 @@ struct _scpi_sensor_info { };struct sensor_value { -__le32 lo_val; -__le32 hi_val; -} __packed; +__le64 val; +};struct dev_pstate_set {__le16 dev_id;
@@ -785,11 +784,10 @@ static int scpi_sensor_get_value(u16 sensor, u64 *val)return ret;if (scpi_info->is_legacy) -/* only 32-bits supported, hi_val can be junk */ - *val =le32_to_cpu (buf.lo_val); +/* only 32-bits supported, upper 32 bits can be junk */ + *val =le32_to_cpup ((__le32 *)&buf.val);else - *val = (u64 )le32_to_cpu (buf.hi_val) <<32 | -le32_to_cpu (buf.lo_val); + *val =le64_to_cpu (buf.val);return 0 ; }
Signature · 1 line
2.14.2
PATCH 1/3 firmware: arm_scpi: improve struct dvfs_info to make code better readable
In reply to Heiner KallweitQuoted 5 lines · Heiner Kallweit
Making the header subfields members of struct
dvfs_infoallows to make the code better readable and avoids some macro magic.In addition remove a useless statement using
info->latency.
All 3 looks trivial and applied now. Thanks for the cleanup.
I found couple of other trivial things that can be cleaned. I will CC you on them, it would be good if you can review and/or test.
I need to send PR by end of this week or early next week.
Signature · 2 lines
Regards, Sudeep