Zhikang Zhang | 982388e | 2017-08-03 02:30:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 NXP Semiconductors |
| 3 | * Copyright (C) 2017 Bin Meng <bmeng.cn@gmail.com> |
| 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0+ |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 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 | }; |