blob: bea0b040738c3d87181af02409e5c9d808035f5c [file] [log] [blame]
Mario Sixf95104d2018-08-09 14:51:18 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2018
4 * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
5 */
6
Patrick Delaunay81313352021-04-27 11:02:19 +02007#define LOG_CATEGORY UCLASS_AXI_EMUL
8
Mario Sixf95104d2018-08-09 14:51:18 +02009#include <axi.h>
10#include <dm.h>
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
Mario Sixf95104d2018-08-09 14:51:18 +020012#include <dm/device-internal.h>
13#include <asm/axi.h>
14
15int axi_sandbox_get_emul(struct udevice *bus, ulong address,
Heinrich Schuchardtcdf52c72023-05-10 11:59:20 +020016 const enum axi_size_t size, struct udevice **emulp)
Mario Sixf95104d2018-08-09 14:51:18 +020017{
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
74int 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
84UCLASS_DRIVER(axi_emul) = {
85 .id = UCLASS_AXI_EMUL,
86 .name = "axi_emul",
87};