On Wed, Jul 10, 2024 at 11:36:12AM +0100, André Draszik wrote: > Align the last remaining field TCPC_ROLE_CTRL_RP_VAL with the other > fields in the TCPC_ROLE_CTRL register by using GENMASK() and > FIELD_PREP(). > > Signed-off-by: André Draszik <andre.draszik@xxxxxxxxxx> Reviewed-by: Heikki Krogerus <heikki.krogerus@xxxxxxxxxxxxxxx> > --- > drivers/usb/typec/tcpm/tcpci.c | 21 ++++++++++++--------- > drivers/usb/typec/tcpm/tcpci_rt1711h.c | 12 ++++++------ > include/linux/usb/tcpci.h | 3 +-- > 3 files changed, 19 insertions(+), 17 deletions(-) > > diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c > index cd71ece7b956..5ad05a5bbbd1 100644 > --- a/drivers/usb/typec/tcpm/tcpci.c > +++ b/drivers/usb/typec/tcpm/tcpci.c > @@ -114,17 +114,20 @@ static int tcpci_set_cc(struct tcpc_dev *tcpc, enum typec_cc_status cc) > case TYPEC_CC_RP_DEF: > reg = (FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RP) > | FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RP) > - | (TCPC_ROLE_CTRL_RP_VAL_DEF << TCPC_ROLE_CTRL_RP_VAL_SHIFT)); > + | FIELD_PREP(TCPC_ROLE_CTRL_RP_VAL, > + TCPC_ROLE_CTRL_RP_VAL_DEF)); > break; > case TYPEC_CC_RP_1_5: > reg = (FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RP) > | FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RP) > - | (TCPC_ROLE_CTRL_RP_VAL_1_5 << TCPC_ROLE_CTRL_RP_VAL_SHIFT)); > + | FIELD_PREP(TCPC_ROLE_CTRL_RP_VAL, > + TCPC_ROLE_CTRL_RP_VAL_1_5)); > break; > case TYPEC_CC_RP_3_0: > reg = (FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RP) > | FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RP) > - | (TCPC_ROLE_CTRL_RP_VAL_3_0 << TCPC_ROLE_CTRL_RP_VAL_SHIFT)); > + | FIELD_PREP(TCPC_ROLE_CTRL_RP_VAL, > + TCPC_ROLE_CTRL_RP_VAL_3_0)); > break; > case TYPEC_CC_OPEN: > default: > @@ -194,16 +197,16 @@ static int tcpci_start_toggling(struct tcpc_dev *tcpc, > switch (cc) { > default: > case TYPEC_CC_RP_DEF: > - reg |= (TCPC_ROLE_CTRL_RP_VAL_DEF << > - TCPC_ROLE_CTRL_RP_VAL_SHIFT); > + reg |= FIELD_PREP(TCPC_ROLE_CTRL_RP_VAL, > + TCPC_ROLE_CTRL_RP_VAL_DEF); > break; > case TYPEC_CC_RP_1_5: > - reg |= (TCPC_ROLE_CTRL_RP_VAL_1_5 << > - TCPC_ROLE_CTRL_RP_VAL_SHIFT); > + reg |= FIELD_PREP(TCPC_ROLE_CTRL_RP_VAL, > + TCPC_ROLE_CTRL_RP_VAL_1_5); > break; > case TYPEC_CC_RP_3_0: > - reg |= (TCPC_ROLE_CTRL_RP_VAL_3_0 << > - TCPC_ROLE_CTRL_RP_VAL_SHIFT); > + reg |= FIELD_PREP(TCPC_ROLE_CTRL_RP_VAL, > + TCPC_ROLE_CTRL_RP_VAL_3_0); > break; > } > > diff --git a/drivers/usb/typec/tcpm/tcpci_rt1711h.c b/drivers/usb/typec/tcpm/tcpci_rt1711h.c > index bdb78d08b5b5..64f6dd0dc660 100644 > --- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c > +++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c > @@ -232,16 +232,16 @@ static int rt1711h_start_drp_toggling(struct tcpci *tcpci, > switch (cc) { > default: > case TYPEC_CC_RP_DEF: > - reg |= (TCPC_ROLE_CTRL_RP_VAL_DEF << > - TCPC_ROLE_CTRL_RP_VAL_SHIFT); > + reg |= FIELD_PREP(TCPC_ROLE_CTRL_RP_VAL, > + TCPC_ROLE_CTRL_RP_VAL_DEF); > break; > case TYPEC_CC_RP_1_5: > - reg |= (TCPC_ROLE_CTRL_RP_VAL_1_5 << > - TCPC_ROLE_CTRL_RP_VAL_SHIFT); > + reg |= FIELD_PREP(TCPC_ROLE_CTRL_RP_VAL, > + TCPC_ROLE_CTRL_RP_VAL_1_5); > break; > case TYPEC_CC_RP_3_0: > - reg |= (TCPC_ROLE_CTRL_RP_VAL_3_0 << > - TCPC_ROLE_CTRL_RP_VAL_SHIFT); > + reg |= FIELD_PREP(TCPC_ROLE_CTRL_RP_VAL, > + TCPC_ROLE_CTRL_RP_VAL_3_0); > break; > } > > diff --git a/include/linux/usb/tcpci.h b/include/linux/usb/tcpci.h > index 552d074429f0..80652d4f722e 100644 > --- a/include/linux/usb/tcpci.h > +++ b/include/linux/usb/tcpci.h > @@ -63,8 +63,7 @@ > > #define TCPC_ROLE_CTRL 0x1a > #define TCPC_ROLE_CTRL_DRP BIT(6) > -#define TCPC_ROLE_CTRL_RP_VAL_SHIFT 4 > -#define TCPC_ROLE_CTRL_RP_VAL_MASK 0x3 > +#define TCPC_ROLE_CTRL_RP_VAL GENMASK(5, 4) > #define TCPC_ROLE_CTRL_RP_VAL_DEF 0x0 > #define TCPC_ROLE_CTRL_RP_VAL_1_5 0x1 > #define TCPC_ROLE_CTRL_RP_VAL_3_0 0x2 > > -- > 2.45.2.803.g4e1b14247a-goog -- heikki