1/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * (C) Copyright 2017, 2018
4 * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
5 */
6
7#ifndef _AXI_H_
8#define _AXI_H_
9
10struct udevice;
11
12/**
13 * enum axi_size_t - Determine size of AXI transfer
14 * @AXI_SIZE_8:  AXI sransfer is 8-bit wide
15 * @AXI_SIZE_16: AXI sransfer is 16-bit wide
16 * @AXI_SIZE_32: AXI sransfer is 32-bit wide
17 */
18enum axi_size_t {
19	AXI_SIZE_8,
20	AXI_SIZE_16,
21	AXI_SIZE_32,
22};
23
24struct axi_ops {
25	/**
26	 * read() - Read a single value from a specified address on a AXI bus
27	 * @dev:	AXI bus to read from.
28	 * @address:	The address to read from.
29	 * @data:	Pointer to a variable that takes the data value read
30	 *		from the address on the AXI bus.
31	 * @size:	The size of the data to be read.
32	 *
33	 * Return: 0 if OK, -ve on error.
34	 */
35	int (*read)(struct udevice *dev, ulong address, void *data,
36		    enum axi_size_t size);
37
38	/**
39	 * write() - Write a single value to a specified address on a AXI bus
40	 * @dev:	AXI bus to write to.
41	 * @address:	The address to write to.
42	 * @data:	Pointer to the data value to be written to the address
43	 *		on the AXI bus.
44	 * @size:	The size of the data to write.
45	 *
46	 * Return 0 if OK, -ve on error.
47	 */
48	int (*write)(struct udevice *dev, ulong address, void *data,
49		     enum axi_size_t size);
50};
51
52#define axi_get_ops(dev)	((struct axi_ops *)(dev)->driver->ops)
53
54/**
55 * axi_read() - Read a single value from a specified address on a AXI bus
56 * @dev:	AXI bus to read from.
57 * @address:	The address to read from.
58 * @data:	Pointer to a variable that takes the data value read from the
59 *              address on the AXI bus.
60 * @size:	The size of the data to write.
61 *
62 * Return: 0 if OK, -ve on error.
63 */
64int axi_read(struct udevice *dev, ulong address, void *data,
65	     enum axi_size_t size);
66
67/**
68 * axi_write() - Write a single value to a specified address on a AXI bus
69 * @dev:	AXI bus to write to.
70 * @address:	The address to write to.
71 * @data:	Pointer to the data value to be written to the address on the
72 *		AXI bus.
73 * @size:	The size of the data to write.
74 *
75 * Return: 0 if OK, -ve on error.
76 */
77int axi_write(struct udevice *dev, ulong address, void *data,
78	      enum axi_size_t size);
79
80struct axi_emul_ops {
81	/**
82	 * read() - Read a single value from a specified address on a AXI bus
83	 * @dev:	AXI bus to read from.
84	 * @address:	The address to read from.
85	 * @data:	Pointer to a variable that takes the data value read
86	 *		from the address on the AXI bus.
87	 * @size:	The size of the data to be read.
88	 *
89	 * Return: 0 if OK, -ve on error.
90	 */
91	int (*read)(struct udevice *dev, ulong address, void *data,
92		    enum axi_size_t size);
93
94	/**
95	 * write() - Write a single value to a specified address on a AXI bus
96	 * @dev:	AXI bus to write to.
97	 * @address:	The address to write to.
98	 * @data:	Pointer to the data value to be written to the address
99	 *		on the AXI bus.
100	 * @size:	The size of the data to write.
101	 *
102	 * Return: 0 if OK, -ve on error.
103	 */
104	int (*write)(struct udevice *dev, ulong address, void *data,
105		     enum axi_size_t size);
106
107	/**
108	 * get_store() - Get address of internal storage of a emulated AXI
109	 *		 device
110	 * @dev:	Emulated AXI device to get the pointer of the internal
111	 *		storage for.
112	 * @storep:	Pointer to the internal storage of the emulated AXI
113	 *		device.
114	 *
115	 * Return: 0 if OK, -ve on error.
116	 */
117	int (*get_store)(struct udevice *dev, u8 **storep);
118};
119
120#endif
121