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"
15 #include "qemu-common.h"
17 #include "exec/address-spaces.h"
18 #include "hw/arm/aspeed_soc.h"
19 #include "hw/char/serial.h"
21 #include "hw/i2c/aspeed_i2c.h"
24 #define ASPEED_SOC_UART_5_BASE 0x00184000
25 #define ASPEED_SOC_IOMEM_SIZE 0x00200000
26 #define ASPEED_SOC_IOMEM_BASE 0x1E600000
27 #define ASPEED_SOC_FMC_BASE 0x1E620000
28 #define ASPEED_SOC_SPI_BASE 0x1E630000
29 #define ASPEED_SOC_SPI2_BASE 0x1E631000
30 #define ASPEED_SOC_VIC_BASE 0x1E6C0000
31 #define ASPEED_SOC_SDMC_BASE 0x1E6E0000
32 #define ASPEED_SOC_SCU_BASE 0x1E6E2000
33 #define ASPEED_SOC_SRAM_BASE 0x1E720000
34 #define ASPEED_SOC_TIMER_BASE 0x1E782000
35 #define ASPEED_SOC_WDT_BASE 0x1E785000
36 #define ASPEED_SOC_I2C_BASE 0x1E78A000
37 #define ASPEED_SOC_ETH1_BASE 0x1E660000
38 #define ASPEED_SOC_ETH2_BASE 0x1E680000
40 static const int uart_irqs
[] = { 9, 32, 33, 34, 10 };
41 static const int timer_irqs
[] = { 16, 17, 18, 35, 36, 37, 38, 39, };
43 #define AST2400_SDRAM_BASE 0x40000000
44 #define AST2500_SDRAM_BASE 0x80000000
46 static const hwaddr aspeed_soc_ast2400_spi_bases
[] = { ASPEED_SOC_SPI_BASE
};
47 static const char *aspeed_soc_ast2400_typenames
[] = { "aspeed.smc.spi" };
49 static const hwaddr aspeed_soc_ast2500_spi_bases
[] = { ASPEED_SOC_SPI_BASE
,
50 ASPEED_SOC_SPI2_BASE
};
51 static const char *aspeed_soc_ast2500_typenames
[] = {
52 "aspeed.smc.ast2500-spi1", "aspeed.smc.ast2500-spi2" };
54 static const AspeedSoCInfo aspeed_socs
[] = {
57 .cpu_model
= "arm926",
58 .silicon_rev
= AST2400_A0_SILICON_REV
,
59 .sdram_base
= AST2400_SDRAM_BASE
,
62 .spi_bases
= aspeed_soc_ast2400_spi_bases
,
63 .fmc_typename
= "aspeed.smc.fmc",
64 .spi_typename
= aspeed_soc_ast2400_typenames
,
68 .cpu_model
= "arm926",
69 .silicon_rev
= AST2400_A1_SILICON_REV
,
70 .sdram_base
= AST2400_SDRAM_BASE
,
73 .spi_bases
= aspeed_soc_ast2400_spi_bases
,
74 .fmc_typename
= "aspeed.smc.fmc",
75 .spi_typename
= aspeed_soc_ast2400_typenames
,
79 .cpu_model
= "arm926",
80 .silicon_rev
= AST2400_A0_SILICON_REV
,
81 .sdram_base
= AST2400_SDRAM_BASE
,
84 .spi_bases
= aspeed_soc_ast2400_spi_bases
,
85 .fmc_typename
= "aspeed.smc.fmc",
86 .spi_typename
= aspeed_soc_ast2400_typenames
,
90 .cpu_model
= "arm1176",
91 .silicon_rev
= AST2500_A1_SILICON_REV
,
92 .sdram_base
= AST2500_SDRAM_BASE
,
95 .spi_bases
= aspeed_soc_ast2500_spi_bases
,
96 .fmc_typename
= "aspeed.smc.ast2500-fmc",
97 .spi_typename
= aspeed_soc_ast2500_typenames
,
103 * IO handlers: simply catch any reads/writes to IO addresses that aren't
104 * handled by a device mapping.
107 static uint64_t aspeed_soc_io_read(void *p
, hwaddr offset
, unsigned size
)
109 qemu_log_mask(LOG_UNIMP
, "%s: 0x%" HWADDR_PRIx
" [%u]\n",
110 __func__
, offset
, size
);
114 static void aspeed_soc_io_write(void *opaque
, hwaddr offset
, uint64_t value
,
117 qemu_log_mask(LOG_UNIMP
, "%s: 0x%" HWADDR_PRIx
" <- 0x%" PRIx64
" [%u]\n",
118 __func__
, offset
, value
, size
);
121 static const MemoryRegionOps aspeed_soc_io_ops
= {
122 .read
= aspeed_soc_io_read
,
123 .write
= aspeed_soc_io_write
,
124 .endianness
= DEVICE_LITTLE_ENDIAN
,
127 static void aspeed_soc_init(Object
*obj
)
129 AspeedSoCState
*s
= ASPEED_SOC(obj
);
130 AspeedSoCClass
*sc
= ASPEED_SOC_GET_CLASS(s
);
134 cpu_typename
= g_strdup_printf("%s-" TYPE_ARM_CPU
, sc
->info
->cpu_model
);
135 object_initialize(&s
->cpu
, sizeof(s
->cpu
), cpu_typename
);
136 object_property_add_child(obj
, "cpu", OBJECT(&s
->cpu
), NULL
);
137 g_free(cpu_typename
);
139 object_initialize(&s
->vic
, sizeof(s
->vic
), TYPE_ASPEED_VIC
);
140 object_property_add_child(obj
, "vic", OBJECT(&s
->vic
), NULL
);
141 qdev_set_parent_bus(DEVICE(&s
->vic
), sysbus_get_default());
143 object_initialize(&s
->timerctrl
, sizeof(s
->timerctrl
), TYPE_ASPEED_TIMER
);
144 object_property_add_child(obj
, "timerctrl", OBJECT(&s
->timerctrl
), NULL
);
145 qdev_set_parent_bus(DEVICE(&s
->timerctrl
), sysbus_get_default());
147 object_initialize(&s
->i2c
, sizeof(s
->i2c
), TYPE_ASPEED_I2C
);
148 object_property_add_child(obj
, "i2c", OBJECT(&s
->i2c
), NULL
);
149 qdev_set_parent_bus(DEVICE(&s
->i2c
), sysbus_get_default());
151 object_initialize(&s
->scu
, sizeof(s
->scu
), TYPE_ASPEED_SCU
);
152 object_property_add_child(obj
, "scu", OBJECT(&s
->scu
), NULL
);
153 qdev_set_parent_bus(DEVICE(&s
->scu
), sysbus_get_default());
154 qdev_prop_set_uint32(DEVICE(&s
->scu
), "silicon-rev",
155 sc
->info
->silicon_rev
);
156 object_property_add_alias(obj
, "hw-strap1", OBJECT(&s
->scu
),
157 "hw-strap1", &error_abort
);
158 object_property_add_alias(obj
, "hw-strap2", OBJECT(&s
->scu
),
159 "hw-strap2", &error_abort
);
161 object_initialize(&s
->fmc
, sizeof(s
->fmc
), sc
->info
->fmc_typename
);
162 object_property_add_child(obj
, "fmc", OBJECT(&s
->fmc
), NULL
);
163 qdev_set_parent_bus(DEVICE(&s
->fmc
), sysbus_get_default());
164 object_property_add_alias(obj
, "num-cs", OBJECT(&s
->fmc
), "num-cs",
167 for (i
= 0; i
< sc
->info
->spis_num
; i
++) {
168 object_initialize(&s
->spi
[i
], sizeof(s
->spi
[i
]),
169 sc
->info
->spi_typename
[i
]);
170 object_property_add_child(obj
, "spi[*]", OBJECT(&s
->spi
[i
]), NULL
);
171 qdev_set_parent_bus(DEVICE(&s
->spi
[i
]), sysbus_get_default());
174 object_initialize(&s
->sdmc
, sizeof(s
->sdmc
), TYPE_ASPEED_SDMC
);
175 object_property_add_child(obj
, "sdmc", OBJECT(&s
->sdmc
), NULL
);
176 qdev_set_parent_bus(DEVICE(&s
->sdmc
), sysbus_get_default());
177 qdev_prop_set_uint32(DEVICE(&s
->sdmc
), "silicon-rev",
178 sc
->info
->silicon_rev
);
179 object_property_add_alias(obj
, "ram-size", OBJECT(&s
->sdmc
),
180 "ram-size", &error_abort
);
182 for (i
= 0; i
< sc
->info
->wdts_num
; i
++) {
183 object_initialize(&s
->wdt
[i
], sizeof(s
->wdt
[i
]), TYPE_ASPEED_WDT
);
184 object_property_add_child(obj
, "wdt[*]", OBJECT(&s
->wdt
[i
]), NULL
);
185 qdev_set_parent_bus(DEVICE(&s
->wdt
[i
]), sysbus_get_default());
188 object_initialize(&s
->ftgmac100
, sizeof(s
->ftgmac100
), TYPE_FTGMAC100
);
189 object_property_add_child(obj
, "ftgmac100", OBJECT(&s
->ftgmac100
), NULL
);
190 qdev_set_parent_bus(DEVICE(&s
->ftgmac100
), sysbus_get_default());
193 static void aspeed_soc_realize(DeviceState
*dev
, Error
**errp
)
196 AspeedSoCState
*s
= ASPEED_SOC(dev
);
197 AspeedSoCClass
*sc
= ASPEED_SOC_GET_CLASS(s
);
198 Error
*err
= NULL
, *local_err
= NULL
;
201 memory_region_init_io(&s
->iomem
, NULL
, &aspeed_soc_io_ops
, NULL
,
202 "aspeed_soc.io", ASPEED_SOC_IOMEM_SIZE
);
203 memory_region_add_subregion_overlap(get_system_memory(),
204 ASPEED_SOC_IOMEM_BASE
, &s
->iomem
, -1);
207 object_property_set_bool(OBJECT(&s
->cpu
), true, "realized", &err
);
209 error_propagate(errp
, err
);
214 memory_region_init_ram_nomigrate(&s
->sram
, OBJECT(dev
), "aspeed.sram",
215 sc
->info
->sram_size
, &err
);
217 error_propagate(errp
, err
);
220 vmstate_register_ram_global(&s
->sram
);
221 memory_region_add_subregion(get_system_memory(), ASPEED_SOC_SRAM_BASE
,
225 object_property_set_bool(OBJECT(&s
->vic
), true, "realized", &err
);
227 error_propagate(errp
, err
);
230 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->vic
), 0, ASPEED_SOC_VIC_BASE
);
231 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->vic
), 0,
232 qdev_get_gpio_in(DEVICE(&s
->cpu
), ARM_CPU_IRQ
));
233 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->vic
), 1,
234 qdev_get_gpio_in(DEVICE(&s
->cpu
), ARM_CPU_FIQ
));
237 object_property_set_bool(OBJECT(&s
->timerctrl
), true, "realized", &err
);
239 error_propagate(errp
, err
);
242 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->timerctrl
), 0, ASPEED_SOC_TIMER_BASE
);
243 for (i
= 0; i
< ARRAY_SIZE(timer_irqs
); i
++) {
244 qemu_irq irq
= qdev_get_gpio_in(DEVICE(&s
->vic
), timer_irqs
[i
]);
245 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->timerctrl
), i
, irq
);
249 object_property_set_bool(OBJECT(&s
->scu
), true, "realized", &err
);
251 error_propagate(errp
, err
);
254 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->scu
), 0, ASPEED_SOC_SCU_BASE
);
256 /* UART - attach an 8250 to the IO space as our UART5 */
258 qemu_irq uart5
= qdev_get_gpio_in(DEVICE(&s
->vic
), uart_irqs
[4]);
259 serial_mm_init(&s
->iomem
, ASPEED_SOC_UART_5_BASE
, 2,
260 uart5
, 38400, serial_hds
[0], DEVICE_LITTLE_ENDIAN
);
264 object_property_set_bool(OBJECT(&s
->i2c
), true, "realized", &err
);
266 error_propagate(errp
, err
);
269 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->i2c
), 0, ASPEED_SOC_I2C_BASE
);
270 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->i2c
), 0,
271 qdev_get_gpio_in(DEVICE(&s
->vic
), 12));
273 /* FMC, The number of CS is set at the board level */
274 object_property_set_bool(OBJECT(&s
->fmc
), true, "realized", &err
);
276 error_propagate(errp
, err
);
279 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->fmc
), 0, ASPEED_SOC_FMC_BASE
);
280 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->fmc
), 1,
281 s
->fmc
.ctrl
->flash_window_base
);
282 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->fmc
), 0,
283 qdev_get_gpio_in(DEVICE(&s
->vic
), 19));
286 for (i
= 0; i
< sc
->info
->spis_num
; i
++) {
287 object_property_set_int(OBJECT(&s
->spi
[i
]), 1, "num-cs", &err
);
288 object_property_set_bool(OBJECT(&s
->spi
[i
]), true, "realized",
290 error_propagate(&err
, local_err
);
292 error_propagate(errp
, err
);
295 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->spi
[i
]), 0, sc
->info
->spi_bases
[i
]);
296 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->spi
[i
]), 1,
297 s
->spi
[i
].ctrl
->flash_window_base
);
300 /* SDMC - SDRAM Memory Controller */
301 object_property_set_bool(OBJECT(&s
->sdmc
), true, "realized", &err
);
303 error_propagate(errp
, err
);
306 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->sdmc
), 0, ASPEED_SOC_SDMC_BASE
);
309 for (i
= 0; i
< sc
->info
->wdts_num
; i
++) {
310 object_property_set_bool(OBJECT(&s
->wdt
[i
]), true, "realized", &err
);
312 error_propagate(errp
, err
);
315 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->wdt
[i
]), 0,
316 ASPEED_SOC_WDT_BASE
+ i
* 0x20);
320 qdev_set_nic_properties(DEVICE(&s
->ftgmac100
), &nd_table
[0]);
321 object_property_set_bool(OBJECT(&s
->ftgmac100
), true, "aspeed", &err
);
322 object_property_set_bool(OBJECT(&s
->ftgmac100
), true, "realized",
324 error_propagate(&err
, local_err
);
326 error_propagate(errp
, err
);
329 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->ftgmac100
), 0, ASPEED_SOC_ETH1_BASE
);
330 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->ftgmac100
), 0,
331 qdev_get_gpio_in(DEVICE(&s
->vic
), 2));
334 static void aspeed_soc_class_init(ObjectClass
*oc
, void *data
)
336 DeviceClass
*dc
= DEVICE_CLASS(oc
);
337 AspeedSoCClass
*sc
= ASPEED_SOC_CLASS(oc
);
339 sc
->info
= (AspeedSoCInfo
*) data
;
340 dc
->realize
= aspeed_soc_realize
;
343 static const TypeInfo aspeed_soc_type_info
= {
344 .name
= TYPE_ASPEED_SOC
,
345 .parent
= TYPE_DEVICE
,
346 .instance_init
= aspeed_soc_init
,
347 .instance_size
= sizeof(AspeedSoCState
),
348 .class_size
= sizeof(AspeedSoCClass
),
352 static void aspeed_soc_register_types(void)
356 type_register_static(&aspeed_soc_type_info
);
357 for (i
= 0; i
< ARRAY_SIZE(aspeed_socs
); ++i
) {
359 .name
= aspeed_socs
[i
].name
,
360 .parent
= TYPE_ASPEED_SOC
,
361 .class_init
= aspeed_soc_class_init
,
362 .class_data
= (void *) &aspeed_socs
[i
],
368 type_init(aspeed_soc_register_types
)