Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fby4: sd: Support PLDM host power control #1344

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion meta-facebook/yv4-sd/src/platform/plat_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void pal_pre_init()
void pal_post_init()
{
plat_mctp_init();
pldm_load_state_effecter_table(MAX_STATE_EFFECTER_IDX);
pldm_load_state_effecter_table(PLAT_PLDM_MAX_STATE_EFFECTER_IDX);
pldm_assign_gpio_effecter_id(PLAT_EFFECTER_ID_GPIO_HIGH_BYTE);
}

Expand Down
110 changes: 110 additions & 0 deletions meta-facebook/yv4-sd/src/platform/plat_pldm_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,33 @@
#include "pldm.h"

#include "plat_gpio.h"
#include "plat_i2c.h"
#include "plat_sensor_table.h"
#include "plat_pldm_monitor.h"

LOG_MODULE_REGISTER(plat_pldm_monitor);

#define PLAT_PLDM_POWER_ON_BUTTON_MSEC 1000
#define PLAT_PLDM_RESET_BUTTON_MSEC 1000
#define PLAT_PLDM_GRACEFUL_SHUTDOWN_BUTTON_MSEC 1000
#define PLAT_PLDM_POWER_OFF_BUTTON_MSEC 6000
#define PLAT_PLDM_POWER_CYCLE_INTERVAL_MSEC 5000

#define PLAT_PLDM_SEQUENCE_CNT 3

static uint8_t power_sequence[PLAT_PLDM_SEQUENCE_CNT] = {PLAT_PLDM_HOST_PWR_CTRL_DEFAULT, PLAT_PLDM_HOST_PWR_BTN_LOW,
PLAT_PLDM_HOST_PWR_CTRL_DEFAULT};
static uint8_t reset_sequence[PLAT_PLDM_SEQUENCE_CNT] = {PLAT_PLDM_HOST_PWR_CTRL_DEFAULT, PLAT_PLDM_HOST_RST_BTN_LOW,
PLAT_PLDM_HOST_PWR_CTRL_DEFAULT};

struct pldm_state_effecter_info plat_state_effecter_table[] = {
[0 ... PLDM_PLATFORM_OEM_AST1030_GPIO_PIN_NUM_MAX] = {
.entity_type = PLDM_ENTITY_IO_CONTROLLER,
},
[PLDM_PLATFORM_OEM_AST1030_GPIO_PIN_NUM_MAX + 1] = {
.entity_type = PLDM_ENTITY_SUB_CHASSIS,
.effecter_id = 0x0000,
},
};

