All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: Bjorn Andersson <quic_bjorande@quicinc.com>
Cc: Vinod Koul <vkoul@kernel.org>,
	Kishon Vijay Abraham I <kishon@kernel.org>,
	Bjorn Andersson <andersson@kernel.org>,
	Konrad Dybcio <konrad.dybcio@linaro.org>,
	Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	linux-arm-msm@vger.kernel.org, linux-phy@lists.infradead.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 4/7] phy: qcom-qmp-combo: Introduce orientation switching
Date: Tue, 2 May 2023 13:56:42 +0200	[thread overview]
Message-ID: <ZFD6evxxzjqqaCZk@hovoldconsulting.com> (raw)
In-Reply-To: <20230425034010.3789376-5-quic_bjorande@quicinc.com>

On Mon, Apr 24, 2023 at 08:40:07PM -0700, Bjorn Andersson wrote:
> The data lanes of the QMP PHY is swapped in order to handle changing
> orientation of the USB Type-C cable. Register a typec_switch device to
> allow a TCPM to configure the orientation.
> 
> The newly introduced orientation variable is adjusted based on the
> request, and the initialized components are brought down and up again.
> To keep track of what parts needs to be cycled new variables to keep
> track of the individual init_count is introduced.
> 
> Both the USB and the DisplayPort altmode signals are properly switched.
> For DisplayPort the controller will after the TCPM having established
> orientation power on the PHY, so this is not done implicitly, but for
> USB the PHY typically is kept initialized across the switch, and must
> therefor then be reinitialized.
> 
> This is based on initial work by Wesley Cheng.
> 
> Link: https://lore.kernel.org/r/20201009082843.28503-3-wcheng@codeaurora.org/
> Signed-off-by: Bjorn Andersson <quic_bjorande@quicinc.com>
> ---
>  drivers/phy/qualcomm/phy-qcom-qmp-combo.c | 92 ++++++++++++++++++++---
>  1 file changed, 83 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/phy/qualcomm/phy-qcom-qmp-combo.c b/drivers/phy/qualcomm/phy-qcom-qmp-combo.c
> index 6748f31da7a3..5d6d6ef3944b 100644
> --- a/drivers/phy/qualcomm/phy-qcom-qmp-combo.c
> +++ b/drivers/phy/qualcomm/phy-qcom-qmp-combo.c

> @@ -2567,8 +2573,9 @@ static int qmp_combo_dp_exit(struct phy *phy)
>  
>  	mutex_lock(&qmp->phy_mutex);
>  
> -	qmp_combo_com_exit(qmp);
> +	qmp_combo_com_exit(qmp, false);
>  
> +	qmp->dp_init_count--;

Nit: add a newline for symmetry.

>  	mutex_unlock(&qmp->phy_mutex);
>  
>  	return 0;

> @@ -3351,6 +3362,65 @@ static struct phy *qmp_combo_phy_xlate(struct device *dev, struct of_phandle_arg
>  	return ERR_PTR(-EINVAL);
>  }
>  
> +#if IS_ENABLED(CONFIG_TYPEC)
> +static int qmp_combo_typec_switch_set(struct typec_switch_dev *sw,
> +				      enum typec_orientation orientation)
> +{
> +	struct qmp_combo *qmp = typec_switch_get_drvdata(sw);
> +	const struct qmp_phy_cfg *cfg = qmp->cfg;
> +
> +	if (orientation == qmp->orientation || orientation == TYPEC_ORIENTATION_NONE)
> +		return 0;
> +
> +	mutex_lock(&qmp->phy_mutex);
> +	qmp->orientation = orientation;
> +
> +	if (qmp->init_count) {
> +		if (qmp->usb_init_count)
> +			qmp_combo_usb_power_off(qmp->usb_phy);
> +		qmp_combo_com_exit(qmp, true);
> +
> +		qmp_combo_com_init(qmp, true);
> +		if (qmp->usb_init_count)
> +			qmp_combo_usb_power_on(qmp->usb_phy);
> +		if (qmp->dp_init_count)
> +			cfg->dp_aux_init(qmp);
> +	}
> +	mutex_unlock(&qmp->phy_mutex);
> +
> +	return 0;
> +}
> +
> +static void qmp_combo_typec_unregister(void *data)
> +{
> +	struct qmp_combo *qmp = data;
> +
> +	typec_switch_unregister(qmp->sw);
> +}
> +
> +static int qmp_combo_typec_switch_register(struct qmp_combo *qmp)
> +{
> +	struct typec_switch_desc sw_desc = {};
> +	struct device *dev = qmp->dev;
> +
> +	sw_desc.drvdata = qmp;
> +	sw_desc.fwnode = dev->fwnode;
> +	sw_desc.set = qmp_combo_typec_switch_set;

Nit: I'd add a newline here for readability.

> +	qmp->sw = typec_switch_register(dev, &sw_desc);
> +	if (IS_ERR(qmp->sw)) {
> +		dev_err(dev, "Unable to register typec switch: %pe\n", qmp->sw);
> +		return PTR_ERR(qmp->sw);
> +	}
> +
> +	return devm_add_action_or_reset(dev, qmp_combo_typec_unregister, qmp);
> +}
> +#else
> +static int qmp_combo_typec_switch_register(struct qmp_combo *qmp)
> +{
> +	return 0;
> +}
> +#endif

