From: Randy Dunlap <rdunlap@infradead.org>
To: Hans de Goede <hdegoede@redhat.com>,
Darren Hart <dvhart@infradead.org>,
Andy Shevchenko <andy@infradead.org>,
MyungJoo Ham <myungjoo.ham@samsung.com>,
Chanwoo Choi <cw00.choi@samsung.com>,
Mathias Nyman <mathias.nyman@intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Guenter Roeck <linux@roeck-us.net>,
Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: platform-driver-x86@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org
Subject: Re: [PATCH v2 03/12] usb: typec: API for controlling USB Type-C Multiplexers
Date: Sun, 25 Feb 2018 11:22:18 -0800 [thread overview]
Message-ID: <3147a267-0f20-e3f4-deca-b81d7e60f412@infradead.org> (raw)
In-Reply-To: <20180225152510.10159-4-hdegoede@redhat.com>
On 02/25/2018 07:25 AM, Hans de Goede wrote:
> From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
>
> ---
> Documentation/driver-api/usb/typec.rst | 73 +++++++++++--
> drivers/usb/typec/Makefile | 1 +
> drivers/usb/typec/{typec.c => class.c} | 70 ++++++++++++
> drivers/usb/typec/mux.c | 188 +++++++++++++++++++++++++++++++++
> include/linux/usb/typec.h | 14 +++
> include/linux/usb/typec_mux.h | 55 ++++++++++
> 6 files changed, 390 insertions(+), 11 deletions(-)
> rename drivers/usb/typec/{typec.c => class.c} (95%)
> create mode 100644 drivers/usb/typec/mux.c
> create mode 100644 include/linux/usb/typec_mux.h
>
> diff --git a/Documentation/driver-api/usb/typec.rst b/Documentation/driver-api/usb/typec.rst
> index 8a7249f2ff04..091e4def3a39 100644
> --- a/Documentation/driver-api/usb/typec.rst
> +++ b/Documentation/driver-api/usb/typec.rst
> +
> +Multiplexer/DeMultiplexer Switches
> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> +
> +USB Type-C connectors may have one or more mux/demux switches behind them. Since
> +the plugs can be inserted right-side-up or upside-down, a switch is needed to
> +route the correct data pairs from the connector to the USB controllers. If
> +Alternate or Accessory Modes are supported, an other switch is needed that can
another
> +route the pins on the connector to some other component besides USB. USB Type-C
> +Connector Class supplies an API for registering those switches.
> +
> +.. kernel-doc:: drivers/usb/typec/mux.c
> + :functions: typec_switch_register typec_switch_unregister typec_mux_register typec_mux_unregister
> +
> +In most cases the same physical mux will handle both the orientation and mode.
> +However, as the port drivers will be responsible of the orientation, and the
for the orientation,
> +alternate mode drivers of the mode, the two are always separated into their own
for the mode,
> +logical components: "mux" for the mode and "switch" for the orientation.
> +
> +When a port is registered, USB Type-C Connector Class requests both the mux and
> +the switch for the port. The drivers can then use the following API for
> +controlling them:
> +
> +.. kernel-doc:: drivers/usb/typec/class.c
> + :functions: typec_set_orientation typec_set_mode
> +
> +If the connector is dual-role capable, there may also be a switch for the data
> +role. USB Type-C Connector Class does not supply separate API for them. The
> +port drivers can use USB Role Class API with those.
> +
> +Illustration of the muxes behind a connector that supports an alternate mode:
> +
> + ------------------------
> + | Connector |
> + ------------------------
> + | |
> + ------------------------
> + \ Orientation /
> + --------------------
> + |
> + --------------------
> + / Mode \
> + ------------------------
> + / \
> + ------------------------ --------------------
> + | Alt Mode | / USB Role \
> + ------------------------ ------------------------
> + / \
> + ------------------------ ------------------------
> + | USB Host | | USB Device |
> + ------------------------ ------------------------
> diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c
> new file mode 100644
> index 000000000000..3102238366ed
> --- /dev/null
> +++ b/drivers/usb/typec/mux.c
> @@ -0,0 +1,188 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/**
> + * USB Type-C Multiplexer/DeMultiplexer Switch support
> + *
> + * Copyright (C) 2018 Intel Corporation
> + * Author: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> + * Hans de Goede <hdegoede@redhat.com>
> + */
> +
> +#include <linux/device.h>
> +#include <linux/connection.h>
> +#include <linux/usb/typec_mux.h>
Needs: <linux/mutex.h> <linux/list.h> ...
> +static DEFINE_MUTEX(switch_lock);
> +static DEFINE_MUTEX(mux_lock);
> +static LIST_HEAD(switch_list);
> +static LIST_HEAD(mux_list);
> +
> +static void *typec_switch_match(struct devcon *con, int ep, void *data)
> +{
> + struct typec_switch *sw;
> +
> + list_for_each_entry(sw, &switch_list, entry)
> + if (!strcmp(con->endpoint[ep], dev_name(sw->dev)))
> + return sw;
> +
> + /*
> + * We only get called if a connection was found, tell the caller to
> + * wait for the switch to show-up.
show up.
> + */
> + return ERR_PTR(-EPROBE_DEFER);
> +}
> +
> +static void *typec_mux_match(struct devcon *con, int ep, void *data)
> +{
> + struct typec_mux *mux;
> +
> + list_for_each_entry(mux, &mux_list, entry)
> + if (!strcmp(con->endpoint[ep], dev_name(mux->dev)))
> + return mux;
> +
> + /*
> + * We only get called if a connection was found, tell the caller to
> + * wait for the switch to show-up.
show up.
> + */
> + return ERR_PTR(-EPROBE_DEFER);
> +}
> diff --git a/include/linux/usb/typec_mux.h b/include/linux/usb/typec_mux.h
> new file mode 100644
> index 000000000000..0ddaaa8b0ac1
> --- /dev/null
> +++ b/include/linux/usb/typec_mux.h
> @@ -0,0 +1,55 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#ifndef __USB_TYPEC_MUX
> +#define __USB_TYPEC_MUX
> +
> +#include <linux/list.h>
> +#include <linux/usb/typec.h>
> +
> +struct device;
> +
> +/**
> + * typec_switch - USB Type-C cable orientation switch
* struct typec_switch - USB Type-C cable orientation switch
> + * @dev: Switch device
> + * @entry: List entry
> + * @set: Callback to the driver for setting the orientation
> + *
> + * USB Type-C pin flipper switch routing the correct data pairs from the
> + * connector to the USB controller depending on the orientation of the cable
> + * plug.
> + */
> +struct typec_switch {
> + struct device *dev;
> + struct list_head entry;
> +
> + int (*set)(struct typec_switch *sw, enum typec_orientation orientation);
> +};
> +
> +/**
> + * typec_switch - USB Type-C connector pin mux
* struct typec_mux - USB Type-C connector pin mux
> + * @dev: Mux device
> + * @entry: List entry
> + * @set: Callback to the driver for setting the state of the mux
> + *
> + * Pin Multiplexer/DeMultiplexer switch routing the USB Type-C connector pins to
> + * different components depending on the requested mode of operation. Used with
> + * Accessory/Alternate modes.
> + */
> +struct typec_mux {
> + struct device *dev;
> + struct list_head entry;
> +
> + int (*set)(struct typec_mux *mux, int state);
> +};
ta.
--
~Randy
next prev parent reply other threads:[~2018-02-25 19:22 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-25 15:24 [PATCH v2 00/12] USB Type-C device-connection, mux and switch support Hans de Goede
2018-02-25 15:24 ` [PATCH v2 01/12] drivers: base: Unified device connection lookup Hans de Goede
2018-02-25 19:04 ` Randy Dunlap
2018-02-25 15:25 ` [PATCH v2 02/12] usb: typec: Start using ERR_PTR Hans de Goede
2018-02-25 21:38 ` Guenter Roeck
2018-02-25 15:25 ` [PATCH v2 03/12] usb: typec: API for controlling USB Type-C Multiplexers Hans de Goede
2018-02-25 19:22 ` Randy Dunlap [this message]
2018-02-25 15:25 ` [PATCH v2 04/12] usb: common: Small class for USB role switches Hans de Goede
2018-02-25 15:25 ` [PATCH v2 05/12] usb: typec: tcpm: Set USB role switch to device mode when configured as such Hans de Goede
2018-02-25 21:33 ` Guenter Roeck
2018-02-25 15:25 ` [PATCH v2 06/12] usb: typec: tcpm: Use new Type-C switch/mux and usb-role-switch functions Hans de Goede
2018-02-25 21:38 ` Guenter Roeck
2018-02-25 15:25 ` [PATCH v2 07/12] xhci: Add option to get next extended capability in list by passing id = 0 Hans de Goede
2018-02-25 15:25 ` [PATCH v2 08/12] xhci: Add Intel extended cap / otg phy mux handling Hans de Goede
2018-02-25 15:25 ` [PATCH v2 09/12] usb: roles: Add Intel xHCI USB role switch driver Hans de Goede
2018-02-25 18:48 ` Randy Dunlap
2018-02-25 15:25 ` [PATCH v2 10/12] usb: typec: driver for Pericom PI3USB30532 Type-C cross switch Hans de Goede
2018-02-25 15:25 ` [PATCH v2 11/12] platform/x86: intel_cht_int33fe: Add device connections for the Type-C port Hans de Goede
2018-02-25 15:25 ` [PATCH v2 12/12] extcon: axp288: Set USB role where necessary Hans de Goede
2018-02-25 18:51 ` Randy Dunlap
2018-02-26 8:07 ` Hans de Goede
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=3147a267-0f20-e3f4-deca-b81d7e60f412@infradead.org \
--to=rdunlap@infradead.org \
--cc=andy@infradead.org \
--cc=cw00.choi@samsung.com \
--cc=dvhart@infradead.org \
--cc=gregkh@linuxfoundation.org \
--cc=hdegoede@redhat.com \
--cc=heikki.krogerus@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=mathias.nyman@intel.com \
--cc=myungjoo.ham@samsung.com \
--cc=platform-driver-x86@vger.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®