Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Zhikang Zhang | 982388e | 2017-08-03 02:30:57 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2017 NXP Semiconductors |
| 4 | * Copyright (C) 2017 Bin Meng <bmeng.cn@gmail.com> |
Zhikang Zhang | 982388e | 2017-08-03 02:30:57 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | e6f6f9e | 2020-05-10 11:39:58 -0600 | [diff] [blame] | 8 | #include <blk.h> |
Zhikang Zhang | 982388e | 2017-08-03 02:30:57 -0700 | [diff] [blame] | 9 | #include <errno.h> |
| 10 | #include <dm.h> |
| 11 | #include <dm/device.h> |
| 12 | #include "nvme.h" |
| 13 | |
Zhikang Zhang | 982388e | 2017-08-03 02:30:57 -0700 | [diff] [blame] | 14 | static int nvme_uclass_post_probe(struct udevice *udev) |
| 15 | { |
| 16 | char name[20]; |
Zhikang Zhang | 982388e | 2017-08-03 02:30:57 -0700 | [diff] [blame] | 17 | struct udevice *ns_udev; |
| 18 | int i, ret; |
| 19 | struct nvme_dev *ndev = dev_get_priv(udev); |
| 20 | |
| 21 | /* Create a blk device for each namespace */ |
| 22 | for (i = 0; i < ndev->nn; i++) { |
Bin Meng | 18aa5a4 | 2017-08-22 08:15:16 -0700 | [diff] [blame] | 23 | /* |
| 24 | * Encode the namespace id to the device name so that |
| 25 | * we can extract it when doing the probe. |
| 26 | */ |
| 27 | sprintf(name, "blk#%d", i); |
Zhikang Zhang | 982388e | 2017-08-03 02:30:57 -0700 | [diff] [blame] | 28 | |
| 29 | /* The real blksz and size will be set by nvme_blk_probe() */ |
Bin Meng | d5b7ee9 | 2017-08-22 08:15:15 -0700 | [diff] [blame] | 30 | ret = blk_create_devicef(udev, "nvme-blk", name, IF_TYPE_NVME, |
Bin Meng | 18aa5a4 | 2017-08-22 08:15:16 -0700 | [diff] [blame] | 31 | -1, 512, 0, &ns_udev); |
| 32 | if (ret) |
Zhikang Zhang | 982388e | 2017-08-03 02:30:57 -0700 | [diff] [blame] | 33 | return ret; |
Zhikang Zhang | 982388e | 2017-08-03 02:30:57 -0700 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | return 0; |
| 37 | } |
| 38 | |
| 39 | UCLASS_DRIVER(nvme) = { |
| 40 | .name = "nvme", |
| 41 | .id = UCLASS_NVME, |
Zhikang Zhang | 982388e | 2017-08-03 02:30:57 -0700 | [diff] [blame] | 42 | .post_probe = nvme_uclass_post_probe, |
Zhikang Zhang | 982388e | 2017-08-03 02:30:57 -0700 | [diff] [blame] | 43 | }; |