blob: 5bb43d299fca865577ac1daf2fb6be1327e11f27 [file] [log] [blame]
Mark Kettenis045474b2022-01-22 20:38:11 +01001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2017 NXP Semiconductors
4 * Copyright (C) 2017 Bin Meng <bmeng.cn@gmail.com>
5 */
6
7#include <common.h>
8#include <dm.h>
Simon Glass38534712023-05-04 16:55:07 -06009#include <init.h>
Mark Kettenis045474b2022-01-22 20:38:11 +010010#include <pci.h>
11#include "nvme.h"
12
13static int nvme_bind(struct udevice *udev)
14{
15 static int ndev_num;
16 char name[20];
17
18 sprintf(name, "nvme#%d", ndev_num++);
19
20 return device_set_name(udev, name);
21}
22
23static int nvme_probe(struct udevice *udev)
24{
25 struct nvme_dev *ndev = dev_get_priv(udev);
26 struct pci_child_plat *pplat;
27
28 pplat = dev_get_parent_plat(udev);
29 sprintf(ndev->vendor, "0x%.4x", pplat->vendor);
30
31 ndev->instance = trailing_strtol(udev->name);
Andrew Scull12507a22022-04-21 16:11:10 +000032 ndev->bar = dm_pci_map_bar(udev, PCI_BASE_ADDRESS_0, 0, 0,
Andrew Scull2635e3b2022-04-21 16:11:13 +000033 PCI_REGION_TYPE, PCI_REGION_MEM);
Simon Glass38534712023-05-04 16:55:07 -060034
35 /* Turn on bus-mastering */
36 dm_pci_clrset_config16(udev, PCI_COMMAND, 0, PCI_COMMAND_MASTER);
37
Mark Kettenis045474b2022-01-22 20:38:11 +010038 return nvme_init(udev);
39}
40
41U_BOOT_DRIVER(nvme) = {
42 .name = "nvme",
43 .id = UCLASS_NVME,
44 .bind = nvme_bind,
45 .probe = nvme_probe,
46 .priv_auto = sizeof(struct nvme_dev),
47};
48
49struct pci_device_id nvme_supported[] = {
50 { PCI_DEVICE_CLASS(PCI_CLASS_STORAGE_EXPRESS, ~0) },
51 {}
52};
53
54U_BOOT_PCI_DEVICE(nvme, nvme_supported);