* [PATCH RFT 0/5] i3c: introduce and use generic parity helper
@ 2024-12-20 11:29 ` Wolfram Sang
0 siblings, 0 replies; 13+ messages in thread
From: Wolfram Sang @ 2024-12-20 11:29 UTC (permalink / raw)
To: linux-renesas-soc
Cc: Yury Norov, Wolfram Sang, Alexandre Belloni, Guenter Roeck,
Jean Delvare, linux-hwmon, linux-i3c, Przemysław Gaj
I am currently working on upstreaming another I3C controller driver. As
many others, it needs to ensure odd parity for a dynamically assigned
address. The BSP version of the driver implemented a custom parity
algorithm. Wondering why we don't have a generic helper for this in the
kernel, I found that many I3C controller drivers all implement their
version of handling parity.
So, I sent out an RFC[1] moving the efficient implementation of the
SPD5118 driver to a generic location. The series was well received, but
the path for upstream was not clear. Because I need the implementation
for my I3C controller driver and I3C is a prominent user of this new
function, I got the idea of converting the existing I3C drivers and
resend the series, suggesting this all goes upstream via I3C.
Is this acceptable? The non-I3C patches have all the tags they need,
only the I3C patches would need testing on hardware.
A locally build-tested branch is here:
git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git renesas/i3c/get_parity
Looking forward to comments...
[1] https://lore.kernel.org/all/20241214085833.8695-1-wsa+renesas@sang-engineering.com/
Wolfram Sang (5):
bitops: add generic parity calculation for u8
hwmon: (spd5118) Use generic parity calculation
i3c: dw: use get_parity8 helper instead of open coding it
i3c: mipi-i3c-hci: use get_parity8 helper instead of open coding it
i3c: cdns: use get_parity8 helper instead of open coding it
drivers/hwmon/spd5118.c | 8 +-----
drivers/i3c/master/dw-i3c-master.c | 14 +++--------
drivers/i3c/master/i3c-master-cdns.c | 3 +--
drivers/i3c/master/mipi-i3c-hci/dat_v1.c | 11 +--------
include/linux/bitops.h | 31 ++++++++++++++++++++++++
5 files changed, 37 insertions(+), 30 deletions(-)
--
2.39.2
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH RFT 0/5] i3c: introduce and use generic parity helper
@ 2024-12-20 11:29 ` Wolfram Sang
0 siblings, 0 replies; 13+ messages in thread
From: Wolfram Sang @ 2024-12-20 11:29 UTC (permalink / raw)
To: linux-renesas-soc
Cc: Yury Norov, Wolfram Sang, Alexandre Belloni, Guenter Roeck,
Jean Delvare, linux-hwmon, linux-i3c, Przemysław Gaj
I am currently working on upstreaming another I3C controller driver. As
many others, it needs to ensure odd parity for a dynamically assigned
address. The BSP version of the driver implemented a custom parity
algorithm. Wondering why we don't have a generic helper for this in the
kernel, I found that many I3C controller drivers all implement their
version of handling parity.
So, I sent out an RFC[1] moving the efficient implementation of the
SPD5118 driver to a generic location. The series was well received, but
the path for upstream was not clear. Because I need the implementation
for my I3C controller driver and I3C is a prominent user of this new
function, I got the idea of converting the existing I3C drivers and
resend the series, suggesting this all goes upstream via I3C.
Is this acceptable? The non-I3C patches have all the tags they need,
only the I3C patches would need testing on hardware.
A locally build-tested branch is here:
git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git renesas/i3c/get_parity
Looking forward to comments...
[1] https://lore.kernel.org/all/20241214085833.8695-1-wsa+renesas@sang-engineering.com/
Wolfram Sang (5):
bitops: add generic parity calculation for u8
hwmon: (spd5118) Use generic parity calculation
i3c: dw: use get_parity8 helper instead of open coding it
i3c: mipi-i3c-hci: use get_parity8 helper instead of open coding it
i3c: cdns: use get_parity8 helper instead of open coding it
drivers/hwmon/spd5118.c | 8 +-----
drivers/i3c/master/dw-i3c-master.c | 14 +++--------
drivers/i3c/master/i3c-master-cdns.c | 3 +--
drivers/i3c/master/mipi-i3c-hci/dat_v1.c | 11 +--------
include/linux/bitops.h | 31 ++++++++++++++++++++++++
5 files changed, 37 insertions(+), 30 deletions(-)
--
2.39.2
--
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH RFT 1/5] bitops: add generic parity calculation for u8
2024-12-20 11:29 ` Wolfram Sang
(?)
@ 2024-12-20 11:29 ` Wolfram Sang
2024-12-20 11:50 ` Rasmus Villemoes
-1 siblings, 1 reply; 13+ messages in thread
From: Wolfram Sang @ 2024-12-20 11:29 UTC (permalink / raw)
To: linux-renesas-soc
Cc: Yury Norov, Wolfram Sang, Guenter Roeck, Geert Uytterhoeven,
Kuan-Wei Chiu, Rasmus Villemoes
There are multiple open coded implementations for getting the parity of
a byte in the kernel, even using different approaches. Take the pretty
efficient version from SPD5118 driver and make it generally available by
putting it into the bitops header. As long as there is just one parity
calculation helper, the creation of a distinct 'parity.h' header was
discarded. Also, the usage of hweight8() for architectures having a
popcnt instruction is postponed until a use case within hot paths is
desired. The motivation for this patch is the frequent use of odd parity
in the I3C specification and to simplify drivers there.
Changes compared to the original SPD5118 version are the addition of
kernel documentation, switching the return type from bool to int, and
renaming the argument of the function.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Yury Norov <yury.norov@gmail.com>
Reviewed-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Tested-by: Kuan-Wei Chiu <visitorckw@gmail.com>
---
include/linux/bitops.h | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index ba35bbf07798..4ed430934ffc 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -229,6 +229,37 @@ static inline int get_count_order_long(unsigned long l)
return (int)fls_long(--l);
}
+/**
+ * get_parity8 - get the parity of an u8 value
+ * @value: the value to be examined
+ *
+ * Determine the parity of the u8 argument.
+ *
+ * Returns:
+ * 0 for even parity, 1 for odd parity
+ *
+ * Note: This function informs you about the current parity. Example to bail
+ * out when parity is odd:
+ *
+ * if (get_parity8(val) == 1)
+ * return -EBADMSG;
+ *
+ * If you need to calculate a parity bit, you need to draw the conclusion from
+ * this result yourself. Example to enforce odd parity, parity bit is bit 7:
+ *
+ * if (get_parity8(val) == 0)
+ * val |= BIT(7);
+ */
+static inline int get_parity8(u8 val)
+{
+ /*
+ * One explanation of this algorithm:
+ * https://funloop.org/codex/problem/parity/README.html
+ */
+ val ^= val >> 4;
+ return (0x6996 >> (val & 0xf)) & 1;
+}
+
/**
* __ffs64 - find first set bit in a 64 bit word
* @word: The 64 bit word
--
2.39.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH RFT 2/5] hwmon: (spd5118) Use generic parity calculation
2024-12-20 11:29 ` Wolfram Sang
(?)
(?)
@ 2024-12-20 11:29 ` Wolfram Sang
2024-12-20 15:23 ` Guenter Roeck
-1 siblings, 1 reply; 13+ messages in thread
From: Wolfram Sang @ 2024-12-20 11:29 UTC (permalink / raw)
To: linux-renesas-soc
Cc: Yury Norov, Wolfram Sang, Guenter Roeck, Geert Uytterhoeven,
Kuan-Wei Chiu, Jean Delvare, linux-hwmon
Make use of the new generic helper for calculating the parity.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Kuan-Wei Chiu <visitorckw@gmail.com>
---
drivers/hwmon/spd5118.c | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
diff --git a/drivers/hwmon/spd5118.c b/drivers/hwmon/spd5118.c
index 6cee48a3e5c3..07ab3a47b00c 100644
--- a/drivers/hwmon/spd5118.c
+++ b/drivers/hwmon/spd5118.c
@@ -291,12 +291,6 @@ static umode_t spd5118_is_visible(const void *_data, enum hwmon_sensor_types typ
}
}
-static inline bool spd5118_parity8(u8 w)
-{
- w ^= w >> 4;
- return (0x6996 >> (w & 0xf)) & 1;
-}
-
/*
* Bank and vendor id are 8-bit fields with seven data bits and odd parity.
* Vendor IDs 0 and 0x7f are invalid.
@@ -304,7 +298,7 @@ static inline bool spd5118_parity8(u8 w)
*/
static bool spd5118_vendor_valid(u8 bank, u8 id)
{
- if (!spd5118_parity8(bank) || !spd5118_parity8(id))
+ if (get_parity8(bank) == 0 || get_parity8(id) == 0)
return false;
id &= 0x7f;
--
2.39.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH RFT 3/5] i3c: dw: use get_parity8 helper instead of open coding it
2024-12-20 11:29 ` Wolfram Sang
@ 2024-12-20 11:29 ` Wolfram Sang
-1 siblings, 0 replies; 13+ messages in thread
From: Wolfram Sang @ 2024-12-20 11:29 UTC (permalink / raw)
To: linux-renesas-soc; +Cc: Yury Norov, Wolfram Sang, Alexandre Belloni, linux-i3c
The kernel has now a generic helper for getting parity with easier to
understand semantics. Make use of it.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
drivers/i3c/master/dw-i3c-master.c | 14 +++-----------
1 file changed, 3 insertions(+), 11 deletions(-)
diff --git a/drivers/i3c/master/dw-i3c-master.c b/drivers/i3c/master/dw-i3c-master.c
index d4b80eb8cecd..a6d7fade5007 100644
--- a/drivers/i3c/master/dw-i3c-master.c
+++ b/drivers/i3c/master/dw-i3c-master.c
@@ -251,14 +251,6 @@ struct dw_i3c_i2c_dev_data {
struct i3c_generic_ibi_pool *ibi_pool;
};
-static u8 even_parity(u8 p)
-{
- p ^= p >> 4;
- p &= 0xf;
-
- return (0x9669 >> p) & 1;
-}
-
static bool dw_i3c_master_supports_ccc_cmd(struct i3c_master_controller *m,
const struct i3c_ccc_cmd *cmd)
{
@@ -848,7 +840,7 @@ static int dw_i3c_master_daa(struct i3c_master_controller *m)
struct dw_i3c_xfer *xfer;
struct dw_i3c_cmd *cmd;
u32 olddevs, newdevs;
- u8 p, last_addr = 0;
+ u8 last_addr = 0;
int ret, pos;
ret = pm_runtime_resume_and_get(master->dev);
@@ -873,9 +865,9 @@ static int dw_i3c_master_daa(struct i3c_master_controller *m)
}
master->devs[pos].addr = ret;
- p = even_parity(ret);
last_addr = ret;
- ret |= (p << 7);
+
+ ret |= get_parity8(ret) ? 0 : BIT(7);
writel(DEV_ADDR_TABLE_DYNAMIC_ADDR(ret),
master->regs +
--
2.39.2
--
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH RFT 3/5] i3c: dw: use get_parity8 helper instead of open coding it
@ 2024-12-20 11:29 ` Wolfram Sang
0 siblings, 0 replies; 13+ messages in thread
From: Wolfram Sang @ 2024-12-20 11:29 UTC (permalink / raw)
To: linux-renesas-soc; +Cc: Yury Norov, Wolfram Sang, Alexandre Belloni, linux-i3c
The kernel has now a generic helper for getting parity with easier to
understand semantics. Make use of it.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
drivers/i3c/master/dw-i3c-master.c | 14 +++-----------
1 file changed, 3 insertions(+), 11 deletions(-)
diff --git a/drivers/i3c/master/dw-i3c-master.c b/drivers/i3c/master/dw-i3c-master.c
index d4b80eb8cecd..a6d7fade5007 100644
--- a/drivers/i3c/master/dw-i3c-master.c
+++ b/drivers/i3c/master/dw-i3c-master.c
@@ -251,14 +251,6 @@ struct dw_i3c_i2c_dev_data {
struct i3c_generic_ibi_pool *ibi_pool;
};
-static u8 even_parity(u8 p)
-{
- p ^= p >> 4;
- p &= 0xf;
-
- return (0x9669 >> p) & 1;
-}
-
static bool dw_i3c_master_supports_ccc_cmd(struct i3c_master_controller *m,
const struct i3c_ccc_cmd *cmd)
{
@@ -848,7 +840,7 @@ static int dw_i3c_master_daa(struct i3c_master_controller *m)
struct dw_i3c_xfer *xfer;
struct dw_i3c_cmd *cmd;
u32 olddevs, newdevs;
- u8 p, last_addr = 0;
+ u8 last_addr = 0;
int ret, pos;
ret = pm_runtime_resume_and_get(master->dev);
@@ -873,9 +865,9 @@ static int dw_i3c_master_daa(struct i3c_master_controller *m)
}
master->devs[pos].addr = ret;
- p = even_parity(ret);
last_addr = ret;
- ret |= (p << 7);
+
+ ret |= get_parity8(ret) ? 0 : BIT(7);
writel(DEV_ADDR_TABLE_DYNAMIC_ADDR(ret),
master->regs +
--
2.39.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH RFT 4/5] i3c: mipi-i3c-hci: use get_parity8 helper instead of open coding it
2024-12-20 11:29 ` Wolfram Sang
@ 2024-12-20 11:29 ` Wolfram Sang
-1 siblings, 0 replies; 13+ messages in thread
From: Wolfram Sang @ 2024-12-20 11:29 UTC (permalink / raw)
To: linux-renesas-soc; +Cc: Yury Norov, Wolfram Sang, Alexandre Belloni, linux-i3c
The kernel has now a generic helper for getting parity with easier to
understand semantics. Make use of it.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
drivers/i3c/master/mipi-i3c-hci/dat_v1.c | 11 +----------
1 file changed, 1 insertion(+), 10 deletions(-)
diff --git a/drivers/i3c/master/mipi-i3c-hci/dat_v1.c b/drivers/i3c/master/mipi-i3c-hci/dat_v1.c
index 47b9b4d4ed3f..ac67016932b0 100644
--- a/drivers/i3c/master/mipi-i3c-hci/dat_v1.c
+++ b/drivers/i3c/master/mipi-i3c-hci/dat_v1.c
@@ -40,15 +40,6 @@
#define dat_w0_write(i, v) writel(v, hci->DAT_regs + (i) * 8)
#define dat_w1_write(i, v) writel(v, hci->DAT_regs + (i) * 8 + 4)
-static inline bool dynaddr_parity(unsigned int addr)
-{
- addr |= 1 << 7;
- addr += addr >> 4;
- addr += addr >> 2;
- addr += addr >> 1;
- return (addr & 1);
-}
-
static int hci_dat_v1_init(struct i3c_hci *hci)
{
unsigned int dat_idx;
@@ -123,7 +114,7 @@ static void hci_dat_v1_set_dynamic_addr(struct i3c_hci *hci,
dat_w0 = dat_w0_read(dat_idx);
dat_w0 &= ~(DAT_0_DYNAMIC_ADDRESS | DAT_0_DYNADDR_PARITY);
dat_w0 |= FIELD_PREP(DAT_0_DYNAMIC_ADDRESS, address) |
- (dynaddr_parity(address) ? DAT_0_DYNADDR_PARITY : 0);
+ (get_parity8(address) ? 0 : DAT_0_DYNADDR_PARITY);
dat_w0_write(dat_idx, dat_w0);
}
--
2.39.2
--
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH RFT 4/5] i3c: mipi-i3c-hci: use get_parity8 helper instead of open coding it
@ 2024-12-20 11:29 ` Wolfram Sang
0 siblings, 0 replies; 13+ messages in thread
From: Wolfram Sang @ 2024-12-20 11:29 UTC (permalink / raw)
To: linux-renesas-soc; +Cc: Yury Norov, Wolfram Sang, Alexandre Belloni, linux-i3c
The kernel has now a generic helper for getting parity with easier to
understand semantics. Make use of it.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
drivers/i3c/master/mipi-i3c-hci/dat_v1.c | 11 +----------
1 file changed, 1 insertion(+), 10 deletions(-)
diff --git a/drivers/i3c/master/mipi-i3c-hci/dat_v1.c b/drivers/i3c/master/mipi-i3c-hci/dat_v1.c
index 47b9b4d4ed3f..ac67016932b0 100644
--- a/drivers/i3c/master/mipi-i3c-hci/dat_v1.c
+++ b/drivers/i3c/master/mipi-i3c-hci/dat_v1.c
@@ -40,15 +40,6 @@
#define dat_w0_write(i, v) writel(v, hci->DAT_regs + (i) * 8)
#define dat_w1_write(i, v) writel(v, hci->DAT_regs + (i) * 8 + 4)
-static inline bool dynaddr_parity(unsigned int addr)
-{
- addr |= 1 << 7;
- addr += addr >> 4;
- addr += addr >> 2;
- addr += addr >> 1;
- return (addr & 1);
-}
-
static int hci_dat_v1_init(struct i3c_hci *hci)
{
unsigned int dat_idx;
@@ -123,7 +114,7 @@ static void hci_dat_v1_set_dynamic_addr(struct i3c_hci *hci,
dat_w0 = dat_w0_read(dat_idx);
dat_w0 &= ~(DAT_0_DYNAMIC_ADDRESS | DAT_0_DYNADDR_PARITY);
dat_w0 |= FIELD_PREP(DAT_0_DYNAMIC_ADDRESS, address) |
- (dynaddr_parity(address) ? DAT_0_DYNADDR_PARITY : 0);
+ (get_parity8(address) ? 0 : DAT_0_DYNADDR_PARITY);
dat_w0_write(dat_idx, dat_w0);
}
--
2.39.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH RFT 5/5] i3c: cdns: use get_parity8 helper instead of open coding it
2024-12-20 11:29 ` Wolfram Sang
@ 2024-12-20 11:29 ` Wolfram Sang
-1 siblings, 0 replies; 13+ messages in thread
From: Wolfram Sang @ 2024-12-20 11:29 UTC (permalink / raw)
To: linux-renesas-soc
Cc: Yury Norov, Wolfram Sang, Przemysław Gaj, Alexandre Belloni,
linux-i3c
The kernel has now a generic helper for getting parity with easier to
understand semantics. Make use of it.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
Can't the '& 0x7f' be left out here?
drivers/i3c/master/i3c-master-cdns.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/i3c/master/i3c-master-cdns.c b/drivers/i3c/master/i3c-master-cdns.c
index 06c0592487d3..abeef6f70b53 100644
--- a/drivers/i3c/master/i3c-master-cdns.c
+++ b/drivers/i3c/master/i3c-master-cdns.c
@@ -889,8 +889,7 @@ static u32 prepare_rr0_dev_address(u32 addr)
ret |= (addr & GENMASK(9, 7)) << 6;
/* RR0[0] = ~XOR(addr[6:0]) */
- if (!(hweight8(addr & 0x7f) & 1))
- ret |= 1;
+ ret |= get_parity8(addr & 0x7f) ? 0 : BIT(0);
return ret;
}
--
2.39.2
--
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH RFT 5/5] i3c: cdns: use get_parity8 helper instead of open coding it
@ 2024-12-20 11:29 ` Wolfram Sang
0 siblings, 0 replies; 13+ messages in thread
From: Wolfram Sang @ 2024-12-20 11:29 UTC (permalink / raw)
To: linux-renesas-soc
Cc: Yury Norov, Wolfram Sang, Przemysław Gaj, Alexandre Belloni,
linux-i3c
The kernel has now a generic helper for getting parity with easier to
understand semantics. Make use of it.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
Can't the '& 0x7f' be left out here?
drivers/i3c/master/i3c-master-cdns.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/i3c/master/i3c-master-cdns.c b/drivers/i3c/master/i3c-master-cdns.c
index 06c0592487d3..abeef6f70b53 100644
--- a/drivers/i3c/master/i3c-master-cdns.c
+++ b/drivers/i3c/master/i3c-master-cdns.c
@@ -889,8 +889,7 @@ static u32 prepare_rr0_dev_address(u32 addr)
ret |= (addr & GENMASK(9, 7)) << 6;
/* RR0[0] = ~XOR(addr[6:0]) */
- if (!(hweight8(addr & 0x7f) & 1))
- ret |= 1;
+ ret |= get_parity8(addr & 0x7f) ? 0 : BIT(0);
return ret;
}
--
2.39.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH RFT 1/5] bitops: add generic parity calculation for u8
2024-12-20 11:29 ` [PATCH RFT 1/5] bitops: add generic parity calculation for u8 Wolfram Sang
@ 2024-12-20 11:50 ` Rasmus Villemoes
2024-12-22 13:00 ` Wolfram Sang
0 siblings, 1 reply; 13+ messages in thread
From: Rasmus Villemoes @ 2024-12-20 11:50 UTC (permalink / raw)
To: Wolfram Sang
Cc: linux-renesas-soc, Yury Norov, Guenter Roeck, Geert Uytterhoeven,
Kuan-Wei Chiu
> +/**
> + * get_parity8 - get the parity of an u8 value
I know it's prototypical bikeshedding, but what's with the "get_"
prefix? Certainly the purpose of any pure function is to "get" the
result of some computation. We don't have "get_strlen()".
Please either just "parity8", or if you want to emphasize that this
belongs in the bit-munging family, "bit_parity8".
> + * @value: the value to be examined
> + *
> + * Determine the parity of the u8 argument.
> + *
> + * Returns:
> + * 0 for even parity, 1 for odd parity
> + *
> + * Note: This function informs you about the current parity. Example to bail
> + * out when parity is odd:
> + *
> + * if (get_parity8(val) == 1)
> + * return -EBADMSG;
> + *
> + * If you need to calculate a parity bit, you need to draw the conclusion from
> + * this result yourself. Example to enforce odd parity, parity bit is bit 7:
> + *
> + * if (get_parity8(val) == 0)
> + * val |= BIT(7);
Shouldn't that be ^= in general? Of course in some particular
application one may have constructed the value in the lower 7 bits and
"know" that bit 7 is currently clear.
Rasmus
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH RFT 2/5] hwmon: (spd5118) Use generic parity calculation
2024-12-20 11:29 ` [PATCH RFT 2/5] hwmon: (spd5118) Use generic parity calculation Wolfram Sang
@ 2024-12-20 15:23 ` Guenter Roeck
0 siblings, 0 replies; 13+ messages in thread
From: Guenter Roeck @ 2024-12-20 15:23 UTC (permalink / raw)
To: Wolfram Sang, linux-renesas-soc
Cc: Yury Norov, Geert Uytterhoeven, Kuan-Wei Chiu, Jean Delvare,
linux-hwmon
On 12/20/24 03:29, Wolfram Sang wrote:
> Make use of the new generic helper for calculating the parity.
>
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> Tested-by: Guenter Roeck <linux@roeck-us.net>
> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
> Reviewed-by: Kuan-Wei Chiu <visitorckw@gmail.com>
For the record:
Acked-by: Guenter Roeck <linux@roeck-us.net>
I don't care about the function name, so please retain the tags if/when
changing it.
Thanks,
Guenter
> ---
> drivers/hwmon/spd5118.c | 8 +-------
> 1 file changed, 1 insertion(+), 7 deletions(-)
>
> diff --git a/drivers/hwmon/spd5118.c b/drivers/hwmon/spd5118.c
> index 6cee48a3e5c3..07ab3a47b00c 100644
> --- a/drivers/hwmon/spd5118.c
> +++ b/drivers/hwmon/spd5118.c
> @@ -291,12 +291,6 @@ static umode_t spd5118_is_visible(const void *_data, enum hwmon_sensor_types typ
> }
> }
>
> -static inline bool spd5118_parity8(u8 w)
> -{
> - w ^= w >> 4;
> - return (0x6996 >> (w & 0xf)) & 1;
> -}
> -
> /*
> * Bank and vendor id are 8-bit fields with seven data bits and odd parity.
> * Vendor IDs 0 and 0x7f are invalid.
> @@ -304,7 +298,7 @@ static inline bool spd5118_parity8(u8 w)
> */
> static bool spd5118_vendor_valid(u8 bank, u8 id)
> {
> - if (!spd5118_parity8(bank) || !spd5118_parity8(id))
> + if (get_parity8(bank) == 0 || get_parity8(id) == 0)
> return false;
>
> id &= 0x7f;
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH RFT 1/5] bitops: add generic parity calculation for u8
2024-12-20 11:50 ` Rasmus Villemoes
@ 2024-12-22 13:00 ` Wolfram Sang
0 siblings, 0 replies; 13+ messages in thread
From: Wolfram Sang @ 2024-12-22 13:00 UTC (permalink / raw)
To: Rasmus Villemoes
Cc: linux-renesas-soc, Yury Norov, Guenter Roeck, Geert Uytterhoeven,
Kuan-Wei Chiu
[-- Attachment #1: Type: text/plain, Size: 1366 bytes --]
Hi Rasmus,
thanks for the review!
> I know it's prototypical bikeshedding, but what's with the "get_"
> prefix? Certainly the purpose of any pure function is to "get" the
> result of some computation. We don't have "get_strlen()".
Hmmm, can be argued.
The reason I chose the naming was that the open coded implementations
were sometimes either returning the current parity or returning the bit
which you need to enforce a certain parity. And this was never obvious
from their names. Sometimes it was not even clear if the returned bit
was for odd or even parity, just for "their" parity whatever it was.
So, with "get_" I wanted to ensure that people can read from the name,
that this is about the current parity and one has to draw conclusions
from there. But maybe the kdoc documentation is good enough for this?
> Please either just "parity8", or if you want to emphasize that this
> belongs in the bit-munging family, "bit_parity8".
I'd go for 'parity8' then.
> > + * if (get_parity8(val) == 0)
> > + * val |= BIT(7);
>
> Shouldn't that be ^= in general? Of course in some particular
> application one may have constructed the value in the lower 7 bits and
> "know" that bit 7 is currently clear.
Yeah, that is my use case. True, your example is more generic. Will fix.
All the best,
Wolfram
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2024-12-22 13:00 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-20 11:29 [PATCH RFT 0/5] i3c: introduce and use generic parity helper Wolfram Sang
2024-12-20 11:29 ` Wolfram Sang
2024-12-20 11:29 ` [PATCH RFT 1/5] bitops: add generic parity calculation for u8 Wolfram Sang
2024-12-20 11:50 ` Rasmus Villemoes
2024-12-22 13:00 ` Wolfram Sang
2024-12-20 11:29 ` [PATCH RFT 2/5] hwmon: (spd5118) Use generic parity calculation Wolfram Sang
2024-12-20 15:23 ` Guenter Roeck
2024-12-20 11:29 ` [PATCH RFT 3/5] i3c: dw: use get_parity8 helper instead of open coding it Wolfram Sang
2024-12-20 11:29 ` Wolfram Sang
2024-12-20 11:29 ` [PATCH RFT 4/5] i3c: mipi-i3c-hci: " Wolfram Sang
2024-12-20 11:29 ` Wolfram Sang
2024-12-20 11:29 ` [PATCH RFT 5/5] i3c: cdns: " Wolfram Sang
2024-12-20 11:29 ` Wolfram Sang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.