Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp2265685pxb; Thu, 3 Feb 2022 03:05:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJwXmcoslCWJymwzOlHxWmE+RvLgDv+gbAT+nbbSRUk2TU8JY9Uj27Nt91MRxlrwDqOOzHhK X-Received: by 2002:a17:902:d4ce:: with SMTP id o14mr35472915plg.39.1643886316490; Thu, 03 Feb 2022 03:05:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643886316; cv=none; d=google.com; s=arc-20160816; b=UZ/e15ueltkJCGFWXnuTt7TsO7sruUaZ1oPh8hLPFQSZzOdB4R6tw1cv6heZ7OKKQE AYEyX8Xaz2VHkIB4IZVqbhrfLHuHsu1zzG5snt31Gi+jEWpsSjg8t5pG2jRyGfLkGsuR 2kmnmFuUWTCvtP9K2qCikyitDwTDGZVPwNQricyBFKGjYr2I2SLpQBtPs9N8WS4TY3bi H+vbuwz7lVY7SI8r34lrzXDA71KEXfGiLuQSQgK2gNPKjFYN/PtVli3+vRlxdC+JUHst pwJSLn0X2YbmWH1xRMv+UNRzQ6yFkaCSV2adMBmD8z6lopa+MiiIhIenkH3COPIVEv7F LFCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=Xs1zDsbUVkBNQ8Xqh/xz1yx3FBHqCokCJ3va+NN7ckQ=; b=h+EjXAc9hAFTZxUjtQzLrbn7vABFFsqZED83zt+XXCvAQC4aA7wXWSuBkrTpMHPUA8 tXJIcolsX9mSJ52AWyoa4VJudeAAECuFfYwirm/6OeVRqLRlF+fVmhedLokFZBjFu5AO G+6F/MeqP7BBxv1yMXsji3VQlHZ0UXG36NE6KTMwjhRqzv9GoAZPNSLPYkJ6aP4XuCJW Gz/01aYHtmr9ldqc/Eoas0QGh37+Z1adlwHteJtEq+NZu5tZdZTqh9WsI+3V6tt74CAi SPG8cHmN/23btvU3zZ2qjVYMx1nubppzDe8cpu4A7nY/ju+FNSzSGQxazs5faqcbqr8L yuQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sholland.org header.s=fm1 header.b=JwLzvK5c; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b="Zy/8/TFc"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t62si21854092pgd.601.2022.02.03.03.05.04; Thu, 03 Feb 2022 03:05:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sholland.org header.s=fm1 header.b=JwLzvK5c; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b="Zy/8/TFc"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347882AbiBBWUA (ORCPT + 99 others); Wed, 2 Feb 2022 17:20:00 -0500 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:43751 "EHLO out1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347867AbiBBWTy (ORCPT ); Wed, 2 Feb 2022 17:19:54 -0500 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 10B595C01A6; Wed, 2 Feb 2022 17:19:54 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Wed, 02 Feb 2022 17:19:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= cc:cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm1; bh=Xs1zDsbUVkBNQ8Xqh/xz1yx3FBHqCo kCJ3va+NN7ckQ=; b=JwLzvK5cZudUshAmPboWiDnMv8zVTqxOiKI4uu6vJnHHLJ N+tHjg5Kp1RFzJRyFukkm38nSi0FjqBpjyCwraaOfExHDHlCG8ZuIcUQC4wE86DZ DMIZeXzoU3ZhMQQgEBZ43mC8GYO3m2Pf75BMu5Binybc7PH7Z1GpfmhM2MA8rYfo 4CRn+ZUJwk1ewTdbbJJbqhcdPz+bbyk1dtuM8II2/qAx4l8Da3CEc/hpg4JsIMea iH/h2Q2wYWrNKIJMqqqSVu9ihQPztLYwf/Ckq1L5xiUZEt59V5BD3ONu98knRJRK mslqmMzK1IWx1Rs9RbOpC9mqUc7cqsFFVl/s8qyQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=Xs1zDs bUVkBNQ8Xqh/xz1yx3FBHqCokCJ3va+NN7ckQ=; b=Zy/8/TFcqiKfzftZjgo+Fk XZXMU5OogJYjy683rmMfbOLcNdQbstBVoQmX0NnL0ihgqTsy+08eNll6GHxEbA/V UBwvy6LoXfvc7LXXz15qwO7RcUouRKeRZ5yuwyFfRsfbbfLew0TonSFmAS/J1yz1 rPdd4M4DSoukLivcWwajmIZ+8tXx0VfFUXYzQn9WCbVscPJRV5BVAebOLHC5dFvM SU3c6hm1tDMatzllzZyE/K9UAdvGjFAkJNFG1Wi/h0AuFg1TeikVpxMS97m4ngQK pNQn1LIoy6S6sfuiC5Q9N8C1su7Mghv4cWDalUmn60IryJv18fXc9n3RTyUP/I2Q == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrgeehgdduheelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefurghmuhgv lhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenucggtf frrghtthgvrhhnpeduhfejfedvhffgfeehtefghfeiiefgfeehgfdvvdevfeegjeehjedv gfejheeuieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 2 Feb 2022 17:19:53 -0500 (EST) From: Samuel Holland To: Heikki Krogerus , Guenter Roeck , Greg Kroah-Hartman , Rob Herring , devicetree@vger.kernel.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Samuel Holland Subject: [PATCH v2 3/4] usb: typec: Factor out non-PD fwnode properties Date: Wed, 2 Feb 2022 16:19:46 -0600 Message-Id: <20220202221948.5690-4-samuel@sholland.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220202221948.5690-1-samuel@sholland.org> References: <20220202221948.5690-1-samuel@sholland.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Basic programmable non-PD Type-C port controllers do not need the full TCPM library, but they share the same devicetree binding and the same typec_capability structure. Factor out a helper for parsing those properties which map to fields in struct typec_capability, so the code can be shared between TCPM and basic non-TCPM drivers. Signed-off-by: Samuel Holland --- Changes in v2: - Always put the return values from typec_find_* in a signed variable for error checking. drivers/usb/typec/class.c | 52 +++++++++++++++++++++++++++++++++++ drivers/usb/typec/tcpm/tcpm.c | 32 +-------------------- include/linux/usb/typec.h | 3 ++ 3 files changed, 56 insertions(+), 31 deletions(-) diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index 45a6f0c807cb..b67ba9478c82 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -1894,6 +1894,58 @@ void *typec_get_drvdata(struct typec_port *port) } EXPORT_SYMBOL_GPL(typec_get_drvdata); +int typec_get_fw_cap(struct typec_capability *cap, + struct fwnode_handle *fwnode) +{ + const char *cap_str; + int ret; + + /* + * This fwnode has a "compatible" property, but is never populated as a + * struct device. Instead we simply parse it to read the properties. + * This it breaks fw_devlink=on. To maintain backward compatibility + * with existing DT files, we work around this by deleting any + * fwnode_links to/from this fwnode. + */ + fw_devlink_purge_absent_suppliers(fwnode); + + cap->fwnode = fwnode; + + ret = fwnode_property_read_string(fwnode, "power-role", &cap_str); + if (ret < 0) + return ret; + + ret = typec_find_port_power_role(cap_str); + if (ret < 0) + return ret; + cap->type = ret; + + /* USB data support is optional */ + ret = fwnode_property_read_string(fwnode, "data-role", &cap_str); + if (ret == 0) { + ret = typec_find_port_data_role(cap_str); + if (ret < 0) + return ret; + cap->data = ret; + } + + /* Get the preferred power role for a DRP */ + if (cap->type == TYPEC_PORT_DRP) { + cap->prefer_role = TYPEC_NO_PREFERRED_ROLE; + + ret = fwnode_property_read_string(fwnode, "try-power-role", &cap_str); + if (ret == 0) { + ret = typec_find_power_role(cap_str); + if (ret < 0) + return ret; + cap->prefer_role = ret; + } + } + + return 0; +} +EXPORT_SYMBOL_GPL(typec_get_fw_cap); + /** * typec_port_register_altmode - Register USB Type-C Port Alternate Mode * @port: USB Type-C Port that supports the alternate mode diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index 5fce795b69c7..8b58aa6e3509 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -5935,32 +5935,10 @@ static int tcpm_fw_get_caps(struct tcpm_port *port, if (!fwnode) return -EINVAL; - /* - * This fwnode has a "compatible" property, but is never populated as a - * struct device. Instead we simply parse it to read the properties. - * This it breaks fw_devlink=on. To maintain backward compatibility - * with existing DT files, we work around this by deleting any - * fwnode_links to/from this fwnode. - */ - fw_devlink_purge_absent_suppliers(fwnode); - - /* USB data support is optional */ - ret = fwnode_property_read_string(fwnode, "data-role", &cap_str); - if (ret == 0) { - ret = typec_find_port_data_role(cap_str); - if (ret < 0) - return ret; - port->typec_caps.data = ret; - } - - ret = fwnode_property_read_string(fwnode, "power-role", &cap_str); + ret = typec_get_fw_cap(&port->typec_caps, fwnode); if (ret < 0) return ret; - ret = typec_find_port_power_role(cap_str); - if (ret < 0) - return ret; - port->typec_caps.type = ret; port->port_type = port->typec_caps.type; port->pd_supported = !fwnode_property_read_bool(fwnode, "pd-disable"); @@ -5997,14 +5975,6 @@ static int tcpm_fw_get_caps(struct tcpm_port *port, if (port->port_type == TYPEC_PORT_SRC) return 0; - /* Get the preferred power role for DRP */ - ret = fwnode_property_read_string(fwnode, "try-power-role", &cap_str); - if (ret < 0) - return ret; - - port->typec_caps.prefer_role = typec_find_power_role(cap_str); - if (port->typec_caps.prefer_role < 0) - return -EINVAL; sink: port->self_powered = fwnode_property_read_bool(fwnode, "self-powered"); diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h index 7ba45a97eeae..fdf737d48b3b 100644 --- a/include/linux/usb/typec.h +++ b/include/linux/usb/typec.h @@ -295,6 +295,9 @@ int typec_set_mode(struct typec_port *port, int mode); void *typec_get_drvdata(struct typec_port *port); +int typec_get_fw_cap(struct typec_capability *cap, + struct fwnode_handle *fwnode); + int typec_find_pwr_opmode(const char *name); int typec_find_orientation(const char *name); int typec_find_port_power_role(const char *name); -- 2.33.1