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 28*8be545baSRichard Henderson #include "system/memory.h" 29a27bd6c7SMarkus Armbruster #include "hw/qdev-core.h" 30db1015e9SEduardo Habkost #include "qom/object.h" 316fc7f77fSKONRAD Frederic 326fc7f77fSKONRAD Frederic typedef struct AUXSlave AUXSlave; 336fc7f77fSKONRAD Frederic typedef enum AUXCommand AUXCommand; 346fc7f77fSKONRAD Frederic typedef enum AUXReply AUXReply; 35cb8cf86bSEduardo Habkost 36cb8cf86bSEduardo Habkost #define TYPE_AUXTOI2C "aux-to-i2c-bridge" 378063396bSEduardo Habkost OBJECT_DECLARE_SIMPLE_TYPE(AUXTOI2CState, AUXTOI2C) 386fc7f77fSKONRAD Frederic 396fc7f77fSKONRAD Frederic enum AUXCommand { 406fc7f77fSKONRAD Frederic WRITE_I2C = 0, 416fc7f77fSKONRAD Frederic READ_I2C = 1, 426fc7f77fSKONRAD Frederic WRITE_I2C_STATUS = 2, 436fc7f77fSKONRAD Frederic WRITE_I2C_MOT = 4, 446fc7f77fSKONRAD Frederic READ_I2C_MOT = 5, 456fc7f77fSKONRAD Frederic WRITE_AUX = 8, 466fc7f77fSKONRAD Frederic READ_AUX = 9 476fc7f77fSKONRAD Frederic }; 486fc7f77fSKONRAD Frederic 496fc7f77fSKONRAD Frederic enum AUXReply { 506fc7f77fSKONRAD Frederic AUX_I2C_ACK = 0, 516fc7f77fSKONRAD Frederic AUX_NACK = 1, 526fc7f77fSKONRAD Frederic AUX_DEFER = 2, 536fc7f77fSKONRAD Frederic AUX_I2C_NACK = 4, 546fc7f77fSKONRAD Frederic AUX_I2C_DEFER = 8 556fc7f77fSKONRAD Frederic }; 566fc7f77fSKONRAD Frederic 576fc7f77fSKONRAD Frederic #define TYPE_AUX_BUS "aux-bus" 588063396bSEduardo Habkost OBJECT_DECLARE_SIMPLE_TYPE(AUXBus, AUX_BUS) 596fc7f77fSKONRAD Frederic 606fc7f77fSKONRAD Frederic struct AUXBus { 616fc7f77fSKONRAD Frederic /* < private > */ 626fc7f77fSKONRAD Frederic BusState qbus; 636fc7f77fSKONRAD Frederic 646fc7f77fSKONRAD Frederic /* < public > */ 656fc7f77fSKONRAD Frederic AUXSlave *current_dev; 666fc7f77fSKONRAD Frederic AUXSlave *dev; 676fc7f77fSKONRAD Frederic uint32_t last_i2c_address; 686fc7f77fSKONRAD Frederic AUXCommand last_transaction; 696fc7f77fSKONRAD Frederic 706fc7f77fSKONRAD Frederic AUXTOI2CState *bridge; 716fc7f77fSKONRAD Frederic 726fc7f77fSKONRAD Frederic MemoryRegion *aux_io; 736fc7f77fSKONRAD Frederic AddressSpace aux_addr_space; 746fc7f77fSKONRAD Frederic }; 756fc7f77fSKONRAD Frederic 766fc7f77fSKONRAD Frederic #define TYPE_AUX_SLAVE "aux-slave" 778063396bSEduardo Habkost OBJECT_DECLARE_SIMPLE_TYPE(AUXSlave, AUX_SLAVE) 786fc7f77fSKONRAD Frederic 796fc7f77fSKONRAD Frederic struct AUXSlave { 806fc7f77fSKONRAD Frederic /* < private > */ 816fc7f77fSKONRAD Frederic DeviceState parent_obj; 826fc7f77fSKONRAD Frederic 836fc7f77fSKONRAD Frederic /* < public > */ 846fc7f77fSKONRAD Frederic MemoryRegion *mmio; 856fc7f77fSKONRAD Frederic }; 866fc7f77fSKONRAD Frederic 876fc7f77fSKONRAD Frederic /** 88dbe4070eSMarkus Armbruster * aux_bus_init: Initialize an AUX bus. 896fc7f77fSKONRAD Frederic * 906fc7f77fSKONRAD Frederic * Returns the new AUX bus created. 916fc7f77fSKONRAD Frederic * 926fc7f77fSKONRAD Frederic * @parent The device where this bus is located. 936fc7f77fSKONRAD Frederic * @name The name of the bus. 946fc7f77fSKONRAD Frederic */ 95dbe4070eSMarkus Armbruster AUXBus *aux_bus_init(DeviceState *parent, const char *name); 966fc7f77fSKONRAD Frederic 97b7a1b548SMarkus Armbruster /** 98b7a1b548SMarkus Armbruster * aux_bus_realize: Realize an AUX bus. 99b7a1b548SMarkus Armbruster * 100b7a1b548SMarkus Armbruster * @bus: The AUX bus. 101b7a1b548SMarkus Armbruster */ 102b7a1b548SMarkus Armbruster void aux_bus_realize(AUXBus *bus); 103b7a1b548SMarkus Armbruster 1046fc7f77fSKONRAD Frederic /* 1056fc7f77fSKONRAD Frederic * aux_request: Make a request on the bus. 1066fc7f77fSKONRAD Frederic * 1076fc7f77fSKONRAD Frederic * Returns the reply of the request. 1086fc7f77fSKONRAD Frederic * 1098fa21b80SMichael Tokarev * @bus The bus where the request happen. 1106fc7f77fSKONRAD Frederic * @cmd The command requested. 1116fc7f77fSKONRAD Frederic * @address The 20bits address of the slave. 1126fc7f77fSKONRAD Frederic * @len The length of the read or write. 1136fc7f77fSKONRAD Frederic * @data The data array which will be filled or read during transfer. 1146fc7f77fSKONRAD Frederic */ 1156fc7f77fSKONRAD Frederic AUXReply aux_request(AUXBus *bus, AUXCommand cmd, uint32_t address, 1166fc7f77fSKONRAD Frederic uint8_t len, uint8_t *data); 1176fc7f77fSKONRAD Frederic 1186fc7f77fSKONRAD Frederic /* 1196fc7f77fSKONRAD Frederic * aux_get_i2c_bus: Get the i2c bus for I2C over AUX command. 1206fc7f77fSKONRAD Frederic * 1216fc7f77fSKONRAD Frederic * Returns the i2c bus associated to this AUX bus. 1226fc7f77fSKONRAD Frederic * 1236fc7f77fSKONRAD Frederic * @bus The AUX bus. 1246fc7f77fSKONRAD Frederic */ 1256fc7f77fSKONRAD Frederic I2CBus *aux_get_i2c_bus(AUXBus *bus); 1266fc7f77fSKONRAD Frederic 1276fc7f77fSKONRAD Frederic /* 1286fc7f77fSKONRAD Frederic * aux_init_mmio: Init an mmio for an AUX slave. 1296fc7f77fSKONRAD Frederic * 1306fc7f77fSKONRAD Frederic * @aux_slave The AUX slave. 1316fc7f77fSKONRAD Frederic * @mmio The mmio to be registered. 1326fc7f77fSKONRAD Frederic */ 1336fc7f77fSKONRAD Frederic void aux_init_mmio(AUXSlave *aux_slave, MemoryRegion *mmio); 1346fc7f77fSKONRAD Frederic 135fe04f0b4SPaolo Bonzini /* aux_map_slave: Map the mmio for an AUX slave on the bus. 136fe04f0b4SPaolo Bonzini * 137fe04f0b4SPaolo Bonzini * @dev The AUX slave. 138fe04f0b4SPaolo Bonzini * @addr The address for the slave's mmio. 139fe04f0b4SPaolo Bonzini */ 140fe04f0b4SPaolo Bonzini void aux_map_slave(AUXSlave *dev, hwaddr addr); 1416fc7f77fSKONRAD Frederic 142121d0712SMarkus Armbruster #endif /* HW_MISC_AUXBUS_H */ 143