From: Akash Kumar <akash.kumar@oss.qualcomm.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Bjorn Andersson <andersson@kernel.org>,
Konrad Dybcio <konradybcio@kernel.org>,
Rob Herring <robh@kernel.org>,
Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org
Subject: [PATCH v2 2/2] usb: typec: ucsi_ccg: Add CC orientation sensing via GPIO
Date: Mon, 23 Nov 2026 14:40:24 +0530 [thread overview]
Message-ID: <20261123091024.2214918-3-akash.kumar@oss.qualcomm.com> (raw)
In-Reply-To: <20261123091024.2214918-1-akash.kumar@oss.qualcomm.com>
The CCGx chip has no HPI register exposing CC polarity, so there is
no way for the driver to report typec_cap.orientation_aware or call
typec_set_orientation() from UCSI status alone. On boards that wire
a sense line to the connector, pick it up via the orientation-gpios
property and use it to report orientation.
Acquire an optional "orientation" GPIO for each connector child node
in ucsi_ccg_probe(), indexed by the connector's reg property. Add
update_connector and connector_status ops that mark the connector
orientation_aware when a GPIO is present, and drive
typec_set_orientation() from the GPIO value while connected.
Signed-off-by: Akash Kumar <akash.kumar@oss.qualcomm.com>
---
Changes in v2:
- Return early when the GPIO read fails instead of wrapping
typec_set_orientation() in a positive-case conditional, avoiding the
wrapped ternary continuation lines entirely (Heikki Krogerus).
drivers/usb/typec/ucsi/ucsi_ccg.c | 77 ++++++++++++++++++++++++++++++-
1 file changed, 76 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/typec/ucsi/ucsi_ccg.c b/drivers/usb/typec/ucsi/ucsi_ccg.c
index c560d4539302..06c536d87694 100644
--- a/drivers/usb/typec/ucsi/ucsi_ccg.c
+++ b/drivers/usb/typec/ucsi/ucsi_ccg.c
@@ -10,6 +10,7 @@
#include <linux/acpi.h>
#include <linux/delay.h>
#include <linux/firmware.h>
+#include <linux/gpio/consumer.h>
#include <linux/hex.h>
#include <linux/i2c.h>
#include <linux/module.h>
@@ -17,6 +18,7 @@
#include <linux/platform_device.h>
#include <linux/pm.h>
#include <linux/pm_runtime.h>
+#include <linux/property.h>
#include <linux/usb/typec_dp.h>
#include <linux/unaligned.h>
@@ -201,6 +203,9 @@ struct op_region {
__le32 message_in[CCGX_MESSAGE_IN_MAX];
};
+/* CCGx can expose at most 2 PD ports per chip */
+#define CCG_MAX_PORTS 2
+
struct ucsi_ccg {
struct device *dev;
struct ucsi *ucsi;
@@ -235,6 +240,15 @@ struct ucsi_ccg {
*/
spinlock_t op_lock;
struct op_region op_data;
+
+ /*
+ * Optional per-connector CC-orientation GPIO ("orientation-gpios"
+ * on the controller node). Not part of the UCSI spec's connector
+ * status - the CCGx chip has no HPI register exposing CC polarity,
+ * so orientation must come from a board-level sense line if one
+ * exists. Left NULL (orientation_aware stays false) when absent.
+ */
+ struct gpio_desc *orientation_gpio[CCG_MAX_PORTS];
};
static int ccg_read(struct ucsi_ccg *uc, u16 rab, u8 *data, u32 len)
@@ -694,6 +708,37 @@ static int ucsi_ccg_sync_control(struct ucsi *ucsi, u64 command, u32 *cci,
return ret;
}
+static void ucsi_ccg_update_connector(struct ucsi_connector *con)
+{
+ struct ucsi_ccg *uc = ucsi_get_drvdata(con->ucsi);
+
+ if (con->num > CCG_MAX_PORTS || !uc->orientation_gpio[con->num - 1])
+ return;
+
+ con->typec_cap.orientation_aware = true;
+}
+
+static void ucsi_ccg_connector_status(struct ucsi_connector *con)
+{
+ struct ucsi_ccg *uc = ucsi_get_drvdata(con->ucsi);
+ int orientation;
+
+ if (!UCSI_CONSTAT(con, CONNECTED)) {
+ typec_set_orientation(con->port, TYPEC_ORIENTATION_NONE);
+ return;
+ }
+
+ if (con->num > CCG_MAX_PORTS || !uc->orientation_gpio[con->num - 1])
+ return;
+
+ orientation = gpiod_get_value_cansleep(uc->orientation_gpio[con->num - 1]);
+ if (orientation < 0)
+ return;
+
+ typec_set_orientation(con->port, orientation ? TYPEC_ORIENTATION_REVERSE :
+ TYPEC_ORIENTATION_NORMAL);
+}
+
static const struct ucsi_operations ucsi_ccg_ops = {
.read_version = ucsi_ccg_read_version,
.read_cci = ucsi_ccg_read_cci,
@@ -701,7 +746,9 @@ static const struct ucsi_operations ucsi_ccg_ops = {
.read_message_in = ucsi_ccg_read_message_in,
.sync_control = ucsi_ccg_sync_control,
.async_control = ucsi_ccg_async_control,
- .update_altmodes = ucsi_ccg_update_altmodes
+ .update_altmodes = ucsi_ccg_update_altmodes,
+ .update_connector = ucsi_ccg_update_connector,
+ .connector_status = ucsi_ccg_connector_status,
};
static irqreturn_t ccg_irq_handler(int irq, void *data)
@@ -1506,6 +1553,34 @@ static int ucsi_ccg_probe(struct i2c_client *client)
if (uc->info.mode & CCG_DEVINFO_PDPORTS_MASK)
uc->port_num++;
+ device_for_each_child_node_scoped(dev, fwnode) {
+ struct gpio_desc *desc;
+ u32 port;
+
+ status = fwnode_property_read_u32(fwnode, "reg", &port);
+ if (status < 0) {
+ dev_err(dev, "missing reg property of %pOFn\n", fwnode);
+ return status;
+ }
+
+ if (port >= CCG_MAX_PORTS) {
+ dev_warn(dev, "invalid connector number, ignoring\n");
+ continue;
+ }
+
+ desc = devm_gpiod_get_index_optional(dev, "orientation", port, GPIOD_IN);
+
+ /* If GPIO isn't found, continue */
+ if (!desc)
+ continue;
+
+ if (IS_ERR(desc))
+ return dev_err_probe(dev, PTR_ERR(desc),
+ "unable to acquire orientation gpio\n");
+
+ uc->orientation_gpio[port] = desc;
+ }
+
uc->ucsi = ucsi_create(dev, &ucsi_ccg_ops);
if (IS_ERR(uc->ucsi))
return PTR_ERR(uc->ucsi);
--
2.43.0
next prev parent reply other threads:[~2026-11-23 9:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 9:10 [PATCH v2 0/2] " Akash Kumar
2026-11-23 9:10 ` [PATCH v2 1/2] dt-bindings: usb: cypress,cypd4226: Add orientation-gpios property Akash Kumar
2026-11-23 9:10 ` Akash Kumar [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-11-17 14:09 [PATCH v2 0/2] usb: typec: ucsi_ccg: Add CC orientation-gpios support Akash Kumar
2026-11-17 14:09 ` [PATCH v2 2/2] usb: typec: ucsi_ccg: Add CC orientation sensing via GPIO Akash Kumar
2026-11-20 14:51 ` 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=20261123091024.2214918-3-akash.kumar@oss.qualcomm.com \
--to=akash.kumar@oss.qualcomm.com \
--cc=andersson@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.baryshkov@oss.qualcomm.com \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=konradybcio@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.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
all inboxes | Powered by JetHome®