Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Zhikang Zhang | 982388e | 2017-08-03 02:30:57 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2017 NXP Semiconductors |
| 4 | * Copyright (C) 2017 Bin Meng <bmeng.cn@gmail.com> |
Zhikang Zhang | 982388e | 2017-08-03 02:30:57 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <errno.h> |
| 9 | #include <dm.h> |
| 10 | #include <dm/device.h> |
| 11 | #include "nvme.h" |
| 12 | |
Zhikang Zhang | 982388e | 2017-08-03 02:30:57 -0700 | [diff] [blame] | 13 | static int nvme_uclass_post_probe(struct udevice *udev) |
| 14 | { |
| 15 | char name[20]; |
Zhikang Zhang | 982388e | 2017-08-03 02:30:57 -0700 | [diff] [blame] | 16 | 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 Meng | 18aa5a4 | 2017-08-22 08:15:16 -0700 | [diff] [blame] | 22 | /* |
| 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 Zhang | 982388e | 2017-08-03 02:30:57 -0700 | [diff] [blame] | 27 | |
| 28 | /* The real blksz and size will be set by nvme_blk_probe() */ |
Bin Meng | d5b7ee9 | 2017-08-22 08:15:15 -0700 | [diff] [blame] | 29 | ret = blk_create_devicef(udev, "nvme-blk", name, IF_TYPE_NVME, |
Bin Meng | 18aa5a4 | 2017-08-22 08:15:16 -0700 | [diff] [blame] | 30 | -1, 512, 0, &ns_udev); |
| 31 | if (ret) |
Zhikang Zhang | 982388e | 2017-08-03 02:30:57 -0700 | [diff] [blame] | 32 | return ret; |
Zhikang Zhang | 982388e | 2017-08-03 02:30:57 -0700 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | return 0; |
| 36 | } |
| 37 | |
| 38 | UCLASS_DRIVER(nvme) = { |
| 39 | .name = "nvme", |
| 40 | .id = UCLASS_NVME, |
Zhikang Zhang | 982388e | 2017-08-03 02:30:57 -0700 | [diff] [blame] | 41 | .post_probe = nvme_uclass_post_probe, |
Zhikang Zhang | 982388e | 2017-08-03 02:30:57 -0700 | [diff] [blame] | 42 | }; |