xref: /openbmc/qemu/include/hw/misc/auxbus.h (revision 8fa3b702)
1 /*
2  * auxbus.h
3  *
4  *  Copyright (C)2014 : GreenSocs Ltd
5  *      http://www.greensocs.com/ , email: info@greensocs.com
6  *
7  *  Developed by :
8  *  Frederic Konrad   <fred.konrad@greensocs.com>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 2 of the License, or
13  * (at your option)any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License along
21  * with this program; if not, see <http://www.gnu.org/licenses/>.
22  *
23  */
24 
25 #ifndef HW_MISC_AUXBUS_H
26 #define HW_MISC_AUXBUS_H
27 
28 #include "exec/memory.h"
29 #include "hw/qdev-core.h"
30 #include "qom/object.h"
31 
32 typedef struct AUXBus AUXBus;
33 typedef struct AUXSlave AUXSlave;
34 typedef enum AUXCommand AUXCommand;
35 typedef enum AUXReply AUXReply;
36 
37 #define TYPE_AUXTOI2C "aux-to-i2c-bridge"
38 typedef struct AUXTOI2CState AUXTOI2CState;
39 DECLARE_INSTANCE_CHECKER(AUXTOI2CState, AUXTOI2C,
40                          TYPE_AUXTOI2C)
41 
42 enum AUXCommand {
43     WRITE_I2C = 0,
44     READ_I2C = 1,
45     WRITE_I2C_STATUS = 2,
46     WRITE_I2C_MOT = 4,
47     READ_I2C_MOT = 5,
48     WRITE_AUX = 8,
49     READ_AUX = 9
50 };
51 
52 enum AUXReply {
53     AUX_I2C_ACK = 0,
54     AUX_NACK = 1,
55     AUX_DEFER = 2,
56     AUX_I2C_NACK = 4,
57     AUX_I2C_DEFER = 8
58 };
59 
60 #define TYPE_AUX_BUS "aux-bus"
61 DECLARE_INSTANCE_CHECKER(AUXBus, AUX_BUS,
62                          TYPE_AUX_BUS)
63 
64 struct AUXBus {
65     /* < private > */
66     BusState qbus;
67 
68     /* < public > */
69     AUXSlave *current_dev;
70     AUXSlave *dev;
71     uint32_t last_i2c_address;
72     AUXCommand last_transaction;
73 
74     AUXTOI2CState *bridge;
75 
76     MemoryRegion *aux_io;
77     AddressSpace aux_addr_space;
78 };
79 
80 #define TYPE_AUX_SLAVE "aux-slave"
81 DECLARE_INSTANCE_CHECKER(AUXSlave, AUX_SLAVE,
82                          TYPE_AUX_SLAVE)
83 
84 struct AUXSlave {
85     /* < private > */
86     DeviceState parent_obj;
87 
88     /* < public > */
89     MemoryRegion *mmio;
90 };
91 
92 /**
93  * aux_bus_init: Initialize an AUX bus.
94  *
95  * Returns the new AUX bus created.
96  *
97  * @parent The device where this bus is located.
98  * @name The name of the bus.
99  */
100 AUXBus *aux_bus_init(DeviceState *parent, const char *name);
101 
102 /**
103  * aux_bus_realize: Realize an AUX bus.
104  *
105  * @bus: The AUX bus.
106  */
107 void aux_bus_realize(AUXBus *bus);
108 
109 /*
110  * aux_request: Make a request on the bus.
111  *
112  * Returns the reply of the request.
113  *
114  * @bus Ths bus where the request happen.
115  * @cmd The command requested.
116  * @address The 20bits address of the slave.
117  * @len The length of the read or write.
118  * @data The data array which will be filled or read during transfer.
119  */
120 AUXReply aux_request(AUXBus *bus, AUXCommand cmd, uint32_t address,
121                               uint8_t len, uint8_t *data);
122 
123 /*
124  * aux_get_i2c_bus: Get the i2c bus for I2C over AUX command.
125  *
126  * Returns the i2c bus associated to this AUX bus.
127  *
128  * @bus The AUX bus.
129  */
130 I2CBus *aux_get_i2c_bus(AUXBus *bus);
131 
132 /*
133  * aux_init_mmio: Init an mmio for an AUX slave.
134  *
135  * @aux_slave The AUX slave.
136  * @mmio The mmio to be registered.
137  */
138 void aux_init_mmio(AUXSlave *aux_slave, MemoryRegion *mmio);
139 
140 /* aux_map_slave: Map the mmio for an AUX slave on the bus.
141  *
142  * @dev The AUX slave.
143  * @addr The address for the slave's mmio.
144  */
145 void aux_map_slave(AUXSlave *dev, hwaddr addr);
146 
147 #endif /* HW_MISC_AUXBUS_H */
148