From patchwork Wed Jul 1 11:56:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heikki Krogerus X-Patchwork-Id: 11636185 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 65E05912 for ; Wed, 1 Jul 2020 11:56:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4DFB12067D for ; Wed, 1 Jul 2020 11:56:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730419AbgGAL4X (ORCPT ); Wed, 1 Jul 2020 07:56:23 -0400 Received: from mga07.intel.com ([134.134.136.100]:8600 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730374AbgGAL4X (ORCPT ); Wed, 1 Jul 2020 07:56:23 -0400 IronPort-SDR: 9ylQ8NdVfgzPOurkK5OiM5S0EeWQZM0Ir0X6hDRmSUaMX47H5Ls6tY1BMrp9Zbtmr+JKG5w408 iGbpFf777MDA== X-IronPort-AV: E=McAfee;i="6000,8403,9668"; a="211607997" X-IronPort-AV: E=Sophos;i="5.75,300,1589266800"; d="scan'208";a="211607997" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jul 2020 04:56:23 -0700 IronPort-SDR: zbLY/2+T+blpg0yGhLIecwSTQQxLSJWGZTbKu/VILO73iIyNyFjQCYDtiElVUxTg7WP63mFEKr p+p106PkVqzQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,300,1589266800"; d="scan'208";a="386988134" Received: from black.fi.intel.com (HELO black.fi.intel.com.) ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 01 Jul 2020 04:56:21 -0700 From: Heikki Krogerus To: Greg Kroah-Hartman Cc: Prashant Malani , Benson Leung , "Mani, Rajmohan" , linux-usb@vger.kernel.org Subject: [PATCH 1/4] usb: typec: Combine the definitions for Accessory and USB modes Date: Wed, 1 Jul 2020 14:56:15 +0300 Message-Id: <20200701115618.22482-2-heikki.krogerus@linux.intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200701115618.22482-1-heikki.krogerus@linux.intel.com> References: <20200701115618.22482-1-heikki.krogerus@linux.intel.com> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org There is no need to describe them sparately. Signed-off-by: Heikki Krogerus --- include/linux/usb/typec_altmode.h | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/include/linux/usb/typec_altmode.h b/include/linux/usb/typec_altmode.h index d834e236c6df6..a4b65eaa0f623 100644 --- a/include/linux/usb/typec_altmode.h +++ b/include/linux/usb/typec_altmode.h @@ -95,13 +95,7 @@ enum { * * Port drivers can use TYPEC_MODE_AUDIO and TYPEC_MODE_DEBUG as the mode * value for typec_set_mode() when accessory modes are supported. - */ -enum { - TYPEC_MODE_AUDIO = TYPEC_STATE_MODAL, /* Audio Accessory */ - TYPEC_MODE_DEBUG, /* Debug Accessory */ -}; - -/* + * * USB4 also requires that the pins on the connector are repurposed, just like * Alternate Modes. USB4 mode is however not entered with the Enter Mode Command * like the Alternate Modes are, but instead with a special Enter_USB Message. @@ -112,9 +106,11 @@ enum { * state values, just like the Accessory Modes. */ enum { - TYPEC_MODE_USB2 = TYPEC_MODE_DEBUG, /* USB 2.0 mode */ + TYPEC_MODE_USB2 = TYPEC_STATE_MODAL, /* USB 2.0 mode */ TYPEC_MODE_USB3, /* USB 3.2 mode */ - TYPEC_MODE_USB4 /* USB4 mode */ + TYPEC_MODE_USB4, /* USB4 mode */ + TYPEC_MODE_AUDIO, /* Audio Accessory */ + TYPEC_MODE_DEBUG, /* Debug Accessory */ }; #define TYPEC_MODAL_STATE(_state_) ((_state_) + TYPEC_STATE_MODAL) From patchwork Wed Jul 1 11:56:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heikki Krogerus X-Patchwork-Id: 11636187 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C9D60912 for ; Wed, 1 Jul 2020 11:56:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B2085206CB for ; Wed, 1 Jul 2020 11:56:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730449AbgGAL40 (ORCPT ); Wed, 1 Jul 2020 07:56:26 -0400 Received: from mga07.intel.com ([134.134.136.100]:8600 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730374AbgGAL4Z (ORCPT ); Wed, 1 Jul 2020 07:56:25 -0400 IronPort-SDR: wkXz5vjwdkLXJFIjwHExOJeFw0shjmwOWIgbXDPCyeavJlkSt3HoEoIHFg8psBG1ze3eVJNrNg uz9Nzwtbm25A== X-IronPort-AV: E=McAfee;i="6000,8403,9668"; a="211607999" X-IronPort-AV: E=Sophos;i="5.75,300,1589266800"; d="scan'208";a="211607999" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jul 2020 04:56:25 -0700 IronPort-SDR: JsV+IhZWWLUZfS6q1QQrH8hBZ/lK0aLhht2418DhVEEw8ipUKPfFiaOv4mTmYIMpe+xvImwSY4 /YqOXV5xqiVw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,300,1589266800"; d="scan'208";a="386988139" Received: from black.fi.intel.com (HELO black.fi.intel.com.) ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 01 Jul 2020 04:56:23 -0700 From: Heikki Krogerus To: Greg Kroah-Hartman Cc: Prashant Malani , Benson Leung , "Mani, Rajmohan" , linux-usb@vger.kernel.org Subject: [PATCH 2/4] usb: typec: Add data structure for Enter_USB message Date: Wed, 1 Jul 2020 14:56:16 +0300 Message-Id: <20200701115618.22482-3-heikki.krogerus@linux.intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200701115618.22482-1-heikki.krogerus@linux.intel.com> References: <20200701115618.22482-1-heikki.krogerus@linux.intel.com> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org This data structure can be delivered to the mux drivers when Enter_USB Message is used exactly the same way as the Alternate Mode specific data structures are delivered to the mux drivers when Enter Mode Messages are used. The Enter_USB data structure shall have all details related to the Enter_USB Message, most importantly the Enter_USB Date Object that was used. Signed-off-by: Heikki Krogerus --- include/linux/usb/typec.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h index 5daa1c49761c3..9cb1bec94b710 100644 --- a/include/linux/usb/typec.h +++ b/include/linux/usb/typec.h @@ -72,6 +72,20 @@ enum typec_orientation { TYPEC_ORIENTATION_REVERSE, }; +/* + * struct enter_usb_data - Enter_USB Message details + * @eudo: Enter_USB Data Object + * @active_link_training: Active Cable Plug Link Training + * + * @active_link_training is a flag that should be set with uni-directional SBRX + * communication, and left 0 with passive cables and with bi-directional SBRX + * communication. + */ +struct enter_usb_data { + u32 eudo; + unsigned char active_link_training:1; +}; + /* * struct usb_pd_identity - USB Power Delivery identity data * @id_header: ID Header VDO From patchwork Wed Jul 1 11:56:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heikki Krogerus X-Patchwork-Id: 11636189 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4570F912 for ; Wed, 1 Jul 2020 11:56:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2B6A220772 for ; Wed, 1 Jul 2020 11:56:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730457AbgGAL41 (ORCPT ); Wed, 1 Jul 2020 07:56:27 -0400 Received: from mga07.intel.com ([134.134.136.100]:8600 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730374AbgGAL41 (ORCPT ); Wed, 1 Jul 2020 07:56:27 -0400 IronPort-SDR: TsH7U2DsB6PHjptrADE0jVlreOfQrxuHhG9BDjxZk4qZY27yRrw8LvnYZxeFNJz/nGeNiO0/W9 ODbZeToRUyfA== X-IronPort-AV: E=McAfee;i="6000,8403,9668"; a="211608003" X-IronPort-AV: E=Sophos;i="5.75,300,1589266800"; d="scan'208";a="211608003" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jul 2020 04:56:26 -0700 IronPort-SDR: JjHjqzbsM7MYVbyzPJNKopWJ1QUruFtrL5pU/xuB59NIjy//TCpJcxK+hRCiFQ4dC/WWPD+ER/ HR1/HrNWBUqA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,300,1589266800"; d="scan'208";a="386988145" Received: from black.fi.intel.com (HELO black.fi.intel.com.) ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 01 Jul 2020 04:56:25 -0700 From: Heikki Krogerus To: Greg Kroah-Hartman Cc: Prashant Malani , Benson Leung , "Mani, Rajmohan" , linux-usb@vger.kernel.org Subject: [PATCH 3/4] usb: typec: intel_pmc_mux: Definitions for response status bits Date: Wed, 1 Jul 2020 14:56:17 +0300 Message-Id: <20200701115618.22482-4-heikki.krogerus@linux.intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200701115618.22482-1-heikki.krogerus@linux.intel.com> References: <20200701115618.22482-1-heikki.krogerus@linux.intel.com> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Adding definitions for the two status bits that we have in the command response data structure. Also, from now on only considering the second status bit, which tells was the failure fatal or not, if the first bit is set. If the first bit is not set, then the command was successful, and we need to ignore the second bit. Signed-off-by: Heikki Krogerus --- drivers/usb/typec/mux/intel_pmc_mux.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/mux/intel_pmc_mux.c b/drivers/usb/typec/mux/intel_pmc_mux.c index 70ddc9d6d49e4..31fa62f968fb2 100644 --- a/drivers/usb/typec/mux/intel_pmc_mux.c +++ b/drivers/usb/typec/mux/intel_pmc_mux.c @@ -19,6 +19,10 @@ #define PMC_USBC_CMD 0xa7 +/* Response status bits */ +#define PMC_USB_RESP_STATUS_FAILURE BIT(0) +#define PMC_USB_RESP_STATUS_FATAL BIT(1) + /* "Usage" OOB Message field values */ enum { PMC_USB_CONNECT, @@ -130,8 +134,8 @@ static int pmc_usb_command(struct pmc_usb_port *port, u8 *msg, u32 len) */ intel_scu_ipc_dev_command(port->pmc->ipc, PMC_USBC_CMD, 0, msg, len, response, sizeof(response)); - if (response[2]) { - if (response[2] & BIT(1)) + if (response[2] & PMC_USB_RESP_STATUS_FAILURE) { + if (response[2] & PMC_USB_RESP_STATUS_FATAL) return -EIO; return -EBUSY; } From patchwork Wed Jul 1 11:56:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heikki Krogerus X-Patchwork-Id: 11636191 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3DCAA13B6 for ; Wed, 1 Jul 2020 11:56:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 27A9C206CB for ; Wed, 1 Jul 2020 11:56:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730459AbgGAL43 (ORCPT ); Wed, 1 Jul 2020 07:56:29 -0400 Received: from mga07.intel.com ([134.134.136.100]:8600 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730374AbgGAL43 (ORCPT ); Wed, 1 Jul 2020 07:56:29 -0400 IronPort-SDR: Sr8GntgOj3wRgVx27MNPgqeyblQAh2eto6CVZTKK3AzQOA76DoYnGdMz4Q35tdnjQE2bzWq5t1 a2nfpt+gukhw== X-IronPort-AV: E=McAfee;i="6000,8403,9668"; a="211608004" X-IronPort-AV: E=Sophos;i="5.75,300,1589266800"; d="scan'208";a="211608004" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jul 2020 04:56:28 -0700 IronPort-SDR: za8VEdySbLBdepjdf1Pm6qoB6KF24icFD/cLXa+nDb/cXNm+0gIEn3nyvNEKhdTeYiSX9+JuRr YiiYR9KRzgaA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,300,1589266800"; d="scan'208";a="386988152" Received: from black.fi.intel.com (HELO black.fi.intel.com.) ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 01 Jul 2020 04:56:27 -0700 From: Heikki Krogerus To: Greg Kroah-Hartman Cc: Prashant Malani , Benson Leung , "Mani, Rajmohan" , linux-usb@vger.kernel.org Subject: [PATCH 4/4] usb: typec: intel_pmc_mux: Add support for USB4 Date: Wed, 1 Jul 2020 14:56:18 +0300 Message-Id: <20200701115618.22482-5-heikki.krogerus@linux.intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200701115618.22482-1-heikki.krogerus@linux.intel.com> References: <20200701115618.22482-1-heikki.krogerus@linux.intel.com> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The PMC mux-agent can be used also to enter USB4 mode. The mux-agent does not have USB4 specific message, but it can be put into the TBT3 alternate mode also with USB4. That is OK because the controller is in any case the same with TBT3 and USB4. Signed-off-by: Heikki Krogerus --- drivers/usb/typec/mux/intel_pmc_mux.c | 67 +++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 9 deletions(-) diff --git a/drivers/usb/typec/mux/intel_pmc_mux.c b/drivers/usb/typec/mux/intel_pmc_mux.c index 31fa62f968fb2..2aba07c7b221a 100644 --- a/drivers/usb/typec/mux/intel_pmc_mux.c +++ b/drivers/usb/typec/mux/intel_pmc_mux.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -231,6 +232,43 @@ pmc_usb_mux_tbt(struct pmc_usb_port *port, struct typec_mux_state *state) return pmc_usb_command(port, (void *)&req, sizeof(req)); } +static int +pmc_usb_mux_usb4(struct pmc_usb_port *port, struct typec_mux_state *state) +{ + struct enter_usb_data *data = state->data; + struct altmode_req req = { }; + u8 cable_speed; + + req.usage = PMC_USB_ALT_MODE; + req.usage |= port->usb3_port << PMC_USB_MSG_USB3_PORT_SHIFT; + req.mode_type = PMC_USB_MODE_TYPE_TBT << PMC_USB_MODE_TYPE_SHIFT; + + /* USB4 Mode */ + req.mode_data = PMC_USB_ALTMODE_FORCE_LSR; + + if (data->active_link_training) + req.mode_data |= PMC_USB_ALTMODE_ACTIVE_LINK; + + req.mode_data |= (port->orientation - 1) << PMC_USB_ALTMODE_ORI_SHIFT; + req.mode_data |= (port->role - 1) << PMC_USB_ALTMODE_UFP_SHIFT; + + switch ((data->eudo & EUDO_CABLE_TYPE_MASK) >> EUDO_CABLE_TYPE_SHIFT) { + case EUDO_CABLE_TYPE_PASSIVE: + break; + case EUDO_CABLE_TYPE_OPTICAL: + req.mode_data |= PMC_USB_ALTMODE_CABLE_TYPE; + fallthrough; + default: + req.mode_data |= PMC_USB_ALTMODE_ACTIVE_CABLE; + break; + } + + cable_speed = (data->eudo & EUDO_CABLE_SPEED_MASK) >> EUDO_CABLE_SPEED_SHIFT; + req.mode_data |= PMC_USB_ALTMODE_CABLE_SPD(cable_speed); + + return pmc_usb_command(port, (void *)&req, sizeof(req)); +} + static int pmc_usb_mux_safe_state(struct pmc_usb_port *port) { u8 msg; @@ -272,17 +310,28 @@ pmc_usb_mux_set(struct typec_mux *mux, struct typec_mux_state *state) { struct pmc_usb_port *port = typec_mux_get_drvdata(mux); - if (!state->alt) - return 0; - if (state->mode == TYPEC_STATE_SAFE) return pmc_usb_mux_safe_state(port); - - switch (state->alt->svid) { - case USB_TYPEC_TBT_SID: - return pmc_usb_mux_tbt(port, state); - case USB_TYPEC_DP_SID: - return pmc_usb_mux_dp(port, state); + if (state->mode == TYPEC_STATE_USB) + return pmc_usb_connect(port); + + if (state->alt) { + switch (state->alt->svid) { + case USB_TYPEC_TBT_SID: + return pmc_usb_mux_tbt(port, state); + case USB_TYPEC_DP_SID: + return pmc_usb_mux_dp(port, state); + } + } else { + switch (state->mode) { + case TYPEC_MODE_USB2: + /* REVISIT: Try with usb3_port set to 0? */ + break; + case TYPEC_MODE_USB3: + return pmc_usb_connect(port); + case TYPEC_MODE_USB4: + return pmc_usb_mux_usb4(port, state); + } } return -EOPNOTSUPP;