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 <common.h>
10#include <bootdev.h>
11#include <dm.h>
12#include <usb.h>
13
14static int usb_bootdev_bind(struct udevice *dev)
15{
16	struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev);
17
18	ucp->prio = BOOTDEVP_5_SCAN_SLOW;
19
20	return 0;
21}
22
23static int usb_bootdev_hunt(struct bootdev_hunter *info, bool show)
24{
25	if (usb_started)
26		return 0;
27
28	return usb_init();
29}
30
31struct bootdev_ops usb_bootdev_ops = {
32};
33
34static const struct udevice_id usb_bootdev_ids[] = {
35	{ .compatible = "u-boot,bootdev-usb" },
36	{ }
37};
38
39U_BOOT_DRIVER(usb_bootdev) = {
40	.name		= "usb_bootdev",
41	.id		= UCLASS_BOOTDEV,
42	.ops		= &usb_bootdev_ops,
43	.bind		= usb_bootdev_bind,
44	.of_match	= usb_bootdev_ids,
45};
46
47BOOTDEV_HUNTER(usb_bootdev_hunter) = {
48	.prio		= BOOTDEVP_5_SCAN_SLOW,
49	.uclass		= UCLASS_USB,
50	.hunt		= usb_bootdev_hunt,
51	.drv		= DM_DRIVER_REF(usb_bootdev),
52};
53