[as4610] Add support for OOM optoe driver

This commit is contained in:
Brandon Chuang
2018-06-21 15:26:11 +08:00
parent 16f97c4cae
commit c1b7904d34
6 changed files with 2041 additions and 2035 deletions

View File

@@ -868,7 +868,7 @@ CONFIG_EEPROM_AT25=y
# CONFIG_EEPROM_93CX6 is not set
# CONFIG_EEPROM_93XX46 is not set
# CONFIG_EEPROM_SFF_8436 is not set
CONFIG_EEPROM_ACCTON_AS4610_SFP=y
CONFIG_EEPROM_OPTOE=y
# CONFIG_CB710_CORE is not set
# CONFIG_IWMC3200TOP is not set
@@ -1497,7 +1497,7 @@ CONFIG_SENSORS_W83781D=y
# CONFIG_SENSORS_W83L786NG is not set
# CONFIG_SENSORS_W83627HF is not set
# CONFIG_SENSORS_W83627EHF is not set
CONFIG_SENSORS_ACCTON_I2C_CPLD=y
CONFIG_SENSORS_ACCTON_AS4610_CPLD=y
CONFIG_SENSORS_ACCTON_AS4610_FAN=y
CONFIG_SENSORS_ACCTON_AS4610_PSU=y
CONFIG_SENSORS_YM2651Y=y

View File

