1/* 2 * aux.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 QEMU_AUX_H 26#define QEMU_AUX_H 27 28#include "hw/qdev.h" 29 30enum aux_command { 31 WRITE_I2C = 0, 32 READ_I2C = 1, 33 WRITE_I2C_STATUS = 2, 34 WRITE_I2C_MOT = 4, 35 READ_I2C_MOT = 5, 36 WRITE_AUX = 8, 37 READ_AUX = 9 38}; 39 40enum aux_reply { 41 AUX_I2C_ACK = 0, 42 AUX_NACK = 1, 43 AUX_DEFER = 2, 44 AUX_I2C_NACK = 4, 45 AUX_I2C_DEFER = 8 46}; 47 48typedef struct AUXBus AUXBus; 49typedef struct AUXSlave AUXSlave; 50typedef enum aux_command aux_command; 51typedef enum aux_reply aux_reply; 52 53#define TYPE_AUX_SLAVE "aux-slave" 54#define AUX_SLAVE(obj) \ 55 OBJECT_CHECK(AUXSlave, (obj), TYPE_AUX_SLAVE) 56#define AUX_SLAVE_CLASS(klass) \ 57 OBJECT_CLASS_CHECK(AUXSlaveClass, (klass), TYPE_AUX_SLAVE) 58#define AUX_SLAVE_GET_CLASS(obj) \ 59 OBJECT_GET_CLASS(AUXSlaveClass, (obj), TYPE_AUX_SLAVE) 60 61struct AUXSlave { 62 /* < private > */ 63 DeviceState parent_obj; 64 65 /* address of the device on the aux bus. */ 66 hwaddr address; 67 /* memory region associated. */ 68 MemoryRegion *mmio; 69}; 70 71typedef struct AUXSlaveClass { 72 DeviceClass parent_class; 73 74 /* Callbacks provided by the device. */ 75 int (*init)(AUXSlave *dev); 76} AUXSlaveClass; 77 78/* 79 * \func aux_init_bus 80 * \brief Init an aux bus. 81 * \param parent The device where this bus is located. 82 * \param name The name of the bus. 83 * \return The new aux bus. 84 */ 85AUXBus *aux_init_bus(DeviceState *parent, const char *name); 86 87/* 88 * \func aux_slave_set_address 89 * \brief Set the address of the slave on the aux bus. 90 * \param dev The aux slave device. 91 * \param address The address to give to the slave. 92 */ 93void aux_set_slave_address(AUXSlave *dev, uint32_t address); 94 95/* 96 * \func aux_request 97 * \brief Make a request on the bus. 98 * \param bus Ths bus where the request happen. 99 * \param cmd The command requested. 100 * \param address The 20bits address of the slave. 101 * \param len The length of the read or write. 102 * \param data The data array which will be filled or read during transfer. 103 * \return Return the reply of the request. 104 */ 105aux_reply aux_request(AUXBus *bus, aux_command cmd, uint32_t address, 106 uint8_t len, uint8_t *data); 107 108/* 109 * \func aux_get_i2c_bus 110 * \brief Get the i2c bus for I2C over AUX command. 111 * \param bus The aux bus. 112 * \return Return the i2c bus associated. 113 */ 114I2CBus *aux_get_i2c_bus(AUXBus *bus); 115 116/* 117 * \func aux_init_mmio 118 * \brief Init an mmio for an aux slave, must be called after 119 * memory_region_init_io. 120 * \param aux_slave The aux slave. 121 * \param mmio The mmio to be registered. 122 */ 123void aux_init_mmio(AUXSlave *aux_slave, MemoryRegion *mmio); 124 125DeviceState *aux_create_slave(AUXBus *bus, const char *name, uint32_t addr); 126 127#endif /* !QEMU_AUX_H */ 128