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"
24 #include "qemu-common.h"
26 #include "hw/arm/fsl-imx31.h"
27 #include "sysemu/sysemu.h"
28 #include "exec/address-spaces.h"
29 #include "hw/boards.h"
30 #include "chardev/char.h"
32 static void fsl_imx31_init(Object
*obj
)
34 FslIMX31State
*s
= FSL_IMX31(obj
);
37 object_initialize(&s
->cpu
, sizeof(s
->cpu
), "arm1136-" TYPE_ARM_CPU
);
39 sysbus_init_child_obj(obj
, "avic", &s
->avic
, sizeof(s
->avic
),
42 sysbus_init_child_obj(obj
, "ccm", &s
->ccm
, sizeof(s
->ccm
), TYPE_IMX31_CCM
);
44 for (i
= 0; i
< FSL_IMX31_NUM_UARTS
; i
++) {
45 sysbus_init_child_obj(obj
, "uart[*]", &s
->uart
[i
], sizeof(s
->uart
[i
]),
49 sysbus_init_child_obj(obj
, "gpt", &s
->gpt
, sizeof(s
->gpt
), TYPE_IMX31_GPT
);
51 for (i
= 0; i
< FSL_IMX31_NUM_EPITS
; i
++) {
52 sysbus_init_child_obj(obj
, "epit[*]", &s
->epit
[i
], sizeof(s
->epit
[i
]),
56 for (i
= 0; i
< FSL_IMX31_NUM_I2CS
; i
++) {
57 sysbus_init_child_obj(obj
, "i2c[*]", &s
->i2c
[i
], sizeof(s
->i2c
[i
]),
61 for (i
= 0; i
< FSL_IMX31_NUM_GPIOS
; i
++) {
62 sysbus_init_child_obj(obj
, "gpio[*]", &s
->gpio
[i
], sizeof(s
->gpio
[i
]),
67 static void fsl_imx31_realize(DeviceState
*dev
, Error
**errp
)
69 FslIMX31State
*s
= FSL_IMX31(dev
);
73 object_property_set_bool(OBJECT(&s
->cpu
), true, "realized", &err
);
75 error_propagate(errp
, err
);
79 object_property_set_bool(OBJECT(&s
->avic
), true, "realized", &err
);
81 error_propagate(errp
, err
);
84 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->avic
), 0, FSL_IMX31_AVIC_ADDR
);
85 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->avic
), 0,
86 qdev_get_gpio_in(DEVICE(&s
->cpu
), ARM_CPU_IRQ
));
87 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->avic
), 1,
88 qdev_get_gpio_in(DEVICE(&s
->cpu
), ARM_CPU_FIQ
));
90 object_property_set_bool(OBJECT(&s
->ccm
), true, "realized", &err
);
92 error_propagate(errp
, err
);
95 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->ccm
), 0, FSL_IMX31_CCM_ADDR
);
97 /* Initialize all UARTS */
98 for (i
= 0; i
< FSL_IMX31_NUM_UARTS
; i
++) {
102 } serial_table
[FSL_IMX31_NUM_UARTS
] = {
103 { FSL_IMX31_UART1_ADDR
, FSL_IMX31_UART1_IRQ
},
104 { FSL_IMX31_UART2_ADDR
, FSL_IMX31_UART2_IRQ
},
107 qdev_prop_set_chr(DEVICE(&s
->uart
[i
]), "chardev", serial_hd(i
));
109 object_property_set_bool(OBJECT(&s
->uart
[i
]), true, "realized", &err
);
111 error_propagate(errp
, err
);
115 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->uart
[i
]), 0, serial_table
[i
].addr
);
116 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->uart
[i
]), 0,
117 qdev_get_gpio_in(DEVICE(&s
->avic
),
118 serial_table
[i
].irq
));
121 s
->gpt
.ccm
= IMX_CCM(&s
->ccm
);
123 object_property_set_bool(OBJECT(&s
->gpt
), true, "realized", &err
);
125 error_propagate(errp
, err
);
129 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->gpt
), 0, FSL_IMX31_GPT_ADDR
);
130 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->gpt
), 0,
131 qdev_get_gpio_in(DEVICE(&s
->avic
), FSL_IMX31_GPT_IRQ
));
133 /* Initialize all EPIT timers */
134 for (i
= 0; i
< FSL_IMX31_NUM_EPITS
; i
++) {
135 static const struct {
138 } epit_table
[FSL_IMX31_NUM_EPITS
] = {
139 { FSL_IMX31_EPIT1_ADDR
, FSL_IMX31_EPIT1_IRQ
},
140 { FSL_IMX31_EPIT2_ADDR
, FSL_IMX31_EPIT2_IRQ
},
143 s
->epit
[i
].ccm
= IMX_CCM(&s
->ccm
);
145 object_property_set_bool(OBJECT(&s
->epit
[i
]), true, "realized", &err
);
147 error_propagate(errp
, err
);
151 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->epit
[i
]), 0, epit_table
[i
].addr
);
152 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->epit
[i
]), 0,
153 qdev_get_gpio_in(DEVICE(&s
->avic
),
157 /* Initialize all I2C */
158 for (i
= 0; i
< FSL_IMX31_NUM_I2CS
; i
++) {
159 static const struct {
162 } i2c_table
[FSL_IMX31_NUM_I2CS
] = {
163 { FSL_IMX31_I2C1_ADDR
, FSL_IMX31_I2C1_IRQ
},
164 { FSL_IMX31_I2C2_ADDR
, FSL_IMX31_I2C2_IRQ
},
165 { FSL_IMX31_I2C3_ADDR
, FSL_IMX31_I2C3_IRQ
}
168 /* Initialize the I2C */
169 object_property_set_bool(OBJECT(&s
->i2c
[i
]), true, "realized", &err
);
171 error_propagate(errp
, err
);
175 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->i2c
[i
]), 0, i2c_table
[i
].addr
);
176 /* Connect I2C IRQ to PIC */
177 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->i2c
[i
]), 0,
178 qdev_get_gpio_in(DEVICE(&s
->avic
),
182 /* Initialize all GPIOs */
183 for (i
= 0; i
< FSL_IMX31_NUM_GPIOS
; i
++) {
184 static const struct {
187 } gpio_table
[FSL_IMX31_NUM_GPIOS
] = {
188 { FSL_IMX31_GPIO1_ADDR
, FSL_IMX31_GPIO1_IRQ
},
189 { FSL_IMX31_GPIO2_ADDR
, FSL_IMX31_GPIO2_IRQ
},
190 { FSL_IMX31_GPIO3_ADDR
, FSL_IMX31_GPIO3_IRQ
}
193 object_property_set_bool(OBJECT(&s
->gpio
[i
]), false, "has-edge-sel",
195 object_property_set_bool(OBJECT(&s
->gpio
[i
]), true, "realized", &err
);
197 error_propagate(errp
, err
);
200 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->gpio
[i
]), 0, gpio_table
[i
].addr
);
201 /* Connect GPIO IRQ to PIC */
202 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->gpio
[i
]), 0,
203 qdev_get_gpio_in(DEVICE(&s
->avic
),
207 /* On a real system, the first 16k is a `secure boot rom' */
208 memory_region_init_rom(&s
->secure_rom
, NULL
, "imx31.secure_rom",
209 FSL_IMX31_SECURE_ROM_SIZE
, &err
);
211 error_propagate(errp
, err
);
214 memory_region_add_subregion(get_system_memory(), FSL_IMX31_SECURE_ROM_ADDR
,
217 /* There is also a 16k ROM */
218 memory_region_init_rom(&s
->rom
, NULL
, "imx31.rom",
219 FSL_IMX31_ROM_SIZE
, &err
);
221 error_propagate(errp
, err
);
224 memory_region_add_subregion(get_system_memory(), FSL_IMX31_ROM_ADDR
,
227 /* initialize internal RAM (16 KB) */
228 memory_region_init_ram(&s
->iram
, NULL
, "imx31.iram", FSL_IMX31_IRAM_SIZE
,
231 error_propagate(errp
, err
);
234 memory_region_add_subregion(get_system_memory(), FSL_IMX31_IRAM_ADDR
,
237 /* internal RAM (16 KB) is aliased over 256 MB - 16 KB */
238 memory_region_init_alias(&s
->iram_alias
, NULL
, "imx31.iram_alias",
239 &s
->iram
, 0, FSL_IMX31_IRAM_ALIAS_SIZE
);
240 memory_region_add_subregion(get_system_memory(), FSL_IMX31_IRAM_ALIAS_ADDR
,
244 static void fsl_imx31_class_init(ObjectClass
*oc
, void *data
)
246 DeviceClass
*dc
= DEVICE_CLASS(oc
);
248 dc
->realize
= fsl_imx31_realize
;
249 dc
->desc
= "i.MX31 SOC";
251 * Reason: uses serial_hds in realize and the kzm board does not
252 * support multiple CPUs
254 dc
->user_creatable
= false;
257 static const TypeInfo fsl_imx31_type_info
= {
258 .name
= TYPE_FSL_IMX31
,
259 .parent
= TYPE_DEVICE
,
260 .instance_size
= sizeof(FslIMX31State
),
261 .instance_init
= fsl_imx31_init
,
262 .class_init
= fsl_imx31_class_init
,
265 static void fsl_imx31_register_types(void)
267 type_register_static(&fsl_imx31_type_info
);
270 type_init(fsl_imx31_register_types
)