From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Guenter Roeck <linux@roeck-us.net>,
Bjorn Andersson <andersson@kernel.org>,
Neil Armstrong <neil.armstrong@linaro.org>,
Konrad Dybcio <konrad.dybcio@linaro.org>,
Johan Hovold <johan+linaro@kernel.org>,
linux-usb@vger.kernel.org, linux-arm-msm@vger.kernel.org
Subject: Re: [PATCH v2 07/11] usb: typec: ucsi: support delaying GET_PDOS for device
Date: Tue, 2 Apr 2024 14:04:28 +0300 [thread overview]
Message-ID: <ZgvmPPUEaqyOLchN@kuha.fi.intel.com> (raw)
In-Reply-To: <20240329-qcom-ucsi-fixes-v2-7-0f5d37ed04db@linaro.org>
On Fri, Mar 29, 2024 at 08:15:39AM +0200, Dmitry Baryshkov wrote:
> Qualcomm firmware doesn't return sane information for device's PDOs
> unless the partner is also using a PD mode. On SC8280XP this even
> results in the Error bit being set in the UCSI response (with 0 error
> status).
>
> Add a quirk to delay reading USB PD capabilities for a device until we
> detect a partner in PD mode.
>
> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> ---
> drivers/usb/typec/ucsi/ucsi.c | 41 ++++++++++++++++++++++++++++-------------
> drivers/usb/typec/ucsi/ucsi.h | 1 +
> 2 files changed, 29 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index 18b2e4ffc57e..f5ec776b84d6 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -821,6 +821,28 @@ static int ucsi_check_altmodes(struct ucsi_connector *con)
> return ret;
> }
>
> +static void ucsi_register_device_pdos(struct ucsi_connector *con)
> +{
> + struct ucsi *ucsi = con->ucsi;
> + struct usb_power_delivery_desc desc = { ucsi->cap.pd_version };
> + struct usb_power_delivery_capabilities *pd_cap;
> +
> + if (con->pd)
> + return;
> +
> + con->pd = usb_power_delivery_register(ucsi->dev, &desc);
> +
> + pd_cap = ucsi_get_pd_caps(con, TYPEC_SOURCE, false);
> + if (!IS_ERR(pd_cap))
> + con->port_source_caps = pd_cap;
> +
> + pd_cap = ucsi_get_pd_caps(con, TYPEC_SINK, false);
> + if (!IS_ERR(pd_cap))
> + con->port_sink_caps = pd_cap;
> +
> + typec_port_set_usb_power_delivery(con->port, con->pd);
> +}
> +
> static int ucsi_register_partner_pdos(struct ucsi_connector *con)
> {
> struct usb_power_delivery_desc desc = { con->ucsi->cap.pd_version };
> @@ -981,6 +1003,9 @@ static int ucsi_register_partner(struct ucsi_connector *con)
> break;
> }
>
> + if (pwr_opmode == UCSI_CONSTAT_PWR_OPMODE_PD)
> + ucsi_register_device_pdos(con);
> +
> desc.identity = &con->partner_identity;
> desc.usb_pd = pwr_opmode == UCSI_CONSTAT_PWR_OPMODE_PD;
> desc.pd_revision = UCSI_CONCAP_FLAG_PARTNER_PD_MAJOR_REV_AS_BCD(con->cap.flags);
> @@ -1465,8 +1490,6 @@ static struct fwnode_handle *ucsi_find_fwnode(struct ucsi_connector *con)
>
> static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con)
> {
> - struct usb_power_delivery_desc desc = { ucsi->cap.pd_version};
> - struct usb_power_delivery_capabilities *pd_cap;
> struct typec_capability *cap = &con->typec_cap;
> enum typec_accessory *accessory = cap->accessory;
> enum usb_role u_role = USB_ROLE_NONE;
> @@ -1544,17 +1567,8 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con)
> goto out;
> }
>
> - con->pd = usb_power_delivery_register(ucsi->dev, &desc);
> -
> - pd_cap = ucsi_get_pd_caps(con, TYPEC_SOURCE, false);
> - if (!IS_ERR(pd_cap))
> - con->port_source_caps = pd_cap;
> -
> - pd_cap = ucsi_get_pd_caps(con, TYPEC_SINK, false);
> - if (!IS_ERR(pd_cap))
> - con->port_sink_caps = pd_cap;
> -
> - typec_port_set_usb_power_delivery(con->port, con->pd);
> + if (!(ucsi->quirks & UCSI_DELAY_DEVICE_PDOS))
> + ucsi_register_device_pdos(con);
>
> /* Alternate modes */
> ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_CON);
> @@ -1617,6 +1631,7 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con)
> if (con->partner &&
> UCSI_CONSTAT_PWR_OPMODE(con->status.flags) ==
> UCSI_CONSTAT_PWR_OPMODE_PD) {
> + ucsi_register_device_pdos(con);
> ucsi_get_src_pdos(con);
> ucsi_check_altmodes(con);
> }
> diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h
> index 591f734d457b..2caf2969668c 100644
> --- a/drivers/usb/typec/ucsi/ucsi.h
> +++ b/drivers/usb/typec/ucsi/ucsi.h
> @@ -406,6 +406,7 @@ struct ucsi {
>
> unsigned long quirks;
> #define UCSI_NO_PARTNER_PDOS BIT(0) /* Don't read partner's PDOs */
> +#define UCSI_DELAY_DEVICE_PDOS BIT(1) /* Reading PDOs fails until the parter is in PD mode */
> };
>
> #define UCSI_MAX_SVID 5
>
> --
> 2.39.2
--
heikki
next prev parent reply other threads:[~2024-04-02 11:04 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-29 6:15 [PATCH v2 00/11] usb: typec: ucsi: fix several issues manifesting on Qualcomm platforms Dmitry Baryshkov
2024-03-29 6:15 ` [PATCH v2 01/11] usb: typec: ucsi: allow non-partner GET_PDOS for Qualcomm devices Dmitry Baryshkov
2024-03-29 6:15 ` [PATCH v2 02/11] usb: typec: ucsi: limit the UCSI_NO_PARTNER_PDOS even further Dmitry Baryshkov
2024-03-29 6:15 ` [PATCH v2 03/11] usb: typec: ucsi: properly register partner's PD device Dmitry Baryshkov
2024-03-29 6:15 ` [PATCH v2 04/11] usb: typec: ucsi: always register a link to USB " Dmitry Baryshkov
2024-04-02 10:38 ` Heikki Krogerus
2024-03-29 6:15 ` [PATCH v2 05/11] usb: typec: ucsi: simplify partner's PD caps registration Dmitry Baryshkov
2024-04-02 10:40 ` Heikki Krogerus
2024-03-29 6:15 ` [PATCH v2 06/11] usb: typec: ucsi: extract code to read PD caps Dmitry Baryshkov
2024-04-02 10:41 ` Heikki Krogerus
2024-03-29 6:15 ` [PATCH v2 07/11] usb: typec: ucsi: support delaying GET_PDOS for device Dmitry Baryshkov
2024-04-02 11:04 ` Heikki Krogerus [this message]
2024-03-29 6:15 ` [PATCH v2 08/11] usb: typec: ucsi_glink: rework quirks implementation Dmitry Baryshkov
2024-04-02 11:06 ` Heikki Krogerus
2024-03-29 6:15 ` [PATCH v2 09/11] usb: typec: ucsi_glink: enable the UCSI_DELAY_DEVICE_PDOS quirk Dmitry Baryshkov
2024-04-02 11:07 ` Heikki Krogerus
2024-03-29 6:15 ` [PATCH v2 10/11] soc: qcom: pmic_glink: reenable UCSI on sc8280xp Dmitry Baryshkov
2024-03-29 6:15 ` [PATCH v2 11/11] soc: qcom: pmic_glink: enable UCSI on sc8180x Dmitry Baryshkov
2024-04-02 11:07 ` 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=ZgvmPPUEaqyOLchN@kuha.fi.intel.com \
--to=heikki.krogerus@linux.intel.com \
--cc=andersson@kernel.org \
--cc=dmitry.baryshkov@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=johan+linaro@kernel.org \
--cc=konrad.dybcio@linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=neil.armstrong@linaro.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;
as well as URLs for NNTP newsgroup(s).