Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Accton/AS4630] update reg use for new CPLD FW #8115

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ static ssize_t show_status(struct device *dev, struct device_attribute *da,
break;
case MODULE_TXDISABLE_49 ... MODULE_TXDISABLE_50:
reg=0x5;
mask=0x1 << (attr->index==MODULE_TXFAULT_49?7:3);
mask=0x1 << (attr->index==MODULE_TXDISABLE_49?7:3);
break;

case MODULE_RXLOS_51 ... MODULE_RXLOS_52:
Expand All @@ -290,7 +290,7 @@ static ssize_t show_status(struct device *dev, struct device_attribute *da,
break;
case MODULE_TXDISABLE_51 ... MODULE_TXDISABLE_52:
reg=0x6;
mask=0x1 << (attr->index==MODULE_TXFAULT_51?7:3);
mask=0x1 << (attr->index==MODULE_TXDISABLE_51?7:3);
break;
case MODULE_PRESENT_53 ... MODULE_PRESENT_54:
reg=0x21;
Expand Down Expand Up @@ -338,11 +338,11 @@ static ssize_t set_tx_disable(struct device *dev, struct device_attribute *da,
{
case MODULE_TXDISABLE_49 ... MODULE_TXDISABLE_50:
reg=0x5;
mask=0x1 << (attr->index==MODULE_TXFAULT_49?7:3);
mask=0x1 << (attr->index==MODULE_TXDISABLE_49?7:3);
break;
case MODULE_TXDISABLE_51 ... MODULE_TXDISABLE_52:
reg=0x6;
mask=0x1 << (attr->index==MODULE_TXFAULT_51?7:3);
mask=0x1 << (attr->index==MODULE_TXDISABLE_51?7:3);
break;

default:
Expand Down Expand Up @@ -498,11 +498,11 @@ static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da,

static u8 reg_val_to_direction(u8 reg_val, enum fan_id id)
{
u8 mask = (1 << id);
u8 mask = (1 << (4 + id));

reg_val &= mask;

return reg_val ? 1 : 0;
return reg_val ? 0 : 1;
}

static u8 reg_val_to_is_present(u8 reg_val, enum fan_id id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static struct accton_as4630_54pe_led_data *ledctl = NULL;
#define LED_TYPE_POE_REG_MASK (0x2|0x1)
#define LED_MODE_POE_GREEN_VALUE 0x1
#define LED_MODE_POE_AMBER_VALUE 0x2
#define LED_MODE_POE_OFF_VALUE 0x0
#define LED_MODE_POE_OFF_VALUE 0x3

#define LED_TYPE_STK1_REG_MASK 0x20
#define LED_MODE_STK1_GREEN_VALUE 0x0
Expand All @@ -74,20 +74,20 @@ static struct accton_as4630_54pe_led_data *ledctl = NULL;
#define LED_MODE_STK2_GREEN_VALUE 0x0
#define LED_MODE_STK2_OFF_VALUE 0x10

#define LED_TYPE_FAN_REG_MASK (0x20|0x10)
#define LED_MODE_FAN_AMBER_VALUE 0x20
#define LED_MODE_FAN_GREEN_VALUE 0x10
#define LED_MODE_FAN_OFF_VALUE (0x0)
#define LED_TYPE_FAN_REG_MASK (0x8|0x4)
#define LED_MODE_FAN_AMBER_VALUE 0x8
#define LED_MODE_FAN_GREEN_VALUE 0x4
#define LED_MODE_FAN_OFF_VALUE (0xC)

#define LED_TYPE_PSU2_REG_MASK (0x8|0x4)
#define LED_MODE_PSU2_AMBER_VALUE 0x8
#define LED_MODE_PSU2_GREEN_VALUE 0x4
#define LED_MODE_PSU2_OFF_VALUE (0x0)
#define LED_TYPE_PSU2_REG_MASK (0x80|0x40)
#define LED_MODE_PSU2_AMBER_VALUE 0x80
#define LED_MODE_PSU2_GREEN_VALUE 0x40
#define LED_MODE_PSU2_OFF_VALUE (0xC0)

#define LED_TYPE_PSU1_REG_MASK (0x2|0x1)
#define LED_MODE_PSU1_AMBER_VALUE 0x2
#define LED_MODE_PSU1_GREEN_VALUE 0x1
#define LED_MODE_PSU1_OFF_VALUE (0x0)
#define LED_MODE_PSU1_OFF_VALUE (0x3)

enum led_type {
LED_TYPE_DIAG,
Expand All @@ -106,8 +106,8 @@ struct led_reg {
};

static const struct led_reg led_reg_map[] = {
{(1<<LED_TYPE_DIAG)| (1<<LED_TYPE_PRI) | (1<<LED_TYPE_PSU2) , 0x30},
{(1<<LED_TYPE_PSU1) | (1<<LED_TYPE_FAN) | (1<<LED_TYPE_POE) |(1<<LED_TYPE_STK1) | (1<<LED_TYPE_STK2) , 0x31},
{(1<<LED_TYPE_DIAG)| (1<<LED_TYPE_PRI) | (1<<LED_TYPE_PSU1) , 0x30},
{(1<<LED_TYPE_PSU2) | (1<<LED_TYPE_FAN) | (1<<LED_TYPE_POE) |(1<<LED_TYPE_STK1) | (1<<LED_TYPE_STK2) , 0x31},
};


Expand Down Expand Up @@ -371,7 +371,7 @@ static void accton_as4630_54pe_led_fan_set(struct led_classdev *led_cdev,
static enum led_brightness accton_as4630_54pe_led_fan_get(struct led_classdev *cdev)
{
accton_as4630_54pe_led_update();
return led_reg_val_to_light_mode(LED_TYPE_FAN, ledctl->reg_val[0]);
return led_reg_val_to_light_mode(LED_TYPE_FAN, ledctl->reg_val[1]);
}

static void accton_as4630_54pe_led_psu1_set(struct led_classdev *led_cdev,
Expand All @@ -395,7 +395,7 @@ static void accton_as4630_54pe_led_psu2_set(struct led_classdev *led_cdev,
static enum led_brightness accton_as4630_54pe_led_psu2_get(struct led_classdev *cdev)
{
accton_as4630_54pe_led_update();
return led_reg_val_to_light_mode(LED_TYPE_PSU2, ledctl->reg_val[0]);
return led_reg_val_to_light_mode(LED_TYPE_PSU2, ledctl->reg_val[1]);
}

static struct led_classdev accton_as4630_54pe_leds[] = {
Expand All @@ -405,7 +405,7 @@ static struct led_classdev accton_as4630_54pe_leds[] = {
.brightness_set = accton_as4630_54pe_led_diag_set,
.brightness_get = accton_as4630_54pe_led_diag_get,
.flags = LED_CORE_SUSPENDRESUME,
.max_brightness = LED_MODE_GREEN,
.max_brightness = LED_MODE_GREEN_BLINK,
},
[LED_TYPE_PRI] = {
.name = "pri",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ static struct as4630_54pe_psu_data *as4630_54pe_psu_update_device(struct device
/* Read model name */
memset(data->model_name, 0, sizeof(data->model_name));
memset(data->serial_number, 0, sizeof(data->serial_number));
power_good = (data->status >> (3-data->index) & 0x1);
power_good = (data->status >> (data->index==0? 6:2)) & 0x1;

if (power_good) {
status = as4630_54pe_psu_read_block(client, 0x20, data->model_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ static const struct i2c_device_id as4630_54te_cpld_id[] = {
};
MODULE_DEVICE_TABLE(i2c, as4630_54te_cpld_id);

#define TRANSCEIVER_RESET_ATTR_ID(index) MODULE_RESET_##index
#define TRANSCEIVER_LPMODE_ATTR_ID(index) MODULE_LPMODE_##index
#define TRANSCEIVER_PRESENT_ATTR_ID(index) MODULE_PRESENT_##index
#define TRANSCEIVER_TXDISABLE_ATTR_ID(index) MODULE_TXDISABLE_##index
#define TRANSCEIVER_RXLOS_ATTR_ID(index) MODULE_RXLOS_##index
Expand Down Expand Up @@ -123,6 +125,10 @@ enum as4630_54te_cpld_sysfs_attributes {
TRANSCEIVER_PRESENT_ATTR_ID(52),
TRANSCEIVER_PRESENT_ATTR_ID(53),
TRANSCEIVER_PRESENT_ATTR_ID(54),
TRANSCEIVER_RESET_ATTR_ID(53),
TRANSCEIVER_RESET_ATTR_ID(54),
TRANSCEIVER_LPMODE_ATTR_ID(53),
TRANSCEIVER_LPMODE_ATTR_ID(54),
TRANSCEIVER_TXDISABLE_ATTR_ID(49),
TRANSCEIVER_TXDISABLE_ATTR_ID(50),
TRANSCEIVER_TXDISABLE_ATTR_ID(51),
Expand All @@ -148,6 +154,8 @@ static ssize_t show_status(struct device *dev, struct device_attribute *da,
char *buf);
static ssize_t set_tx_disable(struct device *dev, struct device_attribute *da,
const char *buf, size_t count);
static ssize_t set_qsfp(struct device *dev, struct device_attribute *da,
const char *buf, size_t count);
static ssize_t access(struct device *dev, struct device_attribute *da,
const char *buf, size_t count);
static ssize_t show_version(struct device *dev, struct device_attribute *da,
Expand Down Expand Up @@ -180,9 +188,13 @@ static ssize_t get_sys_temp(struct device *dev, struct device_attribute *da, cha
&sensor_dev_attr_module_tx_fault_##index.dev_attr.attr

#define DECLARE_QSFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(index) \
static SENSOR_DEVICE_ATTR(module_lpmode_##index, S_IRUGO | S_IWUSR, show_status, set_qsfp, MODULE_LPMODE_##index); \
static SENSOR_DEVICE_ATTR(module_reset_##index, S_IRUGO | S_IWUSR, show_status, set_qsfp, MODULE_RESET_##index); \
static SENSOR_DEVICE_ATTR(module_present_##index, S_IRUGO, show_status, NULL, MODULE_PRESENT_##index);

#define DECLARE_QSFP_TRANSCEIVER_ATTR(index) \
&sensor_dev_attr_module_lpmode_##index.dev_attr.attr, \
&sensor_dev_attr_module_reset_##index.dev_attr.attr, \
&sensor_dev_attr_module_present_##index.dev_attr.attr


Expand Down Expand Up @@ -273,7 +285,7 @@ static ssize_t show_status(struct device *dev, struct device_attribute *da,
break;
case MODULE_TXDISABLE_49 ... MODULE_TXDISABLE_50:
reg=0x5;
mask=0x1 << (attr->index==MODULE_TXFAULT_49?7:3);
mask=0x1 << (attr->index==MODULE_TXDISABLE_49?7:3);
break;

case MODULE_RXLOS_51 ... MODULE_RXLOS_52:
Expand All @@ -290,12 +302,22 @@ static ssize_t show_status(struct device *dev, struct device_attribute *da,
break;
case MODULE_TXDISABLE_51 ... MODULE_TXDISABLE_52:
reg=0x6;
mask=0x1 << (attr->index==MODULE_TXFAULT_51?7:3);
mask=0x1 << (attr->index==MODULE_TXDISABLE_51?7:3);
break;
case MODULE_PRESENT_53 ... MODULE_PRESENT_54:
reg=0x21;
mask=0x1 << (attr->index==MODULE_PRESENT_53?0:4);
break;
case MODULE_RESET_53 ... MODULE_RESET_54:
reg=0x21;
mask=0x1 << (attr->index==MODULE_RESET_53?3:7);
revert = 1;
break;
case MODULE_LPMODE_53 ... MODULE_LPMODE_54:
reg = 0x21;
mask = 0x1 << (attr->index==MODULE_LPMODE_53?2:6);
revert = 0;
break;
default:
return 0;
}
Expand All @@ -319,6 +341,61 @@ static ssize_t show_status(struct device *dev, struct device_attribute *da,
return status;
}

static ssize_t set_qsfp(struct device *dev, struct device_attribute *da,
const char *buf, size_t count)
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
struct i2c_client *client = to_i2c_client(dev);
struct as4630_54te_cpld_data *data = i2c_get_clientdata(client);
long disable;
int status;
u8 reg = 0, mask = 0, revert = 0;

status = kstrtol(buf, 10, &disable);
if (status) {
return status;
}
reg = 0x21;
switch (attr->index)
{
case MODULE_RESET_53 ... MODULE_RESET_54:
mask=0x1 << (attr->index==MODULE_RESET_53?3:7);
revert = 1;
break;
case MODULE_LPMODE_53 ... MODULE_LPMODE_54:
mask=0x1 << (attr->index==MODULE_LPMODE_53?2:6);
revert = 0;
break;
default:
return 0;
}

disable = revert ? disable : !disable;
/* Read current status */
mutex_lock(&data->update_lock);
status = as4630_54te_cpld_read_internal(client, reg);
if (unlikely(status < 0)) {
goto exit;
}
if (disable) {
status &= ~mask;
}
else {
status |= mask;
}
status = as4630_54te_cpld_write_internal(client, reg, status);
if (unlikely(status < 0)) {
goto exit;
}

mutex_unlock(&data->update_lock);
return count;

exit:
mutex_unlock(&data->update_lock);
return status;
}

static ssize_t set_tx_disable(struct device *dev, struct device_attribute *da,
const char *buf, size_t count)
{
Expand All @@ -338,11 +415,11 @@ static ssize_t set_tx_disable(struct device *dev, struct device_attribute *da,
{
case MODULE_TXDISABLE_49 ... MODULE_TXDISABLE_50:
reg=0x5;
mask=0x1 << (attr->index==MODULE_TXFAULT_49?7:3);
mask=0x1 << (attr->index==MODULE_TXDISABLE_49?7:3);
break;
case MODULE_TXDISABLE_51 ... MODULE_TXDISABLE_52:
reg=0x6;
mask=0x1 << (attr->index==MODULE_TXFAULT_51?7:3);
mask=0x1 << (attr->index==MODULE_TXDISABLE_51?7:3);
break;

default:
Expand All @@ -357,10 +434,10 @@ static ssize_t set_tx_disable(struct device *dev, struct device_attribute *da,
}
/* Update tx_disable status */
if (disable) {
status &= ~mask;
status |= mask;
}
else {
status |= mask;
status &= ~mask;
}
status = as4630_54te_cpld_write_internal(client, reg, status);
if (unlikely(status < 0)) {
Expand Down Expand Up @@ -498,11 +575,11 @@ static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da,

static u8 reg_val_to_direction(u8 reg_val, enum fan_id id)
{
u8 mask = (1 << id);
u8 mask = (1 << (4 + id));

reg_val &= mask;

return reg_val ? 1 : 0;
return reg_val ? 0 : 1;
}

static u8 reg_val_to_is_present(u8 reg_val, enum fan_id id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static struct accton_as4630_54te_led_data *ledctl = NULL;
#define LED_TYPE_POE_REG_MASK (0x2|0x1)
#define LED_MODE_POE_GREEN_VALUE 0x1
#define LED_MODE_POE_AMBER_VALUE 0x2
#define LED_MODE_POE_OFF_VALUE 0x0
#define LED_MODE_POE_OFF_VALUE 0x3

#define LED_TYPE_STK1_REG_MASK 0x20
#define LED_MODE_STK1_GREEN_VALUE 0x0
Expand All @@ -74,20 +74,20 @@ static struct accton_as4630_54te_led_data *ledctl = NULL;
#define LED_MODE_STK2_GREEN_VALUE 0x0
#define LED_MODE_STK2_OFF_VALUE 0x10

#define LED_TYPE_FAN_REG_MASK (0x20|0x10)
#define LED_MODE_FAN_AMBER_VALUE 0x20
#define LED_MODE_FAN_GREEN_VALUE 0x10
#define LED_MODE_FAN_OFF_VALUE (0x0)
#define LED_TYPE_FAN_REG_MASK (0x8|0x4)
#define LED_MODE_FAN_AMBER_VALUE 0x8
#define LED_MODE_FAN_GREEN_VALUE 0x4
#define LED_MODE_FAN_OFF_VALUE (0xC)

#define LED_TYPE_PSU2_REG_MASK (0x8|0x4)
#define LED_MODE_PSU2_AMBER_VALUE 0x8
#define LED_MODE_PSU2_GREEN_VALUE 0x4
#define LED_MODE_PSU2_OFF_VALUE (0x0)
#define LED_TYPE_PSU2_REG_MASK (0x80|0x40)
#define LED_MODE_PSU2_AMBER_VALUE 0x80
#define LED_MODE_PSU2_GREEN_VALUE 0x40
#define LED_MODE_PSU2_OFF_VALUE (0xC0)

#define LED_TYPE_PSU1_REG_MASK (0x2|0x1)
#define LED_MODE_PSU1_AMBER_VALUE 0x2
#define LED_MODE_PSU1_GREEN_VALUE 0x1
#define LED_MODE_PSU1_OFF_VALUE (0x0)
#define LED_MODE_PSU1_OFF_VALUE (0x3)

enum led_type {
LED_TYPE_DIAG,
Expand All @@ -106,8 +106,8 @@ struct led_reg {
};

static const struct led_reg led_reg_map[] = {
{(1<<LED_TYPE_DIAG)| (1<<LED_TYPE_PRI) | (1<<LED_TYPE_PSU2) , 0x30},
{(1<<LED_TYPE_PSU1) | (1<<LED_TYPE_FAN) | (1<<LED_TYPE_POE) |(1<<LED_TYPE_STK1) | (1<<LED_TYPE_STK2) , 0x31},
{(1<<LED_TYPE_DIAG)| (1<<LED_TYPE_PRI) | (1<<LED_TYPE_PSU1) , 0x30},
{(1<<LED_TYPE_PSU2) | (1<<LED_TYPE_FAN) | (1<<LED_TYPE_POE) |(1<<LED_TYPE_STK1) | (1<<LED_TYPE_STK2) , 0x31},
};


Expand Down Expand Up @@ -371,7 +371,7 @@ static void accton_as4630_54te_led_fan_set(struct led_classdev *led_cdev,
static enum led_brightness accton_as4630_54te_led_fan_get(struct led_classdev *cdev)
{
accton_as4630_54te_led_update();
return led_reg_val_to_light_mode(LED_TYPE_FAN, ledctl->reg_val[0]);
return led_reg_val_to_light_mode(LED_TYPE_FAN, ledctl->reg_val[1]);
}

static void accton_as4630_54te_led_psu1_set(struct led_classdev *led_cdev,
Expand All @@ -395,7 +395,7 @@ static void accton_as4630_54te_led_psu2_set(struct led_classdev *led_cdev,
static enum led_brightness accton_as4630_54te_led_psu2_get(struct led_classdev *cdev)
{
accton_as4630_54te_led_update();
return led_reg_val_to_light_mode(LED_TYPE_PSU2, ledctl->reg_val[0]);
return led_reg_val_to_light_mode(LED_TYPE_PSU2, ledctl->reg_val[1]);
}

static struct led_classdev accton_as4630_54te_leds[] = {
Expand All @@ -405,7 +405,7 @@ static struct led_classdev accton_as4630_54te_leds[] = {
.brightness_set = accton_as4630_54te_led_diag_set,
.brightness_get = accton_as4630_54te_led_diag_get,
.flags = LED_CORE_SUSPENDRESUME,
.max_brightness = LED_MODE_GREEN,
.max_brightness = LED_MODE_GREEN_BLINK,
},
[LED_TYPE_PRI] = {
.name = "pri",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ static struct as4630_54te_psu_data *as4630_54te_psu_update_device(struct device
/* Read model name */
memset(data->model_name, 0, sizeof(data->model_name));
memset(data->serial_number, 0, sizeof(data->serial_number));
power_good = (data->status >> (3-data->index) & 0x1);
power_good = (data->status >> (data->index==0? 6:2)) & 0x1;

if (power_good) {
status = as4630_54te_psu_read_block(client, 0x20, data->model_name,
Expand Down