xref: /qemu/include/hw/ssi/ssi.h (revision ec7e429bd250ecfb6528e27eec58ea9ee47cd95d)
190d37239SPaul Brook /* QEMU Synchronous Serial Interface support.  */
290d37239SPaul Brook 
39ce89a22SPhilippe Mathieu-Daudé /*
49ce89a22SPhilippe Mathieu-Daudé  * In principle SSI is a point-point interface.  As such the qemu
5*ec7e429bSPhilippe Mathieu-Daudé  * implementation has a single peripheral on a "bus".
6*ec7e429bSPhilippe Mathieu-Daudé  * However it is fairly common for boards to have multiple peripherals
79ce89a22SPhilippe Mathieu-Daudé  * connected to a single master, and select devices with an external
89ce89a22SPhilippe Mathieu-Daudé  * chip select.  This is implemented in qemu by having an explicit mux device.
9*ec7e429bSPhilippe Mathieu-Daudé  * It is assumed that master and peripheral are both using the same transfer
109ce89a22SPhilippe 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 
21*ec7e429bSPhilippe Mathieu-Daudé #define TYPE_SSI_PERIPHERAL "ssi-peripheral"
22*ec7e429bSPhilippe Mathieu-Daudé OBJECT_DECLARE_TYPE(SSIPeripheral, SSIPeripheralClass,
23*ec7e429bSPhilippe Mathieu-Daudé                     SSI_PERIPHERAL)
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 
33*ec7e429bSPhilippe Mathieu-Daudé /* Peripherals.  */
34*ec7e429bSPhilippe Mathieu-Daudé struct SSIPeripheralClass {
35cd6c4cf2SAnthony Liguori     DeviceClass parent_class;
36cd6c4cf2SAnthony Liguori 
37*ec7e429bSPhilippe Mathieu-Daudé     void (*realize)(SSIPeripheral *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      */
42*ec7e429bSPhilippe Mathieu-Daudé     uint32_t (*transfer)(SSIPeripheral *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      */
47*ec7e429bSPhilippe Mathieu-Daudé     int (*set_cs)(SSIPeripheral *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      */
56*ec7e429bSPhilippe Mathieu-Daudé     uint32_t (*transfer_raw)(SSIPeripheral *dev, uint32_t val);
578fd06719SAlistair Francis };
5890d37239SPaul Brook 
59*ec7e429bSPhilippe Mathieu-Daudé struct SSIPeripheral {
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 
66*ec7e429bSPhilippe Mathieu-Daudé extern const VMStateDescription vmstate_ssi_peripheral;
6766530953SPeter A. G. Crosthwaite 
68*ec7e429bSPhilippe Mathieu-Daudé #define VMSTATE_SSI_PERIPHERAL(_field, _state) {                     \
6966530953SPeter A. G. Crosthwaite     .name       = (stringify(_field)),                               \
70*ec7e429bSPhilippe Mathieu-Daudé     .size       = sizeof(SSIPeripheral),                             \
71*ec7e429bSPhilippe Mathieu-Daudé     .vmsd       = &vmstate_ssi_peripheral,                           \
7266530953SPeter A. G. Crosthwaite     .flags      = VMS_STRUCT,                                        \
73*ec7e429bSPhilippe Mathieu-Daudé     .offset     = vmstate_offset_value(_state, _field, SSIPeripheral), \
7466530953SPeter A. G. Crosthwaite }
7566530953SPeter A. G. Crosthwaite 
76*ec7e429bSPhilippe Mathieu-Daudé DeviceState *ssi_create_peripheral(SSIBus *bus, const char *name);
77581e109dSPeter Maydell /**
78*ec7e429bSPhilippe Mathieu-Daudé  * ssi_realize_and_unref: realize and unref an SSI peripheral
79*ec7e429bSPhilippe Mathieu-Daudé  * @dev: SSI peripheral 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
90*ec7e429bSPhilippe Mathieu-Daudé  * to set properties then ssi_create_peripheral() is probably better (as it
91581e109dSPeter Maydell  * does the create, init and realize in one step).
92581e109dSPeter Maydell  *
93*ec7e429bSPhilippe Mathieu-Daudé  * If you are embedding the SSI peripheral 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