xref: /openbmc/u-boot/drivers/core/uclass.c (revision c1d6f919)
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 #include <common.h>
116494d708SSimon Glass #include <errno.h>
126494d708SSimon Glass #include <malloc.h>
136494d708SSimon Glass #include <dm/device.h>
146494d708SSimon Glass #include <dm/device-internal.h>
156494d708SSimon Glass #include <dm/lists.h>
166494d708SSimon Glass #include <dm/uclass.h>
176494d708SSimon Glass #include <dm/uclass-internal.h>
186494d708SSimon Glass #include <dm/util.h>
196494d708SSimon Glass 
206494d708SSimon Glass DECLARE_GLOBAL_DATA_PTR;
216494d708SSimon Glass 
226494d708SSimon Glass struct uclass *uclass_find(enum uclass_id key)
236494d708SSimon Glass {
246494d708SSimon Glass 	struct uclass *uc;
256494d708SSimon Glass 
26c910e2e2SSimon Glass 	if (!gd->dm_root)
27c910e2e2SSimon Glass 		return NULL;
286494d708SSimon Glass 	/*
296494d708SSimon Glass 	 * TODO(sjg@chromium.org): Optimise this, perhaps moving the found
306494d708SSimon Glass 	 * node to the start of the list, or creating a linear array mapping
316494d708SSimon Glass 	 * id to node.
326494d708SSimon Glass 	 */
336494d708SSimon Glass 	list_for_each_entry(uc, &gd->uclass_root, sibling_node) {
346494d708SSimon Glass 		if (uc->uc_drv->id == key)
356494d708SSimon Glass 			return uc;
366494d708SSimon Glass 	}
376494d708SSimon Glass 
386494d708SSimon Glass 	return NULL;
396494d708SSimon Glass }
406494d708SSimon Glass 
416494d708SSimon Glass /**
426494d708SSimon Glass  * uclass_add() - Create new uclass in list
436494d708SSimon Glass  * @id: Id number to create
446494d708SSimon Glass  * @ucp: Returns pointer to uclass, or NULL on error
456494d708SSimon Glass  * @return 0 on success, -ve on error
466494d708SSimon Glass  *
476494d708SSimon Glass  * The new uclass is added to the list. There must be only one uclass for
486494d708SSimon Glass  * each id.
496494d708SSimon Glass  */
506494d708SSimon Glass static int uclass_add(enum uclass_id id, struct uclass **ucp)
516494d708SSimon Glass {
526494d708SSimon Glass 	struct uclass_driver *uc_drv;
536494d708SSimon Glass 	struct uclass *uc;
546494d708SSimon Glass 	int ret;
556494d708SSimon Glass 
566494d708SSimon Glass 	*ucp = NULL;
576494d708SSimon Glass 	uc_drv = lists_uclass_lookup(id);
586494d708SSimon Glass 	if (!uc_drv) {
596494d708SSimon Glass 		dm_warn("Cannot find uclass for id %d: please add the UCLASS_DRIVER() declaration for this UCLASS_... id\n",
606494d708SSimon Glass 			id);
616494d708SSimon Glass 		return -ENOENT;
626494d708SSimon Glass 	}
636494d708SSimon Glass 	uc = calloc(1, sizeof(*uc));
646494d708SSimon Glass 	if (!uc)
656494d708SSimon Glass 		return -ENOMEM;
666494d708SSimon Glass 	if (uc_drv->priv_auto_alloc_size) {
676494d708SSimon Glass 		uc->priv = calloc(1, uc_drv->priv_auto_alloc_size);
686494d708SSimon Glass 		if (!uc->priv) {
696494d708SSimon Glass 			ret = -ENOMEM;
706494d708SSimon Glass 			goto fail_mem;
716494d708SSimon Glass 		}
726494d708SSimon Glass 	}
736494d708SSimon Glass 	uc->uc_drv = uc_drv;
746494d708SSimon Glass 	INIT_LIST_HEAD(&uc->sibling_node);
756494d708SSimon Glass 	INIT_LIST_HEAD(&uc->dev_head);
7689876a55SSimon Glass 	list_add(&uc->sibling_node, &DM_UCLASS_ROOT_NON_CONST);
776494d708SSimon Glass 
786494d708SSimon Glass 	if (uc_drv->init) {
796494d708SSimon Glass 		ret = uc_drv->init(uc);
806494d708SSimon Glass 		if (ret)
816494d708SSimon Glass 			goto fail;
826494d708SSimon Glass 	}
836494d708SSimon Glass 
846494d708SSimon Glass 	*ucp = uc;
856494d708SSimon Glass 
866494d708SSimon Glass 	return 0;
876494d708SSimon Glass fail:
886494d708SSimon Glass 	if (uc_drv->priv_auto_alloc_size) {
896494d708SSimon Glass 		free(uc->priv);
906494d708SSimon Glass 		uc->priv = NULL;
916494d708SSimon Glass 	}
926494d708SSimon Glass 	list_del(&uc->sibling_node);
936494d708SSimon Glass fail_mem:
946494d708SSimon Glass 	free(uc);
956494d708SSimon Glass 
966494d708SSimon Glass 	return ret;
976494d708SSimon Glass }
986494d708SSimon Glass 
996494d708SSimon Glass int uclass_destroy(struct uclass *uc)
1006494d708SSimon Glass {
1016494d708SSimon Glass 	struct uclass_driver *uc_drv;
10254c5d08aSHeiko Schocher 	struct udevice *dev, *tmp;
1036494d708SSimon Glass 	int ret;
1046494d708SSimon Glass 
1056494d708SSimon Glass 	list_for_each_entry_safe(dev, tmp, &uc->dev_head, uclass_node) {
1066494d708SSimon Glass 		ret = device_remove(dev);
1076494d708SSimon Glass 		if (ret)
1086494d708SSimon Glass 			return ret;
1096494d708SSimon Glass 		ret = device_unbind(dev);
1106494d708SSimon Glass 		if (ret)
1116494d708SSimon Glass 			return ret;
1126494d708SSimon Glass 	}
1136494d708SSimon Glass 
1146494d708SSimon Glass 	uc_drv = uc->uc_drv;
1156494d708SSimon Glass 	if (uc_drv->destroy)
1166494d708SSimon Glass 		uc_drv->destroy(uc);
1176494d708SSimon Glass 	list_del(&uc->sibling_node);
1186494d708SSimon Glass 	if (uc_drv->priv_auto_alloc_size)
1196494d708SSimon Glass 		free(uc->priv);
1206494d708SSimon Glass 	free(uc);
1216494d708SSimon Glass 
1226494d708SSimon Glass 	return 0;
1236494d708SSimon Glass }
1246494d708SSimon Glass 
1256494d708SSimon Glass int uclass_get(enum uclass_id id, struct uclass **ucp)
1266494d708SSimon Glass {
1276494d708SSimon Glass 	struct uclass *uc;
1286494d708SSimon Glass 
1296494d708SSimon Glass 	*ucp = NULL;
1306494d708SSimon Glass 	uc = uclass_find(id);
1316494d708SSimon Glass 	if (!uc)
1326494d708SSimon Glass 		return uclass_add(id, ucp);
1336494d708SSimon Glass 	*ucp = uc;
1346494d708SSimon Glass 
1356494d708SSimon Glass 	return 0;
1366494d708SSimon Glass }
1376494d708SSimon Glass 
13854c5d08aSHeiko Schocher int uclass_find_device(enum uclass_id id, int index, struct udevice **devp)
1396494d708SSimon Glass {
1406494d708SSimon Glass 	struct uclass *uc;
14154c5d08aSHeiko Schocher 	struct udevice *dev;
1426494d708SSimon Glass 	int ret;
1436494d708SSimon Glass 
1446494d708SSimon Glass 	*devp = NULL;
1456494d708SSimon Glass 	ret = uclass_get(id, &uc);
1466494d708SSimon Glass 	if (ret)
1476494d708SSimon Glass 		return ret;
1486494d708SSimon Glass 
1496494d708SSimon Glass 	list_for_each_entry(dev, &uc->dev_head, uclass_node) {
1506494d708SSimon Glass 		if (!index--) {
1516494d708SSimon Glass 			*devp = dev;
1526494d708SSimon Glass 			return 0;
1536494d708SSimon Glass 		}
1546494d708SSimon Glass 	}
1556494d708SSimon Glass 
1566494d708SSimon Glass 	return -ENODEV;
1576494d708SSimon Glass }
1586494d708SSimon Glass 
159*c1d6f919SPrzemyslaw Marczak int uclass_find_first_device(enum uclass_id id, struct udevice **devp)
160*c1d6f919SPrzemyslaw Marczak {
161*c1d6f919SPrzemyslaw Marczak 	struct uclass *uc;
162*c1d6f919SPrzemyslaw Marczak 	int ret;
163*c1d6f919SPrzemyslaw Marczak 
164*c1d6f919SPrzemyslaw Marczak 	*devp = NULL;
165*c1d6f919SPrzemyslaw Marczak 	ret = uclass_get(id, &uc);
166*c1d6f919SPrzemyslaw Marczak 	if (ret)
167*c1d6f919SPrzemyslaw Marczak 		return ret;
168*c1d6f919SPrzemyslaw Marczak 	if (list_empty(&uc->dev_head))
169*c1d6f919SPrzemyslaw Marczak 		return 0;
170*c1d6f919SPrzemyslaw Marczak 
171*c1d6f919SPrzemyslaw Marczak 	*devp = list_first_entry(&uc->dev_head, struct udevice, uclass_node);
172*c1d6f919SPrzemyslaw Marczak 
173*c1d6f919SPrzemyslaw Marczak 	return 0;
174*c1d6f919SPrzemyslaw Marczak }
175*c1d6f919SPrzemyslaw Marczak 
176*c1d6f919SPrzemyslaw Marczak int uclass_find_next_device(struct udevice **devp)
177*c1d6f919SPrzemyslaw Marczak {
178*c1d6f919SPrzemyslaw Marczak 	struct udevice *dev = *devp;
179*c1d6f919SPrzemyslaw Marczak 
180*c1d6f919SPrzemyslaw Marczak 	*devp = NULL;
181*c1d6f919SPrzemyslaw Marczak 	if (list_is_last(&dev->uclass_node, &dev->uclass->dev_head))
182*c1d6f919SPrzemyslaw Marczak 		return 0;
183*c1d6f919SPrzemyslaw Marczak 
184*c1d6f919SPrzemyslaw Marczak 	*devp = list_entry(dev->uclass_node.next, struct udevice, uclass_node);
185*c1d6f919SPrzemyslaw Marczak 
186*c1d6f919SPrzemyslaw Marczak 	return 0;
187*c1d6f919SPrzemyslaw Marczak }
188*c1d6f919SPrzemyslaw Marczak 
1895a66a8ffSSimon Glass int uclass_find_device_by_seq(enum uclass_id id, int seq_or_req_seq,
1905a66a8ffSSimon Glass 			      bool find_req_seq, struct udevice **devp)
1915a66a8ffSSimon Glass {
1925a66a8ffSSimon Glass 	struct uclass *uc;
1935a66a8ffSSimon Glass 	struct udevice *dev;
1945a66a8ffSSimon Glass 	int ret;
1955a66a8ffSSimon Glass 
1965a66a8ffSSimon Glass 	*devp = NULL;
1975a66a8ffSSimon Glass 	debug("%s: %d %d\n", __func__, find_req_seq, seq_or_req_seq);
1985a66a8ffSSimon Glass 	if (seq_or_req_seq == -1)
1995a66a8ffSSimon Glass 		return -ENODEV;
2005a66a8ffSSimon Glass 	ret = uclass_get(id, &uc);
2015a66a8ffSSimon Glass 	if (ret)
2025a66a8ffSSimon Glass 		return ret;
2035a66a8ffSSimon Glass 
2045a66a8ffSSimon Glass 	list_for_each_entry(dev, &uc->dev_head, uclass_node) {
2055a66a8ffSSimon Glass 		debug("   - %d %d\n", dev->req_seq, dev->seq);
2065a66a8ffSSimon Glass 		if ((find_req_seq ? dev->req_seq : dev->seq) ==
2075a66a8ffSSimon Glass 				seq_or_req_seq) {
2085a66a8ffSSimon Glass 			*devp = dev;
2095a66a8ffSSimon Glass 			debug("   - found\n");
2105a66a8ffSSimon Glass 			return 0;
2115a66a8ffSSimon Glass 		}
2125a66a8ffSSimon Glass 	}
2135a66a8ffSSimon Glass 	debug("   - not found\n");
2145a66a8ffSSimon Glass 
2155a66a8ffSSimon Glass 	return -ENODEV;
2165a66a8ffSSimon Glass }
2175a66a8ffSSimon Glass 
218f4cdead2SSimon Glass static int uclass_find_device_by_of_offset(enum uclass_id id, int node,
219f4cdead2SSimon Glass 					   struct udevice **devp)
220f4cdead2SSimon Glass {
221f4cdead2SSimon Glass 	struct uclass *uc;
222f4cdead2SSimon Glass 	struct udevice *dev;
223f4cdead2SSimon Glass 	int ret;
224f4cdead2SSimon Glass 
225f4cdead2SSimon Glass 	*devp = NULL;
226f4cdead2SSimon Glass 	if (node < 0)
227f4cdead2SSimon Glass 		return -ENODEV;
228f4cdead2SSimon Glass 	ret = uclass_get(id, &uc);
229f4cdead2SSimon Glass 	if (ret)
230f4cdead2SSimon Glass 		return ret;
231f4cdead2SSimon Glass 
232f4cdead2SSimon Glass 	list_for_each_entry(dev, &uc->dev_head, uclass_node) {
233f4cdead2SSimon Glass 		if (dev->of_offset == node) {
234f4cdead2SSimon Glass 			*devp = dev;
235f4cdead2SSimon Glass 			return 0;
236f4cdead2SSimon Glass 		}
237f4cdead2SSimon Glass 	}
238f4cdead2SSimon Glass 
239f4cdead2SSimon Glass 	return -ENODEV;
240f4cdead2SSimon Glass }
241f4cdead2SSimon Glass 
2429ca296a1SSimon Glass /**
2439ca296a1SSimon Glass  * uclass_get_device_tail() - handle the end of a get_device call
2449ca296a1SSimon Glass  *
2459ca296a1SSimon Glass  * This handles returning an error or probing a device as needed.
2469ca296a1SSimon Glass  *
2479ca296a1SSimon Glass  * @dev: Device that needs to be probed
2489ca296a1SSimon Glass  * @ret: Error to return. If non-zero then the device is not probed
2499ca296a1SSimon Glass  * @devp: Returns the value of 'dev' if there is no error
2509ca296a1SSimon Glass  * @return ret, if non-zero, else the result of the device_probe() call
2519ca296a1SSimon Glass  */
2529ca296a1SSimon Glass static int uclass_get_device_tail(struct udevice *dev, int ret,
2539ca296a1SSimon Glass 				  struct udevice **devp)
2546494d708SSimon Glass {
2556494d708SSimon Glass 	if (ret)
2566494d708SSimon Glass 		return ret;
2576494d708SSimon Glass 
2586494d708SSimon Glass 	ret = device_probe(dev);
2596494d708SSimon Glass 	if (ret)
2606494d708SSimon Glass 		return ret;
2616494d708SSimon Glass 
2626494d708SSimon Glass 	*devp = dev;
2636494d708SSimon Glass 
2646494d708SSimon Glass 	return 0;
2656494d708SSimon Glass }
2666494d708SSimon Glass 
2679ca296a1SSimon Glass int uclass_get_device(enum uclass_id id, int index, struct udevice **devp)
2689ca296a1SSimon Glass {
2699ca296a1SSimon Glass 	struct udevice *dev;
2709ca296a1SSimon Glass 	int ret;
2719ca296a1SSimon Glass 
2729ca296a1SSimon Glass 	*devp = NULL;
2739ca296a1SSimon Glass 	ret = uclass_find_device(id, index, &dev);
2749ca296a1SSimon Glass 	return uclass_get_device_tail(dev, ret, devp);
2759ca296a1SSimon Glass }
2769ca296a1SSimon Glass 
2775a66a8ffSSimon Glass int uclass_get_device_by_seq(enum uclass_id id, int seq, struct udevice **devp)
2785a66a8ffSSimon Glass {
2795a66a8ffSSimon Glass 	struct udevice *dev;
2805a66a8ffSSimon Glass 	int ret;
2815a66a8ffSSimon Glass 
2825a66a8ffSSimon Glass 	*devp = NULL;
2835a66a8ffSSimon Glass 	ret = uclass_find_device_by_seq(id, seq, false, &dev);
2845a66a8ffSSimon Glass 	if (ret == -ENODEV) {
2855a66a8ffSSimon Glass 		/*
2865a66a8ffSSimon Glass 		 * We didn't find it in probed devices. See if there is one
2875a66a8ffSSimon Glass 		 * that will request this seq if probed.
2885a66a8ffSSimon Glass 		 */
2895a66a8ffSSimon Glass 		ret = uclass_find_device_by_seq(id, seq, true, &dev);
2905a66a8ffSSimon Glass 	}
2915a66a8ffSSimon Glass 	return uclass_get_device_tail(dev, ret, devp);
2925a66a8ffSSimon Glass }
2935a66a8ffSSimon Glass 
294f4cdead2SSimon Glass int uclass_get_device_by_of_offset(enum uclass_id id, int node,
295f4cdead2SSimon Glass 				   struct udevice **devp)
296f4cdead2SSimon Glass {
297f4cdead2SSimon Glass 	struct udevice *dev;
298f4cdead2SSimon Glass 	int ret;
299f4cdead2SSimon Glass 
300f4cdead2SSimon Glass 	*devp = NULL;
301f4cdead2SSimon Glass 	ret = uclass_find_device_by_of_offset(id, node, &dev);
302f4cdead2SSimon Glass 	return uclass_get_device_tail(dev, ret, devp);
303f4cdead2SSimon Glass }
304f4cdead2SSimon Glass 
30554c5d08aSHeiko Schocher int uclass_first_device(enum uclass_id id, struct udevice **devp)
3066494d708SSimon Glass {
30754c5d08aSHeiko Schocher 	struct udevice *dev;
3086494d708SSimon Glass 	int ret;
3096494d708SSimon Glass 
3106494d708SSimon Glass 	*devp = NULL;
311*c1d6f919SPrzemyslaw Marczak 	ret = uclass_find_first_device(id, &dev);
312*c1d6f919SPrzemyslaw Marczak 	return uclass_get_device_tail(dev, ret, devp);
3136494d708SSimon Glass }
3146494d708SSimon Glass 
31554c5d08aSHeiko Schocher int uclass_next_device(struct udevice **devp)
3166494d708SSimon Glass {
31754c5d08aSHeiko Schocher 	struct udevice *dev = *devp;
3186494d708SSimon Glass 	int ret;
3196494d708SSimon Glass 
3206494d708SSimon Glass 	*devp = NULL;
321*c1d6f919SPrzemyslaw Marczak 	ret = uclass_find_next_device(&dev);
322*c1d6f919SPrzemyslaw Marczak 	return uclass_get_device_tail(dev, ret, devp);
3236494d708SSimon Glass }
3246494d708SSimon Glass 
32554c5d08aSHeiko Schocher int uclass_bind_device(struct udevice *dev)
3266494d708SSimon Glass {
3276494d708SSimon Glass 	struct uclass *uc;
3286494d708SSimon Glass 	int ret;
3296494d708SSimon Glass 
3306494d708SSimon Glass 	uc = dev->uclass;
3316494d708SSimon Glass 	list_add_tail(&dev->uclass_node, &uc->dev_head);
3326494d708SSimon Glass 
333081f2fcbSSimon Glass 	if (dev->parent) {
334081f2fcbSSimon Glass 		struct uclass_driver *uc_drv = dev->parent->uclass->uc_drv;
335081f2fcbSSimon Glass 
336081f2fcbSSimon Glass 		if (uc_drv->child_post_bind) {
337081f2fcbSSimon Glass 			ret = uc_drv->child_post_bind(dev);
338081f2fcbSSimon Glass 			if (ret)
339081f2fcbSSimon Glass 				goto err;
340081f2fcbSSimon Glass 		}
341081f2fcbSSimon Glass 	}
3426494d708SSimon Glass 	if (uc->uc_drv->post_bind) {
3436494d708SSimon Glass 		ret = uc->uc_drv->post_bind(dev);
344081f2fcbSSimon Glass 		if (ret)
345081f2fcbSSimon Glass 			goto err;
3466494d708SSimon Glass 	}
3476494d708SSimon Glass 
3486494d708SSimon Glass 	return 0;
349081f2fcbSSimon Glass err:
350081f2fcbSSimon Glass 	/* There is no need to undo the parent's post_bind call */
351081f2fcbSSimon Glass 	list_del(&dev->uclass_node);
352081f2fcbSSimon Glass 
353081f2fcbSSimon Glass 	return ret;
3546494d708SSimon Glass }
3556494d708SSimon Glass 
35654c5d08aSHeiko Schocher int uclass_unbind_device(struct udevice *dev)
3576494d708SSimon Glass {
3586494d708SSimon Glass 	struct uclass *uc;
3596494d708SSimon Glass 	int ret;
3606494d708SSimon Glass 
3616494d708SSimon Glass 	uc = dev->uclass;
3626494d708SSimon Glass 	if (uc->uc_drv->pre_unbind) {
3636494d708SSimon Glass 		ret = uc->uc_drv->pre_unbind(dev);
3646494d708SSimon Glass 		if (ret)
3656494d708SSimon Glass 			return ret;
3666494d708SSimon Glass 	}
3676494d708SSimon Glass 
3686494d708SSimon Glass 	list_del(&dev->uclass_node);
3696494d708SSimon Glass 	return 0;
3706494d708SSimon Glass }
3716494d708SSimon Glass 
3725a66a8ffSSimon Glass int uclass_resolve_seq(struct udevice *dev)
3735a66a8ffSSimon Glass {
3745a66a8ffSSimon Glass 	struct udevice *dup;
3755a66a8ffSSimon Glass 	int seq;
3765a66a8ffSSimon Glass 	int ret;
3775a66a8ffSSimon Glass 
3785a66a8ffSSimon Glass 	assert(dev->seq == -1);
3795a66a8ffSSimon Glass 	ret = uclass_find_device_by_seq(dev->uclass->uc_drv->id, dev->req_seq,
3805a66a8ffSSimon Glass 					false, &dup);
3815a66a8ffSSimon Glass 	if (!ret) {
3825a66a8ffSSimon Glass 		dm_warn("Device '%s': seq %d is in use by '%s'\n",
3835a66a8ffSSimon Glass 			dev->name, dev->req_seq, dup->name);
3845a66a8ffSSimon Glass 	} else if (ret == -ENODEV) {
3855a66a8ffSSimon Glass 		/* Our requested sequence number is available */
3865a66a8ffSSimon Glass 		if (dev->req_seq != -1)
3875a66a8ffSSimon Glass 			return dev->req_seq;
3885a66a8ffSSimon Glass 	} else {
3895a66a8ffSSimon Glass 		return ret;
3905a66a8ffSSimon Glass 	}
3915a66a8ffSSimon Glass 
3925a66a8ffSSimon Glass 	for (seq = 0; seq < DM_MAX_SEQ; seq++) {
3935a66a8ffSSimon Glass 		ret = uclass_find_device_by_seq(dev->uclass->uc_drv->id, seq,
3945a66a8ffSSimon Glass 						false, &dup);
3955a66a8ffSSimon Glass 		if (ret == -ENODEV)
3965a66a8ffSSimon Glass 			break;
3975a66a8ffSSimon Glass 		if (ret)
3985a66a8ffSSimon Glass 			return ret;
3995a66a8ffSSimon Glass 	}
4005a66a8ffSSimon Glass 	return seq;
4015a66a8ffSSimon Glass }
4025a66a8ffSSimon Glass 
40302c07b37SSimon Glass int uclass_pre_probe_device(struct udevice *dev)
40483c7e434SSimon Glass {
40583c7e434SSimon Glass 	struct uclass_driver *uc_drv;
40602c07b37SSimon Glass 	int ret;
40702c07b37SSimon Glass 
40802c07b37SSimon Glass 	uc_drv = dev->uclass->uc_drv;
40902c07b37SSimon Glass 	if (uc_drv->pre_probe) {
41002c07b37SSimon Glass 		ret = uc_drv->pre_probe(dev);
41102c07b37SSimon Glass 		if (ret)
41202c07b37SSimon Glass 			return ret;
41302c07b37SSimon Glass 	}
41483c7e434SSimon Glass 
41583c7e434SSimon Glass 	if (!dev->parent)
41683c7e434SSimon Glass 		return 0;
41783c7e434SSimon Glass 	uc_drv = dev->parent->uclass->uc_drv;
41883c7e434SSimon Glass 	if (uc_drv->child_pre_probe)
41983c7e434SSimon Glass 		return uc_drv->child_pre_probe(dev);
42083c7e434SSimon Glass 
42183c7e434SSimon Glass 	return 0;
42283c7e434SSimon Glass }
42383c7e434SSimon Glass 
42454c5d08aSHeiko Schocher int uclass_post_probe_device(struct udevice *dev)
4256494d708SSimon Glass {
4266494d708SSimon Glass 	struct uclass_driver *uc_drv = dev->uclass->uc_drv;
4276494d708SSimon Glass 
4286494d708SSimon Glass 	if (uc_drv->post_probe)
4296494d708SSimon Glass 		return uc_drv->post_probe(dev);
4306494d708SSimon Glass 
4316494d708SSimon Glass 	return 0;
4326494d708SSimon Glass }
4336494d708SSimon Glass 
43454c5d08aSHeiko Schocher int uclass_pre_remove_device(struct udevice *dev)
4356494d708SSimon Glass {
4366494d708SSimon Glass 	struct uclass_driver *uc_drv;
4376494d708SSimon Glass 	struct uclass *uc;
4386494d708SSimon Glass 	int ret;
4396494d708SSimon Glass 
4406494d708SSimon Glass 	uc = dev->uclass;
4416494d708SSimon Glass 	uc_drv = uc->uc_drv;
4426494d708SSimon Glass 	if (uc->uc_drv->pre_remove) {
4436494d708SSimon Glass 		ret = uc->uc_drv->pre_remove(dev);
4446494d708SSimon Glass 		if (ret)
4456494d708SSimon Glass 			return ret;
4466494d708SSimon Glass 	}
4476494d708SSimon Glass 	if (uc_drv->per_device_auto_alloc_size) {
4486494d708SSimon Glass 		free(dev->uclass_priv);
4496494d708SSimon Glass 		dev->uclass_priv = NULL;
4506494d708SSimon Glass 	}
4515a66a8ffSSimon Glass 	dev->seq = -1;
4526494d708SSimon Glass 
4536494d708SSimon Glass 	return 0;
4546494d708SSimon Glass }
455