From patchwork Mon Nov 14 11:51:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 625069 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 144DDC4332F for ; Mon, 14 Nov 2022 11:56:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236942AbiKNL4p (ORCPT ); Mon, 14 Nov 2022 06:56:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236923AbiKNL4b (ORCPT ); Mon, 14 Nov 2022 06:56:31 -0500 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9E9724952 for ; Mon, 14 Nov 2022 03:52:09 -0800 (PST) Received: by mail-lj1-x22c.google.com with SMTP id h12so12815411ljg.9 for ; Mon, 14 Nov 2022 03:52:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=23J2rxW29+aENYRjYQO3CvbM83oXKeca0v4ut8EgLyc=; b=SSqYE2X6QeuX6Oc6rgira/TUu8ELeOHcfffGwFc1Jjku0sOgO4gIum4DoqTQNT5qNk hcbN7I69awhwye9HmUNBROziQ1TlnxA+U6LVOkFHQ3YIE9Bb7hXNRCPjotMA1gBy/+Wp wi2pmlaPqGtHVKecw5bV/vZenlc6Nvg+zwbCebB1fn9A2PuvdEO0SejLUp2A/BDu3dhE nmRZNsVyk0Rrir4Zc/D9H0Rku9EnlC/GUpOn4JLVtn2J7Vzm2xvZdwPAF3XDhvG8JCT2 t0kXticvcPgHboc6IVMENf27bFBfyu6zKs2Lo7iXqID4R5R1+qrMNdkZ5w4iFiVyIeHl cZNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=23J2rxW29+aENYRjYQO3CvbM83oXKeca0v4ut8EgLyc=; b=iJev4WOPhpkh4sxIXagT4Y4ODIcuCG5wOeQRttp0NBdY8cWpsuVg4vPg4qWt0H3mtN g8Jm3EI5CIktlNxMIZ/gHvQ3C+RLTr+UKIxaM2PNclWtWaEckuFrVywhUDtdnNleKn8E NYHgKv4ZxGJ0iKVp0NBtUuRyBkMsrsofj79AvlqiRTRSQW8aYd9uttTw4FdMGpa4vqdp Iap2QRXdAbBE0CV6AR2+g3e3jchCxSrn17dXDRVuRoOeugEAunjgRQF8gMyU8EzODf71 bD3LZXhwBBr0wxuKnpU1hM6Q16YuzatauumXQRK5Hi2vrBe2ju9FqTNs7F9PBqnflJCh AoLA== X-Gm-Message-State: ANoB5pnsIDSY6PzLsuAm3rMt5lgQfmC+u30ct4BJBAjY0iFIVGrpIXRI MrRQzR7GeJMVneRNVjf8fGGxLEOl8U5FHQ== X-Google-Smtp-Source: AA0mqf7XeSBAJW33aWa+cj4Lwq//cEDc+UOJ45dGGge6iVbcmhseP5juMhNmoC3w2qnm4TwB/KLfJg== X-Received: by 2002:a2e:be0a:0:b0:277:a8b:4a53 with SMTP id z10-20020a2ebe0a000000b002770a8b4a53mr3849259ljq.197.1668426728192; Mon, 14 Nov 2022 03:52:08 -0800 (PST) Received: from Fecusia.lan (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id h8-20020a05651c124800b0027758f0619fsm1981531ljh.132.2022.11.14.03.52.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 03:52:07 -0800 (PST) From: Linus Walleij To: Greg Kroah-Hartman , Felipe Balbi Cc: linux-usb@vger.kernel.org, Linus Walleij Subject: [PATCH 1/4] fotg210-udc: Use dev pointer in probe and dev_messages Date: Mon, 14 Nov 2022 12:51:58 +0100 Message-Id: <20221114115201.302887-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Add a local struct device *dev pointer and use dev_err() etc to report status. Signed-off-by: Linus Walleij --- drivers/usb/fotg210/fotg210-udc.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/usb/fotg210/fotg210-udc.c b/drivers/usb/fotg210/fotg210-udc.c index 3c357ce42d3b..b3106e4b3194 100644 --- a/drivers/usb/fotg210/fotg210-udc.c +++ b/drivers/usb/fotg210/fotg210-udc.c @@ -1091,6 +1091,7 @@ int fotg210_udc_probe(struct platform_device *pdev) struct resource *res, *ires; struct fotg210_udc *fotg210 = NULL; struct fotg210_ep *_ep[FOTG210_MAX_NUM_EP]; + struct device *dev = &pdev->dev; int ret = 0; int i; @@ -1122,7 +1123,7 @@ int fotg210_udc_probe(struct platform_device *pdev) fotg210->reg = ioremap(res->start, resource_size(res)); if (fotg210->reg == NULL) { - pr_err("ioremap error.\n"); + dev_err(dev, "ioremap error\n"); goto err_alloc; } @@ -1133,8 +1134,8 @@ int fotg210_udc_probe(struct platform_device *pdev) fotg210->gadget.ops = &fotg210_gadget_ops; fotg210->gadget.max_speed = USB_SPEED_HIGH; - fotg210->gadget.dev.parent = &pdev->dev; - fotg210->gadget.dev.dma_mask = pdev->dev.dma_mask; + fotg210->gadget.dev.parent = dev; + fotg210->gadget.dev.dma_mask = dev->dma_mask; fotg210->gadget.name = udc_name; INIT_LIST_HEAD(&fotg210->gadget.ep_list); @@ -1180,15 +1181,15 @@ int fotg210_udc_probe(struct platform_device *pdev) ret = request_irq(ires->start, fotg210_irq, IRQF_SHARED, udc_name, fotg210); if (ret < 0) { - pr_err("request_irq error (%d)\n", ret); + dev_err(dev, "request_irq error (%d)\n", ret); goto err_req; } - ret = usb_add_gadget_udc(&pdev->dev, &fotg210->gadget); + ret = usb_add_gadget_udc(dev, &fotg210->gadget); if (ret) goto err_add_udc; - dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION); + dev_info(dev, "version %s\n", DRIVER_VERSION); return 0; From patchwork Mon Nov 14 11:51:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 625068 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 9E2DCC4332F for ; Mon, 14 Nov 2022 11:56:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237039AbiKNL4t (ORCPT ); Mon, 14 Nov 2022 06:56:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236995AbiKNL4c (ORCPT ); Mon, 14 Nov 2022 06:56:32 -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 2B986248D9 for ; Mon, 14 Nov 2022 03:52:13 -0800 (PST) Received: by mail-lf1-x12b.google.com with SMTP id bp15so18784009lfb.13 for ; Mon, 14 Nov 2022 03:52:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=490Ahm7yaCTQkYNJWQbuTL/BW7+rQHebePQfeeMmwms=; b=NbJ2xWM59vGj5Q4Ani3KZYob6uYLhu545lKWD1FXdO1GmeZs377Gx0qkVGilK5G1qq B6ajpQaojSxMxxNMbPYxPMgUgSd0CapE2YybDt9or9tZ9W3W5AWV8OLPdMFP4Q5SY65l 34r3VlTq3nPt4iT8qpuUbaCLmAGz6+qfgRm2NN3qKjTktAfgqUNeRpjNosQCh2J3JnyW elbQT7JuhiMTuTDE/twVEY/hc7MbVVjgZc3T9sAH4Gg5Q2yTZKtfyenUqhGc0WJ5bnLX edpCTPRVvHPh67DeD6wA/bDxR/hXJIJ67JKlfFJsHTA1+7fg6oB1HFYSkmHZsXLjV7Cm BNtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=490Ahm7yaCTQkYNJWQbuTL/BW7+rQHebePQfeeMmwms=; b=ENtLhcfKhvkEJ/sMTKXYo8m9QwOzjhB3ETCBN+mFM53v6og3Fe84uV3eUF75Ip28i3 4ho2z3kEKILvnxkkAUviP5iW+LWonxay4Oe6rp4giIr2ehrHDPyq28Rovw4HPPYZ31TV bu58iGTppzvoaMH/d1LctNRWYjUai+iG8hmW/HDtDpAICLqXe81/yTtojCWSFBfPs9a0 BYfVmnWP5Fww7LXEOYYEFagLJj5F+AXiGk8ekEdhMHH+S0m3EkPbRUhPhFNFwDCETMyU Bj0KSX6lWZiQOLPwN8nQmqFPfeYiyicn/Zt/DAbpm3GcZPcY93zSLuoj31+8xqSIcI1u rBFg== X-Gm-Message-State: ANoB5pmMhRpkEENpRESEkOlFvDY9YLF6/vVJMVDY8dWOmC4nz2RS2Qbm 6lRAsHiaJ3OxMfZyFWuGWXVO2w== X-Google-Smtp-Source: AA0mqf5aInL6CGbekkcCLO6Q/9AWq2rxeNDM4dHGxZKTfnpdVX9Syelrj6Syo+HCWbOQd2MIdTjlmQ== X-Received: by 2002:a05:6512:329c:b0:494:79b6:c7a2 with SMTP id p28-20020a056512329c00b0049479b6c7a2mr4426474lfe.513.1668426731461; Mon, 14 Nov 2022 03:52:11 -0800 (PST) Received: from Fecusia.lan (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id h8-20020a05651c124800b0027758f0619fsm1981531ljh.132.2022.11.14.03.52.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 03:52:11 -0800 (PST) From: Linus Walleij To: Greg Kroah-Hartman , Felipe Balbi Cc: linux-usb@vger.kernel.org, Linus Walleij Subject: [PATCH 2/4] fotg210-udc: Support optional external PHY Date: Mon, 14 Nov 2022 12:51:59 +0100 Message-Id: <20221114115201.302887-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221114115201.302887-1-linus.walleij@linaro.org> References: <20221114115201.302887-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org This adds support for an optional external PHY to the FOTG210 UDC driver. Tested with the GPIO VBUS PHY driver on the Gemini SoC. Signed-off-by: Linus Walleij --- drivers/usb/fotg210/fotg210-udc.c | 72 +++++++++++++++++++++++++++++++ drivers/usb/fotg210/fotg210-udc.h | 2 + 2 files changed, 74 insertions(+) diff --git a/drivers/usb/fotg210/fotg210-udc.c b/drivers/usb/fotg210/fotg210-udc.c index b3106e4b3194..4026103330e1 100644 --- a/drivers/usb/fotg210/fotg210-udc.c +++ b/drivers/usb/fotg210/fotg210-udc.c @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include "fotg210.h" #include "fotg210-udc.h" @@ -1008,11 +1010,19 @@ static int fotg210_udc_start(struct usb_gadget *g, { struct fotg210_udc *fotg210 = gadget_to_fotg210(g); u32 value; + int ret; /* hook up the driver */ driver->driver.bus = NULL; fotg210->driver = driver; + if (!IS_ERR_OR_NULL(fotg210->phy)) { + ret = otg_set_peripheral(fotg210->phy->otg, + &fotg210->gadget); + if (ret) + dev_err(fotg210->dev, "can't bind to phy\n"); + } + /* enable device global interrupt */ value = ioread32(fotg210->reg + FOTG210_DMCR); value |= DMCR_GLINT_EN; @@ -1054,6 +1064,9 @@ static int fotg210_udc_stop(struct usb_gadget *g) struct fotg210_udc *fotg210 = gadget_to_fotg210(g); unsigned long flags; + if (!IS_ERR_OR_NULL(fotg210->phy)) + return otg_set_peripheral(fotg210->phy->otg, NULL); + spin_lock_irqsave(&fotg210->lock, flags); fotg210_init(fotg210); @@ -1069,12 +1082,50 @@ static const struct usb_gadget_ops fotg210_gadget_ops = { .udc_stop = fotg210_udc_stop, }; +/** + * fotg210_phy_event - Called by phy upon VBus event + * @nb: notifier block + * @action: phy action, is vbus connect or disconnect + * @data: the usb_gadget structure in fotg210 + * + * Called by the USB Phy when a cable connect or disconnect is sensed. + * + * Returns NOTIFY_OK or NOTIFY_DONE + */ +static int fotg210_phy_event(struct notifier_block *nb, unsigned long action, + void *data) +{ + struct usb_gadget *gadget = data; + + if (!gadget) + return NOTIFY_DONE; + + switch (action) { + case USB_EVENT_VBUS: + usb_gadget_vbus_connect(gadget); + return NOTIFY_OK; + case USB_EVENT_NONE: + usb_gadget_vbus_disconnect(gadget); + return NOTIFY_OK; + default: + return NOTIFY_DONE; + } +} + +static struct notifier_block fotg210_phy_notifier = { + .notifier_call = fotg210_phy_event, +}; + int fotg210_udc_remove(struct platform_device *pdev) { struct fotg210_udc *fotg210 = platform_get_drvdata(pdev); int i; usb_del_gadget_udc(&fotg210->gadget); + if (!IS_ERR_OR_NULL(fotg210->phy)) { + usb_unregister_notifier(fotg210->phy, &fotg210_phy_notifier); + usb_put_phy(fotg210->phy); + } iounmap(fotg210->reg); free_irq(platform_get_irq(pdev, 0), fotg210); @@ -1114,6 +1165,22 @@ int fotg210_udc_probe(struct platform_device *pdev) if (fotg210 == NULL) goto err; + fotg210->dev = dev; + + fotg210->phy = devm_usb_get_phy_by_phandle(dev->parent, "usb-phy", 0); + if (IS_ERR(fotg210->phy)) { + ret = PTR_ERR(fotg210->phy); + if (ret == -EPROBE_DEFER) + goto err; + dev_info(dev, "no PHY found\n"); + fotg210->phy = NULL; + } else { + ret = usb_phy_init(fotg210->phy); + if (ret) + goto err; + dev_info(dev, "found and initialized PHY\n"); + } + for (i = 0; i < FOTG210_MAX_NUM_EP; i++) { _ep[i] = kzalloc(sizeof(struct fotg210_ep), GFP_KERNEL); if (_ep[i] == NULL) @@ -1185,6 +1252,9 @@ int fotg210_udc_probe(struct platform_device *pdev) goto err_req; } + if (!IS_ERR_OR_NULL(fotg210->phy)) + usb_register_notifier(fotg210->phy, &fotg210_phy_notifier); + ret = usb_add_gadget_udc(dev, &fotg210->gadget); if (ret) goto err_add_udc; @@ -1194,6 +1264,8 @@ int fotg210_udc_probe(struct platform_device *pdev) return 0; err_add_udc: + if (!IS_ERR_OR_NULL(fotg210->phy)) + usb_unregister_notifier(fotg210->phy, &fotg210_phy_notifier); free_irq(ires->start, fotg210); err_req: diff --git a/drivers/usb/fotg210/fotg210-udc.h b/drivers/usb/fotg210/fotg210-udc.h index 08c32957503b..e3067d22a895 100644 --- a/drivers/usb/fotg210/fotg210-udc.h +++ b/drivers/usb/fotg210/fotg210-udc.h @@ -234,6 +234,8 @@ struct fotg210_udc { unsigned long irq_trigger; + struct device *dev; + struct usb_phy *phy; struct usb_gadget gadget; struct usb_gadget_driver *driver; From patchwork Mon Nov 14 11:52:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 624740 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 6ADEAC433FE for ; Mon, 14 Nov 2022 11:56:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237003AbiKNL4r (ORCPT ); Mon, 14 Nov 2022 06:56:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236958AbiKNL4c (ORCPT ); Mon, 14 Nov 2022 06:56:32 -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 5063B25E81 for ; Mon, 14 Nov 2022 03:52:15 -0800 (PST) Received: by mail-lf1-x12e.google.com with SMTP id be13so18858833lfb.4 for ; Mon, 14 Nov 2022 03:52:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=r7exiVCrJbaM9H+RqYL7LmV64o+Q+SRzu55CzL4HBG8=; b=NlqU7a5Rms7Kf+dRf9fj/RAcJYMVgYbgccJ41nRDEhxNwFkXz1flwK4D1V6YhFdG+8 LsAKCKNNgkKp0UqQwYcQmx8Ng08xXgiiIP18GxkeGnR/ggPOsP1DPzaybFySgIppXthn bRaD9F4D9r6b2aQAWP5Or5dXjl3ZttLHcWr5Tup2UXfpybSpWWNABnxfi9oJYc52gFrq V0osDhi8G2rtJ36fP+ZxTgogx18D1hq5d7mf3v85AYezqHjta70DlGyvGNkpd3XDabdK xojC27P2dPTmvSZ+fv0YTkq5XErneMgyexBbLi5yIXgOC99hv2wSF+/XPf6nv8wKytIh FYpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=r7exiVCrJbaM9H+RqYL7LmV64o+Q+SRzu55CzL4HBG8=; b=fDIV6KVfuBA2BUzpj7kpLbOqQcQdNgQzwcL11z2W/WDl8LP/1+u6JrR99vVT+ifeI+ LFgz7cFQ20IpmQjOTHIqz37J1nhy/RIWAl+zEaneec5V1RVaCrJE0HEX3Q64NOvPkWt8 BCOHe/1Qvkw6n2SPHE43cgOMLz6ShzDROOSLRMgFNZzn2jHOV/4G0sB/46Q9UD7WyXeU HzH+yoqXFKiPek+p2rzd/qVS70/GGB0Ef1eTD2b4ShypBe+gSh1KxemNBNqYl36+fvkQ egw+f56zg7gLmy8u4oNjHhowUAdTRELdJDLlzGCCAO0KqR2IZInvje9IQ3dbNscVGz2X 6ToA== X-Gm-Message-State: ANoB5plQAjZCbGo78I+zUF4BOY3+chwwsPbaX2l+M6MgNip4k2R/KEXX GLeBXgKVWC8Rh07Xc+TAjIQempKmcNCSiw== X-Google-Smtp-Source: AA0mqf7CUNguB9m6WTIBXnmWrKskLozk/fLnIAN4ZwufexQSGY2VKnvYsxT6pRa3p5egCQcjxoddLg== X-Received: by 2002:a19:7909:0:b0:4a2:4282:89c7 with SMTP id u9-20020a197909000000b004a2428289c7mr4192598lfc.437.1668426733676; Mon, 14 Nov 2022 03:52:13 -0800 (PST) Received: from Fecusia.lan (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id h8-20020a05651c124800b0027758f0619fsm1981531ljh.132.2022.11.14.03.52.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 03:52:13 -0800 (PST) From: Linus Walleij To: Greg Kroah-Hartman , Felipe Balbi Cc: linux-usb@vger.kernel.org, Linus Walleij Subject: [PATCH 3/4] fotg210-udc: Handle PCLK Date: Mon, 14 Nov 2022 12:52:00 +0100 Message-Id: <20221114115201.302887-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221114115201.302887-1-linus.walleij@linaro.org> References: <20221114115201.302887-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org This adds optional handling of the peripheral clock PCLK. Signed-off-by: Linus Walleij --- drivers/usb/fotg210/fotg210-udc.c | 30 ++++++++++++++++++++++++++++-- drivers/usb/fotg210/fotg210-udc.h | 1 + 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/drivers/usb/fotg210/fotg210-udc.c b/drivers/usb/fotg210/fotg210-udc.c index 4026103330e1..de0f72ca103c 100644 --- a/drivers/usb/fotg210/fotg210-udc.c +++ b/drivers/usb/fotg210/fotg210-udc.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -1132,6 +1133,10 @@ int fotg210_udc_remove(struct platform_device *pdev) fotg210_ep_free_request(&fotg210->ep[0]->ep, fotg210->ep0_req); 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; @@ -1167,17 +1172,34 @@ int fotg210_udc_probe(struct platform_device *pdev) fotg210->dev = dev; + /* 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"); + return ret; + } + } 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->parent, "usb-phy", 0); if (IS_ERR(fotg210->phy)) { ret = PTR_ERR(fotg210->phy); if (ret == -EPROBE_DEFER) - goto err; + goto err_pclk; dev_info(dev, "no PHY found\n"); fotg210->phy = NULL; } else { ret = usb_phy_init(fotg210->phy); if (ret) - goto err; + goto err_pclk; dev_info(dev, "found and initialized PHY\n"); } @@ -1277,6 +1299,10 @@ int fotg210_udc_probe(struct platform_device *pdev) 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); + kfree(fotg210); err: diff --git a/drivers/usb/fotg210/fotg210-udc.h b/drivers/usb/fotg210/fotg210-udc.h index e3067d22a895..fadb57ca8d78 100644 --- a/drivers/usb/fotg210/fotg210-udc.h +++ b/drivers/usb/fotg210/fotg210-udc.h @@ -231,6 +231,7 @@ struct fotg210_ep { struct fotg210_udc { spinlock_t lock; /* protect the struct */ void __iomem *reg; + struct clk *pclk; unsigned long irq_trigger; From patchwork Mon Nov 14 11:52:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 624739 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 B0670C43217 for ; Mon, 14 Nov 2022 11:56:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237041AbiKNL4u (ORCPT ); Mon, 14 Nov 2022 06:56:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237000AbiKNL4c (ORCPT ); Mon, 14 Nov 2022 06:56:32 -0500 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B325124BD0 for ; Mon, 14 Nov 2022 03:52:17 -0800 (PST) Received: by mail-lj1-x229.google.com with SMTP id u11so12789970ljk.6 for ; Mon, 14 Nov 2022 03:52:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AyU+TKJuyeZ4uZNx8LKOm+8a/rFdvv0uEXAlRDXnoqk=; b=vqkzWOw5wv0EZ2VceJ01cP+qBlni3kSVxvqEoek3e9YK2ghh5S3Ta7EwGHo/BS9rmA R2fNc6jpGj4gZ/Vqb3wavDH6eVRwyItaRm5d5i+SFneIVuagPKzXPQkcONJLb9PPLC16 UT+fiVjdNJ+FjtmBN5zkffHbLys3Fbh7ryXs+m4d3mk4On9pYSLq1WkggEF9IwBhqKH4 cqxjD+h9owR+ItJa85pC//36xYgt9LCJ63UeTgtM0OWzlOV5FHkrMC4n4kic4atR+6PI yte6g/yFJzrfkBl+kT8VefB18TYqch4Qr/n7QU2GfBG09guzKB8zGsj8X+UHhA2h4cvP F7Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AyU+TKJuyeZ4uZNx8LKOm+8a/rFdvv0uEXAlRDXnoqk=; b=Tu5GCX2rf9JPYrHBDEzM8RHurkSSJyAkdQleQofWoYYo7TSiIciYrcfmcc0ESkyG07 +BfhqtDtW8il37LyBKCn1QKQtqHEiUuX0bxTiPFtFpgt8g5DVnCQU/1RgRboWoR9GNMD m4PUPhcgITFOAFhez3jRycGLpJKqLiyKvG4DqjwipgvShgQp8lgjENZNd0Ux5x8SrzG/ v0CqzK90qpLOog99BMMVovyWPXbYRvTlCt5JgF3+Ik3UrzB+bdi+Cge/LBrQfJNfmg7t R8kG4WHy6eF3yU9ukC+UAfkFaRnNiMDs8kdzgc7HzUxvGrTp49SNrmcXRfgUJB/Q+sAk fxaA== X-Gm-Message-State: ANoB5pmX1v9pLLn4r9xxzfrrTSuAn4tc9Usm7/+ZT/J1b/S2NybweTCG sZaEII+iNPmfgJL3ZoY7Zq+Kqw3VTxX0Tw== X-Google-Smtp-Source: AA0mqf5hxgsrPgiw2s2iSSwrLwtU7J3XBTwnbTUlG8ZfTZbyRY6MBbe6xK5CcT7J9NoHOqFJxPYeoA== X-Received: by 2002:a2e:80da:0:b0:277:5c6b:7653 with SMTP id r26-20020a2e80da000000b002775c6b7653mr4058420ljg.398.1668426736081; Mon, 14 Nov 2022 03:52:16 -0800 (PST) Received: from Fecusia.lan (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id h8-20020a05651c124800b0027758f0619fsm1981531ljh.132.2022.11.14.03.52.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 03:52:15 -0800 (PST) From: Linus Walleij To: Greg Kroah-Hartman , Felipe Balbi Cc: linux-usb@vger.kernel.org, Linus Walleij Subject: [PATCH 4/4] fotg210-udc: Get IRQ using platform_get_irq() Date: Mon, 14 Nov 2022 12:52:01 +0100 Message-Id: <20221114115201.302887-4-linus.walleij@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221114115201.302887-1-linus.walleij@linaro.org> References: <20221114115201.302887-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The platform_get_irq() is necessary to use to get dynamic IRQ resolution when instantiating the device from the device tree. IRQs are not passed as resources in that case. Signed-off-by: Linus Walleij --- drivers/usb/fotg210/fotg210-udc.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/usb/fotg210/fotg210-udc.c b/drivers/usb/fotg210/fotg210-udc.c index de0f72ca103c..44dfe66e189c 100644 --- a/drivers/usb/fotg210/fotg210-udc.c +++ b/drivers/usb/fotg210/fotg210-udc.c @@ -1144,10 +1144,11 @@ int fotg210_udc_remove(struct platform_device *pdev) int fotg210_udc_probe(struct platform_device *pdev) { - struct resource *res, *ires; + struct resource *res; struct fotg210_udc *fotg210 = NULL; struct fotg210_ep *_ep[FOTG210_MAX_NUM_EP]; struct device *dev = &pdev->dev; + int irq; int ret = 0; int i; @@ -1157,9 +1158,9 @@ int fotg210_udc_probe(struct platform_device *pdev) return -ENODEV; } - ires = platform_get_resource(pdev, IORESOURCE_IRQ, 0); - if (!ires) { - pr_err("platform_get_resource IORESOURCE_IRQ error.\n"); + irq = platform_get_irq(pdev, 0); + if (irq < 0) { + pr_err("could not get irq\n"); return -ENODEV; } @@ -1189,7 +1190,7 @@ int fotg210_udc_probe(struct platform_device *pdev) goto err; } - fotg210->phy = devm_usb_get_phy_by_phandle(dev->parent, "usb-phy", 0); + 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) @@ -1267,7 +1268,7 @@ int fotg210_udc_probe(struct platform_device *pdev) fotg210_disable_unplug(fotg210); - ret = request_irq(ires->start, fotg210_irq, IRQF_SHARED, + ret = request_irq(irq, fotg210_irq, IRQF_SHARED, udc_name, fotg210); if (ret < 0) { dev_err(dev, "request_irq error (%d)\n", ret); @@ -1288,7 +1289,7 @@ int fotg210_udc_probe(struct platform_device *pdev) err_add_udc: if (!IS_ERR_OR_NULL(fotg210->phy)) usb_unregister_notifier(fotg210->phy, &fotg210_phy_notifier); - free_irq(ires->start, fotg210); + free_irq(irq, fotg210); err_req: fotg210_ep_free_request(&fotg210->ep[0]->ep, fotg210->ep0_req);