Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2237821rdb; Fri, 8 Dec 2023 02:17:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IEOX2EF2awbeXQU22ViN4ImLDJ7Q5RqOLMfZfAYHib0BA48Y4KywIaiSS3URMlDyiI1aCox X-Received: by 2002:a17:903:1205:b0:1d0:af43:9354 with SMTP id l5-20020a170903120500b001d0af439354mr4130081plh.100.1702030630079; Fri, 08 Dec 2023 02:17:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702030630; cv=none; d=google.com; s=arc-20160816; b=VkDctPz6C0Z7KfpKKWKkVh6mvVHDZI6E3mEbR91guqMUW8+1uErCf1ZPF8gNV7drba Tz4XdEIixnAaAVH+0rsdoAvjH1l7oqHyGdYwMJsnuUZX5MGZYwayZwpAQ5LRhrtXXxnD PmPgvyC5+wIKWLXkph5D4u5XdU7IEkAOQrE19HblfEfhzTUcabiWqEyoUhvQvdJuO/SR 6PFcDSHjdrW1knbKG2eLdcRx6bl80Vx3I/sHVaMBIQoCP/FDXrHQ4phRHzY/XTUmeKQX GfNUsGqVbdM6p2Gc+OBqssOdvmKyQN6VKKSwtD7EEFGpYc3XHE38FRUR7oJfZKHM58JS nfHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id; bh=GjSme2DZNeYaoi+SfFoP1YR1DMnAf/EdBXK9sgvzyH4=; fh=QPJmqsXEWNhGYmLiHmS1JFjMk5O/JuDfzpTVDZw0ooE=; b=MOaP5MNf2khHJS2mCT82/aoM3e7sKc6J3HtZ3cvpbeuMoe8rbv1EUPbuKh5HC85nSZ GSi2KAcp6sWVrrw9oldOhcy9A++4XLbNz9ZMljfKhxcCNIkdfGRbw+G6odEhZLgbwkpc KS5iW0M+6jCVz5sJ8BheyhwR/43eT3Px0PFkJXKizt5Cokcw/A3qdGKCX0aVgB4KD/ew L5fgq6tKEDQjtR1lGWMH8CFAjrJl8pne3uwqQ67naYhnuONpVi8f+BBA+gBQzQV4txc1 USDvtV3NAfKZ8+5HxEo61W67sN0XjaEE4+KuuqW2k9uI0U0zdHY8HYw/W/AfTIE+cdwa Pagg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id w13-20020a170902a70d00b001cf817b01d2si1339709plq.277.2023.12.08.02.17.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 02:17:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 01DA4817C3EE; Fri, 8 Dec 2023 02:17:07 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573559AbjLHKQi convert rfc822-to-8bit (ORCPT + 99 others); Fri, 8 Dec 2023 05:16:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1573551AbjLHKQg (ORCPT ); Fri, 8 Dec 2023 05:16:36 -0500 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [IPv6:2a0a:edc0:2:b01:1d::104]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4B161708 for ; Fri, 8 Dec 2023 02:16:41 -0800 (PST) Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=[IPv6:::1]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rBXuC-0001oc-U3; Fri, 08 Dec 2023 11:16:25 +0100 Message-ID: <0cd40cf388e70b101b3857220fd7a74cf75cfa81.camel@pengutronix.de> Subject: Re: [PATCH 1/4] PCI: imx6: Add pci host wakeup support on imx platforms. From: Lucas Stach To: Sherry Sun , hongxing.zhu@nxp.com, lpieralisi@kernel.org, kw@linux.com, robh@kernel.org, bhelgaas@google.com, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com Cc: linux-imx@nxp.com, linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Date: Fri, 08 Dec 2023 11:16:23 +0100 In-Reply-To: <20231208091355.1417292-2-sherry.sun@nxp.com> References: <20231208091355.1417292-1-sherry.sun@nxp.com> <20231208091355.1417292-2-sherry.sun@nxp.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT User-Agent: Evolution 3.48.4 (3.48.4-1.fc38) MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: l.stach@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Fri, 08 Dec 2023 02:17:07 -0800 (PST) Am Freitag, dem 08.12.2023 um 17:13 +0800 schrieb Sherry Sun: > Add pci host wakeup feature for imx platforms. > Example of configuring the corresponding dts property under the PCI > node: > host-wake-gpio = <&gpio5 21 GPIO_ACTIVE_LOW>; > > Signed-off-by: Sherry Sun > Reviewed-by: Richard Zhu > --- > drivers/pci/controller/dwc/pci-imx6.c | 69 +++++++++++++++++++++++++++ > 1 file changed, 69 insertions(+) > > diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c > index 74703362aeec..050c9140f4a3 100644 > --- a/drivers/pci/controller/dwc/pci-imx6.c > +++ b/drivers/pci/controller/dwc/pci-imx6.c > @@ -72,6 +72,7 @@ struct imx6_pcie_drvdata { > struct imx6_pcie { > struct dw_pcie *pci; > int reset_gpio; > + int host_wake_irq; > bool gpio_active_high; > bool link_is_up; > struct clk *pcie_bus; > @@ -1237,11 +1238,46 @@ static int imx6_pcie_resume_noirq(struct device *dev) > return 0; > } > > +static int imx6_pcie_suspend(struct device *dev) > +{ > + struct imx6_pcie *imx6_pcie = dev_get_drvdata(dev); > + > + if (imx6_pcie->host_wake_irq >= 0) > + enable_irq_wake(imx6_pcie->host_wake_irq); > + > + return 0; > +} > + > +static int imx6_pcie_resume(struct device *dev) > +{ > + struct imx6_pcie *imx6_pcie = dev_get_drvdata(dev); > + > + if (imx6_pcie->host_wake_irq >= 0) > + disable_irq_wake(imx6_pcie->host_wake_irq); > + > + return 0; > +} > + > static const struct dev_pm_ops imx6_pcie_pm_ops = { > NOIRQ_SYSTEM_SLEEP_PM_OPS(imx6_pcie_suspend_noirq, > imx6_pcie_resume_noirq) > + SYSTEM_SLEEP_PM_OPS(imx6_pcie_suspend, imx6_pcie_resume) > }; > > +irqreturn_t host_wake_irq_handler(int irq, void *priv) > +{ > + struct imx6_pcie *imx6_pcie = priv; > + struct device *dev = imx6_pcie->pci->dev; > + > + dev_dbg(dev, "%s: host wakeup by pcie", __func__); > + Not sure how much value this debug print carries. If you want to keep it, drop the __func__. There is no other place in this driver handling the wakeup, so the function name in the print is pure noise. > + /* Notify PM core we are wakeup source */ > + pm_wakeup_event(dev, 0); > + pm_system_wakeup(); > + > + return IRQ_HANDLED; > +} > + > static int imx6_pcie_probe(struct platform_device *pdev) > { > struct device *dev = &pdev->dev; > @@ -1250,6 +1286,7 @@ static int imx6_pcie_probe(struct platform_device *pdev) > struct device_node *np; > struct resource *dbi_base; > struct device_node *node = dev->of_node; > + struct gpio_desc *host_wake_gpio; > int ret; > u16 val; > > @@ -1457,6 +1494,32 @@ static int imx6_pcie_probe(struct platform_device *pdev) > val |= PCI_MSI_FLAGS_ENABLE; > dw_pcie_writew_dbi(pci, offset + PCI_MSI_FLAGS, val); > } > + > + /* host wakeup support */ > + imx6_pcie->host_wake_irq = -1; > + host_wake_gpio = devm_gpiod_get_optional(dev, "host-wake", GPIOD_IN); > + if (IS_ERR(host_wake_gpio)) > + return PTR_ERR(host_wake_gpio); > + > + if (host_wake_gpio != NULL) { > + imx6_pcie->host_wake_irq = gpiod_to_irq(host_wake_gpio); > + ret = devm_request_threaded_irq(dev, imx6_pcie->host_wake_irq, NULL, > + host_wake_irq_handler, > + IRQF_ONESHOT | IRQF_TRIGGER_FALLING, > + "host_wake", imx6_pcie); > + if (ret) { > + dev_err(dev, "Failed to request host_wake_irq %d (%d)\n", > + imx6_pcie->host_wake_irq, ret); > + imx6_pcie->host_wake_irq = -1; What's the point of resetting host_wake_irq to -1 in those error paths? Nobody is going to access this member anymore after the error. Just drop this. You could simplify all those error paths to if (err) return dev_err_probe(...); > + return ret; > + } > + > + if (device_init_wakeup(dev, true)) { > + dev_err(dev, "fail to init host_wake_irq\n"); > + imx6_pcie->host_wake_irq = -1; > + return ret; > + } > + } > } > > return 0; > @@ -1466,6 +1529,12 @@ static void imx6_pcie_shutdown(struct platform_device *pdev) > { > struct imx6_pcie *imx6_pcie = platform_get_drvdata(pdev); > > + if (imx6_pcie->host_wake_irq >= 0) { > + device_init_wakeup(&pdev->dev, false); > + disable_irq(imx6_pcie->host_wake_irq); > + imx6_pcie->host_wake_irq = -1; > + } > + > /* bring down link, so bootloader gets clean state in case of reboot */ > imx6_pcie_assert_core_reset(imx6_pcie); > }