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 1454c5d08aSHeiko Schocher struct udevice; 156494d708SSimon Glass 166494d708SSimon Glass /** 176494d708SSimon Glass * device_bind() - Create a device and bind it to a driver 186494d708SSimon Glass * 196494d708SSimon Glass * Called to set up a new device attached to a driver. The device will either 206494d708SSimon Glass * have platdata, or a device tree node which can be used to create the 216494d708SSimon Glass * platdata. 226494d708SSimon Glass * 236494d708SSimon Glass * Once bound a device exists but is not yet active until device_probe() is 246494d708SSimon Glass * called. 256494d708SSimon Glass * 266494d708SSimon Glass * @parent: Pointer to device's parent, under which this driver will exist 276494d708SSimon Glass * @drv: Device's driver 286494d708SSimon Glass * @name: Name of device (e.g. device tree node name) 296494d708SSimon Glass * @platdata: Pointer to data for this device - the structure is device- 306494d708SSimon Glass * specific but may include the device's I/O address, etc.. This is NULL for 316494d708SSimon Glass * devices which use device tree. 326494d708SSimon Glass * @of_offset: Offset of device tree node for this device. This is -1 for 336494d708SSimon Glass * devices which don't use device tree. 346494d708SSimon Glass * @devp: Returns a pointer to the bound device 356494d708SSimon Glass * @return 0 if OK, -ve on error 366494d708SSimon Glass */ 373479253dSSimon Glass int device_bind(struct udevice *parent, const struct driver *drv, 386494d708SSimon Glass const char *name, void *platdata, int of_offset, 3954c5d08aSHeiko Schocher struct udevice **devp); 406494d708SSimon Glass 416494d708SSimon Glass /** 426494d708SSimon Glass * device_bind_by_name: Create a device and bind it to a driver 436494d708SSimon Glass * 446494d708SSimon Glass * This is a helper function used to bind devices which do not use device 456494d708SSimon Glass * tree. 466494d708SSimon Glass * 476494d708SSimon Glass * @parent: Pointer to device's parent 4800606d7eSSimon Glass * @pre_reloc_only: If true, bind the driver only if its DM_INIT_F flag is set. 4900606d7eSSimon Glass * If false bind the driver always. 506494d708SSimon Glass * @info: Name and platdata for this device 516494d708SSimon Glass * @devp: Returns a pointer to the bound device 526494d708SSimon Glass * @return 0 if OK, -ve on error 536494d708SSimon Glass */ 5400606d7eSSimon Glass int device_bind_by_name(struct udevice *parent, bool pre_reloc_only, 5500606d7eSSimon Glass const struct driver_info *info, struct udevice **devp); 566494d708SSimon Glass 576494d708SSimon Glass /** 586494d708SSimon Glass * device_probe() - Probe a device, activating it 596494d708SSimon Glass * 606494d708SSimon Glass * Activate a device so that it is ready for use. All its parents are probed 616494d708SSimon Glass * first. 626494d708SSimon Glass * 636494d708SSimon Glass * @dev: Pointer to device to probe 646494d708SSimon Glass * @return 0 if OK, -ve on error 656494d708SSimon Glass */ 6654c5d08aSHeiko Schocher int device_probe(struct udevice *dev); 676494d708SSimon Glass 686494d708SSimon Glass /** 69accd4b19SSimon Glass * device_probe() - Probe a child device, activating it 70accd4b19SSimon Glass * 71accd4b19SSimon Glass * Activate a device so that it is ready for use. All its parents are probed 72accd4b19SSimon Glass * first. The child is provided with parent data if parent_priv is not NULL. 73accd4b19SSimon Glass * 74accd4b19SSimon Glass * @dev: Pointer to device to probe 75accd4b19SSimon Glass * @parent_priv: Pointer to parent data. If non-NULL then this is provided to 76accd4b19SSimon Glass * the child. 77accd4b19SSimon Glass * @return 0 if OK, -ve on error 78accd4b19SSimon Glass */ 79accd4b19SSimon Glass int device_probe_child(struct udevice *dev, void *parent_priv); 80accd4b19SSimon Glass 81accd4b19SSimon Glass /** 826494d708SSimon Glass * device_remove() - Remove a device, de-activating it 836494d708SSimon Glass * 846494d708SSimon Glass * De-activate a device so that it is no longer ready for use. All its 856494d708SSimon Glass * children are deactivated first. 866494d708SSimon Glass * 876494d708SSimon Glass * @dev: Pointer to device to remove 886494d708SSimon Glass * @return 0 if OK, -ve on error (an error here is normally a very bad thing) 896494d708SSimon Glass */ 903ac435d3SSimon Glass #ifdef CONFIG_DM_DEVICE_REMOVE 9154c5d08aSHeiko Schocher int device_remove(struct udevice *dev); 923ac435d3SSimon Glass #else 933ac435d3SSimon Glass static inline int device_remove(struct udevice *dev) { return 0; } 943ac435d3SSimon Glass #endif 956494d708SSimon Glass 966494d708SSimon Glass /** 976494d708SSimon Glass * device_unbind() - Unbind a device, destroying it 986494d708SSimon Glass * 996494d708SSimon Glass * Unbind a device and remove all memory used by it 1006494d708SSimon Glass * 1016494d708SSimon Glass * @dev: Pointer to device to unbind 1026494d708SSimon Glass * @return 0 if OK, -ve on error 1036494d708SSimon Glass */ 10466c03151SMarek Vasut #ifdef CONFIG_DM_DEVICE_REMOVE 10554c5d08aSHeiko Schocher int device_unbind(struct udevice *dev); 10666c03151SMarek Vasut #else 10766c03151SMarek Vasut static inline int device_unbind(struct udevice *dev) { return 0; } 10866c03151SMarek Vasut #endif 1096494d708SSimon Glass 110bb52b367SHans de Goede /** 111bb52b367SHans de Goede * device_remove_children() - Stop all device's children 112bb52b367SHans de Goede * @dev: The device whose children are to be removed 113bb52b367SHans de Goede * @return 0 on success, -ve on error 114bb52b367SHans de Goede */ 115bb52b367SHans de Goede #ifdef CONFIG_DM_DEVICE_REMOVE 116bb52b367SHans de Goede int device_remove_children(struct udevice *dev); 117bb52b367SHans de Goede #else 118bb52b367SHans de Goede static inline int device_remove_children(struct udevice *dev) { return 0; } 119bb52b367SHans de Goede #endif 120bb52b367SHans de Goede 121bb52b367SHans de Goede /** 122bb52b367SHans de Goede * device_unbind_children() - Unbind all device's children from the device 123bb52b367SHans de Goede * 124bb52b367SHans de Goede * On error, the function continues to unbind all children, and reports the 125bb52b367SHans de Goede * first error. 126bb52b367SHans de Goede * 127bb52b367SHans de Goede * @dev: The device that is to be stripped of its children 128bb52b367SHans de Goede * @return 0 on success, -ve on error 129bb52b367SHans de Goede */ 130bb52b367SHans de Goede #ifdef CONFIG_DM_DEVICE_REMOVE 131bb52b367SHans de Goede int device_unbind_children(struct udevice *dev); 132bb52b367SHans de Goede #else 133bb52b367SHans de Goede static inline int device_unbind_children(struct udevice *dev) { return 0; } 134bb52b367SHans de Goede #endif 135bb52b367SHans de Goede 1363ac435d3SSimon Glass #ifdef CONFIG_DM_DEVICE_REMOVE 1373ac435d3SSimon Glass void device_free(struct udevice *dev); 1383ac435d3SSimon Glass #else 1393ac435d3SSimon Glass static inline void device_free(struct udevice *dev) {} 1403ac435d3SSimon Glass #endif 1413ac435d3SSimon Glass 142*f3301771SSimon Glass /** 143*f3301771SSimon Glass * simple_bus_translate() - translate a bus address to a system address 144*f3301771SSimon Glass * 145*f3301771SSimon Glass * This handles the 'ranges' property in a simple bus. It translates the 146*f3301771SSimon Glass * device address @addr to a system address using this property. 147*f3301771SSimon Glass * 148*f3301771SSimon Glass * @dev: Simple bus device (parent of target device) 149*f3301771SSimon Glass * @addr: Address to translate 150*f3301771SSimon Glass * @return new address 151*f3301771SSimon Glass */ 152*f3301771SSimon Glass fdt_addr_t simple_bus_translate(struct udevice *dev, fdt_addr_t addr); 153*f3301771SSimon Glass 15489876a55SSimon Glass /* Cast away any volatile pointer */ 15589876a55SSimon Glass #define DM_ROOT_NON_CONST (((gd_t *)gd)->dm_root) 15689876a55SSimon Glass #define DM_UCLASS_ROOT_NON_CONST (((gd_t *)gd)->uclass_root) 15789876a55SSimon Glass 1586494d708SSimon Glass #endif 159