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: 638843 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 14B80C54EBD for ; Tue, 3 Jan 2023 23:35:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238242AbjACXf3 (ORCPT ); Tue, 3 Jan 2023 18:35:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237880AbjACXf1 (ORCPT ); Tue, 3 Jan 2023 18:35:27 -0500 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2660416497 for ; Tue, 3 Jan 2023 15:35:26 -0800 (PST) Received: by mail-lf1-x12d.google.com with SMTP id y25so47976913lfa.9 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=ZhYQdM4/JZEgXTLoNQmczhzSe6hGY8gJ+FufnGB/e3s5GIsrQ9eZiP6OtLbLvMhUzI pQBcXwR3Gy/yE7mhZlOhudNgtLLLXokITAuzzAXGAOkxP/5BW09zkK2OFNC38sIuK7Wa nhppdADSZF82EH9bjbgtygAw/mNiqxzHtT6ZFHArmUFXN6ylq6jWREdE4MQmQkuGcmHA 3tl7v1plD2KjpS0oXjTwZoSN4pahvN3lwFmPoPZSCZ/IlkRZBF6t4YZWebuDsdpHTsuC RiTXCwTMMloxjBYok5SgWwwtuorksmwVhod90iGhSATkHVfrrnc5507bLrJJ6+mxG2hj JmnQ== X-Gm-Message-State: AFqh2kqmeUACgJgMNkpUsvGZvM0aBd2Ipro/DpdQwuAs0H1WLH16N92C i8J+NO4qJZzFK7J/rnTTmnAH+GTEk2qJxA4v 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: devicetree@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: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: 638842 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 C2BFCC54EBF for ; Tue, 3 Jan 2023 23:35:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237814AbjACXfb (ORCPT ); Tue, 3 Jan 2023 18:35:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238123AbjACXf2 (ORCPT ); Tue, 3 Jan 2023 18:35:28 -0500 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40DD2164B9 for ; Tue, 3 Jan 2023 15:35:27 -0800 (PST) Received: by mail-lf1-x12a.google.com with SMTP id m6so37598610lfj.11 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=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=nzL5+Ai8B+BXQTxVOT4r0wjZeL9E4VVJGFZ6FrT+PWpYe/2CnzosIDSzeWWV+dRDw0 Ft2R4G4k4hubVGvCm30ADb8og5bU2wcpJeCdk4Q3qvek2T4amzJTrdyny1Lq1BlvoXWc mHn3qlDNJIrIWEN7yyu0QeqCP1SlxIxqgL++1VyWluAGWtVednyqSWM48lzTVjcWM2Dd ibAv2zW3tXequwhU+Yw62lF8WmwaXTrsZSDw3EWjf3FbF71fOM3Q+NxMXXV3zfAVowcI mYv9jaD7waf7/dXBV7Fo5w9P/KBk5gbePbX8/MnsESwJ3jw1cEbchKMVDayN2y/1WoNb /I2g== X-Gm-Message-State: AFqh2kpFRIywL7/XeCfytzKoBOKRcp3HIpiPIyXFrn2j/G7r07eGBwsG XAmE6sP77G3NZz93UXtOPvd3ig== 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: devicetree@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: 638841 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 3AF2CC5479D for ; Tue, 3 Jan 2023 23:35:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233187AbjACXfd (ORCPT ); Tue, 3 Jan 2023 18:35:33 -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 S238269AbjACXf3 (ORCPT ); Tue, 3 Jan 2023 18:35:29 -0500 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 515CA165A6 for ; Tue, 3 Jan 2023 15:35:28 -0800 (PST) Received: by mail-lf1-x12d.google.com with SMTP id y25so47977162lfa.9 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=htsJVj3EMGUO63Db/1DxzwSQnPjY/6sds7g/6pQDt8xFYjGSOziLYru3BG0dZCXocR DZQH1EoMN92EE8zv7ak1yRpgFX2wGwdSHZ2i4WZvNLy8gWhEmrsPzFlZ/ciX1urx6J9h q0DwwW2PQOo6w5Ex6BVDZpgUPWJrIKl0dGrKayIlMO4u7lQSoPqy0aYxE1aVEpgQA+/B gyWuBvRO1N8s1hKNTv2M6d4nNC6caMpcz110Z0Rk0Y0GQGMh4YCGB8cM1jVrGIP/7AR+ /XZA1PlrbuNBfbiiAoL0TZf/Y6fwe1BgmdCKNqxB5S8jptA1/1UZlmAWQOSf+rM8KihA xlBw== X-Gm-Message-State: AFqh2kpx9ScB+7H8RLXzUF6x0Jb0H5Age7nGGo5cvHyKWS2I7GIMi3m+ WeY2yP81kzG2gLWofdC+x/sDGw== 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: devicetree@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: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: 638840 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 0DD3FC4708E for ; Tue, 3 Jan 2023 23:35:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238297AbjACXfh (ORCPT ); Tue, 3 Jan 2023 18:35:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238230AbjACXfc (ORCPT ); Tue, 3 Jan 2023 18:35:32 -0500 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDAE716497 for ; Tue, 3 Jan 2023 15:35:31 -0800 (PST) Received: by mail-lf1-x12a.google.com with SMTP id g13so47949198lfv.7 for ; Tue, 03 Jan 2023 15:35:31 -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=ercrDNLYZHFIZzbGTDSlj7apDm8K0Bdmw01wh1CIcv9YwxejtTj8hF2DyMJ1qWrCOJ 4FEQFBWATnAzpVVCqekpNSzor5GHyCpivmtWuBuVcUQ1AV5a1zP2HIMAbZl+VUsnf5MG C5DSS+FJuSvQh1Roq15WNXA5b9yvIBNUI5naXLEMHHTlLiR3kWqx9J6yrPwCC4zdjapO NRQ2wzY+2I7Zfn9FKxPD5PewN13LinuxwZBu1TjjGpczQKVXYJqhv/A9t5qcmaub/TIG GYSD4sUN1lYwbXPWf375rEdaiOY8xr5aWWIXMxOc7Vz0v9qVYk0v5rRYoC3RpgHF+lJO eKqw== X-Gm-Message-State: AFqh2koGRUyf46QpcQHlMbQcCyto6YmGRakz3oEcxp9a9jLiPrLh+1Sm r/JPZO/POB2VZMInlK7we8uyhg== 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: devicetree@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);