From patchwork Wed Jan 18 07:09:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 644013 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 C3398C54EBE for ; Wed, 18 Jan 2023 07:45:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229548AbjARHpV (ORCPT ); Wed, 18 Jan 2023 02:45:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229823AbjARHop (ORCPT ); Wed, 18 Jan 2023 02:44:45 -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 44AB461D40 for ; Tue, 17 Jan 2023 23:09:33 -0800 (PST) Received: by mail-ed1-x530.google.com with SMTP id b4so28838905edf.0 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=ELxtVB7O7SxJzQrxSUvRE57S3kvBx7loSjlQuPiipny79cMpfmPSHOZTkMYzS6QFgP zdZ1hXDwll47455qn4X+Q1nk5+iMwNSpyB/K/RgVm08F2jiGid7ZGLIcM/VJn1R3eq8W T/vNNmzShQZbfMIei0KOfGj2tg3BbDpQzwEw/+6TsFJuY2PzgM8hzl2Ce/qy3Qxyh0ZJ angvu40MSZEXEmchf8vyS+0YM9UgxTuvWQMNQQCVs5dwqH0U2PGT8JYTqelpm+Rq4RFo rgSqokkWSUcF+NcAYgLlnjHryrt5v5OLG09Sxw81hiNYTU9vf6hOXKmtNubH8LfJy5Un IBGA== X-Gm-Message-State: AFqh2kozw3pp/2XewgnIUObbgs594KV+S1eRj8Jf3tM4oQ/ez/xBcsG8 JrH/IqExsa29PtTa1HbziNulow== 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 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-usb@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/Documentation/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# -title: Faraday Technology FOTG210 HS OTG USB 2.0 controller +title: Faraday Technology FOTG200 series HS OTG USB 2.0 controller 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 reg: maxItems: 1 @@ -66,7 +67,7 @@ examples: #include #include usb0: usb@68000000 { - compatible = "cortina,gemini-usb", "faraday,fotg210"; + compatible = "cortina,gemini-usb", "faraday,fotg200"; reg = <0x68000000 0x1000>; interrupts = <10 IRQ_TYPE_LEVEL_HIGH>; resets = <&syscon GEMINI_RESET_USB0>; From patchwork Wed Jan 18 07:09:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 644998 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 46E22C004D4 for ; Wed, 18 Jan 2023 07:45:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229693AbjARHpX (ORCPT ); Wed, 18 Jan 2023 02:45:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229916AbjARHov (ORCPT ); Wed, 18 Jan 2023 02:44:51 -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 8A112618BE for ; Tue, 17 Jan 2023 23:09:34 -0800 (PST) Received: by mail-ed1-x52c.google.com with SMTP id v6so48278635edd.6 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=byp7Pnu8uqwANps7KhDnkbSQGIUBjkKrBq3CLkOWeCMEA8dAuPAyLtQbd5Iz3N0LJs IZwGICUvzwdTOf0G91sZkpfg+8ZaEVCLrP//xNRYX3B3OAYGnayIq5UAm5j7HRWsq28H HC14lpSiQLbd8aIag3NqgpzqZICSruz3tiyVGLvDcuN9N05gSG3We/bP1nUFci+JTkBx AFLqqHeWyCDsHnL5B556sce3pIs0z5bb83Zx3w3sw3yh5jPRCC7xeNmWJId9wjC+vE/m BGgr9kioyAlBHsgrUYb7JAkgQxFyNVmMiR8dkyISIg7FvpmlEQhkihlnDhj7nanWxATw i/qA== X-Gm-Message-State: AFqh2kqH3bx9O/6o8N1I8s7yGvLM1BcRLK8WS42Hqx5HQzxNlWsOYbKX oHmS9GJTu74s+nQbJjGbnpYsDA== 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 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-usb@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/fotg210-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) #ifdef CONFIG_OF static const struct of_device_id fotg210_of_match[] = { + { .compatible = "faraday,fotg200" }, { .compatible = "faraday,fotg210" }, + /* TODO: can we also handle FUSB220? */ {}, }; MODULE_DEVICE_TABLE(of, fotg210_of_match); From patchwork Wed Jan 18 07:09:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 644997 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 A3114C004D4 for ; Wed, 18 Jan 2023 07:45:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229564AbjARHp1 (ORCPT ); Wed, 18 Jan 2023 02:45:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230008AbjARHox (ORCPT ); Wed, 18 Jan 2023 02:44:53 -0500 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEE8F63E03 for ; Tue, 17 Jan 2023 23:09:35 -0800 (PST) Received: by mail-ed1-x536.google.com with SMTP id 18so48329171edw.7 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=GvirTeWpxhl87tv2pE/ya5fXfvvMRKAJh1/2V6x0NSxiQFKexeo0TRdfJCW6VYnXbr vb4yTMK+K7/iq2vk6eiSNWxlt1oMGAGIXPNnXAPoXhxsLMsD6l6z06HaherqPNp9OTg6 nEjuuEsiRhXGcpeSGgqI3dURvJeRgUpPryf7ogM0qYjQr5PuINgZ9W5F9hHxT9TFK9Pl DKt1BlO52fiFFSD/OfD32V3LXLDXPL+i4SxtmEILN2QHIxTBspKY46iAg13lQijc4TK7 JTuxHV91ID8TWeVGIJs6eGrihkFrgT4Lx0aRRBlR2GRU0XLguh0CDmV6l613dPUVxVoH Z1Yw== X-Gm-Message-State: AFqh2kpjfsMPr1f2QXWYmyDYJLBQG2qVVCdw3Q89gXORV27wUzpXlcug v2Om+fdSU6d5C6cnNFPaBP6FQ1Kfd9zk2Ry3 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 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-usb@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/fotg210-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) -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 = fotg->dev; struct device_node *np = 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 = map; wakeup = of_property_read_bool(np, "wakeup-source"); /* @@ -55,6 +57,7 @@ static int fotg210_gemini_init(struct device *dev, struct resource *res, */ mask = 0; if (res->start == 0x69000000) { + fotg->port = GEMINI_PORT_1; mask = GEMINI_MISC_USB1_VBUS_ON | GEMINI_MISC_USB1_MINI_B | GEMINI_MISC_USB1_WAKEUP; if (mode == USB_DR_MODE_HOST) @@ -64,6 +67,7 @@ static int fotg210_gemini_init(struct device *dev, struct resource *res, if (wakeup) val |= GEMINI_MISC_USB1_WAKEUP; } else { + fotg->port = GEMINI_PORT_0; mask = GEMINI_MISC_USB0_VBUS_ON | GEMINI_MISC_USB0_MINI_B | GEMINI_MISC_USB0_WAKEUP; if (mode == USB_DR_MODE_HOST) @@ -89,23 +93,34 @@ static int fotg210_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; enum usb_dr_mode mode; + struct fotg210 *fotg; int ret; + fotg = devm_kzalloc(dev, sizeof(*fotg), GFP_KERNEL); + if (!fotg) + return -ENOMEM; + fotg->dev = dev; + + fotg->res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!fotg->res) + return -ENODEV; + + fotg->base = devm_ioremap_resource(dev, fotg->res); + if (!fotg->base) + return -ENOMEM; + mode = usb_get_dr_mode(dev); if (of_device_is_compatible(dev->of_node, "cortina,gemini-usb")) { - struct resource *res; - - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - ret = fotg210_gemini_init(dev, res, mode); + ret = fotg210_gemini_init(fotg, fotg->res, mode); if (ret) return ret; } if (mode == USB_DR_MODE_PERIPHERAL) - ret = fotg210_udc_probe(pdev); + ret = fotg210_udc_probe(pdev, fotg); else - ret = fotg210_hcd_probe(pdev); + ret = fotg210_hcd_probe(pdev, fotg); return ret; } diff --git a/drivers/usb/fotg210/fotg210-hcd.c b/drivers/usb/fotg210/fotg210-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 *fotg210) * 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 = &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) hcd->has_tt = 1; - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - hcd->regs = devm_ioremap_resource(&pdev->dev, res); - if (IS_ERR(hcd->regs)) { - retval = PTR_ERR(hcd->regs); - goto failed_put_hcd; - } + hcd->regs = fotg->base; - hcd->rsrc_start = res->start; - hcd->rsrc_len = resource_size(res); + hcd->rsrc_start = fotg->res->start; + hcd->rsrc_len = resource_size(fotg->res); fotg210 = hcd_to_fotg210(hcd); + fotg210->fotg = fotg; fotg210->caps = hcd->regs; /* It's OK not to supply this clock */ diff --git a/drivers/usb/fotg210/fotg210-hcd.h b/drivers/usb/fotg210/fotg210-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 + struct fotg210 *fotg; /* Overarching FOTG210 device */ /* silicon clock */ struct clk *pclk; }; diff --git a/drivers/usb/fotg210/fotg210-udc.c b/drivers/usb/fotg210/fotg210-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; } -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 = NULL; struct device *dev = &pdev->dev; int irq; int ret = 0; int i; - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!res) { - pr_err("platform_get_resource error.\n"); - return -ENODEV; - } - irq = 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; fotg210->dev = dev; + fotg210->fotg = fotg; /* It's OK not to supply this clock */ fotg210->pclk = devm_clk_get(dev, "PCLK"); @@ -1207,11 +1201,7 @@ int fotg210_udc_probe(struct platform_device *pdev) goto err_alloc; } - fotg210->reg = ioremap(res->start, resource_size(res)); - if (fotg210->reg == NULL) { - dev_err(dev, "ioremap error\n"); - goto err_alloc; - } + fotg210->reg = fotg->base; spin_lock_init(&fotg210->lock); diff --git a/drivers/usb/fotg210/fotg210-udc.h b/drivers/usb/fotg210/fotg210-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; 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 +enum gemini_port { + GEMINI_PORT_NONE = 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 #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; } From patchwork Wed Jan 18 07:09:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 644012 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 6DF25C54EBE for ; Wed, 18 Jan 2023 07:45:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229436AbjARHp0 (ORCPT ); Wed, 18 Jan 2023 02:45:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229999AbjARHox (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 EEF4B63E04 for ; Tue, 17 Jan 2023 23:09:35 -0800 (PST) Received: by mail-ed1-x533.google.com with SMTP id s21so4121339edi.12 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=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=r3/WMIFbwicAjxfA82ojLLdzZ59a+2TICa4Nx5PDk76RukkrBGfDaaydijU0xRVxrt 2ZDxfoihvSeIXWxyMLe8nufW8bEattijxtmWLktTHk7hddqzAU2dunSu8aN8mOeWftEl RSUC1QQgh4QzXCQF8byKYVsG8abp3+EiqycGHJGrDdhHsDQ/qhfkCvciuT8GMz9/ww/f W4mGzzRAouPqoxY0PyFdThpsYJ4B3cwwn9qLfqCcknQ2ih8HG08iExcOCzh/R/m/J8O6 wMa8W08TQuL6IuwyuZgY4yv0ykIaQY9Y2DWKFpJCYwXaZKRd5m5jJEkQKNYlveQItWGC 0wQA== X-Gm-Message-State: AFqh2krJLLlaTvfkPJaBWqUzarZYn0eUI+qUOUrUz7dtx4aeSiVBiBFf 205yA20ksvtgDOw4anrqw8/UiA== 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 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-usb@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/fotg210-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; + fotg->pclk = devm_clk_get_optional_enabled(dev, "PCLK"); + if (IS_ERR(fotg->pclk)) + return PTR_ERR(fotg->pclk); + mode = usb_get_dr_mode(dev); if (of_device_is_compatible(dev->of_node, "cortina,gemini-usb")) { diff --git a/drivers/usb/fotg210/fotg210-hcd.c b/drivers/usb/fotg210/fotg210-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 #include #include @@ -5594,44 +5593,22 @@ int fotg210_hcd_probe(struct platform_device *pdev, struct fotg210 *fotg) fotg210->fotg = fotg; fotg210->caps = hcd->regs; - /* It's OK not to supply this clock */ - fotg210->pclk = clk_get(dev, "PCLK"); - if (!IS_ERR(fotg210->pclk)) { - retval = 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) == -EPROBE_DEFER) { - /* - * Percolate deferrals, for anything else, - * just live without the clocking. - */ - retval = PTR_ERR(fotg210->pclk); - goto failed_dis_clk; - } - retval = fotg210_setup(hcd); if (retval) - goto failed_dis_clk; + goto failed_put_hcd; fotg210_init(fotg210); retval = 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); return retval; -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 = platform_get_drvdata(pdev); - struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); - - if (!IS_ERR(fotg210->pclk)) { - clk_disable_unprepare(fotg210->pclk); - clk_put(fotg210->pclk); - } usb_remove_hcd(hcd); usb_put_hcd(hcd); diff --git a/drivers/usb/fotg210/fotg210-udc.c b/drivers/usb/fotg210/fotg210-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 @@ -1134,9 +1133,6 @@ int fotg210_udc_remove(struct platform_device *pdev) for (i = 0; i < FOTG210_MAX_NUM_EP; i++) kfree(fotg210->ep[i]); - if (!IS_ERR(fotg210->pclk)) - clk_disable_unprepare(fotg210->pclk); - kfree(fotg210); return 0; @@ -1164,34 +1160,17 @@ int fotg210_udc_probe(struct platform_device *pdev, struct fotg210 *fotg) fotg210->dev = dev; fotg210->fotg = fotg; - /* It's OK not to supply this clock */ - fotg210->pclk = devm_clk_get(dev, "PCLK"); - if (!IS_ERR(fotg210->pclk)) { - ret = clk_prepare_enable(fotg210->pclk); - if (ret) { - dev_err(dev, "failed to enable PCLK\n"); - goto err; - } - } else if (PTR_ERR(fotg210->pclk) == -EPROBE_DEFER) { - /* - * Percolate deferrals, for anything else, - * just live without the clocking. - */ - ret = -EPROBE_DEFER; - goto err; - } - fotg210->phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0); if (IS_ERR(fotg210->phy)) { ret = PTR_ERR(fotg210->phy); if (ret == -EPROBE_DEFER) - goto err_pclk; + goto err_free; dev_info(dev, "no PHY found\n"); fotg210->phy = NULL; } else { ret = usb_phy_init(fotg210->phy); if (ret) - goto err_pclk; + goto err_free; dev_info(dev, "found and initialized PHY\n"); } @@ -1286,11 +1265,8 @@ int fotg210_udc_probe(struct platform_device *pdev, struct fotg210 *fotg) err_alloc: for (i = 0; i < FOTG210_MAX_NUM_EP; i++) kfree(fotg210->ep[i]); -err_pclk: - if (!IS_ERR(fotg210->pclk)) - clk_disable_unprepare(fotg210->pclk); -err: +err_free: kfree(fotg210); return ret; } diff --git a/drivers/usb/fotg210/fotg210-udc.h b/drivers/usb/fotg210/fotg210-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; unsigned long irq_trigger; 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; }; From patchwork Wed Jan 18 07:09:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 644011 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 79BADC32793 for ; Wed, 18 Jan 2023 07:45:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229705AbjARHpe (ORCPT ); Wed, 18 Jan 2023 02:45:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230106AbjARHo6 (ORCPT ); Wed, 18 Jan 2023 02:44:58 -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 248D363E33 for ; Tue, 17 Jan 2023 23:09:38 -0800 (PST) Received: by mail-ed1-x530.google.com with SMTP id w14so31019529edi.5 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=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=tjUMjqLOJUpIitpbbAfCTXAwneBcCZE97Vm6qmN9YeqpsS/7ys6Oz7abjPoHOzhr+L Fcvn8gK6SLSeJc4CmGgjrEM1Gs3CnS7bbh/YUcAQiAXlEzXW8geNJNuYIIkN83V3R/Ap 4Qutlh7qYjzQBKfuJg/z6w5oFtFdYMqArfaMZ3G/ibByXurHwtZTtKUiLiF7PysInI1B ZqbPm7z93C43OhVeeBVEFuIlEZ6VWYWFBi1wuJoA4boJWJHbYMGJCx5KyZmI09ox3+xM Evmv1bOhPrfSGQVKe2Yorcgi1nEX+HP16BmDhHmOgWvO9A2eRvJ+zfJRSnf31CSzkjVj JKaw== X-Gm-Message-State: AFqh2koZB2JjdGiKv3UN33lXNU4ETuVh/QuRMC+xNUfbCHf846mhaQPF v7UFTjpAnenPLYqB2jiOUsIgrQ== 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 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-usb@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/fotg210-core.c index 58d84747fb30..013a1d0112fc 100644 --- a/drivers/usb/fotg210/fotg210-core.c +++ b/drivers/usb/fotg210/fotg210-core.c @@ -18,6 +18,11 @@ #include "fotg210.h" +/* Role Register 0x80 */ +#define FOTG210_RR 0x80 +#define FOTG210_RR_ID BIT(21) /* 1 = B-device, 0 = A-device */ +#define FOTG210_RR_CROLE BIT(20) /* 1 = device, 0 = 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 = &pdev->dev; enum usb_dr_mode mode; struct fotg210 *fotg; + u32 val; int ret; fotg = devm_kzalloc(dev, sizeof(*fotg), GFP_KERNEL); @@ -122,10 +128,16 @@ static int fotg210_probe(struct platform_device *pdev) return ret; } - if (mode == USB_DR_MODE_PERIPHERAL) + val = readl(fotg->base + FOTG210_RR); + if (mode == USB_DR_MODE_PERIPHERAL) { + if (!(val & FOTG210_RR_CROLE)) + dev_err(dev, "block not in device role\n"); ret = fotg210_udc_probe(pdev, fotg); - else + } else { + if (val & FOTG210_RR_CROLE) + dev_err(dev, "block not in host role\n"); ret = fotg210_hcd_probe(pdev, fotg); + } return ret; } From patchwork Wed Jan 18 07:09:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 644996 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 588D5C004D4 for ; Wed, 18 Jan 2023 07:45:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229551AbjARHpu (ORCPT ); Wed, 18 Jan 2023 02:45:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230139AbjARHpI (ORCPT ); Wed, 18 Jan 2023 02:45:08 -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 30EF763E21 for ; Tue, 17 Jan 2023 23:09:39 -0800 (PST) Received: by mail-ed1-x533.google.com with SMTP id x36so13684259ede.13 for ; Tue, 17 Jan 2023 23:09:39 -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=ZyoRIDf4DIvaX29HKedSWfhgkKPNx7Wx5nVmYITmmZqJBUjHxUHLfcI8T8qIDmMVsG Y3wNWsKD9K0irLxSJVMidSyjij8qpLobOYIYTZycc9uFPHk1ZmP3s7noaFumKCh7KjXO XKuyZZLHcVdD6rTDeAzeU9d+hfM4lUB1YWtSdV8zCSPL5ofWnbQ7Xia4NACmEy6ys2zZ 2yEk8nHzj16B/Oz1yE5Aqtjf91+HMiVKwlwcwvpI/W+3kPAdkrJBpJZBEwYPmBg/rA2w fye8JN9AVSN6rw58EKM2iQCrl27X+Qd30EDocXeAoqIbrVXZREwxD0k3HGT9nEuIHZHn +9zg== X-Gm-Message-State: AFqh2kq0SuEZRwY3Q7jUvqe2ybIZRVjGvo5/0imfboNY0zJnixxI0niM hzRquiF+QB4unqr+FCdbbtNKGw== 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 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-usb@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/fotg210-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 = NULL; fotg210->driver = driver; + fotg210->gadget.dev.of_node = fotg210->dev->of_node; + fotg210->gadget.speed = USB_SPEED_UNKNOWN; + + dev_info(fotg210->dev, "bound driver %s\n", driver->driver.name); if (!IS_ERR_OR_NULL(fotg210->phy)) { ret = otg_set_peripheral(fotg210->phy->otg, @@ -1071,6 +1075,7 @@ static int fotg210_udc_stop(struct usb_gadget *g) fotg210_init(fotg210); fotg210->driver = NULL; + fotg210->gadget.speed = USB_SPEED_UNKNOWN; spin_unlock_irqrestore(&fotg210->lock, flags); From patchwork Wed Jan 18 07:09:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 644010 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 E0659C32793 for ; Wed, 18 Jan 2023 07:45:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229912AbjARHpx (ORCPT ); Wed, 18 Jan 2023 02:45:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230149AbjARHpJ (ORCPT ); Wed, 18 Jan 2023 02:45:09 -0500 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E17063E3C for ; Tue, 17 Jan 2023 23:09:40 -0800 (PST) Received: by mail-ej1-x62d.google.com with SMTP id ud5so80983666ejc.4 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=ws1qeugiP6t5jq8fQlSwaFpM20N4om/Cz4LIU/GoxzVXnw4Ou6JxLbkPk08IdcBw05 ttm4SWBo9hMGtJAjJ1Hnk8VmpIqDCILBb9AK+EJLK4H30I0EoSNmSEq4uWIwTcJGtswF jeuZE9QFiGS99g439LEU/27QV7JEa4xPUmMpA1yN8wYx5A5mFqf9IXT5yQLfO0F0LzQM aMPm6pU5DkviRo3f8BljDDtZvgubQ9wjkU9Ls8zRJpMCjBUrjeOAt8RyahUqtOnuSdxT pxyxaJFnrdLOCdrM4YLoLzZcK68Z43KqJl0PvQkdr8in+JpgQao5jwMxSCx9BZpbVm7V QBJw== X-Gm-Message-State: AFqh2kpNz9Ybuw4GIXpua2pndyHZib9YEjWCPDjdkdbhRwDBUAZXRjzr OE/Lex8VG+fjrVBt2Ut22rtjuA== 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 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-usb@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/fotg210-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, struct resource *res, return 0; } +/** + * 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 = GEMINI_MISC_USB0_VBUS_ON; + val = enable ? GEMINI_MISC_USB0_VBUS_ON : 0; + break; + case GEMINI_PORT_1: + mask = GEMINI_MISC_USB1_VBUS_ON; + val = enable ? GEMINI_MISC_USB1_VBUS_ON : 0; + break; + default: + return; + } + ret = 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" : "disable"); +} + static int fotg210_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; diff --git a/drivers/usb/fotg210/fotg210-udc.c b/drivers/usb/fotg210/fotg210-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; } +/** + * 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 = 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 = { .udc_start = fotg210_udc_start, .udc_stop = fotg210_udc_stop, + .vbus_session = fotg210_vbus_session, }; /** 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; }; +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);