Skip to content

Commit

Permalink
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/gi…
Browse files Browse the repository at this point in the history
…t/sfr/ofcons

* 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/sfr/ofcons:
  Create drivers/of/platform.c
  Create linux/of_platorm.h
  [SPARC/64] Rename some functions like PowerPC
  Begin consolidation of of_device.h
  Begin to consolidate of_device.c
  Consolidate of_find_node_by routines
  Consolidate of_get_next_child
  Consolidate of_get_parent
  Consolidate of_find_property
  Consolidate of_device_is_compatible
  Start split out of common open firmware code
  Split out common parts of prom.h
  • Loading branch information
Linus Torvalds committed Jul 20, 2007
2 parents d638d49 + 3f23de1 commit 2cb7e71
Show file tree
Hide file tree
Showing 33 changed files with 846 additions and 1,483 deletions.
3 changes: 3 additions & 0 deletions arch/powerpc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ config ARCH_MAY_HAVE_PC_FDC
config PPC_OF
def_bool y

config OF
def_bool y

config PPC_UDBG_16550
bool
default n
Expand Down
122 changes: 1 addition & 121 deletions arch/powerpc/kernel/of_device.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <linux/string.h>
#include <linux/kernel.h>
#include <linux/of.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/mod_devicetable.h>
Expand All @@ -8,118 +9,6 @@
#include <asm/errno.h>
#include <asm/of_device.h>

/**
* of_match_node - Tell if an device_node has a matching of_match structure
* @ids: array of of device match structures to search in
* @node: the of device structure to match against
*
* Low level utility function used by device matching.
*/
const struct of_device_id *of_match_node(const struct of_device_id *matches,
const struct device_node *node)
{
while (matches->name[0] || matches->type[0] || matches->compatible[0]) {
int match = 1;
if (matches->name[0])
match &= node->name
&& !strcmp(matches->name, node->name);
if (matches->type[0])
match &= node->type
&& !strcmp(matches->type, node->type);
if (matches->compatible[0])
match &= of_device_is_compatible(node,
matches->compatible);
if (match)
return matches;
matches++;
}
return NULL;
}

/**
* of_match_device - Tell if an of_device structure has a matching
* of_match structure
* @ids: array of of device match structures to search in
* @dev: the of device structure to match against
*
* Used by a driver to check whether an of_device present in the
* system is in its list of supported devices.
*/
const struct of_device_id *of_match_device(const struct of_device_id *matches,
const struct of_device *dev)
{
if (!dev->node)
return NULL;
return of_match_node(matches, dev->node);
}

struct of_device *of_dev_get(struct of_device *dev)
{
struct device *tmp;

if (!dev)
return NULL;
tmp = get_device(&dev->dev);
if (tmp)
return to_of_device(tmp);
else
return NULL;
}

void of_dev_put(struct of_device *dev)
{
if (dev)
put_device(&dev->dev);
}

static ssize_t dev_show_devspec(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct of_device *ofdev;

ofdev = to_of_device(dev);
return sprintf(buf, "%s", ofdev->node->full_name);
}

static DEVICE_ATTR(devspec, S_IRUGO, dev_show_devspec, NULL);

/**
* of_release_dev - free an of device structure when all users of it are finished.
* @dev: device that's been disconnected
*
* Will be called only by the device core when all users of this of device are
* done.
*/
void of_release_dev(struct device *dev)
{
struct of_device *ofdev;

ofdev = to_of_device(dev);
of_node_put(ofdev->node);
kfree(ofdev);
}

int of_device_register(struct of_device *ofdev)
{
int rc;

BUG_ON(ofdev->node == NULL);

rc = device_register(&ofdev->dev);
if (rc)
return rc;

return device_create_file(&ofdev->dev, &dev_attr_devspec);
}

void of_device_unregister(struct of_device *ofdev)
{
device_remove_file(&ofdev->dev, &dev_attr_devspec);

device_unregister(&ofdev->dev);
}


ssize_t of_device_get_modalias(struct of_device *ofdev,
char *str, ssize_t len)
{
Expand Down Expand Up @@ -229,14 +118,5 @@ int of_device_uevent(struct device *dev,

return 0;
}


EXPORT_SYMBOL(of_match_node);
EXPORT_SYMBOL(of_match_device);
EXPORT_SYMBOL(of_device_register);
EXPORT_SYMBOL(of_device_unregister);
EXPORT_SYMBOL(of_dev_get);
EXPORT_SYMBOL(of_dev_put);
EXPORT_SYMBOL(of_release_dev);
EXPORT_SYMBOL(of_device_uevent);
EXPORT_SYMBOL(of_device_get_modalias);
82 changes: 1 addition & 81 deletions arch/powerpc/kernel/of_platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,94 +55,14 @@ static struct of_device_id of_default_bus_ids[] = {

static atomic_t bus_no_reg_magic;

/*
*
* OF platform device type definition & base infrastructure
*
*/

static int of_platform_bus_match(struct device *dev, struct device_driver *drv)
{
struct of_device * of_dev = to_of_device(dev);
struct of_platform_driver * of_drv = to_of_platform_driver(drv);
const struct of_device_id * matches = of_drv->match_table;

if (!matches)
return 0;

return of_match_device(matches, of_dev) != NULL;
}

static int of_platform_device_probe(struct device *dev)
{
int error = -ENODEV;
struct of_platform_driver *drv;
struct of_device *of_dev;
const struct of_device_id *match;

drv = to_of_platform_driver(dev->driver);
of_dev = to_of_device(dev);

if (!drv->probe)
return error;

of_dev_get(of_dev);

match = of_match_device(drv->match_table, of_dev);
if (match)
error = drv->probe(of_dev, match);
if (error)
of_dev_put(of_dev);

return error;
}

static int of_platform_device_remove(struct device *dev)
{
struct of_device * of_dev = to_of_device(dev);
struct of_platform_driver * drv = to_of_platform_driver(dev->driver);

if (dev->driver && drv->remove)
drv->remove(of_dev);
return 0;
}

static int of_platform_device_suspend(struct device *dev, pm_message_t state)
{
struct of_device * of_dev = to_of_device(dev);
struct of_platform_driver * drv = to_of_platform_driver(dev->driver);
int error = 0;

if (dev->driver && drv->suspend)
error = drv->suspend(of_dev, state);
return error;
}

static int of_platform_device_resume(struct device * dev)
{
struct of_device * of_dev = to_of_device(dev);
struct of_platform_driver * drv = to_of_platform_driver(dev->driver);
int error = 0;

if (dev->driver && drv->resume)
error = drv->resume(of_dev);
return error;
}

struct bus_type of_platform_bus_type = {
.name = "of_platform",
.match = of_platform_bus_match,
.uevent = of_device_uevent,
.probe = of_platform_device_probe,
.remove = of_platform_device_remove,
.suspend = of_platform_device_suspend,
.resume = of_platform_device_resume,
};
EXPORT_SYMBOL(of_platform_bus_type);

static int __init of_bus_driver_init(void)
{
return bus_register(&of_platform_bus_type);
return of_bus_type_init(&of_platform_bus_type, "of_platform");
}

postcore_initcall(of_bus_driver_init);
Expand Down
Loading

0 comments on commit 2cb7e71

Please sign in to comment.