hw/arm: Restore local modifications
[qemu/ar7.git] / hw / vlynq.c
blob67b0dfaf3826b901175d1db800edd5ed95496be6
1 /*
2 * QEMU VLYNQ Serial Interface support.
4 * Copyright (C) 2009-2012 Stefan Weil
6 * Portions of the code are copies from ssi.c.
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) version 3 or any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "qemu/osdep.h"
24 #include "vlynq.h"
26 #if 0 // TODO: Fix code for QOM API.
28 struct _VLYNQBus {
29 BusState qbus;
32 static struct BusInfo vlynq_bus_info = {
33 .name = "VLYNQ",
34 .size = sizeof(VLYNQBus),
37 static int vlynq_qdev_init(DeviceState *qdev, DeviceInfo *base)
39 VLYNQDevice *vlynq_dev = (VLYNQDevice *)qdev;
40 VLYNQDeviceInfo *info = container_of(base, VLYNQDeviceInfo, qdev);
41 //~ int devfn;
42 int rc;
44 //~ VLYNQBus *bus = FROM_QBUS(VLYNQBus, qdev_get_parent_bus(qdev));
45 //~ devfn = pci_dev->devfn;
46 //~ vlynq_dev = do_pci_register_device(pci_dev, bus, base->name, devfn,
47 //~ info->config_read, info->config_write,
48 //~ info->header_type);
49 //~ if (vlynq_dev == NULL) {
50 //~ return -1;
51 //~ }
52 rc = info->init(vlynq_dev);
53 if (rc != 0) {
54 //~ do_pci_unregister_device(pci_dev);
57 return rc;
60 static int vlynq_unregister_device(DeviceState *dev)
62 // TODO: missing implementation.
64 //~ VLYNQDevice *vlynq_dev = DO_UPCAST(VLYNQDevice, qdev, dev);
65 //~ VLYNQDeviceInfo *info = DO_UPCAST(VLYNQDeviceInfo, qdev, dev->info);
66 int ret = 0;
68 //~ if (info->exit) {
69 //~ ret = info->exit(vlynq_dev);
70 //~ }
71 if (ret) {
72 return ret;
75 //~ pci_unregister_io_regions(pci_dev);
76 //~ do_pci_unregister_device(pci_dev);
77 return 0;
80 void vlynq_qdev_register(VLYNQDeviceInfo *info)
82 info->qdev.init = vlynq_qdev_init;
83 //~ info->qdev.unplug = vlynq_unplug_device;
84 info->qdev.exit = vlynq_unregister_device;
85 info->qdev.bus_info = &vlynq_bus_info;
86 qdev_register(&info->qdev);
89 #if 0
90 static int vlynq_slave_init(DeviceState *dev, DeviceInfo *base_info)
92 VLYNQSlaveInfo *info = container_of(base_info, VLYNQSlaveInfo, qdev);
93 VLYNQSlave *s = VLYNQ_SLAVE_FROM_QDEV(dev);
94 VLYNQBus *bus;
96 bus = FROM_QBUS(VLYNQBus, qdev_get_parent_bus(dev));
97 if (QLIST_FIRST(&bus->qbus.children) != dev
98 || QLIST_NEXT(dev, sibling) != NULL) {
99 hw_error("Too many devices on VLYNQ bus");
102 s->info = info;
103 return info->init(s);
106 void vlynq_register_slave(VLYNQSlaveInfo *info)
108 assert(info->qdev.size >= sizeof(VLYNQSlave));
109 info->qdev.init = vlynq_slave_init;
110 info->qdev.bus_info = &vlynq_bus_info;
111 qdev_register(&info->qdev);
114 #endif
116 DeviceState *vlynq_create_slave(VLYNQBus *bus, const char *name)
118 DeviceState *dev;
119 dev = qdev_create(&bus->qbus, name);
120 qdev_init_nofail(dev);
121 return dev;
124 VLYNQBus *vlynq_create_bus(DeviceState *parent, const char *name)
126 BusState *bus;
127 bus = qbus_create(&vlynq_bus_info, parent, name);
128 return FROM_QBUS(VLYNQBus, bus);
131 #if 0
132 uint32_t vlynq_transfer(VLYNQBus *bus, uint32_t val)
134 DeviceState *dev;
135 VLYNQSlave *slave;
136 dev = QLIST_FIRST(&bus->qbus.children);
137 if (!dev) {
138 return 0;
140 slave = VLYNQ_SLAVE_FROM_QDEV(dev);
141 return slave->info->transfer(slave, val);
143 #endif
144 #endif // Fix code for QOM API.