avionic design with actual uboot and tooling

submodule of avionic design uboot bootloader and with included tools to
get you started , read readme.md and readme-tk1-loader.md
This commit is contained in:
2026-03-03 21:46:32 +02:00
parent fe3ba02c96
commit 68d74d3181
11967 changed files with 2221897 additions and 0 deletions

View File

@@ -0,0 +1,175 @@
/*
* Copyright (C) 2013 Google, Inc
*
* (C) Copyright 2012
* Pavel Herrmann <morpheus.ibis@gmail.com>
* Marek Vasut <marex@denx.de>
*
* SPDX-License-Identifier: GPL-2.0+
*/
#ifndef _DM_DEVICE_INTERNAL_H
#define _DM_DEVICE_INTERNAL_H
struct udevice;
/**
* device_bind() - Create a device and bind it to a driver
*
* Called to set up a new device attached to a driver. The device will either
* have platdata, or a device tree node which can be used to create the
* platdata.
*
* Once bound a device exists but is not yet active until device_probe() is
* called.
*
* @parent: Pointer to device's parent, under which this driver will exist
* @drv: Device's driver
* @name: Name of device (e.g. device tree node name)
* @platdata: Pointer to data for this device - the structure is device-
* specific but may include the device's I/O address, etc.. This is NULL for
* devices which use device tree.
* @of_offset: Offset of device tree node for this device. This is -1 for
* devices which don't use device tree.
* @devp: if non-NULL, returns a pointer to the bound device
* @return 0 if OK, -ve on error
*/
int device_bind(struct udevice *parent, const struct driver *drv,
const char *name, void *platdata, int of_offset,
struct udevice **devp);
/**
* device_bind_with_driver_data() - Create a device and bind it to a driver
*
* Called to set up a new device attached to a driver, in the case where the
* driver was matched to the device by means of a match table that provides
* driver_data.
*
* Once bound a device exists but is not yet active until device_probe() is
* called.
*
* @parent: Pointer to device's parent, under which this driver will exist
* @drv: Device's driver
* @name: Name of device (e.g. device tree node name)
* @driver_data: The driver_data field from the driver's match table.
* @of_offset: Offset of device tree node for this device. This is -1 for
* devices which don't use device tree.
* @devp: if non-NULL, returns a pointer to the bound device
* @return 0 if OK, -ve on error
*/
int device_bind_with_driver_data(struct udevice *parent,
const struct driver *drv, const char *name,
ulong driver_data, int of_offset,
struct udevice **devp);
/**
* device_bind_by_name: Create a device and bind it to a driver
*
* This is a helper function used to bind devices which do not use device
* tree.
*
* @parent: Pointer to device's parent
* @pre_reloc_only: If true, bind the driver only if its DM_INIT_F flag is set.
* If false bind the driver always.
* @info: Name and platdata for this device
* @devp: if non-NULL, returns a pointer to the bound device
* @return 0 if OK, -ve on error
*/
int device_bind_by_name(struct udevice *parent, bool pre_reloc_only,
const struct driver_info *info, struct udevice **devp);
/**
* device_probe() - Probe a device, activating it
*
* Activate a device so that it is ready for use. All its parents are probed
* first.
*
* @dev: Pointer to device to probe
* @return 0 if OK, -ve on error
*/
int device_probe(struct udevice *dev);
/**
* device_remove() - Remove a device, de-activating it
*
* De-activate a device so that it is no longer ready for use. All its
* children are deactivated first.
*
* @dev: Pointer to device to remove
* @return 0 if OK, -ve on error (an error here is normally a very bad thing)
*/
#if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
int device_remove(struct udevice *dev);
#else
static inline int device_remove(struct udevice *dev) { return 0; }
#endif
/**
* device_unbind() - Unbind a device, destroying it
*
* Unbind a device and remove all memory used by it
*
* @dev: Pointer to device to unbind
* @return 0 if OK, -ve on error
*/
#if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
int device_unbind(struct udevice *dev);
#else
static inline int device_unbind(struct udevice *dev) { return 0; }
#endif
#if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
void device_free(struct udevice *dev);
#else
static inline void device_free(struct udevice *dev) {}
#endif
/**
* simple_bus_translate() - translate a bus address to a system address
*
* This handles the 'ranges' property in a simple bus. It translates the
* device address @addr to a system address using this property.
*
* @dev: Simple bus device (parent of target device)
* @addr: Address to translate
* @return new address
*/
fdt_addr_t simple_bus_translate(struct udevice *dev, fdt_addr_t addr);
/* Cast away any volatile pointer */
#define DM_ROOT_NON_CONST (((gd_t *)gd)->dm_root)
#define DM_UCLASS_ROOT_NON_CONST (((gd_t *)gd)->uclass_root)
/* device resource management */
#ifdef CONFIG_DEVRES
/**
* devres_release_probe - Release managed resources allocated after probing
* @dev: Device to release resources for
*
* Release all resources allocated for @dev when it was probed or later.
* This function is called on driver removal.
*/
void devres_release_probe(struct udevice *dev);
/**
* devres_release_all - Release all managed resources
* @dev: Device to release resources for
*
* Release all resources associated with @dev. This function is
* called on driver unbinding.
*/
void devres_release_all(struct udevice *dev);
#else /* ! CONFIG_DEVRES */
static inline void devres_release_probe(struct udevice *dev)
{
}
static inline void devres_release_all(struct udevice *dev)
{
}
#endif /* ! CONFIG_DEVRES */
#endif

872
u-boot/include/dm/device.h Normal file
View File

