From patchwork Thu Apr 8 20:31:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 12192447 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34166C43460 for ; Thu, 8 Apr 2021 20:31:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EB25A61165 for ; Thu, 8 Apr 2021 20:31:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231906AbhDHUby (ORCPT ); Thu, 8 Apr 2021 16:31:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:50354 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231676AbhDHUby (ORCPT ); Thu, 8 Apr 2021 16:31:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617913902; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jGOitQjkoMTJ+bX1WGm4tbkjjJT/BDFiFAV+vF35KT4=; b=V6+Al3iTRAFbQxVSKhAaVSKA4+Kv5M/pL+Dh4MPRQwY516v2bgb2RtgDgIm5gHRxHZpBJS CVynrEcjmGy6H+QQowVmht5voQ98YjoTlSUP5yRxd3Ct5KGUcB3ne6pResRwkqHgB7KTQJ C0qVZaYdV+Jk8LcCfIJVYXxqcLue7HE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-100-XhqmW_DMMvyAqrCge0SwJA-1; Thu, 08 Apr 2021 16:31:40 -0400 X-MC-Unique: XhqmW_DMMvyAqrCge0SwJA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A93B9DF8B3; Thu, 8 Apr 2021 20:31:39 +0000 (UTC) Received: from x1.localdomain (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4EE0A6A045; Thu, 8 Apr 2021 20:31:38 +0000 (UTC) From: Hans de Goede To: Greg Kroah-Hartman , Guenter Roeck , Heikki Krogerus Cc: Hans de Goede , Rob Herring , Zhen Lei , linux-usb@vger.kernel.org Subject: [PATCH v2 1/3] usb: typec: Add typec_port_register_altmodes_from_fwnode() Date: Thu, 8 Apr 2021 22:31:27 +0200 Message-Id: <20210408203129.526604-2-hdegoede@redhat.com> In-Reply-To: <20210408203129.526604-1-hdegoede@redhat.com> References: <20210408203129.526604-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org This can be used by Type-C controller drivers which use a standard usb-connector fwnode, with altmodes sub-node, to describe the available altmodes. Note there are is no devicetree bindings documentation for the altmodes node, this is deliberate. ATM the fwnodes used to register the altmodes are only used internally to pass platform info from a drivers/platform/x86 driver to the type-c subsystem. When a devicetree user of this functionally comes up and the dt-bindings have been hashed out the internal use can be adjusted to match the dt-bindings. Currently the typec_port_register_altmodes_from_fwnode() function expects an "altmodes" child fwnode on port->dev with this "altmodes" fwnode having child fwnodes itself with each child containing 2 integer properties: 1. A "svid" property, which sets the id of the altmode, e.g. displayport altmode has a svid of 0xff01. 2. A "vdo" property, typically used as a bitmask describing the capabilities of the altmode, the bits in the vdo are specified in the specification of the altmode. Signed-off-by: Hans de Goede Reviewed-by: Heikki Krogerus --- Changes in v2: - Drop the unnecessary fwnode parameter from typec_port_register_altmodes_from_fwnode() - Document the expected "altmodes" fwnode in the commit message for now as v2 of the patch-set drops the dt-bindings since there are not DT users for this yet --- drivers/usb/typec/class.c | 55 +++++++++++++++++++++++++++++++++++++++ include/linux/usb/typec.h | 6 +++++ 2 files changed, 61 insertions(+) diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index 45f0bf65e9ab..a82344fe1650 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -1978,6 +1978,61 @@ typec_port_register_altmode(struct typec_port *port, } EXPORT_SYMBOL_GPL(typec_port_register_altmode); +void typec_port_register_altmodes_from_fwnode(struct typec_port *port, + const struct typec_altmode_ops *ops, void *drvdata, + struct typec_altmode **altmodes, size_t n) +{ + struct fwnode_handle *altmodes_node, *child; + struct typec_altmode_desc desc; + struct typec_altmode *alt; + size_t index = 0; + u32 svid, vdo; + int ret; + + altmodes_node = device_get_named_child_node(&port->dev, "altmodes"); + if (!altmodes_node) + return; /* No altmodes specified */ + + child = NULL; + while ((child = fwnode_get_next_child_node(altmodes_node, child))) { + ret = fwnode_property_read_u32(child, "svid", &svid); + if (ret) { + dev_err(&port->dev, "Error reading svid for altmode %s\n", + fwnode_get_name(child)); + continue; + } + + ret = fwnode_property_read_u32(child, "vdo", &vdo); + if (ret) { + dev_err(&port->dev, "Error reading vdo for altmode %s\n", + fwnode_get_name(child)); + continue; + } + + if (index >= n) { + dev_err(&port->dev, "Error not enough space for altmode %s\n", + fwnode_get_name(child)); + continue; + } + + desc.svid = svid; + desc.vdo = vdo; + desc.mode = index + 1; + alt = typec_port_register_altmode(port, &desc); + if (IS_ERR(alt)) { + dev_err(&port->dev, "Error registering altmode %s\n", + fwnode_get_name(child)); + continue; + } + + alt->ops = ops; + typec_altmode_set_drvdata(alt, drvdata); + altmodes[index] = alt; + index++; + } +} +EXPORT_SYMBOL_GPL(typec_port_register_altmodes_from_fwnode); + /** * typec_register_port - Register a USB Type-C Port * @parent: Parent device diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h index 91b4303ca305..75d54558f962 100644 --- a/include/linux/usb/typec.h +++ b/include/linux/usb/typec.h @@ -17,6 +17,7 @@ struct typec_partner; struct typec_cable; struct typec_plug; struct typec_port; +struct typec_altmode_ops; struct fwnode_handle; struct device; @@ -138,6 +139,11 @@ struct typec_altmode struct typec_altmode *typec_port_register_altmode(struct typec_port *port, const struct typec_altmode_desc *desc); + +void typec_port_register_altmodes_from_fwnode(struct typec_port *port, + const struct typec_altmode_ops *ops, void *drvdata, + struct typec_altmode **altmodes, size_t n); + void typec_unregister_altmode(struct typec_altmode *altmode); struct typec_port *typec_altmode2port(struct typec_altmode *alt); From patchwork Thu Apr 8 20:31:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 12192449 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83385C43460 for ; Thu, 8 Apr 2021 20:31:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 44ADC61178 for ; Thu, 8 Apr 2021 20:31:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232218AbhDHUb7 (ORCPT ); Thu, 8 Apr 2021 16:31:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:23714 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232091AbhDHUb6 (ORCPT ); Thu, 8 Apr 2021 16:31:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617913906; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8HsHyrYvNsJ2EBquF9BD7h4e+bgseUlInL7EhF5TJOE=; b=IdQog+oaPBYPcc0nkk2yhtFv8FcgbURwhzwfEXtCa0mOLTzh9+CRrIboQccU1blZTWPfhA DULK6UdfUSy3Pf7OhFYtWLBUcrIfJuprgYmXMZ8d37S0DlaftNjVx7psBYBs7n66a8r6A/ PJFWrPmB0Y0Dhoj5L+NmmYXubyAC2AQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-541-YMAkX9LEM_6CBOMNHuqoHw-1; Thu, 08 Apr 2021 16:31:42 -0400 X-MC-Unique: YMAkX9LEM_6CBOMNHuqoHw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 57FAA19DB061; Thu, 8 Apr 2021 20:31:41 +0000 (UTC) Received: from x1.localdomain (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id F0CFB6A045; Thu, 8 Apr 2021 20:31:39 +0000 (UTC) From: Hans de Goede To: Greg Kroah-Hartman , Guenter Roeck , Heikki Krogerus Cc: Hans de Goede , Rob Herring , Zhen Lei , linux-usb@vger.kernel.org Subject: [PATCH v2 2/3] usb: typec: tcpm: Add support for altmodes Date: Thu, 8 Apr 2021 22:31:28 +0200 Message-Id: <20210408203129.526604-3-hdegoede@redhat.com> In-Reply-To: <20210408203129.526604-1-hdegoede@redhat.com> References: <20210408203129.526604-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Add support for altmodes described in the usb-connector fwnode associated with the Type-C controller by calling the new typec_port_register_altmodes_from_fwnode() helper for this. Signed-off-by: Hans de Goede --- drivers/usb/typec/tcpm/tcpm.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index ce7af398c7c1..4aec8441772c 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -6072,6 +6072,11 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc) goto out_role_sw_put; } + typec_port_register_altmodes_from_fwnode(port->typec_port, + &tcpm_altmode_ops, port, + port->port_altmode, + ALTMODE_DISCOVERY_MAX); + mutex_lock(&port->lock); tcpm_init(port); mutex_unlock(&port->lock); From patchwork Thu Apr 8 20:31:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 12192451 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7102FC433B4 for ; Thu, 8 Apr 2021 20:31:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1BA1361165 for ; Thu, 8 Apr 2021 20:31:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232005AbhDHUb7 (ORCPT ); Thu, 8 Apr 2021 16:31:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:58967 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231940AbhDHUb5 (ORCPT ); Thu, 8 Apr 2021 16:31:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617913906; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=I8lNmTWeFJeCRoNCPnN3eakh8e2Qo1egO6nCTM4vpAc=; b=OOs/XDm0CeQRTMFcb6+5ENtePK46tCaOpCAmGwzyhJ0hQv+cHXxxUN9jyccKJN+Wkn9J4V OvuIreoz1V9P5vKmC/eKej67p0ZJGV+Pigulb4ODNJR+R+9sFSaYC+zj0e5fCZjBndFL2T FlW/6S1FJQN7BkRL/SLQKLrKFHfIoBQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-486-onQYqOPpNqKP7hLcsn9DuA-1; Thu, 08 Apr 2021 16:31:44 -0400 X-MC-Unique: onQYqOPpNqKP7hLcsn9DuA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F392A19DB062; Thu, 8 Apr 2021 20:31:42 +0000 (UTC) Received: from x1.localdomain (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C37F6A045; Thu, 8 Apr 2021 20:31:41 +0000 (UTC) From: Hans de Goede To: Greg Kroah-Hartman , Guenter Roeck , Heikki Krogerus Cc: Hans de Goede , Rob Herring , Zhen Lei , linux-usb@vger.kernel.org Subject: [PATCH v2 3/3] platform/x86/intel_cht_int33fe: Add displayport altmode fwnode to the connector fwnode Date: Thu, 8 Apr 2021 22:31:29 +0200 Message-Id: <20210408203129.526604-4-hdegoede@redhat.com> In-Reply-To: <20210408203129.526604-1-hdegoede@redhat.com> References: <20210408203129.526604-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Add a displayport altmode fwnode to the usb-connector fwnode, devices which use this driver support display-port altmode through the PI3USB30532 USB switch, this enables support for this. Signed-off-by: Hans de Goede --- .../platform/x86/intel_cht_int33fe_typec.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/platform/x86/intel_cht_int33fe_typec.c b/drivers/platform/x86/intel_cht_int33fe_typec.c index 48638d1c56e5..b61bad9cc8d2 100644 --- a/drivers/platform/x86/intel_cht_int33fe_typec.c +++ b/drivers/platform/x86/intel_cht_int33fe_typec.c @@ -124,12 +124,31 @@ static const struct software_node usb_connector_node = { .properties = usb_connector_properties, }; +static const struct software_node altmodes_node = { + .name = "altmodes", + .parent = &usb_connector_node, +}; + +static const struct property_entry dp_altmode_properties[] = { + PROPERTY_ENTRY_U32("svid", 0xff01), + PROPERTY_ENTRY_U32("vdo", 0x0c0086), + { } +}; + +static const struct software_node dp_altmode_node = { + .name = "displayport-altmode", + .parent = &altmodes_node, + .properties = dp_altmode_properties, +}; + static const struct software_node *node_group[] = { &fusb302_node, &max17047_node, &pi3usb30532_node, &displayport_node, &usb_connector_node, + &altmodes_node, + &dp_altmode_node, NULL };