/src/u-boot/drivers/mtd/nvmxip/nvmxip_qspi.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 <fdt_support.h> |
11 | | #include <nvmxip.h> |
12 | | #include <linux/errno.h> |
13 | | |
14 | | #include <asm/global_data.h> |
15 | | DECLARE_GLOBAL_DATA_PTR; |
16 | | |
17 | | #define NVMXIP_QSPI_DRV_NAME "nvmxip_qspi" |
18 | | |
19 | | /** |
20 | | * nvmxip_qspi_of_to_plat() -read from DT |
21 | | * @dev: the NVMXIP device |
22 | | * |
23 | | * Read from the DT the NVMXIP information. |
24 | | * |
25 | | * Return: |
26 | | * |
27 | | * 0 on success. Otherwise, failure |
28 | | */ |
29 | | static int nvmxip_qspi_of_to_plat(struct udevice *dev) |
30 | 0 | { |
31 | 0 | struct nvmxip_plat *plat = dev_get_plat(dev); |
32 | 0 | int ret; |
33 | |
|
34 | 0 | plat->phys_base = (phys_addr_t)dev_read_addr(dev); |
35 | 0 | if (plat->phys_base == FDT_ADDR_T_NONE) { |
36 | 0 | log_err("[%s]: can not get base address from device tree\n", dev->name); |
37 | 0 | return -EINVAL; |
38 | 0 | } |
39 | | |
40 | 0 | ret = dev_read_u32(dev, "lba_shift", &plat->lba_shift); |
41 | 0 | if (ret) { |
42 | 0 | log_err("[%s]: can not get lba_shift from device tree\n", dev->name); |
43 | 0 | return -EINVAL; |
44 | 0 | } |
45 | | |
46 | 0 | ret = dev_read_u32(dev, "lba", (u32 *)&plat->lba); |
47 | 0 | if (ret) { |
48 | 0 | log_err("[%s]: can not get lba from device tree\n", dev->name); |
49 | 0 | return -EINVAL; |
50 | 0 | } |
51 | | |
52 | 0 | log_debug("[%s]: XIP device base addr: 0x%p , lba_shift: %d , lbas: " LBAF "\n", |
53 | 0 | dev->name, (void *)(uintptr_t)plat->phys_base, plat->lba_shift, plat->lba); |
54 | |
|
55 | 0 | return 0; |
56 | 0 | } |
57 | | |
58 | | static const struct udevice_id nvmxip_qspi_ids[] = { |
59 | | { .compatible = "nvmxip,qspi" }, |
60 | | { /* sentinel */ } |
61 | | }; |
62 | | |
63 | | U_BOOT_DRIVER(nvmxip_qspi) = { |
64 | | .name = NVMXIP_QSPI_DRV_NAME, |
65 | | .id = UCLASS_NVMXIP, |
66 | | .of_match = nvmxip_qspi_ids, |
67 | | .of_to_plat = nvmxip_qspi_of_to_plat, |
68 | | .probe = nvmxip_probe, |
69 | | .plat_auto = sizeof(struct nvmxip_plat), |
70 | | }; |