xref: /qemu/hw/arm/aspeed.c (revision ccc2c41890afd3a28183ea93bfab688890eb3df6)
1327d8e4eSAndrew Jeffery /*
2327d8e4eSAndrew Jeffery  * OpenPOWER Palmetto BMC
3327d8e4eSAndrew Jeffery  *
4327d8e4eSAndrew Jeffery  * Andrew Jeffery <andrew@aj.id.au>
5327d8e4eSAndrew Jeffery  *
6327d8e4eSAndrew Jeffery  * Copyright 2016 IBM Corp.
7327d8e4eSAndrew Jeffery  *
8327d8e4eSAndrew Jeffery  * This code is licensed under the GPL version 2 or later.  See
9327d8e4eSAndrew Jeffery  * the COPYING file in the top-level directory.
10327d8e4eSAndrew Jeffery  */
11327d8e4eSAndrew Jeffery 
12327d8e4eSAndrew Jeffery #include "qemu/osdep.h"
13da34e65cSMarkus Armbruster #include "qapi/error.h"
144771d756SPaolo Bonzini #include "cpu.h"
15327d8e4eSAndrew Jeffery #include "exec/address-spaces.h"
1612ec8bd5SPeter Maydell #include "hw/arm/boot.h"
17fca9ca1bSCédric Le Goater #include "hw/arm/aspeed.h"
1800442402SCédric Le Goater #include "hw/arm/aspeed_soc.h"
19327d8e4eSAndrew Jeffery #include "hw/boards.h"
2093198b6cSCorey Minyard #include "hw/i2c/smbus_eeprom.h"
21044475f3SPhilippe Mathieu-Daudé #include "hw/misc/pca9552.h"
22044475f3SPhilippe Mathieu-Daudé #include "hw/misc/tmp105.h"
23a27bd6c7SMarkus Armbruster #include "hw/qdev-properties.h"
2403dd024fSPaolo Bonzini #include "qemu/log.h"
25e1ad9bc4SCédric Le Goater #include "sysemu/block-backend.h"
26ece09beeSCédric Le Goater #include "sysemu/sysemu.h"
27d769a1daSCédric Le Goater #include "hw/loader.h"
28d769a1daSCédric Le Goater #include "qemu/error-report.h"
29a9df9622SJoel Stanley #include "qemu/units.h"
30327d8e4eSAndrew Jeffery 
3174fb1f38SCédric Le Goater static struct arm_boot_info aspeed_board_binfo = {
32b033271fSCédric Le Goater     .board_id = -1, /* device-tree-only board */
33327d8e4eSAndrew Jeffery };
34327d8e4eSAndrew Jeffery 
35ea066d39SThomas Huth struct AspeedBoardState {
36ff90606fSCédric Le Goater     AspeedSoCState soc;
37ad1a9782SCédric Le Goater     MemoryRegion ram_container;
38327d8e4eSAndrew Jeffery     MemoryRegion ram;
39ebe31c0aSCédric Le Goater     MemoryRegion max_ram;
40ea066d39SThomas Huth };
41327d8e4eSAndrew Jeffery 
42ef17f836SCédric Le Goater /* Palmetto hardware value: 0x120CE416 */
438da33ef7SCédric Le Goater #define PALMETTO_BMC_HW_STRAP1 (                                        \
448da33ef7SCédric Le Goater         SCU_AST2400_HW_STRAP_DRAM_SIZE(DRAM_SIZE_256MB) |               \
458da33ef7SCédric Le Goater         SCU_AST2400_HW_STRAP_DRAM_CONFIG(2 /* DDR3 with CL=6, CWL=5 */) | \
468da33ef7SCédric Le Goater         SCU_AST2400_HW_STRAP_ACPI_DIS |                                 \
478da33ef7SCédric Le Goater         SCU_AST2400_HW_STRAP_SET_CLK_SOURCE(AST2400_CLK_48M_IN) |       \
488da33ef7SCédric Le Goater         SCU_HW_STRAP_VGA_CLASS_CODE |                                   \
498da33ef7SCédric Le Goater         SCU_HW_STRAP_LPC_RESET_PIN |                                    \
508da33ef7SCédric Le Goater         SCU_HW_STRAP_SPI_MODE(SCU_HW_STRAP_SPI_M_S_EN) |                \
518da33ef7SCédric Le Goater         SCU_AST2400_HW_STRAP_SET_CPU_AHB_RATIO(AST2400_CPU_AHB_RATIO_2_1) | \
528da33ef7SCédric Le Goater         SCU_HW_STRAP_SPI_WIDTH |                                        \
538da33ef7SCédric Le Goater         SCU_HW_STRAP_VGA_SIZE_SET(VGA_16M_DRAM) |                       \
548da33ef7SCédric Le Goater         SCU_AST2400_HW_STRAP_BOOT_MODE(AST2400_SPI_BOOT))
558da33ef7SCédric Le Goater 
56ef17f836SCédric Le Goater /* AST2500 evb hardware value: 0xF100C2E6 */
579a7c1750SCédric Le Goater #define AST2500_EVB_HW_STRAP1 ((                                        \
589a7c1750SCédric Le Goater         AST2500_HW_STRAP1_DEFAULTS |                                    \
599a7c1750SCédric Le Goater         SCU_AST2500_HW_STRAP_SPI_AUTOFETCH_ENABLE |                     \
609a7c1750SCédric Le Goater         SCU_AST2500_HW_STRAP_GPIO_STRAP_ENABLE |                        \
619a7c1750SCédric Le Goater         SCU_AST2500_HW_STRAP_UART_DEBUG |                               \
629a7c1750SCédric Le Goater         SCU_AST2500_HW_STRAP_DDR4_ENABLE |                              \
639a7c1750SCédric Le Goater         SCU_HW_STRAP_MAC1_RGMII |                                       \
649a7c1750SCédric Le Goater         SCU_HW_STRAP_MAC0_RGMII) &                                      \
659a7c1750SCédric Le Goater         ~SCU_HW_STRAP_2ND_BOOT_WDT)
669a7c1750SCédric Le Goater 
67ef17f836SCédric Le Goater /* Romulus hardware value: 0xF10AD206 */
68ef17f836SCédric Le Goater #define ROMULUS_BMC_HW_STRAP1 (                                         \
69ef17f836SCédric Le Goater         AST2500_HW_STRAP1_DEFAULTS |                                    \
70ef17f836SCédric Le Goater         SCU_AST2500_HW_STRAP_SPI_AUTOFETCH_ENABLE |                     \
71ef17f836SCédric Le Goater         SCU_AST2500_HW_STRAP_GPIO_STRAP_ENABLE |                        \
72ef17f836SCédric Le Goater         SCU_AST2500_HW_STRAP_UART_DEBUG |                               \
73ef17f836SCédric Le Goater         SCU_AST2500_HW_STRAP_DDR4_ENABLE |                              \
74ef17f836SCédric Le Goater         SCU_AST2500_HW_STRAP_ACPI_ENABLE |                              \
75ef17f836SCédric Le Goater         SCU_HW_STRAP_SPI_MODE(SCU_HW_STRAP_SPI_MASTER))
76ef17f836SCédric Le Goater 
77aae7a18dSAdriana Kobylak /* Swift hardware value: 0xF11AD206 */
78aae7a18dSAdriana Kobylak #define SWIFT_BMC_HW_STRAP1 (                                           \
79aae7a18dSAdriana Kobylak         AST2500_HW_STRAP1_DEFAULTS |                                    \
80aae7a18dSAdriana Kobylak         SCU_AST2500_HW_STRAP_SPI_AUTOFETCH_ENABLE |                     \
81aae7a18dSAdriana Kobylak         SCU_AST2500_HW_STRAP_GPIO_STRAP_ENABLE |                        \
82aae7a18dSAdriana Kobylak         SCU_AST2500_HW_STRAP_UART_DEBUG |                               \
83aae7a18dSAdriana Kobylak         SCU_AST2500_HW_STRAP_DDR4_ENABLE |                              \
84aae7a18dSAdriana Kobylak         SCU_H_PLL_BYPASS_EN |                                           \
85aae7a18dSAdriana Kobylak         SCU_AST2500_HW_STRAP_ACPI_ENABLE |                              \
86aae7a18dSAdriana Kobylak         SCU_HW_STRAP_SPI_MODE(SCU_HW_STRAP_SPI_MASTER))
87aae7a18dSAdriana Kobylak 
8862c2c2ebSCédric Le Goater /* Witherspoon hardware value: 0xF10AD216 (but use romulus definition) */
8962c2c2ebSCédric Le Goater #define WITHERSPOON_BMC_HW_STRAP1 ROMULUS_BMC_HW_STRAP1
9062c2c2ebSCédric Le Goater 
91*ccc2c418SCédric Le Goater /* AST2600 evb hardware value */
92*ccc2c418SCédric Le Goater #define AST2600_EVB_HW_STRAP1 0x000000C0
93*ccc2c418SCédric Le Goater #define AST2600_EVB_HW_STRAP2 0x00000003
94*ccc2c418SCédric Le Goater 
95ebe31c0aSCédric Le Goater /*
96ebe31c0aSCédric Le Goater  * The max ram region is for firmwares that scan the address space
97ebe31c0aSCédric Le Goater  * with load/store to guess how much RAM the SoC has.
98ebe31c0aSCédric Le Goater  */
99ebe31c0aSCédric Le Goater static uint64_t max_ram_read(void *opaque, hwaddr offset, unsigned size)
100ebe31c0aSCédric Le Goater {
101ebe31c0aSCédric Le Goater     return 0;
102ebe31c0aSCédric Le Goater }
103ebe31c0aSCédric Le Goater 
104ebe31c0aSCédric Le Goater static void max_ram_write(void *opaque, hwaddr offset, uint64_t value,
105ebe31c0aSCédric Le Goater                            unsigned size)
106ebe31c0aSCédric Le Goater {
107ebe31c0aSCédric Le Goater     /* Discard writes */
108ebe31c0aSCédric Le Goater }
109ebe31c0aSCédric Le Goater 
110ebe31c0aSCédric Le Goater static const MemoryRegionOps max_ram_ops = {
111ebe31c0aSCédric Le Goater     .read = max_ram_read,
112ebe31c0aSCédric Le Goater     .write = max_ram_write,
113ebe31c0aSCédric Le Goater     .endianness = DEVICE_NATIVE_ENDIAN,
114ebe31c0aSCédric Le Goater };
115ebe31c0aSCédric Le Goater 
116d769a1daSCédric Le Goater #define FIRMWARE_ADDR 0x0
117d769a1daSCédric Le Goater 
118d769a1daSCédric Le Goater static void write_boot_rom(DriveInfo *dinfo, hwaddr addr, size_t rom_size,
119d769a1daSCédric Le Goater                            Error **errp)
120d769a1daSCédric Le Goater {
121d769a1daSCédric Le Goater     BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
122d769a1daSCédric Le Goater     uint8_t *storage;
1230c7209beSCédric Le Goater     int64_t size;
124d769a1daSCédric Le Goater 
1250c7209beSCédric Le Goater     /* The block backend size should have already been 'validated' by
1260c7209beSCédric Le Goater      * the creation of the m25p80 object.
1270c7209beSCédric Le Goater      */
1280c7209beSCédric Le Goater     size = blk_getlength(blk);
1290c7209beSCédric Le Goater     if (size <= 0) {
1300c7209beSCédric Le Goater         error_setg(errp, "failed to get flash size");
1310c7209beSCédric Le Goater         return;
1320c7209beSCédric Le Goater     }
1330c7209beSCédric Le Goater 
1340c7209beSCédric Le Goater     if (rom_size > size) {
1350c7209beSCédric Le Goater         rom_size = size;
136d769a1daSCédric Le Goater     }
137d769a1daSCédric Le Goater 
138d769a1daSCédric Le Goater     storage = g_new0(uint8_t, rom_size);
139d769a1daSCédric Le Goater     if (blk_pread(blk, 0, storage, rom_size) < 0) {
140d769a1daSCédric Le Goater         error_setg(errp, "failed to read the initial flash content");
141d769a1daSCédric Le Goater         return;
142d769a1daSCédric Le Goater     }
143d769a1daSCédric Le Goater 
144d769a1daSCédric Le Goater     rom_add_blob_fixed("aspeed.boot_rom", storage, rom_size, addr);
145d769a1daSCédric Le Goater     g_free(storage);
146d769a1daSCédric Le Goater }
147d769a1daSCédric Le Goater 
14874fb1f38SCédric Le Goater static void aspeed_board_init_flashes(AspeedSMCState *s, const char *flashtype,
149e1ad9bc4SCédric Le Goater                                       Error **errp)
150e1ad9bc4SCédric Le Goater {
151e1ad9bc4SCédric Le Goater     int i ;
152e1ad9bc4SCédric Le Goater 
153e1ad9bc4SCédric Le Goater     for (i = 0; i < s->num_cs; ++i) {
154e1ad9bc4SCédric Le Goater         AspeedSMCFlash *fl = &s->flashes[i];
155e1ad9bc4SCédric Le Goater         DriveInfo *dinfo = drive_get_next(IF_MTD);
156e1ad9bc4SCédric Le Goater         qemu_irq cs_line;
157e1ad9bc4SCédric Le Goater 
158e1ad9bc4SCédric Le Goater         fl->flash = ssi_create_slave_no_init(s->spi, flashtype);
159e1ad9bc4SCédric Le Goater         if (dinfo) {
160e1ad9bc4SCédric Le Goater             qdev_prop_set_drive(fl->flash, "drive", blk_by_legacy_dinfo(dinfo),
161e1ad9bc4SCédric Le Goater                                 errp);
162e1ad9bc4SCédric Le Goater         }
163e1ad9bc4SCédric Le Goater         qdev_init_nofail(fl->flash);
164e1ad9bc4SCédric Le Goater 
165e1ad9bc4SCédric Le Goater         cs_line = qdev_get_gpio_in_named(fl->flash, SSI_GPIO_CS, 0);
166e1ad9bc4SCédric Le Goater         sysbus_connect_irq(SYS_BUS_DEVICE(s), i + 1, cs_line);
167e1ad9bc4SCédric Le Goater     }
168e1ad9bc4SCédric Le Goater }
169e1ad9bc4SCédric Le Goater 
170c3ba99f7SCédric Le Goater static void aspeed_board_init(MachineState *machine,
171c3ba99f7SCédric Le Goater                               const AspeedBoardConfig *cfg)
172327d8e4eSAndrew Jeffery {
17374fb1f38SCédric Le Goater     AspeedBoardState *bmc;
174b033271fSCédric Le Goater     AspeedSoCClass *sc;
175d769a1daSCédric Le Goater     DriveInfo *drive0 = drive_get(IF_MTD, 0, 0);
176ebe31c0aSCédric Le Goater     ram_addr_t max_ram_size;
1772bea128cSEddie James     int i;
178327d8e4eSAndrew Jeffery 
17974fb1f38SCédric Le Goater     bmc = g_new0(AspeedBoardState, 1);
180ad1a9782SCédric Le Goater 
181ad1a9782SCédric Le Goater     memory_region_init(&bmc->ram_container, NULL, "aspeed-ram-container",
182ad1a9782SCédric Le Goater                        UINT32_MAX);
183ad1a9782SCédric Le Goater 
1841b0ad567SPhilippe Mathieu-Daudé     object_initialize_child(OBJECT(machine), "soc", &bmc->soc,
1851b0ad567SPhilippe Mathieu-Daudé                             (sizeof(bmc->soc)), cfg->soc_name, &error_abort,
1861b0ad567SPhilippe Mathieu-Daudé                             NULL);
187327d8e4eSAndrew Jeffery 
188b033271fSCédric Le Goater     sc = ASPEED_SOC_GET_CLASS(&bmc->soc);
189b033271fSCédric Le Goater 
19019e9cdf0SMarc-André Lureau     object_property_set_uint(OBJECT(&bmc->soc), ram_size, "ram-size",
191c6c7cfb0SCédric Le Goater                              &error_abort);
192c3ba99f7SCédric Le Goater     object_property_set_int(OBJECT(&bmc->soc), cfg->hw_strap1, "hw-strap1",
19387e79af0SAndrew Jeffery                             &error_abort);
194*ccc2c418SCédric Le Goater     object_property_set_int(OBJECT(&bmc->soc), cfg->hw_strap2, "hw-strap2",
195*ccc2c418SCédric Le Goater                             &error_abort);
19626d5df95SCédric Le Goater     object_property_set_int(OBJECT(&bmc->soc), cfg->num_cs, "num-cs",
19726d5df95SCédric Le Goater                             &error_abort);
198cc7d44c2SLike Xu     object_property_set_int(OBJECT(&bmc->soc), machine->smp.cpus, "num-cpus",
199ece09beeSCédric Le Goater                             &error_abort);
200c4e1f0b4SCédric Le Goater     object_property_set_link(OBJECT(&bmc->soc), OBJECT(&bmc->ram_container),
201c4e1f0b4SCédric Le Goater                              "dram", &error_abort);
202b6e70d1dSJoel Stanley     if (machine->kernel_filename) {
203b6e70d1dSJoel Stanley         /*
204b6e70d1dSJoel Stanley          * When booting with a -kernel command line there is no u-boot
205b6e70d1dSJoel Stanley          * that runs to unlock the SCU. In this case set the default to
206b6e70d1dSJoel Stanley          * be unlocked as the kernel expects
207b6e70d1dSJoel Stanley          */
208b6e70d1dSJoel Stanley         object_property_set_int(OBJECT(&bmc->soc), ASPEED_SCU_PROT_KEY,
209b6e70d1dSJoel Stanley                                 "hw-prot-key", &error_abort);
210b6e70d1dSJoel Stanley     }
211327d8e4eSAndrew Jeffery     object_property_set_bool(OBJECT(&bmc->soc), true, "realized",
212327d8e4eSAndrew Jeffery                              &error_abort);
213327d8e4eSAndrew Jeffery 
214de46f5f4SCédric Le Goater     /*
215de46f5f4SCédric Le Goater      * Allocate RAM after the memory controller has checked the size
216de46f5f4SCédric Le Goater      * was valid. If not, a default value is used.
217de46f5f4SCédric Le Goater      */
21819e9cdf0SMarc-André Lureau     ram_size = object_property_get_uint(OBJECT(&bmc->soc), "ram-size",
219de46f5f4SCédric Le Goater                                         &error_abort);
220de46f5f4SCédric Le Goater 
221de46f5f4SCédric Le Goater     memory_region_allocate_system_memory(&bmc->ram, NULL, "ram", ram_size);
222ad1a9782SCédric Le Goater     memory_region_add_subregion(&bmc->ram_container, 0, &bmc->ram);
223d783d1feSCédric Le Goater     memory_region_add_subregion(get_system_memory(),
22454ecafb7SCédric Le Goater                                 sc->memmap[ASPEED_SDRAM],
225ad1a9782SCédric Le Goater                                 &bmc->ram_container);
226de46f5f4SCédric Le Goater 
227ebe31c0aSCédric Le Goater     max_ram_size = object_property_get_uint(OBJECT(&bmc->soc), "max-ram-size",
228ebe31c0aSCédric Le Goater                                             &error_abort);
229ebe31c0aSCédric Le Goater     memory_region_init_io(&bmc->max_ram, NULL, &max_ram_ops, NULL,
230ebe31c0aSCédric Le Goater                           "max_ram", max_ram_size  - ram_size);
231ad1a9782SCédric Le Goater     memory_region_add_subregion(&bmc->ram_container, ram_size, &bmc->max_ram);
232ebe31c0aSCédric Le Goater 
2336a0e947bSCédric Le Goater     aspeed_board_init_flashes(&bmc->soc.fmc, cfg->fmc_model, &error_abort);
2346a0e947bSCédric Le Goater     aspeed_board_init_flashes(&bmc->soc.spi[0], cfg->spi_model, &error_abort);
235e1ad9bc4SCédric Le Goater 
236d769a1daSCédric Le Goater     /* Install first FMC flash content as a boot rom. */
237d769a1daSCédric Le Goater     if (drive0) {
238d769a1daSCédric Le Goater         AspeedSMCFlash *fl = &bmc->soc.fmc.flashes[0];
239d769a1daSCédric Le Goater         MemoryRegion *boot_rom = g_new(MemoryRegion, 1);
240d769a1daSCédric Le Goater 
241d769a1daSCédric Le Goater         /*
242d769a1daSCédric Le Goater          * create a ROM region using the default mapping window size of
24393bf276dSCédric Le Goater          * the flash module. The window size is 64MB for the AST2400
24493bf276dSCédric Le Goater          * SoC and 128MB for the AST2500 SoC, which is twice as big as
24593bf276dSCédric Le Goater          * needed by the flash modules of the Aspeed machines.
246d769a1daSCédric Le Goater          */
24744cf837dSPeter Maydell         memory_region_init_rom(boot_rom, OBJECT(bmc), "aspeed.boot_rom",
248d769a1daSCédric Le Goater                                fl->size, &error_abort);
249d769a1daSCédric Le Goater         memory_region_add_subregion(get_system_memory(), FIRMWARE_ADDR,
250d769a1daSCédric Le Goater                                     boot_rom);
251d769a1daSCédric Le Goater         write_boot_rom(drive0, FIRMWARE_ADDR, fl->size, &error_abort);
252d769a1daSCédric Le Goater     }
253d769a1daSCédric Le Goater 
25474fb1f38SCédric Le Goater     aspeed_board_binfo.ram_size = ram_size;
25554ecafb7SCédric Le Goater     aspeed_board_binfo.loader_start = sc->memmap[ASPEED_SDRAM];
256ece09beeSCédric Le Goater     aspeed_board_binfo.nb_cpus = bmc->soc.num_cpus;
257b033271fSCédric Le Goater 
2582cf6cb50SCédric Le Goater     if (cfg->i2c_init) {
2592cf6cb50SCédric Le Goater         cfg->i2c_init(bmc);
2602cf6cb50SCédric Le Goater     }
2612cf6cb50SCédric Le Goater 
2622bea128cSEddie James     for (i = 0; i < ARRAY_SIZE(bmc->soc.sdhci.slots); i++) {
2632bea128cSEddie James         SDHCIState *sdhci = &bmc->soc.sdhci.slots[i];
2642bea128cSEddie James         DriveInfo *dinfo = drive_get_next(IF_SD);
2652bea128cSEddie James         BlockBackend *blk;
2662bea128cSEddie James         DeviceState *card;
2672bea128cSEddie James 
2682bea128cSEddie James         blk = dinfo ? blk_by_legacy_dinfo(dinfo) : NULL;
2692bea128cSEddie James         card = qdev_create(qdev_get_child_bus(DEVICE(sdhci), "sd-bus"),
2702bea128cSEddie James                            TYPE_SD_CARD);
2712bea128cSEddie James         qdev_prop_set_drive(card, "drive", blk, &error_fatal);
2722bea128cSEddie James         object_property_set_bool(OBJECT(card), true, "realized", &error_fatal);
2732bea128cSEddie James     }
2742bea128cSEddie James 
2752744ece8STao Xu     arm_load_kernel(ARM_CPU(first_cpu), machine, &aspeed_board_binfo);
276327d8e4eSAndrew Jeffery }
277327d8e4eSAndrew Jeffery 
2782cf6cb50SCédric Le Goater static void palmetto_bmc_i2c_init(AspeedBoardState *bmc)
2792cf6cb50SCédric Le Goater {
2802cf6cb50SCédric Le Goater     AspeedSoCState *soc = &bmc->soc;
281a87e81b9SCédric Le Goater     DeviceState *dev;
2823d165f12SCédric Le Goater     uint8_t *eeprom_buf = g_malloc0(32 * 1024);
2832cf6cb50SCédric Le Goater 
2842cf6cb50SCédric Le Goater     /* The palmetto platform expects a ds3231 RTC but a ds1338 is
2852cf6cb50SCédric Le Goater      * enough to provide basic RTC features. Alarms will be missing */
2862cf6cb50SCédric Le Goater     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 0), "ds1338", 0x68);
287a87e81b9SCédric Le Goater 
2883d165f12SCédric Le Goater     smbus_eeprom_init_one(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 0), 0x50,
2893d165f12SCédric Le Goater                           eeprom_buf);
2903d165f12SCédric Le Goater 
291a87e81b9SCédric Le Goater     /* add a TMP423 temperature sensor */
292a87e81b9SCédric Le Goater     dev = i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 2),
293a87e81b9SCédric Le Goater                            "tmp423", 0x4c);
294a87e81b9SCédric Le Goater     object_property_set_int(OBJECT(dev), 31000, "temperature0", &error_abort);
295a87e81b9SCédric Le Goater     object_property_set_int(OBJECT(dev), 28000, "temperature1", &error_abort);
296a87e81b9SCédric Le Goater     object_property_set_int(OBJECT(dev), 20000, "temperature2", &error_abort);
297a87e81b9SCédric Le Goater     object_property_set_int(OBJECT(dev), 110000, "temperature3", &error_abort);
2982cf6cb50SCédric Le Goater }
2992cf6cb50SCédric Le Goater 
3002cf6cb50SCédric Le Goater static void ast2500_evb_i2c_init(AspeedBoardState *bmc)
3012cf6cb50SCédric Le Goater {
3022cf6cb50SCédric Le Goater     AspeedSoCState *soc = &bmc->soc;
3033d165f12SCédric Le Goater     uint8_t *eeprom_buf = g_malloc0(8 * 1024);
3043d165f12SCédric Le Goater 
3053d165f12SCédric Le Goater     smbus_eeprom_init_one(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 3), 0x50,
3063d165f12SCédric Le Goater                           eeprom_buf);
3072cf6cb50SCédric Le Goater 
3082cf6cb50SCédric Le Goater     /* The AST2500 EVB expects a LM75 but a TMP105 is compatible */
309044475f3SPhilippe Mathieu-Daudé     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 7),
310044475f3SPhilippe Mathieu-Daudé                      TYPE_TMP105, 0x4d);
3116c4567c7SCédric Le Goater 
3126c4567c7SCédric Le Goater     /* The AST2500 EVB does not have an RTC. Let's pretend that one is
3136c4567c7SCédric Le Goater      * plugged on the I2C bus header */
3146c4567c7SCédric Le Goater     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 11), "ds1338", 0x32);
3152cf6cb50SCédric Le Goater }
3162cf6cb50SCédric Le Goater 
317*ccc2c418SCédric Le Goater static void ast2600_evb_i2c_init(AspeedBoardState *bmc)
318*ccc2c418SCédric Le Goater {
319*ccc2c418SCédric Le Goater     /* Start with some devices on our I2C busses */
320*ccc2c418SCédric Le Goater     ast2500_evb_i2c_init(bmc);
321*ccc2c418SCédric Le Goater }
322*ccc2c418SCédric Le Goater 
3236c4567c7SCédric Le Goater static void romulus_bmc_i2c_init(AspeedBoardState *bmc)
3246c4567c7SCédric Le Goater {
3256c4567c7SCédric Le Goater     AspeedSoCState *soc = &bmc->soc;
3266c4567c7SCédric Le Goater 
3276c4567c7SCédric Le Goater     /* The romulus board expects Epson RX8900 I2C RTC but a ds1338 is
3286c4567c7SCédric Le Goater      * good enough */
3296c4567c7SCédric Le Goater     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 11), "ds1338", 0x32);
3306c4567c7SCédric Le Goater }
3316c4567c7SCédric Le Goater 
332aae7a18dSAdriana Kobylak static void swift_bmc_i2c_init(AspeedBoardState *bmc)
333aae7a18dSAdriana Kobylak {
334aae7a18dSAdriana Kobylak     AspeedSoCState *soc = &bmc->soc;
335aae7a18dSAdriana Kobylak 
336aae7a18dSAdriana Kobylak     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 3), "pca9552", 0x60);
337aae7a18dSAdriana Kobylak 
338aae7a18dSAdriana Kobylak     /* The swift board expects a TMP275 but a TMP105 is compatible */
339aae7a18dSAdriana Kobylak     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 7), "tmp105", 0x48);
340aae7a18dSAdriana Kobylak     /* The swift board expects a pca9551 but a pca9552 is compatible */
341aae7a18dSAdriana Kobylak     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 7), "pca9552", 0x60);
342aae7a18dSAdriana Kobylak 
343aae7a18dSAdriana Kobylak     /* The swift board expects an Epson RX8900 RTC but a ds1338 is compatible */
344aae7a18dSAdriana Kobylak     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 8), "ds1338", 0x32);
345aae7a18dSAdriana Kobylak     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 8), "pca9552", 0x60);
346aae7a18dSAdriana Kobylak 
347aae7a18dSAdriana Kobylak     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 9), "tmp423", 0x4c);
348aae7a18dSAdriana Kobylak     /* The swift board expects a pca9539 but a pca9552 is compatible */
349aae7a18dSAdriana Kobylak     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 9), "pca9552", 0x74);
350aae7a18dSAdriana Kobylak 
351aae7a18dSAdriana Kobylak     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 10), "tmp423", 0x4c);
352aae7a18dSAdriana Kobylak     /* The swift board expects a pca9539 but a pca9552 is compatible */
353aae7a18dSAdriana Kobylak     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 10), "pca9552",
354aae7a18dSAdriana Kobylak                      0x74);
355aae7a18dSAdriana Kobylak 
356aae7a18dSAdriana Kobylak     /* The swift board expects a TMP275 but a TMP105 is compatible */
357aae7a18dSAdriana Kobylak     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 12), "tmp105", 0x48);
358aae7a18dSAdriana Kobylak     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 12), "tmp105", 0x4a);
359aae7a18dSAdriana Kobylak }
360aae7a18dSAdriana Kobylak 
36162c2c2ebSCédric Le Goater static void witherspoon_bmc_i2c_init(AspeedBoardState *bmc)
36262c2c2ebSCédric Le Goater {
36362c2c2ebSCédric Le Goater     AspeedSoCState *soc = &bmc->soc;
3643d165f12SCédric Le Goater     uint8_t *eeprom_buf = g_malloc0(8 * 1024);
36562c2c2ebSCédric Le Goater 
366044475f3SPhilippe Mathieu-Daudé     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 3), TYPE_PCA9552,
367044475f3SPhilippe Mathieu-Daudé                      0x60);
3688c9a61d7SCédric Le Goater 
36962c2c2ebSCédric Le Goater     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 4), "tmp423", 0x4c);
37062c2c2ebSCédric Le Goater     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 5), "tmp423", 0x4c);
37162c2c2ebSCédric Le Goater 
37262c2c2ebSCédric Le Goater     /* The Witherspoon expects a TMP275 but a TMP105 is compatible */
373044475f3SPhilippe Mathieu-Daudé     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 9), TYPE_TMP105,
374044475f3SPhilippe Mathieu-Daudé                      0x4a);
3756c4567c7SCédric Le Goater 
3766c4567c7SCédric Le Goater     /* The witherspoon board expects Epson RX8900 I2C RTC but a ds1338 is
3776c4567c7SCédric Le Goater      * good enough */
3786c4567c7SCédric Le Goater     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 11), "ds1338", 0x32);
3793d165f12SCédric Le Goater 
3803d165f12SCédric Le Goater     smbus_eeprom_init_one(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 11), 0x51,
3813d165f12SCédric Le Goater                           eeprom_buf);
382044475f3SPhilippe Mathieu-Daudé     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 11), TYPE_PCA9552,
3838c9a61d7SCédric Le Goater                      0x60);
38462c2c2ebSCédric Le Goater }
38562c2c2ebSCédric Le Goater 
386fca9ca1bSCédric Le Goater static void aspeed_machine_init(MachineState *machine)
38762c2c2ebSCédric Le Goater {
388fca9ca1bSCédric Le Goater     AspeedMachineClass *amc = ASPEED_MACHINE_GET_CLASS(machine);
389fca9ca1bSCédric Le Goater 
390fca9ca1bSCédric Le Goater     aspeed_board_init(machine, amc->board);
39162c2c2ebSCédric Le Goater }
39262c2c2ebSCédric Le Goater 
393fca9ca1bSCédric Le Goater static void aspeed_machine_class_init(ObjectClass *oc, void *data)
39462c2c2ebSCédric Le Goater {
39562c2c2ebSCédric Le Goater     MachineClass *mc = MACHINE_CLASS(oc);
396fca9ca1bSCédric Le Goater     AspeedMachineClass *amc = ASPEED_MACHINE_CLASS(oc);
397fca9ca1bSCédric Le Goater     const AspeedBoardConfig *board = data;
39862c2c2ebSCédric Le Goater 
399fca9ca1bSCédric Le Goater     mc->desc = board->desc;
400fca9ca1bSCédric Le Goater     mc->init = aspeed_machine_init;
401ece09beeSCédric Le Goater     mc->max_cpus = ASPEED_CPUS_NUM;
40262c2c2ebSCédric Le Goater     mc->no_floppy = 1;
40362c2c2ebSCédric Le Goater     mc->no_cdrom = 1;
40462c2c2ebSCédric Le Goater     mc->no_parallel = 1;
405a9df9622SJoel Stanley     if (board->ram) {
406a9df9622SJoel Stanley         mc->default_ram_size = board->ram;
407a9df9622SJoel Stanley     }
408fca9ca1bSCédric Le Goater     amc->board = board;
40962c2c2ebSCédric Le Goater }
41062c2c2ebSCédric Le Goater 
411fca9ca1bSCédric Le Goater static const TypeInfo aspeed_machine_type = {
412fca9ca1bSCédric Le Goater     .name = TYPE_ASPEED_MACHINE,
41362c2c2ebSCédric Le Goater     .parent = TYPE_MACHINE,
414fca9ca1bSCédric Le Goater     .instance_size = sizeof(AspeedMachine),
415fca9ca1bSCédric Le Goater     .class_size = sizeof(AspeedMachineClass),
416fca9ca1bSCédric Le Goater     .abstract = true,
41762c2c2ebSCédric Le Goater };
41862c2c2ebSCédric Le Goater 
419fca9ca1bSCédric Le Goater static const AspeedBoardConfig aspeed_boards[] = {
42074fb1f38SCédric Le Goater     {
421fca9ca1bSCédric Le Goater         .name      = MACHINE_TYPE_NAME("palmetto-bmc"),
422fca9ca1bSCédric Le Goater         .desc      = "OpenPOWER Palmetto BMC (ARM926EJ-S)",
423fca9ca1bSCédric Le Goater         .soc_name  = "ast2400-a1",
424fca9ca1bSCédric Le Goater         .hw_strap1 = PALMETTO_BMC_HW_STRAP1,
425fca9ca1bSCédric Le Goater         .fmc_model = "n25q256a",
426fca9ca1bSCédric Le Goater         .spi_model = "mx25l25635e",
427fca9ca1bSCédric Le Goater         .num_cs    = 1,
428fca9ca1bSCédric Le Goater         .i2c_init  = palmetto_bmc_i2c_init,
429a9df9622SJoel Stanley         .ram       = 256 * MiB,
430fca9ca1bSCédric Le Goater     }, {
431fca9ca1bSCédric Le Goater         .name      = MACHINE_TYPE_NAME("ast2500-evb"),
432fca9ca1bSCédric Le Goater         .desc      = "Aspeed AST2500 EVB (ARM1176)",
433fca9ca1bSCédric Le Goater         .soc_name  = "ast2500-a1",
434fca9ca1bSCédric Le Goater         .hw_strap1 = AST2500_EVB_HW_STRAP1,
435fca9ca1bSCédric Le Goater         .fmc_model = "w25q256",
436fca9ca1bSCédric Le Goater         .spi_model = "mx25l25635e",
437fca9ca1bSCédric Le Goater         .num_cs    = 1,
438fca9ca1bSCédric Le Goater         .i2c_init  = ast2500_evb_i2c_init,
439a9df9622SJoel Stanley         .ram       = 512 * MiB,
440fca9ca1bSCédric Le Goater     }, {
441fca9ca1bSCédric Le Goater         .name      = MACHINE_TYPE_NAME("romulus-bmc"),
442fca9ca1bSCédric Le Goater         .desc      = "OpenPOWER Romulus BMC (ARM1176)",
443fca9ca1bSCédric Le Goater         .soc_name  = "ast2500-a1",
444fca9ca1bSCédric Le Goater         .hw_strap1 = ROMULUS_BMC_HW_STRAP1,
445fca9ca1bSCédric Le Goater         .fmc_model = "n25q256a",
446fca9ca1bSCédric Le Goater         .spi_model = "mx66l1g45g",
447fca9ca1bSCédric Le Goater         .num_cs    = 2,
448fca9ca1bSCédric Le Goater         .i2c_init  = romulus_bmc_i2c_init,
449a9df9622SJoel Stanley         .ram       = 512 * MiB,
450fca9ca1bSCédric Le Goater     }, {
451aae7a18dSAdriana Kobylak         .name      = MACHINE_TYPE_NAME("swift-bmc"),
452aae7a18dSAdriana Kobylak         .desc      = "OpenPOWER Swift BMC (ARM1176)",
453aae7a18dSAdriana Kobylak         .soc_name  = "ast2500-a1",
454aae7a18dSAdriana Kobylak         .hw_strap1 = SWIFT_BMC_HW_STRAP1,
455aae7a18dSAdriana Kobylak         .fmc_model = "mx66l1g45g",
456aae7a18dSAdriana Kobylak         .spi_model = "mx66l1g45g",
457aae7a18dSAdriana Kobylak         .num_cs    = 2,
458aae7a18dSAdriana Kobylak         .i2c_init  = swift_bmc_i2c_init,
459aae7a18dSAdriana Kobylak         .ram       = 512 * MiB,
460aae7a18dSAdriana Kobylak     }, {
461fca9ca1bSCédric Le Goater         .name      = MACHINE_TYPE_NAME("witherspoon-bmc"),
462fca9ca1bSCédric Le Goater         .desc      = "OpenPOWER Witherspoon BMC (ARM1176)",
463fca9ca1bSCédric Le Goater         .soc_name  = "ast2500-a1",
464fca9ca1bSCédric Le Goater         .hw_strap1 = WITHERSPOON_BMC_HW_STRAP1,
465fca9ca1bSCédric Le Goater         .fmc_model = "mx25l25635e",
466fca9ca1bSCédric Le Goater         .spi_model = "mx66l1g45g",
467fca9ca1bSCédric Le Goater         .num_cs    = 2,
468fca9ca1bSCédric Le Goater         .i2c_init  = witherspoon_bmc_i2c_init,
469a9df9622SJoel Stanley         .ram       = 512 * MiB,
470*ccc2c418SCédric Le Goater     }, {
471*ccc2c418SCédric Le Goater         .name      = MACHINE_TYPE_NAME("ast2600-evb"),
472*ccc2c418SCédric Le Goater         .desc      = "Aspeed AST2600 EVB (Cortex A7)",
473*ccc2c418SCédric Le Goater         .soc_name  = "ast2600-a0",
474*ccc2c418SCédric Le Goater         .hw_strap1 = AST2600_EVB_HW_STRAP1,
475*ccc2c418SCédric Le Goater         .hw_strap2 = AST2600_EVB_HW_STRAP2,
476*ccc2c418SCédric Le Goater         .fmc_model = "w25q512jv",
477*ccc2c418SCédric Le Goater         .spi_model = "mx66u51235f",
478*ccc2c418SCédric Le Goater         .num_cs    = 1,
479*ccc2c418SCédric Le Goater         .i2c_init  = ast2600_evb_i2c_init,
480*ccc2c418SCédric Le Goater         .ram       = 1 * GiB,
481fca9ca1bSCédric Le Goater     },
482fca9ca1bSCédric Le Goater };
483fca9ca1bSCédric Le Goater 
484fca9ca1bSCédric Le Goater static void aspeed_machine_types(void)
485fca9ca1bSCédric Le Goater {
486fca9ca1bSCédric Le Goater     int i;
487fca9ca1bSCédric Le Goater 
488fca9ca1bSCédric Le Goater     type_register_static(&aspeed_machine_type);
489fca9ca1bSCédric Le Goater     for (i = 0; i < ARRAY_SIZE(aspeed_boards); ++i) {
490fca9ca1bSCédric Le Goater         TypeInfo ti = {
491fca9ca1bSCédric Le Goater             .name       = aspeed_boards[i].name,
492fca9ca1bSCédric Le Goater             .parent     = TYPE_ASPEED_MACHINE,
493fca9ca1bSCédric Le Goater             .class_init = aspeed_machine_class_init,
494fca9ca1bSCédric Le Goater             .class_data = (void *)&aspeed_boards[i],
495fca9ca1bSCédric Le Goater         };
496fca9ca1bSCédric Le Goater         type_register(&ti);
497fca9ca1bSCédric Le Goater     }
49874fb1f38SCédric Le Goater }
49974fb1f38SCédric Le Goater 
500fca9ca1bSCédric Le Goater type_init(aspeed_machine_types)
501