| 1 | /* |
| 2 | * OpenPOWER Witherspoon |
| 3 | * |
| 4 | * Copyright 2016 IBM Corp. |
| 5 | * |
| 6 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 7 | */ |
| 8 | |
| 9 | #include "qemu/osdep.h" |
| 10 | #include "qapi/error.h" |
| 11 | #include "hw/arm/machines-qom.h" |
| 12 | #include "hw/arm/aspeed.h" |
| 13 | #include "hw/arm/aspeed_soc.h" |
| 14 | #include "hw/misc/led.h" |
| 15 | #include "hw/sensor/tmp105.h" |
| 16 | #include "hw/i2c/smbus_eeprom.h" |
| 17 | #include "hw/gpio/pca9552.h" |
| 18 | |
| 19 | /* Witherspoon hardware value: 0xF10AD216 */ |
| 20 | #define WITHERSPOON_BMC_HW_STRAP1 ( \ |
| 21 | AST2500_HW_STRAP1_DEFAULTS | \ |
| 22 | SCU_AST2500_HW_STRAP_SPI_AUTOFETCH_ENABLE | \ |
| 23 | SCU_AST2500_HW_STRAP_GPIO_STRAP_ENABLE | \ |
| 24 | SCU_AST2500_HW_STRAP_UART_DEBUG | \ |
| 25 | SCU_AST2500_HW_STRAP_DDR4_ENABLE | \ |
| 26 | SCU_AST2500_HW_STRAP_ACPI_ENABLE | \ |
| 27 | SCU_HW_STRAP_SPI_MODE(SCU_HW_STRAP_SPI_MASTER)) |
| 28 | |
| 29 | static void witherspoon_bmc_i2c_init(AspeedMachineState *bmc) |
| 30 | { |
| 31 | static const struct { |
| 32 | unsigned gpio_id; |
| 33 | LEDColor color; |
| 34 | const char *description; |
| 35 | bool gpio_polarity; |
| 36 | } pca1_leds[] = { |
| 37 | {13, LED_COLOR_GREEN, "front-fault-4", GPIO_POLARITY_ACTIVE_LOW}, |
| 38 | {14, LED_COLOR_GREEN, "front-power-3", GPIO_POLARITY_ACTIVE_LOW}, |
| 39 | {15, LED_COLOR_GREEN, "front-id-5", GPIO_POLARITY_ACTIVE_LOW}, |
| 40 | }; |
| 41 | AspeedSoCState *soc = bmc->soc; |
| 42 | uint8_t *eeprom_buf = g_malloc0(8 * 1024); |
| 43 | DeviceState *dev; |
| 44 | LEDState *led; |
| 45 | |
| 46 | /* Bus 3: TODO bmp280@77 */ |
| 47 | dev = DEVICE(i2c_slave_new(TYPE_PCA9552, 0x60)); |
| 48 | qdev_prop_set_string(dev, "description", "pca1"); |
| 49 | i2c_slave_realize_and_unref(I2C_SLAVE(dev), |
| 50 | aspeed_i2c_get_bus(&soc->i2c, 3), |
| 51 | &error_fatal); |
| 52 | |
| 53 | for (size_t i = 0; i < ARRAY_SIZE(pca1_leds); i++) { |
| 54 | led = led_create_simple(OBJECT(bmc), |
| 55 | pca1_leds[i].gpio_polarity, |
| 56 | pca1_leds[i].color, |
| 57 | pca1_leds[i].description); |
| 58 | qdev_connect_gpio_out(dev, pca1_leds[i].gpio_id, |
| 59 | qdev_get_gpio_in(DEVICE(led), 0)); |
| 60 | } |
| 61 | i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 3), "dps310", 0x76); |
| 62 | i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 3), "max31785", 0x52); |
| 63 | i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 4), "tmp423", 0x4c); |
| 64 | i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 5), "tmp423", 0x4c); |
| 65 | |
| 66 | /* The Witherspoon expects a TMP275 but a TMP105 is compatible */ |
| 67 | i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 9), TYPE_TMP105, |
| 68 | 0x4a); |
| 69 | |
| 70 | /* |
| 71 | * The witherspoon board expects Epson RX8900 I2C RTC but a ds1338 is |
| 72 | * good enough |
| 73 | */ |
| 74 | i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 11), "ds1338", 0x32); |
| 75 | |
| 76 | smbus_eeprom_init_one(aspeed_i2c_get_bus(&soc->i2c, 11), 0x51, |
| 77 | eeprom_buf); |
| 78 | dev = DEVICE(i2c_slave_new(TYPE_PCA9552, 0x60)); |
| 79 | qdev_prop_set_string(dev, "description", "pca0"); |
| 80 | i2c_slave_realize_and_unref(I2C_SLAVE(dev), |
| 81 | aspeed_i2c_get_bus(&soc->i2c, 11), |
| 82 | &error_fatal); |
| 83 | /* Bus 11: TODO ucd90160@64 */ |
| 84 | } |
| 85 | |
| 86 | static void aspeed_machine_witherspoon_class_init(ObjectClass *oc, |
| 87 | const void *data) |
| 88 | { |
| 89 | MachineClass *mc = MACHINE_CLASS(oc); |
| 90 | AspeedMachineClass *amc = ASPEED_MACHINE_CLASS(oc); |
| 91 | |
| 92 | mc->desc = "OpenPOWER Witherspoon BMC (ARM1176)"; |
| 93 | amc->soc_name = "ast2500-a1"; |
| 94 | amc->hw_strap1 = WITHERSPOON_BMC_HW_STRAP1; |
| 95 | amc->fmc_model = "mx25l25635f"; |
| 96 | amc->spi_model = "mx66l1g45g"; |
| 97 | amc->num_cs = 2; |
| 98 | amc->i2c_init = witherspoon_bmc_i2c_init; |
| 99 | mc->default_ram_size = 512 * MiB; |
| 100 | aspeed_machine_class_init_cpus_defaults(mc); |
| 101 | }; |
| 102 | |
| 103 | static const TypeInfo aspeed_ast2500_witherspoon_types[] = { |
| 104 | { |
| 105 | .name = MACHINE_TYPE_NAME("witherspoon-bmc"), |
| 106 | .parent = TYPE_ASPEED_MACHINE, |
| 107 | .class_init = aspeed_machine_witherspoon_class_init, |
| 108 | .interfaces = arm_machine_interfaces, |
| 109 | } |
| 110 | }; |
| 111 | |
| 112 | DEFINE_TYPES(aspeed_ast2500_witherspoon_types) |