All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
To: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
Cc: Russell King <linux@arm.linux.org.uk>,
	Jason Cooper <jason@lakedaemon.net>, Andrew Lunn <andrew@lunn.ch>,
	Bjorn Helgaas <bhelgaas@google.com>,
	Thomas Petazzoni <thomas.petazzoni@free-electrons.com>,
	devicetree@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org
Subject: [PATCH 4/9] PCI: mvebu: add support for reset on GPIO
Date: Mon, 12 Aug 2013 20:46:50 +0200	[thread overview]
Message-ID: <1376333215-12885-5-git-send-email-sebastian.hesselbarth@gmail.com> (raw)
In-Reply-To: <1376333215-12885-1-git-send-email-sebastian.hesselbarth@gmail.com>

This patch adds a check for DT passed reset-gpios property and deasserts/
asserts reset pin on probe/remove with configurable delay. Corresponding
binding documentation is also updated.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Jason Cooper <jason@lakedaemon.net>
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Cc: devicetree@vger.kernel.org
Cc: linux-doc@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-pci@vger.kernel.org
---
 .../devicetree/bindings/pci/mvebu-pci.txt          |    2 ++
 drivers/pci/host/pci-mvebu.c                       |   33 +++++++++++++++++++-
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/pci/mvebu-pci.txt b/Documentation/devicetree/bindings/pci/mvebu-pci.txt
index 638673a..f2fa261 100644
--- a/Documentation/devicetree/bindings/pci/mvebu-pci.txt
+++ b/Documentation/devicetree/bindings/pci/mvebu-pci.txt
@@ -76,6 +76,8 @@ and the following optional properties:
 - marvell,pcie-lane: the physical PCIe lane number, for ports having
   multiple lanes. If this property is not found, we assume that the
   value is 0.
+- reset-gpios: optional gpio to PERST#
+- reset-delay-ms: delay in ms to wait after reset de-assertion
 
 Example:
 
diff --git a/drivers/pci/host/pci-mvebu.c b/drivers/pci/host/pci-mvebu.c
index 2370b59..bdad4d4 100644
--- a/drivers/pci/host/pci-mvebu.c
+++ b/drivers/pci/host/pci-mvebu.c
@@ -9,14 +9,17 @@
 #include <linux/kernel.h>
 #include <linux/pci.h>
 #include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/gpio.h>
 #include <linux/module.h>
 #include <linux/mbus.h>
 #include <linux/msi.h>
 #include <linux/slab.h>
 #include <linux/platform_device.h>
 #include <linux/of_address.h>
-#include <linux/of_pci.h>
 #include <linux/of_irq.h>
