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 | |
Tom Rini | abb9a04 | 2024-05-18 20:20:43 -0600 | [diff] [blame] | 7 | #include <common.h> |
Mark Kettenis | f8463d6 | 2022-01-22 20:38:11 +0100 | [diff] [blame] | 8 | #include <dm.h> |
Simon Glass | 4e969d6 | 2023-05-04 16:55:07 -0600 | [diff] [blame] | 9 | #include <init.h> |
Mark Kettenis | f8463d6 | 2022-01-22 20:38:11 +0100 | [diff] [blame] | 10 | #include <pci.h> |
| 11 | #include "nvme.h" |
| 12 | |
| 13 | static 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 | |
| 23 | static 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 Scull | 58c6102 | 2022-04-21 16:11:10 +0000 | [diff] [blame] | 32 | 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] | 33 | PCI_REGION_TYPE, PCI_REGION_MEM); |
Simon Glass | 4e969d6 | 2023-05-04 16:55:07 -0600 | [diff] [blame] | 34 | |
| 35 | /* Turn on bus-mastering */ |
| 36 | dm_pci_clrset_config16(udev, PCI_COMMAND, 0, PCI_COMMAND_MASTER); |
| 37 | |
Mark Kettenis | f8463d6 | 2022-01-22 20:38:11 +0100 | [diff] [blame] | 38 | return nvme_init(udev); |
| 39 | } |
| 40 | |
| 41 | U_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 | |
| 49 | struct pci_device_id nvme_supported[] = { |
| 50 | { PCI_DEVICE_CLASS(PCI_CLASS_STORAGE_EXPRESS, ~0) }, |
| 51 | {} |
| 52 | }; |
| 53 | |
| 54 | U_BOOT_PCI_DEVICE(nvme, nvme_supported); |