@@ -0,0 +1,872 @@
/*
* Copyright (c) 2013 Google, Inc
*
* (C) Copyright 2012
* Pavel Herrmann <morpheus.ibis@gmail.com>
* Marek Vasut <marex@denx.de>
*
* SPDX-License-Identifier: GPL-2.0+
*/
#ifndef _DM_DEVICE_H
#define _DM_DEVICE_H
#include <dm/uclass-id.h>
#include <fdtdec.h>
#include <linker_lists.h>
#include <linux/compat.h>
#include <linux/kernel.h>
#include <linux/list.h>
struct driver_info;
/* Driver is active (probed). Cleared when it is removed */
#define DM_FLAG_ACTIVATED (1 << 0)
/* DM is responsible for allocating and freeing platdata */
#define DM_FLAG_ALLOC_PDATA (1 << 1)
/* DM should init this device prior to relocation */
#define DM_FLAG_PRE_RELOC (1 << 2)
/* DM is responsible for allocating and freeing parent_platdata */
#define DM_FLAG_ALLOC_PARENT_PDATA (1 << 3)
/* DM is responsible for allocating and freeing uclass_platdata */
#define DM_FLAG_ALLOC_UCLASS_PDATA (1 << 4)
/* Allocate driver private data on a DMA boundary */
#define DM_FLAG_ALLOC_PRIV_DMA (1 << 5)
/* Device is bound */
#define DM_FLAG_BOUND (1 << 6)
/* Device name is allocated and should be freed on unbind() */
#define DM_NAME_ALLOCED (1 << 7)
/**
* struct udevice - An instance of a driver
*
* This holds information about a device, which is a driver bound to a
* particular port or peripheral (essentially a driver instance).
*
* A device will come into existence through a 'bind' call, either due to
* a U_BOOT_DEVICE() macro (in which case platdata is non-NULL) or a node
* in the device tree (in which case of_offset is >= 0). In the latter case
* we translate the device tree information into platdata in a function
* implemented by the driver ofdata_to_platdata method (called just before the
* probe method if the device has a device tree node.
*
* All three of platdata, priv and uclass_priv can be allocated by the
* driver, or you can use the auto_alloc_size members of struct driver and
* struct uclass_driver to have driver model do this automatically.
*
* @driver: The driver used by this device
* @name: Name of device, typically the FDT node name
* @platdata: Configuration data for this device
* @parent_platdata: The parent bus's configuration data for this device
* @uclass_platdata: The uclass's configuration data for this device
* @of_offset: Device tree node offset for this device (- for none)
* @driver_data: Driver data word for the entry that matched this device with
* its driver
* @parent: Parent of this device, or NULL for the top level device
* @priv: Private data for this device
* @uclass: Pointer to uclass for this device
* @uclass_priv: The uclass's private data for this device
* @parent_priv: The parent's private data for this device
* @uclass_node: Used by uclass to link its devices
* @child_head: List of children of this device
* @sibling_node: Next device in list of all devices
* @flags: Flags for this device DM_FLAG_...
* @req_seq: Requested sequence number for this device (-1 = any)
* @seq: Allocated sequence number for this device (-1 = none). This is set up
* when the device is probed and will be unique within the device's uclass.
* @devres_head: List of memory allocations associated with this device.
* When CONFIG_DEVRES is enabled, devm_kmalloc() and friends will
* add to this list. Memory so-allocated will be freed
* automatically when the device is removed / unbound
*/
struct udevice {
const struct driver *driver;
const char *name;
void *platdata;
void *parent_platdata;
void *uclass_platdata;
int of_offset;
ulong driver_data;
struct udevice *parent;
void *priv;
struct uclass *uclass;
void *uclass_priv;
void *parent_priv;
struct list_head uclass_node;
struct list_head child_head;
struct list_head sibling_node;
uint32_t flags;
int req_seq;
int seq;
#ifdef CONFIG_DEVRES
struct list_head devres_head;
#endif
};
/* Maximum sequence number supported */
#define DM_MAX_SEQ 999
/* Returns the operations for a device */
#define device_get_ops(dev) (dev->driver->ops)
/* Returns non-zero if the device is active (probed and not removed) */
#define device_active(dev) ((dev)->flags & DM_FLAG_ACTIVATED)
/**
* struct udevice_id - Lists the compatible strings supported by a driver
* @compatible: Compatible string
* @data: Data for this compatible string
*/
struct udevice_id {
const char *compatible;
ulong data;
};
#if CONFIG_IS_ENABLED(OF_CONTROL)
#define of_match_ptr(_ptr) (_ptr)
#else
#define of_match_ptr(_ptr) NULL
#endif /* CONFIG_IS_ENABLED(OF_CONTROL) */
/**
* struct driver - A driver for a feature or peripheral
*
* This holds methods for setting up a new device, and also removing it.
* The device needs information to set itself up - this is provided either
* by platdata or a device tree node (which we find by looking up
* matching compatible strings with of_match).
*
* Drivers all belong to a uclass, representing a class of devices of the
* same type. Common elements of the drivers can be implemented in the uclass,
* or the uclass can provide a consistent interface to the drivers within
* it.
*
* @name: Device name
* @id: Identiies the uclass we belong to
* @of_match: List of compatible strings to match, and any identifying data
* for each.
* @bind: Called to bind a device to its driver
* @probe: Called to probe a device, i.e. activate it
* @remove: Called to remove a device, i.e. de-activate it
* @unbind: Called to unbind a device from its driver
* @ofdata_to_platdata: Called before probe to decode device tree data
* @child_post_bind: Called after a new child has been bound
* @child_pre_probe: Called before a child device is probed. The device has
* memory allocated but it has not yet been probed.
* @child_post_remove: Called after a child device is removed. The device
* has memory allocated but its device_remove() method has been called.
* @priv_auto_alloc_size: If non-zero this is the size of the private data
* to be allocated in the device's ->priv pointer. If zero, then the driver
* is responsible for allocating any data required.
* @platdata_auto_alloc_size: If non-zero this is the size of the
* platform data to be allocated in the device's ->platdata pointer.
* This is typically only useful for device-tree-aware drivers (those with
* an of_match), since drivers which use platdata will have the data
* provided in the U_BOOT_DEVICE() instantiation.
* @per_child_auto_alloc_size: Each device can hold private data owned by
* its parent. If required this will be automatically allocated if this
* value is non-zero.
* @per_child_platdata_auto_alloc_size: A bus likes to store information about
* its children. If non-zero this is the size of this data, to be allocated
* in the child's parent_platdata pointer.
* @ops: Driver-specific operations. This is typically a list of function
* pointers defined by the driver, to implement driver functions required by
* the uclass.
* @flags: driver flags - see DM_FLAGS_...
*/
struct driver {
char *name;
enum uclass_id id;
const struct udevice_id *of_match;
int (*bind)(struct udevice *dev);
int (*probe)(struct udevice *dev);
int (*remove)(struct udevice *dev);
int (*unbind)(struct udevice *dev);
int (*ofdata_to_platdata)(struct udevice *dev);
int (*child_post_bind)(struct udevice *dev);
int (*child_pre_probe)(struct udevice *dev);
int (*child_post_remove)(struct udevice *dev);
int priv_auto_alloc_size;
int platdata_auto_alloc_size;
int per_child_auto_alloc_size;
int per_child_platdata_auto_alloc_size;
const void *ops; /* driver-specific operations */
uint32_t flags;
};
/* Declare a new U-Boot driver */
#define U_BOOT_DRIVER(__name) \
ll_entry_declare(struct driver, __name, driver)
/**
* dev_get_platdata() - Get the platform data for a device
*
* This checks that dev is not NULL, but no other checks for now
*
* @dev Device to check
* @return platform data, or NULL if none
*/
void *dev_get_platdata(struct udevice *dev);
/**
* dev_get_parent_platdata() - Get the parent platform data for a device
*
* This checks that dev is not NULL, but no other checks for now
*
* @dev Device to check
* @return parent's platform data, or NULL if none
*/
void *dev_get_parent_platdata(struct udevice *dev);
/**
* dev_get_uclass_platdata() - Get the uclass platform data for a device
*
* This checks that dev is not NULL, but no other checks for now
*
* @dev Device to check
* @return uclass's platform data, or NULL if none
*/
void *dev_get_uclass_platdata(struct udevice *dev);
/**
* dev_get_priv() - Get the private data for a device
*
* This checks that dev is not NULL, but no other checks for now
*
* @dev Device to check
* @return private data, or NULL if none
*/
void *dev_get_priv(struct udevice *dev);
/**
* dev_get_parent_priv() - Get the parent private data for a device
*
* The parent private data is data stored in the device but owned by the
* parent. For example, a USB device may have parent data which contains
* information about how to talk to the device over USB.
*
* This checks that dev is not NULL, but no other checks for now
*
* @dev Device to check
* @return parent data, or NULL if none
*/
void *dev_get_parent_priv(struct udevice *dev);
/**
* dev_get_uclass_priv() - Get the private uclass data for a device
*
* This checks that dev is not NULL, but no other checks for now
*
* @dev Device to check
* @return private uclass data for this device, or NULL if none
*/
void *dev_get_uclass_priv(struct udevice *dev);
/**
* struct dev_get_parent() - Get the parent of a device
*
* @child: Child to check
* @return parent of child, or NULL if this is the root device
*/
struct udevice *dev_get_parent(struct udevice *child);
/**
* dev_get_driver_data() - get the driver data used to bind a device
*
* When a device is bound using a device tree node, it matches a
* particular compatible string in struct udevice_id. This function
* returns the associated data value for that compatible string. This is
* the 'data' field in struct udevice_id.
*
* As an example, consider this structure:
* static const struct udevice_id tegra_i2c_ids[] = {
* { .compatible = "nvidia,tegra114-i2c", .data = TYPE_114 },
* { .compatible = "nvidia,tegra20-i2c", .data = TYPE_STD },
* { .compatible = "nvidia,tegra20-i2c-dvc", .data = TYPE_DVC },
* { }
* };
*
* When driver model finds a driver for this it will store the 'data' value
* corresponding to the compatible string it matches. This function returns
* that value. This allows the driver to handle several variants of a device.
*
* For USB devices, this is the driver_info field in struct usb_device_id.
*
* @dev: Device to check
* @return driver data (0 if none is provided)
*/
ulong dev_get_driver_data(struct udevice *dev);
/**
* dev_get_driver_ops() - get the device's driver's operations
*
* This checks that dev is not NULL, and returns the pointer to device's
* driver's operations.
*
* @dev: Device to check
* @return void pointer to driver's operations or NULL for NULL-dev or NULL-ops
*/
const void *dev_get_driver_ops(struct udevice *dev);
/**
* device_get_uclass_id() - return the uclass ID of a device
*
* @dev: Device to check
* @return uclass ID for the device
*/
enum uclass_id device_get_uclass_id(struct udevice *dev);
/**
* dev_get_uclass_name() - return the uclass name of a device
*
* This checks that dev is not NULL.
*
* @dev: Device to check
* @return pointer to the uclass name for the device
*/
const char *dev_get_uclass_name(struct udevice *dev);
/**
* device_get_child() - Get the child of a device by index
*
* Returns the numbered child, 0 being the first. This does not use
* sequence numbers, only the natural order.
*
* @dev: Parent device to check
* @index: Child index
* @devp: Returns pointer to device
* @return 0 if OK, -ENODEV if no such device, other error if the device fails
* to probe
*/
int device_get_child(struct udevice *parent, int index, struct udevice **devp);
/**
* device_find_child_by_seq() - Find a child device based on a sequence
*
* This searches for a device with the given seq or req_seq.
*
* For seq, if an active device has this sequence it will be returned.
* If there is no such device then this will return -ENODEV.
*
* For req_seq, if a device (whether activated or not) has this req_seq
* value, that device will be returned. This is a strong indication that
* the device will receive that sequence when activated.
*
* @parent: Parent device
* @seq_or_req_seq: Sequence number to find (0=first)
* @find_req_seq: true to find req_seq, false to find seq
* @devp: Returns pointer to device (there is only one per for each seq).
* Set to NULL if none is found
* @return 0 if OK, -ve on error
*/
int device_find_child_by_seq(struct udevice *parent, int seq_or_req_seq,
bool find_req_seq, struct udevice **devp);
/**
* device_get_child_by_seq() - Get a child device based on a sequence
*
* If an active device has this sequence it will be returned. If there is no
* such device then this will check for a device that is requesting this
* sequence.
*
* The device is probed to activate it ready for use.
*
* @parent: Parent device
* @seq: Sequence number to find (0=first)
* @devp: Returns pointer to device (there is only one per for each seq)
* Set to NULL if none is found
* @return 0 if OK, -ve on error
*/
int device_get_child_by_seq(struct udevice *parent, int seq,
struct udevice **devp);
/**
* device_find_child_by_of_offset() - Find a child device based on FDT offset
*
* Locates a child device by its device tree offset.
*
* @parent: Parent device
* @of_offset: Device tree offset to find
* @devp: Returns pointer to device if found, otherwise this is set to NULL
* @return 0 if OK, -ve on error
*/
int device_find_child_by_of_offset(struct udevice *parent, int of_offset,
struct udevice **devp);
/**
* device_get_child_by_of_offset() - Get a child device based on FDT offset
*
* Locates a child device by its device tree offset.
*
* The device is probed to activate it ready for use.
*
* @parent: Parent device
* @of_offset: Device tree offset to find
* @devp: Returns pointer to device if found, otherwise this is set to NULL
* @return 0 if OK, -ve on error
*/
int device_get_child_by_of_offset(struct udevice *parent, int of_offset,
struct udevice **devp);
/**
* device_get_global_by_of_offset() - Get a device based on FDT offset
*
* Locates a device by its device tree offset, searching globally throughout
* the all driver model devices.
*
* The device is probed to activate it ready for use.
*
* @of_offset: Device tree offset to find
* @devp: Returns pointer to device if found, otherwise this is set to NULL
* @return 0 if OK, -ve on error
*/
int device_get_global_by_of_offset(int of_offset, struct udevice **devp);
/**
* device_find_first_child() - Find the first child of a device
*
* @parent: Parent device to search
* @devp: Returns first child device, or NULL if none
* @return 0
*/
int device_find_first_child(struct udevice *parent, struct udevice **devp);
/**
* device_find_next_child() - Find the next child of a device
*
* @devp: Pointer to previous child device on entry. Returns pointer to next
* child device, or NULL if none
* @return 0
*/
int device_find_next_child(struct udevice **devp);
/**
* dev_get_addr() - Get the reg property of a device
*
* @dev: Pointer to a device
*
* @return addr
*/
fdt_addr_t dev_get_addr(struct udevice *dev);
/**
* dev_get_addr_ptr() - Return pointer to the address of the reg property
* of a device
*
* @dev: Pointer to a device
*
* @return Pointer to addr, or NULL if there is no such property
*/
void *dev_get_addr_ptr(struct udevice *dev);
/**
* dev_get_addr_index() - Get the indexed reg property of a device
*
* @dev: Pointer to a device
* @index: the 'reg' property can hold a list of <addr, size> pairs
* and @index is used to select which one is required
*
* @return addr
*/
fdt_addr_t dev_get_addr_index(struct udevice *dev, int index);
/**
* dev_get_addr_name() - Get the reg property of a device, indexed by name
*
* @dev: Pointer to a device
* @name: the 'reg' property can hold a list of <addr, size> pairs, with the
* 'reg-names' property providing named-based identification. @index
* indicates the value to search for in 'reg-names'.
*
* @return addr
*/
fdt_addr_t dev_get_addr_name(struct udevice *dev, const char *name);
/**
* device_has_children() - check if a device has any children
*
* @dev: Device to check
* @return true if the device has one or more children
*/
bool device_has_children(struct udevice *dev);
/**
* device_has_active_children() - check if a device has any active children
*
* @dev: Device to check
* @return true if the device has one or more children and at least one of
* them is active (probed).
*/
bool device_has_active_children(struct udevice *dev);
/**
* device_is_last_sibling() - check if a device is the last sibling
*
* This function can be useful for display purposes, when special action needs
* to be taken when displaying the last sibling. This can happen when a tree
* view of devices is being displayed.
*
* @dev: Device to check
* @return true if there are no more siblings after this one - i.e. is it
* last in the list.
*/
bool device_is_last_sibling(struct udevice *dev);
/**
* device_set_name() - set the name of a device
*
* This must be called in the device's bind() method and no later. Normally
* this is unnecessary but for probed devices which don't get a useful name
* this function can be helpful.
*
* The name is allocated and will be freed automatically when the device is
* unbound.
*
* @dev: Device to update
* @name: New name (this string is allocated new memory and attached to
* the device)
* @return 0 if OK, -ENOMEM if there is not enough memory to allocate the
* string
*/
int device_set_name(struct udevice *dev, const char *name);
/**
* device_set_name_alloced() - note that a device name is allocated
*
* This sets the DM_NAME_ALLOCED flag for the device, so that when it is
* unbound the name will be freed. This avoids memory leaks.
*
* @dev: Device to update
*/
void device_set_name_alloced(struct udevice *dev);
/**
* of_device_is_compatible() - check if the device is compatible with the compat
*
* This allows to check whether the device is comaptible with the compat.
*
* @dev: udevice pointer for which compatible needs to be verified.
* @compat: Compatible string which needs to verified in the given
* device
* @return true if OK, false if the compatible is not found
*/
bool of_device_is_compatible(struct udevice *dev, const char *compat);
/**
* of_machine_is_compatible() - check if the machine is compatible with
* the compat
*
* This allows to check whether the machine is comaptible with the compat.
*
* @compat: Compatible string which needs to verified
* @return true if OK, false if the compatible is not found
*/
bool of_machine_is_compatible(const char *compat);
/**
* device_is_on_pci_bus - Test if a device is on a PCI bus
*
* @dev: device to test
* @return: true if it is on a PCI bus, false otherwise
*/
static inline bool device_is_on_pci_bus(struct udevice *dev)
{
return device_get_uclass_id(dev->parent) == UCLASS_PCI;
}
/**
* device_foreach_child_safe() - iterate through child devices safely
*
* This allows the @pos child to be removed in the loop if required.
*
* @pos: struct udevice * for the current device
* @next: struct udevice * for the next device
* @parent: parent device to scan
*/
#define device_foreach_child_safe(pos, next, parent) \
list_for_each_entry_safe(pos, next, &parent->child_head, sibling_node)
/* device resource management */
typedef void (*dr_release_t)(struct udevice *dev, void *res);
typedef int (*dr_match_t)(struct udevice *dev, void *res, void *match_data);
#ifdef CONFIG_DEVRES
#ifdef CONFIG_DEBUG_DEVRES
void *__devres_alloc(dr_release_t release, size_t size, gfp_t gfp,
const char *name);
#define _devres_alloc(release, size, gfp) \
__devres_alloc(release, size, gfp, #release)
#else
void *_devres_alloc(dr_release_t release, size_t size, gfp_t gfp);
#endif
/**
* devres_alloc() - Allocate device resource data
* @release: Release function devres will be associated with
* @size: Allocation size
* @gfp: Allocation flags
*
* Allocate devres of @size bytes. The allocated area is associated
* with @release. The returned pointer can be passed to
* other devres_*() functions.
*
* RETURNS:
* Pointer to allocated devres on success, NULL on failure.
*/
#define devres_alloc(release, size, gfp) \
_devres_alloc(release, size, gfp | __GFP_ZERO)
/**
* devres_free() - Free device resource data
* @res: Pointer to devres data to free
*
* Free devres created with devres_alloc().
*/
void devres_free(void *res);
/**
* devres_add() - Register device resource
* @dev: Device to add resource to
* @res: Resource to register
*
* Register devres @res to @dev. @res should have been allocated
* using devres_alloc(). On driver detach, the associated release
* function will be invoked and devres will be freed automatically.
*/
void devres_add(struct udevice *dev, void *res);
/**
* devres_find() - Find device resource
* @dev: Device to lookup resource from
* @release: Look for resources associated with this release function
* @match: Match function (optional)
* @match_data: Data for the match function
*
* Find the latest devres of @dev which is associated with @release
* and for which @match returns 1. If @match is NULL, it's considered
* to match all.
*
* @return pointer to found devres, NULL if not found.
*/
void *devres_find(struct udevice *dev, dr_release_t release,
dr_match_t match, void *match_data);
/**
* devres_get() - Find devres, if non-existent, add one atomically
* @dev: Device to lookup or add devres for
* @new_res: Pointer to new initialized devres to add if not found
* @match: Match function (optional)
* @match_data: Data for the match function
*
* Find the latest devres of @dev which has the same release function
* as @new_res and for which @match return 1. If found, @new_res is
* freed; otherwise, @new_res is added atomically.
*
* @return ointer to found or added devres.
*/
void *devres_get(struct udevice *dev, void *new_res,
dr_match_t match, void *match_data);
/**
* devres_remove() - Find a device resource and remove it
* @dev: Device to find resource from
* @release: Look for resources associated with this release function
* @match: Match function (optional)
* @match_data: Data for the match function
*
* Find the latest devres of @dev associated with @release and for
* which @match returns 1. If @match is NULL, it's considered to
* match all. If found, the resource is removed atomically and
* returned.
*
* @return ointer to removed devres on success, NULL if not found.
*/
void *devres_remove(struct udevice *dev, dr_release_t release,
dr_match_t match, void *match_data);
/**
* devres_destroy() - Find a device resource and destroy it
* @dev: Device to find resource from
* @release: Look for resources associated with this release function
* @match: Match function (optional)
* @match_data: Data for the match function
*
* Find the latest devres of @dev associated with @release and for
* which @match returns 1. If @match is NULL, it's considered to
* match all. If found, the resource is removed atomically and freed.
*
* Note that the release function for the resource will not be called,
* only the devres-allocated data will be freed. The caller becomes
* responsible for freeing any other data.
*
* @return 0 if devres is found and freed, -ENOENT if not found.
*/
int devres_destroy(struct udevice *dev, dr_release_t release,
dr_match_t match, void *match_data);
/**
* devres_release() - Find a device resource and destroy it, calling release
* @dev: Device to find resource from
* @release: Look for resources associated with this release function
* @match: Match function (optional)
* @match_data: Data for the match function
*
* Find the latest devres of @dev associated with @release and for
* which @match returns 1. If @match is NULL, it's considered to
* match all. If found, the resource is removed atomically, the
* release function called and the resource freed.
*
* @return 0 if devres is found and freed, -ENOENT if not found.
*/
int devres_release(struct udevice *dev, dr_release_t release,
dr_match_t match, void *match_data);
/* managed devm_k.alloc/kfree for device drivers */
/**
* devm_kmalloc() - Resource-managed kmalloc
* @dev: Device to allocate memory for
* @size: Allocation size
* @gfp: Allocation gfp flags
*
* Managed kmalloc. Memory allocated with this function is
* automatically freed on driver detach. Like all other devres
* resources, guaranteed alignment is unsigned long long.
*
* @return pointer to allocated memory on success, NULL on failure.
*/
void *devm_kmalloc(struct udevice *dev, size_t size, gfp_t gfp);
static inline void *devm_kzalloc(struct udevice *dev, size_t size, gfp_t gfp)
{
return devm_kmalloc(dev, size, gfp | __GFP_ZERO);
}
static inline void *devm_kmalloc_array(struct udevice *dev,
size_t n, size_t size, gfp_t flags)
{
if (size != 0 && n > SIZE_MAX / size)
return NULL;
return devm_kmalloc(dev, n * size, flags);
}
static inline void *devm_kcalloc(struct udevice *dev,
size_t n, size_t size, gfp_t flags)
{
return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO);
}
/**
* devm_kfree() - Resource-managed kfree
* @dev: Device this memory belongs to
* @ptr: Memory to free
*
* Free memory allocated with devm_kmalloc().
*/
void devm_kfree(struct udevice *dev, void *ptr);
#else /* ! CONFIG_DEVRES */
static inline void *devres_alloc(dr_release_t release, size_t size, gfp_t gfp)
{
return kzalloc(size, gfp);
}
static inline void devres_free(void *res)
{
kfree(res);
}
static inline void devres_add(struct udevice *dev, void *res)
{
}
static inline void *devres_find(struct udevice *dev, dr_release_t release,
dr_match_t match, void *match_data)
{
return NULL;
}
static inline void *devres_get(struct udevice *dev, void *new_res,
dr_match_t match, void *match_data)
{
return NULL;
}
static inline void *devres_remove(struct udevice *dev, dr_release_t release,
dr_match_t match, void *match_data)
{
return NULL;
}
static inline int devres_destroy(struct udevice *dev, dr_release_t release,
dr_match_t match, void *match_data)
{
return 0;
}
static inline int devres_release(struct udevice *dev, dr_release_t release,
dr_match_t match, void *match_data)
{
return 0;
}
static inline void *devm_kmalloc(struct udevice *dev, size_t size, gfp_t gfp)
{
return kmalloc(size, gfp);
}
static inline void *devm_kzalloc(struct udevice *dev, size_t size, gfp_t gfp)
{
return kzalloc(size, gfp);
}
static inline void *devm_kmaloc_array(struct udevice *dev,
size_t n, size_t size, gfp_t flags)
{
/* TODO: add kmalloc_array() to linux/compat.h */
if (size != 0 && n > SIZE_MAX / size)
return NULL;
return kmalloc(n * size, flags);
}
static inline void *devm_kcalloc(struct udevice *dev,
size_t n, size_t size, gfp_t flags)
{
/* TODO: add kcalloc() to linux/compat.h */
return kmalloc(n * size, flags | __GFP_ZERO);
}
static inline void devm_kfree(struct udevice *dev, void *ptr)
{
kfree(ptr);
}
#endif /* ! CONFIG_DEVRES */
/**
* dm_set_translation_offset() - Set translation offset
* @offs: Translation offset
*
* Some platforms need a special address translation. Those
* platforms (e.g. mvebu in SPL) can configure a translation
* offset in the DM by calling this function. It will be
* added to all addresses returned in dev_get_addr().
*/
void dm_set_translation_offset(fdt_addr_t offs);
/**
* dm_get_translation_offset() - Get translation offset
*
* This function returns the translation offset that can
* be configured by calling dm_set_translation_offset().
*
* @return translation offset for the device address (0 as default).
*/
fdt_addr_t dm_get_translation_offset(void);
#endif

