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

aalc: Add 2nd src Brick driver and init config setting #2081

Closed
wants to merge 2 commits into from
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
112 changes: 112 additions & 0 deletions common/dev/bmr4922302_803.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* 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 <stdio.h>
#include <string.h>
#include <logging/log.h>
#include "libutil.h"
#include "sensor.h"
#include "hal_i2c.h"
#include "pmbus.h"
#include "util_pmbus.h"

#define BMR4922302_803_READ_VOUT_EXP_VALUE (1.0 / (1 << 11)) //2^(-11) 0x15 2's complement in 5-bit

LOG_MODULE_REGISTER(bmr4922302_803);

uint8_t bmr4922302_803_read(sensor_cfg *cfg, int *reading)
{
CHECK_NULL_ARG_WITH_RETURN(cfg, SENSOR_UNSPECIFIED_ERROR);
CHECK_NULL_ARG_WITH_RETURN(reading, SENSOR_UNSPECIFIED_ERROR);

if (cfg->num > SENSOR_NUM_MAX) {
LOG_ERR("sensor num: 0x%x is invalid", cfg->num);
return SENSOR_UNSPECIFIED_ERROR;
}

uint8_t retry = 5;
sensor_val *sval = (sensor_val *)reading;
I2C_MSG msg;
memset(sval, 0, sizeof(sensor_val));
msg.bus = cfg->port;
msg.target_addr = cfg->target_addr;
msg.tx_len = 1;
msg.rx_len = 2;
uint16_t read_back_data;
float val, vin_val, vout_val, iout_val, temp_val;

switch (cfg->offset) {
case PMBUS_READ_VIN:
msg.data[0] = PMBUS_READ_VIN;
if (i2c_master_read(&msg, retry))
return SENSOR_FAIL_TO_ACCESS;

read_back_data = (msg.data[1] << 8) | msg.data[0];
vin_val = slinear11_to_float(read_back_data);
val = vin_val;

break;
case PMBUS_READ_VOUT:
msg.data[0] = PMBUS_READ_VOUT;
if (i2c_master_read(&msg, retry))
return SENSOR_FAIL_TO_ACCESS;

read_back_data = (msg.data[1] << 8) | msg.data[0];
vout_val = read_back_data * BMR4922302_803_READ_VOUT_EXP_VALUE;
val = vout_val;

break;
case PMBUS_READ_IOUT:
msg.data[0] = PMBUS_READ_IOUT;
if (i2c_master_read(&msg, retry))
return SENSOR_FAIL_TO_ACCESS;

read_back_data = (msg.data[1] << 8) | msg.data[0];
iout_val = slinear11_to_float(read_back_data);
val = iout_val;

break;
case PMBUS_READ_TEMPERATURE_1:
msg.data[0] = PMBUS_READ_TEMPERATURE_1;
if (i2c_master_read(&msg, retry))
return SENSOR_FAIL_TO_ACCESS;

read_back_data = (msg.data[1] << 8) | msg.data[0];
temp_val = slinear11_to_float(read_back_data);
val = temp_val;

break;
default:
return SENSOR_UNSPECIFIED_ERROR;
}

sval->integer = val;
sval->fraction = (val - sval->integer) * 1000;

return SENSOR_READ_SUCCESS;
}

uint8_t bmr4922302_803_init(sensor_cfg *cfg)
{
CHECK_NULL_ARG_WITH_RETURN(cfg, SENSOR_INIT_UNSPECIFIED_ERROR);

if (cfg->num > SENSOR_NUM_MAX) {
return SENSOR_INIT_UNSPECIFIED_ERROR;
}

cfg->read = bmr4922302_803_read;
return SENSOR_INIT_SUCCESS;
}
24 changes: 24 additions & 0 deletions common/dev/include/bmr4922302_803.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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.
*/

#ifndef BMR4922302_803H
#define BMR4922302_803H

typedef struct _bmr4922302_803_init_arg {
bool is_init;
} bmr4922302_803_init_arg;

#endif
10 changes: 9 additions & 1 deletion common/service/sensor/sensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ const char *const sensor_type_name[] = {
sensor_name_to_num(rtq6056)
sensor_name_to_num(mp29816a)
sensor_name_to_num(raa228249)
sensor_name_to_num(bmr4922302_803)
};
// clang-format on

