public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Abdel Alkuor <alkuor@gmail.com>
Cc: krzysztof.kozlowski+dt@linaro.org, bryan.odonoghue@linaro.org,
	gregkh@linuxfoundation.org, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org, ryan.eleceng@gmail.com,
	robh+dt@kernel.org, conor+dt@kernel.org,
	devicetree@vger.kernel.org, Abdel Alkuor <abdelalkuor@geotab.com>
Subject: Re: [PATCH v9 10/14] USB: typec: tps6598x: Add port registration for tps25750
Date: Tue, 3 Oct 2023 09:50:21 +0300	[thread overview]
Message-ID: <ZRu5rURFLbZYhDz6@kuha.fi.intel.com> (raw)
In-Reply-To: <20231001081134.37101-11-alkuor@gmail.com>

On Sun, Oct 01, 2023 at 04:11:30AM -0400, Abdel Alkuor wrote:
> From: Abdel Alkuor <abdelalkuor@geotab.com>
> 
> TPS25750 doesn't have system configuration register to get dr/pr of the
> current applied binary configuration.
> 
> Get data role from the device node and power role from PD status register.
> 
> Signed-off-by: Abdel Alkuor <abdelalkuor@geotab.com>

This also has to be done at the same time you enable TPS25750.

> ---
> Changes in v9:
>   - Move device data structs to the top of of_device_id
> Changes in v8:
>   - Change tps->cb to tps->data
> Changes in v7:
>   - Add driver name to commit subject
> Changes in v6:
>   - Add port registration to tipd data factory
> Changes in v5:
>   - Incorporating tps25750 into tps6598x driver
> 
>  drivers/usb/typec/tipd/core.c     | 68 ++++++++++++++++++++++++++++++-
>  drivers/usb/typec/tipd/tps6598x.h | 10 +++++
>  2 files changed, 77 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c
> index 0195eabd96bf..ae08c5306707 100644
> --- a/drivers/usb/typec/tipd/core.c
> +++ b/drivers/usb/typec/tipd/core.c
> @@ -40,6 +40,7 @@
>  #define TPS_REG_CTRL_CONF		0x29
>  #define TPS_REG_BOOT_STATUS		0x2D
>  #define TPS_REG_POWER_STATUS		0x3f
> +#define TPS_REG_PD_STATUS		0x40
>  #define TPS_REG_RX_IDENTITY_SOP		0x48
>  #define TPS_REG_DATA_STATUS		0x5f
>  
> @@ -102,8 +103,11 @@ static const char *const modes[] = {
>  /* Unrecognized commands will be replaced with "!CMD" */
>  #define INVALID_CMD(_cmd_)		(_cmd_ == 0x444d4321)
>  
> +struct tps6598x;
> +
>  struct tipd_data {
>  	irq_handler_t irq_handler;
> +	int (*register_port)(struct tps6598x *tps, struct fwnode_handle *node);
>  };
>  
>  struct tps6598x {
> @@ -208,6 +212,11 @@ static inline int tps6598x_read64(struct tps6598x *tps, u8 reg, u64 *val)
>  	return tps6598x_block_read(tps, reg, val, sizeof(u64));
>  }
>  
> +static inline int tps6598x_write8(struct tps6598x *tps, u8 reg, u8 val)
> +{
> +	return tps6598x_block_write(tps, reg, &val, sizeof(u8));
> +}
> +
>  static inline int tps6598x_write64(struct tps6598x *tps, u8 reg, u64 val)
>  {
>  	return tps6598x_block_write(tps, reg, &val, sizeof(u64));
> @@ -1084,6 +1093,60 @@ tps6598x_register_port(struct tps6598x *tps, struct fwnode_handle *fwnode)
>  	return 0;
>  }
>  
> +static int
> +tps25750_register_port(struct tps6598x *tps, struct fwnode_handle *fwnode)
> +{
> +	struct typec_capability typec_cap = { };
> +	const char *data_role;
> +	u8 pd_status;
> +	int ret;
> +
> +	ret = tps6598x_read8(tps, TPS_REG_PD_STATUS, &pd_status);
> +	if (ret)
> +		return ret;
> +
> +	ret = fwnode_property_read_string(fwnode, "data-role", &data_role);
> +	if (ret) {
> +		dev_err(tps->dev, "data-role not found: %d\n", ret);
> +		return ret;
> +	}
> +
> +	ret = typec_find_port_data_role(data_role);
> +	if (ret < 0) {
> +		dev_err(tps->dev, "unknown data-role: %s\n", data_role);
> +		return ret;
> +	}
> +
> +	typec_cap.data = ret;
> +	typec_cap.revision = USB_TYPEC_REV_1_3;
> +	typec_cap.pd_revision = 0x300;
> +	typec_cap.driver_data = tps;
> +	typec_cap.ops = &tps6598x_ops;
> +	typec_cap.fwnode = fwnode;
> +	typec_cap.prefer_role = TYPEC_NO_PREFERRED_ROLE;
> +
> +	switch (TPS_PD_STATUS_PORT_TYPE(pd_status)) {
> +	case TPS_PD_STATUS_PORT_TYPE_SINK_SOURCE:
> +	case TPS_PD_STATUS_PORT_TYPE_SOURCE_SINK:
> +		typec_cap.type = TYPEC_PORT_DRP;
> +		break;
> +	case TPS_PD_STATUS_PORT_TYPE_SINK:
> +		typec_cap.type = TYPEC_PORT_SNK;
> +		break;
> +	case TPS_PD_STATUS_PORT_TYPE_SOURCE:
> +		typec_cap.type = TYPEC_PORT_SRC;
> +		break;
> +	default:
> +		return -ENODEV;
> +	}
> +
> +	tps->port = typec_register_port(tps->dev, &typec_cap);
> +	if (IS_ERR(tps->port))
> +		return PTR_ERR(tps->port);
> +
> +	return 0;
> +}
> +
>  static int tps6598x_probe(struct i2c_client *client)
>  {
>  	struct device_node *np = client->dev.of_node;
> @@ -1183,7 +1246,7 @@ static int tps6598x_probe(struct i2c_client *client)
>  	if (ret)
>  		goto err_role_put;
>  
> -	ret = tps6598x_register_port(tps, fwnode);
> +	ret = tps->data->register_port(tps, fwnode);
>  	if (ret)
>  		goto err_role_put;
>  
> @@ -1308,14 +1371,17 @@ static const struct dev_pm_ops tps6598x_pm_ops = {
>  
>  static const struct tipd_data cd321x_data = {
>  	.irq_handler = cd321x_interrupt,
> +	.register_port = tps6598x_register_port,
>  };
>  
>  static const struct tipd_data tps6598x_data = {
>  	.irq_handler = tps6598x_interrupt,
> +	.register_port = tps6598x_register_port,
>  };
>  
>  static const struct tipd_data tps25750_data = {
>  	.irq_handler = tps25750_interrupt,
> +	.register_port = tps25750_register_port,
>  };
>  
>  static const struct of_device_id tps6598x_of_match[] = {
> diff --git a/drivers/usb/typec/tipd/tps6598x.h b/drivers/usb/typec/tipd/tps6598x.h
> index c000170f4547..3a9a43394134 100644
> --- a/drivers/usb/typec/tipd/tps6598x.h
> +++ b/drivers/usb/typec/tipd/tps6598x.h
> @@ -203,4 +203,14 @@
>  #define TPS_BOOT_STATUS_DEAD_BATTERY_FLAG	BIT(2)
>  #define TPS_BOOT_STATUS_I2C_EEPROM_PRESENT	BIT(3)
>  
> +/* PD STATUS REG */
> +#define TPS_REG_PD_STATUS_PORT_TYPE_MASK	GENMASK(5, 4)
> +#define TPS_PD_STATUS_PORT_TYPE(x) \
> +	TPS_FIELD_GET(TPS_REG_PD_STATUS_PORT_TYPE_MASK, x)
> +
> +#define TPS_PD_STATUS_PORT_TYPE_SINK_SOURCE	0
> +#define TPS_PD_STATUS_PORT_TYPE_SINK		1
> +#define TPS_PD_STATUS_PORT_TYPE_SOURCE		2
> +#define TPS_PD_STATUS_PORT_TYPE_SOURCE_SINK	3
> +
>  #endif /* __TPS6598X_H__ */
> -- 
> 2.34.1

-- 
heikki

  reply	other threads:[~2023-10-03  6:50 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-01  8:11 [PATCH v9 00/14] Add TPS25750 USB type-C PD controller support Abdel Alkuor
2023-10-01  8:11 ` [PATCH v9 01/14] dt-bindings: usb: tps6598x: Add tps25750 Abdel Alkuor
2023-10-01  8:11 ` [PATCH v9 02/14] USB: typec: tsp6598x: Add cmd timeout and response delay Abdel Alkuor
2023-10-01  8:11 ` [PATCH v9 03/14] USB: typec: tps6598x: Add patch mode to tps6598x Abdel Alkuor
2023-10-03  5:28   ` Heikki Krogerus
2023-10-01  8:11 ` [PATCH v9 04/14] USB: typec: tps6598x: Load TPS25750 patch bundle Abdel Alkuor
2023-10-03  5:30   ` Heikki Krogerus
2023-10-03  7:01   ` Heikki Krogerus
2023-10-01  8:11 ` [PATCH v9 05/14] USB: typec: tps6598x: Check for EEPROM present Abdel Alkuor
2023-10-03  5:34   ` Heikki Krogerus
2023-10-03 11:11     ` Abdel Alkuor
2023-10-01  8:11 ` [PATCH v9 06/14] USB: typec: tps6598x: Clear dead battery flag Abdel Alkuor
2023-10-03  6:03   ` Heikki Krogerus
2023-10-03 11:13     ` Abdel Alkuor
2023-10-01  8:11 ` [PATCH v9 07/14] USB: typec: tps6598x: Apply patch again after power resume Abdel Alkuor
2023-10-03  6:21   ` Heikki Krogerus
2023-10-03 11:14     ` Abdel Alkuor
2023-10-01  8:11 ` [PATCH v9 08/14] USB: typec: tps6598x: Add interrupt support for TPS25750 Abdel Alkuor
2023-10-03  6:39   ` Heikki Krogerus
2023-10-03 11:18     ` Abdel Alkuor
2023-10-01  8:11 ` [PATCH v9 09/14] USB: typec: tps6598x: Refactor tps6598x port registration Abdel Alkuor
2023-10-03  6:43   ` Heikki Krogerus
2023-10-01  8:11 ` [PATCH v9 10/14] USB: typec: tps6598x: Add port registration for tps25750 Abdel Alkuor
2023-10-03  6:50   ` Heikki Krogerus [this message]
2023-10-01  8:11 ` [PATCH v9 11/14] USB: typec: tps6598x: Enable sleep mode " Abdel Alkuor
2023-10-01  8:11 ` [PATCH v9 12/14] USB: typec: tps6598x: Add trace for tps25750 irq Abdel Alkuor
2023-10-01  8:11 ` [PATCH v9 13/14] USB: typec: tps6598x: Add power status trace for tps25750 Abdel Alkuor
2023-10-01  8:11 ` [PATCH v9 14/14] USB: typec: tps6598x: Add " Abdel Alkuor

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=ZRu5rURFLbZYhDz6@kuha.fi.intel.com \
    --to=heikki.krogerus@linux.intel.com \
    --cc=abdelalkuor@geotab.com \
    --cc=alkuor@gmail.com \
    --cc=bryan.odonoghue@linaro.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=ryan.eleceng@gmail.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