1 /* 2 * ASPEED SoC family 3 * 4 * Andrew Jeffery <andrew@aj.id.au> 5 * Jeremy Kerr <jk@ozlabs.org> 6 * 7 * Copyright 2016 IBM Corp. 8 * 9 * This code is licensed under the GPL version 2 or later. See 10 * the COPYING file in the top-level directory. 11 */ 12 13 #include "qemu/osdep.h" 14 #include "qemu/units.h" 15 #include "qapi/error.h" 16 #include "hw/misc/unimp.h" 17 #include "hw/arm/aspeed_soc.h" 18 #include "hw/char/serial-mm.h" 19 #include "qemu/module.h" 20 #include "qemu/error-report.h" 21 #include "hw/i2c/aspeed_i2c.h" 22 #include "net/net.h" 23 #include "sysemu/sysemu.h" 24 #include "target/arm/cpu-qom.h" 25 26 #define ASPEED_SOC_IOMEM_SIZE 0x00200000 27 28 static const hwaddr aspeed_soc_ast2400_memmap[] = { 29 [ASPEED_DEV_SPI_BOOT] = 0x00000000, 30 [ASPEED_DEV_IOMEM] = 0x1E600000, 31 [ASPEED_DEV_FMC] = 0x1E620000, 32 [ASPEED_DEV_SPI1] = 0x1E630000, 33 [ASPEED_DEV_EHCI1] = 0x1E6A1000, 34 [ASPEED_DEV_UHCI] = 0x1E6B0000, 35 [ASPEED_DEV_VIC] = 0x1E6C0000, 36 [ASPEED_DEV_SDMC] = 0x1E6E0000, 37 [ASPEED_DEV_SCU] = 0x1E6E2000, 38 [ASPEED_DEV_HACE] = 0x1E6E3000, 39 [ASPEED_DEV_GFX] = 0x1E6E6000, 40 [ASPEED_DEV_XDMA] = 0x1E6E7000, 41 [ASPEED_DEV_VIDEO] = 0x1E700000, 42 [ASPEED_DEV_ADC] = 0x1E6E9000, 43 [ASPEED_DEV_SRAM] = 0x1E720000, 44 [ASPEED_DEV_SDHCI] = 0x1E740000, 45 [ASPEED_DEV_GPIO] = 0x1E780000, 46 [ASPEED_DEV_RTC] = 0x1E781000, 47 [ASPEED_DEV_TIMER1] = 0x1E782000, 48 [ASPEED_DEV_WDT] = 0x1E785000, 49 [ASPEED_DEV_PWM] = 0x1E786000, 50 [ASPEED_DEV_LPC] = 0x1E789000, 51 [ASPEED_DEV_IBT] = 0x1E789140, 52 [ASPEED_DEV_I2C] = 0x1E78A000, 53 [ASPEED_DEV_PECI] = 0x1E78B000, 54 [ASPEED_DEV_ETH1] = 0x1E660000, 55 [ASPEED_DEV_ETH2] = 0x1E680000, 56 [ASPEED_DEV_UART1] = 0x1E783000, 57 [ASPEED_DEV_UART2] = 0x1E78D000, 58 [ASPEED_DEV_UART3] = 0x1E78E000, 59 [ASPEED_DEV_UART4] = 0x1E78F000, 60 [ASPEED_DEV_UART5] = 0x1E784000, 61 [ASPEED_DEV_VUART] = 0x1E787000, 62 [ASPEED_DEV_SDRAM] = 0x40000000, 63 }; 64 65 static const hwaddr aspeed_soc_ast2500_memmap[] = { 66 [ASPEED_DEV_SPI_BOOT] = 0x00000000, 67 [ASPEED_DEV_IOMEM] = 0x1E600000, 68 [ASPEED_DEV_FMC] = 0x1E620000, 69 [ASPEED_DEV_SPI1] = 0x1E630000, 70 [ASPEED_DEV_SPI2] = 0x1E631000, 71 [ASPEED_DEV_EHCI1] = 0x1E6A1000, 72 [ASPEED_DEV_EHCI2] = 0x1E6A3000, 73 [ASPEED_DEV_UHCI] = 0x1E6B0000, 74 [ASPEED_DEV_VIC] = 0x1E6C0000, 75 [ASPEED_DEV_SDMC] = 0x1E6E0000, 76 [ASPEED_DEV_SCU] = 0x1E6E2000, 77 [ASPEED_DEV_HACE] = 0x1E6E3000, 78 [ASPEED_DEV_GFX] = 0x1E6E6000, 79 [ASPEED_DEV_XDMA] = 0x1E6E7000, 80 [ASPEED_DEV_ADC] = 0x1E6E9000, 81 [ASPEED_DEV_VIDEO] = 0x1E700000, 82 [ASPEED_DEV_SRAM] = 0x1E720000, 83 [ASPEED_DEV_SDHCI] = 0x1E740000, 84 [ASPEED_DEV_GPIO] = 0x1E780000, 85 [ASPEED_DEV_RTC] = 0x1E781000, 86 [ASPEED_DEV_TIMER1] = 0x1E782000, 87 [ASPEED_DEV_WDT] = 0x1E785000, 88 [ASPEED_DEV_PWM] = 0x1E786000, 89 [ASPEED_DEV_LPC] = 0x1E789000, 90 [ASPEED_DEV_IBT] = 0x1E789140, 91 [ASPEED_DEV_I2C] = 0x1E78A000, 92 [ASPEED_DEV_PECI] = 0x1E78B000, 93 [ASPEED_DEV_ETH1] = 0x1E660000, 94 [ASPEED_DEV_ETH2] = 0x1E680000, 95 [ASPEED_DEV_UART1] = 0x1E783000, 96 [ASPEED_DEV_UART2] = 0x1E78D000, 97 [ASPEED_DEV_UART3] = 0x1E78E000, 98 [ASPEED_DEV_UART4] = 0x1E78F000, 99 [ASPEED_DEV_UART5] = 0x1E784000, 100 [ASPEED_DEV_VUART] = 0x1E787000, 101 [ASPEED_DEV_SDRAM] = 0x80000000, 102 }; 103 104 static const int aspeed_soc_ast2400_irqmap[] = { 105 [ASPEED_DEV_UART1] = 9, 106 [ASPEED_DEV_UART2] = 32, 107 [ASPEED_DEV_UART3] = 33, 108 [ASPEED_DEV_UART4] = 34, 109 [ASPEED_DEV_UART5] = 10, 110 [ASPEED_DEV_VUART] = 8, 111 [ASPEED_DEV_FMC] = 19, 112 [ASPEED_DEV_EHCI1] = 5, 113 [ASPEED_DEV_EHCI2] = 13, 114 [ASPEED_DEV_UHCI] = 14, 115 [ASPEED_DEV_SDMC] = 0, 116 [ASPEED_DEV_SCU] = 21, 117 [ASPEED_DEV_ADC] = 31, 118 [ASPEED_DEV_GFX] = 25, 119 [ASPEED_DEV_GPIO] = 20, 120 [ASPEED_DEV_RTC] = 22, 121 [ASPEED_DEV_TIMER1] = 16, 122 [ASPEED_DEV_TIMER2] = 17, 123 [ASPEED_DEV_TIMER3] = 18, 124 [ASPEED_DEV_TIMER4] = 35, 125 [ASPEED_DEV_TIMER5] = 36, 126 [ASPEED_DEV_TIMER6] = 37, 127 [ASPEED_DEV_TIMER7] = 38, 128 [ASPEED_DEV_TIMER8] = 39, 129 [ASPEED_DEV_WDT] = 27, 130 [ASPEED_DEV_PWM] = 28, 131 [ASPEED_DEV_LPC] = 8, 132 [ASPEED_DEV_I2C] = 12, 133 [ASPEED_DEV_PECI] = 15, 134 [ASPEED_DEV_ETH1] = 2, 135 [ASPEED_DEV_ETH2] = 3, 136 [ASPEED_DEV_XDMA] = 6, 137 [ASPEED_DEV_SDHCI] = 26, 138 [ASPEED_DEV_HACE] = 4, 139 }; 140 141 #define aspeed_soc_ast2500_irqmap aspeed_soc_ast2400_irqmap 142 143 static qemu_irq aspeed_soc_ast2400_get_irq(AspeedSoCState *s, int dev) 144 { 145 Aspeed2400SoCState *a = ASPEED2400_SOC(s); 146 AspeedSoCClass *sc = ASPEED_SOC_GET_CLASS(s); 147 148 return qdev_get_gpio_in(DEVICE(&a->vic), sc->irqmap[dev]); 149 } 150 151 static void aspeed_ast2400_soc_init(Object *obj) 152 { 153 Aspeed2400SoCState *a = ASPEED2400_SOC(obj); 154 AspeedSoCState *s = ASPEED_SOC(obj); 155 AspeedSoCClass *sc = ASPEED_SOC_GET_CLASS(s); 156 int i; 157 char socname[8]; 158 char typename[64]; 159 160 if (sscanf(sc->name, "%7s", socname) != 1) { 161 g_assert_not_reached(); 162 } 163 164 for (i = 0; i < sc->num_cpus; i++) { 165 object_initialize_child(obj, "cpu[*]", &a->cpu[i], 166 aspeed_soc_cpu_type(sc)); 167 } 168 169 snprintf(typename, sizeof(typename), "aspeed.scu-%s", socname); 170 object_initialize_child(obj, "scu", &s->scu, typename); 171 qdev_prop_set_uint32(DEVICE(&s->scu), "silicon-rev", 172 sc->silicon_rev); 173 object_property_add_alias(obj, "hw-strap1", OBJECT(&s->scu), 174 "hw-strap1"); 175 object_property_add_alias(obj, "hw-strap2", OBJECT(&s->scu), 176 "hw-strap2"); 177 object_property_add_alias(obj, "hw-prot-key", OBJECT(&s->scu), 178 "hw-prot-key"); 179 180 object_initialize_child(obj, "vic", &a->vic, TYPE_ASPEED_VIC); 181 182 object_initialize_child(obj, "rtc", &s->rtc, TYPE_ASPEED_RTC); 183 184 snprintf(typename, sizeof(typename), "aspeed.timer-%s", socname); 185 object_initialize_child(obj, "timerctrl", &s->timerctrl, typename); 186 187 for (i = 0; i < sc->wdts_num; i++) { 188 snprintf(typename, sizeof(typename), "aspeed.wdt-%s", socname); 189 object_initialize_child(obj, "wdt[*]", &s->wdt[i], typename); 190 } 191 192 snprintf(typename, sizeof(typename), "aspeed.adc-%s", socname); 193 object_initialize_child(obj, "adc", &s->adc, typename); 194 195 snprintf(typename, sizeof(typename), "aspeed.i2c-%s", socname); 196 object_initialize_child(obj, "i2c", &s->i2c, typename); 197 198 object_initialize_child(obj, "peci", &s->peci, TYPE_ASPEED_PECI); 199 200 snprintf(typename, sizeof(typename), "aspeed.fmc-%s", socname); 201 object_initialize_child(obj, "fmc", &s->fmc, typename); 202 203 for (i = 0; i < sc->spis_num; i++) { 204 snprintf(typename, sizeof(typename), "aspeed.spi%d-%s", i + 1, socname); 205 object_initialize_child(obj, "spi[*]", &s->spi[i], typename); 206 } 207 208 for (i = 0; i < sc->ehcis_num; i++) { 209 object_initialize_child(obj, "ehci[*]", &s->ehci[i], 210 TYPE_PLATFORM_EHCI); 211 } 212 213 object_initialize_child(obj, "uhci", &s->uhci, TYPE_ASPEED_UHCI); 214 215 snprintf(typename, sizeof(typename), "aspeed.sdmc-%s", socname); 216 object_initialize_child(obj, "sdmc", &s->sdmc, typename); 217 object_property_add_alias(obj, "ram-size", OBJECT(&s->sdmc), 218 "ram-size"); 219 220 for (i = 0; i < sc->macs_num; i++) { 221 object_initialize_child(obj, "ftgmac100[*]", &s->ftgmac100[i], 222 TYPE_FTGMAC100); 223 } 224 225 for (i = 0; i < sc->uarts_num; i++) { 226 object_initialize_child(obj, "uart[*]", &s->uart[i], TYPE_SERIAL_MM); 227 } 228 229 snprintf(typename, sizeof(typename), TYPE_ASPEED_XDMA "-%s", socname); 230 object_initialize_child(obj, "xdma", &s->xdma, typename); 231 232 snprintf(typename, sizeof(typename), "aspeed.gpio-%s", socname); 233 object_initialize_child(obj, "gpio", &s->gpio, typename); 234 235 object_initialize_child(obj, "sdc", &s->sdhci, TYPE_ASPEED_SDHCI); 236 237 object_property_set_int(OBJECT(&s->sdhci), "num-slots", 2, &error_abort); 238 239 /* Init sd card slot class here so that they're under the correct parent */ 240 for (i = 0; i < ASPEED_SDHCI_NUM_SLOTS; ++i) { 241 object_initialize_child(obj, "sdhci[*]", &s->sdhci.slots[i], 242 TYPE_SYSBUS_SDHCI); 243 } 244 245 object_initialize_child(obj, "lpc", &s->lpc, TYPE_ASPEED_LPC); 246 247 object_initialize_child(obj, "ibt", &s->ibt, TYPE_ASPEED_IBT); 248 249 snprintf(typename, sizeof(typename), "aspeed.hace-%s", socname); 250 object_initialize_child(obj, "hace", &s->hace, typename); 251 252 object_initialize_child(obj, "gfx", &s->gfx, TYPE_ASPEED_GFX); 253 254 object_initialize_child(obj, "iomem", &s->iomem, TYPE_UNIMPLEMENTED_DEVICE); 255 object_initialize_child(obj, "video", &s->video, TYPE_UNIMPLEMENTED_DEVICE); 256 257 object_initialize_child(obj, "pwm", &s->pwm, TYPE_ASPEED_PWM); 258 } 259 260 static void aspeed_ast2400_soc_realize(DeviceState *dev, Error **errp) 261 { 262 int i; 263 Aspeed2400SoCState *a = ASPEED2400_SOC(dev); 264 AspeedSoCState *s = ASPEED_SOC(dev); 265 AspeedSoCClass *sc = ASPEED_SOC_GET_CLASS(s); 266 g_autofree char *sram_name = NULL; 267 268 /* Default boot region (SPI memory or ROMs) */ 269 memory_region_init(&s->spi_boot_container, OBJECT(s), 270 "aspeed.spi_boot_container", 0x10000000); 271 memory_region_add_subregion(s->memory, sc->memmap[ASPEED_DEV_SPI_BOOT], 272 &s->spi_boot_container); 273 274 /* IO space */ 275 aspeed_mmio_map_unimplemented(s, SYS_BUS_DEVICE(&s->iomem), "aspeed.io", 276 sc->memmap[ASPEED_DEV_IOMEM], 277 ASPEED_SOC_IOMEM_SIZE); 278 279 /* Video engine stub */ 280 aspeed_mmio_map_unimplemented(s, SYS_BUS_DEVICE(&s->video), "aspeed.video", 281 sc->memmap[ASPEED_DEV_VIDEO], 0x1000); 282 283 /* CPU */ 284 for (i = 0; i < sc->num_cpus; i++) { 285 object_property_set_link(OBJECT(&a->cpu[i]), "memory", 286 OBJECT(s->memory), &error_abort); 287 if (!qdev_realize(DEVICE(&a->cpu[i]), NULL, errp)) { 288 return; 289 } 290 } 291 292 /* SRAM */ 293 sram_name = g_strdup_printf("aspeed.sram.%d", CPU(&a->cpu[0])->cpu_index); 294 if (!memory_region_init_ram(&s->sram, OBJECT(s), sram_name, sc->sram_size, 295 errp)) { 296 return; 297 } 298 memory_region_add_subregion(s->memory, 299 sc->memmap[ASPEED_DEV_SRAM], &s->sram); 300 301 /* SCU */ 302 if (!sysbus_realize(SYS_BUS_DEVICE(&s->scu), errp)) { 303 return; 304 } 305 aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->scu), 0, sc->memmap[ASPEED_DEV_SCU]); 306 307 /* VIC */ 308 if (!sysbus_realize(SYS_BUS_DEVICE(&a->vic), errp)) { 309 return; 310 } 311 aspeed_mmio_map(s, SYS_BUS_DEVICE(&a->vic), 0, sc->memmap[ASPEED_DEV_VIC]); 312 sysbus_connect_irq(SYS_BUS_DEVICE(&a->vic), 0, 313 qdev_get_gpio_in(DEVICE(&a->cpu), ARM_CPU_IRQ)); 314 sysbus_connect_irq(SYS_BUS_DEVICE(&a->vic), 1, 315 qdev_get_gpio_in(DEVICE(&a->cpu), ARM_CPU_FIQ)); 316 317 /* RTC */ 318 if (!sysbus_realize(SYS_BUS_DEVICE(&s->rtc), errp)) { 319 return; 320 } 321 aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->rtc), 0, sc->memmap[ASPEED_DEV_RTC]); 322 sysbus_connect_irq(SYS_BUS_DEVICE(&s->rtc), 0, 323 aspeed_soc_get_irq(s, ASPEED_DEV_RTC)); 324 325 /* Timer */ 326 object_property_set_link(OBJECT(&s->timerctrl), "scu", OBJECT(&s->scu), 327 &error_abort); 328 if (!sysbus_realize(SYS_BUS_DEVICE(&s->timerctrl), errp)) { 329 return; 330 } 331 aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->timerctrl), 0, 332 sc->memmap[ASPEED_DEV_TIMER1]); 333 for (i = 0; i < ASPEED_TIMER_NR_TIMERS; i++) { 334 qemu_irq irq = aspeed_soc_get_irq(s, ASPEED_DEV_TIMER1 + i); 335 sysbus_connect_irq(SYS_BUS_DEVICE(&s->timerctrl), i, irq); 336 } 337 338 /* Watch dog */ 339 for (i = 0; i < sc->wdts_num; i++) { 340 AspeedWDTClass *awc = ASPEED_WDT_GET_CLASS(&s->wdt[i]); 341 342 object_property_set_link(OBJECT(&s->wdt[i]), "scu", OBJECT(&s->scu), 343 &error_abort); 344 if (!sysbus_realize(SYS_BUS_DEVICE(&s->wdt[i]), errp)) { 345 return; 346 } 347 aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->wdt[i]), 0, 348 sc->memmap[ASPEED_DEV_WDT] + i * awc->iosize); 349 } 350 351 /* ADC */ 352 if (!sysbus_realize(SYS_BUS_DEVICE(&s->adc), errp)) { 353 return; 354 } 355 aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->adc), 0, sc->memmap[ASPEED_DEV_ADC]); 356 sysbus_connect_irq(SYS_BUS_DEVICE(&s->adc), 0, 357 aspeed_soc_get_irq(s, ASPEED_DEV_ADC)); 358 359 /* UART */ 360 if (!aspeed_soc_uart_realize(s, errp)) { 361 return; 362 } 363 364 /* I2C */ 365 object_property_set_link(OBJECT(&s->i2c), "dram", OBJECT(s->dram_mr), 366 &error_abort); 367 if (!sysbus_realize(SYS_BUS_DEVICE(&s->i2c), errp)) { 368 return; 369 } 370 aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->i2c), 0, sc->memmap[ASPEED_DEV_I2C]); 371 sysbus_connect_irq(SYS_BUS_DEVICE(&s->i2c), 0, 372 aspeed_soc_get_irq(s, ASPEED_DEV_I2C)); 373 374 /* PECI */ 375 if (!sysbus_realize(SYS_BUS_DEVICE(&s->peci), errp)) { 376 return; 377 } 378 aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->peci), 0, 379 sc->memmap[ASPEED_DEV_PECI]); 380 sysbus_connect_irq(SYS_BUS_DEVICE(&s->peci), 0, 381 aspeed_soc_get_irq(s, ASPEED_DEV_PECI)); 382 383 /* FMC, The number of CS is set at the board level */ 384 object_property_set_link(OBJECT(&s->fmc), "dram", OBJECT(s->dram_mr), 385 &error_abort); 386 if (!sysbus_realize(SYS_BUS_DEVICE(&s->fmc), errp)) { 387 return; 388 } 389 aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->fmc), 0, sc->memmap[ASPEED_DEV_FMC]); 390 aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->fmc), 1, 391 ASPEED_SMC_GET_CLASS(&s->fmc)->flash_window_base); 392 sysbus_connect_irq(SYS_BUS_DEVICE(&s->fmc), 0, 393 aspeed_soc_get_irq(s, ASPEED_DEV_FMC)); 394 395 /* Set up an alias on the FMC CE0 region (boot default) */ 396 MemoryRegion *fmc0_mmio = &s->fmc.flashes[0].mmio; 397 memory_region_init_alias(&s->spi_boot, OBJECT(s), "aspeed.spi_boot", 398 fmc0_mmio, 0, memory_region_size(fmc0_mmio)); 399 memory_region_add_subregion(&s->spi_boot_container, 0x0, &s->spi_boot); 400 401 /* SPI */ 402 for (i = 0; i < sc->spis_num; i++) { 403 if (!sysbus_realize(SYS_BUS_DEVICE(&s->spi[i]), errp)) { 404 return; 405 } 406 aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->spi[i]), 0, 407 sc->memmap[ASPEED_DEV_SPI1 + i]); 408 aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->spi[i]), 1, 409 ASPEED_SMC_GET_CLASS(&s->spi[i])->flash_window_base); 410 } 411 412 /* EHCI */ 413 for (i = 0; i < sc->ehcis_num; i++) { 414 if (!sysbus_realize(SYS_BUS_DEVICE(&s->ehci[i]), errp)) { 415 return; 416 } 417 aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->ehci[i]), 0, 418 sc->memmap[ASPEED_DEV_EHCI1 + i]); 419 sysbus_connect_irq(SYS_BUS_DEVICE(&s->ehci[i]), 0, 420 aspeed_soc_get_irq(s, ASPEED_DEV_EHCI1 + i)); 421 } 422 423 /* UHCI */ 424 if (!sysbus_realize(SYS_BUS_DEVICE(&s->uhci), errp)) { 425 return; 426 } 427 aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->uhci), 0, 428 sc->memmap[ASPEED_DEV_UHCI]); 429 sysbus_connect_irq(SYS_BUS_DEVICE(&s->uhci), 0, 430 aspeed_soc_get_irq(s, ASPEED_DEV_UHCI)); 431 432 /* SDMC - SDRAM Memory Controller */ 433 if (!sysbus_realize(SYS_BUS_DEVICE(&s->sdmc), errp)) { 434 return; 435 } 436 aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->sdmc), 0, 437 sc->memmap[ASPEED_DEV_SDMC]); 438 439 /* RAM */ 440 if (!aspeed_soc_dram_init(s, errp)) { 441 return; 442 } 443 444 /* Net */ 445 for (i = 0; i < sc->macs_num; i++) { 446 object_property_set_bool(OBJECT(&s->ftgmac100[i]), "aspeed", true, 447 &error_abort); 448 if (!sysbus_realize(SYS_BUS_DEVICE(&s->ftgmac100[i]), errp)) { 449 return; 450 } 451 aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->ftgmac100[i]), 0, 452 sc->memmap[ASPEED_DEV_ETH1 + i]); 453 sysbus_connect_irq(SYS_BUS_DEVICE(&s->ftgmac100[i]), 0, 454 aspeed_soc_get_irq(s, ASPEED_DEV_ETH1 + i)); 455 } 456 457 /* XDMA */ 458 if (!sysbus_realize(SYS_BUS_DEVICE(&s->xdma), errp)) { 459 return; 460 } 461 aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->xdma), 0, 462 sc->memmap[ASPEED_DEV_XDMA]); 463 sysbus_connect_irq(SYS_BUS_DEVICE(&s->xdma), 0, 464 aspeed_soc_get_irq(s, ASPEED_DEV_XDMA)); 465 466 /* GPIO */ 467 if (!sysbus_realize(SYS_BUS_DEVICE(&s->gpio), errp)) { 468 return; 469 } 470 aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->gpio), 0, 471 sc->memmap[ASPEED_DEV_GPIO]); 472 sysbus_connect_irq(SYS_BUS_DEVICE(&s->gpio), 0, 473 aspeed_soc_get_irq(s, ASPEED_DEV_GPIO)); 474 475 /* SDHCI */ 476 if (!sysbus_realize(SYS_BUS_DEVICE(&s->sdhci), errp)) { 477 return; 478 } 479 aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->sdhci), 0, 480 sc->memmap[ASPEED_DEV_SDHCI]); 481 sysbus_connect_irq(SYS_BUS_DEVICE(&s->sdhci), 0, 482 aspeed_soc_get_irq(s, ASPEED_DEV_SDHCI)); 483 484 /* LPC */ 485 if (!sysbus_realize(SYS_BUS_DEVICE(&s->lpc), errp)) { 486 return; 487 } 488 aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->lpc), 0, sc->memmap[ASPEED_DEV_LPC]); 489 490 /* Connect the LPC IRQ to the VIC */ 491 sysbus_connect_irq(SYS_BUS_DEVICE(&s->lpc), 0, 492 aspeed_soc_get_irq(s, ASPEED_DEV_LPC)); 493 494 /* 495 * On the AST2400 and AST2500 the one LPC IRQ is shared between all of the 496 * subdevices. Connect the LPC subdevice IRQs to the LPC controller IRQ (by 497 * contrast, on the AST2600, the subdevice IRQs are connected straight to 498 * the GIC). 499 * 500 * LPC subdevice IRQ sources are offset from 1 because the shared IRQ output 501 * to the VIC is at offset 0. 502 */ 503 sysbus_connect_irq(SYS_BUS_DEVICE(&s->lpc), 1 + aspeed_lpc_kcs_1, 504 qdev_get_gpio_in(DEVICE(&s->lpc), aspeed_lpc_kcs_1)); 505 506 sysbus_connect_irq(SYS_BUS_DEVICE(&s->lpc), 1 + aspeed_lpc_kcs_2, 507 qdev_get_gpio_in(DEVICE(&s->lpc), aspeed_lpc_kcs_2)); 508 509 sysbus_connect_irq(SYS_BUS_DEVICE(&s->lpc), 1 + aspeed_lpc_kcs_3, 510 qdev_get_gpio_in(DEVICE(&s->lpc), aspeed_lpc_kcs_3)); 511 512 sysbus_connect_irq(SYS_BUS_DEVICE(&s->lpc), 1 + aspeed_lpc_kcs_4, 513 qdev_get_gpio_in(DEVICE(&s->lpc), aspeed_lpc_kcs_4)); 514 515 /* iBT */ 516 if (!sysbus_realize(SYS_BUS_DEVICE(&s->ibt), errp)) { 517 return; 518 } 519 memory_region_add_subregion(&s->lpc.iomem, 520 sc->memmap[ASPEED_DEV_IBT] - sc->memmap[ASPEED_DEV_LPC], 521 &s->ibt.iomem); 522 sysbus_connect_irq(SYS_BUS_DEVICE(&s->lpc), 1 + aspeed_lpc_ibt, 523 qdev_get_gpio_in(DEVICE(&s->lpc), aspeed_lpc_ibt)); 524 525 /* HACE */ 526 object_property_set_link(OBJECT(&s->hace), "dram", OBJECT(s->dram_mr), 527 &error_abort); 528 if (!sysbus_realize(SYS_BUS_DEVICE(&s->hace), errp)) { 529 return; 530 } 531 aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->hace), 0, 532 sc->memmap[ASPEED_DEV_HACE]); 533 sysbus_connect_irq(SYS_BUS_DEVICE(&s->hace), 0, 534 aspeed_soc_get_irq(s, ASPEED_DEV_HACE)); 535 536 /* GFX */ 537 if (!sysbus_realize(SYS_BUS_DEVICE(&s->gfx), errp)) { 538 return; 539 } 540 aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->gfx), 0, sc->memmap[ASPEED_DEV_GFX]); 541 sysbus_connect_irq(SYS_BUS_DEVICE(&s->gfx), 0, 542 aspeed_soc_get_irq(s, ASPEED_DEV_GFX)); 543 544 /* PWM */ 545 if (!sysbus_realize(SYS_BUS_DEVICE(&s->pwm), errp)) { 546 return; 547 } 548 aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->pwm), 0, sc->memmap[ASPEED_DEV_PWM]); 549 sysbus_connect_irq(SYS_BUS_DEVICE(&s->pwm), 0, 550 aspeed_soc_get_irq(s, ASPEED_DEV_PWM)); 551 } 552 553 static void aspeed_soc_ast2400_class_init(ObjectClass *oc, void *data) 554 { 555 static const char * const valid_cpu_types[] = { 556 ARM_CPU_TYPE_NAME("arm926"), 557 NULL 558 }; 559 AspeedSoCClass *sc = ASPEED_SOC_CLASS(oc); 560 DeviceClass *dc = DEVICE_CLASS(oc); 561 562 dc->realize = aspeed_ast2400_soc_realize; 563 /* Reason: Uses serial_hds and nd_table in realize() directly */ 564 dc->user_creatable = false; 565 566 sc->name = "ast2400-a1"; 567 sc->valid_cpu_types = valid_cpu_types; 568 sc->silicon_rev = AST2400_A1_SILICON_REV; 569 sc->sram_size = 0x8000; 570 sc->spis_num = 1; 571 sc->ehcis_num = 1; 572 sc->wdts_num = 2; 573 sc->macs_num = 2; 574 sc->uarts_num = 5; 575 sc->uarts_base = ASPEED_DEV_UART1; 576 sc->irqmap = aspeed_soc_ast2400_irqmap; 577 sc->memmap = aspeed_soc_ast2400_memmap; 578 sc->num_cpus = 1; 579 sc->get_irq = aspeed_soc_ast2400_get_irq; 580 } 581 582 static void aspeed_soc_ast2500_class_init(ObjectClass *oc, void *data) 583 { 584 static const char * const valid_cpu_types[] = { 585 ARM_CPU_TYPE_NAME("arm1176"), 586 NULL 587 }; 588 AspeedSoCClass *sc = ASPEED_SOC_CLASS(oc); 589 DeviceClass *dc = DEVICE_CLASS(oc); 590 591 dc->realize = aspeed_ast2400_soc_realize; 592 /* Reason: Uses serial_hds and nd_table in realize() directly */ 593 dc->user_creatable = false; 594 595 sc->name = "ast2500-a1"; 596 sc->valid_cpu_types = valid_cpu_types; 597 sc->silicon_rev = AST2500_A1_SILICON_REV; 598 sc->sram_size = 0x9000; 599 sc->spis_num = 2; 600 sc->ehcis_num = 2; 601 sc->wdts_num = 3; 602 sc->macs_num = 2; 603 sc->uarts_num = 5; 604 sc->uarts_base = ASPEED_DEV_UART1; 605 sc->irqmap = aspeed_soc_ast2500_irqmap; 606 sc->memmap = aspeed_soc_ast2500_memmap; 607 sc->num_cpus = 1; 608 sc->get_irq = aspeed_soc_ast2400_get_irq; 609 } 610 611 static const TypeInfo aspeed_soc_ast2400_types[] = { 612 { 613 .name = TYPE_ASPEED2400_SOC, 614 .parent = TYPE_ASPEED_SOC, 615 .instance_init = aspeed_ast2400_soc_init, 616 .instance_size = sizeof(Aspeed2400SoCState), 617 .abstract = true, 618 }, { 619 .name = "ast2400-a1", 620 .parent = TYPE_ASPEED2400_SOC, 621 .class_init = aspeed_soc_ast2400_class_init, 622 }, { 623 .name = "ast2500-a1", 624 .parent = TYPE_ASPEED2400_SOC, 625 .class_init = aspeed_soc_ast2500_class_init, 626 }, 627 }; 628 629 DEFINE_TYPES(aspeed_soc_ast2400_types) 630