Commit 1d87af65 authored by Evan Lojewski's avatar Evan Lojewski Committed by Raptor Engineering Development Team
Browse files

i2c: Add a cpu-specific datastructure for use with i2c transactions

parent ce097c90
......@@ -99,6 +99,18 @@ uint8_t post_code_low = 0;
static uint8_t allow_flash_write = 0;
static uint8_t enable_post_code_console_output = 0;
typedef struct
{
int8_t index;
uint8_t *i2c_master;
} cpu_info_t;
static const cpu_info_t g_cpu_info[] = {
{ .index = 0, .i2c_master = (uint8_t *)I2CMASTER1_BASE },
#ifdef I2CMASTER2_BASE
{ .index = 1, .i2c_master = (uint8_t *)I2CMASTER2_BASE },
#endif
};
void primary_service_event_loop(void);
static char *readstr(void)
......@@ -1362,20 +1374,20 @@ static void run_post_shutdown_bmc_peripheral_teardown(void)
set_led_bank_display(0x00);
}
static int apply_avsbus_workarounds_cpu(int cpu, uint8_t *i2c_master)
static int apply_avsbus_workarounds_cpu(const cpu_info_t *cpu)
{
printf("\tVDD/VCS %d: Enabling AVSBus CLK/MDAT pullups and selecting "
"VIH/VIL 0x2 (0.65V/0.55V)\n",
cpu);
if (i2c_write_register_byte(i2c_master, 0x28, 0x2e, 0x23))
cpu->index);
if (i2c_write_register_byte(cpu->i2c_master, 0x28, 0x2e, 0x23))
{
return -1;
}
printf("\tVDN %d: Enabling AVSBus CLK/MDAT pullups and selecting VIH/VIL "
"0x2 (0.65V/0.55V)\n",
cpu);
if (i2c_write_register_byte(i2c_master, 0x2b, 0x2e, 0x23))
cpu->index);
if (i2c_write_register_byte(cpu->i2c_master, 0x2b, 0x2e, 0x23))
{
return -1;
}
......@@ -1383,57 +1395,51 @@ static int apply_avsbus_workarounds_cpu(int cpu, uint8_t *i2c_master)
return 0;
}
static int apply_avsbus_workarounds(int cpu_count)
static int apply_avsbus_workarounds(const cpu_info_t *cpu_info, int cpu_count)
{
printf("Applying AVSBus workarounds...\n");
if (apply_avsbus_workarounds_cpu(0, (uint8_t *)I2CMASTER1_BASE))
while (--cpu_count)
{
return -1;
}
#ifdef I2CMASTER2_BASE
if (cpu_count > 1)
{
if (apply_avsbus_workarounds_cpu(1, (uint8_t *)I2CMASTER2_BASE))
if (apply_avsbus_workarounds_cpu(&cpu_info[0]))
{
return -1;
}
cpu_info++;
}
#endif
printf("\tAVSBus workaround application complete!\n");
return 0;
}
static int enable_avsbus_pmbus_cpu(int cpu, uint8_t *i2c_master)
static int enable_avsbus_pmbus_cpu(const cpu_info_t *cpu)
{
printf("\tVDD %d: Placing device in AVSBus voltage command mode\n", cpu);
if (i2c_write_register_byte(i2c_master, 0x70, 0x00, 0x00))
printf("\tVDD %d: Placing device in AVSBus voltage command mode\n", cpu->index);
if (i2c_write_register_byte(cpu->i2c_master, 0x70, 0x00, 0x00))
{
return -1;
}
if (i2c_write_register_byte(i2c_master, 0x70, 0x01, 0xb0))
if (i2c_write_register_byte(cpu->i2c_master, 0x70, 0x01, 0xb0))
{
return -1;
}
printf("\tVCS %d: Placing device in AVSBus voltage command mode\n", cpu);
if (i2c_write_register_byte(i2c_master, 0x70, 0x00, 0x01))
printf("\tVCS %d: Placing device in AVSBus voltage command mode\n", cpu->index);
if (i2c_write_register_byte(cpu->i2c_master, 0x70, 0x00, 0x01))
{
return -1;
}
if (i2c_write_register_byte(i2c_master, 0x70, 0x01, 0xb0))
if (i2c_write_register_byte(cpu->i2c_master, 0x70, 0x01, 0xb0))
{
return -1;
}
printf("\tVDN %d: Placing device in AVSBus voltage command mode\n", cpu);
if (i2c_write_register_byte(i2c_master, 0x73, 0x00, 0x00))
printf("\tVDN %d: Placing device in AVSBus voltage command mode\n", cpu->index);
if (i2c_write_register_byte(cpu->i2c_master, 0x73, 0x00, 0x00))
{
return -1;
}
if (i2c_write_register_byte(i2c_master, 0x73, 0x01, 0xb0))
if (i2c_write_register_byte(cpu->i2c_master, 0x73, 0x01, 0xb0))
{
return -1;
}
......@@ -1441,81 +1447,69 @@ static int enable_avsbus_pmbus_cpu(int cpu, uint8_t *i2c_master)
return 0;
}
static int enable_avsbus_pmbus(int cpu_count)
static int enable_avsbus_pmbus(const cpu_info_t *cpu_info, int cpu_count)
{
printf("Enabling AVSbus PMBUS functionality...\n");
if (enable_avsbus_pmbus_cpu(0, (uint8_t *)I2CMASTER1_BASE))
{
return -1;
}
#ifdef I2CMASTER2_BASE
if (cpu_count > 1)
while (--cpu_count)
{
if (enable_avsbus_pmbus_cpu(1, (uint8_t *)I2CMASTER2_BASE))
if (enable_avsbus_pmbus_cpu(&cpu_info[0]))
{
return -1;
}
cpu_info++;
}
#endif
printf("\tAVSBus PMBUS functionality enabled!\n");
return 0;
}
static int disable_avsbus_pmbus_cpu(int cpu, uint8_t *i2c_master)
static int disable_avsbus_pmbus_cpu(const cpu_info_t *cpu)
{
printf("\tVDD %d: Placing device in immediate off mode\n", cpu);
if (i2c_write_register_byte(i2c_master, 0x70, 0x00, 0x00))
printf("\tVDD %d: Placing device in immediate off mode\n", cpu->index);
if (i2c_write_register_byte(cpu->i2c_master, 0x70, 0x00, 0x00))
{
return -1;
}
if (i2c_write_register_byte(i2c_master, 0x70, 0x01, 0xb0))
if (i2c_write_register_byte(cpu->i2c_master, 0x70, 0x01, 0xb0))
{
return -1;
}
printf("\tVCS %d: Placing device in immediate off mode\n", cpu);
if (i2c_write_register_byte(i2c_master, 0x70, 0x00, 0x01))
printf("\tVCS %d: Placing device in immediate off mode\n", cpu->index);
if (i2c_write_register_byte(cpu->i2c_master, 0x70, 0x00, 0x01))
{
return -1;
}
if (i2c_write_register_byte(i2c_master, 0x70, 0x01, 0xb0))
if (i2c_write_register_byte(cpu->i2c_master, 0x70, 0x01, 0xb0))
{
return -1;
}
printf("\tVDN %d: Placing device in immediate off mode\n", cpu);
if (i2c_write_register_byte(i2c_master, 0x73, 0x00, 0x00))
printf("\tVDN %d: Placing device in immediate off mode\n", cpu->index);
if (i2c_write_register_byte(cpu->i2c_master, 0x73, 0x00, 0x00))
{
return -1;
}
if (i2c_write_register_byte(i2c_master, 0x73, 0x01, 0xb0))
if (i2c_write_register_byte(cpu->i2c_master, 0x73, 0x01, 0xb0))
{
return -1;
}
return 0;
}
static int disable_avsbus_pmbus(int cpu_count)
static int disable_avsbus_pmbus(const cpu_info_t *cpu_info, int cpu_count)
{
printf("Disabling AVSbus PMBUS functionality...\n");
if (disable_avsbus_pmbus_cpu(0, (uint8_t *)I2CMASTER1_BASE))
while (--cpu_count)
{
return -1;
}
#ifdef I2CMASTER2_BASE
if (cpu_count > 1)
{
if (disable_avsbus_pmbus_cpu(1, (uint8_t *)I2CMASTER2_BASE))
if (disable_avsbus_pmbus_cpu(&cpu_info[0]))
{
return -1;
}
cpu_info++;
}
#endif
printf("\tAVSBus PMBUS functionality disabled!\n");
return 0;
......@@ -1524,7 +1518,7 @@ static int disable_avsbus_pmbus(int cpu_count)
static void power_off_chassis(void)
{
// Disable PMBUS
if (disable_avsbus_pmbus(configured_cpu_count))
if (disable_avsbus_pmbus(g_cpu_info, configured_cpu_count))
{
printf("PMBUS disable failed!\n");
}
......@@ -1593,7 +1587,7 @@ static int power_on_chassis(void)
printf("%d CPU(s) installed\n", cpu_count);
// Apply AVSBus workarounds
if (apply_avsbus_workarounds(cpu_count))
if (apply_avsbus_workarounds(g_cpu_info, cpu_count))
{
printf("AVSBus setup failed!\n");
power_off_chassis();
......@@ -1601,7 +1595,7 @@ static int power_on_chassis(void)
}
// Enable PMBUS
if (enable_avsbus_pmbus(cpu_count))
if (enable_avsbus_pmbus(g_cpu_info, cpu_count))
{
printf("PMBUS enable failed!\n");
power_off_chassis();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment