aboutsummaryrefslogtreecommitdiff
path: root/drivers/axi/axi_sandbox.c
blob: b91c91f6b3b6368d2645d59cc400c35748470c37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// SPDX-License-Identifier: GPL-2.0+
/*
 * (C) Copyright 2018
 * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
 */

#include <common.h>
#include <axi.h>
#include <dm.h>
#include <asm/axi.h>

/*
 * This driver implements a AXI bus for the sandbox architecture for testing
 * purposes.
 *
 * The bus forwards every access to it to a special AXI emulation device (which
 * it gets via the axi_emul_get_ops function) that implements a simple
 * read/write storage.
 *
 * The emulator device must still be contained in the device tree in the usual
 * way, since configuration data for the storage is read from the DT.
 */

static int axi_sandbox_read(struct udevice *bus, ulong address, void *data,
			    enum axi_size_t size)
{
	struct axi_emul_ops *ops;
	struct udevice *emul;
	int ret;

	/* Get emulator device */
	ret = axi_sandbox_get_emul(bus, address, size, &emul);
	if (ret)
		return ret == -ENODEV ? 0 : ret;
	/* Forward all reads to the AXI emulator */
	ops = axi_emul_get_ops(emul);
	if (!ops || !ops->read)
		return -ENOSYS;

	return ops->read(emul, address, data, size);
}

static int axi_sandbox_write(struct udevice *bus, ulong address, void *data,
			     enum axi_size_t size)
{
	struct axi_emul_ops *ops;
	struct udevice *emul;
	int ret;

	/* Get emulator device */
	ret = axi_sandbox_get_emul(bus, address, size, &emul);
	if (ret)
		return ret == -ENODEV ? 0 : ret;
	/* Forward all writes to the AXI emulator */
	ops = axi_emul_get_ops(emul);
	if (!ops || !ops->write)
		return -ENOSYS;

	return ops->write(emul, address, data, size);
}

static const struct udevice_id axi_sandbox_ids[] = {
	{ .compatible = "sandbox,axi" },
	{ /* sentinel */ }
};

static const struct axi_ops axi_sandbox_ops = {
	.read = axi_sandbox_read,
	.write = axi_sandbox_write,
};

U_BOOT_DRIVER(axi_sandbox_bus) = {
	.name           = "axi_sandbox_bus",
	.id             = UCLASS_AXI,
	.of_match       = axi_sandbox_ids,
	.ops		= &axi_sandbox_ops,
};