xref: /rk3399_rockchip-uboot/include/dm/device-internal.h (revision 1fdafb2e3dfecdc4129a8062ad25b1adb32b0efb)
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_INTERNAL_H
126494d708SSimon Glass #define _DM_DEVICE_INTERNAL_H
136494d708SSimon Glass 
14396e343bSSimon Glass #include <dm/ofnode.h>
15396e343bSSimon Glass 
16396e343bSSimon Glass struct device_node;
1754c5d08aSHeiko Schocher struct udevice;
186494d708SSimon Glass 
196494d708SSimon Glass /**
206494d708SSimon Glass  * device_bind() - Create a device and bind it to a driver
216494d708SSimon Glass  *
226494d708SSimon Glass  * Called to set up a new device attached to a driver. The device will either
236494d708SSimon Glass  * have platdata, or a device tree node which can be used to create the
246494d708SSimon Glass  * platdata.
256494d708SSimon Glass  *
266494d708SSimon Glass  * Once bound a device exists but is not yet active until device_probe() is
276494d708SSimon Glass  * called.
286494d708SSimon Glass  *
296494d708SSimon Glass  * @parent: Pointer to device's parent, under which this driver will exist
306494d708SSimon Glass  * @drv: Device's driver
316494d708SSimon Glass  * @name: Name of device (e.g. device tree node name)
326494d708SSimon Glass  * @platdata: Pointer to data for this device - the structure is device-
336494d708SSimon Glass  * specific but may include the device's I/O address, etc.. This is NULL for
346494d708SSimon Glass  * devices which use device tree.
356494d708SSimon Glass  * @of_offset: Offset of device tree node for this device. This is -1 for
366494d708SSimon Glass  * devices which don't use device tree.
37e6cabe4aSMasahiro Yamada  * @devp: if non-NULL, returns a pointer to the bound device
386494d708SSimon Glass  * @return 0 if OK, -ve on error
396494d708SSimon Glass  */
403479253dSSimon Glass int device_bind(struct udevice *parent, const struct driver *drv,
416494d708SSimon Glass 		const char *name, void *platdata, int of_offset,
4254c5d08aSHeiko Schocher 		struct udevice **devp);
436494d708SSimon Glass 
446494d708SSimon Glass /**
45daac3bfeSStephen Warren  * device_bind_with_driver_data() - Create a device and bind it to a driver
46daac3bfeSStephen Warren  *
47daac3bfeSStephen Warren  * Called to set up a new device attached to a driver, in the case where the
48daac3bfeSStephen Warren  * driver was matched to the device by means of a match table that provides
49daac3bfeSStephen Warren  * driver_data.
50daac3bfeSStephen Warren  *
51daac3bfeSStephen Warren  * Once bound a device exists but is not yet active until device_probe() is
52daac3bfeSStephen Warren  * called.
53daac3bfeSStephen Warren  *
54daac3bfeSStephen Warren  * @parent: Pointer to device's parent, under which this driver will exist
55daac3bfeSStephen Warren  * @drv: Device's driver
56daac3bfeSStephen Warren  * @name: Name of device (e.g. device tree node name)
57daac3bfeSStephen Warren  * @driver_data: The driver_data field from the driver's match table.
58396e343bSSimon Glass  * @node: Device tree node for this device. This is invalid for devices which
59396e343bSSimon Glass  * don't use device tree.
60daac3bfeSStephen Warren  * @devp: if non-NULL, returns a pointer to the bound device
61daac3bfeSStephen Warren  * @return 0 if OK, -ve on error
62daac3bfeSStephen Warren  */
63daac3bfeSStephen Warren int device_bind_with_driver_data(struct udevice *parent,
64daac3bfeSStephen Warren 				 const struct driver *drv, const char *name,
65396e343bSSimon Glass 				 ulong driver_data, ofnode node,
66daac3bfeSStephen Warren 				 struct udevice **devp);
67daac3bfeSStephen Warren /**
686494d708SSimon Glass  * device_bind_by_name: Create a device and bind it to a driver
696494d708SSimon Glass  *
706494d708SSimon Glass  * This is a helper function used to bind devices which do not use device
716494d708SSimon Glass  * tree.
726494d708SSimon Glass  *
736494d708SSimon Glass  * @parent: Pointer to device's parent
7400606d7eSSimon Glass  * @pre_reloc_only: If true, bind the driver only if its DM_INIT_F flag is set.
7500606d7eSSimon Glass  * If false bind the driver always.
766494d708SSimon Glass  * @info: Name and platdata for this device
77e6cabe4aSMasahiro Yamada  * @devp: if non-NULL, returns a pointer to the bound device
786494d708SSimon Glass  * @return 0 if OK, -ve on error
796494d708SSimon Glass  */
8000606d7eSSimon Glass int device_bind_by_name(struct udevice *parent, bool pre_reloc_only,
8100606d7eSSimon Glass 			const struct driver_info *info, struct udevice **devp);
826494d708SSimon Glass 
836494d708SSimon Glass /**
846494d708SSimon Glass  * device_probe() - Probe a device, activating it
856494d708SSimon Glass  *
866494d708SSimon Glass  * Activate a device so that it is ready for use. All its parents are probed
876494d708SSimon Glass  * first.
886494d708SSimon Glass  *
896494d708SSimon Glass  * @dev: Pointer to device to probe
906494d708SSimon Glass  * @return 0 if OK, -ve on error
916494d708SSimon Glass  */
9254c5d08aSHeiko Schocher int device_probe(struct udevice *dev);
936494d708SSimon Glass 
946494d708SSimon Glass /**
956494d708SSimon Glass  * device_remove() - Remove a device, de-activating it
966494d708SSimon Glass  *
976494d708SSimon Glass  * De-activate a device so that it is no longer ready for use. All its
986494d708SSimon Glass  * children are deactivated first.
996494d708SSimon Glass  *
1006494d708SSimon Glass  * @dev: Pointer to device to remove
101*e88afcccSSimon Glass  * @flags: Flags for selective device removal (DM_REMOVE_...)
1026494d708SSimon Glass  * @return 0 if OK, -ve on error (an error here is normally a very bad thing)
1036494d708SSimon Glass  */
1040a5804b5SMasahiro Yamada #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
105706865afSStefan Roese int device_remove(struct udevice *dev, uint flags);
1063ac435d3SSimon Glass #else
device_remove(struct udevice * dev,uint flags)107706865afSStefan Roese static inline int device_remove(struct udevice *dev, uint flags) { return 0; }
1083ac435d3SSimon Glass #endif
1096494d708SSimon Glass 
1106494d708SSimon Glass /**
1116494d708SSimon Glass  * device_unbind() - Unbind a device, destroying it
1126494d708SSimon Glass  *
1136494d708SSimon Glass  * Unbind a device and remove all memory used by it
1146494d708SSimon Glass  *
1156494d708SSimon Glass  * @dev: Pointer to device to unbind
1166494d708SSimon Glass  * @return 0 if OK, -ve on error
1176494d708SSimon Glass  */
1180a5804b5SMasahiro Yamada #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
11954c5d08aSHeiko Schocher int device_unbind(struct udevice *dev);
12066c03151SMarek Vasut #else
device_unbind(struct udevice * dev)12166c03151SMarek Vasut static inline int device_unbind(struct udevice *dev) { return 0; }
12266c03151SMarek Vasut #endif
1236494d708SSimon Glass 
1240a5804b5SMasahiro Yamada #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
1253ac435d3SSimon Glass void device_free(struct udevice *dev);
1263ac435d3SSimon Glass #else
device_free(struct udevice * dev)1273ac435d3SSimon Glass static inline void device_free(struct udevice *dev) {}
1283ac435d3SSimon Glass #endif
1293ac435d3SSimon Glass 
130f3301771SSimon Glass /**
131f3301771SSimon Glass  * simple_bus_translate() - translate a bus address to a system address
132f3301771SSimon Glass  *
133f3301771SSimon Glass  * This handles the 'ranges' property in a simple bus. It translates the
134f3301771SSimon Glass  * device address @addr to a system address using this property.
135f3301771SSimon Glass  *
136f3301771SSimon Glass  * @dev:	Simple bus device (parent of target device)
137f3301771SSimon Glass  * @addr:	Address to translate
138f3301771SSimon Glass  * @return new address
139f3301771SSimon Glass  */
140f3301771SSimon Glass fdt_addr_t simple_bus_translate(struct udevice *dev, fdt_addr_t addr);
141f3301771SSimon Glass 
14289876a55SSimon Glass /* Cast away any volatile pointer */
14389876a55SSimon Glass #define DM_ROOT_NON_CONST		(((gd_t *)gd)->dm_root)
14489876a55SSimon Glass #define DM_UCLASS_ROOT_NON_CONST	(((gd_t *)gd)->uclass_root)
14589876a55SSimon Glass 
146608f26c5SMasahiro Yamada /* device resource management */
147e2282d70SMasahiro Yamada #ifdef CONFIG_DEVRES
148e2282d70SMasahiro Yamada 
149608f26c5SMasahiro Yamada /**
150608f26c5SMasahiro Yamada  * devres_release_probe - Release managed resources allocated after probing
151608f26c5SMasahiro Yamada  * @dev: Device to release resources for
152608f26c5SMasahiro Yamada  *
153608f26c5SMasahiro Yamada  * Release all resources allocated for @dev when it was probed or later.
154608f26c5SMasahiro Yamada  * This function is called on driver removal.
155608f26c5SMasahiro Yamada  */
156608f26c5SMasahiro Yamada void devres_release_probe(struct udevice *dev);
157608f26c5SMasahiro Yamada 
158608f26c5SMasahiro Yamada /**
159608f26c5SMasahiro Yamada  * devres_release_all - Release all managed resources
160608f26c5SMasahiro Yamada  * @dev: Device to release resources for
161608f26c5SMasahiro Yamada  *
162608f26c5SMasahiro Yamada  * Release all resources associated with @dev.  This function is
163608f26c5SMasahiro Yamada  * called on driver unbinding.
164608f26c5SMasahiro Yamada  */
165608f26c5SMasahiro Yamada void devres_release_all(struct udevice *dev);
166608f26c5SMasahiro Yamada 
167e2282d70SMasahiro Yamada #else /* ! CONFIG_DEVRES */
168e2282d70SMasahiro Yamada 
devres_release_probe(struct udevice * dev)169e2282d70SMasahiro Yamada static inline void devres_release_probe(struct udevice *dev)
170e2282d70SMasahiro Yamada {
171e2282d70SMasahiro Yamada }
172e2282d70SMasahiro Yamada 
devres_release_all(struct udevice * dev)173e2282d70SMasahiro Yamada static inline void devres_release_all(struct udevice *dev)
174e2282d70SMasahiro Yamada {
175e2282d70SMasahiro Yamada }
176e2282d70SMasahiro Yamada 
177e2282d70SMasahiro Yamada #endif /* ! CONFIG_DEVRES */
1786494d708SSimon Glass #endif
179