92
u-boot/include/dm/lists.h Normal file
View File

@@ -0,0 +1,92 @@
/*
* Copyright (c) 2013 Google, Inc
*
* (C) Copyright 2012
* Pavel Herrmann <morpheus.ibis@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0+
*/
#ifndef _DM_LISTS_H_
#define _DM_LISTS_H_
#include <dm/uclass-id.h>
/**
* lists_driver_lookup_name() - Return u_boot_driver corresponding to name
*
* This function returns a pointer to a driver given its name. This is used
* for binding a driver given its name and platdata.
*
* @name: Name of driver to look up
* @return pointer to driver, or NULL if not found
*/
struct driver *lists_driver_lookup_name(const char *name);
/**
* lists_uclass_lookup() - Return uclass_driver based on ID of the class
* id: ID of the class
*
* This function returns the pointer to uclass_driver, which is the class's
* base structure based on the ID of the class. Returns NULL on error.
*/
struct uclass_driver *lists_uclass_lookup(enum uclass_id id);
/**
* lists_bind_drivers() - search for and bind all drivers to parent
*
* This searches the U_BOOT_DEVICE() structures and creates new devices for
* each one. The devices will have @parent as their parent.
*
* @parent: parent device (root)
* @early_only: If true, bind only drivers with the DM_INIT_F flag. If false
* bind all drivers.
*/
int lists_bind_drivers(struct udevice *parent, bool pre_reloc_only);
/**
* lists_bind_fdt() - bind a device tree node
*
* This creates a new device bound to the given device tree node, with
* @parent as its parent.
*
* @parent: parent device (root)
* @blob: device tree blob
* @offset: offset of this device tree node
* @devp: if non-NULL, returns a pointer to the bound device
* @return 0 if device was bound, -EINVAL if the device tree is invalid,
* other -ve value on error
*/
int lists_bind_fdt(struct udevice *parent, const void *blob, int offset,
struct udevice **devp);
/**
* device_bind_driver() - bind a device to a driver
*
* This binds a new device to a driver.
*
* @parent: Parent device
* @drv_name: Name of driver to attach to this parent
* @dev_name: Name of the new device thus created
* @devp: If non-NULL, returns the newly bound device
*/
int device_bind_driver(struct udevice *parent, const char *drv_name,
const char *dev_name, struct udevice **devp);
/**
* device_bind_driver_to_node() - bind a device to a driver for a node
*
* This binds a new device to a driver for a given device tree node. This
* should only be needed if the node lacks a compatible strings.
*
* @parent: Parent device
* @drv_name: Name of driver to attach to this parent
* @dev_name: Name of the new device thus created
* @node: Device tree node
* @devp: If non-NULL, returns the newly bound device
*/
int device_bind_driver_to_node(struct udevice *parent, const char *drv_name,
const char *dev_name, int node,
struct udevice **devp);
#endif

