| 1 | /* |
| 2 | * Facebook Fuji |
| 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/i2c/i2c_mux_pca954x.h" |
| 15 | #include "hw/sensor/tmp105.h" |
| 16 | #include "hw/nvram/eeprom_at24c.h" |
| 17 | |
| 18 | #define TYPE_LM75 TYPE_TMP105 |
| 19 | #define TYPE_TMP75 TYPE_TMP105 |
| 20 | #define TYPE_TMP422 "tmp422" |
| 21 | |
| 22 | /* Fuji hardware value */ |
| 23 | #define FUJI_BMC_HW_STRAP1 0x00000000 |
| 24 | #define FUJI_BMC_HW_STRAP2 0x00000000 |
| 25 | #define FUJI_BMC_RAM_SIZE ASPEED_RAM_SIZE(2 * GiB) |
| 26 | |
| 27 | static void get_pca9548_channels(I2CBus *bus, uint8_t mux_addr, |
| 28 | I2CBus **channels) |
| 29 | { |
| 30 | I2CSlave *mux = i2c_slave_create_simple(bus, "pca9548", mux_addr); |
| 31 | for (int i = 0; i < 8; i++) { |
| 32 | channels[i] = pca954x_i2c_get_bus(mux, i); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | static void fuji_bmc_i2c_init(AspeedMachineState *bmc) |
| 37 | { |
| 38 | AspeedSoCState *soc = bmc->soc; |
| 39 | I2CBus *i2c[144] = {}; |
| 40 | |
| 41 | for (int i = 0; i < 16; i++) { |
| 42 | i2c[i] = aspeed_i2c_get_bus(&soc->i2c, i); |
| 43 | } |
| 44 | I2CBus *i2c180 = i2c[2]; |
| 45 | I2CBus *i2c480 = i2c[8]; |
| 46 | I2CBus *i2c600 = i2c[11]; |
| 47 | |
| 48 | get_pca9548_channels(i2c180, 0x70, &i2c[16]); |
| 49 | get_pca9548_channels(i2c480, 0x70, &i2c[24]); |
| 50 | /* NOTE: The device tree skips [32, 40) in the alias numbering */ |
| 51 | get_pca9548_channels(i2c600, 0x77, &i2c[40]); |
| 52 | get_pca9548_channels(i2c[24], 0x71, &i2c[48]); |
| 53 | get_pca9548_channels(i2c[25], 0x72, &i2c[56]); |
| 54 | get_pca9548_channels(i2c[26], 0x76, &i2c[64]); |
| 55 | get_pca9548_channels(i2c[27], 0x76, &i2c[72]); |
| 56 | for (int i = 0; i < 8; i++) { |
| 57 | get_pca9548_channels(i2c[40 + i], 0x76, &i2c[80 + i * 8]); |
| 58 | } |
| 59 | |
| 60 | i2c_slave_create_simple(i2c[17], TYPE_LM75, 0x4c); |
| 61 | i2c_slave_create_simple(i2c[17], TYPE_LM75, 0x4d); |
| 62 | |
| 63 | /* |
| 64 | * EEPROM 24c64 size is 64Kbits or 8 Kbytes |
| 65 | * 24c02 size is 2Kbits or 256 bytes |
| 66 | */ |
| 67 | at24c_eeprom_init(i2c[19], 0x52, 8 * KiB); |
| 68 | at24c_eeprom_init(i2c[20], 0x50, 256); |
| 69 | at24c_eeprom_init(i2c[22], 0x52, 256); |
| 70 | |
| 71 | i2c_slave_create_simple(i2c[3], TYPE_LM75, 0x48); |
| 72 | i2c_slave_create_simple(i2c[3], TYPE_LM75, 0x49); |
| 73 | i2c_slave_create_simple(i2c[3], TYPE_LM75, 0x4a); |
| 74 | i2c_slave_create_simple(i2c[3], TYPE_TMP422, 0x4c); |
| 75 | |
| 76 | at24c_eeprom_init(i2c[8], 0x51, 8 * KiB); |
| 77 | i2c_slave_create_simple(i2c[8], TYPE_LM75, 0x4a); |
| 78 | |
| 79 | i2c_slave_create_simple(i2c[50], TYPE_LM75, 0x4c); |
| 80 | at24c_eeprom_init(i2c[50], 0x52, 8 * KiB); |
| 81 | i2c_slave_create_simple(i2c[51], TYPE_TMP75, 0x48); |
| 82 | i2c_slave_create_simple(i2c[52], TYPE_TMP75, 0x49); |
| 83 | |
| 84 | i2c_slave_create_simple(i2c[59], TYPE_TMP75, 0x48); |
| 85 | i2c_slave_create_simple(i2c[60], TYPE_TMP75, 0x49); |
| 86 | |
| 87 | at24c_eeprom_init(i2c[65], 0x53, 8 * KiB); |
| 88 | i2c_slave_create_simple(i2c[66], TYPE_TMP75, 0x49); |
| 89 | i2c_slave_create_simple(i2c[66], TYPE_TMP75, 0x48); |
| 90 | at24c_eeprom_init(i2c[68], 0x52, 8 * KiB); |
| 91 | at24c_eeprom_init(i2c[69], 0x52, 8 * KiB); |
| 92 | at24c_eeprom_init(i2c[70], 0x52, 8 * KiB); |
| 93 | at24c_eeprom_init(i2c[71], 0x52, 8 * KiB); |
| 94 | |
| 95 | at24c_eeprom_init(i2c[73], 0x53, 8 * KiB); |
| 96 | i2c_slave_create_simple(i2c[74], TYPE_TMP75, 0x49); |
| 97 | i2c_slave_create_simple(i2c[74], TYPE_TMP75, 0x48); |
| 98 | at24c_eeprom_init(i2c[76], 0x52, 8 * KiB); |
| 99 | at24c_eeprom_init(i2c[77], 0x52, 8 * KiB); |
| 100 | at24c_eeprom_init(i2c[78], 0x52, 8 * KiB); |
| 101 | at24c_eeprom_init(i2c[79], 0x52, 8 * KiB); |
| 102 | at24c_eeprom_init(i2c[28], 0x50, 256); |
| 103 | |
| 104 | for (int i = 0; i < 8; i++) { |
| 105 | at24c_eeprom_init(i2c[81 + i * 8], 0x56, 64 * KiB); |
| 106 | i2c_slave_create_simple(i2c[82 + i * 8], TYPE_TMP75, 0x48); |
| 107 | i2c_slave_create_simple(i2c[83 + i * 8], TYPE_TMP75, 0x4b); |
| 108 | i2c_slave_create_simple(i2c[84 + i * 8], TYPE_TMP75, 0x4a); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | static void aspeed_machine_fuji_class_init(ObjectClass *oc, const void *data) |
| 113 | { |
| 114 | MachineClass *mc = MACHINE_CLASS(oc); |
| 115 | AspeedMachineClass *amc = ASPEED_MACHINE_CLASS(oc); |
| 116 | |
| 117 | mc->desc = "Facebook Fuji BMC (Cortex-A7)"; |
| 118 | amc->soc_name = "ast2600-a3"; |
| 119 | amc->hw_strap1 = FUJI_BMC_HW_STRAP1; |
| 120 | amc->hw_strap2 = FUJI_BMC_HW_STRAP2; |
| 121 | amc->fmc_model = "mx66l1g45g"; |
| 122 | amc->spi_model = "mx66l1g45g"; |
| 123 | amc->num_cs = 2; |
| 124 | amc->macs_mask = ASPEED_MAC3_ON; |
| 125 | amc->i2c_init = fuji_bmc_i2c_init; |
| 126 | amc->uart_default = ASPEED_DEV_UART1; |
| 127 | mc->default_ram_size = FUJI_BMC_RAM_SIZE; |
| 128 | aspeed_machine_class_init_cpus_defaults(mc); |
| 129 | }; |
| 130 | |
| 131 | static const TypeInfo aspeed_ast2600_fuji_types[] = { |
| 132 | { |
| 133 | .name = MACHINE_TYPE_NAME("fuji-bmc"), |
| 134 | .parent = TYPE_ASPEED_MACHINE, |
| 135 | .class_init = aspeed_machine_fuji_class_init, |
| 136 | .interfaces = arm_machine_interfaces, |
| 137 | } |
| 138 | }; |
| 139 | |
| 140 | DEFINE_TYPES(aspeed_ast2600_fuji_types) |