* [PATCH v4 1/3] PCI: dw-rockchip: Remove unused PCIE_CLIENT_GENERAL_DEBUG
2025-04-27 12:53 [PATCH v4 0/3] PCI: dw-rockchip: Reorganize register and bitfield definitions Hans Zhang
@ 2025-04-27 12:53 ` Hans Zhang
2025-04-27 12:53 ` [PATCH v4 2/3] PCI: dw-rockchip: Reorganize register and bitfield definitions Hans Zhang
` (2 subsequent siblings)
3 siblings, 0 replies; 9+ messages in thread
From: Hans Zhang @ 2025-04-27 12:53 UTC (permalink / raw)
To: lpieralisi, kw, bhelgaas, heiko
Cc: manivannan.sadhasivam, robh, jingoohan1, shawn.lin, linux-pci,
linux-kernel, linux-arm-kernel, linux-rockchip, Hans Zhang,
Niklas Cassel
The PCIE_CLIENT_GENERAL_DEBUG register offset is defined but never
used in the driver. Its presence adds noise to the register map and
may mislead future developers.
Remove this redundant definition to keep the register list minimal
and aligned with actual hardware usage.
Signed-off-by: Hans Zhang <18255117159@163.com>
Reviewed-by: Niklas Cassel <cassel@kernel.org>
Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---
drivers/pci/controller/dwc/pcie-dw-rockchip.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/drivers/pci/controller/dwc/pcie-dw-rockchip.c b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
index 7790a9f33e48..e7d33d545d5b 100644
--- a/drivers/pci/controller/dwc/pcie-dw-rockchip.c
+++ b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
@@ -47,7 +47,6 @@
#define PCIE_CLIENT_GENERAL_CONTROL 0x0
#define PCIE_CLIENT_INTR_STATUS_LEGACY 0x8
#define PCIE_CLIENT_INTR_MASK_LEGACY 0x1c
-#define PCIE_CLIENT_GENERAL_DEBUG 0x104
#define PCIE_CLIENT_HOT_RESET_CTRL 0x180
#define PCIE_CLIENT_LTSSM_STATUS 0x300
#define PCIE_LTSSM_ENABLE_ENHANCE BIT(4)
--
2.25.1
_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v4 2/3] PCI: dw-rockchip: Reorganize register and bitfield definitions
2025-04-27 12:53 [PATCH v4 0/3] PCI: dw-rockchip: Reorganize register and bitfield definitions Hans Zhang
2025-04-27 12:53 ` [PATCH v4 1/3] PCI: dw-rockchip: Remove unused PCIE_CLIENT_GENERAL_DEBUG Hans Zhang
@ 2025-04-27 12:53 ` Hans Zhang
2025-04-27 14:14 ` Manivannan Sadhasivam
2025-04-28 3:28 ` Wilfred Mallawa
2025-04-27 12:53 ` [PATCH v4 3/3] PCI: dw-rockchip: Unify link status checks with FIELD_GET Hans Zhang
2025-04-27 15:17 ` [PATCH v4 0/3] PCI: dw-rockchip: Reorganize register and bitfield definitions Manivannan Sadhasivam
3 siblings, 2 replies; 9+ messages in thread
From: Hans Zhang @ 2025-04-27 12:53 UTC (permalink / raw)
To: lpieralisi, kw, bhelgaas, heiko
Cc: manivannan.sadhasivam, robh, jingoohan1, shawn.lin, linux-pci,
linux-kernel, linux-arm-kernel, linux-rockchip, Hans Zhang,
Niklas Cassel
Register definitions were scattered with ambiguous names (e.g.,
PCIE_RDLH_LINK_UP_CHGED in PCIE_CLIENT_INTR_STATUS_MISC) and lacked
hierarchical grouping. Magic values for bit operations reduced code
clarity.
Group registers and their associated bitfields logically. This improves
maintainability and aligns the code with hardware documentation.
Signed-off-by: Hans Zhang <18255117159@163.com>
Reviewed-by: Niklas Cassel <cassel@kernel.org>
Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---
drivers/pci/controller/dwc/pcie-dw-rockchip.c | 49 ++++++++++++-------
1 file changed, 31 insertions(+), 18 deletions(-)
diff --git a/drivers/pci/controller/dwc/pcie-dw-rockchip.c b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
index e7d33d545d5b..a778f4f61595 100644
--- a/drivers/pci/controller/dwc/pcie-dw-rockchip.c
+++ b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
@@ -33,24 +33,37 @@
#define to_rockchip_pcie(x) dev_get_drvdata((x)->dev)
-#define PCIE_CLIENT_RC_MODE HIWORD_UPDATE_BIT(0x40)
-#define PCIE_CLIENT_EP_MODE HIWORD_UPDATE(0xf0, 0x0)
-#define PCIE_CLIENT_ENABLE_LTSSM HIWORD_UPDATE_BIT(0xc)
-#define PCIE_CLIENT_DISABLE_LTSSM HIWORD_UPDATE(0x0c, 0x8)
-#define PCIE_CLIENT_INTR_STATUS_MISC 0x10
-#define PCIE_CLIENT_INTR_MASK_MISC 0x24
-#define PCIE_SMLH_LINKUP BIT(16)
-#define PCIE_RDLH_LINKUP BIT(17)
-#define PCIE_LINKUP (PCIE_SMLH_LINKUP | PCIE_RDLH_LINKUP)
-#define PCIE_RDLH_LINK_UP_CHGED BIT(1)
-#define PCIE_LINK_REQ_RST_NOT_INT BIT(2)
-#define PCIE_CLIENT_GENERAL_CONTROL 0x0
+/* General Control Register */
+#define PCIE_CLIENT_GENERAL_CON 0x0
+#define PCIE_CLIENT_RC_MODE HIWORD_UPDATE_BIT(0x40)
+#define PCIE_CLIENT_EP_MODE HIWORD_UPDATE(0xf0, 0x0)
+#define PCIE_CLIENT_ENABLE_LTSSM HIWORD_UPDATE_BIT(0xc)
+#define PCIE_CLIENT_DISABLE_LTSSM HIWORD_UPDATE(0x0c, 0x8)
+
+/* Interrupt Status Register Related to Legacy Interrupt */
#define PCIE_CLIENT_INTR_STATUS_LEGACY 0x8
+
+/* Interrupt Status Register Related to Miscellaneous Operation */
+#define PCIE_CLIENT_INTR_STATUS_MISC 0x10
+#define PCIE_RDLH_LINK_UP_CHGED BIT(1)
+#define PCIE_LINK_REQ_RST_NOT_INT BIT(2)
+
+/* Interrupt Mask Register Related to Legacy Interrupt */
#define PCIE_CLIENT_INTR_MASK_LEGACY 0x1c
+
+/* Interrupt Mask Register Related to Miscellaneous Operation */
+#define PCIE_CLIENT_INTR_MASK_MISC 0x24
+
+/* Hot Reset Control Register */
#define PCIE_CLIENT_HOT_RESET_CTRL 0x180
+#define PCIE_LTSSM_ENABLE_ENHANCE BIT(4)
+
+/* LTSSM Status Register */
#define PCIE_CLIENT_LTSSM_STATUS 0x300
-#define PCIE_LTSSM_ENABLE_ENHANCE BIT(4)
-#define PCIE_LTSSM_STATUS_MASK GENMASK(5, 0)
+#define PCIE_SMLH_LINKUP BIT(16)
+#define PCIE_RDLH_LINKUP BIT(17)
+#define PCIE_LINKUP (PCIE_SMLH_LINKUP | PCIE_RDLH_LINKUP)
+#define PCIE_LTSSM_STATUS_MASK GENMASK(5, 0)
struct rockchip_pcie {
struct dw_pcie pci;
@@ -161,13 +174,13 @@ static u32 rockchip_pcie_get_ltssm(struct rockchip_pcie *rockchip)
static void rockchip_pcie_enable_ltssm(struct rockchip_pcie *rockchip)
{
rockchip_pcie_writel_apb(rockchip, PCIE_CLIENT_ENABLE_LTSSM,
- PCIE_CLIENT_GENERAL_CONTROL);
+ PCIE_CLIENT_GENERAL_CON);
}
static void rockchip_pcie_disable_ltssm(struct rockchip_pcie *rockchip)
{
rockchip_pcie_writel_apb(rockchip, PCIE_CLIENT_DISABLE_LTSSM,
- PCIE_CLIENT_GENERAL_CONTROL);
+ PCIE_CLIENT_GENERAL_CON);
}
static int rockchip_pcie_link_up(struct dw_pcie *pci)
@@ -516,7 +529,7 @@ static int rockchip_pcie_configure_rc(struct platform_device *pdev,
rockchip_pcie_writel_apb(rockchip, val, PCIE_CLIENT_HOT_RESET_CTRL);
rockchip_pcie_writel_apb(rockchip, PCIE_CLIENT_RC_MODE,
- PCIE_CLIENT_GENERAL_CONTROL);
+ PCIE_CLIENT_GENERAL_CON);
pp = &rockchip->pci.pp;
pp->ops = &rockchip_pcie_host_ops;
@@ -562,7 +575,7 @@ static int rockchip_pcie_configure_ep(struct platform_device *pdev,
rockchip_pcie_writel_apb(rockchip, val, PCIE_CLIENT_HOT_RESET_CTRL);
rockchip_pcie_writel_apb(rockchip, PCIE_CLIENT_EP_MODE,
- PCIE_CLIENT_GENERAL_CONTROL);
+ PCIE_CLIENT_GENERAL_CON);
rockchip->pci.ep.ops = &rockchip_pcie_ep_ops;
rockchip->pci.ep.page_size = SZ_64K;
--
2.25.1
_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH v4 2/3] PCI: dw-rockchip: Reorganize register and bitfield definitions
2025-04-27 12:53 ` [PATCH v4 2/3] PCI: dw-rockchip: Reorganize register and bitfield definitions Hans Zhang
@ 2025-04-27 14:14 ` Manivannan Sadhasivam
2025-04-27 14:26 ` Hans Zhang
2025-04-28 3:28 ` Wilfred Mallawa
1 sibling, 1 reply; 9+ messages in thread
From: Manivannan Sadhasivam @ 2025-04-27 14:14 UTC (permalink / raw)
To: Hans Zhang
Cc: lpieralisi, kw, bhelgaas, heiko, robh, jingoohan1, shawn.lin,
linux-pci, linux-kernel, linux-arm-kernel, linux-rockchip,
Niklas Cassel
On Sun, Apr 27, 2025 at 08:53:15PM +0800, Hans Zhang wrote:
> Register definitions were scattered with ambiguous names (e.g.,
> PCIE_RDLH_LINK_UP_CHGED in PCIE_CLIENT_INTR_STATUS_MISC) and lacked
> hierarchical grouping. Magic values for bit operations reduced code
> clarity.
>
> Group registers and their associated bitfields logically. This improves
> maintainability and aligns the code with hardware documentation.
>
> Signed-off-by: Hans Zhang <18255117159@163.com>
> Reviewed-by: Niklas Cassel <cassel@kernel.org>
> Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> ---
> drivers/pci/controller/dwc/pcie-dw-rockchip.c | 49 ++++++++++++-------
> 1 file changed, 31 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/pci/controller/dwc/pcie-dw-rockchip.c b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
> index e7d33d545d5b..a778f4f61595 100644
> --- a/drivers/pci/controller/dwc/pcie-dw-rockchip.c
> +++ b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
> @@ -33,24 +33,37 @@
>
> #define to_rockchip_pcie(x) dev_get_drvdata((x)->dev)
>
> -#define PCIE_CLIENT_RC_MODE HIWORD_UPDATE_BIT(0x40)
> -#define PCIE_CLIENT_EP_MODE HIWORD_UPDATE(0xf0, 0x0)
> -#define PCIE_CLIENT_ENABLE_LTSSM HIWORD_UPDATE_BIT(0xc)
> -#define PCIE_CLIENT_DISABLE_LTSSM HIWORD_UPDATE(0x0c, 0x8)
> -#define PCIE_CLIENT_INTR_STATUS_MISC 0x10
> -#define PCIE_CLIENT_INTR_MASK_MISC 0x24
> -#define PCIE_SMLH_LINKUP BIT(16)
> -#define PCIE_RDLH_LINKUP BIT(17)
> -#define PCIE_LINKUP (PCIE_SMLH_LINKUP | PCIE_RDLH_LINKUP)
> -#define PCIE_RDLH_LINK_UP_CHGED BIT(1)
> -#define PCIE_LINK_REQ_RST_NOT_INT BIT(2)
> -#define PCIE_CLIENT_GENERAL_CONTROL 0x0
> +/* General Control Register */
> +#define PCIE_CLIENT_GENERAL_CON 0x0
Is this the actual name of the register as per the documentation? Just asking
because of '_CON' instead of '_CONTROL'.
- Mani
> +#define PCIE_CLIENT_RC_MODE HIWORD_UPDATE_BIT(0x40)
> +#define PCIE_CLIENT_EP_MODE HIWORD_UPDATE(0xf0, 0x0)
> +#define PCIE_CLIENT_ENABLE_LTSSM HIWORD_UPDATE_BIT(0xc)
> +#define PCIE_CLIENT_DISABLE_LTSSM HIWORD_UPDATE(0x0c, 0x8)
> +
> +/* Interrupt Status Register Related to Legacy Interrupt */
> #define PCIE_CLIENT_INTR_STATUS_LEGACY 0x8
> +
> +/* Interrupt Status Register Related to Miscellaneous Operation */
> +#define PCIE_CLIENT_INTR_STATUS_MISC 0x10
> +#define PCIE_RDLH_LINK_UP_CHGED BIT(1)
> +#define PCIE_LINK_REQ_RST_NOT_INT BIT(2)
> +
> +/* Interrupt Mask Register Related to Legacy Interrupt */
> #define PCIE_CLIENT_INTR_MASK_LEGACY 0x1c
> +
> +/* Interrupt Mask Register Related to Miscellaneous Operation */
> +#define PCIE_CLIENT_INTR_MASK_MISC 0x24
> +
> +/* Hot Reset Control Register */
> #define PCIE_CLIENT_HOT_RESET_CTRL 0x180
> +#define PCIE_LTSSM_ENABLE_ENHANCE BIT(4)
> +
> +/* LTSSM Status Register */
> #define PCIE_CLIENT_LTSSM_STATUS 0x300
> -#define PCIE_LTSSM_ENABLE_ENHANCE BIT(4)
> -#define PCIE_LTSSM_STATUS_MASK GENMASK(5, 0)
> +#define PCIE_SMLH_LINKUP BIT(16)
> +#define PCIE_RDLH_LINKUP BIT(17)
> +#define PCIE_LINKUP (PCIE_SMLH_LINKUP | PCIE_RDLH_LINKUP)
> +#define PCIE_LTSSM_STATUS_MASK GENMASK(5, 0)
>
> struct rockchip_pcie {
> struct dw_pcie pci;
> @@ -161,13 +174,13 @@ static u32 rockchip_pcie_get_ltssm(struct rockchip_pcie *rockchip)
> static void rockchip_pcie_enable_ltssm(struct rockchip_pcie *rockchip)
> {
> rockchip_pcie_writel_apb(rockchip, PCIE_CLIENT_ENABLE_LTSSM,
> - PCIE_CLIENT_GENERAL_CONTROL);
> + PCIE_CLIENT_GENERAL_CON);
> }
>
> static void rockchip_pcie_disable_ltssm(struct rockchip_pcie *rockchip)
> {
> rockchip_pcie_writel_apb(rockchip, PCIE_CLIENT_DISABLE_LTSSM,
> - PCIE_CLIENT_GENERAL_CONTROL);
> + PCIE_CLIENT_GENERAL_CON);
> }
>
> static int rockchip_pcie_link_up(struct dw_pcie *pci)
> @@ -516,7 +529,7 @@ static int rockchip_pcie_configure_rc(struct platform_device *pdev,
> rockchip_pcie_writel_apb(rockchip, val, PCIE_CLIENT_HOT_RESET_CTRL);
>
> rockchip_pcie_writel_apb(rockchip, PCIE_CLIENT_RC_MODE,
> - PCIE_CLIENT_GENERAL_CONTROL);
> + PCIE_CLIENT_GENERAL_CON);
>
> pp = &rockchip->pci.pp;
> pp->ops = &rockchip_pcie_host_ops;
> @@ -562,7 +575,7 @@ static int rockchip_pcie_configure_ep(struct platform_device *pdev,
> rockchip_pcie_writel_apb(rockchip, val, PCIE_CLIENT_HOT_RESET_CTRL);
>
> rockchip_pcie_writel_apb(rockchip, PCIE_CLIENT_EP_MODE,
> - PCIE_CLIENT_GENERAL_CONTROL);
> + PCIE_CLIENT_GENERAL_CON);
>
> rockchip->pci.ep.ops = &rockchip_pcie_ep_ops;
> rockchip->pci.ep.page_size = SZ_64K;
> --
> 2.25.1
>
--
மணிவண்ணன் சதாசிவம்
_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH v4 2/3] PCI: dw-rockchip: Reorganize register and bitfield definitions
2025-04-27 14:14 ` Manivannan Sadhasivam
@ 2025-04-27 14:26 ` Hans Zhang
0 siblings, 0 replies; 9+ messages in thread
From: Hans Zhang @ 2025-04-27 14:26 UTC (permalink / raw)
To: Manivannan Sadhasivam
Cc: lpieralisi, kw, bhelgaas, heiko, robh, jingoohan1, shawn.lin,
linux-pci, linux-kernel, linux-arm-kernel, linux-rockchip,
Niklas Cassel
On 2025/4/27 22:14, Manivannan Sadhasivam wrote:
> On Sun, Apr 27, 2025 at 08:53:15PM +0800, Hans Zhang wrote:
>> Register definitions were scattered with ambiguous names (e.g.,
>> PCIE_RDLH_LINK_UP_CHGED in PCIE_CLIENT_INTR_STATUS_MISC) and lacked
>> hierarchical grouping. Magic values for bit operations reduced code
>> clarity.
>>
>> Group registers and their associated bitfields logically. This improves
>> maintainability and aligns the code with hardware documentation.
>>
>> Signed-off-by: Hans Zhang <18255117159@163.com>
>> Reviewed-by: Niklas Cassel <cassel@kernel.org>
>> Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
>> ---
>> drivers/pci/controller/dwc/pcie-dw-rockchip.c | 49 ++++++++++++-------
>> 1 file changed, 31 insertions(+), 18 deletions(-)
>>
>> diff --git a/drivers/pci/controller/dwc/pcie-dw-rockchip.c b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
>> index e7d33d545d5b..a778f4f61595 100644
>> --- a/drivers/pci/controller/dwc/pcie-dw-rockchip.c
>> +++ b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
>> @@ -33,24 +33,37 @@
>>
>> #define to_rockchip_pcie(x) dev_get_drvdata((x)->dev)
>>
>> -#define PCIE_CLIENT_RC_MODE HIWORD_UPDATE_BIT(0x40)
>> -#define PCIE_CLIENT_EP_MODE HIWORD_UPDATE(0xf0, 0x0)
>> -#define PCIE_CLIENT_ENABLE_LTSSM HIWORD_UPDATE_BIT(0xc)
>> -#define PCIE_CLIENT_DISABLE_LTSSM HIWORD_UPDATE(0x0c, 0x8)
>> -#define PCIE_CLIENT_INTR_STATUS_MISC 0x10
>> -#define PCIE_CLIENT_INTR_MASK_MISC 0x24
>> -#define PCIE_SMLH_LINKUP BIT(16)
>> -#define PCIE_RDLH_LINKUP BIT(17)
>> -#define PCIE_LINKUP (PCIE_SMLH_LINKUP | PCIE_RDLH_LINKUP)
>> -#define PCIE_RDLH_LINK_UP_CHGED BIT(1)
>> -#define PCIE_LINK_REQ_RST_NOT_INT BIT(2)
>> -#define PCIE_CLIENT_GENERAL_CONTROL 0x0
>> +/* General Control Register */
>> +#define PCIE_CLIENT_GENERAL_CON 0x0
>
> Is this the actual name of the register as per the documentation? Just asking
> because of '_CON' instead of '_CONTROL'.
>
Hi Mani,
Yes. I saw that RK3588 TRM is named like this.
PCIE_CLIENT_GENERAL_CON
Best regards,
Hans
> - Mani
>
>> +#define PCIE_CLIENT_RC_MODE HIWORD_UPDATE_BIT(0x40)
>> +#define PCIE_CLIENT_EP_MODE HIWORD_UPDATE(0xf0, 0x0)
>> +#define PCIE_CLIENT_ENABLE_LTSSM HIWORD_UPDATE_BIT(0xc)
>> +#define PCIE_CLIENT_DISABLE_LTSSM HIWORD_UPDATE(0x0c, 0x8)
>> +
>> +/* Interrupt Status Register Related to Legacy Interrupt */
>> #define PCIE_CLIENT_INTR_STATUS_LEGACY 0x8
>> +
>> +/* Interrupt Status Register Related to Miscellaneous Operation */
>> +#define PCIE_CLIENT_INTR_STATUS_MISC 0x10
>> +#define PCIE_RDLH_LINK_UP_CHGED BIT(1)
>> +#define PCIE_LINK_REQ_RST_NOT_INT BIT(2)
>> +
>> +/* Interrupt Mask Register Related to Legacy Interrupt */
>> #define PCIE_CLIENT_INTR_MASK_LEGACY 0x1c
>> +
>> +/* Interrupt Mask Register Related to Miscellaneous Operation */
>> +#define PCIE_CLIENT_INTR_MASK_MISC 0x24
>> +
>> +/* Hot Reset Control Register */
>> #define PCIE_CLIENT_HOT_RESET_CTRL 0x180
>> +#define PCIE_LTSSM_ENABLE_ENHANCE BIT(4)
>> +
>> +/* LTSSM Status Register */
>> #define PCIE_CLIENT_LTSSM_STATUS 0x300
>> -#define PCIE_LTSSM_ENABLE_ENHANCE BIT(4)
>> -#define PCIE_LTSSM_STATUS_MASK GENMASK(5, 0)
>> +#define PCIE_SMLH_LINKUP BIT(16)
>> +#define PCIE_RDLH_LINKUP BIT(17)
>> +#define PCIE_LINKUP (PCIE_SMLH_LINKUP | PCIE_RDLH_LINKUP)
>> +#define PCIE_LTSSM_STATUS_MASK GENMASK(5, 0)
>>
>> struct rockchip_pcie {
>> struct dw_pcie pci;
>> @@ -161,13 +174,13 @@ static u32 rockchip_pcie_get_ltssm(struct rockchip_pcie *rockchip)
>> static void rockchip_pcie_enable_ltssm(struct rockchip_pcie *rockchip)
>> {
>> rockchip_pcie_writel_apb(rockchip, PCIE_CLIENT_ENABLE_LTSSM,
>> - PCIE_CLIENT_GENERAL_CONTROL);
>> + PCIE_CLIENT_GENERAL_CON);
>> }
>>
>> static void rockchip_pcie_disable_ltssm(struct rockchip_pcie *rockchip)
>> {
>> rockchip_pcie_writel_apb(rockchip, PCIE_CLIENT_DISABLE_LTSSM,
>> - PCIE_CLIENT_GENERAL_CONTROL);
>> + PCIE_CLIENT_GENERAL_CON);
>> }
>>
>> static int rockchip_pcie_link_up(struct dw_pcie *pci)
>> @@ -516,7 +529,7 @@ static int rockchip_pcie_configure_rc(struct platform_device *pdev,
>> rockchip_pcie_writel_apb(rockchip, val, PCIE_CLIENT_HOT_RESET_CTRL);
>>
>> rockchip_pcie_writel_apb(rockchip, PCIE_CLIENT_RC_MODE,
>> - PCIE_CLIENT_GENERAL_CONTROL);
>> + PCIE_CLIENT_GENERAL_CON);
>>
>> pp = &rockchip->pci.pp;
>> pp->ops = &rockchip_pcie_host_ops;
>> @@ -562,7 +575,7 @@ static int rockchip_pcie_configure_ep(struct platform_device *pdev,
>> rockchip_pcie_writel_apb(rockchip, val, PCIE_CLIENT_HOT_RESET_CTRL);
>>
>> rockchip_pcie_writel_apb(rockchip, PCIE_CLIENT_EP_MODE,
>> - PCIE_CLIENT_GENERAL_CONTROL);
>> + PCIE_CLIENT_GENERAL_CON);
>>
>> rockchip->pci.ep.ops = &rockchip_pcie_ep_ops;
>> rockchip->pci.ep.page_size = SZ_64K;
>> --
>> 2.25.1
>>
>
_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v4 2/3] PCI: dw-rockchip: Reorganize register and bitfield definitions
2025-04-27 12:53 ` [PATCH v4 2/3] PCI: dw-rockchip: Reorganize register and bitfield definitions Hans Zhang
2025-04-27 14:14 ` Manivannan Sadhasivam
@ 2025-04-28 3:28 ` Wilfred Mallawa
1 sibling, 0 replies; 9+ messages in thread
From: Wilfred Mallawa @ 2025-04-28 3:28 UTC (permalink / raw)
To: Hans Zhang, lpieralisi, kw, bhelgaas, heiko
Cc: manivannan.sadhasivam, robh, jingoohan1, shawn.lin, linux-pci,
linux-kernel, linux-arm-kernel, linux-rockchip, Niklas Cassel
On Sun, 2025-04-27 at 20:53 +0800, Hans Zhang wrote:
> Register definitions were scattered with ambiguous names (e.g.,
> PCIE_RDLH_LINK_UP_CHGED in PCIE_CLIENT_INTR_STATUS_MISC) and lacked
> hierarchical grouping. Magic values for bit operations reduced code
> clarity.
>
> Group registers and their associated bitfields logically. This
> improves
> maintainability and aligns the code with hardware documentation.
>
> Signed-off-by: Hans Zhang <18255117159@163.com>
> Reviewed-by: Niklas Cassel <cassel@kernel.org>
> Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> ---
> drivers/pci/controller/dwc/pcie-dw-rockchip.c | 49 ++++++++++++-----
> --
> 1 file changed, 31 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/pci/controller/dwc/pcie-dw-rockchip.c
> b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
> index e7d33d545d5b..a778f4f61595 100644
> --- a/drivers/pci/controller/dwc/pcie-dw-rockchip.c
> +++ b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
> @@ -33,24 +33,37 @@
>
> #define to_rockchip_pcie(x) dev_get_drvdata((x)->dev)
>
> -#define PCIE_CLIENT_RC_MODE HIWORD_UPDATE_BIT(0x40)
> -#define PCIE_CLIENT_EP_MODE HIWORD_UPDATE(0xf0, 0x0)
> -#define PCIE_CLIENT_ENABLE_LTSSM HIWORD_UPDATE_BIT(0xc)
> -#define PCIE_CLIENT_DISABLE_LTSSM HIWORD_UPDATE(0x0c, 0x8)
> -#define PCIE_CLIENT_INTR_STATUS_MISC 0x10
> -#define PCIE_CLIENT_INTR_MASK_MISC 0x24
> -#define PCIE_SMLH_LINKUP BIT(16)
> -#define PCIE_RDLH_LINKUP BIT(17)
> -#define PCIE_LINKUP (PCIE_SMLH_LINKUP |
> PCIE_RDLH_LINKUP)
> -#define PCIE_RDLH_LINK_UP_CHGED BIT(1)
> -#define PCIE_LINK_REQ_RST_NOT_INT BIT(2)
> -#define PCIE_CLIENT_GENERAL_CONTROL 0x0
> +/* General Control Register */
> +#define PCIE_CLIENT_GENERAL_CON 0x0
> +#define PCIE_CLIENT_RC_MODE HIWORD_UPDATE_BIT(0x40)
> +#define PCIE_CLIENT_EP_MODE HIWORD_UPDATE(0xf0, 0x0)
> +#define PCIE_CLIENT_ENABLE_LTSSM HIWORD_UPDATE_BIT(0xc)
> +#define PCIE_CLIENT_DISABLE_LTSSM HIWORD_UPDATE(0x0c, 0x8)
> +
> +/* Interrupt Status Register Related to Legacy Interrupt */
> #define PCIE_CLIENT_INTR_STATUS_LEGACY 0x8
> +
> +/* Interrupt Status Register Related to Miscellaneous Operation */
> +#define PCIE_CLIENT_INTR_STATUS_MISC 0x10
> +#define PCIE_RDLH_LINK_UP_CHGED BIT(1)
> +#define PCIE_LINK_REQ_RST_NOT_INT BIT(2)
> +
> +/* Interrupt Mask Register Related to Legacy Interrupt */
> #define PCIE_CLIENT_INTR_MASK_LEGACY 0x1c
> +
> +/* Interrupt Mask Register Related to Miscellaneous Operation */
> +#define PCIE_CLIENT_INTR_MASK_MISC 0x24
> +
> +/* Hot Reset Control Register */
> #define PCIE_CLIENT_HOT_RESET_CTRL 0x180
> +#define PCIE_LTSSM_ENABLE_ENHANCE BIT(4)
> +
> +/* LTSSM Status Register */
> #define PCIE_CLIENT_LTSSM_STATUS 0x300
> -#define PCIE_LTSSM_ENABLE_ENHANCE BIT(4)
> -#define PCIE_LTSSM_STATUS_MASK GENMASK(5, 0)
> +#define PCIE_SMLH_LINKUP BIT(16)
> +#define PCIE_RDLH_LINKUP BIT(17)
> +#define PCIE_LINKUP (PCIE_SMLH_LINKUP |
> PCIE_RDLH_LINKUP)
> +#define PCIE_LTSSM_STATUS_MASK GENMASK(5, 0)
>
> struct rockchip_pcie {
> struct dw_pcie pci;
> @@ -161,13 +174,13 @@ static u32 rockchip_pcie_get_ltssm(struct
> rockchip_pcie *rockchip)
> static void rockchip_pcie_enable_ltssm(struct rockchip_pcie
> *rockchip)
> {
> rockchip_pcie_writel_apb(rockchip, PCIE_CLIENT_ENABLE_LTSSM,
> - PCIE_CLIENT_GENERAL_CONTROL);
> + PCIE_CLIENT_GENERAL_CON);
> }
>
> static void rockchip_pcie_disable_ltssm(struct rockchip_pcie
> *rockchip)
> {
> rockchip_pcie_writel_apb(rockchip,
> PCIE_CLIENT_DISABLE_LTSSM,
> - PCIE_CLIENT_GENERAL_CONTROL);
> + PCIE_CLIENT_GENERAL_CON);
> }
>
> static int rockchip_pcie_link_up(struct dw_pcie *pci)
> @@ -516,7 +529,7 @@ static int rockchip_pcie_configure_rc(struct
> platform_device *pdev,
> rockchip_pcie_writel_apb(rockchip, val,
> PCIE_CLIENT_HOT_RESET_CTRL);
>
> rockchip_pcie_writel_apb(rockchip, PCIE_CLIENT_RC_MODE,
> - PCIE_CLIENT_GENERAL_CONTROL);
> + PCIE_CLIENT_GENERAL_CON);
>
> pp = &rockchip->pci.pp;
> pp->ops = &rockchip_pcie_host_ops;
> @@ -562,7 +575,7 @@ static int rockchip_pcie_configure_ep(struct
> platform_device *pdev,
> rockchip_pcie_writel_apb(rockchip, val,
> PCIE_CLIENT_HOT_RESET_CTRL);
>
> rockchip_pcie_writel_apb(rockchip, PCIE_CLIENT_EP_MODE,
> - PCIE_CLIENT_GENERAL_CONTROL);
> + PCIE_CLIENT_GENERAL_CON);
>
> rockchip->pci.ep.ops = &rockchip_pcie_ep_ops;
> rockchip->pci.ep.page_size = SZ_64K;
Reviewed-by: Wilfred Mallawa <wilfred.mallawa@wdc.com>
_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v4 3/3] PCI: dw-rockchip: Unify link status checks with FIELD_GET
2025-04-27 12:53 [PATCH v4 0/3] PCI: dw-rockchip: Reorganize register and bitfield definitions Hans Zhang
2025-04-27 12:53 ` [PATCH v4 1/3] PCI: dw-rockchip: Remove unused PCIE_CLIENT_GENERAL_DEBUG Hans Zhang
2025-04-27 12:53 ` [PATCH v4 2/3] PCI: dw-rockchip: Reorganize register and bitfield definitions Hans Zhang
@ 2025-04-27 12:53 ` Hans Zhang
2025-04-28 3:26 ` Wilfred Mallawa
2025-04-27 15:17 ` [PATCH v4 0/3] PCI: dw-rockchip: Reorganize register and bitfield definitions Manivannan Sadhasivam
3 siblings, 1 reply; 9+ messages in thread
From: Hans Zhang @ 2025-04-27 12:53 UTC (permalink / raw)
To: lpieralisi, kw, bhelgaas, heiko
Cc: manivannan.sadhasivam, robh, jingoohan1, shawn.lin, linux-pci,
linux-kernel, linux-arm-kernel, linux-rockchip, Hans Zhang,
Niklas Cassel
Link-up detection manually checked PCIE_LINKUP bits across RC/EP modes,
leading to code duplication. Centralize the logic using FIELD_GET. This
removes redundancy and abstracts hardware-specific bit masking, ensuring
consistent link state handling.
Signed-off-by: Hans Zhang <18255117159@163.com>
Reviewed-by: Niklas Cassel <cassel@kernel.org>
Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---
drivers/pci/controller/dwc/pcie-dw-rockchip.c | 21 +++++++------------
1 file changed, 8 insertions(+), 13 deletions(-)
diff --git a/drivers/pci/controller/dwc/pcie-dw-rockchip.c b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
index a778f4f61595..bfc47dab32e5 100644
--- a/drivers/pci/controller/dwc/pcie-dw-rockchip.c
+++ b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
@@ -8,6 +8,7 @@
* Author: Simon Xue <xxm@rock-chips.com>
*/
+#include <linux/bitfield.h>
#include <linux/clk.h>
#include <linux/gpio/consumer.h>
#include <linux/irqchip/chained_irq.h>
@@ -60,9 +61,8 @@
/* LTSSM Status Register */
#define PCIE_CLIENT_LTSSM_STATUS 0x300
-#define PCIE_SMLH_LINKUP BIT(16)
-#define PCIE_RDLH_LINKUP BIT(17)
-#define PCIE_LINKUP (PCIE_SMLH_LINKUP | PCIE_RDLH_LINKUP)
+#define PCIE_LINKUP 0x3
+#define PCIE_LINKUP_MASK GENMASK(17, 16)
#define PCIE_LTSSM_STATUS_MASK GENMASK(5, 0)
struct rockchip_pcie {
@@ -188,10 +188,7 @@ static int rockchip_pcie_link_up(struct dw_pcie *pci)
struct rockchip_pcie *rockchip = to_rockchip_pcie(pci);
u32 val = rockchip_pcie_get_ltssm(rockchip);
- if ((val & PCIE_LINKUP) == PCIE_LINKUP)
- return 1;
-
- return 0;
+ return FIELD_GET(PCIE_LINKUP_MASK, val) == PCIE_LINKUP;
}
static void rockchip_pcie_enable_l0s(struct dw_pcie *pci)
@@ -450,7 +447,7 @@ static irqreturn_t rockchip_pcie_rc_sys_irq_thread(int irq, void *arg)
struct dw_pcie *pci = &rockchip->pci;
struct dw_pcie_rp *pp = &pci->pp;
struct device *dev = pci->dev;
- u32 reg, val;
+ u32 reg;
reg = rockchip_pcie_readl_apb(rockchip, PCIE_CLIENT_INTR_STATUS_MISC);
rockchip_pcie_writel_apb(rockchip, reg, PCIE_CLIENT_INTR_STATUS_MISC);
@@ -459,8 +456,7 @@ static irqreturn_t rockchip_pcie_rc_sys_irq_thread(int irq, void *arg)
dev_dbg(dev, "LTSSM_STATUS: %#x\n", rockchip_pcie_get_ltssm(rockchip));
if (reg & PCIE_RDLH_LINK_UP_CHGED) {
- val = rockchip_pcie_get_ltssm(rockchip);
- if ((val & PCIE_LINKUP) == PCIE_LINKUP) {
+ if (rockchip_pcie_link_up(pci)) {
dev_dbg(dev, "Received Link up event. Starting enumeration!\n");
/* Rescan the bus to enumerate endpoint devices */
pci_lock_rescan_remove();
@@ -477,7 +473,7 @@ static irqreturn_t rockchip_pcie_ep_sys_irq_thread(int irq, void *arg)
struct rockchip_pcie *rockchip = arg;
struct dw_pcie *pci = &rockchip->pci;
struct device *dev = pci->dev;
- u32 reg, val;
+ u32 reg;
reg = rockchip_pcie_readl_apb(rockchip, PCIE_CLIENT_INTR_STATUS_MISC);
rockchip_pcie_writel_apb(rockchip, reg, PCIE_CLIENT_INTR_STATUS_MISC);
@@ -491,8 +487,7 @@ static irqreturn_t rockchip_pcie_ep_sys_irq_thread(int irq, void *arg)
}
if (reg & PCIE_RDLH_LINK_UP_CHGED) {
- val = rockchip_pcie_get_ltssm(rockchip);
- if ((val & PCIE_LINKUP) == PCIE_LINKUP) {
+ if (rockchip_pcie_link_up(pci)) {
dev_dbg(dev, "link up\n");
dw_pcie_ep_linkup(&pci->ep);
}
--
2.25.1
_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH v4 3/3] PCI: dw-rockchip: Unify link status checks with FIELD_GET
2025-04-27 12:53 ` [PATCH v4 3/3] PCI: dw-rockchip: Unify link status checks with FIELD_GET Hans Zhang
@ 2025-04-28 3:26 ` Wilfred Mallawa
0 siblings, 0 replies; 9+ messages in thread
From: Wilfred Mallawa @ 2025-04-28 3:26 UTC (permalink / raw)
To: Hans Zhang, lpieralisi, kw, bhelgaas, heiko
Cc: manivannan.sadhasivam, robh, jingoohan1, shawn.lin, linux-pci,
linux-kernel, linux-arm-kernel, linux-rockchip, Niklas Cassel
On Sun, 2025-04-27 at 20:53 +0800, Hans Zhang wrote:
> Link-up detection manually checked PCIE_LINKUP bits across RC/EP
> modes,
> leading to code duplication. Centralize the logic using FIELD_GET.
> This
> removes redundancy and abstracts hardware-specific bit masking,
> ensuring
> consistent link state handling.
>
> Signed-off-by: Hans Zhang <18255117159@163.com>
> Reviewed-by: Niklas Cassel <cassel@kernel.org>
> Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> ---
> drivers/pci/controller/dwc/pcie-dw-rockchip.c | 21 +++++++----------
> --
> 1 file changed, 8 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/pci/controller/dwc/pcie-dw-rockchip.c
> b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
> index a778f4f61595..bfc47dab32e5 100644
> --- a/drivers/pci/controller/dwc/pcie-dw-rockchip.c
> +++ b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
> @@ -8,6 +8,7 @@
> * Author: Simon Xue <xxm@rock-chips.com>
> */
>
> +#include <linux/bitfield.h>
> #include <linux/clk.h>
> #include <linux/gpio/consumer.h>
> #include <linux/irqchip/chained_irq.h>
> @@ -60,9 +61,8 @@
>
> /* LTSSM Status Register */
> #define PCIE_CLIENT_LTSSM_STATUS 0x300
> -#define PCIE_SMLH_LINKUP BIT(16)
> -#define PCIE_RDLH_LINKUP BIT(17)
> -#define PCIE_LINKUP (PCIE_SMLH_LINKUP |
> PCIE_RDLH_LINKUP)
> +#define PCIE_LINKUP 0x3
> +#define PCIE_LINKUP_MASK GENMASK(17, 16)
> #define PCIE_LTSSM_STATUS_MASK GENMASK(5, 0)
>
> struct rockchip_pcie {
> @@ -188,10 +188,7 @@ static int rockchip_pcie_link_up(struct dw_pcie
> *pci)
> struct rockchip_pcie *rockchip = to_rockchip_pcie(pci);
> u32 val = rockchip_pcie_get_ltssm(rockchip);
>
> - if ((val & PCIE_LINKUP) == PCIE_LINKUP)
> - return 1;
> -
> - return 0;
> + return FIELD_GET(PCIE_LINKUP_MASK, val) == PCIE_LINKUP;
> }
>
> static void rockchip_pcie_enable_l0s(struct dw_pcie *pci)
> @@ -450,7 +447,7 @@ static irqreturn_t
> rockchip_pcie_rc_sys_irq_thread(int irq, void *arg)
> struct dw_pcie *pci = &rockchip->pci;
> struct dw_pcie_rp *pp = &pci->pp;
> struct device *dev = pci->dev;
> - u32 reg, val;
> + u32 reg;
>
> reg = rockchip_pcie_readl_apb(rockchip,
> PCIE_CLIENT_INTR_STATUS_MISC);
> rockchip_pcie_writel_apb(rockchip, reg,
> PCIE_CLIENT_INTR_STATUS_MISC);
> @@ -459,8 +456,7 @@ static irqreturn_t
> rockchip_pcie_rc_sys_irq_thread(int irq, void *arg)
> dev_dbg(dev, "LTSSM_STATUS: %#x\n",
> rockchip_pcie_get_ltssm(rockchip));
>
> if (reg & PCIE_RDLH_LINK_UP_CHGED) {
> - val = rockchip_pcie_get_ltssm(rockchip);
> - if ((val & PCIE_LINKUP) == PCIE_LINKUP) {
> + if (rockchip_pcie_link_up(pci)) {
> dev_dbg(dev, "Received Link up event.
> Starting enumeration!\n");
> /* Rescan the bus to enumerate endpoint
> devices */
> pci_lock_rescan_remove();
> @@ -477,7 +473,7 @@ static irqreturn_t
> rockchip_pcie_ep_sys_irq_thread(int irq, void *arg)
> struct rockchip_pcie *rockchip = arg;
> struct dw_pcie *pci = &rockchip->pci;
> struct device *dev = pci->dev;
> - u32 reg, val;
> + u32 reg;
>
> reg = rockchip_pcie_readl_apb(rockchip,
> PCIE_CLIENT_INTR_STATUS_MISC);
> rockchip_pcie_writel_apb(rockchip, reg,
> PCIE_CLIENT_INTR_STATUS_MISC);
> @@ -491,8 +487,7 @@ static irqreturn_t
> rockchip_pcie_ep_sys_irq_thread(int irq, void *arg)
> }
>
> if (reg & PCIE_RDLH_LINK_UP_CHGED) {
> - val = rockchip_pcie_get_ltssm(rockchip);
> - if ((val & PCIE_LINKUP) == PCIE_LINKUP) {
> + if (rockchip_pcie_link_up(pci)) {
> dev_dbg(dev, "link up\n");
> dw_pcie_ep_linkup(&pci->ep);
> }
Reviewed-by: Wilfred Mallawa <wilfred.mallawa@wdc.com>
_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v4 0/3] PCI: dw-rockchip: Reorganize register and bitfield definitions
2025-04-27 12:53 [PATCH v4 0/3] PCI: dw-rockchip: Reorganize register and bitfield definitions Hans Zhang
` (2 preceding siblings ...)
2025-04-27 12:53 ` [PATCH v4 3/3] PCI: dw-rockchip: Unify link status checks with FIELD_GET Hans Zhang
@ 2025-04-27 15:17 ` Manivannan Sadhasivam
3 siblings, 0 replies; 9+ messages in thread
From: Manivannan Sadhasivam @ 2025-04-27 15:17 UTC (permalink / raw)
To: lpieralisi, kw, bhelgaas, heiko, Hans Zhang
Cc: Manivannan Sadhasivam, robh, jingoohan1, shawn.lin, linux-pci,
linux-kernel, linux-arm-kernel, linux-rockchip
On Sun, 27 Apr 2025 20:53:13 +0800, Hans Zhang wrote:
> 1. PCI: dw-rockchip: Remove unused PCIE_CLIENT_GENERAL_DEBUG
> 2. PCI: dw-rockchip: Reorganize register and bitfield definitions
> 3. PCI: dw-rockchip: Unify link status checks with FIELD_GET
>
Applied, thanks!
[1/3] PCI: dw-rockchip: Remove unused PCIE_CLIENT_GENERAL_DEBUG
commit: c2f61b8479b2abcd9e20f8bd4c46e54bb7f5286f
[2/3] PCI: dw-rockchip: Reorganize register and bitfield definitions
commit: ae8ed2b091ee8bd92da365d3332eebf159de8e0f
[3/3] PCI: dw-rockchip: Unify link status checks with FIELD_GET
commit: 5e5a3bf48eed8d90bc5c5b710466f24663231f0a
Best regards,
--
Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
^ permalink raw reply [flat|nested] 9+ messages in thread