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