qemu/include/hw/ssi/ssi.h
<<
>>
Prefs
   1/* QEMU Synchronous Serial Interface support.  */
   2
   3/* In principle SSI is a point-point interface.  As such the qemu
   4   implementation has a single slave device on a "bus".
   5   However it is fairly common for boards to have multiple slaves
   6   connected to a single master, and select devices with an external
   7   chip select.  This is implemented in qemu by having an explicit mux device.
   8   It is assumed that master and slave are both using the same transfer width.
   9   */
  10
  11#ifndef QEMU_SSI_H
  12#define QEMU_SSI_H
  13
  14#include "hw/qdev.h"
  15
  16typedef struct SSISlave SSISlave;
  17typedef struct SSISlaveClass SSISlaveClass;
  18typedef enum SSICSMode SSICSMode;
  19
  20#define TYPE_SSI_SLAVE "ssi-slave"
  21#define SSI_SLAVE(obj) \
  22     OBJECT_CHECK(SSISlave, (obj), TYPE_SSI_SLAVE)
  23#define SSI_SLAVE_CLASS(klass) \
  24     OBJECT_CLASS_CHECK(SSISlaveClass, (klass), TYPE_SSI_SLAVE)
  25#define SSI_SLAVE_GET_CLASS(obj) \
  26     OBJECT_GET_CLASS(SSISlaveClass, (obj), TYPE_SSI_SLAVE)
  27
  28#define SSI_GPIO_CS "ssi-gpio-cs"
  29
  30enum SSICSMode {
  31    SSI_CS_NONE = 0,
  32    SSI_CS_LOW,
  33    SSI_CS_HIGH,
  34};
  35
  36/* Slave devices.  */
  37struct SSISlaveClass {
  38    DeviceClass parent_class;
  39
  40    int (*init)(SSISlave *dev);
  41
  42    /* if you have standard or no CS behaviour, just override transfer.
  43     * This is called when the device cs is active (true by default).
  44     */
  45    uint32_t (*transfer)(SSISlave *dev, uint32_t val);
  46    uint32_t (*transfer_bits)(SSISlave *dev, uint32_t val, int num_bits);
  47    /* called when the CS line changes. Optional, devices only need to implement
  48     * this if they have side effects associated with the cs line (beyond
  49     * tristating the txrx lines).
  50     */
  51    int (*set_cs)(SSISlave *dev, bool select);
  52    /* define whether or not CS exists and is active low/high */
  53    SSICSMode cs_polarity;
  54
  55    /* if you have non-standard CS behaviour override this to take control
  56     * of the CS behaviour at the device level. transfer, set_cs, and
  57     * cs_polarity are unused if this is overwritten. Transfer_raw will
  58     * always be called for the device for every txrx access to the parent bus
  59     */
  60    uint32_t (*transfer_raw)(SSISlave *dev, uint32_t val, int num_bits);
  61    /* Call this method to set the spi mode to single, dual or quad mode */
  62    void (*set_data_lines)(SSISlave *dev, uint8_t val);
  63};
  64
  65struct SSISlave {
  66    DeviceState parent_obj;
  67
  68    /* Chip select state */
  69    bool cs;
  70};
  71
  72#define FROM_SSI_SLAVE(type, dev) DO_UPCAST(type, ssidev, dev)
  73
  74extern const VMStateDescription vmstate_ssi_slave;
  75
  76#define VMSTATE_SSI_SLAVE(_field, _state) {                          \
  77    .name       = (stringify(_field)),                               \
  78    .size       = sizeof(SSISlave),                                  \
  79    .vmsd       = &vmstate_ssi_slave,                                \
  80    .flags      = VMS_STRUCT,                                        \
  81    .offset     = vmstate_offset_value(_state, _field, SSISlave),    \
  82}
  83
  84DeviceState *ssi_create_slave(SSIBus *bus, const char *name);
  85DeviceState *ssi_create_slave_no_init(SSIBus *bus, const char *name);
  86
  87/* Master interface.  */
  88SSIBus *ssi_create_bus(DeviceState *parent, const char *name);
  89
  90uint32_t ssi_transfer_bits(SSIBus *bus, uint32_t val, int num_bits);
  91uint32_t ssi_transfer(SSIBus *bus, uint32_t val);
  92
  93void ssi_set_datalines(SSIBus *bus, uint8_t val);
  94
  95/* Automatically connect all children nodes a spi controller as slaves */
  96void ssi_auto_connect_slaves(DeviceState *parent, qemu_irq *cs_lines,
  97                             SSIBus *bus);
  98
  99/* max111x.c */
 100void max111x_set_input(DeviceState *dev, int line, uint8_t value);
 101
 102#endif
 103