blob: 362b46dc466ebc92af987d3031dcefa6c407c10f [file] [log] [blame]
Simon Glasse1917ef2022-04-24 23:31:23 -06001// SPDX-License-Identifier: GPL-2.0+
2/*
Simon Glass41571582023-07-12 09:04:32 -06003 * Bootdev for USB
Simon Glasse1917ef2022-04-24 23:31:23 -06004 *
5 * Copyright 2021 Google LLC
6 * Written by Simon Glass <sjg@chromium.org>
7 */
8
Simon Glasse1917ef2022-04-24 23:31:23 -06009#include <bootdev.h>
10#include <dm.h>
11#include <usb.h>
12
Simon Glasse1917ef2022-04-24 23:31:23 -060013static int usb_bootdev_bind(struct udevice *dev)
14{
15 struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev);
16
Simon Glass7e1f6a42023-01-17 10:48:08 -070017 ucp->prio = BOOTDEVP_5_SCAN_SLOW;
Simon Glasse1917ef2022-04-24 23:31:23 -060018
19 return 0;
20}
21
Simon Glassf3cb89f2023-01-17 10:47:37 -070022static int usb_bootdev_hunt(struct bootdev_hunter *info, bool show)
23{
Simon Glass4bb7c162023-05-05 20:03:04 -060024 if (usb_started)
25 return 0;
26
Simon Glassf3cb89f2023-01-17 10:47:37 -070027 return usb_init();
28}
29
Simon Glasse1917ef2022-04-24 23:31:23 -060030struct bootdev_ops usb_bootdev_ops = {
Simon Glasse1917ef2022-04-24 23:31:23 -060031};
32
33static const struct udevice_id usb_bootdev_ids[] = {
34 { .compatible = "u-boot,bootdev-usb" },
35 { }
36};
37
38U_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};
Simon Glassf3cb89f2023-01-17 10:47:37 -070045
46BOOTDEV_HUNTER(usb_bootdev_hunter) = {
Simon Glass7e1f6a42023-01-17 10:48:08 -070047 .prio = BOOTDEVP_5_SCAN_SLOW,
Simon Glassf3cb89f2023-01-17 10:47:37 -070048 .uclass = UCLASS_USB,
49 .hunt = usb_bootdev_hunt,
50 .drv = DM_DRIVER_REF(usb_bootdev),
51};