void set_sys_config()

in meta-facebook/yv35-cl/src/platform/hwmon.c [465:559]


void set_sys_config()
{
	I2C_MSG i2c_msg;
	uint8_t retry = 3;

	/* According hardware design, BIC can check the class type through GPIOs.
	 * The board ID is "0000" if the class type is class1.
	 * The board ID is "0001" if the class type is calss2.
	 */
	if (gpio_get(BOARD_ID0)) { // HW design: class1 board_ID 0000, class2 board_ID 0001
		bic_class = sys_class_2;
	} else {
		bic_class = sys_class_1;
	}

	uint8_t tx_len, rx_len;
	uint8_t class_type = 0x0;
	char *data = (uint8_t *)malloc(I2C_DATA_SIZE * sizeof(uint8_t));
	if (data == NULL) {
		printf("Could not allocate memory for I2C data.\n");
		return;
	}

	/* Read the expansion present from CPLD's class type register
	 * CPLD Class Type Register(05h)
	 * Bit[7:4] - Board ID(0000b: Class-1, 0001b: Class-2)
	 * Bit[3] - 2ou x8/x16 Riser Expansion Present
	 * Bit[2] - 1ou Expansion Present Pin
	 * Bit[1:0] - Reserved
	 */
	tx_len = 1;
	rx_len = 1;
	memset(data, 0, I2C_DATA_SIZE);
	data[0] = CPLD_CLASS_TYPE_REG;
	i2c_msg = construct_i2c_message(i2c_bus_to_index[1], CPLD_ADDR, tx_len, data, rx_len);
	if (!i2c_master_read(&i2c_msg, retry)) {
		class_type = i2c_msg.data[0];
		is_1ou_present = (class_type & 0x4 ? false : true);
		is_2ou_present = (class_type & 0x8 ? false : true);
	} else {
		printf("Failed to read expansion present from CPLD\n");
	}
	/* Set the class type to CPLD's class type register(the bit[4] of offset 05h) */
	tx_len = 2;
	rx_len = 0;
	memset(data, 0, I2C_DATA_SIZE);
	data[0] = CPLD_CLASS_TYPE_REG;
	data[1] = (((uint8_t)bic_class << 4) & 0x10) | class_type;
	i2c_msg = construct_i2c_message(i2c_bus_to_index[1], CPLD_ADDR, tx_len, data, rx_len);
	if (i2c_master_write(&i2c_msg, retry)) {
		printf("Failed to set class type to CPLD)\n");
	}

	/* Get the board revision to CPLD's board rev id reg(the bit[3:0] of offset 08h)
	 * CPLD Board REV ID Register(08h)
	 * Bit[7:4] - Reserved
	 * Bit[3:0] - Board revision
	 */
	tx_len = 1;
	rx_len = 1;
	memset(data, 0, I2C_DATA_SIZE);
	data[0] = CPLD_BOARD_REV_ID_REG;
	i2c_msg = construct_i2c_message(i2c_bus_to_index[1], CPLD_ADDR, tx_len, data, rx_len);
	int ret = i2c_master_read(&i2c_msg, retry);
	if (ret == 0) {
		board_revision = i2c_msg.data[0] & 0xF;
	} else {
		printf("Failed to read board ID from CPLD\n");
	}
	printk("BIC class type(class-%d), 1ou present status(%d), 2ou present status(%d), board revision(0x%x)\n",
	       (int)bic_class + 1, (int)is_1ou_present, (int)is_2ou_present, board_revision);

	if (is_2ou_present) {
		tx_len = 1;
		rx_len = 1;
		memset(data, 0, I2C_DATA_SIZE);
		data[0] = CPLD_2OU_EXPANSION_CARD_REG;
		i2c_msg =
			construct_i2c_message(i2c_bus_to_index[1], CPLD_ADDR, tx_len, data, rx_len);
		if (!i2c_master_read(&i2c_msg, retry)) {
			if (i2c_msg.data[0] == type_2ou_dpv2) {
				card_type_2ou = type_2ou_dpv2;
			} else if (i2c_msg.data[0] == type_2ou_spe) {
				card_type_2ou = type_2ou_spe;
			} else if (i2c_msg.data[0] == type_2ou_exp) {
				card_type_2ou = type_2ou_exp;
			} else if (i2c_msg.data[0] == type_2ou_dpv2_8) { // in case the SKU exist
				card_type_2ou = type_2ou_dpv2_8;
			} else if (i2c_msg.data[0] == type_2ou_dpv2_16) { // in case the SKU exist
				card_type_2ou = type_2ou_dpv2_16;
			}
		}
	}
	SAFE_FREE(data);
}