* [PATCH 0/6] usb: Use FIELD_MODIFY() for bitfield operations
@ 2026-04-30 16:39 Hans Zhang
2026-04-30 16:39 ` [PATCH 1/6] usb: dwc3: Use FIELD_MODIFY() Hans Zhang
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Hans Zhang @ 2026-04-30 16:39 UTC (permalink / raw)
To: Thinh.Nguyen, gregkh, peter.griffin, andre.draszik, tudor.ambarus,
mathias.nyman, chunfeng.yun, matthias.bgg,
angelogioacchino.delregno, badhri, heikki.krogerus
Cc: linux-usb, linux-kernel, linux-arm-kernel, linux-samsung-soc,
linux-mediatek, Hans Zhang
Replace open-coded bitfield modifications with the standard FIELD_MODIFY()
macro across multiple USB drivers (dwc3, xhci, typec). This improves
readability and adds compile-time checking without functional changes.
---
Hi, If the Maintainers think it's not necessary, please ignore it.
---
Hans Zhang (6):
usb: dwc3: Use FIELD_MODIFY()
usb: dwc3: google: Use FIELD_MODIFY()
usb: dwc3: dwc3-octeon: Use FIELD_MODIFY()
usb: xhci: Use FIELD_MODIFY()
usb: xhci-mtk: Use FIELD_MODIFY()
usb: typec: Use FIELD_MODIFY()
drivers/usb/dwc3/core.c | 12 ++++--------
drivers/usb/dwc3/dwc3-google.c | 5 ++---
drivers/usb/dwc3/dwc3-octeon.c | 11 ++++-------
drivers/usb/host/xhci-hub.c | 5 ++---
drivers/usb/host/xhci-mtk.c | 6 +++---
drivers/usb/typec/tcpm/tcpci.c | 11 ++++-------
6 files changed, 19 insertions(+), 31 deletions(-)
base-commit: 3b3bea6d4b9c162f9e555905d96b8c1da67ecd5b
--
2.34.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/6] usb: dwc3: Use FIELD_MODIFY()
2026-04-30 16:39 [PATCH 0/6] usb: Use FIELD_MODIFY() for bitfield operations Hans Zhang
@ 2026-04-30 16:39 ` Hans Zhang
2026-04-30 16:39 ` [PATCH 2/6] usb: dwc3: google: " Hans Zhang
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Hans Zhang @ 2026-04-30 16:39 UTC (permalink / raw)
To: Thinh.Nguyen, gregkh, peter.griffin, andre.draszik, tudor.ambarus,
mathias.nyman, chunfeng.yun, matthias.bgg,
angelogioacchino.delregno, badhri, heikki.krogerus
Cc: linux-usb, linux-kernel, linux-arm-kernel, linux-samsung-soc,
linux-mediatek, Hans Zhang
Use FIELD_MODIFY() to remove open-coded bit manipulation.
No functional change intended.
Signed-off-by: Hans Zhang <18255117159@163.com>
---
drivers/usb/dwc3/core.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 58899b1fa96d..f95201470ab2 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -425,8 +425,7 @@ static void dwc3_ref_clk_period(struct dwc3 *dwc)
}
reg = dwc3_readl(dwc, DWC3_GUCTL);
- reg &= ~DWC3_GUCTL_REFCLKPER_MASK;
- reg |= FIELD_PREP(DWC3_GUCTL_REFCLKPER_MASK, period);
+ FIELD_MODIFY(DWC3_GUCTL_REFCLKPER_MASK, ®, period);
dwc3_writel(dwc, DWC3_GUCTL, reg);
if (DWC3_VER_IS_PRIOR(DWC3, 250A))
@@ -456,12 +455,9 @@ static void dwc3_ref_clk_period(struct dwc3 *dwc)
decr = 480000000 / rate;
reg = dwc3_readl(dwc, DWC3_GFLADJ);
- reg &= ~DWC3_GFLADJ_REFCLK_FLADJ_MASK
- & ~DWC3_GFLADJ_240MHZDECR
- & ~DWC3_GFLADJ_240MHZDECR_PLS1;
- reg |= FIELD_PREP(DWC3_GFLADJ_REFCLK_FLADJ_MASK, fladj)
- | FIELD_PREP(DWC3_GFLADJ_240MHZDECR, decr >> 1)
- | FIELD_PREP(DWC3_GFLADJ_240MHZDECR_PLS1, decr & 1);
+ FIELD_MODIFY(DWC3_GFLADJ_REFCLK_FLADJ_MASK, ®, fladj);
+ FIELD_MODIFY(DWC3_GFLADJ_240MHZDECR, ®, decr >> 1);
+ FIELD_MODIFY(DWC3_GFLADJ_240MHZDECR_PLS1, ®, decr & 1);
if (dwc->gfladj_refclk_lpm_sel)
reg |= DWC3_GFLADJ_REFCLK_LPM_SEL;
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/6] usb: dwc3: google: Use FIELD_MODIFY()
2026-04-30 16:39 [PATCH 0/6] usb: Use FIELD_MODIFY() for bitfield operations Hans Zhang
2026-04-30 16:39 ` [PATCH 1/6] usb: dwc3: Use FIELD_MODIFY() Hans Zhang
@ 2026-04-30 16:39 ` Hans Zhang
2026-04-30 16:39 ` [PATCH 3/6] usb: dwc3: dwc3-octeon: " Hans Zhang
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Hans Zhang @ 2026-04-30 16:39 UTC (permalink / raw)
To: Thinh.Nguyen, gregkh, peter.griffin, andre.draszik, tudor.ambarus,
mathias.nyman, chunfeng.yun, matthias.bgg,
angelogioacchino.delregno, badhri, heikki.krogerus
Cc: linux-usb, linux-kernel, linux-arm-kernel, linux-samsung-soc,
linux-mediatek, Hans Zhang
Use FIELD_MODIFY() to remove open-coded bit manipulation.
No functional change intended.
Signed-off-by: Hans Zhang <18255117159@163.com>
---
drivers/usb/dwc3/dwc3-google.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/dwc3/dwc3-google.c b/drivers/usb/dwc3/dwc3-google.c
index 4ca567ec01d0..60ee4cc99b28 100644
--- a/drivers/usb/dwc3/dwc3-google.c
+++ b/drivers/usb/dwc3/dwc3-google.c
@@ -104,9 +104,8 @@ static int dwc3_google_set_pmu_state(struct dwc3_google *google, int state)
regmap_read(google->usb_cfg_regmap,
google->host_cfg_offset + HOST_CFG1_OFFSET, ®);
- reg &= ~HOST_CFG1_PM_POWER_STATE_REQUEST;
- reg |= (FIELD_PREP(HOST_CFG1_PM_POWER_STATE_REQUEST, state) |
- HOST_CFG1_PME_EN);
+ FIELD_MODIFY(HOST_CFG1_PM_POWER_STATE_REQUEST, ®, state);
+ reg |= HOST_CFG1_PME_EN;
regmap_write(google->usb_cfg_regmap,
google->host_cfg_offset + HOST_CFG1_OFFSET, reg);
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/6] usb: dwc3: dwc3-octeon: Use FIELD_MODIFY()
2026-04-30 16:39 [PATCH 0/6] usb: Use FIELD_MODIFY() for bitfield operations Hans Zhang
2026-04-30 16:39 ` [PATCH 1/6] usb: dwc3: Use FIELD_MODIFY() Hans Zhang
2026-04-30 16:39 ` [PATCH 2/6] usb: dwc3: google: " Hans Zhang
@ 2026-04-30 16:39 ` Hans Zhang
2026-04-30 16:39 ` [PATCH 4/6] usb: xhci: " Hans Zhang
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Hans Zhang @ 2026-04-30 16:39 UTC (permalink / raw)
To: Thinh.Nguyen, gregkh, peter.griffin, andre.draszik, tudor.ambarus,
mathias.nyman, chunfeng.yun, matthias.bgg,
angelogioacchino.delregno, badhri, heikki.krogerus
Cc: linux-usb, linux-kernel, linux-arm-kernel, linux-samsung-soc,
linux-mediatek, Hans Zhang
Use FIELD_MODIFY() to remove open-coded bit manipulation.
No functional change intended.
Signed-off-by: Hans Zhang <18255117159@163.com>
---
drivers/usb/dwc3/dwc3-octeon.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/drivers/usb/dwc3/dwc3-octeon.c b/drivers/usb/dwc3/dwc3-octeon.c
index 42bfc14ae0c4..2201f0f34abb 100644
--- a/drivers/usb/dwc3/dwc3-octeon.c
+++ b/drivers/usb/dwc3/dwc3-octeon.c
@@ -296,8 +296,7 @@ static int dwc3_octeon_setup(struct dwc3_octeon *octeon,
return div;
}
val = dwc3_octeon_readq(uctl_ctl_reg);
- val &= ~USBDRD_UCTL_CTL_H_CLKDIV_SEL;
- val |= FIELD_PREP(USBDRD_UCTL_CTL_H_CLKDIV_SEL, div);
+ FIELD_MODIFY(USBDRD_UCTL_CTL_H_CLKDIV_SEL, &val, div);
val |= USBDRD_UCTL_CTL_H_CLK_EN;
dwc3_octeon_writeq(uctl_ctl_reg, val);
val = dwc3_octeon_readq(uctl_ctl_reg);
@@ -314,14 +313,11 @@ static int dwc3_octeon_setup(struct dwc3_octeon *octeon,
/* Step 5a: Reference clock configuration. */
val = dwc3_octeon_readq(uctl_ctl_reg);
val &= ~USBDRD_UCTL_CTL_REF_CLK_DIV2;
- val &= ~USBDRD_UCTL_CTL_REF_CLK_SEL;
- val |= FIELD_PREP(USBDRD_UCTL_CTL_REF_CLK_SEL, ref_clk_sel);
+ FIELD_MODIFY(USBDRD_UCTL_CTL_REF_CLK_SEL, &val, ref_clk_sel);
- val &= ~USBDRD_UCTL_CTL_REF_CLK_FSEL;
- val |= FIELD_PREP(USBDRD_UCTL_CTL_REF_CLK_FSEL, ref_clk_fsel);
+ FIELD_MODIFY(USBDRD_UCTL_CTL_REF_CLK_FSEL, &val, ref_clk_fsel);
- val &= ~USBDRD_UCTL_CTL_MPLL_MULTIPLIER;
- val |= FIELD_PREP(USBDRD_UCTL_CTL_MPLL_MULTIPLIER, mpll_mul);
+ FIELD_MODIFY(USBDRD_UCTL_CTL_MPLL_MULTIPLIER, &val, mpll_mul);
/* Step 5b: Configure and enable spread-spectrum for SuperSpeed. */
val |= USBDRD_UCTL_CTL_SSC_EN;
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/6] usb: xhci: Use FIELD_MODIFY()
2026-04-30 16:39 [PATCH 0/6] usb: Use FIELD_MODIFY() for bitfield operations Hans Zhang
` (2 preceding siblings ...)
2026-04-30 16:39 ` [PATCH 3/6] usb: dwc3: dwc3-octeon: " Hans Zhang
@ 2026-04-30 16:39 ` Hans Zhang
2026-04-30 16:39 ` [PATCH 5/6] usb: xhci-mtk: " Hans Zhang
2026-04-30 16:39 ` [PATCH 6/6] usb: typec: " Hans Zhang
5 siblings, 0 replies; 7+ messages in thread
From: Hans Zhang @ 2026-04-30 16:39 UTC (permalink / raw)
To: Thinh.Nguyen, gregkh, peter.griffin, andre.draszik, tudor.ambarus,
mathias.nyman, chunfeng.yun, matthias.bgg,
angelogioacchino.delregno, badhri, heikki.krogerus
Cc: linux-usb, linux-kernel, linux-arm-kernel, linux-samsung-soc,
linux-mediatek, Hans Zhang
Use FIELD_MODIFY() to remove open-coded bit manipulation.
No functional change intended.
Signed-off-by: Hans Zhang <18255117159@163.com>
---
drivers/usb/host/xhci-hub.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index bacd0ddd0d09..3830d4123961 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -226,9 +226,8 @@ static int xhci_create_usb3x_bos_desc(struct xhci_hcd *xhci, char *buf,
USB_SSP_SUBLINK_SPEED_ST_SYM_RX);
ssp_cap->bmSublinkSpeedAttr[offset++] = cpu_to_le32(attr);
- attr &= ~USB_SSP_SUBLINK_SPEED_ST;
- attr |= FIELD_PREP(USB_SSP_SUBLINK_SPEED_ST,
- USB_SSP_SUBLINK_SPEED_ST_SYM_TX);
+ FIELD_MODIFY(USB_SSP_SUBLINK_SPEED_ST, &attr,
+ USB_SSP_SUBLINK_SPEED_ST_SYM_TX);
ssp_cap->bmSublinkSpeedAttr[offset++] = cpu_to_le32(attr);
break;
case PLT_ASYM_RX:
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 5/6] usb: xhci-mtk: Use FIELD_MODIFY()
2026-04-30 16:39 [PATCH 0/6] usb: Use FIELD_MODIFY() for bitfield operations Hans Zhang
` (3 preceding siblings ...)
2026-04-30 16:39 ` [PATCH 4/6] usb: xhci: " Hans Zhang
@ 2026-04-30 16:39 ` Hans Zhang
2026-04-30 16:39 ` [PATCH 6/6] usb: typec: " Hans Zhang
5 siblings, 0 replies; 7+ messages in thread
From: Hans Zhang @ 2026-04-30 16:39 UTC (permalink / raw)
To: Thinh.Nguyen, gregkh, peter.griffin, andre.draszik, tudor.ambarus,
mathias.nyman, chunfeng.yun, matthias.bgg,
angelogioacchino.delregno, badhri, heikki.krogerus
Cc: linux-usb, linux-kernel, linux-arm-kernel, linux-samsung-soc,
linux-mediatek, Hans Zhang
Use FIELD_MODIFY() to remove open-coded bit manipulation.
No functional change intended.
Signed-off-by: Hans Zhang <18255117159@163.com>
---
drivers/usb/host/xhci-mtk.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c
index 06043c7c3100..d9b865546a67 100644
--- a/drivers/usb/host/xhci-mtk.c
+++ b/drivers/usb/host/xhci-mtk.c
@@ -185,9 +185,9 @@ static void xhci_mtk_rxfifo_depth_set(struct xhci_hcd_mtk *mtk)
return;
value = readl(hcd->regs + HSCH_CFG1);
- value &= ~SCH3_RXFIFO_DEPTH_MASK;
- value |= FIELD_PREP(SCH3_RXFIFO_DEPTH_MASK,
- SCH_FIFO_TO_KB(mtk->rxfifo_depth) - 1);
+ FIELD_MODIFY(SCH3_RXFIFO_DEPTH_MASK, &value,
+ SCH_FIFO_TO_KB(mtk->rxfifo_depth) - 1);
+
writel(value, hcd->regs + HSCH_CFG1);
}
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 6/6] usb: typec: Use FIELD_MODIFY()
2026-04-30 16:39 [PATCH 0/6] usb: Use FIELD_MODIFY() for bitfield operations Hans Zhang
` (4 preceding siblings ...)
2026-04-30 16:39 ` [PATCH 5/6] usb: xhci-mtk: " Hans Zhang
@ 2026-04-30 16:39 ` Hans Zhang
5 siblings, 0 replies; 7+ messages in thread
From: Hans Zhang @ 2026-04-30 16:39 UTC (permalink / raw)
To: Thinh.Nguyen, gregkh, peter.griffin, andre.draszik, tudor.ambarus,
mathias.nyman, chunfeng.yun, matthias.bgg,
angelogioacchino.delregno, badhri, heikki.krogerus
Cc: linux-usb, linux-kernel, linux-arm-kernel, linux-samsung-soc,
linux-mediatek, Hans Zhang
Use FIELD_MODIFY() to remove open-coded bit manipulation.
No functional change intended.
Signed-off-by: Hans Zhang <18255117159@163.com>
---
drivers/usb/typec/tcpm/tcpci.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c
index 0148b8f50412..24c87dfa6b64 100644
--- a/drivers/usb/typec/tcpm/tcpci.c
+++ b/drivers/usb/typec/tcpm/tcpci.c
@@ -141,13 +141,10 @@ static int tcpci_set_cc(struct tcpc_dev *tcpc, enum typec_cc_status cc)
}
if (vconn_pres) {
- if (polarity == TYPEC_POLARITY_CC2) {
- reg &= ~TCPC_ROLE_CTRL_CC1;
- reg |= FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_OPEN);
- } else {
- reg &= ~TCPC_ROLE_CTRL_CC2;
- reg |= FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_OPEN);
- }
+ if (polarity == TYPEC_POLARITY_CC2)
+ FIELD_MODIFY(TCPC_ROLE_CTRL_CC1, ®, TCPC_ROLE_CTRL_CC_OPEN);
+ else
+ FIELD_MODIFY(TCPC_ROLE_CTRL_CC2, ®, TCPC_ROLE_CTRL_CC_OPEN);
}
ret = regmap_write(tcpci->regmap, TCPC_ROLE_CTRL, reg);
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-04-30 16:40 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-30 16:39 [PATCH 0/6] usb: Use FIELD_MODIFY() for bitfield operations Hans Zhang
2026-04-30 16:39 ` [PATCH 1/6] usb: dwc3: Use FIELD_MODIFY() Hans Zhang
2026-04-30 16:39 ` [PATCH 2/6] usb: dwc3: google: " Hans Zhang
2026-04-30 16:39 ` [PATCH 3/6] usb: dwc3: dwc3-octeon: " Hans Zhang
2026-04-30 16:39 ` [PATCH 4/6] usb: xhci: " Hans Zhang
2026-04-30 16:39 ` [PATCH 5/6] usb: xhci-mtk: " Hans Zhang
2026-04-30 16:39 ` [PATCH 6/6] usb: typec: " Hans Zhang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox