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 <ahci.h>
9 #include <bootdev.h>
10 #include <dm.h>
11 #include <init.h>
12 #include <sata.h>
13
sata_bootdev_bind(struct udevice * dev)14 static int sata_bootdev_bind(struct udevice *dev)
15 {
16 struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev);
17
18 ucp->prio = BOOTDEVP_4_SCAN_FAST;
19
20 return 0;
21 }
22
sata_bootdev_hunt(struct bootdev_hunter * info,bool show)23 static int sata_bootdev_hunt(struct bootdev_hunter *info, bool show)
24 {
25 int ret;
26
27 if (IS_ENABLED(CONFIG_PCI)) {
28 ret = pci_init();
29 if (ret)
30 return ret;
31 }
32
33 ret = sata_rescan(true);
34 if (ret)
35 return ret;
36
37 return 0;
38 }
39
40 struct bootdev_ops sata_bootdev_ops = {
41 };
42
43 static const struct udevice_id sata_bootdev_ids[] = {
44 { .compatible = "u-boot,bootdev-sata" },
45 { }
46 };
47
48 U_BOOT_DRIVER(sata_bootdev) = {
49 .name = "sata_bootdev",
50 .id = UCLASS_BOOTDEV,
51 .ops = &sata_bootdev_ops,
52 .bind = sata_bootdev_bind,
53 .of_match = sata_bootdev_ids,
54 };
55
56 BOOTDEV_HUNTER(sata_bootdev_hunter) = {
57 .prio = BOOTDEVP_4_SCAN_FAST,
58 .uclass = UCLASS_AHCI,
59 .hunt = sata_bootdev_hunt,
60 .drv = DM_DRIVER_REF(sata_bootdev),
61 };
62