blob: 7fa1c601dff52fdb166fa96be700a34ac7653748 [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
9#include <common.h>
10#include <bootdev.h>
11#include <dm.h>
12#include <usb.h>
13
Simon Glasse1917ef2022-04-24 23:31:23 -060014static int usb_bootdev_bind(struct udevice *dev)
15{
16 struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev);
17
Simon Glass7e1f6a42023-01-17 10:48:08 -070018 ucp->prio = BOOTDEVP_5_SCAN_SLOW;
Simon Glasse1917ef2022-04-24 23:31:23 -060019
20 return 0;
21}
22
Simon Glassf3cb89f2023-01-17 10:47:37 -070023static int usb_bootdev_hunt(struct bootdev_hunter *info, bool show)
24{
Simon Glass4bb7c162023-05-05 20:03:04 -060025 if (usb_started)
26 return 0;
27
Simon Glassf3cb89f2023-01-17 10:47:37 -070028 return usb_init();
29}
30
Simon Glasse1917ef2022-04-24 23:31:23 -060031struct bootdev_ops usb_bootdev_ops = {
Simon Glasse1917ef2022-04-24 23:31:23 -060032};
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};
Simon Glassf3cb89f2023-01-17 10:47:37 -070046
47BOOTDEV_HUNTER(usb_bootdev_hunter) = {
Simon Glass7e1f6a42023-01-17 10:48:08 -070048 .prio = BOOTDEVP_5_SCAN_SLOW,
Simon Glassf3cb89f2023-01-17 10:47:37 -070049 .uclass = UCLASS_USB,
50 .hunt = usb_bootdev_hunt,
51 .drv = DM_DRIVER_REF(usb_bootdev),
52};