2 * Copyright (c) 2013 Jean-Christophe Dubois <jcd@tribudubois.net>
4 * i.MX31 SOC emulation.
6 * Based on hw/arm/fsl-imx31.c
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, see <http://www.gnu.org/licenses/>.
22 #include "qemu/osdep.h"
23 #include "qapi/error.h"
25 #include "hw/arm/fsl-imx31.h"
26 #include "sysemu/sysemu.h"
27 #include "exec/address-spaces.h"
28 #include "hw/qdev-properties.h"
29 #include "chardev/char.h"
31 static void fsl_imx31_init(Object
*obj
)
33 FslIMX31State
*s
= FSL_IMX31(obj
);
36 object_initialize_child(obj
, "cpu", &s
->cpu
, ARM_CPU_TYPE_NAME("arm1136"));
38 object_initialize_child(obj
, "avic", &s
->avic
, TYPE_IMX_AVIC
);
40 object_initialize_child(obj
, "ccm", &s
->ccm
, TYPE_IMX31_CCM
);
42 for (i
= 0; i
< FSL_IMX31_NUM_UARTS
; i
++) {
43 object_initialize_child(obj
, "uart[*]", &s
->uart
[i
], TYPE_IMX_SERIAL
);
46 object_initialize_child(obj
, "gpt", &s
->gpt
, TYPE_IMX31_GPT
);
48 for (i
= 0; i
< FSL_IMX31_NUM_EPITS
; i
++) {
49 object_initialize_child(obj
, "epit[*]", &s
->epit
[i
], TYPE_IMX_EPIT
);
52 for (i
= 0; i
< FSL_IMX31_NUM_I2CS
; i
++) {
53 object_initialize_child(obj
, "i2c[*]", &s
->i2c
[i
], TYPE_IMX_I2C
);
56 for (i
= 0; i
< FSL_IMX31_NUM_GPIOS
; i
++) {
57 object_initialize_child(obj
, "gpio[*]", &s
->gpio
[i
], TYPE_IMX_GPIO
);
60 object_initialize_child(obj
, "wdt", &s
->wdt
, TYPE_IMX2_WDT
);
63 static void fsl_imx31_realize(DeviceState
*dev
, Error
**errp
)
65 FslIMX31State
*s
= FSL_IMX31(dev
);
69 if (!qdev_realize(DEVICE(&s
->cpu
), NULL
, errp
)) {
73 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->avic
), errp
)) {
76 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->avic
), 0, FSL_IMX31_AVIC_ADDR
);
77 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->avic
), 0,
78 qdev_get_gpio_in(DEVICE(&s
->cpu
), ARM_CPU_IRQ
));
79 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->avic
), 1,
80 qdev_get_gpio_in(DEVICE(&s
->cpu
), ARM_CPU_FIQ
));
82 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->ccm
), errp
)) {
85 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->ccm
), 0, FSL_IMX31_CCM_ADDR
);
87 /* Initialize all UARTS */
88 for (i
= 0; i
< FSL_IMX31_NUM_UARTS
; i
++) {
92 } serial_table
[FSL_IMX31_NUM_UARTS
] = {
93 { FSL_IMX31_UART1_ADDR
, FSL_IMX31_UART1_IRQ
},
94 { FSL_IMX31_UART2_ADDR
, FSL_IMX31_UART2_IRQ
},
97 qdev_prop_set_chr(DEVICE(&s
->uart
[i
]), "chardev", serial_hd(i
));
99 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->uart
[i
]), errp
)) {
103 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->uart
[i
]), 0, serial_table
[i
].addr
);
104 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->uart
[i
]), 0,
105 qdev_get_gpio_in(DEVICE(&s
->avic
),
106 serial_table
[i
].irq
));
109 s
->gpt
.ccm
= IMX_CCM(&s
->ccm
);
111 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->gpt
), errp
)) {
115 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->gpt
), 0, FSL_IMX31_GPT_ADDR
);
116 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->gpt
), 0,
117 qdev_get_gpio_in(DEVICE(&s
->avic
), FSL_IMX31_GPT_IRQ
));
119 /* Initialize all EPIT timers */
120 for (i
= 0; i
< FSL_IMX31_NUM_EPITS
; i
++) {
121 static const struct {
124 } epit_table
[FSL_IMX31_NUM_EPITS
] = {
125 { FSL_IMX31_EPIT1_ADDR
, FSL_IMX31_EPIT1_IRQ
},
126 { FSL_IMX31_EPIT2_ADDR
, FSL_IMX31_EPIT2_IRQ
},
129 s
->epit
[i
].ccm
= IMX_CCM(&s
->ccm
);
131 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->epit
[i
]), errp
)) {
135 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->epit
[i
]), 0, epit_table
[i
].addr
);
136 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->epit
[i
]), 0,
137 qdev_get_gpio_in(DEVICE(&s
->avic
),
141 /* Initialize all I2C */
142 for (i
= 0; i
< FSL_IMX31_NUM_I2CS
; i
++) {
143 static const struct {
146 } i2c_table
[FSL_IMX31_NUM_I2CS
] = {
147 { FSL_IMX31_I2C1_ADDR
, FSL_IMX31_I2C1_IRQ
},
148 { FSL_IMX31_I2C2_ADDR
, FSL_IMX31_I2C2_IRQ
},
149 { FSL_IMX31_I2C3_ADDR
, FSL_IMX31_I2C3_IRQ
}
152 /* Initialize the I2C */
153 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->i2c
[i
]), errp
)) {
157 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->i2c
[i
]), 0, i2c_table
[i
].addr
);
158 /* Connect I2C IRQ to PIC */
159 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->i2c
[i
]), 0,
160 qdev_get_gpio_in(DEVICE(&s
->avic
),
164 /* Initialize all GPIOs */
165 for (i
= 0; i
< FSL_IMX31_NUM_GPIOS
; i
++) {
166 static const struct {
169 } gpio_table
[FSL_IMX31_NUM_GPIOS
] = {
170 { FSL_IMX31_GPIO1_ADDR
, FSL_IMX31_GPIO1_IRQ
},
171 { FSL_IMX31_GPIO2_ADDR
, FSL_IMX31_GPIO2_IRQ
},
172 { FSL_IMX31_GPIO3_ADDR
, FSL_IMX31_GPIO3_IRQ
}
175 object_property_set_bool(OBJECT(&s
->gpio
[i
]), "has-edge-sel", false,
177 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->gpio
[i
]), errp
)) {
180 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->gpio
[i
]), 0, gpio_table
[i
].addr
);
181 /* Connect GPIO IRQ to PIC */
182 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->gpio
[i
]), 0,
183 qdev_get_gpio_in(DEVICE(&s
->avic
),
188 sysbus_realize(SYS_BUS_DEVICE(&s
->wdt
), &error_abort
);
189 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->wdt
), 0, FSL_IMX31_WDT_ADDR
);
191 /* On a real system, the first 16k is a `secure boot rom' */
192 memory_region_init_rom(&s
->secure_rom
, OBJECT(dev
), "imx31.secure_rom",
193 FSL_IMX31_SECURE_ROM_SIZE
, &err
);
195 error_propagate(errp
, err
);
198 memory_region_add_subregion(get_system_memory(), FSL_IMX31_SECURE_ROM_ADDR
,
201 /* There is also a 16k ROM */
202 memory_region_init_rom(&s
->rom
, OBJECT(dev
), "imx31.rom",
203 FSL_IMX31_ROM_SIZE
, &err
);
205 error_propagate(errp
, err
);
208 memory_region_add_subregion(get_system_memory(), FSL_IMX31_ROM_ADDR
,
211 /* initialize internal RAM (16 KB) */
212 memory_region_init_ram(&s
->iram
, NULL
, "imx31.iram", FSL_IMX31_IRAM_SIZE
,
215 error_propagate(errp
, err
);
218 memory_region_add_subregion(get_system_memory(), FSL_IMX31_IRAM_ADDR
,
221 /* internal RAM (16 KB) is aliased over 256 MB - 16 KB */
222 memory_region_init_alias(&s
->iram_alias
, OBJECT(dev
), "imx31.iram_alias",
223 &s
->iram
, 0, FSL_IMX31_IRAM_ALIAS_SIZE
);
224 memory_region_add_subregion(get_system_memory(), FSL_IMX31_IRAM_ALIAS_ADDR
,
228 static void fsl_imx31_class_init(ObjectClass
*oc
, void *data
)
230 DeviceClass
*dc
= DEVICE_CLASS(oc
);
232 dc
->realize
= fsl_imx31_realize
;
233 dc
->desc
= "i.MX31 SOC";
235 * Reason: uses serial_hds in realize and the kzm board does not
236 * support multiple CPUs
238 dc
->user_creatable
= false;
241 static const TypeInfo fsl_imx31_type_info
= {
242 .name
= TYPE_FSL_IMX31
,
243 .parent
= TYPE_DEVICE
,
244 .instance_size
= sizeof(FslIMX31State
),
245 .instance_init
= fsl_imx31_init
,
246 .class_init
= fsl_imx31_class_init
,
249 static void fsl_imx31_register_types(void)
251 type_register_static(&fsl_imx31_type_info
);
254 type_init(fsl_imx31_register_types
)