xref: /qemu/include/hw/ssi/ssi.h (revision 9ce89a22aed41e8486dddb27fbeea9f182b90516)
190d37239SPaul Brook /* QEMU Synchronous Serial Interface support.  */
290d37239SPaul Brook 
3*9ce89a22SPhilippe Mathieu-Daudé /*
4*9ce89a22SPhilippe Mathieu-Daudé  * In principle SSI is a point-point interface.  As such the qemu
5*9ce89a22SPhilippe Mathieu-Daudé  * implementation has a single slave device on a "bus".
6*9ce89a22SPhilippe Mathieu-Daudé  * However it is fairly common for boards to have multiple slaves
7*9ce89a22SPhilippe Mathieu-Daudé  * connected to a single master, and select devices with an external
8*9ce89a22SPhilippe Mathieu-Daudé  * chip select.  This is implemented in qemu by having an explicit mux device.
9*9ce89a22SPhilippe Mathieu-Daudé  * It is assumed that master and slave are both using the same transfer
10*9ce89a22SPhilippe Mathieu-Daudé  * width.
1190d37239SPaul Brook  */
1290d37239SPaul Brook 
1390d37239SPaul Brook #ifndef QEMU_SSI_H
1490d37239SPaul Brook #define QEMU_SSI_H
1590d37239SPaul Brook 
16a27bd6c7SMarkus Armbruster #include "hw/qdev-core.h"
17db1015e9SEduardo Habkost #include "qom/object.h"
1890d37239SPaul Brook 
198fd06719SAlistair Francis typedef enum SSICSMode SSICSMode;
2090d37239SPaul Brook 
21cd6c4cf2SAnthony Liguori #define TYPE_SSI_SLAVE "ssi-slave"
22c821774aSEduardo Habkost OBJECT_DECLARE_TYPE(SSISlave, SSISlaveClass,
2330b5707cSEduardo Habkost                     SSI_SLAVE)
24cd6c4cf2SAnthony Liguori 
25de77914eSPeter Crosthwaite #define SSI_GPIO_CS "ssi-gpio-cs"
26de77914eSPeter Crosthwaite 
278fd06719SAlistair Francis enum SSICSMode {
2866530953SPeter A. G. Crosthwaite     SSI_CS_NONE = 0,
2966530953SPeter A. G. Crosthwaite     SSI_CS_LOW,
3066530953SPeter A. G. Crosthwaite     SSI_CS_HIGH,
318fd06719SAlistair Francis };
3266530953SPeter A. G. Crosthwaite 
3390d37239SPaul Brook /* Slave devices.  */
348fd06719SAlistair Francis struct SSISlaveClass {
35cd6c4cf2SAnthony Liguori     DeviceClass parent_class;
36cd6c4cf2SAnthony Liguori 
377673bb4cSCédric Le Goater     void (*realize)(SSISlave *dev, Error **errp);
3866530953SPeter A. G. Crosthwaite 
3966530953SPeter A. G. Crosthwaite     /* if you have standard or no CS behaviour, just override transfer.
4066530953SPeter A. G. Crosthwaite      * This is called when the device cs is active (true by default).
4166530953SPeter A. G. Crosthwaite      */
4290d37239SPaul Brook     uint32_t (*transfer)(SSISlave *dev, uint32_t val);
4366530953SPeter A. G. Crosthwaite     /* called when the CS line changes. Optional, devices only need to implement
4466530953SPeter A. G. Crosthwaite      * this if they have side effects associated with the cs line (beyond
4566530953SPeter A. G. Crosthwaite      * tristating the txrx lines).
4666530953SPeter A. G. Crosthwaite      */
4766530953SPeter A. G. Crosthwaite     int (*set_cs)(SSISlave *dev, bool select);
4866530953SPeter A. G. Crosthwaite     /* define whether or not CS exists and is active low/high */
4966530953SPeter A. G. Crosthwaite     SSICSMode cs_polarity;
5066530953SPeter A. G. Crosthwaite 
5166530953SPeter A. G. Crosthwaite     /* if you have non-standard CS behaviour override this to take control
5266530953SPeter A. G. Crosthwaite      * of the CS behaviour at the device level. transfer, set_cs, and
5366530953SPeter A. G. Crosthwaite      * cs_polarity are unused if this is overwritten. Transfer_raw will
5466530953SPeter A. G. Crosthwaite      * always be called for the device for every txrx access to the parent bus
5566530953SPeter A. G. Crosthwaite      */
5666530953SPeter A. G. Crosthwaite     uint32_t (*transfer_raw)(SSISlave *dev, uint32_t val);
578fd06719SAlistair Francis };
5890d37239SPaul Brook 
5990d37239SPaul Brook struct SSISlave {
601f760d5fSPeter Crosthwaite     DeviceState parent_obj;
6166530953SPeter A. G. Crosthwaite 
6266530953SPeter A. G. Crosthwaite     /* Chip select state */
6366530953SPeter A. G. Crosthwaite     bool cs;
6490d37239SPaul Brook };
6590d37239SPaul Brook 
6666530953SPeter A. G. Crosthwaite extern const VMStateDescription vmstate_ssi_slave;
6766530953SPeter A. G. Crosthwaite 
6866530953SPeter A. G. Crosthwaite #define VMSTATE_SSI_SLAVE(_field, _state) {                          \
6966530953SPeter A. G. Crosthwaite     .name       = (stringify(_field)),                               \
7066530953SPeter A. G. Crosthwaite     .size       = sizeof(SSISlave),                                  \
7166530953SPeter A. G. Crosthwaite     .vmsd       = &vmstate_ssi_slave,                                \
7266530953SPeter A. G. Crosthwaite     .flags      = VMS_STRUCT,                                        \
7366530953SPeter A. G. Crosthwaite     .offset     = vmstate_offset_value(_state, _field, SSISlave),    \
7466530953SPeter A. G. Crosthwaite }
7566530953SPeter A. G. Crosthwaite 
7690d37239SPaul Brook DeviceState *ssi_create_slave(SSIBus *bus, const char *name);
77581e109dSPeter Maydell /**
78581e109dSPeter Maydell  * ssi_realize_and_unref: realize and unref an SSI slave device
79581e109dSPeter Maydell  * @dev: SSI slave device to realize
80581e109dSPeter Maydell  * @bus: SSI bus to put it on
81581e109dSPeter Maydell  * @errp: error pointer
82581e109dSPeter Maydell  *
83581e109dSPeter Maydell  * Call 'realize' on @dev, put it on the specified @bus, and drop the
84581e109dSPeter Maydell  * reference to it. Errors are reported via @errp and by returning
85581e109dSPeter Maydell  * false.
86581e109dSPeter Maydell  *
87581e109dSPeter Maydell  * This function is useful if you have created @dev via qdev_new()
88581e109dSPeter Maydell  * (which takes a reference to the device it returns to you), so that
89581e109dSPeter Maydell  * you can set properties on it before realizing it. If you don't need
90581e109dSPeter Maydell  * to set properties then ssi_create_slave() is probably better (as it
91581e109dSPeter Maydell  * does the create, init and realize in one step).
92581e109dSPeter Maydell  *
93581e109dSPeter Maydell  * If you are embedding the SSI slave into another QOM device and
94581e109dSPeter Maydell  * initialized it via some variant on object_initialize_child() then
95581e109dSPeter Maydell  * do not use this function, because that family of functions arrange
96581e109dSPeter Maydell  * for the only reference to the child device to be held by the parent
97581e109dSPeter Maydell  * via the child<> property, and so the reference-count-drop done here
98581e109dSPeter Maydell  * would be incorrect.  (Instead you would want ssi_realize(), which
99581e109dSPeter Maydell  * doesn't currently exist but would be trivial to create if we had
100581e109dSPeter Maydell  * any code that wanted it.)
101581e109dSPeter Maydell  */
102581e109dSPeter Maydell bool ssi_realize_and_unref(DeviceState *dev, SSIBus *bus, Error **errp);
10390d37239SPaul Brook 
10490d37239SPaul Brook /* Master interface.  */
10502e2da45SPaul Brook SSIBus *ssi_create_bus(DeviceState *parent, const char *name);
10690d37239SPaul Brook 
10790d37239SPaul Brook uint32_t ssi_transfer(SSIBus *bus, uint32_t val);
10890d37239SPaul Brook 
10990d37239SPaul Brook #endif
110