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
7 #include <common.h>
8 #include <errno.h>
9 #include <dm.h>
10 #include <dm/device.h>
11 #include "nvme.h"
12
nvme_uclass_post_probe(struct udevice * udev)13 static int nvme_uclass_post_probe(struct udevice *udev)
14 {
15 char name[20];
16 struct udevice *ns_udev;
17 int i, ret;
18 struct nvme_dev *ndev = dev_get_priv(udev);
19
20 /* Create a blk device for each namespace */
21 for (i = 0; i < ndev->nn; i++) {
22 /*
23 * Encode the namespace id to the device name so that
24 * we can extract it when doing the probe.
25 */
26 sprintf(name, "blk#%d", i);
27
28 /* The real blksz and size will be set by nvme_blk_probe() */
29 ret = blk_create_devicef(udev, "nvme-blk", name, IF_TYPE_NVME,
30 -1, 512, 0, &ns_udev);
31 if (ret)
32 return ret;
33 }
34
35 return 0;
36 }
37
38 UCLASS_DRIVER(nvme) = {
39 .name = "nvme",
40 .id = UCLASS_NVME,
41 .post_probe = nvme_uclass_post_probe,
42 };
43