From patchwork Tue Mar 21 13:42:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 9636619 X-Patchwork-Delegate: bhelgaas@google.com 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 D6DA160216 for ; Tue, 21 Mar 2017 13:42:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1E8627C0B for ; Tue, 21 Mar 2017 13:42:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C6ABB27D29; Tue, 21 Mar 2017 13:42:58 +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=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=unavailable 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 768A627C0B for ; Tue, 21 Mar 2017 13:42:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756870AbdCUNmq (ORCPT ); Tue, 21 Mar 2017 09:42:46 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:34011 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757456AbdCUNmK (ORCPT ); Tue, 21 Mar 2017 09:42:10 -0400 Received: by mail-pf0-f196.google.com with SMTP id o126so22017720pfb.1; Tue, 21 Mar 2017 06:42:09 -0700 (PDT) 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=BE62W0Q+6y6xlFPOkd78JHI+VWlckZCCwtEdi5j8rNo=; b=scbx4Kawg4skpqePY/KdgepENUOPkY1Vc0yja4PiN6lQzQ6OI5vmXVHP5BHDPct2PQ sgVIl9zM3Ec5ubVygNTjeRCj/rEu1aJZsMcduvQ/WaDTKLEWk8LQiHHUHTSEIFPix9aE +2c4vnHoQtzjCwy7v2K/QmTBAqAcNxqe0kTr3ZwUjkB//5wZ5K8chTsQUKokgkipwHi0 1yu2EnAI1BA2TzfGWHM5+dNfwNDGRQyzV8wQRjVDkasuBCIhHJCJ6V8kMYf7FNs0Lre2 JOEe1yJlehE7zXNk23F1ozRR6mwSBsvA9nKZ7Ll7y9A3yjipa+Jv43qijSeAKLUBSzSZ pMlg== 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=BE62W0Q+6y6xlFPOkd78JHI+VWlckZCCwtEdi5j8rNo=; b=e3LYtTmzmOb1knZT0bET8L8nsrrTUYUU6xl1FJyjj1GPYJGJ3H87OG4QY4qVXVgYyJ FkGXw5Zu4+fyFCmRego8fVBSZdRo+vIjEaO3XWePyCu547d/OnPN3vu2Brff0vD1vqqR w0h2XOxX4TM2m4I2Q5RpU2EMjInDFjCXrV6PgM2IkzInOaNfkAaU3CzRvlgfqeDTr2xm 3Wr7rWd6GxNRpijlZAC4XcqwnZVBv+XsrH5T8eFAOfYYi4HuH4YxkxrgH3L5BOanSwQq s/w50N5lEK96oe7DMgUUv/hX9GQP0ETPVZr5MD4i16uwygGVnNLOWCrJGPrtHR+y0W7n ShRA== X-Gm-Message-State: AFeK/H0z5Ngm3Xje9ccP5g6SlM/3e9SbnRfOJhNGFvDNmXI23CyV8SI3yYxJFKlM3iQv2A== X-Received: by 10.84.217.149 with SMTP id p21mr26127103pli.18.1490103729065; Tue, 21 Mar 2017 06:42:09 -0700 (PDT) Received: from squirtle.lan (c-73-19-0-61.hsd1.wa.comcast.net. [73.19.0.61]) by smtp.gmail.com with ESMTPSA id x21sm39898761pfa.71.2017.03.21.06.42.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Mar 2017 06:42:08 -0700 (PDT) From: Andrey Smirnov To: linux-pci@vger.kernel.org Cc: Andrey Smirnov , yurovsky@gmail.com, Lucas Stach , Bjorn Helgaas , Fabio Estevam , Dong Aisheng , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 2/4] PCI: imx6: Allow probe deferal by reset GPIO Date: Tue, 21 Mar 2017 06:42:01 -0700 Message-Id: <20170321134203.26325-3-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170321134203.26325-1-andrew.smirnov@gmail.com> References: <20170321134203.26325-1-andrew.smirnov@gmail.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some designs implement reset GPIO via a GPIO expander connected to a peripheral bus. One such example would be i.MX7 Sabre board where said GPIO is provided by SPI shift register connected to a bitbanged SPI bus. In order to support such designs allow reset GPIO request to defer probing of the driver. Cc: yurovsky@gmail.com Cc: Lucas Stach Cc: Bjorn Helgaas Cc: Fabio Estevam Cc: Dong Aisheng Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Andrey Smirnov Reviewed-by: Lucas Stach --- drivers/pci/dwc/pci-imx6.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/drivers/pci/dwc/pci-imx6.c b/drivers/pci/dwc/pci-imx6.c index e0c36d6..64de9bb 100644 --- a/drivers/pci/dwc/pci-imx6.c +++ b/drivers/pci/dwc/pci-imx6.c @@ -595,8 +595,8 @@ static struct dw_pcie_host_ops imx6_pcie_host_ops = { .host_init = imx6_pcie_host_init, }; -static int __init imx6_add_pcie_port(struct imx6_pcie *imx6_pcie, - struct platform_device *pdev) +static int imx6_add_pcie_port(struct imx6_pcie *imx6_pcie, + struct platform_device *pdev) { struct dw_pcie *pci = imx6_pcie->pci; struct pcie_port *pp = &pci->pp; @@ -636,7 +636,7 @@ static const struct dw_pcie_ops dw_pcie_ops = { .link_up = imx6_pcie_link_up, }; -static int __init imx6_pcie_probe(struct platform_device *pdev) +static int imx6_pcie_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct dw_pcie *pci; @@ -660,10 +660,6 @@ static int __init imx6_pcie_probe(struct platform_device *pdev) imx6_pcie->variant = (enum imx6_pcie_variants)of_device_get_match_data(dev); - /* Added for PCI abort handling */ - hook_fault_code(16 + 6, imx6q_pcie_abort_handler, SIGBUS, 0, - "imprecise external abort"); - dbi_base = platform_get_resource(pdev, IORESOURCE_MEM, 0); pci->dbi_base = devm_ioremap_resource(dev, dbi_base); if (IS_ERR(pci->dbi_base)) @@ -683,6 +679,8 @@ static int __init imx6_pcie_probe(struct platform_device *pdev) dev_err(dev, "unable to get reset gpio\n"); return ret; } + } else if (imx6_pcie->reset_gpio == -EPROBE_DEFER) { + return imx6_pcie->reset_gpio; } /* Fetch clocks */ @@ -796,11 +794,22 @@ static struct platform_driver imx6_pcie_driver = { .name = "imx6q-pcie", .of_match_table = imx6_pcie_of_match, }, + .probe = imx6_pcie_probe, .shutdown = imx6_pcie_shutdown, }; static int __init imx6_pcie_init(void) { - return platform_driver_probe(&imx6_pcie_driver, imx6_pcie_probe); + /* + * Since probe() can be deferred we need to make sure that + * hook_fault_code is not called after __init memory is freed + * by kernel and since imx6q_pcie_abort_handler() is a no-op + * we can install the handler here without risking it + * accessing some unitialized driver state + */ + hook_fault_code(16 + 6, imx6q_pcie_abort_handler, SIGBUS, 0, + "imprecise external abort"); + + return platform_driver_register(&imx6_pcie_driver); } device_initcall(imx6_pcie_init);