Commit e735e77c authored by Benjamin Larsson's avatar Benjamin Larsson
Browse files

Read sfp i2c bus device from hw.board.sfpBus instead of hardcoded config in...

Read sfp i2c bus device from hw.board.sfpBus instead of hardcoded config in binary, enable temperature readings
parent 92e4355f
Pipeline #992 passed with stage
in 55 seconds
......@@ -24,32 +24,21 @@
//static struct blob_buf b;
struct i2c_sfp {
struct i2c_sfp_ctx {
const char *bus;
int rom_addr;
int ddm_addr;
const char *name;
};
const struct i2c_sfp i2c_sfp_list[] = {
{ .bus = "/dev/i2c-0",
.rom_addr = 0x50,
.ddm_addr = 0x51,
.name = "EG200"
},
{ .bus = "/dev/i2c-1",
.rom_addr = 0x50,
.ddm_addr = 0x51,
.name = "EG300"
},
{ .bus = "/dev/i2c-1",
.rom_addr = 0x50,
.ddm_addr = 0x51,
.name = "EG400"
},
struct i2c_sfp_ctx i2c_sfp_conf = {
.bus = "/dev/i2c-0",
.rom_addr = 0x50,
.ddm_addr = 0x51,
.name = "Default"
};
const struct i2c_sfp *i2c_sfp;
struct i2c_sfp_ctx *i2c_sfp;
static int sfp_rom_fd = -1;
static int sfp_ddm_fd = -1;
......@@ -846,7 +835,7 @@ static int ddm_prepare(void)
return 1;
};
#if 0
static int sfp_ddm_get_temperature(struct blob_buf *b, int raw)
{
float x;
......@@ -881,7 +870,7 @@ static int sfp_ddm_get_temperature_method(struct ubus_context *ubus_ctx, struct
blob_buf_free(&b);
return 0;
}
#endif
static int sfp_ddm_get_voltage(struct blob_buf *b, int raw)
{
......@@ -1076,7 +1065,7 @@ static struct ubus_object_type sfp_rom_type =
static const struct ubus_method sfp_ddm_methods[] = {
{ .name = "get-rx-pwr", .handler = sfp_ddm_get_rx_pwr_method },
{ .name = "get-tx-pwr", .handler = sfp_ddm_get_tx_pwr_method },
//{ .name = "get-temperature", .handler = sfp_ddm_get_temperature_method },
{ .name = "get-temperature", .handler = sfp_ddm_get_temperature_method },
{ .name = "get-current", .handler = sfp_ddm_get_current_method },
{ .name = "get-voltage", .handler = sfp_ddm_get_voltage_method },
{ .name = "get-all", .handler = sfp_ddm_get_all_method },
......@@ -1095,29 +1084,17 @@ static struct ubus_object sfp_objects[] = {
struct sfp_handler * sfp_init( struct uci_context *uci_ctx)
{
const char *p;
unsigned int i;
p = ucix_get_option(uci_ctx, "hw", "board", "hardware");
p = ucix_get_option(uci_ctx, "hw", "board", "sfpBus");
if (p == 0){
syslog(LOG_INFO, "%s: Missing Hardware identifier in configuration. I2C is not started",__func__);
syslog(LOG_INFO, "%s: Missing key (sfpBus) in db configuration. I2C is not started",__func__);
return 0;
}
/* Here we match the hardware name to a init table, and get the
i2c chip address */
i2c_sfp = NULL;
for (i = 0; i < sizeof(i2c_sfp_list) / sizeof(i2c_sfp_list[0]); i++) {
DBG(1,"I2C hardware platform %s tested.", i2c_sfp_list[i].name);
if (!strcmp(i2c_sfp_list[i].name, p)) {
DBG(1,"I2C hardware platform %s found.", p);
i2c_sfp = &i2c_sfp_list[i];
break;
}
}
if (!i2c_sfp) {
DBG(1,"No sfp I2C hardware found: %s.", p);
return 0;
}
/* Here we configure the i2c bus that is set in the db file */
i2c_sfp = &i2c_sfp_conf;
i2c_sfp->bus = strdup(p);
DBG(1,"Configured sfp bus device: %s", i2c_sfp->bus);
/* just return something not NULL */
return (struct sfp_handler *)4;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment