xref: /rk3399_rockchip-uboot/include/dm/device.h (revision 69b41388ba45b853b3538f5b8cac8ab2154d36d8)
16494d708SSimon Glass /*
26494d708SSimon Glass  * Copyright (c) 2013 Google, Inc
36494d708SSimon Glass  *
46494d708SSimon Glass  * (C) Copyright 2012
56494d708SSimon Glass  * Pavel Herrmann <morpheus.ibis@gmail.com>
66494d708SSimon Glass  * Marek Vasut <marex@denx.de>
76494d708SSimon Glass  *
86494d708SSimon Glass  * SPDX-License-Identifier:	GPL-2.0+
96494d708SSimon Glass  */
106494d708SSimon Glass 
116494d708SSimon Glass #ifndef _DM_DEVICE_H
126494d708SSimon Glass #define _DM_DEVICE_H
136494d708SSimon Glass 
146494d708SSimon Glass #include <dm/uclass-id.h>
15c9cac3f8SPeng Fan #include <fdtdec.h>
166494d708SSimon Glass #include <linker_lists.h>
172b07f685SMasahiro Yamada #include <linux/compat.h>
182b07f685SMasahiro Yamada #include <linux/kernel.h>
196494d708SSimon Glass #include <linux/list.h>
206494d708SSimon Glass 
216494d708SSimon Glass struct driver_info;
226494d708SSimon Glass 
236494d708SSimon Glass /* Driver is active (probed). Cleared when it is removed */
246494d708SSimon Glass #define DM_FLAG_ACTIVATED		(1 << 0)
256494d708SSimon Glass 
266494d708SSimon Glass /* DM is responsible for allocating and freeing platdata */
27f2bc6fc3SSimon Glass #define DM_FLAG_ALLOC_PDATA		(1 << 1)
286494d708SSimon Glass 
2900606d7eSSimon Glass /* DM should init this device prior to relocation */
3000606d7eSSimon Glass #define DM_FLAG_PRE_RELOC		(1 << 2)
3100606d7eSSimon Glass 
32cdc133bdSSimon Glass /* DM is responsible for allocating and freeing parent_platdata */
33cdc133bdSSimon Glass #define DM_FLAG_ALLOC_PARENT_PDATA	(1 << 3)
34cdc133bdSSimon Glass 
355eaed880SPrzemyslaw Marczak /* DM is responsible for allocating and freeing uclass_platdata */
365eaed880SPrzemyslaw Marczak #define DM_FLAG_ALLOC_UCLASS_PDATA	(1 << 4)
375eaed880SPrzemyslaw Marczak 
382c03c463SSimon Glass /* Allocate driver private data on a DMA boundary */
395eaed880SPrzemyslaw Marczak #define DM_FLAG_ALLOC_PRIV_DMA		(1 << 5)
402c03c463SSimon Glass 
41aed1a4ddSMasahiro Yamada /* Device is bound */
42aed1a4ddSMasahiro Yamada #define DM_FLAG_BOUND			(1 << 6)
43aed1a4ddSMasahiro Yamada 
446494d708SSimon Glass /**
4554c5d08aSHeiko Schocher  * struct udevice - An instance of a driver
466494d708SSimon Glass  *
476494d708SSimon Glass  * This holds information about a device, which is a driver bound to a
486494d708SSimon Glass  * particular port or peripheral (essentially a driver instance).
496494d708SSimon Glass  *
506494d708SSimon Glass  * A device will come into existence through a 'bind' call, either due to
516494d708SSimon Glass  * a U_BOOT_DEVICE() macro (in which case platdata is non-NULL) or a node
526494d708SSimon Glass  * in the device tree (in which case of_offset is >= 0). In the latter case
536494d708SSimon Glass  * we translate the device tree information into platdata in a function
546494d708SSimon Glass  * implemented by the driver ofdata_to_platdata method (called just before the
556494d708SSimon Glass  * probe method if the device has a device tree node.
566494d708SSimon Glass  *
576494d708SSimon Glass  * All three of platdata, priv and uclass_priv can be allocated by the
586494d708SSimon Glass  * driver, or you can use the auto_alloc_size members of struct driver and
596494d708SSimon Glass  * struct uclass_driver to have driver model do this automatically.
606494d708SSimon Glass  *
616494d708SSimon Glass  * @driver: The driver used by this device
626494d708SSimon Glass  * @name: Name of device, typically the FDT node name
636494d708SSimon Glass  * @platdata: Configuration data for this device
64cdc133bdSSimon Glass  * @parent_platdata: The parent bus's configuration data for this device
655eaed880SPrzemyslaw Marczak  * @uclass_platdata: The uclass's configuration data for this device
666494d708SSimon Glass  * @of_offset: Device tree node offset for this device (- for none)
6739de8433SSimon Glass  * @driver_data: Driver data word for the entry that matched this device with
6839de8433SSimon Glass  *		its driver
696494d708SSimon Glass  * @parent: Parent of this device, or NULL for the top level device
706494d708SSimon Glass  * @priv: Private data for this device
716494d708SSimon Glass  * @uclass: Pointer to uclass for this device
726494d708SSimon Glass  * @uclass_priv: The uclass's private data for this device
73e59f458dSSimon Glass  * @parent_priv: The parent's private data for this device
746494d708SSimon Glass  * @uclass_node: Used by uclass to link its devices
756494d708SSimon Glass  * @child_head: List of children of this device
766494d708SSimon Glass  * @sibling_node: Next device in list of all devices
776494d708SSimon Glass  * @flags: Flags for this device DM_FLAG_...
785a66a8ffSSimon Glass  * @req_seq: Requested sequence number for this device (-1 = any)
79547cea19SSimon Glass  * @seq: Allocated sequence number for this device (-1 = none). This is set up
80547cea19SSimon Glass  * when the device is probed and will be unique within the device's uclass.
8193c7fe4aSSimon Glass  * @devres_head: List of memory allocations associated with this device.
8293c7fe4aSSimon Glass  *		When CONFIG_DEVRES is enabled, devm_kmalloc() and friends will
8393c7fe4aSSimon Glass  *		add to this list. Memory so-allocated will be freed
8493c7fe4aSSimon Glass  *		automatically when the device is removed / unbound
856494d708SSimon Glass  */
8654c5d08aSHeiko Schocher struct udevice {
873479253dSSimon Glass 	const struct driver *driver;
886494d708SSimon Glass 	const char *name;
896494d708SSimon Glass 	void *platdata;
90cdc133bdSSimon Glass 	void *parent_platdata;
915eaed880SPrzemyslaw Marczak 	void *uclass_platdata;
926494d708SSimon Glass 	int of_offset;
9339de8433SSimon Glass 	ulong driver_data;
9454c5d08aSHeiko Schocher 	struct udevice *parent;
956494d708SSimon Glass 	void *priv;
966494d708SSimon Glass 	struct uclass *uclass;
976494d708SSimon Glass 	void *uclass_priv;
98e59f458dSSimon Glass 	void *parent_priv;
996494d708SSimon Glass 	struct list_head uclass_node;
1006494d708SSimon Glass 	struct list_head child_head;
1016494d708SSimon Glass 	struct list_head sibling_node;
1026494d708SSimon Glass 	uint32_t flags;
1035a66a8ffSSimon Glass 	int req_seq;
1045a66a8ffSSimon Glass 	int seq;
105e2282d70SMasahiro Yamada #ifdef CONFIG_DEVRES
106608f26c5SMasahiro Yamada 	struct list_head devres_head;
107e2282d70SMasahiro Yamada #endif
1086494d708SSimon Glass };
1096494d708SSimon Glass 
1105a66a8ffSSimon Glass /* Maximum sequence number supported */
1115a66a8ffSSimon Glass #define DM_MAX_SEQ	999
1125a66a8ffSSimon Glass 
1136494d708SSimon Glass /* Returns the operations for a device */
1146494d708SSimon Glass #define device_get_ops(dev)	(dev->driver->ops)
1156494d708SSimon Glass 
1166494d708SSimon Glass /* Returns non-zero if the device is active (probed and not removed) */
1176494d708SSimon Glass #define device_active(dev)	((dev)->flags & DM_FLAG_ACTIVATED)
1186494d708SSimon Glass 
1196494d708SSimon Glass /**
120ae7f4513SSimon Glass  * struct udevice_id - Lists the compatible strings supported by a driver
1216494d708SSimon Glass  * @compatible: Compatible string
1226494d708SSimon Glass  * @data: Data for this compatible string
1236494d708SSimon Glass  */
124ae7f4513SSimon Glass struct udevice_id {
1256494d708SSimon Glass 	const char *compatible;
1266494d708SSimon Glass 	ulong data;
1276494d708SSimon Glass };
1286494d708SSimon Glass 
1290f925822SMasahiro Yamada #if CONFIG_IS_ENABLED(OF_CONTROL)
130f887cb6dSMasahiro Yamada #define of_match_ptr(_ptr)	(_ptr)
131f887cb6dSMasahiro Yamada #else
132f887cb6dSMasahiro Yamada #define of_match_ptr(_ptr)	NULL
1330f925822SMasahiro Yamada #endif /* CONFIG_IS_ENABLED(OF_CONTROL) */
134f887cb6dSMasahiro Yamada 
1356494d708SSimon Glass /**
1366494d708SSimon Glass  * struct driver - A driver for a feature or peripheral
1376494d708SSimon Glass  *
1386494d708SSimon Glass  * This holds methods for setting up a new device, and also removing it.
1396494d708SSimon Glass  * The device needs information to set itself up - this is provided either
1406494d708SSimon Glass  * by platdata or a device tree node (which we find by looking up
1416494d708SSimon Glass  * matching compatible strings with of_match).
1426494d708SSimon Glass  *
1436494d708SSimon Glass  * Drivers all belong to a uclass, representing a class of devices of the
1446494d708SSimon Glass  * same type. Common elements of the drivers can be implemented in the uclass,
1456494d708SSimon Glass  * or the uclass can provide a consistent interface to the drivers within
1466494d708SSimon Glass  * it.
1476494d708SSimon Glass  *
1486494d708SSimon Glass  * @name: Device name
1496494d708SSimon Glass  * @id: Identiies the uclass we belong to
1506494d708SSimon Glass  * @of_match: List of compatible strings to match, and any identifying data
1516494d708SSimon Glass  * for each.
1526494d708SSimon Glass  * @bind: Called to bind a device to its driver
1536494d708SSimon Glass  * @probe: Called to probe a device, i.e. activate it
1546494d708SSimon Glass  * @remove: Called to remove a device, i.e. de-activate it
1556494d708SSimon Glass  * @unbind: Called to unbind a device from its driver
1566494d708SSimon Glass  * @ofdata_to_platdata: Called before probe to decode device tree data
1570118ce79SSimon Glass  * @child_post_bind: Called after a new child has been bound
158a327dee0SSimon Glass  * @child_pre_probe: Called before a child device is probed. The device has
159a327dee0SSimon Glass  * memory allocated but it has not yet been probed.
160a327dee0SSimon Glass  * @child_post_remove: Called after a child device is removed. The device
161a327dee0SSimon Glass  * has memory allocated but its device_remove() method has been called.
1626494d708SSimon Glass  * @priv_auto_alloc_size: If non-zero this is the size of the private data
1636494d708SSimon Glass  * to be allocated in the device's ->priv pointer. If zero, then the driver
1646494d708SSimon Glass  * is responsible for allocating any data required.
1656494d708SSimon Glass  * @platdata_auto_alloc_size: If non-zero this is the size of the
1666494d708SSimon Glass  * platform data to be allocated in the device's ->platdata pointer.
1676494d708SSimon Glass  * This is typically only useful for device-tree-aware drivers (those with
1686494d708SSimon Glass  * an of_match), since drivers which use platdata will have the data
1696494d708SSimon Glass  * provided in the U_BOOT_DEVICE() instantiation.
170e59f458dSSimon Glass  * @per_child_auto_alloc_size: Each device can hold private data owned by
171e59f458dSSimon Glass  * its parent. If required this will be automatically allocated if this
172e59f458dSSimon Glass  * value is non-zero.
173cdc133bdSSimon Glass  * @per_child_platdata_auto_alloc_size: A bus likes to store information about
174cdc133bdSSimon Glass  * its children. If non-zero this is the size of this data, to be allocated
175cdc133bdSSimon Glass  * in the child's parent_platdata pointer.
1760040b944SSimon Glass  * @ops: Driver-specific operations. This is typically a list of function
1776494d708SSimon Glass  * pointers defined by the driver, to implement driver functions required by
1786494d708SSimon Glass  * the uclass.
17900606d7eSSimon Glass  * @flags: driver flags - see DM_FLAGS_...
1806494d708SSimon Glass  */
1816494d708SSimon Glass struct driver {
1826494d708SSimon Glass 	char *name;
1836494d708SSimon Glass 	enum uclass_id id;
184ae7f4513SSimon Glass 	const struct udevice_id *of_match;
18554c5d08aSHeiko Schocher 	int (*bind)(struct udevice *dev);
18654c5d08aSHeiko Schocher 	int (*probe)(struct udevice *dev);
18754c5d08aSHeiko Schocher 	int (*remove)(struct udevice *dev);
18854c5d08aSHeiko Schocher 	int (*unbind)(struct udevice *dev);
18954c5d08aSHeiko Schocher 	int (*ofdata_to_platdata)(struct udevice *dev);
1900118ce79SSimon Glass 	int (*child_post_bind)(struct udevice *dev);
191a327dee0SSimon Glass 	int (*child_pre_probe)(struct udevice *dev);
192a327dee0SSimon Glass 	int (*child_post_remove)(struct udevice *dev);
1936494d708SSimon Glass 	int priv_auto_alloc_size;
1946494d708SSimon Glass 	int platdata_auto_alloc_size;
195e59f458dSSimon Glass 	int per_child_auto_alloc_size;
196cdc133bdSSimon Glass 	int per_child_platdata_auto_alloc_size;
1976494d708SSimon Glass 	const void *ops;	/* driver-specific operations */
19800606d7eSSimon Glass 	uint32_t flags;
1996494d708SSimon Glass };
2006494d708SSimon Glass 
2016494d708SSimon Glass /* Declare a new U-Boot driver */
2026494d708SSimon Glass #define U_BOOT_DRIVER(__name)						\
2036494d708SSimon Glass 	ll_entry_declare(struct driver, __name, driver)
2046494d708SSimon Glass 
2056494d708SSimon Glass /**
2066494d708SSimon Glass  * dev_get_platdata() - Get the platform data for a device
2076494d708SSimon Glass  *
2086494d708SSimon Glass  * This checks that dev is not NULL, but no other checks for now
2096494d708SSimon Glass  *
2106494d708SSimon Glass  * @dev		Device to check
2116494d708SSimon Glass  * @return platform data, or NULL if none
2126494d708SSimon Glass  */
21354c5d08aSHeiko Schocher void *dev_get_platdata(struct udevice *dev);
2146494d708SSimon Glass 
2156494d708SSimon Glass /**
216cdc133bdSSimon Glass  * dev_get_parent_platdata() - Get the parent platform data for a device
217cdc133bdSSimon Glass  *
218cdc133bdSSimon Glass  * This checks that dev is not NULL, but no other checks for now
219cdc133bdSSimon Glass  *
220cdc133bdSSimon Glass  * @dev		Device to check
221cdc133bdSSimon Glass  * @return parent's platform data, or NULL if none
222cdc133bdSSimon Glass  */
223cdc133bdSSimon Glass void *dev_get_parent_platdata(struct udevice *dev);
224cdc133bdSSimon Glass 
225cdc133bdSSimon Glass /**
2265eaed880SPrzemyslaw Marczak  * dev_get_uclass_platdata() - Get the uclass platform data for a device
2275eaed880SPrzemyslaw Marczak  *
2285eaed880SPrzemyslaw Marczak  * This checks that dev is not NULL, but no other checks for now
2295eaed880SPrzemyslaw Marczak  *
2305eaed880SPrzemyslaw Marczak  * @dev		Device to check
2315eaed880SPrzemyslaw Marczak  * @return uclass's platform data, or NULL if none
2325eaed880SPrzemyslaw Marczak  */
2335eaed880SPrzemyslaw Marczak void *dev_get_uclass_platdata(struct udevice *dev);
2345eaed880SPrzemyslaw Marczak 
2355eaed880SPrzemyslaw Marczak /**
2369a79f6e6SSimon Glass  * dev_get_priv() - Get the private data for a device
2379a79f6e6SSimon Glass  *
2389a79f6e6SSimon Glass  * This checks that dev is not NULL, but no other checks for now
2399a79f6e6SSimon Glass  *
2409a79f6e6SSimon Glass  * @dev		Device to check
2419a79f6e6SSimon Glass  * @return private data, or NULL if none
2429a79f6e6SSimon Glass  */
2439a79f6e6SSimon Glass void *dev_get_priv(struct udevice *dev);
2449a79f6e6SSimon Glass 
2459a79f6e6SSimon Glass /**
246bcbe3d15SSimon Glass  * dev_get_parent_priv() - Get the parent private data for a device
247e59f458dSSimon Glass  *
248bcbe3d15SSimon Glass  * The parent private data is data stored in the device but owned by the
249bcbe3d15SSimon Glass  * parent. For example, a USB device may have parent data which contains
250bcbe3d15SSimon Glass  * information about how to talk to the device over USB.
251e59f458dSSimon Glass  *
252e59f458dSSimon Glass  * This checks that dev is not NULL, but no other checks for now
253e59f458dSSimon Glass  *
254e59f458dSSimon Glass  * @dev		Device to check
255e59f458dSSimon Glass  * @return parent data, or NULL if none
256e59f458dSSimon Glass  */
257bcbe3d15SSimon Glass void *dev_get_parent_priv(struct udevice *dev);
258e59f458dSSimon Glass 
259e59f458dSSimon Glass /**
260e564f054SSimon Glass  * dev_get_uclass_priv() - Get the private uclass data for a device
261e564f054SSimon Glass  *
262e564f054SSimon Glass  * This checks that dev is not NULL, but no other checks for now
263e564f054SSimon Glass  *
264e564f054SSimon Glass  * @dev		Device to check
265e564f054SSimon Glass  * @return private uclass data for this device, or NULL if none
266e564f054SSimon Glass  */
267e564f054SSimon Glass void *dev_get_uclass_priv(struct udevice *dev);
268e564f054SSimon Glass 
269e564f054SSimon Glass /**
2709a79f6e6SSimon Glass  * struct dev_get_parent() - Get the parent of a device
2719a79f6e6SSimon Glass  *
2729a79f6e6SSimon Glass  * @child:	Child to check
2739a79f6e6SSimon Glass  * @return parent of child, or NULL if this is the root device
2749a79f6e6SSimon Glass  */
2759a79f6e6SSimon Glass struct udevice *dev_get_parent(struct udevice *child);
2769a79f6e6SSimon Glass 
2779a79f6e6SSimon Glass /**
27839de8433SSimon Glass  * dev_get_driver_data() - get the driver data used to bind a device
2792ef249b4SSimon Glass  *
2802ef249b4SSimon Glass  * When a device is bound using a device tree node, it matches a
2818d1f3a9dSSimon Glass  * particular compatible string in struct udevice_id. This function
28239de8433SSimon Glass  * returns the associated data value for that compatible string. This is
28339de8433SSimon Glass  * the 'data' field in struct udevice_id.
28439de8433SSimon Glass  *
2858d1f3a9dSSimon Glass  * As an example, consider this structure:
2868d1f3a9dSSimon Glass  * static const struct udevice_id tegra_i2c_ids[] = {
2878d1f3a9dSSimon Glass  *	{ .compatible = "nvidia,tegra114-i2c", .data = TYPE_114 },
2888d1f3a9dSSimon Glass  *	{ .compatible = "nvidia,tegra20-i2c", .data = TYPE_STD },
2898d1f3a9dSSimon Glass  *	{ .compatible = "nvidia,tegra20-i2c-dvc", .data = TYPE_DVC },
2908d1f3a9dSSimon Glass  *	{ }
2918d1f3a9dSSimon Glass  * };
2928d1f3a9dSSimon Glass  *
2938d1f3a9dSSimon Glass  * When driver model finds a driver for this it will store the 'data' value
2948d1f3a9dSSimon Glass  * corresponding to the compatible string it matches. This function returns
2958d1f3a9dSSimon Glass  * that value. This allows the driver to handle several variants of a device.
2968d1f3a9dSSimon Glass  *
29739de8433SSimon Glass  * For USB devices, this is the driver_info field in struct usb_device_id.
29839de8433SSimon Glass  *
29939de8433SSimon Glass  * @dev:	Device to check
3008d1f3a9dSSimon Glass  * @return driver data (0 if none is provided)
3012ef249b4SSimon Glass  */
30239de8433SSimon Glass ulong dev_get_driver_data(struct udevice *dev);
3032ef249b4SSimon Glass 
304cc73d37bSPrzemyslaw Marczak /**
305cc73d37bSPrzemyslaw Marczak  * dev_get_driver_ops() - get the device's driver's operations
306cc73d37bSPrzemyslaw Marczak  *
307cc73d37bSPrzemyslaw Marczak  * This checks that dev is not NULL, and returns the pointer to device's
308cc73d37bSPrzemyslaw Marczak  * driver's operations.
309cc73d37bSPrzemyslaw Marczak  *
310cc73d37bSPrzemyslaw Marczak  * @dev:	Device to check
311cc73d37bSPrzemyslaw Marczak  * @return void pointer to driver's operations or NULL for NULL-dev or NULL-ops
312cc73d37bSPrzemyslaw Marczak  */
313cc73d37bSPrzemyslaw Marczak const void *dev_get_driver_ops(struct udevice *dev);
314cc73d37bSPrzemyslaw Marczak 
3158d1f3a9dSSimon Glass /**
316b3670531SSimon Glass  * device_get_uclass_id() - return the uclass ID of a device
317b3670531SSimon Glass  *
318b3670531SSimon Glass  * @dev:	Device to check
319b3670531SSimon Glass  * @return uclass ID for the device
320b3670531SSimon Glass  */
321b3670531SSimon Glass enum uclass_id device_get_uclass_id(struct udevice *dev);
322b3670531SSimon Glass 
3238d1f3a9dSSimon Glass /**
324f9c370dcSPrzemyslaw Marczak  * dev_get_uclass_name() - return the uclass name of a device
325f9c370dcSPrzemyslaw Marczak  *
326f9c370dcSPrzemyslaw Marczak  * This checks that dev is not NULL.
327f9c370dcSPrzemyslaw Marczak  *
328f9c370dcSPrzemyslaw Marczak  * @dev:	Device to check
329f9c370dcSPrzemyslaw Marczak  * @return  pointer to the uclass name for the device
330f9c370dcSPrzemyslaw Marczak  */
331f9c370dcSPrzemyslaw Marczak const char *dev_get_uclass_name(struct udevice *dev);
332f9c370dcSPrzemyslaw Marczak 
3332ef249b4SSimon Glass /**
334997c87bbSSimon Glass  * device_get_child() - Get the child of a device by index
335997c87bbSSimon Glass  *
336997c87bbSSimon Glass  * Returns the numbered child, 0 being the first. This does not use
337997c87bbSSimon Glass  * sequence numbers, only the natural order.
338997c87bbSSimon Glass  *
339997c87bbSSimon Glass  * @dev:	Parent device to check
340997c87bbSSimon Glass  * @index:	Child index
341997c87bbSSimon Glass  * @devp:	Returns pointer to device
3423f416f33SSimon Glass  * @return 0 if OK, -ENODEV if no such device, other error if the device fails
3433f416f33SSimon Glass  *	   to probe
344997c87bbSSimon Glass  */
345997c87bbSSimon Glass int device_get_child(struct udevice *parent, int index, struct udevice **devp);
346997c87bbSSimon Glass 
347997c87bbSSimon Glass /**
3485a66a8ffSSimon Glass  * device_find_child_by_seq() - Find a child device based on a sequence
3495a66a8ffSSimon Glass  *
3505a66a8ffSSimon Glass  * This searches for a device with the given seq or req_seq.
3515a66a8ffSSimon Glass  *
3525a66a8ffSSimon Glass  * For seq, if an active device has this sequence it will be returned.
3535a66a8ffSSimon Glass  * If there is no such device then this will return -ENODEV.
3545a66a8ffSSimon Glass  *
3555a66a8ffSSimon Glass  * For req_seq, if a device (whether activated or not) has this req_seq
3565a66a8ffSSimon Glass  * value, that device will be returned. This is a strong indication that
3575a66a8ffSSimon Glass  * the device will receive that sequence when activated.
3585a66a8ffSSimon Glass  *
3595a66a8ffSSimon Glass  * @parent: Parent device
3605a66a8ffSSimon Glass  * @seq_or_req_seq: Sequence number to find (0=first)
3615a66a8ffSSimon Glass  * @find_req_seq: true to find req_seq, false to find seq
3625a66a8ffSSimon Glass  * @devp: Returns pointer to device (there is only one per for each seq).
3635a66a8ffSSimon Glass  * Set to NULL if none is found
3645a66a8ffSSimon Glass  * @return 0 if OK, -ve on error
3655a66a8ffSSimon Glass  */
3665a66a8ffSSimon Glass int device_find_child_by_seq(struct udevice *parent, int seq_or_req_seq,
3675a66a8ffSSimon Glass 			     bool find_req_seq, struct udevice **devp);
3685a66a8ffSSimon Glass 
369997c87bbSSimon Glass /**
370997c87bbSSimon Glass  * device_get_child_by_seq() - Get a child device based on a sequence
371997c87bbSSimon Glass  *
372997c87bbSSimon Glass  * If an active device has this sequence it will be returned. If there is no
373997c87bbSSimon Glass  * such device then this will check for a device that is requesting this
374997c87bbSSimon Glass  * sequence.
375997c87bbSSimon Glass  *
376997c87bbSSimon Glass  * The device is probed to activate it ready for use.
377997c87bbSSimon Glass  *
378997c87bbSSimon Glass  * @parent: Parent device
379997c87bbSSimon Glass  * @seq: Sequence number to find (0=first)
380997c87bbSSimon Glass  * @devp: Returns pointer to device (there is only one per for each seq)
381997c87bbSSimon Glass  * Set to NULL if none is found
382997c87bbSSimon Glass  * @return 0 if OK, -ve on error
383997c87bbSSimon Glass  */
384997c87bbSSimon Glass int device_get_child_by_seq(struct udevice *parent, int seq,
385997c87bbSSimon Glass 			    struct udevice **devp);
386997c87bbSSimon Glass 
387997c87bbSSimon Glass /**
388997c87bbSSimon Glass  * device_find_child_by_of_offset() - Find a child device based on FDT offset
389997c87bbSSimon Glass  *
390997c87bbSSimon Glass  * Locates a child device by its device tree offset.
391997c87bbSSimon Glass  *
392997c87bbSSimon Glass  * @parent: Parent device
393997c87bbSSimon Glass  * @of_offset: Device tree offset to find
394997c87bbSSimon Glass  * @devp: Returns pointer to device if found, otherwise this is set to NULL
395997c87bbSSimon Glass  * @return 0 if OK, -ve on error
396997c87bbSSimon Glass  */
397997c87bbSSimon Glass int device_find_child_by_of_offset(struct udevice *parent, int of_offset,
398997c87bbSSimon Glass 				   struct udevice **devp);
399997c87bbSSimon Glass 
400997c87bbSSimon Glass /**
401997c87bbSSimon Glass  * device_get_child_by_of_offset() - Get a child device based on FDT offset
402997c87bbSSimon Glass  *
403997c87bbSSimon Glass  * Locates a child device by its device tree offset.
404997c87bbSSimon Glass  *
405997c87bbSSimon Glass  * The device is probed to activate it ready for use.
406997c87bbSSimon Glass  *
407997c87bbSSimon Glass  * @parent: Parent device
408997c87bbSSimon Glass  * @of_offset: Device tree offset to find
409997c87bbSSimon Glass  * @devp: Returns pointer to device if found, otherwise this is set to NULL
410997c87bbSSimon Glass  * @return 0 if OK, -ve on error
411997c87bbSSimon Glass  */
412132f9bfcSSimon Glass int device_get_child_by_of_offset(struct udevice *parent, int of_offset,
413997c87bbSSimon Glass 				  struct udevice **devp);
414997c87bbSSimon Glass 
415a8981d4fSSimon Glass /**
4162693047aSSimon Glass  * device_get_global_by_of_offset() - Get a device based on FDT offset
4172693047aSSimon Glass  *
4182693047aSSimon Glass  * Locates a device by its device tree offset, searching globally throughout
4192693047aSSimon Glass  * the all driver model devices.
4202693047aSSimon Glass  *
4212693047aSSimon Glass  * The device is probed to activate it ready for use.
4222693047aSSimon Glass  *
4232693047aSSimon Glass  * @of_offset: Device tree offset to find
4242693047aSSimon Glass  * @devp: Returns pointer to device if found, otherwise this is set to NULL
4252693047aSSimon Glass  * @return 0 if OK, -ve on error
4262693047aSSimon Glass  */
4272693047aSSimon Glass int device_get_global_by_of_offset(int of_offset, struct udevice **devp);
4282693047aSSimon Glass 
4292693047aSSimon Glass /**
430a8981d4fSSimon Glass  * device_find_first_child() - Find the first child of a device
431a8981d4fSSimon Glass  *
432a8981d4fSSimon Glass  * @parent: Parent device to search
433a8981d4fSSimon Glass  * @devp: Returns first child device, or NULL if none
434a8981d4fSSimon Glass  * @return 0
435a8981d4fSSimon Glass  */
436a8981d4fSSimon Glass int device_find_first_child(struct udevice *parent, struct udevice **devp);
437a8981d4fSSimon Glass 
438a8981d4fSSimon Glass /**
4393f416f33SSimon Glass  * device_find_next_child() - Find the next child of a device
440a8981d4fSSimon Glass  *
441a8981d4fSSimon Glass  * @devp: Pointer to previous child device on entry. Returns pointer to next
442a8981d4fSSimon Glass  *		child device, or NULL if none
443a8981d4fSSimon Glass  * @return 0
444a8981d4fSSimon Glass  */
445a8981d4fSSimon Glass int device_find_next_child(struct udevice **devp);
446a8981d4fSSimon Glass 
447c9cac3f8SPeng Fan /**
448c9cac3f8SPeng Fan  * dev_get_addr() - Get the reg property of a device
449c9cac3f8SPeng Fan  *
450c9cac3f8SPeng Fan  * @dev: Pointer to a device
451c9cac3f8SPeng Fan  *
452c9cac3f8SPeng Fan  * @return addr
453c9cac3f8SPeng Fan  */
454c9cac3f8SPeng Fan fdt_addr_t dev_get_addr(struct udevice *dev);
455c9cac3f8SPeng Fan 
456c5785673SSimon Glass /**
457*69b41388SMugunthan V N  * dev_get_addr_index() - Get the indexed reg property of a device
458*69b41388SMugunthan V N  *
459*69b41388SMugunthan V N  * @dev: Pointer to a device
460*69b41388SMugunthan V N  * @index: the 'reg' property can hold a list of <addr, size> pairs
461*69b41388SMugunthan V N  *	   and @index is used to select which one is required
462*69b41388SMugunthan V N  *
463*69b41388SMugunthan V N  * @return addr
464*69b41388SMugunthan V N  */
465*69b41388SMugunthan V N fdt_addr_t dev_get_addr_index(struct udevice *dev, int index);
466*69b41388SMugunthan V N 
467*69b41388SMugunthan V N /**
468c5785673SSimon Glass  * device_has_children() - check if a device has any children
469c5785673SSimon Glass  *
470c5785673SSimon Glass  * @dev:	Device to check
471c5785673SSimon Glass  * @return true if the device has one or more children
472c5785673SSimon Glass  */
473c5785673SSimon Glass bool device_has_children(struct udevice *dev);
474c5785673SSimon Glass 
475c5785673SSimon Glass /**
476c5785673SSimon Glass  * device_has_active_children() - check if a device has any active children
477c5785673SSimon Glass  *
478c5785673SSimon Glass  * @dev:	Device to check
479c5785673SSimon Glass  * @return true if the device has one or more children and at least one of
480c5785673SSimon Glass  * them is active (probed).
481c5785673SSimon Glass  */
482c5785673SSimon Glass bool device_has_active_children(struct udevice *dev);
483c5785673SSimon Glass 
484c5785673SSimon Glass /**
485c5785673SSimon Glass  * device_is_last_sibling() - check if a device is the last sibling
486c5785673SSimon Glass  *
487c5785673SSimon Glass  * This function can be useful for display purposes, when special action needs
488c5785673SSimon Glass  * to be taken when displaying the last sibling. This can happen when a tree
489c5785673SSimon Glass  * view of devices is being displayed.
490c5785673SSimon Glass  *
491c5785673SSimon Glass  * @dev:	Device to check
492c5785673SSimon Glass  * @return true if there are no more siblings after this one - i.e. is it
493c5785673SSimon Glass  * last in the list.
494c5785673SSimon Glass  */
495c5785673SSimon Glass bool device_is_last_sibling(struct udevice *dev);
496c5785673SSimon Glass 
497f5c67ea0SSimon Glass /**
498f5c67ea0SSimon Glass  * device_set_name() - set the name of a device
499f5c67ea0SSimon Glass  *
500f5c67ea0SSimon Glass  * This must be called in the device's bind() method and no later. Normally
501f5c67ea0SSimon Glass  * this is unnecessary but for probed devices which don't get a useful name
502f5c67ea0SSimon Glass  * this function can be helpful.
503f5c67ea0SSimon Glass  *
504f5c67ea0SSimon Glass  * @dev:	Device to update
505f5c67ea0SSimon Glass  * @name:	New name (this string is allocated new memory and attached to
506f5c67ea0SSimon Glass  *		the device)
507f5c67ea0SSimon Glass  * @return 0 if OK, -ENOMEM if there is not enough memory to allocate the
508f5c67ea0SSimon Glass  * string
509f5c67ea0SSimon Glass  */
510f5c67ea0SSimon Glass int device_set_name(struct udevice *dev, const char *name);
511f5c67ea0SSimon Glass 
5121e0f2263SBin Meng /**
5131e0f2263SBin Meng  * device_is_on_pci_bus - Test if a device is on a PCI bus
5141e0f2263SBin Meng  *
5151e0f2263SBin Meng  * @dev:	device to test
5161e0f2263SBin Meng  * @return:	true if it is on a PCI bus, false otherwise
5171e0f2263SBin Meng  */
5181e0f2263SBin Meng static inline bool device_is_on_pci_bus(struct udevice *dev)
5191e0f2263SBin Meng {
5201e0f2263SBin Meng 	return device_get_uclass_id(dev->parent) == UCLASS_PCI;
5211e0f2263SBin Meng }
5221e0f2263SBin Meng 
5237aeac5bcSSimon Glass /**
5247aeac5bcSSimon Glass  * device_foreach_child_safe() - iterate through child devices safely
5257aeac5bcSSimon Glass  *
5267aeac5bcSSimon Glass  * This allows the @pos child to be removed in the loop if required.
5277aeac5bcSSimon Glass  *
5287aeac5bcSSimon Glass  * @pos: struct udevice * for the current device
5297aeac5bcSSimon Glass  * @next: struct udevice * for the next device
5307aeac5bcSSimon Glass  * @parent: parent device to scan
5317aeac5bcSSimon Glass  */
5327aeac5bcSSimon Glass #define device_foreach_child_safe(pos, next, parent)	\
5337aeac5bcSSimon Glass 	list_for_each_entry_safe(pos, next, &parent->child_head, sibling_node)
5347aeac5bcSSimon Glass 
535608f26c5SMasahiro Yamada /* device resource management */
536608f26c5SMasahiro Yamada typedef void (*dr_release_t)(struct udevice *dev, void *res);
537608f26c5SMasahiro Yamada typedef int (*dr_match_t)(struct udevice *dev, void *res, void *match_data);
538608f26c5SMasahiro Yamada 
539e2282d70SMasahiro Yamada #ifdef CONFIG_DEVRES
540e2282d70SMasahiro Yamada 
541608f26c5SMasahiro Yamada #ifdef CONFIG_DEBUG_DEVRES
542608f26c5SMasahiro Yamada void *__devres_alloc(dr_release_t release, size_t size, gfp_t gfp,
543608f26c5SMasahiro Yamada 		     const char *name);
544608f26c5SMasahiro Yamada #define _devres_alloc(release, size, gfp) \
545608f26c5SMasahiro Yamada 	__devres_alloc(release, size, gfp, #release)
546608f26c5SMasahiro Yamada #else
547608f26c5SMasahiro Yamada void *_devres_alloc(dr_release_t release, size_t size, gfp_t gfp);
548608f26c5SMasahiro Yamada #endif
549608f26c5SMasahiro Yamada 
550608f26c5SMasahiro Yamada /**
55193c7fe4aSSimon Glass  * devres_alloc() - Allocate device resource data
552608f26c5SMasahiro Yamada  * @release: Release function devres will be associated with
553608f26c5SMasahiro Yamada  * @size: Allocation size
554608f26c5SMasahiro Yamada  * @gfp: Allocation flags
555608f26c5SMasahiro Yamada  *
556608f26c5SMasahiro Yamada  * Allocate devres of @size bytes.  The allocated area is associated
557608f26c5SMasahiro Yamada  * with @release.  The returned pointer can be passed to
558608f26c5SMasahiro Yamada  * other devres_*() functions.
559608f26c5SMasahiro Yamada  *
560608f26c5SMasahiro Yamada  * RETURNS:
561608f26c5SMasahiro Yamada  * Pointer to allocated devres on success, NULL on failure.
562608f26c5SMasahiro Yamada  */
563608f26c5SMasahiro Yamada #define devres_alloc(release, size, gfp) \
564608f26c5SMasahiro Yamada 	_devres_alloc(release, size, gfp | __GFP_ZERO)
565608f26c5SMasahiro Yamada 
566608f26c5SMasahiro Yamada /**
56793c7fe4aSSimon Glass  * devres_free() - Free device resource data
568608f26c5SMasahiro Yamada  * @res: Pointer to devres data to free
569608f26c5SMasahiro Yamada  *
570608f26c5SMasahiro Yamada  * Free devres created with devres_alloc().
571608f26c5SMasahiro Yamada  */
572608f26c5SMasahiro Yamada void devres_free(void *res);
573608f26c5SMasahiro Yamada 
574608f26c5SMasahiro Yamada /**
57593c7fe4aSSimon Glass  * devres_add() - Register device resource
576608f26c5SMasahiro Yamada  * @dev: Device to add resource to
577608f26c5SMasahiro Yamada  * @res: Resource to register
578608f26c5SMasahiro Yamada  *
579608f26c5SMasahiro Yamada  * Register devres @res to @dev.  @res should have been allocated
580608f26c5SMasahiro Yamada  * using devres_alloc().  On driver detach, the associated release
581608f26c5SMasahiro Yamada  * function will be invoked and devres will be freed automatically.
582608f26c5SMasahiro Yamada  */
583608f26c5SMasahiro Yamada void devres_add(struct udevice *dev, void *res);
584608f26c5SMasahiro Yamada 
585608f26c5SMasahiro Yamada /**
58693c7fe4aSSimon Glass  * devres_find() - Find device resource
587608f26c5SMasahiro Yamada  * @dev: Device to lookup resource from
588608f26c5SMasahiro Yamada  * @release: Look for resources associated with this release function
589608f26c5SMasahiro Yamada  * @match: Match function (optional)
590608f26c5SMasahiro Yamada  * @match_data: Data for the match function
591608f26c5SMasahiro Yamada  *
592608f26c5SMasahiro Yamada  * Find the latest devres of @dev which is associated with @release
593608f26c5SMasahiro Yamada  * and for which @match returns 1.  If @match is NULL, it's considered
594608f26c5SMasahiro Yamada  * to match all.
595608f26c5SMasahiro Yamada  *
59693c7fe4aSSimon Glass  * @return pointer to found devres, NULL if not found.
597608f26c5SMasahiro Yamada  */
598608f26c5SMasahiro Yamada void *devres_find(struct udevice *dev, dr_release_t release,
599608f26c5SMasahiro Yamada 		  dr_match_t match, void *match_data);
600608f26c5SMasahiro Yamada 
601608f26c5SMasahiro Yamada /**
60293c7fe4aSSimon Glass  * devres_get() - Find devres, if non-existent, add one atomically
603608f26c5SMasahiro Yamada  * @dev: Device to lookup or add devres for
604608f26c5SMasahiro Yamada  * @new_res: Pointer to new initialized devres to add if not found
605608f26c5SMasahiro Yamada  * @match: Match function (optional)
606608f26c5SMasahiro Yamada  * @match_data: Data for the match function
607608f26c5SMasahiro Yamada  *
608608f26c5SMasahiro Yamada  * Find the latest devres of @dev which has the same release function
609608f26c5SMasahiro Yamada  * as @new_res and for which @match return 1.  If found, @new_res is
610608f26c5SMasahiro Yamada  * freed; otherwise, @new_res is added atomically.
611608f26c5SMasahiro Yamada  *
61293c7fe4aSSimon Glass  * @return ointer to found or added devres.
613608f26c5SMasahiro Yamada  */
614608f26c5SMasahiro Yamada void *devres_get(struct udevice *dev, void *new_res,
615608f26c5SMasahiro Yamada 		 dr_match_t match, void *match_data);
616608f26c5SMasahiro Yamada 
617608f26c5SMasahiro Yamada /**
61893c7fe4aSSimon Glass  * devres_remove() - Find a device resource and remove it
619608f26c5SMasahiro Yamada  * @dev: Device to find resource from
620608f26c5SMasahiro Yamada  * @release: Look for resources associated with this release function
621608f26c5SMasahiro Yamada  * @match: Match function (optional)
622608f26c5SMasahiro Yamada  * @match_data: Data for the match function
623608f26c5SMasahiro Yamada  *
624608f26c5SMasahiro Yamada  * Find the latest devres of @dev associated with @release and for
625608f26c5SMasahiro Yamada  * which @match returns 1.  If @match is NULL, it's considered to
626608f26c5SMasahiro Yamada  * match all.  If found, the resource is removed atomically and
627608f26c5SMasahiro Yamada  * returned.
628608f26c5SMasahiro Yamada  *
62993c7fe4aSSimon Glass  * @return ointer to removed devres on success, NULL if not found.
630608f26c5SMasahiro Yamada  */
631608f26c5SMasahiro Yamada void *devres_remove(struct udevice *dev, dr_release_t release,
632608f26c5SMasahiro Yamada 		    dr_match_t match, void *match_data);
633608f26c5SMasahiro Yamada 
634608f26c5SMasahiro Yamada /**
63593c7fe4aSSimon Glass  * devres_destroy() - Find a device resource and destroy it
636608f26c5SMasahiro Yamada  * @dev: Device to find resource from
637608f26c5SMasahiro Yamada  * @release: Look for resources associated with this release function
638608f26c5SMasahiro Yamada  * @match: Match function (optional)
639608f26c5SMasahiro Yamada  * @match_data: Data for the match function
640608f26c5SMasahiro Yamada  *
641608f26c5SMasahiro Yamada  * Find the latest devres of @dev associated with @release and for
642608f26c5SMasahiro Yamada  * which @match returns 1.  If @match is NULL, it's considered to
643608f26c5SMasahiro Yamada  * match all.  If found, the resource is removed atomically and freed.
644608f26c5SMasahiro Yamada  *
645608f26c5SMasahiro Yamada  * Note that the release function for the resource will not be called,
646608f26c5SMasahiro Yamada  * only the devres-allocated data will be freed.  The caller becomes
647608f26c5SMasahiro Yamada  * responsible for freeing any other data.
648608f26c5SMasahiro Yamada  *
64993c7fe4aSSimon Glass  * @return 0 if devres is found and freed, -ENOENT if not found.
650608f26c5SMasahiro Yamada  */
651608f26c5SMasahiro Yamada int devres_destroy(struct udevice *dev, dr_release_t release,
652608f26c5SMasahiro Yamada 		   dr_match_t match, void *match_data);
653608f26c5SMasahiro Yamada 
654608f26c5SMasahiro Yamada /**
65593c7fe4aSSimon Glass  * devres_release() - Find a device resource and destroy it, calling release
656608f26c5SMasahiro Yamada  * @dev: Device to find resource from
657608f26c5SMasahiro Yamada  * @release: Look for resources associated with this release function
658608f26c5SMasahiro Yamada  * @match: Match function (optional)
659608f26c5SMasahiro Yamada  * @match_data: Data for the match function
660608f26c5SMasahiro Yamada  *
661608f26c5SMasahiro Yamada  * Find the latest devres of @dev associated with @release and for
662608f26c5SMasahiro Yamada  * which @match returns 1.  If @match is NULL, it's considered to
663608f26c5SMasahiro Yamada  * match all.  If found, the resource is removed atomically, the
664608f26c5SMasahiro Yamada  * release function called and the resource freed.
665608f26c5SMasahiro Yamada  *
66693c7fe4aSSimon Glass  * @return 0 if devres is found and freed, -ENOENT if not found.
667608f26c5SMasahiro Yamada  */
668608f26c5SMasahiro Yamada int devres_release(struct udevice *dev, dr_release_t release,
669608f26c5SMasahiro Yamada 		   dr_match_t match, void *match_data);
670608f26c5SMasahiro Yamada 
6712b07f685SMasahiro Yamada /* managed devm_k.alloc/kfree for device drivers */
6722b07f685SMasahiro Yamada /**
67393c7fe4aSSimon Glass  * devm_kmalloc() - Resource-managed kmalloc
6742b07f685SMasahiro Yamada  * @dev: Device to allocate memory for
6752b07f685SMasahiro Yamada  * @size: Allocation size
6762b07f685SMasahiro Yamada  * @gfp: Allocation gfp flags
6772b07f685SMasahiro Yamada  *
6782b07f685SMasahiro Yamada  * Managed kmalloc.  Memory allocated with this function is
6792b07f685SMasahiro Yamada  * automatically freed on driver detach.  Like all other devres
6802b07f685SMasahiro Yamada  * resources, guaranteed alignment is unsigned long long.
6812b07f685SMasahiro Yamada  *
68293c7fe4aSSimon Glass  * @return pointer to allocated memory on success, NULL on failure.
6832b07f685SMasahiro Yamada  */
6842b07f685SMasahiro Yamada void *devm_kmalloc(struct udevice *dev, size_t size, gfp_t gfp);
6852b07f685SMasahiro Yamada static inline void *devm_kzalloc(struct udevice *dev, size_t size, gfp_t gfp)
6862b07f685SMasahiro Yamada {
6872b07f685SMasahiro Yamada 	return devm_kmalloc(dev, size, gfp | __GFP_ZERO);
6882b07f685SMasahiro Yamada }
6892b07f685SMasahiro Yamada static inline void *devm_kmalloc_array(struct udevice *dev,
6902b07f685SMasahiro Yamada 				       size_t n, size_t size, gfp_t flags)
6912b07f685SMasahiro Yamada {
6922b07f685SMasahiro Yamada 	if (size != 0 && n > SIZE_MAX / size)
6932b07f685SMasahiro Yamada 		return NULL;
6942b07f685SMasahiro Yamada 	return devm_kmalloc(dev, n * size, flags);
6952b07f685SMasahiro Yamada }
6962b07f685SMasahiro Yamada static inline void *devm_kcalloc(struct udevice *dev,
6972b07f685SMasahiro Yamada 				 size_t n, size_t size, gfp_t flags)
6982b07f685SMasahiro Yamada {
6992b07f685SMasahiro Yamada 	return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO);
7002b07f685SMasahiro Yamada }
7012b07f685SMasahiro Yamada 
7022b07f685SMasahiro Yamada /**
70393c7fe4aSSimon Glass  * devm_kfree() - Resource-managed kfree
7042b07f685SMasahiro Yamada  * @dev: Device this memory belongs to
70593c7fe4aSSimon Glass  * @ptr: Memory to free
7062b07f685SMasahiro Yamada  *
7072b07f685SMasahiro Yamada  * Free memory allocated with devm_kmalloc().
7082b07f685SMasahiro Yamada  */
70993c7fe4aSSimon Glass void devm_kfree(struct udevice *dev, void *ptr);
7102b07f685SMasahiro Yamada 
711e2282d70SMasahiro Yamada #else /* ! CONFIG_DEVRES */
712e2282d70SMasahiro Yamada 
713e2282d70SMasahiro Yamada static inline void *devres_alloc(dr_release_t release, size_t size, gfp_t gfp)
714e2282d70SMasahiro Yamada {
715e2282d70SMasahiro Yamada 	return kzalloc(size, gfp);
716e2282d70SMasahiro Yamada }
717e2282d70SMasahiro Yamada 
718e2282d70SMasahiro Yamada static inline void devres_free(void *res)
719e2282d70SMasahiro Yamada {
720e2282d70SMasahiro Yamada 	kfree(res);
721e2282d70SMasahiro Yamada }
722e2282d70SMasahiro Yamada 
723e2282d70SMasahiro Yamada static inline void devres_add(struct udevice *dev, void *res)
724e2282d70SMasahiro Yamada {
725e2282d70SMasahiro Yamada }
726e2282d70SMasahiro Yamada 
727e2282d70SMasahiro Yamada static inline void *devres_find(struct udevice *dev, dr_release_t release,
728e2282d70SMasahiro Yamada 				dr_match_t match, void *match_data)
729e2282d70SMasahiro Yamada {
730e2282d70SMasahiro Yamada 	return NULL;
731e2282d70SMasahiro Yamada }
732e2282d70SMasahiro Yamada 
733e2282d70SMasahiro Yamada static inline void *devres_get(struct udevice *dev, void *new_res,
734e2282d70SMasahiro Yamada 			       dr_match_t match, void *match_data)
735e2282d70SMasahiro Yamada {
736e2282d70SMasahiro Yamada 	return NULL;
737e2282d70SMasahiro Yamada }
738e2282d70SMasahiro Yamada 
739e2282d70SMasahiro Yamada static inline void *devres_remove(struct udevice *dev, dr_release_t release,
740e2282d70SMasahiro Yamada 				  dr_match_t match, void *match_data)
741e2282d70SMasahiro Yamada {
742e2282d70SMasahiro Yamada 	return NULL;
743e2282d70SMasahiro Yamada }
744e2282d70SMasahiro Yamada 
745e2282d70SMasahiro Yamada static inline int devres_destroy(struct udevice *dev, dr_release_t release,
746e2282d70SMasahiro Yamada 				 dr_match_t match, void *match_data)
747e2282d70SMasahiro Yamada {
748e2282d70SMasahiro Yamada 	return 0;
749e2282d70SMasahiro Yamada }
750e2282d70SMasahiro Yamada 
751e2282d70SMasahiro Yamada static inline int devres_release(struct udevice *dev, dr_release_t release,
752e2282d70SMasahiro Yamada 				 dr_match_t match, void *match_data)
753e2282d70SMasahiro Yamada {
754e2282d70SMasahiro Yamada 	return 0;
755e2282d70SMasahiro Yamada }
756e2282d70SMasahiro Yamada 
757e2282d70SMasahiro Yamada static inline void *devm_kmalloc(struct udevice *dev, size_t size, gfp_t gfp)
758e2282d70SMasahiro Yamada {
759e2282d70SMasahiro Yamada 	return kmalloc(size, gfp);
760e2282d70SMasahiro Yamada }
761e2282d70SMasahiro Yamada 
762e2282d70SMasahiro Yamada static inline void *devm_kzalloc(struct udevice *dev, size_t size, gfp_t gfp)
763e2282d70SMasahiro Yamada {
764e2282d70SMasahiro Yamada 	return kzalloc(size, gfp);
765e2282d70SMasahiro Yamada }
766e2282d70SMasahiro Yamada 
767e2282d70SMasahiro Yamada static inline void *devm_kmaloc_array(struct udevice *dev,
768e2282d70SMasahiro Yamada 				      size_t n, size_t size, gfp_t flags)
769e2282d70SMasahiro Yamada {
770e2282d70SMasahiro Yamada 	/* TODO: add kmalloc_array() to linux/compat.h */
771e2282d70SMasahiro Yamada 	if (size != 0 && n > SIZE_MAX / size)
772e2282d70SMasahiro Yamada 		return NULL;
773e2282d70SMasahiro Yamada 	return kmalloc(n * size, flags);
774e2282d70SMasahiro Yamada }
775e2282d70SMasahiro Yamada 
776e2282d70SMasahiro Yamada static inline void *devm_kcalloc(struct udevice *dev,
777e2282d70SMasahiro Yamada 				 size_t n, size_t size, gfp_t flags)
778e2282d70SMasahiro Yamada {
779e2282d70SMasahiro Yamada 	/* TODO: add kcalloc() to linux/compat.h */
780e2282d70SMasahiro Yamada 	return kmalloc(n * size, flags | __GFP_ZERO);
781e2282d70SMasahiro Yamada }
782e2282d70SMasahiro Yamada 
78393c7fe4aSSimon Glass static inline void devm_kfree(struct udevice *dev, void *ptr)
784e2282d70SMasahiro Yamada {
78593c7fe4aSSimon Glass 	kfree(ptr);
786e2282d70SMasahiro Yamada }
787e2282d70SMasahiro Yamada 
788e2282d70SMasahiro Yamada #endif /* ! CONFIG_DEVRES */
7892b07f685SMasahiro Yamada 
79066eaea6cSStefan Roese /**
79166eaea6cSStefan Roese  * dm_set_translation_offset() - Set translation offset
79266eaea6cSStefan Roese  * @offs: Translation offset
79366eaea6cSStefan Roese  *
79466eaea6cSStefan Roese  * Some platforms need a special address translation. Those
79566eaea6cSStefan Roese  * platforms (e.g. mvebu in SPL) can configure a translation
79666eaea6cSStefan Roese  * offset in the DM by calling this function. It will be
79766eaea6cSStefan Roese  * added to all addresses returned in dev_get_addr().
79866eaea6cSStefan Roese  */
79966eaea6cSStefan Roese void dm_set_translation_offset(fdt_addr_t offs);
80066eaea6cSStefan Roese 
80166eaea6cSStefan Roese /**
80266eaea6cSStefan Roese  * dm_get_translation_offset() - Get translation offset
80366eaea6cSStefan Roese  *
80466eaea6cSStefan Roese  * This function returns the translation offset that can
80566eaea6cSStefan Roese  * be configured by calling dm_set_translation_offset().
80666eaea6cSStefan Roese  *
80766eaea6cSStefan Roese  * @return translation offset for the device address (0 as default).
80866eaea6cSStefan Roese  */
80966eaea6cSStefan Roese fdt_addr_t dm_get_translation_offset(void);
81066eaea6cSStefan Roese 
8116494d708SSimon Glass #endif
812