remove #if 0 code for timers
[qemu/ar7.git] / hw / ssi.c
blobb47953a989d1b1be046edcda01db6d550d6f83ec
1 /*
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.
13 #include "ssi.h"
15 struct SSIBus {
16 BusState qbus;
19 static struct BusInfo ssi_bus_info = {
20 .name = "SSI",
21 .size = sizeof(SSIBus),
24 static int ssi_slave_init(DeviceState *dev, DeviceInfo *base_info)
26 SSISlaveInfo *info = container_of(base_info, SSISlaveInfo, qdev);
27 SSISlave *s = SSI_SLAVE_FROM_QDEV(dev);
28 SSIBus *bus;
30 bus = FROM_QBUS(SSIBus, qdev_get_parent_bus(dev));
31 if (QTAILQ_FIRST(&bus->qbus.children) != dev
32 || QTAILQ_NEXT(dev, sibling) != NULL) {
33 hw_error("Too many devices on SSI bus");
36 s->info = info;
37 return info->init(s);
40 void ssi_register_slave(SSISlaveInfo *info)
42 assert(info->qdev.size >= sizeof(SSISlave));
43 info->qdev.init = ssi_slave_init;
44 info->qdev.bus_info = &ssi_bus_info;
45 qdev_register(&info->qdev);
48 DeviceState *ssi_create_slave(SSIBus *bus, const char *name)
50 DeviceState *dev;
51 dev = qdev_create(&bus->qbus, name);
52 qdev_init_nofail(dev);
53 return dev;
56 SSIBus *ssi_create_bus(DeviceState *parent, const char *name)
58 BusState *bus;
59 bus = qbus_create(&ssi_bus_info, parent, name);
60 return FROM_QBUS(SSIBus, bus);
63 uint32_t ssi_transfer(SSIBus *bus, uint32_t val)
65 DeviceState *dev;
66 SSISlave *slave;
67 dev = QTAILQ_FIRST(&bus->qbus.children);
68 if (!dev) {
69 return 0;
71 slave = SSI_SLAVE_FROM_QDEV(dev);
72 return slave->info->transfer(slave, val);