2009-05-15 01:35:09 +04:00
|
|
|
/* QEMU Synchronous Serial Interface support. */
|
|
|
|
|
2020-10-12 15:49:54 +03:00
|
|
|
/*
|
|
|
|
* In principle SSI is a point-point interface. As such the qemu
|
|
|
|
* implementation has a single slave device on a "bus".
|
|
|
|
* However it is fairly common for boards to have multiple slaves
|
|
|
|
* connected to a single master, and select devices with an external
|
|
|
|
* chip select. This is implemented in qemu by having an explicit mux device.
|
|
|
|
* It is assumed that master and slave are both using the same transfer
|
|
|
|
* width.
|
|
|
|
*/
|
2009-05-15 01:35:09 +04:00
|
|
|
|
|
|
|
#ifndef QEMU_SSI_H
|
|
|
|
#define QEMU_SSI_H
|
|
|
|
|
2019-08-12 08:23:51 +03:00
|
|
|
#include "hw/qdev-core.h"
|
2020-09-03 23:43:22 +03:00
|
|
|
#include "qom/object.h"
|
2009-05-15 01:35:09 +04:00
|
|
|
|
2016-01-21 17:15:03 +03:00
|
|
|
typedef enum SSICSMode SSICSMode;
|
2009-05-15 01:35:09 +04:00
|
|
|
|
2011-12-16 23:36:39 +04:00
|
|
|
#define TYPE_SSI_SLAVE "ssi-slave"
|
2020-09-01 00:07:37 +03:00
|
|
|
OBJECT_DECLARE_TYPE(SSISlave, SSISlaveClass,
|
qom: Remove module_obj_name parameter from OBJECT_DECLARE* macros
One of the goals of having less boilerplate on QOM declarations
is to avoid human error. Requiring an extra argument that is
never used is an opportunity for mistakes.
Remove the unused argument from OBJECT_DECLARE_TYPE and
OBJECT_DECLARE_SIMPLE_TYPE.
Coccinelle patch used to convert all users of the macros:
@@
declarer name OBJECT_DECLARE_TYPE;
identifier InstanceType, ClassType, lowercase, UPPERCASE;
@@
OBJECT_DECLARE_TYPE(InstanceType, ClassType,
- lowercase,
UPPERCASE);
@@
declarer name OBJECT_DECLARE_SIMPLE_TYPE;
identifier InstanceType, lowercase, UPPERCASE;
@@
OBJECT_DECLARE_SIMPLE_TYPE(InstanceType,
- lowercase,
UPPERCASE);
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Acked-by: Cornelia Huck <cohuck@redhat.com>
Acked-by: Igor Mammedov <imammedo@redhat.com>
Acked-by: Paul Durrant <paul@xen.org>
Acked-by: Thomas Huth <thuth@redhat.com>
Message-Id: <20200916182519.415636-4-ehabkost@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
2020-09-16 21:25:17 +03:00
|
|
|
SSI_SLAVE)
|
2011-12-16 23:36:39 +04:00
|
|
|
|
2014-05-20 10:31:33 +04:00
|
|
|
#define SSI_GPIO_CS "ssi-gpio-cs"
|
|
|
|
|
2016-01-21 17:15:03 +03:00
|
|
|
enum SSICSMode {
|
2012-07-24 06:23:22 +04:00
|
|
|
SSI_CS_NONE = 0,
|
|
|
|
SSI_CS_LOW,
|
|
|
|
SSI_CS_HIGH,
|
2016-01-21 17:15:03 +03:00
|
|
|
};
|
2012-07-24 06:23:22 +04:00
|
|
|
|
2009-05-15 01:35:09 +04:00
|
|
|
/* Slave devices. */
|
2016-01-21 17:15:03 +03:00
|
|
|
struct SSISlaveClass {
|
2011-12-16 23:36:39 +04:00
|
|
|
DeviceClass parent_class;
|
|
|
|
|
2016-07-04 15:06:37 +03:00
|
|
|
void (*realize)(SSISlave *dev, Error **errp);
|
2012-07-24 06:23:22 +04:00
|
|
|
|
|
|
|
/* if you have standard or no CS behaviour, just override transfer.
|
|
|
|
* This is called when the device cs is active (true by default).
|
|
|
|
*/
|
2009-05-15 01:35:09 +04:00
|
|
|
uint32_t (*transfer)(SSISlave *dev, uint32_t val);
|
2012-07-24 06:23:22 +04:00
|
|
|
/* called when the CS line changes. Optional, devices only need to implement
|
|
|
|
* this if they have side effects associated with the cs line (beyond
|
|
|
|
* tristating the txrx lines).
|
|
|
|
*/
|
|
|
|
int (*set_cs)(SSISlave *dev, bool select);
|
|
|
|
/* define whether or not CS exists and is active low/high */
|
|
|
|
SSICSMode cs_polarity;
|
|
|
|
|
|
|
|
/* if you have non-standard CS behaviour override this to take control
|
|
|
|
* of the CS behaviour at the device level. transfer, set_cs, and
|
|
|
|
* cs_polarity are unused if this is overwritten. Transfer_raw will
|
|
|
|
* always be called for the device for every txrx access to the parent bus
|
|
|
|
*/
|
|
|
|
uint32_t (*transfer_raw)(SSISlave *dev, uint32_t val);
|
2016-01-21 17:15:03 +03:00
|
|
|
};
|
2009-05-15 01:35:09 +04:00
|
|
|
|
|
|
|
struct SSISlave {
|
2014-02-12 04:30:10 +04:00
|
|
|
DeviceState parent_obj;
|
2012-07-24 06:23:22 +04:00
|
|
|
|
|
|
|
/* Chip select state */
|
|
|
|
bool cs;
|
2009-05-15 01:35:09 +04:00
|
|
|
};
|
|
|
|
|
2012-07-24 06:23:22 +04:00
|
|
|
extern const VMStateDescription vmstate_ssi_slave;
|
|
|
|
|
|
|
|
#define VMSTATE_SSI_SLAVE(_field, _state) { \
|
|
|
|
.name = (stringify(_field)), \
|
|
|
|
.size = sizeof(SSISlave), \
|
|
|
|
.vmsd = &vmstate_ssi_slave, \
|
|
|
|
.flags = VMS_STRUCT, \
|
|
|
|
.offset = vmstate_offset_value(_state, _field, SSISlave), \
|
|
|
|
}
|
|
|
|
|
2009-05-15 01:35:09 +04:00
|
|
|
DeviceState *ssi_create_slave(SSIBus *bus, const char *name);
|
2020-07-03 18:59:44 +03:00
|
|
|
/**
|
|
|
|
* ssi_realize_and_unref: realize and unref an SSI slave device
|
|
|
|
* @dev: SSI slave device to realize
|
|
|
|
* @bus: SSI bus to put it on
|
|
|
|
* @errp: error pointer
|
|
|
|
*
|
|
|
|
* Call 'realize' on @dev, put it on the specified @bus, and drop the
|
|
|
|
* reference to it. Errors are reported via @errp and by returning
|
|
|
|
* false.
|
|
|
|
*
|
|
|
|
* This function is useful if you have created @dev via qdev_new()
|
|
|
|
* (which takes a reference to the device it returns to you), so that
|
|
|
|
* you can set properties on it before realizing it. If you don't need
|
|
|
|
* to set properties then ssi_create_slave() is probably better (as it
|
|
|
|
* does the create, init and realize in one step).
|
|
|
|
*
|
|
|
|
* If you are embedding the SSI slave into another QOM device and
|
|
|
|
* initialized it via some variant on object_initialize_child() then
|
|
|
|
* do not use this function, because that family of functions arrange
|
|
|
|
* for the only reference to the child device to be held by the parent
|
|
|
|
* via the child<> property, and so the reference-count-drop done here
|
|
|
|
* would be incorrect. (Instead you would want ssi_realize(), which
|
|
|
|
* doesn't currently exist but would be trivial to create if we had
|
|
|
|
* any code that wanted it.)
|
|
|
|
*/
|
|
|
|
bool ssi_realize_and_unref(DeviceState *dev, SSIBus *bus, Error **errp);
|
2009-05-15 01:35:09 +04:00
|
|
|
|
|
|
|
/* Master interface. */
|
2009-05-23 03:05:19 +04:00
|
|
|
SSIBus *ssi_create_bus(DeviceState *parent, const char *name);
|
2009-05-15 01:35:09 +04:00
|
|
|
|
|
|
|
uint32_t ssi_transfer(SSIBus *bus, uint32_t val);
|
|
|
|
|
|
|
|
#endif
|