From: Bjorn Andersson <andersson@kernel.org>
To: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Cc: linux@roeck-us.net, heikki.krogerus@linux.intel.com,
gregkh@linuxfoundation.org, robh+dt@kernel.org,
krzysztof.kozlowski+dt@linaro.org, linux-usb@vger.kernel.org,
linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org,
caleb.connolly@linaro.org, konrad.dybcio@linaro.org,
subbaram@quicinc.com, jackp@quicinc.com,
robertom@qti.qualcomm.com,
Dmitry Baryshkov <dmitry.baryshkov@linaro.org>,
Wesley Cheng <wcheng@codeaurora.org>
Subject: Re: [PATCH v5 14/14] phy: qcom-qmp: Register as a typec switch for orientation detection
Date: Tue, 18 Apr 2023 05:57:23 -0700 [thread overview]
Message-ID: <20230418125723.r7fkxgrs2ncxbb7j@ripper> (raw)
In-Reply-To: <20230413113438.1577658-15-bryan.odonoghue@linaro.org>
On Thu, Apr 13, 2023 at 12:34:38PM +0100, Bryan O'Donoghue wrote:
> From: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
>
> The lane select switch for USB typec orientation is within the USB QMP PHY.
> the current device. It could be connected through an endpoint, to an
> independent device handling the typec detection, ie the QCOM SPMI typec
> driver.
>
> bod: Fixed the logic qcom_qmp_phy_typec_switch_set() to disable phy
> on disconnect if and only if we have initialized the PHY.
> Retained CC orientation logic in qcom_qmp_phy_com_init() to simplify
> patch.
>
> bod: Ported from earlier version of driver to phy-qcom-qmp-combo.c
>
> Co-developed-by: Wesley Cheng <wcheng@codeaurora.org>
> Signed-off-by: Wesley Cheng <wcheng@codeaurora.org>
> Co-developed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Your s-o-b should be last here...
> ---
> drivers/phy/qualcomm/Kconfig | 8 +++
> drivers/phy/qualcomm/phy-qcom-qmp-combo.c | 80 +++++++++++++++++++++--
> 2 files changed, 84 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/phy/qualcomm/Kconfig b/drivers/phy/qualcomm/Kconfig
> index 4850d48f31fa1..8240fffdbed4e 100644
> --- a/drivers/phy/qualcomm/Kconfig
> +++ b/drivers/phy/qualcomm/Kconfig
> @@ -101,6 +101,14 @@ config PHY_QCOM_QMP_USB
>
> endif # PHY_QCOM_QMP
>
> +config PHY_QCOM_QMP_TYPEC
> + def_bool PHY_QCOM_QMP=y && TYPEC=y || PHY_QCOM_QMP=m && TYPEC
> + help
> + Register a type C switch from the QMP PHY driver for type C
> + orientation support. This has dependencies with if the type C kernel
> + configuration is enabled or not. This support will not be present if
> + USB type C is disabled.
> +
> config PHY_QCOM_QUSB2
> tristate "Qualcomm QUSB2 PHY Driver"
> depends on OF && (ARCH_QCOM || COMPILE_TEST)
> diff --git a/drivers/phy/qualcomm/phy-qcom-qmp-combo.c b/drivers/phy/qualcomm/phy-qcom-qmp-combo.c
> index 6850e04c329b8..b9a30c087423d 100644
> --- a/drivers/phy/qualcomm/phy-qcom-qmp-combo.c
> +++ b/drivers/phy/qualcomm/phy-qcom-qmp-combo.c
> @@ -19,6 +19,7 @@
> #include <linux/regulator/consumer.h>
> #include <linux/reset.h>
> #include <linux/slab.h>
> +#include <linux/usb/typec_mux.h>
>
> #include <dt-bindings/phy/phy-qcom-qmp.h>
>
> @@ -63,6 +64,10 @@
> /* QPHY_V3_PCS_MISC_CLAMP_ENABLE register bits */
> #define CLAMP_EN BIT(0) /* enables i/o clamp_n */
>
> +/* QPHY_V3_DP_COM_TYPEC_CTRL register bits */
> +#define SW_PORTSELECT_VAL BIT(0)
> +#define SW_PORTSELECT_MUX BIT(1)
> +
> #define PHY_INIT_COMPLETE_TIMEOUT 10000
>
> struct qmp_phy_init_tbl {
> @@ -1323,6 +1328,9 @@ struct qmp_combo {
> struct clk_fixed_rate pipe_clk_fixed;
> struct clk_hw dp_link_hw;
> struct clk_hw dp_pixel_hw;
> +
> + struct typec_switch_dev *sw;
> + enum typec_orientation orientation;
> };
>
> static void qmp_v3_dp_aux_init(struct qmp_combo *qmp);
> @@ -1955,7 +1963,8 @@ static void qmp_v3_configure_dp_tx(struct qmp_combo *qmp)
> static bool qmp_combo_configure_dp_mode(struct qmp_combo *qmp)
> {
> u32 val;
> - bool reverse = false;
> + bool reverse = qmp->orientation == TYPEC_ORIENTATION_REVERSE;
> + const struct phy_configure_opts_dp *dp_opts = &qmp->dp_opts;
>
> val = DP_PHY_PD_CTL_PWRDN | DP_PHY_PD_CTL_AUX_PWRDN |
> DP_PHY_PD_CTL_PLL_PWRDN | DP_PHY_PD_CTL_DP_CLAMP_EN;
> @@ -1974,10 +1983,18 @@ static bool qmp_combo_configure_dp_mode(struct qmp_combo *qmp)
> * if (orientation == ORIENTATION_CC2)
> * writel(0x4c, qmp->dp_dp_phy + QSERDES_V3_DP_PHY_MODE);
> */
> + if (dp_opts->lanes == 4 || reverse)
> + val |= DP_PHY_PD_CTL_LANE_0_1_PWRDN;
> + if (dp_opts->lanes == 4 || !reverse)
> + val |= DP_PHY_PD_CTL_LANE_2_3_PWRDN;
> +
> val |= DP_PHY_PD_CTL_LANE_2_3_PWRDN;
When "reverse" this implies 4 lanes, I think it's an accidental left
over from introducing the conditionals.
> writel(val, qmp->dp_dp_phy + QSERDES_DP_PHY_PD_CTL);
>
> - writel(0x5c, qmp->dp_dp_phy + QSERDES_DP_PHY_MODE);
> + if (reverse)
> + writel(0x4c, qmp->pcs + QSERDES_DP_PHY_MODE);
> + else
> + writel(0x5c, qmp->pcs + QSERDES_DP_PHY_MODE);
>
> return reverse;
> }
> @@ -2461,6 +2478,7 @@ static int qmp_combo_com_init(struct qmp_combo *qmp)
> {
> const struct qmp_phy_cfg *cfg = qmp->cfg;
> void __iomem *com = qmp->com;
> + u32 val;
> int ret;
>
> mutex_lock(&qmp->phy_mutex);
> @@ -2498,8 +2516,11 @@ static int qmp_combo_com_init(struct qmp_combo *qmp)
> SW_DPPHY_RESET_MUX | SW_DPPHY_RESET |
> SW_USB3PHY_RESET_MUX | SW_USB3PHY_RESET);
>
> - /* Default type-c orientation, i.e CC1 */
> - qphy_setbits(com, QPHY_V3_DP_COM_TYPEC_CTRL, 0x02);
> + /* Latch CC orientation based on reported state by TCPM */
> + val = SW_PORTSELECT_MUX;
> + if (qmp->orientation == TYPEC_ORIENTATION_REVERSE)
> + val |= SW_PORTSELECT_VAL;
> + qphy_setbits(com, QPHY_V3_DP_COM_TYPEC_CTRL, val);
>
> qphy_setbits(com, QPHY_V3_DP_COM_PHY_MODE_CTRL, USB3_MODE | DP_MODE);
>
> @@ -3338,6 +3359,53 @@ static struct phy *qmp_combo_phy_xlate(struct device *dev, struct of_phandle_arg
> return ERR_PTR(-EINVAL);
> }
>
> +#if IS_ENABLED(CONFIG_PHY_QCOM_QMP_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);
> + struct phy *dp_phy = qmp->dp_phy;
> + int ret = 0;
> +
> + dev_dbg(qmp->dev, "Toggling orientation current %d requested %d\n",
> + qmp->orientation, orientation);
> +
> + qmp->orientation = orientation;
> +
> + if (orientation == TYPEC_ORIENTATION_NONE) {
> + if (qmp->init_count)
> + ret = qmp_combo_dp_power_off(dp_phy);
> + } else {
> + if (!qmp->init_count)
> + ret = qmp_combo_dp_power_on(dp_phy);
> + }
This sequence is crashing my laptop, need some more time to debug the
actual cause.
Regards,
Bjorn
> +
> + return 0;
> +}
> +
> +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;
> + qmp->sw = typec_switch_register(dev, &sw_desc);
> + if (IS_ERR(qmp->sw)) {
> + dev_err(dev, "Error registering typec switch: %ld\n",
> + PTR_ERR(qmp->sw));
> + }
> +
> + return 0;
> +}
> +#else
> +static int qmp_combo_typec_switch_register(struct qmp_combo *qmp)
> +{
> + return 0;
> +}
> +#endif
> +
> static int qmp_combo_probe(struct platform_device *pdev)
> {
> struct qmp_combo *qmp;
> @@ -3428,6 +3496,10 @@ static int qmp_combo_probe(struct platform_device *pdev)
> else
> phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
>
> + ret = qmp_combo_typec_switch_register(qmp);
> + if (ret)
> + goto err_node_put;
> +
> of_node_put(usb_np);
> of_node_put(dp_np);
>
> --
> 2.39.2
>
next prev parent reply other threads:[~2023-04-18 12:54 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-13 11:34 [PATCH v5 00/14] Add Qualcomm PMIC TPCM support Bryan O'Donoghue
2023-04-13 11:34 ` [PATCH v5 01/14] dt-bindings: regulator: qcom,usb-vbus-regulator: Mark reg as required Bryan O'Donoghue
2023-04-16 17:43 ` Krzysztof Kozlowski
2023-04-13 11:34 ` [PATCH v5 02/14] dt-bindings: regulator: qcom,usb-vbus-regulator: Mark regulator-*-microamp required Bryan O'Donoghue
2023-04-13 11:34 ` [PATCH v5 03/14] dt-bindings: phy: qcom,sc7180-qmp-usb3-dp-phy: Add orientation-switch as optional Bryan O'Donoghue
2023-04-13 11:34 ` [PATCH v5 04/14] dt-bindings: phy: qcom,sc7180-qmp-usb3-dp-phy: Add ports as an optional Bryan O'Donoghue
2023-04-14 7:23 ` Marijn Suijten
2023-04-16 17:47 ` Krzysztof Kozlowski
2023-04-17 0:09 ` Bryan O'Donoghue
2023-04-17 6:16 ` Krzysztof Kozlowski
2023-04-13 11:34 ` [PATCH v5 05/14] dt-bindings: usb: Add Qualcomm PMIC Type-C YAML schema Bryan O'Donoghue
2023-04-14 7:27 ` Marijn Suijten
2023-04-16 17:49 ` Krzysztof Kozlowski
2023-04-13 11:34 ` [PATCH v5 06/14] dt-bindings: mfd: qcom,spmi-pmic: Add typec to SPMI device types Bryan O'Donoghue
2023-04-16 17:50 ` Krzysztof Kozlowski
2023-04-13 11:34 ` [PATCH v5 07/14] arm64: dts: qcom: sm8250: Define ports for qmpphy orientation-switching Bryan O'Donoghue
2023-04-13 11:34 ` [PATCH v5 08/14] arm64: dts: qcom: pm8150b: Add a TCPM description Bryan O'Donoghue
2023-04-13 11:34 ` [PATCH v5 09/14] arm64: dts: qcom: qrb5165-rb5: Switch on Type-C VBUS boost Bryan O'Donoghue
2023-04-13 11:34 ` [PATCH v5 10/14] arm64: dts: qcom: qrb5165-rb5: Switch on basic TCPM Bryan O'Donoghue
2023-04-13 11:34 ` [PATCH v5 11/14] arm64: dts: qcom: qrb5165-rb5: Switch on TCPM usb-role-switching for usb_1 Bryan O'Donoghue
2023-04-22 14:52 ` Konrad Dybcio
2023-04-22 14:53 ` Konrad Dybcio
2023-04-13 11:34 ` [PATCH v5 12/14] arm64: dts: qcom: qrb5165-rb5: Switch on TCPM orientation-switch for usb_1_qmpphy Bryan O'Donoghue
2023-04-13 11:34 ` [PATCH v5 13/14] usb: typec: qcom: Add Qualcomm PMIC TCPM support Bryan O'Donoghue
2023-04-24 13:11 ` Heikki Krogerus
2023-04-24 13:48 ` Bryan O'Donoghue
2023-04-13 11:34 ` [PATCH v5 14/14] phy: qcom-qmp: Register as a typec switch for orientation detection Bryan O'Donoghue
2023-04-18 12:57 ` Bjorn Andersson [this message]
2023-04-18 16:54 ` Bryan O'Donoghue
2023-04-13 14:19 ` [PATCH v5 00/14] Add Qualcomm PMIC TPCM support Luca Weiss
2023-04-13 15:08 ` Bryan O'Donoghue
2023-04-14 6:51 ` Luca Weiss
2023-04-17 0:30 ` Bryan O'Donoghue
2023-04-17 7:35 ` Luca Weiss
2023-04-17 10:04 ` Bryan O'Donoghue
2023-04-17 10:11 ` Bryan O'Donoghue
2023-04-21 10:26 ` Luca Weiss
2023-04-22 22:16 ` Bryan O'Donoghue
2023-04-25 7:29 ` Luca Weiss
2023-09-20 2:13 ` 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=20230418125723.r7fkxgrs2ncxbb7j@ripper \
--to=andersson@kernel.org \
--cc=bryan.odonoghue@linaro.org \
--cc=caleb.connolly@linaro.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.baryshkov@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=jackp@quicinc.com \
--cc=konrad.dybcio@linaro.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=robertom@qti.qualcomm.com \
--cc=robh+dt@kernel.org \
--cc=subbaram@quicinc.com \
--cc=wcheng@codeaurora.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox