blob: 56a6171876b3dea422c9903e80139165c57db0e8 [file] [log] [blame]
Zhikang Zhang145b88f2017-08-03 02:30:57 -07001/*
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 Zhang145b88f2017-08-03 02:30:57 -070014static int nvme_uclass_post_probe(struct udevice *udev)
15{
16 char name[20];
Zhikang Zhang145b88f2017-08-03 02:30:57 -070017 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 Meng348187382017-08-22 08:15:16 -070023 /*
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 Zhang145b88f2017-08-03 02:30:57 -070028
29 /* The real blksz and size will be set by nvme_blk_probe() */
Bin Mengfbd422b2017-08-22 08:15:15 -070030 ret = blk_create_devicef(udev, "nvme-blk", name, IF_TYPE_NVME,
Bin Meng348187382017-08-22 08:15:16 -070031 -1, 512, 0, &ns_udev);
32 if (ret)
Zhikang Zhang145b88f2017-08-03 02:30:57 -070033 return ret;
Zhikang Zhang145b88f2017-08-03 02:30:57 -070034 }
35
36 return 0;
37}
38
39UCLASS_DRIVER(nvme) = {
40 .name = "nvme",
41 .id = UCLASS_NVME,
Zhikang Zhang145b88f2017-08-03 02:30:57 -070042 .post_probe = nvme_uclass_post_probe,
Zhikang Zhang145b88f2017-08-03 02:30:57 -070043};