Skip to content

Commit

Permalink
minerva-ag: Support soc_pcie_perst commands
Browse files Browse the repository at this point in the history
Summary:
- Support soc_pcie_perst commands

Test Plan:
- Build code: PASS
  • Loading branch information
LisaChang-Quanta committed Feb 3, 2025
1 parent 1de5872 commit 24b9dc4
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 0 deletions.
78 changes: 78 additions & 0 deletions meta-facebook/minerva-ag/src/platform/plat_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ bool vr_status_name_get(uint8_t rail, uint8_t **name)

#define TEMP_THRESHOLD_USER_SETTINGS_OFFSET 0x8100
#define VR_VOUT_USER_SETTINGS_OFFSET 0x8000
#define SOC_PCIE_PERST_USER_SETTINGS_OFFSET 0x8300

vr_vout_user_settings user_settings = { 0 };
struct vr_vout_user_settings default_settings = { 0 };
Expand Down Expand Up @@ -510,6 +511,55 @@ bool vr_vout_user_settings_set(void *user_settings)
return true;
}

bool set_user_settings_soc_pcie_perst_to_eeprom(void *user_settings, uint8_t data_length)
{
CHECK_NULL_ARG_WITH_RETURN(user_settings, false);

I2C_MSG msg = { 0 };
uint8_t retry = 5;
msg.bus = I2C_BUS12;
msg.target_addr = 0xA0 >> 1;
msg.tx_len = data_length + 2;
msg.data[0] = SOC_PCIE_PERST_USER_SETTINGS_OFFSET >> 8;
msg.data[1] = SOC_PCIE_PERST_USER_SETTINGS_OFFSET & 0xff;

memcpy(&msg.data[2], user_settings, data_length);
LOG_DBG("soc_pcie_perst write eeprom, bus: %d, addr: 0x%x, reg: 0x%x 0x%x, tx_len: %d",
msg.bus, msg.target_addr, msg.data[0], msg.data[1], msg.tx_len);

if (i2c_master_write(&msg, retry)) {
LOG_ERR("soc_pcie_perst Failed to write eeprom, bus: %d, addr: 0x%x, reg: 0x%x 0x%x, tx_len: %d",
msg.bus, msg.target_addr, msg.data[0], msg.data[1], msg.tx_len);
return false;
}
k_msleep(EEPROM_MAX_WRITE_TIME);

return true;
}

bool get_user_settings_soc_pcie_perst_from_eeprom(void *user_settings, uint8_t data_length)
{
CHECK_NULL_ARG_WITH_RETURN(user_settings, false);

I2C_MSG msg = { 0 };
uint8_t retry = 5;
msg.bus = I2C_BUS12;
msg.target_addr = 0xA0 >> 1;
msg.tx_len = 2;
msg.data[0] = SOC_PCIE_PERST_USER_SETTINGS_OFFSET >> 8;
msg.data[1] = SOC_PCIE_PERST_USER_SETTINGS_OFFSET & 0xff;
msg.rx_len = data_length;

if (i2c_master_read(&msg, retry)) {
LOG_ERR("Failed to read eeprom, bus: %d, addr: 0x%x, reg: 0x%x%x", msg.bus,
msg.target_addr, msg.data[0], msg.data[1]);
return false;
}
memcpy(user_settings, msg.data, data_length);

return true;
}

int set_user_settings_alert_level_to_eeprom(void *user_settings, uint8_t data_length)
{
CHECK_NULL_ARG_WITH_RETURN(user_settings, -1);
Expand Down Expand Up @@ -577,6 +627,25 @@ static int alert_level_user_settings_init(void)
return 0;
}

static bool soc_pcie_perst_user_settings_init(void)
{
uint8_t setting_data = 0xFF;
if (!get_user_settings_soc_pcie_perst_from_eeprom(&setting_data, sizeof(setting_data))) {
LOG_ERR("get soc_pcie_perst user settings fail");
return false;
}

if (setting_data != 0xFF) {
if (!plat_i2c_write(I2C_BUS5, AEGIS_CPLD_ADDR, 0x43, &setting_data,
sizeof(setting_data))) {
LOG_ERR("Can't set soc_pcie_perst=%d by user settings", setting_data);
return false;
}
}

return true;
}

static bool vr_vout_user_settings_init(void)
{
if (vr_vout_user_settings_get(&user_settings) == false) {
Expand Down Expand Up @@ -747,6 +816,7 @@ void user_settings_init(void)
vr_vout_user_settings_init();
temp_threshold_user_settings_init();
temp_threshold_default_settings_init();
soc_pcie_perst_user_settings_init();
}

void set_uart_power_event_is_enable(bool is_enable)
Expand Down Expand Up @@ -982,6 +1052,14 @@ bool perm_config_clear(void)
return false;
}