Perhaps you can move the type-c block after qmp_combo_register_clocks()
above to keep the type-c and later added bridge functions together and
better reflect the probe init order (e.g. keeping the dt-functions just
above probe()).

> +
>  static int qmp_combo_probe(struct platform_device *pdev)
>  {
>  	struct qmp_combo *qmp;
> @@ -3385,6 +3455,10 @@ static int qmp_combo_probe(struct platform_device *pdev)
>  	if (ret)
>  		return ret;
>  
> +	ret = qmp_combo_typec_switch_register(qmp);
> +	if (ret)
> +		return ret;
> +
>  	/* Check for legacy binding with child nodes. */
>  	usb_np = of_get_child_by_name(dev->of_node, "usb3-phy");
>  	if (usb_np) {

Looks good otherwise:

Reviewed-by: Johan Hovold <johan+linaro@kernel.org>

Johan

WARNING: multiple messages have this Message-ID (diff)
From: Johan Hovold <johan@kernel.org>
To: Bjorn Andersson <quic_bjorande@quicinc.com>
Cc: Vinod Koul <vkoul@kernel.org>,
	Kishon Vijay Abraham I <kishon@kernel.org>,
	Bjorn Andersson <andersson@kernel.org>,
	Konrad Dybcio <konrad.dybcio@linaro.org>,
	Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	linux-arm-msm@vger.kernel.org, linux-phy@lists.infradead.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 4/7] phy: qcom-qmp-combo: Introduce orientation switching
Date: Tue, 2 May 2023 13:56:42 +0200	[thread overview]
Message-ID: <ZFD6evxxzjqqaCZk@hovoldconsulting.com> (raw)
In-Reply-To: <20230425034010.3789376-5-quic_bjorande@quicinc.com>

On Mon, Apr 24, 2023 at 08:40:07PM -0700, Bjorn Andersson wrote:
> The data lanes of the QMP PHY is swapped in order to handle changing
> orientation of the USB Type-C cable. Register a typec_switch device to
> allow a TCPM to configure the orientation.
> 
> The newly introduced orientation variable is adjusted based on the
> request, and the initialized components are brought down and up again.
> To keep track of what parts needs to be cycled new variables to keep
> track of the individual init_count is introduced.
> 
> Both the USB and the DisplayPort altmode signals are properly switched.
> For DisplayPort the controller will after the TCPM having established
> orientation power on the PHY, so this is not done implicitly, but for
> USB the PHY typically is kept initialized across the switch, and must
> therefor then be reinitialized.
> 
> This is based on initial work by Wesley Cheng.
> 
> Link: https://lore.kernel.org/r/20201009082843.28503-3-wcheng@codeaurora.org/
> Signed-off-by: Bjorn Andersson <quic_bjorande@quicinc.com>
> ---
>  drivers/phy/qualcomm/phy-qcom-qmp-combo.c | 92 ++++++++++++++++++++---
>  1 file changed, 83 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/phy/qualcomm/phy-qcom-qmp-combo.c b/drivers/phy/qualcomm/phy-qcom-qmp-combo.c
> index 6748f31da7a3..5d6d6ef3944b 100644
> --- a/drivers/phy/qualcomm/phy-qcom-qmp-combo.c
> +++ b/drivers/phy/qualcomm/phy-qcom-qmp-combo.c

> @@ -2567,8 +2573,9 @@ static int qmp_combo_dp_exit(struct phy *phy)
>  
>  	mutex_lock(&qmp->phy_mutex);
>  
> -	qmp_combo_com_exit(qmp);
> +	qmp_combo_com_exit(qmp, false);
>  
> +	qmp->dp_init_count--;

Nit: add a newline for symmetry.

>  	mutex_unlock(&qmp->phy_mutex);
>  
>  	return 0;

> @@ -3351,6 +3362,65 @@ static struct phy *qmp_combo_phy_xlate(struct device *dev, struct of_phandle_arg
>  	return ERR_PTR(-EINVAL);
>  }
>  
> +#if IS_ENABLED(CONFIG_TYPEC)
> +static int qmp_combo_typec_switch_set(struct typec_switch_dev *sw,
> +				      enum typec_orientation orientation)
> +{
> +	struct qmp_combo *qmp = typec_switch_get_drvdata(sw);
> +	const struct qmp_phy_cfg *cfg = qmp->cfg;
> +
> +	if (orientation == qmp->orientation || orientation == TYPEC_ORIENTATION_NONE)
> +		return 0;
> +
> +	mutex_lock(&qmp->phy_mutex);
> +	qmp->orientation = orientation;
> +
> +	if (qmp->init_count) {
> +		if (qmp->usb_init_count)
> +			qmp_combo_usb_power_off(qmp->usb_phy);
> +		qmp_combo_com_exit(qmp, true);
> +
> +		qmp_combo_com_init(qmp, true);
> +		if (qmp->usb_init_count)
> +			qmp_combo_usb_power_on(qmp->usb_phy);
> +		if (qmp->dp_init_count)
> +			cfg->dp_aux_init(qmp);
> +	}
> +	mutex_unlock(&qmp->phy_mutex);
> +
> +	return 0;
> +}
> +
> +static void qmp_combo_typec_unregister(void *data)
> +{
> +	struct qmp_combo *qmp = data;
> +
> +	typec_switch_unregister(qmp->sw);
> +}
> +
> +static int qmp_combo_typec_switch_register(struct qmp_combo *qmp)
> +{
> +	struct typec_switch_desc sw_desc = {};
> +	struct device *dev = qmp->dev;
> +
> +	sw_desc.drvdata = qmp;
> +	sw_desc.fwnode = dev->fwnode;
> +	sw_desc.set = qmp_combo_typec_switch_set;

Nit: I'd add a newline here for readability.

> +	qmp->sw = typec_switch_register(dev, &sw_desc);
> +	if (IS_ERR(qmp->sw)) {
> +		dev_err(dev, "Unable to register typec switch: %pe\n", qmp->sw);
> +		return PTR_ERR(qmp->sw);
> +	}
> +
> +	return devm_add_action_or_reset(dev, qmp_combo_typec_unregister, qmp);
> +}
> +#else
> +static int qmp_combo_typec_switch_register(struct qmp_combo *qmp)
> +{
> +	return 0;
> +}
> +#endif

Perhaps you can move the type-c block after qmp_combo_register_clocks()
above to keep the type-c and later added bridge functions together and
better reflect the probe init order (e.g. keeping the dt-functions just
above probe()).

> +
>  static int qmp_combo_probe(struct platform_device *pdev)
>  {
>  	struct qmp_combo *qmp;
> @@ -3385,6 +3455,10 @@ static int qmp_combo_probe(struct platform_device *pdev)
>  	if (ret)
>  		return ret;
>  
> +	ret = qmp_combo_typec_switch_register(qmp);
> +	if (ret)
> +		return ret;
> +
>  	/* Check for legacy binding with child nodes. */
>  	usb_np = of_get_child_by_name(dev->of_node, "usb3-phy");
>  	if (usb_np) {

Looks good otherwise:

Reviewed-by: Johan Hovold <johan+linaro@kernel.org>

Johan

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

  parent reply	other threads:[~2023-05-02 11:56 UTC|newest]

Thread overview: 90+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-25  3:40 [PATCH 0/7] phy: qcom-qmp-combo: Support orientation switching Bjorn Andersson
2023-04-25  3:40 ` Bjorn Andersson
2023-04-25  3:40 ` [PATCH 1/7] dt-bindings: phy: qcom,sc8280xp-qmp-usb43dp: Add ports and orientation-switch Bjorn Andersson
2023-04-25  3:40   ` Bjorn Andersson
2023-04-25 18:58   ` Rob Herring
2023-04-25 18:58     ` Rob Herring
2023-04-26 10:21   ` Bryan O'Donoghue
2023-04-26 10:21     ` Bryan O'Donoghue
2023-04-27 19:52     ` Bjorn Andersson
2023-04-27 19:52       ` Bjorn Andersson
2023-05-03 20:37       ` Bryan O'Donoghue
2023-05-03 20:37         ` Bryan O'Donoghue
2023-05-04 13:50       ` Neil Armstrong
2023-05-04 13:50         ` Neil Armstrong
2023-05-04 14:51         ` Bjorn Andersson
2023-05-04 14:51           ` Bjorn Andersson
2023-04-25  3:40 ` [PATCH 2/7] phy: qcom-qmp-combo: Move phy_mutex out of com_init/exit Bjorn Andersson
2023-04-25  3:40   ` Bjorn Andersson
2023-05-02 10:43   ` Johan Hovold
2023-05-02 10:43     ` Johan Hovold
2023-04-25  3:40 ` [PATCH 3/7] phy: qcom-qmp-combo: Introduce orientation variable Bjorn Andersson
2023-04-25  3:40   ` Bjorn Andersson
2023-04-27 13:13   ` Neil Armstrong
2023-04-27 13:13     ` Neil Armstrong
2023-05-02 11:48   ` Johan Hovold
2023-05-02 11:48     ` Johan Hovold
2023-05-04  3:29     ` Bjorn Andersson
2023-05-04  3:29       ` Bjorn Andersson
2023-05-04 13:44       ` Johan Hovold
2023-05-04 13:44         ` Johan Hovold
2023-05-04 15:16         ` Bjorn Andersson
2023-05-04 15:16           ` Bjorn Andersson
2023-05-04 15:41           ` Johan Hovold
2023-05-04 15:41             ` Johan Hovold
2023-04-25  3:40 ` [PATCH 4/7] phy: qcom-qmp-combo: Introduce orientation switching Bjorn Andersson
2023-04-25  3:40   ` Bjorn Andersson
2023-04-27 13:18   ` Neil Armstrong
2023-04-27 13:18     ` Neil Armstrong
2023-05-02 11:56   ` Johan Hovold [this message]
2023-05-02 11:56     ` Johan Hovold
2023-04-25  3:40 ` [PATCH 5/7] phy: qcom-qmp-combo: Introduce drm_bridge Bjorn Andersson
2023-04-25  3:40   ` Bjorn Andersson
2023-04-26 10:33   ` Bryan O'Donoghue
2023-04-26 10:33     ` Bryan O'Donoghue
2023-04-27 13:11     ` Neil Armstrong
2023-04-27 13:11       ` Neil Armstrong
2023-04-27 18:00       ` Dmitry Baryshkov
2023-04-27 18:00         ` Dmitry Baryshkov
2023-04-27 19:55     ` Bjorn Andersson
2023-04-27 19:55       ` Bjorn Andersson
2023-04-28  6:55       ` Bryan O'Donoghue
2023-04-28  6:55         ` Bryan O'Donoghue
2023-05-01 19:32   ` kernel test robot
2023-05-02  5:16   ` kernel test robot
2023-05-02 12:05   ` Johan Hovold
2023-05-02 12:05     ` Johan Hovold
2023-05-04  3:13     ` Bjorn Andersson
2023-05-04  3:13       ` Bjorn Andersson
2023-05-04  8:38       ` Johan Hovold
2023-05-04  8:38         ` Johan Hovold
2023-05-04  8:55         ` Dmitry Baryshkov
2023-05-04  8:55           ` Dmitry Baryshkov
2023-05-04 15:49         ` Bjorn Andersson
2023-05-04 15:49           ` Bjorn Andersson
2023-04-25  3:40 ` [PATCH 6/7] arm64: dts: qcom: sc8280xp-crd: Add QMP to SuperSpeed graph Bjorn Andersson
2023-04-25  3:40   ` Bjorn Andersson
2023-04-26 23:33   ` Konrad Dybcio
2023-04-26 23:33     ` Konrad Dybcio
2023-04-27 13:27     ` Neil Armstrong
2023-04-27 13:27       ` Neil Armstrong
2023-05-02 11:03       ` Konrad Dybcio
2023-05-02 11:03         ` Konrad Dybcio
2023-04-27 19:48     ` Bjorn Andersson
2023-04-27 19:48       ` Bjorn Andersson
2023-05-02 12:22   ` Johan Hovold
2023-05-02 12:22     ` Johan Hovold
2023-05-04  3:07     ` Bjorn Andersson
2023-05-04  3:07       ` Bjorn Andersson
2023-04-25  3:40 ` [PATCH 7/7] arm64: dts: qcom: sc8280xp-x13s: " Bjorn Andersson
2023-04-25  3:40   ` Bjorn Andersson
2023-04-25  4:58 ` [PATCH 0/7] phy: qcom-qmp-combo: Support orientation switching Steev Klimaszewski
2023-04-25  4:58   ` Steev Klimaszewski
2023-04-26 14:25 ` Abel Vesa
2023-04-26 14:25   ` Abel Vesa
2023-05-02 12:26 ` Johan Hovold
2023-05-02 12:26   ` Johan Hovold
2023-05-03  9:50 ` Neil Armstrong
2023-05-03  9:50   ` Neil Armstrong
2023-05-23  3:03 ` Bjorn Andersson
2023-05-23  3:03   ` Bjorn Andersson

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=ZFD6evxxzjqqaCZk@hovoldconsulting.com \
    --to=johan@kernel.org \
    --cc=andersson@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=kishon@kernel.org \
    --cc=konrad.dybcio@linaro.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-phy@lists.infradead.org \
    --cc=quic_bjorande@quicinc.com \
    --cc=robh+dt@kernel.org \
    --cc=vkoul@kernel.org \
    /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.