2 * OpenPOWER Palmetto BMC
4 * Andrew Jeffery <andrew@aj.id.au>
6 * Copyright 2016 IBM Corp.
8 * This code is licensed under the GPL version 2 or later. See
9 * the COPYING file in the top-level directory.
12 #include "qemu/osdep.h"
13 #include "qapi/error.h"
14 #include "qemu-common.h"
16 #include "exec/address-spaces.h"
17 #include "hw/arm/arm.h"
18 #include "hw/arm/aspeed_soc.h"
19 #include "hw/boards.h"
21 #include "sysemu/block-backend.h"
22 #include "hw/loader.h"
23 #include "qemu/error-report.h"
25 static struct arm_boot_info aspeed_board_binfo
= {
26 .board_id
= -1, /* device-tree-only board */
30 typedef struct AspeedBoardState
{
35 typedef struct AspeedBoardConfig
{
38 const char *fmc_model
;
39 const char *spi_model
;
41 void (*i2c_init
)(AspeedBoardState
*bmc
);
51 /* Palmetto hardware value: 0x120CE416 */
52 #define PALMETTO_BMC_HW_STRAP1 ( \
53 SCU_AST2400_HW_STRAP_DRAM_SIZE(DRAM_SIZE_256MB) | \
54 SCU_AST2400_HW_STRAP_DRAM_CONFIG(2 /* DDR3 with CL=6, CWL=5 */) | \
55 SCU_AST2400_HW_STRAP_ACPI_DIS | \
56 SCU_AST2400_HW_STRAP_SET_CLK_SOURCE(AST2400_CLK_48M_IN) | \
57 SCU_HW_STRAP_VGA_CLASS_CODE | \
58 SCU_HW_STRAP_LPC_RESET_PIN | \
59 SCU_HW_STRAP_SPI_MODE(SCU_HW_STRAP_SPI_M_S_EN) | \
60 SCU_AST2400_HW_STRAP_SET_CPU_AHB_RATIO(AST2400_CPU_AHB_RATIO_2_1) | \
61 SCU_HW_STRAP_SPI_WIDTH | \
62 SCU_HW_STRAP_VGA_SIZE_SET(VGA_16M_DRAM) | \
63 SCU_AST2400_HW_STRAP_BOOT_MODE(AST2400_SPI_BOOT))
65 /* AST2500 evb hardware value: 0xF100C2E6 */
66 #define AST2500_EVB_HW_STRAP1 (( \
67 AST2500_HW_STRAP1_DEFAULTS | \
68 SCU_AST2500_HW_STRAP_SPI_AUTOFETCH_ENABLE | \
69 SCU_AST2500_HW_STRAP_GPIO_STRAP_ENABLE | \
70 SCU_AST2500_HW_STRAP_UART_DEBUG | \
71 SCU_AST2500_HW_STRAP_DDR4_ENABLE | \
72 SCU_HW_STRAP_MAC1_RGMII | \
73 SCU_HW_STRAP_MAC0_RGMII) & \
74 ~SCU_HW_STRAP_2ND_BOOT_WDT)
76 /* Romulus hardware value: 0xF10AD206 */
77 #define ROMULUS_BMC_HW_STRAP1 ( \
78 AST2500_HW_STRAP1_DEFAULTS | \
79 SCU_AST2500_HW_STRAP_SPI_AUTOFETCH_ENABLE | \
80 SCU_AST2500_HW_STRAP_GPIO_STRAP_ENABLE | \
81 SCU_AST2500_HW_STRAP_UART_DEBUG | \
82 SCU_AST2500_HW_STRAP_DDR4_ENABLE | \
83 SCU_AST2500_HW_STRAP_ACPI_ENABLE | \
84 SCU_HW_STRAP_SPI_MODE(SCU_HW_STRAP_SPI_MASTER))
86 /* Witherspoon hardware value: 0xF10AD216 (but use romulus definition) */
87 #define WITHERSPOON_BMC_HW_STRAP1 ROMULUS_BMC_HW_STRAP1
89 static void palmetto_bmc_i2c_init(AspeedBoardState
*bmc
);
90 static void ast2500_evb_i2c_init(AspeedBoardState
*bmc
);
91 static void witherspoon_bmc_i2c_init(AspeedBoardState
*bmc
);
93 static const AspeedBoardConfig aspeed_boards
[] = {
95 .soc_name
= "ast2400-a1",
96 .hw_strap1
= PALMETTO_BMC_HW_STRAP1
,
97 .fmc_model
= "n25q256a",
98 .spi_model
= "mx25l25635e",
100 .i2c_init
= palmetto_bmc_i2c_init
,
103 .soc_name
= "ast2500-a1",
104 .hw_strap1
= AST2500_EVB_HW_STRAP1
,
105 .fmc_model
= "n25q256a",
106 .spi_model
= "mx25l25635e",
108 .i2c_init
= ast2500_evb_i2c_init
,
111 .soc_name
= "ast2500-a1",
112 .hw_strap1
= ROMULUS_BMC_HW_STRAP1
,
113 .fmc_model
= "n25q256a",
114 .spi_model
= "mx66l1g45g",
117 [WITHERSPOON_BMC
] = {
118 .soc_name
= "ast2500-a1",
119 .hw_strap1
= WITHERSPOON_BMC_HW_STRAP1
,
120 .fmc_model
= "mx25l25635e",
121 .spi_model
= "mx66l1g45g",
123 .i2c_init
= witherspoon_bmc_i2c_init
,
127 #define FIRMWARE_ADDR 0x0
129 static void write_boot_rom(DriveInfo
*dinfo
, hwaddr addr
, size_t rom_size
,
132 BlockBackend
*blk
= blk_by_legacy_dinfo(dinfo
);
136 /* The block backend size should have already been 'validated' by
137 * the creation of the m25p80 object.
139 size
= blk_getlength(blk
);
141 error_setg(errp
, "failed to get flash size");
145 if (rom_size
> size
) {
149 storage
= g_new0(uint8_t, rom_size
);
150 if (blk_pread(blk
, 0, storage
, rom_size
) < 0) {
151 error_setg(errp
, "failed to read the initial flash content");
155 rom_add_blob_fixed("aspeed.boot_rom", storage
, rom_size
, addr
);
159 static void aspeed_board_init_flashes(AspeedSMCState
*s
, const char *flashtype
,
164 for (i
= 0; i
< s
->num_cs
; ++i
) {
165 AspeedSMCFlash
*fl
= &s
->flashes
[i
];
166 DriveInfo
*dinfo
= drive_get_next(IF_MTD
);
169 fl
->flash
= ssi_create_slave_no_init(s
->spi
, flashtype
);
171 qdev_prop_set_drive(fl
->flash
, "drive", blk_by_legacy_dinfo(dinfo
),
174 qdev_init_nofail(fl
->flash
);
176 cs_line
= qdev_get_gpio_in_named(fl
->flash
, SSI_GPIO_CS
, 0);
177 sysbus_connect_irq(SYS_BUS_DEVICE(s
), i
+ 1, cs_line
);
181 static void aspeed_board_init(MachineState
*machine
,
182 const AspeedBoardConfig
*cfg
)
184 AspeedBoardState
*bmc
;
186 DriveInfo
*drive0
= drive_get(IF_MTD
, 0, 0);
188 bmc
= g_new0(AspeedBoardState
, 1);
189 object_initialize(&bmc
->soc
, (sizeof(bmc
->soc
)), cfg
->soc_name
);
190 object_property_add_child(OBJECT(machine
), "soc", OBJECT(&bmc
->soc
),
193 sc
= ASPEED_SOC_GET_CLASS(&bmc
->soc
);
195 object_property_set_uint(OBJECT(&bmc
->soc
), ram_size
, "ram-size",
197 object_property_set_int(OBJECT(&bmc
->soc
), cfg
->hw_strap1
, "hw-strap1",
199 object_property_set_int(OBJECT(&bmc
->soc
), cfg
->num_cs
, "num-cs",
201 if (machine
->kernel_filename
) {
203 * When booting with a -kernel command line there is no u-boot
204 * that runs to unlock the SCU. In this case set the default to
205 * be unlocked as the kernel expects
207 object_property_set_int(OBJECT(&bmc
->soc
), ASPEED_SCU_PROT_KEY
,
208 "hw-prot-key", &error_abort
);
210 object_property_set_bool(OBJECT(&bmc
->soc
), true, "realized",
214 * Allocate RAM after the memory controller has checked the size
215 * was valid. If not, a default value is used.
217 ram_size
= object_property_get_uint(OBJECT(&bmc
->soc
), "ram-size",
220 memory_region_allocate_system_memory(&bmc
->ram
, NULL
, "ram", ram_size
);
221 memory_region_add_subregion(get_system_memory(), sc
->info
->sdram_base
,
223 object_property_add_const_link(OBJECT(&bmc
->soc
), "ram", OBJECT(&bmc
->ram
),
226 aspeed_board_init_flashes(&bmc
->soc
.fmc
, cfg
->fmc_model
, &error_abort
);
227 aspeed_board_init_flashes(&bmc
->soc
.spi
[0], cfg
->spi_model
, &error_abort
);
229 /* Install first FMC flash content as a boot rom. */
231 AspeedSMCFlash
*fl
= &bmc
->soc
.fmc
.flashes
[0];
232 MemoryRegion
*boot_rom
= g_new(MemoryRegion
, 1);
235 * create a ROM region using the default mapping window size of
236 * the flash module. The window size is 64MB for the AST2400
237 * SoC and 128MB for the AST2500 SoC, which is twice as big as
238 * needed by the flash modules of the Aspeed machines.
240 memory_region_init_rom(boot_rom
, OBJECT(bmc
), "aspeed.boot_rom",
241 fl
->size
, &error_abort
);
242 memory_region_add_subregion(get_system_memory(), FIRMWARE_ADDR
,
244 write_boot_rom(drive0
, FIRMWARE_ADDR
, fl
->size
, &error_abort
);
247 aspeed_board_binfo
.kernel_filename
= machine
->kernel_filename
;
248 aspeed_board_binfo
.initrd_filename
= machine
->initrd_filename
;
249 aspeed_board_binfo
.kernel_cmdline
= machine
->kernel_cmdline
;
250 aspeed_board_binfo
.ram_size
= ram_size
;
251 aspeed_board_binfo
.loader_start
= sc
->info
->sdram_base
;
257 arm_load_kernel(ARM_CPU(first_cpu
), &aspeed_board_binfo
);
260 static void palmetto_bmc_i2c_init(AspeedBoardState
*bmc
)
262 AspeedSoCState
*soc
= &bmc
->soc
;
265 /* The palmetto platform expects a ds3231 RTC but a ds1338 is
266 * enough to provide basic RTC features. Alarms will be missing */
267 i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc
->i2c
), 0), "ds1338", 0x68);
269 /* add a TMP423 temperature sensor */
270 dev
= i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc
->i2c
), 2),
272 object_property_set_int(OBJECT(dev
), 31000, "temperature0", &error_abort
);
273 object_property_set_int(OBJECT(dev
), 28000, "temperature1", &error_abort
);
274 object_property_set_int(OBJECT(dev
), 20000, "temperature2", &error_abort
);
275 object_property_set_int(OBJECT(dev
), 110000, "temperature3", &error_abort
);
278 static void palmetto_bmc_init(MachineState
*machine
)
280 aspeed_board_init(machine
, &aspeed_boards
[PALMETTO_BMC
]);
283 static void palmetto_bmc_class_init(ObjectClass
*oc
, void *data
)
285 MachineClass
*mc
= MACHINE_CLASS(oc
);
287 mc
->desc
= "OpenPOWER Palmetto BMC (ARM926EJ-S)";
288 mc
->init
= palmetto_bmc_init
;
296 static const TypeInfo palmetto_bmc_type
= {
297 .name
= MACHINE_TYPE_NAME("palmetto-bmc"),
298 .parent
= TYPE_MACHINE
,
299 .class_init
= palmetto_bmc_class_init
,
302 static void ast2500_evb_i2c_init(AspeedBoardState
*bmc
)
304 AspeedSoCState
*soc
= &bmc
->soc
;
306 /* The AST2500 EVB expects a LM75 but a TMP105 is compatible */
307 i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc
->i2c
), 7), "tmp105", 0x4d);
310 static void ast2500_evb_init(MachineState
*machine
)
312 aspeed_board_init(machine
, &aspeed_boards
[AST2500_EVB
]);
315 static void ast2500_evb_class_init(ObjectClass
*oc
, void *data
)
317 MachineClass
*mc
= MACHINE_CLASS(oc
);
319 mc
->desc
= "Aspeed AST2500 EVB (ARM1176)";
320 mc
->init
= ast2500_evb_init
;
328 static const TypeInfo ast2500_evb_type
= {
329 .name
= MACHINE_TYPE_NAME("ast2500-evb"),
330 .parent
= TYPE_MACHINE
,
331 .class_init
= ast2500_evb_class_init
,
334 static void romulus_bmc_init(MachineState
*machine
)
336 aspeed_board_init(machine
, &aspeed_boards
[ROMULUS_BMC
]);
339 static void romulus_bmc_class_init(ObjectClass
*oc
, void *data
)
341 MachineClass
*mc
= MACHINE_CLASS(oc
);
343 mc
->desc
= "OpenPOWER Romulus BMC (ARM1176)";
344 mc
->init
= romulus_bmc_init
;
352 static const TypeInfo romulus_bmc_type
= {
353 .name
= MACHINE_TYPE_NAME("romulus-bmc"),
354 .parent
= TYPE_MACHINE
,
355 .class_init
= romulus_bmc_class_init
,
358 static void witherspoon_bmc_i2c_init(AspeedBoardState
*bmc
)
360 AspeedSoCState
*soc
= &bmc
->soc
;
362 i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc
->i2c
), 4), "tmp423", 0x4c);
363 i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc
->i2c
), 5), "tmp423", 0x4c);
365 /* The Witherspoon expects a TMP275 but a TMP105 is compatible */
366 i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc
->i2c
), 9), "tmp105", 0x4a);
369 static void witherspoon_bmc_init(MachineState
*machine
)
371 aspeed_board_init(machine
, &aspeed_boards
[WITHERSPOON_BMC
]);
374 static void witherspoon_bmc_class_init(ObjectClass
*oc
, void *data
)
376 MachineClass
*mc
= MACHINE_CLASS(oc
);
378 mc
->desc
= "OpenPOWER Witherspoon BMC (ARM1176)";
379 mc
->init
= witherspoon_bmc_init
;
387 static const TypeInfo witherspoon_bmc_type
= {
388 .name
= MACHINE_TYPE_NAME("witherspoon-bmc"),
389 .parent
= TYPE_MACHINE
,
390 .class_init
= witherspoon_bmc_class_init
,
393 static void aspeed_machine_init(void)
395 type_register_static(&palmetto_bmc_type
);
396 type_register_static(&ast2500_evb_type
);
397 type_register_static(&romulus_bmc_type
);
398 type_register_static(&witherspoon_bmc_type
);
401 type_init(aspeed_machine_init
)