public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Sven Peter <sven@svenpeter.dev>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Guido Günther" <agx@sigxcpu.org>,
	"Bryan O'Donoghue" <bryan.odonoghue@linaro.org>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Hector Martin" <marcan@marcan.st>,
	"Mohamed Mediouni" <mohamed.mediouni@caramail.com>,
	"Stan Skowronek" <stan@corellium.com>,
	"Mark Kettenis" <mark.kettenis@xs4all.nl>,
	"Alexander Graf" <graf@amazon.com>,
	"Alyssa Rosenzweig" <alyssa@rosenzweig.io>
Subject: Re: [PATCH v3 2/6] usb: typec: tipd: Split interrupt handler
Date: Thu, 30 Sep 2021 13:08:58 +0300	[thread overview]
Message-ID: <YVWMuleXQqJMvZ1f@kuha.fi.intel.com> (raw)
In-Reply-To: <20210928155502.71372-3-sven@svenpeter.dev>

On Tue, Sep 28, 2021 at 05:54:58PM +0200, Sven Peter wrote:
> Split the handlers for the individual interrupts into their own functions
> to prepare for adding a second interrupt handler for the Apple CD321x
> chips
> 
> Signed-off-by: Sven Peter <sven@svenpeter.dev>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
> no changes since v2
> 
> changes since v1:
>   - new commit since Heikki suggested to add a separate irq handler
>     for the cd321x variant
> 
>  drivers/usb/typec/tipd/core.c | 96 ++++++++++++++++++++++++-----------
>  1 file changed, 65 insertions(+), 31 deletions(-)
> 
> diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c
> index 93e56291f0cf..172715c6c238 100644
> --- a/drivers/usb/typec/tipd/core.c
> +++ b/drivers/usb/typec/tipd/core.c
> @@ -404,13 +404,69 @@ static const struct typec_operations tps6598x_ops = {
>  	.pr_set = tps6598x_pr_set,
>  };
>  
> +static bool tps6598x_read_status(struct tps6598x *tps, u32 *status)
> +{
> +	int ret;
> +
> +	ret = tps6598x_read32(tps, TPS_REG_STATUS, status);
> +	if (ret) {
> +		dev_err(tps->dev, "%s: failed to read status\n", __func__);
> +		return false;
> +	}
> +	trace_tps6598x_status(*status);
> +
> +	return true;
> +}
> +
> +static bool tps6598x_read_data_status(struct tps6598x *tps)
> +{
> +	u32 data_status;
> +	int ret;
> +
> +	ret = tps6598x_read32(tps, TPS_REG_DATA_STATUS, &data_status);
> +	if (ret < 0) {
> +		dev_err(tps->dev, "failed to read data status: %d\n", ret);
> +		return false;
> +	}
> +	trace_tps6598x_data_status(data_status);
> +
> +	return true;
> +}
> +
> +static bool tps6598x_read_power_status(struct tps6598x *tps)
> +{
> +	u16 pwr_status;
> +	int ret;
> +
> +	ret = tps6598x_read16(tps, TPS_REG_POWER_STATUS, &pwr_status);
> +	if (ret < 0) {
> +		dev_err(tps->dev, "failed to read power status: %d\n", ret);
> +		return false;
> +	}
> +	trace_tps6598x_power_status(pwr_status);
> +
> +	return true;
> +}
> +
> +static void tps6598x_handle_plug_event(struct tps6598x *tps, u32 status)
> +{
> +	int ret;
> +
> +	if (status & TPS_STATUS_PLUG_PRESENT) {
> +		ret = tps6598x_connect(tps, status);
> +		if (ret)
> +			dev_err(tps->dev, "failed to register partner\n");
> +	} else {
> +		tps6598x_disconnect(tps, status);
> +	}
> +}
> +
>  static irqreturn_t tps6598x_interrupt(int irq, void *data)
>  {
>  	struct tps6598x *tps = data;
>  	u64 event1;
>  	u64 event2;
> -	u32 status, data_status;
> -	u16 pwr_status;
> +	u32 status;
>  	int ret;
>  
>  	mutex_lock(&tps->lock);
> @@ -423,42 +479,20 @@ static irqreturn_t tps6598x_interrupt(int irq, void *data)
>  	}
>  	trace_tps6598x_irq(event1, event2);
>  
> -	ret = tps6598x_read32(tps, TPS_REG_STATUS, &status);
> -	if (ret) {
> -		dev_err(tps->dev, "%s: failed to read status\n", __func__);
> +	if (!tps6598x_read_status(tps, &status))
>  		goto err_clear_ints;
> -	}
> -	trace_tps6598x_status(status);
>  
> -	if ((event1 | event2) & TPS_REG_INT_POWER_STATUS_UPDATE) {
> -		ret = tps6598x_read16(tps, TPS_REG_POWER_STATUS, &pwr_status);
> -		if (ret < 0) {
> -			dev_err(tps->dev, "failed to read power status: %d\n", ret);
> +	if ((event1 | event2) & TPS_REG_INT_POWER_STATUS_UPDATE)
> +		if (!tps6598x_read_power_status(tps))
>  			goto err_clear_ints;
> -		}
> -		trace_tps6598x_power_status(pwr_status);
> -	}
>  
> -	if ((event1 | event2) & TPS_REG_INT_DATA_STATUS_UPDATE) {
> -		ret = tps6598x_read32(tps, TPS_REG_DATA_STATUS, &data_status);
> -		if (ret < 0) {
> -			dev_err(tps->dev, "failed to read data status: %d\n", ret);
> +	if ((event1 | event2) & TPS_REG_INT_DATA_STATUS_UPDATE)
> +		if (!tps6598x_read_data_status(tps))
>  			goto err_clear_ints;
> -		}
> -		trace_tps6598x_data_status(data_status);
> -	}
>  
>  	/* Handle plug insert or removal */
> -	if ((event1 | event2) & TPS_REG_INT_PLUG_EVENT) {
> -		if (status & TPS_STATUS_PLUG_PRESENT) {
> -			ret = tps6598x_connect(tps, status);
> -			if (ret)
> -				dev_err(tps->dev,
> -					"failed to register partner\n");
> -		} else {
> -			tps6598x_disconnect(tps, status);
> -		}
> -	}
> +	if ((event1 | event2) & TPS_REG_INT_PLUG_EVENT)
> +		tps6598x_handle_plug_event(tps, status);
>  
>  err_clear_ints:
>  	tps6598x_write64(tps, TPS_REG_INT_CLEAR1, event1);
> -- 
> 2.25.1