332
u-boot/include/dm/pinctrl.h Normal file
View File

@@ -0,0 +1,332 @@
/*
* Copyright (C) 2015 Masahiro Yamada <yamada.masahiro@socionext.com>
*
* SPDX-License-Identifier: GPL-2.0+
*/
#ifndef __PINCTRL_H
#define __PINCTRL_H
/**
* struct pinconf_param - pin config parameters
*
* @property: property name in DT nodes
* @param: ID for this config parameter
* @default_value: default value for this config parameter used in case
* no value is specified in DT nodes
*/
struct pinconf_param {
const char * const property;
unsigned int param;
u32 default_value;
};
/**
* struct pinctrl_ops - pin control operations, to be implemented by
* pin controller drivers.
*
* The @set_state is the only mandatory operation. You can implement your
* pinctrl driver with its own @set_state. In this case, the other callbacks
* are not required. Otherwise, generic pinctrl framework is also available;
* use pinctrl_generic_set_state for @set_state, and implement other operations
* depending on your necessity.
*
* @get_pins_count: return number of selectable named pins available
* in this driver. (necessary to parse "pins" property in DTS)
* @get_pin_name: return the pin name of the pin selector,
* called by the core to figure out which pin it shall do
* operations to. (necessary to parse "pins" property in DTS)
* @get_groups_count: return number of selectable named groups available
* in this driver. (necessary to parse "groups" property in DTS)
* @get_group_name: return the group name of the group selector,
* called by the core to figure out which pin group it shall do
* operations to. (necessary to parse "groups" property in DTS)
* @get_functions_count: return number of selectable named functions available
* in this driver. (necessary for pin-muxing)
* @get_function_name: return the function name of the muxing selector,
* called by the core to figure out which mux setting it shall map a
* certain device to. (necessary for pin-muxing)
* @pinmux_set: enable a certain muxing function with a certain pin.
* The @func_selector selects a certain function whereas @pin_selector
* selects a certain pin to be used. On simple controllers one of them
* may be ignored. (necessary for pin-muxing against a single pin)
* @pinmux_group_set: enable a certain muxing function with a certain pin
* group. The @func_selector selects a certain function whereas
* @group_selector selects a certain set of pins to be used. On simple
* controllers one of them may be ignored.
* (necessary for pin-muxing against a pin group)
* @pinconf_num_params: number of driver-specific parameters to be parsed
* from device trees (necessary for pin-configuration)
* @pinconf_params: list of driver_specific parameters to be parsed from
* device trees (necessary for pin-configuration)
* @pinconf_set: configure an individual pin with a given parameter.
* (necessary for pin-configuration against a single pin)
* @pinconf_group_set: configure all pins in a group with a given parameter.
* (necessary for pin-configuration against a pin group)
* @set_state: do pinctrl operations specified by @config, a pseudo device
* pointing a config node. (necessary for pinctrl_full)
* @set_state_simple: do needed pinctrl operations for a peripherl @periph.
* (necessary for pinctrl_simple)
*/
struct pinctrl_ops {
int (*get_pins_count)(struct udevice *dev);
const char *(*get_pin_name)(struct udevice *dev, unsigned selector);
int (*get_groups_count)(struct udevice *dev);
const char *(*get_group_name)(struct udevice *dev, unsigned selector);
int (*get_functions_count)(struct udevice *dev);
const char *(*get_function_name)(struct udevice *dev,
unsigned selector);
int (*pinmux_set)(struct udevice *dev, unsigned pin_selector,
unsigned func_selector);
int (*pinmux_group_set)(struct udevice *dev, unsigned group_selector,
unsigned func_selector);
unsigned int pinconf_num_params;
const struct pinconf_param *pinconf_params;
int (*pinconf_set)(struct udevice *dev, unsigned pin_selector,
unsigned param, unsigned argument);
int (*pinconf_group_set)(struct udevice *dev, unsigned group_selector,
unsigned param, unsigned argument);
int (*set_state)(struct udevice *dev, struct udevice *config);
/* for pinctrl-simple */
int (*set_state_simple)(struct udevice *dev, struct udevice *periph);
/**
* request() - Request a particular pinctrl function
*
* This activates the selected function.
*
* @dev: Device to adjust (UCLASS_PINCTRL)
* @func: Function number (driver-specific)
* @return 0 if OK, -ve on error
*/
int (*request)(struct udevice *dev, int func, int flags);
/**
* get_periph_id() - get the peripheral ID for a device
*
* This generally looks at the peripheral's device tree node to work
* out the peripheral ID. The return value is normally interpreted as
* enum periph_id. so long as this is defined by the platform (which it
* should be).
*
* @dev: Pinctrl device to use for decoding
* @periph: Device to check
* @return peripheral ID of @periph, or -ENOENT on error
*/
int (*get_periph_id)(struct udevice *dev, struct udevice *periph);
/**
* get_gpio_mux() - get the mux value for a particular GPIO
*
* This allows the raw mux value for a GPIO to be obtained. It is
* useful for displaying the function being used by that GPIO, such
* as with the 'gpio' command. This function is internal to the GPIO
* subsystem and should not be used by generic code. Typically it is
* used by a GPIO driver with knowledge of the SoC pinctrl setup.
*
* @dev: Pinctrl device to use
* @banknum: GPIO bank number
* @index: GPIO index within the bank
* @return mux value (SoC-specific, e.g. 0 for input, 1 for output)
*/
int (*get_gpio_mux)(struct udevice *dev, int banknum, int index);
};
#define pinctrl_get_ops(dev) ((struct pinctrl_ops *)(dev)->driver->ops)
/**
* Generic pin configuration paramters
*
* @PIN_CONFIG_BIAS_DISABLE: disable any pin bias on the pin, a
* transition from say pull-up to pull-down implies that you disable
* pull-up in the process, this setting disables all biasing.
* @PIN_CONFIG_BIAS_HIGH_IMPEDANCE: the pin will be set to a high impedance
* mode, also know as "third-state" (tristate) or "high-Z" or "floating".
* On output pins this effectively disconnects the pin, which is useful
* if for example some other pin is going to drive the signal connected
* to it for a while. Pins used for input are usually always high
* impedance.
* @PIN_CONFIG_BIAS_BUS_HOLD: the pin will be set to weakly latch so that it
* weakly drives the last value on a tristate bus, also known as a "bus
* holder", "bus keeper" or "repeater". This allows another device on the
* bus to change the value by driving the bus high or low and switching to
* tristate. The argument is ignored.
* @PIN_CONFIG_BIAS_PULL_UP: the pin will be pulled up (usually with high
* impedance to VDD). If the argument is != 0 pull-up is enabled,
* if it is 0, pull-up is total, i.e. the pin is connected to VDD.
* @PIN_CONFIG_BIAS_PULL_DOWN: the pin will be pulled down (usually with high
* impedance to GROUND). If the argument is != 0 pull-down is enabled,
* if it is 0, pull-down is total, i.e. the pin is connected to GROUND.
* @PIN_CONFIG_BIAS_PULL_PIN_DEFAULT: the pin will be pulled up or down based
* on embedded knowledge of the controller hardware, like current mux
* function. The pull direction and possibly strength too will normally
* be decided completely inside the hardware block and not be readable
* from the kernel side.
* If the argument is != 0 pull up/down is enabled, if it is 0, the
* configuration is ignored. The proper way to disable it is to use
* @PIN_CONFIG_BIAS_DISABLE.
* @PIN_CONFIG_DRIVE_PUSH_PULL: the pin will be driven actively high and
* low, this is the most typical case and is typically achieved with two
* active transistors on the output. Setting this config will enable
* push-pull mode, the argument is ignored.
* @PIN_CONFIG_DRIVE_OPEN_DRAIN: the pin will be driven with open drain (open
* collector) which means it is usually wired with other output ports
* which are then pulled up with an external resistor. Setting this
* config will enable open drain mode, the argument is ignored.
* @PIN_CONFIG_DRIVE_OPEN_SOURCE: the pin will be driven with open source
* (open emitter). Setting this config will enable open source mode, the
* argument is ignored.
* @PIN_CONFIG_DRIVE_STRENGTH: the pin will sink or source at most the current
* passed as argument. The argument is in mA.
* @PIN_CONFIG_INPUT_ENABLE: enable the pin's input. Note that this does not
* affect the pin's ability to drive output. 1 enables input, 0 disables
* input.
* @PIN_CONFIG_INPUT_SCHMITT_ENABLE: control schmitt-trigger mode on the pin.
* If the argument != 0, schmitt-trigger mode is enabled. If it's 0,
* schmitt-trigger mode is disabled.
* @PIN_CONFIG_INPUT_SCHMITT: this will configure an input pin to run in
* schmitt-trigger mode. If the schmitt-trigger has adjustable hysteresis,
* the threshold value is given on a custom format as argument when
* setting pins to this mode.
* @PIN_CONFIG_INPUT_DEBOUNCE: this will configure the pin to debounce mode,
* which means it will wait for signals to settle when reading inputs. The
* argument gives the debounce time in usecs. Setting the
* argument to zero turns debouncing off.
* @PIN_CONFIG_POWER_SOURCE: if the pin can select between different power
* supplies, the argument to this parameter (on a custom format) tells
* the driver which alternative power source to use.
* @PIN_CONFIG_SLEW_RATE: if the pin can select slew rate, the argument to
* this parameter (on a custom format) tells the driver which alternative
* slew rate to use.
* @PIN_CONFIG_LOW_POWER_MODE: this will configure the pin for low power
* operation, if several modes of operation are supported these can be
* passed in the argument on a custom form, else just use argument 1
* to indicate low power mode, argument 0 turns low power mode off.
* @PIN_CONFIG_OUTPUT: this will configure the pin as an output. Use argument
* 1 to indicate high level, argument 0 to indicate low level. (Please
* see Documentation/pinctrl.txt, section "GPIO mode pitfalls" for a
* discussion around this parameter.)
* @PIN_CONFIG_END: this is the last enumerator for pin configurations, if
* you need to pass in custom configurations to the pin controller, use
* PIN_CONFIG_END+1 as the base offset.
*/
#define PIN_CONFIG_BIAS_DISABLE 0
#define PIN_CONFIG_BIAS_HIGH_IMPEDANCE 1
#define PIN_CONFIG_BIAS_BUS_HOLD 2
#define PIN_CONFIG_BIAS_PULL_UP 3
#define PIN_CONFIG_BIAS_PULL_DOWN 4
#define PIN_CONFIG_BIAS_PULL_PIN_DEFAULT 5
#define PIN_CONFIG_DRIVE_PUSH_PULL 6
#define PIN_CONFIG_DRIVE_OPEN_DRAIN 7
#define PIN_CONFIG_DRIVE_OPEN_SOURCE 8
#define PIN_CONFIG_DRIVE_STRENGTH 9
#define PIN_CONFIG_INPUT_ENABLE 10
#define PIN_CONFIG_INPUT_SCHMITT_ENABLE 11
#define PIN_CONFIG_INPUT_SCHMITT 12
#define PIN_CONFIG_INPUT_DEBOUNCE 13
#define PIN_CONFIG_POWER_SOURCE 14
#define PIN_CONFIG_SLEW_RATE 15
#define PIN_CONFIG_LOW_POWER_MODE 16
#define PIN_CONFIG_OUTPUT 17
#define PIN_CONFIG_END 0x7FFF
#if CONFIG_IS_ENABLED(PINCTRL_GENERIC)
/**
* pinctrl_generic_set_state() - generic set_state operation
* Parse the DT node of @config and its children and handle generic properties
* such as "pins", "groups", "functions", and pin configuration parameters.
*
* @pctldev: pinctrl device
* @config: config device (pseudo device), pointing a config node in DTS
* @return: 0 on success, or negative error code on failure
*/
int pinctrl_generic_set_state(struct udevice *pctldev, struct udevice *config);
#else
static inline int pinctrl_generic_set_state(struct udevice *pctldev,
struct udevice *config)
{
return -EINVAL;
}
#endif
#if CONFIG_IS_ENABLED(PINCTRL)
/**
* pinctrl_select_state() - set a device to a given state
*
* @dev: peripheral device
* @statename: state name, like "default"
* @return: 0 on success, or negative error code on failure
*/
int pinctrl_select_state(struct udevice *dev, const char *statename);
#else
static inline int pinctrl_select_state(struct udevice *dev,
const char *statename)
{
return -EINVAL;
}
#endif
/**
* pinctrl_request() - Request a particular pinctrl function
*
* @dev: Device to check (UCLASS_PINCTRL)
* @func: Function number (driver-specific)
* @flags: Flags (driver-specific)
* @return 0 if OK, -ve on error
*/
int pinctrl_request(struct udevice *dev, int func, int flags);
/**
* pinctrl_request_noflags() - Request a particular pinctrl function
*
* This is similar to pinctrl_request() but uses 0 for @flags.
*
* @dev: Device to check (UCLASS_PINCTRL)
* @func: Function number (driver-specific)
* @return 0 if OK, -ve on error
*/
int pinctrl_request_noflags(struct udevice *dev, int func);
/**
* pinctrl_get_periph_id() - get the peripheral ID for a device
*
* This generally looks at the peripheral's device tree node to work out the
* peripheral ID. The return value is normally interpreted as enum periph_id.
* so long as this is defined by the platform (which it should be).
*
* @dev: Pinctrl device to use for decoding
* @periph: Device to check
* @return peripheral ID of @periph, or -ENOENT on error
*/
int pinctrl_get_periph_id(struct udevice *dev, struct udevice *periph);
/**
* pinctrl_decode_pin_config() - decode pin configuration flags
*
* This decodes some of the PIN_CONFIG values into flags, with each value
* being (1 << pin_cfg). This does not support things with values like the
* slew rate.
*
* @blob: Device tree blob
* @node: Node containing the PIN_CONFIG values
* @return decoded flag value, or -ve on error
*/
int pinctrl_decode_pin_config(const void *blob, int node);
/**
* pinctrl_get_gpio_mux() - get the mux value for a particular GPIO
*
* This allows the raw mux value for a GPIO to be obtained. It is
* useful for displaying the function being used by that GPIO, such
* as with the 'gpio' command. This function is internal to the GPIO
* subsystem and should not be used by generic code. Typically it is
* used by a GPIO driver with knowledge of the SoC pinctrl setup.
*
* @dev: Pinctrl device to use
* @banknum: GPIO bank number
* @index: GPIO index within the bank
* @return mux value (SoC-specific, e.g. 0 for input, 1 for output)
*/
int pinctrl_get_gpio_mux(struct udevice *dev, int banknum, int index);
#endif /* __PINCTRL_H */

