mirror of
https://github.com/Telecominfraproject/OpenNetworkLinux.git
synced 2025-12-25 17:27:01 +00:00
Merge pull request #445 from brandonchuang/as5916_54xks
[as5916-54xks] Update peripheral drivers to use BMC
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,485 +1,460 @@
|
||||
/*
|
||||
* A hwmon driver for the Accton as5916 54x fan
|
||||
* Copyright (C) Brandon Chuang <brandon_chuang@accton.com.tw>
|
||||
*
|
||||
* Copyright (C) 2016 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.
|
||||
* Based on:
|
||||
* pca954x.c from Kumar Gala <galak@kernel.crashing.org>
|
||||
* Copyright (C) 2006
|
||||
*
|
||||
* 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.
|
||||
* Based on:
|
||||
* pca954x.c from Ken Harrenstien
|
||||
* Copyright (C) 2004 Google, Inc. (Ken Harrenstien)
|
||||
*
|
||||
* 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.
|
||||
* 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/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/init.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/dmi.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/version.h>
|
||||
#include <linux/stat.h>
|
||||
#include <linux/sysfs.h>
|
||||
#include <linux/hwmon-sysfs.h>
|
||||
#include <linux/ipmi.h>
|
||||
#include <linux/ipmi_smi.h>
|
||||
#include <linux/platform_device.h>
|
||||
|
||||
#define DRVNAME "as5916_54xks_fan"
|
||||
#define MAX_FAN_SPEED_RPM 25500
|
||||
#define ACCTON_IPMI_NETFN 0x34
|
||||
#define IPMI_FAN_READ_CMD 0x14
|
||||
#define IPMI_FAN_WRITE_CMD 0x15
|
||||
#define IPMI_TIMEOUT (20 * HZ)
|
||||
|
||||
static struct as5916_54xks_fan_data *as5916_54xks_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);
|
||||
static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data);
|
||||
static ssize_t set_fan(struct device *dev, struct device_attribute *da,
|
||||
const char *buf, size_t count);
|
||||
static ssize_t show_fan(struct device *dev, struct device_attribute *attr, char *buf);
|
||||
static int as5916_54xks_fan_probe(struct platform_device *pdev);
|
||||
static int as5916_54xks_fan_remove(struct platform_device *pdev);
|
||||
|
||||
/* 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:B2F 1:F2B) */
|
||||
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) */
|
||||
enum fan_id {
|
||||
FAN_1,
|
||||
FAN_2,
|
||||
FAN_3,
|
||||
FAN_4,
|
||||
FAN_5,
|
||||
FAN_6,
|
||||
NUM_OF_FAN
|
||||
};
|
||||
|
||||
enum fan_data_index {
|
||||
FAN_PRESENT,
|
||||
FAN_PWM,
|
||||
FAN_SPEED0,
|
||||
FAN_SPEED1,
|
||||
FAN_DATA_COUNT
|
||||
};
|
||||
|
||||
struct ipmi_data {
|
||||
struct completion read_complete;
|
||||
struct ipmi_addr address;
|
||||
ipmi_user_t user;
|
||||
int interface;
|
||||
|
||||
struct kernel_ipmi_msg tx_message;
|
||||
long tx_msgid;
|
||||
|
||||
void *rx_msg_data;
|
||||
unsigned short rx_msg_len;
|
||||
unsigned char rx_result;
|
||||
int rx_recv_type;
|
||||
|
||||
struct ipmi_user_hndl ipmi_hndlrs;
|
||||
};
|
||||
|
||||
/* Each client has this additional data */
|
||||
struct as5916_54xks_fan_data {
|
||||
struct device *hwmon_dev;
|
||||
struct platform_device *pdev;
|
||||
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 */
|
||||
unsigned char ipmi_resp[24];
|
||||
struct ipmi_data ipmi;
|
||||
unsigned char ipmi_tx_data[3]; /* 0: FAN id, 1: 0x02, 2: PWM */
|
||||
};
|
||||
|
||||
enum fan_id {
|
||||
FAN1_ID,
|
||||
FAN2_ID,
|
||||
FAN3_ID,
|
||||
FAN4_ID,
|
||||
FAN5_ID,
|
||||
FAN6_ID
|
||||
struct as5916_54xks_fan_data *data = NULL;
|
||||
|
||||
static struct platform_driver as5916_54xks_fan_driver = {
|
||||
.probe = as5916_54xks_fan_probe,
|
||||
.remove = as5916_54xks_fan_remove,
|
||||
.driver = {
|
||||
.name = DRVNAME,
|
||||
.owner = THIS_MODULE,
|
||||
},
|
||||
};
|
||||
|
||||
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,
|
||||
FAN_MAX_RPM
|
||||
#define FAN_PRESENT_ATTR_ID(index) FAN##index##_PRESENT
|
||||
#define FAN_PWM_ATTR_ID(index) FAN##index##_PWM
|
||||
#define FAN_RPM_ATTR_ID(index) FAN##index##_INPUT
|
||||
|
||||
#define FAN_ATTR(fan_id) \
|
||||
FAN_PRESENT_ATTR_ID(fan_id), \
|
||||
FAN_PWM_ATTR_ID(fan_id), \
|
||||
FAN_RPM_ATTR_ID(fan_id)
|
||||
|
||||
enum as5916_54x_fan_sysfs_attrs {
|
||||
FAN_ATTR(1),
|
||||
FAN_ATTR(2),
|
||||
FAN_ATTR(3),
|
||||
FAN_ATTR(4),
|
||||
FAN_ATTR(5),
|
||||
FAN_ATTR(6),
|
||||
NUM_OF_FAN_ATTR,
|
||||
NUM_OF_PER_FAN_ATTR = (NUM_OF_FAN_ATTR/NUM_OF_FAN)
|
||||
};
|
||||
|
||||
/* 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
|
||||
/* fan attributes */
|
||||
#define DECLARE_FAN_SENSOR_DEVICE_ATTR(index) \
|
||||
static SENSOR_DEVICE_ATTR(fan##index##_present, S_IRUGO, show_fan, NULL, FAN##index##_PRESENT); \
|
||||
static SENSOR_DEVICE_ATTR(fan##index##_pwm, S_IWUSR | S_IRUGO, show_fan, set_fan, FAN##index##_PWM); \
|
||||
static SENSOR_DEVICE_ATTR(fan##index##_input, S_IRUGO, show_fan, NULL, FAN##index##_INPUT)
|
||||
#define DECLARE_FAN_ATTR(index) \
|
||||
&sensor_dev_attr_fan##index##_present.dev_attr.attr, \
|
||||
&sensor_dev_attr_fan##index##_pwm.dev_attr.attr, \
|
||||
&sensor_dev_attr_fan##index##_input.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
|
||||
|
||||
static SENSOR_DEVICE_ATTR(fan_max_speed_rpm, S_IRUGO, fan_show_value, NULL, FAN_MAX_RPM);
|
||||
#define DECLARE_FAN_MAX_RPM_ATTR(index) &sensor_dev_attr_fan_max_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();
|
||||
DECLARE_FAN_SENSOR_DEVICE_ATTR(1);
|
||||
DECLARE_FAN_SENSOR_DEVICE_ATTR(2);
|
||||
DECLARE_FAN_SENSOR_DEVICE_ATTR(3);
|
||||
DECLARE_FAN_SENSOR_DEVICE_ATTR(4);
|
||||
DECLARE_FAN_SENSOR_DEVICE_ATTR(5);
|
||||
DECLARE_FAN_SENSOR_DEVICE_ATTR(6);
|
||||
|
||||
static struct attribute *as5916_54xks_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(),
|
||||
DECLARE_FAN_MAX_RPM_ATTR(),
|
||||
/* fan attributes */
|
||||
DECLARE_FAN_ATTR(1),
|
||||
DECLARE_FAN_ATTR(2),
|
||||
DECLARE_FAN_ATTR(3),
|
||||
DECLARE_FAN_ATTR(4),
|
||||
DECLARE_FAN_ATTR(5),
|
||||
DECLARE_FAN_ATTR(6),
|
||||
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 as5916_54xks_fan_read_value(struct i2c_client *client, u8 reg)
|
||||
{
|
||||
return i2c_smbus_read_byte_data(client, reg);
|
||||
}
|
||||
|
||||
static int as5916_54xks_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)
|
||||
{
|
||||
return !!(reg_val & BIT(id));
|
||||
}
|
||||
|
||||
static u8 reg_val_to_is_present(u8 reg_val, enum fan_id id)
|
||||
{
|
||||
return !(reg_val & BIT(id));
|
||||
}
|
||||
|
||||
static u8 is_fan_fault(struct as5916_54xks_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;
|
||||
|
||||
as5916_54xks_fan_write_value(client, 0x33, 0); /* Disable fan speed watch dog */
|
||||
as5916_54xks_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 as5916_54xks_fan_data *data = as5916_54xks_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;
|
||||
case FAN_MAX_RPM:
|
||||
ret = sprintf(buf, "%d\n", MAX_FAN_SPEED_RPM);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const struct attribute_group as5916_54xks_fan_group = {
|
||||
.attrs = as5916_54xks_fan_attributes,
|
||||
};
|
||||
|
||||
static struct as5916_54xks_fan_data *as5916_54xks_fan_update_device(struct device *dev)
|
||||
/* Functions to talk to the IPMI layer */
|
||||
|
||||
/* Initialize IPMI address, message buffers and user data */
|
||||
static int init_ipmi_data(struct ipmi_data *ipmi, int iface,
|
||||
struct device *dev)
|
||||
{
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct as5916_54xks_fan_data *data = i2c_get_clientdata(client);
|
||||
int err;
|
||||
|
||||
init_completion(&ipmi->read_complete);
|
||||
|
||||
/* Initialize IPMI address */
|
||||
ipmi->address.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
|
||||
ipmi->address.channel = IPMI_BMC_CHANNEL;
|
||||
ipmi->address.data[0] = 0;
|
||||
ipmi->interface = iface;
|
||||
|
||||
/* Initialize message buffers */
|
||||
ipmi->tx_msgid = 0;
|
||||
ipmi->tx_message.netfn = ACCTON_IPMI_NETFN;
|
||||
|
||||
ipmi->ipmi_hndlrs.ipmi_recv_hndl = ipmi_msg_handler;
|
||||
|
||||
/* Create IPMI messaging interface user */
|
||||
err = ipmi_create_user(ipmi->interface, &ipmi->ipmi_hndlrs,
|
||||
ipmi, &ipmi->user);
|
||||
if (err < 0) {
|
||||
dev_err(dev, "Unable to register user with IPMI "
|
||||
"interface %d\n", ipmi->interface);
|
||||
return -EACCES;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Send an IPMI command */
|
||||
static int ipmi_send_message(struct ipmi_data *ipmi, unsigned char cmd,
|
||||
unsigned char *tx_data, unsigned short tx_len,
|
||||
unsigned char *rx_data, unsigned short rx_len)
|
||||
{
|
||||
int err;
|
||||
|
||||
ipmi->tx_message.cmd = cmd;
|
||||
ipmi->tx_message.data = tx_data;
|
||||
ipmi->tx_message.data_len = tx_len;
|
||||
ipmi->rx_msg_data = rx_data;
|
||||
ipmi->rx_msg_len = rx_len;
|
||||
|
||||
err = ipmi_validate_addr(&ipmi->address, sizeof(ipmi->address));
|
||||
if (err)
|
||||
goto addr_err;
|
||||
|
||||
ipmi->tx_msgid++;
|
||||
err = ipmi_request_settime(ipmi->user, &ipmi->address, ipmi->tx_msgid,
|
||||
&ipmi->tx_message, ipmi, 0, 0, 0);
|
||||
if (err)
|
||||
goto ipmi_req_err;
|
||||
|
||||
err = wait_for_completion_timeout(&ipmi->read_complete, IPMI_TIMEOUT);
|
||||
if (!err)
|
||||
goto ipmi_timeout_err;
|
||||
|
||||
return 0;
|
||||
|
||||
ipmi_timeout_err:
|
||||
err = -ETIMEDOUT;
|
||||
dev_err(&data->pdev->dev, "request_timeout=%x\n", err);
|
||||
return err;
|
||||
ipmi_req_err:
|
||||
dev_err(&data->pdev->dev, "request_settime=%x\n", err);
|
||||
return err;
|
||||
addr_err:
|
||||
dev_err(&data->pdev->dev, "validate_addr=%x\n", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Dispatch IPMI messages to callers */
|
||||
static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data)
|
||||
{
|
||||
unsigned short rx_len;
|
||||
struct ipmi_data *ipmi = user_msg_data;
|
||||
|
||||
if (msg->msgid != ipmi->tx_msgid) {
|
||||
dev_err(&data->pdev->dev, "Mismatch between received msgid "
|
||||
"(%02x) and transmitted msgid (%02x)!\n",
|
||||
(int)msg->msgid,
|
||||
(int)ipmi->tx_msgid);
|
||||
ipmi_free_recv_msg(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
ipmi->rx_recv_type = msg->recv_type;
|
||||
if (msg->msg.data_len > 0)
|
||||
ipmi->rx_result = msg->msg.data[0];
|
||||
else
|
||||
ipmi->rx_result = IPMI_UNKNOWN_ERR_COMPLETION_CODE;
|
||||
|
||||
if (msg->msg.data_len > 1) {
|
||||
rx_len = msg->msg.data_len - 1;
|
||||
if (ipmi->rx_msg_len < rx_len)
|
||||
rx_len = ipmi->rx_msg_len;
|
||||
ipmi->rx_msg_len = rx_len;
|
||||
memcpy(ipmi->rx_msg_data, msg->msg.data + 1, ipmi->rx_msg_len);
|
||||
} else
|
||||
ipmi->rx_msg_len = 0;
|
||||
|
||||
ipmi_free_recv_msg(msg);
|
||||
complete(&ipmi->read_complete);
|
||||
}
|
||||
|
||||
static struct as5916_54xks_fan_data *as5916_54xks_fan_update_device(void)
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
if (time_before(jiffies, data->last_updated + HZ * 5) && data->valid) {
|
||||
return data;
|
||||
}
|
||||
|
||||
mutex_lock(&data->update_lock);
|
||||
|
||||
if (time_after(jiffies, data->last_updated + HZ + HZ / 2) ||
|
||||
!data->valid) {
|
||||
int i;
|
||||
|
||||
dev_dbg(&client->dev, "Starting as5916_54xks_fan update\n");
|
||||
data->valid = 0;
|
||||
|
||||
/* Update fan data
|
||||
*/
|
||||
for (i = 0; i < ARRAY_SIZE(data->reg_val); i++) {
|
||||
int status = as5916_54xks_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;
|
||||
data->valid = 0;
|
||||
status = ipmi_send_message(&data->ipmi, IPMI_FAN_READ_CMD, NULL, 0,
|
||||
data->ipmi_resp, sizeof(data->ipmi_resp));
|
||||
if (unlikely(status != 0)) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
mutex_unlock(&data->update_lock);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
static int as5916_54xks_fan_probe(struct i2c_client *client,
|
||||
const struct i2c_device_id *dev_id)
|
||||
{
|
||||
struct as5916_54xks_fan_data *data;
|
||||
int status;
|
||||
|
||||
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
|
||||
if (unlikely(data->ipmi.rx_result != 0)) {
|
||||
status = -EIO;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
data = kzalloc(sizeof(struct as5916_54xks_fan_data), GFP_KERNEL);
|
||||
if (!data) {
|
||||
status = -ENOMEM;
|
||||
goto exit;
|
||||
data->last_updated = jiffies;
|
||||
data->valid = 1;
|
||||
|
||||
exit:
|
||||
mutex_unlock(&data->update_lock);
|
||||
return data;
|
||||
}
|
||||
|
||||
static ssize_t show_fan(struct device *dev, struct device_attribute *da, char *buf)
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||
unsigned char fid = attr->index / NUM_OF_PER_FAN_ATTR;
|
||||
struct as5916_54xks_fan_data *data = NULL;
|
||||
int value = 0;
|
||||
int index = 0;
|
||||
int present = 0;
|
||||
|
||||
data = as5916_54xks_fan_update_device();
|
||||
if (!data->valid) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
i2c_set_clientdata(client, data);
|
||||
data->valid = 0;
|
||||
mutex_init(&data->update_lock);
|
||||
index = fid * FAN_DATA_COUNT; /* base index */
|
||||
present = !data->ipmi_resp[index + FAN_PRESENT];
|
||||
|
||||
dev_info(&client->dev, "chip found\n");
|
||||
|
||||
/* Register sysfs hooks */
|
||||
status = sysfs_create_group(&client->dev.kobj, &as5916_54xks_fan_group);
|
||||
if (status) {
|
||||
goto exit_free;
|
||||
switch (attr->index) {
|
||||
case FAN1_PRESENT:
|
||||
case FAN2_PRESENT:
|
||||
case FAN3_PRESENT:
|
||||
case FAN4_PRESENT:
|
||||
case FAN5_PRESENT:
|
||||
case FAN6_PRESENT:
|
||||
value = !data->ipmi_resp[index + FAN_PRESENT];
|
||||
break;
|
||||
case FAN1_PWM:
|
||||
case FAN2_PWM:
|
||||
case FAN3_PWM:
|
||||
case FAN4_PWM:
|
||||
case FAN5_PWM:
|
||||
case FAN6_PWM:
|
||||
value = (data->ipmi_resp[index + FAN_PWM] + 1) * 625 / 100;
|
||||
break;
|
||||
case FAN1_INPUT:
|
||||
case FAN2_INPUT:
|
||||
case FAN3_INPUT:
|
||||
case FAN4_INPUT:
|
||||
case FAN5_INPUT:
|
||||
case FAN6_INPUT:
|
||||
value = (int)data->ipmi_resp[index + FAN_SPEED0] |
|
||||
(int)data->ipmi_resp[index + FAN_SPEED1] << 8;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
data->hwmon_dev = hwmon_device_register(&client->dev);
|
||||
if (IS_ERR(data->hwmon_dev)) {
|
||||
status = PTR_ERR(data->hwmon_dev);
|
||||
goto exit_remove;
|
||||
return sprintf(buf, "%d\n", present ? value : 0);
|
||||
}
|
||||
|
||||
static ssize_t set_fan(struct device *dev, struct device_attribute *da,
|
||||
const char *buf, size_t count)
|
||||
{
|
||||
long pwm;
|
||||
int status;
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||
unsigned char fid = attr->index / NUM_OF_PER_FAN_ATTR;
|
||||
|
||||
status = kstrtol(buf, 10, &pwm);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
|
||||
pwm = (pwm * 100) / 625 - 1; /* Convert pwm to register value */
|
||||
|
||||
/* Send IPMI write command */
|
||||
data->ipmi_tx_data[0] = 1; /* All FANs share the same PWM register, ALWAYS set 1 for each fan */
|
||||
data->ipmi_tx_data[1] = 0x02;
|
||||
data->ipmi_tx_data[2] = pwm;
|
||||
status = ipmi_send_message(&data->ipmi, IPMI_FAN_WRITE_CMD,
|
||||
data->ipmi_tx_data, sizeof(data->ipmi_tx_data), NULL, 0);
|
||||
if (unlikely(status != 0)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
dev_info(&client->dev, "%s: fan '%s'\n",
|
||||
dev_name(data->hwmon_dev), client->name);
|
||||
if (unlikely(data->ipmi.rx_result != 0)) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/* Update pwm to ipmi_resp buffer to prevent from the impact of lazy update */
|
||||
data->ipmi_resp[fid * FAN_DATA_COUNT + FAN_PWM] = pwm;
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static int as5916_54xks_fan_probe(struct platform_device *pdev)
|
||||
{
|
||||
int status = -1;
|
||||
|
||||
/* Register sysfs hooks */
|
||||
status = sysfs_create_group(&pdev->dev.kobj, &as5916_54xks_fan_group);
|
||||
if (status) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
dev_info(&pdev->dev, "device created\n");
|
||||
|
||||
return 0;
|
||||
|
||||
exit_remove:
|
||||
sysfs_remove_group(&client->dev.kobj, &as5916_54xks_fan_group);
|
||||
exit_free:
|
||||
kfree(data);
|
||||
exit:
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static int as5916_54xks_fan_remove(struct i2c_client *client)
|
||||
static int as5916_54xks_fan_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct as5916_54xks_fan_data *data = i2c_get_clientdata(client);
|
||||
hwmon_device_unregister(data->hwmon_dev);
|
||||
sysfs_remove_group(&client->dev.kobj, &as5916_54xks_fan_group);
|
||||
|
||||
sysfs_remove_group(&pdev->dev.kobj, &as5916_54xks_fan_group);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Addresses to scan */
|
||||
static const unsigned short normal_i2c[] = { 0x66, I2C_CLIENT_END };
|
||||
|
||||
static const struct i2c_device_id as5916_54xks_fan_id[] = {
|
||||
{ "as5916_54xks_fan", 0 },
|
||||
{}
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, as5916_54xks_fan_id);
|
||||
|
||||
static struct i2c_driver as5916_54xks_fan_driver = {
|
||||
.class = I2C_CLASS_HWMON,
|
||||
.driver = {
|
||||
.name = DRVNAME,
|
||||
},
|
||||
.probe = as5916_54xks_fan_probe,
|
||||
.remove = as5916_54xks_fan_remove,
|
||||
.id_table = as5916_54xks_fan_id,
|
||||
.address_list = normal_i2c,
|
||||
};
|
||||
|
||||
static int __init as5916_54xks_fan_init(void)
|
||||
{
|
||||
return i2c_add_driver(&as5916_54xks_fan_driver);
|
||||
int ret;
|
||||
|
||||
data = kzalloc(sizeof(struct as5916_54xks_fan_data), GFP_KERNEL);
|
||||
if (!data) {
|
||||
ret = -ENOMEM;
|
||||
goto alloc_err;
|
||||
}
|
||||
|
||||
mutex_init(&data->update_lock);
|
||||
data->valid = 0;
|
||||
|
||||
ret = platform_driver_register(&as5916_54xks_fan_driver);
|
||||
if (ret < 0) {
|
||||
goto dri_reg_err;
|
||||
}
|
||||
|
||||
data->pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
|
||||
if (IS_ERR(data->pdev)) {
|
||||
ret = PTR_ERR(data->pdev);
|
||||
goto dev_reg_err;
|
||||
}
|
||||
|
||||
/* Set up IPMI interface */
|
||||
ret = init_ipmi_data(&data->ipmi, 0, &data->pdev->dev);
|
||||
if (ret)
|
||||
goto ipmi_err;
|
||||
|
||||
return 0;
|
||||
|
||||
ipmi_err:
|
||||
platform_device_unregister(data->pdev);
|
||||
dev_reg_err:
|
||||
platform_driver_unregister(&as5916_54xks_fan_driver);
|
||||
dri_reg_err:
|
||||
kfree(data);
|
||||
alloc_err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void __exit as5916_54xks_fan_exit(void)
|
||||
{
|
||||
i2c_del_driver(&as5916_54xks_fan_driver);
|
||||
ipmi_destroy_user(data->ipmi.user);
|
||||
platform_device_unregister(data->pdev);
|
||||
platform_driver_unregister(&as5916_54xks_fan_driver);
|
||||
kfree(data);
|
||||
}
|
||||
|
||||
MODULE_AUTHOR("Brandon Chuang <brandon_chuang@accton.com.tw>");
|
||||
MODULE_DESCRIPTION("as5916_54xks fan driver");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
module_init(as5916_54xks_fan_init);
|
||||
module_exit(as5916_54xks_fan_exit);
|
||||
|
||||
MODULE_AUTHOR("Brandon Chuang <brandon_chuang@accton.com.tw>");
|
||||
MODULE_DESCRIPTION("as5916_54xks_fan driver");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
|
||||
@@ -1,84 +1,92 @@
|
||||
/*
|
||||
* A LED driver for the accton_as5916_54xks_led
|
||||
* Copyright (C) Brandon Chuang <brandon_chuang@accton.com.tw>
|
||||
*
|
||||
* Copyright (C) 2016 Accton Technology Corporation.
|
||||
* Brandon Chuang <brandon_chuang@accton.com.tw>
|
||||
* Based on:
|
||||
* pca954x.c from Kumar Gala <galak@kernel.crashing.org>
|
||||
* Copyright (C) 2006
|
||||
*
|
||||
* 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.
|
||||
* Based on:
|
||||
* pca954x.c from Ken Harrenstien
|
||||
* Copyright (C) 2004 Google, Inc. (Ken Harrenstien)
|
||||
*
|
||||
* 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.
|
||||
* Based on:
|
||||
* i2c-virtual_cb.c from Brian Kuschak <bkuschak@yahoo.com>
|
||||
* and
|
||||
* pca9540.c from Jean Delvare <khali@linux-fr.org>.
|
||||
*
|
||||
* 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.
|
||||
* 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/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/device.h>
|
||||
#include <linux/version.h>
|
||||
#include <linux/stat.h>
|
||||
#include <linux/sysfs.h>
|
||||
#include <linux/hwmon-sysfs.h>
|
||||
#include <linux/ipmi.h>
|
||||
#include <linux/ipmi_smi.h>
|
||||
#include <linux/platform_device.h>
|
||||
|
||||
#define DRVNAME "accton_as5916_54xks_led"
|
||||
#define DRVNAME "as5916_54xks_led"
|
||||
#define ACCTON_IPMI_NETFN 0x34
|
||||
#define IPMI_LED_READ_CMD 0x1A
|
||||
#define IPMI_LED_WRITE_CMD 0x1B
|
||||
#define IPMI_TIMEOUT (20 * HZ)
|
||||
|
||||
#define DEBUG_MODE 1
|
||||
static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data);
|
||||
static ssize_t set_led(struct device *dev, struct device_attribute *da,
|
||||
const char *buf, size_t count);
|
||||
static ssize_t show_led(struct device *dev, struct device_attribute *attr, char *buf);
|
||||
static int as5916_54xks_led_probe(struct platform_device *pdev);
|
||||
static int as5916_54xks_led_remove(struct platform_device *pdev);
|
||||
|
||||
#if (DEBUG_MODE == 1)
|
||||
#define DEBUG_PRINT(fmt, args...) \
|
||||
printk (KERN_INFO "%s:%s[%d]: " fmt "\r\n", __FILE__, __FUNCTION__, __LINE__, ##args)
|
||||
#else
|
||||
#define DEBUG_PRINT(fmt, args...)
|
||||
#endif
|
||||
|
||||
extern int as5916_54xks_cpld_read(unsigned short cpld_addr, u8 reg);
|
||||
extern int as5916_54xks_cpld_write(unsigned short cpld_addr, u8 reg, u8 value);
|
||||
|
||||
struct accton_as5916_54xks_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[2]; /* Register value, 0 = RELEASE/DIAG LED,
|
||||
1 = FAN/PSU LED,
|
||||
2 ~ 4 = SYSTEM LED */
|
||||
enum led_data_index {
|
||||
LOC_INDEX,
|
||||
DIAG_RED_INDEX,
|
||||
DIAG_GREEN_INDEX
|
||||
};
|
||||
|
||||
static struct accton_as5916_54xks_led_data *ledctl = NULL;
|
||||
struct ipmi_data {
|
||||
struct completion read_complete;
|
||||
struct ipmi_addr address;
|
||||
ipmi_user_t user;
|
||||
int interface;
|
||||
|
||||
#define LED_CNTRLER_I2C_ADDRESS (0x60)
|
||||
struct kernel_ipmi_msg tx_message;
|
||||
long tx_msgid;
|
||||
|
||||
#define LED_TYPE_DIAG_REG_MASK (0x0C)
|
||||
#define LED_MODE_DIAG_GREEN_VALUE (0x04)
|
||||
#define LED_MODE_DIAG_ORANGE_VALUE (0x08)
|
||||
#define LED_MODE_DIAG_OFF_VALUE (0x0C)
|
||||
void *rx_msg_data;
|
||||
unsigned short rx_msg_len;
|
||||
unsigned char rx_result;
|
||||
int rx_recv_type;
|
||||
|
||||
|
||||
#define LED_TYPE_LOC_REG_MASK (0x10)
|
||||
#define LED_MODE_LOC_ORANGE_VALUE (0x00)
|
||||
#define LED_MODE_LOC_OFF_VALUE (0x10)
|
||||
|
||||
static const u8 led_reg[] = {
|
||||
0x65, /* LOC/DIAG/FAN LED */
|
||||
0x66, /* PSU LED */
|
||||
};
|
||||
|
||||
enum led_type {
|
||||
LED_TYPE_DIAG,
|
||||
LED_TYPE_LOC,
|
||||
LED_TYPE_FAN,
|
||||
LED_TYPE_PSU1,
|
||||
LED_TYPE_PSU2
|
||||
struct ipmi_user_hndl ipmi_hndlrs;
|
||||
};
|
||||
|
||||
struct as5916_54xks_led_data {
|
||||
struct platform_device *pdev;
|
||||
struct mutex update_lock;
|
||||
char valid; /* != 0 if registers are valid */
|
||||
unsigned long last_updated; /* In jiffies */
|
||||
unsigned char ipmi_resp[3]; /* 0: LOC LED, 1: DIAG Red LED, 2: DIAG Green LED */
|
||||
struct ipmi_data ipmi;
|
||||
};
|
||||
|
||||
struct as5916_54xks_led_data *data = NULL;
|
||||
|
||||
static struct platform_driver as5916_54xks_led_driver = {
|
||||
.probe = as5916_54xks_led_probe,
|
||||
.remove = as5916_54xks_led_remove,
|
||||
.driver = {
|
||||
.name = DRVNAME,
|
||||
.owner = THIS_MODULE,
|
||||
},
|
||||
};
|
||||
|
||||
/* FAN/PSU/DIAG/RELEASE led mode */
|
||||
enum led_light_mode {
|
||||
LED_MODE_OFF,
|
||||
LED_MODE_RED = 10,
|
||||
@@ -102,285 +110,346 @@ enum led_light_mode {
|
||||
LED_MODE_UNKNOWN = 99
|
||||
};
|
||||
|
||||
struct led_type_mode {
|
||||
enum led_type type;
|
||||
enum led_light_mode mode;
|
||||
int type_mask;
|
||||
int mode_value;
|
||||
enum as5916_54x_led_sysfs_attrs {
|
||||
LED_LOC,
|
||||
LED_DIAG,
|
||||
LED_PSU1,
|
||||
LED_PSU2,
|
||||
LED_FAN
|
||||
};
|
||||
|
||||
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_ORANGE, LED_TYPE_LOC_REG_MASK, LED_MODE_LOC_ORANGE_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_ORANGE, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_ORANGE_VALUE},
|
||||
static SENSOR_DEVICE_ATTR(led_loc, S_IWUSR | S_IRUGO, show_led, set_led, LED_LOC);
|
||||
static SENSOR_DEVICE_ATTR(led_diag, S_IWUSR | S_IRUGO, show_led, set_led, LED_DIAG);
|
||||
static SENSOR_DEVICE_ATTR(led_psu1, S_IWUSR | S_IRUGO, show_led, set_led, LED_PSU1);
|
||||
static SENSOR_DEVICE_ATTR(led_psu2, S_IWUSR | S_IRUGO, show_led, set_led, LED_PSU2);
|
||||
static SENSOR_DEVICE_ATTR(led_fan, S_IWUSR | S_IRUGO, show_led, set_led, LED_FAN);
|
||||
|
||||
static struct attribute *as5916_54xks_led_attributes[] = {
|
||||
&sensor_dev_attr_led_loc.dev_attr.attr,
|
||||
&sensor_dev_attr_led_diag.dev_attr.attr,
|
||||
&sensor_dev_attr_led_psu1.dev_attr.attr,
|
||||
&sensor_dev_attr_led_psu2.dev_attr.attr,
|
||||
&sensor_dev_attr_led_fan.dev_attr.attr,
|
||||
NULL
|
||||
};
|
||||
|
||||
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].type_mask & reg_val) ==
|
||||
led_type_mode_data[i].mode_value) {
|
||||
return led_type_mode_data[i].mode;
|
||||
}
|
||||
}
|
||||
|
||||
return LED_MODE_UNKNOWN;
|
||||
}
|
||||
|
||||
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++) {
|
||||
int type_mask, mode_value;
|
||||
|
||||
if (type != led_type_mode_data[i].type)
|
||||
continue;
|
||||
|
||||
if (mode != led_type_mode_data[i].mode)
|
||||
continue;
|
||||
|
||||
type_mask = led_type_mode_data[i].type_mask;
|
||||
mode_value = led_type_mode_data[i].mode_value;
|
||||
reg_val = (reg_val & ~type_mask) | mode_value;
|
||||
}
|
||||
|
||||
return reg_val;
|
||||
}
|
||||
|
||||
static int accton_as5916_54xks_led_read_value(u8 reg)
|
||||
{
|
||||
return as5916_54xks_cpld_read(LED_CNTRLER_I2C_ADDRESS, reg);
|
||||
}
|
||||
|
||||
static int accton_as5916_54xks_led_write_value(u8 reg, u8 value)
|
||||
{
|
||||
return as5916_54xks_cpld_write(LED_CNTRLER_I2C_ADDRESS, reg, value);
|
||||
}
|
||||
|
||||
static void accton_as5916_54xks_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_as5916_54xks_led update\n");
|
||||
ledctl->valid = 0;
|
||||
|
||||
/* Update LED data
|
||||
*/
|
||||
for (i = 0; i < ARRAY_SIZE(ledctl->reg_val); i++) {
|
||||
int status = accton_as5916_54xks_led_read_value(led_reg[i]);
|
||||
|
||||
if (status < 0) {
|
||||
dev_dbg(&ledctl->pdev->dev, "reg %d, err %d\n", led_reg[i], 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_as5916_54xks_led_set(struct led_classdev *led_cdev,
|
||||
enum led_brightness led_light_mode,
|
||||
u8 reg, enum led_type type)
|
||||
{
|
||||
int reg_val;
|
||||
|
||||
mutex_lock(&ledctl->update_lock);
|
||||
reg_val = accton_as5916_54xks_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_as5916_54xks_led_write_value(reg, reg_val);
|
||||
ledctl->valid = 0;
|
||||
|
||||
exit:
|
||||
mutex_unlock(&ledctl->update_lock);
|
||||
}
|
||||
|
||||
static void accton_as7312_54x_led_auto_set(struct led_classdev *led_cdev,
|
||||
enum led_brightness led_light_mode)
|
||||
{
|
||||
}
|
||||
|
||||
static enum led_brightness accton_as7312_54x_led_auto_get(struct led_classdev *cdev)
|
||||
{
|
||||
return LED_MODE_AUTO;
|
||||
}
|
||||
|
||||
static void accton_as5916_54xks_led_diag_set(struct led_classdev *led_cdev,
|
||||
enum led_brightness led_light_mode)
|
||||
{
|
||||
accton_as5916_54xks_led_set(led_cdev, led_light_mode, led_reg[0], LED_TYPE_DIAG);
|
||||
}
|
||||
|
||||
static enum led_brightness accton_as5916_54xks_led_diag_get(struct led_classdev *cdev)
|
||||
{
|
||||
accton_as5916_54xks_led_update();
|
||||
return led_reg_val_to_light_mode(LED_TYPE_DIAG, ledctl->reg_val[0]);
|
||||
}
|
||||
|
||||
static enum led_brightness accton_as5916_54xks_led_loc_get(struct led_classdev *cdev)
|
||||
{
|
||||
accton_as5916_54xks_led_update();
|
||||
return led_reg_val_to_light_mode(LED_TYPE_LOC, ledctl->reg_val[0]);
|
||||
}
|
||||
|
||||
static void accton_as5916_54xks_led_loc_set(struct led_classdev *led_cdev,
|
||||
enum led_brightness led_light_mode)
|
||||
{
|
||||
accton_as5916_54xks_led_set(led_cdev, led_light_mode, led_reg[0], LED_TYPE_LOC);
|
||||
}
|
||||
|
||||
static struct led_classdev accton_as5916_54xks_leds[] = {
|
||||
[LED_TYPE_LOC] = {
|
||||
.name = "accton_as5916_54xks_led::loc",
|
||||
.default_trigger = "unused",
|
||||
.brightness_set = accton_as5916_54xks_led_loc_set,
|
||||
.brightness_get = accton_as5916_54xks_led_loc_get,
|
||||
.max_brightness = LED_MODE_ORANGE,
|
||||
},
|
||||
[LED_TYPE_DIAG] = {
|
||||
.name = "accton_as5916_54xks_led::diag",
|
||||
.default_trigger = "unused",
|
||||
.brightness_set = accton_as5916_54xks_led_diag_set,
|
||||
.brightness_get = accton_as5916_54xks_led_diag_get,
|
||||
.max_brightness = LED_MODE_GREEN,
|
||||
},
|
||||
[LED_TYPE_PSU1] = {
|
||||
.name = "accton_as5916_54xks_led::psu1",
|
||||
.default_trigger = "unused",
|
||||
.brightness_set = accton_as7312_54x_led_auto_set,
|
||||
.brightness_get = accton_as7312_54x_led_auto_get,
|
||||
.max_brightness = LED_MODE_AUTO,
|
||||
},
|
||||
[LED_TYPE_PSU2] = {
|
||||
.name = "accton_as5916_54xks_led::psu2",
|
||||
.default_trigger = "unused",
|
||||
.brightness_set = accton_as7312_54x_led_auto_set,
|
||||
.brightness_get = accton_as7312_54x_led_auto_get,
|
||||
.max_brightness = LED_MODE_AUTO,
|
||||
},
|
||||
[LED_TYPE_FAN] = {
|
||||
.name = "accton_as5916_54xks_led::fan",
|
||||
.default_trigger = "unused",
|
||||
.brightness_set = accton_as7312_54x_led_auto_set,
|
||||
.brightness_get = accton_as7312_54x_led_auto_get,
|
||||
.max_brightness = LED_MODE_AUTO,
|
||||
},
|
||||
static const struct attribute_group as5916_54xks_led_group = {
|
||||
.attrs = as5916_54xks_led_attributes,
|
||||
};
|
||||
|
||||
static int accton_as5916_54xks_led_probe(struct platform_device *pdev)
|
||||
{
|
||||
int ret, i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(accton_as5916_54xks_leds); i++) {
|
||||
ret = led_classdev_register(&pdev->dev, &accton_as5916_54xks_leds[i]);
|
||||
|
||||
if (ret < 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if all LEDs were successfully registered */
|
||||
if (i != ARRAY_SIZE(accton_as5916_54xks_leds)){
|
||||
int j;
|
||||
|
||||
/* only unregister the LEDs that were successfully registered */
|
||||
for (j = 0; j < i; j++) {
|
||||
led_classdev_unregister(&accton_as5916_54xks_leds[i]);
|
||||
}
|
||||
}
|
||||
/* Functions to talk to the IPMI layer */
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int accton_as5916_54xks_led_remove(struct platform_device *pdev)
|
||||
/* Initialize IPMI address, message buffers and user data */
|
||||
static int init_ipmi_data(struct ipmi_data *ipmi, int iface,
|
||||
struct device *dev)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(accton_as5916_54xks_leds); i++) {
|
||||
led_classdev_unregister(&accton_as5916_54xks_leds[i]);
|
||||
int err;
|
||||
|
||||
init_completion(&ipmi->read_complete);
|
||||
|
||||
/* Initialize IPMI address */
|
||||
ipmi->address.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
|
||||
ipmi->address.channel = IPMI_BMC_CHANNEL;
|
||||
ipmi->address.data[0] = 0;
|
||||
ipmi->interface = iface;
|
||||
|
||||
/* Initialize message buffers */
|
||||
ipmi->tx_msgid = 0;
|
||||
ipmi->tx_message.netfn = ACCTON_IPMI_NETFN;
|
||||
|
||||
ipmi->ipmi_hndlrs.ipmi_recv_hndl = ipmi_msg_handler;
|
||||
|
||||
/* Create IPMI messaging interface user */
|
||||
err = ipmi_create_user(ipmi->interface, &ipmi->ipmi_hndlrs,
|
||||
ipmi, &ipmi->user);
|
||||
if (err < 0) {
|
||||
dev_err(dev, "Unable to register user with IPMI "
|
||||
"interface %d\n", ipmi->interface);
|
||||
return -EACCES;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct platform_driver accton_as5916_54xks_led_driver = {
|
||||
.probe = accton_as5916_54xks_led_probe,
|
||||
.remove = accton_as5916_54xks_led_remove,
|
||||
.driver = {
|
||||
.name = DRVNAME,
|
||||
.owner = THIS_MODULE,
|
||||
},
|
||||
};
|
||||
|
||||
static int __init accton_as5916_54xks_led_init(void)
|
||||
/* Send an IPMI command */
|
||||
static int ipmi_send_message(struct ipmi_data *ipmi, unsigned char cmd,
|
||||
unsigned char *tx_data, unsigned short tx_len,
|
||||
unsigned char *rx_data, unsigned short rx_len)
|
||||
{
|
||||
int ret;
|
||||
int err;
|
||||
|
||||
ret = platform_driver_register(&accton_as5916_54xks_led_driver);
|
||||
if (ret < 0) {
|
||||
goto exit;
|
||||
}
|
||||
ipmi->tx_message.cmd = cmd;
|
||||
ipmi->tx_message.data = tx_data;
|
||||
ipmi->tx_message.data_len = tx_len;
|
||||
ipmi->rx_msg_data = rx_data;
|
||||
ipmi->rx_msg_len = rx_len;
|
||||
|
||||
ledctl = kzalloc(sizeof(struct accton_as5916_54xks_led_data), GFP_KERNEL);
|
||||
if (!ledctl) {
|
||||
ret = -ENOMEM;
|
||||
goto exit_driver;
|
||||
}
|
||||
err = ipmi_validate_addr(&ipmi->address, sizeof(ipmi->address));
|
||||
if (err)
|
||||
goto addr_err;
|
||||
|
||||
mutex_init(&ledctl->update_lock);
|
||||
ipmi->tx_msgid++;
|
||||
err = ipmi_request_settime(ipmi->user, &ipmi->address, ipmi->tx_msgid,
|
||||
&ipmi->tx_message, ipmi, 0, 0, 0);
|
||||
if (err)
|
||||
goto ipmi_req_err;
|
||||
|
||||
ledctl->pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
|
||||
if (IS_ERR(ledctl->pdev)) {
|
||||
ret = PTR_ERR(ledctl->pdev);
|
||||
goto exit_free;
|
||||
}
|
||||
err = wait_for_completion_timeout(&ipmi->read_complete, IPMI_TIMEOUT);
|
||||
if (!err)
|
||||
goto ipmi_timeout_err;
|
||||
|
||||
return 0;
|
||||
|
||||
exit_free:
|
||||
kfree(ledctl);
|
||||
exit_driver:
|
||||
platform_driver_unregister(&accton_as5916_54xks_led_driver);
|
||||
exit:
|
||||
return ret;
|
||||
ipmi_timeout_err:
|
||||
err = -ETIMEDOUT;
|
||||
dev_err(&data->pdev->dev, "request_timeout=%x\n", err);
|
||||
return err;
|
||||
ipmi_req_err:
|
||||
dev_err(&data->pdev->dev, "request_settime=%x\n", err);
|
||||
return err;
|
||||
addr_err:
|
||||
dev_err(&data->pdev->dev, "validate_addr=%x\n", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
static void __exit accton_as5916_54xks_led_exit(void)
|
||||
/* Dispatch IPMI messages to callers */
|
||||
static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data)
|
||||
{
|
||||
platform_device_unregister(ledctl->pdev);
|
||||
platform_driver_unregister(&accton_as5916_54xks_led_driver);
|
||||
kfree(ledctl);
|
||||
unsigned short rx_len;
|
||||
struct ipmi_data *ipmi = user_msg_data;
|
||||
|
||||
if (msg->msgid != ipmi->tx_msgid) {
|
||||
dev_err(&data->pdev->dev, "Mismatch between received msgid "
|
||||
"(%02x) and transmitted msgid (%02x)!\n",
|
||||
(int)msg->msgid,
|
||||
(int)ipmi->tx_msgid);
|
||||
ipmi_free_recv_msg(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
ipmi->rx_recv_type = msg->recv_type;
|
||||
if (msg->msg.data_len > 0)
|
||||
ipmi->rx_result = msg->msg.data[0];
|
||||
else
|
||||
ipmi->rx_result = IPMI_UNKNOWN_ERR_COMPLETION_CODE;
|
||||
|
||||
if (msg->msg.data_len > 1) {
|
||||
rx_len = msg->msg.data_len - 1;
|
||||
if (ipmi->rx_msg_len < rx_len)
|
||||
rx_len = ipmi->rx_msg_len;
|
||||
ipmi->rx_msg_len = rx_len;
|
||||
memcpy(ipmi->rx_msg_data, msg->msg.data + 1, ipmi->rx_msg_len);
|
||||
} else
|
||||
ipmi->rx_msg_len = 0;
|
||||
|
||||
ipmi_free_recv_msg(msg);
|
||||
complete(&ipmi->read_complete);
|
||||
}
|
||||
|
||||
late_initcall(accton_as5916_54xks_led_init);
|
||||
module_exit(accton_as5916_54xks_led_exit);
|
||||
static struct as5916_54xks_led_data *as5916_54xks_led_update_device(void)
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
if (time_before(jiffies, data->last_updated + HZ * 5) && data->valid) {
|
||||
return data;
|
||||
}
|
||||
|
||||
mutex_lock(&data->update_lock);
|
||||
|
||||
data->valid = 0;
|
||||
status = ipmi_send_message(&data->ipmi, IPMI_LED_READ_CMD, NULL, 0,
|
||||
data->ipmi_resp, sizeof(data->ipmi_resp));
|
||||
if (unlikely(status != 0)) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (unlikely(data->ipmi.rx_result != 0)) {
|
||||
status = -EIO;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
data->last_updated = jiffies;
|
||||
data->valid = 1;
|
||||
|
||||
exit:
|
||||
mutex_unlock(&data->update_lock);
|
||||
return data;
|
||||
}
|
||||
|
||||
static ssize_t show_led(struct device *dev, struct device_attribute *da, char *buf)
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||
struct as5916_54xks_led_data *data = NULL;
|
||||
int value = 0;
|
||||
|
||||
data = as5916_54xks_led_update_device();
|
||||
if (!data->valid) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
switch (attr->index) {
|
||||
case LED_LOC:
|
||||
value = data->ipmi_resp[LOC_INDEX] ? LED_MODE_ORANGE_BLINKING : LED_MODE_OFF;
|
||||
break;
|
||||
case LED_DIAG:
|
||||
{
|
||||
if (!data->ipmi_resp[DIAG_GREEN_INDEX] && !data->ipmi_resp[DIAG_RED_INDEX])
|
||||
value = LED_MODE_OFF;
|
||||
else if (data->ipmi_resp[DIAG_GREEN_INDEX] && data->ipmi_resp[DIAG_RED_INDEX])
|
||||
value = LED_MODE_OFF;
|
||||
else if (data->ipmi_resp[DIAG_RED_INDEX])
|
||||
value = LED_MODE_ORANGE;
|
||||
else if (data->ipmi_resp[DIAG_GREEN_INDEX])
|
||||
value = LED_MODE_GREEN;
|
||||
break;
|
||||
}
|
||||
case LED_PSU1:
|
||||
case LED_PSU2:
|
||||
case LED_FAN:
|
||||
value = LED_MODE_AUTO;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return sprintf(buf, "%d\n", value);
|
||||
}
|
||||
|
||||
static ssize_t set_led(struct device *dev, struct device_attribute *da,
|
||||
const char *buf, size_t count)
|
||||
{
|
||||
long mode;
|
||||
int status;
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||
struct as5916_54xks_led_data *data = NULL;
|
||||
|
||||
status = kstrtol(buf, 10, &mode);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
|
||||
data = as5916_54xks_led_update_device();
|
||||
if (!data->valid) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
switch (attr->index) {
|
||||
case LED_LOC:
|
||||
data->ipmi_resp[LOC_INDEX] = !!mode;
|
||||
break;
|
||||
case LED_DIAG:
|
||||
{
|
||||
if (mode == LED_MODE_GREEN) {
|
||||
data->ipmi_resp[DIAG_GREEN_INDEX] = 1;
|
||||
data->ipmi_resp[DIAG_RED_INDEX] = 0;
|
||||
}
|
||||
else if (mode == LED_MODE_ORANGE) {
|
||||
data->ipmi_resp[DIAG_GREEN_INDEX] = 0;
|
||||
data->ipmi_resp[DIAG_RED_INDEX] = 1;
|
||||
}
|
||||
else { /* OFF */
|
||||
data->ipmi_resp[DIAG_GREEN_INDEX] = 0;
|
||||
data->ipmi_resp[DIAG_RED_INDEX] = 0;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Send IPMI write command */
|
||||
status = ipmi_send_message(&data->ipmi, IPMI_LED_WRITE_CMD,
|
||||
data->ipmi_resp, sizeof(data->ipmi_resp), NULL, 0);
|
||||
if (unlikely(status != 0)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
if (unlikely(data->ipmi.rx_result != 0)) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static int as5916_54xks_led_probe(struct platform_device *pdev)
|
||||
{
|
||||
int status = -1;
|
||||
|
||||
/* Register sysfs hooks */
|
||||
status = sysfs_create_group(&pdev->dev.kobj, &as5916_54xks_led_group);
|
||||
if (status) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
dev_info(&pdev->dev, "device created\n");
|
||||
|
||||
return 0;
|
||||
|
||||
exit:
|
||||
return status;
|
||||
}
|
||||
|
||||
static int as5916_54xks_led_remove(struct platform_device *pdev)
|
||||
{
|
||||
sysfs_remove_group(&pdev->dev.kobj, &as5916_54xks_led_group);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __init as5916_54xks_led_init(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
data = kzalloc(sizeof(struct as5916_54xks_led_data), GFP_KERNEL);
|
||||
if (!data) {
|
||||
ret = -ENOMEM;
|
||||
goto alloc_err;
|
||||
}
|
||||
|
||||
mutex_init(&data->update_lock);
|
||||
data->valid = 0;
|
||||
|
||||
ret = platform_driver_register(&as5916_54xks_led_driver);
|
||||
if (ret < 0) {
|
||||
goto dri_reg_err;
|
||||
}
|
||||
|
||||
data->pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
|
||||
if (IS_ERR(data->pdev)) {
|
||||
ret = PTR_ERR(data->pdev);
|
||||
goto dev_reg_err;
|
||||
}
|
||||
|
||||
/* Set up IPMI interface */
|
||||
ret = init_ipmi_data(&data->ipmi, 0, &data->pdev->dev);
|
||||
if (ret)
|
||||
goto ipmi_err;
|
||||
|
||||
return 0;
|
||||
|
||||
ipmi_err:
|
||||
platform_device_unregister(data->pdev);
|
||||
dev_reg_err:
|
||||
platform_driver_unregister(&as5916_54xks_led_driver);
|
||||
dri_reg_err:
|
||||
kfree(data);
|
||||
alloc_err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void __exit as5916_54xks_led_exit(void)
|
||||
{
|
||||
ipmi_destroy_user(data->ipmi.user);
|
||||
platform_device_unregister(data->pdev);
|
||||
platform_driver_unregister(&as5916_54xks_led_driver);
|
||||
kfree(data);
|
||||
}
|
||||
|
||||
MODULE_AUTHOR("Brandon Chuang <brandon_chuang@accton.com.tw>");
|
||||
MODULE_DESCRIPTION("accton_as5916_54xks_led driver");
|
||||
MODULE_DESCRIPTION("AS5916 54XKS led driver");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
module_init(as5916_54xks_led_init);
|
||||
module_exit(as5916_54xks_led_exit);
|
||||
|
||||
|
||||
@@ -1,288 +1,531 @@
|
||||
/*
|
||||
* An hwmon driver for accton as5916_54xks Power Module
|
||||
* Copyright (C) Brandon Chuang <brandon_chuang@accton.com.tw>
|
||||
* Based on:
|
||||
* pca954x.c from Kumar Gala <galak@kernel.crashing.org>
|
||||
* Copyright (C) 2006
|
||||
*
|
||||
* Copyright (C) 2014 Accton Technology Corporation.
|
||||
* Brandon Chuang <brandon_chuang@accton.com.tw>
|
||||
* Based on:
|
||||
* pca954x.c from Ken Harrenstien
|
||||
* Copyright (C) 2004 Google, Inc. (Ken Harrenstien)
|
||||
*
|
||||
* Based on ad7414.c
|
||||
* Copyright 2006 Stefan Roese <sr at denx.de>, DENX Software Engineering
|
||||
* Based on:
|
||||
* i2c-virtual_cb.c from Brian Kuschak <bkuschak@yahoo.com>
|
||||
* and
|
||||
* pca9540.c from Jean Delvare <khali@linux-fr.org>.
|
||||
*
|
||||
* 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.
|
||||
* 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/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/init.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/dmi.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/version.h>
|
||||
#include <linux/stat.h>
|
||||
#include <linux/sysfs.h>
|
||||
#include <linux/hwmon-sysfs.h>
|
||||
#include <linux/ipmi.h>
|
||||
#include <linux/ipmi_smi.h>
|
||||
#include <linux/platform_device.h>
|
||||
|
||||
static ssize_t show_status(struct device *dev, struct device_attribute *da, char *buf);
|
||||
static ssize_t show_model_name(struct device *dev, struct device_attribute *da, char *buf);
|
||||
static int as5916_54xks_psu_read_block(struct i2c_client *client, u8 command, u8 *data,int data_len);
|
||||
extern int as5916_54xks_cpld_read(unsigned short cpld_addr, u8 reg);
|
||||
#define DRVNAME "as5916_54xks_psu"
|
||||
#define ACCTON_IPMI_NETFN 0x34
|
||||
#define IPMI_PSU_READ_CMD 0x16
|
||||
#define IPMI_PSU_MODEL_NAME_CMD 0x10
|
||||
#define IPMI_PSU_SERIAL_NUM_CMD 0x11
|
||||
#define IPMI_TIMEOUT (20 * HZ)
|
||||
|
||||
/* Addresses scanned
|
||||
*/
|
||||
static const unsigned short normal_i2c[] = { I2C_CLIENT_END };
|
||||
static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data);
|
||||
static ssize_t show_psu(struct device *dev, struct device_attribute *attr, char *buf);
|
||||
static ssize_t show_string(struct device *dev, struct device_attribute *attr, char *buf);
|
||||
static int as5916_54xks_psu_probe(struct platform_device *pdev);
|
||||
static int as5916_54xks_psu_remove(struct platform_device *pdev);
|
||||
|
||||
enum psu_id {
|
||||
PSU_1,
|
||||
PSU_2,
|
||||
NUM_OF_PSU
|
||||
};
|
||||
|
||||
enum psu_data_index {
|
||||
PSU_PRESENT = 0,
|
||||
PSU_TEMP_FAULT,
|
||||
PSU_POWER_GOOD_CPLD,
|
||||
PSU_POWER_GOOD_PMBUS,
|
||||
PSU_OVER_VOLTAGE,
|
||||
PSU_OVER_CURRENT,
|
||||
PSU_POWER_ON,
|
||||
PSU_VIN0,
|
||||
PSU_VIN1,
|
||||
PSU_VOUT0,
|
||||
PSU_VOUT1,
|
||||
PSU_IOUT0,
|
||||
PSU_IOUT1,
|
||||
PSU_TEMP0,
|
||||
PSU_TEMP1,
|
||||
PSU_FAN0,
|
||||
PSU_FAN1,
|
||||
PSU_POUT0,
|
||||
PSU_POUT1,
|
||||
PSU_STATUS_COUNT,
|
||||
PSU_MODEL = 0,
|
||||
PSU_SERIAL = 0
|
||||
};
|
||||
|
||||
struct ipmi_data {
|
||||
struct completion read_complete;
|
||||
struct ipmi_addr address;
|
||||
ipmi_user_t user;
|
||||
int interface;
|
||||
|
||||
struct kernel_ipmi_msg tx_message;
|
||||
long tx_msgid;
|
||||
|
||||
void *rx_msg_data;
|
||||
unsigned short rx_msg_len;
|
||||
unsigned char rx_result;
|
||||
int rx_recv_type;
|
||||
|
||||
struct ipmi_user_hndl ipmi_hndlrs;
|
||||
};
|
||||
|
||||
struct ipmi_psu_resp_data {
|
||||
unsigned char status[19];
|
||||
char serial[19];
|
||||
char model[9];
|
||||
};
|
||||
|
||||
/* Each client has this additional data
|
||||
*/
|
||||
struct as5916_54xks_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[9]; /* Model name, read from eeprom */
|
||||
struct platform_device *pdev;
|
||||
struct mutex update_lock;
|
||||
char valid[2]; /* != 0 if registers are valid, 0: PSU1, 1: PSU2 */
|
||||
unsigned long last_updated[2]; /* In jiffies, 0: PSU1, 1: PSU2 */
|
||||
struct ipmi_data ipmi;
|
||||
struct ipmi_psu_resp_data ipmi_resp[2]; /* 0: PSU1, 1: PSU2 */
|
||||
unsigned char ipmi_tx_data[2];
|
||||
};
|
||||
|
||||
static struct as5916_54xks_psu_data *as5916_54xks_psu_update_device(struct device *dev);
|
||||
struct as5916_54xks_psu_data *data = NULL;
|
||||
|
||||
enum as5916_54xks_psu_sysfs_attributes {
|
||||
PSU_PRESENT,
|
||||
PSU_MODEL_NAME,
|
||||
PSU_POWER_GOOD
|
||||
static struct platform_driver as5916_54xks_psu_driver = {
|
||||
.probe = as5916_54xks_psu_probe,
|
||||
.remove = as5916_54xks_psu_remove,
|
||||
.driver = {
|
||||
.name = DRVNAME,
|
||||
.owner = THIS_MODULE,
|
||||
},
|
||||
};
|
||||
|
||||
/* 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_model_name,NULL, PSU_MODEL_NAME);
|
||||
static SENSOR_DEVICE_ATTR(psu_power_good, S_IRUGO, show_status, NULL, PSU_POWER_GOOD);
|
||||
#define PSU_PRESENT_ATTR_ID(index) PSU##index##_PRESENT
|
||||
#define PSU_POWERGOOD_ATTR_ID(index) PSU##index##_POWER_GOOD
|
||||
#define PSU_VOUT_ATTR_ID(index) PSU##index##_VOUT
|
||||
#define PSU_IOUT_ATTR_ID(index) PSU##index##_IOUT
|
||||
#define PSU_POUT_ATTR_ID(index) PSU##index##_POUT
|
||||
#define PSU_MODEL_ATTR_ID(index) PSU##index##_MODEL
|
||||
#define PSU_SERIAL_ATTR_ID(index) PSU##index##_SERIAL
|
||||
#define PSU_TEMP_INPUT_ATTR_ID(index) PSU##index##_TEMP_INPUT
|
||||
#define PSU_FAN_INPUT_ATTR_ID(index) PSU##index##_FAN_INPUT
|
||||
|
||||
#define PSU_ATTR(psu_id) \
|
||||
PSU_PRESENT_ATTR_ID(psu_id), \
|
||||
PSU_POWERGOOD_ATTR_ID(psu_id), \
|
||||
PSU_VOUT_ATTR_ID(psu_id), \
|
||||
PSU_IOUT_ATTR_ID(psu_id), \
|
||||
PSU_POUT_ATTR_ID(psu_id), \
|
||||
PSU_MODEL_ATTR_ID(psu_id), \
|
||||
PSU_SERIAL_ATTR_ID(psu_id), \
|
||||
PSU_TEMP_INPUT_ATTR_ID(psu_id), \
|
||||
PSU_FAN_INPUT_ATTR_ID(psu_id)
|
||||
|
||||
enum as5916_54x_psu_sysfs_attrs {
|
||||
/* psu attributes */
|
||||
PSU_ATTR(1),
|
||||
PSU_ATTR(2),
|
||||
NUM_OF_PSU_ATTR,
|
||||
NUM_OF_PER_PSU_ATTR = (NUM_OF_PSU_ATTR/NUM_OF_PSU)
|
||||
};
|
||||
|
||||
/* psu attributes */
|
||||
#define DECLARE_PSU_SENSOR_DEVICE_ATTR(index) \
|
||||
static SENSOR_DEVICE_ATTR(psu##index##_present, S_IRUGO, show_psu, NULL, PSU##index##_PRESENT); \
|
||||
static SENSOR_DEVICE_ATTR(psu##index##_power_good, S_IRUGO, show_psu, NULL, PSU##index##_POWER_GOOD); \
|
||||
static SENSOR_DEVICE_ATTR(psu##index##_vout, S_IRUGO, show_psu, NULL, PSU##index##_VOUT); \
|
||||
static SENSOR_DEVICE_ATTR(psu##index##_iout, S_IRUGO, show_psu, NULL, PSU##index##_IOUT); \
|
||||
static SENSOR_DEVICE_ATTR(psu##index##_pout, S_IRUGO, show_psu, NULL, PSU##index##_POUT); \
|
||||
static SENSOR_DEVICE_ATTR(psu##index##_model, S_IRUGO, show_string, NULL, PSU##index##_MODEL); \
|
||||
static SENSOR_DEVICE_ATTR(psu##index##_serial, S_IRUGO, show_string, NULL, PSU##index##_SERIAL);\
|
||||
static SENSOR_DEVICE_ATTR(psu##index##_temp1_input, S_IRUGO, show_psu, NULL, PSU##index##_TEMP_INPUT); \
|
||||
static SENSOR_DEVICE_ATTR(psu##index##_fan1_input, S_IRUGO, show_psu, NULL, PSU##index##_FAN_INPUT)
|
||||
#define DECLARE_PSU_ATTR(index) \
|
||||
&sensor_dev_attr_psu##index##_present.dev_attr.attr, \
|
||||
&sensor_dev_attr_psu##index##_power_good.dev_attr.attr, \
|
||||
&sensor_dev_attr_psu##index##_vout.dev_attr.attr, \
|
||||
&sensor_dev_attr_psu##index##_iout.dev_attr.attr, \
|
||||
&sensor_dev_attr_psu##index##_pout.dev_attr.attr, \
|
||||
&sensor_dev_attr_psu##index##_model.dev_attr.attr, \
|
||||
&sensor_dev_attr_psu##index##_serial.dev_attr.attr,\
|
||||
&sensor_dev_attr_psu##index##_temp1_input.dev_attr.attr, \
|
||||
&sensor_dev_attr_psu##index##_fan1_input.dev_attr.attr
|
||||
|
||||
DECLARE_PSU_SENSOR_DEVICE_ATTR(1);
|
||||
DECLARE_PSU_SENSOR_DEVICE_ATTR(2);
|
||||
|
||||
static struct attribute *as5916_54xks_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,
|
||||
/* psu attributes */
|
||||
DECLARE_PSU_ATTR(1),
|
||||
DECLARE_PSU_ATTR(2),
|
||||
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 as5916_54xks_psu_data *data = as5916_54xks_psu_update_device(dev);
|
||||
u8 status = 0;
|
||||
|
||||
if (attr->index == PSU_PRESENT) {
|
||||
status = !(data->status & BIT(1 - data->index));;
|
||||
}
|
||||
else { /* PSU_POWER_GOOD */
|
||||
status = !!(data->status & BIT(3 - data->index));
|
||||
}
|
||||
|
||||
return sprintf(buf, "%d\n", status);
|
||||
}
|
||||
|
||||
static ssize_t show_model_name(struct device *dev, struct device_attribute *da,
|
||||
char *buf)
|
||||
{
|
||||
struct as5916_54xks_psu_data *data = as5916_54xks_psu_update_device(dev);
|
||||
|
||||
return sprintf(buf, "%s\n", data->model_name);
|
||||
}
|
||||
|
||||
static const struct attribute_group as5916_54xks_psu_group = {
|
||||
.attrs = as5916_54xks_psu_attributes,
|
||||
};
|
||||
|
||||
static int as5916_54xks_psu_probe(struct i2c_client *client,
|
||||
const struct i2c_device_id *dev_id)
|
||||
{
|
||||
struct as5916_54xks_psu_data *data;
|
||||
int status;
|
||||
/* Functions to talk to the IPMI layer */
|
||||
|
||||
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) {
|
||||
/* Initialize IPMI address, message buffers and user data */
|
||||
static int init_ipmi_data(struct ipmi_data *ipmi, int iface,
|
||||
struct device *dev)
|
||||
{
|
||||
int err;
|
||||
|
||||
init_completion(&ipmi->read_complete);
|
||||
|
||||
/* Initialize IPMI address */
|
||||
ipmi->address.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
|
||||
ipmi->address.channel = IPMI_BMC_CHANNEL;
|
||||
ipmi->address.data[0] = 0;
|
||||
ipmi->interface = iface;
|
||||
|
||||
/* Initialize message buffers */
|
||||
ipmi->tx_msgid = 0;
|
||||
ipmi->tx_message.netfn = ACCTON_IPMI_NETFN;
|
||||
|
||||
ipmi->ipmi_hndlrs.ipmi_recv_hndl = ipmi_msg_handler;
|
||||
|
||||
/* Create IPMI messaging interface user */
|
||||
err = ipmi_create_user(ipmi->interface, &ipmi->ipmi_hndlrs,
|
||||
ipmi, &ipmi->user);
|
||||
if (err < 0) {
|
||||
dev_err(dev, "Unable to register user with IPMI "
|
||||
"interface %d\n", ipmi->interface);
|
||||
return -EACCES;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Send an IPMI command */
|
||||
static int ipmi_send_message(struct ipmi_data *ipmi, unsigned char cmd,
|
||||
unsigned char *tx_data, unsigned short tx_len,
|
||||
unsigned char *rx_data, unsigned short rx_len)
|
||||
{
|
||||
int err;
|
||||
|
||||
ipmi->tx_message.cmd = cmd;
|
||||
ipmi->tx_message.data = tx_data;
|
||||
ipmi->tx_message.data_len = tx_len;
|
||||
ipmi->rx_msg_data = rx_data;
|
||||
ipmi->rx_msg_len = rx_len;
|
||||
|
||||
err = ipmi_validate_addr(&ipmi->address, sizeof(ipmi->address));
|
||||
if (err)
|
||||
goto addr_err;
|
||||
|
||||
ipmi->tx_msgid++;
|
||||
err = ipmi_request_settime(ipmi->user, &ipmi->address, ipmi->tx_msgid,
|
||||
&ipmi->tx_message, ipmi, 0, 0, 0);
|
||||
if (err)
|
||||
goto ipmi_req_err;
|
||||
|
||||
err = wait_for_completion_timeout(&ipmi->read_complete, IPMI_TIMEOUT);
|
||||
if (!err)
|
||||
goto ipmi_timeout_err;
|
||||
|
||||
return 0;
|
||||
|
||||
ipmi_timeout_err:
|
||||
err = -ETIMEDOUT;
|
||||
dev_err(&data->pdev->dev, "request_timeout=%x\n", err);
|
||||
return err;
|
||||
ipmi_req_err:
|
||||
dev_err(&data->pdev->dev, "request_settime=%x\n", err);
|
||||
return err;
|
||||
addr_err:
|
||||
dev_err(&data->pdev->dev, "validate_addr=%x\n", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Dispatch IPMI messages to callers */
|
||||
static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data)
|
||||
{
|
||||
unsigned short rx_len;
|
||||
struct ipmi_data *ipmi = user_msg_data;
|
||||
|
||||
if (msg->msgid != ipmi->tx_msgid) {
|
||||
dev_err(&data->pdev->dev, "Mismatch between received msgid "
|
||||
"(%02x) and transmitted msgid (%02x)!\n",
|
||||
(int)msg->msgid,
|
||||
(int)ipmi->tx_msgid);
|
||||
ipmi_free_recv_msg(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
ipmi->rx_recv_type = msg->recv_type;
|
||||
if (msg->msg.data_len > 0)
|
||||
ipmi->rx_result = msg->msg.data[0];
|
||||
else
|
||||
ipmi->rx_result = IPMI_UNKNOWN_ERR_COMPLETION_CODE;
|
||||
|
||||
if (msg->msg.data_len > 1) {
|
||||
rx_len = msg->msg.data_len - 1;
|
||||
if (ipmi->rx_msg_len < rx_len)
|
||||
rx_len = ipmi->rx_msg_len;
|
||||
ipmi->rx_msg_len = rx_len;
|
||||
memcpy(ipmi->rx_msg_data, msg->msg.data + 1, ipmi->rx_msg_len);
|
||||
} else
|
||||
ipmi->rx_msg_len = 0;
|
||||
|
||||
ipmi_free_recv_msg(msg);
|
||||
complete(&ipmi->read_complete);
|
||||
}
|
||||
|
||||
static struct as5916_54xks_psu_data *as5916_54xks_psu_update_device(struct device_attribute *da)
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||
unsigned char pid = attr->index / NUM_OF_PER_PSU_ATTR;
|
||||
int status = 0;
|
||||
|
||||
if (time_before(jiffies, data->last_updated[pid] + HZ * 5) && data->valid[pid]) {
|
||||
return data;
|
||||
}
|
||||
|
||||
mutex_lock(&data->update_lock);
|
||||
|
||||
data->valid[pid] = 0;
|
||||
|
||||
/* Get status from ipmi */
|
||||
data->ipmi_tx_data[0] = pid + 1; /* PSU ID base id for ipmi start from 1 */
|
||||
status = ipmi_send_message(&data->ipmi, IPMI_PSU_READ_CMD, data->ipmi_tx_data, 1,
|
||||
data->ipmi_resp[pid].status, sizeof(data->ipmi_resp[pid].status));
|
||||
if (unlikely(status != 0)) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (unlikely(data->ipmi.rx_result != 0)) {
|
||||
status = -EIO;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
data = kzalloc(sizeof(struct as5916_54xks_psu_data), GFP_KERNEL);
|
||||
if (!data) {
|
||||
status = -ENOMEM;
|
||||
/* Get model name from ipmi */
|
||||
data->ipmi_tx_data[1] = 0x10;
|
||||
status = ipmi_send_message(&data->ipmi, IPMI_PSU_READ_CMD, data->ipmi_tx_data, 2,
|
||||
data->ipmi_resp[pid].model, sizeof(data->ipmi_resp[pid].model) - 1);
|
||||
if (unlikely(status != 0)) {
|
||||
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, &as5916_54xks_psu_group);
|
||||
if (status) {
|
||||
goto exit_free;
|
||||
if (unlikely(data->ipmi.rx_result != 0)) {
|
||||
status = -EIO;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
data->hwmon_dev = hwmon_device_register(&client->dev);
|
||||
if (IS_ERR(data->hwmon_dev)) {
|
||||
status = PTR_ERR(data->hwmon_dev);
|
||||
goto exit_remove;
|
||||
/* Get serial number from ipmi */
|
||||
data->ipmi_tx_data[1] = 0x11;
|
||||
status = ipmi_send_message(&data->ipmi, IPMI_PSU_READ_CMD, data->ipmi_tx_data, 2,
|
||||
data->ipmi_resp[pid].serial, sizeof(data->ipmi_resp[pid].serial) - 1);
|
||||
if (unlikely(status != 0)) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
dev_info(&client->dev, "%s: psu '%s'\n",
|
||||
dev_name(data->hwmon_dev), client->name);
|
||||
|
||||
if (unlikely(data->ipmi.rx_result != 0)) {
|
||||
status = -EIO;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
data->last_updated[pid] = jiffies;
|
||||
data->valid[pid] = 1;
|
||||
|
||||
exit:
|
||||
mutex_unlock(&data->update_lock);
|
||||
return data;
|
||||
}
|
||||
|
||||
#define VALIDATE_PRESENT_RETURN(id) \
|
||||
{ \
|
||||
if (data->ipmi_resp[id].status[PSU_PRESENT] != 0) { \
|
||||
return -ENXIO; \
|
||||
} \
|
||||
}
|
||||
|
||||
static ssize_t show_psu(struct device *dev, struct device_attribute *da, char *buf)
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||
unsigned char pid = attr->index / NUM_OF_PER_PSU_ATTR;
|
||||
struct as5916_54xks_psu_data *data = NULL;
|
||||
int value = 0;
|
||||
|
||||
data = as5916_54xks_psu_update_device(da);
|
||||
if (!data->valid[pid]) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
switch (attr->index) {
|
||||
case PSU1_PRESENT:
|
||||
case PSU2_PRESENT:
|
||||
value = !(data->ipmi_resp[pid].status[PSU_PRESENT]);
|
||||
break;
|
||||
case PSU1_POWER_GOOD:
|
||||
case PSU2_POWER_GOOD:
|
||||
VALIDATE_PRESENT_RETURN(pid);
|
||||
value = data->ipmi_resp[pid].status[PSU_POWER_GOOD_CPLD];
|
||||
break;
|
||||
case PSU1_VOUT:
|
||||
case PSU2_VOUT:
|
||||
VALIDATE_PRESENT_RETURN(pid);
|
||||
value = ((int)data->ipmi_resp[pid].status[PSU_VOUT0] |
|
||||
(int)data->ipmi_resp[pid].status[PSU_VOUT1] << 8) * 1000;
|
||||
break;
|
||||
case PSU1_IOUT:
|
||||
case PSU2_IOUT:
|
||||
VALIDATE_PRESENT_RETURN(pid);
|
||||
value = ((int)data->ipmi_resp[pid].status[PSU_IOUT0] |
|
||||
(int)data->ipmi_resp[pid].status[PSU_IOUT1] << 8) * 1000;
|
||||
break;
|
||||
case PSU1_POUT:
|
||||
case PSU2_POUT:
|
||||
VALIDATE_PRESENT_RETURN(pid);
|
||||
value = ((int)data->ipmi_resp[pid].status[PSU_POUT0] |
|
||||
(int)data->ipmi_resp[pid].status[PSU_POUT1] << 8) * 1000;
|
||||
break;
|
||||
case PSU1_TEMP_INPUT:
|
||||
case PSU2_TEMP_INPUT:
|
||||
VALIDATE_PRESENT_RETURN(pid);
|
||||
value = ((int)data->ipmi_resp[pid].status[PSU_TEMP0] |
|
||||
(int)data->ipmi_resp[pid].status[PSU_TEMP1] << 8) * 1000;
|
||||
break;
|
||||
case PSU1_FAN_INPUT:
|
||||
case PSU2_FAN_INPUT:
|
||||
VALIDATE_PRESENT_RETURN(pid);
|
||||
value = ((int)data->ipmi_resp[pid].status[PSU_FAN0] |
|
||||
(int)data->ipmi_resp[pid].status[PSU_FAN1] << 8);
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return sprintf(buf, "%d\n", value);
|
||||
}
|
||||
|
||||
static ssize_t show_string(struct device *dev, struct device_attribute *da, char *buf)
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||
unsigned char pid = attr->index / NUM_OF_PER_PSU_ATTR;
|
||||
struct as5916_54xks_psu_data *data;
|
||||
char *str = NULL;
|
||||
|
||||
data = as5916_54xks_psu_update_device(da);
|
||||
if (!data->valid[pid]) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
switch (attr->index) {
|
||||
case PSU1_MODEL:
|
||||
case PSU2_MODEL:
|
||||
VALIDATE_PRESENT_RETURN(pid);
|
||||
str = data->ipmi_resp[pid].model;
|
||||
break;
|
||||
case PSU1_SERIAL:
|
||||
case PSU2_SERIAL:
|
||||
VALIDATE_PRESENT_RETURN(pid);
|
||||
str = data->ipmi_resp[pid].serial;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return sprintf(buf, "%s\n", str);
|
||||
}
|
||||
|
||||
static int as5916_54xks_psu_probe(struct platform_device *pdev)
|
||||
{
|
||||
int status = -1;
|
||||
|
||||
/* Register sysfs hooks */
|
||||
status = sysfs_create_group(&pdev->dev.kobj, &as5916_54xks_psu_group);
|
||||
if (status) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
||||
dev_info(&pdev->dev, "device created\n");
|
||||
|
||||
return 0;
|
||||
|
||||
exit_remove:
|
||||
sysfs_remove_group(&client->dev.kobj, &as5916_54xks_psu_group);
|
||||
exit_free:
|
||||
kfree(data);
|
||||
exit:
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static int as5916_54xks_psu_remove(struct i2c_client *client)
|
||||
static int as5916_54xks_psu_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct as5916_54xks_psu_data *data = i2c_get_clientdata(client);
|
||||
|
||||
hwmon_device_unregister(data->hwmon_dev);
|
||||
sysfs_remove_group(&client->dev.kobj, &as5916_54xks_psu_group);
|
||||
kfree(data);
|
||||
|
||||
sysfs_remove_group(&pdev->dev.kobj, &as5916_54xks_psu_group);
|
||||
return 0;
|
||||
}
|
||||
|
||||
enum psu_index
|
||||
{
|
||||
as5916_54xks_psu1,
|
||||
as5916_54xks_psu2
|
||||
};
|
||||
|
||||
static const struct i2c_device_id as5916_54xks_psu_id[] = {
|
||||
{ "as5916_54xks_psu1", as5916_54xks_psu1 },
|
||||
{ "as5916_54xks_psu2", as5916_54xks_psu2 },
|
||||
{}
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, as5916_54xks_psu_id);
|
||||
|
||||
static struct i2c_driver as5916_54xks_psu_driver = {
|
||||
.class = I2C_CLASS_HWMON,
|
||||
.driver = {
|
||||
.name = "as5916_54xks_psu",
|
||||
},
|
||||
.probe = as5916_54xks_psu_probe,
|
||||
.remove = as5916_54xks_psu_remove,
|
||||
.id_table = as5916_54xks_psu_id,
|
||||
.address_list = normal_i2c,
|
||||
};
|
||||
|
||||
static int as5916_54xks_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 as5916_54xks_psu_data *as5916_54xks_psu_update_device(struct device *dev)
|
||||
{
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct as5916_54xks_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 as5916_54xks update\n");
|
||||
|
||||
/* Read psu status */
|
||||
status = as5916_54xks_cpld_read(0x60, 0x2);
|
||||
|
||||
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));
|
||||
power_good = data->status & BIT(3 - data->index);
|
||||
|
||||
if (power_good) {
|
||||
status = as5916_54xks_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';
|
||||
}
|
||||
}
|
||||
|
||||
data->last_updated = jiffies;
|
||||
data->valid = 1;
|
||||
}
|
||||
|
||||
mutex_unlock(&data->update_lock);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
static int __init as5916_54xks_psu_init(void)
|
||||
{
|
||||
return i2c_add_driver(&as5916_54xks_psu_driver);
|
||||
int ret;
|
||||
|
||||
data = kzalloc(sizeof(struct as5916_54xks_psu_data), GFP_KERNEL);
|
||||
if (!data) {
|
||||
ret = -ENOMEM;
|
||||
goto alloc_err;
|
||||
}
|
||||
|
||||
mutex_init(&data->update_lock);
|
||||
|
||||
ret = platform_driver_register(&as5916_54xks_psu_driver);
|
||||
if (ret < 0) {
|
||||
goto dri_reg_err;
|
||||
}
|
||||
|
||||
data->pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
|
||||
if (IS_ERR(data->pdev)) {
|
||||
ret = PTR_ERR(data->pdev);
|
||||
goto dev_reg_err;
|
||||
}
|
||||
|
||||
/* Set up IPMI interface */
|
||||
ret = init_ipmi_data(&data->ipmi, 0, &data->pdev->dev);
|
||||
if (ret)
|
||||
goto ipmi_err;
|
||||
|
||||
return 0;
|
||||
|
||||
ipmi_err:
|
||||
platform_device_unregister(data->pdev);
|
||||
dev_reg_err:
|
||||
platform_driver_unregister(&as5916_54xks_psu_driver);
|
||||
dri_reg_err:
|
||||
kfree(data);
|
||||
alloc_err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void __exit as5916_54xks_psu_exit(void)
|
||||
{
|
||||
i2c_del_driver(&as5916_54xks_psu_driver);
|
||||
ipmi_destroy_user(data->ipmi.user);
|
||||
platform_device_unregister(data->pdev);
|
||||
platform_driver_unregister(&as5916_54xks_psu_driver);
|
||||
kfree(data);
|
||||
}
|
||||
|
||||
MODULE_AUTHOR("Brandon Chuang <brandon_chuang@accton.com.tw>");
|
||||
MODULE_DESCRIPTION("AS5916 54XKS PSU driver");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
module_init(as5916_54xks_psu_init);
|
||||
module_exit(as5916_54xks_psu_exit);
|
||||
|
||||
MODULE_AUTHOR("Brandon Chuang <brandon_chuang@accton.com.tw>");
|
||||
MODULE_DESCRIPTION("as5916_54xks_psu driver");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,687 @@
|
||||
/*
|
||||
* Copyright (C) Brandon Chuang <brandon_chuang@accton.com.tw>
|
||||
*
|
||||
* 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/version.h>
|
||||
#include <linux/stat.h>
|
||||
#include <linux/sysfs.h>
|
||||
#include <linux/hwmon-sysfs.h>
|
||||
#include <linux/ipmi.h>
|
||||
#include <linux/ipmi_smi.h>
|
||||
#include <linux/platform_device.h>
|
||||
|
||||
#define DRVNAME "as5916_54xks_sys"
|
||||
#define ACCTON_IPMI_NETFN 0x34
|
||||
#define IPMI_TCAM_READ_CMD 0x1E
|
||||
#define IPMI_TCAM_WRITE_CMD 0x1F
|
||||
#define IPMI_TCAM_RESET_SUBCMD 1
|
||||
#define IPMI_TCAM_INT_SUMCMD 2
|
||||
#define IPMI_TCAM_INT_MASK_SUBCMD 3
|
||||
|
||||
#define IPMI_SYSEEPROM_READ_CMD 0x18
|
||||
#define IPMI_TIMEOUT (20 * HZ)
|
||||
#define IPMI_READ_MAX_LEN 128
|
||||
|
||||
#define EEPROM_NAME "eeprom"
|
||||
#define EEPROM_SIZE 512 /* 512 byte eeprom */
|
||||
|
||||
#define IPMI_GET_CPLD_VER_CMD 0x20
|
||||
#define MAINBOARD_CPLD1_ADDR 0x60
|
||||
#define MAINBOARD_CPLD2_ADDR 0x62
|
||||
#define CPU_CPLD_ADDR 0x65
|
||||
#define FAN_CPLD_ADDR 0x66
|
||||
|
||||
static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data);
|
||||
static int as5916_54xks_sys_probe(struct platform_device *pdev);
|
||||
static int as5916_54xks_sys_remove(struct platform_device *pdev);
|
||||
static ssize_t show_sys_reset_6(struct device *dev, struct device_attribute *da, char *buf);
|
||||
static ssize_t set_sys_reset_6(struct device *dev, struct device_attribute *da,
|
||||
const char *buf, size_t count);
|
||||
static ssize_t show_interrupt_status_6(struct device *dev, struct device_attribute *da, char *buf);
|
||||
static ssize_t set_interrupt_status_6_mask(struct device *dev, struct device_attribute *da,
|
||||
const char *buf, size_t count);
|
||||
static ssize_t show_cpld_version(struct device *dev, struct device_attribute *da, char *buf);
|
||||
|
||||
struct ipmi_data {
|
||||
struct completion read_complete;
|
||||
struct ipmi_addr address;
|
||||
ipmi_user_t user;
|
||||
int interface;
|
||||
|
||||
struct kernel_ipmi_msg tx_message;
|
||||
long tx_msgid;
|
||||
|
||||
void *rx_msg_data;
|
||||
unsigned short rx_msg_len;
|
||||
unsigned char rx_result;
|
||||
int rx_recv_type;
|
||||
|
||||
struct ipmi_user_hndl ipmi_hndlrs;
|
||||
};
|
||||
|
||||
struct as5916_54xks_sys_data {
|
||||
struct platform_device *pdev;
|
||||
struct mutex update_lock;
|
||||
char valid; /* != 0 if registers are valid */
|
||||
unsigned long last_updated; /* In jiffies */
|
||||
struct ipmi_data ipmi;
|
||||
unsigned char ipmi_resp_eeprom[EEPROM_SIZE];
|
||||
unsigned char ipmi_resp_tcam; /* tcam reset: (CPLD register 0x51)
|
||||
Bit0/1: Reserved
|
||||
Bit 2 : CPU_JTAG_RST
|
||||
Bit 3 : RESET_SYS_CPLD
|
||||
Bit 4 : RESET_MAC
|
||||
Bit 5 : CPLD1_TCAM_SRST_L
|
||||
Bit 6 : CPLD1_TCAM_PERST_L
|
||||
Bit 7 : CPLD1_TCAM_CRST_L
|
||||
tcam interrupt (CPLD register 0x62)
|
||||
tcam interrupt mask (CPLD register 0x63)
|
||||
Bit 0 : TCAM_CPLD1_GIO_L_1
|
||||
Bit 1 : TCAM_CPLD1_GIO_L_0 */
|
||||
unsigned char ipmi_resp_cpld;
|
||||
unsigned char ipmi_tx_data[3];
|
||||
struct bin_attribute eeprom; /* eeprom data */
|
||||
};
|
||||
|
||||
struct as5916_54xks_sys_data *data = NULL;
|
||||
|
||||
static struct platform_driver as5916_54xks_sys_driver = {
|
||||
.probe = as5916_54xks_sys_probe,
|
||||
.remove = as5916_54xks_sys_remove,
|
||||
.driver = {
|
||||
.name = DRVNAME,
|
||||
.owner = THIS_MODULE,
|
||||
},
|
||||
};
|
||||
|
||||
enum as5916_54xks_sys_sysfs_attrs {
|
||||
SYS_RESET_6_BIT0, /* Not Used */
|
||||
SYS_RESET_6_BIT1, /* Not Used */
|
||||
CPU_JTAG_RST,
|
||||
RESET_SYS_CPLD,
|
||||
RESET_MAC,
|
||||
TCAM_SRST_L,
|
||||
TCAM_PERST_L,
|
||||
TCAM_CRST_L,
|
||||
TCAM_RST_ALL,
|
||||
SYS_RESET_6_ALL,
|
||||
TCAM_CPLD1_GIO_L,
|
||||
TCAM_CPLD1_GIO_L_MASK,
|
||||
MB_CPLD1_VER, /* mainboard cpld1 version */
|
||||
MB_CPLD2_VER, /* mainboard cpld2 version */
|
||||
CPU_CPLD_VER, /* CPU board CPLD version */
|
||||
FAN_CPLD_VER, /* FAN CPLD version */
|
||||
};
|
||||
|
||||
static SENSOR_DEVICE_ATTR(tcam_rst_c, S_IWUSR | S_IRUGO, show_sys_reset_6, set_sys_reset_6, TCAM_CRST_L);
|
||||
static SENSOR_DEVICE_ATTR(tcam_rst_pe, S_IWUSR | S_IRUGO, show_sys_reset_6, set_sys_reset_6, TCAM_PERST_L);
|
||||
static SENSOR_DEVICE_ATTR(tcam_rst_s, S_IWUSR | S_IRUGO, show_sys_reset_6, set_sys_reset_6, TCAM_SRST_L);
|
||||
static SENSOR_DEVICE_ATTR(tcam_rst_all, S_IWUSR | S_IRUGO, show_sys_reset_6, set_sys_reset_6, TCAM_RST_ALL);
|
||||
static SENSOR_DEVICE_ATTR(sys_rst_6, S_IWUSR | S_IRUGO, show_sys_reset_6, set_sys_reset_6, SYS_RESET_6_ALL);
|
||||
static SENSOR_DEVICE_ATTR(tcam_int, S_IRUGO, show_interrupt_status_6, NULL, TCAM_CPLD1_GIO_L);
|
||||
static SENSOR_DEVICE_ATTR(tcam_int_msk, S_IWUSR | S_IRUGO, show_interrupt_status_6, set_interrupt_status_6_mask, TCAM_CPLD1_GIO_L_MASK);
|
||||
static SENSOR_DEVICE_ATTR(mb_cpld1_ver, S_IRUGO, show_cpld_version, NULL, MB_CPLD1_VER);
|
||||
static SENSOR_DEVICE_ATTR(mb_cpld2_ver, S_IRUGO, show_cpld_version, NULL, MB_CPLD2_VER);
|
||||
static SENSOR_DEVICE_ATTR(cpu_cpld_ver, S_IRUGO, show_cpld_version, NULL, CPU_CPLD_VER);
|
||||
static SENSOR_DEVICE_ATTR(fan_cpld_ver, S_IRUGO, show_cpld_version, NULL, FAN_CPLD_VER);
|
||||
|
||||
static struct attribute *as5916_54xks_sys_attributes[] = {
|
||||
&sensor_dev_attr_tcam_rst_c.dev_attr.attr,
|
||||
&sensor_dev_attr_tcam_rst_pe.dev_attr.attr,
|
||||
&sensor_dev_attr_tcam_rst_s.dev_attr.attr,
|
||||
&sensor_dev_attr_tcam_rst_all.dev_attr.attr,
|
||||
&sensor_dev_attr_sys_rst_6.dev_attr.attr,
|
||||
&sensor_dev_attr_tcam_int.dev_attr.attr,
|
||||
&sensor_dev_attr_tcam_int_msk.dev_attr.attr,
|
||||
&sensor_dev_attr_mb_cpld1_ver.dev_attr.attr,
|
||||
&sensor_dev_attr_mb_cpld2_ver.dev_attr.attr,
|
||||
&sensor_dev_attr_cpu_cpld_ver.dev_attr.attr,
|
||||
&sensor_dev_attr_fan_cpld_ver.dev_attr.attr,
|
||||
NULL
|
||||
};
|
||||
|
||||
static const struct attribute_group as5916_54xks_sys_group = {
|
||||
.attrs = as5916_54xks_sys_attributes,
|
||||
};
|
||||
|
||||
/* Functions to talk to the IPMI layer */
|
||||
|
||||
/* Initialize IPMI address, message buffers and user data */
|
||||
static int init_ipmi_data(struct ipmi_data *ipmi, int iface,
|
||||
struct device *dev)
|
||||
{
|
||||
int err;
|
||||
|
||||
init_completion(&ipmi->read_complete);
|
||||
|
||||
/* Initialize IPMI address */
|
||||
ipmi->address.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
|
||||
ipmi->address.channel = IPMI_BMC_CHANNEL;
|
||||
ipmi->address.data[0] = 0;
|
||||
ipmi->interface = iface;
|
||||
|
||||
/* Initialize message buffers */
|
||||
ipmi->tx_msgid = 0;
|
||||
ipmi->tx_message.netfn = ACCTON_IPMI_NETFN;
|
||||
|
||||
ipmi->ipmi_hndlrs.ipmi_recv_hndl = ipmi_msg_handler;
|
||||
|
||||
/* Create IPMI messaging interface user */
|
||||
err = ipmi_create_user(ipmi->interface, &ipmi->ipmi_hndlrs,
|
||||
ipmi, &ipmi->user);
|
||||
if (err < 0) {
|
||||
dev_err(dev, "Unable to register user with IPMI "
|
||||
"interface %d\n", ipmi->interface);
|
||||
return -EACCES;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Send an IPMI command */
|
||||
static int ipmi_send_message(struct ipmi_data *ipmi, unsigned char cmd,
|
||||
unsigned char *tx_data, unsigned short tx_len,
|
||||
unsigned char *rx_data, unsigned short rx_len)
|
||||
{
|
||||
int err;
|
||||
|
||||
ipmi->tx_message.cmd = cmd;
|
||||
ipmi->tx_message.data = tx_data;
|
||||
ipmi->tx_message.data_len = tx_len;
|
||||
ipmi->rx_msg_data = rx_data;
|
||||
ipmi->rx_msg_len = rx_len;
|
||||
|
||||
err = ipmi_validate_addr(&ipmi->address, sizeof(ipmi->address));
|
||||
if (err)
|
||||
goto addr_err;
|
||||
|
||||
ipmi->tx_msgid++;
|
||||
err = ipmi_request_settime(ipmi->user, &ipmi->address, ipmi->tx_msgid,
|
||||
&ipmi->tx_message, ipmi, 0, 0, 0);
|
||||
if (err)
|
||||
goto ipmi_req_err;
|
||||
|
||||
err = wait_for_completion_timeout(&ipmi->read_complete, IPMI_TIMEOUT);
|
||||
if (!err)
|
||||
goto ipmi_timeout_err;
|
||||
|
||||
return 0;
|
||||
|
||||
ipmi_timeout_err:
|
||||
err = -ETIMEDOUT;
|
||||
dev_err(&data->pdev->dev, "request_timeout=%x\n", err);
|
||||
return err;
|
||||
ipmi_req_err:
|
||||
dev_err(&data->pdev->dev, "request_settime=%x\n", err);
|
||||
return err;
|
||||
addr_err:
|
||||
dev_err(&data->pdev->dev, "validate_addr=%x\n", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Dispatch IPMI messages to callers */
|
||||
static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data)
|
||||
{
|
||||
unsigned short rx_len;
|
||||
struct ipmi_data *ipmi = user_msg_data;
|
||||
|
||||
if (msg->msgid != ipmi->tx_msgid) {
|
||||
dev_err(&data->pdev->dev, "Mismatch between received msgid "
|
||||
"(%02x) and transmitted msgid (%02x)!\n",
|
||||
(int)msg->msgid,
|
||||
(int)ipmi->tx_msgid);
|
||||
ipmi_free_recv_msg(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
ipmi->rx_recv_type = msg->recv_type;
|
||||
if (msg->msg.data_len > 0)
|
||||
ipmi->rx_result = msg->msg.data[0];
|
||||
else
|
||||
ipmi->rx_result = IPMI_UNKNOWN_ERR_COMPLETION_CODE;
|
||||
|
||||
if (msg->msg.data_len > 1) {
|
||||
rx_len = msg->msg.data_len - 1;
|
||||
if (ipmi->rx_msg_len < rx_len)
|
||||
rx_len = ipmi->rx_msg_len;
|
||||
ipmi->rx_msg_len = rx_len;
|
||||
memcpy(ipmi->rx_msg_data, msg->msg.data + 1, ipmi->rx_msg_len);
|
||||
} else
|
||||
ipmi->rx_msg_len = 0;
|
||||
|
||||
ipmi_free_recv_msg(msg);
|
||||
complete(&ipmi->read_complete);
|
||||
}
|
||||
|
||||
static ssize_t sys_eeprom_read(loff_t off, char *buf, size_t count)
|
||||
{
|
||||
int status = 0;
|
||||
unsigned char length = 0;
|
||||
|
||||
if ((off + count) > EEPROM_SIZE) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
length = (count >= IPMI_READ_MAX_LEN) ? IPMI_READ_MAX_LEN : count;
|
||||
data->ipmi_tx_data[0] = (off >> 8) & 0xff;
|
||||
data->ipmi_tx_data[1] = (off & 0xff);
|
||||
data->ipmi_tx_data[2] = length;
|
||||
status = ipmi_send_message(&data->ipmi, IPMI_SYSEEPROM_READ_CMD,
|
||||
data->ipmi_tx_data, sizeof(data->ipmi_tx_data),
|
||||
data->ipmi_resp_eeprom + off, length);
|
||||
if (unlikely(status != 0)) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (unlikely(data->ipmi.rx_result != 0)) {
|
||||
status = -EIO;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
status = length; /* Read length */
|
||||
memcpy(buf, data->ipmi_resp_eeprom + off, length);
|
||||
|
||||
exit:
|
||||
return status;
|
||||
}
|
||||
|
||||
static ssize_t sysfs_bin_read(struct file *filp, struct kobject *kobj,
|
||||
struct bin_attribute *attr,
|
||||
char *buf, loff_t off, size_t count)
|
||||
{
|
||||
ssize_t retval = 0;
|
||||
|
||||
if (unlikely(!count)) {
|
||||
return count;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read data from chip, protecting against concurrent updates
|
||||
* from this host
|
||||
*/
|
||||
mutex_lock(&data->update_lock);
|
||||
|
||||
while (count) {
|
||||
ssize_t status;
|
||||
|
||||
status = sys_eeprom_read(off, buf, count);
|
||||
if (status <= 0) {
|
||||
if (retval == 0) {
|
||||
retval = status;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
buf += status;
|
||||
off += status;
|
||||
count -= status;
|
||||
retval += status;
|
||||
}
|
||||
|
||||
mutex_unlock(&data->update_lock);
|
||||
return retval;
|
||||
|
||||
}
|
||||
|
||||
static int sysfs_eeprom_init(struct kobject *kobj, struct bin_attribute *eeprom)
|
||||
{
|
||||
sysfs_bin_attr_init(eeprom);
|
||||
eeprom->attr.name = EEPROM_NAME;
|
||||
eeprom->attr.mode = S_IRUGO;
|
||||
eeprom->read = sysfs_bin_read;
|
||||
eeprom->write = NULL;
|
||||
eeprom->size = EEPROM_SIZE;
|
||||
|
||||
/* Create eeprom file */
|
||||
return sysfs_create_bin_file(kobj, eeprom);
|
||||
}
|
||||
|
||||
static int sysfs_eeprom_cleanup(struct kobject *kobj, struct bin_attribute *eeprom)
|
||||
{
|
||||
sysfs_remove_bin_file(kobj, eeprom);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct as5916_54xks_sys_data *as5916_54xks_sys_update_tcam(unsigned char subcmd)
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
mutex_lock(&data->update_lock);
|
||||
|
||||
data->valid = 0;
|
||||
data->ipmi_tx_data[0] = subcmd;
|
||||
status = ipmi_send_message(&data->ipmi, IPMI_TCAM_READ_CMD, data->ipmi_tx_data, 1,
|
||||
&data->ipmi_resp_tcam, sizeof(data->ipmi_resp_tcam));
|
||||
if (unlikely(status != 0)) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (unlikely(data->ipmi.rx_result != 0)) {
|
||||
status = -EIO;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
data->last_updated = jiffies;
|
||||
data->valid = 1;
|
||||
|
||||
exit:
|
||||
mutex_unlock(&data->update_lock);
|
||||
return data;
|
||||
}
|
||||
|
||||
static ssize_t set_sys_reset_6(struct device *dev, struct device_attribute *da,
|
||||
const char *buf, size_t count)
|
||||
{
|
||||
long reset; /* reset value to be set */
|
||||
int status;
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||
struct as5916_54xks_sys_data *data = NULL;
|
||||
|
||||
status = kstrtol(buf, 10, &reset);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
|
||||
data = as5916_54xks_sys_update_tcam(IPMI_TCAM_RESET_SUBCMD);
|
||||
if (!data->valid) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
switch (attr->index) {
|
||||
case SYS_RESET_6_BIT0:
|
||||
case SYS_RESET_6_BIT1:
|
||||
case CPU_JTAG_RST:
|
||||
case RESET_SYS_CPLD:
|
||||
case RESET_MAC:
|
||||
case TCAM_SRST_L:
|
||||
case TCAM_PERST_L:
|
||||
case TCAM_CRST_L:
|
||||
data->ipmi_tx_data[1] = reset ? (data->ipmi_resp_tcam | (1 << attr->index)):
|
||||
(data->ipmi_resp_tcam & ~(1 << attr->index));
|
||||
break;
|
||||
case TCAM_RST_ALL:
|
||||
data->ipmi_tx_data[1] = (data->ipmi_resp_tcam & 0x1f) | (reset << TCAM_SRST_L);
|
||||
break;
|
||||
case SYS_RESET_6_ALL:
|
||||
data->ipmi_tx_data[1] = reset;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Send IPMI write command */
|
||||
data->ipmi_tx_data[0] = IPMI_TCAM_RESET_SUBCMD;
|
||||
status = ipmi_send_message(&data->ipmi, IPMI_TCAM_WRITE_CMD,
|
||||
data->ipmi_tx_data, 2, NULL, 0);
|
||||
if (unlikely(status != 0)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
if (unlikely(data->ipmi.rx_result != 0)) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static ssize_t show_sys_reset_6(struct device *dev, struct device_attribute *da, char *buf)
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||
struct as5916_54xks_sys_data *data = NULL;
|
||||
int value = 0;
|
||||
|
||||
data = as5916_54xks_sys_update_tcam(IPMI_TCAM_RESET_SUBCMD);
|
||||
if (!data->valid) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
switch (attr->index) {
|
||||
case SYS_RESET_6_BIT0:
|
||||
case SYS_RESET_6_BIT1:
|
||||
case CPU_JTAG_RST:
|
||||
case RESET_SYS_CPLD:
|
||||
case RESET_MAC:
|
||||
case TCAM_SRST_L:
|
||||
case TCAM_PERST_L:
|
||||
case TCAM_CRST_L:
|
||||
value = !!(data->ipmi_resp_tcam & (1 << attr->index));
|
||||
break;
|
||||
case TCAM_RST_ALL:
|
||||
value = (data->ipmi_resp_tcam >> 5) & 0x7;
|
||||
break;
|
||||
case SYS_RESET_6_ALL:
|
||||
value = data->ipmi_resp_tcam & 0xff;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return sprintf(buf, "%d\n", value);
|
||||
}
|
||||
|
||||
static ssize_t show_interrupt_status_6(struct device *dev, struct device_attribute *da, char *buf)
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||
struct as5916_54xks_sys_data *data = NULL;
|
||||
unsigned char subcmd = 0;
|
||||
int value = 0;
|
||||
|
||||
switch (attr->index) {
|
||||
case TCAM_CPLD1_GIO_L:
|
||||
subcmd = IPMI_TCAM_INT_SUMCMD;
|
||||
break;
|
||||
case TCAM_CPLD1_GIO_L_MASK:
|
||||
subcmd = IPMI_TCAM_INT_MASK_SUBCMD;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
data = as5916_54xks_sys_update_tcam(subcmd);
|
||||
if (!data->valid) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
value = data->ipmi_resp_tcam & 0x3;
|
||||
return sprintf(buf, "%d\n", value);
|
||||
}
|
||||
|
||||
static ssize_t set_interrupt_status_6_mask(struct device *dev, struct device_attribute *da,
|
||||
const char *buf, size_t count)
|
||||
{
|
||||
long mask = 0; /* mask value to be set */
|
||||
int status;
|
||||
struct as5916_54xks_sys_data *data = NULL;
|
||||
|
||||
status = kstrtol(buf, 10, &mask);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
|
||||
data = as5916_54xks_sys_update_tcam(IPMI_TCAM_INT_MASK_SUBCMD);
|
||||
if (!data->valid) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/* Send IPMI write command */
|
||||
data->ipmi_tx_data[0] = IPMI_TCAM_INT_MASK_SUBCMD;
|
||||
data->ipmi_tx_data[1] = (data->ipmi_resp_tcam & 0xfc) | (mask & 0x3);
|
||||
status = ipmi_send_message(&data->ipmi, IPMI_TCAM_WRITE_CMD,
|
||||
data->ipmi_tx_data, 2, NULL, 0);
|
||||
if (unlikely(status != 0)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
if (unlikely(data->ipmi.rx_result != 0)) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static struct as5916_54xks_sys_data *as5916_54xks_sys_update_cpld_ver(unsigned char cpld_addr)
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
mutex_lock(&data->update_lock);
|
||||
|
||||
data->valid = 0;
|
||||
data->ipmi_tx_data[0] = cpld_addr;
|
||||
status = ipmi_send_message(&data->ipmi, IPMI_GET_CPLD_VER_CMD, data->ipmi_tx_data, 1,
|
||||
&data->ipmi_resp_cpld, sizeof(data->ipmi_resp_cpld));
|
||||
if (unlikely(status != 0)) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (unlikely(data->ipmi.rx_result != 0)) {
|
||||
status = -EIO;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
data->last_updated = jiffies;
|
||||
data->valid = 1;
|
||||
|
||||
exit:
|
||||
mutex_unlock(&data->update_lock);
|
||||
return data;
|
||||
}
|
||||
|
||||
static ssize_t show_cpld_version(struct device *dev, struct device_attribute *da, char *buf)
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||
struct as5916_54xks_sys_data *data = NULL;
|
||||
unsigned char cpld_addr = 0;
|
||||
|
||||
switch (attr->index) {
|
||||
case MB_CPLD1_VER:
|
||||
cpld_addr = MAINBOARD_CPLD1_ADDR;
|
||||
break;
|
||||
case MB_CPLD2_VER:
|
||||
cpld_addr = MAINBOARD_CPLD2_ADDR;
|
||||
break;
|
||||
case CPU_CPLD_VER:
|
||||
cpld_addr = CPU_CPLD_ADDR;
|
||||
break;
|
||||
case FAN_CPLD_VER:
|
||||
cpld_addr = FAN_CPLD_ADDR;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
data = as5916_54xks_sys_update_cpld_ver(cpld_addr);
|
||||
if (!data->valid) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
return sprintf(buf, "%d\n", data->ipmi_resp_cpld);
|
||||
}
|
||||
|
||||
static int as5916_54xks_sys_probe(struct platform_device *pdev)
|
||||
{
|
||||
int status = -1;
|
||||
|
||||
/* Register sysfs hooks */
|
||||
status = sysfs_eeprom_init(&pdev->dev.kobj, &data->eeprom);
|
||||
if (status) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* Register sysfs hooks */
|
||||
status = sysfs_create_group(&pdev->dev.kobj, &as5916_54xks_sys_group);
|
||||
if (status) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
dev_info(&pdev->dev, "device created\n");
|
||||
|
||||
return 0;
|
||||
|
||||
exit:
|
||||
return status;
|
||||
}
|
||||
|
||||
static int as5916_54xks_sys_remove(struct platform_device *pdev)
|
||||
{
|
||||
sysfs_eeprom_cleanup(&pdev->dev.kobj, &data->eeprom);
|
||||
sysfs_remove_group(&pdev->dev.kobj, &as5916_54xks_sys_group);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __init as5916_54xks_sys_init(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
data = kzalloc(sizeof(struct as5916_54xks_sys_data), GFP_KERNEL);
|
||||
if (!data) {
|
||||
ret = -ENOMEM;
|
||||
goto alloc_err;
|
||||
}
|
||||
|
||||
mutex_init(&data->update_lock);
|
||||
|
||||
ret = platform_driver_register(&as5916_54xks_sys_driver);
|
||||
if (ret < 0) {
|
||||
goto dri_reg_err;
|
||||
}
|
||||
|
||||
data->pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
|
||||
if (IS_ERR(data->pdev)) {
|
||||
ret = PTR_ERR(data->pdev);
|
||||
goto dev_reg_err;
|
||||
}
|
||||
|
||||
/* Set up IPMI interface */
|
||||
ret = init_ipmi_data(&data->ipmi, 0, &data->pdev->dev);
|
||||
if (ret)
|
||||
goto ipmi_err;
|
||||
|
||||
return 0;
|
||||
|
||||
ipmi_err:
|
||||
platform_device_unregister(data->pdev);
|
||||
dev_reg_err:
|
||||
platform_driver_unregister(&as5916_54xks_sys_driver);
|
||||
dri_reg_err:
|
||||
kfree(data);
|
||||
alloc_err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void __exit as5916_54xks_sys_exit(void)
|
||||
{
|
||||
ipmi_destroy_user(data->ipmi.user);
|
||||
platform_device_unregister(data->pdev);
|
||||
platform_driver_unregister(&as5916_54xks_sys_driver);
|
||||
kfree(data);
|
||||
}
|
||||
|
||||
MODULE_AUTHOR("Brandon Chuang <brandon_chuang@accton.com.tw>");
|
||||
MODULE_DESCRIPTION("AS5916-54XKS System driver");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
module_init(as5916_54xks_sys_init);
|
||||
module_exit(as5916_54xks_sys_exit);
|
||||
|
||||
@@ -0,0 +1,347 @@
|
||||
/*
|
||||
* Copyright (C) Brandon Chuang <brandon_chuang@accton.com.tw>
|
||||
*
|
||||
* 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/version.h>
|
||||
#include <linux/stat.h>
|
||||
#include <linux/sysfs.h>
|
||||
#include <linux/hwmon-sysfs.h>
|
||||
#include <linux/ipmi.h>
|
||||
#include <linux/ipmi_smi.h>
|
||||
#include <linux/platform_device.h>
|
||||
|
||||
#define DRVNAME "as5916_54xks_thermal"
|
||||
#define ACCTON_IPMI_NETFN 0x34
|
||||
#define IPMI_THERMAL_READ_CMD 0x12
|
||||
#define IPMI_TIMEOUT (20 * HZ)
|
||||
|
||||
static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data);
|
||||
static ssize_t show_temp(struct device *dev, struct device_attribute *attr, char *buf);
|
||||
static int as5916_54xks_thermal_probe(struct platform_device *pdev);
|
||||
static int as5916_54xks_thermal_remove(struct platform_device *pdev);
|
||||
|
||||
enum temp_data_index {
|
||||
TEMP_ADDR,
|
||||
TEMP_FAULT,
|
||||
TEMP_INPUT,
|
||||
TEMP_DATA_COUNT
|
||||
};
|
||||
|
||||
struct ipmi_data {
|
||||
struct completion read_complete;
|
||||
struct ipmi_addr address;
|
||||
ipmi_user_t user;
|
||||
int interface;
|
||||
|
||||
struct kernel_ipmi_msg tx_message;
|
||||
long tx_msgid;
|
||||
|
||||
void *rx_msg_data;
|
||||
unsigned short rx_msg_len;
|
||||
unsigned char rx_result;
|
||||
int rx_recv_type;
|
||||
|
||||
struct ipmi_user_hndl ipmi_hndlrs;
|
||||
};
|
||||
|
||||
struct as5916_54xks_thermal_data {
|
||||
struct platform_device *pdev;
|
||||
struct mutex update_lock;
|
||||
char valid; /* != 0 if registers are valid */
|
||||
unsigned long last_updated; /* In jiffies */
|
||||
char ipmi_resp[12]; /* 3 bytes for each thermal */
|
||||
struct ipmi_data ipmi;
|
||||
};
|
||||
|
||||
struct as5916_54xks_thermal_data *data = NULL;
|
||||
|
||||
static struct platform_driver as5916_54xks_thermal_driver = {
|
||||
.probe = as5916_54xks_thermal_probe,
|
||||
.remove = as5916_54xks_thermal_remove,
|
||||
.driver = {
|
||||
.name = DRVNAME,
|
||||
.owner = THIS_MODULE,
|
||||
},
|
||||
};
|
||||
|
||||
enum as5916_54x_thermal_sysfs_attrs {
|
||||
TEMP1_INPUT,
|
||||
TEMP2_INPUT,
|
||||
TEMP3_INPUT,
|
||||
TEMP4_INPUT,
|
||||
};
|
||||
|
||||
static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, TEMP1_INPUT);
|
||||
static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, TEMP2_INPUT);
|
||||
static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, TEMP3_INPUT);
|
||||
static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, show_temp, NULL, TEMP4_INPUT);
|
||||
|
||||
static struct attribute *as5916_54xks_thermal_attributes[] = {
|
||||
&sensor_dev_attr_temp1_input.dev_attr.attr,
|
||||
&sensor_dev_attr_temp2_input.dev_attr.attr,
|
||||
&sensor_dev_attr_temp3_input.dev_attr.attr,
|
||||
&sensor_dev_attr_temp4_input.dev_attr.attr,
|
||||
NULL
|
||||
};
|
||||
|
||||
static const struct attribute_group as5916_54xks_thermal_group = {
|
||||
.attrs = as5916_54xks_thermal_attributes,
|
||||
};
|
||||
|
||||
/* Functions to talk to the IPMI layer */
|
||||
|
||||
/* Initialize IPMI address, message buffers and user data */
|
||||
static int init_ipmi_data(struct ipmi_data *ipmi, int iface,
|
||||
struct device *dev)
|
||||
{
|
||||
int err;
|
||||
|
||||
init_completion(&ipmi->read_complete);
|
||||
|
||||
/* Initialize IPMI address */
|
||||
ipmi->address.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
|
||||
ipmi->address.channel = IPMI_BMC_CHANNEL;
|
||||
ipmi->address.data[0] = 0;
|
||||
ipmi->interface = iface;
|
||||
|
||||
/* Initialize message buffers */
|
||||
ipmi->tx_msgid = 0;
|
||||
ipmi->tx_message.netfn = ACCTON_IPMI_NETFN;
|
||||
|
||||
ipmi->ipmi_hndlrs.ipmi_recv_hndl = ipmi_msg_handler;
|
||||
|
||||
/* Create IPMI messaging interface user */
|
||||
err = ipmi_create_user(ipmi->interface, &ipmi->ipmi_hndlrs,
|
||||
ipmi, &ipmi->user);
|
||||
if (err < 0) {
|
||||
dev_err(dev, "Unable to register user with IPMI "
|
||||
"interface %d\n", ipmi->interface);
|
||||
return -EACCES;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Send an IPMI command */
|
||||
static int ipmi_send_message(struct ipmi_data *ipmi, unsigned char cmd,
|
||||
unsigned char *tx_data, unsigned short tx_len,
|
||||
unsigned char *rx_data, unsigned short rx_len)
|
||||
{
|
||||
int err;
|
||||
|
||||
ipmi->tx_message.cmd = cmd;
|
||||
ipmi->tx_message.data = tx_data;
|
||||
ipmi->tx_message.data_len = tx_len;
|
||||
ipmi->rx_msg_data = rx_data;
|
||||
ipmi->rx_msg_len = rx_len;
|
||||
|
||||
err = ipmi_validate_addr(&ipmi->address, sizeof(ipmi->address));
|
||||
if (err)
|
||||
goto addr_err;
|
||||
|
||||
ipmi->tx_msgid++;
|
||||
err = ipmi_request_settime(ipmi->user, &ipmi->address, ipmi->tx_msgid,
|
||||
&ipmi->tx_message, ipmi, 0, 0, 0);
|
||||
if (err)
|
||||
goto ipmi_req_err;
|
||||
|
||||
err = wait_for_completion_timeout(&ipmi->read_complete, IPMI_TIMEOUT);
|
||||
if (!err)
|
||||
goto ipmi_timeout_err;
|
||||
|
||||
return 0;
|
||||
|
||||
ipmi_timeout_err:
|
||||
err = -ETIMEDOUT;
|
||||
dev_err(&data->pdev->dev, "request_timeout=%x\n", err);
|
||||
return err;
|
||||
ipmi_req_err:
|
||||
dev_err(&data->pdev->dev, "request_settime=%x\n", err);
|
||||
return err;
|
||||
addr_err:
|
||||
dev_err(&data->pdev->dev, "validate_addr=%x\n", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Dispatch IPMI messages to callers */
|
||||
static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data)
|
||||
{
|
||||
unsigned short rx_len;
|
||||
struct ipmi_data *ipmi = user_msg_data;
|
||||
|
||||
if (msg->msgid != ipmi->tx_msgid) {
|
||||
dev_err(&data->pdev->dev, "Mismatch between received msgid "
|
||||
"(%02x) and transmitted msgid (%02x)!\n",
|
||||
(int)msg->msgid,
|
||||
(int)ipmi->tx_msgid);
|
||||
ipmi_free_recv_msg(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
ipmi->rx_recv_type = msg->recv_type;
|
||||
if (msg->msg.data_len > 0)
|
||||
ipmi->rx_result = msg->msg.data[0];
|
||||
else
|
||||
ipmi->rx_result = IPMI_UNKNOWN_ERR_COMPLETION_CODE;
|
||||
|
||||
if (msg->msg.data_len > 1) {
|
||||
rx_len = msg->msg.data_len - 1;
|
||||
if (ipmi->rx_msg_len < rx_len)
|
||||
rx_len = ipmi->rx_msg_len;
|
||||
ipmi->rx_msg_len = rx_len;
|
||||
memcpy(ipmi->rx_msg_data, msg->msg.data + 1, ipmi->rx_msg_len);
|
||||
} else
|
||||
ipmi->rx_msg_len = 0;
|
||||
|
||||
ipmi_free_recv_msg(msg);
|
||||
complete(&ipmi->read_complete);
|
||||
}
|
||||
|
||||
static ssize_t show_temp(struct device *dev, struct device_attribute *da, char *buf)
|
||||
{
|
||||
int status = 0;
|
||||
int index = 0;
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||
|
||||
mutex_lock(&data->update_lock);
|
||||
|
||||
if (time_after(jiffies, data->last_updated + HZ * 5) || !data->valid) {
|
||||
data->valid = 0;
|
||||
|
||||
status = ipmi_send_message(&data->ipmi, IPMI_THERMAL_READ_CMD, NULL, 0,
|
||||
data->ipmi_resp, sizeof(data->ipmi_resp));
|
||||
if (unlikely(status != 0)) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (unlikely(data->ipmi.rx_result != 0)) {
|
||||
status = -EIO;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
data->last_updated = jiffies;
|
||||
data->valid = 1;
|
||||
}
|
||||
|
||||
mutex_unlock(&data->update_lock);
|
||||
|
||||
/* Get temp fault status */
|
||||
index = attr->index * TEMP_DATA_COUNT + TEMP_FAULT;
|
||||
if (unlikely(data->ipmi_resp[index] == 0)) {
|
||||
status = -EIO;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* Get temperature in degree celsius */
|
||||
index = attr->index * TEMP_DATA_COUNT + TEMP_INPUT;
|
||||
status = data->ipmi_resp[index] * 1000;
|
||||
|
||||
return sprintf(buf, "%d\n", status);
|
||||
|
||||
exit:
|
||||
mutex_unlock(&data->update_lock);
|
||||
return status;
|
||||
}
|
||||
|
||||
static int as5916_54xks_thermal_probe(struct platform_device *pdev)
|
||||
{
|
||||
int status = -1;
|
||||
|
||||
/* Register sysfs hooks */
|
||||
status = sysfs_create_group(&pdev->dev.kobj, &as5916_54xks_thermal_group);
|
||||
if (status) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
dev_info(&pdev->dev, "device created\n");
|
||||
|
||||
return 0;
|
||||
|
||||
exit:
|
||||
return status;
|
||||
}
|
||||
|
||||
static int as5916_54xks_thermal_remove(struct platform_device *pdev)
|
||||
{
|
||||
sysfs_remove_group(&pdev->dev.kobj, &as5916_54xks_thermal_group);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __init as5916_54xks_thermal_init(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
data = kzalloc(sizeof(struct as5916_54xks_thermal_data), GFP_KERNEL);
|
||||
if (!data) {
|
||||
ret = -ENOMEM;
|
||||
goto alloc_err;
|
||||
}
|
||||
|
||||
mutex_init(&data->update_lock);
|
||||
data->valid = 0;
|
||||
|
||||
ret = platform_driver_register(&as5916_54xks_thermal_driver);
|
||||
if (ret < 0) {
|
||||
goto dri_reg_err;
|
||||
}
|
||||
|
||||
data->pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
|
||||
if (IS_ERR(data->pdev)) {
|
||||
ret = PTR_ERR(data->pdev);
|
||||
goto dev_reg_err;
|
||||
}
|
||||
|
||||
/* Set up IPMI interface */
|
||||
ret = init_ipmi_data(&data->ipmi, 0, &data->pdev->dev);
|
||||
if (ret)
|
||||
goto ipmi_err;
|
||||
|
||||
return 0;
|
||||
|
||||
ipmi_err:
|
||||
platform_device_unregister(data->pdev);
|
||||
dev_reg_err:
|
||||
platform_driver_unregister(&as5916_54xks_thermal_driver);
|
||||
dri_reg_err:
|
||||
kfree(data);
|
||||
alloc_err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void __exit as5916_54xks_thermal_exit(void)
|
||||
{
|
||||
ipmi_destroy_user(data->ipmi.user);
|
||||
platform_device_unregister(data->pdev);
|
||||
platform_driver_unregister(&as5916_54xks_thermal_driver);
|
||||
kfree(data);
|
||||
}
|
||||
|
||||
MODULE_AUTHOR("Brandon Chuang <brandon_chuang@accton.com.tw>");
|
||||
MODULE_DESCRIPTION("AS5916 54XKS Thermal driver");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
module_init(as5916_54xks_thermal_init);
|
||||
module_exit(as5916_54xks_thermal_exit);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
###############################################################################
|
||||
#
|
||||
# x86_64_accton_as5916_54x README
|
||||
# x86_64_accton_as5916_54xks README
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
###############################################################################
|
||||
#
|
||||
# x86_64_accton_as5916_54xks Autogeneration
|
||||
#
|
||||
###############################################################################
|
||||
x86_64_accton_as5916_54xks_AUTO_DEFS := module/auto/x86_64_accton_as5916_54xks.yml
|
||||
x86_64_accton_as5916_54xks_AUTO_DIRS := module/inc/x86_64_accton_as5916_54xks module/src
|
||||
include $(BUILDER)/auto.mk
|
||||
|
||||
@@ -100,110 +100,57 @@ _onlp_fani_info_get_fan(int fid, onlp_fan_info_t* info)
|
||||
info->status |= ONLP_FAN_STATUS_PRESENT;
|
||||
|
||||
|
||||
/* get fan fault status (turn on when any one fails)
|
||||
/* get fan direction
|
||||
*/
|
||||
ret = onlp_file_read_int(&value, "%s""fan%d_fault", FAN_BOARD_PATH, fid);
|
||||
if (ret < 0) {
|
||||
AIM_LOG_ERROR("Unable to read status from (%s)\r\n", FAN_BOARD_PATH);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
if (value > 0) {
|
||||
info->status |= ONLP_FAN_STATUS_FAILED;
|
||||
}
|
||||
info->status |= ONLP_FAN_STATUS_F2B;
|
||||
|
||||
|
||||
/* get fan direction (both : the same)
|
||||
/* get fan speed
|
||||
*/
|
||||
ret = onlp_file_read_int(&value, "%s""fan%d_direction", FAN_BOARD_PATH, fid);
|
||||
if (ret < 0) {
|
||||
AIM_LOG_ERROR("Unable to read status from (%s)\r\n", FAN_BOARD_PATH);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
info->status |= value ? ONLP_FAN_STATUS_F2B : ONLP_FAN_STATUS_B2F;
|
||||
|
||||
|
||||
/* get front fan speed
|
||||
*/
|
||||
ret = onlp_file_read_int(&value, "%s""fan%d_front_speed_rpm", FAN_BOARD_PATH, fid);
|
||||
ret = onlp_file_read_int(&value, "%s""fan%d_input", FAN_BOARD_PATH, fid);
|
||||
if (ret < 0) {
|
||||
AIM_LOG_ERROR("Unable to read status from (%s)\r\n", FAN_BOARD_PATH);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
info->rpm = value;
|
||||
info->percentage = (info->rpm * 100)/MAX_FAN_SPEED;
|
||||
|
||||
/* get rear fan speed
|
||||
*/
|
||||
ret = onlp_file_read_int(&value, "%s""fan%d_rear_speed_rpm", FAN_BOARD_PATH, fid);
|
||||
if (ret < 0) {
|
||||
AIM_LOG_ERROR("Unable to read status from (%s)\r\n", FAN_BOARD_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
|
||||
*/
|
||||
ret = onlp_file_read_int(&value, "%s""fan_max_speed_rpm", FAN_BOARD_PATH);
|
||||
if (ret < 0) {
|
||||
AIM_LOG_ERROR("Unable to read status from (%s)\r\n", FAN_BOARD_PATH);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
info->percentage = (info->rpm * 100)/value;
|
||||
|
||||
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
|
||||
/* get fan fault status
|
||||
*/
|
||||
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;
|
||||
}
|
||||
if (!info->rpm) {
|
||||
info->status |= ONLP_FAN_STATUS_FAILED;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
_onlp_fani_info_get_fan_on_psu(int pid, onlp_fan_info_t* info)
|
||||
{
|
||||
int val = 0;
|
||||
int value, ret;
|
||||
|
||||
info->status |= ONLP_FAN_STATUS_PRESENT;
|
||||
|
||||
/* get fan direction
|
||||
*/
|
||||
info->status |= _onlp_get_fan_direction_on_psu();
|
||||
info->status |= ONLP_FAN_STATUS_F2B;
|
||||
|
||||
/* 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;
|
||||
info->status |= (val == 0) ? ONLP_FAN_STATUS_FAILED : 0;
|
||||
ret = onlp_file_read_int(&value, "%s""psu%d_fan1_input", PSU_SYSFS_PATH, pid);
|
||||
if (ret < 0) {
|
||||
AIM_LOG_ERROR("Unable to read status from (%s)\r\n", PSU_SYSFS_PATH);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
info->rpm = value;
|
||||
info->percentage = (info->rpm * 100)/MAX_PSU_FAN_SPEED;
|
||||
|
||||
/* get fan fault status
|
||||
*/
|
||||
if (!info->rpm) {
|
||||
info->status |= ONLP_FAN_STATUS_FAILED;
|
||||
}
|
||||
|
||||
return ONLP_STATUS_OK;
|
||||
@@ -264,7 +211,6 @@ int
|
||||
onlp_fani_percentage_set(onlp_oid_t id, int p)
|
||||
{
|
||||
int fid;
|
||||
char *path = NULL;
|
||||
|
||||
VALIDATE(id);
|
||||
|
||||
@@ -275,26 +221,12 @@ onlp_fani_percentage_set(onlp_oid_t id, int p)
|
||||
return ONLP_STATUS_E_INVALID;
|
||||
}
|
||||
|
||||
switch (fid)
|
||||
{
|
||||
case FAN_1_ON_PSU_1:
|
||||
return psu_ym2651y_pmbus_info_set(PSU1_ID, "psu_fan1_duty_cycle_percentage", p);
|
||||
case FAN_1_ON_PSU_2:
|
||||
return psu_ym2651y_pmbus_info_set(PSU2_ID, "psu_fan1_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;
|
||||
if (fid < FAN_1_ON_FAN_BOARD || fid > FAN_6_ON_FAN_BOARD) {
|
||||
return ONLP_STATUS_E_INVALID;
|
||||
}
|
||||
|
||||
if (onlp_file_write_int(p, path) < 0) {
|
||||
AIM_LOG_ERROR("Unable to write data to file (%s)\r\n", path);
|
||||
if (onlp_file_write_int(p, "%s""fan%d_pwm", FAN_BOARD_PATH, fid) < 0) {
|
||||
AIM_LOG_ERROR("Unable to write data to file %s""fan%d_pwm", FAN_BOARD_PATH, fid);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include <onlp/platformi/ledi.h>
|
||||
#include "platform_lib.h"
|
||||
|
||||
#define LED_FORMAT "/sys/class/leds/accton_as5916_54xks_led::%s/brightness"
|
||||
#define LED_FORMAT "/sys/devices/platform/as5916_54xks_led/%s"
|
||||
|
||||
#define VALIDATE(_id) \
|
||||
do { \
|
||||
@@ -78,8 +78,8 @@ typedef struct led_light_mode_map {
|
||||
} led_light_mode_map_t;
|
||||
|
||||
led_light_mode_map_t led_map[] = {
|
||||
{LED_LOC, LED_MODE_OFF, ONLP_LED_MODE_OFF},
|
||||
{LED_LOC, LED_MODE_ORANGE, ONLP_LED_MODE_ORANGE},
|
||||
{LED_LOC, LED_MODE_OFF, ONLP_LED_MODE_OFF},
|
||||
{LED_LOC, LED_MODE_ORANGE_BLINKING, ONLP_LED_MODE_ORANGE_BLINKING},
|
||||
{LED_DIAG, LED_MODE_OFF, ONLP_LED_MODE_OFF},
|
||||
{LED_DIAG, LED_MODE_GREEN, ONLP_LED_MODE_GREEN},
|
||||
{LED_DIAG, LED_MODE_ORANGE, ONLP_LED_MODE_ORANGE},
|
||||
@@ -91,11 +91,11 @@ led_light_mode_map_t led_map[] = {
|
||||
static char *leds[] = /* must map with onlp_led_id */
|
||||
{
|
||||
NULL,
|
||||
"loc",
|
||||
"diag",
|
||||
"psu1",
|
||||
"psu2",
|
||||
"fan"
|
||||
"led_loc",
|
||||
"led_diag",
|
||||
"led_psu1",
|
||||
"led_psu2",
|
||||
"led_fan"
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -107,12 +107,12 @@ static onlp_led_info_t linfo[] =
|
||||
{
|
||||
{ ONLP_LED_ID_CREATE(LED_LOC), "Chassis LED 1 (LOC LED)", 0 },
|
||||
ONLP_LED_STATUS_PRESENT,
|
||||
ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_ORANGE,
|
||||
ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_ORANGE_BLINKING,
|
||||
},
|
||||
{
|
||||
{ ONLP_LED_ID_CREATE(LED_DIAG), "Chassis LED 2 (DIAG LED)", 0 },
|
||||
ONLP_LED_STATUS_PRESENT,
|
||||
ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_GREEN,
|
||||
ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_ORANGE,
|
||||
},
|
||||
{
|
||||
{ ONLP_LED_ID_CREATE(LED_PSU1), "Chassis LED 3 (PSU1 LED)", 0 },
|
||||
@@ -197,7 +197,7 @@ onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info)
|
||||
info->mode = driver_to_onlp_led_mode(lid, value);
|
||||
|
||||
/* Set the on/off status */
|
||||
if (info->mode != ONLP_LED_MODE_OFF) {
|
||||
if (info->mode != ONLP_LED_MODE_OFF && info->mode != ONLP_LED_MODE_AUTO) {
|
||||
info->status |= ONLP_LED_STATUS_ON;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,124 +0,0 @@
|
||||
/************************************************************
|
||||
* <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 <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <onlplib/file.h>
|
||||
#include <onlp/onlp.h>
|
||||
#include "platform_lib.h"
|
||||
|
||||
#define PSU_NODE_MAX_PATH_LEN 64
|
||||
#define PSU_MODEL_NAME_LEN 9
|
||||
#define PSU_FAN_DIR_LEN 3
|
||||
|
||||
psu_type_t get_psu_type(int id, char* modelname, int modelname_len)
|
||||
{
|
||||
int ret = 0, value = 0;
|
||||
char model[PSU_MODEL_NAME_LEN + 1] = {0};
|
||||
char fan_dir[PSU_FAN_DIR_LEN + 1] = {0};
|
||||
char *path = NULL;
|
||||
|
||||
if (modelname && modelname_len < PSU_MODEL_NAME_LEN) {
|
||||
return PSU_TYPE_UNKNOWN;
|
||||
}
|
||||
|
||||
/* Check AC model name */
|
||||
path = (id == PSU1_ID) ? PSU1_AC_EEPROM_NODE(psu_model_name) : PSU2_AC_EEPROM_NODE(psu_model_name);
|
||||
ret = onlp_file_read((uint8_t*)model, PSU_MODEL_NAME_LEN, &value, path);
|
||||
if (ret != ONLP_STATUS_OK || value != PSU_MODEL_NAME_LEN) {
|
||||
return PSU_TYPE_UNKNOWN;
|
||||
|
||||
}
|
||||
|
||||
if (strncmp(model, "YM-2651Y", strlen("YM-2651Y")) != 0) {
|
||||
return PSU_TYPE_UNKNOWN;
|
||||
}
|
||||
|
||||
if (modelname) {
|
||||
strncpy(modelname, model, modelname_len-1);
|
||||
}
|
||||
|
||||
path = (id == PSU1_ID) ? PSU1_AC_PMBUS_NODE(psu_fan_dir) : PSU2_AC_PMBUS_NODE(psu_fan_dir);
|
||||
ret = onlp_file_read((uint8_t*)fan_dir, sizeof(fan_dir), &value, path);
|
||||
if (ret != ONLP_STATUS_OK) {
|
||||
return PSU_TYPE_UNKNOWN;
|
||||
}
|
||||
|
||||
if (strncmp(fan_dir, "F2B", strlen("F2B")) == 0) {
|
||||
return PSU_TYPE_AC_F2B;
|
||||
}
|
||||
|
||||
if (strncmp(fan_dir, "B2F", strlen("B2F")) == 0) {
|
||||
return PSU_TYPE_AC_B2F;
|
||||
}
|
||||
|
||||
return PSU_TYPE_UNKNOWN;
|
||||
}
|
||||
|
||||
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) {
|
||||
ret = onlp_file_read_int(value, "%s%s", PSU1_AC_PMBUS_PREFIX, node);
|
||||
}
|
||||
else {
|
||||
ret = onlp_file_read_int(value, "%s%s", PSU2_AC_PMBUS_PREFIX, node);
|
||||
}
|
||||
|
||||
if (ret < 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_int(value, path) < 0) {
|
||||
AIM_LOG_ERROR("Unable to write data to file (%s)\r\n", path);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
@@ -36,22 +36,9 @@
|
||||
#define PSU1_ID 1
|
||||
#define PSU2_ID 2
|
||||
|
||||
#define PSU1_AC_PMBUS_PREFIX "/sys/bus/i2c/devices/18-005b/"
|
||||
#define PSU2_AC_PMBUS_PREFIX "/sys/bus/i2c/devices/17-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_EEPROM_PREFIX "/sys/bus/i2c/devices/18-0053/"
|
||||
#define PSU2_AC_EEPROM_PREFIX "/sys/bus/i2c/devices/17-0050/"
|
||||
|
||||
#define PSU1_AC_EEPROM_NODE(node) PSU1_AC_EEPROM_PREFIX#node
|
||||
#define PSU2_AC_EEPROM_NODE(node) PSU2_AC_EEPROM_PREFIX#node
|
||||
|
||||
#define FAN_BOARD_PATH "/sys/bus/i2c/devices/9-0066/"
|
||||
#define FAN_NODE(node) FAN_BOARD_PATH#node
|
||||
|
||||
#define IDPROM_PATH "/sys/bus/i2c/devices/0-0056/eeprom"
|
||||
#define PSU_SYSFS_PATH "/sys/devices/platform/as5916_54xks_psu/"
|
||||
#define FAN_BOARD_PATH "/sys/devices/platform/as5916_54xks_fan/"
|
||||
#define IDPROM_PATH "/sys/devices/platform/as5916_54xks_sys/eeprom"
|
||||
|
||||
enum onlp_thermal_id
|
||||
{
|
||||
@@ -65,16 +52,6 @@ enum onlp_thermal_id
|
||||
THERMAL_1_ON_PSU2,
|
||||
};
|
||||
|
||||
typedef enum psu_type {
|
||||
PSU_TYPE_UNKNOWN,
|
||||
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_ym2651y_pmbus_info_get(int id, char *node, int *value);
|
||||
int psu_ym2651y_pmbus_info_set(int id, char *node, int value);
|
||||
|
||||
#define DEBUG_MODE 0
|
||||
|
||||
#if (DEBUG_MODE == 1)
|
||||
@@ -86,4 +63,3 @@ int psu_ym2651y_pmbus_info_set(int id, char *node, int value);
|
||||
|
||||
#endif /* __PLATFORM_LIB_H__ */
|
||||
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
|
||||
#define PSU_STATUS_PRESENT 1
|
||||
#define PSU_STATUS_POWER_GOOD 1
|
||||
#define PSU_NODE_MAX_PATH_LEN 64
|
||||
|
||||
#define VALIDATE(_id) \
|
||||
do { \
|
||||
@@ -38,65 +37,12 @@
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
static int
|
||||
psu_status_info_get(int id, char *node, int *value)
|
||||
{
|
||||
char *prefix = NULL;
|
||||
|
||||
*value = 0;
|
||||
|
||||
prefix = (id == PSU1_ID) ? PSU1_AC_EEPROM_PREFIX : PSU2_AC_EEPROM_PREFIX;
|
||||
if (onlp_file_read_int(value, "%s%s", prefix, node) < 0) {
|
||||
AIM_LOG_ERROR("Unable to read status from file(%s%s)\r\n", prefix, node);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get all information about the given PSU oid.
|
||||
*/
|
||||
@@ -116,17 +62,18 @@ 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;
|
||||
int pid = ONLP_OID_ID_GET(id);
|
||||
|
||||
VALIDATE(id);
|
||||
|
||||
memset(info, 0, sizeof(onlp_psu_info_t));
|
||||
*info = pinfo[index]; /* Set the onlp_oid_hdr_t */
|
||||
*info = pinfo[pid]; /* Set the onlp_oid_hdr_t */
|
||||
|
||||
/* Get the present state */
|
||||
if (psu_status_info_get(index, "psu_present", &val) != 0) {
|
||||
printf("Unable to read PSU(%d) node(psu_present)\r\n", index);
|
||||
ret = onlp_file_read_int(&val, "%s""psu%d_present", PSU_SYSFS_PATH, pid);
|
||||
if (ret < 0) {
|
||||
AIM_LOG_ERROR("Unable to read status from (%s""psu%d_present)\r\n", PSU_SYSFS_PATH, pid);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
if (val != PSU_STATUS_PRESENT) {
|
||||
@@ -137,41 +84,71 @@ onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info)
|
||||
|
||||
|
||||
/* Get power good status */
|
||||
if (psu_status_info_get(index, "psu_power_good", &val) != 0) {
|
||||
printf("Unable to read PSU(%d) node(psu_power_good)\r\n", index);
|
||||
ret = onlp_file_read_int(&val, "%s""psu%d_power_good", PSU_SYSFS_PATH, pid);
|
||||
if (ret < 0) {
|
||||
AIM_LOG_ERROR("Unable to read status from (%s""psu%d_power_good)\r\n", PSU_SYSFS_PATH, pid);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
if (val != PSU_STATUS_POWER_GOOD) {
|
||||
info->status |= ONLP_PSU_STATUS_FAILED;
|
||||
}
|
||||
|
||||
if (info->status & ONLP_PSU_STATUS_FAILED) {
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
/* Get PSU type
|
||||
*/
|
||||
psu_type = get_psu_type(index, info->model, sizeof(info->model));
|
||||
/* Read voltage, current and power */
|
||||
val = 0;
|
||||
if (onlp_file_read_int(&val, "%s""psu%d_vin", PSU_SYSFS_PATH, pid) == 0 && val) {
|
||||
info->mvin = val;
|
||||
info->caps |= ONLP_PSU_CAPS_VIN;
|
||||
}
|
||||
|
||||
val = 0;
|
||||
if (onlp_file_read_int(&val, "%s""psu%d_vout", PSU_SYSFS_PATH, pid) == 0 && val) {
|
||||
info->mvout = val;
|
||||
info->caps |= ONLP_PSU_CAPS_VOUT;
|
||||
}
|
||||
|
||||
switch (psu_type) {
|
||||
case PSU_TYPE_AC_F2B:
|
||||
case PSU_TYPE_AC_B2F:
|
||||
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;
|
||||
val = 0;
|
||||
if (onlp_file_read_int(&val, "%s""psu%d_iout", PSU_SYSFS_PATH, pid) == 0 && val) {
|
||||
info->miout = val;
|
||||
info->caps |= ONLP_PSU_CAPS_IOUT;
|
||||
}
|
||||
|
||||
val = 0;
|
||||
if (onlp_file_read_int(&val, "%s""psu%d_pout", PSU_SYSFS_PATH, pid) == 0 && val) {
|
||||
info->mpout = val;
|
||||
info->caps |= ONLP_PSU_CAPS_POUT;
|
||||
}
|
||||
|
||||
/* Set the associated oid_table */
|
||||
val = 0;
|
||||
if (onlp_file_read_int(&val, "%s""psu%d_fan1_input", PSU_SYSFS_PATH, pid) == 0 && val) {
|
||||
info->hdr.coids[0] = ONLP_FAN_ID_CREATE(pid + CHASSIS_FAN_COUNT);
|
||||
}
|
||||
|
||||
val = 0;
|
||||
if (onlp_file_read_int(&val, "%s""psu%d_temp1_input", PSU_SYSFS_PATH, pid) == 0 && val) {
|
||||
info->hdr.coids[1] = ONLP_THERMAL_ID_CREATE(pid + CHASSIS_THERMAL_COUNT);
|
||||
}
|
||||
|
||||
/* Read model */
|
||||
char *string = NULL;
|
||||
int len = onlp_file_read_str(&string, "%s""psu%d_model", PSU_SYSFS_PATH, pid);
|
||||
if (string && len) {
|
||||
strncpy(info->model, string, len);
|
||||
aim_free(string);
|
||||
}
|
||||
|
||||
/* Read serial */
|
||||
len = onlp_file_read_str(&string, "%s""psu%d_serial", PSU_SYSFS_PATH, pid);
|
||||
if (string && len) {
|
||||
strncpy(info->serial, string, len);
|
||||
aim_free(string);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_psui_ioctl(onlp_oid_t pid, va_list vargs)
|
||||
{
|
||||
return ONLP_STATUS_E_UNSUPPORTED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -29,16 +29,13 @@
|
||||
#include "x86_64_accton_as5916_54xks_int.h"
|
||||
#include "x86_64_accton_as5916_54xks_log.h"
|
||||
|
||||
#define PORT_BUS_INDEX(port) (port+33)
|
||||
|
||||
#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"
|
||||
#define MODULE_PRESENT_ALL_ATTR "/sys/bus/i2c/devices/%d-00%d/module_present_all"
|
||||
#define MODULE_RXLOS_ALL_ATTR_CPLD1 "/sys/bus/i2c/devices/11-0060/module_rx_los_all"
|
||||
#define MODULE_RXLOS_ALL_ATTR_CPLD2 "/sys/bus/i2c/devices/12-0062/module_rx_los_all"
|
||||
#define PORT_EEPROM_FORMAT "/sys/devices/platform/as5916_54xks_sfp/module_eeprom_%d"
|
||||
#define MODULE_PRESENT_FORMAT "/sys/devices/platform/as5916_54xks_sfp/module_present_%d"
|
||||
#define MODULE_RXLOS_FORMAT "/sys/devices/platform/as5916_54xks_sfp/module_rx_los_%d"
|
||||
#define MODULE_TXFAULT_FORMAT "/sys/devices/platform/as5916_54xks_sfp/module_tx_fault_%d"
|
||||
#define MODULE_TXDISABLE_FORMAT "/sys/devices/platform/as5916_54xks_sfp/module_tx_disable_%d"
|
||||
#define MODULE_PRESENT_ALL_ATTR "/sys/devices/platform/as5916_54xks_sfp/module_present_all"
|
||||
#define MODULE_RXLOS_ALL_ATTR "/sys/devices/platform/as5916_54xks_sfp/module_rxlos_all"
|
||||
|
||||
/************************************************************
|
||||
*
|
||||
@@ -76,12 +73,8 @@ onlp_sfpi_is_present(int port)
|
||||
* Return < 0 if error.
|
||||
*/
|
||||
int present;
|
||||
int bus, addr;
|
||||
|
||||
addr = (port < 24) ? 60 : 62;
|
||||
bus = (addr == 60) ? 11 : 12;
|
||||
|
||||
if (onlp_file_read_int(&present, MODULE_PRESENT_FORMAT, bus, addr, (port+1)) < 0) {
|
||||
if (onlp_file_read_int(&present, MODULE_PRESENT_FORMAT, (port+1)) < 0) {
|
||||
AIM_LOG_ERROR("Unable to read present status from port(%d)\r\n", port);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
@@ -92,45 +85,25 @@ onlp_sfpi_is_present(int port)
|
||||
int
|
||||
onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst)
|
||||
{
|
||||
uint32_t bytes[7], *ptr = NULL;
|
||||
uint32_t bytes[7];
|
||||
FILE* fp;
|
||||
int addr;
|
||||
|
||||
ptr = bytes;
|
||||
/* Read present status of port 0~54 */
|
||||
int count = 0;
|
||||
|
||||
for (addr = 60; addr <= 62; addr+=2) {
|
||||
/* Read present status of port 0~53 */
|
||||
int count = 0;
|
||||
char file[64] = {0};
|
||||
int bus = (addr == 60) ? 11 : 12;
|
||||
|
||||
sprintf(file, MODULE_PRESENT_ALL_ATTR, bus, addr);
|
||||
fp = fopen(file, "r");
|
||||
if(fp == NULL) {
|
||||
AIM_LOG_ERROR("Unable to open the module_present_all device file of CPLD(0x%d).", addr);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
fp = fopen(MODULE_PRESENT_ALL_ATTR, "r");
|
||||
if(fp == NULL) {
|
||||
AIM_LOG_ERROR("Unable to open the module_present_all device file from (%s).", MODULE_PRESENT_ALL_ATTR);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
if (addr == 60) { /* CPLD1 */
|
||||
count = fscanf(fp, "%x %x %x", ptr+0, ptr+1, ptr+2);
|
||||
fclose(fp);
|
||||
if(count != 3) {
|
||||
/* Likely a CPLD read timeout. */
|
||||
AIM_LOG_ERROR("Unable to read all fields the module_present_all device file of CPLD(0x%d).", addr);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
}
|
||||
else { /* CPLD2 */
|
||||
count = fscanf(fp, "%x %x %x %x", ptr+0, ptr+1, ptr+2, ptr+3);
|
||||
fclose(fp);
|
||||
if(count != 4) {
|
||||
/* Likely a CPLD read timeout. */
|
||||
AIM_LOG_ERROR("Unable to read all fields the module_present_all device file of CPLD(0x%d).", addr);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
}
|
||||
|
||||
ptr += count;
|
||||
count = fscanf(fp, "%x %x %x %x %x %x %x", bytes+0, bytes+1, bytes+2, bytes+3,
|
||||
bytes+4, bytes+5, bytes+6);
|
||||
fclose(fp);
|
||||
if(count != 7) {
|
||||
/* Likely a CPLD read timeout. */
|
||||
AIM_LOG_ERROR("Unable to read all fields the module_present_all device file from(%s).", MODULE_PRESENT_ALL_ATTR);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
/* Mask out non-existant QSFP ports */
|
||||
@@ -157,38 +130,28 @@ int
|
||||
onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst)
|
||||
{
|
||||
uint32_t bytes[6];
|
||||
uint32_t *ptr = bytes;
|
||||
FILE* fp;
|
||||
|
||||
/* Read present status of port 0~23 */
|
||||
int addr, i = 0;
|
||||
/* Read present status of port 0~25 */
|
||||
int count = 0;
|
||||
|
||||
for (addr = 60; addr <= 62; addr+=2) {
|
||||
if (addr == 60) {
|
||||
fp = fopen(MODULE_RXLOS_ALL_ATTR_CPLD1, "r");
|
||||
}
|
||||
else {
|
||||
fp = fopen(MODULE_RXLOS_ALL_ATTR_CPLD2, "r");
|
||||
}
|
||||
|
||||
if(fp == NULL) {
|
||||
AIM_LOG_ERROR("Unable to open the module_rx_los_all device file of CPLD(0x%d)", addr);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
int count = fscanf(fp, "%x %x %x", ptr+0, ptr+1, ptr+2);
|
||||
fclose(fp);
|
||||
if(count != 3) {
|
||||
/* Likely a CPLD read timeout. */
|
||||
AIM_LOG_ERROR("Unable to read all fields from the module_rx_los_all device file of CPLD(0x%d)", addr);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
ptr += count;
|
||||
fp = fopen(MODULE_RXLOS_ALL_ATTR, "r");
|
||||
if(fp == NULL) {
|
||||
AIM_LOG_ERROR("Unable to open the module_rxlos_all device file from (%s).", MODULE_RXLOS_ALL_ATTR);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
count = fscanf(fp, "%x %x %x %x %x %x", bytes+0, bytes+1, bytes+2,
|
||||
bytes+3, bytes+4, bytes+5);
|
||||
fclose(fp);
|
||||
if(count != 6) {
|
||||
/* Likely a CPLD read timeout. */
|
||||
AIM_LOG_ERROR("Unable to read all fields the module_rxlos_all device file from(%s).", MODULE_RXLOS_ALL_ATTR);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
/* Convert to 64 bit integer in port order */
|
||||
i = 0;
|
||||
int i = 0;
|
||||
uint64_t rx_los_all = 0 ;
|
||||
for(i = AIM_ARRAYSIZE(bytes)-1; i >= 0; i--) {
|
||||
rx_los_all <<= 8;
|
||||
@@ -216,7 +179,7 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256])
|
||||
int size = 0;
|
||||
memset(data, 0, 256);
|
||||
|
||||
if(onlp_file_read(data, 256, &size, PORT_EEPROM_FORMAT, PORT_BUS_INDEX(port)) != ONLP_STATUS_OK) {
|
||||
if(onlp_file_read(data, 256, &size, PORT_EEPROM_FORMAT, (port+1)) != ONLP_STATUS_OK) {
|
||||
AIM_LOG_ERROR("Unable to read eeprom from port(%d)\r\n", port);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
@@ -229,52 +192,16 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256])
|
||||
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, PORT_BUS_INDEX(port));
|
||||
fp = fopen(file, "r");
|
||||
if(fp == NULL) {
|
||||
AIM_LOG_ERROR("Unable to open the eeprom device file of port(%d)", port);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
if (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_control_set(int port, onlp_sfp_control_t control, int value)
|
||||
{
|
||||
int rv;
|
||||
|
||||
if (port < 0 || port >= 48) {
|
||||
return ONLP_STATUS_E_UNSUPPORTED;
|
||||
}
|
||||
|
||||
int addr = (port < 24) ? 60 : 62;
|
||||
int bus = (addr == 60) ? 11 : 12;
|
||||
|
||||
switch(control)
|
||||
{
|
||||
case ONLP_SFP_CONTROL_TX_DISABLE:
|
||||
{
|
||||
if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT, bus, addr, (port+1)) < 0) {
|
||||
if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT, (port+1)) < 0) {
|
||||
AIM_LOG_ERROR("Unable to set tx_disable status to port(%d)\r\n", port);
|
||||
rv = ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
@@ -297,18 +224,19 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value)
|
||||
{
|
||||
int rv;
|
||||
|
||||
if (port < 0 || port >= 48) {
|
||||
if (port < 0) {
|
||||
return ONLP_STATUS_E_UNSUPPORTED;
|
||||
}
|
||||
|
||||
int addr = (port < 24) ? 60 : 62;
|
||||
int bus = (addr == 60) ? 11 : 12;
|
||||
|
||||
switch(control)
|
||||
{
|
||||
case ONLP_SFP_CONTROL_RX_LOS:
|
||||
{
|
||||
if (onlp_file_read_int(value, MODULE_RXLOS_FORMAT, bus, addr, (port+1)) < 0) {
|
||||
if (port >= 48) {
|
||||
return ONLP_STATUS_E_UNSUPPORTED;
|
||||
}
|
||||
|
||||
if (onlp_file_read_int(value, MODULE_RXLOS_FORMAT, (port+1)) < 0) {
|
||||
AIM_LOG_ERROR("Unable to read rx_loss status from port(%d)\r\n", port);
|
||||
rv = ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
@@ -320,7 +248,11 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value)
|
||||
|
||||
case ONLP_SFP_CONTROL_TX_FAULT:
|
||||
{
|
||||
if (onlp_file_read_int(value, MODULE_TXFAULT_FORMAT, bus, addr, (port+1)) < 0) {
|
||||
if (port >= 48) {
|
||||
return ONLP_STATUS_E_UNSUPPORTED;
|
||||
}
|
||||
|
||||
if (onlp_file_read_int(value, MODULE_TXFAULT_FORMAT, (port+1)) < 0) {
|
||||
AIM_LOG_ERROR("Unable to read tx_fault status from port(%d)\r\n", port);
|
||||
rv = ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
@@ -332,7 +264,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value)
|
||||
|
||||
case ONLP_SFP_CONTROL_TX_DISABLE:
|
||||
{
|
||||
if (onlp_file_read_int(value, MODULE_TXDISABLE_FORMAT, bus, addr, (port+1)) < 0) {
|
||||
if (onlp_file_read_int(value, MODULE_TXDISABLE_FORMAT, (port+1)) < 0) {
|
||||
AIM_LOG_ERROR("Unable to read tx_disabled status from port(%d)\r\n", port);
|
||||
rv = ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <onlplib/i2c.h>
|
||||
#include <onlplib/file.h>
|
||||
#include <onlp/platformi/sysi.h>
|
||||
#include <onlp/platformi/ledi.h>
|
||||
@@ -38,15 +37,6 @@
|
||||
#include "x86_64_accton_as5916_54xks_int.h"
|
||||
#include "x86_64_accton_as5916_54xks_log.h"
|
||||
|
||||
#define CPLD_VERSION_FORMAT "/sys/bus/i2c/devices/%s/version"
|
||||
#define NUM_OF_CPLD 2
|
||||
|
||||
static char* cpld_path[NUM_OF_CPLD] =
|
||||
{
|
||||
"11-0060",
|
||||
"12-0062"
|
||||
};
|
||||
|
||||
const char*
|
||||
onlp_sysi_platform_get(void)
|
||||
{
|
||||
@@ -56,26 +46,17 @@ onlp_sysi_platform_get(void)
|
||||
int
|
||||
onlp_sysi_onie_data_get(uint8_t** data, int* size)
|
||||
{
|
||||
int ret = ONLP_STATUS_OK;
|
||||
int i = 0;
|
||||
uint8_t* rdata = aim_zmalloc(256);
|
||||
|
||||
for (i = 0; i < 128; i++) {
|
||||
ret = onlp_i2c_readw(0, 0x56, i*2, ONLP_I2C_F_FORCE);
|
||||
if (ret < 0) {
|
||||
aim_free(rdata);
|
||||
*size = 0;
|
||||
return ret;
|
||||
uint8_t* rdata = aim_zmalloc(512);
|
||||
if(onlp_file_read(rdata, 512, size, IDPROM_PATH) == ONLP_STATUS_OK) {
|
||||
if(*size == 512) {
|
||||
*data = rdata;
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
rdata[i*2] = ret & 0xff;
|
||||
rdata[i*2+1] = (ret >> 8) & 0xff;
|
||||
}
|
||||
|
||||
*size = 256;
|
||||
*data = rdata;
|
||||
|
||||
return ONLP_STATUS_OK;
|
||||
aim_free(rdata);
|
||||
*size = 0;
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -108,20 +89,38 @@ onlp_sysi_oids_get(onlp_oid_t* table, int max)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define CPLD_VERSION_FORMAT "/sys/devices/platform/as5916_54xks_sys/%s"
|
||||
|
||||
typedef struct cpld_version {
|
||||
char *attr_name;
|
||||
int version;
|
||||
char *description;
|
||||
} cpld_version_t;
|
||||
|
||||
int
|
||||
onlp_sysi_platform_info_get(onlp_platform_info_t* pi)
|
||||
{
|
||||
int i, v[NUM_OF_CPLD] = {0};
|
||||
int i, ret;
|
||||
cpld_version_t cplds[] = { { "mb_cpld1_ver", 0, "Mainboard-CPLD#1"},
|
||||
{ "mb_cpld2_ver", 0, "Mainboard-CPLD#2"},
|
||||
{ "cpu_cpld_ver", 0, "CPU-CPLD"},
|
||||
{ "fan_cpld_ver", 0, "FAN-CPLD"} };
|
||||
/* Read CPLD version
|
||||
*/
|
||||
for (i = 0; i < AIM_ARRAYSIZE(cplds); i++) {
|
||||
ret = onlp_file_read_int(&cplds[i].version, CPLD_VERSION_FORMAT, cplds[i].attr_name);
|
||||
|
||||
for (i = 0; i < AIM_ARRAYSIZE(cpld_path); i++) {
|
||||
v[i] = 0;
|
||||
|
||||
if(onlp_file_read_int(v+i, CPLD_VERSION_FORMAT , cpld_path[i]) < 0) {
|
||||
if (ret < 0) {
|
||||
AIM_LOG_ERROR("Unable to read version from CPLD(%s)\r\n", cplds[i].attr_name);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
}
|
||||
|
||||
pi->cpld_versions = aim_fstrdup("%d.%d", v[0], v[1]);
|
||||
pi->cpld_versions = aim_fstrdup("%s:%d, %s:%d, %s:%d, %s:%d",
|
||||
cplds[0].description, cplds[0].version,
|
||||
cplds[1].description, cplds[1].version,
|
||||
cplds[2].description, cplds[2].version,
|
||||
cplds[3].description, cplds[3].version);
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
@@ -131,219 +130,3 @@ onlp_sysi_platform_info_free(onlp_platform_info_t* pi)
|
||||
aim_free(pi->cpld_versions);
|
||||
}
|
||||
|
||||
#define FAN_DUTY_MAX (100)
|
||||
#define FAN_DUTY_MID (69)
|
||||
#define FAN_DUTY_MIN (38)
|
||||
|
||||
#define FANCTRL_DIR_FACTOR (ONLP_FAN_STATUS_B2F)
|
||||
#define FANCTRL_DIR_FACTOR_DUTY_ADDON (6)
|
||||
|
||||
static int
|
||||
sysi_fanctrl_fan_fault_policy(onlp_fan_info_t fi[CHASSIS_FAN_COUNT],
|
||||
onlp_thermal_info_t ti[CHASSIS_THERMAL_COUNT],
|
||||
int *adjusted)
|
||||
{
|
||||
int i;
|
||||
*adjusted = 0;
|
||||
|
||||
/* Bring fan speed to FAN_DUTY_MAX if any fan is not operational */
|
||||
for (i = 0; i < CHASSIS_FAN_COUNT; i++) {
|
||||
if (!(fi[i].status & ONLP_FAN_STATUS_FAILED)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
*adjusted = 1;
|
||||
return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_MAX);
|
||||
}
|
||||
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
sysi_fanctrl_fan_absent_policy(onlp_fan_info_t fi[CHASSIS_FAN_COUNT],
|
||||
onlp_thermal_info_t ti[CHASSIS_THERMAL_COUNT],
|
||||
int *adjusted)
|
||||
{
|
||||
int i;
|
||||
*adjusted = 0;
|
||||
|
||||
/* Bring fan speed to FAN_DUTY_MAX if fan is not present */
|
||||
for (i = 0; i < CHASSIS_FAN_COUNT; i++) {
|
||||
if (fi[i].status & ONLP_FAN_STATUS_PRESENT) {
|
||||
continue;
|
||||
}
|
||||
|
||||
*adjusted = 1;
|
||||
return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_MAX);
|
||||
}
|
||||
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
sysi_fanctrl_fan_unknown_speed_policy(onlp_fan_info_t fi[CHASSIS_FAN_COUNT],
|
||||
onlp_thermal_info_t ti[CHASSIS_THERMAL_COUNT],
|
||||
int *adjusted)
|
||||
{
|
||||
int fanduty;
|
||||
int fanduty_min = FAN_DUTY_MIN;
|
||||
int fanduty_mid = FAN_DUTY_MID;
|
||||
|
||||
*adjusted = 0;
|
||||
fanduty_min += (fi[0].status & FANCTRL_DIR_FACTOR) ? FANCTRL_DIR_FACTOR_DUTY_ADDON : 0;
|
||||
fanduty_mid += (fi[0].status & FANCTRL_DIR_FACTOR) ? FANCTRL_DIR_FACTOR_DUTY_ADDON : 0;
|
||||
|
||||
if (onlp_file_read_int(&fanduty, FAN_NODE(fan_duty_cycle_percentage)) < 0) {
|
||||
*adjusted = 1;
|
||||
return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_MAX);
|
||||
}
|
||||
|
||||
/* Bring fan speed to max if current speed is not expected
|
||||
*/
|
||||
if (fanduty != fanduty_min && fanduty != fanduty_mid && fanduty != FAN_DUTY_MAX) {
|
||||
*adjusted = 1;
|
||||
return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_MAX);
|
||||
}
|
||||
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
sysi_fanctrl_single_thermal_sensor_policy(onlp_fan_info_t fi[CHASSIS_FAN_COUNT],
|
||||
onlp_thermal_info_t ti[CHASSIS_THERMAL_COUNT],
|
||||
int *adjusted)
|
||||
{
|
||||
int i;
|
||||
*adjusted = 0;
|
||||
|
||||
/* When anyone higher than 50 degrees, all fans run with duty 100%.
|
||||
*/
|
||||
for (i = (THERMAL_1_ON_MAIN_BROAD); i <= (THERMAL_3_ON_MAIN_BROAD); i++) {
|
||||
if (ti[i-1].mcelsius < 50000) {
|
||||
continue;
|
||||
}
|
||||
|
||||
*adjusted = 1;
|
||||
return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_MAX);
|
||||
}
|
||||
|
||||
/* When anyone higher than 45 degrees, all fans run with duty 62.5%.
|
||||
*/
|
||||
for (i = (THERMAL_1_ON_MAIN_BROAD); i <= (THERMAL_3_ON_MAIN_BROAD); i++) {
|
||||
if (ti[i-1].mcelsius < 45000) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int fanduty_mid = FAN_DUTY_MID;
|
||||
fanduty_mid += (fi[0].status & FANCTRL_DIR_FACTOR) ? FANCTRL_DIR_FACTOR_DUTY_ADDON : 0;
|
||||
|
||||
*adjusted = 1;
|
||||
return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), fanduty_mid);
|
||||
}
|
||||
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
sysi_fanctrl_overall_thermal_sensor_policy(onlp_fan_info_t fi[CHASSIS_FAN_COUNT],
|
||||
onlp_thermal_info_t ti[CHASSIS_THERMAL_COUNT],
|
||||
int *adjusted)
|
||||
{
|
||||
int fanduty_min = FAN_DUTY_MIN;
|
||||
int fanduty_mid = FAN_DUTY_MID;
|
||||
int i, num_of_sensor = 0, temp_avg = 0;
|
||||
|
||||
*adjusted = 0;
|
||||
fanduty_min += (fi[0].status & FANCTRL_DIR_FACTOR) ? FANCTRL_DIR_FACTOR_DUTY_ADDON : 0;
|
||||
fanduty_mid += (fi[0].status & FANCTRL_DIR_FACTOR) ? FANCTRL_DIR_FACTOR_DUTY_ADDON : 0;
|
||||
|
||||
for (i = (THERMAL_1_ON_MAIN_BROAD); i <= (THERMAL_3_ON_MAIN_BROAD); i++) {
|
||||
num_of_sensor++;
|
||||
temp_avg += ti[i-1].mcelsius;
|
||||
}
|
||||
|
||||
temp_avg /= num_of_sensor;
|
||||
|
||||
if (temp_avg >= 45000) {
|
||||
*adjusted = 1;
|
||||
return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_MAX);
|
||||
}
|
||||
else if (temp_avg >= 40000) {
|
||||
*adjusted = 1;
|
||||
return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), fanduty_mid);
|
||||
}
|
||||
else if (temp_avg < 35000) {
|
||||
*adjusted = 1;
|
||||
return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), fanduty_min);
|
||||
}
|
||||
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
typedef int (*fan_control_policy)(onlp_fan_info_t fi[CHASSIS_FAN_COUNT],
|
||||
onlp_thermal_info_t ti[CHASSIS_THERMAL_COUNT],
|
||||
int *adjusted);
|
||||
|
||||
fan_control_policy fan_control_policies[] = {
|
||||
sysi_fanctrl_fan_fault_policy,
|
||||
sysi_fanctrl_fan_absent_policy,
|
||||
sysi_fanctrl_fan_unknown_speed_policy,
|
||||
sysi_fanctrl_single_thermal_sensor_policy,
|
||||
sysi_fanctrl_overall_thermal_sensor_policy,
|
||||
};
|
||||
|
||||
int
|
||||
onlp_sysi_platform_manage_fans(void)
|
||||
{
|
||||
int i, rc;
|
||||
onlp_fan_info_t fi[CHASSIS_FAN_COUNT];
|
||||
onlp_thermal_info_t ti[CHASSIS_THERMAL_COUNT];
|
||||
|
||||
memset(fi, 0, sizeof(fi));
|
||||
memset(ti, 0, sizeof(ti));
|
||||
|
||||
/* Get fan status
|
||||
*/
|
||||
for (i = 0; i < CHASSIS_FAN_COUNT; i++) {
|
||||
rc = onlp_fani_info_get(ONLP_FAN_ID_CREATE(i+1), &fi[i]);
|
||||
|
||||
if (rc != ONLP_STATUS_OK) {
|
||||
onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_MAX);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get thermal sensor status
|
||||
*/
|
||||
for (i = 0; i < CHASSIS_THERMAL_COUNT; i++) {
|
||||
rc = onlp_thermali_info_get(ONLP_THERMAL_ID_CREATE(i+1), &ti[i]);
|
||||
|
||||
if (rc != ONLP_STATUS_OK) {
|
||||
onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_MAX);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Apply thermal policy according the policy list,
|
||||
* If fan duty is adjusted by one of the policies, skip the others
|
||||
*/
|
||||
for (i = 0; i < AIM_ARRAYSIZE(fan_control_policies); i++) {
|
||||
int adjusted = 0;
|
||||
|
||||
rc = fan_control_policies[i](fi, ti, &adjusted);
|
||||
if (!adjusted) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_sysi_platform_manage_leds(void)
|
||||
{
|
||||
return ONLP_STATUS_E_UNSUPPORTED;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,16 +34,16 @@
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
static char* devfiles__[] = /* must map with onlp_thermal_id */
|
||||
static char* ipmi_devfiles__[] = /* must map with onlp_thermal_id */
|
||||
{
|
||||
NULL,
|
||||
NULL, /* CPU_CORE files */
|
||||
"/sys/bus/i2c/devices/10-0048*temp1_input",
|
||||
"/sys/bus/i2c/devices/10-0049*temp1_input",
|
||||
"/sys/bus/i2c/devices/10-004a*temp1_input",
|
||||
"/sys/bus/i2c/devices/10-004b*temp1_input",
|
||||
"/sys/bus/i2c/devices/18-005b*psu_temp1_input",
|
||||
"/sys/bus/i2c/devices/17-0058*psu_temp1_input",
|
||||
"/sys/devices/platform/as5916_54xks_thermal/temp1_input",
|
||||
"/sys/devices/platform/as5916_54xks_thermal/temp2_input",
|
||||
"/sys/devices/platform/as5916_54xks_thermal/temp3_input",
|
||||
"/sys/devices/platform/as5916_54xks_thermal/temp4_input",
|
||||
"/sys/devices/platform/as5916_54xks_psu/psu1_temp1_input",
|
||||
"/sys/devices/platform/as5916_54xks_psu/psu2_temp1_input",
|
||||
};
|
||||
|
||||
static char* cpu_coretemp_files[] =
|
||||
@@ -62,19 +62,19 @@ static onlp_thermal_info_t linfo[] = {
|
||||
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_ID_CREATE(THERMAL_1_ON_MAIN_BROAD), "LM75-1", 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_ID_CREATE(THERMAL_2_ON_MAIN_BROAD), "LM75-2", 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_ID_CREATE(THERMAL_3_ON_MAIN_BROAD), "LM75-3", 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-3-4B", 0},
|
||||
{ { ONLP_THERMAL_ID_CREATE(THERMAL_4_ON_MAIN_BROAD), "LM75-4", 0},
|
||||
ONLP_THERMAL_STATUS_PRESENT,
|
||||
ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS
|
||||
},
|
||||
@@ -123,6 +123,7 @@ onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* info)
|
||||
return rv;
|
||||
}
|
||||
|
||||
return onlp_file_read_int(&info->mcelsius, devfiles__[tid]);
|
||||
return onlp_file_read_int(&info->mcelsius, ipmi_devfiles__[tid]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -2,71 +2,14 @@ from onl.platform.base import *
|
||||
from onl.platform.accton import *
|
||||
|
||||
class OnlPlatform_x86_64_accton_as5916_54xks_r0(OnlPlatformAccton,
|
||||
OnlPlatformPortConfig_48x10_6x40):
|
||||
OnlPlatformPortConfig_48x10_6x100):
|
||||
PLATFORM='x86-64-accton-as5916-54xks-r0'
|
||||
MODEL="AS5916-54XKS"
|
||||
SYS_OBJECT_ID=".5916.54"
|
||||
|
||||
def baseconfig(self):
|
||||
self.insmod('optoe')
|
||||
self.insmod("ym2651y")
|
||||
for m in [ "cpld", "psu", "fan", "leds" ]:
|
||||
self.insmod("x86-64-accton-as5916-54xks-%s" % m)
|
||||
|
||||
########### initialize I2C bus 0 ###########
|
||||
self.new_i2c_devices(
|
||||
[
|
||||
# initialize multiplexer (PCA9548)
|
||||
('pca9548', 0x77, 0),
|
||||
('pca9548', 0x76, 1),
|
||||
|
||||
# initiate chassis fan
|
||||
('as5916_54xks_fan', 0x66, 9),
|
||||
|
||||
# inititate LM75
|
||||
('lm75', 0x48, 10),
|
||||
('lm75', 0x49, 10),
|
||||
('lm75', 0x4a, 10),
|
||||
('lm75', 0x4b, 10),
|
||||
|
||||
# initialize CPLDs
|
||||
('as5916_54xks_cpld1', 0x60, 11),
|
||||
('as5916_54xks_cpld2', 0x62, 12),
|
||||
|
||||
# initialize multiplexer (PCA9548)
|
||||
('pca9548', 0x74, 2),
|
||||
|
||||
# initiate PSU-1 AC Power
|
||||
('as5916_54xks_psu1', 0x53, 18),
|
||||
('ym2651', 0x5b, 18),
|
||||
|
||||
# initiate PSU-2 AC Power
|
||||
('as5916_54xks_psu2', 0x50, 17),
|
||||
('ym2651', 0x58, 17),
|
||||
|
||||
# initialize multiplexer (PCA9548)
|
||||
('pca9548', 0x72, 2),
|
||||
('pca9548', 0x75, 25),
|
||||
('pca9548', 0x75, 26),
|
||||
('pca9548', 0x75, 27),
|
||||
('pca9548', 0x75, 28),
|
||||
('pca9548', 0x75, 29),
|
||||
('pca9548', 0x75, 30),
|
||||
('pca9548', 0x75, 31),
|
||||
|
||||
]
|
||||
)
|
||||
|
||||
# initialize SFP devices
|
||||
for port in range(1, 49):
|
||||
self.new_i2c_device('optoe2', 0x50, port+32)
|
||||
|
||||
# initialize QSFP devices
|
||||
for port in range(49, 55):
|
||||
self.new_i2c_device('optoe1', 0x50, port+32)
|
||||
|
||||
for port in range(1, 55):
|
||||
subprocess.call('echo port%d > /sys/bus/i2c/devices/%d-0050/port_name' % (port, port+32), shell=True)
|
||||
for m in [ 'fan', 'psu', 'leds', 'sfp', 'sys', 'thermal' ]:
|
||||
self.insmod("x86-64-accton-as5916-54xks-%s.ko" % m)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user