@@ -1,6 +1,6 @@
--- /dev/null
+++ b/arch/arm/boot/dts/accton_as4610_54.dts
@@ -0,0 +1,250 @@
@@ -0,0 +1,256 @@
+/*
+ * Accton AS4610 54 Device Tree Source
+ *
@@ -117,7 +117,7 @@
+ cpld@1,0 {
+ #address-cells = <1>;
+ #size-cells = <1>;
+ compatible = "accton,as4610-54-cpld";
+ compatible = "accton,as4610_54_cpld";
+ label = "cpld";
+ reg = <0x30>;
+ };
@@ -142,8 +142,8 @@
+ #address-cells = <1>;
+ #size-cells = <0>;
+ reg = <0>;
+ sfp_eeprom@50 {
+ compatible = "at,24c04";
+ optoe@50 {
+ compatible = "optoe2";
+ reg = <0x50>;
+ label = "port49";
+ };
@@ -154,8 +154,8 @@
+ #address-cells = <1>;
+ #size-cells = <0>;
+ reg = <1>;
+ sfp_eeprom@50 {
+ compatible = "at,24c04";
+ optoe@50 {
+ compatible = "optoe2";
+ reg = <0x50>;
+ label = "port50";
+ };
@@ -166,8 +166,8 @@
+ #address-cells = <1>;
+ #size-cells = <0>;
+ reg = <2>;
+ sfp_eeprom@50 {
+ compatible = "at,24c04";
+ optoe@50 {
+ compatible = "optoe2";
+ reg = <0x50>;
+ label = "port51";
+ };
@@ -178,8 +178,8 @@
+ #address-cells = <1>;
+ #size-cells = <0>;
+ reg = <3>;
+ sfp_eeprom@50 {
+ compatible = "at,24c04";
+ optoe@50 {
+ compatible = "optoe2";
+ reg = <0x50>;
+ label = "port52";
+ };
@@ -190,9 +190,10 @@
+ #address-cells = <1>;
+ #size-cells = <0>;
+ reg = <4>;
+ sfp_eeprom@50 {
+ compatible = "at,24c04";
+ optoe@50 {
+ compatible = "optoe1";
+ reg = <0x50>;
+ label = "port53";
+ };
+ };
+
@@ -201,9 +202,10 @@
+ #address-cells = <1>;
+ #size-cells = <0>;
+ reg = <5>;
+ sfp_eeprom@50 {
+ compatible = "at,24c04";
+ optoe@50 {
+ compatible = "optoe1";
+ reg = <0x50>;
+ label = "port54";
+ };
+ };
+
@@ -212,17 +214,21 @@
+ #address-cells = <1>;
+ #size-cells = <0>;
+ reg = <6>;
+ psu_eeprom@50 {
+ compatible = "at,24c02";
+ psu1_eeprom@50 {
+ compatible = "accton,as4610_psu1";
+ reg = <0x50>;
+ label = "psu1_eeprom";
+ read-only;
+ };
+ psu_eeprom@51 {
+ compatible = "at,24c02";
+ psu1_pmbus@58 {
+ compatible = "3y-power,ym1921";
+ reg = <0x58>;
+ };
+ psu2_eeprom@51 {
+ compatible = "accton,as4610_psu2";
+ reg = <0x51>;
+ label = "psu2_eeprom";
+ read-only;
+ };
+ psu2_pmbus@59 {
+ compatible = "3y-power,ym1921";
+ reg = <0x59>;
+ };
+ };
+

View File

@@ -139,8 +139,8 @@
#address-cells = <1>;
#size-cells = <0>;
reg = <0>;
sfp_eeprom@50 {
compatible = "at,as4610_sfp1";
optoe@50 {
compatible = "optoe2";
reg = <0x50>;
label = "port49";
};
@@ -151,8 +151,8 @@
#address-cells = <1>;
#size-cells = <0>;
reg = <1>;
sfp_eeprom@50 {
compatible = "accton,as4610_sfp2";
optoe@50 {
compatible = "optoe2";
reg = <0x50>;
label = "port50";
};
@@ -163,8 +163,8 @@
#address-cells = <1>;
#size-cells = <0>;
reg = <2>;
sfp_eeprom@50 {
compatible = "accton,as4610_sfp3";
optoe@50 {
compatible = "optoe2";
reg = <0x50>;
label = "port51";
};
@@ -175,8 +175,8 @@
#address-cells = <1>;
#size-cells = <0>;
reg = <3>;
sfp_eeprom@50 {
compatible = "accton,as4610_sfp4";
optoe@50 {
compatible = "optoe2";
reg = <0x50>;
label = "port52";
};
@@ -187,9 +187,10 @@
#address-cells = <1>;
#size-cells = <0>;
reg = <4>;
sfp_eeprom@50 {
compatible = "accton,as4610_sfp5";
optoe@50 {
compatible = "optoe1";
reg = <0x50>;
label = "port53";
};
};
@@ -198,9 +199,10 @@
#address-cells = <1>;
#size-cells = <0>;
reg = <5>;
sfp_eeprom@50 {
compatible = "accton,as4610_sfp6";
optoe@50 {
compatible = "optoe1";
reg = <0x50>;
label = "port54";
};
};

View File

@@ -139,8 +139,8 @@
#address-cells = <1>;
#size-cells = <0>;
reg = <0>;
sfp_eeprom@50 {
compatible = "at,as4610_sfp1";
optoe@50 {
compatible = "optoe2";
reg = <0x50>;
label = "port49";
};
@@ -151,8 +151,8 @@
#address-cells = <1>;
#size-cells = <0>;
reg = <1>;
sfp_eeprom@50 {
compatible = "accton,as4610_sfp2";
optoe@50 {
compatible = "optoe2";
reg = <0x50>;
label = "port50";
};
@@ -163,8 +163,8 @@
#address-cells = <1>;
#size-cells = <0>;
reg = <2>;
sfp_eeprom@50 {
compatible = "accton,as4610_sfp3";
optoe@50 {
compatible = "optoe2";
reg = <0x50>;
label = "port51";
};
@@ -175,8 +175,8 @@
#address-cells = <1>;
#size-cells = <0>;
reg = <3>;
sfp_eeprom@50 {
compatible = "accton,as4610_sfp4";
optoe@50 {
compatible = "optoe2";
reg = <0x50>;
label = "port52";
};
@@ -187,9 +187,10 @@
#address-cells = <1>;
#size-cells = <0>;
reg = <4>;
sfp_eeprom@50 {
compatible = "accton,as4610_sfp5";
optoe@50 {
compatible = "optoe1";
reg = <0x50>;
label = "port53";
};
};
@@ -198,9 +199,10 @@
#address-cells = <1>;
#size-cells = <0>;
reg = <5>;
sfp_eeprom@50 {
compatible = "accton,as4610_sfp6";
optoe@50 {
compatible = "optoe1";
reg = <0x50>;
label = "port54";
};
};

View File

@@ -24,50 +24,31 @@
*
***********************************************************/
#include <onlp/platformi/sfpi.h>
#include <onlplib/file.h>
#include "platform_lib.h"
#include <arm_accton_as4610/arm_accton_as4610_config.h>
#include "arm_accton_as4610_log.h"
#define MAX_SFP_PATH 64
static char sfp_node_path[MAX_SFP_PATH] = {0};
#define FRONT_PORT_MUX_INDEX(port) (port-46)
#define PORT_EEPROM_FORMAT "/sys/bus/i2c/devices/%d-0050/eeprom"
#define MODULE_PRESENT_FORMAT "/sys/bus/i2c/devices/0-0030/module_present_%d"
#define MODULE_RXLOS_FORMAT "/sys/bus/i2c/devices/0-0030/module_rx_los_%d"
#define MODULE_TXFAULT_FORMAT "/sys/bus/i2c/devices/0-0030/module_tx_fault_%d"
#define MODULE_PRESENT_ALL_ATTR_CPLD "/sys/bus/i2c/devices/0-0030/module_present_all"
#define MODULE_RXLOS_ALL_ATTR_CPLD "/sys/bus/i2c/devices/0-0030/module_rx_los_all"
static int
sfp_node_read_int(char *node_path, int *value, int data_len)
static int front_port_bus_index(int port)
{
int ret = 0;
char buf[8];
*value = 0;
ret = deviceNodeReadString(node_path, buf, sizeof(buf), data_len);
if (ret == 0) {
*value = atoi(buf);
}
return ret;
return (platform_id == PLATFORM_ID_POWERPC_ACCTON_AS4610_30_R0) ?
(port - 22) : /* PLATFORM_ID_POWERPC_ACCTON_AS4610_30_R0 */
(port - 46) ; /* PLATFORM_ID_POWERPC_ACCTON_AS4610_54_R0 */
}
static char*
sfp_get_port_path_addr(int port, int addr, char *node_name)
static int front_port_to_cpld_port(int port)
{
int front_port_mux_id;
if(platform_id == PLATFORM_ID_POWERPC_ACCTON_AS4610_30_R0)
front_port_mux_id = port - 22;
else /*PLATFORM_ID_POWERPC_ACCTON_AS4610_54_R0*/
front_port_mux_id = port - 46;
sprintf(sfp_node_path, "/sys/bus/i2c/devices/%d-00%d/%s",
front_port_mux_id, addr, node_name);
return sfp_node_path;
}
static char*
sfp_get_port_path(int port, char *node_name)
{
return sfp_get_port_path_addr(port, 50, node_name);
return (platform_id == PLATFORM_ID_POWERPC_ACCTON_AS4610_30_R0) ?
(port - 23) : /* PLATFORM_ID_POWERPC_ACCTON_AS4610_30_R0 */
(port - 47) ; /* PLATFORM_ID_POWERPC_ACCTON_AS4610_54_R0 */
}
/************************************************************
@@ -115,9 +96,9 @@ onlp_sfpi_is_present(int port)
* Return < 0 if error.
*/
int present;
char* path = sfp_get_port_path(port, "sfp_is_present");
if (sfp_node_read_int(path, &present, 0) != 0) {
int cpld_port = front_port_to_cpld_port(port);
if (onlp_file_read_int(&present, MODULE_PRESENT_FORMAT, cpld_port) < 0) {
AIM_LOG_ERROR("Unable to read present status from port(%d)\r\n", port);
return ONLP_STATUS_E_INTERNAL;
}
@@ -129,7 +110,6 @@ int
onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst)
{
uint32_t byte;
char* path;
FILE* fp;
int port;
@@ -140,18 +120,18 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst)
else /*PLATFORM_ID_POWERPC_ACCTON_AS4610_54_R0*/
port = 48;
path = sfp_get_port_path(port, "sfp_is_present_all");
fp = fopen(path, "r");
/* Read present status of each port */
fp = fopen(MODULE_PRESENT_ALL_ATTR_CPLD, "r");
if(fp == NULL) {
AIM_LOG_ERROR("Unable to open the sfp_is_present_all device file.");
AIM_LOG_ERROR("Unable to open the module_present_all device file of CPLD.");
return ONLP_STATUS_E_INTERNAL;
}
int count = fscanf(fp, "%x", &byte);
fclose(fp);
if(count != 1) {
/* Likely a CPLD read timeout. */
AIM_LOG_ERROR("Unable to read all fields from the sfp_is_present_all device file.");
AIM_LOG_ERROR("Unable to read all fields the module_present_all device file of CPLD.");
return ONLP_STATUS_E_INTERNAL;
}
@@ -173,7 +153,6 @@ int
onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst)
{
uint32_t byte;
char* path;
FILE* fp;
int port;
@@ -182,16 +161,18 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst)
else /*PLATFORM_ID_POWERPC_ACCTON_AS4610_54_R0*/
port = 48;
path = sfp_get_port_path(port, "sfp_rx_los_all");
fp = fopen(path, "r");
/* Read present status of each port */
fp = fopen(MODULE_RXLOS_ALL_ATTR_CPLD, "r");
if(fp == NULL) {
AIM_LOG_ERROR("Unable to open the sfp_rx_los_all device file.");
AIM_LOG_ERROR("Unable to open the module_rx_los_all device file of CPLD.");
return ONLP_STATUS_E_INTERNAL;
}
int count = fscanf(fp, "%x", &byte);
fclose(fp);
if(count != 1) {
AIM_LOG_ERROR("Unable to read all fields from the sfp_rx_los_all device file.");
/* Likely a CPLD read timeout. */
AIM_LOG_ERROR("Unable to read all fields the module_rx_los_all device file of CPLD.");
return ONLP_STATUS_E_INTERNAL;
}
@@ -212,32 +193,51 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst)
int
onlp_sfpi_eeprom_read(int port, uint8_t data[256])
{
char* path = sfp_get_port_path(port, "sfp_eeprom");
/*
* Read the SFP eeprom into data[]
*
* Return MISSING if SFP is missing.
* Return OK if eeprom is read
*/
int size = 0;
memset(data, 0, 256);
if (deviceNodeReadBinary(path, (char*)data, 256, 256) != 0) {
if(onlp_file_read(data, 256, &size, PORT_EEPROM_FORMAT, front_port_bus_index(port)) != ONLP_STATUS_OK) {
AIM_LOG_ERROR("Unable to read eeprom from port(%d)\r\n", port);
return ONLP_STATUS_E_INTERNAL;
}
if (size != 256) {
AIM_LOG_ERROR("Unable to read eeprom from port(%d), size is different!\r\n", port);
return ONLP_STATUS_E_INTERNAL;
}
return ONLP_STATUS_OK;
}
int
onlp_sfpi_dom_read(int port, uint8_t data[256])
{
char* path = sfp_get_port_path_addr(port, 51, "sfp_eeprom");
memset(data, 0, 256);
FILE* fp;
char file[64] = {0};
sprintf(file, PORT_EEPROM_FORMAT, front_port_bus_index(port));
fp = fopen(file, "r");
if(fp == NULL) {
AIM_LOG_ERROR("Unable to open the eeprom device file of port(%d)", port);
return ONLP_STATUS_E_INTERNAL;
}
if (deviceNodeReadBinary(path, (char*)data, 256, 256) != 0) {
AIM_LOG_INFO("Unable to read eeprom from port(%d)\r\n", port);
if (fseek(fp, 256, SEEK_CUR) != 0) {
fclose(fp);
AIM_LOG_ERROR("Unable to set the file position indicator of port(%d)", port);
return ONLP_STATUS_E_INTERNAL;
}
int ret = fread(data, 1, 256, fp);
fclose(fp);
if (ret != 256) {
AIM_LOG_ERROR("Unable to read the module_eeprom device file of port(%d)", port);
return ONLP_STATUS_E_INTERNAL;
}
@@ -247,45 +247,24 @@ onlp_sfpi_dom_read(int port, uint8_t data[256])
int
onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value)
{
int rv;
switch(control)
{
case ONLP_SFP_CONTROL_TX_DISABLE:
{
char* path = sfp_get_port_path(port, "sfp_tx_disable");
if (deviceNodeWriteInt(path, value, 0) != 0) {
AIM_LOG_ERROR("Unable to set tx_disable status to port(%d)\r\n", port);
rv = ONLP_STATUS_E_INTERNAL;
}
else {
rv = ONLP_STATUS_OK;
}
break;
}
default:
rv = ONLP_STATUS_E_UNSUPPORTED;
break;
}
return rv;
return ONLP_STATUS_E_UNSUPPORTED;
}
int
onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value)
{
int rv;
char* path = NULL;
int cpld_port = front_port_to_cpld_port(port);
if (cpld_port > 4) {
return ONLP_STATUS_E_UNSUPPORTED;
}
switch(control)
{
case ONLP_SFP_CONTROL_RX_LOS:
{
path = sfp_get_port_path(port, "sfp_rx_los");
if (sfp_node_read_int(path, value, 0) != 0) {
if (onlp_file_read_int(value, MODULE_RXLOS_FORMAT, cpld_port) < 0) {
AIM_LOG_ERROR("Unable to read rx_los status from port(%d)\r\n", port);
rv = ONLP_STATUS_E_INTERNAL;
}
@@ -297,9 +276,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value)
case ONLP_SFP_CONTROL_TX_FAULT:
{
path = sfp_get_port_path(port, "sfp_tx_fault");
if (sfp_node_read_int(path, value, 0) != 0) {
if (onlp_file_read_int(value, MODULE_TXFAULT_FORMAT, cpld_port) < 0) {
AIM_LOG_ERROR("Unable to read tx_fault status from port(%d)\r\n", port);
rv = ONLP_STATUS_E_INTERNAL;
}
@@ -309,20 +286,6 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value)
break;
}
case ONLP_SFP_CONTROL_TX_DISABLE:
{
path = sfp_get_port_path(port, "sfp_tx_disable");
if (sfp_node_read_int(path, value, 0) != 0) {
AIM_LOG_ERROR("Unable to read tx_disabled status from port(%d)\r\n", port);
rv = ONLP_STATUS_E_INTERNAL;
}
else {
rv = ONLP_STATUS_OK;
}
break;
}
default:
rv = ONLP_STATUS_E_UNSUPPORTED;
}
@@ -330,9 +293,9 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value)
return rv;
}
int
onlp_sfpi_denit(void)
{
return ONLP_STATUS_OK;
}