1 /* QEMU Synchronous Serial Interface support. */
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.
14 #include "hw/qdev-core.h"
15 #include "qom/object.h"
17 typedef struct SSISlave SSISlave
;
18 typedef struct SSISlaveClass SSISlaveClass
;
19 typedef enum SSICSMode SSICSMode
;
21 #define TYPE_SSI_SLAVE "ssi-slave"
22 DECLARE_OBJ_CHECKERS(SSISlave
, SSISlaveClass
,
23 SSI_SLAVE
, TYPE_SSI_SLAVE
)
25 #define SSI_GPIO_CS "ssi-gpio-cs"
34 struct SSISlaveClass
{
35 DeviceClass parent_class
;
37 void (*realize
)(SSISlave
*dev
, Error
**errp
);
39 /* if you have standard or no CS behaviour, just override transfer.
40 * This is called when the device cs is active (true by default).
42 uint32_t (*transfer
)(SSISlave
*dev
, uint32_t val
);
43 /* called when the CS line changes. Optional, devices only need to implement
44 * this if they have side effects associated with the cs line (beyond
45 * tristating the txrx lines).
47 int (*set_cs
)(SSISlave
*dev
, bool select
);
48 /* define whether or not CS exists and is active low/high */
49 SSICSMode cs_polarity
;
51 /* if you have non-standard CS behaviour override this to take control
52 * of the CS behaviour at the device level. transfer, set_cs, and
53 * cs_polarity are unused if this is overwritten. Transfer_raw will
54 * always be called for the device for every txrx access to the parent bus
56 uint32_t (*transfer_raw
)(SSISlave
*dev
, uint32_t val
);
60 DeviceState parent_obj
;
62 /* Chip select state */
66 extern const VMStateDescription vmstate_ssi_slave
;
68 #define VMSTATE_SSI_SLAVE(_field, _state) { \
69 .name = (stringify(_field)), \
70 .size = sizeof(SSISlave), \
71 .vmsd = &vmstate_ssi_slave, \
72 .flags = VMS_STRUCT, \
73 .offset = vmstate_offset_value(_state, _field, SSISlave), \
76 DeviceState
*ssi_create_slave(SSIBus
*bus
, const char *name
);
78 * ssi_realize_and_unref: realize and unref an SSI slave device
79 * @dev: SSI slave device to realize
80 * @bus: SSI bus to put it on
81 * @errp: error pointer
83 * Call 'realize' on @dev, put it on the specified @bus, and drop the
84 * reference to it. Errors are reported via @errp and by returning
87 * This function is useful if you have created @dev via qdev_new()
88 * (which takes a reference to the device it returns to you), so that
89 * you can set properties on it before realizing it. If you don't need
90 * to set properties then ssi_create_slave() is probably better (as it
91 * does the create, init and realize in one step).
93 * If you are embedding the SSI slave into another QOM device and
94 * initialized it via some variant on object_initialize_child() then
95 * do not use this function, because that family of functions arrange
96 * for the only reference to the child device to be held by the parent
97 * via the child<> property, and so the reference-count-drop done here
98 * would be incorrect. (Instead you would want ssi_realize(), which
99 * doesn't currently exist but would be trivial to create if we had
100 * any code that wanted it.)
102 bool ssi_realize_and_unref(DeviceState
*dev
, SSIBus
*bus
, Error
**errp
);
104 /* Master interface. */
105 SSIBus
*ssi_create_bus(DeviceState
*parent
, const char *name
);
107 uint32_t ssi_transfer(SSIBus
*bus
, uint32_t val
);