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 "hw/boards.h"
26 #include "hw/qdev-properties.h"
27 #include "sysemu/sysemu.h"
28 #include "chardev/char.h"
29 #include "qemu/error-report.h"
30 #include "qemu/module.h"
32 #define IMX6_ESDHC_CAPABILITIES 0x057834b4
36 static void fsl_imx6_init(Object
*obj
)
38 MachineState
*ms
= MACHINE(qdev_get_machine());
39 FslIMX6State
*s
= FSL_IMX6(obj
);
43 for (i
= 0; i
< MIN(ms
->smp
.cpus
, FSL_IMX6_NUM_CPUS
); i
++) {
44 snprintf(name
, NAME_SIZE
, "cpu%d", i
);
45 object_initialize_child(obj
, name
, &s
->cpu
[i
], sizeof(s
->cpu
[i
]),
46 "cortex-a9-" TYPE_ARM_CPU
, &error_abort
, NULL
);
49 sysbus_init_child_obj(obj
, "a9mpcore", &s
->a9mpcore
, sizeof(s
->a9mpcore
),
52 sysbus_init_child_obj(obj
, "ccm", &s
->ccm
, sizeof(s
->ccm
), TYPE_IMX6_CCM
);
54 sysbus_init_child_obj(obj
, "src", &s
->src
, sizeof(s
->src
), TYPE_IMX6_SRC
);
56 for (i
= 0; i
< FSL_IMX6_NUM_UARTS
; i
++) {
57 snprintf(name
, NAME_SIZE
, "uart%d", i
+ 1);
58 sysbus_init_child_obj(obj
, name
, &s
->uart
[i
], sizeof(s
->uart
[i
]),
62 sysbus_init_child_obj(obj
, "gpt", &s
->gpt
, sizeof(s
->gpt
), TYPE_IMX6_GPT
);
64 for (i
= 0; i
< FSL_IMX6_NUM_EPITS
; i
++) {
65 snprintf(name
, NAME_SIZE
, "epit%d", i
+ 1);
66 sysbus_init_child_obj(obj
, name
, &s
->epit
[i
], sizeof(s
->epit
[i
]),
70 for (i
= 0; i
< FSL_IMX6_NUM_I2CS
; i
++) {
71 snprintf(name
, NAME_SIZE
, "i2c%d", i
+ 1);
72 sysbus_init_child_obj(obj
, name
, &s
->i2c
[i
], sizeof(s
->i2c
[i
]),
76 for (i
= 0; i
< FSL_IMX6_NUM_GPIOS
; i
++) {
77 snprintf(name
, NAME_SIZE
, "gpio%d", i
+ 1);
78 sysbus_init_child_obj(obj
, name
, &s
->gpio
[i
], sizeof(s
->gpio
[i
]),
82 for (i
= 0; i
< FSL_IMX6_NUM_ESDHCS
; i
++) {
83 snprintf(name
, NAME_SIZE
, "sdhc%d", i
+ 1);
84 sysbus_init_child_obj(obj
, name
, &s
->esdhc
[i
], sizeof(s
->esdhc
[i
]),
88 for (i
= 0; i
< FSL_IMX6_NUM_ECSPIS
; i
++) {
89 snprintf(name
, NAME_SIZE
, "spi%d", i
+ 1);
90 sysbus_init_child_obj(obj
, name
, &s
->spi
[i
], sizeof(s
->spi
[i
]),
94 sysbus_init_child_obj(obj
, "eth", &s
->eth
, sizeof(s
->eth
), TYPE_IMX_ENET
);
97 static void fsl_imx6_realize(DeviceState
*dev
, Error
**errp
)
99 MachineState
*ms
= MACHINE(qdev_get_machine());
100 FslIMX6State
*s
= FSL_IMX6(dev
);
103 unsigned int smp_cpus
= ms
->smp
.cpus
;
105 if (smp_cpus
> FSL_IMX6_NUM_CPUS
) {
106 error_setg(errp
, "%s: Only %d CPUs are supported (%d requested)",
107 TYPE_FSL_IMX6
, FSL_IMX6_NUM_CPUS
, smp_cpus
);
111 for (i
= 0; i
< smp_cpus
; i
++) {
113 /* On uniprocessor, the CBAR is set to 0 */
115 object_property_set_int(OBJECT(&s
->cpu
[i
]), FSL_IMX6_A9MPCORE_ADDR
,
116 "reset-cbar", &error_abort
);
119 /* All CPU but CPU 0 start in power off mode */
121 object_property_set_bool(OBJECT(&s
->cpu
[i
]), true,
122 "start-powered-off", &error_abort
);
125 object_property_set_bool(OBJECT(&s
->cpu
[i
]), true, "realized", &err
);
127 error_propagate(errp
, err
);
132 object_property_set_int(OBJECT(&s
->a9mpcore
), smp_cpus
, "num-cpu",
135 object_property_set_int(OBJECT(&s
->a9mpcore
),
136 FSL_IMX6_MAX_IRQ
+ GIC_INTERNAL
, "num-irq",
139 object_property_set_bool(OBJECT(&s
->a9mpcore
), true, "realized", &err
);
141 error_propagate(errp
, err
);
144 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->a9mpcore
), 0, FSL_IMX6_A9MPCORE_ADDR
);
146 for (i
= 0; i
< smp_cpus
; i
++) {
147 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->a9mpcore
), i
,
148 qdev_get_gpio_in(DEVICE(&s
->cpu
[i
]), ARM_CPU_IRQ
));
149 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->a9mpcore
), i
+ smp_cpus
,
150 qdev_get_gpio_in(DEVICE(&s
->cpu
[i
]), ARM_CPU_FIQ
));
153 object_property_set_bool(OBJECT(&s
->ccm
), true, "realized", &err
);
155 error_propagate(errp
, err
);
158 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->ccm
), 0, FSL_IMX6_CCM_ADDR
);
160 object_property_set_bool(OBJECT(&s
->src
), true, "realized", &err
);
162 error_propagate(errp
, err
);
165 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->src
), 0, FSL_IMX6_SRC_ADDR
);
167 /* Initialize all UARTs */
168 for (i
= 0; i
< FSL_IMX6_NUM_UARTS
; i
++) {
169 static const struct {
172 } serial_table
[FSL_IMX6_NUM_UARTS
] = {
173 { FSL_IMX6_UART1_ADDR
, FSL_IMX6_UART1_IRQ
},
174 { FSL_IMX6_UART2_ADDR
, FSL_IMX6_UART2_IRQ
},
175 { FSL_IMX6_UART3_ADDR
, FSL_IMX6_UART3_IRQ
},
176 { FSL_IMX6_UART4_ADDR
, FSL_IMX6_UART4_IRQ
},
177 { FSL_IMX6_UART5_ADDR
, FSL_IMX6_UART5_IRQ
},
180 qdev_prop_set_chr(DEVICE(&s
->uart
[i
]), "chardev", serial_hd(i
));
182 object_property_set_bool(OBJECT(&s
->uart
[i
]), true, "realized", &err
);
184 error_propagate(errp
, err
);
188 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->uart
[i
]), 0, serial_table
[i
].addr
);
189 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->uart
[i
]), 0,
190 qdev_get_gpio_in(DEVICE(&s
->a9mpcore
),
191 serial_table
[i
].irq
));
194 s
->gpt
.ccm
= IMX_CCM(&s
->ccm
);
196 object_property_set_bool(OBJECT(&s
->gpt
), true, "realized", &err
);
198 error_propagate(errp
, err
);
202 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->gpt
), 0, FSL_IMX6_GPT_ADDR
);
203 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->gpt
), 0,
204 qdev_get_gpio_in(DEVICE(&s
->a9mpcore
),
207 /* Initialize all EPIT timers */
208 for (i
= 0; i
< FSL_IMX6_NUM_EPITS
; i
++) {
209 static const struct {
212 } epit_table
[FSL_IMX6_NUM_EPITS
] = {
213 { FSL_IMX6_EPIT1_ADDR
, FSL_IMX6_EPIT1_IRQ
},
214 { FSL_IMX6_EPIT2_ADDR
, FSL_IMX6_EPIT2_IRQ
},
217 s
->epit
[i
].ccm
= IMX_CCM(&s
->ccm
);
219 object_property_set_bool(OBJECT(&s
->epit
[i
]), true, "realized", &err
);
221 error_propagate(errp
, err
);
225 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->epit
[i
]), 0, epit_table
[i
].addr
);
226 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->epit
[i
]), 0,
227 qdev_get_gpio_in(DEVICE(&s
->a9mpcore
),
231 /* Initialize all I2C */
232 for (i
= 0; i
< FSL_IMX6_NUM_I2CS
; i
++) {
233 static const struct {
236 } i2c_table
[FSL_IMX6_NUM_I2CS
] = {
237 { FSL_IMX6_I2C1_ADDR
, FSL_IMX6_I2C1_IRQ
},
238 { FSL_IMX6_I2C2_ADDR
, FSL_IMX6_I2C2_IRQ
},
239 { FSL_IMX6_I2C3_ADDR
, FSL_IMX6_I2C3_IRQ
}
242 object_property_set_bool(OBJECT(&s
->i2c
[i
]), true, "realized", &err
);
244 error_propagate(errp
, err
);
248 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->i2c
[i
]), 0, i2c_table
[i
].addr
);
249 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->i2c
[i
]), 0,
250 qdev_get_gpio_in(DEVICE(&s
->a9mpcore
),
254 /* Initialize all GPIOs */
255 for (i
= 0; i
< FSL_IMX6_NUM_GPIOS
; i
++) {
256 static const struct {
258 unsigned int irq_low
;
259 unsigned int irq_high
;
260 } gpio_table
[FSL_IMX6_NUM_GPIOS
] = {
263 FSL_IMX6_GPIO1_LOW_IRQ
,
264 FSL_IMX6_GPIO1_HIGH_IRQ
268 FSL_IMX6_GPIO2_LOW_IRQ
,
269 FSL_IMX6_GPIO2_HIGH_IRQ
273 FSL_IMX6_GPIO3_LOW_IRQ
,
274 FSL_IMX6_GPIO3_HIGH_IRQ
278 FSL_IMX6_GPIO4_LOW_IRQ
,
279 FSL_IMX6_GPIO4_HIGH_IRQ
283 FSL_IMX6_GPIO5_LOW_IRQ
,
284 FSL_IMX6_GPIO5_HIGH_IRQ
288 FSL_IMX6_GPIO6_LOW_IRQ
,
289 FSL_IMX6_GPIO6_HIGH_IRQ
293 FSL_IMX6_GPIO7_LOW_IRQ
,
294 FSL_IMX6_GPIO7_HIGH_IRQ
298 object_property_set_bool(OBJECT(&s
->gpio
[i
]), true, "has-edge-sel",
300 object_property_set_bool(OBJECT(&s
->gpio
[i
]), true, "has-upper-pin-irq",
302 object_property_set_bool(OBJECT(&s
->gpio
[i
]), true, "realized", &err
);
304 error_propagate(errp
, err
);
308 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->gpio
[i
]), 0, gpio_table
[i
].addr
);
309 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->gpio
[i
]), 0,
310 qdev_get_gpio_in(DEVICE(&s
->a9mpcore
),
311 gpio_table
[i
].irq_low
));
312 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->gpio
[i
]), 1,
313 qdev_get_gpio_in(DEVICE(&s
->a9mpcore
),
314 gpio_table
[i
].irq_high
));
317 /* Initialize all SDHC */
318 for (i
= 0; i
< FSL_IMX6_NUM_ESDHCS
; i
++) {
319 static const struct {
322 } esdhc_table
[FSL_IMX6_NUM_ESDHCS
] = {
323 { FSL_IMX6_uSDHC1_ADDR
, FSL_IMX6_uSDHC1_IRQ
},
324 { FSL_IMX6_uSDHC2_ADDR
, FSL_IMX6_uSDHC2_IRQ
},
325 { FSL_IMX6_uSDHC3_ADDR
, FSL_IMX6_uSDHC3_IRQ
},
326 { FSL_IMX6_uSDHC4_ADDR
, FSL_IMX6_uSDHC4_IRQ
},
329 /* UHS-I SDIO3.0 SDR104 1.8V ADMA */
330 object_property_set_uint(OBJECT(&s
->esdhc
[i
]), 3, "sd-spec-version",
332 object_property_set_uint(OBJECT(&s
->esdhc
[i
]), IMX6_ESDHC_CAPABILITIES
,
334 object_property_set_bool(OBJECT(&s
->esdhc
[i
]), true, "realized", &err
);
336 error_propagate(errp
, err
);
339 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->esdhc
[i
]), 0, esdhc_table
[i
].addr
);
340 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->esdhc
[i
]), 0,
341 qdev_get_gpio_in(DEVICE(&s
->a9mpcore
),
342 esdhc_table
[i
].irq
));
345 /* Initialize all ECSPI */
346 for (i
= 0; i
< FSL_IMX6_NUM_ECSPIS
; i
++) {
347 static const struct {
350 } spi_table
[FSL_IMX6_NUM_ECSPIS
] = {
351 { FSL_IMX6_eCSPI1_ADDR
, FSL_IMX6_ECSPI1_IRQ
},
352 { FSL_IMX6_eCSPI2_ADDR
, FSL_IMX6_ECSPI2_IRQ
},
353 { FSL_IMX6_eCSPI3_ADDR
, FSL_IMX6_ECSPI3_IRQ
},
354 { FSL_IMX6_eCSPI4_ADDR
, FSL_IMX6_ECSPI4_IRQ
},
355 { FSL_IMX6_eCSPI5_ADDR
, FSL_IMX6_ECSPI5_IRQ
},
358 /* Initialize the SPI */
359 object_property_set_bool(OBJECT(&s
->spi
[i
]), true, "realized", &err
);
361 error_propagate(errp
, err
);
365 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->spi
[i
]), 0, spi_table
[i
].addr
);
366 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->spi
[i
]), 0,
367 qdev_get_gpio_in(DEVICE(&s
->a9mpcore
),
371 qdev_set_nic_properties(DEVICE(&s
->eth
), &nd_table
[0]);
372 object_property_set_bool(OBJECT(&s
->eth
), true, "realized", &err
);
374 error_propagate(errp
, err
);
377 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->eth
), 0, FSL_IMX6_ENET_ADDR
);
378 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->eth
), 0,
379 qdev_get_gpio_in(DEVICE(&s
->a9mpcore
),
380 FSL_IMX6_ENET_MAC_IRQ
));
381 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->eth
), 1,
382 qdev_get_gpio_in(DEVICE(&s
->a9mpcore
),
383 FSL_IMX6_ENET_MAC_1588_IRQ
));
386 memory_region_init_rom(&s
->rom
, NULL
, "imx6.rom",
387 FSL_IMX6_ROM_SIZE
, &err
);
389 error_propagate(errp
, err
);
392 memory_region_add_subregion(get_system_memory(), FSL_IMX6_ROM_ADDR
,
396 memory_region_init_rom(&s
->caam
, NULL
, "imx6.caam",
397 FSL_IMX6_CAAM_MEM_SIZE
, &err
);
399 error_propagate(errp
, err
);
402 memory_region_add_subregion(get_system_memory(), FSL_IMX6_CAAM_MEM_ADDR
,
406 memory_region_init_ram(&s
->ocram
, NULL
, "imx6.ocram", FSL_IMX6_OCRAM_SIZE
,
409 error_propagate(errp
, err
);
412 memory_region_add_subregion(get_system_memory(), FSL_IMX6_OCRAM_ADDR
,
415 /* internal OCRAM (256 KB) is aliased over 1 MB */
416 memory_region_init_alias(&s
->ocram_alias
, NULL
, "imx6.ocram_alias",
417 &s
->ocram
, 0, FSL_IMX6_OCRAM_ALIAS_SIZE
);
418 memory_region_add_subregion(get_system_memory(), FSL_IMX6_OCRAM_ALIAS_ADDR
,
422 static void fsl_imx6_class_init(ObjectClass
*oc
, void *data
)
424 DeviceClass
*dc
= DEVICE_CLASS(oc
);
426 dc
->realize
= fsl_imx6_realize
;
427 dc
->desc
= "i.MX6 SOC";
428 /* Reason: Uses serial_hd() in the realize() function */
429 dc
->user_creatable
= false;
432 static const TypeInfo fsl_imx6_type_info
= {
433 .name
= TYPE_FSL_IMX6
,
434 .parent
= TYPE_DEVICE
,
435 .instance_size
= sizeof(FslIMX6State
),
436 .instance_init
= fsl_imx6_init
,
437 .class_init
= fsl_imx6_class_init
,
440 static void fsl_imx6_register_types(void)
442 type_register_static(&fsl_imx6_type_info
);
445 type_init(fsl_imx6_register_types
)