+#include <linux/of_gpio.h>
+#include <linux/of_pci.h>
 #include <linux/of_platform.h>
 
 /*
@@ -126,6 +129,9 @@ struct mvebu_pcie_port {
 	unsigned int io_target;
 	unsigned int io_attr;
 	struct clk *clk;
+	int reset_gpio;
+	int reset_active_low;
+	char *reset_name;
 	struct mvebu_sw_pci_bridge bridge;
 	struct device_node *dn;
 	struct mvebu_pcie *pcie;
@@ -856,6 +862,7 @@ static int mvebu_pcie_probe(struct platform_device *pdev)
 
 	for_each_child_of_node(pdev->dev.of_node, child) {
 		struct mvebu_pcie_port *port = &pcie->ports[pcie->nports];
+		enum of_gpio_flags flags;
 
 		if (!of_device_is_available(child))
 			continue;
@@ -896,6 +903,25 @@ static int mvebu_pcie_probe(struct platform_device *pdev)
 			continue;
 		}
 
+		port->reset_gpio = of_get_named_gpio_flags(child,
+						   "reset-gpios", 0, &flags);
+		if (gpio_is_valid(port->reset_gpio)) {
+			u32 reset_mdelay = 20;
+			port->reset_active_low = flags & OF_GPIO_ACTIVE_LOW;
+			port->reset_name = kasprintf(GFP_KERNEL,
+				     "pcie%d.%d-reset", port->port, port->lane);
+			ret = devm_gpio_request_one(&pdev->dev,
+			    port->reset_gpio, GPIOF_DIR_OUT, port->reset_name);
+			if (ret)
+				return ret;
+			gpio_set_value(port->reset_gpio,
+				       (port->reset_active_low) ? 1 : 0);
+
+			of_property_read_u32(child, "reset-delay-ms",
+					     &reset_mdelay);
+			mdelay(reset_mdelay);
+		}
+
 		port->clk = of_clk_get_by_name(child, NULL);
 		if (IS_ERR(port->clk)) {
 			dev_err(&pdev->dev, "PCIe%d.%d: cannot get clock\n",
@@ -945,6 +971,11 @@ static int mvebu_pcie_remove(struct platform_device *pdev)
 	int i;
 
 	for (i = 0; i < pcie->nports; i++, port++) {
+		if (gpio_is_valid(port->reset_gpio)) {
+			gpio_set_value(port->reset_gpio,
+			       (port->reset_active_low) ? 0 : 1);
+			kfree(port->reset_name);
+		}
 		clk_disable_unprepare(port->clk);
 		kfree(port->name);
 	}
-- 
1.7.10.4


WARNING: multiple messages have this Message-ID (diff)
From: sebastian.hesselbarth@gmail.com (Sebastian Hesselbarth)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 4/9] PCI: mvebu: add support for reset on GPIO
Date: Mon, 12 Aug 2013 20:46:50 +0200	[thread overview]
Message-ID: <1376333215-12885-5-git-send-email-sebastian.hesselbarth@gmail.com> (raw)
In-Reply-To: <1376333215-12885-1-git-send-email-sebastian.hesselbarth@gmail.com>

This patch adds a check for DT passed reset-gpios property and deasserts/
asserts reset pin on probe/remove with configurable delay. Corresponding
binding documentation is also updated.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Jason Cooper <jason@lakedaemon.net>
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Cc: devicetree at vger.kernel.org
Cc: linux-doc at vger.kernel.org
Cc: linux-kernel at vger.kernel.org
Cc: linux-arm-kernel at lists.infradead.org
Cc: linux-pci at vger.kernel.org
---
 .../devicetree/bindings/pci/mvebu-pci.txt          |    2 ++
 drivers/pci/host/pci-mvebu.c                       |   33 +++++++++++++++++++-
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/pci/mvebu-pci.txt b/Documentation/devicetree/bindings/pci/mvebu-pci.txt
index 638673a..f2fa261 100644
--- a/Documentation/devicetree/bindings/pci/mvebu-pci.txt
+++ b/Documentation/devicetree/bindings/pci/mvebu-pci.txt
@@ -76,6 +76,8 @@ and the following optional properties:
 - marvell,pcie-lane: the physical PCIe lane number, for ports having
   multiple lanes. If this property is not found, we assume that the
   value is 0.
+- reset-gpios: optional gpio to PERST#
+- reset-delay-ms: delay in ms to wait after reset de-assertion
 
 Example:
 
diff --git a/drivers/pci/host/pci-mvebu.c b/drivers/pci/host/pci-mvebu.c
index 2370b59..bdad4d4 100644
--- a/drivers/pci/host/pci-mvebu.c
+++ b/drivers/pci/host/pci-mvebu.c
@@ -9,14 +9,17 @@
 #include <linux/kernel.h>
 #include <linux/pci.h>
 #include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/gpio.h>
 #include <linux/module.h>
 #include <linux/mbus.h>
 #include <linux/msi.h>
 #include <linux/slab.h>
 #include <linux/platform_device.h>
 #include <linux/of_address.h>
-#include <linux/of_pci.h>
 #include <linux/of_irq.h>
+#include <linux/of_gpio.h>
+#include <linux/of_pci.h>
 #include <linux/of_platform.h>
 
 /*
@@ -126,6 +129,9 @@ struct mvebu_pcie_port {
 	unsigned int io_target;
 	unsigned int io_attr;
 	struct clk *clk;
+	int reset_gpio;
+	int reset_active_low;
+	char *reset_name;
 	struct mvebu_sw_pci_bridge bridge;
 	struct device_node *dn;
 	struct mvebu_pcie *pcie;
@@ -856,6 +862,7 @@ static int mvebu_pcie_probe(struct platform_device *pdev)
 
 	for_each_child_of_node(pdev->dev.of_node, child) {
 		struct mvebu_pcie_port *port = &pcie->ports[pcie->nports];
+		enum of_gpio_flags flags;
 
 		if (!of_device_is_available(child))
 			continue;
@@ -896,6 +903,25 @@ static int mvebu_pcie_probe(struct platform_device *pdev)
 			continue;
 		}
 
+		port->reset_gpio = of_get_named_gpio_flags(child,
+						   "reset-gpios", 0, &flags);
+		if (gpio_is_valid(port->reset_gpio)) {
+			u32 reset_mdelay = 20;
+			port->reset_active_low = flags & OF_GPIO_ACTIVE_LOW;
+			port->reset_name = kasprintf(GFP_KERNEL,
+				     "pcie%d.%d-reset", port->port, port->lane);
+			ret = devm_gpio_request_one(&pdev->dev,
+			    port->reset_gpio, GPIOF_DIR_OUT, port->reset_name);
+			if (ret)
+				return ret;
+			gpio_set_value(port->reset_gpio,
+				       (port->reset_active_low) ? 1 : 0);
+
+			of_property_read_u32(child, "reset-delay-ms",
+					     &reset_mdelay);
+			mdelay(reset_mdelay);
+		}
+
 		port->clk = of_clk_get_by_name(child, NULL);
 		if (IS_ERR(port->clk)) {
 			dev_err(&pdev->dev, "PCIe%d.%d: cannot get clock\n",
@@ -945,6 +971,11 @@ static int mvebu_pcie_remove(struct platform_device *pdev)
 	int i;
 
 	for (i = 0; i < pcie->nports; i++, port++) {
+		if (gpio_is_valid(port->reset_gpio)) {
+			gpio_set_value(port->reset_gpio,
+			       (port->reset_active_low) ? 0 : 1);
+			kfree(port->reset_name);
+		}
 		clk_disable_unprepare(port->clk);
 		kfree(port->name);
 	}
-- 
1.7.10.4

  parent reply	other threads:[~2013-08-12 18:49 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-12 18:46 [PATCH 0/9] ARM: dove: DT PCIe support Sebastian Hesselbarth
2013-08-12 18:46 ` Sebastian Hesselbarth
2013-08-12 18:46 ` [PATCH 1/9] PCI: mvebu: move clock enable before register access Sebastian Hesselbarth
2013-08-12 18:46   ` Sebastian Hesselbarth
2013-08-13  7:11   ` Thomas Petazzoni
2013-08-13  7:11     ` Thomas Petazzoni
2013-08-13  9:22     ` Sebastian Hesselbarth
2013-08-13  9:22       ` Sebastian Hesselbarth
2013-08-13  7:58   ` Thierry Reding
2013-08-13  7:58     ` Thierry Reding
2013-08-12 18:46 ` [PATCH 2/9] PCI: mvebu: increment nports only for registered ports Sebastian Hesselbarth
2013-08-12 18:46   ` Sebastian Hesselbarth
2013-08-13  7:15   ` Thomas Petazzoni
2013-08-13  7:15     ` Thomas Petazzoni
2013-08-13  9:23     ` Sebastian Hesselbarth
2013-08-13  9:23       ` Sebastian Hesselbarth
2013-08-12 18:46 ` [PATCH 3/9] PCI: mvebu: remove subsys_initcall Sebastian Hesselbarth
2013-08-12 18:46   ` Sebastian Hesselbarth
2013-08-13  7:19   ` Thomas Petazzoni
2013-08-13  7:19     ` Thomas Petazzoni
2013-08-13  8:06     ` Thierry Reding
2013-08-13  8:06       ` Thierry Reding
2013-08-13  9:25       ` Sebastian Hesselbarth
2013-08-13  9:25         ` Sebastian Hesselbarth
2013-08-12 18:46 ` Sebastian Hesselbarth [this message]
2013-08-12 18:46   ` [PATCH 4/9] PCI: mvebu: add support for reset on GPIO Sebastian Hesselbarth
2013-08-13  0:56   ` Kumar Gala
2013-08-13  0:56     ` Kumar Gala
2013-08-13  9:19     ` Sebastian Hesselbarth
2013-08-13  9:19       ` Sebastian Hesselbarth
2013-08-13  8:09   ` Thierry Reding
2013-08-13  8:09     ` Thierry Reding
2013-08-13  8:30     ` Thomas Petazzoni
2013-08-13  8:30       ` Thomas Petazzoni
2013-08-13  9:59       ` Sascha Hauer
2013-08-13  9:59         ` Sascha Hauer
2013-08-13 10:03       ` Thierry Reding
2013-08-13 10:03         ` Thierry Reding
2013-08-13 10:40         ` Sebastian Hesselbarth
2013-08-13 10:40           ` Sebastian Hesselbarth
2013-08-13 10:59           ` Philipp Zabel
2013-08-13 10:59             ` Philipp Zabel
2013-08-12 18:46 ` [PATCH 5/9] PCI: mvebu: add support for Marvell Dove SoCs Sebastian Hesselbarth
2013-08-12 18:46   ` Sebastian Hesselbarth
2013-08-12 18:46 ` [PATCH 6/9] ARM: dove: update dove_defconfig with SI5351, PCI, and xHCI Sebastian Hesselbarth
2013-08-12 18:46   ` Sebastian Hesselbarth
2013-08-12 20:00   ` Jason Cooper
2013-08-12 20:00     ` Jason Cooper
2013-08-12 18:46 ` [PATCH 7/9] ARM: dove: add PCIe controllers to SoC DT Sebastian Hesselbarth
2013-08-12 18:46   ` Sebastian Hesselbarth
2013-08-12 20:04   ` Jason Cooper
2013-08-12 20:04     ` Jason Cooper
2013-08-13 11:28     ` Sebastian Hesselbarth
2013-08-13 11:28       ` Sebastian Hesselbarth
2013-08-13 13:21       ` Jason Cooper
2013-08-13 13:21         ` Jason Cooper
2013-08-13 13:48       ` Jason Cooper
2013-08-13 13:48         ` Jason Cooper
2013-08-12 18:46 ` [PATCH 8/9] ARM: dove: add initial DT file for Globalscale D3Plug Sebastian Hesselbarth
2013-08-12 18:46   ` Sebastian Hesselbarth
2013-08-12 18:46 ` [PATCH 9/9] ARM: dove: remove legacy pcie and clock init Sebastian Hesselbarth
2013-08-12 18:46   ` Sebastian Hesselbarth
2013-08-12 20:54 ` [PATCH 0/9] ARM: dove: DT PCIe support Bjorn Helgaas
2013-08-12 20:54   ` Bjorn Helgaas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1376333215-12885-5-git-send-email-sebastian.hesselbarth@gmail.com \
    --to=sebastian.hesselbarth@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=bhelgaas@google.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jason@lakedaemon.net \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=thomas.petazzoni@free-electrons.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.