2009-05-15 05:35:09 +08:00
|
|
|
/* QEMU Synchronous Serial Interface support. */
|
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef QEMU_SSI_H
|
|
|
|
#define QEMU_SSI_H
|
|
|
|
|
2013-02-04 22:40:22 +08:00
|
|
|
#include "hw/qdev.h"
|
2009-05-15 05:35:09 +08:00
|
|
|
|
|
|
|
typedef struct SSISlave SSISlave;
|
|
|
|
|
2011-12-17 03:36:39 +08:00
|
|
|
#define TYPE_SSI_SLAVE "ssi-slave"
|
|
|
|
#define SSI_SLAVE(obj) \
|
|
|
|
OBJECT_CHECK(SSISlave, (obj), TYPE_SSI_SLAVE)
|
|
|
|
#define SSI_SLAVE_CLASS(klass) \
|
|
|
|
OBJECT_CLASS_CHECK(SSISlaveClass, (klass), TYPE_SSI_SLAVE)
|
|
|
|
#define SSI_SLAVE_GET_CLASS(obj) \
|
|
|
|
OBJECT_GET_CLASS(SSISlaveClass, (obj), TYPE_SSI_SLAVE)
|
|
|
|
|
2014-05-20 14:31:33 +08:00
|
|
|
#define SSI_GPIO_CS "ssi-gpio-cs"
|
|
|
|
|
2012-07-24 10:23:22 +08:00
|
|
|
typedef enum {
|
|
|
|
SSI_CS_NONE = 0,
|
|
|
|
SSI_CS_LOW,
|
|
|
|
SSI_CS_HIGH,
|
|
|
|
} SSICSMode;
|
|
|
|
|
2009-05-15 05:35:09 +08:00
|
|
|
/* Slave devices. */
|
2011-12-17 03:36:39 +08:00
|
|
|
typedef struct SSISlaveClass {
|
|
|
|
DeviceClass parent_class;
|
|
|
|
|
2009-08-14 16:36:05 +08:00
|
|
|
int (*init)(SSISlave *dev);
|
2012-07-24 10:23:22 +08: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 05:35:09 +08:00
|
|
|
uint32_t (*transfer)(SSISlave *dev, uint32_t val);
|
2012-07-24 10:23:22 +08: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);
|
2011-12-17 03:36:39 +08:00
|
|
|
} SSISlaveClass;
|
2009-05-15 05:35:09 +08:00
|
|
|
|
|
|
|
struct SSISlave {
|
2014-02-12 08:30:10 +08:00
|
|
|
DeviceState parent_obj;
|
2012-07-24 10:23:22 +08:00
|
|
|
|
|
|
|
/* Chip select state */
|
|
|
|
bool cs;
|
2009-05-15 05:35:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#define FROM_SSI_SLAVE(type, dev) DO_UPCAST(type, ssidev, dev)
|
|
|
|
|
2012-07-24 10:23:22 +08: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 05:35:09 +08:00
|
|
|
DeviceState *ssi_create_slave(SSIBus *bus, const char *name);
|
2012-07-24 11:56:27 +08:00
|
|
|
DeviceState *ssi_create_slave_no_init(SSIBus *bus, const char *name);
|
2009-05-15 05:35:09 +08:00
|
|
|
|
|
|
|
/* Master interface. */
|
2009-05-23 07:05:19 +08:00
|
|
|
SSIBus *ssi_create_bus(DeviceState *parent, const char *name);
|
2009-05-15 05:35:09 +08:00
|
|
|
|
|
|
|
uint32_t ssi_transfer(SSIBus *bus, uint32_t val);
|
|
|
|
|
2012-10-01 10:34:37 +08:00
|
|
|
/* Automatically connect all children nodes a spi controller as slaves */
|
|
|
|
void ssi_auto_connect_slaves(DeviceState *parent, qemu_irq *cs_lines,
|
|
|
|
SSIBus *bus);
|
|
|
|
|
2009-05-15 05:35:09 +08:00
|
|
|
/* max111x.c */
|
|
|
|
void max111x_set_input(DeviceState *dev, int line, uint8_t value);
|
|
|
|
|
2009-05-15 05:35:09 +08:00
|
|
|
#endif
|