blob: befbae5a01bfdebca91b3d21a267591a20f4b034 [file] [log] [blame]
Simon Glass6494d702014-02-26 15:59:18 -07001/*
2 * Copyright (c) 2013 Google, Inc
3 *
4 * (C) Copyright 2012
5 * Pavel Herrmann <morpheus.ibis@gmail.com>
6 *
7 * SPDX-License-Identifier: GPL-2.0+
8 */
9
10#ifndef _DM_UCLASS_INTERNAL_H
11#define _DM_UCLASS_INTERNAL_H
12
13/**
14 * uclass_find_device() - Return n-th child of uclass
15 * @id: Id number of the uclass
16 * @index: Position of the child in uclass's list
17 * #devp: Returns pointer to device, or NULL on error
18 *
19 * The device is not prepared for use - this is an internal function
20 *
21 * @return the uclass pointer of a child at the given index or
22 * return NULL on error.
23 */
Heiko Schocher54c5d082014-05-22 12:43:05 +020024int uclass_find_device(enum uclass_id id, int index, struct udevice **devp);
Simon Glass6494d702014-02-26 15:59:18 -070025
26/**
Przemyslaw Marczakc1d6f912015-04-15 13:07:17 +020027 * uclass_find_first_device() - Return the first device in a uclass
28 * @id: Id number of the uclass
29 * #devp: Returns pointer to device, or NULL on error
30 *
31 * The device is not prepared for use - this is an internal function
32 *
33 * @return 0 if OK (found or not found), -1 on error
34 */
35int uclass_find_first_device(enum uclass_id id, struct udevice **devp);
36
37/**
38 * uclass_find_next_device() - Return the next device in a uclass
39 * @devp: On entry, pointer to device to lookup. On exit, returns pointer
40 * to the next device in the same uclass, or NULL if none
41 *
42 * The device is not prepared for use - this is an internal function
43 *
44 * @return 0 if OK (found or not found), -1 on error
45 */
46int uclass_find_next_device(struct udevice **devp);
47
48/**
Simon Glass6494d702014-02-26 15:59:18 -070049 * uclass_bind_device() - Associate device with a uclass
50 *
51 * Connect the device into uclass's list of devices.
52 *
53 * @dev: Pointer to the device
54 * #return 0 on success, -ve on error
55 */
Heiko Schocher54c5d082014-05-22 12:43:05 +020056int uclass_bind_device(struct udevice *dev);
Simon Glass6494d702014-02-26 15:59:18 -070057
58/**
59 * uclass_unbind_device() - Deassociate device with a uclass
60 *
61 * Disconnect the device from uclass's list of devices.
62 *
63 * @dev: Pointer to the device
64 * #return 0 on success, -ve on error
65 */
Heiko Schocher54c5d082014-05-22 12:43:05 +020066int uclass_unbind_device(struct udevice *dev);
Simon Glass6494d702014-02-26 15:59:18 -070067
68/**
Simon Glass02c07b32015-03-05 12:25:22 -070069 * uclass_pre_probe_device() - Deal with a device that is about to be probed
Simon Glass83c7e432015-01-25 08:27:10 -070070 *
71 * Perform any pre-processing that is needed by the uclass before it can be
Simon Glass02c07b32015-03-05 12:25:22 -070072 * probed. This includes the uclass' pre-probe() method and the parent
73 * uclass' child_pre_probe() method.
Simon Glass83c7e432015-01-25 08:27:10 -070074 *
75 * @dev: Pointer to the device
76 * #return 0 on success, -ve on error
77 */
Simon Glass02c07b32015-03-05 12:25:22 -070078int uclass_pre_probe_device(struct udevice *dev);
Simon Glass83c7e432015-01-25 08:27:10 -070079
80/**
Simon Glass6494d702014-02-26 15:59:18 -070081 * uclass_post_probe_device() - Deal with a device that has just been probed
82 *
83 * Perform any post-processing of a probed device that is needed by the
84 * uclass.
85 *
86 * @dev: Pointer to the device
87 * #return 0 on success, -ve on error
88 */
Heiko Schocher54c5d082014-05-22 12:43:05 +020089int uclass_post_probe_device(struct udevice *dev);
Simon Glass6494d702014-02-26 15:59:18 -070090
91/**
92 * uclass_pre_remove_device() - Handle a device which is about to be removed
93 *
94 * Perform any pre-processing of a device that is about to be removed.
95 *
96 * @dev: Pointer to the device
97 * #return 0 on success, -ve on error
98 */
Heiko Schocher54c5d082014-05-22 12:43:05 +020099int uclass_pre_remove_device(struct udevice *dev);
Simon Glass6494d702014-02-26 15:59:18 -0700100
101/**
102 * uclass_find() - Find uclass by its id
103 *
104 * @id: Id to serach for
105 * @return pointer to uclass, or NULL if not found
106 */
107struct uclass *uclass_find(enum uclass_id key);
108
109/**
110 * uclass_destroy() - Destroy a uclass
111 *
112 * Destroy a uclass and all its devices
113 *
114 * @uc: uclass to destroy
115 * @return 0 on success, -ve on error
116 */
117int uclass_destroy(struct uclass *uc);
118
Simon Glass5a66a8f2014-07-23 06:55:12 -0600119/**
120 * uclass_find_device_by_seq() - Find uclass device based on ID and sequence
121 *
122 * This searches for a device with the given seq or req_seq.
123 *
124 * For seq, if an active device has this sequence it will be returned.
125 * If there is no such device then this will return -ENODEV.
126 *
127 * For req_seq, if a device (whether activated or not) has this req_seq
128 * value, that device will be returned. This is a strong indication that
129 * the device will receive that sequence when activated.
130 *
131 * The device is NOT probed, it is merely returned.
132 *
133 * @id: ID to look up
134 * @seq_or_req_seq: Sequence number to find (0=first)
135 * @find_req_seq: true to find req_seq, false to find seq
136 * @devp: Returns pointer to device (there is only one per for each seq)
137 * @return 0 if OK, -ve on error
138 */
139int uclass_find_device_by_seq(enum uclass_id id, int seq_or_req_seq,
140 bool find_req_seq, struct udevice **devp);
141
Simon Glass6494d702014-02-26 15:59:18 -0700142#endif