Abdellatif El Khlifi | 6db33c2 | 2023-04-17 10:11:53 +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 | 6db33c2 | 2023-04-17 10:11:53 +0100 | [diff] [blame] | 9 | #include <dm.h> |
| 10 | #include <fdt_support.h> |
Heinrich Schuchardt | ab397a5 | 2024-07-15 15:19:50 +0200 | [diff] [blame] | 11 | #include <nvmxip.h> |
Abdellatif El Khlifi | 6db33c2 | 2023-04-17 10:11:53 +0100 | [diff] [blame] | 12 | #include <linux/errno.h> |
Abdellatif El Khlifi | 6db33c2 | 2023-04-17 10:11:53 +0100 | [diff] [blame] | 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 | { |
| 31 | struct nvmxip_plat *plat = dev_get_plat(dev); |
| 32 | int ret; |
| 33 | |
| 34 | plat->phys_base = (phys_addr_t)dev_read_addr(dev); |
| 35 | if (plat->phys_base == FDT_ADDR_T_NONE) { |
| 36 | log_err("[%s]: can not get base address from device tree\n", dev->name); |
| 37 | return -EINVAL; |
| 38 | } |
| 39 | |
| 40 | ret = dev_read_u32(dev, "lba_shift", &plat->lba_shift); |
| 41 | if (ret) { |
| 42 | log_err("[%s]: can not get lba_shift from device tree\n", dev->name); |
| 43 | return -EINVAL; |
| 44 | } |
| 45 | |
| 46 | ret = dev_read_u32(dev, "lba", (u32 *)&plat->lba); |
| 47 | if (ret) { |
| 48 | log_err("[%s]: can not get lba from device tree\n", dev->name); |
| 49 | return -EINVAL; |
| 50 | } |
| 51 | |
Marek Vasut | b9c7426 | 2023-08-23 02:18:19 +0200 | [diff] [blame] | 52 | log_debug("[%s]: XIP device base addr: 0x%p , lba_shift: %d , lbas: %lu\n", |
| 53 | dev->name, (void *)(uintptr_t)plat->phys_base, plat->lba_shift, plat->lba); |
Abdellatif El Khlifi | 6db33c2 | 2023-04-17 10:11:53 +0100 | [diff] [blame] | 54 | |
| 55 | return 0; |
| 56 | } |
| 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, |
Marek Vasut | aec5dc7 | 2023-08-23 02:18:17 +0200 | [diff] [blame] | 68 | .probe = nvmxip_probe, |
Abdellatif El Khlifi | 6db33c2 | 2023-04-17 10:11:53 +0100 | [diff] [blame] | 69 | .plat_auto = sizeof(struct nvmxip_plat), |
| 70 | }; |