xref: /qemu/include/hw/misc/auxbus.h (revision db1015e92e04835c9eb50c29625fe566d1202dbd)
16fc7f77fSKONRAD Frederic /*
2e0dadc1eSPeter Maydell  * auxbus.h
36fc7f77fSKONRAD Frederic  *
46fc7f77fSKONRAD Frederic  *  Copyright (C)2014 : GreenSocs Ltd
56fc7f77fSKONRAD Frederic  *      http://www.greensocs.com/ , email: info@greensocs.com
66fc7f77fSKONRAD Frederic  *
76fc7f77fSKONRAD Frederic  *  Developed by :
86fc7f77fSKONRAD Frederic  *  Frederic Konrad   <fred.konrad@greensocs.com>
96fc7f77fSKONRAD Frederic  *
106fc7f77fSKONRAD Frederic  * This program is free software; you can redistribute it and/or modify
116fc7f77fSKONRAD Frederic  * it under the terms of the GNU General Public License as published by
126fc7f77fSKONRAD Frederic  * the Free Software Foundation, either version 2 of the License, or
136fc7f77fSKONRAD Frederic  * (at your option)any later version.
146fc7f77fSKONRAD Frederic  *
156fc7f77fSKONRAD Frederic  * This program is distributed in the hope that it will be useful,
166fc7f77fSKONRAD Frederic  * but WITHOUT ANY WARRANTY; without even the implied warranty of
176fc7f77fSKONRAD Frederic  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
186fc7f77fSKONRAD Frederic  * GNU General Public License for more details.
196fc7f77fSKONRAD Frederic  *
206fc7f77fSKONRAD Frederic  * You should have received a copy of the GNU General Public License along
216fc7f77fSKONRAD Frederic  * with this program; if not, see <http://www.gnu.org/licenses/>.
226fc7f77fSKONRAD Frederic  *
236fc7f77fSKONRAD Frederic  */
246fc7f77fSKONRAD Frederic 
25121d0712SMarkus Armbruster #ifndef HW_MISC_AUXBUS_H
26121d0712SMarkus Armbruster #define HW_MISC_AUXBUS_H
276fc7f77fSKONRAD Frederic 
28d4842052SMarkus Armbruster #include "exec/memory.h"
29a27bd6c7SMarkus Armbruster #include "hw/qdev-core.h"
30*db1015e9SEduardo Habkost #include "qom/object.h"
316fc7f77fSKONRAD Frederic 
326fc7f77fSKONRAD Frederic typedef struct AUXBus AUXBus;
336fc7f77fSKONRAD Frederic typedef struct AUXSlave AUXSlave;
346fc7f77fSKONRAD Frederic typedef enum AUXCommand AUXCommand;
356fc7f77fSKONRAD Frederic typedef enum AUXReply AUXReply;
36cb8cf86bSEduardo Habkost 
37cb8cf86bSEduardo Habkost #define TYPE_AUXTOI2C "aux-to-i2c-bridge"
386fc7f77fSKONRAD Frederic typedef struct AUXTOI2CState AUXTOI2CState;
39cb8cf86bSEduardo Habkost #define AUXTOI2C(obj) OBJECT_CHECK(AUXTOI2CState, (obj), TYPE_AUXTOI2C)
406fc7f77fSKONRAD Frederic 
416fc7f77fSKONRAD Frederic enum AUXCommand {
426fc7f77fSKONRAD Frederic     WRITE_I2C = 0,
436fc7f77fSKONRAD Frederic     READ_I2C = 1,
446fc7f77fSKONRAD Frederic     WRITE_I2C_STATUS = 2,
456fc7f77fSKONRAD Frederic     WRITE_I2C_MOT = 4,
466fc7f77fSKONRAD Frederic     READ_I2C_MOT = 5,
476fc7f77fSKONRAD Frederic     WRITE_AUX = 8,
486fc7f77fSKONRAD Frederic     READ_AUX = 9
496fc7f77fSKONRAD Frederic };
506fc7f77fSKONRAD Frederic 
516fc7f77fSKONRAD Frederic enum AUXReply {
526fc7f77fSKONRAD Frederic     AUX_I2C_ACK = 0,
536fc7f77fSKONRAD Frederic     AUX_NACK = 1,
546fc7f77fSKONRAD Frederic     AUX_DEFER = 2,
556fc7f77fSKONRAD Frederic     AUX_I2C_NACK = 4,
566fc7f77fSKONRAD Frederic     AUX_I2C_DEFER = 8
576fc7f77fSKONRAD Frederic };
586fc7f77fSKONRAD Frederic 
596fc7f77fSKONRAD Frederic #define TYPE_AUX_BUS "aux-bus"
606fc7f77fSKONRAD Frederic #define AUX_BUS(obj) OBJECT_CHECK(AUXBus, (obj), TYPE_AUX_BUS)
616fc7f77fSKONRAD Frederic 
626fc7f77fSKONRAD Frederic struct AUXBus {
636fc7f77fSKONRAD Frederic     /* < private > */
646fc7f77fSKONRAD Frederic     BusState qbus;
656fc7f77fSKONRAD Frederic 
666fc7f77fSKONRAD Frederic     /* < public > */
676fc7f77fSKONRAD Frederic     AUXSlave *current_dev;
686fc7f77fSKONRAD Frederic     AUXSlave *dev;
696fc7f77fSKONRAD Frederic     uint32_t last_i2c_address;
706fc7f77fSKONRAD Frederic     AUXCommand last_transaction;
716fc7f77fSKONRAD Frederic 
726fc7f77fSKONRAD Frederic     AUXTOI2CState *bridge;
736fc7f77fSKONRAD Frederic 
746fc7f77fSKONRAD Frederic     MemoryRegion *aux_io;
756fc7f77fSKONRAD Frederic     AddressSpace aux_addr_space;
766fc7f77fSKONRAD Frederic };
776fc7f77fSKONRAD Frederic 
786fc7f77fSKONRAD Frederic #define TYPE_AUX_SLAVE "aux-slave"
796fc7f77fSKONRAD Frederic #define AUX_SLAVE(obj) \
806fc7f77fSKONRAD Frederic      OBJECT_CHECK(AUXSlave, (obj), TYPE_AUX_SLAVE)
816fc7f77fSKONRAD Frederic 
826fc7f77fSKONRAD Frederic struct AUXSlave {
836fc7f77fSKONRAD Frederic     /* < private > */
846fc7f77fSKONRAD Frederic     DeviceState parent_obj;
856fc7f77fSKONRAD Frederic 
866fc7f77fSKONRAD Frederic     /* < public > */
876fc7f77fSKONRAD Frederic     MemoryRegion *mmio;
886fc7f77fSKONRAD Frederic };
896fc7f77fSKONRAD Frederic 
906fc7f77fSKONRAD Frederic /**
91dbe4070eSMarkus Armbruster  * aux_bus_init: Initialize an AUX bus.
926fc7f77fSKONRAD Frederic  *
936fc7f77fSKONRAD Frederic  * Returns the new AUX bus created.
946fc7f77fSKONRAD Frederic  *
956fc7f77fSKONRAD Frederic  * @parent The device where this bus is located.
966fc7f77fSKONRAD Frederic  * @name The name of the bus.
976fc7f77fSKONRAD Frederic  */
98dbe4070eSMarkus Armbruster AUXBus *aux_bus_init(DeviceState *parent, const char *name);
996fc7f77fSKONRAD Frederic 
100b7a1b548SMarkus Armbruster /**
101b7a1b548SMarkus Armbruster  * aux_bus_realize: Realize an AUX bus.
102b7a1b548SMarkus Armbruster  *
103b7a1b548SMarkus Armbruster  * @bus: The AUX bus.
104b7a1b548SMarkus Armbruster  */
105b7a1b548SMarkus Armbruster void aux_bus_realize(AUXBus *bus);
106b7a1b548SMarkus Armbruster 
1076fc7f77fSKONRAD Frederic /*
1086fc7f77fSKONRAD Frederic  * aux_request: Make a request on the bus.
1096fc7f77fSKONRAD Frederic  *
1106fc7f77fSKONRAD Frederic  * Returns the reply of the request.
1116fc7f77fSKONRAD Frederic  *
1126fc7f77fSKONRAD Frederic  * @bus Ths bus where the request happen.
1136fc7f77fSKONRAD Frederic  * @cmd The command requested.
1146fc7f77fSKONRAD Frederic  * @address The 20bits address of the slave.
1156fc7f77fSKONRAD Frederic  * @len The length of the read or write.
1166fc7f77fSKONRAD Frederic  * @data The data array which will be filled or read during transfer.
1176fc7f77fSKONRAD Frederic  */
1186fc7f77fSKONRAD Frederic AUXReply aux_request(AUXBus *bus, AUXCommand cmd, uint32_t address,
1196fc7f77fSKONRAD Frederic                               uint8_t len, uint8_t *data);
1206fc7f77fSKONRAD Frederic 
1216fc7f77fSKONRAD Frederic /*
1226fc7f77fSKONRAD Frederic  * aux_get_i2c_bus: Get the i2c bus for I2C over AUX command.
1236fc7f77fSKONRAD Frederic  *
1246fc7f77fSKONRAD Frederic  * Returns the i2c bus associated to this AUX bus.
1256fc7f77fSKONRAD Frederic  *
1266fc7f77fSKONRAD Frederic  * @bus The AUX bus.
1276fc7f77fSKONRAD Frederic  */
1286fc7f77fSKONRAD Frederic I2CBus *aux_get_i2c_bus(AUXBus *bus);
1296fc7f77fSKONRAD Frederic 
1306fc7f77fSKONRAD Frederic /*
1316fc7f77fSKONRAD Frederic  * aux_init_mmio: Init an mmio for an AUX slave.
1326fc7f77fSKONRAD Frederic  *
1336fc7f77fSKONRAD Frederic  * @aux_slave The AUX slave.
1346fc7f77fSKONRAD Frederic  * @mmio The mmio to be registered.
1356fc7f77fSKONRAD Frederic  */
1366fc7f77fSKONRAD Frederic void aux_init_mmio(AUXSlave *aux_slave, MemoryRegion *mmio);
1376fc7f77fSKONRAD Frederic 
138fe04f0b4SPaolo Bonzini /* aux_map_slave: Map the mmio for an AUX slave on the bus.
139fe04f0b4SPaolo Bonzini  *
140fe04f0b4SPaolo Bonzini  * @dev The AUX slave.
141fe04f0b4SPaolo Bonzini  * @addr The address for the slave's mmio.
142fe04f0b4SPaolo Bonzini  */
143fe04f0b4SPaolo Bonzini void aux_map_slave(AUXSlave *dev, hwaddr addr);
1446fc7f77fSKONRAD Frederic 
145121d0712SMarkus Armbruster #endif /* HW_MISC_AUXBUS_H */
146