From patchwork Thu Mar 3 22:33:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 547939 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22F4FC433EF for ; Thu, 3 Mar 2022 22:32:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234749AbiCCWcv (ORCPT ); Thu, 3 Mar 2022 17:32:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234087AbiCCWcs (ORCPT ); Thu, 3 Mar 2022 17:32:48 -0500 Received: from mail-oo1-xc31.google.com (mail-oo1-xc31.google.com [IPv6:2607:f8b0:4864:20::c31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F402D1375A3 for ; Thu, 3 Mar 2022 14:32:01 -0800 (PST) Received: by mail-oo1-xc31.google.com with SMTP id k13-20020a4a948d000000b003172f2f6bdfso7456629ooi.1 for ; Thu, 03 Mar 2022 14:32:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=GXj+JJPwfsy1TPTyievdzxMaMQ1HgahsIy1fHCecuJ8=; b=s5oo+ymjcJWqfAiP1BwjR3idcGDdOwaFb2X8H+Z/c3G5sY1UtDiv3Fv7vjncR7nFMO wA8UYS+eLiiZUeb9Rrgal3IJ+vrQnXJmt3tiaP67Qu+bpO+I1pKc9eYWPE82v9mAuy0a zf0JzaDYQVuA41giUxuz7reKLPok3cCf431Pr/tlhu8wiiki7ajXlfmw9DWYkqIP9KPA MexWfe2ty+nGrQ/qkN0EQ00ztZard0NnaFwi6x9CO5pb5xycrzQoIxbN5A4zHkhBQrm+ vSeWTJEqXUe38QHMrC0SrFuUr9O+0Ik1aqwc8yImJ4BdGByk5nVux5cKyLQ/gTzC2JRh J2Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=GXj+JJPwfsy1TPTyievdzxMaMQ1HgahsIy1fHCecuJ8=; b=Ttt+LceFAz6+Kmr/wvC2tIeslDpV+hjsVFisuAs1TT+KltPoSpHypivS0pNQZQYCHk uW+bJH5UmG3DiINYMP4EfWqWq3Z1Rw7jY5yOGZ62SOg208Z3RL5kW1lbe5T0mRuqaQ2Q KsUSZ/3f8VjFl25ODK438++N3TCygslp9H54IUWIqVg/u3o/ONQeDTk+zbtRCO+Ujvwa +Cthx0oSbjw+LwTFiBeKzQpLL79JwDcz03tQk6TSL6aEN7Pf9rlWB5h9E6rntW+x7bUd 6WzUC4sN5RU6TrrmqdjVG85NfPPHqjOKlAVnT8ZvZD9Ql+ziIJ4T7Qg0Z6AQg1m01p1m zmlA== X-Gm-Message-State: AOAM530T2netj1JkOhCGLaVvX+YxnvRjUd1TNMfaMx4rUmpWotnDTRAR u0V2ZNcZaH65LTrvR6UdSafGYg== X-Google-Smtp-Source: ABdhPJzkhWKivVU8Vch0wuh08xQA/XMkkCLJf277FgVKCZMd2uuRFKuuha1IbHcDRlai/7h6StF3NQ== X-Received: by 2002:a4a:d21b:0:b0:2e2:113:db90 with SMTP id c27-20020a4ad21b000000b002e20113db90mr19603967oos.50.1646346721308; Thu, 03 Mar 2022 14:32:01 -0800 (PST) Received: from ripper.. ([2600:1700:a0:3dc8:205:1bff:fec0:b9b3]) by smtp.gmail.com with ESMTPSA id fq14-20020a0568710b0e00b000d4492531a2sm1764777oab.17.2022.03.03.14.32.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Mar 2022 14:32:00 -0800 (PST) From: Bjorn Andersson To: Rob Herring , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , "Rafael J. Wysocki" , Hans de Goede Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Dmitry Baryshkov Subject: [PATCH v3 1/6] device property: Helper to match multiple connections Date: Thu, 3 Mar 2022 14:33:46 -0800 Message-Id: <20220303223351.141238-1-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.33.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org In some cases multiple connections with the same connection id needs to be resolved from a fwnode graph. One such example is when separate hardware is used for performing muxing and/or orientation switching of the SuperSpeed and SBU lines in a USB Type-C connector. In this case the connector needs to belong to a graph with multiple matching remote endpoints, and the Type-C controller needs to be able to resolve them both. Add a new API that allows this kind of lookup. Signed-off-by: Bjorn Andersson --- Changes since v2: - Allow the caller of the new api to pass a matches of NULL, to count possible matches. I previously argued that this will cause memory leaks, but Andy pointed out that this depends on the caller and the match function. - Fixed spelling mistakes in commit message and kernel-doc. - Use two "count" variables to make the math clearer. Changes since v1: - Iterator in fwnode_devcon_matches() is now unsigned. - fwnode_handle_put() node for unavailable nodes. - Extended commit message on the subject of supporting dynamically sized "matches" array. drivers/base/property.c | 107 +++++++++++++++++++++++++++++++++++++++ include/linux/property.h | 5 ++ 2 files changed, 112 insertions(+) diff --git a/drivers/base/property.c b/drivers/base/property.c index c0e94cce9c29..5cda205136f6 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -1218,6 +1218,40 @@ fwnode_graph_devcon_match(struct fwnode_handle *fwnode, const char *con_id, return NULL; } +static unsigned int fwnode_graph_devcon_matches(struct fwnode_handle *fwnode, + const char *con_id, void *data, + devcon_match_fn_t match, + void **matches, + unsigned int matches_len) +{ + struct fwnode_handle *node; + struct fwnode_handle *ep; + unsigned int count = 0; + void *ret; + + fwnode_graph_for_each_endpoint(fwnode, ep) { + if (count >= matches_len && matches) { + fwnode_handle_put(ep); + return count; + } + + node = fwnode_graph_get_remote_port_parent(ep); + if (!fwnode_device_is_available(node)) { + fwnode_handle_put(node); + continue; + } + + ret = match(node, con_id, data); + fwnode_handle_put(node); + if (ret) { + if (matches) + matches[count] = ret; + count++; + } + } + return count; +} + static void * fwnode_devcon_match(struct fwnode_handle *fwnode, const char *con_id, void *data, devcon_match_fn_t match) @@ -1240,6 +1274,37 @@ fwnode_devcon_match(struct fwnode_handle *fwnode, const char *con_id, return NULL; } +static unsigned int fwnode_devcon_matches(struct fwnode_handle *fwnode, + const char *con_id, void *data, + devcon_match_fn_t match, + void **matches, + unsigned int matches_len) +{ + struct fwnode_handle *node; + unsigned int count = 0; + unsigned int i; + void *ret; + + for (i = 0; ; i++) { + if (count >= matches_len && matches) + return count; + + node = fwnode_find_reference(fwnode, con_id, i); + if (IS_ERR(node)) + break; + + ret = match(node, NULL, data); + fwnode_handle_put(node); + if (ret) { + if (matches) + matches[count] = ret; + count++; + } + } + + return count; +} + /** * fwnode_connection_find_match - Find connection from a device node * @fwnode: Device node with the connection @@ -1267,3 +1332,45 @@ void *fwnode_connection_find_match(struct fwnode_handle *fwnode, return fwnode_devcon_match(fwnode, con_id, data, match); } EXPORT_SYMBOL_GPL(fwnode_connection_find_match); + +/** + * fwnode_connection_find_matches - Find connections from a device node + * @fwnode: Device node with the connection + * @con_id: Identifier for the connection + * @data: Data for the match function + * @match: Function to check and convert the connection description + * @matches: Array of pointers to fill with matches + * @matches_len: Length of @matches + * + * Find up to @matches_len connections with unique identifier @con_id between + * @fwnode and other device nodes. @match will be used to convert the + * connection description to data the caller is expecting to be returned + * through the @matches array. + * If @matches is NULL @matches_len is ignored and the total number of resolved + * matches is returned. + * + * Return: Number of matches resolved, or negative errno. + */ +int fwnode_connection_find_matches(struct fwnode_handle *fwnode, + const char *con_id, void *data, + devcon_match_fn_t match, + void **matches, unsigned int matches_len) +{ + unsigned int count_graph; + unsigned int count_ref; + + if (!fwnode || !match) + return -EINVAL; + + count_graph = fwnode_graph_devcon_matches(fwnode, con_id, data, match, + matches, matches_len); + + matches += count_graph; + matches_len -= count_graph; + + count_ref = fwnode_devcon_matches(fwnode, con_id, data, match, + matches, matches_len); + + return count_graph + count_ref; +} +EXPORT_SYMBOL_GPL(fwnode_connection_find_matches); diff --git a/include/linux/property.h b/include/linux/property.h index 4cd4b326941f..de7ff336d2c8 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -447,6 +447,11 @@ static inline void *device_connection_find_match(struct device *dev, return fwnode_connection_find_match(dev_fwnode(dev), con_id, data, match); } +int fwnode_connection_find_matches(struct fwnode_handle *fwnode, + const char *con_id, void *data, + devcon_match_fn_t match, + void **matches, unsigned int matches_len); + /* -------------------------------------------------------------------------- */ /* Software fwnode support - when HW description is incomplete or missing */ From patchwork Thu Mar 3 22:33:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 547937 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03877C4167B for ; Thu, 3 Mar 2022 22:32:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236925AbiCCWdC (ORCPT ); Thu, 3 Mar 2022 17:33:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236951AbiCCWdA (ORCPT ); Thu, 3 Mar 2022 17:33:00 -0500 Received: from mail-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B65B15042D for ; Thu, 3 Mar 2022 14:32:07 -0800 (PST) Received: by mail-oi1-x236.google.com with SMTP id j2so6196613oie.7 for ; Thu, 03 Mar 2022 14:32:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1EyMZD3c/zIXsNVVHj1OKSD/HT/7oGKTphYrrLv5168=; b=oKc4oqU8nDy2TFCgnyBWJMqCo1SsOqWK9WQ8aBRmjcKdWhGfm9zGlPdtca5IuKxTqj fJ8YoWzd4HO7UiPynPE0Rxdg6xhLuniDS2TJc4YAVfcpysIK1xAHmR9ewzWHHLIUraOQ N66QQbnAbBn9s/qLP2/tj+X9y2iXLvogDwzt5Olxs/x3rGc/00ubnxc28WU8O8jCY+Rv mJgVk3Ocs0nHxxRxPN8WMgyrYEmJL3YkPmLL34Nu0a481HfTstLAfKdSlke2p6U/krGn KXNGmqFhpML53uMyFtM+pPpTu8fp2HvJwFiAjUP2KKH2l5zQ3DX8ktih+vI6AHVqcyhw +2xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1EyMZD3c/zIXsNVVHj1OKSD/HT/7oGKTphYrrLv5168=; b=BHo+Snq2kaQlu8osm/903Z36SqTEXk+tnQiIKAwzfVbDOPSqU4fdL9WMVRRuR8/q8R t2vQHVqeUc0oPcxN33DmpakxvCSVlb0EgPls46J5LS0+zQd+b9KgMueEJUlR0FTNEDTl o74oJUZ4O5603eMObG15mfaDuyysvCXYZXPlvbD3WWQbapkyCF1Jg/fYekh0gb8KNypc eYmgN9UhRWyJHVU53UhOrAneCo1xlf8TLhlDX4ix9eQS+XnrAK1THcOsVYZhKgkJP0Im UvYxeRCfl9NnFCMF42JY9qWRlKeLWEGL4oL/HMsn/Rq3gCODzeDBt3OJLCgLpD/l0SD/ EHbw== X-Gm-Message-State: AOAM531CejQAhc/+uRF8owJgpm2DYXT4DJlbMDOP8M/dBJkKHyONKw/Q YjfHwmPqJ95M+NughUYAK+AJIw== X-Google-Smtp-Source: ABdhPJwiGWJlSF9hF/8/sULjrKbSMeUf1/DIOzRH1uxY8zKGPp2SKf1nmJKlAhhfKzPMbXrYflMjMQ== X-Received: by 2002:a05:6808:1599:b0:2d4:6846:f0ad with SMTP id t25-20020a056808159900b002d46846f0admr6719328oiw.72.1646346726911; Thu, 03 Mar 2022 14:32:06 -0800 (PST) Received: from ripper.. ([2600:1700:a0:3dc8:205:1bff:fec0:b9b3]) by smtp.gmail.com with ESMTPSA id fq14-20020a0568710b0e00b000d4492531a2sm1764777oab.17.2022.03.03.14.32.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Mar 2022 14:32:06 -0800 (PST) From: Bjorn Andersson To: Rob Herring , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , "Rafael J. Wysocki" , Hans de Goede Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Dmitry Baryshkov Subject: [PATCH v3 4/6] typec: mux: Allow multiple mux_devs per mux Date: Thu, 3 Mar 2022 14:33:49 -0800 Message-Id: <20220303223351.141238-4-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220303223351.141238-1-bjorn.andersson@linaro.org> References: <20220303223351.141238-1-bjorn.andersson@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org In the Qualcomm platforms the USB/DP PHY handles muxing and orientation switching of the SuperSpeed lines, but the SBU lines needs to be connected and switched by external (to the SoC) hardware. It's therefor necessary to be able to have the TypeC controller operate multiple TypeC muxes and switches. Use the newly introduced indirection object to handle this, to avoid having to taint the TypeC controllers with knowledge about the downstream hardware configuration. The max number of devs per indirection is set to 3, which account for being able to mux/switch the USB HS, SS and SBU lines, as per defined defined in the usb-c-connector binding. This number could be grown if need arrises at a later point in time. Acked-by: Heikki Krogerus Signed-off-by: Bjorn Andersson --- Changes since v2: - Picked up Heikki's ack. Changes since v1: - Improved the motivation for the 3 in the commit message. - kfree sw and mux in error paths drivers/usb/typec/mux.c | 128 ++++++++++++++++++++++++++++++++-------- 1 file changed, 102 insertions(+), 26 deletions(-) diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c index d0b42c297aca..cf2347dd1663 100644 --- a/drivers/usb/typec/mux.c +++ b/drivers/usb/typec/mux.c @@ -17,8 +17,11 @@ #include "class.h" #include "mux.h" +#define TYPEC_MUX_MAX_DEVS 3 + struct typec_switch { - struct typec_switch_dev *sw_dev; + struct typec_switch_dev *sw_devs[TYPEC_MUX_MAX_DEVS]; + unsigned int num_sw_devs; }; static int switch_fwnode_match(struct device *dev, const void *fwnode) @@ -67,25 +70,50 @@ static void *typec_switch_match(struct fwnode_handle *fwnode, const char *id, */ struct typec_switch *fwnode_typec_switch_get(struct fwnode_handle *fwnode) { - struct typec_switch_dev *sw_dev; + struct typec_switch_dev *sw_devs[TYPEC_MUX_MAX_DEVS]; struct typec_switch *sw; + int count; + int err; + int i; sw = kzalloc(sizeof(*sw), GFP_KERNEL); if (!sw) return ERR_PTR(-ENOMEM); - sw_dev = fwnode_connection_find_match(fwnode, "orientation-switch", NULL, - typec_switch_match); - if (IS_ERR_OR_NULL(sw_dev)) { + count = fwnode_connection_find_matches(fwnode, "orientation-switch", NULL, + typec_switch_match, + (void **)sw_devs, + ARRAY_SIZE(sw_devs)); + if (count <= 0) { kfree(sw); - return ERR_CAST(sw_dev); + return NULL; } - WARN_ON(!try_module_get(sw_dev->dev.parent->driver->owner)); + for (i = 0; i < count; i++) { + if (IS_ERR(sw_devs[i])) { + err = PTR_ERR(sw_devs[i]); + goto put_sw_devs; + } + } - sw->sw_dev = sw_dev; + for (i = 0; i < count; i++) { + WARN_ON(!try_module_get(sw_devs[i]->dev.parent->driver->owner)); + sw->sw_devs[i] = sw_devs[i]; + } + + sw->num_sw_devs = count; return sw; + +put_sw_devs: + for (i = 0; i < count; i++) { + if (!IS_ERR(sw_devs[i])) + put_device(&sw_devs[i]->dev); + } + + kfree(sw); + + return ERR_PTR(err); } EXPORT_SYMBOL_GPL(fwnode_typec_switch_get); @@ -98,14 +126,17 @@ EXPORT_SYMBOL_GPL(fwnode_typec_switch_get); void typec_switch_put(struct typec_switch *sw) { struct typec_switch_dev *sw_dev; + unsigned int i; if (IS_ERR_OR_NULL(sw)) return; - sw_dev = sw->sw_dev; + for (i = 0; i < sw->num_sw_devs; i++) { + sw_dev = sw->sw_devs[i]; - module_put(sw_dev->dev.parent->driver->owner); - put_device(&sw_dev->dev); + module_put(sw_dev->dev.parent->driver->owner); + put_device(&sw_dev->dev); + } kfree(sw); } EXPORT_SYMBOL_GPL(typec_switch_put); @@ -170,13 +201,21 @@ int typec_switch_set(struct typec_switch *sw, enum typec_orientation orientation) { struct typec_switch_dev *sw_dev; + unsigned int i; + int ret; if (IS_ERR_OR_NULL(sw)) return 0; - sw_dev = sw->sw_dev; + for (i = 0; i < sw->num_sw_devs; i++) { + sw_dev = sw->sw_devs[i]; + + ret = sw_dev->set(sw_dev, orientation); + if (ret) + return ret; + } - return sw_dev->set(sw_dev, orientation); + return 0; } EXPORT_SYMBOL_GPL(typec_switch_set); @@ -208,7 +247,8 @@ EXPORT_SYMBOL_GPL(typec_switch_get_drvdata); /* ------------------------------------------------------------------------- */ struct typec_mux { - struct typec_mux_dev *mux_dev; + struct typec_mux_dev *mux_devs[TYPEC_MUX_MAX_DEVS]; + unsigned int num_mux_devs; }; static int mux_fwnode_match(struct device *dev, const void *fwnode) @@ -291,25 +331,50 @@ static void *typec_mux_match(struct fwnode_handle *fwnode, const char *id, struct typec_mux *fwnode_typec_mux_get(struct fwnode_handle *fwnode, const struct typec_altmode_desc *desc) { - struct typec_mux_dev *mux_dev; + struct typec_mux_dev *mux_devs[TYPEC_MUX_MAX_DEVS]; struct typec_mux *mux; + int count; + int err; + int i; mux = kzalloc(sizeof(*mux), GFP_KERNEL); if (!mux) return ERR_PTR(-ENOMEM); - mux_dev = fwnode_connection_find_match(fwnode, "mode-switch", (void *)desc, - typec_mux_match); - if (IS_ERR_OR_NULL(mux_dev)) { + count = fwnode_connection_find_matches(fwnode, "mode-switch", + (void *)desc, typec_mux_match, + (void **)mux_devs, + ARRAY_SIZE(mux_devs)); + if (count <= 0) { kfree(mux); - return ERR_CAST(mux_dev); + return NULL; } - WARN_ON(!try_module_get(mux_dev->dev.parent->driver->owner)); + for (i = 0; i < count; i++) { + if (IS_ERR(mux_devs[i])) { + err = PTR_ERR(mux_devs[i]); + goto put_mux_devs; + } + } + + for (i = 0; i < count; i++) { + WARN_ON(!try_module_get(mux_devs[i]->dev.parent->driver->owner)); + mux->mux_devs[i] = mux_devs[i]; + } - mux->mux_dev = mux_dev; + mux->num_mux_devs = count; return mux; + +put_mux_devs: + for (i = 0; i < count; i++) { + if (!IS_ERR(mux_devs[i])) + put_device(&mux_devs[i]->dev); + } + + kfree(mux); + + return ERR_PTR(err); } EXPORT_SYMBOL_GPL(fwnode_typec_mux_get); @@ -322,13 +387,16 @@ EXPORT_SYMBOL_GPL(fwnode_typec_mux_get); void typec_mux_put(struct typec_mux *mux) { struct typec_mux_dev *mux_dev; + unsigned int i; if (IS_ERR_OR_NULL(mux)) return; - mux_dev = mux->mux_dev; - module_put(mux_dev->dev.parent->driver->owner); - put_device(&mux_dev->dev); + for (i = 0; i < mux->num_mux_devs; i++) { + mux_dev = mux->mux_devs[i]; + module_put(mux_dev->dev.parent->driver->owner); + put_device(&mux_dev->dev); + } kfree(mux); } EXPORT_SYMBOL_GPL(typec_mux_put); @@ -336,13 +404,21 @@ EXPORT_SYMBOL_GPL(typec_mux_put); int typec_mux_set(struct typec_mux *mux, struct typec_mux_state *state) { struct typec_mux_dev *mux_dev; + unsigned int i; + int ret; if (IS_ERR_OR_NULL(mux)) return 0; - mux_dev = mux->mux_dev; + for (i = 0; i < mux->num_mux_devs; i++) { + mux_dev = mux->mux_devs[i]; + + ret = mux_dev->set(mux_dev, state); + if (ret) + return ret; + } - return mux_dev->set(mux_dev, state); + return 0; } EXPORT_SYMBOL_GPL(typec_mux_set); From patchwork Thu Mar 3 22:33:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 547938 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F78EC4321E for ; Thu, 3 Mar 2022 22:32:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236932AbiCCWdB (ORCPT ); Thu, 3 Mar 2022 17:33:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236950AbiCCWdA (ORCPT ); Thu, 3 Mar 2022 17:33:00 -0500 Received: from mail-oi1-x234.google.com (mail-oi1-x234.google.com [IPv6:2607:f8b0:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 847BD151342 for ; Thu, 3 Mar 2022 14:32:08 -0800 (PST) Received: by mail-oi1-x234.google.com with SMTP id z7so6209231oid.4 for ; Thu, 03 Mar 2022 14:32:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ASiZOAYz5KFcP3A9IjHRNygM9ZeiNc0Yjtm5LFE6Rdc=; b=ae3+M6IkfZ5jIJWwSuAWT+APA3geWlw1DsEAgf4oY1C9rMvnx9bK68l4Zv+1+d21JF H43hFi1TMM69h7jkLG8okLLEx7uXxHJdI2TgdG4ioF5OcavJWIcKrbCBM8a2ze9hj0Wb vw+2AHq3ru1fv0yg+3ybHn+fzAFilDUx7F5N4gv2GPwIB1z7eg4A73mPWetezFqe+Dca AcqNmM9be1MyP0wLK+bq+gbR2AoTuzbzFBBNHr7g1Qpd/6fV56gpEFyzncZk7OgnmRUK zsETF1Ke4Mafo0nHUmGb3d8oqz/uB1CpsS2xxajo8Vlm10aoQU+rXrGGRJJ4EUeXFOHL iQMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ASiZOAYz5KFcP3A9IjHRNygM9ZeiNc0Yjtm5LFE6Rdc=; b=no9XpT23jhPeXEHS3KC9wI9vUT6NEDdBN2uaxXuhz/+KUWjuaMMiSj+eogCD7jdDbQ kNvn+u9KaG5yAFkrWNAkHph/z7Zx3jd+K9HutdxneFkQkEq1MoRFzr8kI4YPv3n0hPv6 lym93ORoddIJNhUk7MfGVe7lanvgFJyBLFsGlllrTNylNYhwmUxrH/b+JF+lWJ3S1Y0+ RNWOlxxkeZbzxn52r/O4PLWiEhqJIXBmcFNYCvm12Z9nHj3xZxdidBAutphJ72Ife8EW Hss1AcJX0hVNCFXV8rSdsXaT3sWalvQr5s75AO8k3GfCDiEukh9ms7SlcUQso8uq646o HUEw== X-Gm-Message-State: AOAM530NVsJfObV/2Ph6fOe8niRyvJ9m9sFT6VZg3V7xHWiKUvN9FF0M TEUFVdsfWt88rwIkHntsNGxoYw== X-Google-Smtp-Source: ABdhPJwZTpBb0lAcz7RJZp79KrGZH2AYZv5mXWcLJKlyRZFmJ6c0paiUJ4LUztTfkTxB/BrAkOdzBA== X-Received: by 2002:a05:6808:1402:b0:2d3:4a20:3dfa with SMTP id w2-20020a056808140200b002d34a203dfamr6624463oiv.143.1646346727905; Thu, 03 Mar 2022 14:32:07 -0800 (PST) Received: from ripper.. ([2600:1700:a0:3dc8:205:1bff:fec0:b9b3]) by smtp.gmail.com with ESMTPSA id fq14-20020a0568710b0e00b000d4492531a2sm1764777oab.17.2022.03.03.14.32.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Mar 2022 14:32:07 -0800 (PST) From: Bjorn Andersson To: Rob Herring , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , "Rafael J. Wysocki" , Hans de Goede Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Dmitry Baryshkov , Rob Herring Subject: [PATCH v3 5/6] dt-bindings: usb: Add binding for fcs,fsa4480 Date: Thu, 3 Mar 2022 14:33:50 -0800 Message-Id: <20220303223351.141238-5-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220303223351.141238-1-bjorn.andersson@linaro.org> References: <20220303223351.141238-1-bjorn.andersson@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The Fairchild/ON Semiconductor FSA4480 Analog Audio switch is used in USB Type-C configurations for muxing analog audio onto the USB connector, and as such used to control the SBU signals for altmodes such as DisplayPort. Add a binding for this hardware block. Reviewed-by: Rob Herring Signed-off-by: Bjorn Andersson --- Changes since v2: - Picked up Rob's reviewed-by Changes since v1: - None .../devicetree/bindings/usb/fcs,fsa4480.yaml | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/fcs,fsa4480.yaml diff --git a/Documentation/devicetree/bindings/usb/fcs,fsa4480.yaml b/Documentation/devicetree/bindings/usb/fcs,fsa4480.yaml new file mode 100644 index 000000000000..9473f26b0621 --- /dev/null +++ b/Documentation/devicetree/bindings/usb/fcs,fsa4480.yaml @@ -0,0 +1,72 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: "http://devicetree.org/schemas/usb/fcs,fsa4480.yaml#" +$schema: "http://devicetree.org/meta-schemas/core.yaml#" + +title: ON Semiconductor Analog Audio Switch + +maintainers: + - Bjorn Andersson + +properties: + compatible: + enum: + - fcs,fsa4480 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + vcc-supply: + description: power supply (2.7V-5.5V) + + mode-switch: + description: Flag the port as possible handle of altmode switching + type: boolean + + orientation-switch: + description: Flag the port as possible handler of orientation switching + type: boolean + + port: + $ref: /schemas/graph.yaml#/properties/port + description: + A port node to link the FSA4480 to a TypeC controller for the purpose of + handling altmode muxing and orientation switching. + +required: + - compatible + - reg + - port + +additionalProperties: false + +examples: + - | + #include + i2c13 { + #address-cells = <1>; + #size-cells = <0>; + + fsa4480@42 { + compatible = "fcs,fsa4480"; + reg = <0x42>; + + interrupts-extended = <&tlmm 2 IRQ_TYPE_LEVEL_LOW>; + + vcc-supply = <&vreg_bob>; + + mode-switch; + orientation-switch; + + port { + fsa4480_ept: endpoint { + remote-endpoint = <&typec_controller>; + }; + }; + }; + }; +...