void plat_pldm_load_state_effecter_table(void)
Expand All @@ -56,6 +74,9 @@ uint8_t plat_pldm_set_state_effecter_state_handler(const uint8_t *buf, uint16_t
set_effecter_state_gpio_handler(buf, len, resp, resp_len,
(uint8_t)(info_p->effecter_id & GENMASK(7, 0)));
break;
case PLDM_ENTITY_SUB_CHASSIS:
plat_pldm_set_effecter_state_host_power_control(buf, len, resp, resp_len);
break;
default:
LOG_ERR("Unsupport entity type, (%d)", info_p->entity_type);
*completion_code_p = PLDM_ERROR_INVALID_DATA;
Expand Down Expand Up @@ -90,3 +111,92 @@ uint8_t plat_pldm_get_state_effecter_state_handler(const uint8_t *buf, uint16_t

return PLDM_SUCCESS;
}

uint8_t plat_pldm_host_button_sequence(const uint8_t *power_sequence, uint16_t pressing_interval)
{
uint8_t retry = 3;
I2C_MSG i2c_msg;
i2c_msg.bus = I2C_BUS5;
i2c_msg.target_addr = 0x21; //server board cpld addr
i2c_msg.tx_len = 2;
i2c_msg.rx_len = 0;
i2c_msg.data[0] = 0x00;

for (int i = 0; i < PLAT_PLDM_SEQUENCE_CNT; i++) {
i2c_msg.data[1] = power_sequence[i];
if (i2c_master_write(&i2c_msg, retry)) {
return -1;
}

if (i == 1) {
k_msleep(pressing_interval);
}
}
return 0;
}

void plat_pldm_set_effecter_state_host_power_control(const uint8_t *buf, uint16_t len,
uint8_t *resp, uint16_t *resp_len)
{
CHECK_NULL_ARG(buf);
CHECK_NULL_ARG(resp);
CHECK_NULL_ARG(resp_len);

struct pldm_set_state_effecter_states_req *req_p =
(struct pldm_set_state_effecter_states_req *)buf;
uint8_t *completion_code_p = resp;
*resp_len = 1;

if (req_p->composite_effecter_count != PLDM_PLATFORM_OEM_HOST_POWER_CTRL_EFFECTER_STATE_FIELD_COUNT) {
LOG_ERR("Unsupported host power control effecter count, (%d)", req_p->composite_effecter_count);
*completion_code_p = PLDM_ERROR_INVALID_DATA;
return;
}

set_effecter_state_field_t *host_power_state = &req_p->field[0];

if (host_power_state->set_request >= PLDM_SET_REQUEST_MAX) {
LOG_ERR("Invalid host power control set request (%d)",
host_power_state->set_request);
*completion_code_p = PLDM_PLATFORM_UNSUPPORTED_EFFECTERSTATE;
return;
}

switch (host_power_state->effecter_state) {
case EFFECTER_STATE_POWER_STATUS_ON:
if (plat_pldm_host_button_sequence(power_sequence, PLAT_PLDM_POWER_ON_BUTTON_MSEC) != 0) {
LOG_ERR("Failed to do host power on");
}
break;
case EFFECTER_STATE_POWER_STATUS_OFF:
if (plat_pldm_host_button_sequence(power_sequence, PLAT_PLDM_POWER_OFF_BUTTON_MSEC) != 0) {
LOG_ERR("Failed to do host power off");
}
break;
case EFFECTER_STATE_POWER_STATUS_CYCLE:
if (plat_pldm_host_button_sequence(power_sequence, PLAT_PLDM_POWER_OFF_BUTTON_MSEC) != 0) {
LOG_ERR("Failed to do host power cycle");
}
k_msleep(PLAT_PLDM_POWER_CYCLE_INTERVAL_MSEC);
if (plat_pldm_host_button_sequence(power_sequence, PLAT_PLDM_POWER_ON_BUTTON_MSEC) != 0) {
LOG_ERR("Failed to do host power cycle");
}
break;
case EFFECTER_STATE_POWER_STATUS_RESET:
if (plat_pldm_host_button_sequence(reset_sequence, PLAT_PLDM_RESET_BUTTON_MSEC) != 0) {
LOG_ERR("Failed to do host power reset");
}
break;
case EFFECTER_STATE_POWER_STATUS_GRACEFUL_SHUTDOWN:
if (plat_pldm_host_button_sequence(power_sequence, PLAT_PLDM_GRACEFUL_SHUTDOWN_BUTTON_MSEC) != 0) {
LOG_ERR("Failed to do host graceful shutdown");
}
break;
default:
LOG_ERR("Unsupported host power control effecter state, (%d)",
host_power_state->effecter_state);
*completion_code_p = PLDM_ERROR_INVALID_DATA;
}

return;
}
6 changes: 5 additions & 1 deletion meta-facebook/yv4-sd/src/platform/plat_pldm_monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
#ifndef PLAT_PLDM_MONITOR_H
#define PLAT_PLDM_MONITOR_H

#define MAX_STATE_EFFECTER_IDX 168
#define PLAT_PLDM_MAX_STATE_EFFECTER_IDX 169

#define PLAT_PLDM_HOST_PWR_CTRL_DEFAULT 0xFF
#define PLAT_PLDM_HOST_PWR_BTN_LOW 0xFE
#define PLAT_PLDM_HOST_RST_BTN_LOW 0xFD

enum pldm_plat_effecter_id_high_byte {
PLAT_EFFECTER_ID_GPIO_HIGH_BYTE = (0xFF << 8),
Expand Down
Loading