2009-05-15 05:35:09 +08:00
|
|
|
/*
|
|
|
|
* QEMU Synchronous Serial Interface support
|
|
|
|
*
|
|
|
|
* Copyright (c) 2009 CodeSourcery.
|
|
|
|
* Written by Paul Brook
|
|
|
|
*
|
2011-06-26 10:21:35 +08:00
|
|
|
* This code is licensed under the GNU GPL v2.
|
2012-01-14 00:44:23 +08:00
|
|
|
*
|
|
|
|
* Contributions after 2012-01-13 are licensed under the terms of the
|
|
|
|
* GNU GPL, version 2 or (at your option) any later version.
|
2009-05-15 05:35:09 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ssi.h"
|
|
|
|
|
|
|
|
struct SSIBus {
|
2009-05-23 07:05:19 +08:00
|
|
|
BusState qbus;
|
2009-05-15 05:35:09 +08:00
|
|
|
};
|
|
|
|
|
2009-06-30 20:12:08 +08:00
|
|
|
static struct BusInfo ssi_bus_info = {
|
|
|
|
.name = "SSI",
|
|
|
|
.size = sizeof(SSIBus),
|
|
|
|
};
|
|
|
|
|
2011-12-10 05:02:56 +08:00
|
|
|
static int ssi_slave_init(DeviceState *dev)
|
2009-05-15 05:35:09 +08:00
|
|
|
{
|
2011-12-17 03:36:39 +08:00
|
|
|
SSISlave *s = SSI_SLAVE(dev);
|
|
|
|
SSISlaveClass *ssc = SSI_SLAVE_GET_CLASS(s);
|
2009-05-23 07:05:19 +08:00
|
|
|
SSIBus *bus;
|
|
|
|
|
|
|
|
bus = FROM_QBUS(SSIBus, qdev_get_parent_bus(dev));
|
2011-09-14 15:28:06 +08:00
|
|
|
if (QTAILQ_FIRST(&bus->qbus.children) != dev
|
|
|
|
|| QTAILQ_NEXT(dev, sibling) != NULL) {
|
2009-05-23 07:05:19 +08:00
|
|
|
hw_error("Too many devices on SSI bus");
|
|
|
|
}
|
2009-05-15 05:35:09 +08:00
|
|
|
|
2011-12-17 03:36:39 +08:00
|
|
|
return ssc->init(s);
|
2009-05-15 05:35:09 +08:00
|
|
|
}
|
|
|
|
|
2011-12-08 11:34:16 +08:00
|
|
|
static void ssi_slave_class_init(ObjectClass *klass, void *data)
|
2009-05-15 05:35:09 +08:00
|
|
|
{
|
2011-12-08 11:34:16 +08:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
dc->init = ssi_slave_init;
|
|
|
|
dc->bus_info = &ssi_bus_info;
|
2009-05-15 05:35:09 +08:00
|
|
|
}
|
|
|
|
|
2011-12-08 11:34:16 +08:00
|
|
|
static TypeInfo ssi_slave_info = {
|
|
|
|
.name = TYPE_SSI_SLAVE,
|
|
|
|
.parent = TYPE_DEVICE,
|
|
|
|
.class_init = ssi_slave_class_init,
|
|
|
|
.class_size = sizeof(SSISlaveClass),
|
|
|
|
.abstract = true,
|
|
|
|
};
|
|
|
|
|
2009-05-15 05:35:09 +08:00
|
|
|
DeviceState *ssi_create_slave(SSIBus *bus, const char *name)
|
|
|
|
{
|
|
|
|
DeviceState *dev;
|
2009-05-23 07:05:19 +08:00
|
|
|
dev = qdev_create(&bus->qbus, name);
|
2009-10-07 07:15:58 +08:00
|
|
|
qdev_init_nofail(dev);
|
2009-05-15 05:35:09 +08:00
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2009-05-23 07:05:19 +08:00
|
|
|
BusState *bus;
|
2009-06-30 20:12:08 +08:00
|
|
|
bus = qbus_create(&ssi_bus_info, parent, name);
|
2009-05-23 07:05:19 +08:00
|
|
|
return FROM_QBUS(SSIBus, bus);
|
2009-05-15 05:35:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t ssi_transfer(SSIBus *bus, uint32_t val)
|
|
|
|
{
|
2009-05-23 07:05:19 +08:00
|
|
|
DeviceState *dev;
|
|
|
|
SSISlave *slave;
|
2011-12-17 03:36:39 +08:00
|
|
|
SSISlaveClass *ssc;
|
2011-09-14 15:28:06 +08:00
|
|
|
dev = QTAILQ_FIRST(&bus->qbus.children);
|
2009-05-23 07:05:19 +08:00
|
|
|
if (!dev) {
|
2009-05-15 05:35:09 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2011-12-17 03:36:39 +08:00
|
|
|
slave = SSI_SLAVE(dev);
|
|
|
|
ssc = SSI_SLAVE_GET_CLASS(slave);
|
|
|
|
return ssc->transfer(slave, val);
|
2009-05-15 05:35:09 +08:00
|
|
|
}
|
2011-12-08 11:34:16 +08:00
|
|
|
|
2012-02-09 22:20:55 +08:00
|
|
|
static void ssi_slave_register_types(void)
|
2011-12-08 11:34:16 +08:00
|
|
|
{
|
|
|
|
type_register_static(&ssi_slave_info);
|
|
|
|
}
|
|
|
|
|
2012-02-09 22:20:55 +08:00
|
|
|
type_init(ssi_slave_register_types)
|