-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
aalc: Add 2nd src Brick driver and init config setting (#2081)
Summary: - new file: common/dev/bmr4922302_803.c - new file: common/dev/include/bmr4922302_803.h - modified: common/service/sensor/sensor.c - modified: common/service/sensor/sensor.h - modified: meta-facebook/aalc-rpu/src/platform/plat_hook.c - modified: meta-facebook/aalc-rpu/src/platform/plat_hook.h - modified: meta-facebook/aalc-rpu/src/platform/plat_sensor_table.c Description: - Add Brick 2md src bmr4922302_803 driver. - Add function to check sensor is main src or 2nd src Pull Request resolved: #2081 Test Plan: - Build code: PASS Reviewed By: wangx6f Differential Revision: D66340511 fbshipit-source-id: 297ad42aa01180533e41203a8fdcedba061b7ee1
- Loading branch information
1 parent
7d61a4b
commit d2f677d
Showing
7 changed files
with
190 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters