Mario Six | f95104d | 2018-08-09 14:51:18 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) Copyright 2018 |
| 4 | * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc |
| 5 | */ |
| 6 | |
Mario Six | f95104d | 2018-08-09 14:51:18 +0200 | [diff] [blame] | 7 | #include <axi.h> |
| 8 | #include <dm.h> |
| 9 | #include <asm/axi.h> |
| 10 | |
| 11 | /* |
| 12 | * This driver implements a AXI bus for the sandbox architecture for testing |
| 13 | * purposes. |
| 14 | * |
| 15 | * The bus forwards every access to it to a special AXI emulation device (which |
| 16 | * it gets via the axi_emul_get_ops function) that implements a simple |
| 17 | * read/write storage. |
| 18 | * |
| 19 | * The emulator device must still be contained in the device tree in the usual |
| 20 | * way, since configuration data for the storage is read from the DT. |
| 21 | */ |
| 22 | |
| 23 | static int axi_sandbox_read(struct udevice *bus, ulong address, void *data, |
| 24 | enum axi_size_t size) |
| 25 | { |
| 26 | struct axi_emul_ops *ops; |
| 27 | struct udevice *emul; |
| 28 | int ret; |
| 29 | |
| 30 | /* Get emulator device */ |
| 31 | ret = axi_sandbox_get_emul(bus, address, size, &emul); |
| 32 | if (ret) |
| 33 | return ret == -ENODEV ? 0 : ret; |
| 34 | /* Forward all reads to the AXI emulator */ |
| 35 | ops = axi_emul_get_ops(emul); |
| 36 | if (!ops || !ops->read) |
| 37 | return -ENOSYS; |
| 38 | |
| 39 | return ops->read(emul, address, data, size); |
| 40 | } |
| 41 | |
| 42 | static int axi_sandbox_write(struct udevice *bus, ulong address, void *data, |
| 43 | enum axi_size_t size) |
| 44 | { |
| 45 | struct axi_emul_ops *ops; |
| 46 | struct udevice *emul; |
| 47 | int ret; |
| 48 | |
| 49 | /* Get emulator device */ |
| 50 | ret = axi_sandbox_get_emul(bus, address, size, &emul); |
| 51 | if (ret) |
| 52 | return ret == -ENODEV ? 0 : ret; |
| 53 | /* Forward all writes to the AXI emulator */ |
| 54 | ops = axi_emul_get_ops(emul); |
| 55 | if (!ops || !ops->write) |
| 56 | return -ENOSYS; |
| 57 | |
| 58 | return ops->write(emul, address, data, size); |
| 59 | } |
| 60 | |
| 61 | static const struct udevice_id axi_sandbox_ids[] = { |
| 62 | { .compatible = "sandbox,axi" }, |
| 63 | { /* sentinel */ } |
| 64 | }; |
| 65 | |
| 66 | static const struct axi_ops axi_sandbox_ops = { |
| 67 | .read = axi_sandbox_read, |
| 68 | .write = axi_sandbox_write, |
| 69 | }; |
| 70 | |
| 71 | U_BOOT_DRIVER(axi_sandbox_bus) = { |
| 72 | .name = "axi_sandbox_bus", |
| 73 | .id = UCLASS_AXI, |
| 74 | .of_match = axi_sandbox_ids, |
| 75 | .ops = &axi_sandbox_ops, |
| 76 | }; |