blob: 460887c7da343388569d6f1138e32e4e556d9333 [file] [log] [blame]
Abdellatif El Khlifi6db33c22023-04-17 10:11:53 +01001// 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 Khlifi6db33c22023-04-17 10:11:53 +01009#include <dm.h>
10#include <fdt_support.h>
11#include <linux/errno.h>
12#include "nvmxip.h"
13
14#include <asm/global_data.h>
15DECLARE_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 */
29static 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 Vasutb9c74262023-08-23 02:18:19 +020052 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 Khlifi6db33c22023-04-17 10:11:53 +010054
55 return 0;
56}
57
58static const struct udevice_id nvmxip_qspi_ids[] = {
59 { .compatible = "nvmxip,qspi" },
60 { /* sentinel */ }
61};
62
63U_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 Vasutaec5dc72023-08-23 02:18:17 +020068 .probe = nvmxip_probe,
Abdellatif El Khlifi6db33c22023-04-17 10:11:53 +010069 .plat_auto = sizeof(struct nvmxip_plat),
70};