From nobody Sun Sep 14 22:18:29 2025 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 2AAEAC32793 for ; Wed, 18 Jan 2023 07:46:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229744AbjARHqI (ORCPT ); Wed, 18 Jan 2023 02:46:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229849AbjARHop (ORCPT ); Wed, 18 Jan 2023 02:44:45 -0500 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 459B361D63 for ; Tue, 17 Jan 2023 23:09:33 -0800 (PST) Received: by mail-ed1-x52c.google.com with SMTP id z11so48368475ede.1 for ; Tue, 17 Jan 2023 23:09:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=tz/0Vx6eDg0DiBO/TaaOaa2oRiAZoQpqzz9GXBsd0QI=; b=BOmgKM0ZDO1zyDLyzTQDcxlUBStdroCvk+RDaDQ/lnIrEIpNzUZ8LhHH497vVWux0C lUInWZVL2l+49/noO6Kr/fJXPJ2QzISh2921HrIvaqfnHQUKxyvcNH7/MZy/ZTT3XLoL YmDQcT8cVo1wWxud4qZolFXblmCWHxw6mxM5vjbXCetXdYipM1Uvl36Qxgyqrx1AD/2X unfn9T8iEQ28UpQge+cj8q/+/59hV+ii7noq2IAYbnOBZICU1yxqd+K0V3E1KS7jq8Oo aF3tDoDuQac/ObCPPrSE1Xlpu8AIq+rhFqOH39hdNXUZdwB7w09kXQcs5vT+OtAm+m2h TwQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tz/0Vx6eDg0DiBO/TaaOaa2oRiAZoQpqzz9GXBsd0QI=; b=HAaD+1e4CN7F1mwjJv6kcb0/EnMKJafnR2LPtLZCy427o9iJ0wNSX0byQMVShvDVXQ /lmjC83Ll3U0o6JLMjMWYv7Qqoqz4X0foE+V30wbQWum/0pgy5Ynzx3kicRbipmGif0d OK2bnqi2H0xc3a5e+kgd6sVpyV/XgYjiddv8Ny54upq4JD3HNXdUcU74OzUe6af7pgtd qGnF3TC7VNgEbm+r2KJDNkDhABmsTnOO+gKUZixhmsL/SR+v31FtmRc48Iu1IF0U7Gij qL+nnQdk9uL3Dl0jN5K0glyx2+U+LLy2ZzGMqkGGXAyL61SucdiKdwlf/uOQ7hvg1T7C XiaQ== X-Gm-Message-State: AFqh2koZupCRpud390NSDgOp+nVvVZGIeqBxyCgNX5LPV8JNK3qBSdDJ ZErY1ZDX8xhl2W6bEV+ZEv/NpdBNEI9kjpKc X-Google-Smtp-Source: AMrXdXt4Udi3FAFMC87aqlBsx9ONEbBCJsUYVUhdK45xI3OBB1BGdOLJFxK/Wg0POwC86YiL+z+ZFg== X-Received: by 2002:aa7:d887:0:b0:499:1ed2:6461 with SMTP id u7-20020aa7d887000000b004991ed26461mr5812989edq.17.1674025771805; Tue, 17 Jan 2023 23:09:31 -0800 (PST) Received: from fedora.local (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id bt16-20020a0564020a5000b00482e0c55e2bsm13596984edb.93.2023.01.17.23.09.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 23:09:31 -0800 (PST) From: Linus Walleij Date: Wed, 18 Jan 2023 08:09:15 +0100 Subject: [PATCH v2 1/7] dt-bindings: usb: Correct and extend FOTG210 schema MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230103-gemini-fotg210-usb-v2-1-100388af9810@linaro.org> References: <20230103-gemini-fotg210-usb-v2-0-100388af9810@linaro.org> In-Reply-To: <20230103-gemini-fotg210-usb-v2-0-100388af9810@linaro.org> To: Greg Kroah-Hartman , Rob Herring , Krzysztof Kozlowski Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Fabian Vogt , Linus Walleij X-Mailer: b4 0.11.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It turns out that this IP block exists in at least two incarnations: FOTG200 and FOTG210. The one in the Gemini is FOTG200, so add the variants and rectify the binding for Gemini. This affects things such as the placement of certain registers. It remains to be seen how similar this block is to the third USB block from Faraday, FUSB220. Signed-off-by: Linus Walleij Reviewed-by: Krzysztof Kozlowski --- ChangeLog v1->v2: - Drop stray word "bindings" in description --- Documentation/devicetree/bindings/usb/faraday,fotg210.yaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/usb/faraday,fotg210.yaml b/D= ocumentation/devicetree/bindings/usb/faraday,fotg210.yaml index 84b3b69256b1..3fe4d1564dfe 100644 --- a/Documentation/devicetree/bindings/usb/faraday,fotg210.yaml +++ b/Documentation/devicetree/bindings/usb/faraday,fotg210.yaml @@ -5,7 +5,7 @@ $id: http://devicetree.org/schemas/usb/faraday,fotg210.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# =20 -title: Faraday Technology FOTG210 HS OTG USB 2.0 controller +title: Faraday Technology FOTG200 series HS OTG USB 2.0 controller =20 maintainers: - Linus Walleij @@ -17,10 +17,11 @@ allOf: properties: compatible: oneOf: + - const: faraday,fotg200 - const: faraday,fotg210 - items: - const: cortina,gemini-usb - - const: faraday,fotg210 + - const: faraday,fotg200 =20 reg: maxItems: 1 @@ -66,7 +67,7 @@ examples: #include #include usb0: usb@68000000 { - compatible =3D "cortina,gemini-usb", "faraday,fotg210"; + compatible =3D "cortina,gemini-usb", "faraday,fotg200"; reg =3D <0x68000000 0x1000>; interrupts =3D <10 IRQ_TYPE_LEVEL_HIGH>; resets =3D <&syscon GEMINI_RESET_USB0>; --=20 2.39.0 From nobody Sun Sep 14 22:18:29 2025 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 7B227C004D4 for ; Wed, 18 Jan 2023 07:46:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229576AbjARHpy (ORCPT ); Wed, 18 Jan 2023 02:45:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229902AbjARHor (ORCPT ); Wed, 18 Jan 2023 02:44:47 -0500 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 871F9470B1 for ; Tue, 17 Jan 2023 23:09:34 -0800 (PST) Received: by mail-ed1-x533.google.com with SMTP id 18so48329114edw.7 for ; Tue, 17 Jan 2023 23:09:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=W+ByaNjNMsFVHh2+86A0e94ppJsulN3YnOrh35qT8wE=; b=j2OAqho3+opiA5EDso1N0iVJ8/kZBW3beSDtZYYdS3aPzzUkwS3SAm8pEm7EOhJvHj bD9M4bDvOyqr18y7V47tHmJBYuZdk/OE+ASdFx8OmVeX3tCGCwQwdhGNbvJehuQk0eAF 0aTsmD0w6JuhPMalUOQNiq9ehLy1eaIo106sCXsThKMH4jcNTgIyOSRrDplzzzF66K0K 4yemZrWlRo9tZ57LkQ4UQd3h80UZnLR/2cYO8eOEz2frQGffpIIghK/BFw83SpRLYJB3 TxJqHDt0v6cvvaG1pCCZZzFis3R22em/z0VT2pjChkvDO1lYdLVCQYkLm7XavJPKiP4n 3I4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W+ByaNjNMsFVHh2+86A0e94ppJsulN3YnOrh35qT8wE=; b=TVYW7GVA6a/E35qIhYHtBkS/A4Tx9uiakO7elcgnp6eQG/9AN+Jgu006VO3PnQ7rme yT4RXmISMwmHhQ2WNkLLh7pcH8NzEe2uf7NPXv7KEXTViosARGQIiIusJ1EGObmlHjpd A+OU46xlMQFV+hLaCf/mQY8obKG1CkL1ttEr7sV0eHmbdmprCEMjztudtRcdDmRY8lgx wVbBuE0yAqpZQBGNCTspQWvjIHq6U7MrhMGXAAeBeFglxd8DkDcPCUhse1+FGeRX1Cju BVS9LCMJ2+N+DwL8cYxggEN+9UyFQH138rfiXymnur5kKyCa4nXc3TVHsosEY3jfgluS EgyQ== X-Gm-Message-State: AFqh2krN/QOGt7Lbu6TQPQ4BjHkCzfa57wEIIbkQUMQcsvY8PEQgKLrr h45VaLeK3iTe2IHRscCY2m+Acw== X-Google-Smtp-Source: AMrXdXvUjQ2NHklo1tbpD/3j6iYk5a1/tWpve9YdingtRsyKNBuxJfJOQGbSkjfFInM6pB6qhXtJvw== X-Received: by 2002:a05:6402:524f:b0:490:47c3:3d7f with SMTP id t15-20020a056402524f00b0049047c33d7fmr8255387edd.2.1674025773120; Tue, 17 Jan 2023 23:09:33 -0800 (PST) Received: from fedora.local (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id bt16-20020a0564020a5000b00482e0c55e2bsm13596984edb.93.2023.01.17.23.09.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 23:09:32 -0800 (PST) From: Linus Walleij Date: Wed, 18 Jan 2023 08:09:16 +0100 Subject: [PATCH v2 2/7] usb: fotg210: List different variants MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230103-gemini-fotg210-usb-v2-2-100388af9810@linaro.org> References: <20230103-gemini-fotg210-usb-v2-0-100388af9810@linaro.org> In-Reply-To: <20230103-gemini-fotg210-usb-v2-0-100388af9810@linaro.org> To: Greg Kroah-Hartman , Rob Herring , Krzysztof Kozlowski Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Fabian Vogt , Linus Walleij X-Mailer: b4 0.11.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are at least two variants of the FOTG: FOTG200 and FOTG210. Handle them in this driver and let's add more quirks as we go along. Signed-off-by: Linus Walleij --- drivers/usb/fotg210/fotg210-core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/usb/fotg210/fotg210-core.c b/drivers/usb/fotg210/fotg2= 10-core.c index 8a54edf921ac..cef12827e797 100644 --- a/drivers/usb/fotg210/fotg210-core.c +++ b/drivers/usb/fotg210/fotg210-core.c @@ -127,7 +127,9 @@ static int fotg210_remove(struct platform_device *pdev) =20 #ifdef CONFIG_OF static const struct of_device_id fotg210_of_match[] =3D { + { .compatible =3D "faraday,fotg200" }, { .compatible =3D "faraday,fotg210" }, + /* TODO: can we also handle FUSB220? */ {}, }; MODULE_DEVICE_TABLE(of, fotg210_of_match); --=20 2.39.0 From nobody Sun Sep 14 22:18:29 2025 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 407D9C38159 for ; Wed, 18 Jan 2023 07:45:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229646AbjARHp3 (ORCPT ); Wed, 18 Jan 2023 02:45:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229995AbjARHox (ORCPT ); Wed, 18 Jan 2023 02:44:53 -0500 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF10063E06 for ; Tue, 17 Jan 2023 23:09:35 -0800 (PST) Received: by mail-ed1-x533.google.com with SMTP id v30so48343641edb.9 for ; Tue, 17 Jan 2023 23:09:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=a3+Ki3jVLQ0LRVXvgBC5LvGWwpzkotK4uxgJyLKL2bM=; b=vewduD/jVKEMwZZFSWQzb5JyBn0POCggM/Ke8wGza2mC4TKmzBy1Z1t3tZNYC19JtS KPh+e3siB+GMgsJNYMKhkxYy7Do59VzaRxc68cLGHuG3OkiHmCQSpJjTWoNptd1VeRiU w4CXy6HsR1cjLwjGWMDytBzspLv/DJaf9cR4f02nLusa9Xj+iQ/GIWqd3aw8aYcsDAfs hsEBP7gW8j2S148wXY3HmgBKk4PJAkLcU5+O32vFRuULVNl/HRGkoIy2yuYGkrHb/KA1 9SsaDhI9Plff56ltuIR3YInh1aJNhP7kxWuoztFSLszGZBxEyJJETT2EZb3zDgtn3rML /qjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=a3+Ki3jVLQ0LRVXvgBC5LvGWwpzkotK4uxgJyLKL2bM=; b=TVilVMFlFUCNykM18vloTOn2BSeHvJhGcB8gDZAfrFGmUBh9G9wjWwHyp1fNc4das8 IMOkwAhL5/DQmc/KzXMdhbwzUvUaHS+v70lV19rSYtYEMG9YpxSqRNJYGA69dys6JEUY ZSDh41+stdwhRJWgJEkzQ1cRKGG/pFPgOKwa26KT0/U+Ei2+Td7Ik7qOz/aICLQCp7TI SVcIJtEV7PGAX0fMfeLORMROZowCqnzbWRNXzg2yVxZ2yUABvlc4BzetAXXlaOYbQS0y h1Km0NuxdreTAcF/4N76F+r2ex5zYQd4nDoT49B5QyzNZJ3Y4ubFyJ0E3Ac3Y9G6aqLN JmCg== X-Gm-Message-State: AFqh2krePo3EUml8RV28CznPOJURT41G7F5Sg6bcqeGSxKq6yXsnNa23 C6+VDNPssJX0fabGecjYztsHUQ== X-Google-Smtp-Source: AMrXdXuhBSl9RsDzVcHcePXxiXpm9ySg8ojiHz96hagXoVg64LCiMcprPcjn+z5ScvmVN4AU9LZkWg== X-Received: by 2002:aa7:c91a:0:b0:48e:c0c3:796f with SMTP id b26-20020aa7c91a000000b0048ec0c3796fmr5705818edt.28.1674025774347; Tue, 17 Jan 2023 23:09:34 -0800 (PST) Received: from fedora.local (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id bt16-20020a0564020a5000b00482e0c55e2bsm13596984edb.93.2023.01.17.23.09.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 23:09:34 -0800 (PST) From: Linus Walleij Date: Wed, 18 Jan 2023 08:09:17 +0100 Subject: [PATCH v2 3/7] usb: fotg210: Acquire memory resource in core MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230103-gemini-fotg210-usb-v2-3-100388af9810@linaro.org> References: <20230103-gemini-fotg210-usb-v2-0-100388af9810@linaro.org> In-Reply-To: <20230103-gemini-fotg210-usb-v2-0-100388af9810@linaro.org> To: Greg Kroah-Hartman , Rob Herring , Krzysztof Kozlowski Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Fabian Vogt , Linus Walleij X-Mailer: b4 0.11.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The subdrivers are obtaining and mapping the memory resource separately. Create a common state container for the shared resources and start populating this by acquiring the IO memory resource and remap it and pass this to the subdrivers for host and peripheral. Signed-off-by: Linus Walleij --- drivers/usb/fotg210/fotg210-core.c | 29 ++++++++++++++++++++++------- drivers/usb/fotg210/fotg210-hcd.c | 15 +++++---------- drivers/usb/fotg210/fotg210-hcd.h | 1 + drivers/usb/fotg210/fotg210-udc.c | 16 +++------------- drivers/usb/fotg210/fotg210-udc.h | 1 + drivers/usb/fotg210/fotg210.h | 24 ++++++++++++++++++++---- 6 files changed, 52 insertions(+), 34 deletions(-) diff --git a/drivers/usb/fotg210/fotg210-core.c b/drivers/usb/fotg210/fotg2= 10-core.c index cef12827e797..4593120c02de 100644 --- a/drivers/usb/fotg210/fotg210-core.c +++ b/drivers/usb/fotg210/fotg210-core.c @@ -33,9 +33,10 @@ #define GEMINI_MISC_USB0_MINI_B BIT(29) #define GEMINI_MISC_USB1_MINI_B BIT(30) =20 -static int fotg210_gemini_init(struct device *dev, struct resource *res, +static int fotg210_gemini_init(struct fotg210 *fotg, struct resource *res, enum usb_dr_mode mode) { + struct device *dev =3D fotg->dev; struct device_node *np =3D dev->of_node; struct regmap *map; bool wakeup; @@ -47,6 +48,7 @@ static int fotg210_gemini_init(struct device *dev, struct= resource *res, dev_err(dev, "no syscon\n"); return PTR_ERR(map); } + fotg->map =3D map; wakeup =3D of_property_read_bool(np, "wakeup-source"); =20 /* @@ -55,6 +57,7 @@ static int fotg210_gemini_init(struct device *dev, struct= resource *res, */ mask =3D 0; if (res->start =3D=3D 0x69000000) { + fotg->port =3D GEMINI_PORT_1; mask =3D GEMINI_MISC_USB1_VBUS_ON | GEMINI_MISC_USB1_MINI_B | GEMINI_MISC_USB1_WAKEUP; if (mode =3D=3D USB_DR_MODE_HOST) @@ -64,6 +67,7 @@ static int fotg210_gemini_init(struct device *dev, struct= resource *res, if (wakeup) val |=3D GEMINI_MISC_USB1_WAKEUP; } else { + fotg->port =3D GEMINI_PORT_0; mask =3D GEMINI_MISC_USB0_VBUS_ON | GEMINI_MISC_USB0_MINI_B | GEMINI_MISC_USB0_WAKEUP; if (mode =3D=3D USB_DR_MODE_HOST) @@ -89,23 +93,34 @@ static int fotg210_probe(struct platform_device *pdev) { struct device *dev =3D &pdev->dev; enum usb_dr_mode mode; + struct fotg210 *fotg; int ret; =20 + fotg =3D devm_kzalloc(dev, sizeof(*fotg), GFP_KERNEL); + if (!fotg) + return -ENOMEM; + fotg->dev =3D dev; + + fotg->res =3D platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!fotg->res) + return -ENODEV; + + fotg->base =3D devm_ioremap_resource(dev, fotg->res); + if (!fotg->base) + return -ENOMEM; + mode =3D usb_get_dr_mode(dev); =20 if (of_device_is_compatible(dev->of_node, "cortina,gemini-usb")) { - struct resource *res; - - res =3D platform_get_resource(pdev, IORESOURCE_MEM, 0); - ret =3D fotg210_gemini_init(dev, res, mode); + ret =3D fotg210_gemini_init(fotg, fotg->res, mode); if (ret) return ret; } =20 if (mode =3D=3D USB_DR_MODE_PERIPHERAL) - ret =3D fotg210_udc_probe(pdev); + ret =3D fotg210_udc_probe(pdev, fotg); else - ret =3D fotg210_hcd_probe(pdev); + ret =3D fotg210_hcd_probe(pdev, fotg); =20 return ret; } diff --git a/drivers/usb/fotg210/fotg210-hcd.c b/drivers/usb/fotg210/fotg21= 0-hcd.c index 51ac93a2eb98..15ba5b1618e1 100644 --- a/drivers/usb/fotg210/fotg210-hcd.c +++ b/drivers/usb/fotg210/fotg210-hcd.c @@ -5557,11 +5557,10 @@ static void fotg210_init(struct fotg210_hcd *fotg21= 0) * then invokes the start() method for the HCD associated with it * through the hotplug entry's driver_data. */ -int fotg210_hcd_probe(struct platform_device *pdev) +int fotg210_hcd_probe(struct platform_device *pdev, struct fotg210 *fotg) { struct device *dev =3D &pdev->dev; struct usb_hcd *hcd; - struct resource *res; int irq; int retval; struct fotg210_hcd *fotg210; @@ -5585,18 +5584,14 @@ int fotg210_hcd_probe(struct platform_device *pdev) =20 hcd->has_tt =3D 1; =20 - res =3D platform_get_resource(pdev, IORESOURCE_MEM, 0); - hcd->regs =3D devm_ioremap_resource(&pdev->dev, res); - if (IS_ERR(hcd->regs)) { - retval =3D PTR_ERR(hcd->regs); - goto failed_put_hcd; - } + hcd->regs =3D fotg->base; =20 - hcd->rsrc_start =3D res->start; - hcd->rsrc_len =3D resource_size(res); + hcd->rsrc_start =3D fotg->res->start; + hcd->rsrc_len =3D resource_size(fotg->res); =20 fotg210 =3D hcd_to_fotg210(hcd); =20 + fotg210->fotg =3D fotg; fotg210->caps =3D hcd->regs; =20 /* It's OK not to supply this clock */ diff --git a/drivers/usb/fotg210/fotg210-hcd.h b/drivers/usb/fotg210/fotg21= 0-hcd.h index 0781442b7a24..13c9342982ee 100644 --- a/drivers/usb/fotg210/fotg210-hcd.h +++ b/drivers/usb/fotg210/fotg210-hcd.h @@ -182,6 +182,7 @@ struct fotg210_hcd { /* one per controller */ # define INCR(x) do {} while (0) #endif =20 + struct fotg210 *fotg; /* Overarching FOTG210 device */ /* silicon clock */ struct clk *pclk; }; diff --git a/drivers/usb/fotg210/fotg210-udc.c b/drivers/usb/fotg210/fotg21= 0-udc.c index 66e1b7ee3346..034193592a36 100644 --- a/drivers/usb/fotg210/fotg210-udc.c +++ b/drivers/usb/fotg210/fotg210-udc.c @@ -1142,21 +1142,14 @@ int fotg210_udc_remove(struct platform_device *pdev) return 0; } =20 -int fotg210_udc_probe(struct platform_device *pdev) +int fotg210_udc_probe(struct platform_device *pdev, struct fotg210 *fotg) { - struct resource *res; struct fotg210_udc *fotg210 =3D NULL; struct device *dev =3D &pdev->dev; int irq; int ret =3D 0; int i; =20 - res =3D platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!res) { - pr_err("platform_get_resource error.\n"); - return -ENODEV; - } - irq =3D platform_get_irq(pdev, 0); if (irq < 0) { pr_err("could not get irq\n"); @@ -1169,6 +1162,7 @@ int fotg210_udc_probe(struct platform_device *pdev) return -ENOMEM; =20 fotg210->dev =3D dev; + fotg210->fotg =3D fotg; =20 /* It's OK not to supply this clock */ fotg210->pclk =3D devm_clk_get(dev, "PCLK"); @@ -1207,11 +1201,7 @@ int fotg210_udc_probe(struct platform_device *pdev) goto err_alloc; } =20 - fotg210->reg =3D ioremap(res->start, resource_size(res)); - if (fotg210->reg =3D=3D NULL) { - dev_err(dev, "ioremap error\n"); - goto err_alloc; - } + fotg210->reg =3D fotg->base; =20 spin_lock_init(&fotg210->lock); =20 diff --git a/drivers/usb/fotg210/fotg210-udc.h b/drivers/usb/fotg210/fotg21= 0-udc.h index fadb57ca8d78..20335a38a410 100644 --- a/drivers/usb/fotg210/fotg210-udc.h +++ b/drivers/usb/fotg210/fotg210-udc.h @@ -236,6 +236,7 @@ struct fotg210_udc { unsigned long irq_trigger; =20 struct device *dev; + struct fotg210 *fotg; struct usb_phy *phy; struct usb_gadget gadget; struct usb_gadget_driver *driver; diff --git a/drivers/usb/fotg210/fotg210.h b/drivers/usb/fotg210/fotg210.h index ef79d8323d89..50436cc16538 100644 --- a/drivers/usb/fotg210/fotg210.h +++ b/drivers/usb/fotg210/fotg210.h @@ -2,13 +2,28 @@ #ifndef __FOTG210_H #define __FOTG210_H =20 +enum gemini_port { + GEMINI_PORT_NONE =3D 0, + GEMINI_PORT_0, + GEMINI_PORT_1, +}; + +struct fotg210 { + struct device *dev; + struct resource *res; + void __iomem *base; + struct regmap *map; + enum gemini_port port; +}; + #ifdef CONFIG_USB_FOTG210_HCD -int fotg210_hcd_probe(struct platform_device *pdev); +int fotg210_hcd_probe(struct platform_device *pdev, struct fotg210 *fotg); int fotg210_hcd_remove(struct platform_device *pdev); int fotg210_hcd_init(void); void fotg210_hcd_cleanup(void); #else -static inline int fotg210_hcd_probe(struct platform_device *pdev) +static inline int fotg210_hcd_probe(struct platform_device *pdev, + struct fotg210 *fotg) { return 0; } @@ -26,10 +41,11 @@ static inline void fotg210_hcd_cleanup(void) #endif =20 #ifdef CONFIG_USB_FOTG210_UDC -int fotg210_udc_probe(struct platform_device *pdev); +int fotg210_udc_probe(struct platform_device *pdev, struct fotg210 *fotg); int fotg210_udc_remove(struct platform_device *pdev); #else -static inline int fotg210_udc_probe(struct platform_device *pdev) +static inline int fotg210_udc_probe(struct platform_device *pdev, + struct fotg210 *fotg) { return 0; } --=20 2.39.0 From nobody Sun Sep 14 22:18:29 2025 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 D3457C004D4 for ; Wed, 18 Jan 2023 07:46:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229470AbjARHqY (ORCPT ); Wed, 18 Jan 2023 02:46:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230048AbjARHoz (ORCPT ); Wed, 18 Jan 2023 02:44:55 -0500 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEF3861D6B for ; Tue, 17 Jan 2023 23:09:36 -0800 (PST) Received: by mail-ed1-x530.google.com with SMTP id x36so13684182ede.13 for ; Tue, 17 Jan 2023 23:09:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=MPfoISQ8yjAy6Kx331RQfusK05V745Ciii+y5Z5oDqY=; b=wmBctA3n37PE/Qp9VALE9hvyzokhZGhVlRNSBMG/pR54HplM0ADaFZtoQFMksmipEH BEjNgVhJHaYD3m+ygGntHKc58L/3ykSpeavTFyxZz5O1leoe+/DM+ePod4CBmWLxwAgV IK/YQT7ilfTtVzQixBiKdyVxImzjpGhkmtXPc8yb+SBpOGtbx7SbrcKelgEtejFs0fiI S/fiNx6xMaezZ+IZRpe437F8EYrB3ovmHkKIaLrs4eqHLEAx1jJYPMU3xHWsNd8VWcDH Xk0mrBequEd/CuuXL/cIoB//DRWRvUA84Emwn1so7JKoE+EEmgr784BZHZp4+5zaHZa5 nJkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MPfoISQ8yjAy6Kx331RQfusK05V745Ciii+y5Z5oDqY=; b=uxBzAGYEzlNOm130ttoBdTWRJwWx6J6OBY1pJvQriJ9ovmJBU2oXsRwQL/MjoG8fDW 9Xft4hC581W8gavTyFti7rZc/ONCJ3ATYSTon3TAJ6tt/cTIiAfBBTam/zB/6LvhL7OC 61Onex72ha0xoxrA7Y0Q4vevjIPa52j366Uu/ITaje+AXFzyCcN/XqvwKcqT7pieNlRf SYC+T+kig8QQDFMJ6CMGhvVwWfBxxH1w16y6B+97fY5eY4IjoD6O2RsckK3cRD3icEor +j+l0AtzTIvZK/bTd8kP34gKAwF0/VHTWNi/1/wJZodqRdjMfWnBfPQcOuHVGxLJrtTa m2ZA== X-Gm-Message-State: AFqh2kqDdfLtpm3LaFhokIyf2KjBODa7s5mBcQJssecIlaxxi9X+slx/ iiZmTyuD1GbJv9O7sDW2LyGffT7Dy5GNS7T6 X-Google-Smtp-Source: AMrXdXu4OC2mKZpsbLSD/HcB5wYa2/7FLc96flTP6G7qjawHln77BreuslsRpeko5dWsoYGR520/6A== X-Received: by 2002:a05:6402:14d0:b0:498:1995:ac54 with SMTP id f16-20020a05640214d000b004981995ac54mr5288614edx.40.1674025775533; Tue, 17 Jan 2023 23:09:35 -0800 (PST) Received: from fedora.local (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id bt16-20020a0564020a5000b00482e0c55e2bsm13596984edb.93.2023.01.17.23.09.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 23:09:35 -0800 (PST) From: Linus Walleij Date: Wed, 18 Jan 2023 08:09:18 +0100 Subject: [PATCH v2 4/7] usb: fotg210: Move clock handling to core MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230103-gemini-fotg210-usb-v2-4-100388af9810@linaro.org> References: <20230103-gemini-fotg210-usb-v2-0-100388af9810@linaro.org> In-Reply-To: <20230103-gemini-fotg210-usb-v2-0-100388af9810@linaro.org> To: Greg Kroah-Hartman , Rob Herring , Krzysztof Kozlowski Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Fabian Vogt , Linus Walleij X-Mailer: b4 0.11.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Grab the optional silicon block clock, prepare and enable it in the core before proceeding to prepare the host or peripheral driver. This saves duplicate code and also uses the simple devm_clk_get_optional_enabled() to do everything we really want to do. Signed-off-by: Linus Walleij --- drivers/usb/fotg210/fotg210-core.c | 5 +++++ drivers/usb/fotg210/fotg210-hcd.c | 33 ++------------------------------- drivers/usb/fotg210/fotg210-udc.c | 30 +++--------------------------- drivers/usb/fotg210/fotg210-udc.h | 1 - drivers/usb/fotg210/fotg210.h | 1 + 5 files changed, 11 insertions(+), 59 deletions(-) diff --git a/drivers/usb/fotg210/fotg210-core.c b/drivers/usb/fotg210/fotg2= 10-core.c index 4593120c02de..58d84747fb30 100644 --- a/drivers/usb/fotg210/fotg210-core.c +++ b/drivers/usb/fotg210/fotg210-core.c @@ -6,6 +6,7 @@ * driver. */ #include +#include #include #include #include @@ -109,6 +110,10 @@ static int fotg210_probe(struct platform_device *pdev) if (!fotg->base) return -ENOMEM; =20 + fotg->pclk =3D devm_clk_get_optional_enabled(dev, "PCLK"); + if (IS_ERR(fotg->pclk)) + return PTR_ERR(fotg->pclk); + mode =3D usb_get_dr_mode(dev); =20 if (of_device_is_compatible(dev->of_node, "cortina,gemini-usb")) { diff --git a/drivers/usb/fotg210/fotg210-hcd.c b/drivers/usb/fotg210/fotg21= 0-hcd.c index 15ba5b1618e1..7bd1e8f3080d 100644 --- a/drivers/usb/fotg210/fotg210-hcd.c +++ b/drivers/usb/fotg210/fotg210-hcd.c @@ -33,7 +33,6 @@ #include #include #include -#include =20 #include #include @@ -5594,44 +5593,22 @@ int fotg210_hcd_probe(struct platform_device *pdev,= struct fotg210 *fotg) fotg210->fotg =3D fotg; fotg210->caps =3D hcd->regs; =20 - /* It's OK not to supply this clock */ - fotg210->pclk =3D clk_get(dev, "PCLK"); - if (!IS_ERR(fotg210->pclk)) { - retval =3D clk_prepare_enable(fotg210->pclk); - if (retval) { - dev_err(dev, "failed to enable PCLK\n"); - goto failed_put_hcd; - } - } else if (PTR_ERR(fotg210->pclk) =3D=3D -EPROBE_DEFER) { - /* - * Percolate deferrals, for anything else, - * just live without the clocking. - */ - retval =3D PTR_ERR(fotg210->pclk); - goto failed_dis_clk; - } - retval =3D fotg210_setup(hcd); if (retval) - goto failed_dis_clk; + goto failed_put_hcd; =20 fotg210_init(fotg210); =20 retval =3D usb_add_hcd(hcd, irq, IRQF_SHARED); if (retval) { dev_err(dev, "failed to add hcd with err %d\n", retval); - goto failed_dis_clk; + goto failed_put_hcd; } device_wakeup_enable(hcd->self.controller); platform_set_drvdata(pdev, hcd); =20 return retval; =20 -failed_dis_clk: - if (!IS_ERR(fotg210->pclk)) { - clk_disable_unprepare(fotg210->pclk); - clk_put(fotg210->pclk); - } failed_put_hcd: usb_put_hcd(hcd); fail_create_hcd: @@ -5647,12 +5624,6 @@ int fotg210_hcd_probe(struct platform_device *pdev, = struct fotg210 *fotg) int fotg210_hcd_remove(struct platform_device *pdev) { struct usb_hcd *hcd =3D platform_get_drvdata(pdev); - struct fotg210_hcd *fotg210 =3D hcd_to_fotg210(hcd); - - if (!IS_ERR(fotg210->pclk)) { - clk_disable_unprepare(fotg210->pclk); - clk_put(fotg210->pclk); - } =20 usb_remove_hcd(hcd); usb_put_hcd(hcd); diff --git a/drivers/usb/fotg210/fotg210-udc.c b/drivers/usb/fotg210/fotg21= 0-udc.c index 034193592a36..6a4b94d26951 100644 --- a/drivers/usb/fotg210/fotg210-udc.c +++ b/drivers/usb/fotg210/fotg210-udc.c @@ -15,7 +15,6 @@ #include #include #include -#include #include #include =20 @@ -1134,9 +1133,6 @@ int fotg210_udc_remove(struct platform_device *pdev) for (i =3D 0; i < FOTG210_MAX_NUM_EP; i++) kfree(fotg210->ep[i]); =20 - if (!IS_ERR(fotg210->pclk)) - clk_disable_unprepare(fotg210->pclk); - kfree(fotg210); =20 return 0; @@ -1164,34 +1160,17 @@ int fotg210_udc_probe(struct platform_device *pdev,= struct fotg210 *fotg) fotg210->dev =3D dev; fotg210->fotg =3D fotg; =20 - /* It's OK not to supply this clock */ - fotg210->pclk =3D devm_clk_get(dev, "PCLK"); - if (!IS_ERR(fotg210->pclk)) { - ret =3D clk_prepare_enable(fotg210->pclk); - if (ret) { - dev_err(dev, "failed to enable PCLK\n"); - goto err; - } - } else if (PTR_ERR(fotg210->pclk) =3D=3D -EPROBE_DEFER) { - /* - * Percolate deferrals, for anything else, - * just live without the clocking. - */ - ret =3D -EPROBE_DEFER; - goto err; - } - fotg210->phy =3D devm_usb_get_phy_by_phandle(dev, "usb-phy", 0); if (IS_ERR(fotg210->phy)) { ret =3D PTR_ERR(fotg210->phy); if (ret =3D=3D -EPROBE_DEFER) - goto err_pclk; + goto err_free; dev_info(dev, "no PHY found\n"); fotg210->phy =3D NULL; } else { ret =3D usb_phy_init(fotg210->phy); if (ret) - goto err_pclk; + goto err_free; dev_info(dev, "found and initialized PHY\n"); } =20 @@ -1286,11 +1265,8 @@ int fotg210_udc_probe(struct platform_device *pdev, = struct fotg210 *fotg) err_alloc: for (i =3D 0; i < FOTG210_MAX_NUM_EP; i++) kfree(fotg210->ep[i]); -err_pclk: - if (!IS_ERR(fotg210->pclk)) - clk_disable_unprepare(fotg210->pclk); =20 -err: +err_free: kfree(fotg210); return ret; } diff --git a/drivers/usb/fotg210/fotg210-udc.h b/drivers/usb/fotg210/fotg21= 0-udc.h index 20335a38a410..22b72caf498c 100644 --- a/drivers/usb/fotg210/fotg210-udc.h +++ b/drivers/usb/fotg210/fotg210-udc.h @@ -231,7 +231,6 @@ struct fotg210_ep { struct fotg210_udc { spinlock_t lock; /* protect the struct */ void __iomem *reg; - struct clk *pclk; =20 unsigned long irq_trigger; =20 diff --git a/drivers/usb/fotg210/fotg210.h b/drivers/usb/fotg210/fotg210.h index 50436cc16538..4d0d4ae1a957 100644 --- a/drivers/usb/fotg210/fotg210.h +++ b/drivers/usb/fotg210/fotg210.h @@ -12,6 +12,7 @@ struct fotg210 { struct device *dev; struct resource *res; void __iomem *base; + struct clk *pclk; struct regmap *map; enum gemini_port port; }; --=20 2.39.0 From nobody Sun Sep 14 22:18:29 2025 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 95369C004D4 for ; Wed, 18 Jan 2023 07:47:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229544AbjARHq5 (ORCPT ); Wed, 18 Jan 2023 02:46:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230051AbjARHoz (ORCPT ); Wed, 18 Jan 2023 02:44:55 -0500 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23AD463E11 for ; Tue, 17 Jan 2023 23:09:37 -0800 (PST) Received: by mail-ed1-x530.google.com with SMTP id b4so28839131edf.0 for ; Tue, 17 Jan 2023 23:09:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=sResmjpkOst92em2xHEqCRKaDl2VpyxVgJORb+VfbaQ=; b=YemzCb/qx1iRfYzhK9MKaNtuiANnVfC1Abut0sC2esnXr2/e+4FpPdrNk8mYkAQWoM BZENHwcZvGshPwQWDz5EjDBnHW6zY9Iqe5ziDE4GUICXxQid/AKpK87Ukj32x1c/MJqp HzqWrCB0q6TxjbFtDi/h6W5e6HtSLqVkd2EzLgiBGM/kYJUSuLQbdm8Kd+bclLgn26M4 B07WtxWgeNeXX+pvGTXdTfICy0GIo46l/iHWM4TyjR1Dn4DxnQAw7utgEKARMSkYfwLn Ka7ZGRQjc676jd5oTl7XYr24IintPyUY/ADOlTXsBKxdZhQsT/9KgqjEzc8noOj8MDxk hJuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sResmjpkOst92em2xHEqCRKaDl2VpyxVgJORb+VfbaQ=; b=0Y1EBpewCnNzreJDFNrOfx/JlUL9/Gls9OwOTfkQRIG2W84BoNLtiJlqW+AidqtDw6 6tLhm47KUB7laSarWkUvocnqWrhzGasuL6xLYpuAxkdlgHwN/l3LzVpmT7EjanzThWA3 r+pSPexPieh0MRVOrzENziQddBbhjRX2UFR4TEYN8zJKKg2Ib1ZZK75IbBuG7nj1NG+I ijzV1oywwc1tMP/xWrlW6zVWJ6rXcQkwGdATavRQYzPHY5Z7fFc0nMcwqGbe9enAd6zn qnuLhW1xsJ2WMC8h9yqytmwRYyagpaiEX2JDvUv+/Rq+MTgMoF9X06DmY+J9z86k6s6+ 5oOQ== X-Gm-Message-State: AFqh2kr9IeNE4qccKkNuwE5DGtsQGxra5SZNY8Kz3SzZDknaH9trDrVw e5df1n0nEO9hd9iMl0vgOio74A== X-Google-Smtp-Source: AMrXdXvHolvXpn338X+Xd6mmsm/S0UgEeFH7Qz6oPd+L0ab6LKcoRXGsVyk6VswdzoX9g5djyMJ1og== X-Received: by 2002:a05:6402:4025:b0:49b:67c3:39ae with SMTP id d37-20020a056402402500b0049b67c339aemr6608930eda.33.1674025776660; Tue, 17 Jan 2023 23:09:36 -0800 (PST) Received: from fedora.local (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id bt16-20020a0564020a5000b00482e0c55e2bsm13596984edb.93.2023.01.17.23.09.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 23:09:36 -0800 (PST) From: Linus Walleij Date: Wed, 18 Jan 2023 08:09:19 +0100 Subject: [PATCH v2 5/7] usb: fotg210: Check role register in core MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230103-gemini-fotg210-usb-v2-5-100388af9810@linaro.org> References: <20230103-gemini-fotg210-usb-v2-0-100388af9810@linaro.org> In-Reply-To: <20230103-gemini-fotg210-usb-v2-0-100388af9810@linaro.org> To: Greg Kroah-Hartman , Rob Herring , Krzysztof Kozlowski Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Fabian Vogt , Linus Walleij X-Mailer: b4 0.11.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Read the role register and check that we are in host/peripheral mode and issue warnings if we're not in the right role when probing respective driver. Signed-off-by: Linus Walleij --- drivers/usb/fotg210/fotg210-core.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/usb/fotg210/fotg210-core.c b/drivers/usb/fotg210/fotg2= 10-core.c index 58d84747fb30..013a1d0112fc 100644 --- a/drivers/usb/fotg210/fotg210-core.c +++ b/drivers/usb/fotg210/fotg210-core.c @@ -18,6 +18,11 @@ =20 #include "fotg210.h" =20 +/* Role Register 0x80 */ +#define FOTG210_RR 0x80 +#define FOTG210_RR_ID BIT(21) /* 1 =3D B-device, 0 =3D A-device */ +#define FOTG210_RR_CROLE BIT(20) /* 1 =3D device, 0 =3D host */ + /* * Gemini-specific initialization function, only executed on the * Gemini SoC using the global misc control register. @@ -95,6 +100,7 @@ static int fotg210_probe(struct platform_device *pdev) struct device *dev =3D &pdev->dev; enum usb_dr_mode mode; struct fotg210 *fotg; + u32 val; int ret; =20 fotg =3D devm_kzalloc(dev, sizeof(*fotg), GFP_KERNEL); @@ -122,10 +128,16 @@ static int fotg210_probe(struct platform_device *pdev) return ret; } =20 - if (mode =3D=3D USB_DR_MODE_PERIPHERAL) + val =3D readl(fotg->base + FOTG210_RR); + if (mode =3D=3D USB_DR_MODE_PERIPHERAL) { + if (!(val & FOTG210_RR_CROLE)) + dev_err(dev, "block not in device role\n"); ret =3D fotg210_udc_probe(pdev, fotg); - else + } else { + if (val & FOTG210_RR_CROLE) + dev_err(dev, "block not in host role\n"); ret =3D fotg210_hcd_probe(pdev, fotg); + } =20 return ret; } --=20 2.39.0 From nobody Sun Sep 14 22:18:29 2025 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 79840C004D4 for ; Wed, 18 Jan 2023 07:47:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229734AbjARHrI (ORCPT ); Wed, 18 Jan 2023 02:47:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230100AbjARHo6 (ORCPT ); Wed, 18 Jan 2023 02:44:58 -0500 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2480963E2E for ; Tue, 17 Jan 2023 23:09:38 -0800 (PST) Received: by mail-ed1-x52c.google.com with SMTP id v6so48278817edd.6 for ; Tue, 17 Jan 2023 23:09:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=BGi6nevtBEvlgNue4HrSz3FnhFRGHNrkieQvtpQFYHc=; b=YtWCclO174QhyaMA5EVNNQLEWZVxz+9FPz49LoHxX2km/CLtESfB+9DI3Ioq/2Axmz ZIdzk2YypknjThU/8BJSCfqmXhoEtefbk2or5M0kiK0rhsMybkXbKV92/dpwpewYjKMe ZW8gR0PdnL1d6aDKso6qqZKbCSYwjg5Ay2BQxN93YOG2scLrRlPBe9oYcWi02CteNDPK rJiAPrxMv1jqH8YvB4R/0C8J3dBUHG2xj7Y072Bm/LyyBCa4jiK4ztQnApC012ubxC1G PA3j01E5IQ+lkOUrNXKe6E0ppjHgCXo99HP3+/2YXjJsTgIMHjEf7Em9bbIcITNwnd9w 1pUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BGi6nevtBEvlgNue4HrSz3FnhFRGHNrkieQvtpQFYHc=; b=idxpseY55+v1W3Md8pVLjD7ettCWg3TAdMcD9TysfA8cmIIGO39DV/7kK12Pw7wNvF GRAweSK4YtP2wDGmQqCWJnkTyT9d1BeJWyNOOm0TZDaOx6dOPm0+/mE6TyE5oPcD68Q2 Yt1haYtOUe4knGtuwMOq/fml679UY3/lnZPRZk+CSGwYW+pGN9kLM6o8y39iqmADFmxi tDaoDfTZgUbvtZSzNnEP3rozvqx3qkiTwTz2bxnK4Z2AAGYG9EaU/uv9D7uO5ejUkp1f 1B6yfvaDaS3oWZPGTAoGi4BoSaUZ+AeH+jrVC63CV6nm3JulQZT/7yJqvzYupDM6B5k3 QymA== X-Gm-Message-State: AFqh2kp9VfE2SMnNeiKFpNsMNEjPT6qA8ieAHEb2+MMqb06fX9G4zmDj cKV62FPdOj8TS2INW/iufuZ2ZQ== X-Google-Smtp-Source: AMrXdXuwTSY8tCFZbjM9bYBnfxUsuHCctXu6vpXm8O9G6S2RSxRklk3QaVS88VNS2HuBjvhxm1j1+A== X-Received: by 2002:a05:6402:3226:b0:498:1ca:80d0 with SMTP id g38-20020a056402322600b0049801ca80d0mr7193209eda.28.1674025777745; Tue, 17 Jan 2023 23:09:37 -0800 (PST) Received: from fedora.local (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id bt16-20020a0564020a5000b00482e0c55e2bsm13596984edb.93.2023.01.17.23.09.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 23:09:37 -0800 (PST) From: Linus Walleij Date: Wed, 18 Jan 2023 08:09:20 +0100 Subject: [PATCH v2 6/7] usb: fotg210-udc: Assign of_node and speed on start MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230103-gemini-fotg210-usb-v2-6-100388af9810@linaro.org> References: <20230103-gemini-fotg210-usb-v2-0-100388af9810@linaro.org> In-Reply-To: <20230103-gemini-fotg210-usb-v2-0-100388af9810@linaro.org> To: Greg Kroah-Hartman , Rob Herring , Krzysztof Kozlowski Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Fabian Vogt , Linus Walleij X-Mailer: b4 0.11.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Follow the example set by other drivers to assign of_node and speed to the driver when binding, also print bound info akin to other UDC drivers. Signed-off-by: Linus Walleij --- drivers/usb/fotg210/fotg210-udc.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/usb/fotg210/fotg210-udc.c b/drivers/usb/fotg210/fotg21= 0-udc.c index 6a4b94d26951..4099e7453112 100644 --- a/drivers/usb/fotg210/fotg210-udc.c +++ b/drivers/usb/fotg210/fotg210-udc.c @@ -1015,6 +1015,10 @@ static int fotg210_udc_start(struct usb_gadget *g, /* hook up the driver */ driver->driver.bus =3D NULL; fotg210->driver =3D driver; + fotg210->gadget.dev.of_node =3D fotg210->dev->of_node; + fotg210->gadget.speed =3D USB_SPEED_UNKNOWN; + + dev_info(fotg210->dev, "bound driver %s\n", driver->driver.name); =20 if (!IS_ERR_OR_NULL(fotg210->phy)) { ret =3D otg_set_peripheral(fotg210->phy->otg, @@ -1071,6 +1075,7 @@ static int fotg210_udc_stop(struct usb_gadget *g) =20 fotg210_init(fotg210); fotg210->driver =3D NULL; + fotg210->gadget.speed =3D USB_SPEED_UNKNOWN; =20 spin_unlock_irqrestore(&fotg210->lock, flags); =20 --=20 2.39.0 From nobody Sun Sep 14 22:18:29 2025 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 57BADC004D4 for ; Wed, 18 Jan 2023 07:47:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229548AbjARHri (ORCPT ); Wed, 18 Jan 2023 02:47:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230165AbjARHpK (ORCPT ); Wed, 18 Jan 2023 02:45:10 -0500 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF5906468B for ; Tue, 17 Jan 2023 23:09:40 -0800 (PST) Received: by mail-ej1-x634.google.com with SMTP id v6so37928609ejg.6 for ; Tue, 17 Jan 2023 23:09:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ERUzW2NTS0HSKxHZgJkhNmc/Fre4SMT/MoW1Mr8mzQ4=; b=zQwd7J7HLRznjgSFM9pKJya0EuA8lZun8bi0lci+/+J+INOZCIV9Q3HPoKn/H2t7EZ jGeRwvaXEEWwexTNs3th+4lE4e2mfsFiw/zpJ3Z2FAhlJ8oZ4NPzOPm3JmLPTx3MBNFa w+ISOMSy7RMkJTr+lHArjUK0VmYFRNOdUPFojbNu8WS85Fhi/m+b4tZShv0heXwB4nZ+ OaD6sQhZ5YawH9Zq9fKNUcFXqrmF8AdLX7z3wvO56SfZWRMkcpGeS2cMRP2lbeOTxsxi Riltb4cI1zp2s3bCg92Y1AWH58vCLH83S015+aG7gcRb/BeKW1MbD21VA3x+OJyB4tLM uKuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ERUzW2NTS0HSKxHZgJkhNmc/Fre4SMT/MoW1Mr8mzQ4=; b=MSB4KBJnXbcfjPVp4qadTQa8zdqyEkIyvyKoLWa6AX7MhXoyam/Hy5DxF/8g0gppF4 Vx+EY5h7vytSqb7jGCBUOwO2b/Zw1FGevp66m534gKir4Vppa6Dh/Lx2KfZyVNJ2WB2/ 4dUWBMh/Y8nDKvqLT7EgoAV7oKwbhngXysZN1NV34X7MPdX6F06yZ8q1wcw+brCcstf2 ts+lAbOS36+KN16bXfbq6RNdRvpXZD15pzRAyOvnW4UaQ+GcNtLdQFqICi97tjvNT5aH 2vu4uM69dKXfDNK3GBG5J3xesCLOSVHE5uTUxktJrwPbkbr9qezBJkpnrzphmuT43YS/ cwwg== X-Gm-Message-State: AFqh2koOqQD1FVyzqY2c25Y74Yl9w4Yr5EY+rr4oz8Z3w59GkDzEhT8l uGFYWCLFLYGOymDNirWFdyT2Gg== X-Google-Smtp-Source: AMrXdXu9lF2KzIrGyO/dXleTYY7hoYpmKSAJsg5YK0OSjR507Yv6uTjCD3X7ZbwT73YIZ7fWv5YvoA== X-Received: by 2002:a17:907:b9da:b0:872:21b2:9a1f with SMTP id xa26-20020a170907b9da00b0087221b29a1fmr5931576ejc.58.1674025778843; Tue, 17 Jan 2023 23:09:38 -0800 (PST) Received: from fedora.local (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id bt16-20020a0564020a5000b00482e0c55e2bsm13596984edb.93.2023.01.17.23.09.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 23:09:38 -0800 (PST) From: Linus Walleij Date: Wed, 18 Jan 2023 08:09:21 +0100 Subject: [PATCH v2 7/7] usb: fotg210-udc: Implement VBUS session MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230103-gemini-fotg210-usb-v2-7-100388af9810@linaro.org> References: <20230103-gemini-fotg210-usb-v2-0-100388af9810@linaro.org> In-Reply-To: <20230103-gemini-fotg210-usb-v2-0-100388af9810@linaro.org> To: Greg Kroah-Hartman , Rob Herring , Krzysztof Kozlowski Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Fabian Vogt , Linus Walleij X-Mailer: b4 0.11.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Implement VBUS session handling for FOTG210. This is mainly used by the UDC driver which needs to call down to the FOTG210 core and enable/disable VBUS, as this needs to be handled outside of the HCD and UDC drivers, by platform specific glue code. The Gemini has a special bit in a system register to turn VBUS on and off so we implement this in the FOTG210 core. Signed-off-by: Linus Walleij --- drivers/usb/fotg210/fotg210-core.c | 29 +++++++++++++++++++++++++++++ drivers/usb/fotg210/fotg210-udc.c | 17 +++++++++++++++++ drivers/usb/fotg210/fotg210.h | 2 ++ 3 files changed, 48 insertions(+) diff --git a/drivers/usb/fotg210/fotg210-core.c b/drivers/usb/fotg210/fotg2= 10-core.c index 013a1d0112fc..70d2ff5a2682 100644 --- a/drivers/usb/fotg210/fotg210-core.c +++ b/drivers/usb/fotg210/fotg210-core.c @@ -95,6 +95,35 @@ static int fotg210_gemini_init(struct fotg210 *fotg, str= uct resource *res, return 0; } =20 +/** + * fotg210_vbus() - Called by gadget driver to enable/disable VBUS + * @enable: true to enable VBUS, false to disable VBUS + */ +void fotg210_vbus(struct fotg210 *fotg, bool enable) +{ + u32 mask; + u32 val; + int ret; + + switch (fotg->port) { + case GEMINI_PORT_0: + mask =3D GEMINI_MISC_USB0_VBUS_ON; + val =3D enable ? GEMINI_MISC_USB0_VBUS_ON : 0; + break; + case GEMINI_PORT_1: + mask =3D GEMINI_MISC_USB1_VBUS_ON; + val =3D enable ? GEMINI_MISC_USB1_VBUS_ON : 0; + break; + default: + return; + } + ret =3D regmap_update_bits(fotg->map, GEMINI_GLOBAL_MISC_CTRL, mask, val); + if (ret) + dev_err(fotg->dev, "failed to %s VBUS\n", + enable ? "enable" : "disable"); + dev_info(fotg->dev, "%s: %s VBUS\n", __func__, enable ? "enable" : "disab= le"); +} + static int fotg210_probe(struct platform_device *pdev) { struct device *dev =3D &pdev->dev; diff --git a/drivers/usb/fotg210/fotg210-udc.c b/drivers/usb/fotg210/fotg21= 0-udc.c index 4099e7453112..754429553f61 100644 --- a/drivers/usb/fotg210/fotg210-udc.c +++ b/drivers/usb/fotg210/fotg210-udc.c @@ -1082,9 +1082,26 @@ static int fotg210_udc_stop(struct usb_gadget *g) return 0; } =20 +/** + * fotg210_vbus_session - Called by external transceiver to enable/disable= udc + * @_gadget: usb gadget + * @is_active: 0 if should disable UDC VBUS, 1 if should enable + * + * Returns 0 + */ +static int fotg210_vbus_session(struct usb_gadget *g, int is_active) +{ + struct fotg210_udc *fotg210 =3D gadget_to_fotg210(g); + + /* Call down to core integration layer to drive or disable VBUS */ + fotg210_vbus(fotg210->fotg, is_active); + return 0; +} + static const struct usb_gadget_ops fotg210_gadget_ops =3D { .udc_start =3D fotg210_udc_start, .udc_stop =3D fotg210_udc_stop, + .vbus_session =3D fotg210_vbus_session, }; =20 /** diff --git a/drivers/usb/fotg210/fotg210.h b/drivers/usb/fotg210/fotg210.h index 4d0d4ae1a957..c44c0afe2956 100644 --- a/drivers/usb/fotg210/fotg210.h +++ b/drivers/usb/fotg210/fotg210.h @@ -17,6 +17,8 @@ struct fotg210 { enum gemini_port port; }; =20 +void fotg210_vbus(struct fotg210 *fotg, bool enable); + #ifdef CONFIG_USB_FOTG210_HCD int fotg210_hcd_probe(struct platform_device *pdev, struct fotg210 *fotg); int fotg210_hcd_remove(struct platform_device *pdev); --=20 2.39.0