2 * QEMU Synchronous Serial Interface support
4 * Copyright (c) 2009 CodeSourcery.
5 * Written by Paul Brook
7 * This code is licensed under the GNU GPL v2.
9 * Contributions after 2012-01-13 are licensed under the terms of the
10 * GNU GPL, version 2 or (at your option) any later version.
19 #define TYPE_SSI_BUS "SSI"
20 #define SSI_BUS(obj) OBJECT_CHECK(SSIBus, (obj), TYPE_SSI_BUS)
22 static const TypeInfo ssi_bus_info
= {
25 .instance_size
= sizeof(SSIBus
),
28 static int ssi_slave_init(DeviceState
*dev
)
30 SSISlave
*s
= SSI_SLAVE(dev
);
31 SSISlaveClass
*ssc
= SSI_SLAVE_GET_CLASS(s
);
35 bus
= FROM_QBUS(SSIBus
, qdev_get_parent_bus(dev
));
36 kid
= QTAILQ_FIRST(&bus
->qbus
.children
);
37 if (kid
->child
!= dev
|| QTAILQ_NEXT(kid
, sibling
) != NULL
) {
38 hw_error("Too many devices on SSI bus");
44 static void ssi_slave_class_init(ObjectClass
*klass
, void *data
)
46 DeviceClass
*dc
= DEVICE_CLASS(klass
);
47 dc
->init
= ssi_slave_init
;
48 dc
->bus_type
= TYPE_SSI_BUS
;
51 static TypeInfo ssi_slave_info
= {
52 .name
= TYPE_SSI_SLAVE
,
53 .parent
= TYPE_DEVICE
,
54 .class_init
= ssi_slave_class_init
,
55 .class_size
= sizeof(SSISlaveClass
),
59 DeviceState
*ssi_create_slave(SSIBus
*bus
, const char *name
)
62 dev
= qdev_create(&bus
->qbus
, name
);
63 qdev_init_nofail(dev
);
67 SSIBus
*ssi_create_bus(DeviceState
*parent
, const char *name
)
70 bus
= qbus_create(TYPE_SSI_BUS
, parent
, name
);
71 return FROM_QBUS(SSIBus
, bus
);
74 uint32_t ssi_transfer(SSIBus
*bus
, uint32_t val
)
80 kid
= QTAILQ_FIRST(&bus
->qbus
.children
);
84 slave
= SSI_SLAVE(kid
->child
);
85 ssc
= SSI_SLAVE_GET_CLASS(slave
);
86 return ssc
->transfer(slave
, val
);
89 static void ssi_slave_register_types(void)
91 type_register_static(&ssi_bus_info
);
92 type_register_static(&ssi_slave_info
);
95 type_init(ssi_slave_register_types
)