2 * QEMU model of the Xilinx usb subsystem
4 * Copyright (c) 2020 Xilinx Inc. Sai Pavan Boddu <sai.pava.boddu@xilinx.com>
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 #include "qemu/osdep.h"
26 #include "hw/sysbus.h"
27 #include "hw/register.h"
28 #include "qemu/bitops.h"
29 #include "qom/object.h"
30 #include "qapi/error.h"
31 #include "hw/qdev-properties.h"
32 #include "hw/usb/xlnx-usb-subsystem.h"
34 static void versal_usb2_realize(DeviceState
*dev
, Error
**errp
)
36 VersalUsb2
*s
= VERSAL_USB2(dev
);
37 SysBusDevice
*sbd
= SYS_BUS_DEVICE(dev
);
40 sysbus_realize(SYS_BUS_DEVICE(&s
->dwc3
), &err
);
42 error_propagate(errp
, err
);
45 sysbus_realize(SYS_BUS_DEVICE(&s
->usb2Ctrl
), &err
);
47 error_propagate(errp
, err
);
50 sysbus_init_mmio(sbd
, &s
->dwc3_mr
);
51 sysbus_init_mmio(sbd
, &s
->usb2Ctrl_mr
);
52 qdev_pass_gpios(DEVICE(&s
->dwc3
.sysbus_xhci
), dev
, SYSBUS_DEVICE_GPIO_IRQ
);
55 static void versal_usb2_init(Object
*obj
)
57 VersalUsb2
*s
= VERSAL_USB2(obj
);
59 object_initialize_child(obj
, "versal.dwc3", &s
->dwc3
,
61 object_initialize_child(obj
, "versal.usb2-ctrl", &s
->usb2Ctrl
,
62 TYPE_XILINX_VERSAL_USB2_CTRL_REGS
);
63 memory_region_init_alias(&s
->dwc3_mr
, obj
, "versal.dwc3_alias",
64 &s
->dwc3
.iomem
, 0, DWC3_SIZE
);
65 memory_region_init_alias(&s
->usb2Ctrl_mr
, obj
, "versal.usb2Ctrl_alias",
66 &s
->usb2Ctrl
.iomem
, 0, USB2_REGS_R_MAX
* 4);
67 qdev_alias_all_properties(DEVICE(&s
->dwc3
), obj
);
68 qdev_alias_all_properties(DEVICE(&s
->dwc3
.sysbus_xhci
), obj
);
69 object_property_add_alias(obj
, "dma", OBJECT(&s
->dwc3
.sysbus_xhci
), "dma");
72 static void versal_usb2_class_init(ObjectClass
*klass
, void *data
)
74 DeviceClass
*dc
= DEVICE_CLASS(klass
);
76 dc
->realize
= versal_usb2_realize
;
79 static const TypeInfo versal_usb2_info
= {
80 .name
= TYPE_XILINX_VERSAL_USB2
,
81 .parent
= TYPE_SYS_BUS_DEVICE
,
82 .instance_size
= sizeof(VersalUsb2
),
83 .class_init
= versal_usb2_class_init
,
84 .instance_init
= versal_usb2_init
,
87 static void versal_usb_types(void)
89 type_register_static(&versal_usb2_info
);
92 type_init(versal_usb_types
)