thanks,

-- 
heikki

  reply	other threads:[~2021-09-30 10:09 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-28 15:54 [PATCH v3 0/6] usb: typec: tipd: Add Apple M1 support Sven Peter
2021-09-28 15:54 ` [PATCH v3 1/6] dt-bindings: usb: tps6598x: Add Apple CD321x compatible Sven Peter
2021-09-28 15:54 ` [PATCH v3 2/6] usb: typec: tipd: Split interrupt handler Sven Peter
2021-09-30 10:08   ` Heikki Krogerus [this message]
2021-09-28 15:54 ` [PATCH v3 3/6] usb: typec: tipd: Add short-circuit for no irqs Sven Peter
2021-09-28 15:55 ` [PATCH v3 4/6] usb: typec: tipd: Add support for Apple CD321X Sven Peter
2021-09-30 10:09   ` Heikki Krogerus
2021-09-28 15:55 ` [PATCH v3 5/6] usb: typec: tipd: Switch CD321X power state to S0 Sven Peter
2021-09-30 10:10   ` Heikki Krogerus
2021-09-28 15:55 ` [PATCH v3 6/6] usb: typec: tipd: Remove FIXME about testing with I2C_FUNC_I2C Sven Peter

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=YVWMuleXQqJMvZ1f@kuha.fi.intel.com \
    --to=heikki.krogerus@linux.intel.com \
    --cc=agx@sigxcpu.org \
    --cc=alyssa@rosenzweig.io \
    --cc=bryan.odonoghue@linaro.org \
    --cc=graf@amazon.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=marcan@marcan.st \
    --cc=mark.kettenis@xs4all.nl \
    --cc=mohamed.mediouni@caramail.com \
    --cc=stan@corellium.com \
    --cc=sven@svenpeter.dev \
    /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