blob: 44c88ad27f3e20d70162b52a31356e1452e7dfd3 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Zhikang Zhang145b88f2017-08-03 02:30:57 -07002/*
3 * Copyright (C) 2017 NXP Semiconductors
4 * Copyright (C) 2017 Bin Meng <bmeng.cn@gmail.com>
Zhikang Zhang145b88f2017-08-03 02:30:57 -07005 */
6
Patrick Delaunay81313352021-04-27 11:02:19 +02007#define LOG_CATEGORY UCLASS_NVME
8
Simon Glass08382872023-01-17 10:47:47 -07009#include <bootdev.h>
Zhikang Zhang145b88f2017-08-03 02:30:57 -070010#include <dm.h>
Simon Glass08382872023-01-17 10:47:47 -070011#include <init.h>
12#include <log.h>
13#include <nvme.h>
14
15static int nvme_bootdev_bind(struct udevice *dev)
16{
17 struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev);
18
Simon Glass7e1f6a42023-01-17 10:48:08 -070019 ucp->prio = BOOTDEVP_4_SCAN_FAST;
Simon Glass08382872023-01-17 10:47:47 -070020
21 return 0;
22}
23
24static int nvme_bootdev_hunt(struct bootdev_hunter *info, bool show)
25{
26 int ret;
27
28 /* init PCI first since this is often used to provide NVMe */
29 if (IS_ENABLED(CONFIG_PCI)) {
30 ret = pci_init();
31 if (ret)
32 log_warning("Failed to init PCI (%dE)\n", ret);
33 }
34
35 ret = nvme_scan_namespace();
36 if (ret)
37 return log_msg_ret("scan", ret);
38
39 return 0;
40}
Zhikang Zhang145b88f2017-08-03 02:30:57 -070041
42UCLASS_DRIVER(nvme) = {
43 .name = "nvme",
44 .id = UCLASS_NVME,
Zhikang Zhang145b88f2017-08-03 02:30:57 -070045};
Simon Glass08382872023-01-17 10:47:47 -070046
47struct bootdev_ops nvme_bootdev_ops = {
48};
49
50static const struct udevice_id nvme_bootdev_ids[] = {
51 { .compatible = "u-boot,bootdev-nvme" },
52 { }
53};
54
55U_BOOT_DRIVER(nvme_bootdev) = {
56 .name = "nvme_bootdev",
57 .id = UCLASS_BOOTDEV,
58 .ops = &nvme_bootdev_ops,
59 .bind = nvme_bootdev_bind,
60 .of_match = nvme_bootdev_ids,
61};
62
63BOOTDEV_HUNTER(nvme_bootdev_hunter) = {
Simon Glass7e1f6a42023-01-17 10:48:08 -070064 .prio = BOOTDEVP_4_SCAN_FAST,
Simon Glass08382872023-01-17 10:47:47 -070065 .uclass = UCLASS_NVME,
66 .hunt = nvme_bootdev_hunt,
67 .drv = DM_DRIVER_REF(nvme_bootdev),
68};