]> git.proxmox.com Git - mirror_qemu.git/blame - include/hw/ssi/ssi.h
Move QOM typedefs and add missing includes
[mirror_qemu.git] / include / hw / ssi / ssi.h
CommitLineData
90d37239
PB
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
a27bd6c7 14#include "hw/qdev-core.h"
db1015e9 15#include "qom/object.h"
90d37239
PB
16
17typedef struct SSISlave SSISlave;
8fd06719
AF
18typedef struct SSISlaveClass SSISlaveClass;
19typedef enum SSICSMode SSICSMode;
90d37239 20
cd6c4cf2
AL
21#define TYPE_SSI_SLAVE "ssi-slave"
22#define SSI_SLAVE(obj) \
23 OBJECT_CHECK(SSISlave, (obj), TYPE_SSI_SLAVE)
24#define SSI_SLAVE_CLASS(klass) \
25 OBJECT_CLASS_CHECK(SSISlaveClass, (klass), TYPE_SSI_SLAVE)
26#define SSI_SLAVE_GET_CLASS(obj) \
27 OBJECT_GET_CLASS(SSISlaveClass, (obj), TYPE_SSI_SLAVE)
28
de77914e
PC
29#define SSI_GPIO_CS "ssi-gpio-cs"
30
8fd06719 31enum SSICSMode {
66530953
PC
32 SSI_CS_NONE = 0,
33 SSI_CS_LOW,
34 SSI_CS_HIGH,
8fd06719 35};
66530953 36
90d37239 37/* Slave devices. */
8fd06719 38struct SSISlaveClass {
cd6c4cf2
AL
39 DeviceClass parent_class;
40
7673bb4c 41 void (*realize)(SSISlave *dev, Error **errp);
66530953
PC
42
43 /* if you have standard or no CS behaviour, just override transfer.
44 * This is called when the device cs is active (true by default).
45 */
90d37239 46 uint32_t (*transfer)(SSISlave *dev, uint32_t val);
66530953
PC
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);
8fd06719 61};
90d37239
PB
62
63struct SSISlave {
1f760d5f 64 DeviceState parent_obj;
66530953
PC
65
66 /* Chip select state */
67 bool cs;
90d37239
PB
68};
69
66530953
PC
70extern const VMStateDescription vmstate_ssi_slave;
71
72#define VMSTATE_SSI_SLAVE(_field, _state) { \
73 .name = (stringify(_field)), \
74 .size = sizeof(SSISlave), \
75 .vmsd = &vmstate_ssi_slave, \
76 .flags = VMS_STRUCT, \
77 .offset = vmstate_offset_value(_state, _field, SSISlave), \
78}
79
90d37239 80DeviceState *ssi_create_slave(SSIBus *bus, const char *name);
581e109d
PM
81/**
82 * ssi_realize_and_unref: realize and unref an SSI slave device
83 * @dev: SSI slave device to realize
84 * @bus: SSI bus to put it on
85 * @errp: error pointer
86 *
87 * Call 'realize' on @dev, put it on the specified @bus, and drop the
88 * reference to it. Errors are reported via @errp and by returning
89 * false.
90 *
91 * This function is useful if you have created @dev via qdev_new()
92 * (which takes a reference to the device it returns to you), so that
93 * you can set properties on it before realizing it. If you don't need
94 * to set properties then ssi_create_slave() is probably better (as it
95 * does the create, init and realize in one step).
96 *
97 * If you are embedding the SSI slave into another QOM device and
98 * initialized it via some variant on object_initialize_child() then
99 * do not use this function, because that family of functions arrange
100 * for the only reference to the child device to be held by the parent
101 * via the child<> property, and so the reference-count-drop done here
102 * would be incorrect. (Instead you would want ssi_realize(), which
103 * doesn't currently exist but would be trivial to create if we had
104 * any code that wanted it.)
105 */
106bool ssi_realize_and_unref(DeviceState *dev, SSIBus *bus, Error **errp);
90d37239
PB
107
108/* Master interface. */
02e2da45 109SSIBus *ssi_create_bus(DeviceState *parent, const char *name);
90d37239
PB
110
111uint32_t ssi_transfer(SSIBus *bus, uint32_t val);
112
113#endif