Simon Glass | e1917ef | 2022-04-24 23:31:23 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
Simon Glass | 4157158 | 2023-07-12 09:04:32 -0600 | [diff] [blame^] | 3 | * Bootdev for USB |
Simon Glass | e1917ef | 2022-04-24 23:31:23 -0600 | [diff] [blame] | 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 | |
Simon Glass | e1917ef | 2022-04-24 23:31:23 -0600 | [diff] [blame] | 14 | static int usb_bootdev_bind(struct udevice *dev) |
| 15 | { |
| 16 | struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev); |
| 17 | |
Simon Glass | 7e1f6a4 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 18 | ucp->prio = BOOTDEVP_5_SCAN_SLOW; |
Simon Glass | e1917ef | 2022-04-24 23:31:23 -0600 | [diff] [blame] | 19 | |
| 20 | return 0; |
| 21 | } |
| 22 | |
Simon Glass | f3cb89f | 2023-01-17 10:47:37 -0700 | [diff] [blame] | 23 | static int usb_bootdev_hunt(struct bootdev_hunter *info, bool show) |
| 24 | { |
Simon Glass | 4bb7c16 | 2023-05-05 20:03:04 -0600 | [diff] [blame] | 25 | if (usb_started) |
| 26 | return 0; |
| 27 | |
Simon Glass | f3cb89f | 2023-01-17 10:47:37 -0700 | [diff] [blame] | 28 | return usb_init(); |
| 29 | } |
| 30 | |
Simon Glass | e1917ef | 2022-04-24 23:31:23 -0600 | [diff] [blame] | 31 | struct bootdev_ops usb_bootdev_ops = { |
Simon Glass | e1917ef | 2022-04-24 23:31:23 -0600 | [diff] [blame] | 32 | }; |
| 33 | |
| 34 | static const struct udevice_id usb_bootdev_ids[] = { |
| 35 | { .compatible = "u-boot,bootdev-usb" }, |
| 36 | { } |
| 37 | }; |
| 38 | |
| 39 | U_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 Glass | f3cb89f | 2023-01-17 10:47:37 -0700 | [diff] [blame] | 46 | |
| 47 | BOOTDEV_HUNTER(usb_bootdev_hunter) = { |
Simon Glass | 7e1f6a4 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 48 | .prio = BOOTDEVP_5_SCAN_SLOW, |
Simon Glass | f3cb89f | 2023-01-17 10:47:37 -0700 | [diff] [blame] | 49 | .uclass = UCLASS_USB, |
| 50 | .hunt = usb_bootdev_hunt, |
| 51 | .drv = DM_DRIVER_REF(usb_bootdev), |
| 52 | }; |