Expand Down Expand Up @@ -357,6 +358,9 @@ SENSOR_DRIVE_INIT_DECLARE(mp29816a);
#ifdef ENABLE_RAA228249
SENSOR_DRIVE_INIT_DECLARE(raa228249);
#endif
#ifndef DISABLE_BMR4922302_803
SENSOR_DRIVE_INIT_DECLARE(bmr4922302_803);
#endif

// The sequence needs to same with SENSOR_DEV ID
sensor_drive_api sensor_drive_tbl[] = {
Expand Down Expand Up @@ -708,7 +712,11 @@ sensor_drive_api sensor_drive_tbl[] = {
#else
SENSOR_DRIVE_TYPE_UNUSE(raa228249),
#endif

#ifdef ENABLE_PLAT_DEF_SENSOR
SENSOR_DRIVE_TYPE_INIT_MAP(bmr4922302_803),
#else
SENSOR_DRIVE_TYPE_UNUSE(bmr4922302_803),
#endif
};

static void init_sensor_num(void)
Expand Down
1 change: 1 addition & 0 deletions common/service/sensor/sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ enum SENSOR_DEV {
sensor_dev_rtq6056 = 0x44,
sensor_dev_mp29816a = 0x45,
sensor_dev_raa228249 = 0x46,
sensor_dev_bmr4922302_803 = 0x47,
sensor_dev_max
};

Expand Down
4 changes: 4 additions & 0 deletions meta-facebook/aalc-rpu/src/platform/plat_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,10 @@ e50sn12051_init_arg e50sn12051_init_args[] = {
[0] = { .is_init = false,},
};

bmr4922302_803_init_arg bmr4922302_803_init_args[] = {
[0] = { .is_init = false,},
};

/**************************************************************************************************
* PRE-HOOK/POST-HOOK ARGS
**************************************************************************************************/
Expand Down
3 changes: 2 additions & 1 deletion meta-facebook/aalc-rpu/src/platform/plat_hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "ast_tach.h"
#include "xdp710.h"
#include "e50sn12051.h"
#include "bmr4922302_803.h"

#define BUS_1_MUX_ADDR 0xE0 >> 1
#define BUS_2_MUX_ADDR 0xE2 >> 1
Expand Down Expand Up @@ -64,7 +65,7 @@ extern xdp710_init_arg xdp710_init_args[];
extern hdc1080_init_arg hdc1080_init_args[];
extern ast_tach_init_arg ast_tach_init_args[];
extern e50sn12051_init_arg e50sn12051_init_args[];

extern bmr4922302_803_init_arg bmr4922302_803_init_args[];
/**************************************************************************************************
* POST ARGS
**************************************************************************************************/
Expand Down
38 changes: 38 additions & 0 deletions meta-facebook/aalc-rpu/src/platform/plat_sensor_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -1213,10 +1213,48 @@ static void change_mb_temp_sensor_config()
}
}

static void change_brick_sensor_config()
{
#define E50SN12051_MFR_ID 0x0644
#define BMR4922302_803_MFR_ID 0x0c46

uint8_t retry = 5;
I2C_MSG msg;
msg.bus = I2C_BUS4;
msg.target_addr = BPB_BRICK_12V_ADDR;
msg.tx_len = 1;
msg.rx_len = 4;
uint16_t mfr_id;
msg.data[0] = PMBUS_MFR_ID;

if (i2c_master_read(&msg, retry)) {
LOG_ERR("Failed to read Brick module MFR_ID");
return;
}

mfr_id = (msg.data[0] << 8) | msg.data[1];
printf("Brick module mfr_id: %x\n", mfr_id);

if (mfr_id == E50SN12051_MFR_ID)
return;

for (uint8_t i = 0; i < ARRAY_SIZE(plat_sensor_config); i++) {
sensor_cfg *p = plat_sensor_config + i;
if (p->num == SENSOR_NUM_BPB_BRICK_12V_VIN_VOLT_V ||
p->num == SENSOR_NUM_BPB_BRICK_12V_VOUT_VOLT_V ||
p->num == SENSOR_NUM_BPB_BRICK_12V_IOUT_CURR_A ||
p->num == SENSOR_NUM_BPB_BRICK_12V_TEMP_C) {
p->type = sensor_dev_bmr4922302_803;
p->init_args = &bmr4922302_803_init_args[0];
}
}
}

void load_sensor_config(void)
{
change_mb_temp_sensor_config();
change_dvt_sensor_config();
change_brick_sensor_config();
memcpy(sensor_config, plat_sensor_config, sizeof(plat_sensor_config));
sensor_config_count = ARRAY_SIZE(plat_sensor_config);

Expand Down
Loading