Tony Dinh | a87cbb8 | 2023-10-11 13:26:42 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Bootdev for sata |
| 4 | * |
| 5 | * Copyright 2023 Tony Dinh <mibodhi@gmail.com> |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <ahci.h> |
| 10 | #include <bootdev.h> |
| 11 | #include <dm.h> |
| 12 | #include <init.h> |
| 13 | #include <sata.h> |
| 14 | |
| 15 | static int sata_bootdev_bind(struct udevice *dev) |
| 16 | { |
| 17 | struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev); |
| 18 | |
| 19 | ucp->prio = BOOTDEVP_4_SCAN_FAST; |
| 20 | |
| 21 | return 0; |
| 22 | } |
| 23 | |
| 24 | static int sata_bootdev_hunt(struct bootdev_hunter *info, bool show) |
| 25 | { |
| 26 | int ret; |
| 27 | |
| 28 | if (IS_ENABLED(CONFIG_PCI)) { |
| 29 | ret = pci_init(); |
| 30 | if (ret) |
| 31 | return ret; |
| 32 | } |
| 33 | |
| 34 | ret = sata_rescan(true); |
| 35 | if (ret) |
| 36 | return ret; |
| 37 | |
| 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | struct bootdev_ops sata_bootdev_ops = { |
| 42 | }; |
| 43 | |
| 44 | static const struct udevice_id sata_bootdev_ids[] = { |
| 45 | { .compatible = "u-boot,bootdev-sata" }, |
| 46 | { } |
| 47 | }; |
| 48 | |
| 49 | U_BOOT_DRIVER(sata_bootdev) = { |
| 50 | .name = "sata_bootdev", |
| 51 | .id = UCLASS_BOOTDEV, |
| 52 | .ops = &sata_bootdev_ops, |
| 53 | .bind = sata_bootdev_bind, |
| 54 | .of_match = sata_bootdev_ids, |
| 55 | }; |
| 56 | |
| 57 | BOOTDEV_HUNTER(sata_bootdev_hunter) = { |
| 58 | .prio = BOOTDEVP_4_SCAN_FAST, |
| 59 | .uclass = UCLASS_AHCI, |
| 60 | .hunt = sata_bootdev_hunt, |
| 61 | .drv = DM_DRIVER_REF(sata_bootdev), |
| 62 | }; |