From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: "André Draszik" <andre.draszik@linaro.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Peter Griffin <peter.griffin@linaro.org>,
Tudor Ambarus <tudor.ambarus@linaro.org>,
Will McVicker <willmcvicker@google.com>,
Badhri Jagan Sridharan <badhri@google.com>,
kernel-team@android.com, linux-usb@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 03/15] usb: typec: tcpci: use GENMASK() for TCPC_CC_STATUS_CC[12]
Date: Wed, 31 Jul 2024 13:26:35 +0300 [thread overview]
Message-ID: <ZqoRW1qIqPFrQA4M@kuha.fi.intel.com> (raw)
In-Reply-To: <20240710-tcpc-cleanup-v1-3-0ec1f41f4263@linaro.org>
On Wed, Jul 10, 2024 at 11:36:10AM +0100, André Draszik wrote:
> The existing code here, particularly in maxim_contaminant.c, is
> arguably quite hard to read due to the open-coded masking and shifting
> spanning multiple lines.
>
> Use GENMASK() and FIELD_GET() instead, which arguably make the code
> much easier to follow.
>
> While at it, use the symbolic name TCPC_CC_STATE_SRC_OPEN for one
> instance of open-coded 0x0.
>
> Signed-off-by: André Draszik <andre.draszik@linaro.org>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> ---
> drivers/usb/typec/tcpm/maxim_contaminant.c | 8 +++-----
> drivers/usb/typec/tcpm/tcpci.c | 7 +++----
> drivers/usb/typec/tcpm/tcpci_rt1711h.c | 7 +++----
> include/linux/usb/tcpci.h | 8 +++-----
> 4 files changed, 12 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/usb/typec/tcpm/maxim_contaminant.c b/drivers/usb/typec/tcpm/maxim_contaminant.c
> index f8504a90da26..e7687aeb69c0 100644
> --- a/drivers/usb/typec/tcpm/maxim_contaminant.c
> +++ b/drivers/usb/typec/tcpm/maxim_contaminant.c
> @@ -5,6 +5,7 @@
> * USB-C module to reduce wakeups due to contaminants.
> */
>
> +#include <linux/bitfield.h>
> #include <linux/device.h>
> #include <linux/irqreturn.h>
> #include <linux/module.h>
> @@ -48,11 +49,8 @@ enum fladc_select {
> #define STATUS_CHECK(reg, mask, val) (((reg) & (mask)) == (val))
>
> #define IS_CC_OPEN(cc_status) \
> - (STATUS_CHECK((cc_status), TCPC_CC_STATUS_CC1_MASK << TCPC_CC_STATUS_CC1_SHIFT, \
> - TCPC_CC_STATE_SRC_OPEN) && STATUS_CHECK((cc_status), \
> - TCPC_CC_STATUS_CC2_MASK << \
> - TCPC_CC_STATUS_CC2_SHIFT, \
> - TCPC_CC_STATE_SRC_OPEN))
> + (FIELD_GET(TCPC_CC_STATUS_CC1, cc_status) == TCPC_CC_STATE_SRC_OPEN \
> + && FIELD_GET(TCPC_CC_STATUS_CC2, cc_status) == TCPC_CC_STATE_SRC_OPEN)
>
> static int max_contaminant_adc_to_mv(struct max_tcpci_chip *chip, enum fladc_select channel,
> bool ua_src, u8 fladc)
> diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c
> index 8a18d561b063..ce11a154c7dc 100644
> --- a/drivers/usb/typec/tcpm/tcpci.c
> +++ b/drivers/usb/typec/tcpm/tcpci.c
> @@ -5,6 +5,7 @@
> * USB Type-C Port Controller Interface.
> */
>
> +#include <linux/bitfield.h>
> #include <linux/delay.h>
> #include <linux/kernel.h>
> #include <linux/module.h>
> @@ -241,12 +242,10 @@ static int tcpci_get_cc(struct tcpc_dev *tcpc,
> if (ret < 0)
> return ret;
>
> - *cc1 = tcpci_to_typec_cc((reg >> TCPC_CC_STATUS_CC1_SHIFT) &
> - TCPC_CC_STATUS_CC1_MASK,
> + *cc1 = tcpci_to_typec_cc(FIELD_GET(TCPC_CC_STATUS_CC1, reg),
> reg & TCPC_CC_STATUS_TERM ||
> tcpc_presenting_rd(role_control, CC1));
> - *cc2 = tcpci_to_typec_cc((reg >> TCPC_CC_STATUS_CC2_SHIFT) &
> - TCPC_CC_STATUS_CC2_MASK,
> + *cc2 = tcpci_to_typec_cc(FIELD_GET(TCPC_CC_STATUS_CC2, reg),
> reg & TCPC_CC_STATUS_TERM ||
> tcpc_presenting_rd(role_control, CC2));
>
> diff --git a/drivers/usb/typec/tcpm/tcpci_rt1711h.c b/drivers/usb/typec/tcpm/tcpci_rt1711h.c
> index 67422d45eb54..c6dbccf6b17a 100644
> --- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c
> +++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c
> @@ -5,6 +5,7 @@
> * Richtek RT1711H Type-C Chip Driver
> */
>
> +#include <linux/bitfield.h>
> #include <linux/bits.h>
> #include <linux/kernel.h>
> #include <linux/mod_devicetable.h>
> @@ -195,12 +196,10 @@ static inline int rt1711h_init_cc_params(struct rt1711h_chip *chip, u8 status)
> if (ret < 0)
> return ret;
>
> - cc1 = tcpci_to_typec_cc((status >> TCPC_CC_STATUS_CC1_SHIFT) &
> - TCPC_CC_STATUS_CC1_MASK,
> + cc1 = tcpci_to_typec_cc(FIELD_GET(TCPC_CC_STATUS_CC1, status),
> status & TCPC_CC_STATUS_TERM ||
> tcpc_presenting_rd(role, CC1));
> - cc2 = tcpci_to_typec_cc((status >> TCPC_CC_STATUS_CC2_SHIFT) &
> - TCPC_CC_STATUS_CC2_MASK,
> + cc2 = tcpci_to_typec_cc(FIELD_GET(TCPC_CC_STATUS_CC2, status),
> status & TCPC_CC_STATUS_TERM ||
> tcpc_presenting_rd(role, CC2));
>
> diff --git a/include/linux/usb/tcpci.h b/include/linux/usb/tcpci.h
> index d27fe0c22a8b..31d21ccf662b 100644
> --- a/include/linux/usb/tcpci.h
> +++ b/include/linux/usb/tcpci.h
> @@ -92,11 +92,9 @@
> #define TCPC_CC_STATUS_TERM BIT(4)
> #define TCPC_CC_STATUS_TERM_RP 0
> #define TCPC_CC_STATUS_TERM_RD 1
> +#define TCPC_CC_STATUS_CC2 GENMASK(3, 2)
> +#define TCPC_CC_STATUS_CC1 GENMASK(1, 0)
> #define TCPC_CC_STATE_SRC_OPEN 0
> -#define TCPC_CC_STATUS_CC2_SHIFT 2
> -#define TCPC_CC_STATUS_CC2_MASK 0x3
> -#define TCPC_CC_STATUS_CC1_SHIFT 0
> -#define TCPC_CC_STATUS_CC1_MASK 0x3
>
> #define TCPC_POWER_STATUS 0x1e
> #define TCPC_POWER_STATUS_DBG_ACC_CON BIT(7)
> @@ -256,7 +254,7 @@ static inline enum typec_cc_status tcpci_to_typec_cc(unsigned int cc, bool sink)
> if (sink)
> return TYPEC_CC_RP_3_0;
> fallthrough;
> - case 0x0:
> + case TCPC_CC_STATE_SRC_OPEN:
> default:
> return TYPEC_CC_OPEN;
> }
>
> --
> 2.45.2.803.g4e1b14247a-goog
--
heikki
next prev parent reply other threads:[~2024-07-31 10:26 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-10 10:36 [PATCH 00/15] usb: typec: tcpci: few TCPCi & TCPCi-Maxim cleanups (mostly genmask()) André Draszik
2024-07-10 10:36 ` [PATCH 01/15] usb: typec: tcpci: fix a comment typo André Draszik
2024-07-31 9:47 ` Heikki Krogerus
2024-07-10 10:36 ` [PATCH 02/15] usb: typec: tcpm/tcpci_maxim: clarify a comment André Draszik
2024-07-31 10:10 ` Heikki Krogerus
2024-07-10 10:36 ` [PATCH 03/15] usb: typec: tcpci: use GENMASK() for TCPC_CC_STATUS_CC[12] André Draszik
2024-07-31 10:26 ` Heikki Krogerus [this message]
2024-07-10 10:36 ` [PATCH 04/15] usb: typec: tcpci: use GENMASK() for TCPC_ROLE_CTRL_CC[12] André Draszik
2024-07-31 10:28 ` Heikki Krogerus
2024-07-10 10:36 ` [PATCH 05/15] usb: typec: tcpci: use GENMASK() for TCPC_ROLE_CTRL_RP_VAL André Draszik
2024-07-31 10:37 ` Heikki Krogerus
2024-07-10 10:36 ` [PATCH 06/15] usb: typec: tcpci: use GENMASK() for TCPC_MSG_HDR_INFO_REV André Draszik
2024-07-31 10:39 ` Heikki Krogerus
2024-07-10 10:36 ` [PATCH 07/15] usb: typec: tcpci: use GENMASK() for TCPC_TRANSMIT register fields André Draszik
2024-07-31 11:01 ` Heikki Krogerus
2024-07-10 10:36 ` [PATCH 08/15] usb: typec: tcpm/tcpci_maxim: sort TCPC_ALERT_MASK values by bit André Draszik
2024-07-31 11:09 ` Heikki Krogerus
2024-07-10 10:36 ` [PATCH 09/15] usb: typec: tcpm/tcpci_maxim: simplify clearing of TCPC_ALERT_RX_BUF_OVF André Draszik
2024-07-31 11:12 ` Heikki Krogerus
2024-07-10 10:36 ` [PATCH 10/15] usb: typec: tcpm/tcpci_maxim: drop STATUS_CHECK() André Draszik
2024-07-31 12:29 ` Heikki Krogerus
2024-07-10 10:36 ` [PATCH 11/15] usb: typec: tcpm/tcpci_maxim: use GENMASK() for TCPC_VENDOR_CC_CTRL2 register André Draszik
2024-07-31 12:36 ` Heikki Krogerus
2024-07-10 10:36 ` [PATCH 12/15] usb: typec: tcpm/tcpci_maxim: use GENMASK() for TCPC_VENDOR_CC_CTRL3 register André Draszik
2024-07-31 12:38 ` Heikki Krogerus
2024-07-10 10:36 ` [PATCH 13/15] usb: typec: tcpm/tcpci_maxim: use GENMASK() for TCPC_VENDOR_ADC_CTRL1 register André Draszik
2024-07-31 12:40 ` Heikki Krogerus
2024-07-10 10:36 ` [PATCH 14/15] usb: typec: tcpm/tcpci_maxim: convert to dev_err_probe() André Draszik
2024-07-31 12:44 ` Heikki Krogerus
2024-07-10 10:36 ` [PATCH 15/15] usb: typec: tcpm/tcpci_maxim: use device managed TCPCI port deregistration André Draszik
2024-07-31 12:45 ` Heikki Krogerus
2024-07-26 5:59 ` [PATCH 00/15] usb: typec: tcpci: few TCPCi & TCPCi-Maxim cleanups (mostly genmask()) André Draszik
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZqoRW1qIqPFrQA4M@kuha.fi.intel.com \
--to=heikki.krogerus@linux.intel.com \
--cc=andre.draszik@linaro.org \
--cc=badhri@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=kernel-team@android.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=peter.griffin@linaro.org \
--cc=tudor.ambarus@linaro.org \
--cc=willmcvicker@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox