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 ARM_CPU_TYPE_NAME("cortex-a9"),
50 sysbus_init_child_obj(obj
, "a9mpcore", &s
->a9mpcore
, sizeof(s
->a9mpcore
),
53 sysbus_init_child_obj(obj
, "ccm", &s
->ccm
, sizeof(s
->ccm
), TYPE_IMX6_CCM
);
55 sysbus_init_child_obj(obj
, "src", &s
->src
, sizeof(s
->src
), TYPE_IMX6_SRC
);
57 for (i
= 0; i
< FSL_IMX6_NUM_UARTS
; i
++) {
58 snprintf(name
, NAME_SIZE
, "uart%d", i
+ 1);
59 sysbus_init_child_obj(obj
, name
, &s
->uart
[i
], sizeof(s
->uart
[i
]),
63 sysbus_init_child_obj(obj
, "gpt", &s
->gpt
, sizeof(s
->gpt
), TYPE_IMX6_GPT
);
65 for (i
= 0; i
< FSL_IMX6_NUM_EPITS
; i
++) {
66 snprintf(name
, NAME_SIZE
, "epit%d", i
+ 1);
67 sysbus_init_child_obj(obj
, name
, &s
->epit
[i
], sizeof(s
->epit
[i
]),
71 for (i
= 0; i
< FSL_IMX6_NUM_I2CS
; i
++) {
72 snprintf(name
, NAME_SIZE
, "i2c%d", i
+ 1);
73 sysbus_init_child_obj(obj
, name
, &s
->i2c
[i
], sizeof(s
->i2c
[i
]),
77 for (i
= 0; i
< FSL_IMX6_NUM_GPIOS
; i
++) {
78 snprintf(name
, NAME_SIZE
, "gpio%d", i
+ 1);
79 sysbus_init_child_obj(obj
, name
, &s
->gpio
[i
], sizeof(s
->gpio
[i
]),
83 for (i
= 0; i
< FSL_IMX6_NUM_ESDHCS
; i
++) {
84 snprintf(name
, NAME_SIZE
, "sdhc%d", i
+ 1);
85 sysbus_init_child_obj(obj
, name
, &s
->esdhc
[i
], sizeof(s
->esdhc
[i
]),
89 for (i
= 0; i
< FSL_IMX6_NUM_ECSPIS
; i
++) {
90 snprintf(name
, NAME_SIZE
, "spi%d", i
+ 1);
91 sysbus_init_child_obj(obj
, name
, &s
->spi
[i
], sizeof(s
->spi
[i
]),
95 sysbus_init_child_obj(obj
, "eth", &s
->eth
, sizeof(s
->eth
), TYPE_IMX_ENET
);
98 static void fsl_imx6_realize(DeviceState
*dev
, Error
**errp
)
100 MachineState
*ms
= MACHINE(qdev_get_machine());
101 FslIMX6State
*s
= FSL_IMX6(dev
);
104 unsigned int smp_cpus
= ms
->smp
.cpus
;
106 if (smp_cpus
> FSL_IMX6_NUM_CPUS
) {
107 error_setg(errp
, "%s: Only %d CPUs are supported (%d requested)",
108 TYPE_FSL_IMX6
, FSL_IMX6_NUM_CPUS
, smp_cpus
);
112 for (i
= 0; i
< smp_cpus
; i
++) {
114 /* On uniprocessor, the CBAR is set to 0 */
116 object_property_set_int(OBJECT(&s
->cpu
[i
]), FSL_IMX6_A9MPCORE_ADDR
,
117 "reset-cbar", &error_abort
);
120 /* All CPU but CPU 0 start in power off mode */
122 object_property_set_bool(OBJECT(&s
->cpu
[i
]), true,
123 "start-powered-off", &error_abort
);
126 object_property_set_bool(OBJECT(&s
->cpu
[i
]), true, "realized", &err
);
128 error_propagate(errp
, err
);
133 object_property_set_int(OBJECT(&s
->a9mpcore
), smp_cpus
, "num-cpu",
136 object_property_set_int(OBJECT(&s
->a9mpcore
),
137 FSL_IMX6_MAX_IRQ
+ GIC_INTERNAL
, "num-irq",
140 object_property_set_bool(OBJECT(&s
->a9mpcore
), true, "realized", &err
);
142 error_propagate(errp
, err
);
145 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->a9mpcore
), 0, FSL_IMX6_A9MPCORE_ADDR
);
147 for (i
= 0; i
< smp_cpus
; i
++) {
148 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->a9mpcore
), i
,
149 qdev_get_gpio_in(DEVICE(&s
->cpu
[i
]), ARM_CPU_IRQ
));
150 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->a9mpcore
), i
+ smp_cpus
,
151 qdev_get_gpio_in(DEVICE(&s
->cpu
[i
]), ARM_CPU_FIQ
));
154 object_property_set_bool(OBJECT(&s
->ccm
), true, "realized", &err
);
156 error_propagate(errp
, err
);
159 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->ccm
), 0, FSL_IMX6_CCM_ADDR
);
161 object_property_set_bool(OBJECT(&s
->src
), true, "realized", &err
);
163 error_propagate(errp
, err
);
166 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->src
), 0, FSL_IMX6_SRC_ADDR
);
168 /* Initialize all UARTs */
169 for (i
= 0; i
< FSL_IMX6_NUM_UARTS
; i
++) {
170 static const struct {
173 } serial_table
[FSL_IMX6_NUM_UARTS
] = {
174 { FSL_IMX6_UART1_ADDR
, FSL_IMX6_UART1_IRQ
},
175 { FSL_IMX6_UART2_ADDR
, FSL_IMX6_UART2_IRQ
},
176 { FSL_IMX6_UART3_ADDR
, FSL_IMX6_UART3_IRQ
},
177 { FSL_IMX6_UART4_ADDR
, FSL_IMX6_UART4_IRQ
},
178 { FSL_IMX6_UART5_ADDR
, FSL_IMX6_UART5_IRQ
},
181 qdev_prop_set_chr(DEVICE(&s
->uart
[i
]), "chardev", serial_hd(i
));
183 object_property_set_bool(OBJECT(&s
->uart
[i
]), true, "realized", &err
);
185 error_propagate(errp
, err
);
189 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->uart
[i
]), 0, serial_table
[i
].addr
);
190 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->uart
[i
]), 0,
191 qdev_get_gpio_in(DEVICE(&s
->a9mpcore
),
192 serial_table
[i
].irq
));
195 s
->gpt
.ccm
= IMX_CCM(&s
->ccm
);
197 object_property_set_bool(OBJECT(&s
->gpt
), true, "realized", &err
);
199 error_propagate(errp
, err
);
203 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->gpt
), 0, FSL_IMX6_GPT_ADDR
);
204 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->gpt
), 0,
205 qdev_get_gpio_in(DEVICE(&s
->a9mpcore
),
208 /* Initialize all EPIT timers */
209 for (i
= 0; i
< FSL_IMX6_NUM_EPITS
; i
++) {
210 static const struct {
213 } epit_table
[FSL_IMX6_NUM_EPITS
] = {
214 { FSL_IMX6_EPIT1_ADDR
, FSL_IMX6_EPIT1_IRQ
},
215 { FSL_IMX6_EPIT2_ADDR
, FSL_IMX6_EPIT2_IRQ
},
218 s
->epit
[i
].ccm
= IMX_CCM(&s
->ccm
);
220 object_property_set_bool(OBJECT(&s
->epit
[i
]), true, "realized", &err
);
222 error_propagate(errp
, err
);
226 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->epit
[i
]), 0, epit_table
[i
].addr
);
227 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->epit
[i
]), 0,
228 qdev_get_gpio_in(DEVICE(&s
->a9mpcore
),
232 /* Initialize all I2C */
233 for (i
= 0; i
< FSL_IMX6_NUM_I2CS
; i
++) {
234 static const struct {
237 } i2c_table
[FSL_IMX6_NUM_I2CS
] = {
238 { FSL_IMX6_I2C1_ADDR
, FSL_IMX6_I2C1_IRQ
},
239 { FSL_IMX6_I2C2_ADDR
, FSL_IMX6_I2C2_IRQ
},
240 { FSL_IMX6_I2C3_ADDR
, FSL_IMX6_I2C3_IRQ
}
243 object_property_set_bool(OBJECT(&s
->i2c
[i
]), true, "realized", &err
);
245 error_propagate(errp
, err
);
249 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->i2c
[i
]), 0, i2c_table
[i
].addr
);
250 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->i2c
[i
]), 0,
251 qdev_get_gpio_in(DEVICE(&s
->a9mpcore
),
255 /* Initialize all GPIOs */
256 for (i
= 0; i
< FSL_IMX6_NUM_GPIOS
; i
++) {
257 static const struct {
259 unsigned int irq_low
;
260 unsigned int irq_high
;
261 } gpio_table
[FSL_IMX6_NUM_GPIOS
] = {
264 FSL_IMX6_GPIO1_LOW_IRQ
,
265 FSL_IMX6_GPIO1_HIGH_IRQ
269 FSL_IMX6_GPIO2_LOW_IRQ
,
270 FSL_IMX6_GPIO2_HIGH_IRQ
274 FSL_IMX6_GPIO3_LOW_IRQ
,
275 FSL_IMX6_GPIO3_HIGH_IRQ
279 FSL_IMX6_GPIO4_LOW_IRQ
,
280 FSL_IMX6_GPIO4_HIGH_IRQ
284 FSL_IMX6_GPIO5_LOW_IRQ
,
285 FSL_IMX6_GPIO5_HIGH_IRQ
289 FSL_IMX6_GPIO6_LOW_IRQ
,
290 FSL_IMX6_GPIO6_HIGH_IRQ
294 FSL_IMX6_GPIO7_LOW_IRQ
,
295 FSL_IMX6_GPIO7_HIGH_IRQ
299 object_property_set_bool(OBJECT(&s
->gpio
[i
]), true, "has-edge-sel",
301 object_property_set_bool(OBJECT(&s
->gpio
[i
]), true, "has-upper-pin-irq",
303 object_property_set_bool(OBJECT(&s
->gpio
[i
]), true, "realized", &err
);
305 error_propagate(errp
, err
);
309 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->gpio
[i
]), 0, gpio_table
[i
].addr
);
310 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->gpio
[i
]), 0,
311 qdev_get_gpio_in(DEVICE(&s
->a9mpcore
),
312 gpio_table
[i
].irq_low
));
313 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->gpio
[i
]), 1,
314 qdev_get_gpio_in(DEVICE(&s
->a9mpcore
),
315 gpio_table
[i
].irq_high
));
318 /* Initialize all SDHC */
319 for (i
= 0; i
< FSL_IMX6_NUM_ESDHCS
; i
++) {
320 static const struct {
323 } esdhc_table
[FSL_IMX6_NUM_ESDHCS
] = {
324 { FSL_IMX6_uSDHC1_ADDR
, FSL_IMX6_uSDHC1_IRQ
},
325 { FSL_IMX6_uSDHC2_ADDR
, FSL_IMX6_uSDHC2_IRQ
},
326 { FSL_IMX6_uSDHC3_ADDR
, FSL_IMX6_uSDHC3_IRQ
},
327 { FSL_IMX6_uSDHC4_ADDR
, FSL_IMX6_uSDHC4_IRQ
},
330 /* UHS-I SDIO3.0 SDR104 1.8V ADMA */
331 object_property_set_uint(OBJECT(&s
->esdhc
[i
]), 3, "sd-spec-version",
333 object_property_set_uint(OBJECT(&s
->esdhc
[i
]), IMX6_ESDHC_CAPABILITIES
,
335 object_property_set_bool(OBJECT(&s
->esdhc
[i
]), true, "realized", &err
);
337 error_propagate(errp
, err
);
340 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->esdhc
[i
]), 0, esdhc_table
[i
].addr
);
341 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->esdhc
[i
]), 0,
342 qdev_get_gpio_in(DEVICE(&s
->a9mpcore
),
343 esdhc_table
[i
].irq
));
346 /* Initialize all ECSPI */
347 for (i
= 0; i
< FSL_IMX6_NUM_ECSPIS
; i
++) {
348 static const struct {
351 } spi_table
[FSL_IMX6_NUM_ECSPIS
] = {
352 { FSL_IMX6_eCSPI1_ADDR
, FSL_IMX6_ECSPI1_IRQ
},
353 { FSL_IMX6_eCSPI2_ADDR
, FSL_IMX6_ECSPI2_IRQ
},
354 { FSL_IMX6_eCSPI3_ADDR
, FSL_IMX6_ECSPI3_IRQ
},
355 { FSL_IMX6_eCSPI4_ADDR
, FSL_IMX6_ECSPI4_IRQ
},
356 { FSL_IMX6_eCSPI5_ADDR
, FSL_IMX6_ECSPI5_IRQ
},
359 /* Initialize the SPI */
360 object_property_set_bool(OBJECT(&s
->spi
[i
]), true, "realized", &err
);
362 error_propagate(errp
, err
);
366 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->spi
[i
]), 0, spi_table
[i
].addr
);
367 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->spi
[i
]), 0,
368 qdev_get_gpio_in(DEVICE(&s
->a9mpcore
),
372 qdev_set_nic_properties(DEVICE(&s
->eth
), &nd_table
[0]);
373 object_property_set_bool(OBJECT(&s
->eth
), true, "realized", &err
);
375 error_propagate(errp
, err
);
378 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->eth
), 0, FSL_IMX6_ENET_ADDR
);
379 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->eth
), 0,
380 qdev_get_gpio_in(DEVICE(&s
->a9mpcore
),
381 FSL_IMX6_ENET_MAC_IRQ
));
382 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->eth
), 1,
383 qdev_get_gpio_in(DEVICE(&s
->a9mpcore
),
384 FSL_IMX6_ENET_MAC_1588_IRQ
));
387 memory_region_init_rom(&s
->rom
, NULL
, "imx6.rom",
388 FSL_IMX6_ROM_SIZE
, &err
);
390 error_propagate(errp
, err
);
393 memory_region_add_subregion(get_system_memory(), FSL_IMX6_ROM_ADDR
,
397 memory_region_init_rom(&s
->caam
, NULL
, "imx6.caam",
398 FSL_IMX6_CAAM_MEM_SIZE
, &err
);
400 error_propagate(errp
, err
);
403 memory_region_add_subregion(get_system_memory(), FSL_IMX6_CAAM_MEM_ADDR
,
407 memory_region_init_ram(&s
->ocram
, NULL
, "imx6.ocram", FSL_IMX6_OCRAM_SIZE
,
410 error_propagate(errp
, err
);
413 memory_region_add_subregion(get_system_memory(), FSL_IMX6_OCRAM_ADDR
,
416 /* internal OCRAM (256 KB) is aliased over 1 MB */
417 memory_region_init_alias(&s
->ocram_alias
, NULL
, "imx6.ocram_alias",
418 &s
->ocram
, 0, FSL_IMX6_OCRAM_ALIAS_SIZE
);
419 memory_region_add_subregion(get_system_memory(), FSL_IMX6_OCRAM_ALIAS_ADDR
,
423 static void fsl_imx6_class_init(ObjectClass
*oc
, void *data
)
425 DeviceClass
*dc
= DEVICE_CLASS(oc
);
427 dc
->realize
= fsl_imx6_realize
;
428 dc
->desc
= "i.MX6 SOC";
429 /* Reason: Uses serial_hd() in the realize() function */
430 dc
->user_creatable
= false;
433 static const TypeInfo fsl_imx6_type_info
= {
434 .name
= TYPE_FSL_IMX6
,
435 .parent
= TYPE_DEVICE
,
436 .instance_size
= sizeof(FslIMX6State
),
437 .instance_init
= fsl_imx6_init
,
438 .class_init
= fsl_imx6_class_init
,
441 static void fsl_imx6_register_types(void)
443 type_register_static(&fsl_imx6_type_info
);
446 type_init(fsl_imx6_register_types
)