* [patch v4 1/4] usb: typec: Stub out typec_switch APIs when CONFIG_TYPEC=n
@ 2025-08-15 9:47 Xu Yang
2025-08-15 9:47 ` [patch v4 2/4] dt-bindings: extcon: ptn5150: Allow "connector" node to present Xu Yang
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Xu Yang @ 2025-08-15 9:47 UTC (permalink / raw)
To: krzk, myungjoo.ham, cw00.choi, robh, conor+dt, gregkh
Cc: swboyd, heikki.krogerus, devicetree, imx, jun.li
From: Stephen Boyd <swboyd@chromium.org>
Ease driver development by adding stubs for the typec_switch APIs when
CONFIG_TYPEC=n. Copy the same method used for the typec_mux APIs to be
consistent.
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---
Changes in v4:
- no changes
Changes in v3:
- add my Signed-off-by
- add Acked-by tag
Changes in v2:
- pick up this patch to fix build error in v1
- refer to https://lore.kernel.org/linux-usb/Ztb1sI2W7t5k2yT7@kuha.fi.intel.com/
---
include/linux/usb/typec_mux.h | 43 +++++++++++++++++++++++++++++++----
1 file changed, 38 insertions(+), 5 deletions(-)
diff --git a/include/linux/usb/typec_mux.h b/include/linux/usb/typec_mux.h
index 2489a7857d8e..efb5ed32b813 100644
--- a/include/linux/usb/typec_mux.h
+++ b/include/linux/usb/typec_mux.h
@@ -3,6 +3,7 @@
#ifndef __USB_TYPEC_MUX
#define __USB_TYPEC_MUX
+#include <linux/err.h>
#include <linux/property.h>
#include <linux/usb/typec.h>
@@ -24,16 +25,13 @@ struct typec_switch_desc {
void *drvdata;
};
+#if IS_ENABLED(CONFIG_TYPEC)
+
struct typec_switch *fwnode_typec_switch_get(struct fwnode_handle *fwnode);
void typec_switch_put(struct typec_switch *sw);
int typec_switch_set(struct typec_switch *sw,
enum typec_orientation orientation);
-static inline struct typec_switch *typec_switch_get(struct device *dev)
-{
- return fwnode_typec_switch_get(dev_fwnode(dev));
-}
-
struct typec_switch_dev *
typec_switch_register(struct device *parent,
const struct typec_switch_desc *desc);
@@ -42,6 +40,41 @@ void typec_switch_unregister(struct typec_switch_dev *sw);
void typec_switch_set_drvdata(struct typec_switch_dev *sw, void *data);
void *typec_switch_get_drvdata(struct typec_switch_dev *sw);
+#else
+
+static inline struct typec_switch *
+fwnode_typec_switch_get(struct fwnode_handle *fwnode)
+{
+ return NULL;
+}
+static inline void typec_switch_put(struct typec_switch *sw) {}
+static inline int typec_switch_set(struct typec_switch *sw,
+ enum typec_orientation orientation)
+{
+ return 0;
+}
+
+static inline struct typec_switch_dev *
+typec_switch_register(struct device *parent,
+ const struct typec_switch_desc *desc)
+{
+ return ERR_PTR(-EOPNOTSUPP);
+}
+static inline void typec_switch_unregister(struct typec_switch_dev *sw) {}
+
+static inline void typec_switch_set_drvdata(struct typec_switch_dev *sw, void *data) {}
+static inline void *typec_switch_get_drvdata(struct typec_switch_dev *sw)
+{
+ return ERR_PTR(-EOPNOTSUPP);
+}
+
+#endif /* CONFIG_TYPEC */
+
+static inline struct typec_switch *typec_switch_get(struct device *dev)
+{
+ return fwnode_typec_switch_get(dev_fwnode(dev));
+}
+
struct typec_mux_state {
struct typec_altmode *alt;
unsigned long mode;
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [patch v4 2/4] dt-bindings: extcon: ptn5150: Allow "connector" node to present
2025-08-15 9:47 [patch v4 1/4] usb: typec: Stub out typec_switch APIs when CONFIG_TYPEC=n Xu Yang
@ 2025-08-15 9:47 ` Xu Yang
2025-08-15 9:47 ` [patch v4 3/4] extcon: ptn5150: Add Type-C orientation switch support Xu Yang
2025-08-15 9:47 ` [patch v4 4/4] extcon: ptn5150: Support USB role switch via connector fwnode Xu Yang
2 siblings, 0 replies; 4+ messages in thread
From: Xu Yang @ 2025-08-15 9:47 UTC (permalink / raw)
To: krzk, myungjoo.ham, cw00.choi, robh, conor+dt, gregkh
Cc: swboyd, heikki.krogerus, devicetree, imx, jun.li
PTN5150 is usually used with a Type-C connector, so allow a "connector"
node to be defined under it.
Acked-by: Rob Herring (Arm) <robh@kernel.org>
Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
---
Changes in v4:
- no changes
Changes in v3:
- add Acked-by tag
Changes in v2:
- improve commit message
---
Documentation/devicetree/bindings/extcon/extcon-ptn5150.yaml | 3 +++
1 file changed, 3 insertions(+)
diff --git a/Documentation/devicetree/bindings/extcon/extcon-ptn5150.yaml b/Documentation/devicetree/bindings/extcon/extcon-ptn5150.yaml
index 072b3c0c5fd0..79f88b5f4e5c 100644
--- a/Documentation/devicetree/bindings/extcon/extcon-ptn5150.yaml
+++ b/Documentation/devicetree/bindings/extcon/extcon-ptn5150.yaml
@@ -42,6 +42,9 @@ properties:
description:
A port node to link the usb controller for the dual role switch.
+ connector:
+ $ref: /schemas/connector/usb-connector.yaml#
+
required:
- compatible
- interrupts
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [patch v4 3/4] extcon: ptn5150: Add Type-C orientation switch support
2025-08-15 9:47 [patch v4 1/4] usb: typec: Stub out typec_switch APIs when CONFIG_TYPEC=n Xu Yang
2025-08-15 9:47 ` [patch v4 2/4] dt-bindings: extcon: ptn5150: Allow "connector" node to present Xu Yang
@ 2025-08-15 9:47 ` Xu Yang
2025-08-15 9:47 ` [patch v4 4/4] extcon: ptn5150: Support USB role switch via connector fwnode Xu Yang
2 siblings, 0 replies; 4+ messages in thread
From: Xu Yang @ 2025-08-15 9:47 UTC (permalink / raw)
To: krzk, myungjoo.ham, cw00.choi, robh, conor+dt, gregkh
Cc: swboyd, heikki.krogerus, devicetree, imx, jun.li
PTN5150 is able to detect CC polarity. The field[1:0] of CC status
register (04H) will keep the result.
00: Cable Not Attached
01: CC1 is connected (normal orientation)
10: CC2 is connected (reversed orientation)
11: Reserved
Add orientation switch support to correctly set orientation of
multiplexer according to CC status.
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
---
Changes in v4:
- add Rb tag
Changes in v3:
- no changes
Changes in v2:
- move "enum typec_orientation orient" ahead
- improve commit message
---
drivers/extcon/Kconfig | 1 +
drivers/extcon/extcon-ptn5150.c | 40 +++++++++++++++++++++++++++++++++
2 files changed, 41 insertions(+)
diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
index a6f6d467aacf..fd4ec5dda0b7 100644
--- a/drivers/extcon/Kconfig
+++ b/drivers/extcon/Kconfig
@@ -145,6 +145,7 @@ config EXTCON_PTN5150
tristate "NXP PTN5150 CC LOGIC USB EXTCON support"
depends on I2C && (GPIOLIB || COMPILE_TEST)
depends on USB_ROLE_SWITCH || !USB_ROLE_SWITCH
+ depends on TYPEC || !TYPEC
select REGMAP_I2C
help
Say Y here to enable support for USB peripheral and USB host
diff --git a/drivers/extcon/extcon-ptn5150.c b/drivers/extcon/extcon-ptn5150.c
index 78ad86c4a3be..768428d306ce 100644
--- a/drivers/extcon/extcon-ptn5150.c
+++ b/drivers/extcon/extcon-ptn5150.c
@@ -18,6 +18,7 @@
#include <linux/extcon-provider.h>
#include <linux/gpio/consumer.h>
#include <linux/usb/role.h>
+#include <linux/usb/typec_mux.h>
/* PTN5150 registers */
#define PTN5150_REG_DEVICE_ID 0x01
@@ -38,7 +39,11 @@
#define PTN5150_REG_DEVICE_ID_VERSION GENMASK(7, 3)
#define PTN5150_REG_DEVICE_ID_VENDOR GENMASK(2, 0)
+#define PTN5150_POLARITY_CC1 0x1
+#define PTN5150_POLARITY_CC2 0x2
+
#define PTN5150_REG_CC_PORT_ATTACHMENT GENMASK(4, 2)
+#define PTN5150_REG_CC_POLARITY GENMASK(1, 0)
#define PTN5150_REG_CC_VBUS_DETECTION BIT(7)
#define PTN5150_REG_INT_CABLE_ATTACH_MASK BIT(0)
#define PTN5150_REG_INT_CABLE_DETACH_MASK BIT(1)
@@ -53,6 +58,7 @@ struct ptn5150_info {
int irq;
struct work_struct irq_work;
struct mutex mutex;
+ struct typec_switch *orient_sw;
struct usb_role_switch *role_sw;
};
@@ -71,6 +77,7 @@ static const struct regmap_config ptn5150_regmap_config = {
static void ptn5150_check_state(struct ptn5150_info *info)
{
+ enum typec_orientation orient = TYPEC_ORIENTATION_NONE;
unsigned int port_status, reg_data, vbus;
enum usb_role usb_role = USB_ROLE_NONE;
int ret;
@@ -81,6 +88,23 @@ static void ptn5150_check_state(struct ptn5150_info *info)
return;
}
+ orient = FIELD_GET(PTN5150_REG_CC_POLARITY, reg_data);
+ switch (orient) {
+ case PTN5150_POLARITY_CC1:
+ orient = TYPEC_ORIENTATION_NORMAL;
+ break;
+ case PTN5150_POLARITY_CC2:
+ orient = TYPEC_ORIENTATION_REVERSE;
+ break;
+ default:
+ orient = TYPEC_ORIENTATION_NONE;
+ break;
+ }
+
+ ret = typec_switch_set(info->orient_sw, orient);
+ if (ret)
+ dev_err(info->dev, "failed to set orientation: %d\n", ret);
+
port_status = FIELD_GET(PTN5150_REG_CC_PORT_ATTACHMENT, reg_data);
switch (port_status) {
@@ -152,6 +176,12 @@ static void ptn5150_irq_work(struct work_struct *work)
dev_err(info->dev,
"failed to set none role: %d\n",
ret);
+
+ ret = typec_switch_set(info->orient_sw,
+ TYPEC_ORIENTATION_NONE);
+ if (ret)
+ dev_err(info->dev,
+ "failed to set orientation: %d\n", ret);
}
}
@@ -219,12 +249,14 @@ static void ptn5150_work_sync_and_put(void *data)
cancel_work_sync(&info->irq_work);
usb_role_switch_put(info->role_sw);
+ typec_switch_put(info->orient_sw);
}
static int ptn5150_i2c_probe(struct i2c_client *i2c)
{
struct device *dev = &i2c->dev;
struct device_node *np = i2c->dev.of_node;
+ struct fwnode_handle *connector;
struct ptn5150_info *info;
int ret;
@@ -311,6 +343,14 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c)
if (ret)
return -EINVAL;
+ connector = device_get_named_child_node(dev, "connector");
+ if (connector) {
+ info->orient_sw = fwnode_typec_switch_get(connector);
+ if (IS_ERR(info->orient_sw))
+ return dev_err_probe(info->dev, PTR_ERR(info->orient_sw),
+ "failed to get orientation switch\n");
+ }
+
info->role_sw = usb_role_switch_get(info->dev);
if (IS_ERR(info->role_sw))
return dev_err_probe(info->dev, PTR_ERR(info->role_sw),
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [patch v4 4/4] extcon: ptn5150: Support USB role switch via connector fwnode
2025-08-15 9:47 [patch v4 1/4] usb: typec: Stub out typec_switch APIs when CONFIG_TYPEC=n Xu Yang
2025-08-15 9:47 ` [patch v4 2/4] dt-bindings: extcon: ptn5150: Allow "connector" node to present Xu Yang
2025-08-15 9:47 ` [patch v4 3/4] extcon: ptn5150: Add Type-C orientation switch support Xu Yang
@ 2025-08-15 9:47 ` Xu Yang
2 siblings, 0 replies; 4+ messages in thread
From: Xu Yang @ 2025-08-15 9:47 UTC (permalink / raw)
To: krzk, myungjoo.ham, cw00.choi, robh, conor+dt, gregkh
Cc: swboyd, heikki.krogerus, devicetree, imx, jun.li
Since the PTN5150 is a Type-C chip, it's common to describe related
properties under the connector node. To align with this, the port
node will be located under the connector node in the future.
To support this layout, retrieve the USB role switch using the
connector's fwnode. For compatibility with existing device trees,
keep the usb_role_switch_get() function.
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
---
Changes in v4:
- add Rb tag
Changes in v3:
- no changes
Changes in v2:
- improve commit message
---
drivers/extcon/extcon-ptn5150.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/extcon/extcon-ptn5150.c b/drivers/extcon/extcon-ptn5150.c
index 768428d306ce..f33f80e103c2 100644
--- a/drivers/extcon/extcon-ptn5150.c
+++ b/drivers/extcon/extcon-ptn5150.c
@@ -352,6 +352,8 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c)
}
info->role_sw = usb_role_switch_get(info->dev);
+ if (!info->role_sw && connector)
+ info->role_sw = fwnode_usb_role_switch_get(connector);
if (IS_ERR(info->role_sw))
return dev_err_probe(info->dev, PTR_ERR(info->role_sw),
"failed to get role switch\n");
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-08-15 9:48 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-15 9:47 [patch v4 1/4] usb: typec: Stub out typec_switch APIs when CONFIG_TYPEC=n Xu Yang
2025-08-15 9:47 ` [patch v4 2/4] dt-bindings: extcon: ptn5150: Allow "connector" node to present Xu Yang
2025-08-15 9:47 ` [patch v4 3/4] extcon: ptn5150: Add Type-C orientation switch support Xu Yang
2025-08-15 9:47 ` [patch v4 4/4] extcon: ptn5150: Support USB role switch via connector fwnode Xu Yang
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).