2 * Copyright (c) 2018, Impinj, Inc.
4 * i.MX7 GPR IP block emulation code
8 * This work is licensed under the terms of the GNU GPL, version 2 or later.
9 * See the COPYING file in the top-level directory.
11 * Bare minimum emulation code needed to support being able to shut
12 * down linux guest gracefully.
15 #include "qemu/osdep.h"
16 #include "hw/misc/imx7_gpr.h"
18 #include "qemu/module.h"
19 #include "sysemu/sysemu.h"
23 enum IMX7GPRRegisters {
49 #define IMX7D_GPR1_IRQ_MASK BIT(12)
50 #define IMX7D_GPR1_ENET1_TX_CLK_SEL_MASK BIT(13)
51 #define IMX7D_GPR1_ENET2_TX_CLK_SEL_MASK BIT(14)
52 #define IMX7D_GPR1_ENET_TX_CLK_SEL_MASK (0x3 << 13)
53 #define IMX7D_GPR1_ENET1_CLK_DIR_MASK BIT(17)
54 #define IMX7D_GPR1_ENET2_CLK_DIR_MASK BIT(18)
55 #define IMX7D_GPR1_ENET_CLK_DIR_MASK (0x3 << 17)
57 #define IMX7D_GPR5_CSI_MUX_CONTROL_MIPI BIT(4)
58 #define IMX7D_GPR12_PCIE_PHY_REFCLK_SEL BIT(5)
59 #define IMX7D_GPR22_PCIE_PHY_PLL_LOCKED BIT(31)
62 static uint64_t imx7_gpr_read(void *opaque, hwaddr offset, unsigned size)
64 trace_imx7_gpr_read(offset);
66 if (offset == IOMUXC_GPR22) {
67 return IMX7D_GPR22_PCIE_PHY_PLL_LOCKED;
73 static void imx7_gpr_write(void *opaque, hwaddr offset,
74 uint64_t v, unsigned size)
76 trace_imx7_gpr_write(offset, v);
79 static const struct MemoryRegionOps imx7_gpr_ops = {
80 .read = imx7_gpr_read,
81 .write = imx7_gpr_write,
82 .endianness = DEVICE_NATIVE_ENDIAN,
85 * Our device would not work correctly if the guest was doing
86 * unaligned access. This might not be a limitation on the
87 * real device but in practice there is no reason for a guest
88 * to access this device unaligned.
96 static void imx7_gpr_init(Object *obj)
98 SysBusDevice *sd = SYS_BUS_DEVICE(obj);
99 IMX7GPRState *s = IMX7_GPR(obj);
101 memory_region_init_io(&s->mmio, obj, &imx7_gpr_ops, s,
102 TYPE_IMX7_GPR, 64 * 1024);
103 sysbus_init_mmio(sd, &s->mmio);
106 static void imx7_gpr_class_init(ObjectClass *klass, void *data)
108 DeviceClass *dc = DEVICE_CLASS(klass);
110 dc->desc = "i.MX7 General Purpose Registers Module";
113 static const TypeInfo imx7_gpr_info = {
114 .name = TYPE_IMX7_GPR,
115 .parent = TYPE_SYS_BUS_DEVICE,
116 .instance_size = sizeof(IMX7GPRState),
117 .instance_init = imx7_gpr_init,
118 .class_init = imx7_gpr_class_init,
121 static void imx7_gpr_register_type(void)
123 type_register_static(&imx7_gpr_info);
125 type_init(imx7_gpr_register_type)