9
0
Fork 0

of: pci: import of_pci_get_devfn()

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>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Sebastian Hesselbarth 2014-07-30 10:39:39 +02:00 committed by Sascha Hauer
parent 916ca9472f
commit 846da3d7df
4 changed files with 51 additions and 0 deletions

View File

@ -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

View File

@ -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

27
drivers/of/of_pci.c Normal file
View File

@ -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);

17
include/of_pci.h Normal file
View File

@ -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