devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Li Jun <jun.li@nxp.com>
To: heikki.krogerus@linux.intel.com, robh+dt@kernel.org, rafael@kernel.org
Cc: gregkh@linuxfoundation.org, andriy.shevchenko@linux.intel.com,
	hdegoede@redhat.com, lee.jones@linaro.org,
	mika.westerberg@linux.intel.com, dmitry.torokhov@gmail.com,
	prabhakar.mahadev-lad.rj@bp.renesas.com,
	laurent.pinchart+renesas@ideasonboard.com,
	linux-usb@vger.kernel.org, devicetree@vger.kernel.org,
	linux-imx@nxp.com, peter.chen@nxp.com
Subject: [PATCH v6 5/6] usb: typec: mux: add typec switch via general mux control
Date: Mon, 23 Nov 2020 22:01:35 +0800	[thread overview]
Message-ID: <1606140096-1382-5-git-send-email-jun.li@nxp.com> (raw)
In-Reply-To: <1606140096-1382-1-git-send-email-jun.li@nxp.com>

The general mux controller can be easily extended to support
various mux selection, this especially fits typec orientation
switch block with a dedicated driver.

Signed-off-by: Li Jun <jun.li@nxp.com>
---
New patch for v6.

 drivers/usb/typec/bus.h       |  1 +
 drivers/usb/typec/mux.c       | 44 ++++++++++++++++++++++++++++++++++++++++---
 include/linux/usb/typec_mux.h |  7 +------
 3 files changed, 43 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/typec/bus.h b/drivers/usb/typec/bus.h
index 8ba8112..235ee82 100644
--- a/drivers/usb/typec/bus.h
+++ b/drivers/usb/typec/bus.h
@@ -38,6 +38,7 @@ extern struct class typec_mux_class;
 struct typec_switch {
 	struct device dev;
 	typec_switch_set_fn_t set;
+	struct mux_control *mux_ctrl;
 };
 
 struct typec_mux {
diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c
index 0219aa4..afc4537 100644
--- a/drivers/usb/typec/mux.c
+++ b/drivers/usb/typec/mux.c
@@ -14,6 +14,7 @@
 #include <linux/property.h>
 #include <linux/slab.h>
 #include <linux/usb/typec_mux.h>
+#include <linux/mux/consumer.h>
 
 #include "bus.h"
 
@@ -42,10 +43,8 @@ static void *typec_switch_match(struct device_connection *con, int ep,
 	if (con->id && !fwnode_is_compatible(con->fwnode, con->id) &&
 		       !fwnode_property_present(con->fwnode, con->id))
 		return NULL;
-
 	dev = class_find_device(&typec_mux_class, NULL, con->fwnode,
 				switch_fwnode_match);
-
 	return dev ? to_typec_switch(dev) : ERR_PTR(-EPROBE_DEFER);
 }
 
@@ -71,6 +70,19 @@ struct typec_switch *fwnode_typec_switch_get(struct fwnode_handle *fwnode)
 }
 EXPORT_SYMBOL_GPL(fwnode_typec_switch_get);
 
+struct typec_switch *typec_switch_get(struct device *dev)
+{
+	struct mux_control *typec_mc = mux_control_get(dev->parent,
+				       "mux-typec-switch");
+	struct typec_switch *sw = fwnode_typec_switch_get(dev_fwnode(dev));
+
+	if (!IS_ERR_OR_NULL(sw) && !IS_ERR_OR_NULL(typec_mc))
+		sw->mux_ctrl = typec_mc;
+
+	return sw;
+}
+EXPORT_SYMBOL_GPL(typec_switch_get);
+
 /**
  * typec_put_switch - Release USB Type-C orientation switch
  * @sw: USB Type-C orientation switch
@@ -142,13 +154,39 @@ typec_switch_register(struct device *parent,
 }
 EXPORT_SYMBOL_GPL(typec_switch_register);
 
+static int typec_switch_mux_ctrl(struct mux_control *sw_mux,
+				enum typec_orientation orientation)
+{
+	int ret = 0;
+
+	if (!sw_mux)
+		return -EINVAL;
+
+	switch (orientation) {
+	case TYPEC_ORIENTATION_NORMAL:
+		ret = mux_control_select(sw_mux, 1);
+		break;
+	case TYPEC_ORIENTATION_REVERSE:
+		ret = mux_control_select(sw_mux, 0);
+		break;
+	case TYPEC_ORIENTATION_NONE:
+		ret = mux_control_deselect(sw_mux);
+		break;
+	}
+
+	return ret;
+}
+
 int typec_switch_set(struct typec_switch *sw,
 		     enum typec_orientation orientation)
 {
 	if (IS_ERR_OR_NULL(sw))
 		return 0;
 
-	return sw->set(sw, orientation);
+	if (sw->mux_ctrl)
+		return typec_switch_mux_ctrl(sw->mux_ctrl, orientation);
+	else
+		return sw->set(sw, orientation);
 }
 EXPORT_SYMBOL_GPL(typec_switch_set);
 
diff --git a/include/linux/usb/typec_mux.h b/include/linux/usb/typec_mux.h
index a9d9957..e2ea141 100644
--- a/include/linux/usb/typec_mux.h
+++ b/include/linux/usb/typec_mux.h
@@ -26,15 +26,10 @@ 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 *
 typec_switch_register(struct device *parent,
 		      const struct typec_switch_desc *desc);
+struct typec_switch *typec_switch_get(struct device *dev);
 void typec_switch_unregister(struct typec_switch *sw);
 
 void typec_switch_set_drvdata(struct typec_switch *sw, void *data);
-- 
2.7.4


  parent reply	other threads:[~2020-11-23 14:09 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-23 14:01 [PATCH v6 1/6] dt-bindings: usb: add documentation for typec switch simple driver Li Jun
2020-11-23 14:01 ` [PATCH v6 2/6] device property: Add fwnode_is_compatible() and device_is_compatible() helpers Li Jun
2020-11-23 14:01 ` [PATCH v6 3/6] usb: typec: mux: add "compatible" property for switch match Li Jun
2020-11-23 14:01 ` [PATCH v6 4/6] usb: typec: mux: use fwnode's dev for driver module user count Li Jun
2020-11-26 11:58   ` Heikki Krogerus
2020-11-23 14:01 ` Li Jun [this message]
2020-11-23 15:31   ` [PATCH v6 5/6] usb: typec: mux: add typec switch via general mux control Andy Shevchenko
2020-11-24  2:15     ` Jun Li
2020-11-23 14:01 ` [PATCH v6 6/6] usb: typec: mux: add typec switch simple driver Li Jun
2020-11-26 11:59   ` Heikki Krogerus
2020-11-30 21:47 ` [PATCH v6 1/6] dt-bindings: usb: add documentation for " Rob Herring
2020-12-01  3:13   ` Jun Li
2020-12-03 12:24     ` Jun Li

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=1606140096-1382-5-git-send-email-jun.li@nxp.com \
    --to=jun.li@nxp.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hdegoede@redhat.com \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=laurent.pinchart+renesas@ideasonboard.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    --cc=peter.chen@nxp.com \
    --cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
    --cc=rafael@kernel.org \
    --cc=robh+dt@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).