From patchwork Tue Jan 3 23:35: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: 13088106 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 E9A07C5479D for ; Tue, 3 Jan 2023 23:35:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238157AbjACXf3 (ORCPT ); Tue, 3 Jan 2023 18:35:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237765AbjACXf0 (ORCPT ); Tue, 3 Jan 2023 18:35:26 -0500 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 117E41659E for ; Tue, 3 Jan 2023 15:35:25 -0800 (PST) Received: by mail-lf1-x12f.google.com with SMTP id bf43so47969558lfb.6 for ; Tue, 03 Jan 2023 15:35:24 -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=INGl8EC4lutAaxK7oytOrepZPv62csf4zgf/Dha7g08=; b=tUh9Qclbxwes1y19TozU8R6/M6yFHt0Tf/7Uk9vnG8eT3MKTfnZ5FPazeKrWpGZ/Zs FDHCXMqufboxBhsvccZNg7j44bIL/+rNLP0e+70HxzbS67f4vUXHkOdA5Xu5FdYxlegb o9SYgd7W1epIDogWkpbLTzQihLn16sHKSZAXrU9AjO4LQV47d63ABNKdaa+4pNhBMVhG Rd9wRbiao8kN0AZQX6BTdOQxwrfmAhr00DTDe3ra1H410N6socCrzWGi30Sz09qMVa42 pJp1lr6X8SfBhq+IueeYNKSdxR/3/E5Z60dCUmMUcUZet97rlLEZYSY+kiS1oHAkmJky zDLQ== 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=INGl8EC4lutAaxK7oytOrepZPv62csf4zgf/Dha7g08=; b=UEiJGllEObzkJsfYOUcx14akOxm9DI13kSodQIoYUWetsveVE3S/zHSltAGvRQPy+E tkWRTrO/Jk0FV+YQTINNkBtJghn+gfK6g2w3c6HGpuqCf12uOh0WRqVpoJ9LnIGZU0iS DeUZWtYpsORHUyQo+C1qjOBdS8fHwpsejEcoM46ge/EhtnYjTLJHvTzcODdezcokxTxu FqJH36ERV8I1gkbLgk7de1cmM+yZzQp3eJXA35qqYzMKcJXBul4480wjjZA/ojIKpf6C 3ToOeJCQwOSaL6wRaHtZShfmW6Z+Ack5LqUYrEyYJ9VPsosVPyTJsuz3rydiuUnpU8Q+ 0fCA== X-Gm-Message-State: AFqh2kpDfu7a1asmZz2nWhJcTYhOd4yNo8lDi4j2KLhVQCV5AaFdbBSY T+PvabtY/sUB+UvBPotNAoWFuC408i6i/AN1 X-Google-Smtp-Source: AMrXdXvAhYJCpYRkWDTIDmckimmTS2x6TV9+jF5DsOMDB10ivmTBIrIyYglIf0/N5/eHOWrkh4XH1g== X-Received: by 2002:a05:6512:3ca9:b0:4b5:61c5:8927 with SMTP id h41-20020a0565123ca900b004b561c58927mr14359517lfv.42.1672788923444; Tue, 03 Jan 2023 15:35:23 -0800 (PST) Received: from Fecusia.local (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id b11-20020a056512070b00b004a45edc1de2sm4939801lfs.239.2023.01.03.15.35.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 15:35:22 -0800 (PST) From: Linus Walleij Date: Wed, 04 Jan 2023 00:35:17 +0100 Subject: [PATCH 1/7] dt-bindings: usb: Correct and extend FOTG210 schema MIME-Version: 1.0 Message-Id: <20230103-gemini-fotg210-usb-v1-1-f2670cb4a492@linaro.org> References: <20230103-gemini-fotg210-usb-v1-0-f2670cb4a492@linaro.org> In-Reply-To: <20230103-gemini-fotg210-usb-v1-0-f2670cb4a492@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 --- 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..12d4fc742f20 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 Bindings 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 Tue Jan 3 23:35: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: 13088107 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 8B2ABC4708E for ; Tue, 3 Jan 2023 23:35:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238330AbjACXfa (ORCPT ); Tue, 3 Jan 2023 18:35:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233437AbjACXf1 (ORCPT ); Tue, 3 Jan 2023 18:35:27 -0500 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26C131659C for ; Tue, 3 Jan 2023 15:35:26 -0800 (PST) Received: by mail-lf1-x136.google.com with SMTP id f34so47915433lfv.10 for ; Tue, 03 Jan 2023 15:35:26 -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=Fm8GAHA4wHOZ6aH5j10PuHm5s/aZ6TljNeVHuGhMRwk=; b=QTSUiaPpbGJceQRcTqfXW+fhAp/0bRlZ9/jR1kVkMF+m6O0/Jhj2v/E3CtGWtHhJTc fGUPGKXKsuxbDkIniisGJjvVwfpYAFdd1BMCkZyGe0WZPVJrV8vIvsSjZpmGrRfIDG4u Bq1I9EzxVDuFg3E1KO2iZjZCukYVUzG9h47QzdrWK60Bp/HUy8pxWGC4wC1hZvR4dRaM RMV8U/TRiXzw279/8nS29dYjLEBl8azTEBmpwtUWsZl+iYh+tjE8ZPKxST+ymIriz6Gb 9Ug0ED9JU3UPSPU8IbR7cJ7/mdS3pcAZ2cZturYPUU6RU90dWgUx53Z6NQrAIuvrpJRN vF6w== 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=Fm8GAHA4wHOZ6aH5j10PuHm5s/aZ6TljNeVHuGhMRwk=; b=TKA6uZUftpw/uohUwMYjxvFISoYbFCVYSrfMX9jFuc0ghRjwnHH0TRtXUDjVRlCCj4 v3oklMHGWi/KGqyR0sGS+SMIN/GK4/7Scwhi6DhOQb3pryDsqLOmbtQzKGvQV3kLq8ZB ub563v3S1Swqcm/k4YtLar1p34EcT50ttB+sEO9O5fxXPoBiL3AfrnnHDQZmzPAWD7b4 MIDby4xzmC/KhJN7vyw6pXSjN1Mjw2EPHyLxA/D3cPnCGyt1tV6rDuA/gAg4eDMJ/bCA mVf6ZKSDGXPFsp8+HZQcYixA6q69v1cPRvqQhjR8CVsFR/OI+UIe1326BwRJLuWCnIwt QIQQ== X-Gm-Message-State: AFqh2kqEGIkc5p5DI+m3PcD1463z3rgMtrwxGWok9Fwf/OUv9a34w4zE 4PjQsANHHjqcs5TXreioteUb2A== X-Google-Smtp-Source: AMrXdXvUEMqhAGEePbJwzuMHSc4UTdEcNlNqP3IyR3XvRSGdbrV9sdapS0Q41zVldzt3iZHk82Lqfw== X-Received: by 2002:a05:6512:220f:b0:4bf:982f:f63b with SMTP id h15-20020a056512220f00b004bf982ff63bmr15779860lfu.21.1672788924538; Tue, 03 Jan 2023 15:35:24 -0800 (PST) Received: from Fecusia.local (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id b11-20020a056512070b00b004a45edc1de2sm4939801lfs.239.2023.01.03.15.35.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 15:35:23 -0800 (PST) From: Linus Walleij Date: Wed, 04 Jan 2023 00:35:18 +0100 Subject: [PATCH 2/7] usb: fotg210: List different variants MIME-Version: 1.0 Message-Id: <20230103-gemini-fotg210-usb-v1-2-f2670cb4a492@linaro.org> References: <20230103-gemini-fotg210-usb-v1-0-f2670cb4a492@linaro.org> In-Reply-To: <20230103-gemini-fotg210-usb-v1-0-f2670cb4a492@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 Tue Jan 3 23:35: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: 13088108 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 F04A7C54EBC for ; Tue, 3 Jan 2023 23:35:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233746AbjACXfc (ORCPT ); Tue, 3 Jan 2023 18:35:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238143AbjACXf2 (ORCPT ); Tue, 3 Jan 2023 18:35:28 -0500 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 494CC165A9 for ; Tue, 3 Jan 2023 15:35:27 -0800 (PST) Received: by mail-lf1-x12e.google.com with SMTP id 1so47951560lfz.4 for ; Tue, 03 Jan 2023 15:35:27 -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=Rq0s4onjSRUwhmApDnZ8KEVauR86LqfQw7i8WlycEFs=; b=rJvaZkk57ZeoGjLTVPf6NQmvZfWeEFVlPJbGJ3wvMJ63Av0UjO5SAxDlXQPXVJjXHQ m3PBikfjuV6CMWTaalBoqNhftpinKPz/nk7SexZAYeM09eTnxslPgQ1eiAOwVNJ/cicV 0fHLNOZyGxMGZu2z5HgpmKd8dqztH7gH0rO3zgZqD6MwhMmr4unT8nCedyeeOytgFzzU Z1JKdzEqA3FL+H6BRqlwdth52gWQjWTAlM4Z46ZhAM20OuRzliT+0mlc0Yf39FlWvkVE ZA9sLIbS6DjEZy0Lu42PSiILujdPeA8wx6/h/RgYfB877zh5jTCrT2YgSUzF4EnWUsGJ xWvA== 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=Rq0s4onjSRUwhmApDnZ8KEVauR86LqfQw7i8WlycEFs=; b=vNW24seMnZFyvvx6GGYtovsnSIh/xKv07zO7kH5/KbD0m6uGPU8Kftd1L0vxR1nOKu O57hNgWc9a1dLn4uxWA8acMCppRDJItcCqCvR5mh7g5ZaZiF/3QvYzxXNqfxJ8IEJBAE nY606tcBlBC8KRk8q1WZ0ihXSwRT+S6gXlALURRhgA/MtUhnf8hD2Eux0t+isJqTz319 5PfVHhRt8b4ZtpM7IpaOTPLcZNQCoKkkXpJlMS70STYc7EbizHShCPXmCtecQmtTXPs6 lAdLgIYSALalYEcq8bIeLesOVdmFi8qbX+saDfKfpMXf/hUuMyHYJwa1xgdlQ2skjrmA HbyQ== X-Gm-Message-State: AFqh2kps9JL5y2k7lVL5gtv2KWI+HL7An9lLx2D55Zk9uMo17zwaBy/R kcoHnDlMGb2QHyGdFEcZDHvFUw== X-Google-Smtp-Source: AMrXdXutAAOkOUBIuK6T1E9JkbuwrOliPzDnYqRmT25gu1gXcfAdrJsGfjDYEORwXECwxCTU2UBEJw== X-Received: by 2002:a05:6512:3b22:b0:4a4:68b9:19e1 with SMTP id f34-20020a0565123b2200b004a468b919e1mr14446708lfv.9.1672788925655; Tue, 03 Jan 2023 15:35:25 -0800 (PST) Received: from Fecusia.local (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id b11-20020a056512070b00b004a45edc1de2sm4939801lfs.239.2023.01.03.15.35.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 15:35:25 -0800 (PST) From: Linus Walleij Date: Wed, 04 Jan 2023 00:35:19 +0100 Subject: [PATCH 3/7] usb: fotg210: Acquire memory resource in core MIME-Version: 1.0 Message-Id: <20230103-gemini-fotg210-usb-v1-3-f2670cb4a492@linaro.org> References: <20230103-gemini-fotg210-usb-v1-0-f2670cb4a492@linaro.org> In-Reply-To: <20230103-gemini-fotg210-usb-v1-0-f2670cb4a492@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 Tue Jan 3 23:35: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: 13088110 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 BCA53C3DA7D for ; Tue, 3 Jan 2023 23:35:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238403AbjACXff (ORCPT ); Tue, 3 Jan 2023 18:35:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238297AbjACXfa (ORCPT ); Tue, 3 Jan 2023 18:35:30 -0500 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B518165AC for ; Tue, 3 Jan 2023 15:35:28 -0800 (PST) Received: by mail-lf1-x132.google.com with SMTP id cf42so47956982lfb.1 for ; Tue, 03 Jan 2023 15:35:28 -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=BtRN+qVRV1KbBnVSqhsl2L1Dw52l5PTGL9dlg3vRmSg=; b=L6pneSlfBV8hJroS5X7KCQsJcflcnd4ohQjKk25rbttOudOaeb8WzOjm86Y79S8dir wqEXKvigPHHUl063jpj6Y38z3agdhfftVLTd0xib2fe7pppM+cjhsFHnZewG5BPIu+sN Vh7vm9SrkiZEOGAAZAwXwo3seFAwO5plR1wYqtg7mvRiikmOVPSL9SaoXTtXUIgmdHu7 eBDc3wzFj2QA3UViFNklFifZ/Ntuy5cdCSfCbD7kVjaaUXdSOSKvM7dQBR63E0DQRmQW uOvLMSAAFRqpFvx0VGEBdDWD13MsNITli4UWWvkbtAeNRawH6VzY6YJf9Pg1XGfqdK/j Sl0Q== 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=BtRN+qVRV1KbBnVSqhsl2L1Dw52l5PTGL9dlg3vRmSg=; b=C34CrdftUT6xIG8WscaaGihaChLiDdJU8n4c0PWX2GtUBph2ndOS28evrYCeAwOtn1 R2HBkiS9aIioUdqyv4Eq0Q9ZyzIGz2OrxUIm/HINBjruF4dTOpwkClCLM4IGDU7s2mQg BbiLWuG0a6AzhBtRfjzJks6j/2ZBpAzmEb1CppCISj5o3C6RHXXpTW0fFHvl3fo6g5yQ OO8vbhVv5dwwOr8MWytKsD8FRI3tt/OScdfQY1wsaJkG1Gau1lmPIyvu7loIKJayLCdQ qa4usqaJB5VtnGn+F44/EtzoyKl2rzYgBbd9ykdx4RaJtlNW/0naTok4IzFCOQAem42n y7yQ== X-Gm-Message-State: AFqh2kqv3NcNrvxdQMUAEBjHlHmXOLeCZlOhaIBvk0du1/0oq2+hLmnK fa5NTJBT2Q0MPHqSXp7fkk7NrQ== X-Google-Smtp-Source: AMrXdXs2bS5QxeAPRgtcNR1L3O1x+4UzA3xGsphCQbmPF0U6qyLhfrjM1yHQng04wacz+B8EAg2dVg== X-Received: by 2002:a05:6512:31d1:b0:4b5:7925:8707 with SMTP id j17-20020a05651231d100b004b579258707mr15867129lfe.26.1672788926805; Tue, 03 Jan 2023 15:35:26 -0800 (PST) Received: from Fecusia.local (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id b11-20020a056512070b00b004a45edc1de2sm4939801lfs.239.2023.01.03.15.35.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 15:35:26 -0800 (PST) From: Linus Walleij Date: Wed, 04 Jan 2023 00:35:20 +0100 Subject: [PATCH 4/7] usb: fotg210: Move clock handling to core MIME-Version: 1.0 Message-Id: <20230103-gemini-fotg210-usb-v1-4-f2670cb4a492@linaro.org> References: <20230103-gemini-fotg210-usb-v1-0-f2670cb4a492@linaro.org> In-Reply-To: <20230103-gemini-fotg210-usb-v1-0-f2670cb4a492@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 Tue Jan 3 23:35: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: 13088109 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 E01D4C54EBE for ; Tue, 3 Jan 2023 23:35:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238269AbjACXfe (ORCPT ); Tue, 3 Jan 2023 18:35:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238221AbjACXf3 (ORCPT ); Tue, 3 Jan 2023 18:35:29 -0500 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 515911659E for ; Tue, 3 Jan 2023 15:35:28 -0800 (PST) Received: by mail-lf1-x12b.google.com with SMTP id bf43so47969911lfb.6 for ; Tue, 03 Jan 2023 15:35:28 -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=LfqK6qBFH8YFyjUi0V5Pk9BV6gkDIZNht4kUj3nmxsk=; b=GsOXISdSRV97jTW19WaKqVcsFh59IOOCGNy41YNbhGo+zogwzgVgxTn2XYIFP5fy51 7OGzxjkJcgZ0iX9B24HlxuWH3BcnSk+RNZ7ss9XGYeF5GDkR0BxZaJcXAQ1Ty495VdZJ nawju/K7S1pBGKMb472tZDFEUxVwuHZsypI24Fw+hvhNo18BYfgLC/861nJOupbDHt19 yHoOh9qBUeiEelUa00crBmI9VpIr2nlgE45Kr/mKET81/5Z5k3oyki3Gor2O8eZmQKWK oAYvROqewlZPvxv02HMLdsLUp5p5zYIhbGt1dEVWoQ9ld7LmRFuKlka4IdT+QAFXchkR JLfA== 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=LfqK6qBFH8YFyjUi0V5Pk9BV6gkDIZNht4kUj3nmxsk=; b=jLNDPpTGK7NqUdM0vu3ZVBr1xf1akNaB1F/iN77NHJmTk2OyYO4c+dDe9JBxAsnrYi vED7R4I8oJaNTh96MRisq5nbR6yWDfXlCXcRLU7Av5/j0HSq2WNyQk2enhGXmb1OL3+F guNC9jpeR1ehSehx/tu/pgC32DfV+GEA4o7pJunm/+9dSSPrNI/fKqi0BlbOPE0iWEXI PRnjKoefRmOSQOYBaa5Xhvzv7z/Y27+kK/FhnmtiWBti/txdHNWH/XzXxHP4onRIyUKO zEM7pN0Gv3S4pFGJN5ssT2FqxI3lRt/A5Xcx40Plu6gIhD3Gihg1E86OUk27lPDnCxmE dy2w== X-Gm-Message-State: AFqh2kpEF1acIEDz895PQjEKCjBd3U3vxe2x9pDU+IoUki06o1m1EDiG MCKmQeI4eaLy/UQowfcxWpIb/Q== X-Google-Smtp-Source: AMrXdXvGQS/bswxpe0igHUGcViNfV0w61Poc5iqZnUfTxEjT7Iz2j6FvCTfduAeRyTbqU3inECNbNw== X-Received: by 2002:ac2:4bd3:0:b0:4b4:a460:c995 with SMTP id o19-20020ac24bd3000000b004b4a460c995mr18141753lfq.5.1672788927892; Tue, 03 Jan 2023 15:35:27 -0800 (PST) Received: from Fecusia.local (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id b11-20020a056512070b00b004a45edc1de2sm4939801lfs.239.2023.01.03.15.35.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 15:35:27 -0800 (PST) From: Linus Walleij Date: Wed, 04 Jan 2023 00:35:21 +0100 Subject: [PATCH 5/7] usb: fotg210: Check role register in core MIME-Version: 1.0 Message-Id: <20230103-gemini-fotg210-usb-v1-5-f2670cb4a492@linaro.org> References: <20230103-gemini-fotg210-usb-v1-0-f2670cb4a492@linaro.org> In-Reply-To: <20230103-gemini-fotg210-usb-v1-0-f2670cb4a492@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 Tue Jan 3 23:35:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13088111 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 25899C5479D for ; Tue, 3 Jan 2023 23:35:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238405AbjACXfh (ORCPT ); Tue, 3 Jan 2023 18:35:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238337AbjACXfb (ORCPT ); Tue, 3 Jan 2023 18:35:31 -0500 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DC4C1659D for ; Tue, 3 Jan 2023 15:35:30 -0800 (PST) Received: by mail-lf1-x134.google.com with SMTP id bq39so40175978lfb.0 for ; Tue, 03 Jan 2023 15:35:30 -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=tcCZcfMImVoguFifloAOWn9GN0CXlpPQ4S3kvfMhx2k=; b=LMzkaTaD9wctPIdbVm6QZUwZrtpXDiu7SaqEPqgdBxrAK6JScPBaGrLm/A0N01Lhiq /h0OmYwR4qgPuUZcg0MhoQMcXM8wZZxbV//ypdaaHphZ9dVEdqWMcg0FSCE80jX22uVM xIz43KghAFD0/iQECoyywpdcNddRH6WyU7KavDCrWnWEdv8Uh3MsXOJLcsh+tL9tr2Qq 4S6lhVTVH9sb1JCGSuu3LZHNAC3/sXJ2Mrugam+0yG0CSodv0QHEPfusOYoT/sI+v5sc IG9UxCWX31XmP//ZJvOvpfu9sS0HxngRJtp5PLWnbYfsLBE7Rq1Oye3utnjwW+o2tF9w 5r2w== 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=tcCZcfMImVoguFifloAOWn9GN0CXlpPQ4S3kvfMhx2k=; b=WQEyLjYWQ1CvaflBTsFV9GSoACPjv0vG+blHOgKqUdylgi8UPJgf8RuDg8lHDW8gfg i6AmrCA+5RsnPNe98qMD0XfWKxWe+3CxBnjQEeLIsHKTD2w2JPIjBGbgxJ6rKSU1oFpC ey9qqZrWfB1xwCim3JlbZI6N5MKQItiZFvjEmXNedvc1/lH/9UfGJpEaJYVtX/soIox2 3EH/T74B/0diyd1pmtXMsz8U1PxLuJQCUrNnny3z0zx+YqPa0g0L2Te6NO3q4ZKRzUty nNLpJOfDHApSSQrMi4XByyf8TRPrMsubxUEIsgpMUtlzLXUn1UgrLyS3ZvsGTh6nabsM tCtg== X-Gm-Message-State: AFqh2kqEcE4CBqNyRxBWUqOL4ZGfdVDW8bIR5BiTpGYMPnBH2CQfFrhA +qTP4Vh7d//pTs3Wj13lC+KUjQ== X-Google-Smtp-Source: AMrXdXvLdlUsU1PT4CQcHXR+z585RdhI7YL7h5GGKY8TbquQG03EMAnBetUu1yFg0GrQv7/0XuJYMg== X-Received: by 2002:a05:6512:2393:b0:4a4:68b9:1a00 with SMTP id c19-20020a056512239300b004a468b91a00mr15548858lfv.40.1672788928996; Tue, 03 Jan 2023 15:35:28 -0800 (PST) Received: from Fecusia.local (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id b11-20020a056512070b00b004a45edc1de2sm4939801lfs.239.2023.01.03.15.35.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 15:35:28 -0800 (PST) From: Linus Walleij Date: Wed, 04 Jan 2023 00:35:22 +0100 Subject: [PATCH 6/7] usb: fotg210-udc: Assign of_node and speed on start MIME-Version: 1.0 Message-Id: <20230103-gemini-fotg210-usb-v1-6-f2670cb4a492@linaro.org> References: <20230103-gemini-fotg210-usb-v1-0-f2670cb4a492@linaro.org> In-Reply-To: <20230103-gemini-fotg210-usb-v1-0-f2670cb4a492@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 Tue Jan 3 23:35:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13088112 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 CCDDEC54EBD for ; Tue, 3 Jan 2023 23:35:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234098AbjACXfj (ORCPT ); Tue, 3 Jan 2023 18:35:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233437AbjACXfc (ORCPT ); Tue, 3 Jan 2023 18:35:32 -0500 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0A9A1659E for ; Tue, 3 Jan 2023 15:35:30 -0800 (PST) Received: by mail-lf1-x136.google.com with SMTP id f34so47915877lfv.10 for ; Tue, 03 Jan 2023 15:35:30 -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=R0uvymsPrpGAEh2BG1RLD0dqjUm8ZCLGS+gXm8386eY=; b=HbM+7KVQBWYkGwSyHDDJwF3QRzIi3Ah0k5QjVzuEEmGnlYXJsCooNiQE9P7xijHOKs BExioI0Ana0mbpWq3NcBftE0EgTQRybRgsf+a1k03OSoIkpPN6Zy2UO2Xnd6HChfEg/X 89t0CMX5NrKXMApK1pnIlrbT9t4h3mQ7sXptbxkRL/o2skXc6SMBbA3jI3GYy+DeledN krz4AILKghp1B22uiSHnsyBra4nsVvKpZKD0KkWRygVQiNswC506OQv+ptsTUFcueoXz 2WouoFIJKXqWNSeOGK19kcp6RtJLrkMb8EulWOOw4fY3iC7NOn6Dl+n7uqZ6UeosvII8 TJ9g== 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=R0uvymsPrpGAEh2BG1RLD0dqjUm8ZCLGS+gXm8386eY=; b=3irDQ6mLpC9j3Gl45GWzypxMwc6ykYbuJoWG6anMxbp8k8SJPnj+tCXwCXBn0koRtp qQaHwRJadnaKIX2OD3dzb7tFQnM7MDRB8kht776nkA8b5kQjkMOQU3i5aQU4f2u0qvrx bnsRI66+2JYfb/Hyj/GM+ErMR2v4OlhDCth0KtC9Ku92d4ZHYyuCO0Vja4wZJVXb4vOW j9OAMK8ACmtyvJxML98ot9YvAig1qavPbiP2DPNV+YE1uonmMSZFYMYV6RS6YvnmYprx OwOGRf+M5LiEFmjORI2so5z9hAxV+IK/vwJ8ybHEXs00qHl4rQl1CsYsE8Sps3raxrMC WpEA== X-Gm-Message-State: AFqh2kq8/7s/Demtn52cFD0LCH3Ye5rDdS1BiON4/lIoK7aR9ntZhISi +g8W/R2EWjrKWzyC54VY2Z6/Tw== X-Google-Smtp-Source: AMrXdXuWUOstb+6wkH9q+lI6gn2lg/hmvSWjds0SNBS4vzz8WVxEUOt+PJ81WQ4spuIcUGH5X0dYcw== X-Received: by 2002:a05:6512:3d9f:b0:4a4:68b7:f878 with SMTP id k31-20020a0565123d9f00b004a468b7f878mr19080201lfv.28.1672788930160; Tue, 03 Jan 2023 15:35:30 -0800 (PST) Received: from Fecusia.local (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id b11-20020a056512070b00b004a45edc1de2sm4939801lfs.239.2023.01.03.15.35.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 15:35:29 -0800 (PST) From: Linus Walleij Date: Wed, 04 Jan 2023 00:35:23 +0100 Subject: [PATCH 7/7] usb: fotg210-udc: Implement VBUS session MIME-Version: 1.0 Message-Id: <20230103-gemini-fotg210-usb-v1-7-f2670cb4a492@linaro.org> References: <20230103-gemini-fotg210-usb-v1-0-f2670cb4a492@linaro.org> In-Reply-To: <20230103-gemini-fotg210-usb-v1-0-f2670cb4a492@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);