View File

@@ -0,0 +1,43 @@
/*
* Copyright (c) 2013 Google, Inc
*
* (C) Copyright 2012
* Pavel Herrmann <morpheus.ibis@gmail.com>
* Marek Vasut <marex@denx.de>
*
* SPDX-License-Identifier: GPL-2.0+
*/
#ifndef _DM_PLATDATA_H
#define _DM_PLATDATA_H
#include <linker_lists.h>
/**
* struct driver_info - Information required to instantiate a device
*
* NOTE: Avoid using this except in extreme circumstances, where device tree
* is not feasible (e.g. serial driver in SPL where <8KB of SRAM is
* available). U-Boot's driver model uses device tree for configuration.
*
* @name: Driver name
* @platdata: Driver-specific platform data
*/
struct driver_info {
const char *name;
const void *platdata;
};
/**
* NOTE: Avoid using these except in extreme circumstances, where device tree
* is not feasible (e.g. serial driver in SPL where <8KB of SRAM is
* available). U-Boot's driver model uses device tree for configuration.
*/
#define U_BOOT_DEVICE(__name) \
ll_entry_declare(struct driver_info, __name, driver_info)
/* Declare a list of devices. The argument is a driver_info[] array */
#define U_BOOT_DEVICES(__name) \
ll_entry_declare_list(struct driver_info, __name, driver_info)
#endif

View File

@@ -0,0 +1,18 @@
/*
* Copyright (c) 2015 Vladimir Zapolskiy <vz@mleia.com>
* SPDX-License-Identifier: GPL-2.0+
*/
#ifndef _LPC32XX_HSUART_PLAT_H
#define _LPC32XX_HSUART_PLAT_H
/**
* struct lpc32xx_hsuart_platdata - NXP LPC32xx HSUART platform data
*
* @base: Base register address
*/
struct lpc32xx_hsuart_platdata {
unsigned long base;
};
#endif

View File

@@ -0,0 +1,24 @@
/*
* (C) Copyright 2016 Stephen Warren <swarren@wwwdotorg.org>
*
* Derived from pl01x code:
* Copyright (c) 2014 Google, Inc
*
* SPDX-License-Identifier: GPL-2.0+
*/
#ifndef __serial_bcm283x_mu_h
#define __serial_bcm283x_mu_h
/*
*Information about a serial port
*
* @base: Register base address
*/
struct bcm283x_mu_serial_platdata {
unsigned long base;
unsigned int clock;
bool skip_init;
};
#endif

View File

@@ -0,0 +1,23 @@
/*
* Copyright (c) 2015 Angelo Dureghello <angelo@sysam.it>
*
* SPDX-License-Identifier: GPL-2.0+
*/
#ifndef __serial_coldfire_h
#define __serial_coldfire_h
/*
* struct coldfire_serial_platdata - information about a coldfire port
*
* @base: Uart port base register address
* @port: Uart port index, for cpu with pinmux for uart / gpio
* baudrtatre: Uart port baudrate
*/
struct coldfire_serial_platdata {
unsigned long base;
int port;
int baudrate;
};
#endif /* __serial_coldfire_h */

View File

@@ -0,0 +1,14 @@
/*
* Copyright (c) 2014 Google, Inc
* SPDX-License-Identifier: GPL-2.0+
*/
#ifndef __serial_mxc_h
#define __serial_mxc_h
/* Information about a serial port */
struct mxc_serial_platdata {
struct mxc_uart *reg; /* address of registers in physical memory */
};
#endif

