2 * Copyright (c) 2018, Impinj, Inc.
4 * i.MX7 SoC definitions
6 * Author: Andrey Smirnov <andrew.smirnov@gmail.com>
8 * Based on hw/arm/fsl-imx6.c
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #include "qemu/osdep.h"
22 #include "qapi/error.h"
23 #include "hw/arm/fsl-imx7.h"
24 #include "hw/misc/unimp.h"
25 #include "hw/boards.h"
26 #include "sysemu/sysemu.h"
27 #include "qemu/error-report.h"
28 #include "qemu/module.h"
32 static void fsl_imx7_init(Object
*obj
)
34 MachineState
*ms
= MACHINE(qdev_get_machine());
35 FslIMX7State
*s
= FSL_IMX7(obj
);
39 for (i
= 0; i
< MIN(ms
->smp
.cpus
, FSL_IMX7_NUM_CPUS
); i
++) {
40 snprintf(name
, NAME_SIZE
, "cpu%d", i
);
41 object_initialize_child(obj
, name
, &s
->cpu
[i
], sizeof(s
->cpu
[i
]),
42 ARM_CPU_TYPE_NAME("cortex-a7"), &error_abort
,
49 sysbus_init_child_obj(obj
, "a7mpcore", &s
->a7mpcore
, sizeof(s
->a7mpcore
),
55 for (i
= 0; i
< FSL_IMX7_NUM_GPIOS
; i
++) {
56 snprintf(name
, NAME_SIZE
, "gpio%d", i
);
57 sysbus_init_child_obj(obj
, name
, &s
->gpio
[i
], sizeof(s
->gpio
[i
]),
64 for (i
= 0; i
< FSL_IMX7_NUM_GPTS
; i
++) {
65 snprintf(name
, NAME_SIZE
, "gpt%d", i
);
66 sysbus_init_child_obj(obj
, name
, &s
->gpt
[i
], sizeof(s
->gpt
[i
]),
73 sysbus_init_child_obj(obj
, "ccm", &s
->ccm
, sizeof(s
->ccm
), TYPE_IMX7_CCM
);
78 sysbus_init_child_obj(obj
, "analog", &s
->analog
, sizeof(s
->analog
),
84 sysbus_init_child_obj(obj
, "gpcv2", &s
->gpcv2
, sizeof(s
->gpcv2
),
87 for (i
= 0; i
< FSL_IMX7_NUM_ECSPIS
; i
++) {
88 snprintf(name
, NAME_SIZE
, "spi%d", i
+ 1);
89 sysbus_init_child_obj(obj
, name
, &s
->spi
[i
], sizeof(s
->spi
[i
]),
94 for (i
= 0; i
< FSL_IMX7_NUM_I2CS
; i
++) {
95 snprintf(name
, NAME_SIZE
, "i2c%d", i
+ 1);
96 sysbus_init_child_obj(obj
, name
, &s
->i2c
[i
], sizeof(s
->i2c
[i
]),
103 for (i
= 0; i
< FSL_IMX7_NUM_UARTS
; i
++) {
104 snprintf(name
, NAME_SIZE
, "uart%d", i
);
105 sysbus_init_child_obj(obj
, name
, &s
->uart
[i
], sizeof(s
->uart
[i
]),
112 for (i
= 0; i
< FSL_IMX7_NUM_ETHS
; i
++) {
113 snprintf(name
, NAME_SIZE
, "eth%d", i
);
114 sysbus_init_child_obj(obj
, name
, &s
->eth
[i
], sizeof(s
->eth
[i
]),
121 for (i
= 0; i
< FSL_IMX7_NUM_USDHCS
; i
++) {
122 snprintf(name
, NAME_SIZE
, "usdhc%d", i
);
123 sysbus_init_child_obj(obj
, name
, &s
->usdhc
[i
], sizeof(s
->usdhc
[i
]),
130 sysbus_init_child_obj(obj
, "snvs", &s
->snvs
, sizeof(s
->snvs
),
136 for (i
= 0; i
< FSL_IMX7_NUM_WDTS
; i
++) {
137 snprintf(name
, NAME_SIZE
, "wdt%d", i
);
138 sysbus_init_child_obj(obj
, name
, &s
->wdt
[i
], sizeof(s
->wdt
[i
]),
145 sysbus_init_child_obj(obj
, "gpr", &s
->gpr
, sizeof(s
->gpr
), TYPE_IMX7_GPR
);
147 sysbus_init_child_obj(obj
, "pcie", &s
->pcie
, sizeof(s
->pcie
),
148 TYPE_DESIGNWARE_PCIE_HOST
);
150 for (i
= 0; i
< FSL_IMX7_NUM_USBS
; i
++) {
151 snprintf(name
, NAME_SIZE
, "usb%d", i
);
152 sysbus_init_child_obj(obj
, name
, &s
->usb
[i
], sizeof(s
->usb
[i
]),
157 static void fsl_imx7_realize(DeviceState
*dev
, Error
**errp
)
159 MachineState
*ms
= MACHINE(qdev_get_machine());
160 FslIMX7State
*s
= FSL_IMX7(dev
);
164 char name
[NAME_SIZE
];
165 unsigned int smp_cpus
= ms
->smp
.cpus
;
167 if (smp_cpus
> FSL_IMX7_NUM_CPUS
) {
168 error_setg(errp
, "%s: Only %d CPUs are supported (%d requested)",
169 TYPE_FSL_IMX7
, FSL_IMX7_NUM_CPUS
, smp_cpus
);
173 for (i
= 0; i
< smp_cpus
; i
++) {
174 o
= OBJECT(&s
->cpu
[i
]);
176 object_property_set_int(o
, QEMU_PSCI_CONDUIT_SMC
,
177 "psci-conduit", &error_abort
);
179 /* On uniprocessor, the CBAR is set to 0 */
181 object_property_set_int(o
, FSL_IMX7_A7MPCORE_ADDR
,
182 "reset-cbar", &error_abort
);
186 /* Secondary CPUs start in PSCI powered-down state */
187 object_property_set_bool(o
, true,
188 "start-powered-off", &error_abort
);
191 object_property_set_bool(o
, true, "realized", &error_abort
);
197 object_property_set_int(OBJECT(&s
->a7mpcore
), smp_cpus
, "num-cpu",
199 object_property_set_int(OBJECT(&s
->a7mpcore
),
200 FSL_IMX7_MAX_IRQ
+ GIC_INTERNAL
,
201 "num-irq", &error_abort
);
203 object_property_set_bool(OBJECT(&s
->a7mpcore
), true, "realized",
205 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->a7mpcore
), 0, FSL_IMX7_A7MPCORE_ADDR
);
207 for (i
= 0; i
< smp_cpus
; i
++) {
208 SysBusDevice
*sbd
= SYS_BUS_DEVICE(&s
->a7mpcore
);
209 DeviceState
*d
= DEVICE(qemu_get_cpu(i
));
211 irq
= qdev_get_gpio_in(d
, ARM_CPU_IRQ
);
212 sysbus_connect_irq(sbd
, i
, irq
);
213 irq
= qdev_get_gpio_in(d
, ARM_CPU_FIQ
);
214 sysbus_connect_irq(sbd
, i
+ smp_cpus
, irq
);
215 irq
= qdev_get_gpio_in(d
, ARM_CPU_VIRQ
);
216 sysbus_connect_irq(sbd
, i
+ 2 * smp_cpus
, irq
);
217 irq
= qdev_get_gpio_in(d
, ARM_CPU_VFIQ
);
218 sysbus_connect_irq(sbd
, i
+ 3 * smp_cpus
, irq
);
224 create_unimplemented_device("a7mpcore-dap", FSL_IMX7_A7MPCORE_DAP_ADDR
,
230 for (i
= 0; i
< FSL_IMX7_NUM_GPTS
; i
++) {
231 static const hwaddr FSL_IMX7_GPTn_ADDR
[FSL_IMX7_NUM_GPTS
] = {
238 s
->gpt
[i
].ccm
= IMX_CCM(&s
->ccm
);
239 object_property_set_bool(OBJECT(&s
->gpt
[i
]), true, "realized",
241 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->gpt
[i
]), 0, FSL_IMX7_GPTn_ADDR
[i
]);
244 for (i
= 0; i
< FSL_IMX7_NUM_GPIOS
; i
++) {
245 static const hwaddr FSL_IMX7_GPIOn_ADDR
[FSL_IMX7_NUM_GPIOS
] = {
255 object_property_set_bool(OBJECT(&s
->gpio
[i
]), true, "realized",
257 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->gpio
[i
]), 0, FSL_IMX7_GPIOn_ADDR
[i
]);
261 * IOMUXC and IOMUXC_LPSR
263 for (i
= 0; i
< FSL_IMX7_NUM_IOMUXCS
; i
++) {
264 static const hwaddr FSL_IMX7_IOMUXCn_ADDR
[FSL_IMX7_NUM_IOMUXCS
] = {
265 FSL_IMX7_IOMUXC_ADDR
,
266 FSL_IMX7_IOMUXC_LPSR_ADDR
,
269 snprintf(name
, NAME_SIZE
, "iomuxc%d", i
);
270 create_unimplemented_device(name
, FSL_IMX7_IOMUXCn_ADDR
[i
],
271 FSL_IMX7_IOMUXCn_SIZE
);
277 object_property_set_bool(OBJECT(&s
->ccm
), true, "realized", &error_abort
);
278 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->ccm
), 0, FSL_IMX7_CCM_ADDR
);
283 object_property_set_bool(OBJECT(&s
->analog
), true, "realized",
285 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->analog
), 0, FSL_IMX7_ANALOG_ADDR
);
290 object_property_set_bool(OBJECT(&s
->gpcv2
), true,
291 "realized", &error_abort
);
292 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->gpcv2
), 0, FSL_IMX7_GPC_ADDR
);
294 /* Initialize all ECSPI */
295 for (i
= 0; i
< FSL_IMX7_NUM_ECSPIS
; i
++) {
296 static const hwaddr FSL_IMX7_SPIn_ADDR
[FSL_IMX7_NUM_ECSPIS
] = {
297 FSL_IMX7_ECSPI1_ADDR
,
298 FSL_IMX7_ECSPI2_ADDR
,
299 FSL_IMX7_ECSPI3_ADDR
,
300 FSL_IMX7_ECSPI4_ADDR
,
303 static const int FSL_IMX7_SPIn_IRQ
[FSL_IMX7_NUM_ECSPIS
] = {
310 /* Initialize the SPI */
311 object_property_set_bool(OBJECT(&s
->spi
[i
]), true, "realized",
313 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->spi
[i
]), 0,
314 FSL_IMX7_SPIn_ADDR
[i
]);
315 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->spi
[i
]), 0,
316 qdev_get_gpio_in(DEVICE(&s
->a7mpcore
),
317 FSL_IMX7_SPIn_IRQ
[i
]));
320 for (i
= 0; i
< FSL_IMX7_NUM_I2CS
; i
++) {
321 static const hwaddr FSL_IMX7_I2Cn_ADDR
[FSL_IMX7_NUM_I2CS
] = {
328 static const int FSL_IMX7_I2Cn_IRQ
[FSL_IMX7_NUM_I2CS
] = {
335 object_property_set_bool(OBJECT(&s
->i2c
[i
]), true, "realized",
337 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->i2c
[i
]), 0, FSL_IMX7_I2Cn_ADDR
[i
]);
339 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->i2c
[i
]), 0,
340 qdev_get_gpio_in(DEVICE(&s
->a7mpcore
),
341 FSL_IMX7_I2Cn_IRQ
[i
]));
347 for (i
= 0; i
< FSL_IMX7_NUM_UARTS
; i
++) {
348 static const hwaddr FSL_IMX7_UARTn_ADDR
[FSL_IMX7_NUM_UARTS
] = {
358 static const int FSL_IMX7_UARTn_IRQ
[FSL_IMX7_NUM_UARTS
] = {
369 qdev_prop_set_chr(DEVICE(&s
->uart
[i
]), "chardev", serial_hd(i
));
371 object_property_set_bool(OBJECT(&s
->uart
[i
]), true, "realized",
374 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->uart
[i
]), 0, FSL_IMX7_UARTn_ADDR
[i
]);
376 irq
= qdev_get_gpio_in(DEVICE(&s
->a7mpcore
), FSL_IMX7_UARTn_IRQ
[i
]);
377 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->uart
[i
]), 0, irq
);
383 for (i
= 0; i
< FSL_IMX7_NUM_ETHS
; i
++) {
384 static const hwaddr FSL_IMX7_ENETn_ADDR
[FSL_IMX7_NUM_ETHS
] = {
389 object_property_set_uint(OBJECT(&s
->eth
[i
]), FSL_IMX7_ETH_NUM_TX_RINGS
,
390 "tx-ring-num", &error_abort
);
391 qdev_set_nic_properties(DEVICE(&s
->eth
[i
]), &nd_table
[i
]);
392 object_property_set_bool(OBJECT(&s
->eth
[i
]), true, "realized",
395 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->eth
[i
]), 0, FSL_IMX7_ENETn_ADDR
[i
]);
397 irq
= qdev_get_gpio_in(DEVICE(&s
->a7mpcore
), FSL_IMX7_ENET_IRQ(i
, 0));
398 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->eth
[i
]), 0, irq
);
399 irq
= qdev_get_gpio_in(DEVICE(&s
->a7mpcore
), FSL_IMX7_ENET_IRQ(i
, 3));
400 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->eth
[i
]), 1, irq
);
406 for (i
= 0; i
< FSL_IMX7_NUM_USDHCS
; i
++) {
407 static const hwaddr FSL_IMX7_USDHCn_ADDR
[FSL_IMX7_NUM_USDHCS
] = {
408 FSL_IMX7_USDHC1_ADDR
,
409 FSL_IMX7_USDHC2_ADDR
,
410 FSL_IMX7_USDHC3_ADDR
,
413 static const int FSL_IMX7_USDHCn_IRQ
[FSL_IMX7_NUM_USDHCS
] = {
419 object_property_set_bool(OBJECT(&s
->usdhc
[i
]), true, "realized",
422 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->usdhc
[i
]), 0,
423 FSL_IMX7_USDHCn_ADDR
[i
]);
425 irq
= qdev_get_gpio_in(DEVICE(&s
->a7mpcore
), FSL_IMX7_USDHCn_IRQ
[i
]);
426 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->usdhc
[i
]), 0, irq
);
432 object_property_set_bool(OBJECT(&s
->snvs
), true, "realized", &error_abort
);
433 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->snvs
), 0, FSL_IMX7_SNVS_ADDR
);
438 create_unimplemented_device("src", FSL_IMX7_SRC_ADDR
, FSL_IMX7_SRC_SIZE
);
443 for (i
= 0; i
< FSL_IMX7_NUM_WDTS
; i
++) {
444 static const hwaddr FSL_IMX7_WDOGn_ADDR
[FSL_IMX7_NUM_WDTS
] = {
451 object_property_set_bool(OBJECT(&s
->wdt
[i
]), true, "realized",
454 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->wdt
[i
]), 0, FSL_IMX7_WDOGn_ADDR
[i
]);
460 create_unimplemented_device("sdma", FSL_IMX7_SDMA_ADDR
, FSL_IMX7_SDMA_SIZE
);
463 object_property_set_bool(OBJECT(&s
->gpr
), true, "realized",
465 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->gpr
), 0, FSL_IMX7_GPR_ADDR
);
467 object_property_set_bool(OBJECT(&s
->pcie
), true,
468 "realized", &error_abort
);
469 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->pcie
), 0, FSL_IMX7_PCIE_REG_ADDR
);
471 irq
= qdev_get_gpio_in(DEVICE(&s
->a7mpcore
), FSL_IMX7_PCI_INTA_IRQ
);
472 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->pcie
), 0, irq
);
473 irq
= qdev_get_gpio_in(DEVICE(&s
->a7mpcore
), FSL_IMX7_PCI_INTB_IRQ
);
474 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->pcie
), 1, irq
);
475 irq
= qdev_get_gpio_in(DEVICE(&s
->a7mpcore
), FSL_IMX7_PCI_INTC_IRQ
);
476 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->pcie
), 2, irq
);
477 irq
= qdev_get_gpio_in(DEVICE(&s
->a7mpcore
), FSL_IMX7_PCI_INTD_IRQ
);
478 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->pcie
), 3, irq
);
481 for (i
= 0; i
< FSL_IMX7_NUM_USBS
; i
++) {
482 static const hwaddr FSL_IMX7_USBMISCn_ADDR
[FSL_IMX7_NUM_USBS
] = {
483 FSL_IMX7_USBMISC1_ADDR
,
484 FSL_IMX7_USBMISC2_ADDR
,
485 FSL_IMX7_USBMISC3_ADDR
,
488 static const hwaddr FSL_IMX7_USBn_ADDR
[FSL_IMX7_NUM_USBS
] = {
494 static const int FSL_IMX7_USBn_IRQ
[FSL_IMX7_NUM_USBS
] = {
500 object_property_set_bool(OBJECT(&s
->usb
[i
]), true, "realized",
502 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->usb
[i
]), 0,
503 FSL_IMX7_USBn_ADDR
[i
]);
505 irq
= qdev_get_gpio_in(DEVICE(&s
->a7mpcore
), FSL_IMX7_USBn_IRQ
[i
]);
506 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->usb
[i
]), 0, irq
);
508 snprintf(name
, NAME_SIZE
, "usbmisc%d", i
);
509 create_unimplemented_device(name
, FSL_IMX7_USBMISCn_ADDR
[i
],
510 FSL_IMX7_USBMISCn_SIZE
);
516 for (i
= 0; i
< FSL_IMX7_NUM_ADCS
; i
++) {
517 static const hwaddr FSL_IMX7_ADCn_ADDR
[FSL_IMX7_NUM_ADCS
] = {
522 snprintf(name
, NAME_SIZE
, "adc%d", i
);
523 create_unimplemented_device(name
, FSL_IMX7_ADCn_ADDR
[i
],
530 create_unimplemented_device("lcdif", FSL_IMX7_LCDIF_ADDR
,
531 FSL_IMX7_LCDIF_SIZE
);
536 create_unimplemented_device("dma-apbh", FSL_IMX7_DMA_APBH_ADDR
,
537 FSL_IMX7_DMA_APBH_SIZE
);
541 create_unimplemented_device("pcie-phy", FSL_IMX7_PCIE_PHY_ADDR
,
542 FSL_IMX7_PCIE_PHY_SIZE
);
545 static void fsl_imx7_class_init(ObjectClass
*oc
, void *data
)
547 DeviceClass
*dc
= DEVICE_CLASS(oc
);
549 dc
->realize
= fsl_imx7_realize
;
551 /* Reason: Uses serial_hds and nd_table in realize() directly */
552 dc
->user_creatable
= false;
553 dc
->desc
= "i.MX7 SOC";
556 static const TypeInfo fsl_imx7_type_info
= {
557 .name
= TYPE_FSL_IMX7
,
558 .parent
= TYPE_DEVICE
,
559 .instance_size
= sizeof(FslIMX7State
),
560 .instance_init
= fsl_imx7_init
,
561 .class_init
= fsl_imx7_class_init
,
564 static void fsl_imx7_register_types(void)
566 type_register_static(&fsl_imx7_type_info
);
568 type_init(fsl_imx7_register_types
)