/src/u-boot/drivers/mtd/nvmxip/nvmxip-uclass.c
Line | Count | Source |
1 | | // SPDX-License-Identifier: GPL-2.0+ |
2 | | /* |
3 | | * Copyright 2023 Arm Limited and/or its affiliates <open-source-office@arm.com> |
4 | | * |
5 | | * Authors: |
6 | | * Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com> |
7 | | */ |
8 | | |
9 | | #include <dm.h> |
10 | | #include <log.h> |
11 | | #include <nvmxip.h> |
12 | | #if CONFIG_IS_ENABLED(SANDBOX64) |
13 | | #include <asm/test.h> |
14 | | #endif |
15 | | #include <linux/bitops.h> |
16 | | |
17 | | /* LBA Macros */ |
18 | | |
19 | | #define DEFAULT_LBA_SHIFT 10 /* 1024 bytes per block */ |
20 | 0 | #define DEFAULT_LBA_COUNT 1024 /* block count */ |
21 | | |
22 | 0 | #define DEFAULT_LBA_SZ BIT(DEFAULT_LBA_SHIFT) |
23 | | |
24 | | int nvmxip_probe(struct udevice *udev) |
25 | 0 | { |
26 | 0 | int ret; |
27 | 0 | struct udevice *bdev = NULL; |
28 | 0 | char bdev_name[NVMXIP_BLKDEV_NAME_SZ + 1]; |
29 | 0 | int devnum; |
30 | |
|
31 | 0 | devnum = uclass_id_count(UCLASS_NVMXIP); |
32 | 0 | snprintf(bdev_name, NVMXIP_BLKDEV_NAME_SZ, "blk#%d", devnum); |
33 | |
|
34 | 0 | ret = blk_create_devicef(udev, NVMXIP_BLKDRV_NAME, bdev_name, UCLASS_NVMXIP, |
35 | 0 | devnum, DEFAULT_LBA_SZ, |
36 | 0 | DEFAULT_LBA_COUNT, &bdev); |
37 | 0 | if (ret) { |
38 | 0 | log_err("[%s]: failure during creation of the block device %s, error %d\n", |
39 | 0 | udev->name, bdev_name, ret); |
40 | 0 | return ret; |
41 | 0 | } |
42 | | |
43 | 0 | ret = blk_probe_or_unbind(bdev); |
44 | 0 | if (ret) { |
45 | 0 | log_err("[%s]: failure during probing the block device %s, error %d\n", |
46 | 0 | udev->name, bdev_name, ret); |
47 | 0 | return ret; |
48 | 0 | } |
49 | | |
50 | 0 | log_debug("[%s]: the block device %s ready for use\n", udev->name, |
51 | 0 | bdev_name); |
52 | |
|
53 | 0 | return 0; |
54 | 0 | } |
55 | | |
56 | | UCLASS_DRIVER(nvmxip) = { |
57 | | .name = "nvmxip", |
58 | | .id = UCLASS_NVMXIP, |
59 | | }; |