1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Bootdev for USB
4  *
5  * Copyright 2021 Google LLC
6  * Written by Simon Glass <sjg@chromium.org>
7  */
8 
9 #include <bootdev.h>
10 #include <dm.h>
11 #include <usb.h>
12 
usb_bootdev_bind(struct udevice * dev)13 static int usb_bootdev_bind(struct udevice *dev)
14 {
15 	struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev);
16 
17 	ucp->prio = BOOTDEVP_5_SCAN_SLOW;
18 
19 	return 0;
20 }
21 
usb_bootdev_hunt(struct bootdev_hunter * info,bool show)22 static int usb_bootdev_hunt(struct bootdev_hunter *info, bool show)
23 {
24 	if (usb_started)
25 		return 0;
26 
27 	return usb_init();
28 }
29 
30 struct bootdev_ops usb_bootdev_ops = {
31 };
32 
33 static const struct udevice_id usb_bootdev_ids[] = {
34 	{ .compatible = "u-boot,bootdev-usb" },
35 	{ }
36 };
37 
38 U_BOOT_DRIVER(usb_bootdev) = {
39 	.name		= "usb_bootdev",
40 	.id		= UCLASS_BOOTDEV,
41 	.ops		= &usb_bootdev_ops,
42 	.bind		= usb_bootdev_bind,
43 	.of_match	= usb_bootdev_ids,
44 };
45 
46 BOOTDEV_HUNTER(usb_bootdev_hunter) = {
47 	.prio		= BOOTDEVP_5_SCAN_SLOW,
48 	.uclass		= UCLASS_USB,
49 	.hunt		= usb_bootdev_hunt,
50 	.drv		= DM_DRIVER_REF(usb_bootdev),
51 };
52