2009-03-27 14:25:12 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp.
|
|
|
|
|
* <benh@kernel.crashing.org>
|
|
|
|
|
* and Arnd Bergmann, IBM Corp.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#undef DEBUG
|
|
|
|
|
|
|
|
|
|
#include <linux/string.h>
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
|
#include <linux/mod_devicetable.h>
|
|
|
|
|
#include <linux/pci.h>
|
|
|
|
|
#include <linux/of.h>
|
|
|
|
|
#include <linux/of_device.h>
|
|
|
|
|
#include <linux/of_platform.h>
|
|
|
|
|
|
|
|
|
|
#include <linux/errno.h>
|
|
|
|
|
#include <linux/topology.h>
|
|
|
|
|
#include <asm/atomic.h>
|
|
|
|
|
|
|
|
|
|
struct bus_type of_platform_bus_type = {
|
|
|
|
|
.uevent = of_device_uevent,
|
|
|
|
|
};
|
|
|
|
|
EXPORT_SYMBOL(of_platform_bus_type);
|
|
|
|
|
|
|
|
|
|
static int __init of_bus_driver_init(void)
|
|
|
|
|
{
|
|
|
|
|
return of_bus_type_init(&of_platform_bus_type, "of_platform");
|
|
|
|
|
}
|
|
|
|
|
postcore_initcall(of_bus_driver_init);
|
|
|
|
|
|
2010-06-08 07:48:13 -06:00
|
|
|
/*
|
|
|
|
|
* The list of OF IDs below is used for matching bus types in the
|
|
|
|
|
* system whose devices are to be exposed as of_platform_devices.
|
2009-03-27 14:25:12 +01:00
|
|
|
*
|
2010-06-08 07:48:13 -06:00
|
|
|
* This is the default list valid for most platforms. This file provides
|
|
|
|
|
* functions who can take an explicit list if necessary though
|
|
|
|
|
*
|
|
|
|
|
* The search is always performed recursively looking for children of
|
|
|
|
|
* the provided device_node and recursively if such a children matches
|
|
|
|
|
* a bus type in the list
|
2009-03-27 14:25:12 +01:00
|
|
|
*/
|
|
|
|
|
|
2010-06-08 07:48:13 -06:00
|
|
|
const struct of_device_id of_default_bus_ids[] = {
|
|
|
|
|
{ .type = "soc", },
|
|
|
|
|
{ .compatible = "soc", },
|
|
|
|
|
{ .type = "plb5", },
|
|
|
|
|
{ .type = "plb4", },
|
|
|
|
|
{ .type = "opb", },
|
|
|
|
|
{ .type = "simple", },
|
|
|
|
|
{},
|
|
|
|
|
};
|
2009-03-27 14:25:12 +01:00
|
|
|
|
|
|
|
|
static int of_dev_node_match(struct device *dev, void *data)
|
|
|
|
|
{
|
2010-04-13 16:12:29 -07:00
|
|
|
return to_of_device(dev)->dev.of_node == data;
|
2009-03-27 14:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct of_device *of_find_device_by_node(struct device_node *np)
|
|
|
|
|
{
|
|
|
|
|
struct device *dev;
|
|
|
|
|
|
|
|
|
|
dev = bus_find_device(&of_platform_bus_type,
|
|
|
|
|
NULL, np, of_dev_node_match);
|
|
|
|
|
if (dev)
|
|
|
|
|
return to_of_device(dev);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
EXPORT_SYMBOL(of_find_device_by_node);
|
|
|
|
|
|
|
|
|
|
static int of_dev_phandle_match(struct device *dev, void *data)
|
|
|
|
|
{
|
|
|
|
|
phandle *ph = data;
|
2010-04-13 16:12:29 -07:00
|
|
|
return to_of_device(dev)->dev.of_node->phandle == *ph;
|
2009-03-27 14:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct of_device *of_find_device_by_phandle(phandle ph)
|
|
|
|
|
{
|
|
|
|
|
struct device *dev;
|
|
|
|
|
|
|
|
|
|
dev = bus_find_device(&of_platform_bus_type,
|
|
|
|
|
NULL, &ph, of_dev_phandle_match);
|
|
|
|
|
if (dev)
|
|
|
|
|
return to_of_device(dev);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
EXPORT_SYMBOL(of_find_device_by_phandle);
|