mirror of
https://xff.cz/git/u-boot/
synced 2025-09-29 22:41:17 +02:00
dm: core: Add a way to find a device by ofnode
Add a function which looks up a device by its node (either in live tree or flat tree). Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <common.h>
|
#include <common.h>
|
||||||
|
#include <dm.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <dm/device.h>
|
#include <dm/device.h>
|
||||||
@@ -287,6 +288,30 @@ int uclass_find_device_by_of_offset(enum uclass_id id, int node,
|
|||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int uclass_find_device_by_ofnode(enum uclass_id id, ofnode node,
|
||||||
|
struct udevice **devp)
|
||||||
|
{
|
||||||
|
struct uclass *uc;
|
||||||
|
struct udevice *dev;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
*devp = NULL;
|
||||||
|
if (!ofnode_valid(node))
|
||||||
|
return -ENODEV;
|
||||||
|
ret = uclass_get(id, &uc);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
list_for_each_entry(dev, &uc->dev_head, uclass_node) {
|
||||||
|
if (ofnode_equal(dev_ofnode(dev), node)) {
|
||||||
|
*devp = dev;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
#if CONFIG_IS_ENABLED(OF_CONTROL)
|
#if CONFIG_IS_ENABLED(OF_CONTROL)
|
||||||
static int uclass_find_device_by_phandle(enum uclass_id id,
|
static int uclass_find_device_by_phandle(enum uclass_id id,
|
||||||
struct udevice *parent,
|
struct udevice *parent,
|
||||||
@@ -407,6 +432,18 @@ int uclass_get_device_by_of_offset(enum uclass_id id, int node,
|
|||||||
return uclass_get_device_tail(dev, ret, devp);
|
return uclass_get_device_tail(dev, ret, devp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int uclass_get_device_by_ofnode(enum uclass_id id, ofnode node,
|
||||||
|
struct udevice **devp)
|
||||||
|
{
|
||||||
|
struct udevice *dev;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
*devp = NULL;
|
||||||
|
ret = uclass_find_device_by_ofnode(id, node, &dev);
|
||||||
|
|
||||||
|
return uclass_get_device_tail(dev, ret, devp);
|
||||||
|
}
|
||||||
|
|
||||||
#if CONFIG_IS_ENABLED(OF_CONTROL)
|
#if CONFIG_IS_ENABLED(OF_CONTROL)
|
||||||
int uclass_get_device_by_phandle(enum uclass_id id, struct udevice *parent,
|
int uclass_get_device_by_phandle(enum uclass_id id, struct udevice *parent,
|
||||||
const char *name, struct udevice **devp)
|
const char *name, struct udevice **devp)
|
||||||
|
@@ -10,6 +10,8 @@
|
|||||||
#ifndef _DM_UCLASS_INTERNAL_H
|
#ifndef _DM_UCLASS_INTERNAL_H
|
||||||
#define _DM_UCLASS_INTERNAL_H
|
#define _DM_UCLASS_INTERNAL_H
|
||||||
|
|
||||||
|
#include <dm/ofnode.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* uclass_get_device_tail() - handle the end of a get_device call
|
* uclass_get_device_tail() - handle the end of a get_device call
|
||||||
*
|
*
|
||||||
@@ -114,6 +116,22 @@ int uclass_find_device_by_seq(enum uclass_id id, int seq_or_req_seq,
|
|||||||
int uclass_find_device_by_of_offset(enum uclass_id id, int node,
|
int uclass_find_device_by_of_offset(enum uclass_id id, int node,
|
||||||
struct udevice **devp);
|
struct udevice **devp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* uclass_find_device_by_of_node() - Find a uclass device by device tree node
|
||||||
|
*
|
||||||
|
* This searches the devices in the uclass for one attached to the given
|
||||||
|
* device tree node.
|
||||||
|
*
|
||||||
|
* The device is NOT probed, it is merely returned.
|
||||||
|
*
|
||||||
|
* @id: ID to look up
|
||||||
|
* @node: Device tree offset to search for (if NULL then -ENODEV is returned)
|
||||||
|
* @devp: Returns pointer to device (there is only one for each node)
|
||||||
|
* @return 0 if OK, -ve on error
|
||||||
|
*/
|
||||||
|
int uclass_find_device_by_ofnode(enum uclass_id id, ofnode node,
|
||||||
|
struct udevice **devp);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* uclass_bind_device() - Associate device with a uclass
|
* uclass_bind_device() - Associate device with a uclass
|
||||||
*
|
*
|
||||||
|
@@ -10,6 +10,7 @@
|
|||||||
#ifndef _DM_UCLASS_H
|
#ifndef _DM_UCLASS_H
|
||||||
#define _DM_UCLASS_H
|
#define _DM_UCLASS_H
|
||||||
|
|
||||||
|
#include <dm/ofnode.h>
|
||||||
#include <dm/uclass-id.h>
|
#include <dm/uclass-id.h>
|
||||||
#include <linker_lists.h>
|
#include <linker_lists.h>
|
||||||
#include <linux/list.h>
|
#include <linux/list.h>
|
||||||
@@ -185,6 +186,22 @@ int uclass_get_device_by_seq(enum uclass_id id, int seq, struct udevice **devp);
|
|||||||
int uclass_get_device_by_of_offset(enum uclass_id id, int node,
|
int uclass_get_device_by_of_offset(enum uclass_id id, int node,
|
||||||
struct udevice **devp);
|
struct udevice **devp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* uclass_get_device_by_ofnode() - Get a uclass device by device tree node
|
||||||
|
*
|
||||||
|
* This searches the devices in the uclass for one attached to the given
|
||||||
|
* device tree node.
|
||||||
|
*
|
||||||
|
* The device is probed to activate it ready for use.
|
||||||
|
*
|
||||||
|
* @id: ID to look up
|
||||||
|
* @np: Device tree node to search for (if NULL then -ENODEV is returned)
|
||||||
|
* @devp: Returns pointer to device (there is only one for each node)
|
||||||
|
* @return 0 if OK, -ve on error
|
||||||
|
*/
|
||||||
|
int uclass_get_device_by_ofnode(enum uclass_id id, ofnode node,
|
||||||
|
struct udevice **devp);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* uclass_get_device_by_phandle() - Get a uclass device by phandle
|
* uclass_get_device_by_phandle() - Get a uclass device by phandle
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user