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 * 76494d708SSimon Glass * SPDX-License-Identifier: GPL-2.0+ 86494d708SSimon Glass */ 96494d708SSimon Glass 106494d708SSimon Glass #ifndef _DM_UCLASS_INTERNAL_H 116494d708SSimon Glass #define _DM_UCLASS_INTERNAL_H 126494d708SSimon Glass 13*40bb637dSSimon Glass #include <dm/ofnode.h> 14*40bb637dSSimon Glass 156494d708SSimon Glass /** 16794d5219SPrzemyslaw Marczak * uclass_get_device_tail() - handle the end of a get_device call 17794d5219SPrzemyslaw Marczak * 18794d5219SPrzemyslaw Marczak * This handles returning an error or probing a device as needed. 19794d5219SPrzemyslaw Marczak * 20794d5219SPrzemyslaw Marczak * @dev: Device that needs to be probed 21794d5219SPrzemyslaw Marczak * @ret: Error to return. If non-zero then the device is not probed 22794d5219SPrzemyslaw Marczak * @devp: Returns the value of 'dev' if there is no error 23794d5219SPrzemyslaw Marczak * @return ret, if non-zero, else the result of the device_probe() call 24794d5219SPrzemyslaw Marczak */ 25794d5219SPrzemyslaw Marczak int uclass_get_device_tail(struct udevice *dev, int ret, struct udevice **devp); 26794d5219SPrzemyslaw Marczak 27794d5219SPrzemyslaw Marczak /** 286494d708SSimon Glass * uclass_find_device() - Return n-th child of uclass 296494d708SSimon Glass * @id: Id number of the uclass 306494d708SSimon Glass * @index: Position of the child in uclass's list 316494d708SSimon Glass * #devp: Returns pointer to device, or NULL on error 326494d708SSimon Glass * 33794d5219SPrzemyslaw Marczak * The device is not prepared for use - this is an internal function. 34794d5219SPrzemyslaw Marczak * The function uclass_get_device_tail() can be used to probe the device. 356494d708SSimon Glass * 366494d708SSimon Glass * @return the uclass pointer of a child at the given index or 376494d708SSimon Glass * return NULL on error. 386494d708SSimon Glass */ 3954c5d08aSHeiko Schocher int uclass_find_device(enum uclass_id id, int index, struct udevice **devp); 406494d708SSimon Glass 416494d708SSimon Glass /** 42c1d6f919SPrzemyslaw Marczak * uclass_find_first_device() - Return the first device in a uclass 43c1d6f919SPrzemyslaw Marczak * @id: Id number of the uclass 44c1d6f919SPrzemyslaw Marczak * #devp: Returns pointer to device, or NULL on error 45c1d6f919SPrzemyslaw Marczak * 46794d5219SPrzemyslaw Marczak * The device is not prepared for use - this is an internal function. 47794d5219SPrzemyslaw Marczak * The function uclass_get_device_tail() can be used to probe the device. 48c1d6f919SPrzemyslaw Marczak * 49c1d6f919SPrzemyslaw Marczak * @return 0 if OK (found or not found), -1 on error 50c1d6f919SPrzemyslaw Marczak */ 51c1d6f919SPrzemyslaw Marczak int uclass_find_first_device(enum uclass_id id, struct udevice **devp); 52c1d6f919SPrzemyslaw Marczak 53c1d6f919SPrzemyslaw Marczak /** 54c1d6f919SPrzemyslaw Marczak * uclass_find_next_device() - Return the next device in a uclass 55c1d6f919SPrzemyslaw Marczak * @devp: On entry, pointer to device to lookup. On exit, returns pointer 56c1d6f919SPrzemyslaw Marczak * to the next device in the same uclass, or NULL if none 57c1d6f919SPrzemyslaw Marczak * 58794d5219SPrzemyslaw Marczak * The device is not prepared for use - this is an internal function. 59794d5219SPrzemyslaw Marczak * The function uclass_get_device_tail() can be used to probe the device. 60c1d6f919SPrzemyslaw Marczak * 61c1d6f919SPrzemyslaw Marczak * @return 0 if OK (found or not found), -1 on error 62c1d6f919SPrzemyslaw Marczak */ 63c1d6f919SPrzemyslaw Marczak int uclass_find_next_device(struct udevice **devp); 64c1d6f919SPrzemyslaw Marczak 65c1d6f919SPrzemyslaw Marczak /** 66e0735a4cSPrzemyslaw Marczak * uclass_find_device_by_name() - Find uclass device based on ID and name 67e0735a4cSPrzemyslaw Marczak * 68a7b82502SPrzemyslaw Marczak * This searches for a device with the exactly given name. 69e0735a4cSPrzemyslaw Marczak * 70e0735a4cSPrzemyslaw Marczak * The device is NOT probed, it is merely returned. 71e0735a4cSPrzemyslaw Marczak * 72e0735a4cSPrzemyslaw Marczak * @id: ID to look up 73e0735a4cSPrzemyslaw Marczak * @name: name of a device to find 74e0735a4cSPrzemyslaw Marczak * @devp: Returns pointer to device (the first one with the name) 75e0735a4cSPrzemyslaw Marczak * @return 0 if OK, -ve on error 76e0735a4cSPrzemyslaw Marczak */ 77e0735a4cSPrzemyslaw Marczak int uclass_find_device_by_name(enum uclass_id id, const char *name, 78e0735a4cSPrzemyslaw Marczak struct udevice **devp); 79e0735a4cSPrzemyslaw Marczak 80e0735a4cSPrzemyslaw Marczak /** 81e0735a4cSPrzemyslaw Marczak * uclass_find_device_by_seq() - Find uclass device based on ID and sequence 82e0735a4cSPrzemyslaw Marczak * 83e0735a4cSPrzemyslaw Marczak * This searches for a device with the given seq or req_seq. 84e0735a4cSPrzemyslaw Marczak * 85e0735a4cSPrzemyslaw Marczak * For seq, if an active device has this sequence it will be returned. 86e0735a4cSPrzemyslaw Marczak * If there is no such device then this will return -ENODEV. 87e0735a4cSPrzemyslaw Marczak * 88e0735a4cSPrzemyslaw Marczak * For req_seq, if a device (whether activated or not) has this req_seq 89e0735a4cSPrzemyslaw Marczak * value, that device will be returned. This is a strong indication that 90e0735a4cSPrzemyslaw Marczak * the device will receive that sequence when activated. 91e0735a4cSPrzemyslaw Marczak * 92e0735a4cSPrzemyslaw Marczak * The device is NOT probed, it is merely returned. 93e0735a4cSPrzemyslaw Marczak * 94e0735a4cSPrzemyslaw Marczak * @id: ID to look up 95e0735a4cSPrzemyslaw Marczak * @seq_or_req_seq: Sequence number to find (0=first) 96e0735a4cSPrzemyslaw Marczak * @find_req_seq: true to find req_seq, false to find seq 97e0735a4cSPrzemyslaw Marczak * @devp: Returns pointer to device (there is only one per for each seq) 98e0735a4cSPrzemyslaw Marczak * @return 0 if OK, -ve on error 99e0735a4cSPrzemyslaw Marczak */ 100e0735a4cSPrzemyslaw Marczak int uclass_find_device_by_seq(enum uclass_id id, int seq_or_req_seq, 101e0735a4cSPrzemyslaw Marczak bool find_req_seq, struct udevice **devp); 102e0735a4cSPrzemyslaw Marczak 103e0735a4cSPrzemyslaw Marczak /** 1041b30d61dSSimon Glass * uclass_find_device_by_of_offset() - Find a uclass device by device tree node 1051b30d61dSSimon Glass * 1061b30d61dSSimon Glass * This searches the devices in the uclass for one attached to the given 1071b30d61dSSimon Glass * device tree node. 1081b30d61dSSimon Glass * 1091b30d61dSSimon Glass * The device is NOT probed, it is merely returned. 1101b30d61dSSimon Glass * 1111b30d61dSSimon Glass * @id: ID to look up 1121b30d61dSSimon Glass * @node: Device tree offset to search for (if -ve then -ENODEV is returned) 1131b30d61dSSimon Glass * @devp: Returns pointer to device (there is only one for each node) 1141b30d61dSSimon Glass * @return 0 if OK, -ve on error 1151b30d61dSSimon Glass */ 1161b30d61dSSimon Glass int uclass_find_device_by_of_offset(enum uclass_id id, int node, 1171b30d61dSSimon Glass struct udevice **devp); 1181b30d61dSSimon Glass 1191b30d61dSSimon Glass /** 120*40bb637dSSimon Glass * uclass_find_device_by_of_node() - Find a uclass device by device tree node 121*40bb637dSSimon Glass * 122*40bb637dSSimon Glass * This searches the devices in the uclass for one attached to the given 123*40bb637dSSimon Glass * device tree node. 124*40bb637dSSimon Glass * 125*40bb637dSSimon Glass * The device is NOT probed, it is merely returned. 126*40bb637dSSimon Glass * 127*40bb637dSSimon Glass * @id: ID to look up 128*40bb637dSSimon Glass * @node: Device tree offset to search for (if NULL then -ENODEV is returned) 129*40bb637dSSimon Glass * @devp: Returns pointer to device (there is only one for each node) 130*40bb637dSSimon Glass * @return 0 if OK, -ve on error 131*40bb637dSSimon Glass */ 132*40bb637dSSimon Glass int uclass_find_device_by_ofnode(enum uclass_id id, ofnode node, 133*40bb637dSSimon Glass struct udevice **devp); 134*40bb637dSSimon Glass 135*40bb637dSSimon Glass /** 1366494d708SSimon Glass * uclass_bind_device() - Associate device with a uclass 1376494d708SSimon Glass * 1386494d708SSimon Glass * Connect the device into uclass's list of devices. 1396494d708SSimon Glass * 1406494d708SSimon Glass * @dev: Pointer to the device 1416494d708SSimon Glass * #return 0 on success, -ve on error 1426494d708SSimon Glass */ 14354c5d08aSHeiko Schocher int uclass_bind_device(struct udevice *dev); 1446494d708SSimon Glass 1456494d708SSimon Glass /** 1466494d708SSimon Glass * uclass_unbind_device() - Deassociate device with a uclass 1476494d708SSimon Glass * 1486494d708SSimon Glass * Disconnect the device from uclass's list of devices. 1496494d708SSimon Glass * 1506494d708SSimon Glass * @dev: Pointer to the device 1516494d708SSimon Glass * #return 0 on success, -ve on error 1526494d708SSimon Glass */ 1530a5804b5SMasahiro Yamada #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE) 15454c5d08aSHeiko Schocher int uclass_unbind_device(struct udevice *dev); 1557f9875e7SSimon Glass #else 1567f9875e7SSimon Glass static inline int uclass_unbind_device(struct udevice *dev) { return 0; } 1577f9875e7SSimon Glass #endif 1586494d708SSimon Glass 1596494d708SSimon Glass /** 16002c07b37SSimon Glass * uclass_pre_probe_device() - Deal with a device that is about to be probed 16183c7e434SSimon Glass * 16283c7e434SSimon Glass * Perform any pre-processing that is needed by the uclass before it can be 16302c07b37SSimon Glass * probed. This includes the uclass' pre-probe() method and the parent 16402c07b37SSimon Glass * uclass' child_pre_probe() method. 16583c7e434SSimon Glass * 16683c7e434SSimon Glass * @dev: Pointer to the device 16783c7e434SSimon Glass * #return 0 on success, -ve on error 16883c7e434SSimon Glass */ 16902c07b37SSimon Glass int uclass_pre_probe_device(struct udevice *dev); 17083c7e434SSimon Glass 17183c7e434SSimon Glass /** 1726494d708SSimon Glass * uclass_post_probe_device() - Deal with a device that has just been probed 1736494d708SSimon Glass * 1746494d708SSimon Glass * Perform any post-processing of a probed device that is needed by the 1756494d708SSimon Glass * uclass. 1766494d708SSimon Glass * 1776494d708SSimon Glass * @dev: Pointer to the device 1786494d708SSimon Glass * #return 0 on success, -ve on error 1796494d708SSimon Glass */ 18054c5d08aSHeiko Schocher int uclass_post_probe_device(struct udevice *dev); 1816494d708SSimon Glass 1826494d708SSimon Glass /** 1836494d708SSimon Glass * uclass_pre_remove_device() - Handle a device which is about to be removed 1846494d708SSimon Glass * 1856494d708SSimon Glass * Perform any pre-processing of a device that is about to be removed. 1866494d708SSimon Glass * 1876494d708SSimon Glass * @dev: Pointer to the device 1886494d708SSimon Glass * #return 0 on success, -ve on error 1896494d708SSimon Glass */ 1900a5804b5SMasahiro Yamada #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE) 19154c5d08aSHeiko Schocher int uclass_pre_remove_device(struct udevice *dev); 1927f9875e7SSimon Glass #else 1937f9875e7SSimon Glass static inline int uclass_pre_remove_device(struct udevice *dev) { return 0; } 1947f9875e7SSimon Glass #endif 1956494d708SSimon Glass 1966494d708SSimon Glass /** 1976494d708SSimon Glass * uclass_find() - Find uclass by its id 1986494d708SSimon Glass * 1996494d708SSimon Glass * @id: Id to serach for 2006494d708SSimon Glass * @return pointer to uclass, or NULL if not found 2016494d708SSimon Glass */ 2026494d708SSimon Glass struct uclass *uclass_find(enum uclass_id key); 2036494d708SSimon Glass 2046494d708SSimon Glass /** 2056494d708SSimon Glass * uclass_destroy() - Destroy a uclass 2066494d708SSimon Glass * 2076494d708SSimon Glass * Destroy a uclass and all its devices 2086494d708SSimon Glass * 2096494d708SSimon Glass * @uc: uclass to destroy 2106494d708SSimon Glass * @return 0 on success, -ve on error 2116494d708SSimon Glass */ 2126494d708SSimon Glass int uclass_destroy(struct uclass *uc); 2136494d708SSimon Glass 2146494d708SSimon Glass #endif 215