Mark Kettenis | f8463d6 | 2022-01-22 20:38:11 +0100 | [diff] [blame] | 1 | // 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 | |
Mark Kettenis | f8463d6 | 2022-01-22 20:38:11 +0100 | [diff] [blame] | 7 | #include <dm.h> |
Simon Glass | 4e969d6 | 2023-05-04 16:55:07 -0600 | [diff] [blame] | 8 | #include <init.h> |
Mark Kettenis | f8463d6 | 2022-01-22 20:38:11 +0100 | [diff] [blame] | 9 | #include <pci.h> |
| 10 | #include "nvme.h" |
| 11 | |
| 12 | static int nvme_bind(struct udevice *udev) |
| 13 | { |
| 14 | static int ndev_num; |
| 15 | char name[20]; |
| 16 | |
| 17 | sprintf(name, "nvme#%d", ndev_num++); |
| 18 | |
| 19 | return device_set_name(udev, name); |
| 20 | } |
| 21 | |
| 22 | static int nvme_probe(struct udevice *udev) |
| 23 | { |
| 24 | struct nvme_dev *ndev = dev_get_priv(udev); |
| 25 | struct pci_child_plat *pplat; |
| 26 | |
| 27 | pplat = dev_get_parent_plat(udev); |
| 28 | sprintf(ndev->vendor, "0x%.4x", pplat->vendor); |
| 29 | |
| 30 | ndev->instance = trailing_strtol(udev->name); |
Andrew Scull | 58c6102 | 2022-04-21 16:11:10 +0000 | [diff] [blame] | 31 | ndev->bar = dm_pci_map_bar(udev, PCI_BASE_ADDRESS_0, 0, 0, |
Andrew Scull | 6520c82 | 2022-04-21 16:11:13 +0000 | [diff] [blame] | 32 | PCI_REGION_TYPE, PCI_REGION_MEM); |
Simon Glass | 4e969d6 | 2023-05-04 16:55:07 -0600 | [diff] [blame] | 33 | |
| 34 | /* Turn on bus-mastering */ |
| 35 | dm_pci_clrset_config16(udev, PCI_COMMAND, 0, PCI_COMMAND_MASTER); |
| 36 | |
Mark Kettenis | f8463d6 | 2022-01-22 20:38:11 +0100 | [diff] [blame] | 37 | return nvme_init(udev); |
| 38 | } |
| 39 | |
| 40 | U_BOOT_DRIVER(nvme) = { |
| 41 | .name = "nvme", |
| 42 | .id = UCLASS_NVME, |
| 43 | .bind = nvme_bind, |
| 44 | .probe = nvme_probe, |
| 45 | .priv_auto = sizeof(struct nvme_dev), |
| 46 | }; |
| 47 | |
| 48 | struct pci_device_id nvme_supported[] = { |
| 49 | { PCI_DEVICE_CLASS(PCI_CLASS_STORAGE_EXPRESS, ~0) }, |
| 50 | {} |
| 51 | }; |
| 52 | |
| 53 | U_BOOT_PCI_DEVICE(nvme, nvme_supported); |