sandbox: Add PCI driver and test for p2sb
[oweals/u-boot.git] / drivers / misc / sandbox_adder.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Sandbox adder for p2sb testing
4  *
5  * Copyright 2019 Google LLC
6  */
7
8 #define LOG_CATEGORY UCLASS_MISC
9
10 #include <common.h>
11 #include <axi.h>
12 #include <dm.h>
13 #include <misc.h>
14 #include <p2sb.h>
15 #include <asm/io.h>
16
17 struct sandbox_adder_priv {
18         ulong base;
19 };
20
21 int sandbox_adder_read(struct udevice *dev, ulong address, void *data,
22                        enum axi_size_t size)
23 {
24         struct p2sb_child_platdata *pplat = dev_get_parent_platdata(dev);
25         u32 *val = data;
26
27         *val = pplat->pid << 24 | address;
28
29         return 0;
30 }
31
32 int sandbox_adder_write(struct udevice *dev, ulong address, void *data,
33                         enum axi_size_t size)
34 {
35         return 0;
36 }
37
38 static int sandbox_adder_probe(struct udevice *dev)
39 {
40         return 0;
41 }
42
43 static struct axi_ops sandbox_adder_ops = {
44         .read   = sandbox_adder_read,
45         .write  = sandbox_adder_write,
46 };
47
48 static const struct udevice_id sandbox_adder_ids[] = {
49         { .compatible = "sandbox,adder" },
50         { }
51 };
52
53 U_BOOT_DRIVER(adder_sandbox) = {
54         .name = "sandbox_adder",
55         .id = UCLASS_AXI,
56         .of_match = sandbox_adder_ids,
57         .probe = sandbox_adder_probe,
58         .ops = &sandbox_adder_ops,
59         .priv_auto_alloc_size = sizeof(struct sandbox_adder_priv),
60 };