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 "hw/arm/fsl-imx31.h"
23 #include "sysemu/sysemu.h"
24 #include "exec/address-spaces.h"
25 #include "hw/boards.h"
26 #include "sysemu/char.h"
28 static void fsl_imx31_init(Object
*obj
)
30 FslIMX31State
*s
= FSL_IMX31(obj
);
33 object_initialize(&s
->cpu
, sizeof(s
->cpu
), "arm1136-" TYPE_ARM_CPU
);
35 object_initialize(&s
->avic
, sizeof(s
->avic
), TYPE_IMX_AVIC
);
36 qdev_set_parent_bus(DEVICE(&s
->avic
), sysbus_get_default());
38 object_initialize(&s
->ccm
, sizeof(s
->ccm
), TYPE_IMX_CCM
);
39 qdev_set_parent_bus(DEVICE(&s
->ccm
), sysbus_get_default());
41 for (i
= 0; i
< FSL_IMX31_NUM_UARTS
; i
++) {
42 object_initialize(&s
->uart
[i
], sizeof(s
->uart
[i
]), TYPE_IMX_SERIAL
);
43 qdev_set_parent_bus(DEVICE(&s
->uart
[i
]), sysbus_get_default());
46 object_initialize(&s
->gpt
, sizeof(s
->gpt
), TYPE_IMX_GPT
);
47 qdev_set_parent_bus(DEVICE(&s
->gpt
), sysbus_get_default());
49 for (i
= 0; i
< FSL_IMX31_NUM_EPITS
; i
++) {
50 object_initialize(&s
->epit
[i
], sizeof(s
->epit
[i
]), TYPE_IMX_EPIT
);
51 qdev_set_parent_bus(DEVICE(&s
->epit
[i
]), sysbus_get_default());
54 for (i
= 0; i
< FSL_IMX31_NUM_I2CS
; i
++) {
55 object_initialize(&s
->i2c
[i
], sizeof(s
->i2c
[i
]), TYPE_IMX_I2C
);
56 qdev_set_parent_bus(DEVICE(&s
->i2c
[i
]), sysbus_get_default());
60 static void fsl_imx31_realize(DeviceState
*dev
, Error
**errp
)
62 FslIMX31State
*s
= FSL_IMX31(dev
);
66 object_property_set_bool(OBJECT(&s
->cpu
), true, "realized", &err
);
68 error_propagate(errp
, err
);
72 object_property_set_bool(OBJECT(&s
->avic
), true, "realized", &err
);
74 error_propagate(errp
, err
);
77 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->avic
), 0, FSL_IMX31_AVIC_ADDR
);
78 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->avic
), 0,
79 qdev_get_gpio_in(DEVICE(&s
->cpu
), ARM_CPU_IRQ
));
80 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->avic
), 1,
81 qdev_get_gpio_in(DEVICE(&s
->cpu
), ARM_CPU_FIQ
));
83 object_property_set_bool(OBJECT(&s
->ccm
), true, "realized", &err
);
85 error_propagate(errp
, err
);
88 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->ccm
), 0, FSL_IMX31_CCM_ADDR
);
90 /* Initialize all UARTS */
91 for (i
= 0; i
< FSL_IMX31_NUM_UARTS
; i
++) {
95 } serial_table
[FSL_IMX31_NUM_UARTS
] = {
96 { FSL_IMX31_UART1_ADDR
, FSL_IMX31_UART1_IRQ
},
97 { FSL_IMX31_UART2_ADDR
, FSL_IMX31_UART2_IRQ
},
100 if (i
< MAX_SERIAL_PORTS
) {
101 CharDriverState
*chr
;
107 snprintf(label
, sizeof(label
), "imx31.uart%d", i
);
108 chr
= qemu_chr_new(label
, "null", NULL
);
111 qdev_prop_set_chr(DEVICE(&s
->uart
[i
]), "chardev", chr
);
114 object_property_set_bool(OBJECT(&s
->uart
[i
]), true, "realized", &err
);
116 error_propagate(errp
, err
);
120 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->uart
[i
]), 0, serial_table
[i
].addr
);
121 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->uart
[i
]), 0,
122 qdev_get_gpio_in(DEVICE(&s
->avic
),
123 serial_table
[i
].irq
));
126 s
->gpt
.ccm
= DEVICE(&s
->ccm
);
128 object_property_set_bool(OBJECT(&s
->gpt
), true, "realized", &err
);
130 error_propagate(errp
, err
);
134 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->gpt
), 0, FSL_IMX31_GPT_ADDR
);
135 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->gpt
), 0,
136 qdev_get_gpio_in(DEVICE(&s
->avic
), FSL_IMX31_GPT_IRQ
));
138 /* Initialize all EPIT timers */
139 for (i
= 0; i
< FSL_IMX31_NUM_EPITS
; i
++) {
140 static const struct {
143 } epit_table
[FSL_IMX31_NUM_EPITS
] = {
144 { FSL_IMX31_EPIT1_ADDR
, FSL_IMX31_EPIT1_IRQ
},
145 { FSL_IMX31_EPIT2_ADDR
, FSL_IMX31_EPIT2_IRQ
},
148 s
->epit
[i
].ccm
= DEVICE(&s
->ccm
);
150 object_property_set_bool(OBJECT(&s
->epit
[i
]), true, "realized", &err
);
152 error_propagate(errp
, err
);
156 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->epit
[i
]), 0, epit_table
[i
].addr
);
157 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->epit
[i
]), 0,
158 qdev_get_gpio_in(DEVICE(&s
->avic
),
162 /* Initialize all I2C */
163 for (i
= 0; i
< FSL_IMX31_NUM_I2CS
; i
++) {
164 static const struct {
167 } i2c_table
[FSL_IMX31_NUM_I2CS
] = {
168 { FSL_IMX31_I2C1_ADDR
, FSL_IMX31_I2C1_IRQ
},
169 { FSL_IMX31_I2C2_ADDR
, FSL_IMX31_I2C2_IRQ
},
170 { FSL_IMX31_I2C3_ADDR
, FSL_IMX31_I2C3_IRQ
}
173 /* Initialize the I2C */
174 object_property_set_bool(OBJECT(&s
->i2c
[i
]), true, "realized", &err
);
176 error_propagate(errp
, err
);
180 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->i2c
[i
]), 0, i2c_table
[i
].addr
);
181 /* Connect I2C IRQ to PIC */
182 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->i2c
[i
]), 0,
183 qdev_get_gpio_in(DEVICE(&s
->avic
),
187 /* On a real system, the first 16k is a `secure boot rom' */
188 memory_region_init_rom_device(&s
->secure_rom
, NULL
, NULL
, NULL
,
190 FSL_IMX31_SECURE_ROM_SIZE
, &err
);
192 error_propagate(errp
, err
);
195 memory_region_add_subregion(get_system_memory(), FSL_IMX31_SECURE_ROM_ADDR
,
198 /* There is also a 16k ROM */
199 memory_region_init_rom_device(&s
->rom
, NULL
, NULL
, NULL
, "imx31.rom",
200 FSL_IMX31_ROM_SIZE
, &err
);
202 error_propagate(errp
, err
);
205 memory_region_add_subregion(get_system_memory(), FSL_IMX31_ROM_ADDR
,
208 /* initialize internal RAM (16 KB) */
209 memory_region_init_ram(&s
->iram
, NULL
, "imx31.iram", FSL_IMX31_IRAM_SIZE
,
212 error_propagate(errp
, err
);
215 memory_region_add_subregion(get_system_memory(), FSL_IMX31_IRAM_ADDR
,
217 vmstate_register_ram_global(&s
->iram
);
219 /* internal RAM (16 KB) is aliased over 256 MB - 16 KB */
220 memory_region_init_alias(&s
->iram_alias
, NULL
, "imx31.iram_alias",
221 &s
->iram
, 0, FSL_IMX31_IRAM_ALIAS_SIZE
);
222 memory_region_add_subregion(get_system_memory(), FSL_IMX31_IRAM_ALIAS_ADDR
,
226 static void fsl_imx31_class_init(ObjectClass
*oc
, void *data
)
228 DeviceClass
*dc
= DEVICE_CLASS(oc
);
230 dc
->realize
= fsl_imx31_realize
;
233 static const TypeInfo fsl_imx31_type_info
= {
234 .name
= TYPE_FSL_IMX31
,
235 .parent
= TYPE_DEVICE
,
236 .instance_size
= sizeof(FslIMX31State
),
237 .instance_init
= fsl_imx31_init
,
238 .class_init
= fsl_imx31_class_init
,
241 static void fsl_imx31_register_types(void)
243 type_register_static(&fsl_imx31_type_info
);
246 type_init(fsl_imx31_register_types
)