View File

@@ -0,0 +1,30 @@
/*
* Copyright (c) 2014 Google, Inc
* SPDX-License-Identifier: GPL-2.0+
*/
#ifndef __serial_pl01x_h
#define __serial_pl01x_h
enum pl01x_type {
TYPE_PL010,
TYPE_PL011,
};
/*
*Information about a serial port
*
* @base: Register base address
* @type: Port type
* @clock: Input clock rate, used for calculating the baud rate divisor
* @skip_init: Don't attempt to change port configuration (also means @clock
* is ignored)
*/
struct pl01x_serial_platdata {
unsigned long base;
enum pl01x_type type;
unsigned int clock;
bool skip_init;
};
#endif

View File

@@ -0,0 +1,37 @@
/*
* Copyright (c) 2014 Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com>
* Copyright (c) 2014 Renesas Electronics Corporation
*
* SPDX-License-Identifier: GPL-2.0+
*/
#ifndef __serial_sh_h
#define __serial_sh_h
enum sh_clk_mode {
INT_CLK,
EXT_CLK,
};
enum sh_serial_type {
PORT_SCI,
PORT_SCIF,
PORT_SCIFA,
PORT_SCIFB,
};
/*
* Information about SCIF port
*
* @base: Register base address
* @clk: Input clock rate, used for calculating the baud rate divisor
* @clk_mode: Clock mode, set internal (INT) or external (EXT)
* @type: Type of SCIF
*/
struct sh_serial_platdata {
unsigned long base;
unsigned int clk;
enum sh_clk_mode clk_mode;
enum sh_serial_type type;
};
#endif /* __serial_sh_h */

View File

@@ -0,0 +1,16 @@
/*
* (C) Copyright 2015
* Kamil Lulko, <kamil.lulko@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0+
*/
#ifndef __SERIAL_STM32_H
#define __SERIAL_STM32_H
/* Information about a serial port */
struct stm32_serial_platdata {
struct stm32_usart *base; /* address of registers in physical memory */
};
#endif /* __SERIAL_STM32_H */

View File

@@ -0,0 +1,17 @@
/*
* (C) Copyright 2016
* Vikas Manocha, <vikas.manocha@st.com>
*
* SPDX-License-Identifier: GPL-2.0+
*/
#ifndef __SERIAL_STM32x7_H
#define __SERIAL_STM32x7_H
/* Information about a serial port */
struct stm32x7_serial_platdata {
struct stm32_usart *base; /* address of registers in physical memory */
unsigned int clock;
};
#endif /* __SERIAL_STM32x7_H */

108
u-boot/include/dm/root.h Normal file
View File

@@ -0,0 +1,108 @@
/*
* Copyright (c) 2013 Google, Inc
*
* (C) Copyright 2012
* Pavel Herrmann <morpheus.ibis@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0+
*/
#ifndef _DM_ROOT_H_
#define _DM_ROOT_H_
struct udevice;
/**
* dm_root() - Return pointer to the top of the driver tree
*
* This function returns pointer to the root node of the driver tree,
*
* @return pointer to root device, or NULL if not inited yet
*/
struct udevice *dm_root(void);
/**
* dm_scan_platdata() - Scan all platform data and bind drivers
*
* This scans all available platdata and creates drivers for each
*
* @pre_reloc_only: If true, bind only drivers with the DM_FLAG_PRE_RELOC
* flag. If false bind all drivers.
* @return 0 if OK, -ve on error
*/
int dm_scan_platdata(bool pre_reloc_only);
/**
* dm_scan_fdt() - Scan the device tree and bind drivers
*
* This scans the device tree and creates a driver for each node. Only
* the top-level subnodes are examined.
*
* @blob: Pointer to device tree blob
* @pre_reloc_only: If true, bind only drivers with the DM_FLAG_PRE_RELOC
* flag. If false bind all drivers.
* @return 0 if OK, -ve on error
*/
int dm_scan_fdt(const void *blob, bool pre_reloc_only);
/**
* dm_scan_fdt_node() - Scan the device tree and bind drivers for a node
*
* This scans the subnodes of a device tree node and and creates a driver
* for each one.
*
* @parent: Parent device for the devices that will be created
* @blob: Pointer to device tree blob
* @offset: Offset of node to scan
* @pre_reloc_only: If true, bind only drivers with the DM_FLAG_PRE_RELOC
* flag. If false bind all drivers.
* @return 0 if OK, -ve on error
*/
int dm_scan_fdt_node(struct udevice *parent, const void *blob, int offset,
bool pre_reloc_only);
/**
* dm_scan_other() - Scan for other devices
*
* Some devices may not be visible to Driver Model. This weak function can
* be provided by boards which wish to create their own devices
* programmaticaly. They should do this by calling device_bind() on each
* device.
*
* @pre_reloc_only: If true, bind only drivers with the DM_FLAG_PRE_RELOC
* flag. If false bind all drivers.
*/
int dm_scan_other(bool pre_reloc_only);
/**
* dm_init_and_scan() - Initialise Driver Model structures and scan for devices
*
* This function initialises the roots of the driver tree and uclass trees,
* then scans and binds available devices from platform data and the FDT.
* This calls dm_init() to set up Driver Model structures.
*
* @pre_reloc_only: If true, bind only drivers with the DM_FLAG_PRE_RELOC
* flag. If false bind all drivers.
* @return 0 if OK, -ve on error
*/
int dm_init_and_scan(bool pre_reloc_only);
/**
* dm_init() - Initialise Driver Model structures
*
* This function will initialize roots of driver tree and class tree.
* This needs to be called before anything uses the DM
*
* @return 0 if OK, -ve on error
*/
int dm_init(void);
/**
* dm_uninit - Uninitialise Driver Model structures
*
* All devices will be removed and unbound
* @return 0 if OK, -ve on error
*/
int dm_uninit(void);
#endif

215
u-boot/include/dm/test.h Normal file
View File

@@ -0,0 +1,215 @@
/*
* Copyright (c) 2013 Google, Inc.
*
* SPDX-License-Identifier: GPL-2.0+
*/
#ifndef __DM_TEST_H
#define __DM_TEST_H
#include <dm.h>
#include <test/test.h>
/**
* struct dm_test_cdata - configuration data for test instance
*
* @ping_add: Amonut to add each time we get a ping
* @base: Base address of this device
*/
struct dm_test_pdata {
int ping_add;
uint32_t base;
};
/**
* struct test_ops - Operations supported by the test device
*
* @ping: Ping operation
* @dev: Device to operate on
* @pingval: Value to ping the device with
* @pingret: Returns resulting value from driver
* @return 0 if OK, -ve on error
*/
struct test_ops {
int (*ping)(struct udevice *dev, int pingval, int *pingret);
};
/* Operations that our test driver supports */
enum {
DM_TEST_OP_BIND = 0,
DM_TEST_OP_UNBIND,
DM_TEST_OP_PROBE,
DM_TEST_OP_REMOVE,
/* For uclass */
DM_TEST_OP_POST_BIND,
DM_TEST_OP_PRE_UNBIND,
DM_TEST_OP_PRE_PROBE,
DM_TEST_OP_POST_PROBE,
DM_TEST_OP_PRE_REMOVE,
DM_TEST_OP_INIT,
DM_TEST_OP_DESTROY,
DM_TEST_OP_COUNT,
};
/* Test driver types */
enum {
DM_TEST_TYPE_FIRST = 0,
DM_TEST_TYPE_SECOND,
};
/* The number added to the ping total on each probe */
#define DM_TEST_START_TOTAL 5
/**
* struct dm_test_priv - private data for the test devices
*/
struct dm_test_priv {
int ping_total;
int op_count[DM_TEST_OP_COUNT];
int uclass_flag;
int uclass_total;
};
/**
* struct dm_test_perdev_class_priv - private per-device data for test uclass
*/
struct dm_test_uclass_perdev_priv {
int base_add;
};
/**
* struct dm_test_uclass_priv - private data for test uclass
*/
struct dm_test_uclass_priv {
int total_add;
};
/**
* struct dm_test_parent_data - parent's information on each child
*
* @sum: Test value used to check parent data works correctly
* @flag: Used to track calling of parent operations
* @uclass_flag: Used to track calling of parent operations by uclass
*/
struct dm_test_parent_data {
int sum;
int flag;
};
/* Test values for test device's uclass platform data */
enum {
TEST_UC_PDATA_INTVAL1 = 2,
TEST_UC_PDATA_INTVAL2 = 334,
TEST_UC_PDATA_INTVAL3 = 789452,
};
/**
* struct dm_test_uclass_platda - uclass's information on each device
*
* @intval1: set to TEST_UC_PDATA_INTVAL1 in .post_bind method of test uclass
* @intval2: set to TEST_UC_PDATA_INTVAL2 in .post_bind method of test uclass
* @intval3: set to TEST_UC_PDATA_INTVAL3 in .post_bind method of test uclass
*/
struct dm_test_perdev_uc_pdata {
int intval1;
int intval2;
int intval3;
};
/*
* Operation counts for the test driver, used to check that each method is
* called correctly
*/
extern int dm_testdrv_op_count[DM_TEST_OP_COUNT];
extern struct unit_test_state global_dm_test_state;
/*
* struct dm_test_state - Entire state of dm test system
*
* This is often abreviated to dms.
*
* @root: Root device
* @testdev: Test device
* @force_fail_alloc: Force all memory allocs to fail
* @skip_post_probe: Skip uclass post-probe processing
* @removed: Used to keep track of a device that was removed
*/
struct dm_test_state {
struct udevice *root;
struct udevice *testdev;
int force_fail_alloc;
int skip_post_probe;
struct udevice *removed;
};
/* Test flags for each test */
enum {
DM_TESTF_SCAN_PDATA = 1 << 0, /* test needs platform data */
DM_TESTF_PROBE_TEST = 1 << 1, /* probe test uclass */
DM_TESTF_SCAN_FDT = 1 << 2, /* scan device tree */
};
/* Declare a new driver model test */
#define DM_TEST(_name, _flags) UNIT_TEST(_name, _flags, dm_test)
/* This platform data is needed in tests, so declare it here */
struct sandbox_sdl_plat {
int xres;
int yres;
int bpix;
int rot;
const char *vidconsole_drv_name;
int font_size;
};
/* Declare ping methods for the drivers */
int test_ping(struct udevice *dev, int pingval, int *pingret);
int testfdt_ping(struct udevice *dev, int pingval, int *pingret);
/**
* dm_check_operations() - Check that we can perform ping operations
*
* This checks that the ping operations work as expected for a device
*
* @dms: Overall test state
* @dev: Device to test
* @base: Base address, used to check ping return value
* @priv: Pointer to private test information
* @return 0 if OK, -ve on error
*/
int dm_check_operations(struct unit_test_state *uts, struct udevice *dev,
uint32_t base, struct dm_test_priv *priv);
/**
* dm_check_devices() - check the devices respond to operations correctly
*
* @dms: Overall test state
* @num_devices: Number of test devices to check
* @return 0 if OK, -ve on error
*/
int dm_check_devices(struct unit_test_state *uts, int num_devices);
/**
* dm_leak_check_start() - Prepare to check for a memory leak
*
* Call this before allocating memory to record the amount of memory being
* used.
*
* @dms: Overall test state
*/
void dm_leak_check_start(struct unit_test_state *uts);
/**
* dm_leak_check_end() - Check that no memory has leaked
*
* Call this after dm_leak_check_start() and after you have hopefuilly freed
* all the memory that was allocated. This function will print an error if
* it sees a different amount of total memory allocated than before.
*
* @dms: Overall test state
*/int dm_leak_check_end(struct unit_test_state *uts);
#endif

