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"
28 #include "hw/arm/fsl-imx25.h"
29 #include "sysemu/sysemu.h"
30 #include "exec/address-spaces.h"
31 #include "hw/qdev-properties.h"
32 #include "chardev/char.h"
34 #define IMX25_ESDHC_CAPABILITIES 0x07e20000
36 static void fsl_imx25_init(Object
*obj
)
38 FslIMX25State
*s
= FSL_IMX25(obj
);
41 object_initialize_child(obj
, "cpu", &s
->cpu
, ARM_CPU_TYPE_NAME("arm926"));
43 object_initialize_child(obj
, "avic", &s
->avic
, TYPE_IMX_AVIC
);
45 object_initialize_child(obj
, "ccm", &s
->ccm
, TYPE_IMX25_CCM
);
47 for (i
= 0; i
< FSL_IMX25_NUM_UARTS
; i
++) {
48 object_initialize_child(obj
, "uart[*]", &s
->uart
[i
], TYPE_IMX_SERIAL
);
51 for (i
= 0; i
< FSL_IMX25_NUM_GPTS
; i
++) {
52 object_initialize_child(obj
, "gpt[*]", &s
->gpt
[i
], TYPE_IMX25_GPT
);
55 for (i
= 0; i
< FSL_IMX25_NUM_EPITS
; i
++) {
56 object_initialize_child(obj
, "epit[*]", &s
->epit
[i
], TYPE_IMX_EPIT
);
59 object_initialize_child(obj
, "fec", &s
->fec
, TYPE_IMX_FEC
);
61 object_initialize_child(obj
, "rngc", &s
->rngc
, TYPE_IMX_RNGC
);
63 for (i
= 0; i
< FSL_IMX25_NUM_I2CS
; i
++) {
64 object_initialize_child(obj
, "i2c[*]", &s
->i2c
[i
], TYPE_IMX_I2C
);
67 for (i
= 0; i
< FSL_IMX25_NUM_GPIOS
; i
++) {
68 object_initialize_child(obj
, "gpio[*]", &s
->gpio
[i
], TYPE_IMX_GPIO
);
71 for (i
= 0; i
< FSL_IMX25_NUM_ESDHCS
; i
++) {
72 object_initialize_child(obj
, "sdhc[*]", &s
->esdhc
[i
], TYPE_IMX_USDHC
);
75 for (i
= 0; i
< FSL_IMX25_NUM_USBS
; i
++) {
76 object_initialize_child(obj
, "usb[*]", &s
->usb
[i
], TYPE_CHIPIDEA
);
79 object_initialize_child(obj
, "wdt", &s
->wdt
, TYPE_IMX2_WDT
);
82 static void fsl_imx25_realize(DeviceState
*dev
, Error
**errp
)
84 FslIMX25State
*s
= FSL_IMX25(dev
);
88 qdev_realize(DEVICE(&s
->cpu
), NULL
, &err
);
90 error_propagate(errp
, err
);
94 sysbus_realize(SYS_BUS_DEVICE(&s
->avic
), &err
);
96 error_propagate(errp
, err
);
99 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->avic
), 0, FSL_IMX25_AVIC_ADDR
);
100 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->avic
), 0,
101 qdev_get_gpio_in(DEVICE(&s
->cpu
), ARM_CPU_IRQ
));
102 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->avic
), 1,
103 qdev_get_gpio_in(DEVICE(&s
->cpu
), ARM_CPU_FIQ
));
105 sysbus_realize(SYS_BUS_DEVICE(&s
->ccm
), &err
);
107 error_propagate(errp
, err
);
110 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->ccm
), 0, FSL_IMX25_CCM_ADDR
);
112 /* Initialize all UARTs */
113 for (i
= 0; i
< FSL_IMX25_NUM_UARTS
; i
++) {
114 static const struct {
117 } serial_table
[FSL_IMX25_NUM_UARTS
] = {
118 { FSL_IMX25_UART1_ADDR
, FSL_IMX25_UART1_IRQ
},
119 { FSL_IMX25_UART2_ADDR
, FSL_IMX25_UART2_IRQ
},
120 { FSL_IMX25_UART3_ADDR
, FSL_IMX25_UART3_IRQ
},
121 { FSL_IMX25_UART4_ADDR
, FSL_IMX25_UART4_IRQ
},
122 { FSL_IMX25_UART5_ADDR
, FSL_IMX25_UART5_IRQ
}
125 qdev_prop_set_chr(DEVICE(&s
->uart
[i
]), "chardev", serial_hd(i
));
127 sysbus_realize(SYS_BUS_DEVICE(&s
->uart
[i
]), &err
);
129 error_propagate(errp
, err
);
132 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->uart
[i
]), 0, serial_table
[i
].addr
);
133 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->uart
[i
]), 0,
134 qdev_get_gpio_in(DEVICE(&s
->avic
),
135 serial_table
[i
].irq
));
138 /* Initialize all GPT timers */
139 for (i
= 0; i
< FSL_IMX25_NUM_GPTS
; i
++) {
140 static const struct {
143 } gpt_table
[FSL_IMX25_NUM_GPTS
] = {
144 { FSL_IMX25_GPT1_ADDR
, FSL_IMX25_GPT1_IRQ
},
145 { FSL_IMX25_GPT2_ADDR
, FSL_IMX25_GPT2_IRQ
},
146 { FSL_IMX25_GPT3_ADDR
, FSL_IMX25_GPT3_IRQ
},
147 { FSL_IMX25_GPT4_ADDR
, FSL_IMX25_GPT4_IRQ
}
150 s
->gpt
[i
].ccm
= IMX_CCM(&s
->ccm
);
152 sysbus_realize(SYS_BUS_DEVICE(&s
->gpt
[i
]), &err
);
154 error_propagate(errp
, err
);
157 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->gpt
[i
]), 0, gpt_table
[i
].addr
);
158 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->gpt
[i
]), 0,
159 qdev_get_gpio_in(DEVICE(&s
->avic
),
163 /* Initialize all EPIT timers */
164 for (i
= 0; i
< FSL_IMX25_NUM_EPITS
; i
++) {
165 static const struct {
168 } epit_table
[FSL_IMX25_NUM_EPITS
] = {
169 { FSL_IMX25_EPIT1_ADDR
, FSL_IMX25_EPIT1_IRQ
},
170 { FSL_IMX25_EPIT2_ADDR
, FSL_IMX25_EPIT2_IRQ
}
173 s
->epit
[i
].ccm
= IMX_CCM(&s
->ccm
);
175 sysbus_realize(SYS_BUS_DEVICE(&s
->epit
[i
]), &err
);
177 error_propagate(errp
, err
);
180 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->epit
[i
]), 0, epit_table
[i
].addr
);
181 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->epit
[i
]), 0,
182 qdev_get_gpio_in(DEVICE(&s
->avic
),
186 qdev_set_nic_properties(DEVICE(&s
->fec
), &nd_table
[0]);
188 sysbus_realize(SYS_BUS_DEVICE(&s
->fec
), &err
);
190 error_propagate(errp
, err
);
193 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->fec
), 0, FSL_IMX25_FEC_ADDR
);
194 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->fec
), 0,
195 qdev_get_gpio_in(DEVICE(&s
->avic
), FSL_IMX25_FEC_IRQ
));
197 sysbus_realize(SYS_BUS_DEVICE(&s
->rngc
), &err
);
199 error_propagate(errp
, err
);
202 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->rngc
), 0, FSL_IMX25_RNGC_ADDR
);
203 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->rngc
), 0,
204 qdev_get_gpio_in(DEVICE(&s
->avic
), FSL_IMX25_RNGC_IRQ
));
206 /* Initialize all I2C */
207 for (i
= 0; i
< FSL_IMX25_NUM_I2CS
; i
++) {
208 static const struct {
211 } i2c_table
[FSL_IMX25_NUM_I2CS
] = {
212 { FSL_IMX25_I2C1_ADDR
, FSL_IMX25_I2C1_IRQ
},
213 { FSL_IMX25_I2C2_ADDR
, FSL_IMX25_I2C2_IRQ
},
214 { FSL_IMX25_I2C3_ADDR
, FSL_IMX25_I2C3_IRQ
}
217 sysbus_realize(SYS_BUS_DEVICE(&s
->i2c
[i
]), &err
);
219 error_propagate(errp
, err
);
222 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->i2c
[i
]), 0, i2c_table
[i
].addr
);
223 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->i2c
[i
]), 0,
224 qdev_get_gpio_in(DEVICE(&s
->avic
),
228 /* Initialize all GPIOs */
229 for (i
= 0; i
< FSL_IMX25_NUM_GPIOS
; i
++) {
230 static const struct {
233 } gpio_table
[FSL_IMX25_NUM_GPIOS
] = {
234 { FSL_IMX25_GPIO1_ADDR
, FSL_IMX25_GPIO1_IRQ
},
235 { FSL_IMX25_GPIO2_ADDR
, FSL_IMX25_GPIO2_IRQ
},
236 { FSL_IMX25_GPIO3_ADDR
, FSL_IMX25_GPIO3_IRQ
},
237 { FSL_IMX25_GPIO4_ADDR
, FSL_IMX25_GPIO4_IRQ
}
240 sysbus_realize(SYS_BUS_DEVICE(&s
->gpio
[i
]), &err
);
242 error_propagate(errp
, err
);
245 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->gpio
[i
]), 0, gpio_table
[i
].addr
);
246 /* Connect GPIO IRQ to PIC */
247 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->gpio
[i
]), 0,
248 qdev_get_gpio_in(DEVICE(&s
->avic
),
252 /* Initialize all SDHC */
253 for (i
= 0; i
< FSL_IMX25_NUM_ESDHCS
; i
++) {
254 static const struct {
257 } esdhc_table
[FSL_IMX25_NUM_ESDHCS
] = {
258 { FSL_IMX25_ESDHC1_ADDR
, FSL_IMX25_ESDHC1_IRQ
},
259 { FSL_IMX25_ESDHC2_ADDR
, FSL_IMX25_ESDHC2_IRQ
},
262 object_property_set_uint(OBJECT(&s
->esdhc
[i
]), 2, "sd-spec-version",
264 object_property_set_uint(OBJECT(&s
->esdhc
[i
]), IMX25_ESDHC_CAPABILITIES
,
267 object_property_set_uint(OBJECT(&s
->esdhc
[i
]), SDHCI_VENDOR_IMX
,
270 sysbus_realize(SYS_BUS_DEVICE(&s
->esdhc
[i
]), &err
);
272 error_propagate(errp
, err
);
275 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->esdhc
[i
]), 0, esdhc_table
[i
].addr
);
276 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->esdhc
[i
]), 0,
277 qdev_get_gpio_in(DEVICE(&s
->avic
),
278 esdhc_table
[i
].irq
));
282 for (i
= 0; i
< FSL_IMX25_NUM_USBS
; i
++) {
283 static const struct {
286 } usb_table
[FSL_IMX25_NUM_USBS
] = {
287 { FSL_IMX25_USB1_ADDR
, FSL_IMX25_USB1_IRQ
},
288 { FSL_IMX25_USB2_ADDR
, FSL_IMX25_USB2_IRQ
},
291 sysbus_realize(SYS_BUS_DEVICE(&s
->usb
[i
]), &error_abort
);
292 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->usb
[i
]), 0, usb_table
[i
].addr
);
293 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->usb
[i
]), 0,
294 qdev_get_gpio_in(DEVICE(&s
->avic
),
299 object_property_set_bool(OBJECT(&s
->wdt
), true, "pretimeout-support",
301 sysbus_realize(SYS_BUS_DEVICE(&s
->wdt
), &error_abort
);
302 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->wdt
), 0, FSL_IMX25_WDT_ADDR
);
303 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->wdt
), 0,
304 qdev_get_gpio_in(DEVICE(&s
->avic
),
307 /* initialize 2 x 16 KB ROM */
308 memory_region_init_rom(&s
->rom
[0], OBJECT(dev
), "imx25.rom0",
309 FSL_IMX25_ROM0_SIZE
, &err
);
311 error_propagate(errp
, err
);
314 memory_region_add_subregion(get_system_memory(), FSL_IMX25_ROM0_ADDR
,
316 memory_region_init_rom(&s
->rom
[1], OBJECT(dev
), "imx25.rom1",
317 FSL_IMX25_ROM1_SIZE
, &err
);
319 error_propagate(errp
, err
);
322 memory_region_add_subregion(get_system_memory(), FSL_IMX25_ROM1_ADDR
,
325 /* initialize internal RAM (128 KB) */
326 memory_region_init_ram(&s
->iram
, NULL
, "imx25.iram", FSL_IMX25_IRAM_SIZE
,
329 error_propagate(errp
, err
);
332 memory_region_add_subregion(get_system_memory(), FSL_IMX25_IRAM_ADDR
,
335 /* internal RAM (128 KB) is aliased over 128 MB - 128 KB */
336 memory_region_init_alias(&s
->iram_alias
, OBJECT(dev
), "imx25.iram_alias",
337 &s
->iram
, 0, FSL_IMX25_IRAM_ALIAS_SIZE
);
338 memory_region_add_subregion(get_system_memory(), FSL_IMX25_IRAM_ALIAS_ADDR
,
342 static void fsl_imx25_class_init(ObjectClass
*oc
, void *data
)
344 DeviceClass
*dc
= DEVICE_CLASS(oc
);
346 dc
->realize
= fsl_imx25_realize
;
347 dc
->desc
= "i.MX25 SOC";
349 * Reason: uses serial_hds in realize and the imx25 board does not
350 * support multiple CPUs
352 dc
->user_creatable
= false;
355 static const TypeInfo fsl_imx25_type_info
= {
356 .name
= TYPE_FSL_IMX25
,
357 .parent
= TYPE_DEVICE
,
358 .instance_size
= sizeof(FslIMX25State
),
359 .instance_init
= fsl_imx25_init
,
360 .class_init
= fsl_imx25_class_init
,
363 static void fsl_imx25_register_types(void)
365 type_register_static(&fsl_imx25_type_info
);
368 type_init(fsl_imx25_register_types
)