]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
serial: 8250_dw: build Renesas RZN1 CPR value from DW_UART_CPR_* definitions
authorJia Wang <wangjia@ultrarisc.com>
Wed, 29 Apr 2026 09:13:26 +0000 (17:13 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 11 May 2026 15:00:42 +0000 (17:00 +0200)
Replace the magic CPR value for Renesas RZ/N1 with a composition using
DW_UART_CPR_* bit/field definitions and FIELD_PREP_CONST().

Introduce a helper macro to convert a FIFO size (bytes) into the CPR
FIFO_MODE field value, with BUILD_BUG_ON_ZERO() checks for alignment and
bounds. Use it to replace the literal FIFO_MODE values in the RZN1.

Signed-off-by: Jia Wang <wangjia@ultrarisc.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Link: https://patch.msgid.link/20260429-ultrarisc-serial-v7-2-e475cce9e274@ultrarisc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/8250/8250_dw.c
drivers/tty/serial/8250/8250_dwlib.h

index 467755bf009271c903194c4f453e34041cc3a973..480f82d89856f9c99180cc25705370db481a2366 100644 (file)
@@ -937,7 +937,15 @@ static const struct dw8250_platform_data dw8250_armada_38x_data = {
 
 static const struct dw8250_platform_data dw8250_renesas_rzn1_data = {
        .usr_reg = DW_UART_USR,
-       .cpr_value = 0x00012f32,
+       .cpr_value = FIELD_PREP_CONST(DW_UART_CPR_ABP_DATA_WIDTH, 2) |
+                    DW_UART_CPR_AFCE_MODE |
+                    DW_UART_CPR_THRE_MODE |
+                    DW_UART_CPR_ADDITIONAL_FEATURES |
+                    DW_UART_CPR_FIFO_ACCESS |
+                    DW_UART_CPR_FIFO_STAT |
+                    DW_UART_CPR_SHADOW |
+                    DW_UART_CPR_DMA_EXTRA |
+                    DW_UART_CPR_FIFO_MODE_FROM_SIZE(16),
        .quirks = DW_UART_QUIRK_CPR_VALUE | DW_UART_QUIRK_IS_DMA_FC,
 };
 
index 2f26f9ecacbec4718cee13afa17da76119dcda80..1fe52332e774b2fcb52354e1e5f76d5b637ed72b 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <linux/bitfield.h>
 #include <linux/bits.h>
+#include <linux/build_bug.h>
 #include <linux/io.h>
 #include <linux/types.h>
 
 #define DW_UART_CPR_DMA_EXTRA          BIT(13)
 #define DW_UART_CPR_FIFO_MODE          GENMASK(23, 16)
 
-/* Helper for FIFO size calculation */
+/* Helpers for FIFO size calculation */
 #define DW_UART_CPR_FIFO_SIZE(a)       (FIELD_GET(DW_UART_CPR_FIFO_MODE, (a)) * 16)
+#define DW_UART_CPR_FIFO_MODE_FROM_SIZE(size)                  \
+       (FIELD_PREP_CONST(DW_UART_CPR_FIFO_MODE,                \
+                         BUILD_BUG_ON_ZERO((size) > 2048) +    \
+                         BUILD_BUG_ON_ZERO((size) % 16) +      \
+                         ((size) / 16)))
 
 struct dw8250_port_data {
        /* Port properties */