All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm>
Cc: linux-usb@vger.kernel.org,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Sven Peter" <sven@svenpeter.dev>,
	"Guido Günther" <agx@sigxcpu.org>,
	"Angus Ainslie" <angus@akkea.ca>,
	"Hector Martin" <marcan@marcan.st>,
	"Bryan O'Donoghue" <bryan.odonoghue@linaro.org>,
	linux-kernel@vger.kernel.org, kernel@puri.sm
Subject: Re: [PATCH 1/7] usb: typec: tipd: Only update power status on IRQ
Date: Mon, 4 Apr 2022 16:22:25 +0300	[thread overview]
Message-ID: <YkrxEU8nZxkY8txk@kuha.fi.intel.com> (raw)
In-Reply-To: <20220317154518.4082046-2-sebastian.krzyszkowiak@puri.sm>

On Thu, Mar 17, 2022 at 04:45:12PM +0100, Sebastian Krzyszkowiak wrote:
> From: Guido Günther <agx@sigxcpu.org>
> 
> Instead of refetching power status cache it and only update it when a
> change is signalled via irq. This simplifies tracing and adding more
> supply properties in follow up patches.
> 
> Signed-off-by: Guido Günther <agx@sigxcpu.org>
> Signed-off-by: Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm>

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

> ---
>  drivers/usb/typec/tipd/core.c | 32 ++++++++++++--------------------
>  1 file changed, 12 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c
> index 16b4560216ba..dfbba5ae9487 100644
> --- a/drivers/usb/typec/tipd/core.c
> +++ b/drivers/usb/typec/tipd/core.c
> @@ -93,6 +93,8 @@ struct tps6598x {
>  	struct power_supply *psy;
>  	struct power_supply_desc psy_desc;
>  	enum power_supply_usb_type usb_type;
> +
> +	u16 pwr_status;
>  };
>  
>  static enum power_supply_property tps6598x_psy_props[] = {
> @@ -230,17 +232,12 @@ static int tps6598x_connect(struct tps6598x *tps, u32 status)
>  {
>  	struct typec_partner_desc desc;
>  	enum typec_pwr_opmode mode;
> -	u16 pwr_status;
>  	int ret;
>  
>  	if (tps->partner)
>  		return 0;
>  
> -	ret = tps6598x_read16(tps, TPS_REG_POWER_STATUS, &pwr_status);
> -	if (ret < 0)
> -		return ret;
> -
> -	mode = TPS_POWER_STATUS_PWROPMODE(pwr_status);
> +	mode = TPS_POWER_STATUS_PWROPMODE(tps->pwr_status);
>  
>  	desc.usb_pd = mode == TYPEC_PWR_MODE_PD;
>  	desc.accessory = TYPEC_ACCESSORY_NONE; /* XXX: handle accessories */
> @@ -455,6 +452,7 @@ static bool tps6598x_read_power_status(struct tps6598x *tps)
>  		dev_err(tps->dev, "failed to read power status: %d\n", ret);
>  		return false;
>  	}
> +	tps->pwr_status = pwr_status;
>  	trace_tps6598x_power_status(pwr_status);
>  
>  	return true;
> @@ -601,15 +599,8 @@ static const struct regmap_config tps6598x_regmap_config = {
>  static int tps6598x_psy_get_online(struct tps6598x *tps,
>  				   union power_supply_propval *val)
>  {
> -	int ret;
> -	u16 pwr_status;
> -
> -	ret = tps6598x_read16(tps, TPS_REG_POWER_STATUS, &pwr_status);
> -	if (ret < 0)
> -		return ret;
> -
> -	if (TPS_POWER_STATUS_CONNECTION(pwr_status) &&
> -	    TPS_POWER_STATUS_SOURCESINK(pwr_status)) {
> +	if (TPS_POWER_STATUS_CONNECTION(tps->pwr_status) &&
> +	    TPS_POWER_STATUS_SOURCESINK(tps->pwr_status)) {
>  		val->intval = 1;
>  	} else {
>  		val->intval = 0;
> @@ -622,15 +613,11 @@ static int tps6598x_psy_get_prop(struct power_supply *psy,
>  				 union power_supply_propval *val)
>  {
>  	struct tps6598x *tps = power_supply_get_drvdata(psy);
> -	u16 pwr_status;
>  	int ret = 0;
>  
>  	switch (psp) {
>  	case POWER_SUPPLY_PROP_USB_TYPE:
> -		ret = tps6598x_read16(tps, TPS_REG_POWER_STATUS, &pwr_status);
> -		if (ret < 0)
> -			return ret;
> -		if (TPS_POWER_STATUS_PWROPMODE(pwr_status) == TYPEC_PWR_MODE_PD)
> +		if (TPS_POWER_STATUS_PWROPMODE(tps->pwr_status) == TYPEC_PWR_MODE_PD)
>  			val->intval = POWER_SUPPLY_USB_TYPE_PD;
>  		else
>  			val->intval = POWER_SUPPLY_USB_TYPE_C;
> @@ -837,6 +824,11 @@ static int tps6598x_probe(struct i2c_client *client)
>  	fwnode_handle_put(fwnode);
>  
>  	if (status & TPS_STATUS_PLUG_PRESENT) {
> +		ret = tps6598x_read16(tps, TPS_REG_POWER_STATUS, &tps->pwr_status);
> +		if (ret < 0) {
> +			dev_err(tps->dev, "failed to read power status: %d\n", ret);
> +			goto err_role_put;
> +		}
>  		ret = tps6598x_connect(tps, status);
>  		if (ret)
>  			dev_err(&client->dev, "failed to register partner\n");
> -- 
> 2.35.1

-- 
heikki

  reply	other threads:[~2022-04-04 13:22 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-17 15:45 [PATCH 0/7] TPS6598x PD tracing and other improvements Sebastian Krzyszkowiak
2022-03-17 15:45 ` [PATCH 1/7] usb: typec: tipd: Only update power status on IRQ Sebastian Krzyszkowiak
2022-04-04 13:22   ` Heikki Krogerus [this message]
2022-03-17 15:45 ` [PATCH 2/7] usb: typec: tipd: set the data role on tps IRQ Sebastian Krzyszkowiak
2022-04-04 13:29   ` Heikki Krogerus
2022-03-17 15:45 ` [PATCH 3/7] usb: typec: tipd: Add trace event for SINK PD contract Sebastian Krzyszkowiak
2022-04-04 13:42   ` Heikki Krogerus
2022-03-17 15:45 ` [PATCH 4/7] usb: typec: tipd: Provide POWER_SUPPLY_PROP_{CURRENT,VOLTAGE}_MAX Sebastian Krzyszkowiak
2022-04-04 13:57   ` Heikki Krogerus
2022-03-17 15:45 ` [PATCH 5/7] usb: typec: tipd: Provide POWER_SUPPLY_PROP_PRESENT Sebastian Krzyszkowiak
2022-04-04 13:59   ` Heikki Krogerus
2022-03-17 15:45 ` [PATCH 6/7] usb: typec: tipd: Add debugfs entries for customer use word Sebastian Krzyszkowiak
2022-04-04 14:03   ` Heikki Krogerus
2022-03-17 15:45 ` [PATCH 7/7] usb: typec: tipd: Fail probe when the controller is in BOOT mode Sebastian Krzyszkowiak
2022-04-04 14:04   ` Heikki Krogerus
2022-04-01 13:49 ` [PATCH 0/7] TPS6598x PD tracing and other improvements Heikki Krogerus

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=YkrxEU8nZxkY8txk@kuha.fi.intel.com \
    --to=heikki.krogerus@linux.intel.com \
    --cc=agx@sigxcpu.org \
    --cc=angus@akkea.ca \
    --cc=bryan.odonoghue@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kernel@puri.sm \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=marcan@marcan.st \
    --cc=sebastian.krzyszkowiak@puri.sm \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.