diff options
author | Peter Crosthwaite <peter.crosthwaite@xilinx.com> | 2012-10-01 12:34:37 +1000 |
---|---|---|
committer | Peter Crosthwaite <peter.crosthwaite@xilinx.com> | 2012-10-10 11:13:32 +1000 |
commit | b4ae3cfa57b8c1bdbbd7b7d420971e9171203ade (patch) | |
tree | 08fc675a0ce8db85b5096792f85d3bfc01daaade /hw/ssi.c | |
parent | fcb5629d3eb208d84c0fe9aa1ef64a6af7de0139 (diff) | |
download | qemu-b4ae3cfa57b8c1bdbbd7b7d420971e9171203ade.zip qemu-b4ae3cfa57b8c1bdbbd7b7d420971e9171203ade.tar.gz qemu-b4ae3cfa57b8c1bdbbd7b7d420971e9171203ade.tar.bz2 |
ssi: Add slave autoconnect helper
Added helper function to automatically connect SPI slaves based on the QOM child
nodes of a device. A SSI master device can call this routine to automatically
hook-up all child nodes to its SPI bus.
Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
Acked-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'hw/ssi.c')
-rw-r--r-- | hw/ssi.c | 33 |
1 files changed, 33 insertions, 0 deletions
@@ -139,3 +139,36 @@ static void ssi_slave_register_types(void) } type_init(ssi_slave_register_types) + +typedef struct SSIAutoConnectArg { + qemu_irq **cs_linep; + SSIBus *bus; +} SSIAutoConnectArg; + +static int ssi_auto_connect_slave(Object *child, void *opaque) +{ + SSIAutoConnectArg *arg = opaque; + SSISlave *dev = (SSISlave *)object_dynamic_cast(child, TYPE_SSI_SLAVE); + qemu_irq cs_line; + + if (!dev) { + return 0; + } + + cs_line = qdev_get_gpio_in(DEVICE(dev), 0); + qdev_set_parent_bus(DEVICE(dev), &arg->bus->qbus); + **arg->cs_linep = cs_line; + (*arg->cs_linep)++; + return 0; +} + +void ssi_auto_connect_slaves(DeviceState *parent, qemu_irq *cs_line, + SSIBus *bus) +{ + SSIAutoConnectArg arg = { + .cs_linep = &cs_line, + .bus = bus + }; + + object_child_foreach(OBJECT(parent), ssi_auto_connect_slave, &arg); +} |