blob: 2d88efdb619ba6500a76631ac52842f4ddfe945d [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Zhikang Zhang145b88f2017-08-03 02:30:57 -07002/*
3 * Copyright (C) 2017 NXP Semiconductors
4 * Copyright (C) 2017 Bin Meng <bmeng.cn@gmail.com>
Zhikang Zhang145b88f2017-08-03 02:30:57 -07005 */
6
7#include <common.h>
8#include <errno.h>
9#include <dm.h>
10#include <dm/device.h>
11#include "nvme.h"
12
Zhikang Zhang145b88f2017-08-03 02:30:57 -070013static int nvme_uclass_post_probe(struct udevice *udev)
14{
15 char name[20];
Zhikang Zhang145b88f2017-08-03 02:30:57 -070016 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++) {
Bin Meng348187382017-08-22 08:15:16 -070022 /*
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);
Zhikang Zhang145b88f2017-08-03 02:30:57 -070027
28 /* The real blksz and size will be set by nvme_blk_probe() */
Bin Mengfbd422b2017-08-22 08:15:15 -070029 ret = blk_create_devicef(udev, "nvme-blk", name, IF_TYPE_NVME,
Bin Meng348187382017-08-22 08:15:16 -070030 -1, 512, 0, &ns_udev);
31 if (ret)
Zhikang Zhang145b88f2017-08-03 02:30:57 -070032 return ret;
Zhikang Zhang145b88f2017-08-03 02:30:57 -070033 }
34
35 return 0;
36}
37
38UCLASS_DRIVER(nvme) = {
39 .name = "nvme",
40 .id = UCLASS_NVME,
Zhikang Zhang145b88f2017-08-03 02:30:57 -070041 .post_probe = nvme_uclass_post_probe,
Zhikang Zhang145b88f2017-08-03 02:30:57 -070042};