Abdellatif El Khlifi | 857360c | 2023-04-17 10:11:52 +0100 | [diff] [blame] | 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 | |
Abdellatif El Khlifi | 857360c | 2023-04-17 10:11:52 +0100 | [diff] [blame] | 9 | #include <dm.h> |
| 10 | #include <log.h> |
Heinrich Schuchardt | ab397a5 | 2024-07-15 15:19:50 +0200 | [diff] [blame] | 11 | #include <nvmxip.h> |
Abdellatif El Khlifi | 6b00587 | 2023-04-17 10:11:55 +0100 | [diff] [blame] | 12 | #if CONFIG_IS_ENABLED(SANDBOX64) |
| 13 | #include <asm/test.h> |
| 14 | #endif |
Abdellatif El Khlifi | 857360c | 2023-04-17 10:11:52 +0100 | [diff] [blame] | 15 | #include <linux/bitops.h> |
Abdellatif El Khlifi | 857360c | 2023-04-17 10:11:52 +0100 | [diff] [blame] | 16 | |
| 17 | /* LBA Macros */ |
| 18 | |
| 19 | #define DEFAULT_LBA_SHIFT 10 /* 1024 bytes per block */ |
| 20 | #define DEFAULT_LBA_COUNT 1024 /* block count */ |
| 21 | |
| 22 | #define DEFAULT_LBA_SZ BIT(DEFAULT_LBA_SHIFT) |
| 23 | |
Marek Vasut | aec5dc7 | 2023-08-23 02:18:17 +0200 | [diff] [blame] | 24 | int nvmxip_probe(struct udevice *udev) |
Abdellatif El Khlifi | 857360c | 2023-04-17 10:11:52 +0100 | [diff] [blame] | 25 | { |
| 26 | int ret; |
| 27 | struct udevice *bdev = NULL; |
| 28 | char bdev_name[NVMXIP_BLKDEV_NAME_SZ + 1]; |
| 29 | int devnum; |
| 30 | |
Abdellatif El Khlifi | 857360c | 2023-04-17 10:11:52 +0100 | [diff] [blame] | 31 | devnum = uclass_id_count(UCLASS_NVMXIP); |
| 32 | snprintf(bdev_name, NVMXIP_BLKDEV_NAME_SZ, "blk#%d", devnum); |
| 33 | |
| 34 | ret = blk_create_devicef(udev, NVMXIP_BLKDRV_NAME, bdev_name, UCLASS_NVMXIP, |
| 35 | devnum, DEFAULT_LBA_SZ, |
| 36 | DEFAULT_LBA_COUNT, &bdev); |
| 37 | if (ret) { |
| 38 | log_err("[%s]: failure during creation of the block device %s, error %d\n", |
| 39 | udev->name, bdev_name, ret); |
| 40 | return ret; |
| 41 | } |
| 42 | |
| 43 | ret = blk_probe_or_unbind(bdev); |
| 44 | if (ret) { |
| 45 | log_err("[%s]: failure during probing the block device %s, error %d\n", |
| 46 | udev->name, bdev_name, ret); |
| 47 | return ret; |
| 48 | } |
| 49 | |
| 50 | log_info("[%s]: the block device %s ready for use\n", udev->name, bdev_name); |
| 51 | |
Marek Vasut | aec5dc7 | 2023-08-23 02:18:17 +0200 | [diff] [blame] | 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | static int nvmxip_post_bind(struct udevice *udev) |
| 56 | { |
| 57 | dev_or_flags(udev, DM_FLAG_PROBE_AFTER_BIND); |
Abdellatif El Khlifi | 857360c | 2023-04-17 10:11:52 +0100 | [diff] [blame] | 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | UCLASS_DRIVER(nvmxip) = { |
| 62 | .name = "nvmxip", |
| 63 | .id = UCLASS_NVMXIP, |
| 64 | .post_bind = nvmxip_post_bind, |
| 65 | }; |