View File

@@ -0,0 +1,89 @@
/*
* Copyright (c) 2013 Google, Inc
*
* (C) Copyright 2012
* Pavel Herrmann <morpheus.ibis@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0+
*/
#ifndef _DM_UCLASS_ID_H
#define _DM_UCLASS_ID_H
/* TODO(sjg@chromium.org): this could be compile-time generated */
enum uclass_id {
/* These are used internally by driver model */
UCLASS_ROOT = 0,
UCLASS_DEMO,
UCLASS_TEST,
UCLASS_TEST_FDT,
UCLASS_TEST_BUS,
UCLASS_SPI_EMUL, /* sandbox SPI device emulator */
UCLASS_I2C_EMUL, /* sandbox I2C device emulator */
UCLASS_PCI_EMUL, /* sandbox PCI device emulator */
UCLASS_USB_EMUL, /* sandbox USB bus device emulator */
UCLASS_SIMPLE_BUS, /* bus with child devices */
/* U-Boot uclasses start here - in alphabetical order */
UCLASS_ADC, /* Analog-to-digital converter */
UCLASS_AHCI, /* SATA disk controller */
UCLASS_BLK, /* Block device */
UCLASS_CLK, /* Clock source, e.g. used by peripherals */
UCLASS_CPU, /* CPU, typically part of an SoC */
UCLASS_CROS_EC, /* Chrome OS EC */
UCLASS_DISPLAY, /* Display (e.g. DisplayPort, HDMI) */
UCLASS_DMA, /* Direct Memory Access */
UCLASS_RAM, /* RAM controller */
UCLASS_ETH, /* Ethernet device */
UCLASS_GPIO, /* Bank of general-purpose I/O pins */
UCLASS_I2C, /* I2C bus */
UCLASS_I2C_EEPROM, /* I2C EEPROM device */
UCLASS_I2C_GENERIC, /* Generic I2C device */
UCLASS_I2C_MUX, /* I2C multiplexer */
UCLASS_IRQ, /* Interrupt controller */
UCLASS_KEYBOARD, /* Keyboard input device */
UCLASS_LED, /* Light-emitting diode (LED) */
UCLASS_LPC, /* x86 'low pin count' interface */
UCLASS_MAILBOX, /* Mailbox controller */
UCLASS_MASS_STORAGE, /* Mass storage device */
UCLASS_MISC, /* Miscellaneous device */
UCLASS_MMC, /* SD / MMC card or chip */
UCLASS_MOD_EXP, /* RSA Mod Exp device */
UCLASS_MTD, /* Memory Technology Device (MTD) device */
UCLASS_NORTHBRIDGE, /* Intel Northbridge / SDRAM controller */
UCLASS_PANEL, /* Display panel, such as an LCD */
UCLASS_PANEL_BACKLIGHT, /* Backlight controller for panel */
UCLASS_PCH, /* x86 platform controller hub */
UCLASS_PCI, /* PCI bus */
UCLASS_PCI_GENERIC, /* Generic PCI bus device */
UCLASS_PINCTRL, /* Pinctrl (pin muxing/configuration) device */
UCLASS_PINCONFIG, /* Pin configuration node device */
UCLASS_PMIC, /* PMIC I/O device */
UCLASS_PWM, /* Pulse-width modulator */
UCLASS_PWRSEQ, /* Power sequence device */
UCLASS_REGULATOR, /* Regulator device */
UCLASS_REMOTEPROC, /* Remote Processor device */
UCLASS_RESET, /* Reset controller device */
UCLASS_RTC, /* Real time clock device */
UCLASS_SERIAL, /* Serial UART */
UCLASS_SPI, /* SPI bus */
UCLASS_SPMI, /* System Power Management Interface bus */
UCLASS_SPI_FLASH, /* SPI flash */
UCLASS_SPI_GENERIC, /* Generic SPI flash target */
UCLASS_SYSCON, /* System configuration device */
UCLASS_SYSRESET, /* System reset device */
UCLASS_THERMAL, /* Thermal sensor */
UCLASS_TIMER, /* Timer device */
UCLASS_TPM, /* Trusted Platform Module TIS interface */
UCLASS_USB, /* USB bus */
UCLASS_USB_DEV_GENERIC, /* USB generic device */
UCLASS_USB_HUB, /* USB hub */
UCLASS_VIDEO, /* Video or LCD device */
UCLASS_VIDEO_BRIDGE, /* Video bridge, e.g. DisplayPort to LVDS */
UCLASS_VIDEO_CONSOLE, /* Text console driver for video device */
UCLASS_COUNT,
UCLASS_INVALID = -1,
};
#endif

View File

@@ -0,0 +1,196 @@
/*
* Copyright (c) 2013 Google, Inc
*
* (C) Copyright 2012
* Pavel Herrmann <morpheus.ibis@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0+
*/
#ifndef _DM_UCLASS_INTERNAL_H
#define _DM_UCLASS_INTERNAL_H
/**
* uclass_get_device_tail() - handle the end of a get_device call
*
* This handles returning an error or probing a device as needed.
*
* @dev: Device that needs to be probed
* @ret: Error to return. If non-zero then the device is not probed
* @devp: Returns the value of 'dev' if there is no error
* @return ret, if non-zero, else the result of the device_probe() call
*/
int uclass_get_device_tail(struct udevice *dev, int ret, struct udevice **devp);
/**
* uclass_find_device() - Return n-th child of uclass
* @id: Id number of the uclass
* @index: Position of the child in uclass's list
* #devp: Returns pointer to device, or NULL on error
*
* The device is not prepared for use - this is an internal function.
* The function uclass_get_device_tail() can be used to probe the device.
*
* @return the uclass pointer of a child at the given index or
* return NULL on error.
*/
int uclass_find_device(enum uclass_id id, int index, struct udevice **devp);
/**
* uclass_find_first_device() - Return the first device in a uclass
* @id: Id number of the uclass
* #devp: Returns pointer to device, or NULL on error
*
* The device is not prepared for use - this is an internal function.
* The function uclass_get_device_tail() can be used to probe the device.
*
* @return 0 if OK (found or not found), -1 on error
*/
int uclass_find_first_device(enum uclass_id id, struct udevice **devp);
/**
* uclass_find_next_device() - Return the next device in a uclass
* @devp: On entry, pointer to device to lookup. On exit, returns pointer
* to the next device in the same uclass, or NULL if none
*
* The device is not prepared for use - this is an internal function.
* The function uclass_get_device_tail() can be used to probe the device.
*
* @return 0 if OK (found or not found), -1 on error
*/
int uclass_find_next_device(struct udevice **devp);
/**
* uclass_find_device_by_name() - Find uclass device based on ID and name
*
* This searches for a device with the exactly given name.
*
* The device is NOT probed, it is merely returned.
*
* @id: ID to look up
* @name: name of a device to find
* @devp: Returns pointer to device (the first one with the name)
* @return 0 if OK, -ve on error
*/
int uclass_find_device_by_name(enum uclass_id id, const char *name,
struct udevice **devp);
/**
* uclass_find_device_by_seq() - Find uclass device based on ID and sequence
*
* This searches for a device with the given seq or req_seq.
*
* For seq, if an active device has this sequence it will be returned.
* If there is no such device then this will return -ENODEV.
*
* For req_seq, if a device (whether activated or not) has this req_seq
* value, that device will be returned. This is a strong indication that
* the device will receive that sequence when activated.
*
* The device is NOT probed, it is merely returned.
*
* @id: ID to look up
* @seq_or_req_seq: Sequence number to find (0=first)
* @find_req_seq: true to find req_seq, false to find seq
* @devp: Returns pointer to device (there is only one per for each seq)
* @return 0 if OK, -ve on error
*/
int uclass_find_device_by_seq(enum uclass_id id, int seq_or_req_seq,
bool find_req_seq, struct udevice **devp);
/**
* uclass_find_device_by_of_offset() - 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 -ve 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_of_offset(enum uclass_id id, int node,
struct udevice **devp);
/**
* uclass_bind_device() - Associate device with a uclass
*
* Connect the device into uclass's list of devices.
*
* @dev: Pointer to the device
* #return 0 on success, -ve on error
*/
int uclass_bind_device(struct udevice *dev);
/**
* uclass_unbind_device() - Deassociate device with a uclass
*
* Disconnect the device from uclass's list of devices.
*
* @dev: Pointer to the device
* #return 0 on success, -ve on error
*/
#if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
int uclass_unbind_device(struct udevice *dev);
#else
static inline int uclass_unbind_device(struct udevice *dev) { return 0; }
#endif
/**
* uclass_pre_probe_device() - Deal with a device that is about to be probed
*
* Perform any pre-processing that is needed by the uclass before it can be
* probed. This includes the uclass' pre-probe() method and the parent
* uclass' child_pre_probe() method.
*
* @dev: Pointer to the device
* #return 0 on success, -ve on error
*/
int uclass_pre_probe_device(struct udevice *dev);
/**
* uclass_post_probe_device() - Deal with a device that has just been probed
*
* Perform any post-processing of a probed device that is needed by the
* uclass.
*
* @dev: Pointer to the device
* #return 0 on success, -ve on error
*/
int uclass_post_probe_device(struct udevice *dev);
/**
* uclass_pre_remove_device() - Handle a device which is about to be removed
*
* Perform any pre-processing of a device that is about to be removed.
*
* @dev: Pointer to the device
* #return 0 on success, -ve on error
*/
#if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
int uclass_pre_remove_device(struct udevice *dev);
#else
static inline int uclass_pre_remove_device(struct udevice *dev) { return 0; }
#endif
/**
* uclass_find() - Find uclass by its id
*
* @id: Id to serach for
* @return pointer to uclass, or NULL if not found
*/
struct uclass *uclass_find(enum uclass_id key);
/**
* uclass_destroy() - Destroy a uclass
*
* Destroy a uclass and all its devices
*
* @uc: uclass to destroy
* @return 0 on success, -ve on error
*/
int uclass_destroy(struct uclass *uc);
#endif

