From patchwork Wed Jun 21 16:26:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 9802231 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 07F26600C5 for ; Wed, 21 Jun 2017 16:27:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ECBBE2862B for ; Wed, 21 Jun 2017 16:27:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E03982862E; Wed, 21 Jun 2017 16:27:07 +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, 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 5F29B2862D for ; Wed, 21 Jun 2017 16:27:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751122AbdFUQ1C (ORCPT ); Wed, 21 Jun 2017 12:27:02 -0400 Received: from mail-lf0-f44.google.com ([209.85.215.44]:32965 "EHLO mail-lf0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751082AbdFUQ1C (ORCPT ); Wed, 21 Jun 2017 12:27:02 -0400 Received: by mail-lf0-f44.google.com with SMTP id m77so100257952lfe.0 for ; Wed, 21 Jun 2017 09:27:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=QJqXkpjepq5BYbD32L4q0PfREyP/HkRoK6kJFKUWpOY=; b=JcV4yHhe9BwLx8d8K7XwOnmmABMUpcnaJw437E7rtibaSOX6yDt5MyO0Q7DJDDUAET vRa8gaqaK9BMXqmj3OpRhmmzzdENZp1U9jMIGRGHWpKRHvoPnT9SKrGpyD4qne5DuSFy N6zIkSv7ob0JYdvjMB1IEvrr+duv4JEpQi50s= 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; bh=QJqXkpjepq5BYbD32L4q0PfREyP/HkRoK6kJFKUWpOY=; b=IMRv3gAzTg067iFiRnaJfBeBK+wyuOIC3NtLZ5ggm2/ac7U/dh29vkH7B7wgmQJrlT O7AUQ1vDBorTE6ko720o/euIJtc7vfbyeznnV2DsLhFmZGxib0wmFp7/zUItI9Jf3ziK w8EEm4ybgnuAWmCnCgqf8GMV4Sb74bTNcMSWZ1u69OwfveVhNTpnGJY1ATkN/4TLierD bLOC/EAHuKWF8TW+bIS2P7cjZ3GeDkm2HtCaJ7n6noF45nNmHqcE23XrVfSphuKZ3vum Z9PAz2PX0redr2E5sjxasYk8/JH4wGLQNvtXxNqASnGiJYcFOQO8Oux+gZB7h/MJrttc 8bNg== X-Gm-Message-State: AKS2vOyTu0wfGtCXG0koIk+mmwgDjLa0x9y2hqOZbl5JY9d5rCLD9Bx+ H0OZRo6GZyjmcAcB X-Received: by 10.46.33.101 with SMTP id h98mr10420904ljh.94.1498062420191; Wed, 21 Jun 2017 09:27:00 -0700 (PDT) Received: from fabina.bredbandsbolaget.se (c-a57471d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.116.165]) by smtp.gmail.com with ESMTPSA id 91sm1525541lfs.31.2017.06.21.09.26.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Jun 2017 09:26:58 -0700 (PDT) From: Linus Walleij To: Bjorn Helgaas , Lorenzo Pieralisi , linux-pci@vger.kernel.org Cc: Hans Ulli Kroll , Florian Fainelli , Linus Walleij Subject: [PATCH] drivers: pci: host: ftpci100: Remove pre-scan bus dependency Date: Wed, 21 Jun 2017 18:26:51 +0200 Message-Id: <20170621162651.25315-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.9.4 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 From: Lorenzo Pieralisi Remove leftover pci_bus dependencies from the probe path. We were digging around in config space before the bus was up so we need to use a few raw accessors and avoid storing things in the bus structure until the host is initialized. Signed-off-by: Lorenzo Pieralisi Tested-by: Linus Walleij Signed-off-by: Linus Walleij --- This patch on top of Lorenzo's patch series make everything work fine for me. --- drivers/pci/host/pci-ftpci100.c | 53 +++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/drivers/pci/host/pci-ftpci100.c b/drivers/pci/host/pci-ftpci100.c index db31ab21884e..5162dffc102b 100644 --- a/drivers/pci/host/pci-ftpci100.c +++ b/drivers/pci/host/pci-ftpci100.c @@ -183,12 +183,11 @@ static int faraday_res_to_memcfg(resource_size_t mem_base, return 0; } -static int faraday_pci_read_config(struct pci_bus *bus, unsigned int fn, - int config, int size, u32 *value) +static int faraday_raw_pci_read_config(struct faraday_pci *p, int bus_number, + unsigned int fn, int config, int size, + u32 *value) { - struct faraday_pci *p = bus->sysdata; - - writel(PCI_CONF_BUS(bus->number) | + writel(PCI_CONF_BUS(bus_number) | PCI_CONF_DEVICE(PCI_SLOT(fn)) | PCI_CONF_FUNCTION(PCI_FUNC(fn)) | PCI_CONF_WHERE(config) | @@ -202,11 +201,19 @@ static int faraday_pci_read_config(struct pci_bus *bus, unsigned int fn, else if (size == 2) *value = (*value >> (8 * (config & 3))) & 0xFFFF; + return PCIBIOS_SUCCESSFUL; +} + +static int faraday_pci_read_config(struct pci_bus *bus, unsigned int fn, + int config, int size, u32 *value) +{ + struct faraday_pci *p = bus->sysdata; + dev_dbg(&bus->dev, "[read] slt: %.2d, fnc: %d, cnf: 0x%.2X, val (%d bytes): 0x%.8X\n", PCI_SLOT(fn), PCI_FUNC(fn), config, size, *value); - return PCIBIOS_SUCCESSFUL; + return faraday_raw_pci_read_config(p, bus->number, fn, config, size, value); } static int faraday_raw_pci_write_config(struct faraday_pci *p, int bus_number, @@ -262,10 +269,10 @@ static void faraday_pci_ack_irq(struct irq_data *d) struct faraday_pci *p = irq_data_get_irq_chip_data(d); unsigned int reg; - faraday_pci_read_config(p->bus, 0, FARADAY_PCI_CTRL2, 4, ®); + faraday_raw_pci_read_config(p, 0, 0, FARADAY_PCI_CTRL2, 4, ®); reg &= ~(0xF << PCI_CTRL2_INTSTS_SHIFT); reg |= BIT(irqd_to_hwirq(d) + PCI_CTRL2_INTSTS_SHIFT); - faraday_pci_write_config(p->bus, 0, FARADAY_PCI_CTRL2, 4, reg); + faraday_raw_pci_write_config(p, 0, 0, FARADAY_PCI_CTRL2, 4, reg); } static void faraday_pci_mask_irq(struct irq_data *d) @@ -273,10 +280,10 @@ static void faraday_pci_mask_irq(struct irq_data *d) struct faraday_pci *p = irq_data_get_irq_chip_data(d); unsigned int reg; - faraday_pci_read_config(p->bus, 0, FARADAY_PCI_CTRL2, 4, ®); + faraday_raw_pci_read_config(p, 0, 0, FARADAY_PCI_CTRL2, 4, ®); reg &= ~((0xF << PCI_CTRL2_INTSTS_SHIFT) | BIT(irqd_to_hwirq(d) + PCI_CTRL2_INTMASK_SHIFT)); - faraday_pci_write_config(p->bus, 0, FARADAY_PCI_CTRL2, 4, reg); + faraday_raw_pci_write_config(p, 0, 0, FARADAY_PCI_CTRL2, 4, reg); } static void faraday_pci_unmask_irq(struct irq_data *d) @@ -284,10 +291,10 @@ static void faraday_pci_unmask_irq(struct irq_data *d) struct faraday_pci *p = irq_data_get_irq_chip_data(d); unsigned int reg; - faraday_pci_read_config(p->bus, 0, FARADAY_PCI_CTRL2, 4, ®); + faraday_raw_pci_read_config(p, 0, 0, FARADAY_PCI_CTRL2, 4, ®); reg &= ~(0xF << PCI_CTRL2_INTSTS_SHIFT); reg |= BIT(irqd_to_hwirq(d) + PCI_CTRL2_INTMASK_SHIFT); - faraday_pci_write_config(p->bus, 0, FARADAY_PCI_CTRL2, 4, reg); + faraday_raw_pci_write_config(p, 0, 0, FARADAY_PCI_CTRL2, 4, reg); } static void faraday_pci_irq_handler(struct irq_desc *desc) @@ -296,7 +303,7 @@ static void faraday_pci_irq_handler(struct irq_desc *desc) struct irq_chip *irqchip = irq_desc_get_chip(desc); unsigned int irq_stat, reg, i; - faraday_pci_read_config(p->bus, 0, FARADAY_PCI_CTRL2, 4, ®); + faraday_raw_pci_read_config(p, 0, 0, FARADAY_PCI_CTRL2, 4, ®); irq_stat = reg >> PCI_CTRL2_INTSTS_SHIFT; chained_irq_enter(irqchip, desc); @@ -417,8 +424,8 @@ static int faraday_pci_parse_map_dma_ranges(struct faraday_pci *p, dev_info(dev, "DMA MEM%d BASE: 0x%016llx -> 0x%016llx config %08x\n", i + 1, range.pci_addr, end, val); if (i <= 2) { - faraday_pci_write_config(p->bus, 0, confreg[i], - 4, val); + faraday_raw_pci_write_config(p, 0, 0, confreg[i], + 4, val); } else { dev_err(dev, "ignore extraneous dma-range %d\n", i); break; @@ -443,6 +450,8 @@ static int faraday_pci_probe(struct platform_device *pdev) struct resource *io; struct pci_host_bridge *host; struct clk *clk; + unsigned char max_bus_speed = PCI_SPEED_33MHz; + unsigned char cur_bus_speed = PCI_SPEED_33MHz; int ret; u32 val; LIST_HEAD(res); @@ -546,27 +555,27 @@ static int faraday_pci_probe(struct platform_device *pdev) unsigned long rate; u32 val; - faraday_pci_read_config(p->bus, 0, - FARADAY_PCI_STATUS_CMD, 4, &val); + faraday_raw_pci_read_config(p, 0, 0, + FARADAY_PCI_STATUS_CMD, 4, &val); rate = clk_get_rate(p->bus_clk); if ((rate == 33000000) && (val & PCI_STATUS_66MHZ_CAPABLE)) { dev_info(dev, "33MHz bus is 66MHz capable\n"); - p->bus->max_bus_speed = PCI_SPEED_66MHz; + max_bus_speed = PCI_SPEED_66MHz; ret = clk_set_rate(p->bus_clk, 66000000); if (ret) dev_err(dev, "failed to set bus clock\n"); } else { dev_info(dev, "33MHz only bus\n"); - p->bus->max_bus_speed = PCI_SPEED_33MHz; + max_bus_speed = PCI_SPEED_33MHz; } /* Bumping the clock may fail so read back the rate */ rate = clk_get_rate(p->bus_clk); if (rate == 33000000) - p->bus->cur_bus_speed = PCI_SPEED_33MHz; + cur_bus_speed = PCI_SPEED_33MHz; if (rate == 66000000) - p->bus->cur_bus_speed = PCI_SPEED_66MHz; + cur_bus_speed = PCI_SPEED_66MHz; } ret = faraday_pci_parse_map_dma_ranges(p, dev->of_node); @@ -580,6 +589,8 @@ static int faraday_pci_probe(struct platform_device *pdev) return ret; } p->bus = host->bus; + p->bus->max_bus_speed = max_bus_speed; + p->bus->cur_bus_speed = cur_bus_speed; pci_bus_assign_resources(p->bus); pci_bus_add_devices(p->bus);