linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Neil Armstrong <neil.armstrong@linaro.org>
Cc: Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Andy Gross <agross@kernel.org>,
	Bjorn Andersson <andersson@kernel.org>,
	Konrad Dybcio <konrad.dybcio@linaro.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Rob Herring <robh@kernel.org>,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org
Subject: Re: [PATCH RFC 3/7] usb: ucsi: glink: use the connector orientation GPIO to provide switch events
Date: Mon, 5 Jun 2023 13:45:50 +0300	[thread overview]
Message-ID: <ZH283tlyRffPMXGm@kuha.fi.intel.com> (raw)
In-Reply-To: <20230601-topic-sm8550-upstream-type-c-v1-3-d4d97b4d8bab@linaro.org>

On Thu, Jun 01, 2023 at 04:07:03PM +0200, Neil Armstrong wrote:
> On SM8550, the non-altmode orientation is not given anymore within
> altmode events, even with USB SVIDs events.
> 
> On the other side, the Type-C connector orientation is correctly
> reported by a signal from the PMIC.
> 
> Take this gpio signal when we detect some Type-C port activity
> to notify any Type-C switches tied to the Type-C port connectors.
> 
> Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>

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

> ---
>  drivers/usb/typec/ucsi/ucsi_glink.c | 52 ++++++++++++++++++++++++++++++++++++-
>  1 file changed, 51 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/ucsi/ucsi_glink.c b/drivers/usb/typec/ucsi/ucsi_glink.c
> index 1fe9cb5b6bd9..88491dbff7e3 100644
> --- a/drivers/usb/typec/ucsi/ucsi_glink.c
> +++ b/drivers/usb/typec/ucsi/ucsi_glink.c
> @@ -9,9 +9,13 @@
>  #include <linux/mutex.h>
>  #include <linux/property.h>
>  #include <linux/soc/qcom/pdr.h>
> +#include <linux/usb/typec_mux.h>
> +#include <linux/gpio/consumer.h>
>  #include <linux/soc/qcom/pmic_glink.h>
>  #include "ucsi.h"
>  
> +#define PMIC_GLINK_MAX_PORTS	2
> +
>  #define UCSI_BUF_SIZE                   48
>  
>  #define MSG_TYPE_REQ_RESP               1
> @@ -53,6 +57,9 @@ struct ucsi_notify_ind_msg {
>  struct pmic_glink_ucsi {
>  	struct device *dev;
>  
> +	struct gpio_desc *port_orientation[PMIC_GLINK_MAX_PORTS];
> +	struct typec_switch *port_switch[PMIC_GLINK_MAX_PORTS];
> +
>  	struct pmic_glink_client *client;
>  
>  	struct ucsi *ucsi;
> @@ -221,8 +228,20 @@ static void pmic_glink_ucsi_notify(struct work_struct *work)
>  	}
>  
>  	con_num = UCSI_CCI_CONNECTOR(cci);
> -	if (con_num)
> +	if (con_num) {
> +		if (con_num < PMIC_GLINK_MAX_PORTS &&
> +		    ucsi->port_orientation[con_num - 1]) {
> +			int orientation = gpiod_get_value(ucsi->port_orientation[con_num - 1]);
> +
> +			if (orientation >= 0) {
> +				typec_switch_set(ucsi->port_switch[con_num - 1],
> +						 orientation ? TYPEC_ORIENTATION_REVERSE
> +							     : TYPEC_ORIENTATION_NORMAL);
> +			}
> +		}
> +
>  		ucsi_connector_change(ucsi->ucsi, con_num);
> +	}
>  
>  	if (ucsi->sync_pending && cci & UCSI_CCI_BUSY) {
>  		ucsi->sync_val = -EBUSY;
> @@ -283,6 +302,7 @@ static int pmic_glink_ucsi_probe(struct auxiliary_device *adev,
>  {
>  	struct pmic_glink_ucsi *ucsi;
>  	struct device *dev = &adev->dev;
> +	struct fwnode_handle *fwnode;
>  	int ret;
>  
>  	ucsi = devm_kzalloc(dev, sizeof(*ucsi), GFP_KERNEL);
> @@ -310,6 +330,36 @@ static int pmic_glink_ucsi_probe(struct auxiliary_device *adev,
>  
>  	ucsi_set_drvdata(ucsi->ucsi, ucsi);
>  
> +	device_for_each_child_node(dev, fwnode) {
> +		u32 port;
> +
> +		ret = fwnode_property_read_u32(fwnode, "reg", &port);
> +		if (ret < 0) {
> +			dev_err(dev, "missing reg property of %pOFn\n", fwnode);
> +			return ret;
> +		}
> +
> +		if (port >= PMIC_GLINK_MAX_PORTS) {
> +			dev_warn(dev, "invalid connector number, ignoring\n");
> +			continue;
> +		}
> +
> +		ucsi->port_orientation[port] = devm_fwnode_gpiod_get(&adev->dev, fwnode,
> +								     "orientation",
> +								     GPIOD_IN, NULL);
> +		if (IS_ERR(ucsi->port_orientation[port]))
> +			return dev_err_probe(dev, PTR_ERR(ucsi->port_orientation[port]),
> +					     "unable to acquire orientation gpio\n");
> +
> +		if (!ucsi->port_orientation[port])
> +			continue;
> +
> +		ucsi->port_switch[port] = fwnode_typec_switch_get(fwnode);
> +		if (IS_ERR(ucsi->port_switch[port]))
> +			return dev_err_probe(dev, PTR_ERR(ucsi->port_switch[port]),
> +					"failed to acquire orientation-switch\n");
> +	}
> +
>  	ucsi->client = devm_pmic_glink_register_client(dev,
>  						       PMIC_GLINK_OWNER_USBC,
>  						       pmic_glink_ucsi_callback,
> 
> -- 
> 2.34.1

-- 
heikki

  reply	other threads:[~2023-06-05 10:46 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-01 14:07 [PATCH RFC 0/7] arm64: qcom: add Type-C Altmode support Neil Armstrong
2023-06-01 14:07 ` [PATCH RFC 1/7] dt-bindings: connector: usb-connector: add a gpio used to determine the Type-C port plug orientation Neil Armstrong
2023-06-03 18:46   ` Krzysztof Kozlowski
2023-06-03 20:22   ` Dmitry Baryshkov
2023-06-05  7:30     ` Neil Armstrong
2023-06-05 10:13       ` Dmitry Baryshkov
2023-06-01 14:07 ` [PATCH RFC 2/7] soc: qcom: pmic_glink_altmode: handle safe mode when disconnect Neil Armstrong
2023-06-01 14:07 ` [PATCH RFC 3/7] usb: ucsi: glink: use the connector orientation GPIO to provide switch events Neil Armstrong
2023-06-05 10:45   ` Heikki Krogerus [this message]
2023-06-01 14:07 ` [PATCH RFC 4/7] qcom: pmic_glink: enable altmode for SM8550 Neil Armstrong
2023-06-01 14:07 ` [PATCH RFC 5/7] arm64: dts: qcom: sm8550: add ports subnodes in usb/dp qmpphy node Neil Armstrong
2023-06-02  9:16   ` Konrad Dybcio
2023-06-01 14:07 ` [PATCH RFC 6/7] arm64: dts: qcom: sm8550-mtp: add pmic glink port/endpoints Neil Armstrong
2023-06-01 14:07 ` [PATCH RFC 7/7] arm64: dts: qcom: sm8550-qrd: " Neil Armstrong

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=ZH283tlyRffPMXGm@kuha.fi.intel.com \
    --to=heikki.krogerus@linux.intel.com \
    --cc=agross@kernel.org \
    --cc=andersson@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.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-usb@vger.kernel.org \
    --cc=neil.armstrong@linaro.org \
    --cc=robh+dt@kernel.org \
    --cc=robh@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 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).