* [PATCH 1/3] firmware: arm_scpi: improve struct dvfs_info to make code better readable
@ 2017-10-04 18:56 Heiner Kallweit
2017-10-04 19:00 ` [PATCH 2/3] firmware: arm_scpi: improve handling of protocol and firmware version subfields Heiner Kallweit
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Heiner Kallweit @ 2017-10-04 18:56 UTC (permalink / raw)
To: linux-arm-kernel
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.
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
drivers/firmware/arm_scpi.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/drivers/firmware/arm_scpi.c b/drivers/firmware/arm_scpi.c
index f713a64c..412f1c4c 100644
--- a/drivers/firmware/arm_scpi.c
+++ b/drivers/firmware/arm_scpi.c
@@ -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;
}
--
2.14.2
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 2/3] firmware: arm_scpi: improve handling of protocol and firmware version subfields 2017-10-04 18:56 [PATCH 1/3] firmware: arm_scpi: improve struct dvfs_info to make code better readable Heiner Kallweit @ 2017-10-04 19:00 ` Heiner Kallweit 2017-10-04 19:05 ` [PATCH 3/3] firmware: arm_scpi: improve struct sensor_value Heiner Kallweit 2017-10-05 11:02 ` [PATCH 1/3] firmware: arm_scpi: improve struct dvfs_info to make code better readable Sudeep Holla 2 siblings, 0 replies; 4+ messages in thread From: Heiner Kallweit @ 2017-10-04 19:00 UTC (permalink / raw) To: linux-arm-kernel By using FIELD_GET and proper masks we can avoid quite some shifting and masking macro magic and make the code better readable. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> --- drivers/firmware/arm_scpi.c | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/drivers/firmware/arm_scpi.c b/drivers/firmware/arm_scpi.c index 412f1c4c..d305b926 100644 --- a/drivers/firmware/arm_scpi.c +++ b/drivers/firmware/arm_scpi.c @@ -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) -- 2.14.2 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] firmware: arm_scpi: improve struct sensor_value 2017-10-04 18:56 [PATCH 1/3] firmware: arm_scpi: improve struct dvfs_info to make code better readable Heiner Kallweit 2017-10-04 19:00 ` [PATCH 2/3] firmware: arm_scpi: improve handling of protocol and firmware version subfields Heiner Kallweit @ 2017-10-04 19:05 ` Heiner Kallweit 2017-10-05 11:02 ` [PATCH 1/3] firmware: arm_scpi: improve struct dvfs_info to make code better readable Sudeep Holla 2 siblings, 0 replies; 4+ messages in thread From: Heiner Kallweit @ 2017-10-04 19:05 UTC (permalink / raw) To: linux-arm-kernel lo_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. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> --- drivers/firmware/arm_scpi.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/firmware/arm_scpi.c b/drivers/firmware/arm_scpi.c index d305b926..c923d1eb 100644 --- a/drivers/firmware/arm_scpi.c +++ b/drivers/firmware/arm_scpi.c @@ -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; } -- 2.14.2 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 1/3] firmware: arm_scpi: improve struct dvfs_info to make code better readable 2017-10-04 18:56 [PATCH 1/3] firmware: arm_scpi: improve struct dvfs_info to make code better readable Heiner Kallweit 2017-10-04 19:00 ` [PATCH 2/3] firmware: arm_scpi: improve handling of protocol and firmware version subfields Heiner Kallweit 2017-10-04 19:05 ` [PATCH 3/3] firmware: arm_scpi: improve struct sensor_value Heiner Kallweit @ 2017-10-05 11:02 ` Sudeep Holla 2 siblings, 0 replies; 4+ messages in thread From: Sudeep Holla @ 2017-10-05 11:02 UTC (permalink / raw) To: linux-arm-kernel On 04/10/17 19:56, Heiner Kallweit wrote: > 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. > 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. -- Regards, Sudeep ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-10-05 11:02 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2017-10-04 18:56 [PATCH 1/3] firmware: arm_scpi: improve struct dvfs_info to make code better readable Heiner Kallweit 2017-10-04 19:00 ` [PATCH 2/3] firmware: arm_scpi: improve handling of protocol and firmware version subfields Heiner Kallweit 2017-10-04 19:05 ` [PATCH 3/3] firmware: arm_scpi: improve struct sensor_value Heiner Kallweit 2017-10-05 11:02 ` [PATCH 1/3] firmware: arm_scpi: improve struct dvfs_info to make code better readable Sudeep Holla
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).