Merge pull request #439 from roylee123/as5916_54xm_lm75_48to4c

[as5916_54xm]Change one thermal sensor's i2c address to be 0x4C or 0x48.
This commit is contained in:
Jeffrey Townsend
2018-10-09 12:50:01 -07:00
committed by GitHub
2 changed files with 63 additions and 6 deletions

View File

@@ -26,6 +26,7 @@
#include <onlplib/file.h>
#include <onlp/platformi/thermali.h>
#include "platform_lib.h"
#include <limits.h>
#define VALIDATE(_id) \
do { \
@@ -34,11 +35,16 @@
} \
} while(0)
/*Thermal 1 can be at 0x48 for R0A board, or 0x4C otherwise.*/
static int thermal1_addrs[] = {0x4c, 0x48};
static int thermal1_addr = -1;
static char* devfiles__[] = /* must map with onlp_thermal_id */
{
NULL,
NULL, /* CPU_CORE files */
"/sys/bus/i2c/devices/10-0048*temp1_input",
"/sys/bus/i2c/devices/10-00%2x*temp1_input",
"/sys/bus/i2c/devices/10-0049*temp1_input",
"/sys/bus/i2c/devices/10-004a*temp1_input",
"/sys/bus/i2c/devices/10-004b*temp1_input",
@@ -62,7 +68,7 @@ static onlp_thermal_info_t linfo[] = {
ONLP_THERMAL_STATUS_PRESENT,
ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS
},
{ { ONLP_THERMAL_ID_CREATE(THERMAL_1_ON_MAIN_BROAD), "LM75-1-48", 0},
{ { ONLP_THERMAL_ID_CREATE(THERMAL_1_ON_MAIN_BROAD), "LM75-1-%2X", 0},
ONLP_THERMAL_STATUS_PRESENT,
ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS
},
@@ -97,6 +103,30 @@ onlp_thermali_init(void)
return ONLP_STATUS_OK;
}
/*check which addr of thermal1_addrs[] can be read.*/
static int
_get_valid_t1_addr(char *path, int *addr)
{
char fname[PATH_MAX];
int i, rv, tmp;
if (thermal1_addr > 0){
*addr = thermal1_addr;
return ONLP_STATUS_OK;
}
for (i=0; i<AIM_ARRAYSIZE(thermal1_addrs); i++){
snprintf(fname, sizeof(fname), path, thermal1_addrs[i]);
rv = onlp_file_read_int(&tmp, fname);
if (rv == ONLP_STATUS_OK){
thermal1_addr = thermal1_addrs[i];
*addr = thermal1_addr;
return ONLP_STATUS_OK;
}
}
return ONLP_STATUS_E_INVALID;
}
/*
* Retrieve the information structure for the given thermal OID.
*
@@ -111,18 +141,44 @@ int
onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* info)
{
int tid;
char *devfile;
char fname[PATH_MAX];
VALIDATE(id);
tid = ONLP_OID_ID_GET(id);
/* Set the onlp_oid_hdr_t and capabilities */
*info = linfo[tid];
if(tid == THERMAL_CPU_CORE) {
int rv = onlp_file_read_int_max(&info->mcelsius, cpu_coretemp_files);
return rv;
}
return onlp_file_read_int(&info->mcelsius, devfiles__[tid]);
if (tid >= AIM_ARRAYSIZE(devfiles__)){
return ONLP_STATUS_E_PARAM;
}
devfile = devfiles__[tid];
if (tid == THERMAL_1_ON_MAIN_BROAD)
{
onlp_oid_desc_t *des = &info->hdr.description;
char tmp[PATH_MAX];
int t1_addr = thermal1_addrs[0];
int rv;
rv = _get_valid_t1_addr(devfiles__[tid], &t1_addr);
if(rv != ONLP_STATUS_OK)
return rv;
/*Get real path of THERMAL_1 dev file*/
snprintf(fname, sizeof(fname), devfiles__[tid], t1_addr);
devfile = fname;
/*Replace description*/
strncpy(tmp, *des, sizeof(tmp));
snprintf(*des, sizeof(*des), tmp, t1_addr);
}
return onlp_file_read_int(&info->mcelsius, devfile);
}

View File

@@ -27,7 +27,8 @@ class OnlPlatform_x86_64_accton_as5916_54xm_r0(OnlPlatformAccton,
('as5916_54xm_fan', 0x66, 9),
# inititate LM75
('lm75', 0x48, 10),
('lm75', 0x48, 10), #For R0A
('lm75', 0x4c, 10), #For R0B or later
('lm75', 0x49, 10),
('lm75', 0x4a, 10),
('lm75', 0x4b, 10),