Merge tag 'ti-v2020.07-rc3' of https://gitlab.denx.de/u-boot/custodians/u-boot-ti
[oweals/u-boot.git] / drivers / nvme / nvme-uclass.c
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 <blk.h>
9 #include <errno.h>
10 #include <dm.h>
11 #include <dm/device.h>
12 #include "nvme.h"
13
14 static int nvme_uclass_post_probe(struct udevice *udev)
15 {
16         char name[20];
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++) {
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);
28
29                 /* The real blksz and size will be set by nvme_blk_probe() */
30                 ret = blk_create_devicef(udev, "nvme-blk", name, IF_TYPE_NVME,
31                                          -1, 512, 0, &ns_udev);
32                 if (ret)
33                         return ret;
34         }
35
36         return 0;
37 }
38
39 UCLASS_DRIVER(nvme) = {
40         .name   = "nvme",
41         .id     = UCLASS_NVME,
42         .post_probe = nvme_uclass_post_probe,
43 };