2019-12-15 08:56:16

by Lorenzo Bianconi

[permalink] [raw]
Subject: [PATCH 0/2] improve mt76 led code readability

Improve code readability relying on FIELD_PREP macro for led register
definitions and remove open coding

Lorenzo Bianconi (2):
mt76: mt76x02: simplify led reg definitions
mt76: mt7603: simplify led reg definitions

drivers/net/wireless/mediatek/mt76/mt7603/regs.h | 12 +++---------
drivers/net/wireless/mediatek/mt76/mt76x02_regs.h | 9 +++------
2 files changed, 6 insertions(+), 15 deletions(-)

--
2.21.0


2019-12-15 08:56:26

by Lorenzo Bianconi

[permalink] [raw]
Subject: [PATCH 1/2] mt76: mt76x02: simplify led reg definitions

Rely on FIELD_PREP macro for led register definitions and
remove open coding

Signed-off-by: Lorenzo Bianconi <[email protected]>
---
drivers/net/wireless/mediatek/mt76/mt76x02_regs.h | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_regs.h b/drivers/net/wireless/mediatek/mt76/mt76x02_regs.h
index 21c0f351fa09..b69a495d0b9a 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_regs.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_regs.h
@@ -236,14 +236,11 @@
#define MT_LED_S1_BASE 0x0780
#define MT_LED_S1(_n) (MT_LED_S1_BASE + 8 * (_n))
#define MT_LED_STATUS_OFF_MASK GENMASK(31, 24)
-#define MT_LED_STATUS_OFF(_v) (((_v) << __ffs(MT_LED_STATUS_OFF_MASK)) & \
- MT_LED_STATUS_OFF_MASK)
+#define MT_LED_STATUS_OFF(_v) FIELD_PREP(MT_LED_STATUS_OFF_MASK, (_v))
#define MT_LED_STATUS_ON_MASK GENMASK(23, 16)
-#define MT_LED_STATUS_ON(_v) (((_v) << __ffs(MT_LED_STATUS_ON_MASK)) & \
- MT_LED_STATUS_ON_MASK)
+#define MT_LED_STATUS_ON(_v) FIELD_PREP(MT_LED_STATUS_ON_MASK, (_v))
#define MT_LED_STATUS_DURATION_MASK GENMASK(15, 8)
-#define MT_LED_STATUS_DURATION(_v) (((_v) << __ffs(MT_LED_STATUS_DURATION_MASK)) & \
- MT_LED_STATUS_DURATION_MASK)
+#define MT_LED_STATUS_DURATION(_v) FIELD_PREP(MT_LED_STATUS_DURATION_MASK, (_v))

#define MT_FCE_PSE_CTRL 0x0800
#define MT_FCE_PARAMETERS 0x0804
--
2.21.0

2019-12-15 08:56:57

by Lorenzo Bianconi

[permalink] [raw]
Subject: [PATCH 2/2] mt76: mt7603: simplify led reg definitions

Rely on FIELD_PREP macro for led register definitions and
remove open coding

Signed-off-by: Lorenzo Bianconi <[email protected]>
---
drivers/net/wireless/mediatek/mt76/mt7603/regs.h | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7603/regs.h b/drivers/net/wireless/mediatek/mt76/mt7603/regs.h
index 6e23ed3dfdff..52425eb187f6 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7603/regs.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7603/regs.h
@@ -586,17 +586,11 @@ enum {
#define MT_LED_STATUS_0(_n) MT_LED_PHYS(0x10 + ((_n) * 8))
#define MT_LED_STATUS_1(_n) MT_LED_PHYS(0x14 + ((_n) * 8))
#define MT_LED_STATUS_OFF_MASK GENMASK(31, 24)
-#define MT_LED_STATUS_OFF(_v) (((_v) << \
- __ffs(MT_LED_STATUS_OFF_MASK)) & \
- MT_LED_STATUS_OFF_MASK)
+#define MT_LED_STATUS_OFF(_v) FIELD_PREP(MT_LED_STATUS_OFF_MASK, (_v))
#define MT_LED_STATUS_ON_MASK GENMASK(23, 16)
-#define MT_LED_STATUS_ON(_v) (((_v) << \
- __ffs(MT_LED_STATUS_ON_MASK)) & \
- MT_LED_STATUS_ON_MASK)
+#define MT_LED_STATUS_ON(_v) FIELD_PREP(MT_LED_STATUS_ON_MASK, (_v))
#define MT_LED_STATUS_DURATION_MASK GENMASK(15, 0)
-#define MT_LED_STATUS_DURATION(_v) (((_v) << \
- __ffs(MT_LED_STATUS_DURATION_MASK)) &\
- MT_LED_STATUS_DURATION_MASK)
+#define MT_LED_STATUS_DURATION(_v) FIELD_PREP(MT_LED_STATUS_DURATION_MASK, (_v))

#define MT_CLIENT_BASE_PHYS_ADDR 0x800c0000

--
2.21.0

2019-12-15 15:26:35

by Felix Fietkau

[permalink] [raw]
Subject: Re: [PATCH 2/2] mt76: mt7603: simplify led reg definitions

On 2019-12-15 09:54, Lorenzo Bianconi wrote:
> Rely on FIELD_PREP macro for led register definitions and
> remove open coding
>
> Signed-off-by: Lorenzo Bianconi <[email protected]>
Please move the FIELD_PREP from the header files to the source file to
be consistent with the rest of the code. Same applies to the mt7615 patch.

- Felix