mirror of
https://github.com/Telecominfraproject/OpenNetworkLinux.git
synced 2025-12-25 17:27:01 +00:00
Add suport as9716-32d onlp
This commit is contained in:
580
packages/base/any/kernels/modules/accton_i2c_psu.c
Executable file
580
packages/base/any/kernels/modules/accton_i2c_psu.c
Executable file
@@ -0,0 +1,580 @@
|
||||
/*
|
||||
* An hwmon driver for the Accton Redundant Power Module
|
||||
*
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/jiffies.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/hwmon.h>
|
||||
#include <linux/hwmon-sysfs.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/sysfs.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/delay.h>
|
||||
|
||||
#define DRIVER_DESCRIPTION_NAME "accton i2c psu driver"
|
||||
/* PMBus Protocol. */
|
||||
#define PMBUS_LITERAL_DATA_MULTIPLIER 1000
|
||||
#define PMBUS_REGISTER_VOUT_MODE 0x20
|
||||
#define PMBUS_REGISTER_STATUS_BYTE 0x78
|
||||
#define PMBUS_REGISTER_STATUS_WORD 0x79
|
||||
#define PMBUS_REGISTER_STATUS_FAN 0x81
|
||||
#define PMBUS_REGISTER_READ_VIN 0x88
|
||||
#define PMBUS_REGISTER_READ_IIN 0x89
|
||||
#define PMBUS_REGISTER_READ_VOUT 0x8B
|
||||
#define PMBUS_REGISTER_READ_IOUT 0x8C
|
||||
#define PMBUS_REGISTER_READ_TEMPERATURE_1 0x8D
|
||||
#define PMBUS_REGISTER_READ_TEMPERATURE_2 0x8E
|
||||
#define PMBUS_REGISTER_READ_TEMPERATURE_3 0x8F
|
||||
#define PMBUS_REGISTER_READ_FAN_SPEED_1 0x90
|
||||
#define PMBUS_REGISTER_READ_FAN_SPEED_2 0x91
|
||||
|
||||
#define PMBUS_REGISTER_READ_FAN_CONFIG_1 0x3A
|
||||
#define PMBUS_REGISTER_FAN_COMMAND_1 0x3B
|
||||
|
||||
#define PMBUS_REGISTER_READ_POUT 0x96
|
||||
#define PMBUS_REGISTER_READ_PIN 0x97
|
||||
#define PMBUS_REGISTER_MFR_ID 0x99
|
||||
#define PMBUS_REGISTER_MFR_MODEL 0x9A
|
||||
#define PMBUS_REGISTER_MFR_REVISION 0x9B
|
||||
#define PMBUS_REGISTER_MFR_SERIAL 0x9E
|
||||
|
||||
|
||||
#define MAX_FAN_DUTY_CYCLE 100
|
||||
#define I2C_RW_RETRY_COUNT 10
|
||||
#define I2C_RW_RETRY_INTERVAL 60 /* ms */
|
||||
|
||||
/* Addresses scanned
|
||||
*/
|
||||
static const unsigned short normal_i2c[] = { I2C_CLIENT_END };
|
||||
|
||||
/* Each client has this additional data
|
||||
*/
|
||||
struct accton_i2c_psu_data {
|
||||
struct device *hwmon_dev;
|
||||
struct mutex update_lock;
|
||||
char valid; /* !=0 if registers are valid */
|
||||
unsigned long last_updated; /* In jiffies */
|
||||
u8 vout_mode; /* Register value */
|
||||
u16 v_in; /* Register value */
|
||||
u16 v_out; /* Register value */
|
||||
u16 i_in; /* Register value */
|
||||
u16 i_out; /* Register value */
|
||||
u16 p_in; /* Register value */
|
||||
u16 p_out; /* Register value */
|
||||
u16 temp_input[2]; /* Register value */
|
||||
u8 fan_fault; /* Register value */
|
||||
u16 fan_duty_cycle[2]; /* Register value */
|
||||
u16 fan_speed[2]; /* Register value */
|
||||
u8 pmbus_revision; /* Register value */
|
||||
u8 mfr_id[10]; /* Register value */
|
||||
u8 mfr_model[16]; /* Register value */
|
||||
u8 mfr_revsion[3]; /* Register value */
|
||||
u8 mfr_serial[26]; /* Register value */
|
||||
};
|
||||
|
||||
static ssize_t show_linear(struct device *dev, struct device_attribute *da, char *buf);
|
||||
static ssize_t show_fan_fault(struct device *dev, struct device_attribute *da, char *buf);
|
||||
static ssize_t show_vout(struct device *dev, struct device_attribute *da, char *buf);
|
||||
static ssize_t set_fan_duty_cycle(struct device *dev, struct device_attribute *da, const char *buf, size_t count);
|
||||
static ssize_t show_ascii(struct device *dev, struct device_attribute *da,
|
||||
char *buf);
|
||||
static ssize_t show_byte(struct device *dev, struct device_attribute *da,
|
||||
char *buf);
|
||||
|
||||
static int accton_i2c_psu_write_word(struct i2c_client *client, u8 reg, u16 value);
|
||||
static struct accton_i2c_psu_data *accton_i2c_psu_update_device(struct device *dev);
|
||||
|
||||
enum accton_i2c_psu_sysfs_attributes {
|
||||
PSU_V_IN,
|
||||
PSU_V_OUT,
|
||||
PSU_I_IN,
|
||||
PSU_I_OUT,
|
||||
PSU_P_IN,
|
||||
PSU_P_OUT,
|
||||
PSU_TEMP1_INPUT,
|
||||
PSU_FAN1_FAULT,
|
||||
PSU_FAN1_DUTY_CYCLE,
|
||||
PSU_FAN1_SPEED,
|
||||
PSU_PMBUS_REVISION,
|
||||
PSU_MFR_ID,
|
||||
PSU_MFR_MODEL,
|
||||
PSU_MFR_REVISION,
|
||||
PSU_MFR_SERIAL,
|
||||
};
|
||||
|
||||
/* sysfs attributes for hwmon
|
||||
*/
|
||||
static SENSOR_DEVICE_ATTR(psu_v_in, S_IRUGO, show_linear, NULL, PSU_V_IN);
|
||||
static SENSOR_DEVICE_ATTR(psu_v_out, S_IRUGO, show_vout, NULL, PSU_V_OUT);
|
||||
static SENSOR_DEVICE_ATTR(psu_i_in, S_IRUGO, show_linear, NULL, PSU_I_IN);
|
||||
static SENSOR_DEVICE_ATTR(psu_i_out, S_IRUGO, show_linear, NULL, PSU_I_OUT);
|
||||
static SENSOR_DEVICE_ATTR(psu_p_in, S_IRUGO, show_linear, NULL, PSU_P_IN);
|
||||
static SENSOR_DEVICE_ATTR(psu_p_out, S_IRUGO, show_linear, NULL, PSU_P_OUT);
|
||||
static SENSOR_DEVICE_ATTR(psu_temp1_input, S_IRUGO, show_linear, NULL, PSU_TEMP1_INPUT);
|
||||
static SENSOR_DEVICE_ATTR(psu_fan1_fault, S_IRUGO, show_fan_fault, NULL, PSU_FAN1_FAULT);
|
||||
static SENSOR_DEVICE_ATTR(psu_fan1_duty_cycle_percentage, S_IWUSR | S_IRUGO, show_linear, set_fan_duty_cycle, PSU_FAN1_DUTY_CYCLE);
|
||||
static SENSOR_DEVICE_ATTR(psu_fan1_speed_rpm, S_IRUGO, show_linear, NULL, PSU_FAN1_SPEED);
|
||||
static SENSOR_DEVICE_ATTR(psu_pmbus_revision,S_IRUGO, show_byte, NULL, PSU_PMBUS_REVISION);
|
||||
static SENSOR_DEVICE_ATTR(psu_mfr_id, S_IRUGO, show_ascii, NULL, PSU_MFR_ID);
|
||||
static SENSOR_DEVICE_ATTR(psu_mfr_model, S_IRUGO, show_ascii, NULL, PSU_MFR_MODEL);
|
||||
static SENSOR_DEVICE_ATTR(psu_mfr_revision, S_IRUGO, show_ascii, NULL, PSU_MFR_REVISION);
|
||||
static SENSOR_DEVICE_ATTR(psu_mfr_serial, S_IRUGO, show_ascii, NULL, PSU_MFR_SERIAL);
|
||||
|
||||
static struct attribute *accton_i2c_psu_attributes[] = {
|
||||
&sensor_dev_attr_psu_v_in.dev_attr.attr,
|
||||
&sensor_dev_attr_psu_v_out.dev_attr.attr,
|
||||
&sensor_dev_attr_psu_i_in.dev_attr.attr,
|
||||
&sensor_dev_attr_psu_i_out.dev_attr.attr,
|
||||
&sensor_dev_attr_psu_p_in.dev_attr.attr,
|
||||
&sensor_dev_attr_psu_p_out.dev_attr.attr,
|
||||
&sensor_dev_attr_psu_temp1_input.dev_attr.attr,
|
||||
&sensor_dev_attr_psu_fan1_fault.dev_attr.attr,
|
||||
&sensor_dev_attr_psu_fan1_duty_cycle_percentage.dev_attr.attr,
|
||||
&sensor_dev_attr_psu_fan1_speed_rpm.dev_attr.attr,
|
||||
&sensor_dev_attr_psu_pmbus_revision.dev_attr.attr,
|
||||
&sensor_dev_attr_psu_mfr_id.dev_attr.attr,
|
||||
&sensor_dev_attr_psu_mfr_model.dev_attr.attr,
|
||||
&sensor_dev_attr_psu_mfr_revision.dev_attr.attr,
|
||||
&sensor_dev_attr_psu_mfr_serial.dev_attr.attr,
|
||||
NULL
|
||||
};
|
||||
|
||||
static int two_complement_to_int(u16 data, u8 valid_bit, int mask)
|
||||
{
|
||||
u16 valid_data = data & mask;
|
||||
bool is_negative = valid_data >> (valid_bit - 1);
|
||||
|
||||
return is_negative ? (-(((~valid_data) & mask) + 1)) : valid_data;
|
||||
}
|
||||
|
||||
static ssize_t set_fan_duty_cycle(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 accton_i2c_psu_data *data = i2c_get_clientdata(client);
|
||||
int nr = (attr->index == PSU_FAN1_DUTY_CYCLE) ? 0 : 1;
|
||||
long speed;
|
||||
int error;
|
||||
|
||||
error = kstrtol(buf, 10, &speed);
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
if (speed < 0 || speed > MAX_FAN_DUTY_CYCLE)
|
||||
return -EINVAL;
|
||||
|
||||
mutex_lock(&data->update_lock);
|
||||
data->fan_duty_cycle[nr] = speed;
|
||||
accton_i2c_psu_write_word(client, PMBUS_REGISTER_FAN_COMMAND_1 + nr, data->fan_duty_cycle[nr]);
|
||||
mutex_unlock(&data->update_lock);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static ssize_t show_linear(struct device *dev, struct device_attribute *da,
|
||||
char *buf)
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||
struct accton_i2c_psu_data *data = accton_i2c_psu_update_device(dev);
|
||||
|
||||
u16 value = 0;
|
||||
int exponent, mantissa;
|
||||
int multiplier = 0;
|
||||
|
||||
switch (attr->index) {
|
||||
case PSU_V_IN:
|
||||
value = data->v_in;
|
||||
break;
|
||||
case PSU_I_IN:
|
||||
value = data->i_in;
|
||||
break;
|
||||
case PSU_I_OUT:
|
||||
value = data->i_out;
|
||||
break;
|
||||
case PSU_P_IN:
|
||||
value = data->p_in;
|
||||
break;
|
||||
case PSU_P_OUT:
|
||||
value = data->p_out;
|
||||
break;
|
||||
case PSU_TEMP1_INPUT:
|
||||
value = data->temp_input[0];
|
||||
break;
|
||||
case PSU_FAN1_DUTY_CYCLE:
|
||||
multiplier = 1;
|
||||
value = data->fan_duty_cycle[0];
|
||||
break;
|
||||
case PSU_FAN1_SPEED:
|
||||
multiplier = 1;
|
||||
value = data->fan_speed[0];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
exponent = two_complement_to_int(value >> 11, 5, 0x1f);
|
||||
mantissa = two_complement_to_int(value & 0x7ff, 11, 0x7ff);
|
||||
|
||||
if(!multiplier)
|
||||
multiplier = PMBUS_LITERAL_DATA_MULTIPLIER;
|
||||
|
||||
|
||||
return (exponent >= 0) ? sprintf(buf, "%d\n", (mantissa << exponent) * multiplier) :
|
||||
sprintf(buf, "%d\n", (mantissa * multiplier) / (1 << -exponent));
|
||||
}
|
||||
|
||||
static ssize_t show_fan_fault(struct device *dev, struct device_attribute *da,
|
||||
char *buf)
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||
struct accton_i2c_psu_data *data = accton_i2c_psu_update_device(dev);
|
||||
|
||||
u8 shift = (attr->index == PSU_FAN1_FAULT) ? 7 : 6;
|
||||
|
||||
return sprintf(buf, "%d\n", data->fan_fault >> shift);
|
||||
}
|
||||
|
||||
static ssize_t show_vout(struct device *dev, struct device_attribute *da,
|
||||
char *buf)
|
||||
{
|
||||
struct accton_i2c_psu_data *data = accton_i2c_psu_update_device(dev);
|
||||
int exponent, mantissa;
|
||||
|
||||
exponent = two_complement_to_int(data->vout_mode, 5, 0x1f);
|
||||
mantissa = data->v_out;
|
||||
|
||||
return (exponent > 0) ? sprintf(buf, "%d\n", (mantissa << exponent) * PMBUS_LITERAL_DATA_MULTIPLIER) :
|
||||
sprintf(buf, "%d\n", (mantissa * PMBUS_LITERAL_DATA_MULTIPLIER) / (1 << -exponent));
|
||||
}
|
||||
|
||||
static ssize_t show_byte(struct device *dev, struct device_attribute *da,
|
||||
char *buf)
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||
struct accton_i2c_psu_data *data = accton_i2c_psu_update_device(dev);
|
||||
|
||||
if (!data->valid) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (attr->index == PSU_PMBUS_REVISION) ? sprintf(buf, "%d\n", data->pmbus_revision) :
|
||||
sprintf(buf, "0\n");
|
||||
}
|
||||
|
||||
static ssize_t show_ascii(struct device *dev, struct device_attribute *da,
|
||||
char *buf)
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||
struct accton_i2c_psu_data *data = accton_i2c_psu_update_device(dev);
|
||||
u8 *ptr = NULL;
|
||||
|
||||
if (!data->valid) {
|
||||
return 0;
|
||||
}
|
||||
switch (attr->index) {
|
||||
|
||||
case PSU_MFR_ID:
|
||||
ptr = data->mfr_id;
|
||||
break;
|
||||
case PSU_MFR_MODEL:
|
||||
ptr = data->mfr_model;
|
||||
break;
|
||||
case PSU_MFR_REVISION:
|
||||
ptr = data->mfr_revsion;
|
||||
break;
|
||||
case PSU_MFR_SERIAL:
|
||||
ptr = data->mfr_serial;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return sprintf(buf, "%s\n", ptr);
|
||||
}
|
||||
|
||||
|
||||
static const struct attribute_group accton_i2c_psu_group = {
|
||||
.attrs = accton_i2c_psu_attributes,
|
||||
};
|
||||
|
||||
static int accton_i2c_psu_probe(struct i2c_client *client,
|
||||
const struct i2c_device_id *dev_id)
|
||||
{
|
||||
struct accton_i2c_psu_data *data;
|
||||
int status;
|
||||
|
||||
if (!i2c_check_functionality(client->adapter,
|
||||
I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA)) {
|
||||
status = -EIO;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
data = kzalloc(sizeof(struct accton_i2c_psu_data), GFP_KERNEL);
|
||||
if (!data) {
|
||||
status = -ENOMEM;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
i2c_set_clientdata(client, data);
|
||||
data->valid = 0;
|
||||
mutex_init(&data->update_lock);
|
||||
|
||||
dev_info(&client->dev, "chip found\n");
|
||||
|
||||
/* Register sysfs hooks */
|
||||
status = sysfs_create_group(&client->dev.kobj, &accton_i2c_psu_group);
|
||||
if (status) {
|
||||
goto exit_free;
|
||||
}
|
||||
|
||||
data->hwmon_dev = hwmon_device_register(&client->dev);
|
||||
if (IS_ERR(data->hwmon_dev)) {
|
||||
status = PTR_ERR(data->hwmon_dev);
|
||||
goto exit_remove;
|
||||
}
|
||||
|
||||
dev_info(&client->dev, "%s: psu '%s'\n",
|
||||
dev_name(data->hwmon_dev), client->name);
|
||||
|
||||
return 0;
|
||||
|
||||
exit_remove:
|
||||
sysfs_remove_group(&client->dev.kobj, &accton_i2c_psu_group);
|
||||
exit_free:
|
||||
kfree(data);
|
||||
exit:
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static int accton_i2c_psu_remove(struct i2c_client *client)
|
||||
{
|
||||
struct accton_i2c_psu_data *data = i2c_get_clientdata(client);
|
||||
|
||||
hwmon_device_unregister(data->hwmon_dev);
|
||||
sysfs_remove_group(&client->dev.kobj, &accton_i2c_psu_group);
|
||||
kfree(data);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* Support psu moduel
|
||||
*/
|
||||
static const struct i2c_device_id accton_i2c_psu_id[] = {
|
||||
{ "acbel_fsh082", 0 },
|
||||
{}
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, accton_i2c_psu_id);
|
||||
|
||||
static struct i2c_driver accton_i2c_psu_driver = {
|
||||
.class = I2C_CLASS_HWMON,
|
||||
.driver = {
|
||||
.name = "accton_i2c_psu",
|
||||
},
|
||||
.probe = accton_i2c_psu_probe,
|
||||
.remove = accton_i2c_psu_remove,
|
||||
.id_table = accton_i2c_psu_id,
|
||||
.address_list = normal_i2c,
|
||||
};
|
||||
|
||||
static int accton_i2c_psu_read_byte(struct i2c_client *client, u8 reg)
|
||||
{
|
||||
return i2c_smbus_read_byte_data(client, reg);
|
||||
}
|
||||
|
||||
static int accton_i2c_psu_read_word(struct i2c_client *client, u8 reg)
|
||||
{
|
||||
return i2c_smbus_read_word_data(client, reg);
|
||||
}
|
||||
|
||||
static int accton_i2c_psu_write_word(struct i2c_client *client, u8 reg, u16 value)
|
||||
{
|
||||
return i2c_smbus_write_word_data(client, reg, value);
|
||||
}
|
||||
|
||||
static int accton_i2c_psu_read_block(struct i2c_client *client, u8 command, u8 *data,
|
||||
int data_len)
|
||||
{
|
||||
int status = 0, retry = I2C_RW_RETRY_COUNT;
|
||||
|
||||
while (retry) {
|
||||
status = i2c_smbus_read_i2c_block_data(client, command, data_len, data);
|
||||
if (unlikely(status < 0)) {
|
||||
msleep(I2C_RW_RETRY_INTERVAL);
|
||||
retry--;
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
static int accton_i2c_psu_read_block_data(struct i2c_client *client, u8 command, u8 *data, int data_length)
|
||||
{
|
||||
int status = -EIO;
|
||||
int length;
|
||||
u8 buffer[128] = {0}, *ptr = buffer;
|
||||
|
||||
status = accton_i2c_psu_read_byte(client, command);
|
||||
if (status < 0)
|
||||
{
|
||||
dev_dbg(&client->dev, "Unable to get data from offset 0x%02X\r\n", command);
|
||||
status = -EIO;
|
||||
goto EXIT_READ_BLOCK_DATA;
|
||||
}
|
||||
|
||||
status = (status & 0xFF) + 1;
|
||||
if ( status > 128)
|
||||
{
|
||||
dev_dbg(&client->dev, "Unable to get big data from offset 0x%02X\r\n", command);
|
||||
status = -EINVAL;
|
||||
goto EXIT_READ_BLOCK_DATA;
|
||||
}
|
||||
|
||||
length = status;
|
||||
status = accton_i2c_psu_read_block(client, command, buffer, length);
|
||||
if (unlikely(status < 0))
|
||||
goto EXIT_READ_BLOCK_DATA;
|
||||
if (unlikely(status != length)) {
|
||||
status = -EIO;
|
||||
goto EXIT_READ_BLOCK_DATA;
|
||||
}
|
||||
/* The first byte is the count byte of string. */
|
||||
ptr++;
|
||||
status--;
|
||||
|
||||
length=status>(data_length-1)?(data_length-1):status;
|
||||
memcpy(data, ptr, length);
|
||||
data[length-1] = 0;
|
||||
|
||||
EXIT_READ_BLOCK_DATA:
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
struct reg_data_byte {
|
||||
u8 reg;
|
||||
u8 *value;
|
||||
};
|
||||
|
||||
struct reg_data_word {
|
||||
u8 reg;
|
||||
u16 *value;
|
||||
};
|
||||
|
||||
static struct accton_i2c_psu_data *accton_i2c_psu_update_device(struct device *dev)
|
||||
{
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct accton_i2c_psu_data *data = i2c_get_clientdata(client);
|
||||
|
||||
mutex_lock(&data->update_lock);
|
||||
|
||||
if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
|
||||
|| !data->valid) {
|
||||
int i, status, length;
|
||||
u8 command, buf;
|
||||
struct reg_data_byte regs_byte[] = { {PMBUS_REGISTER_VOUT_MODE, &data->vout_mode},
|
||||
{PMBUS_REGISTER_STATUS_FAN, &data->fan_fault}};
|
||||
struct reg_data_word regs_word[] = { {PMBUS_REGISTER_READ_VIN, &data->v_in},
|
||||
{PMBUS_REGISTER_READ_VOUT, &data->v_out},
|
||||
{PMBUS_REGISTER_READ_IIN, &data->i_in},
|
||||
{PMBUS_REGISTER_READ_IOUT, &data->i_out},
|
||||
{PMBUS_REGISTER_READ_POUT, &data->p_out},
|
||||
{PMBUS_REGISTER_READ_PIN, &data->p_in},
|
||||
{PMBUS_REGISTER_READ_TEMPERATURE_1, &(data->temp_input[0])},
|
||||
{PMBUS_REGISTER_READ_TEMPERATURE_2, &(data->temp_input[1])},
|
||||
{PMBUS_REGISTER_FAN_COMMAND_1, &(data->fan_duty_cycle[0])},
|
||||
{PMBUS_REGISTER_READ_FAN_SPEED_1, &(data->fan_speed[0])},
|
||||
{PMBUS_REGISTER_READ_FAN_SPEED_2, &(data->fan_speed[1])},
|
||||
};
|
||||
|
||||
dev_dbg(&client->dev, "Starting accton_i2c_psu update\n");
|
||||
|
||||
/* Read byte data */
|
||||
for (i = 0; i < ARRAY_SIZE(regs_byte); i++) {
|
||||
status = accton_i2c_psu_read_byte(client, regs_byte[i].reg);
|
||||
|
||||
if (status < 0) {
|
||||
dev_dbg(&client->dev, "reg %d, err %d\n",
|
||||
regs_byte[i].reg, status);
|
||||
}
|
||||
else {
|
||||
*(regs_byte[i].value) = status;
|
||||
}
|
||||
}
|
||||
|
||||
/* Read word data */
|
||||
for (i = 0; i < ARRAY_SIZE(regs_word); i++) {
|
||||
status = accton_i2c_psu_read_word(client, regs_word[i].reg);
|
||||
|
||||
if (status < 0) {
|
||||
dev_dbg(&client->dev, "reg %d, err %d\n",
|
||||
regs_word[i].reg, status);
|
||||
}
|
||||
else {
|
||||
*(regs_word[i].value) = status;
|
||||
}
|
||||
|
||||
}
|
||||
/* Read mfr_id */
|
||||
status = accton_i2c_psu_read_block_data(client, PMBUS_REGISTER_MFR_ID, data->mfr_id,
|
||||
ARRAY_SIZE(data->mfr_id));
|
||||
if (status < 0) {
|
||||
dev_dbg(&client->dev, "reg %d, err %d\n", PMBUS_REGISTER_MFR_ID, status);
|
||||
goto exit;
|
||||
}
|
||||
/* Read mfr_model */
|
||||
status = accton_i2c_psu_read_block_data(client, PMBUS_REGISTER_MFR_MODEL, data->mfr_model,
|
||||
ARRAY_SIZE(data->mfr_model));
|
||||
if (status < 0) {
|
||||
dev_dbg(&client->dev, "reg %d, err %d\n", PMBUS_REGISTER_MFR_MODEL, status);
|
||||
goto exit;
|
||||
}
|
||||
/* Read mfr_revsion */
|
||||
status = accton_i2c_psu_read_block_data(client, PMBUS_REGISTER_MFR_REVISION, data->mfr_revsion,
|
||||
ARRAY_SIZE(data->mfr_revsion));
|
||||
if (status < 0) {
|
||||
dev_dbg(&client->dev, "reg %d, err %d\n", PMBUS_REGISTER_MFR_REVISION, status);
|
||||
goto exit;
|
||||
}
|
||||
/* Read mfr_serial */
|
||||
status = accton_i2c_psu_read_block_data(client, PMBUS_REGISTER_MFR_SERIAL, data->mfr_serial,
|
||||
ARRAY_SIZE(data->mfr_serial));
|
||||
if (status < 0) {
|
||||
dev_dbg(&client->dev, "reg %d, err %d\n", PMBUS_REGISTER_MFR_SERIAL, status);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
data->last_updated = jiffies;
|
||||
data->valid = 1;
|
||||
}
|
||||
|
||||
exit:
|
||||
mutex_unlock(&data->update_lock);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
static int __init accton_i2c_psu_init(void)
|
||||
{
|
||||
return i2c_add_driver(&accton_i2c_psu_driver);
|
||||
}
|
||||
|
||||
static void __exit accton_i2c_psu_exit(void)
|
||||
{
|
||||
i2c_del_driver(&accton_i2c_psu_driver);
|
||||
}
|
||||
|
||||
MODULE_AUTHOR("Jostar Yang <jostar_yang@accton.com.tw>");
|
||||
MODULE_DESCRIPTION(DRIVER_DESCRIPTION_NAME);
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
module_init(accton_i2c_psu_init);
|
||||
module_exit(accton_i2c_psu_exit);
|
||||
3
packages/platforms/accton/x86-64/x86-64-accton-as9716_32d/.gitignore
vendored
Executable file
3
packages/platforms/accton/x86-64/x86-64-accton-as9716_32d/.gitignore
vendored
Executable file
@@ -0,0 +1,3 @@
|
||||
*x86*64*accton*as7816*64x*.mk
|
||||
onlpdump.mk
|
||||
|
||||
1
packages/platforms/accton/x86-64/x86-64-accton-as9716_32d/Makefile
Executable file
1
packages/platforms/accton/x86-64/x86-64-accton-as9716_32d/Makefile
Executable file
@@ -0,0 +1 @@
|
||||
include $(ONL)/make/pkg.mk
|
||||
@@ -0,0 +1 @@
|
||||
include $(ONL)/make/pkg.mk
|
||||
@@ -0,0 +1 @@
|
||||
!include $ONL_TEMPLATES/platform-modules.yml VENDOR=accton BASENAME=x86-64-accton-as9716-32d ARCH=amd64 KERNELS="onl-kernel-4.14-lts-x86-64-all:amd64"
|
||||
1
packages/platforms/accton/x86-64/x86-64-accton-as9716_32d/modules/builds/.gitignore
vendored
Executable file
1
packages/platforms/accton/x86-64/x86-64-accton-as9716_32d/modules/builds/.gitignore
vendored
Executable file
@@ -0,0 +1 @@
|
||||
lib
|
||||
@@ -0,0 +1,6 @@
|
||||
KERNELS := onl-kernel-4.14-lts-x86-64-all:amd64
|
||||
KMODULES := $(wildcard *.c)
|
||||
VENDOR := accton
|
||||
BASENAME := x86-64-accton-as9716-32d
|
||||
ARCH := x86_64
|
||||
include $(ONL)/make/kmodule.mk
|
||||
@@ -0,0 +1,679 @@
|
||||
/*
|
||||
* Copyright (C) Brandon Chuang <brandon_chuang@accton.com.tw>
|
||||
*
|
||||
* This module supports the accton cpld that hold the channel select
|
||||
* mechanism for other i2c slave devices, such as SFP.
|
||||
* This includes the:
|
||||
* Accton as9716_32d CPLD1/CPLD2/CPLD3
|
||||
*
|
||||
* Based on:
|
||||
* pca954x.c from Kumar Gala <galak@kernel.crashing.org>
|
||||
* Copyright (C) 2006
|
||||
*
|
||||
* Based on:
|
||||
* pca954x.c from Ken Harrenstien
|
||||
* Copyright (C) 2004 Google, Inc. (Ken Harrenstien)
|
||||
*
|
||||
* Based on:
|
||||
* i2c-virtual_cb.c from Brian Kuschak <bkuschak@yahoo.com>
|
||||
* and
|
||||
* pca9540.c from Jean Delvare <khali@linux-fr.org>.
|
||||
*
|
||||
* This file is licensed under the terms of the GNU General Public
|
||||
* License version 2. This program is licensed "as is" without any
|
||||
* warranty of any kind, whether express or implied.
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/version.h>
|
||||
#include <linux/stat.h>
|
||||
#include <linux/hwmon-sysfs.h>
|
||||
#include <linux/delay.h>
|
||||
|
||||
#define I2C_RW_RETRY_COUNT 10
|
||||
#define I2C_RW_RETRY_INTERVAL 60 /* ms */
|
||||
|
||||
static LIST_HEAD(cpld_client_list);
|
||||
static struct mutex list_lock;
|
||||
|
||||
struct cpld_client_node {
|
||||
struct i2c_client *client;
|
||||
struct list_head list;
|
||||
};
|
||||
|
||||
enum cpld_type {
|
||||
as9716_32d_fpga,
|
||||
as9716_32d_cpld1,
|
||||
as9716_32d_cpld2,
|
||||
as9716_32d_cpld_cpu
|
||||
};
|
||||
|
||||
struct as9716_32d_cpld_data {
|
||||
enum cpld_type type;
|
||||
struct device *hwmon_dev;
|
||||
struct mutex update_lock;
|
||||
};
|
||||
|
||||
static const struct i2c_device_id as9716_32d_cpld_id[] = {
|
||||
{ "as9716_32d_fpga", as9716_32d_fpga },
|
||||
{ "as9716_32d_cpld1", as9716_32d_cpld1 },
|
||||
{ "as9716_32d_cpld2", as9716_32d_cpld2 },
|
||||
{ "as9716_32d_cpld_cpu", as9716_32d_cpld_cpu },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, as9716_32d_cpld_id);
|
||||
|
||||
#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
|
||||
#define TRANSCEIVER_TXFAULT_ATTR_ID(index) MODULE_TXFAULT_##index
|
||||
|
||||
enum as9716_32d_cpld_sysfs_attributes {
|
||||
CPLD_VERSION,
|
||||
ACCESS,
|
||||
/* transceiver attributes */
|
||||
TRANSCEIVER_PRESENT_ATTR_ID(1),
|
||||
TRANSCEIVER_PRESENT_ATTR_ID(2),
|
||||
TRANSCEIVER_PRESENT_ATTR_ID(3),
|
||||
TRANSCEIVER_PRESENT_ATTR_ID(4),
|
||||
TRANSCEIVER_PRESENT_ATTR_ID(5),
|
||||
TRANSCEIVER_PRESENT_ATTR_ID(6),
|
||||
TRANSCEIVER_PRESENT_ATTR_ID(7),
|
||||
TRANSCEIVER_PRESENT_ATTR_ID(8),
|
||||
TRANSCEIVER_PRESENT_ATTR_ID(9),
|
||||
TRANSCEIVER_PRESENT_ATTR_ID(10),
|
||||
TRANSCEIVER_PRESENT_ATTR_ID(11),
|
||||
TRANSCEIVER_PRESENT_ATTR_ID(12),
|
||||
TRANSCEIVER_PRESENT_ATTR_ID(13),
|
||||
TRANSCEIVER_PRESENT_ATTR_ID(14),
|
||||
TRANSCEIVER_PRESENT_ATTR_ID(15),
|
||||
TRANSCEIVER_PRESENT_ATTR_ID(16),
|
||||
TRANSCEIVER_PRESENT_ATTR_ID(17),
|
||||
TRANSCEIVER_PRESENT_ATTR_ID(18),
|
||||
TRANSCEIVER_PRESENT_ATTR_ID(19),
|
||||
TRANSCEIVER_PRESENT_ATTR_ID(20),
|
||||
TRANSCEIVER_PRESENT_ATTR_ID(21),
|
||||
TRANSCEIVER_PRESENT_ATTR_ID(22),
|
||||
TRANSCEIVER_PRESENT_ATTR_ID(23),
|
||||
TRANSCEIVER_PRESENT_ATTR_ID(24),
|
||||
TRANSCEIVER_PRESENT_ATTR_ID(25),
|
||||
TRANSCEIVER_PRESENT_ATTR_ID(26),
|
||||
TRANSCEIVER_PRESENT_ATTR_ID(27),
|
||||
TRANSCEIVER_PRESENT_ATTR_ID(28),
|
||||
TRANSCEIVER_PRESENT_ATTR_ID(29),
|
||||
TRANSCEIVER_PRESENT_ATTR_ID(30),
|
||||
TRANSCEIVER_PRESENT_ATTR_ID(31),
|
||||
TRANSCEIVER_PRESENT_ATTR_ID(32),
|
||||
TRANSCEIVER_PRESENT_ATTR_ID(33),
|
||||
TRANSCEIVER_PRESENT_ATTR_ID(34),
|
||||
TRANSCEIVER_TXDISABLE_ATTR_ID(33),
|
||||
TRANSCEIVER_TXDISABLE_ATTR_ID(34),
|
||||
TRANSCEIVER_RXLOS_ATTR_ID(33),
|
||||
TRANSCEIVER_RXLOS_ATTR_ID(34),
|
||||
TRANSCEIVER_TXFAULT_ATTR_ID(33),
|
||||
TRANSCEIVER_TXFAULT_ATTR_ID(34)
|
||||
};
|
||||
|
||||
/* sysfs attributes for hwmon
|
||||
*/
|
||||
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 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,
|
||||
char *buf);
|
||||
static int as9716_32d_cpld_read_internal(struct i2c_client *client, u8 reg);
|
||||
static int as9716_32d_cpld_write_internal(struct i2c_client *client, u8 reg, u8 value);
|
||||
|
||||
/* transceiver attributes */
|
||||
#define DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(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
|
||||
|
||||
#define DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(index) \
|
||||
static SENSOR_DEVICE_ATTR(module_tx_disable_##index, S_IRUGO | S_IWUSR, show_status, set_tx_disable, MODULE_TXDISABLE_##index); \
|
||||
static SENSOR_DEVICE_ATTR(module_rx_los_##index, S_IRUGO, show_status, NULL, MODULE_RXLOS_##index); \
|
||||
static SENSOR_DEVICE_ATTR(module_tx_fault_##index, S_IRUGO, show_status, NULL, MODULE_RXLOS_##index);
|
||||
|
||||
#define DECLARE_SFP_TRANSCEIVER_ATTR(index) \
|
||||
&sensor_dev_attr_module_tx_disable_##index.dev_attr.attr, \
|
||||
&sensor_dev_attr_module_rx_los_##index.dev_attr.attr, \
|
||||
&sensor_dev_attr_module_tx_fault_##index.dev_attr.attr
|
||||
|
||||
|
||||
static SENSOR_DEVICE_ATTR(version, S_IRUGO, show_version, NULL, CPLD_VERSION);
|
||||
static SENSOR_DEVICE_ATTR(access, S_IWUSR, NULL, access, ACCESS);
|
||||
/* transceiver attributes */
|
||||
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(1);
|
||||
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(2);
|
||||
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(3);
|
||||
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(4);
|
||||
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(5);
|
||||
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(6);
|
||||
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(7);
|
||||
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(8);
|
||||
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(9);
|
||||
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(10);
|
||||
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(11);
|
||||
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(12);
|
||||
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(13);
|
||||
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(14);
|
||||
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(15);
|
||||
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(16);
|
||||
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(17);
|
||||
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(18);
|
||||
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(19);
|
||||
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(20);
|
||||
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(21);
|
||||
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(22);
|
||||
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(23);
|
||||
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(24);
|
||||
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(25);
|
||||
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(26);
|
||||
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(27);
|
||||
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(28);
|
||||
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(29);
|
||||
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(30);
|
||||
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(31);
|
||||
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(32);
|
||||
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(33);
|
||||
DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(34);
|
||||
DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(33);
|
||||
DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(34);
|
||||
|
||||
|
||||
static struct attribute *as9716_32d_fpga_attributes[] = {
|
||||
&sensor_dev_attr_version.dev_attr.attr,
|
||||
&sensor_dev_attr_access.dev_attr.attr,
|
||||
NULL
|
||||
};
|
||||
|
||||
static const struct attribute_group as9716_32d_fpga_group = {
|
||||
.attrs = as9716_32d_fpga_attributes,
|
||||
};
|
||||
|
||||
static struct attribute *as9716_32d_cpld1_attributes[] = {
|
||||
&sensor_dev_attr_version.dev_attr.attr,
|
||||
&sensor_dev_attr_access.dev_attr.attr,
|
||||
DECLARE_TRANSCEIVER_PRESENT_ATTR(1),
|
||||
DECLARE_TRANSCEIVER_PRESENT_ATTR(2),
|
||||
DECLARE_TRANSCEIVER_PRESENT_ATTR(3),
|
||||
DECLARE_TRANSCEIVER_PRESENT_ATTR(4),
|
||||
DECLARE_TRANSCEIVER_PRESENT_ATTR(5),
|
||||
DECLARE_TRANSCEIVER_PRESENT_ATTR(6),
|
||||
DECLARE_TRANSCEIVER_PRESENT_ATTR(7),
|
||||
DECLARE_TRANSCEIVER_PRESENT_ATTR(8),
|
||||
DECLARE_TRANSCEIVER_PRESENT_ATTR(9),
|
||||
DECLARE_TRANSCEIVER_PRESENT_ATTR(10),
|
||||
DECLARE_TRANSCEIVER_PRESENT_ATTR(11),
|
||||
DECLARE_TRANSCEIVER_PRESENT_ATTR(12),
|
||||
DECLARE_TRANSCEIVER_PRESENT_ATTR(13),
|
||||
DECLARE_TRANSCEIVER_PRESENT_ATTR(14),
|
||||
DECLARE_TRANSCEIVER_PRESENT_ATTR(15),
|
||||
DECLARE_TRANSCEIVER_PRESENT_ATTR(16),
|
||||
NULL
|
||||
};
|
||||
|
||||
static const struct attribute_group as9716_32d_cpld1_group = {
|
||||
.attrs = as9716_32d_cpld1_attributes,
|
||||
};
|
||||
|
||||
static struct attribute *as9716_32d_cpld2_attributes[] = {
|
||||
&sensor_dev_attr_version.dev_attr.attr,
|
||||
&sensor_dev_attr_access.dev_attr.attr,
|
||||
DECLARE_TRANSCEIVER_PRESENT_ATTR(17),
|
||||
DECLARE_TRANSCEIVER_PRESENT_ATTR(18),
|
||||
DECLARE_TRANSCEIVER_PRESENT_ATTR(19),
|
||||
DECLARE_TRANSCEIVER_PRESENT_ATTR(20),
|
||||
DECLARE_TRANSCEIVER_PRESENT_ATTR(21),
|
||||
DECLARE_TRANSCEIVER_PRESENT_ATTR(22),
|
||||
DECLARE_TRANSCEIVER_PRESENT_ATTR(23),
|
||||
DECLARE_TRANSCEIVER_PRESENT_ATTR(24),
|
||||
DECLARE_TRANSCEIVER_PRESENT_ATTR(25),
|
||||
DECLARE_TRANSCEIVER_PRESENT_ATTR(26),
|
||||
DECLARE_TRANSCEIVER_PRESENT_ATTR(27),
|
||||
DECLARE_TRANSCEIVER_PRESENT_ATTR(28),
|
||||
DECLARE_TRANSCEIVER_PRESENT_ATTR(29),
|
||||
DECLARE_TRANSCEIVER_PRESENT_ATTR(30),
|
||||
DECLARE_TRANSCEIVER_PRESENT_ATTR(31),
|
||||
DECLARE_TRANSCEIVER_PRESENT_ATTR(32),
|
||||
DECLARE_TRANSCEIVER_PRESENT_ATTR(33),
|
||||
DECLARE_TRANSCEIVER_PRESENT_ATTR(34),
|
||||
DECLARE_SFP_TRANSCEIVER_ATTR(33),
|
||||
DECLARE_SFP_TRANSCEIVER_ATTR(34),
|
||||
NULL
|
||||
};
|
||||
|
||||
static const struct attribute_group as9716_32d_cpld2_group = {
|
||||
.attrs = as9716_32d_cpld2_attributes,
|
||||
};
|
||||
|
||||
|
||||
static ssize_t show_status(struct device *dev, struct device_attribute *da,
|
||||
char *buf)
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct as9716_32d_cpld_data *data = i2c_get_clientdata(client);
|
||||
int status = 0;
|
||||
u8 reg = 0, mask = 0, revert = 0;
|
||||
|
||||
switch (attr->index) {
|
||||
case MODULE_PRESENT_1 ... MODULE_PRESENT_8:
|
||||
reg = 0x12;
|
||||
mask = 0x1 << (attr->index - MODULE_PRESENT_1);
|
||||
break;
|
||||
case MODULE_PRESENT_9 ... MODULE_PRESENT_16:
|
||||
reg = 0x13;
|
||||
mask = 0x1 << (attr->index - MODULE_PRESENT_9);
|
||||
break;
|
||||
case MODULE_PRESENT_17 ... MODULE_PRESENT_24:
|
||||
reg = 0x12;
|
||||
mask = 0x1 << (attr->index - MODULE_PRESENT_17);
|
||||
break;
|
||||
case MODULE_PRESENT_25 ... MODULE_PRESENT_32:
|
||||
reg = 0x13;
|
||||
mask = 0x1 << (attr->index - MODULE_PRESENT_25);
|
||||
break;
|
||||
case MODULE_PRESENT_33:
|
||||
reg = 0x20;
|
||||
mask = 0x1;
|
||||
break;
|
||||
case MODULE_PRESENT_34:
|
||||
reg = 0x20;
|
||||
mask = 0x8;
|
||||
break;
|
||||
case MODULE_RXLOS_33:
|
||||
reg = 0x20;
|
||||
mask = 0x2;
|
||||
break;
|
||||
case MODULE_RXLOS_34:
|
||||
reg = 0x20;
|
||||
mask = 0x10;
|
||||
break;
|
||||
case MODULE_TXDISABLE_33:
|
||||
reg = 0x21;
|
||||
mask = 0x1;
|
||||
break;
|
||||
case MODULE_TXDISABLE_34:
|
||||
reg = 0x21;
|
||||
mask = 0x2;
|
||||
break;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (attr->index >= MODULE_PRESENT_1 && attr->index <= MODULE_PRESENT_34) {
|
||||
revert = 1;
|
||||
}
|
||||
|
||||
mutex_lock(&data->update_lock);
|
||||
status = as9716_32d_cpld_read_internal(client, reg);
|
||||
if (unlikely(status < 0)) {
|
||||
goto exit;
|
||||
}
|
||||
mutex_unlock(&data->update_lock);
|
||||
|
||||
return sprintf(buf, "%d\n", revert ? !(status & mask) : !!(status & mask));
|
||||
|
||||
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)
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct as9716_32d_cpld_data *data = i2c_get_clientdata(client);
|
||||
long disable;
|
||||
int status;
|
||||
u8 reg = 0, mask = 0;
|
||||
|
||||
status = kstrtol(buf, 10, &disable);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
|
||||
switch (attr->index) {
|
||||
case MODULE_TXDISABLE_33:
|
||||
reg = 0x21;
|
||||
mask = 0x1;
|
||||
break;
|
||||
case MODULE_TXDISABLE_34:
|
||||
reg = 0x21;
|
||||
mask = 0x2;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Read current status */
|
||||
mutex_lock(&data->update_lock);
|
||||
status = as9716_32d_cpld_read_internal(client, reg);
|
||||
if (unlikely(status < 0)) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* Update tx_disable status */
|
||||
if (disable) {
|
||||
status |= mask;
|
||||
}
|
||||
else {
|
||||
status &= ~mask;
|
||||
}
|
||||
|
||||
status = as9716_32d_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 access(struct device *dev, struct device_attribute *da,
|
||||
const char *buf, size_t count)
|
||||
{
|
||||
int status;
|
||||
u32 addr, val;
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct as9716_32d_cpld_data *data = i2c_get_clientdata(client);
|
||||
|
||||
if (sscanf(buf, "0x%x 0x%x", &addr, &val) != 2) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (addr > 0xFF || val > 0xFF) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
mutex_lock(&data->update_lock);
|
||||
status = as9716_32d_cpld_write_internal(client, addr, val);
|
||||
if (unlikely(status < 0)) {
|
||||
goto exit;
|
||||
}
|
||||
mutex_unlock(&data->update_lock);
|
||||
return count;
|
||||
|
||||
exit:
|
||||
mutex_unlock(&data->update_lock);
|
||||
return status;
|
||||
}
|
||||
|
||||
static void as9716_32d_cpld_add_client(struct i2c_client *client)
|
||||
{
|
||||
struct cpld_client_node *node = kzalloc(sizeof(struct cpld_client_node), GFP_KERNEL);
|
||||
|
||||
if (!node) {
|
||||
dev_dbg(&client->dev, "Can't allocate cpld_client_node (0x%x)\n", client->addr);
|
||||
return;
|
||||
}
|
||||
|
||||
node->client = client;
|
||||
|
||||
mutex_lock(&list_lock);
|
||||
list_add(&node->list, &cpld_client_list);
|
||||
mutex_unlock(&list_lock);
|
||||
}
|
||||
|
||||
static void as9716_32d_cpld_remove_client(struct i2c_client *client)
|
||||
{
|
||||
struct list_head *list_node = NULL;
|
||||
struct cpld_client_node *cpld_node = NULL;
|
||||
int found = 0;
|
||||
|
||||
mutex_lock(&list_lock);
|
||||
|
||||
list_for_each(list_node, &cpld_client_list)
|
||||
{
|
||||
cpld_node = list_entry(list_node, struct cpld_client_node, list);
|
||||
|
||||
if (cpld_node->client == client) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
list_del(list_node);
|
||||
kfree(cpld_node);
|
||||
}
|
||||
|
||||
mutex_unlock(&list_lock);
|
||||
}
|
||||
|
||||
static ssize_t show_version(struct device *dev, struct device_attribute *attr, char *buf)
|
||||
{
|
||||
int val = 0;
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
|
||||
val = i2c_smbus_read_byte_data(client, 0x1);
|
||||
|
||||
if (val < 0) {
|
||||
dev_dbg(&client->dev, "cpld(0x%x) reg(0x1) err %d\n", client->addr, val);
|
||||
}
|
||||
|
||||
return sprintf(buf, "%d\n", val);
|
||||
}
|
||||
|
||||
/*
|
||||
* I2C init/probing/exit functions
|
||||
*/
|
||||
static int as9716_32d_cpld_probe(struct i2c_client *client,
|
||||
const struct i2c_device_id *id)
|
||||
{
|
||||
struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent);
|
||||
struct as9716_32d_cpld_data *data;
|
||||
int ret = -ENODEV;
|
||||
int status;
|
||||
const struct attribute_group *group = NULL;
|
||||
|
||||
if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE))
|
||||
goto exit;
|
||||
|
||||
data = kzalloc(sizeof(struct as9716_32d_cpld_data), GFP_KERNEL);
|
||||
if (!data) {
|
||||
ret = -ENOMEM;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
i2c_set_clientdata(client, data);
|
||||
mutex_init(&data->update_lock);
|
||||
data->type = id->driver_data;
|
||||
|
||||
|
||||
/* Register sysfs hooks */
|
||||
switch (data->type) {
|
||||
case as9716_32d_fpga:
|
||||
group = &as9716_32d_fpga_group;
|
||||
break;
|
||||
case as9716_32d_cpld1:
|
||||
group = &as9716_32d_cpld1_group;
|
||||
break;
|
||||
case as9716_32d_cpld2:
|
||||
group = &as9716_32d_cpld2_group;
|
||||
break;
|
||||
case as9716_32d_cpld_cpu:
|
||||
/* Disable CPLD reset to avoid DUT will be reset.
|
||||
*/
|
||||
status=as9716_32d_cpld_write_internal(client, 0x3, 0x0);
|
||||
if (status < 0)
|
||||
{
|
||||
dev_dbg(&client->dev, "cpu_cpld reg 0x65 err %d\n", status);
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (group) {
|
||||
ret = sysfs_create_group(&client->dev.kobj, group);
|
||||
if (ret) {
|
||||
goto exit_free;
|
||||
}
|
||||
}
|
||||
|
||||
as9716_32d_cpld_add_client(client);
|
||||
return 0;
|
||||
|
||||
exit_free:
|
||||
kfree(data);
|
||||
exit:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int as9716_32d_cpld_remove(struct i2c_client *client)
|
||||
{
|
||||
struct as9716_32d_cpld_data *data = i2c_get_clientdata(client);
|
||||
const struct attribute_group *group = NULL;
|
||||
|
||||
as9716_32d_cpld_remove_client(client);
|
||||
|
||||
/* Remove sysfs hooks */
|
||||
switch (data->type) {
|
||||
case as9716_32d_fpga:
|
||||
group = &as9716_32d_fpga_group;
|
||||
break;
|
||||
case as9716_32d_cpld1:
|
||||
group = &as9716_32d_cpld1_group;
|
||||
break;
|
||||
case as9716_32d_cpld2:
|
||||
group = &as9716_32d_cpld2_group;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (group) {
|
||||
sysfs_remove_group(&client->dev.kobj, group);
|
||||
}
|
||||
|
||||
kfree(data);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int as9716_32d_cpld_read_internal(struct i2c_client *client, u8 reg)
|
||||
{
|
||||
int status = 0, retry = I2C_RW_RETRY_COUNT;
|
||||
|
||||
while (retry) {
|
||||
status = i2c_smbus_read_byte_data(client, reg);
|
||||
if (unlikely(status < 0)) {
|
||||
msleep(I2C_RW_RETRY_INTERVAL);
|
||||
retry--;
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static int as9716_32d_cpld_write_internal(struct i2c_client *client, u8 reg, u8 value)
|
||||
{
|
||||
int status = 0, retry = I2C_RW_RETRY_COUNT;
|
||||
|
||||
while (retry) {
|
||||
status = i2c_smbus_write_byte_data(client, reg, value);
|
||||
if (unlikely(status < 0)) {
|
||||
msleep(I2C_RW_RETRY_INTERVAL);
|
||||
retry--;
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int as9716_32d_cpld_read(unsigned short cpld_addr, u8 reg)
|
||||
{
|
||||
struct list_head *list_node = NULL;
|
||||
struct cpld_client_node *cpld_node = NULL;
|
||||
int ret = -EPERM;
|
||||
|
||||
mutex_lock(&list_lock);
|
||||
|
||||
list_for_each(list_node, &cpld_client_list)
|
||||
{
|
||||
cpld_node = list_entry(list_node, struct cpld_client_node, list);
|
||||
|
||||
if (cpld_node->client->addr == cpld_addr) {
|
||||
ret = as9716_32d_cpld_read_internal(cpld_node->client, reg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mutex_unlock(&list_lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(as9716_32d_cpld_read);
|
||||
|
||||
int as9716_32d_cpld_write(unsigned short cpld_addr, u8 reg, u8 value)
|
||||
{
|
||||
struct list_head *list_node = NULL;
|
||||
struct cpld_client_node *cpld_node = NULL;
|
||||
int ret = -EIO;
|
||||
|
||||
mutex_lock(&list_lock);
|
||||
|
||||
list_for_each(list_node, &cpld_client_list)
|
||||
{
|
||||
cpld_node = list_entry(list_node, struct cpld_client_node, list);
|
||||
|
||||
if (cpld_node->client->addr == cpld_addr) {
|
||||
ret = as9716_32d_cpld_write_internal(cpld_node->client, reg, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mutex_unlock(&list_lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(as9716_32d_cpld_write);
|
||||
|
||||
static struct i2c_driver as9716_32d_cpld_driver = {
|
||||
.driver = {
|
||||
.name = "as9716_32d_cpld",
|
||||
.owner = THIS_MODULE,
|
||||
},
|
||||
.probe = as9716_32d_cpld_probe,
|
||||
.remove = as9716_32d_cpld_remove,
|
||||
.id_table = as9716_32d_cpld_id,
|
||||
};
|
||||
|
||||
static int __init as9716_32d_cpld_init(void)
|
||||
{
|
||||
mutex_init(&list_lock);
|
||||
return i2c_add_driver(&as9716_32d_cpld_driver);
|
||||
}
|
||||
|
||||
static void __exit as9716_32d_cpld_exit(void)
|
||||
{
|
||||
i2c_del_driver(&as9716_32d_cpld_driver);
|
||||
}
|
||||
|
||||
MODULE_AUTHOR("Brandon Chuang <brandon_chuang@accton.com.tw>");
|
||||
MODULE_DESCRIPTION("Accton I2C CPLD driver");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
module_init(as9716_32d_cpld_init);
|
||||
module_exit(as9716_32d_cpld_exit);
|
||||
|
||||
@@ -0,0 +1,472 @@
|
||||
/*
|
||||
* A hwmon driver for the Accton as7726 32x fan
|
||||
*
|
||||
* Copyright (C) 2014 Accton Technology Corporation.
|
||||
* Brandon Chuang <brandon_chuang@accton.com.tw>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/jiffies.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/hwmon.h>
|
||||
#include <linux/hwmon-sysfs.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/sysfs.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/dmi.h>
|
||||
|
||||
#define DRVNAME "as9716_32d_fan"
|
||||
|
||||
static struct as9716_32d_fan_data *as9716_32d_fan_update_device(struct device *dev);
|
||||
static ssize_t fan_show_value(struct device *dev, struct device_attribute *da, char *buf);
|
||||
static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da,
|
||||
const char *buf, size_t count);
|
||||
|
||||
/* fan related data, the index should match sysfs_fan_attributes
|
||||
*/
|
||||
static const u8 fan_reg[] = {
|
||||
0x0F, /* fan 1-6 present status */
|
||||
0x10, /* fan 1-6 direction(0:F2B 1:B2F) */
|
||||
0x11, /* fan PWM(for all fan) */
|
||||
0x12, /* front fan 1 speed(rpm) */
|
||||
0x13, /* front fan 2 speed(rpm) */
|
||||
0x14, /* front fan 3 speed(rpm) */
|
||||
0x15, /* front fan 4 speed(rpm) */
|
||||
0x16, /* front fan 5 speed(rpm) */
|
||||
0x17, /* front fan 6 speed(rpm) */
|
||||
0x22, /* rear fan 1 speed(rpm) */
|
||||
0x23, /* rear fan 2 speed(rpm) */
|
||||
0x24, /* rear fan 3 speed(rpm) */
|
||||
0x25, /* rear fan 4 speed(rpm) */
|
||||
0x26, /* rear fan 5 speed(rpm) */
|
||||
0x27, /* rear fan 6 speed(rpm) */
|
||||
};
|
||||
|
||||
/* Each client has this additional data */
|
||||
struct as9716_32d_fan_data {
|
||||
struct device *hwmon_dev;
|
||||
struct mutex update_lock;
|
||||
char valid; /* != 0 if registers are valid */
|
||||
unsigned long last_updated; /* In jiffies */
|
||||
u8 reg_val[ARRAY_SIZE(fan_reg)]; /* Register value */
|
||||
};
|
||||
|
||||
enum fan_id {
|
||||
FAN1_ID,
|
||||
FAN2_ID,
|
||||
FAN3_ID,
|
||||
FAN4_ID,
|
||||
FAN5_ID,
|
||||
FAN6_ID
|
||||
};
|
||||
|
||||
enum sysfs_fan_attributes {
|
||||
FAN_PRESENT_REG,
|
||||
FAN_DIRECTION_REG,
|
||||
FAN_DUTY_CYCLE_PERCENTAGE, /* Only one CPLD register to control duty cycle for all fans */
|
||||
FAN1_FRONT_SPEED_RPM,
|
||||
FAN2_FRONT_SPEED_RPM,
|
||||
FAN3_FRONT_SPEED_RPM,
|
||||
FAN4_FRONT_SPEED_RPM,
|
||||
FAN5_FRONT_SPEED_RPM,
|
||||
FAN6_FRONT_SPEED_RPM,
|
||||
FAN1_REAR_SPEED_RPM,
|
||||
FAN2_REAR_SPEED_RPM,
|
||||
FAN3_REAR_SPEED_RPM,
|
||||
FAN4_REAR_SPEED_RPM,
|
||||
FAN5_REAR_SPEED_RPM,
|
||||
FAN6_REAR_SPEED_RPM,
|
||||
FAN1_DIRECTION,
|
||||
FAN2_DIRECTION,
|
||||
FAN3_DIRECTION,
|
||||
FAN4_DIRECTION,
|
||||
FAN5_DIRECTION,
|
||||
FAN6_DIRECTION,
|
||||
FAN1_PRESENT,
|
||||
FAN2_PRESENT,
|
||||
FAN3_PRESENT,
|
||||
FAN4_PRESENT,
|
||||
FAN5_PRESENT,
|
||||
FAN6_PRESENT,
|
||||
FAN1_FAULT,
|
||||
FAN2_FAULT,
|
||||
FAN3_FAULT,
|
||||
FAN4_FAULT,
|
||||
FAN5_FAULT,
|
||||
FAN6_FAULT
|
||||
};
|
||||
|
||||
/* Define attributes
|
||||
*/
|
||||
#define DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(index) \
|
||||
static SENSOR_DEVICE_ATTR(fan##index##_fault, S_IRUGO, fan_show_value, NULL, FAN##index##_FAULT)
|
||||
#define DECLARE_FAN_FAULT_ATTR(index) &sensor_dev_attr_fan##index##_fault.dev_attr.attr
|
||||
|
||||
#define DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(index) \
|
||||
static SENSOR_DEVICE_ATTR(fan##index##_direction, S_IRUGO, fan_show_value, NULL, FAN##index##_DIRECTION)
|
||||
#define DECLARE_FAN_DIRECTION_ATTR(index) &sensor_dev_attr_fan##index##_direction.dev_attr.attr
|
||||
|
||||
#define DECLARE_FAN_DUTY_CYCLE_SENSOR_DEV_ATTR(index) \
|
||||
static SENSOR_DEVICE_ATTR(fan##index##_duty_cycle_percentage, S_IWUSR | S_IRUGO, fan_show_value, set_duty_cycle, FAN##index##_DUTY_CYCLE_PERCENTAGE)
|
||||
#define DECLARE_FAN_DUTY_CYCLE_ATTR(index) &sensor_dev_attr_fan##index##_duty_cycle_percentage.dev_attr.attr
|
||||
|
||||
#define DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(index) \
|
||||
static SENSOR_DEVICE_ATTR(fan##index##_present, S_IRUGO, fan_show_value, NULL, FAN##index##_PRESENT)
|
||||
#define DECLARE_FAN_PRESENT_ATTR(index) &sensor_dev_attr_fan##index##_present.dev_attr.attr
|
||||
|
||||
#define DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(index) \
|
||||
static SENSOR_DEVICE_ATTR(fan##index##_front_speed_rpm, S_IRUGO, fan_show_value, NULL, FAN##index##_FRONT_SPEED_RPM);\
|
||||
static SENSOR_DEVICE_ATTR(fan##index##_rear_speed_rpm, S_IRUGO, fan_show_value, NULL, FAN##index##_REAR_SPEED_RPM)
|
||||
#define DECLARE_FAN_SPEED_RPM_ATTR(index) &sensor_dev_attr_fan##index##_front_speed_rpm.dev_attr.attr, \
|
||||
&sensor_dev_attr_fan##index##_rear_speed_rpm.dev_attr.attr
|
||||
|
||||
/* 6 fan fault attributes in this platform */
|
||||
DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(1);
|
||||
DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(2);
|
||||
DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(3);
|
||||
DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(4);
|
||||
DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(5);
|
||||
DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(6);
|
||||
/* 6 fan speed(rpm) attributes in this platform */
|
||||
DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(1);
|
||||
DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(2);
|
||||
DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(3);
|
||||
DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(4);
|
||||
DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(5);
|
||||
DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(6);
|
||||
/* 6 fan present attributes in this platform */
|
||||
DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(1);
|
||||
DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(2);
|
||||
DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(3);
|
||||
DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(4);
|
||||
DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(5);
|
||||
DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(6);
|
||||
/* 6 fan direction attribute in this platform */
|
||||
DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(1);
|
||||
DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(2);
|
||||
DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(3);
|
||||
DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(4);
|
||||
DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(5);
|
||||
DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(6);
|
||||
/* 1 fan duty cycle attribute in this platform */
|
||||
DECLARE_FAN_DUTY_CYCLE_SENSOR_DEV_ATTR();
|
||||
|
||||
static struct attribute *as9716_32d_fan_attributes[] = {
|
||||
/* fan related attributes */
|
||||
DECLARE_FAN_FAULT_ATTR(1),
|
||||
DECLARE_FAN_FAULT_ATTR(2),
|
||||
DECLARE_FAN_FAULT_ATTR(3),
|
||||
DECLARE_FAN_FAULT_ATTR(4),
|
||||
DECLARE_FAN_FAULT_ATTR(5),
|
||||
DECLARE_FAN_FAULT_ATTR(6),
|
||||
DECLARE_FAN_SPEED_RPM_ATTR(1),
|
||||
DECLARE_FAN_SPEED_RPM_ATTR(2),
|
||||
DECLARE_FAN_SPEED_RPM_ATTR(3),
|
||||
DECLARE_FAN_SPEED_RPM_ATTR(4),
|
||||
DECLARE_FAN_SPEED_RPM_ATTR(5),
|
||||
DECLARE_FAN_SPEED_RPM_ATTR(6),
|
||||
DECLARE_FAN_PRESENT_ATTR(1),
|
||||
DECLARE_FAN_PRESENT_ATTR(2),
|
||||
DECLARE_FAN_PRESENT_ATTR(3),
|
||||
DECLARE_FAN_PRESENT_ATTR(4),
|
||||
DECLARE_FAN_PRESENT_ATTR(5),
|
||||
DECLARE_FAN_PRESENT_ATTR(6),
|
||||
DECLARE_FAN_DIRECTION_ATTR(1),
|
||||
DECLARE_FAN_DIRECTION_ATTR(2),
|
||||
DECLARE_FAN_DIRECTION_ATTR(3),
|
||||
DECLARE_FAN_DIRECTION_ATTR(4),
|
||||
DECLARE_FAN_DIRECTION_ATTR(5),
|
||||
DECLARE_FAN_DIRECTION_ATTR(6),
|
||||
DECLARE_FAN_DUTY_CYCLE_ATTR(),
|
||||
NULL
|
||||
};
|
||||
|
||||
#define FAN_DUTY_CYCLE_REG_MASK 0xF
|
||||
#define FAN_MAX_DUTY_CYCLE 100
|
||||
#define FAN_REG_VAL_TO_SPEED_RPM_STEP 100
|
||||
|
||||
static int as9716_32d_fan_read_value(struct i2c_client *client, u8 reg)
|
||||
{
|
||||
return i2c_smbus_read_byte_data(client, reg);
|
||||
}
|
||||
|
||||
static int as9716_32d_fan_write_value(struct i2c_client *client, u8 reg, u8 value)
|
||||
{
|
||||
return i2c_smbus_write_byte_data(client, reg, value);
|
||||
}
|
||||
|
||||
/* fan utility functions
|
||||
*/
|
||||
static u32 reg_val_to_duty_cycle(u8 reg_val)
|
||||
{
|
||||
reg_val &= FAN_DUTY_CYCLE_REG_MASK;
|
||||
return ((u32)(reg_val+1) * 625 + 75)/ 100;
|
||||
}
|
||||
|
||||
static u8 duty_cycle_to_reg_val(u8 duty_cycle)
|
||||
{
|
||||
return ((u32)duty_cycle * 100 / 625) - 1;
|
||||
}
|
||||
|
||||
static u32 reg_val_to_speed_rpm(u8 reg_val)
|
||||
{
|
||||
return (u32)reg_val * FAN_REG_VAL_TO_SPEED_RPM_STEP;
|
||||
}
|
||||
|
||||
static u8 reg_val_to_direction(u8 reg_val, enum fan_id id)
|
||||
{
|
||||
u8 mask = (1 << id);
|
||||
|
||||
reg_val &= mask;
|
||||
|
||||
return reg_val ? 1 : 0;
|
||||
}
|
||||
static u8 reg_val_to_is_present(u8 reg_val, enum fan_id id)
|
||||
{
|
||||
u8 mask = (1 << id);
|
||||
|
||||
reg_val &= mask;
|
||||
|
||||
return reg_val ? 0 : 1;
|
||||
}
|
||||
|
||||
static u8 is_fan_fault(struct as9716_32d_fan_data *data, enum fan_id id)
|
||||
{
|
||||
u8 ret = 1;
|
||||
int front_fan_index = FAN1_FRONT_SPEED_RPM + id;
|
||||
int rear_fan_index = FAN1_REAR_SPEED_RPM + id;
|
||||
|
||||
/* Check if the speed of front or rear fan is ZERO,
|
||||
*/
|
||||
if (reg_val_to_speed_rpm(data->reg_val[front_fan_index]) &&
|
||||
reg_val_to_speed_rpm(data->reg_val[rear_fan_index])) {
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da,
|
||||
const char *buf, size_t count)
|
||||
{
|
||||
int error, value;
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
|
||||
error = kstrtoint(buf, 10, &value);
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
if (value < 0 || value > FAN_MAX_DUTY_CYCLE)
|
||||
return -EINVAL;
|
||||
|
||||
as9716_32d_fan_write_value(client, 0x33, 0); /* Disable fan speed watch dog */
|
||||
as9716_32d_fan_write_value(client, fan_reg[FAN_DUTY_CYCLE_PERCENTAGE], duty_cycle_to_reg_val(value));
|
||||
return count;
|
||||
}
|
||||
|
||||
static ssize_t fan_show_value(struct device *dev, struct device_attribute *da,
|
||||
char *buf)
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||
struct as9716_32d_fan_data *data = as9716_32d_fan_update_device(dev);
|
||||
ssize_t ret = 0;
|
||||
|
||||
if (data->valid) {
|
||||
switch (attr->index) {
|
||||
case FAN_DUTY_CYCLE_PERCENTAGE:
|
||||
{
|
||||
u32 duty_cycle = reg_val_to_duty_cycle(data->reg_val[FAN_DUTY_CYCLE_PERCENTAGE]);
|
||||
ret = sprintf(buf, "%u\n", duty_cycle);
|
||||
break;
|
||||
}
|
||||
case FAN1_FRONT_SPEED_RPM:
|
||||
case FAN2_FRONT_SPEED_RPM:
|
||||
case FAN3_FRONT_SPEED_RPM:
|
||||
case FAN4_FRONT_SPEED_RPM:
|
||||
case FAN5_FRONT_SPEED_RPM:
|
||||
case FAN6_FRONT_SPEED_RPM:
|
||||
case FAN1_REAR_SPEED_RPM:
|
||||
case FAN2_REAR_SPEED_RPM:
|
||||
case FAN3_REAR_SPEED_RPM:
|
||||
case FAN4_REAR_SPEED_RPM:
|
||||
case FAN5_REAR_SPEED_RPM:
|
||||
case FAN6_REAR_SPEED_RPM:
|
||||
ret = sprintf(buf, "%u\n", reg_val_to_speed_rpm(data->reg_val[attr->index]));
|
||||
break;
|
||||
case FAN1_PRESENT:
|
||||
case FAN2_PRESENT:
|
||||
case FAN3_PRESENT:
|
||||
case FAN4_PRESENT:
|
||||
case FAN5_PRESENT:
|
||||
case FAN6_PRESENT:
|
||||
ret = sprintf(buf, "%d\n",
|
||||
reg_val_to_is_present(data->reg_val[FAN_PRESENT_REG],
|
||||
attr->index - FAN1_PRESENT));
|
||||
break;
|
||||
case FAN1_FAULT:
|
||||
case FAN2_FAULT:
|
||||
case FAN3_FAULT:
|
||||
case FAN4_FAULT:
|
||||
case FAN5_FAULT:
|
||||
case FAN6_FAULT:
|
||||
ret = sprintf(buf, "%d\n", is_fan_fault(data, attr->index - FAN1_FAULT));
|
||||
break;
|
||||
case FAN1_DIRECTION:
|
||||
case FAN2_DIRECTION:
|
||||
case FAN3_DIRECTION:
|
||||
case FAN4_DIRECTION:
|
||||
case FAN5_DIRECTION:
|
||||
case FAN6_DIRECTION:
|
||||
ret = sprintf(buf, "%d\n",
|
||||
reg_val_to_direction(data->reg_val[FAN_DIRECTION_REG],
|
||||
attr->index - FAN1_DIRECTION));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const struct attribute_group as9716_32d_fan_group = {
|
||||
.attrs = as9716_32d_fan_attributes,
|
||||
};
|
||||
|
||||
static struct as9716_32d_fan_data *as9716_32d_fan_update_device(struct device *dev)
|
||||
{
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct as9716_32d_fan_data *data = i2c_get_clientdata(client);
|
||||
|
||||
mutex_lock(&data->update_lock);
|
||||
|
||||
if (time_after(jiffies, data->last_updated + HZ + HZ / 2) ||
|
||||
!data->valid) {
|
||||
int i;
|
||||
|
||||
dev_dbg(&client->dev, "Starting as9716_32d_fan update\n");
|
||||
data->valid = 0;
|
||||
|
||||
/* Update fan data
|
||||
*/
|
||||
for (i = 0; i < ARRAY_SIZE(data->reg_val); i++) {
|
||||
int status = as9716_32d_fan_read_value(client, fan_reg[i]);
|
||||
if (status < 0) {
|
||||
data->valid = 0;
|
||||
mutex_unlock(&data->update_lock);
|
||||
dev_dbg(&client->dev, "reg %d, err %d\n", fan_reg[i], status);
|
||||
return data;
|
||||
}
|
||||
else {
|
||||
data->reg_val[i] = status;
|
||||
}
|
||||
}
|
||||
|
||||
data->last_updated = jiffies;
|
||||
data->valid = 1;
|
||||
}
|
||||
|
||||
mutex_unlock(&data->update_lock);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
static int as9716_32d_fan_probe(struct i2c_client *client,
|
||||
const struct i2c_device_id *dev_id)
|
||||
{
|
||||
struct as9716_32d_fan_data *data;
|
||||
int status;
|
||||
|
||||
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
|
||||
status = -EIO;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
data = kzalloc(sizeof(struct as9716_32d_fan_data), GFP_KERNEL);
|
||||
if (!data) {
|
||||
status = -ENOMEM;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
i2c_set_clientdata(client, data);
|
||||
data->valid = 0;
|
||||
mutex_init(&data->update_lock);
|
||||
|
||||
dev_info(&client->dev, "chip found\n");
|
||||
|
||||
/* Register sysfs hooks */
|
||||
status = sysfs_create_group(&client->dev.kobj, &as9716_32d_fan_group);
|
||||
if (status) {
|
||||
goto exit_free;
|
||||
}
|
||||
|
||||
data->hwmon_dev = hwmon_device_register(&client->dev);
|
||||
if (IS_ERR(data->hwmon_dev)) {
|
||||
status = PTR_ERR(data->hwmon_dev);
|
||||
goto exit_remove;
|
||||
}
|
||||
|
||||
dev_info(&client->dev, "%s: fan '%s'\n",
|
||||
dev_name(data->hwmon_dev), client->name);
|
||||
|
||||
return 0;
|
||||
|
||||
exit_remove:
|
||||
sysfs_remove_group(&client->dev.kobj, &as9716_32d_fan_group);
|
||||
exit_free:
|
||||
kfree(data);
|
||||
exit:
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static int as9716_32d_fan_remove(struct i2c_client *client)
|
||||
{
|
||||
struct as9716_32d_fan_data *data = i2c_get_clientdata(client);
|
||||
hwmon_device_unregister(data->hwmon_dev);
|
||||
sysfs_remove_group(&client->dev.kobj, &as9716_32d_fan_group);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Addresses to scan */
|
||||
static const unsigned short normal_i2c[] = { 0x66, I2C_CLIENT_END };
|
||||
|
||||
static const struct i2c_device_id as9716_32d_fan_id[] = {
|
||||
{ "as9716_32d_fan", 0 },
|
||||
{}
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, as9716_32d_fan_id);
|
||||
|
||||
static struct i2c_driver as9716_32d_fan_driver = {
|
||||
.class = I2C_CLASS_HWMON,
|
||||
.driver = {
|
||||
.name = DRVNAME,
|
||||
},
|
||||
.probe = as9716_32d_fan_probe,
|
||||
.remove = as9716_32d_fan_remove,
|
||||
.id_table = as9716_32d_fan_id,
|
||||
.address_list = normal_i2c,
|
||||
};
|
||||
|
||||
module_i2c_driver(as9716_32d_fan_driver);
|
||||
|
||||
MODULE_AUTHOR("Brandon Chuang <brandon_chuang@accton.com.tw>");
|
||||
MODULE_DESCRIPTION("as9716_32d_fan driver");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
@@ -0,0 +1,492 @@
|
||||
/*
|
||||
* A LED driver for the accton_as9716_32d_led
|
||||
*
|
||||
* Copyright (C) 2014 Accton Technology Corporation.
|
||||
* Brandon Chuang <brandon_chuang@accton.com.tw>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
/*#define DEBUG*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/leds.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/dmi.h>
|
||||
|
||||
extern int as9716_32d_cpld_read (unsigned short cpld_addr, u8 reg);
|
||||
extern int as9716_32d_cpld_write(unsigned short cpld_addr, u8 reg, u8 value);
|
||||
|
||||
#define DRVNAME "accton_as9716_32d_led"
|
||||
|
||||
struct accton_as9716_32d_led_data {
|
||||
struct platform_device *pdev;
|
||||
struct mutex update_lock;
|
||||
char valid; /* != 0 if registers are valid */
|
||||
unsigned long last_updated; /* In jiffies */
|
||||
u8 reg_val[1]; /* only 1 register*/
|
||||
};
|
||||
|
||||
static struct accton_as9716_32d_led_data *ledctl = NULL;
|
||||
|
||||
/* LED related data
|
||||
*/
|
||||
|
||||
#define LED_CNTRLER_I2C_ADDRESS (0x61)
|
||||
|
||||
#define LED_TYPE_DIAG_REG_MASK (0x1|0x2|0x4)
|
||||
#define LED_MODE_DIAG_GREEN_VALUE (0x01)
|
||||
#define LED_MODE_DIAG_AMBER_VALUE (0x02) /*It's yellow actually. Green+Red=Yellow*/
|
||||
#define LED_MODE_DIAG_GREEN_BLINK_VALUE (0x04)
|
||||
#define LED_MODE_DIAG_OFF_VALUE (0x0)
|
||||
|
||||
|
||||
#define LED_TYPE_LOC_REG_MASK (0x80|0x40)
|
||||
#define LED_MODE_LOC_GREEN_BLIKN_VALUE 0x80
|
||||
#define LED_MODE_LOC_AMBER_VALUE 0x40
|
||||
#define LED_MODE_LOC_OFF_VALUE (0x0)
|
||||
|
||||
#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_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_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)
|
||||
|
||||
enum led_type {
|
||||
LED_TYPE_DIAG,
|
||||
LED_TYPE_LOC,
|
||||
LED_TYPE_FAN,
|
||||
LED_TYPE_PSU1,
|
||||
LED_TYPE_PSU2
|
||||
};
|
||||
|
||||
struct led_reg {
|
||||
u32 types;
|
||||
u8 reg_addr;
|
||||
};
|
||||
|
||||
static const struct led_reg led_reg_map[] = {
|
||||
{(1<<LED_TYPE_DIAG), 0x31},
|
||||
{(1<<LED_TYPE_PSU2) | (1<<LED_TYPE_PSU1) | (1<<LED_TYPE_FAN) | (1<<LED_TYPE_LOC), 0x30},
|
||||
};
|
||||
|
||||
|
||||
enum led_light_mode {
|
||||
LED_MODE_OFF = 0,
|
||||
LED_MODE_GREEN,
|
||||
LED_MODE_AMBER,
|
||||
LED_MODE_RED,
|
||||
LED_MODE_BLUE,
|
||||
LED_MODE_GREEN_BLINK,
|
||||
LED_MODE_AMBER_BLINK,
|
||||
LED_MODE_RED_BLINK,
|
||||
LED_MODE_BLUE_BLINK,
|
||||
LED_MODE_AUTO,
|
||||
LED_MODE_UNKNOWN
|
||||
};
|
||||
|
||||
struct led_type_mode {
|
||||
enum led_type type;
|
||||
enum led_light_mode mode;
|
||||
int reg_bit_mask;
|
||||
int mode_value;
|
||||
};
|
||||
|
||||
static struct led_type_mode led_type_mode_data[] = {
|
||||
{LED_TYPE_LOC, LED_MODE_OFF, LED_TYPE_LOC_REG_MASK, LED_MODE_LOC_OFF_VALUE},
|
||||
{LED_TYPE_LOC, LED_MODE_GREEN_BLINK, LED_TYPE_LOC_REG_MASK, LED_MODE_LOC_GREEN_BLIKN_VALUE},
|
||||
{LED_TYPE_LOC, LED_MODE_AMBER, LED_TYPE_LOC_REG_MASK, LED_MODE_LOC_AMBER_VALUE},
|
||||
{LED_TYPE_DIAG,LED_MODE_OFF, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_OFF_VALUE},
|
||||
{LED_TYPE_DIAG,LED_MODE_GREEN, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_GREEN_VALUE},
|
||||
{LED_TYPE_DIAG,LED_MODE_AMBER, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_AMBER_VALUE},
|
||||
{LED_TYPE_DIAG,LED_MODE_GREEN_BLINK, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_GREEN_BLINK_VALUE},
|
||||
{LED_TYPE_FAN,LED_MODE_OFF, LED_TYPE_FAN_REG_MASK, LED_MODE_FAN_OFF_VALUE},
|
||||
{LED_TYPE_FAN,LED_MODE_GREEN, LED_TYPE_FAN_REG_MASK, LED_MODE_FAN_GREEN_VALUE},
|
||||
{LED_TYPE_FAN,LED_MODE_AMBER, LED_TYPE_FAN_REG_MASK, LED_MODE_FAN_AMBER_VALUE},
|
||||
|
||||
{LED_TYPE_PSU1,LED_MODE_OFF, LED_TYPE_PSU1_REG_MASK, LED_MODE_PSU1_OFF_VALUE},
|
||||
{LED_TYPE_PSU1,LED_MODE_GREEN, LED_TYPE_PSU1_REG_MASK, LED_MODE_PSU1_GREEN_VALUE},
|
||||
{LED_TYPE_PSU1,LED_MODE_AMBER, LED_TYPE_PSU1_REG_MASK, LED_MODE_PSU1_AMBER_VALUE},
|
||||
|
||||
{LED_TYPE_PSU2,LED_MODE_OFF, LED_TYPE_PSU2_REG_MASK, LED_MODE_PSU2_OFF_VALUE},
|
||||
{LED_TYPE_PSU2,LED_MODE_GREEN, LED_TYPE_PSU2_REG_MASK, LED_MODE_PSU2_GREEN_VALUE},
|
||||
{LED_TYPE_PSU2,LED_MODE_AMBER, LED_TYPE_PSU2_REG_MASK, LED_MODE_PSU2_AMBER_VALUE},
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
static void accton_as9716_32d_led_set(struct led_classdev *led_cdev,
|
||||
enum led_brightness led_light_mode, enum led_type type);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static int accton_getLedReg(enum led_type type, u8 *reg)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(led_reg_map); i++) {
|
||||
if(led_reg_map[i].types & (1<<type)) {
|
||||
*reg = led_reg_map[i].reg_addr;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int led_reg_val_to_light_mode(enum led_type type, u8 reg_val) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(led_type_mode_data); i++) {
|
||||
|
||||
if (type != led_type_mode_data[i].type)
|
||||
continue;
|
||||
|
||||
if ((led_type_mode_data[i].reg_bit_mask & reg_val) ==
|
||||
led_type_mode_data[i].mode_value)
|
||||
{
|
||||
return led_type_mode_data[i].mode;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static u8 led_light_mode_to_reg_val(enum led_type type,
|
||||
enum led_light_mode mode, u8 reg_val) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(led_type_mode_data); i++) {
|
||||
if (type != led_type_mode_data[i].type)
|
||||
continue;
|
||||
|
||||
if (mode != led_type_mode_data[i].mode)
|
||||
continue;
|
||||
|
||||
reg_val = led_type_mode_data[i].mode_value |
|
||||
(reg_val & (~led_type_mode_data[i].reg_bit_mask));
|
||||
break;
|
||||
}
|
||||
|
||||
return reg_val;
|
||||
}
|
||||
|
||||
static int accton_as9716_32d_led_read_value(u8 reg)
|
||||
{
|
||||
return as9716_32d_cpld_read(LED_CNTRLER_I2C_ADDRESS, reg);
|
||||
}
|
||||
|
||||
static int accton_as9716_32d_led_write_value(u8 reg, u8 value)
|
||||
{
|
||||
return as9716_32d_cpld_write(LED_CNTRLER_I2C_ADDRESS, reg, value);
|
||||
}
|
||||
|
||||
static void accton_as9716_32d_led_update(void)
|
||||
{
|
||||
mutex_lock(&ledctl->update_lock);
|
||||
|
||||
if (time_after(jiffies, ledctl->last_updated + HZ + HZ / 2)
|
||||
|| !ledctl->valid) {
|
||||
int i;
|
||||
|
||||
dev_dbg(&ledctl->pdev->dev, "Starting accton_as9716_32d_led update\n");
|
||||
|
||||
/* Update LED data
|
||||
*/
|
||||
for (i = 0; i < ARRAY_SIZE(ledctl->reg_val); i++) {
|
||||
int status = accton_as9716_32d_led_read_value(led_reg_map[i].reg_addr);
|
||||
|
||||
if (status < 0) {
|
||||
ledctl->valid = 0;
|
||||
dev_dbg(&ledctl->pdev->dev, "reg %d, err %d\n", led_reg_map[i].reg_addr, status);
|
||||
goto exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
ledctl->reg_val[i] = status;
|
||||
}
|
||||
}
|
||||
|
||||
ledctl->last_updated = jiffies;
|
||||
ledctl->valid = 1;
|
||||
}
|
||||
|
||||
exit:
|
||||
mutex_unlock(&ledctl->update_lock);
|
||||
}
|
||||
|
||||
static void accton_as9716_32d_led_set(struct led_classdev *led_cdev,
|
||||
enum led_brightness led_light_mode,
|
||||
enum led_type type)
|
||||
{
|
||||
int reg_val;
|
||||
u8 reg ;
|
||||
mutex_lock(&ledctl->update_lock);
|
||||
|
||||
if( !accton_getLedReg(type, ®))
|
||||
{
|
||||
dev_dbg(&ledctl->pdev->dev, "Not match item for %d.\n", type);
|
||||
}
|
||||
|
||||
reg_val = accton_as9716_32d_led_read_value(reg);
|
||||
|
||||
if (reg_val < 0) {
|
||||
dev_dbg(&ledctl->pdev->dev, "reg %d, err %d\n", reg, reg_val);
|
||||
goto exit;
|
||||
}
|
||||
reg_val = led_light_mode_to_reg_val(type, led_light_mode, reg_val);
|
||||
|
||||
accton_as9716_32d_led_write_value(reg, reg_val);
|
||||
|
||||
/* to prevent the slow-update issue */
|
||||
ledctl->valid = 0;
|
||||
|
||||
exit:
|
||||
mutex_unlock(&ledctl->update_lock);
|
||||
}
|
||||
|
||||
|
||||
static void accton_as9716_32d_led_diag_set(struct led_classdev *led_cdev,
|
||||
enum led_brightness led_light_mode)
|
||||
{
|
||||
accton_as9716_32d_led_set(led_cdev, led_light_mode, LED_TYPE_DIAG);
|
||||
}
|
||||
|
||||
static enum led_brightness accton_as9716_32d_led_diag_get(struct led_classdev *cdev)
|
||||
{
|
||||
accton_as9716_32d_led_update();
|
||||
return led_reg_val_to_light_mode(LED_TYPE_DIAG, ledctl->reg_val[0]);
|
||||
}
|
||||
|
||||
static void accton_as9716_32d_led_loc_set(struct led_classdev *led_cdev,
|
||||
enum led_brightness led_light_mode)
|
||||
{
|
||||
accton_as9716_32d_led_set(led_cdev, led_light_mode, LED_TYPE_LOC);
|
||||
}
|
||||
|
||||
static enum led_brightness accton_as9716_32d_led_loc_get(struct led_classdev *cdev)
|
||||
{
|
||||
accton_as9716_32d_led_update();
|
||||
return led_reg_val_to_light_mode(LED_TYPE_LOC, ledctl->reg_val[0]);
|
||||
}
|
||||
|
||||
static void accton_as9716_32d_led_fan_set(struct led_classdev *led_cdev,
|
||||
enum led_brightness led_light_mode)
|
||||
{
|
||||
accton_as9716_32d_led_set(led_cdev, led_light_mode, LED_TYPE_FAN);
|
||||
}
|
||||
|
||||
static enum led_brightness accton_as9716_32d_led_fan_get(struct led_classdev *cdev)
|
||||
{
|
||||
accton_as9716_32d_led_update();
|
||||
return led_reg_val_to_light_mode(LED_TYPE_FAN, ledctl->reg_val[0]);
|
||||
}
|
||||
|
||||
static void accton_as9716_32d_led_psu1_set(struct led_classdev *led_cdev,
|
||||
enum led_brightness led_light_mode)
|
||||
{
|
||||
accton_as9716_32d_led_set(led_cdev, led_light_mode, LED_TYPE_PSU1);
|
||||
}
|
||||
|
||||
static enum led_brightness accton_as9716_32d_led_psu1_get(struct led_classdev *cdev)
|
||||
{
|
||||
accton_as9716_32d_led_update();
|
||||
return led_reg_val_to_light_mode(LED_TYPE_PSU1, ledctl->reg_val[0]);
|
||||
}
|
||||
|
||||
static void accton_as9716_32d_led_psu2_set(struct led_classdev *led_cdev,
|
||||
enum led_brightness led_light_mode)
|
||||
{
|
||||
accton_as9716_32d_led_set(led_cdev, led_light_mode, LED_TYPE_PSU2);
|
||||
}
|
||||
|
||||
static enum led_brightness accton_as9716_32d_led_psu2_get(struct led_classdev *cdev)
|
||||
{
|
||||
accton_as9716_32d_led_update();
|
||||
return led_reg_val_to_light_mode(LED_TYPE_PSU2, ledctl->reg_val[0]);
|
||||
}
|
||||
|
||||
static struct led_classdev accton_as9716_32d_leds[] = {
|
||||
[LED_TYPE_DIAG] = {
|
||||
.name = "accton_as9716_32d_led::diag",
|
||||
.default_trigger = "unused",
|
||||
.brightness_set = accton_as9716_32d_led_diag_set,
|
||||
.brightness_get = accton_as9716_32d_led_diag_get,
|
||||
.flags = LED_CORE_SUSPENDRESUME,
|
||||
.max_brightness = LED_MODE_GREEN_BLINK,
|
||||
},
|
||||
[LED_TYPE_LOC] = {
|
||||
.name = "accton_as9716_32d_led::loc",
|
||||
.default_trigger = "unused",
|
||||
.brightness_set = accton_as9716_32d_led_loc_set,
|
||||
.brightness_get = accton_as9716_32d_led_loc_get,
|
||||
.flags = LED_CORE_SUSPENDRESUME,
|
||||
.max_brightness = LED_MODE_GREEN_BLINK,
|
||||
},
|
||||
[LED_TYPE_FAN] = {
|
||||
.name = "accton_as9716_32d_led::fan",
|
||||
.default_trigger = "unused",
|
||||
.brightness_set = accton_as9716_32d_led_fan_set,
|
||||
.brightness_get = accton_as9716_32d_led_fan_get,
|
||||
.flags = LED_CORE_SUSPENDRESUME,
|
||||
.max_brightness = LED_MODE_AMBER,
|
||||
},
|
||||
[LED_TYPE_PSU1] = {
|
||||
.name = "accton_as9716_32d_led::psu1",
|
||||
.default_trigger = "unused",
|
||||
.brightness_set = accton_as9716_32d_led_psu1_set,
|
||||
.brightness_get = accton_as9716_32d_led_psu1_get,
|
||||
.flags = LED_CORE_SUSPENDRESUME,
|
||||
.max_brightness = LED_MODE_AMBER,
|
||||
},
|
||||
[LED_TYPE_PSU2] = {
|
||||
.name = "accton_as9716_32d_led::psu2",
|
||||
.default_trigger = "unused",
|
||||
.brightness_set = accton_as9716_32d_led_psu2_set,
|
||||
.brightness_get = accton_as9716_32d_led_psu2_get,
|
||||
.flags = LED_CORE_SUSPENDRESUME,
|
||||
.max_brightness = LED_MODE_AMBER,
|
||||
},
|
||||
};
|
||||
|
||||
static int accton_as9716_32d_led_suspend(struct platform_device *dev,
|
||||
pm_message_t state)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(accton_as9716_32d_leds); i++) {
|
||||
led_classdev_suspend(&accton_as9716_32d_leds[i]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int accton_as9716_32d_led_resume(struct platform_device *dev)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(accton_as9716_32d_leds); i++) {
|
||||
led_classdev_resume(&accton_as9716_32d_leds[i]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int accton_as9716_32d_led_probe(struct platform_device *pdev)
|
||||
{
|
||||
int ret, i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(accton_as9716_32d_leds); i++) {
|
||||
ret = led_classdev_register(&pdev->dev, &accton_as9716_32d_leds[i]);
|
||||
|
||||
if (ret < 0)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Check if all LEDs were successfully registered */
|
||||
if (i != ARRAY_SIZE(accton_as9716_32d_leds)) {
|
||||
int j;
|
||||
|
||||
/* only unregister the LEDs that were successfully registered */
|
||||
for (j = 0; j < i; j++) {
|
||||
led_classdev_unregister(&accton_as9716_32d_leds[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int accton_as9716_32d_led_remove(struct platform_device *pdev)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(accton_as9716_32d_leds); i++) {
|
||||
led_classdev_unregister(&accton_as9716_32d_leds[i]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct platform_driver accton_as9716_32d_led_driver = {
|
||||
.probe = accton_as9716_32d_led_probe,
|
||||
.remove = accton_as9716_32d_led_remove,
|
||||
.suspend = accton_as9716_32d_led_suspend,
|
||||
.resume = accton_as9716_32d_led_resume,
|
||||
.driver = {
|
||||
.name = DRVNAME,
|
||||
.owner = THIS_MODULE,
|
||||
},
|
||||
};
|
||||
|
||||
static int __init accton_as9716_32d_led_init(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = platform_driver_register(&accton_as9716_32d_led_driver);
|
||||
if (ret < 0) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
ledctl = kzalloc(sizeof(struct accton_as9716_32d_led_data), GFP_KERNEL);
|
||||
if (!ledctl) {
|
||||
ret = -ENOMEM;
|
||||
platform_driver_unregister(&accton_as9716_32d_led_driver);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
mutex_init(&ledctl->update_lock);
|
||||
|
||||
ledctl->pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
|
||||
if (IS_ERR(ledctl->pdev)) {
|
||||
ret = PTR_ERR(ledctl->pdev);
|
||||
platform_driver_unregister(&accton_as9716_32d_led_driver);
|
||||
kfree(ledctl);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
exit:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void __exit accton_as9716_32d_led_exit(void)
|
||||
{
|
||||
platform_device_unregister(ledctl->pdev);
|
||||
platform_driver_unregister(&accton_as9716_32d_led_driver);
|
||||
kfree(ledctl);
|
||||
}
|
||||
|
||||
module_init(accton_as9716_32d_led_init);
|
||||
module_exit(accton_as9716_32d_led_exit);
|
||||
|
||||
MODULE_AUTHOR("Brandon Chuang <brandon_chuang@accton.com.tw>");
|
||||
MODULE_DESCRIPTION("accton_as9716_32d_led driver");
|
||||
MODULE_LICENSE("GPL");
|
||||
@@ -0,0 +1,311 @@
|
||||
/*
|
||||
* An hwmon driver for accton as9716_32d Power Module
|
||||
*
|
||||
* Copyright (C) 2014 Accton Technology Corporation.
|
||||
* Brandon Chuang <brandon_chuang@accton.com.tw>
|
||||
*
|
||||
* Based on ad7414.c
|
||||
* Copyright 2006 Stefan Roese <sr at denx.de>, DENX Software Engineering
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/jiffies.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/hwmon.h>
|
||||
#include <linux/hwmon-sysfs.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/sysfs.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/dmi.h>
|
||||
|
||||
#define MAX_MODEL_NAME 16
|
||||
#define MAX_SERIAL_NUMBER 19
|
||||
|
||||
static ssize_t show_status(struct device *dev, struct device_attribute *da, char *buf);
|
||||
static ssize_t show_string(struct device *dev, struct device_attribute *da, char *buf);
|
||||
static int as9716_32d_psu_read_block(struct i2c_client *client, u8 command, u8 *data,int data_len);
|
||||
extern int as9716_32d_cpld_read(unsigned short cpld_addr, u8 reg);
|
||||
|
||||
/* Addresses scanned
|
||||
*/
|
||||
static const unsigned short normal_i2c[] = { 0x50, 0x51, I2C_CLIENT_END };
|
||||
|
||||
/* Each client has this additional data
|
||||
*/
|
||||
struct as9716_32d_psu_data {
|
||||
struct device *hwmon_dev;
|
||||
struct mutex update_lock;
|
||||
char valid; /* !=0 if registers are valid */
|
||||
unsigned long last_updated; /* In jiffies */
|
||||
u8 index; /* PSU index */
|
||||
u8 status; /* Status(present/power_good) register read from CPLD */
|
||||
char model_name[MAX_MODEL_NAME]; /* Model name, read from eeprom */
|
||||
char serial_number[MAX_SERIAL_NUMBER];
|
||||
};
|
||||
|
||||
static struct as9716_32d_psu_data *as9716_32d_psu_update_device(struct device *dev);
|
||||
|
||||
enum as9716_32d_psu_sysfs_attributes {
|
||||
PSU_PRESENT,
|
||||
PSU_MODEL_NAME,
|
||||
PSU_POWER_GOOD,
|
||||
PSU_SERIAL_NUMBER
|
||||
};
|
||||
|
||||
/* sysfs attributes for hwmon
|
||||
*/
|
||||
static SENSOR_DEVICE_ATTR(psu_present, S_IRUGO, show_status, NULL, PSU_PRESENT);
|
||||
static SENSOR_DEVICE_ATTR(psu_model_name, S_IRUGO, show_string, NULL, PSU_MODEL_NAME);
|
||||
static SENSOR_DEVICE_ATTR(psu_power_good, S_IRUGO, show_status, NULL, PSU_POWER_GOOD);
|
||||
static SENSOR_DEVICE_ATTR(psu_serial_number, S_IRUGO, show_string, NULL, PSU_SERIAL_NUMBER);
|
||||
|
||||
|
||||
static struct attribute *as9716_32d_psu_attributes[] = {
|
||||
&sensor_dev_attr_psu_present.dev_attr.attr,
|
||||
&sensor_dev_attr_psu_model_name.dev_attr.attr,
|
||||
&sensor_dev_attr_psu_power_good.dev_attr.attr,
|
||||
&sensor_dev_attr_psu_serial_number.dev_attr.attr,
|
||||
NULL
|
||||
};
|
||||
|
||||
static ssize_t show_status(struct device *dev, struct device_attribute *da,
|
||||
char *buf)
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||
struct as9716_32d_psu_data *data = as9716_32d_psu_update_device(dev);
|
||||
u8 status = 0;
|
||||
|
||||
if (attr->index == PSU_PRESENT) {
|
||||
status = !(data->status >> (1-data->index) & 0x1);
|
||||
}
|
||||
else { /* PSU_POWER_GOOD */
|
||||
status = (data->status >> (3-data->index) & 0x1);
|
||||
}
|
||||
|
||||
return sprintf(buf, "%d\n", status);
|
||||
}
|
||||
|
||||
static ssize_t show_string(struct device *dev, struct device_attribute *da,
|
||||
char *buf)
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||
struct as9716_32d_psu_data *data = as9716_32d_psu_update_device(dev);
|
||||
char *ptr = NULL;
|
||||
|
||||
if (!data->valid) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
switch (attr->index) {
|
||||
case PSU_MODEL_NAME:
|
||||
ptr = data->model_name;
|
||||
break;
|
||||
case PSU_SERIAL_NUMBER:
|
||||
ptr = data->serial_number;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return sprintf(buf, "%s\n", ptr);
|
||||
}
|
||||
|
||||
static const struct attribute_group as9716_32d_psu_group = {
|
||||
.attrs = as9716_32d_psu_attributes,
|
||||
};
|
||||
|
||||
static int as9716_32d_psu_probe(struct i2c_client *client,
|
||||
const struct i2c_device_id *dev_id)
|
||||
{
|
||||
struct as9716_32d_psu_data *data;
|
||||
int status;
|
||||
|
||||
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) {
|
||||
status = -EIO;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
data = kzalloc(sizeof(struct as9716_32d_psu_data), GFP_KERNEL);
|
||||
if (!data) {
|
||||
status = -ENOMEM;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
i2c_set_clientdata(client, data);
|
||||
data->valid = 0;
|
||||
data->index = dev_id->driver_data;
|
||||
mutex_init(&data->update_lock);
|
||||
|
||||
dev_info(&client->dev, "chip found\n");
|
||||
|
||||
/* Register sysfs hooks */
|
||||
status = sysfs_create_group(&client->dev.kobj, &as9716_32d_psu_group);
|
||||
if (status) {
|
||||
goto exit_free;
|
||||
}
|
||||
|
||||
data->hwmon_dev = hwmon_device_register(&client->dev);
|
||||
if (IS_ERR(data->hwmon_dev)) {
|
||||
status = PTR_ERR(data->hwmon_dev);
|
||||
goto exit_remove;
|
||||
}
|
||||
|
||||
dev_info(&client->dev, "%s: psu '%s'\n",
|
||||
dev_name(data->hwmon_dev), client->name);
|
||||
|
||||
return 0;
|
||||
|
||||
exit_remove:
|
||||
sysfs_remove_group(&client->dev.kobj, &as9716_32d_psu_group);
|
||||
exit_free:
|
||||
kfree(data);
|
||||
exit:
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static int as9716_32d_psu_remove(struct i2c_client *client)
|
||||
{
|
||||
struct as9716_32d_psu_data *data = i2c_get_clientdata(client);
|
||||
|
||||
hwmon_device_unregister(data->hwmon_dev);
|
||||
sysfs_remove_group(&client->dev.kobj, &as9716_32d_psu_group);
|
||||
kfree(data);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
enum psu_index
|
||||
{
|
||||
as9716_32d_psu1,
|
||||
as9716_32d_psu2
|
||||
};
|
||||
|
||||
static const struct i2c_device_id as9716_32d_psu_id[] = {
|
||||
{ "as9716_32d_psu1", as9716_32d_psu1 },
|
||||
{ "as9716_32d_psu2", as9716_32d_psu2 },
|
||||
{}
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, as9716_32d_psu_id);
|
||||
|
||||
static struct i2c_driver as9716_32d_psu_driver = {
|
||||
.class = I2C_CLASS_HWMON,
|
||||
.driver = {
|
||||
.name = "as9716_32d_psu",
|
||||
},
|
||||
.probe = as9716_32d_psu_probe,
|
||||
.remove = as9716_32d_psu_remove,
|
||||
.id_table = as9716_32d_psu_id,
|
||||
.address_list = normal_i2c,
|
||||
};
|
||||
|
||||
static int as9716_32d_psu_read_block(struct i2c_client *client, u8 command, u8 *data,
|
||||
int data_len)
|
||||
{
|
||||
int result = 0;
|
||||
int retry_count = 5;
|
||||
|
||||
while (retry_count) {
|
||||
retry_count--;
|
||||
|
||||
result = i2c_smbus_read_i2c_block_data(client, command, data_len, data);
|
||||
|
||||
if (unlikely(result < 0)) {
|
||||
msleep(10);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (unlikely(result != data_len)) {
|
||||
result = -EIO;
|
||||
msleep(10);
|
||||
continue;
|
||||
}
|
||||
|
||||
result = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static struct as9716_32d_psu_data *as9716_32d_psu_update_device(struct device *dev)
|
||||
{
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct as9716_32d_psu_data *data = i2c_get_clientdata(client);
|
||||
|
||||
mutex_lock(&data->update_lock);
|
||||
|
||||
if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
|
||||
|| !data->valid) {
|
||||
int status;
|
||||
int power_good = 0;
|
||||
|
||||
dev_dbg(&client->dev, "Starting as9716_32d update\n");
|
||||
|
||||
/* Read psu status */
|
||||
status = as9716_32d_cpld_read(0x60, 0x3);
|
||||
|
||||
if (status < 0) {
|
||||
dev_dbg(&client->dev, "cpld reg 0x60 err %d\n", status);
|
||||
}
|
||||
else {
|
||||
data->status = status;
|
||||
}
|
||||
|
||||
/* 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);
|
||||
|
||||
if (power_good) {
|
||||
status = as9716_32d_psu_read_block(client, 0x20, data->model_name,
|
||||
ARRAY_SIZE(data->model_name)-1);
|
||||
if (status < 0) {
|
||||
data->model_name[0] = '\0';
|
||||
dev_dbg(&client->dev, "unable to read model name from (0x%x)\n", client->addr);
|
||||
}
|
||||
else {
|
||||
data->model_name[ARRAY_SIZE(data->model_name)-1] = '\0';
|
||||
|
||||
}
|
||||
/* Read from offset 0x2e ~ 0x3d (16 bytes) */
|
||||
status = as9716_32d_psu_read_block(client, 0x2e,data->serial_number, MAX_SERIAL_NUMBER);
|
||||
if (status < 0)
|
||||
{
|
||||
data->serial_number[0] = '\0';
|
||||
dev_dbg(&client->dev, "unable to read model name from (0x%x) offset(0x2e)\n", client->addr);
|
||||
}
|
||||
data->serial_number[MAX_SERIAL_NUMBER-1]='\0';
|
||||
}
|
||||
|
||||
data->last_updated = jiffies;
|
||||
data->valid = 1;
|
||||
}
|
||||
|
||||
mutex_unlock(&data->update_lock);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
module_i2c_driver(as9716_32d_psu_driver);
|
||||
|
||||
MODULE_AUTHOR("Brandon Chuang <brandon_chuang@accton.com.tw>");
|
||||
MODULE_DESCRIPTION("as9716_32d_psu driver");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
1
packages/platforms/accton/x86-64/x86-64-accton-as9716_32d/onlp/Makefile
Executable file
1
packages/platforms/accton/x86-64/x86-64-accton-as9716_32d/onlp/Makefile
Executable file
@@ -0,0 +1 @@
|
||||
include $(ONL)/make/pkg.mk
|
||||
1
packages/platforms/accton/x86-64/x86-64-accton-as9716_32d/onlp/PKG.yml
Executable file
1
packages/platforms/accton/x86-64/x86-64-accton-as9716_32d/onlp/PKG.yml
Executable file
@@ -0,0 +1 @@
|
||||
!include $ONL_TEMPLATES/onlp-platform-any.yml PLATFORM=x86-64-accton-as9716-32d ARCH=amd64 TOOLCHAIN=x86_64-linux-gnu
|
||||
@@ -0,0 +1,2 @@
|
||||
FILTER=src
|
||||
include $(ONL)/make/subdirs.mk
|
||||
@@ -0,0 +1,45 @@
|
||||
############################################################
|
||||
# <bsn.cl fy=2014 v=onl>
|
||||
#
|
||||
# Copyright 2014 BigSwitch Networks, Inc.
|
||||
#
|
||||
# Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.eclipse.org/legal/epl-v10.html
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
# either express or implied. See the License for the specific
|
||||
# language governing permissions and limitations under the
|
||||
# License.
|
||||
#
|
||||
# </bsn.cl>
|
||||
############################################################
|
||||
#
|
||||
#
|
||||
############################################################
|
||||
include $(ONL)/make/config.amd64.mk
|
||||
|
||||
MODULE := libonlp-x86-64-accton-as9716-32d
|
||||
include $(BUILDER)/standardinit.mk
|
||||
|
||||
DEPENDMODULES := AIM IOF x86_64_accton_as9716_32d onlplib
|
||||
DEPENDMODULE_HEADERS := sff
|
||||
|
||||
include $(BUILDER)/dependmodules.mk
|
||||
|
||||
SHAREDLIB := libonlp-x86-64-accton-as9716-32d.so
|
||||
$(SHAREDLIB)_TARGETS := $(ALL_TARGETS)
|
||||
include $(BUILDER)/so.mk
|
||||
.DEFAULT_GOAL := $(SHAREDLIB)
|
||||
|
||||
GLOBAL_CFLAGS += -I$(onlp_BASEDIR)/module/inc
|
||||
GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MODULES_INIT=1
|
||||
GLOBAL_CFLAGS += -fPIC
|
||||
GLOBAL_LINK_LIBS += -lpthread
|
||||
|
||||
include $(BUILDER)/targets.mk
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
############################################################
|
||||
# <bsn.cl fy=2014 v=onl>
|
||||
#
|
||||
# Copyright 2014 BigSwitch Networks, Inc.
|
||||
#
|
||||
# Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.eclipse.org/legal/epl-v10.html
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
# either express or implied. See the License for the specific
|
||||
# language governing permissions and limitations under the
|
||||
# License.
|
||||
#
|
||||
# </bsn.cl>
|
||||
############################################################
|
||||
#
|
||||
#
|
||||
#
|
||||
############################################################
|
||||
include $(ONL)/make/config.amd64.mk
|
||||
|
||||
.DEFAULT_GOAL := onlpdump
|
||||
|
||||
MODULE := onlpdump
|
||||
include $(BUILDER)/standardinit.mk
|
||||
|
||||
DEPENDMODULES := AIM IOF onlp x86_64_accton_as9716_32d onlplib onlp_platform_defaults sff cjson cjson_util timer_wheel OS
|
||||
|
||||
include $(BUILDER)/dependmodules.mk
|
||||
|
||||
BINARY := onlpdump
|
||||
$(BINARY)_LIBRARIES := $(LIBRARY_TARGETS)
|
||||
include $(BUILDER)/bin.mk
|
||||
|
||||
GLOBAL_CFLAGS += -DAIM_CONFIG_AIM_MAIN_FUNCTION=onlpdump_main
|
||||
GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MODULES_INIT=1
|
||||
GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MAIN=1
|
||||
GLOBAL_LINK_LIBS += -lpthread -lm
|
||||
|
||||
include $(BUILDER)/targets.mk
|
||||
|
||||
1
packages/platforms/accton/x86-64/x86-64-accton-as9716_32d/onlp/builds/src/.gitignore
vendored
Executable file
1
packages/platforms/accton/x86-64/x86-64-accton-as9716_32d/onlp/builds/src/.gitignore
vendored
Executable file
@@ -0,0 +1 @@
|
||||
*.mk
|
||||
@@ -0,0 +1 @@
|
||||
name: x86_64_accton_as9716_32d
|
||||
@@ -0,0 +1,9 @@
|
||||
###############################################################################
|
||||
#
|
||||
#
|
||||
#
|
||||
###############################################################################
|
||||
include $(ONL)/make/config.mk
|
||||
MODULE := x86_64_accton_as9716_32d
|
||||
AUTOMODULE := x86_64_accton_as9716_32d
|
||||
include $(BUILDER)/definemodule.mk
|
||||
@@ -0,0 +1,6 @@
|
||||
###############################################################################
|
||||
#
|
||||
# x86_64_accton_as9716_32x README
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
###############################################################################
|
||||
#
|
||||
# x86_64_accton_as9716_32d Autogeneration Definitions.
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
cdefs: &cdefs
|
||||
- X86_64_ACCTON_AS9716_32D_CONFIG_INCLUDE_LOGGING:
|
||||
doc: "Include or exclude logging."
|
||||
default: 1
|
||||
- X86_64_ACCTON_AS9716_32D_CONFIG_LOG_OPTIONS_DEFAULT:
|
||||
doc: "Default enabled log options."
|
||||
default: AIM_LOG_OPTIONS_DEFAULT
|
||||
- X86_64_ACCTON_AS9716_32D_CONFIG_LOG_BITS_DEFAULT:
|
||||
doc: "Default enabled log bits."
|
||||
default: AIM_LOG_BITS_DEFAULT
|
||||
- X86_64_ACCTON_AS9716_32D_CONFIG_LOG_CUSTOM_BITS_DEFAULT:
|
||||
doc: "Default enabled custom log bits."
|
||||
default: 0
|
||||
- X86_64_ACCTON_AS9716_32D_CONFIG_PORTING_STDLIB:
|
||||
doc: "Default all porting macros to use the C standard libraries."
|
||||
default: 1
|
||||
- X86_64_ACCTON_AS9716_32D_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS:
|
||||
doc: "Include standard library headers for stdlib porting macros."
|
||||
default: X86_64_ACCTON_AS9716_32D_CONFIG_PORTING_STDLIB
|
||||
- X86_64_ACCTON_AS9716_32D_CONFIG_INCLUDE_UCLI:
|
||||
doc: "Include generic uCli support."
|
||||
default: 0
|
||||
- X86_64_ACCTON_AS9716_32D_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION:
|
||||
doc: "Assume chassis fan direction is the same as the PSU fan direction."
|
||||
default: 0
|
||||
|
||||
|
||||
definitions:
|
||||
cdefs:
|
||||
X86_64_ACCTON_AS9716_32D_CONFIG_HEADER:
|
||||
defs: *cdefs
|
||||
basename: x86_64_accton_as9716_32d_config
|
||||
|
||||
portingmacro:
|
||||
x86_64_accton_as9716_32d:
|
||||
macros:
|
||||
- malloc
|
||||
- free
|
||||
- memset
|
||||
- memcpy
|
||||
- strncpy
|
||||
- vsnprintf
|
||||
- snprintf
|
||||
- strlen
|
||||
@@ -0,0 +1,14 @@
|
||||
/**************************************************************************//**
|
||||
*
|
||||
*
|
||||
*
|
||||
*****************************************************************************/
|
||||
#include <x86_64_accton_as9716_32d/x86_64_accton_as9716_32d_config.h>
|
||||
|
||||
/* <--auto.start.xmacro(ALL).define> */
|
||||
/* <auto.end.xmacro(ALL).define> */
|
||||
|
||||
/* <--auto.start.xenum(ALL).define> */
|
||||
/* <auto.end.xenum(ALL).define> */
|
||||
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
/**************************************************************************//**
|
||||
*
|
||||
* @file
|
||||
* @brief x86_64_accton_as9716_32d Configuration Header
|
||||
*
|
||||
* @addtogroup x86_64_accton_as9716_32d-config
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
#ifndef __X86_64_ACCTON_AS9716_32D_CONFIG_H__
|
||||
#define __X86_64_ACCTON_AS9716_32D_CONFIG_H__
|
||||
|
||||
#ifdef GLOBAL_INCLUDE_CUSTOM_CONFIG
|
||||
#include <global_custom_config.h>
|
||||
#endif
|
||||
#ifdef X86_64_ACCTON_AS9716_32D_INCLUDE_CUSTOM_CONFIG
|
||||
#include <x86_64_accton_as9716_32d_custom_config.h>
|
||||
#endif
|
||||
|
||||
/* <auto.start.cdefs(X86_64_ACCTON_AS9716_32D_CONFIG_HEADER).header> */
|
||||
#include <AIM/aim.h>
|
||||
/**
|
||||
* X86_64_ACCTON_AS9716_32D_CONFIG_INCLUDE_LOGGING
|
||||
*
|
||||
* Include or exclude logging. */
|
||||
|
||||
|
||||
#ifndef X86_64_ACCTON_AS9716_32D_CONFIG_INCLUDE_LOGGING
|
||||
#define X86_64_ACCTON_AS9716_32D_CONFIG_INCLUDE_LOGGING 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* X86_64_ACCTON_AS9716_32D_CONFIG_LOG_OPTIONS_DEFAULT
|
||||
*
|
||||
* Default enabled log options. */
|
||||
|
||||
|
||||
#ifndef X86_64_ACCTON_AS9716_32D_CONFIG_LOG_OPTIONS_DEFAULT
|
||||
#define X86_64_ACCTON_AS9716_32D_CONFIG_LOG_OPTIONS_DEFAULT AIM_LOG_OPTIONS_DEFAULT
|
||||
#endif
|
||||
|
||||
/**
|
||||
* X86_64_ACCTON_AS9716_32D_CONFIG_LOG_BITS_DEFAULT
|
||||
*
|
||||
* Default enabled log bits. */
|
||||
|
||||
|
||||
#ifndef X86_64_ACCTON_AS9716_32D_CONFIG_LOG_BITS_DEFAULT
|
||||
#define X86_64_ACCTON_AS9716_32D_CONFIG_LOG_BITS_DEFAULT AIM_LOG_BITS_DEFAULT
|
||||
#endif
|
||||
|
||||
/**
|
||||
* X86_64_ACCTON_AS9716_32D_CONFIG_LOG_CUSTOM_BITS_DEFAULT
|
||||
*
|
||||
* Default enabled custom log bits. */
|
||||
|
||||
|
||||
#ifndef X86_64_ACCTON_AS9716_32D_CONFIG_LOG_CUSTOM_BITS_DEFAULT
|
||||
#define X86_64_ACCTON_AS9716_32D_CONFIG_LOG_CUSTOM_BITS_DEFAULT 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* X86_64_ACCTON_AS9716_32D_CONFIG_PORTING_STDLIB
|
||||
*
|
||||
* Default all porting macros to use the C standard libraries. */
|
||||
|
||||
|
||||
#ifndef X86_64_ACCTON_AS9716_32D_CONFIG_PORTING_STDLIB
|
||||
#define X86_64_ACCTON_AS9716_32D_CONFIG_PORTING_STDLIB 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* X86_64_ACCTON_AS9716_32D_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS
|
||||
*
|
||||
* Include standard library headers for stdlib porting macros. */
|
||||
|
||||
|
||||
#ifndef X86_64_ACCTON_AS9716_32D_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS
|
||||
#define X86_64_ACCTON_AS9716_32D_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS X86_64_ACCTON_AS9716_32D_CONFIG_PORTING_STDLIB
|
||||
#endif
|
||||
|
||||
/**
|
||||
* X86_64_ACCTON_AS9716_32D_CONFIG_INCLUDE_UCLI
|
||||
*
|
||||
* Include generic uCli support. */
|
||||
|
||||
|
||||
#ifndef X86_64_ACCTON_AS9716_32D_CONFIG_INCLUDE_UCLI
|
||||
#define X86_64_ACCTON_AS9716_32D_CONFIG_INCLUDE_UCLI 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* X86_64_ACCTON_AS9716_32D_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION
|
||||
*
|
||||
* Assume chassis fan direction is the same as the PSU fan direction. */
|
||||
|
||||
|
||||
#ifndef X86_64_ACCTON_AS9716_32D_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION
|
||||
#define X86_64_ACCTON_AS9716_32D_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION 0
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* All compile time options can be queried or displayed
|
||||
*/
|
||||
|
||||
/** Configuration settings structure. */
|
||||
typedef struct x86_64_accton_as9716_32d_config_settings_s {
|
||||
/** name */
|
||||
const char* name;
|
||||
/** value */
|
||||
const char* value;
|
||||
} x86_64_accton_as9716_32d_config_settings_t;
|
||||
|
||||
/** Configuration settings table. */
|
||||
/** x86_64_accton_as9716_32d_config_settings table. */
|
||||
extern x86_64_accton_as9716_32d_config_settings_t x86_64_accton_as9716_32d_config_settings[];
|
||||
|
||||
/**
|
||||
* @brief Lookup a configuration setting.
|
||||
* @param setting The name of the configuration option to lookup.
|
||||
*/
|
||||
const char* x86_64_accton_as9716_32d_config_lookup(const char* setting);
|
||||
|
||||
/**
|
||||
* @brief Show the compile-time configuration.
|
||||
* @param pvs The output stream.
|
||||
*/
|
||||
int x86_64_accton_as9716_32d_config_show(struct aim_pvs_s* pvs);
|
||||
|
||||
/* <auto.end.cdefs(X86_64_ACCTON_AS9716_32D_CONFIG_HEADER).header> */
|
||||
|
||||
#include "x86_64_accton_as9716_32d_porting.h"
|
||||
|
||||
#endif /* __X86_64_ACCTON_AS9716_32D_CONFIG_H__ */
|
||||
/* @} */
|
||||
@@ -0,0 +1,26 @@
|
||||
/**************************************************************************//**
|
||||
*
|
||||
* x86_64_accton_as9716_32d Doxygen Header
|
||||
*
|
||||
*****************************************************************************/
|
||||
#ifndef __X86_64_ACCTON_AS9716_32D_DOX_H__
|
||||
#define __X86_64_ACCTON_AS9716_32D_DOX_H__
|
||||
|
||||
/**
|
||||
* @defgroup x86_64_accton_as9716_32d x86_64_accton_as9716_32d - x86_64_accton_as9716_32d Description
|
||||
*
|
||||
|
||||
The documentation overview for this module should go here.
|
||||
|
||||
*
|
||||
* @{
|
||||
*
|
||||
* @defgroup x86_64_accton_as9716_32d-x86_64_accton_as9716_32d Public Interface
|
||||
* @defgroup x86_64_accton_as9716_32d-config Compile Time Configuration
|
||||
* @defgroup x86_64_accton_as9716_32d-porting Porting Macros
|
||||
*
|
||||
* @}
|
||||
*
|
||||
*/
|
||||
|
||||
#endif /* __X86_64_ACCTON_AS9716_32D_DOX_H__ */
|
||||
@@ -0,0 +1,107 @@
|
||||
/**************************************************************************//**
|
||||
*
|
||||
* @file
|
||||
* @brief x86_64_accton_as9716_32d Porting Macros.
|
||||
*
|
||||
* @addtogroup x86_64_accton_as9716_32d-porting
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
#ifndef __X86_64_ACCTON_AS9716_32D_PORTING_H__
|
||||
#define __X86_64_ACCTON_AS9716_32D_PORTING_H__
|
||||
|
||||
|
||||
/* <auto.start.portingmacro(ALL).define> */
|
||||
#if X86_64_ACCTON_AS9716_32D_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS == 1
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <memory.h>
|
||||
#endif
|
||||
|
||||
#ifndef X86_64_ACCTON_AS9716_32D_MALLOC
|
||||
#if defined(GLOBAL_MALLOC)
|
||||
#define X86_64_ACCTON_AS9716_32D_MALLOC GLOBAL_MALLOC
|
||||
#elif X86_64_ACCTON_AS9716_32D_CONFIG_PORTING_STDLIB == 1
|
||||
#define X86_64_ACCTON_AS9716_32D_MALLOC malloc
|
||||
#else
|
||||
#error The macro X86_64_ACCTON_AS9716_32D_MALLOC is required but cannot be defined.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef X86_64_ACCTON_AS9716_32D_FREE
|
||||
#if defined(GLOBAL_FREE)
|
||||
#define X86_64_ACCTON_AS9716_32D_FREE GLOBAL_FREE
|
||||
#elif X86_64_ACCTON_AS9716_32D_CONFIG_PORTING_STDLIB == 1
|
||||
#define X86_64_ACCTON_AS9716_32D_FREE free
|
||||
#else
|
||||
#error The macro X86_64_ACCTON_AS9716_32D_FREE is required but cannot be defined.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef X86_64_ACCTON_AS9716_32D_MEMSET
|
||||
#if defined(GLOBAL_MEMSET)
|
||||
#define X86_64_ACCTON_AS9716_32D_MEMSET GLOBAL_MEMSET
|
||||
#elif X86_64_ACCTON_AS9716_32D_CONFIG_PORTING_STDLIB == 1
|
||||
#define X86_64_ACCTON_AS9716_32D_MEMSET memset
|
||||
#else
|
||||
#error The macro X86_64_ACCTON_AS9716_32D_MEMSET is required but cannot be defined.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef X86_64_ACCTON_AS9716_32D_MEMCPY
|
||||
#if defined(GLOBAL_MEMCPY)
|
||||
#define X86_64_ACCTON_AS9716_32D_MEMCPY GLOBAL_MEMCPY
|
||||
#elif X86_64_ACCTON_AS9716_32D_CONFIG_PORTING_STDLIB == 1
|
||||
#define X86_64_ACCTON_AS9716_32D_MEMCPY memcpy
|
||||
#else
|
||||
#error The macro X86_64_ACCTON_AS9716_32D_MEMCPY is required but cannot be defined.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef X86_64_ACCTON_AS9716_32D_STRNCPY
|
||||
#if defined(GLOBAL_STRNCPY)
|
||||
#define X86_64_ACCTON_AS9716_32D_STRNCPY GLOBAL_STRNCPY
|
||||
#elif X86_64_ACCTON_AS9716_32D_CONFIG_PORTING_STDLIB == 1
|
||||
#define X86_64_ACCTON_AS9716_32D_STRNCPY strncpy
|
||||
#else
|
||||
#error The macro X86_64_ACCTON_AS9716_32D_STRNCPY is required but cannot be defined.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef X86_64_ACCTON_AS9716_32D_VSNPRINTF
|
||||
#if defined(GLOBAL_VSNPRINTF)
|
||||
#define X86_64_ACCTON_AS9716_32D_VSNPRINTF GLOBAL_VSNPRINTF
|
||||
#elif X86_64_ACCTON_AS9716_32D_CONFIG_PORTING_STDLIB == 1
|
||||
#define X86_64_ACCTON_AS9716_32D_VSNPRINTF vsnprintf
|
||||
#else
|
||||
#error The macro X86_64_ACCTON_AS9716_32D_VSNPRINTF is required but cannot be defined.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef X86_64_ACCTON_AS9716_32D_SNPRINTF
|
||||
#if defined(GLOBAL_SNPRINTF)
|
||||
#define X86_64_ACCTON_AS9716_32D_SNPRINTF GLOBAL_SNPRINTF
|
||||
#elif X86_64_ACCTON_AS9716_32D_CONFIG_PORTING_STDLIB == 1
|
||||
#define X86_64_ACCTON_AS9716_32D_SNPRINTF snprintf
|
||||
#else
|
||||
#error The macro X86_64_ACCTON_AS9716_32D_SNPRINTF is required but cannot be defined.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef X86_64_ACCTON_AS9716_32D_STRLEN
|
||||
#if defined(GLOBAL_STRLEN)
|
||||
#define X86_64_ACCTON_AS9716_32D_STRLEN GLOBAL_STRLEN
|
||||
#elif X86_64_ACCTON_AS9716_32D_CONFIG_PORTING_STDLIB == 1
|
||||
#define X86_64_ACCTON_AS9716_32D_STRLEN strlen
|
||||
#else
|
||||
#error The macro X86_64_ACCTON_AS9716_32D_STRLEN is required but cannot be defined.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* <auto.end.portingmacro(ALL).define> */
|
||||
|
||||
|
||||
#endif /* __X86_64_ACCTON_AS9716_32D_PORTING_H__ */
|
||||
/* @} */
|
||||
@@ -0,0 +1,9 @@
|
||||
###############################################################################
|
||||
#
|
||||
# Local source generation targets.
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
ucli:
|
||||
@../../../../tools/uclihandlers.py x86_64_accton_as9716_32d_ucli.c
|
||||
|
||||
@@ -0,0 +1,367 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014 Big Switch Networks, Inc.
|
||||
* Copyright 2014 Accton Technology Corporation.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
* Fan Platform Implementation Defaults.
|
||||
*
|
||||
***********************************************************/
|
||||
#include <onlp/platformi/fani.h>
|
||||
#include "platform_lib.h"
|
||||
|
||||
#define PSU_PREFIX_PATH "/sys/bus/i2c/devices/"
|
||||
|
||||
#define MAX_FAN_SPEED 25500
|
||||
#define MAX_PSU_FAN_SPEED 25500
|
||||
|
||||
enum fan_id {
|
||||
FAN_1_ON_FAN_BOARD = 1,
|
||||
FAN_2_ON_FAN_BOARD,
|
||||
FAN_3_ON_FAN_BOARD,
|
||||
FAN_4_ON_FAN_BOARD,
|
||||
FAN_5_ON_FAN_BOARD,
|
||||
FAN_6_ON_FAN_BOARD,
|
||||
FAN_1_ON_PSU_1,
|
||||
FAN_1_ON_PSU_2,
|
||||
};
|
||||
|
||||
#define CHASSIS_FAN_INFO(fid) \
|
||||
{ \
|
||||
{ ONLP_FAN_ID_CREATE(FAN_##fid##_ON_FAN_BOARD), "Chassis Fan - "#fid, 0 },\
|
||||
0x0,\
|
||||
ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE,\
|
||||
0,\
|
||||
0,\
|
||||
ONLP_FAN_MODE_INVALID,\
|
||||
}
|
||||
|
||||
#define PSU_FAN_INFO(pid, fid) \
|
||||
{ \
|
||||
{ ONLP_FAN_ID_CREATE(FAN_##fid##_ON_PSU_##pid), "PSU "#pid" - Fan "#fid, 0 },\
|
||||
0x0,\
|
||||
ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE,\
|
||||
0,\
|
||||
0,\
|
||||
ONLP_FAN_MODE_INVALID,\
|
||||
}
|
||||
|
||||
/* Static fan information */
|
||||
onlp_fan_info_t finfo[] = {
|
||||
{ }, /* Not used */
|
||||
CHASSIS_FAN_INFO(1),
|
||||
CHASSIS_FAN_INFO(2),
|
||||
CHASSIS_FAN_INFO(3),
|
||||
CHASSIS_FAN_INFO(4),
|
||||
CHASSIS_FAN_INFO(5),
|
||||
CHASSIS_FAN_INFO(6),
|
||||
PSU_FAN_INFO(1,1),
|
||||
PSU_FAN_INFO(2,1)
|
||||
};
|
||||
|
||||
#define VALIDATE(_id) \
|
||||
do { \
|
||||
if(!ONLP_OID_IS_FAN(_id)) { \
|
||||
return ONLP_STATUS_E_INVALID; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
static int
|
||||
_onlp_fani_info_get_fan(int fid, onlp_fan_info_t* info)
|
||||
{
|
||||
int value;
|
||||
char path[64] = {0};
|
||||
|
||||
/* get fan present status
|
||||
*/
|
||||
sprintf(path, "%s""fan%d_present", FAN_BOARD_PATH, fid);
|
||||
DEBUG_PRINT("Fan(%d), present path = (%s)", fid, path);
|
||||
|
||||
if (onlp_file_read_int(&value, path) < 0) {
|
||||
AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
if (value == 0) {
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
info->status |= ONLP_FAN_STATUS_PRESENT;
|
||||
|
||||
|
||||
/* get fan fault status (turn on when any one fails)
|
||||
*/
|
||||
sprintf(path, "%s""fan%d_fault", FAN_BOARD_PATH, fid);
|
||||
DEBUG_PRINT("Fan(%d), fault path = (%s)", fid, path);
|
||||
|
||||
if (onlp_file_read_int(&value, path) < 0) {
|
||||
AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
if (value > 0) {
|
||||
info->status |= ONLP_FAN_STATUS_FAILED;
|
||||
}
|
||||
|
||||
|
||||
/* get fan direction (both : the same)
|
||||
*/
|
||||
sprintf(path, "%s""fan%d_direction", FAN_BOARD_PATH, fid);
|
||||
DEBUG_PRINT("Fan(%d), direction path = (%s)", fid, path);
|
||||
|
||||
if (onlp_file_read_int(&value, path) < 0) {
|
||||
AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
info->status |= value ? ONLP_FAN_STATUS_F2B : ONLP_FAN_STATUS_B2F;
|
||||
|
||||
|
||||
/* get front fan speed
|
||||
*/
|
||||
sprintf(path, "%s""fan%d_front_speed_rpm", FAN_BOARD_PATH, fid);
|
||||
DEBUG_PRINT("Fan (%d), front speed path = (%s)", fid, path);
|
||||
|
||||
if (onlp_file_read_int(&value, path) < 0) {
|
||||
AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
info->rpm = value;
|
||||
|
||||
/* get rear fan speed
|
||||
*/
|
||||
sprintf(path, "%s""fan%d_rear_speed_rpm", FAN_BOARD_PATH, fid);
|
||||
DEBUG_PRINT("Fan (%d), rear speed path = (%s)", fid, path);
|
||||
|
||||
if (onlp_file_read_int(&value, path) < 0) {
|
||||
AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
/* take the min value from front/rear fan speed
|
||||
*/
|
||||
if (info->rpm > value) {
|
||||
info->rpm = value;
|
||||
}
|
||||
|
||||
/* get speed percentage from rpm
|
||||
*/
|
||||
info->percentage = (info->rpm * 100)/MAX_FAN_SPEED;
|
||||
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
_onlp_get_fan_direction_on_psu(void)
|
||||
{
|
||||
/* Try to read direction from PSU1.
|
||||
* If PSU1 is not valid, read from PSU2
|
||||
*/
|
||||
int i = 0;
|
||||
|
||||
for (i = PSU1_ID; i <= PSU2_ID; i++) {
|
||||
psu_type_t psu_type;
|
||||
psu_type = get_psu_type(i, NULL, 0);
|
||||
|
||||
if (psu_type == PSU_TYPE_UNKNOWN) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (PSU_TYPE_AC_F2B == psu_type) {
|
||||
return ONLP_FAN_STATUS_F2B;
|
||||
}
|
||||
else {
|
||||
return ONLP_FAN_STATUS_B2F;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
_onlp_fani_info_get_fan_on_psu(int pid, onlp_fan_info_t* info)
|
||||
{
|
||||
int val = 0;
|
||||
|
||||
info->status |= ONLP_FAN_STATUS_PRESENT;
|
||||
|
||||
/* get fan direction
|
||||
*/
|
||||
info->status |= _onlp_get_fan_direction_on_psu();
|
||||
|
||||
/* get fan fault status
|
||||
*/
|
||||
if (psu_ym2651y_pmbus_info_get(pid, "psu_fan1_fault", &val) == ONLP_STATUS_OK) {
|
||||
info->status |= (val > 0) ? ONLP_FAN_STATUS_FAILED : 0;
|
||||
}
|
||||
|
||||
/* get fan speed
|
||||
*/
|
||||
if (psu_ym2651y_pmbus_info_get(pid, "psu_fan1_speed_rpm", &val) == ONLP_STATUS_OK) {
|
||||
info->rpm = val;
|
||||
info->percentage = (info->rpm * 100) / MAX_PSU_FAN_SPEED;
|
||||
}
|
||||
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function will be called prior to all of onlp_fani_* functions.
|
||||
*/
|
||||
int
|
||||
onlp_fani_init(void)
|
||||
{
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_fani_info_get(onlp_oid_t id, onlp_fan_info_t* info)
|
||||
{
|
||||
int rc = 0;
|
||||
int fid;
|
||||
VALIDATE(id);
|
||||
|
||||
fid = ONLP_OID_ID_GET(id);
|
||||
*info = finfo[fid];
|
||||
|
||||
switch (fid)
|
||||
{
|
||||
case FAN_1_ON_PSU_1:
|
||||
rc = _onlp_fani_info_get_fan_on_psu(PSU1_ID, info);
|
||||
break;
|
||||
case FAN_1_ON_PSU_2:
|
||||
rc = _onlp_fani_info_get_fan_on_psu(PSU2_ID, info);
|
||||
break;
|
||||
case FAN_1_ON_FAN_BOARD:
|
||||
case FAN_2_ON_FAN_BOARD:
|
||||
case FAN_3_ON_FAN_BOARD:
|
||||
case FAN_4_ON_FAN_BOARD:
|
||||
case FAN_5_ON_FAN_BOARD:
|
||||
case FAN_6_ON_FAN_BOARD:
|
||||
rc =_onlp_fani_info_get_fan(fid, info);
|
||||
break;
|
||||
default:
|
||||
rc = ONLP_STATUS_E_INVALID;
|
||||
break;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function sets the speed of the given fan in RPM.
|
||||
*
|
||||
* This function will only be called if the fan supprots the RPM_SET
|
||||
* capability.
|
||||
*
|
||||
* It is optional if you have no fans at all with this feature.
|
||||
*/
|
||||
int
|
||||
onlp_fani_rpm_set(onlp_oid_t id, int rpm)
|
||||
{
|
||||
return ONLP_STATUS_E_UNSUPPORTED;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function sets the fan speed of the given OID as a percentage.
|
||||
*
|
||||
* This will only be called if the OID has the PERCENTAGE_SET
|
||||
* capability.
|
||||
*
|
||||
* It is optional if you have no fans at all with this feature.
|
||||
*/
|
||||
int
|
||||
onlp_fani_percentage_set(onlp_oid_t id, int p)
|
||||
{
|
||||
int fid;
|
||||
char *path = NULL;
|
||||
|
||||
VALIDATE(id);
|
||||
|
||||
fid = ONLP_OID_ID_GET(id);
|
||||
|
||||
/* reject p=0 (p=0, stop fan) */
|
||||
if (p == 0){
|
||||
return ONLP_STATUS_E_INVALID;
|
||||
}
|
||||
|
||||
switch (fid)
|
||||
{
|
||||
case FAN_1_ON_PSU_1:
|
||||
return psu_ym2651y_pmbus_info_set(PSU1_ID, "psu_fan_duty_cycle_percentage", p);
|
||||
case FAN_1_ON_PSU_2:
|
||||
return psu_ym2651y_pmbus_info_set(PSU2_ID, "psu_fan_duty_cycle_percentage", p);
|
||||
case FAN_1_ON_FAN_BOARD:
|
||||
case FAN_2_ON_FAN_BOARD:
|
||||
case FAN_3_ON_FAN_BOARD:
|
||||
case FAN_4_ON_FAN_BOARD:
|
||||
case FAN_5_ON_FAN_BOARD:
|
||||
case FAN_6_ON_FAN_BOARD:
|
||||
path = FAN_NODE(fan_duty_cycle_percentage);
|
||||
break;
|
||||
default:
|
||||
return ONLP_STATUS_E_INVALID;
|
||||
}
|
||||
|
||||
DEBUG_PRINT("Fan path = (%s)", path);
|
||||
|
||||
if (onlp_file_write_integer(path, p) < 0) {
|
||||
AIM_LOG_ERROR("Unable to write data to file (%s)\r\n", path);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* This function sets the fan speed of the given OID as per
|
||||
* the predefined ONLP fan speed modes: off, slow, normal, fast, max.
|
||||
*
|
||||
* Interpretation of these modes is up to the platform.
|
||||
*
|
||||
*/
|
||||
int
|
||||
onlp_fani_mode_set(onlp_oid_t id, onlp_fan_mode_t mode)
|
||||
{
|
||||
return ONLP_STATUS_E_UNSUPPORTED;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function sets the fan direction of the given OID.
|
||||
*
|
||||
* This function is only relevant if the fan OID supports both direction
|
||||
* capabilities.
|
||||
*
|
||||
* This function is optional unless the functionality is available.
|
||||
*/
|
||||
int
|
||||
onlp_fani_dir_set(onlp_oid_t id, onlp_fan_dir_t dir)
|
||||
{
|
||||
return ONLP_STATUS_E_UNSUPPORTED;
|
||||
}
|
||||
|
||||
/*
|
||||
* Generic fan ioctl. Optional.
|
||||
*/
|
||||
int
|
||||
onlp_fani_ioctl(onlp_oid_t id, va_list vargs)
|
||||
{
|
||||
return ONLP_STATUS_E_UNSUPPORTED;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,273 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014 Big Switch Networks, Inc.
|
||||
* Copyright 2014 Accton Technology Corporation.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
*
|
||||
*
|
||||
***********************************************************/
|
||||
#include <onlp/platformi/ledi.h>
|
||||
#include <sys/mman.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <onlplib/mmap.h>
|
||||
|
||||
#include "platform_lib.h"
|
||||
|
||||
#define prefix_path "/sys/class/leds/accton_as9716_32d_led::"
|
||||
#define filename "brightness"
|
||||
|
||||
#define VALIDATE(_id) \
|
||||
do { \
|
||||
if(!ONLP_OID_IS_LED(_id)) { \
|
||||
return ONLP_STATUS_E_INVALID; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
/* LED related data
|
||||
*/
|
||||
enum onlp_led_id
|
||||
{
|
||||
LED_RESERVED = 0,
|
||||
LED_DIAG,
|
||||
LED_LOC,
|
||||
LED_FAN,
|
||||
LED_PSU1,
|
||||
LED_PSU2
|
||||
};
|
||||
|
||||
enum led_light_mode {
|
||||
LED_MODE_OFF = 0,
|
||||
LED_MODE_GREEN,
|
||||
LED_MODE_AMBER,
|
||||
LED_MODE_RED,
|
||||
LED_MODE_BLUE,
|
||||
LED_MODE_GREEN_BLINK,
|
||||
LED_MODE_AMBER_BLINK,
|
||||
LED_MODE_RED_BLINK,
|
||||
LED_MODE_BLUE_BLINK,
|
||||
LED_MODE_AUTO,
|
||||
LED_MODE_UNKNOWN
|
||||
};
|
||||
|
||||
typedef struct led_light_mode_map {
|
||||
enum onlp_led_id id;
|
||||
enum led_light_mode driver_led_mode;
|
||||
enum onlp_led_mode_e onlp_led_mode;
|
||||
} led_light_mode_map_t;
|
||||
|
||||
led_light_mode_map_t led_map[] = {
|
||||
{LED_DIAG, LED_MODE_OFF, ONLP_LED_MODE_OFF},
|
||||
{LED_DIAG, LED_MODE_GREEN, ONLP_LED_MODE_GREEN},
|
||||
{LED_DIAG, LED_MODE_AMBER, ONLP_LED_MODE_ORANGE},
|
||||
{LED_DIAG, LED_MODE_GREEN_BLINK, ONLP_LED_MODE_GREEN_BLINKING},
|
||||
|
||||
{LED_LOC, LED_MODE_OFF, ONLP_LED_MODE_OFF},
|
||||
{LED_LOC, LED_MODE_AMBER, ONLP_LED_MODE_ORANGE},
|
||||
{LED_LOC, LED_MODE_GREEN_BLINK, ONLP_LED_MODE_GREEN_BLINKING},
|
||||
|
||||
|
||||
{LED_FAN, LED_MODE_OFF, ONLP_LED_MODE_OFF},
|
||||
{LED_FAN, LED_MODE_AMBER, ONLP_LED_MODE_GREEN},
|
||||
{LED_FAN, LED_MODE_GREEN, ONLP_LED_MODE_ORANGE},
|
||||
|
||||
{LED_PSU1, LED_MODE_OFF, ONLP_LED_MODE_OFF},
|
||||
{LED_PSU1, LED_MODE_AMBER, ONLP_LED_MODE_GREEN},
|
||||
{LED_PSU1, LED_MODE_GREEN, ONLP_LED_MODE_ORANGE},
|
||||
|
||||
{LED_PSU2, LED_MODE_OFF, ONLP_LED_MODE_OFF},
|
||||
{LED_PSU2, LED_MODE_AMBER, ONLP_LED_MODE_GREEN},
|
||||
{LED_PSU2, LED_MODE_GREEN, ONLP_LED_MODE_ORANGE}
|
||||
};
|
||||
|
||||
static char last_path[][10] = /* must map with onlp_led_id */
|
||||
{
|
||||
"reserved",
|
||||
"diag",
|
||||
"loc",
|
||||
"fan",
|
||||
"psu1",
|
||||
"psu2"
|
||||
};
|
||||
|
||||
/*
|
||||
* Get the information for the given LED OID.
|
||||
*/
|
||||
static onlp_led_info_t linfo[] =
|
||||
{
|
||||
{ }, /* Not used */
|
||||
{
|
||||
{ ONLP_LED_ID_CREATE(LED_DIAG), "LED 1 (DIAG LED)", 0 },
|
||||
ONLP_LED_STATUS_PRESENT,
|
||||
ONLP_LED_CAPS_ON_OFF |ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_GREEN_BLINKING,
|
||||
},
|
||||
{
|
||||
{ ONLP_LED_ID_CREATE(LED_LOC), "LED 2 (LOC LED)", 0 },
|
||||
ONLP_LED_STATUS_PRESENT,
|
||||
ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_GREEN_BLINKING,
|
||||
},
|
||||
{
|
||||
{ ONLP_LED_ID_CREATE(LED_FAN), "LED 3 (FAN LED)", 0 },
|
||||
ONLP_LED_STATUS_PRESENT,
|
||||
ONLP_LED_CAPS_ON_OFF |ONLP_LED_CAPS_GREEN| ONLP_LED_CAPS_ORANGE ,
|
||||
},
|
||||
{
|
||||
{ ONLP_LED_ID_CREATE(LED_PSU1), "LED 4 (PSU1 LED)", 0 },
|
||||
ONLP_LED_STATUS_PRESENT,
|
||||
ONLP_LED_CAPS_ON_OFF |ONLP_LED_CAPS_GREEN| ONLP_LED_CAPS_ORANGE ,
|
||||
},
|
||||
{
|
||||
{ ONLP_LED_ID_CREATE(LED_PSU2), "LED 4 (PSU2 LED)", 0 },
|
||||
ONLP_LED_STATUS_PRESENT,
|
||||
ONLP_LED_CAPS_ON_OFF |ONLP_LED_CAPS_GREEN| ONLP_LED_CAPS_ORANGE ,
|
||||
},
|
||||
};
|
||||
|
||||
static int driver_to_onlp_led_mode(enum onlp_led_id id, enum led_light_mode driver_led_mode)
|
||||
{
|
||||
int i, nsize = sizeof(led_map)/sizeof(led_map[0]);
|
||||
|
||||
for (i = 0; i < nsize; i++)
|
||||
{
|
||||
if (id == led_map[i].id && driver_led_mode == led_map[i].driver_led_mode)
|
||||
{
|
||||
return led_map[i].onlp_led_mode;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int onlp_to_driver_led_mode(enum onlp_led_id id, onlp_led_mode_t onlp_led_mode)
|
||||
{
|
||||
int i, nsize = sizeof(led_map)/sizeof(led_map[0]);
|
||||
|
||||
for(i = 0; i < nsize; i++)
|
||||
{
|
||||
if (id == led_map[i].id && onlp_led_mode == led_map[i].onlp_led_mode)
|
||||
{
|
||||
return led_map[i].driver_led_mode;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function will be called prior to any other onlp_ledi_* functions.
|
||||
*/
|
||||
int
|
||||
onlp_ledi_init(void)
|
||||
{
|
||||
onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_DIAG), ONLP_LED_MODE_OFF);
|
||||
onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_LOC), ONLP_LED_MODE_OFF);
|
||||
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info)
|
||||
{
|
||||
int local_id;
|
||||
char data[2] = {0};
|
||||
char fullpath[50] = {0};
|
||||
|
||||
VALIDATE(id);
|
||||
|
||||
local_id = ONLP_OID_ID_GET(id);
|
||||
|
||||
/* get fullpath */
|
||||
sprintf(fullpath, "%s%s/%s", prefix_path, last_path[local_id], filename);
|
||||
|
||||
/* Set the onlp_oid_hdr_t and capabilities */
|
||||
*info = linfo[ONLP_OID_ID_GET(id)];
|
||||
|
||||
/* Set LED mode */
|
||||
if (onlp_file_read_string(fullpath, data, sizeof(data), 0) != 0) {
|
||||
DEBUG_PRINT("%s(%d)\r\n", __FUNCTION__, __LINE__);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
info->mode = driver_to_onlp_led_mode(local_id, atoi(data));
|
||||
|
||||
/* Set the on/off status */
|
||||
if (info->mode != ONLP_LED_MODE_OFF) {
|
||||
info->status |= ONLP_LED_STATUS_ON;
|
||||
}
|
||||
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Turn an LED on or off.
|
||||
*
|
||||
* This function will only be called if the LED OID supports the ONOFF
|
||||
* capability.
|
||||
*
|
||||
* What 'on' means in terms of colors or modes for multimode LEDs is
|
||||
* up to the platform to decide. This is intended as baseline toggle mechanism.
|
||||
*/
|
||||
int
|
||||
onlp_ledi_set(onlp_oid_t id, int on_or_off)
|
||||
{
|
||||
VALIDATE(id);
|
||||
|
||||
if (!on_or_off) {
|
||||
return onlp_ledi_mode_set(id, ONLP_LED_MODE_OFF);
|
||||
}
|
||||
|
||||
return ONLP_STATUS_E_UNSUPPORTED;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function puts the LED into the given mode. It is a more functional
|
||||
* interface for multimode LEDs.
|
||||
*
|
||||
* Only modes reported in the LED's capabilities will be attempted.
|
||||
*/
|
||||
int
|
||||
onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode)
|
||||
{
|
||||
int local_id;
|
||||
char fullpath[50] = {0};
|
||||
|
||||
VALIDATE(id);
|
||||
|
||||
local_id = ONLP_OID_ID_GET(id);
|
||||
sprintf(fullpath, "%s%s/%s", prefix_path, last_path[local_id], filename);
|
||||
|
||||
if (onlp_file_write_integer(fullpath, onlp_to_driver_led_mode(local_id, mode)) != 0)
|
||||
{
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Generic LED ioctl interface.
|
||||
*/
|
||||
int
|
||||
onlp_ledi_ioctl(onlp_oid_t id, va_list vargs)
|
||||
{
|
||||
return ONLP_STATUS_E_UNSUPPORTED;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,219 @@
|
||||
#include <onlp/onlp.h>
|
||||
#include <onlplib/file.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include "platform_lib.h"
|
||||
#include <onlp/platformi/sfpi.h>
|
||||
#include "x86_64_accton_as9716_32d_log.h"
|
||||
|
||||
|
||||
static int _onlp_file_write(char *filename, char *buffer, int buf_size, int data_len)
|
||||
{
|
||||
int fd;
|
||||
int len;
|
||||
|
||||
if ((buffer == NULL) || (buf_size < 0)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((fd = open(filename, O_WRONLY, S_IWUSR)) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((len = write(fd, buffer, buf_size)) < 0) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((close(fd) == -1)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((len > buf_size) || (data_len != 0 && len != data_len)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int onlp_file_write_integer(char *filename, int value)
|
||||
{
|
||||
char buf[8] = {0};
|
||||
sprintf(buf, "%d", value);
|
||||
|
||||
return _onlp_file_write(filename, buf, (int)strlen(buf), 0);
|
||||
}
|
||||
|
||||
int onlp_file_read_binary(char *filename, char *buffer, int buf_size, int data_len)
|
||||
{
|
||||
int fd;
|
||||
int len;
|
||||
|
||||
if ((buffer == NULL) || (buf_size < 0)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((fd = open(filename, O_RDONLY)) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((len = read(fd, buffer, buf_size)) < 0) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((close(fd) == -1)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((len > buf_size) || (data_len != 0 && len != data_len)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int onlp_file_read_string(char *filename, char *buffer, int buf_size, int data_len)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (data_len >= buf_size) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = onlp_file_read_binary(filename, buffer, buf_size-1, data_len);
|
||||
|
||||
if (ret == 0) {
|
||||
buffer[buf_size-1] = '\0';
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define I2C_PSU_MODEL_NAME_LEN 9
|
||||
#define I2C_PSU_FAN_DIR_LEN 3
|
||||
|
||||
psu_type_t get_psu_type(int id, char* modelname, int modelname_len)
|
||||
{
|
||||
char *node = NULL;
|
||||
char model_name[I2C_PSU_MODEL_NAME_LEN + 1] = {0};
|
||||
|
||||
/* Check model name */
|
||||
node = (id == PSU1_ID) ? PSU1_AC_PMBUS_NODE(psu_mfr_model) : PSU2_AC_PMBUS_NODE(psu_mfr_model);
|
||||
memset(model_name, 0x0, I2C_PSU_MODEL_NAME_LEN + 1);
|
||||
memset(modelname, 0x0, modelname_len);
|
||||
if (onlp_file_read_string(node, model_name, sizeof(model_name), 0) != 0) {
|
||||
|
||||
return PSU_TYPE_UNKNOWN;
|
||||
}
|
||||
|
||||
if (!strncmp(model_name, "FSH082", strlen("FSH082")))
|
||||
{
|
||||
if (modelname)
|
||||
strncpy(modelname, model_name, strlen("FSH082")<(modelname_len-1)?strlen("FSH082"):(modelname_len-1));
|
||||
|
||||
return PSU_TYPE_ACBEL;
|
||||
}
|
||||
if (!strncmp(model_name, "YM-2651Y", strlen("YM-2651Y")))
|
||||
{
|
||||
if (modelname)
|
||||
strncpy(modelname, model_name, modelname_len-1);
|
||||
return PSU_TYPE_YM2651Y;
|
||||
}
|
||||
|
||||
return PSU_TYPE_UNKNOWN;
|
||||
}
|
||||
int
|
||||
psu_pmbus_info_get(int id, char *node, int *value)
|
||||
{
|
||||
int ret = 0;
|
||||
char path[PSU_NODE_MAX_PATH_LEN] = {0};
|
||||
|
||||
*value = 0;
|
||||
|
||||
if (PSU1_ID == id) {
|
||||
sprintf(path, "%s%s", PSU1_AC_PMBUS_PREFIX, node);
|
||||
}
|
||||
else {
|
||||
sprintf(path, "%s%s", PSU2_AC_PMBUS_PREFIX, node);
|
||||
}
|
||||
|
||||
if (onlp_file_read_int(value, path) < 0) {
|
||||
AIM_LOG_ERROR("Unable to read status from file(%s)\r\n", path);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int psu_ym2651y_pmbus_info_get(int id, char *node, int *value)
|
||||
{
|
||||
int ret = 0;
|
||||
char path[PSU_NODE_MAX_PATH_LEN] = {0};
|
||||
|
||||
*value = 0;
|
||||
|
||||
if (PSU1_ID == id) {
|
||||
sprintf(path, "%s%s", PSU1_AC_PMBUS_PREFIX, node);
|
||||
}
|
||||
else {
|
||||
sprintf(path, "%s%s", PSU2_AC_PMBUS_PREFIX, node);
|
||||
}
|
||||
|
||||
if (onlp_file_read_int(value, path) < 0) {
|
||||
AIM_LOG_ERROR("Unable to read status from file(%s)\r\n", path);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int psu_ym2651y_pmbus_info_set(int id, char *node, int value)
|
||||
{
|
||||
char path[PSU_NODE_MAX_PATH_LEN] = {0};
|
||||
|
||||
switch (id) {
|
||||
case PSU1_ID:
|
||||
sprintf(path, "%s%s", PSU1_AC_PMBUS_PREFIX, node);
|
||||
break;
|
||||
case PSU2_ID:
|
||||
sprintf(path, "%s%s", PSU2_AC_PMBUS_PREFIX, node);
|
||||
break;
|
||||
default:
|
||||
return ONLP_STATUS_E_UNSUPPORTED;
|
||||
};
|
||||
|
||||
if (onlp_file_write_integer(path, value) < 0) {
|
||||
AIM_LOG_ERROR("Unable to write data to file (%s)\r\n", path);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
#define PSU_SERIAL_NUMBER_LEN 19
|
||||
|
||||
int psu_serial_number_get(int id, char *serial, int serial_len)
|
||||
{
|
||||
int size = 0;
|
||||
int ret = ONLP_STATUS_OK;
|
||||
char *prefix = NULL;
|
||||
|
||||
if (serial == NULL || serial_len < PSU_SERIAL_NUMBER_LEN) {
|
||||
return ONLP_STATUS_E_PARAM;
|
||||
}
|
||||
|
||||
prefix = (id == PSU1_ID) ? PSU1_AC_HWMON_PREFIX : PSU2_AC_HWMON_PREFIX;
|
||||
|
||||
ret = onlp_file_read((uint8_t*)serial, PSU_SERIAL_NUMBER_LEN, &size, "%s%s", prefix, "psu_serial_number");
|
||||
if (ret != ONLP_STATUS_OK || size != PSU_SERIAL_NUMBER_LEN) {
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
|
||||
}
|
||||
serial[PSU_SERIAL_NUMBER_LEN-1] = '\0';
|
||||
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014 Big Switch Networks, Inc.
|
||||
* Copyright 2014 Accton Technology Corporation.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
*
|
||||
*
|
||||
***********************************************************/
|
||||
#ifndef __PLATFORM_LIB_H__
|
||||
#define __PLATFORM_LIB_H__
|
||||
|
||||
#include <onlplib/file.h>
|
||||
#include "x86_64_accton_as9716_32d_log.h"
|
||||
|
||||
#define CHASSIS_FAN_COUNT 6
|
||||
#define CHASSIS_THERMAL_COUNT 8
|
||||
#define CHASSIS_PSU_COUNT 2
|
||||
#define CHASSIS_LED_COUNT 5
|
||||
|
||||
#define PSU1_ID 1
|
||||
#define PSU2_ID 2
|
||||
|
||||
#define PSU_NODE_MAX_INT_LEN 8
|
||||
#define PSU_NODE_MAX_PATH_LEN 64
|
||||
|
||||
#define PSU1_AC_PMBUS_PREFIX "/sys/bus/i2c/devices/10-0059/"
|
||||
#define PSU2_AC_PMBUS_PREFIX "/sys/bus/i2c/devices/9-0058/"
|
||||
|
||||
|
||||
#define PSU1_AC_PMBUS_NODE(node) PSU1_AC_PMBUS_PREFIX#node
|
||||
#define PSU2_AC_PMBUS_NODE(node) PSU2_AC_PMBUS_PREFIX#node
|
||||
|
||||
#define PSU1_AC_HWMON_PREFIX "/sys/bus/i2c/devices/10-0051/"
|
||||
#define PSU2_AC_HWMON_PREFIX "/sys/bus/i2c/devices/9-0050/"
|
||||
|
||||
|
||||
|
||||
#define PSU1_AC_HWMON_NODE(node) PSU1_AC_HWMON_PREFIX#node
|
||||
#define PSU2_AC_HWMON_NODE(node) PSU2_AC_HWMON_PREFIX#node
|
||||
|
||||
#define FAN_BOARD_PATH "/sys/bus/i2c/devices/17-0066/"
|
||||
#define FAN_NODE(node) FAN_BOARD_PATH#node
|
||||
|
||||
#define IDPROM_PATH "/sys/class/i2c-adapter/i2c-0/0-0056/eeprom"
|
||||
|
||||
int onlp_file_write_integer(char *filename, int value);
|
||||
int onlp_file_read_binary(char *filename, char *buffer, int buf_size, int data_len);
|
||||
int onlp_file_read_string(char *filename, char *buffer, int buf_size, int data_len);
|
||||
|
||||
int psu_pmbus_info_get(int id, char *node, int *value);
|
||||
int psu_ym2651y_pmbus_info_get(int id, char *node, int *value);
|
||||
int psu_ym2651y_pmbus_info_set(int id, char *node, int value);
|
||||
|
||||
typedef enum psu_type {
|
||||
PSU_TYPE_UNKNOWN,
|
||||
PSU_TYPE_ACBEL,
|
||||
PSU_TYPE_YM2651Y,
|
||||
PSU_TYPE_AC_F2B,
|
||||
PSU_TYPE_AC_B2F
|
||||
} psu_type_t;
|
||||
|
||||
psu_type_t get_psu_type(int id, char* modelname, int modelname_len);
|
||||
int psu_serial_number_get(int id, char *serial, int serial_len);
|
||||
|
||||
//#define DEBUG_MODE 1
|
||||
|
||||
#if (DEBUG_MODE == 1)
|
||||
#define DEBUG_PRINT(format, ...) printf(format, __VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_PRINT(format, ...)
|
||||
#endif
|
||||
|
||||
#endif /* __PLATFORM_LIB_H__ */
|
||||
|
||||
@@ -0,0 +1,245 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014 Big Switch Networks, Inc.
|
||||
* Copyright 2014 Accton Technology Corporation.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
*
|
||||
*
|
||||
***********************************************************/
|
||||
#include <onlp/platformi/psui.h>
|
||||
#include <onlplib/mmap.h>
|
||||
//#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "platform_lib.h"
|
||||
|
||||
#define PSU_STATUS_PRESENT 1
|
||||
#define PSU_STATUS_POWER_GOOD 1
|
||||
|
||||
|
||||
|
||||
#define VALIDATE(_id) \
|
||||
do { \
|
||||
if(!ONLP_OID_IS_PSU(_id)) { \
|
||||
return ONLP_STATUS_E_INVALID; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
static int
|
||||
psu_status_info_get(int id, char *node, int *value)
|
||||
{
|
||||
int ret = 0;
|
||||
char path[PSU_NODE_MAX_PATH_LEN] = {0};
|
||||
|
||||
*value = 0;
|
||||
|
||||
|
||||
if (PSU1_ID == id) {
|
||||
sprintf(path, "%s%s", PSU1_AC_HWMON_PREFIX, node);
|
||||
}
|
||||
else if (PSU2_ID == id) {
|
||||
sprintf(path, "%s%s", PSU2_AC_HWMON_PREFIX, node);
|
||||
}
|
||||
if (onlp_file_read_int(value, path) < 0) {
|
||||
AIM_LOG_ERROR("Unable to read status from file(%s)\r\n", path);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_psui_init(void)
|
||||
{
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
psu_ym2651y_info_get(onlp_psu_info_t* info)
|
||||
{
|
||||
int val = 0;
|
||||
int index = ONLP_OID_ID_GET(info->hdr.id);
|
||||
|
||||
/* Set capability
|
||||
*/
|
||||
info->caps = ONLP_PSU_CAPS_AC;
|
||||
|
||||
if (info->status & ONLP_PSU_STATUS_FAILED) {
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
/* Set the associated oid_table */
|
||||
info->hdr.coids[0] = ONLP_FAN_ID_CREATE(index + CHASSIS_FAN_COUNT);
|
||||
info->hdr.coids[1] = ONLP_THERMAL_ID_CREATE(index + CHASSIS_THERMAL_COUNT);
|
||||
|
||||
/* Read voltage, current and power */
|
||||
if (psu_ym2651y_pmbus_info_get(index, "psu_v_out", &val) == 0) {
|
||||
info->mvout = val;
|
||||
info->caps |= ONLP_PSU_CAPS_VOUT;
|
||||
}
|
||||
|
||||
if (psu_ym2651y_pmbus_info_get(index, "psu_i_out", &val) == 0) {
|
||||
info->miout = val;
|
||||
info->caps |= ONLP_PSU_CAPS_IOUT;
|
||||
}
|
||||
|
||||
if (psu_ym2651y_pmbus_info_get(index, "psu_p_out", &val) == 0) {
|
||||
info->mpout = val;
|
||||
info->caps |= ONLP_PSU_CAPS_POUT;
|
||||
}
|
||||
|
||||
psu_serial_number_get(index, info->serial, sizeof(info->serial));
|
||||
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int
|
||||
psu_data_info_get(onlp_psu_info_t* info)
|
||||
{
|
||||
int val = 0;
|
||||
int index = ONLP_OID_ID_GET(info->hdr.id);
|
||||
|
||||
/* Set capability
|
||||
*/
|
||||
info->caps = ONLP_PSU_CAPS_AC;
|
||||
|
||||
if (info->status & ONLP_PSU_STATUS_FAILED) {
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
/* Set the associated oid_table */
|
||||
info->hdr.coids[0] = ONLP_FAN_ID_CREATE(index + CHASSIS_FAN_COUNT);
|
||||
info->hdr.coids[1] = ONLP_THERMAL_ID_CREATE(index + CHASSIS_THERMAL_COUNT);
|
||||
|
||||
/* Read voltage, current and power */
|
||||
if (psu_pmbus_info_get(index, "psu_v_out", &val) == 0) {
|
||||
info->mvout = val;
|
||||
info->caps |= ONLP_PSU_CAPS_VOUT;
|
||||
}
|
||||
|
||||
if (psu_pmbus_info_get(index, "psu_v_in", &val) == 0) {
|
||||
info->mvin = val;
|
||||
info->caps |= ONLP_PSU_CAPS_VIN;
|
||||
}
|
||||
|
||||
if (psu_pmbus_info_get(index, "psu_i_out", &val) == 0) {
|
||||
info->miout = val;
|
||||
info->caps |= ONLP_PSU_CAPS_IOUT;
|
||||
}
|
||||
|
||||
if (psu_pmbus_info_get(index, "psu_i_in", &val) == 0) {
|
||||
info->miin = val;
|
||||
info->caps |= ONLP_PSU_CAPS_IIN;
|
||||
}
|
||||
|
||||
if (psu_pmbus_info_get(index, "psu_p_out", &val) == 0) {
|
||||
info->mpout = val;
|
||||
info->caps |= ONLP_PSU_CAPS_POUT;
|
||||
}
|
||||
|
||||
if (psu_pmbus_info_get(index, "psu_p_in", &val) == 0) {
|
||||
info->mpin = val;
|
||||
info->caps |= ONLP_PSU_CAPS_PIN;
|
||||
}
|
||||
psu_serial_number_get(index, info->serial, sizeof(info->serial));
|
||||
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Get all information about the given PSU oid.
|
||||
*/
|
||||
static onlp_psu_info_t pinfo[] =
|
||||
{
|
||||
{ }, /* Not used */
|
||||
{
|
||||
{ ONLP_PSU_ID_CREATE(PSU1_ID), "PSU-1", 0 },
|
||||
},
|
||||
{
|
||||
{ ONLP_PSU_ID_CREATE(PSU2_ID), "PSU-2", 0 },
|
||||
}
|
||||
};
|
||||
|
||||
int
|
||||
onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info)
|
||||
{
|
||||
int val = 0;
|
||||
int ret = ONLP_STATUS_OK;
|
||||
int index = ONLP_OID_ID_GET(id);
|
||||
psu_type_t psu_type;
|
||||
|
||||
VALIDATE(id);
|
||||
|
||||
memset(info, 0, sizeof(onlp_psu_info_t));
|
||||
*info = pinfo[index]; /* Set the onlp_oid_hdr_t */
|
||||
/* Get the present state */
|
||||
if (psu_status_info_get(index, "psu_present", &val) != 0) {
|
||||
AIM_LOG_ERROR("Unable to read PSU(%d) node(psu_present)\r\n", index);
|
||||
}
|
||||
|
||||
if (val != PSU_STATUS_PRESENT) {
|
||||
info->status &= ~ONLP_PSU_STATUS_PRESENT;
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
info->status |= ONLP_PSU_STATUS_PRESENT;
|
||||
|
||||
|
||||
/* Get power good status */
|
||||
if (psu_status_info_get(index, "psu_power_good", &val) != 0) {
|
||||
AIM_LOG_ERROR("Unable to read PSU(%d) node(psu_power_good)\r\n", index);
|
||||
}
|
||||
|
||||
if (val != PSU_STATUS_POWER_GOOD) {
|
||||
info->status |= ONLP_PSU_STATUS_FAILED;
|
||||
}
|
||||
|
||||
/* Get PSU type
|
||||
*/
|
||||
psu_type = get_psu_type(index, info->model, sizeof(info->model));
|
||||
|
||||
|
||||
switch (psu_type) {
|
||||
case PSU_TYPE_ACBEL:
|
||||
ret = psu_data_info_get(info);
|
||||
break;
|
||||
case PSU_TYPE_YM2651Y:
|
||||
ret = psu_ym2651y_info_get(info);
|
||||
break;
|
||||
case PSU_TYPE_UNKNOWN: /* User insert a unknown PSU or unplugged.*/
|
||||
info->status |= ONLP_PSU_STATUS_UNPLUGGED;
|
||||
info->status &= ~ONLP_PSU_STATUS_FAILED;
|
||||
ret = ONLP_STATUS_OK;
|
||||
break;
|
||||
default:
|
||||
ret = ONLP_STATUS_E_UNSUPPORTED;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_psui_ioctl(onlp_oid_t pid, va_list vargs)
|
||||
{
|
||||
return ONLP_STATUS_E_UNSUPPORTED;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,331 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014 Big Switch Networks, Inc.
|
||||
* Copyright 2013 Accton Technology Corporation.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
*
|
||||
*
|
||||
***********************************************************/
|
||||
#include <onlp/platformi/sfpi.h>
|
||||
#include <onlplib/i2c.h>
|
||||
#include <onlplib/file.h>
|
||||
#include "x86_64_accton_as9716_32d_int.h"
|
||||
#include "x86_64_accton_as9716_32d_log.h"
|
||||
|
||||
#define PORT_EEPROM_FORMAT "/sys/bus/i2c/devices/%d-0050/eeprom"
|
||||
#define MODULE_PRESENT_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_present_%d"
|
||||
#define MODULE_RXLOS_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_rx_los_%d"
|
||||
#define MODULE_TXFAULT_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_tx_fault_%d"
|
||||
#define MODULE_TXDISABLE_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_tx_disable_%d"
|
||||
|
||||
int sfp_map_bus[] ={25, 26, 27, 28, 29, 30, 31, 32,
|
||||
33, 34, 35, 36, 37, 38, 39, 40,
|
||||
41, 42, 43, 44, 45, 46, 47, 48,
|
||||
49, 50, 51, 52, 53, 54, 55, 56,
|
||||
57, 58};
|
||||
|
||||
/************************************************************
|
||||
*
|
||||
* SFPI Entry Points
|
||||
*
|
||||
***********************************************************/
|
||||
|
||||
int
|
||||
onlp_sfpi_init(void)
|
||||
{
|
||||
/* Called at initialization time */
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
int
|
||||
onlp_sfpi_map_bus_index(int port)
|
||||
{
|
||||
if(port < 0 || port >=34)
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
return sfp_map_bus[port];
|
||||
}
|
||||
|
||||
int
|
||||
onlp_sfpi_bitmap_get(onlp_sfp_bitmap_t* bmap)
|
||||
{
|
||||
/*
|
||||
* Ports {0, 34}
|
||||
*/
|
||||
int p;
|
||||
|
||||
for(p = 0; p < 34; p++) {
|
||||
AIM_BITMAP_SET(bmap, p);
|
||||
}
|
||||
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_sfpi_is_present(int port)
|
||||
{
|
||||
/*
|
||||
* Return 1 if present.
|
||||
* Return 0 if not present.
|
||||
* Return < 0 if error.
|
||||
*/
|
||||
int present;
|
||||
int bus, addr;
|
||||
|
||||
if(port <0 || port > 34)
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
|
||||
if(port >=0 && port < 16)
|
||||
{
|
||||
addr = 61;
|
||||
bus = 20;
|
||||
}
|
||||
else
|
||||
{
|
||||
addr = 62;
|
||||
bus = 21;
|
||||
}
|
||||
|
||||
if (onlp_file_read_int(&present, MODULE_PRESENT_FORMAT, bus, addr, (port+1)) < 0) {
|
||||
AIM_LOG_ERROR("Unable to read present status from port(%d)\r\n", port);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
return present;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst)
|
||||
{
|
||||
|
||||
return ONLP_STATUS_E_UNSUPPORTED;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst)
|
||||
{
|
||||
uint32_t bytes[5];
|
||||
int i = 0;
|
||||
uint64_t rx_los_all = 0;
|
||||
|
||||
bytes[0]=bytes[1]=bytes[2]=bytes[3]=0x0;
|
||||
bytes[4]=0x03;
|
||||
for(i = AIM_ARRAYSIZE(bytes)-1; i >= 0; i--) {
|
||||
rx_los_all <<= 8;
|
||||
rx_los_all |= bytes[i];
|
||||
}
|
||||
|
||||
/* Populate bitmap */
|
||||
for(i = 0; rx_los_all; i++) {
|
||||
AIM_BITMAP_MOD(dst, i, (rx_los_all & 1));
|
||||
rx_los_all >>= 1;
|
||||
}
|
||||
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_sfpi_eeprom_read(int port, uint8_t data[256])
|
||||
{
|
||||
/*
|
||||
* Read the SFP eeprom into data[]
|
||||
*
|
||||
* Return MISSING if SFP is missing.
|
||||
* Return OK if eeprom is read
|
||||
*/
|
||||
int size = 0;
|
||||
if(port <0 || port > 34)
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
memset(data, 0, 256);
|
||||
|
||||
if(onlp_file_read(data, 256, &size, PORT_EEPROM_FORMAT, onlp_sfpi_map_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])
|
||||
{
|
||||
FILE* fp;
|
||||
char file[64] = {0};
|
||||
|
||||
sprintf(file, PORT_EEPROM_FORMAT, onlp_sfpi_map_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 (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;
|
||||
}
|
||||
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_sfpi_dev_readb(int port, uint8_t devaddr, uint8_t addr)
|
||||
{
|
||||
int bus = onlp_sfpi_map_bus_index(port);
|
||||
return onlp_i2c_readb(bus, devaddr, addr, ONLP_I2C_F_FORCE);
|
||||
}
|
||||
|
||||
int
|
||||
onlp_sfpi_dev_writeb(int port, uint8_t devaddr, uint8_t addr, uint8_t value)
|
||||
{
|
||||
int bus = onlp_sfpi_map_bus_index(port);
|
||||
return onlp_i2c_writeb(bus, devaddr, addr, value, ONLP_I2C_F_FORCE);
|
||||
}
|
||||
|
||||
int
|
||||
onlp_sfpi_dev_readw(int port, uint8_t devaddr, uint8_t addr)
|
||||
{
|
||||
int bus = onlp_sfpi_map_bus_index(port);
|
||||
return onlp_i2c_readw(bus, devaddr, addr, ONLP_I2C_F_FORCE);
|
||||
}
|
||||
|
||||
int
|
||||
onlp_sfpi_dev_writew(int port, uint8_t devaddr, uint8_t addr, uint16_t value)
|
||||
{
|
||||
int bus = onlp_sfpi_map_bus_index(port);
|
||||
return onlp_i2c_writew(bus, devaddr, addr, value, ONLP_I2C_F_FORCE);
|
||||
}
|
||||
|
||||
int
|
||||
onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value)
|
||||
{
|
||||
int rv;
|
||||
int addr = 62;
|
||||
int bus = 21;
|
||||
|
||||
switch(control)
|
||||
{
|
||||
case ONLP_SFP_CONTROL_TX_DISABLE:
|
||||
{
|
||||
if(port==32 || port==33) {
|
||||
if (onlp_file_write_int(0, MODULE_TXDISABLE_FORMAT, bus, addr, (port+1)) < 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;
|
||||
}
|
||||
}
|
||||
else {
|
||||
rv = ONLP_STATUS_E_UNSUPPORTED;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
rv = ONLP_STATUS_E_UNSUPPORTED;
|
||||
break;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value)
|
||||
{
|
||||
int rv;
|
||||
int addr = 62;
|
||||
int bus = 21;
|
||||
|
||||
switch(control)
|
||||
{
|
||||
case ONLP_SFP_CONTROL_RX_LOS:
|
||||
{
|
||||
if(port==32 || port==33) {
|
||||
if (onlp_file_read_int(value, MODULE_RXLOS_FORMAT, bus, addr, (port+1)) < 0) {
|
||||
AIM_LOG_ERROR("Unable to read rx_loss status from port(%d)\r\n", port);
|
||||
rv = ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
else {
|
||||
rv = ONLP_STATUS_OK;
|
||||
}
|
||||
}
|
||||
else {
|
||||
rv = ONLP_STATUS_E_UNSUPPORTED;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case ONLP_SFP_CONTROL_TX_FAULT:
|
||||
{
|
||||
if(port==32 || port==33) {
|
||||
if (onlp_file_read_int(value, MODULE_TXFAULT_FORMAT, bus, addr, (port+1)) < 0) {
|
||||
AIM_LOG_ERROR("Unable to read tx_fault status from port(%d)\r\n", port);
|
||||
rv = ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
else {
|
||||
rv = ONLP_STATUS_OK;
|
||||
}
|
||||
}
|
||||
else {
|
||||
rv = ONLP_STATUS_E_UNSUPPORTED;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case ONLP_SFP_CONTROL_TX_DISABLE:
|
||||
{
|
||||
if(port==32 || port==33) {
|
||||
if (onlp_file_read_int(value, MODULE_TXDISABLE_FORMAT, bus, addr, (port+1)) < 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;
|
||||
}
|
||||
}
|
||||
else {
|
||||
rv = ONLP_STATUS_E_UNSUPPORTED;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
rv = ONLP_STATUS_E_UNSUPPORTED;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_sfpi_denit(void)
|
||||
{
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
@@ -0,0 +1,490 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014 Big Switch Networks, Inc.
|
||||
* Copyright 2014 Accton Technology Corporation.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
*
|
||||
*
|
||||
***********************************************************/
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <onlp/platformi/sysi.h>
|
||||
#include <onlp/platformi/ledi.h>
|
||||
#include <onlp/platformi/thermali.h>
|
||||
#include <onlp/platformi/fani.h>
|
||||
#include <onlp/platformi/psui.h>
|
||||
#include "platform_lib.h"
|
||||
#include "x86_64_accton_as9716_32d_int.h"
|
||||
#include "x86_64_accton_as9716_32d_log.h"
|
||||
|
||||
|
||||
#define PREFIX_PATH_ON_CPLD_DEV "/sys/bus/i2c/devices/"
|
||||
#define NUM_OF_CPLD 3
|
||||
#define FAN_DUTY_CYCLE_MAX (100)
|
||||
#define FAN_DUTY_CYCLE_DEFAULT (32)
|
||||
#define FAN_DUTY_PLUS_FOR_DIR (13)
|
||||
/* Note, all chassis fans share 1 single duty setting.
|
||||
* Here use fan 1 to represent global fan duty value.*/
|
||||
#define FAN_ID_FOR_SET_FAN_DUTY (1)
|
||||
#define CELSIUS_RECORD_NUMBER (2) /*Must >= 2*/
|
||||
|
||||
typedef struct fan_ctrl_policy {
|
||||
int duty_cycle; /* In percetage */
|
||||
int step_up_thermal; /* In mini-Celsius */
|
||||
int step_dn_thermal; /* In mini-Celsius */
|
||||
} fan_ctrl_policy_t;
|
||||
|
||||
static char arr_cplddev_name[NUM_OF_CPLD][10] =
|
||||
{
|
||||
"4-0060",
|
||||
"5-0062",
|
||||
"6-0064"
|
||||
};
|
||||
|
||||
const char*
|
||||
onlp_sysi_platform_get(void)
|
||||
{
|
||||
return "x86-64-accton-as9716-32d-r0";
|
||||
}
|
||||
|
||||
int
|
||||
onlp_sysi_onie_data_get(uint8_t** data, int* size)
|
||||
{
|
||||
uint8_t* rdata = aim_zmalloc(256);
|
||||
|
||||
if(onlp_file_read(rdata, 256, size, IDPROM_PATH) == ONLP_STATUS_OK) {
|
||||
if(*size == 256) {
|
||||
*data = rdata;
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
aim_free(rdata);
|
||||
*size = 0;
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_sysi_oids_get(onlp_oid_t* table, int max)
|
||||
{
|
||||
int i;
|
||||
onlp_oid_t* e = table;
|
||||
memset(table, 0, max*sizeof(onlp_oid_t));
|
||||
|
||||
/* 6 Thermal sensors on the chassis */
|
||||
for (i = 1; i <= CHASSIS_THERMAL_COUNT; i++) {
|
||||
*e++ = ONLP_THERMAL_ID_CREATE(i);
|
||||
}
|
||||
|
||||
/* 5 LEDs on the chassis */
|
||||
for (i = 1; i <= CHASSIS_LED_COUNT; i++) {
|
||||
*e++ = ONLP_LED_ID_CREATE(i);
|
||||
}
|
||||
|
||||
/* 2 PSUs on the chassis */
|
||||
for (i = 1; i <= CHASSIS_PSU_COUNT; i++) {
|
||||
*e++ = ONLP_PSU_ID_CREATE(i);
|
||||
}
|
||||
|
||||
/* 6 Fans on the chassis */
|
||||
for (i = 1; i <= CHASSIS_FAN_COUNT; i++) {
|
||||
*e++ = ONLP_FAN_ID_CREATE(i);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_sysi_platform_info_get(onlp_platform_info_t* pi)
|
||||
{
|
||||
int i, v[NUM_OF_CPLD]={0};
|
||||
|
||||
for (i = 0; i < NUM_OF_CPLD; i++) {
|
||||
v[i] = 0;
|
||||
|
||||
if(onlp_file_read_int(v+i, "%s%s/version", PREFIX_PATH_ON_CPLD_DEV, arr_cplddev_name[i]) < 0) {
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
}
|
||||
pi->cpld_versions = aim_fstrdup("%d.%d.%d", v[0], v[1], v[2]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
onlp_sysi_platform_info_free(onlp_platform_info_t* pi)
|
||||
{
|
||||
aim_free(pi->cpld_versions);
|
||||
}
|
||||
|
||||
/* Thermal plan:
|
||||
* $TMP = (CPU_core + LM75_1+ LM75_2 + LM75_3 + LM75_4)/5
|
||||
* 1. If any FAN failed, set all the other fans as full speed, 100%.
|
||||
* 2. If any sensor is high than 45 degrees, set fan speed to duty 62.5%.
|
||||
* 3. If any sensor is high than 50 degrees, set fan speed to duty 100%.
|
||||
* 4. When $TMP >= 40 C, set fan speed to duty 62.5%.
|
||||
* 5. When $TMP >= 45 C, set fan speed to duty 100%.
|
||||
* 6. When $TMP < 35 C, set fan speed to duty 31.25%.
|
||||
* 7. Direction factor, when B2F, duty + 12.5%.
|
||||
*
|
||||
* Note, all chassis fans share 1 single duty setting.
|
||||
*/
|
||||
fan_ctrl_policy_t fan_ctrl_policy_avg[] = {
|
||||
{FAN_DUTY_CYCLE_MAX , 45000, INT_MIN},
|
||||
{63 , 40000, INT_MIN},
|
||||
{32 , INT_MAX, 35000},
|
||||
};
|
||||
|
||||
fan_ctrl_policy_t fan_ctrl_policy_single[] = {
|
||||
{FAN_DUTY_CYCLE_MAX , 50000, INT_MIN},
|
||||
{63 , 45000, INT_MIN},
|
||||
};
|
||||
|
||||
struct fan_control_data_s {
|
||||
int duty_cycle;
|
||||
int dir_plus;
|
||||
int mc_avg_pre[CELSIUS_RECORD_NUMBER];
|
||||
int mc_high_pre[CELSIUS_RECORD_NUMBER];
|
||||
|
||||
} fan_control_data_pre =
|
||||
{
|
||||
.duty_cycle = FAN_DUTY_CYCLE_DEFAULT,
|
||||
.dir_plus = 0,
|
||||
.mc_avg_pre = {INT_MIN+1, INT_MIN}, /*init as thermal rising to avoid full speed.*/
|
||||
.mc_high_pre = {INT_MIN+1, INT_MIN}, /*init as thermal rising to avoid full speed.*/
|
||||
|
||||
};
|
||||
|
||||
static int
|
||||
sysi_check_fan(uint32_t *fan_dir){
|
||||
int i, present;
|
||||
|
||||
for (i = 1; i <= CHASSIS_FAN_COUNT; i++)
|
||||
{
|
||||
onlp_fan_info_t fan_info;
|
||||
|
||||
if (onlp_fani_info_get(ONLP_FAN_ID_CREATE(i), &fan_info) != ONLP_STATUS_OK) {
|
||||
AIM_LOG_ERROR("Unable to get fan(%d) status\r\n", i);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
present = fan_info.status & ONLP_FAN_STATUS_PRESENT;
|
||||
if ((fan_info.status & ONLP_FAN_STATUS_FAILED) || !present) {
|
||||
AIM_LOG_WARN("Fan(%d) is not working, set the other fans as full speed\r\n", i);
|
||||
int ret = onlp_fani_percentage_set(
|
||||
ONLP_FAN_ID_CREATE(FAN_ID_FOR_SET_FAN_DUTY), FAN_DUTY_CYCLE_MAX);
|
||||
if (ret != ONLP_STATUS_OK)
|
||||
return ret;
|
||||
else
|
||||
return ONLP_STATUS_E_MISSING;
|
||||
}
|
||||
|
||||
/* Get fan direction (Only get the first one since all fan direction are the same)
|
||||
*/
|
||||
if (i == 1) {
|
||||
*fan_dir = fan_info.status & (ONLP_FAN_STATUS_F2B|ONLP_FAN_STATUS_B2F);
|
||||
}
|
||||
}
|
||||
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
sysi_get_fan_duty(int *cur_duty_cycle){
|
||||
int fd, len;
|
||||
char buf[10] = {0};
|
||||
char *node = FAN_NODE(fan_duty_cycle_percentage);
|
||||
|
||||
/* Get current fan duty*/
|
||||
fd = open(node, O_RDONLY);
|
||||
if (fd == -1){
|
||||
AIM_LOG_ERROR("Unable to open fan speed control node (%s)", node);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
len = read(fd, buf, sizeof(buf));
|
||||
close(fd);
|
||||
if (len <= 0) {
|
||||
AIM_LOG_ERROR("Unable to read fan speed from (%s)", node);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
*cur_duty_cycle = atoi(buf);
|
||||
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
sysi_get_thermal_sum(int *mcelsius){
|
||||
onlp_thermal_info_t thermal_info;
|
||||
int i;
|
||||
|
||||
*mcelsius = 0;
|
||||
for (i = 1; i <= CHASSIS_THERMAL_COUNT; i++) {
|
||||
if (onlp_thermali_info_get(ONLP_THERMAL_ID_CREATE(i), &thermal_info)
|
||||
!= ONLP_STATUS_OK) {
|
||||
AIM_LOG_ERROR("Unable to read thermal status");
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
*mcelsius += thermal_info.mcelsius;
|
||||
|
||||
DEBUG_PRINT("Thermal %d: %d \n ", i, thermal_info.mcelsius);
|
||||
|
||||
}
|
||||
|
||||
return ONLP_STATUS_OK;
|
||||
|
||||
}
|
||||
|
||||
static int
|
||||
sysi_get_highest_thermal(int *mcelsius){
|
||||
onlp_thermal_info_t thermal_info;
|
||||
int i, highest;
|
||||
|
||||
highest = 0;
|
||||
for (i = 1; i <= CHASSIS_THERMAL_COUNT; i++) {
|
||||
if (onlp_thermali_info_get(ONLP_THERMAL_ID_CREATE(i), &thermal_info)
|
||||
!= ONLP_STATUS_OK) {
|
||||
AIM_LOG_ERROR("Unable to read thermal status");
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
highest = (thermal_info.mcelsius > highest)?
|
||||
thermal_info.mcelsius : highest;
|
||||
}
|
||||
*mcelsius = highest;
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
/* Anaylze thermal changing history to judge if the change is a stable trend. */
|
||||
static int _is_thermal_a_trend(int *mc_history){
|
||||
int i, trend, trended;
|
||||
|
||||
if (mc_history == NULL) {
|
||||
AIM_LOG_ERROR("Unable to get history of thermal\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Get heat up/down trend. */
|
||||
trend = 0;
|
||||
for (i = 0; i < CELSIUS_RECORD_NUMBER; i++) {
|
||||
if (( mc_history[i+1] < mc_history[i])){
|
||||
trend++;
|
||||
}else if (( mc_history[i+1] > mc_history[i])){
|
||||
trend--;
|
||||
}
|
||||
}
|
||||
|
||||
trended = (abs(trend) >= ((CELSIUS_RECORD_NUMBER+1)/2))? 1:0;
|
||||
#if (DEBUG_MODE == 1)
|
||||
DEBUG_PRINT("[INFO]%s#%d, trended: %d, UP/DW: %d mcelsius:",
|
||||
__func__, __LINE__, trended, trend );
|
||||
for (i = 0; i <= CELSIUS_RECORD_NUMBER; i++) {
|
||||
DEBUG_PRINT(" %d =>", mc_history[i]);
|
||||
}
|
||||
DEBUG_PRINT("%c\n", ' ');
|
||||
#endif
|
||||
|
||||
/*For more than half changes are same direction, it's a firm trend.*/
|
||||
return trended;
|
||||
}
|
||||
|
||||
|
||||
/* Decide duty by highest value of thermal sensors.*/
|
||||
static int
|
||||
sysi_get_duty_by_highest(int *duty_cycle){
|
||||
int i, ret, maxtrix_len;
|
||||
int new_duty_cycle = 0 ;
|
||||
int mc_history[CELSIUS_RECORD_NUMBER+1] = {0};
|
||||
int *mcelsius_pre_p = &mc_history[1];
|
||||
int *mcelsius_now_p = &mc_history[0];
|
||||
|
||||
/* Fill up mcelsius array,
|
||||
* [0] is current temperature, others are history.
|
||||
*/
|
||||
ret = sysi_get_highest_thermal(mcelsius_now_p);
|
||||
if(ONLP_STATUS_OK != ret){
|
||||
return ret;
|
||||
}
|
||||
memcpy (mcelsius_pre_p, fan_control_data_pre.mc_high_pre,
|
||||
sizeof(fan_control_data_pre.mc_high_pre));
|
||||
|
||||
DEBUG_PRINT("[INFO]%s#%d, highest mcelsius:%d!\n",
|
||||
__func__, __LINE__, *mcelsius_now_p);
|
||||
|
||||
/* Shift records to the right */
|
||||
for (i = 0; i < CELSIUS_RECORD_NUMBER; i++) {
|
||||
fan_control_data_pre.mc_high_pre[i] = mc_history[i];
|
||||
}
|
||||
|
||||
/* Only change duty on consecutive heat rising or falling.*/
|
||||
maxtrix_len = AIM_ARRAYSIZE(fan_ctrl_policy_single);
|
||||
|
||||
/* Only change duty when the thermal changing are firm. */
|
||||
if (_is_thermal_a_trend(mc_history))
|
||||
{
|
||||
int matched = 0;
|
||||
for (i = 0; i < maxtrix_len; i++) {
|
||||
if ((*mcelsius_now_p > fan_ctrl_policy_single[i].step_up_thermal)) {
|
||||
new_duty_cycle = fan_ctrl_policy_single[i].duty_cycle;
|
||||
matched = !matched;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* if (!matched) {
|
||||
DEBUG_PRINT("%s#%d, celsius(%d) falls into undefined range!!\n",
|
||||
__func__, __LINE__, *mcelsius_now_p);
|
||||
} */
|
||||
}
|
||||
*duty_cycle = new_duty_cycle;
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
/* Decide duty by average value of thermal sensors.*/
|
||||
static int
|
||||
sysi_get_duty_by_average(int *duty_cycle){
|
||||
int i, mcelsius_avg, ret, maxtrix_len;
|
||||
int new_duty_cycle=0;
|
||||
int mc_history[CELSIUS_RECORD_NUMBER+1] = {0};
|
||||
int *mcelsius_pre_p = &mc_history[1];
|
||||
int *mcelsius_now_p = &mc_history[0];
|
||||
|
||||
/* Fill up mcelsius array,
|
||||
* [0] is current temperature, others are history.
|
||||
*/
|
||||
*mcelsius_now_p = 0;
|
||||
ret = sysi_get_thermal_sum(mcelsius_now_p);
|
||||
if(ONLP_STATUS_OK != ret){
|
||||
return ret;
|
||||
}
|
||||
mcelsius_avg = (*mcelsius_now_p)/CHASSIS_THERMAL_COUNT;
|
||||
|
||||
memcpy (mcelsius_pre_p, fan_control_data_pre.mc_avg_pre,
|
||||
sizeof(fan_control_data_pre.mc_avg_pre));
|
||||
|
||||
DEBUG_PRINT("[INFO]%s#%d, mcelsius:%d!\n", __func__, __LINE__, mcelsius_avg);
|
||||
|
||||
/* Shift records to the right */
|
||||
for (i = 0; i < CELSIUS_RECORD_NUMBER; i++) {
|
||||
fan_control_data_pre.mc_avg_pre[i] = mc_history[i];
|
||||
}
|
||||
|
||||
/* Only change duty on consecutive heat rising or falling.*/
|
||||
maxtrix_len = AIM_ARRAYSIZE(fan_ctrl_policy_avg);
|
||||
|
||||
/* Only change duty when the thermal changing are firm. */
|
||||
if (_is_thermal_a_trend(mc_history))
|
||||
{
|
||||
int matched = 0;
|
||||
for (i = 0; i < maxtrix_len; i++) {
|
||||
if ((mcelsius_avg >= fan_ctrl_policy_avg[i].step_up_thermal)) {
|
||||
new_duty_cycle = fan_ctrl_policy_avg[i].duty_cycle;
|
||||
matched = !matched;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (i = maxtrix_len-1; i>=0; i--) {
|
||||
if ((mcelsius_avg < fan_ctrl_policy_avg[i].step_dn_thermal)) {
|
||||
new_duty_cycle = fan_ctrl_policy_avg[i].duty_cycle;
|
||||
matched = !matched;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/*if (!matched) {
|
||||
DEBUG_PRINT("%s#%d, celsius(%d) falls into undefined range!!\n",
|
||||
__func__, __LINE__, mcelsius_avg);
|
||||
} */
|
||||
}
|
||||
|
||||
*duty_cycle = new_duty_cycle;
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_sysi_platform_manage_fans(void)
|
||||
{
|
||||
uint32_t fan_dir;
|
||||
int ret;
|
||||
int cur_duty_cycle, new_duty_cycle, tmp;
|
||||
int direct_addon = 0;
|
||||
onlp_oid_t fan_duty_oid = ONLP_FAN_ID_CREATE(FAN_ID_FOR_SET_FAN_DUTY);
|
||||
|
||||
/**********************************************************
|
||||
* Decision 1: Set fan as full speed if any fan is failed.
|
||||
**********************************************************/
|
||||
ret = sysi_check_fan(&fan_dir);
|
||||
if(ONLP_STATUS_OK != ret){
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (fan_dir & ONLP_FAN_STATUS_B2F) {
|
||||
direct_addon = FAN_DUTY_PLUS_FOR_DIR;
|
||||
}
|
||||
|
||||
/**********************************************************
|
||||
* Decision 2: If no matched fan speed is found from the policy,
|
||||
* use FAN_DUTY_CYCLE_MIN as default speed
|
||||
**********************************************************/
|
||||
ret = sysi_get_fan_duty(&cur_duty_cycle);
|
||||
if(ONLP_STATUS_OK != ret){
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**********************************************************
|
||||
* Decision 3: Decide new fan speed depend on fan direction and temperature
|
||||
**********************************************************/
|
||||
ret = sysi_get_duty_by_average(&new_duty_cycle);
|
||||
if (ONLP_STATUS_OK != ret){
|
||||
return ret;
|
||||
}
|
||||
ret = sysi_get_duty_by_highest(&tmp);
|
||||
if (ONLP_STATUS_OK != ret){
|
||||
return ret;
|
||||
}
|
||||
|
||||
new_duty_cycle = (tmp > new_duty_cycle)? tmp : new_duty_cycle;
|
||||
if (new_duty_cycle == 0)
|
||||
{
|
||||
new_duty_cycle = fan_control_data_pre.duty_cycle;
|
||||
} else {
|
||||
fan_control_data_pre.duty_cycle = new_duty_cycle;
|
||||
}
|
||||
fan_control_data_pre.dir_plus = direct_addon;
|
||||
DEBUG_PRINT("[INFO]%s#%d, new duty: %d = %d + %d (%d)!\n", __func__, __LINE__,
|
||||
new_duty_cycle + direct_addon, new_duty_cycle, direct_addon, cur_duty_cycle);
|
||||
|
||||
new_duty_cycle += direct_addon;
|
||||
new_duty_cycle = (new_duty_cycle > FAN_DUTY_CYCLE_MAX)?
|
||||
FAN_DUTY_CYCLE_MAX : new_duty_cycle;
|
||||
|
||||
if (new_duty_cycle == cur_duty_cycle) {
|
||||
/* Duty cycle does not change, just return */
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
return onlp_fani_percentage_set(fan_duty_oid, new_duty_cycle);
|
||||
}
|
||||
|
||||
int
|
||||
onlp_sysi_platform_manage_leds(void)
|
||||
{
|
||||
return ONLP_STATUS_E_UNSUPPORTED;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014 Big Switch Networks, Inc.
|
||||
* Copyright 2014 Accton Technology Corporation.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
* Thermal Sensor Platform Implementation.
|
||||
*
|
||||
***********************************************************/
|
||||
//#include <unistd.h>
|
||||
#include <onlplib/file.h>
|
||||
#include <onlp/platformi/thermali.h>
|
||||
#include "platform_lib.h"
|
||||
|
||||
#define THERMAL_PATH_FORMAT "/sys/bus/i2c/devices/%s/*temp1_input"
|
||||
#define PSU_THERMAL_PATH_FORMAT "/sys/bus/i2c/devices/%s/*psu_temp1_input"
|
||||
|
||||
#define VALIDATE(_id) \
|
||||
do { \
|
||||
if(!ONLP_OID_IS_THERMAL(_id)) { \
|
||||
return ONLP_STATUS_E_INVALID; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
enum onlp_thermal_id
|
||||
{
|
||||
THERMAL_RESERVED = 0,
|
||||
THERMAL_CPU_CORE,
|
||||
THERMAL_1_ON_MAIN_BROAD,
|
||||
THERMAL_2_ON_MAIN_BROAD,
|
||||
THERMAL_3_ON_MAIN_BROAD,
|
||||
THERMAL_4_ON_MAIN_BROAD,
|
||||
THERMAL_5_ON_MAIN_BROAD,
|
||||
THERMAL_6_ON_MAIN_BROAD,
|
||||
THERMAL_7_ON_MAIN_BROAD,
|
||||
THERMAL_1_ON_PSU1,
|
||||
THERMAL_1_ON_PSU2,
|
||||
};
|
||||
|
||||
static char* directory[] = /* must map with onlp_thermal_id */
|
||||
{
|
||||
NULL,
|
||||
NULL, /* CPU_CORE files */
|
||||
"18-0048",
|
||||
"18-0049",
|
||||
"18-004a",
|
||||
"18-004b",
|
||||
"18-004c",
|
||||
"18-004e",
|
||||
"18-004f",
|
||||
"10-0059",
|
||||
"9-0058",
|
||||
};
|
||||
|
||||
static char* cpu_coretemp_files[] =
|
||||
{
|
||||
"/sys/devices/platform/coretemp.0*temp2_input",
|
||||
"/sys/devices/platform/coretemp.0*temp3_input",
|
||||
"/sys/devices/platform/coretemp.0*temp4_input",
|
||||
"/sys/devices/platform/coretemp.0*temp5_input",
|
||||
NULL,
|
||||
};
|
||||
|
||||
/* Static values */
|
||||
static onlp_thermal_info_t linfo[] = {
|
||||
{ }, /* Not used */
|
||||
{ { ONLP_THERMAL_ID_CREATE(THERMAL_CPU_CORE), "CPU Core", 0},
|
||||
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_STATUS_PRESENT,
|
||||
ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS
|
||||
},
|
||||
{ { ONLP_THERMAL_ID_CREATE(THERMAL_2_ON_MAIN_BROAD), "LM75-2-49", 0},
|
||||
ONLP_THERMAL_STATUS_PRESENT,
|
||||
ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS
|
||||
},
|
||||
{ { ONLP_THERMAL_ID_CREATE(THERMAL_3_ON_MAIN_BROAD), "LM75-3-4A", 0},
|
||||
ONLP_THERMAL_STATUS_PRESENT,
|
||||
ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS
|
||||
},
|
||||
{ { ONLP_THERMAL_ID_CREATE(THERMAL_4_ON_MAIN_BROAD), "LM75-4-4B", 0},
|
||||
ONLP_THERMAL_STATUS_PRESENT,
|
||||
ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS
|
||||
},
|
||||
{ { ONLP_THERMAL_ID_CREATE(THERMAL_5_ON_MAIN_BROAD), "LM75-5-4C", 0},
|
||||
ONLP_THERMAL_STATUS_PRESENT,
|
||||
ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS
|
||||
},
|
||||
{ { ONLP_THERMAL_ID_CREATE(THERMAL_6_ON_MAIN_BROAD), "LM75-6-4E", 0},
|
||||
ONLP_THERMAL_STATUS_PRESENT,
|
||||
ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS
|
||||
},
|
||||
{ { ONLP_THERMAL_ID_CREATE(THERMAL_7_ON_MAIN_BROAD), "LM75-7-4F", 0},
|
||||
ONLP_THERMAL_STATUS_PRESENT,
|
||||
ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS
|
||||
},
|
||||
{ { ONLP_THERMAL_ID_CREATE(THERMAL_1_ON_PSU1), "PSU-1 Thermal Sensor 1", ONLP_PSU_ID_CREATE(PSU1_ID)},
|
||||
ONLP_THERMAL_STATUS_PRESENT,
|
||||
ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS
|
||||
},
|
||||
{ { ONLP_THERMAL_ID_CREATE(THERMAL_1_ON_PSU2), "PSU-2 Thermal Sensor 1", ONLP_PSU_ID_CREATE(PSU2_ID)},
|
||||
ONLP_THERMAL_STATUS_PRESENT,
|
||||
ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* This will be called to intiialize the thermali subsystem.
|
||||
*/
|
||||
int
|
||||
onlp_thermali_init(void)
|
||||
{
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Retrieve the information structure for the given thermal OID.
|
||||
*
|
||||
* If the OID is invalid, return ONLP_E_STATUS_INVALID.
|
||||
* If an unexpected error occurs, return ONLP_E_STATUS_INTERNAL.
|
||||
* Otherwise, return ONLP_STATUS_OK with the OID's information.
|
||||
*
|
||||
* Note -- it is expected that you fill out the information
|
||||
* structure even if the sensor described by the OID is not present.
|
||||
*/
|
||||
int
|
||||
onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* info)
|
||||
{
|
||||
int tid;
|
||||
char *format = NULL;
|
||||
char path[64] = {0};
|
||||
VALIDATE(id);
|
||||
|
||||
tid = ONLP_OID_ID_GET(id);
|
||||
|
||||
/* Set the onlp_oid_hdr_t and capabilities */
|
||||
*info = linfo[tid];
|
||||
if(tid == THERMAL_CPU_CORE) {
|
||||
return onlp_file_read_int_max(&info->mcelsius, cpu_coretemp_files);
|
||||
}
|
||||
|
||||
switch (tid) {
|
||||
case THERMAL_1_ON_MAIN_BROAD:
|
||||
case THERMAL_2_ON_MAIN_BROAD:
|
||||
case THERMAL_3_ON_MAIN_BROAD:
|
||||
case THERMAL_4_ON_MAIN_BROAD:
|
||||
case THERMAL_5_ON_MAIN_BROAD:
|
||||
case THERMAL_6_ON_MAIN_BROAD:
|
||||
case THERMAL_7_ON_MAIN_BROAD:
|
||||
format = THERMAL_PATH_FORMAT;
|
||||
break;
|
||||
case THERMAL_1_ON_PSU1:
|
||||
case THERMAL_1_ON_PSU2:
|
||||
format = PSU_THERMAL_PATH_FORMAT;
|
||||
break;
|
||||
default:
|
||||
return ONLP_STATUS_E_INVALID;
|
||||
};
|
||||
|
||||
/* get path */
|
||||
sprintf(path, format, directory[tid], tid);
|
||||
if (onlp_file_read_int(&info->mcelsius, path) < 0) {
|
||||
AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
/**************************************************************************//**
|
||||
*
|
||||
*
|
||||
*
|
||||
*****************************************************************************/
|
||||
#include <x86_64_accton_as9716_32d/x86_64_accton_as9716_32d_config.h>
|
||||
|
||||
/* <auto.start.cdefs(X86_64_ACCTON_AS9716_32D_CONFIG_HEADER).source> */
|
||||
#define __x86_64_accton_as9716_32d_config_STRINGIFY_NAME(_x) #_x
|
||||
#define __x86_64_accton_as9716_32d_config_STRINGIFY_VALUE(_x) __x86_64_accton_as9716_32d_config_STRINGIFY_NAME(_x)
|
||||
x86_64_accton_as9716_32d_config_settings_t x86_64_accton_as9716_32d_config_settings[] =
|
||||
{
|
||||
#ifdef X86_64_ACCTON_AS9716_32D_CONFIG_INCLUDE_LOGGING
|
||||
{ __x86_64_accton_as9716_32d_config_STRINGIFY_NAME(X86_64_ACCTON_AS9716_32D_CONFIG_INCLUDE_LOGGING), __x86_64_accton_as9716_32d_config_STRINGIFY_VALUE(X86_64_ACCTON_AS9716_32D_CONFIG_INCLUDE_LOGGING) },
|
||||
#else
|
||||
{ X86_64_ACCTON_AS9716_32D_CONFIG_INCLUDE_LOGGING(__x86_64_accton_as9716_32d_config_STRINGIFY_NAME), "__undefined__" },
|
||||
#endif
|
||||
#ifdef X86_64_ACCTON_AS9716_32D_CONFIG_LOG_OPTIONS_DEFAULT
|
||||
{ __x86_64_accton_as9716_32d_config_STRINGIFY_NAME(X86_64_ACCTON_AS9716_32D_CONFIG_LOG_OPTIONS_DEFAULT), __x86_64_accton_as9716_32d_config_STRINGIFY_VALUE(X86_64_ACCTON_AS9716_32D_CONFIG_LOG_OPTIONS_DEFAULT) },
|
||||
#else
|
||||
{ X86_64_ACCTON_AS9716_32D_CONFIG_LOG_OPTIONS_DEFAULT(__x86_64_accton_as9716_32d_config_STRINGIFY_NAME), "__undefined__" },
|
||||
#endif
|
||||
#ifdef X86_64_ACCTON_AS9716_32D_CONFIG_LOG_BITS_DEFAULT
|
||||
{ __x86_64_accton_as9716_32d_config_STRINGIFY_NAME(X86_64_ACCTON_AS9716_32D_CONFIG_LOG_BITS_DEFAULT), __x86_64_accton_as9716_32d_config_STRINGIFY_VALUE(X86_64_ACCTON_AS9716_32D_CONFIG_LOG_BITS_DEFAULT) },
|
||||
#else
|
||||
{ X86_64_ACCTON_AS9716_32D_CONFIG_LOG_BITS_DEFAULT(__x86_64_accton_as9716_32d_config_STRINGIFY_NAME), "__undefined__" },
|
||||
#endif
|
||||
#ifdef X86_64_ACCTON_AS9716_32D_CONFIG_LOG_CUSTOM_BITS_DEFAULT
|
||||
{ __x86_64_accton_as9716_32d_config_STRINGIFY_NAME(X86_64_ACCTON_AS9716_32D_CONFIG_LOG_CUSTOM_BITS_DEFAULT), __x86_64_accton_as9716_32d_config_STRINGIFY_VALUE(X86_64_ACCTON_AS9716_32D_CONFIG_LOG_CUSTOM_BITS_DEFAULT) },
|
||||
#else
|
||||
{ X86_64_ACCTON_AS9716_32D_CONFIG_LOG_CUSTOM_BITS_DEFAULT(__x86_64_accton_as9716_32d_config_STRINGIFY_NAME), "__undefined__" },
|
||||
#endif
|
||||
#ifdef X86_64_ACCTON_AS9716_32D_CONFIG_PORTING_STDLIB
|
||||
{ __x86_64_accton_as9716_32d_config_STRINGIFY_NAME(X86_64_ACCTON_AS9716_32D_CONFIG_PORTING_STDLIB), __x86_64_accton_as9716_32d_config_STRINGIFY_VALUE(X86_64_ACCTON_AS9716_32D_CONFIG_PORTING_STDLIB) },
|
||||
#else
|
||||
{ X86_64_ACCTON_AS9716_32D_CONFIG_PORTING_STDLIB(__x86_64_accton_as9716_32d_config_STRINGIFY_NAME), "__undefined__" },
|
||||
#endif
|
||||
#ifdef X86_64_ACCTON_AS9716_32D_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS
|
||||
{ __x86_64_accton_as9716_32d_config_STRINGIFY_NAME(X86_64_ACCTON_AS9716_32D_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS), __x86_64_accton_as9716_32d_config_STRINGIFY_VALUE(X86_64_ACCTON_AS9716_32D_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS) },
|
||||
#else
|
||||
{ X86_64_ACCTON_AS9716_32D_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS(__x86_64_accton_as9716_32d_config_STRINGIFY_NAME), "__undefined__" },
|
||||
#endif
|
||||
#ifdef X86_64_ACCTON_AS9716_32D_CONFIG_INCLUDE_UCLI
|
||||
{ __x86_64_accton_as9716_32d_config_STRINGIFY_NAME(X86_64_ACCTON_AS9716_32D_CONFIG_INCLUDE_UCLI), __x86_64_accton_as9716_32d_config_STRINGIFY_VALUE(X86_64_ACCTON_AS9716_32D_CONFIG_INCLUDE_UCLI) },
|
||||
#else
|
||||
{ X86_64_ACCTON_AS9716_32D_CONFIG_INCLUDE_UCLI(__x86_64_accton_as9716_32d_config_STRINGIFY_NAME), "__undefined__" },
|
||||
#endif
|
||||
#ifdef X86_64_ACCTON_AS9716_32D_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION
|
||||
{ __x86_64_accton_as9716_32d_config_STRINGIFY_NAME(X86_64_ACCTON_AS9716_32D_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION), __x86_64_accton_as9716_32d_config_STRINGIFY_VALUE(X86_64_ACCTON_AS9716_32D_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION) },
|
||||
#else
|
||||
{ X86_64_ACCTON_AS9716_32D_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION(__x86_64_accton_as9716_32d_config_STRINGIFY_NAME), "__undefined__" },
|
||||
#endif
|
||||
{ NULL, NULL }
|
||||
};
|
||||
#undef __x86_64_accton_as9716_32d_config_STRINGIFY_VALUE
|
||||
#undef __x86_64_accton_as9716_32d_config_STRINGIFY_NAME
|
||||
|
||||
const char*
|
||||
x86_64_accton_as9716_32d_config_lookup(const char* setting)
|
||||
{
|
||||
int i;
|
||||
for(i = 0; x86_64_accton_as9716_32d_config_settings[i].name; i++) {
|
||||
if(!strcmp(x86_64_accton_as9716_32d_config_settings[i].name, setting)) {
|
||||
return x86_64_accton_as9716_32d_config_settings[i].value;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
x86_64_accton_as9716_32d_config_show(struct aim_pvs_s* pvs)
|
||||
{
|
||||
int i;
|
||||
for(i = 0; x86_64_accton_as9716_32d_config_settings[i].name; i++) {
|
||||
aim_printf(pvs, "%s = %s\n", x86_64_accton_as9716_32d_config_settings[i].name, x86_64_accton_as9716_32d_config_settings[i].value);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
/* <auto.end.cdefs(X86_64_ACCTON_AS9716_32D_CONFIG_HEADER).source> */
|
||||
@@ -0,0 +1,10 @@
|
||||
/**************************************************************************//**
|
||||
*
|
||||
*
|
||||
*
|
||||
*****************************************************************************/
|
||||
#include <x86_64_accton_as9716_32d/x86_64_accton_as9716_32d_config.h>
|
||||
|
||||
/* <--auto.start.enum(ALL).source> */
|
||||
/* <auto.end.enum(ALL).source> */
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
/**************************************************************************//**
|
||||
*
|
||||
* x86_64_accton_as9716_32x Internal Header
|
||||
*
|
||||
*****************************************************************************/
|
||||
#ifndef __x86_64_accton_as9716_32d_INT_H__
|
||||
#define __x86_64_accton_as9716_32d_INT_H__
|
||||
|
||||
#include <x86_64_accton_as9716_32d/x86_64_accton_as9716_32d_config.h>
|
||||
|
||||
|
||||
#endif /* __x86_64_accton_as9716_32d_INT_H__ */
|
||||
@@ -0,0 +1,18 @@
|
||||
/**************************************************************************//**
|
||||
*
|
||||
*
|
||||
*
|
||||
*****************************************************************************/
|
||||
#include <x86_64_accton_as9716_32d/x86_64_accton_as9716_32d_config.h>
|
||||
|
||||
#include "x86_64_accton_as9716_32d_log.h"
|
||||
/*
|
||||
* x86_64_accton_as9716_32d log struct.
|
||||
*/
|
||||
AIM_LOG_STRUCT_DEFINE(
|
||||
X86_64_ACCTON_AS9716_32D_CONFIG_LOG_OPTIONS_DEFAULT,
|
||||
X86_64_ACCTON_AS9716_32D_CONFIG_LOG_BITS_DEFAULT,
|
||||
NULL, /* Custom log map */
|
||||
X86_64_ACCTON_AS9716_32D_CONFIG_LOG_CUSTOM_BITS_DEFAULT
|
||||
);
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
/**************************************************************************//**
|
||||
*
|
||||
*
|
||||
*
|
||||
*****************************************************************************/
|
||||
#ifndef __x86_64_accton_as9716_32d_LOG_H__
|
||||
#define __x86_64_accton_as9716_32d_LOG_H__
|
||||
|
||||
#define AIM_LOG_MODULE_NAME x86_64_accton_as9716_32d
|
||||
#include <AIM/aim_log.h>
|
||||
|
||||
#endif /* __x86_64_accton_as9716_32d_LOG_H__ */
|
||||
@@ -0,0 +1,24 @@
|
||||
/**************************************************************************//**
|
||||
*
|
||||
*
|
||||
*
|
||||
*****************************************************************************/
|
||||
#include <x86_64_accton_as9716_32d/x86_64_accton_as9716_32d_config.h>
|
||||
|
||||
#include "x86_64_accton_as9716_32d_log.h"
|
||||
|
||||
static int
|
||||
datatypes_init__(void)
|
||||
{
|
||||
#define x86_64_accton_as9716_32d_ENUMERATION_ENTRY(_enum_name, _desc) AIM_DATATYPE_MAP_REGISTER(_enum_name, _enum_name##_map, _desc, AIM_LOG_INTERNAL);
|
||||
#include <x86_64_accton_as9716_32d/x86_64_accton_as9716_32d.x>
|
||||
return 0;
|
||||
}
|
||||
|
||||
void __x86_64_accton_as9716_32d_module_init__(void)
|
||||
{
|
||||
AIM_LOG_STRUCT_REGISTER();
|
||||
datatypes_init__();
|
||||
}
|
||||
|
||||
int __onlp_platform_version__ = 1;
|
||||
@@ -0,0 +1,50 @@
|
||||
/**************************************************************************//**
|
||||
*
|
||||
*
|
||||
*
|
||||
*****************************************************************************/
|
||||
#include <x86_64_accton_as9716_32d/x86_64_accton_as9716_32d_config.h>
|
||||
|
||||
#if x86_64_accton_as9716_32d_CONFIG_INCLUDE_UCLI == 1
|
||||
|
||||
#include <uCli/ucli.h>
|
||||
#include <uCli/ucli_argparse.h>
|
||||
#include <uCli/ucli_handler_macros.h>
|
||||
|
||||
static ucli_status_t
|
||||
x86_64_accton_as9716_32d_ucli_ucli__config__(ucli_context_t* uc)
|
||||
{
|
||||
UCLI_HANDLER_MACRO_MODULE_CONFIG(x86_64_accton_as9716_32d)
|
||||
}
|
||||
|
||||
/* <auto.ucli.handlers.start> */
|
||||
/* <auto.ucli.handlers.end> */
|
||||
|
||||
static ucli_module_t
|
||||
x86_64_accton_as9716_32d_ucli_module__ =
|
||||
{
|
||||
"x86_64_accton_as9716_32d_ucli",
|
||||
NULL,
|
||||
x86_64_accton_as9716_32d_ucli_ucli_handlers__,
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
|
||||
ucli_node_t*
|
||||
x86_64_accton_as9716_32d_ucli_node_create(void)
|
||||
{
|
||||
ucli_node_t* n;
|
||||
ucli_module_init(&x86_64_accton_as9716_32d_ucli_module__);
|
||||
n = ucli_node_create("x86_64_accton_as9716_32d", NULL, &x86_64_accton_as9716_32d_ucli_module__);
|
||||
ucli_node_subnode_add(n, ucli_module_log_node_create("x86_64_accton_as9716_32d"));
|
||||
return n;
|
||||
}
|
||||
|
||||
#else
|
||||
void*
|
||||
x86_64_accton_as9716_32d_ucli_node_create(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
include $(ONL)/make/pkg.mk
|
||||
@@ -0,0 +1 @@
|
||||
include $(ONL)/make/pkg.mk
|
||||
@@ -0,0 +1 @@
|
||||
!include $ONL_TEMPLATES/platform-config-platform.yml ARCH=amd64 VENDOR=accton BASENAME=x86-64-accton-as9716-32d REVISION=r0
|
||||
@@ -0,0 +1,31 @@
|
||||
---
|
||||
|
||||
######################################################################
|
||||
#
|
||||
# platform-config for AS9716
|
||||
#
|
||||
######################################################################
|
||||
|
||||
x86-64-accton-as9716-32d-r0:
|
||||
|
||||
grub:
|
||||
|
||||
serial: >-
|
||||
--port=0x3f8
|
||||
--speed=115200
|
||||
--word=8
|
||||
--parity=no
|
||||
--stop=1
|
||||
|
||||
kernel:
|
||||
<<: *kernel-4-14
|
||||
|
||||
args: >-
|
||||
nopat
|
||||
console=ttyS0,115200n8
|
||||
|
||||
##network:
|
||||
## interfaces:
|
||||
## ma1:
|
||||
## name: ~
|
||||
## syspath: pci0000:00/0000:00:1c.0/0000:0a:00.0
|
||||
@@ -0,0 +1,78 @@
|
||||
from onl.platform.base import *
|
||||
from onl.platform.accton import *
|
||||
|
||||
class OnlPlatform_x86_64_accton_as9716_32d_r0(OnlPlatformAccton,
|
||||
OnlPlatformPortConfig_48x25_6x100):
|
||||
|
||||
PLATFORM='x86-64-accton-as9716-32d-r0'
|
||||
MODEL="AS9716-32D"
|
||||
SYS_OBJECT_ID=".9716.32"
|
||||
|
||||
def baseconfig(self):
|
||||
self.insmod('optoe')
|
||||
self.insmod('accton_i2c_psu')
|
||||
for m in [ 'cpld', 'fan', 'psu', 'leds' ]:
|
||||
self.insmod("x86-64-accton-as9716-32d-%s.ko" % m)
|
||||
|
||||
########### initialize I2C bus 0 ###########
|
||||
# initialize multiplexer (PCA9548)
|
||||
self.new_i2c_device('pca9548', 0x77, 0)
|
||||
# initiate multiplexer (PCA9548)
|
||||
self.new_i2c_devices(
|
||||
[
|
||||
# initiate multiplexer (PCA9548)
|
||||
('pca9548', 0x72, 1),
|
||||
('pca9548', 0x76, 1),
|
||||
]
|
||||
)
|
||||
self.new_i2c_devices(
|
||||
[
|
||||
# initiate multiplexer (PCA9548)
|
||||
('pca9548', 0x72, 2),
|
||||
('pca9548', 0x73, 2),
|
||||
('pca9548', 0x74, 2),
|
||||
('pca9548', 0x75, 2),
|
||||
('pca9548', 0x76, 2)
|
||||
]
|
||||
)
|
||||
self.new_i2c_devices([
|
||||
# initialize CPLD
|
||||
#initiate CPLD
|
||||
('as9716_32d_fpga', 0x60, 19),
|
||||
('as9716_32d_cpld1', 0x61, 20),
|
||||
('as9716_32d_cpld2', 0x62, 21),
|
||||
('as9716_32d_cpld_cpu', 0x65, 0),
|
||||
])
|
||||
self.new_i2c_devices([
|
||||
# initiate fan
|
||||
# initiate chassis fan
|
||||
('as9716_32d_fan', 0x66, 17),
|
||||
|
||||
# inititate LM75
|
||||
('lm75', 0x48, 18),
|
||||
('lm75', 0x49, 18),
|
||||
('lm75', 0x4a, 18),
|
||||
('lm75', 0x4b, 18),
|
||||
('lm75', 0x4c, 18),
|
||||
('lm75', 0x4e, 18),
|
||||
('lm75', 0x4f, 18),
|
||||
])
|
||||
|
||||
self.new_i2c_devices([
|
||||
# initiate PSU-2
|
||||
('as9716_32d_psu2', 0x51, 10),
|
||||
('acbel_fsh082', 0x59, 10),
|
||||
|
||||
# initiate PSU-1
|
||||
('as9716_32d_psu1', 0x50, 9),
|
||||
('acbel_fsh082', 0x58, 9),
|
||||
])
|
||||
|
||||
# initialize QSFP port 1~34
|
||||
for port in range(1, 35):
|
||||
self.new_i2c_device('optoe1', 0x50, port+24)
|
||||
subprocess.call('echo port%d > /sys/bus/i2c/devices/%d-0050/port_name' % (port, port+20), shell=True)
|
||||
|
||||
|
||||
self.new_i2c_device('24c02', 0x56, 0)
|
||||
return True
|
||||
Reference in New Issue
Block a user