Commit ce097c90 authored by Evan Lojewski's avatar Evan Lojewski Committed by Raptor Engineering Development Team

i2c: Refactor cpu0/cpu1 power sequencing routines to share common code.

- Add common routines for cpu0/cpu1
- Wrap CPU1 code in #ifdef I3CMASTER2_BASE in teh event that the FPGA was not build with the additioanl i2c master.
parent fa478062
...@@ -1362,182 +1362,160 @@ static void run_post_shutdown_bmc_peripheral_teardown(void) ...@@ -1362,182 +1362,160 @@ static void run_post_shutdown_bmc_peripheral_teardown(void)
set_led_bank_display(0x00); set_led_bank_display(0x00);
} }
static int apply_avsbus_workarounds(int cpu_count) static int apply_avsbus_workarounds_cpu(int cpu, uint8_t *i2c_master)
{ {
printf("Applying AVSBus workarounds...\n"); 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))
{
return -1;
}
printf("\tVDD/VCS 0: Enabling AVSBus CLK/MDAT pullups and selecting VIH/VIL " printf("\tVDN %d: Enabling AVSBus CLK/MDAT pullups and selecting VIH/VIL "
"0x2 (0.65V/0.55V)\n"); "0x2 (0.65V/0.55V)\n",
if (i2c_write_register_byte((uint8_t *)I2CMASTER1_BASE, 0x28, 0x2e, 0x23)) cpu);
if (i2c_write_register_byte(i2c_master, 0x2b, 0x2e, 0x23))
{ {
return -1; return -1;
} }
printf("\tVDN 0: Enabling AVSBus CLK/MDAT pullups and selecting VIH/VIL 0x2 " return 0;
"(0.65V/0.55V)\n"); }
if (i2c_write_register_byte((uint8_t *)I2CMASTER1_BASE, 0x2b, 0x2e, 0x23))
static int apply_avsbus_workarounds(int cpu_count)
{
printf("Applying AVSBus workarounds...\n");
if (apply_avsbus_workarounds_cpu(0, (uint8_t *)I2CMASTER1_BASE))
{ {
return -1; return -1;
} }
#ifdef I2CMASTER2_BASE
if (cpu_count > 1) if (cpu_count > 1)
{ {
printf("\tVDD/VCS 1: Enabling AVSBus CLK/MDAT pullups and selecting " if (apply_avsbus_workarounds_cpu(1, (uint8_t *)I2CMASTER2_BASE))
"VIH/VIL 0x2 (0.65V/0.55V)\n");
if (i2c_write_register_byte((uint8_t *)I2CMASTER2_BASE, 0x28, 0x2e, 0x23))
{
return -1;
}
printf("\tVDN 1: Enabling AVSBus CLK/MDAT pullups and selecting VIH/VIL "
"0x2 (0.65V/0.55V)\n");
if (i2c_write_register_byte((uint8_t *)I2CMASTER2_BASE, 0x2b, 0x2e, 0x23))
{ {
return -1; return -1;
} }
} }
#endif
printf("\tAVSBus workaround application complete!\n"); printf("\tAVSBus workaround application complete!\n");
return 0; return 0;
} }
static int enable_avsbus_pmbus(int cpu_count) static int enable_avsbus_pmbus_cpu(int cpu, uint8_t *i2c_master)
{ {
printf("Enabling AVSbus PMBUS functionality...\n"); printf("\tVDD %d: Placing device in AVSBus voltage command mode\n", cpu);
if (i2c_write_register_byte(i2c_master, 0x70, 0x00, 0x00))
printf("\tVDD 0: Placing device in AVSBus voltage command mode\n");
if (i2c_write_register_byte((uint8_t *)I2CMASTER1_BASE, 0x70, 0x00, 0x00))
{ {
return -1; return -1;
} }
if (i2c_write_register_byte((uint8_t *)I2CMASTER1_BASE, 0x70, 0x01, 0xb0)) if (i2c_write_register_byte(i2c_master, 0x70, 0x01, 0xb0))
{ {
return -1; return -1;
} }
printf("\tVCS 0: Placing device in AVSBus voltage command mode\n"); printf("\tVCS %d: Placing device in AVSBus voltage command mode\n", cpu);
if (i2c_write_register_byte((uint8_t *)I2CMASTER1_BASE, 0x70, 0x00, 0x01)) if (i2c_write_register_byte(i2c_master, 0x70, 0x00, 0x01))
{ {
return -1; return -1;
} }
if (i2c_write_register_byte((uint8_t *)I2CMASTER1_BASE, 0x70, 0x01, 0xb0)) if (i2c_write_register_byte(i2c_master, 0x70, 0x01, 0xb0))
{ {
return -1; return -1;
} }
printf("\tVDN 0: Placing device in AVSBus voltage command mode\n"); printf("\tVDN %d: Placing device in AVSBus voltage command mode\n", cpu);
if (i2c_write_register_byte((uint8_t *)I2CMASTER1_BASE, 0x73, 0x00, 0x00)) if (i2c_write_register_byte(i2c_master, 0x73, 0x00, 0x00))
{ {
return -1; return -1;
} }
if (i2c_write_register_byte((uint8_t *)I2CMASTER1_BASE, 0x73, 0x01, 0xb0)) if (i2c_write_register_byte(i2c_master, 0x73, 0x01, 0xb0))
{ {
return -1; return -1;
} }
if (cpu_count > 1) return 0;
{ }
printf("\tVDD 1: Placing device in AVSBus voltage command mode\n");
if (i2c_write_register_byte((uint8_t *)I2CMASTER2_BASE, 0x70, 0x00, 0x00))
{
return -1;
}
if (i2c_write_register_byte((uint8_t *)I2CMASTER2_BASE, 0x70, 0x01, 0xb0))
{
return -1;
}
printf("\tVCS 1: Placing device in AVSBus voltage command mode\n"); static int enable_avsbus_pmbus(int cpu_count)
if (i2c_write_register_byte((uint8_t *)I2CMASTER2_BASE, 0x70, 0x00, 0x01)) {
{ printf("Enabling AVSbus PMBUS functionality...\n");
return -1;
}
if (i2c_write_register_byte((uint8_t *)I2CMASTER2_BASE, 0x70, 0x01, 0xb0))
{
return -1;
}
printf("\tVDN 1: Placing device in AVSBus voltage command mode\n"); if (enable_avsbus_pmbus_cpu(0, (uint8_t *)I2CMASTER1_BASE))
if (i2c_write_register_byte((uint8_t *)I2CMASTER2_BASE, 0x73, 0x00, 0x00)) {
{ return -1;
return -1; }
}
if (i2c_write_register_byte((uint8_t *)I2CMASTER2_BASE, 0x73, 0x01, 0xb0)) #ifdef I2CMASTER2_BASE
if (cpu_count > 1)
{
if (enable_avsbus_pmbus_cpu(1, (uint8_t *)I2CMASTER2_BASE))
{ {
return -1; return -1;
} }
} }
#endif
printf("\tAVSBus PMBUS functionality enabled!\n"); printf("\tAVSBus PMBUS functionality enabled!\n");
return 0; return 0;
} }
static int disable_avsbus_pmbus(int cpu_count) static int disable_avsbus_pmbus_cpu(int cpu, uint8_t *i2c_master)
{ {
printf("Disabling AVSbus PMBUS functionality...\n"); printf("\tVDD %d: Placing device in immediate off mode\n", cpu);
if (i2c_write_register_byte(i2c_master, 0x70, 0x00, 0x00))
printf("\tVDD 0: Placing device in immediate off mode\n");
if (i2c_write_register_byte((uint8_t *)I2CMASTER1_BASE, 0x70, 0x00, 0x00))
{ {
return -1; return -1;
} }
if (i2c_write_register_byte((uint8_t *)I2CMASTER1_BASE, 0x70, 0x01, 0xb0)) if (i2c_write_register_byte(i2c_master, 0x70, 0x01, 0xb0))
{ {
return -1; return -1;
} }
printf("\tVCS 0: Placing device in immediate off mode\n"); printf("\tVCS %d: Placing device in immediate off mode\n", cpu);
if (i2c_write_register_byte((uint8_t *)I2CMASTER1_BASE, 0x70, 0x00, 0x01)) if (i2c_write_register_byte(i2c_master, 0x70, 0x00, 0x01))
{ {
return -1; return -1;
} }
if (i2c_write_register_byte((uint8_t *)I2CMASTER1_BASE, 0x70, 0x01, 0xb0)) if (i2c_write_register_byte(i2c_master, 0x70, 0x01, 0xb0))
{ {
return -1; return -1;
} }
printf("\tVDN 0: Placing device in immediate off mode\n"); printf("\tVDN %d: Placing device in immediate off mode\n", cpu);
if (i2c_write_register_byte((uint8_t *)I2CMASTER1_BASE, 0x73, 0x00, 0x00)) if (i2c_write_register_byte(i2c_master, 0x73, 0x00, 0x00))
{ {
return -1; return -1;
} }
if (i2c_write_register_byte((uint8_t *)I2CMASTER1_BASE, 0x73, 0x01, 0xb0)) if (i2c_write_register_byte(i2c_master, 0x73, 0x01, 0xb0))
{ {
return -1; return -1;
} }
if (cpu_count > 1) return 0;
{ }
printf("\tVDD 1: Placing device in immediate off mode\n"); static int disable_avsbus_pmbus(int cpu_count)
if (i2c_write_register_byte((uint8_t *)I2CMASTER2_BASE, 0x70, 0x00, 0x00)) {
{ printf("Disabling AVSbus PMBUS functionality...\n");
return -1;
}
if (i2c_write_register_byte((uint8_t *)I2CMASTER2_BASE, 0x70, 0x01, 0xb0))
{
return -1;
}
printf("\tVCS 1: Placing device in immediate off mode\n"); if (disable_avsbus_pmbus_cpu(0, (uint8_t *)I2CMASTER1_BASE))
if (i2c_write_register_byte((uint8_t *)I2CMASTER2_BASE, 0x70, 0x00, 0x01)) {
{ return -1;
return -1; }
}
if (i2c_write_register_byte((uint8_t *)I2CMASTER2_BASE, 0x70, 0x01, 0xb0))
{
return -1;
}
printf("\tVDN 1: Placing device in immediate off mode\n"); #ifdef I2CMASTER2_BASE
if (i2c_write_register_byte((uint8_t *)I2CMASTER2_BASE, 0x73, 0x00, 0x00)) if (cpu_count > 1)
{ {
return -1; if (disable_avsbus_pmbus_cpu(1, (uint8_t *)I2CMASTER2_BASE))
}
if (i2c_write_register_byte((uint8_t *)I2CMASTER2_BASE, 0x73, 0x01, 0xb0))
{ {
return -1; return -1;
} }
} }
#endif
printf("\tAVSBus PMBUS functionality disabled!\n"); printf("\tAVSBus PMBUS functionality disabled!\n");
return 0; return 0;
...@@ -2430,7 +2408,9 @@ int main(void) ...@@ -2430,7 +2408,9 @@ int main(void)
display_character(0x30, 0); // STATUS CODE: 0 display_character(0x30, 0); // STATUS CODE: 0
initialize_i2c_master((uint8_t *)I2CMASTER1_BASE, 100000); initialize_i2c_master((uint8_t *)I2CMASTER1_BASE, 100000);
#ifdef I2CMASTER2_BASE
initialize_i2c_master((uint8_t *)I2CMASTER2_BASE, 100000); initialize_i2c_master((uint8_t *)I2CMASTER2_BASE, 100000);
#endif
// initialize_i2c_master((uint8_t*)I2CMASTER3_BASE, 100000); // initialize_i2c_master((uint8_t*)I2CMASTER3_BASE, 100000);
initialize_i2c_master((uint8_t *)I2CMASTER4_BASE, 100000); initialize_i2c_master((uint8_t *)I2CMASTER4_BASE, 100000);
......
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