[devices]: Add lpmode in sfputil.py for Accton AS6712-32X (#3095)

Signed-off-by: brandon_chuang <brandon_chuang@edge-core.com>
This commit is contained in:
brandonchuang 2019-06-29 12:35:27 +08:00 committed by lguohan
parent 8c3fdfd079
commit 0b8c1a10e8
2 changed files with 210 additions and 154 deletions

View File

@ -6,6 +6,8 @@
try: try:
import time import time
import os import os
import string
from ctypes import create_string_buffer
from sonic_sfp.sfputilbase import SfpUtilBase from sonic_sfp.sfputilbase import SfpUtilBase
except ImportError as e: except ImportError as e:
raise ImportError("%s - required module not found" % str(e)) raise ImportError("%s - required module not found" % str(e))
@ -176,11 +178,85 @@ class SfpUtil(SfpUtilBase):
return False return False
def get_low_power_mode(self, port_num): def get_low_power_mode_cpld(self, port_num):
raise NotImplementedError if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False
cpld_path = self.get_cpld_dev_path(port_num)
_path = cpld_path + "/module_lp_mode_"
_path += str(self._port_to_i2c_mapping[port_num][0])
def set_low_power_mode(self, port_num, lpmode): try:
raise NotImplementedError reg_file = open(_path)
except IOError as e:
print "Error: unable to open file: %s" % str(e)
return False
content = reg_file.readline().rstrip()
reg_file.close()
# content is a string, either "0" or "1"
if content == "1":
return True
return False
def get_low_power_mode(self, port_num):
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False
if not self.get_presence(port_num):
return False
try:
eeprom = None
eeprom = open(self.port_to_eeprom_mapping[port_num], mode="rb", buffering=0)
eeprom.seek(93)
lpmode = ord(eeprom.read(1))
if not (lpmode & 0x1): # 'Power override' bit is 0
return self.get_low_power_mode_cpld(port_num)
else:
if ((lpmode & 0x2) == 0x2):
return True # Low Power Mode if "Power set" bit is 1
else:
return False # High Power Mode if "Power set" bit is 0
except IOError as e:
print "Error: unable to open file: %s" % str(e)
return False
finally:
if eeprom is not None:
eeprom.close()
time.sleep(0.01)
def set_low_power_mode(self, port_num, lpmode):
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False
try:
eeprom = None
if not self.get_presence(port_num):
return False # Port is not present, unable to set the eeprom
# Fill in write buffer
regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode
buffer = create_string_buffer(1)
buffer[0] = chr(regval)
# Write to eeprom
eeprom = open(self.port_to_eeprom_mapping[port_num], mode="r+b", buffering=0)
eeprom.seek(93)
eeprom.write(buffer[0])
return True
except IOError as e:
print "Error: unable to open file: %s" % str(e)
return False
finally:
if eeprom is not None:
eeprom.close()
time.sleep(0.01)
def reset(self, port_num): def reset(self, port_num):
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:

View File

@ -103,6 +103,7 @@ MODULE_DEVICE_TABLE(i2c, as6712_32x_cpld_mux_id);
#define TRANSCEIVER_TXDISABLE_ATTR_ID(index) MODULE_TXDISABLE_##index #define TRANSCEIVER_TXDISABLE_ATTR_ID(index) MODULE_TXDISABLE_##index
#define TRANSCEIVER_RXLOS_ATTR_ID(index) MODULE_RXLOS_##index #define TRANSCEIVER_RXLOS_ATTR_ID(index) MODULE_RXLOS_##index
#define TRANSCEIVER_TXFAULT_ATTR_ID(index) MODULE_TXFAULT_##index #define TRANSCEIVER_TXFAULT_ATTR_ID(index) MODULE_TXFAULT_##index
#define TRANSCEIVER_LPMODE_ATTR_ID(index) MODULE_LPMODE_##index
#define TRANSCEIVER_RESET_ATTR_ID(index) MODULE_RESET_##index #define TRANSCEIVER_RESET_ATTR_ID(index) MODULE_RESET_##index
enum as6712_32x_cpld_sysfs_attributes { enum as6712_32x_cpld_sysfs_attributes {
@ -142,9 +143,9 @@ enum as6712_32x_cpld_sysfs_attributes {
TRANSCEIVER_PRESENT_ATTR_ID(29), TRANSCEIVER_PRESENT_ATTR_ID(29),
TRANSCEIVER_PRESENT_ATTR_ID(30), TRANSCEIVER_PRESENT_ATTR_ID(30),
TRANSCEIVER_PRESENT_ATTR_ID(31), TRANSCEIVER_PRESENT_ATTR_ID(31),
TRANSCEIVER_PRESENT_ATTR_ID(32), TRANSCEIVER_PRESENT_ATTR_ID(32),
/*Reset*/ /*Reset*/
TRANSCEIVER_RESET_ATTR_ID(1), TRANSCEIVER_RESET_ATTR_ID(1),
TRANSCEIVER_RESET_ATTR_ID(2), TRANSCEIVER_RESET_ATTR_ID(2),
TRANSCEIVER_RESET_ATTR_ID(3), TRANSCEIVER_RESET_ATTR_ID(3),
TRANSCEIVER_RESET_ATTR_ID(4), TRANSCEIVER_RESET_ATTR_ID(4),
@ -176,6 +177,38 @@ enum as6712_32x_cpld_sysfs_attributes {
TRANSCEIVER_RESET_ATTR_ID(30), TRANSCEIVER_RESET_ATTR_ID(30),
TRANSCEIVER_RESET_ATTR_ID(31), TRANSCEIVER_RESET_ATTR_ID(31),
TRANSCEIVER_RESET_ATTR_ID(32), TRANSCEIVER_RESET_ATTR_ID(32),
TRANSCEIVER_LPMODE_ATTR_ID(1),
TRANSCEIVER_LPMODE_ATTR_ID(2),
TRANSCEIVER_LPMODE_ATTR_ID(3),
TRANSCEIVER_LPMODE_ATTR_ID(4),
TRANSCEIVER_LPMODE_ATTR_ID(5),
TRANSCEIVER_LPMODE_ATTR_ID(6),
TRANSCEIVER_LPMODE_ATTR_ID(7),
TRANSCEIVER_LPMODE_ATTR_ID(8),
TRANSCEIVER_LPMODE_ATTR_ID(9),
TRANSCEIVER_LPMODE_ATTR_ID(10),
TRANSCEIVER_LPMODE_ATTR_ID(11),
TRANSCEIVER_LPMODE_ATTR_ID(12),
TRANSCEIVER_LPMODE_ATTR_ID(13),
TRANSCEIVER_LPMODE_ATTR_ID(14),
TRANSCEIVER_LPMODE_ATTR_ID(15),
TRANSCEIVER_LPMODE_ATTR_ID(16),
TRANSCEIVER_LPMODE_ATTR_ID(17),
TRANSCEIVER_LPMODE_ATTR_ID(18),
TRANSCEIVER_LPMODE_ATTR_ID(19),
TRANSCEIVER_LPMODE_ATTR_ID(20),
TRANSCEIVER_LPMODE_ATTR_ID(21),
TRANSCEIVER_LPMODE_ATTR_ID(22),
TRANSCEIVER_LPMODE_ATTR_ID(23),
TRANSCEIVER_LPMODE_ATTR_ID(24),
TRANSCEIVER_LPMODE_ATTR_ID(25),
TRANSCEIVER_LPMODE_ATTR_ID(26),
TRANSCEIVER_LPMODE_ATTR_ID(27),
TRANSCEIVER_LPMODE_ATTR_ID(28),
TRANSCEIVER_LPMODE_ATTR_ID(29),
TRANSCEIVER_LPMODE_ATTR_ID(30),
TRANSCEIVER_LPMODE_ATTR_ID(31),
TRANSCEIVER_LPMODE_ATTR_ID(32),
}; };
/* sysfs attributes for hwmon /* sysfs attributes for hwmon
@ -194,83 +227,51 @@ static int as6712_32x_cpld_read_internal(struct i2c_client *client, u8 reg);
static int as6712_32x_cpld_write_internal(struct i2c_client *client, u8 reg, u8 value); static int as6712_32x_cpld_write_internal(struct i2c_client *client, u8 reg, u8 value);
/* transceiver attributes */ /* transceiver attributes */
#define DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(index) \ #define DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(index) \
static SENSOR_DEVICE_ATTR(module_present_##index, S_IRUGO, show_status, NULL, MODULE_PRESENT_##index) static SENSOR_DEVICE_ATTR(module_present_##index, S_IRUGO, show_status, NULL, MODULE_PRESENT_##index); \
#define DECLARE_TRANSCEIVER_PRESENT_ATTR(index) &sensor_dev_attr_module_present_##index.dev_attr.attr static SENSOR_DEVICE_ATTR(module_reset_##index, S_IWUSR|S_IRUGO, show_status, set_status, MODULE_RESET_##index); \
static SENSOR_DEVICE_ATTR(module_lp_mode_##index, S_IRUGO | S_IWUSR, show_status, set_status, MODULE_LPMODE_##index)
#define DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(index) \ #define DECLARE_TRANSCEIVER_ATTR(index) \
static SENSOR_DEVICE_ATTR(module_reset_##index, S_IWUSR|S_IRUGO, show_status, set_status, MODULE_RESET_##index) &sensor_dev_attr_module_present_##index.dev_attr.attr, \
#define DECLARE_TRANSCEIVER_RESET_ATTR(index) &sensor_dev_attr_module_reset_##index.dev_attr.attr &sensor_dev_attr_module_reset_##index.dev_attr.attr, \
&sensor_dev_attr_module_lp_mode_##index.dev_attr.attr
static SENSOR_DEVICE_ATTR(version, S_IRUGO, show_version, NULL, CPLD_VERSION); static SENSOR_DEVICE_ATTR(version, S_IRUGO, show_version, NULL, CPLD_VERSION);
static SENSOR_DEVICE_ATTR(access, S_IWUSR, NULL, access, ACCESS); static SENSOR_DEVICE_ATTR(access, S_IWUSR, NULL, access, ACCESS);
/* transceiver attributes */ /* transceiver attributes */
static SENSOR_DEVICE_ATTR(module_present_all, S_IRUGO, show_present_all, NULL, MODULE_PRESENT_ALL); static SENSOR_DEVICE_ATTR(module_present_all, S_IRUGO, show_present_all, NULL, MODULE_PRESENT_ALL);
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(1); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(1);
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(2); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(2);
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(3); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(3);
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(4); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(4);
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(5); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(5);
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(6); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(6);
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(7); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(7);
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(8); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(8);
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(9); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(9);
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(10); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(10);
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(11); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(11);
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(12); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(12);
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(13); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(13);
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(14); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(14);
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(15); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(15);
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(16); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(16);
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(17); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(17);
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(18); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(18);
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(19); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(19);
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(20); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(20);
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(21); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(21);
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(22); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(22);
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(23); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(23);
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(24); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(24);
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(25); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(25);
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(26); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(26);
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(27); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(27);
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(28); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(28);
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(29); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(29);
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(30); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(30);
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(31); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(31);
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(32); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(32);
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(1);
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(2);
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(3);
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(4);
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(5);
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(6);
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(7);
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(8);
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(9);
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(10);
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(11);
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(12);
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(13);
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(14);
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(15);
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(16);
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(17);
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(18);
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(19);
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(20);
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(21);
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(22);
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(23);
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(24);
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(25);
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(26);
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(27);
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(28);
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(29);
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(30);
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(31);
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(32);
static struct attribute *as6712_32x_cpld1_attributes[] = { static struct attribute *as6712_32x_cpld1_attributes[] = {
@ -288,38 +289,22 @@ static struct attribute *as6712_32x_cpld2_attributes[] = {
&sensor_dev_attr_access.dev_attr.attr, &sensor_dev_attr_access.dev_attr.attr,
/* transceiver attributes */ /* transceiver attributes */
&sensor_dev_attr_module_present_all.dev_attr.attr, &sensor_dev_attr_module_present_all.dev_attr.attr,
DECLARE_TRANSCEIVER_PRESENT_ATTR(1), DECLARE_TRANSCEIVER_ATTR(1),
DECLARE_TRANSCEIVER_PRESENT_ATTR(2), DECLARE_TRANSCEIVER_ATTR(2),
DECLARE_TRANSCEIVER_PRESENT_ATTR(3), DECLARE_TRANSCEIVER_ATTR(3),
DECLARE_TRANSCEIVER_PRESENT_ATTR(4), DECLARE_TRANSCEIVER_ATTR(4),
DECLARE_TRANSCEIVER_PRESENT_ATTR(5), DECLARE_TRANSCEIVER_ATTR(5),
DECLARE_TRANSCEIVER_PRESENT_ATTR(6), DECLARE_TRANSCEIVER_ATTR(6),
DECLARE_TRANSCEIVER_PRESENT_ATTR(7), DECLARE_TRANSCEIVER_ATTR(7),
DECLARE_TRANSCEIVER_PRESENT_ATTR(8), DECLARE_TRANSCEIVER_ATTR(8),
DECLARE_TRANSCEIVER_PRESENT_ATTR(9), DECLARE_TRANSCEIVER_ATTR(9),
DECLARE_TRANSCEIVER_PRESENT_ATTR(10), DECLARE_TRANSCEIVER_ATTR(10),
DECLARE_TRANSCEIVER_PRESENT_ATTR(11), DECLARE_TRANSCEIVER_ATTR(11),
DECLARE_TRANSCEIVER_PRESENT_ATTR(12), DECLARE_TRANSCEIVER_ATTR(12),
DECLARE_TRANSCEIVER_PRESENT_ATTR(13), DECLARE_TRANSCEIVER_ATTR(13),
DECLARE_TRANSCEIVER_PRESENT_ATTR(14), DECLARE_TRANSCEIVER_ATTR(14),
DECLARE_TRANSCEIVER_PRESENT_ATTR(15), DECLARE_TRANSCEIVER_ATTR(15),
DECLARE_TRANSCEIVER_PRESENT_ATTR(16), DECLARE_TRANSCEIVER_ATTR(16),
DECLARE_TRANSCEIVER_RESET_ATTR(1),
DECLARE_TRANSCEIVER_RESET_ATTR(2),
DECLARE_TRANSCEIVER_RESET_ATTR(3),
DECLARE_TRANSCEIVER_RESET_ATTR(4),
DECLARE_TRANSCEIVER_RESET_ATTR(5),
DECLARE_TRANSCEIVER_RESET_ATTR(6),
DECLARE_TRANSCEIVER_RESET_ATTR(7),
DECLARE_TRANSCEIVER_RESET_ATTR(8),
DECLARE_TRANSCEIVER_RESET_ATTR(9),
DECLARE_TRANSCEIVER_RESET_ATTR(10),
DECLARE_TRANSCEIVER_RESET_ATTR(11),
DECLARE_TRANSCEIVER_RESET_ATTR(12),
DECLARE_TRANSCEIVER_RESET_ATTR(13),
DECLARE_TRANSCEIVER_RESET_ATTR(14),
DECLARE_TRANSCEIVER_RESET_ATTR(15),
DECLARE_TRANSCEIVER_RESET_ATTR(16),
NULL NULL
}; };
@ -332,38 +317,22 @@ static struct attribute *as6712_32x_cpld3_attributes[] = {
&sensor_dev_attr_access.dev_attr.attr, &sensor_dev_attr_access.dev_attr.attr,
/* transceiver attributes */ /* transceiver attributes */
&sensor_dev_attr_module_present_all.dev_attr.attr, &sensor_dev_attr_module_present_all.dev_attr.attr,
DECLARE_TRANSCEIVER_PRESENT_ATTR(17), DECLARE_TRANSCEIVER_ATTR(17),
DECLARE_TRANSCEIVER_PRESENT_ATTR(18), DECLARE_TRANSCEIVER_ATTR(18),
DECLARE_TRANSCEIVER_PRESENT_ATTR(19), DECLARE_TRANSCEIVER_ATTR(19),
DECLARE_TRANSCEIVER_PRESENT_ATTR(20), DECLARE_TRANSCEIVER_ATTR(20),
DECLARE_TRANSCEIVER_PRESENT_ATTR(21), DECLARE_TRANSCEIVER_ATTR(21),
DECLARE_TRANSCEIVER_PRESENT_ATTR(22), DECLARE_TRANSCEIVER_ATTR(22),
DECLARE_TRANSCEIVER_PRESENT_ATTR(23), DECLARE_TRANSCEIVER_ATTR(23),
DECLARE_TRANSCEIVER_PRESENT_ATTR(24), DECLARE_TRANSCEIVER_ATTR(24),
DECLARE_TRANSCEIVER_PRESENT_ATTR(25), DECLARE_TRANSCEIVER_ATTR(25),
DECLARE_TRANSCEIVER_PRESENT_ATTR(26), DECLARE_TRANSCEIVER_ATTR(26),
DECLARE_TRANSCEIVER_PRESENT_ATTR(27), DECLARE_TRANSCEIVER_ATTR(27),
DECLARE_TRANSCEIVER_PRESENT_ATTR(28), DECLARE_TRANSCEIVER_ATTR(28),
DECLARE_TRANSCEIVER_PRESENT_ATTR(29), DECLARE_TRANSCEIVER_ATTR(29),
DECLARE_TRANSCEIVER_PRESENT_ATTR(30), DECLARE_TRANSCEIVER_ATTR(30),
DECLARE_TRANSCEIVER_PRESENT_ATTR(31), DECLARE_TRANSCEIVER_ATTR(31),
DECLARE_TRANSCEIVER_PRESENT_ATTR(32), DECLARE_TRANSCEIVER_ATTR(32),
DECLARE_TRANSCEIVER_RESET_ATTR(17),
DECLARE_TRANSCEIVER_RESET_ATTR(18),
DECLARE_TRANSCEIVER_RESET_ATTR(19),
DECLARE_TRANSCEIVER_RESET_ATTR(20),
DECLARE_TRANSCEIVER_RESET_ATTR(21),
DECLARE_TRANSCEIVER_RESET_ATTR(22),
DECLARE_TRANSCEIVER_RESET_ATTR(23),
DECLARE_TRANSCEIVER_RESET_ATTR(24),
DECLARE_TRANSCEIVER_RESET_ATTR(25),
DECLARE_TRANSCEIVER_RESET_ATTR(26),
DECLARE_TRANSCEIVER_RESET_ATTR(27),
DECLARE_TRANSCEIVER_RESET_ATTR(28),
DECLARE_TRANSCEIVER_RESET_ATTR(29),
DECLARE_TRANSCEIVER_RESET_ATTR(30),
DECLARE_TRANSCEIVER_RESET_ATTR(31),
DECLARE_TRANSCEIVER_RESET_ATTR(32),
NULL NULL
}; };
@ -411,9 +380,9 @@ static ssize_t set_status(struct device *dev, struct device_attribute *da,
struct i2c_mux_core *muxc = i2c_get_clientdata(client); struct i2c_mux_core *muxc = i2c_get_clientdata(client);
struct as6712_32x_cpld_data *data = i2c_mux_priv(muxc); struct as6712_32x_cpld_data *data = i2c_mux_priv(muxc);
int status = 0; int status = 0, reverse = 0;
u8 reg = 0, mask = 0; u8 reg = 0, mask = 0;
u32 val, para; u32 val, para;
if (sscanf(buf, "%d", &para) != 1) { if (sscanf(buf, "%d", &para) != 1) {
return -EINVAL; return -EINVAL;
@ -421,8 +390,13 @@ static ssize_t set_status(struct device *dev, struct device_attribute *da,
switch (attr->index) { switch (attr->index) {
case MODULE_RESET_1 ... MODULE_RESET_32: case MODULE_RESET_1 ... MODULE_RESET_32:
reg = 0x4 + (((attr->index - MODULE_PRESENT_1)/8)%2); reg = 0x4 + (((attr->index - MODULE_RESET_1)/8)%2);
mask = 0x1 << ((attr->index - MODULE_PRESENT_1)%8); mask = 0x1 << ((attr->index - MODULE_RESET_1)%8);
reverse = 1;
break;
case MODULE_LPMODE_1 ... MODULE_LPMODE_32:
reg = 0xC + (((attr->index - MODULE_LPMODE_1)/8)%2);
mask = 0x1 << ((attr->index - MODULE_LPMODE_1)%8);
break; break;
default: default:
return 0; return 0;
@ -432,12 +406,13 @@ static ssize_t set_status(struct device *dev, struct device_attribute *da,
status = as6712_32x_cpld_read_internal(client, reg); status = as6712_32x_cpld_read_internal(client, reg);
if (unlikely(status < 0)) { if (unlikely(status < 0)) {
goto exit; goto exit;
} }
val = status & ~mask;
if (!para && reverse) { /*0 means reset*/
val |= mask;
}
val = status & ~mask;
if (!para) { /*0 means reset*/
val |= mask;
}
status = as6712_32x_cpld_write_internal(client, reg, val); status = as6712_32x_cpld_write_internal(client, reg, val);
if (unlikely(status < 0)) { if (unlikely(status < 0)) {
goto exit; goto exit;
@ -477,9 +452,14 @@ static ssize_t show_status(struct device *dev, struct device_attribute *da,
mask = 0x1 << (attr->index - MODULE_PRESENT_25); mask = 0x1 << (attr->index - MODULE_PRESENT_25);
break; break;
case MODULE_RESET_1 ... MODULE_RESET_32: case MODULE_RESET_1 ... MODULE_RESET_32:
reg = 0x4 + (((attr->index - MODULE_PRESENT_1)/8)%2); reg = 0x4 + (((attr->index - MODULE_RESET_1)/8)%2);
mask = 0x1 << ((attr->index - MODULE_PRESENT_1)%8); mask = 0x1 << ((attr->index - MODULE_RESET_1)%8);
break; break;
case MODULE_LPMODE_1 ... MODULE_LPMODE_32:
reg = 0xC + (((attr->index - MODULE_LPMODE_1)/8)%2);
mask = 0x1 << ((attr->index - MODULE_LPMODE_1)%8);
break;
default: default:
return 0; return 0;
} }