Skip to contentSkip to conversation

8250_dwlib: Convert bitops to newer form

PATCH In review Ilpo Järvinen 2 participants 3 messages Jun 30, 2022

Subsystems (3)
lore
Share & tools
lore

Ilpo Järvinen

author maintainer
#0 lore raw

PATCH 1/1 8250_dwlib: Convert bitops to newer form

Instead of open-coding, use BIT(), GENMASK(), and FIELD_GET() helpers.

---
 drivers/tty/serial/8250/8250_dwlib.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)
drivers/tty/serial/8250/8250_dwlib.c +13 -13
index da330ef46446..a8bbed74ea70 100644
@@ -46,21 +46,21 @@
 #define DW_UART_LCR_EXT_TRANSMIT_MODE	BIT(3)
 
 /* Component Parameter Register bits */
-#define DW_UART_CPR_ABP_DATA_WIDTH	(3 << 0)
-#define DW_UART_CPR_AFCE_MODE		(1 << 4)
-#define DW_UART_CPR_THRE_MODE		(1 << 5)
-#define DW_UART_CPR_SIR_MODE		(1 << 6)
-#define DW_UART_CPR_SIR_LP_MODE		(1 << 7)
-#define DW_UART_CPR_ADDITIONAL_FEATURES	(1 << 8)
-#define DW_UART_CPR_FIFO_ACCESS		(1 << 9)
-#define DW_UART_CPR_FIFO_STAT		(1 << 10)
-#define DW_UART_CPR_SHADOW		(1 << 11)
-#define DW_UART_CPR_ENCODED_PARMS	(1 << 12)
-#define DW_UART_CPR_DMA_EXTRA		(1 << 13)
-#define DW_UART_CPR_FIFO_MODE		(0xff << 16)
+#define DW_UART_CPR_ABP_DATA_WIDTH	GENMASK(1, 0)
+#define DW_UART_CPR_AFCE_MODE		BIT(4)
+#define DW_UART_CPR_THRE_MODE		BIT(5)
+#define DW_UART_CPR_SIR_MODE		BIT(6)
+#define DW_UART_CPR_SIR_LP_MODE		BIT(7)
+#define DW_UART_CPR_ADDITIONAL_FEATURES	BIT(8)
+#define DW_UART_CPR_FIFO_ACCESS		BIT(9)
+#define DW_UART_CPR_FIFO_STAT		BIT(10)
+#define DW_UART_CPR_SHADOW		BIT(11)
+#define DW_UART_CPR_ENCODED_PARMS	BIT(12)
+#define DW_UART_CPR_DMA_EXTRA		BIT(13)
+#define DW_UART_CPR_FIFO_MODE		GENMASK(23, 16)
 
 /* Helper for FIFO size calculation */
-#define DW_UART_CPR_FIFO_SIZE(a)	(((a >> 16) & 0xff) * 16)
+#define DW_UART_CPR_FIFO_SIZE(a)	(FIELD_GET(DW_UART_CPR_FIFO_MODE, (a)) * 16)
 
 /*
  * divisor = div(I) + div(F)
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · Ilpo Järvinen

Instead of open-coding, use BIT(), GENMASK(), and FIELD_GET() helpers.

FIELD_GET() requires bitfield.h to be included. Is this the case already? If so,

Quoted 47 lines
---
 drivers/tty/serial/8250/8250_dwlib.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)
drivers/tty/serial/8250/8250_dwlib.c +13 -14
index da330ef46446..a8bbed74ea70 100644
@@ -46,21 +46,21 @@
 #define DW_UART_LCR_EXT_TRANSMIT_MODE  BIT(3)
 
 /* Component Parameter Register bits */
