All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
To: Heikki Krogerus <heikki.krogerus@linux.intel.com>,
	 Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	 Neil Armstrong <neil.armstrong@linaro.org>,
	 Bjorn Andersson <andersson@kernel.org>,
	 Konrad Dybcio <konrad.dybcio@linaro.org>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	 linux-arm-msm@vger.kernel.org,
	 Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Subject: [PATCH 2/8] usb: typec: altmode: add low level altmode configuration helper
Date: Tue, 16 Apr 2024 05:20:51 +0300	[thread overview]
Message-ID: <20240416-ucsi-glink-altmode-v1-2-890db00877ac@linaro.org> (raw)
In-Reply-To: <20240416-ucsi-glink-altmode-v1-0-890db00877ac@linaro.org>

In some obscure cases (Qualcomm PMIC Glink) altmode is completely
handled by the firmware. Linux does not get proper partner altmode info.
Instead we get the notification once the altmode is negotiated and
entered (or left). However even in such a case the driver has to switch
board components (muxes, switches and retimers) according to the altmode
selected by the hardware.

We can not use existing typec_altmode_enter() / typec_altmode_exit() /
typec_altmode_notify() functions in such a case, since there is no
corresponding partner's altmode instance.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
 drivers/usb/typec/bus.c           | 34 ++++++++++++++++++++++++++++++++++
 include/linux/usb/typec_altmode.h |  3 +++
 2 files changed, 37 insertions(+)

diff --git a/drivers/usb/typec/bus.c b/drivers/usb/typec/bus.c
index 6ea103e1abae..68f3908401c6 100644
--- a/drivers/usb/typec/bus.c
+++ b/drivers/usb/typec/bus.c
@@ -67,6 +67,40 @@ static int typec_altmode_set_state(struct typec_altmode *adev,
 	return typec_altmode_set_switches(port_altmode, conf, data);
 }
 
+/**
+ * typec_altmode_set_port - set the altmode configuration
+ * @conf: Alternate mode specific configuration value
+ * @dVata: Alternate mode specific data
+ *
+ * This function allows configuring muxes and retimer for the selected altmode.
+ * This function may only be used by the special case drivers, that handle
+ * the altmode negotiation by the alternative means and thus have no
+ * corresponding typec_altmode instance for the parnter.
+ */
+int typec_altmode_set_port(struct typec_altmode *adev,
+			   unsigned long conf, void *data)
+{
+	bool is_port;
+	struct altmode *altmode;
+	int ret;
+
+	if (!adev)
+		return 0;
+
+	altmode = to_altmode(adev);
+	is_port = is_typec_port(adev->dev.parent);
+
+	if (altmode->partner || !is_port)
+		return -EINVAL;
+
+	ret = typec_altmode_set_switches(altmode, conf, data);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(typec_altmode_set_port);
+
 /* -------------------------------------------------------------------------- */
 /* Common API */
 
diff --git a/include/linux/usb/typec_altmode.h b/include/linux/usb/typec_altmode.h
index b3c0866ea70f..d78a9618bedf 100644
--- a/include/linux/usb/typec_altmode.h
+++ b/include/linux/usb/typec_altmode.h
@@ -77,6 +77,9 @@ int typec_altmode_notify(struct typec_altmode *altmode, unsigned long conf,
 const struct typec_altmode *
 typec_altmode_get_partner(struct typec_altmode *altmode);
 
+int typec_altmode_set_port(struct typec_altmode *altmode, unsigned long conf,
+			   void *data);
+
 /**
  * struct typec_cable_ops - Cable alternate mode operations vector
  * @enter: Operations to be executed with Enter Mode Command

-- 
2.39.2


  parent reply	other threads:[~2024-04-16  2:20 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-16  2:20 [PATCH 0/8] usb: typec: ucsi: glink: merge in altmode support Dmitry Baryshkov
2024-04-16  2:20 ` [PATCH 1/8] usb: typec: Handle retimers in typec_set_mode() Dmitry Baryshkov
2024-04-16 14:30   ` Konrad Dybcio
2024-04-16 17:26   ` Neil Armstrong
2024-04-22  8:00   ` Heikki Krogerus
2024-04-16  2:20 ` Dmitry Baryshkov [this message]
2024-04-16 14:32   ` [PATCH 2/8] usb: typec: altmode: add low level altmode configuration helper Konrad Dybcio
2024-04-16 14:48     ` Dmitry Baryshkov
2024-04-16 14:57       ` Konrad Dybcio
2024-04-16 15:20         ` Dmitry Baryshkov
2024-04-16  2:20 ` [PATCH 3/8] usb: typec: ucsi: glink: check message data sizes Dmitry Baryshkov
2024-04-16 14:33   ` Konrad Dybcio
2024-04-16 14:49     ` Dmitry Baryshkov
2024-04-16  2:20 ` [PATCH 4/8] usb: typec: ucsi: glink: use le32 for message data Dmitry Baryshkov
2024-04-16 14:34   ` Konrad Dybcio
2024-04-16 17:28   ` Neil Armstrong
2024-04-22 10:29   ` Heikki Krogerus
2024-04-16  2:20 ` [PATCH 5/8] usb: typec: ucsi: glink: simplify notification handling Dmitry Baryshkov
2024-04-16 14:36   ` Konrad Dybcio
2024-04-16 15:15     ` Dmitry Baryshkov
2024-04-16  2:20 ` [PATCH 6/8] usb: typec: ucsi: add ucsi_registered() callback Dmitry Baryshkov
2024-04-16  2:20 ` [PATCH 7/8] usb: typec: ucsi: glink: merge pmic_glink_altmode driver Dmitry Baryshkov
2024-04-22 10:59   ` Heikki Krogerus
2024-04-22 12:45     ` Dmitry Baryshkov
2024-04-22 15:02       ` Heikki Krogerus
2024-04-22 15:22         ` Dmitry Baryshkov
2024-05-04  6:49         ` Dmitry Baryshkov
2024-05-15 15:01           ` Dmitry Baryshkov
2024-05-16  8:18             ` Heikki Krogerus
2024-04-16  2:20 ` [PATCH 8/8] soc: qcom: pmic-glink: drop separate altmode driver support Dmitry Baryshkov

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=20240416-ucsi-glink-altmode-v1-2-890db00877ac@linaro.org \
    --to=dmitry.baryshkov@linaro.org \
    --cc=andersson@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=konrad.dybcio@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 \
    /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.