Statistics
| Branch: | Revision:

root / include / hw / ssi.h @ f487b677

History | View | Annotate | Download (3.2 kB)

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