2 * Copyright (c) 2018, Impinj, Inc.
4 * i.MX7 GPR IP block emulation code
6 * Author: Andrey Smirnov <andrew.smirnov@gmail.com>
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 "sysemu/sysemu.h"
22 enum IMX7GPRRegisters
{
48 #define IMX7D_GPR1_IRQ_MASK BIT(12)
49 #define IMX7D_GPR1_ENET1_TX_CLK_SEL_MASK BIT(13)
50 #define IMX7D_GPR1_ENET2_TX_CLK_SEL_MASK BIT(14)
51 #define IMX7D_GPR1_ENET_TX_CLK_SEL_MASK (0x3 << 13)
52 #define IMX7D_GPR1_ENET1_CLK_DIR_MASK BIT(17)
53 #define IMX7D_GPR1_ENET2_CLK_DIR_MASK BIT(18)
54 #define IMX7D_GPR1_ENET_CLK_DIR_MASK (0x3 << 17)
56 #define IMX7D_GPR5_CSI_MUX_CONTROL_MIPI BIT(4)
57 #define IMX7D_GPR12_PCIE_PHY_REFCLK_SEL BIT(5)
58 #define IMX7D_GPR22_PCIE_PHY_PLL_LOCKED BIT(31)
61 static uint64_t imx7_gpr_read(void *opaque
, hwaddr offset
, unsigned size
)
63 trace_imx7_gpr_read(offset
);
65 if (offset
== IOMUXC_GPR22
) {
66 return IMX7D_GPR22_PCIE_PHY_PLL_LOCKED
;
72 static void imx7_gpr_write(void *opaque
, hwaddr offset
,
73 uint64_t v
, unsigned size
)
75 trace_imx7_gpr_write(offset
, v
);
78 static const struct MemoryRegionOps imx7_gpr_ops
= {
79 .read
= imx7_gpr_read
,
80 .write
= imx7_gpr_write
,
81 .endianness
= DEVICE_NATIVE_ENDIAN
,
84 * Our device would not work correctly if the guest was doing
85 * unaligned access. This might not be a limitation on the
86 * real device but in practice there is no reason for a guest
87 * to access this device unaligned.
95 static void imx7_gpr_init(Object
*obj
)
97 SysBusDevice
*sd
= SYS_BUS_DEVICE(obj
);
98 IMX7GPRState
*s
= IMX7_GPR(obj
);
100 memory_region_init_io(&s
->mmio
, obj
, &imx7_gpr_ops
, s
,
101 TYPE_IMX7_GPR
, 64 * 1024);
102 sysbus_init_mmio(sd
, &s
->mmio
);
105 static void imx7_gpr_class_init(ObjectClass
*klass
, void *data
)
107 DeviceClass
*dc
= DEVICE_CLASS(klass
);
109 dc
->desc
= "i.MX7 General Purpose Registers Module";
112 static const TypeInfo imx7_gpr_info
= {
113 .name
= TYPE_IMX7_GPR
,
114 .parent
= TYPE_SYS_BUS_DEVICE
,
115 .instance_size
= sizeof(IMX7GPRState
),
116 .instance_init
= imx7_gpr_init
,
117 .class_init
= imx7_gpr_class_init
,
120 static void imx7_gpr_register_type(void)
122 type_register_static(&imx7_gpr_info
);
124 type_init(imx7_gpr_register_type
)