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
), "num-slots", 2, &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 if (!qdev_realize(DEVICE(&s
->cpu
[i
]), NULL
, errp
)) {
239 memory_region_init_ram(&s
->sram
, OBJECT(dev
), "aspeed.sram",
240 sc
->sram_size
, &err
);
242 error_propagate(errp
, err
);
245 memory_region_add_subregion(get_system_memory(),
246 sc
->memmap
[ASPEED_SRAM
], &s
->sram
);
249 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->scu
), errp
)) {
252 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->scu
), 0, sc
->memmap
[ASPEED_SCU
]);
255 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->vic
), errp
)) {
258 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->vic
), 0, sc
->memmap
[ASPEED_VIC
]);
259 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->vic
), 0,
260 qdev_get_gpio_in(DEVICE(&s
->cpu
), ARM_CPU_IRQ
));
261 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->vic
), 1,
262 qdev_get_gpio_in(DEVICE(&s
->cpu
), ARM_CPU_FIQ
));
265 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->rtc
), errp
)) {
268 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->rtc
), 0, sc
->memmap
[ASPEED_RTC
]);
269 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->rtc
), 0,
270 aspeed_soc_get_irq(s
, ASPEED_RTC
));
273 object_property_set_link(OBJECT(&s
->timerctrl
), "scu", OBJECT(&s
->scu
),
275 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->timerctrl
), errp
)) {
278 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->timerctrl
), 0,
279 sc
->memmap
[ASPEED_TIMER1
]);
280 for (i
= 0; i
< ASPEED_TIMER_NR_TIMERS
; i
++) {
281 qemu_irq irq
= aspeed_soc_get_irq(s
, ASPEED_TIMER1
+ i
);
282 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->timerctrl
), i
, irq
);
285 /* UART - attach an 8250 to the IO space as our UART5 */
287 qemu_irq uart5
= aspeed_soc_get_irq(s
, ASPEED_UART5
);
288 serial_mm_init(get_system_memory(), sc
->memmap
[ASPEED_UART5
], 2,
289 uart5
, 38400, serial_hd(0), DEVICE_LITTLE_ENDIAN
);
293 object_property_set_link(OBJECT(&s
->i2c
), "dram", OBJECT(s
->dram_mr
),
295 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->i2c
), errp
)) {
298 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->i2c
), 0, sc
->memmap
[ASPEED_I2C
]);
299 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->i2c
), 0,
300 aspeed_soc_get_irq(s
, ASPEED_I2C
));
302 /* FMC, The number of CS is set at the board level */
303 object_property_set_link(OBJECT(&s
->fmc
), "dram", OBJECT(s
->dram_mr
),
305 if (!object_property_set_int(OBJECT(&s
->fmc
), "sdram-base",
306 sc
->memmap
[ASPEED_SDRAM
], errp
)) {
309 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->fmc
), errp
)) {
312 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->fmc
), 0, sc
->memmap
[ASPEED_FMC
]);
313 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->fmc
), 1,
314 s
->fmc
.ctrl
->flash_window_base
);
315 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->fmc
), 0,
316 aspeed_soc_get_irq(s
, ASPEED_FMC
));
319 for (i
= 0; i
< sc
->spis_num
; i
++) {
320 object_property_set_int(OBJECT(&s
->spi
[i
]), "num-cs", 1, &error_abort
);
321 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->spi
[i
]), errp
)) {
324 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->spi
[i
]), 0,
325 sc
->memmap
[ASPEED_SPI1
+ i
]);
326 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->spi
[i
]), 1,
327 s
->spi
[i
].ctrl
->flash_window_base
);
331 for (i
= 0; i
< sc
->ehcis_num
; i
++) {
332 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->ehci
[i
]), errp
)) {
335 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->ehci
[i
]), 0,
336 sc
->memmap
[ASPEED_EHCI1
+ i
]);
337 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->ehci
[i
]), 0,
338 aspeed_soc_get_irq(s
, ASPEED_EHCI1
+ i
));
341 /* SDMC - SDRAM Memory Controller */
342 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->sdmc
), errp
)) {
345 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->sdmc
), 0, sc
->memmap
[ASPEED_SDMC
]);
348 for (i
= 0; i
< sc
->wdts_num
; i
++) {
349 AspeedWDTClass
*awc
= ASPEED_WDT_GET_CLASS(&s
->wdt
[i
]);
351 object_property_set_link(OBJECT(&s
->wdt
[i
]), "scu", OBJECT(&s
->scu
),
353 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->wdt
[i
]), errp
)) {
356 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->wdt
[i
]), 0,
357 sc
->memmap
[ASPEED_WDT
] + i
* awc
->offset
);
361 for (i
= 0; i
< sc
->macs_num
; i
++) {
362 object_property_set_bool(OBJECT(&s
->ftgmac100
[i
]), "aspeed", true,
364 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->ftgmac100
[i
]), errp
)) {
367 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->ftgmac100
[i
]), 0,
368 sc
->memmap
[ASPEED_ETH1
+ i
]);
369 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->ftgmac100
[i
]), 0,
370 aspeed_soc_get_irq(s
, ASPEED_ETH1
+ i
));
374 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->xdma
), errp
)) {
377 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->xdma
), 0,
378 sc
->memmap
[ASPEED_XDMA
]);
379 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->xdma
), 0,
380 aspeed_soc_get_irq(s
, ASPEED_XDMA
));
383 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->gpio
), errp
)) {
386 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->gpio
), 0, sc
->memmap
[ASPEED_GPIO
]);
387 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->gpio
), 0,
388 aspeed_soc_get_irq(s
, ASPEED_GPIO
));
391 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->sdhci
), errp
)) {
394 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->sdhci
), 0,
395 sc
->memmap
[ASPEED_SDHCI
]);
396 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->sdhci
), 0,
397 aspeed_soc_get_irq(s
, ASPEED_SDHCI
));
399 static Property aspeed_soc_properties
[] = {
400 DEFINE_PROP_LINK("dram", AspeedSoCState
, dram_mr
, TYPE_MEMORY_REGION
,
402 DEFINE_PROP_END_OF_LIST(),
405 static void aspeed_soc_class_init(ObjectClass
*oc
, void *data
)
407 DeviceClass
*dc
= DEVICE_CLASS(oc
);
409 dc
->realize
= aspeed_soc_realize
;
410 /* Reason: Uses serial_hds and nd_table in realize() directly */
411 dc
->user_creatable
= false;
412 device_class_set_props(dc
, aspeed_soc_properties
);
415 static const TypeInfo aspeed_soc_type_info
= {
416 .name
= TYPE_ASPEED_SOC
,
417 .parent
= TYPE_DEVICE
,
418 .instance_size
= sizeof(AspeedSoCState
),
419 .class_size
= sizeof(AspeedSoCClass
),
420 .class_init
= aspeed_soc_class_init
,
424 static void aspeed_soc_ast2400_class_init(ObjectClass
*oc
, void *data
)
426 AspeedSoCClass
*sc
= ASPEED_SOC_CLASS(oc
);
428 sc
->name
= "ast2400-a1";
429 sc
->cpu_type
= ARM_CPU_TYPE_NAME("arm926");
430 sc
->silicon_rev
= AST2400_A1_SILICON_REV
;
431 sc
->sram_size
= 0x8000;
436 sc
->irqmap
= aspeed_soc_ast2400_irqmap
;
437 sc
->memmap
= aspeed_soc_ast2400_memmap
;
441 static const TypeInfo aspeed_soc_ast2400_type_info
= {
442 .name
= "ast2400-a1",
443 .parent
= TYPE_ASPEED_SOC
,
444 .instance_init
= aspeed_soc_init
,
445 .instance_size
= sizeof(AspeedSoCState
),
446 .class_init
= aspeed_soc_ast2400_class_init
,
449 static void aspeed_soc_ast2500_class_init(ObjectClass
*oc
, void *data
)
451 AspeedSoCClass
*sc
= ASPEED_SOC_CLASS(oc
);
453 sc
->name
= "ast2500-a1";
454 sc
->cpu_type
= ARM_CPU_TYPE_NAME("arm1176");
455 sc
->silicon_rev
= AST2500_A1_SILICON_REV
;
456 sc
->sram_size
= 0x9000;
461 sc
->irqmap
= aspeed_soc_ast2500_irqmap
;
462 sc
->memmap
= aspeed_soc_ast2500_memmap
;
466 static const TypeInfo aspeed_soc_ast2500_type_info
= {
467 .name
= "ast2500-a1",
468 .parent
= TYPE_ASPEED_SOC
,
469 .instance_init
= aspeed_soc_init
,
470 .instance_size
= sizeof(AspeedSoCState
),
471 .class_init
= aspeed_soc_ast2500_class_init
,
473 static void aspeed_soc_register_types(void)
475 type_register_static(&aspeed_soc_type_info
);
476 type_register_static(&aspeed_soc_ast2400_type_info
);
477 type_register_static(&aspeed_soc_ast2500_type_info
);
480 type_init(aspeed_soc_register_types
)