/* clear soc_pcie_perst perm parameter */
uint8_t setting_value_for_soc_pcie_perst = 0xFF;
if (!set_user_settings_soc_pcie_perst_to_eeprom(&setting_value_for_soc_pcie_perst,
sizeof(setting_value_for_soc_pcie_perst))) {
LOG_ERR("The perm_config clear failed");
return false;
}

return true;
}

Expand Down
2 changes: 2 additions & 0 deletions meta-facebook/minerva-ag/src/platform/plat_hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ void set_alert_level_to_default_or_user_setting(bool is_default, int32_t user_se
int set_user_settings_alert_level_to_eeprom(void *user_settings, uint8_t data_length);
int get_user_settings_alert_level_from_eeprom(void *user_settings, uint8_t data_length);
int get_alert_level_info(bool *is_assert, int32_t *default_value, int32_t *setting_value);
bool set_user_settings_soc_pcie_perst_to_eeprom(void *user_settings, uint8_t data_length);
bool get_user_settings_soc_pcie_perst_from_eeprom(void *user_settings, uint8_t data_length);
bool vr_rail_voltage_peak_get(uint8_t *name, int *peak_value);
bool vr_rail_voltage_peak_clear(uint8_t rail_index);
bool vr_vout_user_settings_get(void *user_settings);
Expand Down
12 changes: 12 additions & 0 deletions meta-facebook/minerva-ag/src/shell/plat_perm_config_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ static int cmd_perm_config_get(const struct shell *shell, size_t argc, char **ar
}
}

uint8_t setting_data_for_soc_pcie_perst = 0xFF;
if (!get_user_settings_soc_pcie_perst_from_eeprom(
&setting_data_for_soc_pcie_perst, sizeof(setting_data_for_soc_pcie_perst))) {
LOG_ERR("get soc_pcie_perst user settings failed");
} else {
if (setting_data_for_soc_pcie_perst != 0xFF) {
shell_print(shell, "soc_pcie_perst val=%d",
setting_data_for_soc_pcie_perst);
config_count++;
}
}

if (!config_count) {
shell_print(shell, "no perm parameter exist");
}
Expand Down
76 changes: 76 additions & 0 deletions meta-facebook/minerva-ag/src/shell/plat_soc_pcie_perst_shell.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <shell/shell.h>
#include <stdlib.h>
#include <logging/log.h>
#include "plat_isr.h"
#include "plat_i2c.h"
#include "plat_hook.h"

#define AEGIS_CPLD_ADDR (0x4C >> 1)

LOG_MODULE_REGISTER(plat_soc_pcie_perst_shell, LOG_LEVEL_DBG);

static int cmd_soc_pcie_perst_set(const struct shell *shell, size_t argc, char **argv)
{
bool is_perm = false;

if (argc == 3) {
if (!strcmp(argv[2], "perm")) {
is_perm = true;
} else {
shell_error(shell, "The last argument must be <perm>");
return -1;
}
}

uint8_t setting_value = 0;
if (!strcmp(argv[1], "default")) {
shell_info(shell, "Set PERST delay to default, %svolatile\n",
(argc == 3) ? "non-" : "");
} else {
setting_value = strtol(argv[1], NULL, 10);
if (setting_value < 0 || setting_value > 200) {
shell_warn(shell, "Help: N range from 0 to 200");
return -1;
}
uint16_t delay_time = (setting_value * 50) + 100; // 100ms by default
shell_info(shell, "Set PERST delay to %d ms, %svolatile\n", delay_time,
(argc == 3) ? "non-" : "");
}

if (!plat_i2c_write(I2C_BUS5, AEGIS_CPLD_ADDR, 0x43, &setting_value,
sizeof(setting_value))) {
shell_error(shell, "plat soc_pcie_perst set failed");
return -1;
}

//write to eeprom
if (is_perm) {
if (!set_user_settings_soc_pcie_perst_to_eeprom(&setting_value,
sizeof(setting_value))) {
shell_error(shell, "write PERST delay to eeprom error");
return -1;
}
}

return 0;
}

/* Root of command soc_pcie_perst */
SHELL_CMD_ARG_REGISTER(soc_pcie_perst, NULL, "soc_pcie_perst [N (* 50ms)]|default [perm]",
cmd_soc_pcie_perst_set, 2, 1);

0 comments on commit 24b9dc4

Please sign in to comment.