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