272
u-boot/include/dm/uclass.h Normal file
View File

@@ -0,0 +1,272 @@
/*
* Copyright (c) 2013 Google, Inc
*
* (C) Copyright 2012
* Pavel Herrmann <morpheus.ibis@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0+
*/
#ifndef _DM_UCLASS_H
#define _DM_UCLASS_H
#include <dm/uclass-id.h>
#include <linker_lists.h>
#include <linux/list.h>
/**
* struct uclass - a U-Boot drive class, collecting together similar drivers
*
* A uclass provides an interface to a particular function, which is
* implemented by one or more drivers. Every driver belongs to a uclass even
* if it is the only driver in that uclass. An example uclass is GPIO, which
* provides the ability to change read inputs, set and clear outputs, etc.
* There may be drivers for on-chip SoC GPIO banks, I2C GPIO expanders and
* PMIC IO lines, all made available in a unified way through the uclass.
*
* @priv: Private data for this uclass
* @uc_drv: The driver for the uclass itself, not to be confused with a
* 'struct driver'
* @dev_head: List of devices in this uclass (devices are attached to their
* uclass when their bind method is called)
* @sibling_node: Next uclass in the linked list of uclasses
*/
struct uclass {
void *priv;
struct uclass_driver *uc_drv;
struct list_head dev_head;
struct list_head sibling_node;
};
struct udevice;
/* Members of this uclass sequence themselves with aliases */
#define DM_UC_FLAG_SEQ_ALIAS (1 << 0)
/**
* struct uclass_driver - Driver for the uclass
*
* A uclass_driver provides a consistent interface to a set of related
* drivers.
*
* @name: Name of uclass driver
* @id: ID number of this uclass
* @post_bind: Called after a new device is bound to this uclass
* @pre_unbind: Called before a device is unbound from this uclass
* @pre_probe: Called before a new device is probed
* @post_probe: Called after a new device is probed
* @pre_remove: Called before a device is removed
* @child_post_bind: Called after a child is bound to a device in this uclass
* @init: Called to set up the uclass
* @destroy: Called to destroy the uclass
* @priv_auto_alloc_size: If non-zero this is the size of the private data
* to be allocated in the uclass's ->priv pointer. If zero, then the uclass
* driver is responsible for allocating any data required.
* @per_device_auto_alloc_size: Each device can hold private data owned
* by the uclass. If required this will be automatically allocated if this
* value is non-zero.
* @per_device_platdata_auto_alloc_size: Each device can hold platform data
* owned by the uclass as 'dev->uclass_platdata'. If the value is non-zero,
* then this will be automatically allocated.
* @per_child_auto_alloc_size: Each child device (of a parent in this
* uclass) can hold parent data for the device/uclass. This value is only
* used as a falback if this member is 0 in the driver.
* @per_child_platdata_auto_alloc_size: A bus likes to store information about
* its children. If non-zero this is the size of this data, to be allocated
* in the child device's parent_platdata pointer. This value is only used as
* a falback if this member is 0 in the driver.
* @ops: Uclass operations, providing the consistent interface to devices
* within the uclass.
* @flags: Flags for this uclass (DM_UC_...)
*/
struct uclass_driver {
const char *name;
enum uclass_id id;
int (*post_bind)(struct udevice *dev);
int (*pre_unbind)(struct udevice *dev);
int (*pre_probe)(struct udevice *dev);
int (*post_probe)(struct udevice *dev);
int (*pre_remove)(struct udevice *dev);
int (*child_post_bind)(struct udevice *dev);
int (*child_pre_probe)(struct udevice *dev);
int (*init)(struct uclass *class);
int (*destroy)(struct uclass *class);
int priv_auto_alloc_size;
int per_device_auto_alloc_size;
int per_device_platdata_auto_alloc_size;
int per_child_auto_alloc_size;
int per_child_platdata_auto_alloc_size;
const void *ops;
uint32_t flags;
};
/* Declare a new uclass_driver */
#define UCLASS_DRIVER(__name) \
ll_entry_declare(struct uclass_driver, __name, uclass)
/**
* uclass_get() - Get a uclass based on an ID, creating it if needed
*
* Every uclass is identified by an ID, a number from 0 to n-1 where n is
* the number of uclasses. This function allows looking up a uclass by its
* ID.
*
* @key: ID to look up
* @ucp: Returns pointer to uclass (there is only one per ID)
* @return 0 if OK, -ve on error
*/
int uclass_get(enum uclass_id key, struct uclass **ucp);
/**
* uclass_get_device() - Get a uclass device based on an ID and index
*
* The device is probed to activate it ready for use.
*
* @id: ID to look up
* @index: Device number within that uclass (0=first)
* @devp: Returns pointer to device (there is only one per for each ID)
* @return 0 if OK, -ve on error
*/
int uclass_get_device(enum uclass_id id, int index, struct udevice **devp);
/**
* uclass_get_device_by_name() - Get a uclass device by its name
*
* This searches the devices in the uclass for one with the exactly given name.
*
* The device is probed to activate it ready for use.
*
* @id: ID to look up
* @name: name of a device to get
* @devp: Returns pointer to device (the first one with the name)
* @return 0 if OK, -ve on error
*/
int uclass_get_device_by_name(enum uclass_id id, const char *name,
struct udevice **devp);
/**
* uclass_get_device_by_seq() - Get a uclass device based on an ID and sequence
*
* If an active device has this sequence it will be returned. If there is no
* such device then this will check for a device that is requesting this
* sequence.
*
* The device is probed to activate it ready for use.
*
* @id: ID to look up
* @seq: Sequence number to find (0=first)
* @devp: Returns pointer to device (there is only one for each seq)
* @return 0 if OK, -ve on error
*/
int uclass_get_device_by_seq(enum uclass_id id, int seq, struct udevice **devp);
/**
* uclass_get_device_by_of_offset() - 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
* @node: Device tree offset to search for (if -ve 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_of_offset(enum uclass_id id, int node,
struct udevice **devp);
/**
* uclass_get_device_by_phandle() - Get a uclass device by phandle
*
* This searches the devices in the uclass for one with the given phandle.
*
* The device is probed to activate it ready for use.
*
* @id: uclass ID to look up
* @parent: Parent device containing the phandle pointer
* @name: Name of property in the parent device node
* @devp: Returns pointer to device (there is only one for each node)
* @return 0 if OK, -ENOENT if there is no @name present in the node, other
* -ve on error
*/
int uclass_get_device_by_phandle(enum uclass_id id, struct udevice *parent,
const char *name, struct udevice **devp);
/**
* uclass_first_device() - Get the first device in a uclass
*
* The device returned is probed if necessary, and ready for use
*
* @id: Uclass ID to look up
* @devp: Returns pointer to the first device in that uclass, or NULL if none
* @return 0 if OK (found or not found), other -ve on error
*/
int uclass_first_device(enum uclass_id id, struct udevice **devp);
/**
* uclass_first_device_err() - Get the first device in a uclass
*
* The device returned is probed if necessary, and ready for use
*
* @id: Uclass ID to look up
* @devp: Returns pointer to the first device in that uclass, or NULL if none
* @return 0 if found, -ENODEV if not found, other -ve on error
*/
int uclass_first_device_err(enum uclass_id id, struct udevice **devp);
/**
* uclass_next_device() - Get the next device in a uclass
*
* The device returned is probed if necessary, and ready for use
*
* @devp: On entry, pointer to device to lookup. On exit, returns pointer
* to the next device in the same uclass, or NULL if none
* @return 0 if OK (found or not found), other -ve on error
*/
int uclass_next_device(struct udevice **devp);
/**
* uclass_resolve_seq() - Resolve a device's sequence number
*
* On entry dev->seq is -1, and dev->req_seq may be -1 (to allocate a
* sequence number automatically, or >= 0 to select a particular number.
* If the requested sequence number is in use, then this device will
* be allocated another one.
*
* Note that the device's seq value is not changed by this function.
*
* @dev: Device for which to allocate sequence number
* @return sequence number allocated, or -ve on error
*/
int uclass_resolve_seq(struct udevice *dev);
/**
* uclass_foreach_dev() - Helper function to iteration through devices
*
* This creates a for() loop which works through the available devices in
* a uclass in order from start to end.
*
* @pos: struct udevice * to hold the current device. Set to NULL when there
* are no more devices.
* @uc: uclass to scan
*/
#define uclass_foreach_dev(pos, uc) \
list_for_each_entry(pos, &uc->dev_head, uclass_node)
/**
* uclass_foreach_dev_safe() - Helper function to safely iteration through devs
*
* This creates a for() loop which works through the available devices in
* a uclass in order from start to end. Inside the loop, it is safe to remove
* @pos if required.
*
* @pos: struct udevice * to hold the current device. Set to NULL when there
* are no more devices.
* @next: struct udevice * to hold the next next
* @uc: uclass to scan
*/
#define uclass_foreach_dev_safe(pos, next, uc) \
list_for_each_entry_safe(pos, next, &uc->dev_head, uclass_node)
#endif

51
u-boot/include/dm/util.h Normal file
View File

@@ -0,0 +1,51 @@
/*
* Copyright (c) 2013 Google, Inc
*
* SPDX-License-Identifier: GPL-2.0+
*/
#ifndef __DM_UTIL_H
#define __DM_UTIL_H
#ifdef CONFIG_DM_WARN
void dm_warn(const char *fmt, ...);
#else
static inline void dm_warn(const char *fmt, ...)
{
}
#endif
#ifdef DEBUG
void dm_dbg(const char *fmt, ...);
#else
static inline void dm_dbg(const char *fmt, ...)
{
}
#endif
struct list_head;
/**
* list_count_items() - Count number of items in a list
*
* @param head: Head of list
* @return number of items, or 0 if empty
*/
int list_count_items(struct list_head *head);
/* Dump out a tree of all devices */
void dm_dump_all(void);
/* Dump out a list of uclasses and their devices */
void dm_dump_uclass(void);
#ifdef CONFIG_DEBUG_DEVRES
/* Dump out a list of device resources */
void dm_dump_devres(void);
#else
static inline void dm_dump_devres(void)
{
}
#endif
#endif