Prepare v2024.10
[platform/kernel/u-boot.git] / drivers / axi / axi-emul-uclass.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2018
4  * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
5  */
6
7 #define LOG_CATEGORY UCLASS_AXI_EMUL
8
9 #include <axi.h>
10 #include <dm.h>
11 #include <log.h>
12 #include <dm/device-internal.h>
13 #include <asm/axi.h>
14
15 int axi_sandbox_get_emul(struct udevice *bus, ulong address,
16                          const enum axi_size_t size, struct udevice **emulp)
17 {
18         struct udevice *dev;
19         u32 reg[2];
20         uint offset;
21
22         switch (size) {
23         case AXI_SIZE_8:
24                 offset = 1;
25                 break;
26         case AXI_SIZE_16:
27                 offset = 2;
28                 break;
29         case AXI_SIZE_32:
30                 offset = 4;
31                 break;
32         default:
33                 debug("%s: Unknown AXI transfer size '%d'", bus->name, size);
34                 offset = 0;
35         }
36
37         /*
38          * Note: device_find_* don't activate the devices; they're activated
39          *       as-needed below.
40          */
41         for (device_find_first_child(bus, &dev);
42              dev;
43              device_find_next_child(&dev)) {
44                 int ret;
45
46                 ret = dev_read_u32_array(dev, "reg", reg, ARRAY_SIZE(reg));
47                 if (ret) {
48                         debug("%s: Could not read 'reg' property of %s\n",
49                               bus->name, dev->name);
50                         continue;
51                 }
52
53                 /*
54                  * Does the transfer's address fall into this device's address
55                  * space?
56                  */
57                 if (address >= reg[0] && address <= reg[0] + reg[1] - offset) {
58                         /* If yes, activate it... */
59                         if (device_probe(dev)) {
60                                 debug("%s: Could not activate %s\n",
61                                       bus->name, dev->name);
62                                 return -ENODEV;
63                         }
64
65                         /* ...and return it */
66                         *emulp = dev;
67                         return 0;
68                 }
69         }
70
71         return -ENODEV;
72 }
73
74 int axi_get_store(struct udevice *dev, u8 **storep)
75 {
76         struct axi_emul_ops *ops = axi_emul_get_ops(dev);
77
78         if (!ops->get_store)
79                 return -ENOSYS;
80
81         return ops->get_store(dev, storep);
82 }
83
84 UCLASS_DRIVER(axi_emul) = {
85         .id             = UCLASS_AXI_EMUL,
86         .name           = "axi_emul",
87 };