On 2/4/26 09:21, Kane Chen wrote:
> Connect the SPI device to AST1700 model.
>
> Signed-off-by: Kane-Chen-AS <kane_chen@aspeedtech.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Thanks,
C.
> ---
> include/hw/arm/aspeed_ast1700.h | 3 +++
> hw/arm/aspeed_ast1700.c | 30 ++++++++++++++++++++++++++++++
> hw/arm/aspeed_ast27x0.c | 2 ++
> 3 files changed, 35 insertions(+)
>
> diff --git a/include/hw/arm/aspeed_ast1700.h b/include/hw/arm/aspeed_ast1700.h
> index a981bff3b2..89562eb64f 100644
> --- a/include/hw/arm/aspeed_ast1700.h
> +++ b/include/hw/arm/aspeed_ast1700.h
> @@ -10,6 +10,7 @@
>
> #include "hw/core/sysbus.h"
> #include "hw/misc/aspeed_ltpi.h"
> +#include "hw/ssi/aspeed_smc.h"
> #include "hw/char/serial-mm.h"
>
> #define TYPE_ASPEED_AST1700 "aspeed.ast1700"
> @@ -20,11 +21,13 @@ struct AspeedAST1700SoCState {
> SysBusDevice parent_obj;
>
> MemoryRegion iomem;
> + MemoryRegion *dram_mr;
> uint8_t board_idx;
>
> AspeedLTPIState ltpi;
> SerialMM uart;
> MemoryRegion sram;
> + AspeedSMCState spi;
> };
>
> #endif /* ASPEED_AST1700_H */
> diff --git a/hw/arm/aspeed_ast1700.c b/hw/arm/aspeed_ast1700.c
> index fd5db3268e..97990688f8 100644
> --- a/hw/arm/aspeed_ast1700.c
> +++ b/hw/arm/aspeed_ast1700.c
> @@ -9,6 +9,7 @@
> #include "qemu/osdep.h"
> #include "hw/core/boards.h"
> #include "qom/object.h"
> +#include "qapi/error.h"
> #include "hw/core/qdev-properties.h"
> #include "hw/arm/aspeed_ast1700.h"
>
> @@ -16,15 +17,19 @@
> #define AST1700_SOC_SRAM_SIZE 0x00040000
>
> enum {
> + ASPEED_AST1700_DEV_SPI0,
> ASPEED_AST1700_DEV_SRAM,
> ASPEED_AST1700_DEV_UART12,
> ASPEED_AST1700_DEV_LTPI_CTRL,
> + ASPEED_AST1700_DEV_SPI0_MEM,
> };
>
> static const hwaddr aspeed_ast1700_io_memmap[] = {
> + [ASPEED_AST1700_DEV_SPI0] = 0x00030000,
> [ASPEED_AST1700_DEV_SRAM] = 0x00BC0000,
> [ASPEED_AST1700_DEV_UART12] = 0x00C33B00,
> [ASPEED_AST1700_DEV_LTPI_CTRL] = 0x00C34000,
> + [ASPEED_AST1700_DEV_SPI0_MEM] = 0x04000000,
> };
>
> static void aspeed_ast1700_realize(DeviceState *dev, Error **errp)
> @@ -33,6 +38,11 @@ static void aspeed_ast1700_realize(DeviceState *dev, Error **errp)
> SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
> char dev_name[32];
>
> + if (!s->dram_mr) {
> + error_setg(errp, TYPE_ASPEED_AST1700 ": 'dram' link not set");
> + return;
> + }
> +
> /* Occupy memory space for all controllers in AST1700 */
> memory_region_init(&s->iomem, OBJECT(s), TYPE_ASPEED_AST1700,
> AST2700_SOC_LTPI_SIZE);
> @@ -57,6 +67,20 @@ static void aspeed_ast1700_realize(DeviceState *dev, Error **errp)
> aspeed_ast1700_io_memmap[ASPEED_AST1700_DEV_UART12],
> sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->uart), 0));
>
> + /* SPI */
> + object_property_set_link(OBJECT(&s->spi), "dram",
> + OBJECT(s->dram_mr), errp);
> + if (!sysbus_realize(SYS_BUS_DEVICE(&s->spi), errp)) {
> + return;
> + }
> + memory_region_add_subregion(&s->iomem,
> + aspeed_ast1700_io_memmap[ASPEED_AST1700_DEV_SPI0],
> + sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->spi), 0));
> +
> + memory_region_add_subregion(&s->iomem,
> + aspeed_ast1700_io_memmap[ASPEED_AST1700_DEV_SPI0_MEM],
> + sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->spi), 1));
> +
> /* LTPI controller */
> if (!sysbus_realize(SYS_BUS_DEVICE(&s->ltpi), errp)) {
> return;
> @@ -74,6 +98,10 @@ static void aspeed_ast1700_instance_init(Object *obj)
> object_initialize_child(obj, "uart", &s->uart,
> TYPE_SERIAL_MM);
>
> + /* SPI */
> + object_initialize_child(obj, "ioexp-spi", &s->spi,
> + "aspeed.spi0-ast2700");
> +
> /* LTPI controller */
> object_initialize_child(obj, "ltpi-ctrl",
> &s->ltpi, TYPE_ASPEED_LTPI);
> @@ -83,6 +111,8 @@ static void aspeed_ast1700_instance_init(Object *obj)
>
> static const Property aspeed_ast1700_props[] = {
> DEFINE_PROP_UINT8("board-idx", AspeedAST1700SoCState, board_idx, 0),
> + DEFINE_PROP_LINK("dram", AspeedAST1700SoCState, dram_mr,
> + TYPE_MEMORY_REGION, MemoryRegion *),
> };
>
> static void aspeed_ast1700_class_init(ObjectClass *klass, const void *data)
> diff --git a/hw/arm/aspeed_ast27x0.c b/hw/arm/aspeed_ast27x0.c
> index 6a144742ea..2fc50af8b4 100644
> --- a/hw/arm/aspeed_ast27x0.c
> +++ b/hw/arm/aspeed_ast27x0.c
> @@ -1024,6 +1024,8 @@ static void aspeed_soc_ast2700_realize(DeviceState *dev, Error **errp)
> /* IO Expander */
> for (i = 0; i < sc->ioexp_num; i++) {
> qdev_prop_set_uint8(DEVICE(&s->ioexp[i]), "board-idx", i);
> + object_property_set_link(OBJECT(&s->ioexp[i]), "dram",
> + OBJECT(s->dram_mr), &error_abort);
> if (!sysbus_realize(SYS_BUS_DEVICE(&s->ioexp[i]), errp)) {
> return;
> }