| 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 "system/memory.h" |
| 29 | #include "hw/core/qdev.h" |
| 30 | #include "qom/object.h" |
| 31 | |
| 32 | typedef enum AUXCommand AUXCommand; |
| 33 | typedef enum AUXReply AUXReply; |
| 34 | |
| 35 | #define TYPE_AUXTOI2C "aux-to-i2c-bridge" |
| 36 | OBJECT_DECLARE_SIMPLE_TYPE(AUXTOI2CState, AUXTOI2C) |
| 37 | |
| 38 | #define TYPE_AUX_SLAVE "aux-slave" |
| 39 | OBJECT_DECLARE_SIMPLE_TYPE(AUXSlave, AUX_SLAVE) |
| 40 | |
| 41 | enum AUXCommand { |
| 42 | WRITE_I2C = 0, |
| 43 | READ_I2C = 1, |
| 44 | WRITE_I2C_STATUS = 2, |
| 45 | WRITE_I2C_MOT = 4, |
| 46 | READ_I2C_MOT = 5, |
| 47 | WRITE_AUX = 8, |
| 48 | READ_AUX = 9 |
| 49 | }; |
| 50 | |
| 51 | enum AUXReply { |
| 52 | AUX_I2C_ACK = 0, |
| 53 | AUX_NACK = 1, |
| 54 | AUX_DEFER = 2, |
| 55 | AUX_I2C_NACK = 4, |
| 56 | AUX_I2C_DEFER = 8 |
| 57 | }; |
| 58 | |
| 59 | #define TYPE_AUX_BUS "aux-bus" |
| 60 | OBJECT_DECLARE_SIMPLE_TYPE(AUXBus, AUX_BUS) |
| 61 | |
| 62 | struct AUXBus { |
| 63 | /* < private > */ |
| 64 | BusState qbus; |
| 65 | |
| 66 | /* < public > */ |
| 67 | AUXSlave *current_dev; |
| 68 | AUXSlave *dev; |
| 69 | uint32_t last_i2c_address; |
| 70 | AUXCommand last_transaction; |
| 71 | |
| 72 | AUXTOI2CState *bridge; |
| 73 | |
| 74 | MemoryRegion *aux_io; |
| 75 | AddressSpace aux_addr_space; |
| 76 | }; |
| 77 | |
| 78 | struct AUXSlave { |
| 79 | /* < private > */ |
| 80 | DeviceState parent_obj; |
| 81 | |
| 82 | /* < public > */ |
| 83 | MemoryRegion *mmio; |
| 84 | }; |
| 85 | |
| 86 | /** |
| 87 | * aux_bus_init: Initialize an AUX bus. |
| 88 | * |
| 89 | * Returns the new AUX bus created. |
| 90 | * |
| 91 | * @parent The device where this bus is located. |
| 92 | * @name The name of the bus. |
| 93 | */ |
| 94 | AUXBus *aux_bus_init(DeviceState *parent, const char *name); |
| 95 | |
| 96 | /** |
| 97 | * aux_bus_realize: Realize an AUX bus. |
| 98 | * |
| 99 | * @bus: The AUX bus. |
| 100 | */ |
| 101 | void aux_bus_realize(AUXBus *bus); |
| 102 | |
| 103 | /* |
| 104 | * aux_request: Make a request on the bus. |
| 105 | * |
| 106 | * Returns the reply of the request. |
| 107 | * |
| 108 | * @bus The bus where the request happen. |
| 109 | * @cmd The command requested. |
| 110 | * @address The 20bits address of the slave. |
| 111 | * @len The length of the read or write. |
| 112 | * @data The data array which will be filled or read during transfer. |
| 113 | */ |
| 114 | AUXReply aux_request(AUXBus *bus, AUXCommand cmd, uint32_t address, |
| 115 | uint8_t len, uint8_t *data); |
| 116 | |
| 117 | /* |
| 118 | * aux_get_i2c_bus: Get the i2c bus for I2C over AUX command. |
| 119 | * |
| 120 | * Returns the i2c bus associated to this AUX bus. |
| 121 | * |
| 122 | * @bus The AUX bus. |
| 123 | */ |
| 124 | I2CBus *aux_get_i2c_bus(AUXBus *bus); |
| 125 | |
| 126 | /* |
| 127 | * aux_init_mmio: Init an mmio for an AUX slave. |
| 128 | * |
| 129 | * @aux_slave The AUX slave. |
| 130 | * @mmio The mmio to be registered. |
| 131 | */ |
| 132 | void aux_init_mmio(AUXSlave *aux_slave, MemoryRegion *mmio); |
| 133 | |
| 134 | /* aux_map_slave: Map the mmio for an AUX slave on the bus. |
| 135 | * |
| 136 | * @dev The AUX slave. |
| 137 | * @addr The address for the slave's mmio. |
| 138 | */ |
| 139 | void aux_map_slave(AUXSlave *dev, hwaddr addr); |
| 140 | |
| 141 | #endif /* HW_MISC_AUXBUS_H */ |