mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
To: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>,
	Sascha Hauer <s.hauer@pengutronix.de>
Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>,
	barebox@lists.infradead.org
Subject: [PATCH v2 4/5] of: pci: import of_pci_get_devfn()
Date: Mon, 28 Jul 2014 15:26:09 +0200	[thread overview]
Message-ID: <1406553970-18157-5-git-send-email-sebastian.hesselbarth@gmail.com> (raw)
In-Reply-To: <1406553970-18157-1-git-send-email-sebastian.hesselbarth@gmail.com>

Marvell MVEBU PCIe driver requires of_pcie_get_devfn(), import it from
Linux.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
Acked-by: Lucas Stach <l.stach@pengutronix.de>
---
Changelog:
v1->v2:
- none

Cc: barebox@lists.infradead.org
Cc: Antony Pavlov <antonynpavlov@gmail.com>
Cc: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Cc: Lucas Stach <l.stach@pengutronix.de>
Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Cc: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
---
 drivers/of/Kconfig  |  6 ++++++
 drivers/of/Makefile |  1 +
 drivers/of/of_pci.c | 27 +++++++++++++++++++++++++++
 include/of_pci.h    | 17 +++++++++++++++++
 4 files changed, 51 insertions(+)
 create mode 100644 drivers/of/of_pci.c
 create mode 100644 include/of_pci.h

diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index 2b28cf3fb425..81955063d70c 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -27,6 +27,12 @@ config OF_GPIO
 	depends on OFDEVICE
 	def_bool y
 
+config OF_PCI
+	bool
+	depends on PCI
+	help
+	  OpenFirmware PCI bus accessors
+
 config OF_BAREBOX_DRIVERS
 	depends on OFDEVICE
 	depends on ENV_HANDLING
diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index c883e516c834..0dc2f8d63ed0 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -1,6 +1,7 @@
 obj-y += address.o base.o fdt.o platform.o
 obj-$(CONFIG_OFTREE_MEM_GENERIC) += mem_generic.o
 obj-$(CONFIG_OF_GPIO) += of_gpio.o
+obj-$(CONFIG_OF_PCI) += of_pci.o
 obj-y += partition.o
 obj-y += of_net.o
 obj-$(CONFIG_MTD) += of_mtd.o
diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c
new file mode 100644
index 000000000000..2d0fbd2e5f69
--- /dev/null
+++ b/drivers/of/of_pci.c
@@ -0,0 +1,27 @@
+#include <common.h>
+#include <errno.h>
+#include <of.h>
+#include <of_pci.h>
+
+/**
+ * of_pci_get_devfn() - Get device and function numbers for a device node
+ * @np: device node
+ *
+ * Parses a standard 5-cell PCI resource and returns an 8-bit value that can
+ * be passed to the PCI_SLOT() and PCI_FUNC() macros to extract the device
+ * and function numbers respectively. On error a negative error code is
+ * returned.
+ */
+int of_pci_get_devfn(struct device_node *np)
+{
+	unsigned int size;
+	const __be32 *reg;
+
+	reg = of_get_property(np, "reg", &size);
+
+	if (!reg || size < 5 * sizeof(__be32))
+		return -EINVAL;
+
+	return (be32_to_cpup(reg) >> 8) & 0xff;
+}
+EXPORT_SYMBOL_GPL(of_pci_get_devfn);
diff --git a/include/of_pci.h b/include/of_pci.h
new file mode 100644
index 000000000000..c95cb0135ae0
--- /dev/null
+++ b/include/of_pci.h
@@ -0,0 +1,17 @@
+#ifndef __OF_PCI_H
+#define __OF_PCI_H
+
+#include <linux/pci.h>
+
+#ifdef CONFIG_OF_PCI
+int of_pci_get_devfn(struct device_node *np);
+
+#else
+static inline int of_pci_get_devfn(struct device_node *np)
+{
+	return -EINVAL;
+}
+
+#endif
+
+#endif
-- 
2.0.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2014-07-28 13:26 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-23  9:26 [PATCH RESEND 0/6] Marvell EBU PCIe driver Sebastian Hesselbarth
2014-07-23  9:26 ` [PATCH RESEND 1/6] bus: mvebu: fix resource size handling Sebastian Hesselbarth
2014-07-23  9:26 ` [PATCH RESEND 2/6] pci: pci_scan_bus: respect 64b BARs Sebastian Hesselbarth
2014-07-25  8:51   ` Lucas Stach
2014-07-25 14:43     ` Sebastian Hesselbarth
2014-07-23  9:26 ` [PATCH RESEND 3/6] pci: add host controller struct to sysdata Sebastian Hesselbarth
2014-07-25  9:07   ` Lucas Stach
2014-07-25 14:54     ` Sebastian Hesselbarth
2014-07-23  9:26 ` [PATCH RESEND 4/6] pci: allow to set bus number on register_pci_controller Sebastian Hesselbarth
2014-07-23  9:26 ` [PATCH RESEND 5/6] of: pci: import of_pci_get_devfn() Sebastian Hesselbarth
2014-07-23  9:26 ` [PATCH RESEND 6/6] pci: mvebu: Add PCIe driver Sebastian Hesselbarth
2014-07-23 10:35   ` Sebastian Hesselbarth
2014-07-25  7:27   ` Sascha Hauer
2014-07-25 15:00     ` Sebastian Hesselbarth
2014-07-28  5:19       ` Sascha Hauer
2014-07-28  6:10         ` Sebastian Hesselbarth
2014-07-25  9:16   ` Lucas Stach
2014-07-25 14:57     ` Sebastian Hesselbarth
2014-07-28 13:26 ` [PATCH v2 0/5] Marvell EBU " Sebastian Hesselbarth
2014-07-28 13:26   ` [PATCH v2 1/5] bus: mvebu: fix resource size handling Sebastian Hesselbarth
2014-07-28 13:26   ` [PATCH v2 2/5] pci: pci_scan_bus: respect 64b BARs Sebastian Hesselbarth
2014-07-28 13:26   ` [PATCH v2 3/5] pci: set auto-incremented bus number Sebastian Hesselbarth
2014-07-28 13:26   ` Sebastian Hesselbarth [this message]
2014-07-28 13:26   ` [PATCH v2 5/5] pci: mvebu: Add PCIe driver Sebastian Hesselbarth
2014-07-29 19:58   ` [PATCH v2 0/5] Marvell EBU " Sebastian Hesselbarth
2014-07-30  6:21     ` Sascha Hauer

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=1406553970-18157-5-git-send-email-sebastian.hesselbarth@gmail.com \
    --to=sebastian.hesselbarth@gmail.com \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox