4 * Andrew Jeffery <andrew@aj.id.au>
5 * Jeremy Kerr <jk@ozlabs.org>
7 * Copyright 2016 IBM Corp.
9 * This code is licensed under the GPL version 2 or later. See
10 * the COPYING file in the top-level directory.
13 #include "qemu/osdep.h"
14 #include "qapi/error.h"
16 #include "exec/address-spaces.h"
17 #include "hw/misc/unimp.h"
18 #include "hw/arm/aspeed_soc.h"
19 #include "hw/char/serial.h"
21 #include "qemu/module.h"
22 #include "qemu/error-report.h"
23 #include "hw/i2c/aspeed_i2c.h"
25 #include "sysemu/sysemu.h"
27 #define ASPEED_SOC_IOMEM_SIZE 0x00200000
29 static const hwaddr aspeed_soc_ast2400_memmap
[] = {
30 [ASPEED_IOMEM
] = 0x1E600000,
31 [ASPEED_FMC
] = 0x1E620000,
32 [ASPEED_SPI1
] = 0x1E630000,
33 [ASPEED_EHCI1
] = 0x1E6A1000,
34 [ASPEED_VIC
] = 0x1E6C0000,
35 [ASPEED_SDMC
] = 0x1E6E0000,
36 [ASPEED_SCU
] = 0x1E6E2000,
37 [ASPEED_XDMA
] = 0x1E6E7000,
38 [ASPEED_VIDEO
] = 0x1E700000,
39 [ASPEED_ADC
] = 0x1E6E9000,
40 [ASPEED_SRAM
] = 0x1E720000,
41 [ASPEED_SDHCI
] = 0x1E740000,
42 [ASPEED_GPIO
] = 0x1E780000,
43 [ASPEED_RTC
] = 0x1E781000,
44 [ASPEED_TIMER1
] = 0x1E782000,
45 [ASPEED_WDT
] = 0x1E785000,
46 [ASPEED_PWM
] = 0x1E786000,
47 [ASPEED_LPC
] = 0x1E789000,
48 [ASPEED_IBT
] = 0x1E789140,
49 [ASPEED_I2C
] = 0x1E78A000,
50 [ASPEED_ETH1
] = 0x1E660000,
51 [ASPEED_ETH2
] = 0x1E680000,
52 [ASPEED_UART1
] = 0x1E783000,
53 [ASPEED_UART5
] = 0x1E784000,
54 [ASPEED_VUART
] = 0x1E787000,
55 [ASPEED_SDRAM
] = 0x40000000,
58 static const hwaddr aspeed_soc_ast2500_memmap
[] = {
59 [ASPEED_IOMEM
] = 0x1E600000,
60 [ASPEED_FMC
] = 0x1E620000,
61 [ASPEED_SPI1
] = 0x1E630000,
62 [ASPEED_SPI2
] = 0x1E631000,
63 [ASPEED_EHCI1
] = 0x1E6A1000,
64 [ASPEED_EHCI2
] = 0x1E6A3000,
65 [ASPEED_VIC
] = 0x1E6C0000,
66 [ASPEED_SDMC
] = 0x1E6E0000,
67 [ASPEED_SCU
] = 0x1E6E2000,
68 [ASPEED_XDMA
] = 0x1E6E7000,
69 [ASPEED_ADC
] = 0x1E6E9000,
70 [ASPEED_VIDEO
] = 0x1E700000,
71 [ASPEED_SRAM
] = 0x1E720000,
72 [ASPEED_SDHCI
] = 0x1E740000,
73 [ASPEED_GPIO
] = 0x1E780000,
74 [ASPEED_RTC
] = 0x1E781000,
75 [ASPEED_TIMER1
] = 0x1E782000,
76 [ASPEED_WDT
] = 0x1E785000,
77 [ASPEED_PWM
] = 0x1E786000,
78 [ASPEED_LPC
] = 0x1E789000,
79 [ASPEED_IBT
] = 0x1E789140,
80 [ASPEED_I2C
] = 0x1E78A000,
81 [ASPEED_ETH1
] = 0x1E660000,
82 [ASPEED_ETH2
] = 0x1E680000,
83 [ASPEED_UART1
] = 0x1E783000,
84 [ASPEED_UART5
] = 0x1E784000,
85 [ASPEED_VUART
] = 0x1E787000,
86 [ASPEED_SDRAM
] = 0x80000000,
89 static const int aspeed_soc_ast2400_irqmap
[] = {
104 [ASPEED_TIMER1
] = 16,
105 [ASPEED_TIMER2
] = 17,
106 [ASPEED_TIMER3
] = 18,
107 [ASPEED_TIMER4
] = 35,
108 [ASPEED_TIMER5
] = 36,
109 [ASPEED_TIMER6
] = 37,
110 [ASPEED_TIMER7
] = 38,
111 [ASPEED_TIMER8
] = 39,
115 [ASPEED_IBT
] = 8, /* LPC */
123 #define aspeed_soc_ast2500_irqmap aspeed_soc_ast2400_irqmap
125 static qemu_irq
aspeed_soc_get_irq(AspeedSoCState
*s
, int ctrl
)
127 AspeedSoCClass
*sc
= ASPEED_SOC_GET_CLASS(s
);
129 return qdev_get_gpio_in(DEVICE(&s
->vic
), sc
->irqmap
[ctrl
]);
132 static void aspeed_soc_init(Object
*obj
)
134 AspeedSoCState
*s
= ASPEED_SOC(obj
);
135 AspeedSoCClass
*sc
= ASPEED_SOC_GET_CLASS(s
);
140 if (sscanf(sc
->name
, "%7s", socname
) != 1) {
141 g_assert_not_reached();
144 for (i
= 0; i
< sc
->num_cpus
; i
++) {
145 object_initialize_child(obj
, "cpu[*]", &s
->cpu
[i
], sc
->cpu_type
);
148 snprintf(typename
, sizeof(typename
), "aspeed.scu-%s", socname
);
149 object_initialize_child(obj
, "scu", &s
->scu
, typename
);
150 qdev_prop_set_uint32(DEVICE(&s
->scu
), "silicon-rev",
152 object_property_add_alias(obj
, "hw-strap1", OBJECT(&s
->scu
),
154 object_property_add_alias(obj
, "hw-strap2", OBJECT(&s
->scu
),
156 object_property_add_alias(obj
, "hw-prot-key", OBJECT(&s
->scu
),
159 object_initialize_child(obj
, "vic", &s
->vic
, TYPE_ASPEED_VIC
);
161 object_initialize_child(obj
, "rtc", &s
->rtc
, TYPE_ASPEED_RTC
);
163 snprintf(typename
, sizeof(typename
), "aspeed.timer-%s", socname
);
164 object_initialize_child(obj
, "timerctrl", &s
->timerctrl
, typename
);
166 snprintf(typename
, sizeof(typename
), "aspeed.i2c-%s", socname
);
167 object_initialize_child(obj
, "i2c", &s
->i2c
, typename
);
169 snprintf(typename
, sizeof(typename
), "aspeed.fmc-%s", socname
);
170 object_initialize_child(obj
, "fmc", &s
->fmc
, typename
);
171 object_property_add_alias(obj
, "num-cs", OBJECT(&s
->fmc
), "num-cs");
173 for (i
= 0; i
< sc
->spis_num
; i
++) {
174 snprintf(typename
, sizeof(typename
), "aspeed.spi%d-%s", i
+ 1, socname
);
175 object_initialize_child(obj
, "spi[*]", &s
->spi
[i
], typename
);
178 for (i
= 0; i
< sc
->ehcis_num
; i
++) {
179 object_initialize_child(obj
, "ehci[*]", &s
->ehci
[i
],
183 snprintf(typename
, sizeof(typename
), "aspeed.sdmc-%s", socname
);
184 object_initialize_child(obj
, "sdmc", &s
->sdmc
, typename
);
185 object_property_add_alias(obj
, "ram-size", OBJECT(&s
->sdmc
),
187 object_property_add_alias(obj
, "max-ram-size", OBJECT(&s
->sdmc
),
190 for (i
= 0; i
< sc
->wdts_num
; i
++) {
191 snprintf(typename
, sizeof(typename
), "aspeed.wdt-%s", socname
);
192 object_initialize_child(obj
, "wdt[*]", &s
->wdt
[i
], typename
);
195 for (i
= 0; i
< sc
->macs_num
; i
++) {
196 object_initialize_child(obj
, "ftgmac100[*]", &s
->ftgmac100
[i
],
200 object_initialize_child(obj
, "xdma", &s
->xdma
, TYPE_ASPEED_XDMA
);
202 snprintf(typename
, sizeof(typename
), "aspeed.gpio-%s", socname
);
203 object_initialize_child(obj
, "gpio", &s
->gpio
, typename
);
205 object_initialize_child(obj
, "sdc", &s
->sdhci
, TYPE_ASPEED_SDHCI
);
207 object_property_set_int(OBJECT(&s
->sdhci
), 2, "num-slots", &error_abort
);
209 /* Init sd card slot class here so that they're under the correct parent */
210 for (i
= 0; i
< ASPEED_SDHCI_NUM_SLOTS
; ++i
) {
211 object_initialize_child(obj
, "sdhci[*]", &s
->sdhci
.slots
[i
],
216 static void aspeed_soc_realize(DeviceState
*dev
, Error
**errp
)
219 AspeedSoCState
*s
= ASPEED_SOC(dev
);
220 AspeedSoCClass
*sc
= ASPEED_SOC_GET_CLASS(s
);
224 create_unimplemented_device("aspeed_soc.io", sc
->memmap
[ASPEED_IOMEM
],
225 ASPEED_SOC_IOMEM_SIZE
);
227 /* Video engine stub */
228 create_unimplemented_device("aspeed.video", sc
->memmap
[ASPEED_VIDEO
],
232 for (i
= 0; i
< sc
->num_cpus
; i
++) {
233 qdev_realize(DEVICE(&s
->cpu
[i
]), NULL
, &err
);
235 error_propagate(errp
, err
);
241 memory_region_init_ram(&s
->sram
, OBJECT(dev
), "aspeed.sram",
242 sc
->sram_size
, &err
);
244 error_propagate(errp
, err
);
247 memory_region_add_subregion(get_system_memory(),
248 sc
->memmap
[ASPEED_SRAM
], &s
->sram
);
251 sysbus_realize(SYS_BUS_DEVICE(&s
->scu
), &err
);
253 error_propagate(errp
, err
);
256 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->scu
), 0, sc
->memmap
[ASPEED_SCU
]);
259 sysbus_realize(SYS_BUS_DEVICE(&s
->vic
), &err
);
261 error_propagate(errp
, err
);
264 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->vic
), 0, sc
->memmap
[ASPEED_VIC
]);
265 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->vic
), 0,
266 qdev_get_gpio_in(DEVICE(&s
->cpu
), ARM_CPU_IRQ
));
267 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->vic
), 1,
268 qdev_get_gpio_in(DEVICE(&s
->cpu
), ARM_CPU_FIQ
));
271 sysbus_realize(SYS_BUS_DEVICE(&s
->rtc
), &err
);
273 error_propagate(errp
, err
);
276 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->rtc
), 0, sc
->memmap
[ASPEED_RTC
]);
277 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->rtc
), 0,
278 aspeed_soc_get_irq(s
, ASPEED_RTC
));
281 object_property_set_link(OBJECT(&s
->timerctrl
),
282 OBJECT(&s
->scu
), "scu", &error_abort
);
283 sysbus_realize(SYS_BUS_DEVICE(&s
->timerctrl
), &err
);
285 error_propagate(errp
, err
);
288 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->timerctrl
), 0,
289 sc
->memmap
[ASPEED_TIMER1
]);
290 for (i
= 0; i
< ASPEED_TIMER_NR_TIMERS
; i
++) {
291 qemu_irq irq
= aspeed_soc_get_irq(s
, ASPEED_TIMER1
+ i
);
292 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->timerctrl
), i
, irq
);
295 /* UART - attach an 8250 to the IO space as our UART5 */
297 qemu_irq uart5
= aspeed_soc_get_irq(s
, ASPEED_UART5
);
298 serial_mm_init(get_system_memory(), sc
->memmap
[ASPEED_UART5
], 2,
299 uart5
, 38400, serial_hd(0), DEVICE_LITTLE_ENDIAN
);
303 object_property_set_link(OBJECT(&s
->i2c
), OBJECT(s
->dram_mr
), "dram",
305 sysbus_realize(SYS_BUS_DEVICE(&s
->i2c
), &err
);
307 error_propagate(errp
, err
);
310 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->i2c
), 0, sc
->memmap
[ASPEED_I2C
]);
311 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->i2c
), 0,
312 aspeed_soc_get_irq(s
, ASPEED_I2C
));
314 /* FMC, The number of CS is set at the board level */
315 object_property_set_link(OBJECT(&s
->fmc
), OBJECT(s
->dram_mr
), "dram",
317 object_property_set_int(OBJECT(&s
->fmc
), sc
->memmap
[ASPEED_SDRAM
],
320 error_propagate(errp
, err
);
323 sysbus_realize(SYS_BUS_DEVICE(&s
->fmc
), &err
);
325 error_propagate(errp
, err
);
328 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->fmc
), 0, sc
->memmap
[ASPEED_FMC
]);
329 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->fmc
), 1,
330 s
->fmc
.ctrl
->flash_window_base
);
331 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->fmc
), 0,
332 aspeed_soc_get_irq(s
, ASPEED_FMC
));
335 for (i
= 0; i
< sc
->spis_num
; i
++) {
336 object_property_set_int(OBJECT(&s
->spi
[i
]), 1, "num-cs",
338 sysbus_realize(SYS_BUS_DEVICE(&s
->spi
[i
]), &err
);
340 error_propagate(errp
, err
);
343 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->spi
[i
]), 0,
344 sc
->memmap
[ASPEED_SPI1
+ i
]);
345 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->spi
[i
]), 1,
346 s
->spi
[i
].ctrl
->flash_window_base
);
350 for (i
= 0; i
< sc
->ehcis_num
; i
++) {
351 sysbus_realize(SYS_BUS_DEVICE(&s
->ehci
[i
]), &err
);
353 error_propagate(errp
, err
);
356 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->ehci
[i
]), 0,
357 sc
->memmap
[ASPEED_EHCI1
+ i
]);
358 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->ehci
[i
]), 0,
359 aspeed_soc_get_irq(s
, ASPEED_EHCI1
+ i
));
362 /* SDMC - SDRAM Memory Controller */
363 sysbus_realize(SYS_BUS_DEVICE(&s
->sdmc
), &err
);
365 error_propagate(errp
, err
);
368 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->sdmc
), 0, sc
->memmap
[ASPEED_SDMC
]);
371 for (i
= 0; i
< sc
->wdts_num
; i
++) {
372 AspeedWDTClass
*awc
= ASPEED_WDT_GET_CLASS(&s
->wdt
[i
]);
374 object_property_set_link(OBJECT(&s
->wdt
[i
]),
375 OBJECT(&s
->scu
), "scu", &error_abort
);
376 sysbus_realize(SYS_BUS_DEVICE(&s
->wdt
[i
]), &err
);
378 error_propagate(errp
, err
);
381 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->wdt
[i
]), 0,
382 sc
->memmap
[ASPEED_WDT
] + i
* awc
->offset
);
386 for (i
= 0; i
< sc
->macs_num
; i
++) {
387 object_property_set_bool(OBJECT(&s
->ftgmac100
[i
]), true, "aspeed",
389 sysbus_realize(SYS_BUS_DEVICE(&s
->ftgmac100
[i
]), &err
);
391 error_propagate(errp
, err
);
394 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->ftgmac100
[i
]), 0,
395 sc
->memmap
[ASPEED_ETH1
+ i
]);
396 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->ftgmac100
[i
]), 0,
397 aspeed_soc_get_irq(s
, ASPEED_ETH1
+ i
));
401 sysbus_realize(SYS_BUS_DEVICE(&s
->xdma
), &err
);
403 error_propagate(errp
, err
);
406 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->xdma
), 0,
407 sc
->memmap
[ASPEED_XDMA
]);
408 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->xdma
), 0,
409 aspeed_soc_get_irq(s
, ASPEED_XDMA
));
412 sysbus_realize(SYS_BUS_DEVICE(&s
->gpio
), &err
);
414 error_propagate(errp
, err
);
417 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->gpio
), 0, sc
->memmap
[ASPEED_GPIO
]);
418 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->gpio
), 0,
419 aspeed_soc_get_irq(s
, ASPEED_GPIO
));
422 sysbus_realize(SYS_BUS_DEVICE(&s
->sdhci
), &err
);
424 error_propagate(errp
, err
);
427 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->sdhci
), 0,
428 sc
->memmap
[ASPEED_SDHCI
]);
429 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->sdhci
), 0,
430 aspeed_soc_get_irq(s
, ASPEED_SDHCI
));
432 static Property aspeed_soc_properties
[] = {
433 DEFINE_PROP_LINK("dram", AspeedSoCState
, dram_mr
, TYPE_MEMORY_REGION
,
435 DEFINE_PROP_END_OF_LIST(),
438 static void aspeed_soc_class_init(ObjectClass
*oc
, void *data
)
440 DeviceClass
*dc
= DEVICE_CLASS(oc
);
442 dc
->realize
= aspeed_soc_realize
;
443 /* Reason: Uses serial_hds and nd_table in realize() directly */
444 dc
->user_creatable
= false;
445 device_class_set_props(dc
, aspeed_soc_properties
);
448 static const TypeInfo aspeed_soc_type_info
= {
449 .name
= TYPE_ASPEED_SOC
,
450 .parent
= TYPE_DEVICE
,
451 .instance_size
= sizeof(AspeedSoCState
),
452 .class_size
= sizeof(AspeedSoCClass
),
453 .class_init
= aspeed_soc_class_init
,
457 static void aspeed_soc_ast2400_class_init(ObjectClass
*oc
, void *data
)
459 AspeedSoCClass
*sc
= ASPEED_SOC_CLASS(oc
);
461 sc
->name
= "ast2400-a1";
462 sc
->cpu_type
= ARM_CPU_TYPE_NAME("arm926");
463 sc
->silicon_rev
= AST2400_A1_SILICON_REV
;
464 sc
->sram_size
= 0x8000;
469 sc
->irqmap
= aspeed_soc_ast2400_irqmap
;
470 sc
->memmap
= aspeed_soc_ast2400_memmap
;
474 static const TypeInfo aspeed_soc_ast2400_type_info
= {
475 .name
= "ast2400-a1",
476 .parent
= TYPE_ASPEED_SOC
,
477 .instance_init
= aspeed_soc_init
,
478 .instance_size
= sizeof(AspeedSoCState
),
479 .class_init
= aspeed_soc_ast2400_class_init
,
482 static void aspeed_soc_ast2500_class_init(ObjectClass
*oc
, void *data
)
484 AspeedSoCClass
*sc
= ASPEED_SOC_CLASS(oc
);
486 sc
->name
= "ast2500-a1";
487 sc
->cpu_type
= ARM_CPU_TYPE_NAME("arm1176");
488 sc
->silicon_rev
= AST2500_A1_SILICON_REV
;
489 sc
->sram_size
= 0x9000;
494 sc
->irqmap
= aspeed_soc_ast2500_irqmap
;
495 sc
->memmap
= aspeed_soc_ast2500_memmap
;
499 static const TypeInfo aspeed_soc_ast2500_type_info
= {
500 .name
= "ast2500-a1",
501 .parent
= TYPE_ASPEED_SOC
,
502 .instance_init
= aspeed_soc_init
,
503 .instance_size
= sizeof(AspeedSoCState
),
504 .class_init
= aspeed_soc_ast2500_class_init
,
506 static void aspeed_soc_register_types(void)
508 type_register_static(&aspeed_soc_type_info
);
509 type_register_static(&aspeed_soc_ast2400_type_info
);
510 type_register_static(&aspeed_soc_ast2500_type_info
);
513 type_init(aspeed_soc_register_types
)