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_IMX25_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
) {
127 snprintf(label
, sizeof(label
), "imx31.uart%d", i
);
128 chr
= qemu_chr_new(label
, "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]);
195 object_property_set_bool(OBJECT(&s
->fec
), true, "realized", &err
);
197 error_propagate(errp
, err
);
200 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->fec
), 0, FSL_IMX25_FEC_ADDR
);
201 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->fec
), 0,
202 qdev_get_gpio_in(DEVICE(&s
->avic
), FSL_IMX25_FEC_IRQ
));
205 /* Initialize all I2C */
206 for (i
= 0; i
< FSL_IMX25_NUM_I2CS
; i
++) {
207 static const struct {
210 } i2c_table
[FSL_IMX25_NUM_I2CS
] = {
211 { FSL_IMX25_I2C1_ADDR
, FSL_IMX25_I2C1_IRQ
},
212 { FSL_IMX25_I2C2_ADDR
, FSL_IMX25_I2C2_IRQ
},
213 { FSL_IMX25_I2C3_ADDR
, FSL_IMX25_I2C3_IRQ
}
216 object_property_set_bool(OBJECT(&s
->i2c
[i
]), true, "realized", &err
);
218 error_propagate(errp
, err
);
221 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->i2c
[i
]), 0, i2c_table
[i
].addr
);
222 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->i2c
[i
]), 0,
223 qdev_get_gpio_in(DEVICE(&s
->avic
),
227 /* Initialize all GPIOs */
228 for (i
= 0; i
< FSL_IMX25_NUM_GPIOS
; i
++) {
229 static const struct {
232 } gpio_table
[FSL_IMX25_NUM_GPIOS
] = {
233 { FSL_IMX25_GPIO1_ADDR
, FSL_IMX25_GPIO1_IRQ
},
234 { FSL_IMX25_GPIO2_ADDR
, FSL_IMX25_GPIO2_IRQ
},
235 { FSL_IMX25_GPIO3_ADDR
, FSL_IMX25_GPIO3_IRQ
},
236 { FSL_IMX25_GPIO4_ADDR
, FSL_IMX25_GPIO4_IRQ
}
239 object_property_set_bool(OBJECT(&s
->gpio
[i
]), true, "realized", &err
);
241 error_propagate(errp
, err
);
244 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->gpio
[i
]), 0, gpio_table
[i
].addr
);
245 /* Connect GPIO IRQ to PIC */
246 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->gpio
[i
]), 0,
247 qdev_get_gpio_in(DEVICE(&s
->avic
),
251 /* initialize 2 x 16 KB ROM */
252 memory_region_init_rom(&s
->rom
[0], NULL
,
253 "imx25.rom0", FSL_IMX25_ROM0_SIZE
, &err
);
255 error_propagate(errp
, err
);
258 memory_region_add_subregion(get_system_memory(), FSL_IMX25_ROM0_ADDR
,
260 memory_region_init_rom(&s
->rom
[1], NULL
,
261 "imx25.rom1", FSL_IMX25_ROM1_SIZE
, &err
);
263 error_propagate(errp
, err
);
266 memory_region_add_subregion(get_system_memory(), FSL_IMX25_ROM1_ADDR
,
269 /* initialize internal RAM (128 KB) */
270 memory_region_init_ram(&s
->iram
, NULL
, "imx25.iram", FSL_IMX25_IRAM_SIZE
,
273 error_propagate(errp
, err
);
276 memory_region_add_subregion(get_system_memory(), FSL_IMX25_IRAM_ADDR
,
278 vmstate_register_ram_global(&s
->iram
);
280 /* internal RAM (128 KB) is aliased over 128 MB - 128 KB */
281 memory_region_init_alias(&s
->iram_alias
, NULL
, "imx25.iram_alias",
282 &s
->iram
, 0, FSL_IMX25_IRAM_ALIAS_SIZE
);
283 memory_region_add_subregion(get_system_memory(), FSL_IMX25_IRAM_ALIAS_ADDR
,
287 static void fsl_imx25_class_init(ObjectClass
*oc
, void *data
)
289 DeviceClass
*dc
= DEVICE_CLASS(oc
);
291 dc
->realize
= fsl_imx25_realize
;
294 * Reason: creates an ARM CPU, thus use after free(), see
295 * arm_cpu_class_init()
297 dc
->cannot_destroy_with_object_finalize_yet
= true;
298 dc
->desc
= "i.MX25 SOC";
301 static const TypeInfo fsl_imx25_type_info
= {
302 .name
= TYPE_FSL_IMX25
,
303 .parent
= TYPE_DEVICE
,
304 .instance_size
= sizeof(FslIMX25State
),
305 .instance_init
= fsl_imx25_init
,
306 .class_init
= fsl_imx25_class_init
,
309 static void fsl_imx25_register_types(void)
311 type_register_static(&fsl_imx25_type_info
);
314 type_init(fsl_imx25_register_types
)