blob: 277e31e1f3973de54198312d9884693d85a49bd5 [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>
Simon Glass655306c2020-05-10 11:39:58 -06008#include <blk.h>
Zhikang Zhang145b88f2017-08-03 02:30:57 -07009#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};