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" 306fc7f77fSKONRAD Frederic 316fc7f77fSKONRAD Frederic typedef struct AUXBus AUXBus; 326fc7f77fSKONRAD Frederic typedef struct AUXSlave AUXSlave; 336fc7f77fSKONRAD Frederic typedef enum AUXCommand AUXCommand; 346fc7f77fSKONRAD Frederic typedef enum AUXReply AUXReply; 356fc7f77fSKONRAD Frederic typedef struct AUXTOI2CState AUXTOI2CState; 366fc7f77fSKONRAD Frederic 376fc7f77fSKONRAD Frederic enum AUXCommand { 386fc7f77fSKONRAD Frederic WRITE_I2C = 0, 396fc7f77fSKONRAD Frederic READ_I2C = 1, 406fc7f77fSKONRAD Frederic WRITE_I2C_STATUS = 2, 416fc7f77fSKONRAD Frederic WRITE_I2C_MOT = 4, 426fc7f77fSKONRAD Frederic READ_I2C_MOT = 5, 436fc7f77fSKONRAD Frederic WRITE_AUX = 8, 446fc7f77fSKONRAD Frederic READ_AUX = 9 456fc7f77fSKONRAD Frederic }; 466fc7f77fSKONRAD Frederic 476fc7f77fSKONRAD Frederic enum AUXReply { 486fc7f77fSKONRAD Frederic AUX_I2C_ACK = 0, 496fc7f77fSKONRAD Frederic AUX_NACK = 1, 506fc7f77fSKONRAD Frederic AUX_DEFER = 2, 516fc7f77fSKONRAD Frederic AUX_I2C_NACK = 4, 526fc7f77fSKONRAD Frederic AUX_I2C_DEFER = 8 536fc7f77fSKONRAD Frederic }; 546fc7f77fSKONRAD Frederic 556fc7f77fSKONRAD Frederic #define TYPE_AUX_BUS "aux-bus" 566fc7f77fSKONRAD Frederic #define AUX_BUS(obj) OBJECT_CHECK(AUXBus, (obj), TYPE_AUX_BUS) 576fc7f77fSKONRAD Frederic 586fc7f77fSKONRAD Frederic struct AUXBus { 596fc7f77fSKONRAD Frederic /* < private > */ 606fc7f77fSKONRAD Frederic BusState qbus; 616fc7f77fSKONRAD Frederic 626fc7f77fSKONRAD Frederic /* < public > */ 636fc7f77fSKONRAD Frederic AUXSlave *current_dev; 646fc7f77fSKONRAD Frederic AUXSlave *dev; 656fc7f77fSKONRAD Frederic uint32_t last_i2c_address; 666fc7f77fSKONRAD Frederic AUXCommand last_transaction; 676fc7f77fSKONRAD Frederic 686fc7f77fSKONRAD Frederic AUXTOI2CState *bridge; 696fc7f77fSKONRAD Frederic 706fc7f77fSKONRAD Frederic MemoryRegion *aux_io; 716fc7f77fSKONRAD Frederic AddressSpace aux_addr_space; 726fc7f77fSKONRAD Frederic }; 736fc7f77fSKONRAD Frederic 746fc7f77fSKONRAD Frederic #define TYPE_AUX_SLAVE "aux-slave" 756fc7f77fSKONRAD Frederic #define AUX_SLAVE(obj) \ 766fc7f77fSKONRAD Frederic OBJECT_CHECK(AUXSlave, (obj), TYPE_AUX_SLAVE) 776fc7f77fSKONRAD Frederic 786fc7f77fSKONRAD Frederic struct AUXSlave { 796fc7f77fSKONRAD Frederic /* < private > */ 806fc7f77fSKONRAD Frederic DeviceState parent_obj; 816fc7f77fSKONRAD Frederic 826fc7f77fSKONRAD Frederic /* < public > */ 836fc7f77fSKONRAD Frederic MemoryRegion *mmio; 846fc7f77fSKONRAD Frederic }; 856fc7f77fSKONRAD Frederic 866fc7f77fSKONRAD Frederic /** 87*dbe4070eSMarkus Armbruster * aux_bus_init: Initialize an AUX bus. 886fc7f77fSKONRAD Frederic * 896fc7f77fSKONRAD Frederic * Returns the new AUX bus created. 906fc7f77fSKONRAD Frederic * 916fc7f77fSKONRAD Frederic * @parent The device where this bus is located. 926fc7f77fSKONRAD Frederic * @name The name of the bus. 936fc7f77fSKONRAD Frederic */ 94*dbe4070eSMarkus Armbruster AUXBus *aux_bus_init(DeviceState *parent, const char *name); 956fc7f77fSKONRAD Frederic 966fc7f77fSKONRAD Frederic /* 976fc7f77fSKONRAD Frederic * aux_request: Make a request on the bus. 986fc7f77fSKONRAD Frederic * 996fc7f77fSKONRAD Frederic * Returns the reply of the request. 1006fc7f77fSKONRAD Frederic * 1016fc7f77fSKONRAD Frederic * @bus Ths bus where the request happen. 1026fc7f77fSKONRAD Frederic * @cmd The command requested. 1036fc7f77fSKONRAD Frederic * @address The 20bits address of the slave. 1046fc7f77fSKONRAD Frederic * @len The length of the read or write. 1056fc7f77fSKONRAD Frederic * @data The data array which will be filled or read during transfer. 1066fc7f77fSKONRAD Frederic */ 1076fc7f77fSKONRAD Frederic AUXReply aux_request(AUXBus *bus, AUXCommand cmd, uint32_t address, 1086fc7f77fSKONRAD Frederic uint8_t len, uint8_t *data); 1096fc7f77fSKONRAD Frederic 1106fc7f77fSKONRAD Frederic /* 1116fc7f77fSKONRAD Frederic * aux_get_i2c_bus: Get the i2c bus for I2C over AUX command. 1126fc7f77fSKONRAD Frederic * 1136fc7f77fSKONRAD Frederic * Returns the i2c bus associated to this AUX bus. 1146fc7f77fSKONRAD Frederic * 1156fc7f77fSKONRAD Frederic * @bus The AUX bus. 1166fc7f77fSKONRAD Frederic */ 1176fc7f77fSKONRAD Frederic I2CBus *aux_get_i2c_bus(AUXBus *bus); 1186fc7f77fSKONRAD Frederic 1196fc7f77fSKONRAD Frederic /* 1206fc7f77fSKONRAD Frederic * aux_init_mmio: Init an mmio for an AUX slave. 1216fc7f77fSKONRAD Frederic * 1226fc7f77fSKONRAD Frederic * @aux_slave The AUX slave. 1236fc7f77fSKONRAD Frederic * @mmio The mmio to be registered. 1246fc7f77fSKONRAD Frederic */ 1256fc7f77fSKONRAD Frederic void aux_init_mmio(AUXSlave *aux_slave, MemoryRegion *mmio); 1266fc7f77fSKONRAD Frederic 127fe04f0b4SPaolo Bonzini /* aux_create_slave: Create a new device on an AUX bus 128fe04f0b4SPaolo Bonzini * 129fe04f0b4SPaolo Bonzini * @bus The AUX bus for the new device. 130fe04f0b4SPaolo Bonzini * @name The type of the device to be created. 131fe04f0b4SPaolo Bonzini */ 132fe04f0b4SPaolo Bonzini DeviceState *aux_create_slave(AUXBus *bus, const char *name); 133fe04f0b4SPaolo Bonzini 134fe04f0b4SPaolo Bonzini /* aux_map_slave: Map the mmio for an AUX slave on the bus. 135fe04f0b4SPaolo Bonzini * 136fe04f0b4SPaolo Bonzini * @dev The AUX slave. 137fe04f0b4SPaolo Bonzini * @addr The address for the slave's mmio. 138fe04f0b4SPaolo Bonzini */ 139fe04f0b4SPaolo Bonzini void aux_map_slave(AUXSlave *dev, hwaddr addr); 1406fc7f77fSKONRAD Frederic 141121d0712SMarkus Armbruster #endif /* HW_MISC_AUXBUS_H */ 142