2 * Copyright (c) 2015 Jean-Christophe Dubois <jcd@tribudubois.net>
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 "hw/arm/fsl-imx6.h"
25 #include "sysemu/sysemu.h"
26 #include "chardev/char.h"
27 #include "qemu/error-report.h"
28 #include "qemu/module.h"
30 #define IMX6_ESDHC_CAPABILITIES 0x057834b4
34 static void fsl_imx6_init(Object
*obj
)
36 FslIMX6State
*s
= FSL_IMX6(obj
);
40 for (i
= 0; i
< MIN(smp_cpus
, FSL_IMX6_NUM_CPUS
); i
++) {
41 snprintf(name
, NAME_SIZE
, "cpu%d", i
);
42 object_initialize_child(obj
, name
, &s
->cpu
[i
], sizeof(s
->cpu
[i
]),
43 "cortex-a9-" TYPE_ARM_CPU
, &error_abort
, NULL
);
46 sysbus_init_child_obj(obj
, "a9mpcore", &s
->a9mpcore
, sizeof(s
->a9mpcore
),
49 sysbus_init_child_obj(obj
, "ccm", &s
->ccm
, sizeof(s
->ccm
), TYPE_IMX6_CCM
);
51 sysbus_init_child_obj(obj
, "src", &s
->src
, sizeof(s
->src
), TYPE_IMX6_SRC
);
53 for (i
= 0; i
< FSL_IMX6_NUM_UARTS
; i
++) {
54 snprintf(name
, NAME_SIZE
, "uart%d", i
+ 1);
55 sysbus_init_child_obj(obj
, name
, &s
->uart
[i
], sizeof(s
->uart
[i
]),
59 sysbus_init_child_obj(obj
, "gpt", &s
->gpt
, sizeof(s
->gpt
), TYPE_IMX6_GPT
);
61 for (i
= 0; i
< FSL_IMX6_NUM_EPITS
; i
++) {
62 snprintf(name
, NAME_SIZE
, "epit%d", i
+ 1);
63 sysbus_init_child_obj(obj
, name
, &s
->epit
[i
], sizeof(s
->epit
[i
]),
67 for (i
= 0; i
< FSL_IMX6_NUM_I2CS
; i
++) {
68 snprintf(name
, NAME_SIZE
, "i2c%d", i
+ 1);
69 sysbus_init_child_obj(obj
, name
, &s
->i2c
[i
], sizeof(s
->i2c
[i
]),
73 for (i
= 0; i
< FSL_IMX6_NUM_GPIOS
; i
++) {
74 snprintf(name
, NAME_SIZE
, "gpio%d", i
+ 1);
75 sysbus_init_child_obj(obj
, name
, &s
->gpio
[i
], sizeof(s
->gpio
[i
]),
79 for (i
= 0; i
< FSL_IMX6_NUM_ESDHCS
; i
++) {
80 snprintf(name
, NAME_SIZE
, "sdhc%d", i
+ 1);
81 sysbus_init_child_obj(obj
, name
, &s
->esdhc
[i
], sizeof(s
->esdhc
[i
]),
85 for (i
= 0; i
< FSL_IMX6_NUM_ECSPIS
; i
++) {
86 snprintf(name
, NAME_SIZE
, "spi%d", i
+ 1);
87 sysbus_init_child_obj(obj
, name
, &s
->spi
[i
], sizeof(s
->spi
[i
]),
91 sysbus_init_child_obj(obj
, "eth", &s
->eth
, sizeof(s
->eth
), TYPE_IMX_ENET
);
94 static void fsl_imx6_realize(DeviceState
*dev
, Error
**errp
)
96 FslIMX6State
*s
= FSL_IMX6(dev
);
100 if (smp_cpus
> FSL_IMX6_NUM_CPUS
) {
101 error_setg(errp
, "%s: Only %d CPUs are supported (%d requested)",
102 TYPE_FSL_IMX6
, FSL_IMX6_NUM_CPUS
, smp_cpus
);
106 for (i
= 0; i
< smp_cpus
; i
++) {
108 /* On uniprocessor, the CBAR is set to 0 */
110 object_property_set_int(OBJECT(&s
->cpu
[i
]), FSL_IMX6_A9MPCORE_ADDR
,
111 "reset-cbar", &error_abort
);
114 /* All CPU but CPU 0 start in power off mode */
116 object_property_set_bool(OBJECT(&s
->cpu
[i
]), true,
117 "start-powered-off", &error_abort
);
120 object_property_set_bool(OBJECT(&s
->cpu
[i
]), true, "realized", &err
);
122 error_propagate(errp
, err
);
127 object_property_set_int(OBJECT(&s
->a9mpcore
), smp_cpus
, "num-cpu",
130 object_property_set_int(OBJECT(&s
->a9mpcore
),
131 FSL_IMX6_MAX_IRQ
+ GIC_INTERNAL
, "num-irq",
134 object_property_set_bool(OBJECT(&s
->a9mpcore
), true, "realized", &err
);
136 error_propagate(errp
, err
);
139 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->a9mpcore
), 0, FSL_IMX6_A9MPCORE_ADDR
);
141 for (i
= 0; i
< smp_cpus
; i
++) {
142 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->a9mpcore
), i
,
143 qdev_get_gpio_in(DEVICE(&s
->cpu
[i
]), ARM_CPU_IRQ
));
144 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->a9mpcore
), i
+ smp_cpus
,
145 qdev_get_gpio_in(DEVICE(&s
->cpu
[i
]), ARM_CPU_FIQ
));
148 object_property_set_bool(OBJECT(&s
->ccm
), true, "realized", &err
);
150 error_propagate(errp
, err
);
153 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->ccm
), 0, FSL_IMX6_CCM_ADDR
);
155 object_property_set_bool(OBJECT(&s
->src
), true, "realized", &err
);
157 error_propagate(errp
, err
);
160 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->src
), 0, FSL_IMX6_SRC_ADDR
);
162 /* Initialize all UARTs */
163 for (i
= 0; i
< FSL_IMX6_NUM_UARTS
; i
++) {
164 static const struct {
167 } serial_table
[FSL_IMX6_NUM_UARTS
] = {
168 { FSL_IMX6_UART1_ADDR
, FSL_IMX6_UART1_IRQ
},
169 { FSL_IMX6_UART2_ADDR
, FSL_IMX6_UART2_IRQ
},
170 { FSL_IMX6_UART3_ADDR
, FSL_IMX6_UART3_IRQ
},
171 { FSL_IMX6_UART4_ADDR
, FSL_IMX6_UART4_IRQ
},
172 { FSL_IMX6_UART5_ADDR
, FSL_IMX6_UART5_IRQ
},
175 qdev_prop_set_chr(DEVICE(&s
->uart
[i
]), "chardev", serial_hd(i
));
177 object_property_set_bool(OBJECT(&s
->uart
[i
]), true, "realized", &err
);
179 error_propagate(errp
, err
);
183 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->uart
[i
]), 0, serial_table
[i
].addr
);
184 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->uart
[i
]), 0,
185 qdev_get_gpio_in(DEVICE(&s
->a9mpcore
),
186 serial_table
[i
].irq
));
189 s
->gpt
.ccm
= IMX_CCM(&s
->ccm
);
191 object_property_set_bool(OBJECT(&s
->gpt
), true, "realized", &err
);
193 error_propagate(errp
, err
);
197 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->gpt
), 0, FSL_IMX6_GPT_ADDR
);
198 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->gpt
), 0,
199 qdev_get_gpio_in(DEVICE(&s
->a9mpcore
),
202 /* Initialize all EPIT timers */
203 for (i
= 0; i
< FSL_IMX6_NUM_EPITS
; i
++) {
204 static const struct {
207 } epit_table
[FSL_IMX6_NUM_EPITS
] = {
208 { FSL_IMX6_EPIT1_ADDR
, FSL_IMX6_EPIT1_IRQ
},
209 { FSL_IMX6_EPIT2_ADDR
, FSL_IMX6_EPIT2_IRQ
},
212 s
->epit
[i
].ccm
= IMX_CCM(&s
->ccm
);
214 object_property_set_bool(OBJECT(&s
->epit
[i
]), true, "realized", &err
);
216 error_propagate(errp
, err
);
220 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->epit
[i
]), 0, epit_table
[i
].addr
);
221 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->epit
[i
]), 0,
222 qdev_get_gpio_in(DEVICE(&s
->a9mpcore
),
226 /* Initialize all I2C */
227 for (i
= 0; i
< FSL_IMX6_NUM_I2CS
; i
++) {
228 static const struct {
231 } i2c_table
[FSL_IMX6_NUM_I2CS
] = {
232 { FSL_IMX6_I2C1_ADDR
, FSL_IMX6_I2C1_IRQ
},
233 { FSL_IMX6_I2C2_ADDR
, FSL_IMX6_I2C2_IRQ
},
234 { FSL_IMX6_I2C3_ADDR
, FSL_IMX6_I2C3_IRQ
}
237 object_property_set_bool(OBJECT(&s
->i2c
[i
]), true, "realized", &err
);
239 error_propagate(errp
, err
);
243 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->i2c
[i
]), 0, i2c_table
[i
].addr
);
244 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->i2c
[i
]), 0,
245 qdev_get_gpio_in(DEVICE(&s
->a9mpcore
),
249 /* Initialize all GPIOs */
250 for (i
= 0; i
< FSL_IMX6_NUM_GPIOS
; i
++) {
251 static const struct {
253 unsigned int irq_low
;
254 unsigned int irq_high
;
255 } gpio_table
[FSL_IMX6_NUM_GPIOS
] = {
258 FSL_IMX6_GPIO1_LOW_IRQ
,
259 FSL_IMX6_GPIO1_HIGH_IRQ
263 FSL_IMX6_GPIO2_LOW_IRQ
,
264 FSL_IMX6_GPIO2_HIGH_IRQ
268 FSL_IMX6_GPIO3_LOW_IRQ
,
269 FSL_IMX6_GPIO3_HIGH_IRQ
273 FSL_IMX6_GPIO4_LOW_IRQ
,
274 FSL_IMX6_GPIO4_HIGH_IRQ
278 FSL_IMX6_GPIO5_LOW_IRQ
,
279 FSL_IMX6_GPIO5_HIGH_IRQ
283 FSL_IMX6_GPIO6_LOW_IRQ
,
284 FSL_IMX6_GPIO6_HIGH_IRQ
288 FSL_IMX6_GPIO7_LOW_IRQ
,
289 FSL_IMX6_GPIO7_HIGH_IRQ
293 object_property_set_bool(OBJECT(&s
->gpio
[i
]), true, "has-edge-sel",
295 object_property_set_bool(OBJECT(&s
->gpio
[i
]), true, "has-upper-pin-irq",
297 object_property_set_bool(OBJECT(&s
->gpio
[i
]), true, "realized", &err
);
299 error_propagate(errp
, err
);
303 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->gpio
[i
]), 0, gpio_table
[i
].addr
);
304 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->gpio
[i
]), 0,
305 qdev_get_gpio_in(DEVICE(&s
->a9mpcore
),
306 gpio_table
[i
].irq_low
));
307 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->gpio
[i
]), 1,
308 qdev_get_gpio_in(DEVICE(&s
->a9mpcore
),
309 gpio_table
[i
].irq_high
));
312 /* Initialize all SDHC */
313 for (i
= 0; i
< FSL_IMX6_NUM_ESDHCS
; i
++) {
314 static const struct {
317 } esdhc_table
[FSL_IMX6_NUM_ESDHCS
] = {
318 { FSL_IMX6_uSDHC1_ADDR
, FSL_IMX6_uSDHC1_IRQ
},
319 { FSL_IMX6_uSDHC2_ADDR
, FSL_IMX6_uSDHC2_IRQ
},
320 { FSL_IMX6_uSDHC3_ADDR
, FSL_IMX6_uSDHC3_IRQ
},
321 { FSL_IMX6_uSDHC4_ADDR
, FSL_IMX6_uSDHC4_IRQ
},
324 /* UHS-I SDIO3.0 SDR104 1.8V ADMA */
325 object_property_set_uint(OBJECT(&s
->esdhc
[i
]), 3, "sd-spec-version",
327 object_property_set_uint(OBJECT(&s
->esdhc
[i
]), IMX6_ESDHC_CAPABILITIES
,
329 object_property_set_bool(OBJECT(&s
->esdhc
[i
]), true, "realized", &err
);
331 error_propagate(errp
, err
);
334 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->esdhc
[i
]), 0, esdhc_table
[i
].addr
);
335 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->esdhc
[i
]), 0,
336 qdev_get_gpio_in(DEVICE(&s
->a9mpcore
),
337 esdhc_table
[i
].irq
));
340 /* Initialize all ECSPI */
341 for (i
= 0; i
< FSL_IMX6_NUM_ECSPIS
; i
++) {
342 static const struct {
345 } spi_table
[FSL_IMX6_NUM_ECSPIS
] = {
346 { FSL_IMX6_eCSPI1_ADDR
, FSL_IMX6_ECSPI1_IRQ
},
347 { FSL_IMX6_eCSPI2_ADDR
, FSL_IMX6_ECSPI2_IRQ
},
348 { FSL_IMX6_eCSPI3_ADDR
, FSL_IMX6_ECSPI3_IRQ
},
349 { FSL_IMX6_eCSPI4_ADDR
, FSL_IMX6_ECSPI4_IRQ
},
350 { FSL_IMX6_eCSPI5_ADDR
, FSL_IMX6_ECSPI5_IRQ
},
353 /* Initialize the SPI */
354 object_property_set_bool(OBJECT(&s
->spi
[i
]), true, "realized", &err
);
356 error_propagate(errp
, err
);
360 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->spi
[i
]), 0, spi_table
[i
].addr
);
361 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->spi
[i
]), 0,
362 qdev_get_gpio_in(DEVICE(&s
->a9mpcore
),
366 qdev_set_nic_properties(DEVICE(&s
->eth
), &nd_table
[0]);
367 object_property_set_bool(OBJECT(&s
->eth
), true, "realized", &err
);
369 error_propagate(errp
, err
);
372 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->eth
), 0, FSL_IMX6_ENET_ADDR
);
373 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->eth
), 0,
374 qdev_get_gpio_in(DEVICE(&s
->a9mpcore
),
375 FSL_IMX6_ENET_MAC_IRQ
));
376 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->eth
), 1,
377 qdev_get_gpio_in(DEVICE(&s
->a9mpcore
),
378 FSL_IMX6_ENET_MAC_1588_IRQ
));
381 memory_region_init_rom(&s
->rom
, NULL
, "imx6.rom",
382 FSL_IMX6_ROM_SIZE
, &err
);
384 error_propagate(errp
, err
);
387 memory_region_add_subregion(get_system_memory(), FSL_IMX6_ROM_ADDR
,
391 memory_region_init_rom(&s
->caam
, NULL
, "imx6.caam",
392 FSL_IMX6_CAAM_MEM_SIZE
, &err
);
394 error_propagate(errp
, err
);
397 memory_region_add_subregion(get_system_memory(), FSL_IMX6_CAAM_MEM_ADDR
,
401 memory_region_init_ram(&s
->ocram
, NULL
, "imx6.ocram", FSL_IMX6_OCRAM_SIZE
,
404 error_propagate(errp
, err
);
407 memory_region_add_subregion(get_system_memory(), FSL_IMX6_OCRAM_ADDR
,
410 /* internal OCRAM (256 KB) is aliased over 1 MB */
411 memory_region_init_alias(&s
->ocram_alias
, NULL
, "imx6.ocram_alias",
412 &s
->ocram
, 0, FSL_IMX6_OCRAM_ALIAS_SIZE
);
413 memory_region_add_subregion(get_system_memory(), FSL_IMX6_OCRAM_ALIAS_ADDR
,
417 static void fsl_imx6_class_init(ObjectClass
*oc
, void *data
)
419 DeviceClass
*dc
= DEVICE_CLASS(oc
);
421 dc
->realize
= fsl_imx6_realize
;
422 dc
->desc
= "i.MX6 SOC";
423 /* Reason: Uses serial_hd() in the realize() function */
424 dc
->user_creatable
= false;
427 static const TypeInfo fsl_imx6_type_info
= {
428 .name
= TYPE_FSL_IMX6
,
429 .parent
= TYPE_DEVICE
,
430 .instance_size
= sizeof(FslIMX6State
),
431 .instance_init
= fsl_imx6_init
,
432 .class_init
= fsl_imx6_class_init
,
435 static void fsl_imx6_register_types(void)
437 type_register_static(&fsl_imx6_type_info
);
440 type_init(fsl_imx6_register_types
)