From patchwork Fri Nov 10 21:58:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 10053853 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 289B460637 for ; Fri, 10 Nov 2017 21:59:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C2692929B for ; Fri, 10 Nov 2017 21:59:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 10E662B11C; Fri, 10 Nov 2017 21:59:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F3B32ACE8 for ; Fri, 10 Nov 2017 21:59:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751097AbdKJV7G (ORCPT ); Fri, 10 Nov 2017 16:59:06 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:39452 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754072AbdKJV7F (ORCPT ); Fri, 10 Nov 2017 16:59:05 -0500 Received: by mail-wm0-f65.google.com with SMTP id b189so5211812wmd.4; Fri, 10 Nov 2017 13:59:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=vTpYKyudzVVybk7RfWT0g9pe5sKSHvya/CTQb2xeqko=; b=i5nMO06KV1b6IwSux/t5ruDTIDOuACx3K5uJW4qWpqyQYGF2n3YXOEjhf0MLO/X081 ajqMgyEPGbZoY05gJCttrGH7M3SD++etYG1LrX6p05bOTGYeG+U8GgKVlebiIzBmAm2L GvzVE5mKvF6N8YG33p9lNJJXetBqsXCU0GIXH8t5zg1dOBTP5wRPl+bp+FwomOdk3nBi nNOBBda+49y6lQAQF90dYPw7B9eMvQA+X4f16GC6+5bVg0Ypto+GmOKs8CeDW6AEQ9Wf Uqmv+d6bv9zj8PvGiW45G/DxJwrfItsD3AciudZ/34BLibr28nSNTvete2aW0lBygEYB /68Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=vTpYKyudzVVybk7RfWT0g9pe5sKSHvya/CTQb2xeqko=; b=KI6S4T+R3iHgmufaUTl7GqacKJcbD0ye75lCmCkkqdL6mZvs9kcL7+sG2p4AwmiB3y kHnedpH++d74nn7Wi/RLIddWJ+QAir7Sg+hi3AQigF0mQvE2At1ks+hCZ4A/WrQjkJsK hfsO5/XveVTtyGi8aFLKoF+K3sy8bejhxlySYoceIXKqsOW1RwF4GFkRBBC2hvHF5WFb gm8Mb+LuaNmGgW1J4exdx24T7xSE03zNO75lzpIs5WUoYhKhw+4BLr20AbuCqtTBx4Jh 5FbTLUmTy0T7Gx6lbA0W3bt3bRTHj4hlOSbPn8sX0d8prtQ/tK5d3cQamuuLVpdASmZ0 +MpQ== X-Gm-Message-State: AJaThX41Nxc0bYL2AZ+p7TTMPecnq1hFfgcuelN1x0uWNr4d5SCWNuoJ DZ2fQ6XeOZrr6urS6XYlByrGqRX4 X-Google-Smtp-Source: AGs4zMa6E5v5Zvh5foXzIK2S15VEz0HnlWlL7Js8zY9gIcheSAd+wdW5uG6kgCVyTm5PCk/KxBzrQA== X-Received: by 10.28.84.89 with SMTP id p25mr1154962wmi.112.1510351143410; Fri, 10 Nov 2017 13:59:03 -0800 (PST) Received: from kurokawa.lan (ip-86-49-107-50.net.upcbroadband.cz. [86.49.107.50]) by smtp.gmail.com with ESMTPSA id c3sm4560784wrd.44.2017.11.10.13.59.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Nov 2017 13:59:02 -0800 (PST) From: Marek Vasut X-Google-Original-From: Marek Vasut To: linux-pci@vger.kernel.org Cc: Kazufumi Ikeda , Gaku Inami , Marek Vasut , Geert Uytterhoeven , Phil Edworthy , Simon Horman , Wolfram Sang , linux-renesas-soc@vger.kernel.org Subject: [PATCH V2 5/5] PCI: rcar: Add the suspend/resume for pcie-rcar driver Date: Fri, 10 Nov 2017 22:58:43 +0100 Message-Id: <20171110215843.432-6-marek.vasut+renesas@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171110215843.432-1-marek.vasut+renesas@gmail.com> References: <20171110215843.432-1-marek.vasut+renesas@gmail.com> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Kazufumi Ikeda This adds the suspend/resume supports for pcie-rcar. The resume handler reprograms the hardware based on the software state kept in specific device structures. Also it doesn't need to save any registers. Signed-off-by: Kazufumi Ikeda Signed-off-by: Gaku Inami Signed-off-by: Marek Vasut Cc: Geert Uytterhoeven Cc: Phil Edworthy Cc: Simon Horman Cc: Wolfram Sang Cc: linux-renesas-soc@vger.kernel.org Acked-by: Simon Horman --- V2: - Change return type of rcar_pcie_hw_enable() to void - Drop default: case in switch statement in rcar_pcie_hw_enable() - Sort variables in rcar_pcie_resume() --- drivers/pci/host/pcie-rcar.c | 82 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 74 insertions(+), 8 deletions(-) diff --git a/drivers/pci/host/pcie-rcar.c b/drivers/pci/host/pcie-rcar.c index 068bf9067ec1..f65ad226335d 100644 --- a/drivers/pci/host/pcie-rcar.c +++ b/drivers/pci/host/pcie-rcar.c @@ -471,6 +471,32 @@ static void rcar_pcie_force_speedup(struct rcar_pcie *pcie) (macsr & LINK_SPEED) == LINK_SPEED_5_0GTS ? "5" : "2.5"); } +static void rcar_pcie_hw_enable(struct rcar_pcie *pci) +{ + struct resource_entry *win; + LIST_HEAD(res); + int i = 0; + + /* Try setting 5 GT/s link speed */ + rcar_pcie_force_speedup(pci); + + /* Setup PCI resources */ + resource_list_for_each_entry(win, &pci->resources) { + struct resource *res = win->res; + + if (!res->flags) + continue; + + switch (resource_type(res)) { + case IORESOURCE_IO: + case IORESOURCE_MEM: + rcar_pcie_setup_window(i, pci, res); + i++; + break; + } + } +} + static int rcar_pcie_enable(struct rcar_pcie *pcie) { struct device *dev = pcie->dev; @@ -869,11 +895,25 @@ static const struct irq_domain_ops msi_domain_ops = { .map = rcar_msi_map, }; +static void rcar_pcie_hw_enable_msi(struct rcar_pcie *pcie) +{ + struct rcar_msi *msi = &pcie->msi; + unsigned long base; + + /* setup MSI data target */ + base = virt_to_phys((void *)msi->pages); + + rcar_pci_write_reg(pcie, base | MSIFE, PCIEMSIALR); + rcar_pci_write_reg(pcie, 0, PCIEMSIAUR); + + /* enable all MSI interrupts */ + rcar_pci_write_reg(pcie, 0xffffffff, PCIEMSIIER); +} + static int rcar_pcie_enable_msi(struct rcar_pcie *pcie) { struct device *dev = pcie->dev; struct rcar_msi *msi = &pcie->msi; - unsigned long base; int err, i; mutex_init(&msi->lock); @@ -912,13 +952,7 @@ static int rcar_pcie_enable_msi(struct rcar_pcie *pcie) /* setup MSI data target */ msi->pages = __get_free_pages(GFP_KERNEL, 0); - base = virt_to_phys((void *)msi->pages); - - rcar_pci_write_reg(pcie, base | MSIFE, PCIEMSIALR); - rcar_pci_write_reg(pcie, 0, PCIEMSIAUR); - - /* enable all MSI interrupts */ - rcar_pci_write_reg(pcie, 0xffffffff, PCIEMSIIER); + rcar_pcie_hw_enable_msi(pcie); return 0; @@ -1193,6 +1227,37 @@ static int rcar_pcie_probe(struct platform_device *pdev) return err; } +static int rcar_pcie_resume(struct device *dev) +{ + struct rcar_pcie *pcie = dev_get_drvdata(dev); + int (*hw_init_fn)(struct rcar_pcie *); + unsigned int data; + int err; + + err = rcar_pcie_parse_map_dma_ranges(pcie, dev->of_node); + if (err) + return 0; + + /* Failure to get a link might just be that no cards are inserted */ + hw_init_fn = of_device_get_match_data(dev); + err = hw_init_fn(pcie); + if (err) { + dev_info(dev, "PCIe link down\n"); + return 0; + } + + data = rcar_pci_read_reg(pcie, MACSR); + dev_info(dev, "PCIe x%d: link up\n", (data >> 20) & 0x3f); + + /* Enable MSI */ + if (IS_ENABLED(CONFIG_PCI_MSI)) + rcar_pcie_hw_enable_msi(pcie); + + rcar_pcie_hw_enable(pcie); + + return 0; +} + static int rcar_pcie_resume_noirq(struct device *dev) { struct rcar_pcie *pcie = dev_get_drvdata(dev); @@ -1207,6 +1272,7 @@ static int rcar_pcie_resume_noirq(struct device *dev) } static const struct dev_pm_ops rcar_pcie_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(NULL, rcar_pcie_resume) .resume_noirq = rcar_pcie_resume_noirq, };