2 * Copyright (c) 2013 Jean-Christophe Dubois <jcd@tribudubois.net>
4 * i.MX25 SOC emulation.
6 * Based on hw/arm/xlnx-zynqmp.c
8 * Copyright (C) 2015 Xilinx Inc
9 * Written by Peter Crosthwaite <peter.crosthwaite@xilinx.com>
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, see <http://www.gnu.org/licenses/>.
25 #include "qemu/osdep.h"
26 #include "qapi/error.h"
27 #include "qemu-common.h"
29 #include "hw/arm/fsl-imx25.h"
30 #include "sysemu/sysemu.h"
31 #include "exec/address-spaces.h"
32 #include "hw/boards.h"
33 #include "sysemu/char.h"
35 static void fsl_imx25_init(Object
*obj
)
37 FslIMX25State
*s
= FSL_IMX25(obj
);
40 object_initialize(&s
->cpu
, sizeof(s
->cpu
), "arm926-" TYPE_ARM_CPU
);
42 object_initialize(&s
->avic
, sizeof(s
->avic
), TYPE_IMX_AVIC
);
43 qdev_set_parent_bus(DEVICE(&s
->avic
), sysbus_get_default());
45 object_initialize(&s
->ccm
, sizeof(s
->ccm
), TYPE_IMX25_CCM
);
46 qdev_set_parent_bus(DEVICE(&s
->ccm
), sysbus_get_default());
48 for (i
= 0; i
< FSL_IMX25_NUM_UARTS
; i
++) {
49 object_initialize(&s
->uart
[i
], sizeof(s
->uart
[i
]), TYPE_IMX_SERIAL
);
50 qdev_set_parent_bus(DEVICE(&s
->uart
[i
]), sysbus_get_default());
53 for (i
= 0; i
< FSL_IMX25_NUM_GPTS
; i
++) {
54 object_initialize(&s
->gpt
[i
], sizeof(s
->gpt
[i
]), TYPE_IMX_GPT
);
55 qdev_set_parent_bus(DEVICE(&s
->gpt
[i
]), sysbus_get_default());
58 for (i
= 0; i
< FSL_IMX25_NUM_EPITS
; i
++) {
59 object_initialize(&s
->epit
[i
], sizeof(s
->epit
[i
]), TYPE_IMX_EPIT
);
60 qdev_set_parent_bus(DEVICE(&s
->epit
[i
]), sysbus_get_default());
63 object_initialize(&s
->fec
, sizeof(s
->fec
), TYPE_IMX_FEC
);
64 qdev_set_parent_bus(DEVICE(&s
->fec
), sysbus_get_default());
66 for (i
= 0; i
< FSL_IMX25_NUM_I2CS
; i
++) {
67 object_initialize(&s
->i2c
[i
], sizeof(s
->i2c
[i
]), TYPE_IMX_I2C
);
68 qdev_set_parent_bus(DEVICE(&s
->i2c
[i
]), sysbus_get_default());
71 for (i
= 0; i
< FSL_IMX25_NUM_GPIOS
; i
++) {
72 object_initialize(&s
->gpio
[i
], sizeof(s
->gpio
[i
]), TYPE_IMX_GPIO
);
73 qdev_set_parent_bus(DEVICE(&s
->gpio
[i
]), sysbus_get_default());
77 static void fsl_imx25_realize(DeviceState
*dev
, Error
**errp
)
79 FslIMX25State
*s
= FSL_IMX25(dev
);
83 object_property_set_bool(OBJECT(&s
->cpu
), true, "realized", &err
);
85 error_propagate(errp
, err
);
89 object_property_set_bool(OBJECT(&s
->avic
), true, "realized", &err
);
91 error_propagate(errp
, err
);
94 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->avic
), 0, FSL_IMX25_AVIC_ADDR
);
95 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->avic
), 0,
96 qdev_get_gpio_in(DEVICE(&s
->cpu
), ARM_CPU_IRQ
));
97 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->avic
), 1,
98 qdev_get_gpio_in(DEVICE(&s
->cpu
), ARM_CPU_FIQ
));
100 object_property_set_bool(OBJECT(&s
->ccm
), true, "realized", &err
);
102 error_propagate(errp
, err
);
105 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->ccm
), 0, FSL_IMX25_CCM_ADDR
);
107 /* Initialize all UARTs */
108 for (i
= 0; i
< FSL_IMX25_NUM_UARTS
; i
++) {
109 static const struct {
112 } serial_table
[FSL_IMX25_NUM_UARTS
] = {
113 { FSL_IMX25_UART1_ADDR
, FSL_IMX25_UART1_IRQ
},
114 { FSL_IMX25_UART2_ADDR
, FSL_IMX25_UART2_IRQ
},
115 { FSL_IMX25_UART3_ADDR
, FSL_IMX25_UART3_IRQ
},
116 { FSL_IMX25_UART4_ADDR
, FSL_IMX25_UART4_IRQ
},
117 { FSL_IMX25_UART5_ADDR
, FSL_IMX25_UART5_IRQ
}
120 if (i
< MAX_SERIAL_PORTS
) {
121 CharDriverState
*chr
;
127 snprintf(label
, sizeof(label
), "imx31.uart%d", i
);
128 chr
= qemu_chr_new(label
, "null", NULL
);
131 qdev_prop_set_chr(DEVICE(&s
->uart
[i
]), "chardev", chr
);
134 object_property_set_bool(OBJECT(&s
->uart
[i
]), true, "realized", &err
);
136 error_propagate(errp
, err
);
139 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->uart
[i
]), 0, serial_table
[i
].addr
);
140 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->uart
[i
]), 0,
141 qdev_get_gpio_in(DEVICE(&s
->avic
),
142 serial_table
[i
].irq
));
145 /* Initialize all GPT timers */
146 for (i
= 0; i
< FSL_IMX25_NUM_GPTS
; i
++) {
147 static const struct {
150 } gpt_table
[FSL_IMX25_NUM_GPTS
] = {
151 { FSL_IMX25_GPT1_ADDR
, FSL_IMX25_GPT1_IRQ
},
152 { FSL_IMX25_GPT2_ADDR
, FSL_IMX25_GPT2_IRQ
},
153 { FSL_IMX25_GPT3_ADDR
, FSL_IMX25_GPT3_IRQ
},
154 { FSL_IMX25_GPT4_ADDR
, FSL_IMX25_GPT4_IRQ
}
157 s
->gpt
[i
].ccm
= IMX_CCM(&s
->ccm
);
159 object_property_set_bool(OBJECT(&s
->gpt
[i
]), true, "realized", &err
);
161 error_propagate(errp
, err
);
164 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->gpt
[i
]), 0, gpt_table
[i
].addr
);
165 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->gpt
[i
]), 0,
166 qdev_get_gpio_in(DEVICE(&s
->avic
),
170 /* Initialize all EPIT timers */
171 for (i
= 0; i
< FSL_IMX25_NUM_EPITS
; i
++) {
172 static const struct {
175 } epit_table
[FSL_IMX25_NUM_EPITS
] = {
176 { FSL_IMX25_EPIT1_ADDR
, FSL_IMX25_EPIT1_IRQ
},
177 { FSL_IMX25_EPIT2_ADDR
, FSL_IMX25_EPIT2_IRQ
}
180 s
->epit
[i
].ccm
= IMX_CCM(&s
->ccm
);
182 object_property_set_bool(OBJECT(&s
->epit
[i
]), true, "realized", &err
);
184 error_propagate(errp
, err
);
187 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->epit
[i
]), 0, epit_table
[i
].addr
);
188 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->epit
[i
]), 0,
189 qdev_get_gpio_in(DEVICE(&s
->avic
),
193 qdev_set_nic_properties(DEVICE(&s
->fec
), &nd_table
[0]);
194 object_property_set_bool(OBJECT(&s
->fec
), true, "realized", &err
);
196 error_propagate(errp
, err
);
199 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->fec
), 0, FSL_IMX25_FEC_ADDR
);
200 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->fec
), 0,
201 qdev_get_gpio_in(DEVICE(&s
->avic
), FSL_IMX25_FEC_IRQ
));
204 /* Initialize all I2C */
205 for (i
= 0; i
< FSL_IMX25_NUM_I2CS
; i
++) {
206 static const struct {
209 } i2c_table
[FSL_IMX25_NUM_I2CS
] = {
210 { FSL_IMX25_I2C1_ADDR
, FSL_IMX25_I2C1_IRQ
},
211 { FSL_IMX25_I2C2_ADDR
, FSL_IMX25_I2C2_IRQ
},
212 { FSL_IMX25_I2C3_ADDR
, FSL_IMX25_I2C3_IRQ
}
215 object_property_set_bool(OBJECT(&s
->i2c
[i
]), true, "realized", &err
);
217 error_propagate(errp
, err
);
220 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->i2c
[i
]), 0, i2c_table
[i
].addr
);
221 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->i2c
[i
]), 0,
222 qdev_get_gpio_in(DEVICE(&s
->avic
),
226 /* Initialize all GPIOs */
227 for (i
= 0; i
< FSL_IMX25_NUM_GPIOS
; i
++) {
228 static const struct {
231 } gpio_table
[FSL_IMX25_NUM_GPIOS
] = {
232 { FSL_IMX25_GPIO1_ADDR
, FSL_IMX25_GPIO1_IRQ
},
233 { FSL_IMX25_GPIO2_ADDR
, FSL_IMX25_GPIO2_IRQ
},
234 { FSL_IMX25_GPIO3_ADDR
, FSL_IMX25_GPIO3_IRQ
},
235 { FSL_IMX25_GPIO4_ADDR
, FSL_IMX25_GPIO4_IRQ
}
238 object_property_set_bool(OBJECT(&s
->gpio
[i
]), true, "realized", &err
);
240 error_propagate(errp
, err
);
243 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->gpio
[i
]), 0, gpio_table
[i
].addr
);
244 /* Connect GPIO IRQ to PIC */
245 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->gpio
[i
]), 0,
246 qdev_get_gpio_in(DEVICE(&s
->avic
),
250 /* initialize 2 x 16 KB ROM */
251 memory_region_init_rom_device(&s
->rom
[0], NULL
, NULL
, NULL
,
252 "imx25.rom0", FSL_IMX25_ROM0_SIZE
, &err
);
254 error_propagate(errp
, err
);
257 memory_region_add_subregion(get_system_memory(), FSL_IMX25_ROM0_ADDR
,
259 memory_region_init_rom_device(&s
->rom
[1], NULL
, NULL
, NULL
,
260 "imx25.rom1", FSL_IMX25_ROM1_SIZE
, &err
);
262 error_propagate(errp
, err
);
265 memory_region_add_subregion(get_system_memory(), FSL_IMX25_ROM1_ADDR
,
268 /* initialize internal RAM (128 KB) */
269 memory_region_init_ram(&s
->iram
, NULL
, "imx25.iram", FSL_IMX25_IRAM_SIZE
,
272 error_propagate(errp
, err
);
275 memory_region_add_subregion(get_system_memory(), FSL_IMX25_IRAM_ADDR
,
277 vmstate_register_ram_global(&s
->iram
);
279 /* internal RAM (128 KB) is aliased over 128 MB - 128 KB */
280 memory_region_init_alias(&s
->iram_alias
, NULL
, "imx25.iram_alias",
281 &s
->iram
, 0, FSL_IMX25_IRAM_ALIAS_SIZE
);
282 memory_region_add_subregion(get_system_memory(), FSL_IMX25_IRAM_ALIAS_ADDR
,
286 static void fsl_imx25_class_init(ObjectClass
*oc
, void *data
)
288 DeviceClass
*dc
= DEVICE_CLASS(oc
);
290 dc
->realize
= fsl_imx25_realize
;
293 * Reason: creates an ARM CPU, thus use after free(), see
294 * arm_cpu_class_init()
296 dc
->cannot_destroy_with_object_finalize_yet
= true;
297 dc
->desc
= "i.MX25 SOC";
300 static const TypeInfo fsl_imx25_type_info
= {
301 .name
= TYPE_FSL_IMX25
,
302 .parent
= TYPE_DEVICE
,
303 .instance_size
= sizeof(FslIMX25State
),
304 .instance_init
= fsl_imx25_init
,
305 .class_init
= fsl_imx25_class_init
,
308 static void fsl_imx25_register_types(void)
310 type_register_static(&fsl_imx25_type_info
);
313 type_init(fsl_imx25_register_types
)