-#define DW_UART_CPR_ABP_DATA_WIDTH     (3 << 0)
-#define DW_UART_CPR_AFCE_MODE          (1 << 4)
-#define DW_UART_CPR_THRE_MODE          (1 << 5)
-#define DW_UART_CPR_SIR_MODE           (1 << 6)
-#define DW_UART_CPR_SIR_LP_MODE                (1 << 7)
-#define DW_UART_CPR_ADDITIONAL_FEATURES        (1 << 8)
-#define DW_UART_CPR_FIFO_ACCESS                (1 << 9)
-#define DW_UART_CPR_FIFO_STAT          (1 << 10)
-#define DW_UART_CPR_SHADOW             (1 << 11)
-#define DW_UART_CPR_ENCODED_PARMS      (1 << 12)
-#define DW_UART_CPR_DMA_EXTRA          (1 << 13)
-#define DW_UART_CPR_FIFO_MODE          (0xff << 16)
+#define DW_UART_CPR_ABP_DATA_WIDTH     GENMASK(1, 0)
+#define DW_UART_CPR_AFCE_MODE          BIT(4)
+#define DW_UART_CPR_THRE_MODE          BIT(5)
+#define DW_UART_CPR_SIR_MODE           BIT(6)
+#define DW_UART_CPR_SIR_LP_MODE                BIT(7)
+#define DW_UART_CPR_ADDITIONAL_FEATURES        BIT(8)
+#define DW_UART_CPR_FIFO_ACCESS                BIT(9)
+#define DW_UART_CPR_FIFO_STAT          BIT(10)
+#define DW_UART_CPR_SHADOW             BIT(11)
+#define DW_UART_CPR_ENCODED_PARMS      BIT(12)
+#define DW_UART_CPR_DMA_EXTRA          BIT(13)
+#define DW_UART_CPR_FIFO_MODE          GENMASK(23, 16)
 
 /* Helper for FIFO size calculation */
-#define DW_UART_CPR_FIFO_SIZE(a)       (((a >> 16) & 0xff) * 16)
+#define DW_UART_CPR_FIFO_SIZE(a)       (FIELD_GET(DW_UART_CPR_FIFO_MODE, (a)) * 16)
 
 /*
  * divisor = div(I) + div(F)
--

2.30.2

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#2 lore raw
Quoted 6 lines · Andy Shevchenko
Quoted 2 lines · Ilpo Järvinen

Instead of open-coding, use BIT(), GENMASK(), and FIELD_GET() helpers.

FIELD_GET() requires bitfield.h to be included. Is this the case already?

It's there already.

Signature · 1 line
 i.
Quoted 53 lines

If so,

Quoted 47 lines
---
 drivers/tty/serial/8250/8250_dwlib.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)
drivers/tty/serial/8250/8250_dwlib.c +13 -14
index da330ef46446..a8bbed74ea70 100644
@@ -46,21 +46,21 @@
 #define DW_UART_LCR_EXT_TRANSMIT_MODE  BIT(3)
 
 /* Component Parameter Register bits */
-#define DW_UART_CPR_ABP_DATA_WIDTH     (3 << 0)
-#define DW_UART_CPR_AFCE_MODE          (1 << 4)
-#define DW_UART_CPR_THRE_MODE          (1 << 5)
-#define DW_UART_CPR_SIR_MODE           (1 << 6)
-#define DW_UART_CPR_SIR_LP_MODE                (1 << 7)
-#define DW_UART_CPR_ADDITIONAL_FEATURES        (1 << 8)
-#define DW_UART_CPR_FIFO_ACCESS                (1 << 9)
-#define DW_UART_CPR_FIFO_STAT          (1 << 10)
-#define DW_UART_CPR_SHADOW             (1 << 11)
-#define DW_UART_CPR_ENCODED_PARMS      (1 << 12)
-#define DW_UART_CPR_DMA_EXTRA          (1 << 13)
-#define DW_UART_CPR_FIFO_MODE          (0xff << 16)
+#define DW_UART_CPR_ABP_DATA_WIDTH     GENMASK(1, 0)
+#define DW_UART_CPR_AFCE_MODE          BIT(4)
+#define DW_UART_CPR_THRE_MODE          BIT(5)
+#define DW_UART_CPR_SIR_MODE           BIT(6)
+#define DW_UART_CPR_SIR_LP_MODE                BIT(7)
+#define DW_UART_CPR_ADDITIONAL_FEATURES        BIT(8)
+#define DW_UART_CPR_FIFO_ACCESS                BIT(9)
+#define DW_UART_CPR_FIFO_STAT          BIT(10)
+#define DW_UART_CPR_SHADOW             BIT(11)
+#define DW_UART_CPR_ENCODED_PARMS      BIT(12)
+#define DW_UART_CPR_DMA_EXTRA          BIT(13)
+#define DW_UART_CPR_FIFO_MODE          GENMASK(23, 16)
 
 /* Helper for FIFO size calculation */
-#define DW_UART_CPR_FIFO_SIZE(a)       (((a >> 16) & 0xff) * 16)
+#define DW_UART_CPR_FIFO_SIZE(a)       (FIELD_GET(DW_UART_CPR_FIFO_MODE, (a)) * 16)
 
 /*
  * divisor = div(I) + div(F)
--

2.30.2