blob: 334628cebfc5c75e868b0cf0296601f111ae9f6c [file] [log] [blame]
Zhikang Zhang982388e2017-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
14static int nvme_info_init(struct uclass *uc)
15{
16 struct nvme_info *info = (struct nvme_info *)uc->priv;
17
18 info->ns_num = 0;
19 info->ndev_num = 0;
20 INIT_LIST_HEAD(&info->dev_list);
21 nvme_info = info;
22
23 return 0;
24}
25
26static int nvme_uclass_post_probe(struct udevice *udev)
27{
28 char name[20];
Zhikang Zhang982388e2017-08-03 02:30:57 -070029 struct udevice *ns_udev;
30 int i, ret;
31 struct nvme_dev *ndev = dev_get_priv(udev);
32
33 /* Create a blk device for each namespace */
34 for (i = 0; i < ndev->nn; i++) {
Bin Mengd5b7ee92017-08-22 08:15:15 -070035 sprintf(name, "blk#%d", nvme_info->ns_num);
Zhikang Zhang982388e2017-08-03 02:30:57 -070036
37 /* The real blksz and size will be set by nvme_blk_probe() */
Bin Mengd5b7ee92017-08-22 08:15:15 -070038 ret = blk_create_devicef(udev, "nvme-blk", name, IF_TYPE_NVME,
39 nvme_info->ns_num++, 512, 0, &ns_udev);
Zhikang Zhang982388e2017-08-03 02:30:57 -070040 if (ret) {
Zhikang Zhang982388e2017-08-03 02:30:57 -070041 nvme_info->ns_num--;
42
43 return ret;
44 }
Zhikang Zhang982388e2017-08-03 02:30:57 -070045 }
46
47 return 0;
48}
49
50UCLASS_DRIVER(nvme) = {
51 .name = "nvme",
52 .id = UCLASS_NVME,
53 .init = nvme_info_init,
54 .post_probe = nvme_uclass_post_probe,
55 .priv_auto_alloc_size = sizeof(struct nvme_info),
56};