[platform][Broadcom]Accton, fix building error of kernel modules. (#2197)
* [platform]accton, fix building error of kernel modules at platform broadcom. Signed-off-by: roy_lee <roy_lee@accton.com> * Refine codes by formatter. Signed-off-by: roy_lee <roy_lee@accton.com>
This commit is contained in:
parent
251a850a50
commit
483bd9bbd8
264
platform/broadcom/sonic-platform-modules-accton/as7712-32x/modules/accton_as7712_32x_fan.c
Normal file → Executable file
264
platform/broadcom/sonic-platform-modules-accton/as7712-32x/modules/accton_as7712_32x_fan.c
Normal file → Executable file
@ -49,8 +49,7 @@ static ssize_t get_enable(struct device *dev, struct device_attribute *da, char
|
|||||||
static ssize_t set_enable(struct device *dev, struct device_attribute *da,
|
static ssize_t set_enable(struct device *dev, struct device_attribute *da,
|
||||||
const char *buf, size_t count);
|
const char *buf, size_t count);
|
||||||
static ssize_t get_sys_temp(struct device *dev, struct device_attribute *da, char *buf);
|
static ssize_t get_sys_temp(struct device *dev, struct device_attribute *da, char *buf);
|
||||||
extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg);
|
|
||||||
extern int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value);
|
|
||||||
|
|
||||||
/* fan related data, the index should match sysfs_fan_attributes
|
/* fan related data, the index should match sysfs_fan_attributes
|
||||||
*/
|
*/
|
||||||
@ -291,7 +290,6 @@ static ssize_t set_enable(struct device *dev, struct device_attribute *da,
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static ssize_t get_enable(struct device *dev, struct device_attribute *da,
|
static ssize_t get_enable(struct device *dev, struct device_attribute *da,
|
||||||
char *buf)
|
char *buf)
|
||||||
{
|
{
|
||||||
@ -299,6 +297,7 @@ static ssize_t get_enable(struct device *dev, struct device_attribute *da,
|
|||||||
|
|
||||||
return sprintf(buf, "%u\n", data->enable);
|
return sprintf(buf, "%u\n", data->enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da,
|
static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da,
|
||||||
const char *buf, size_t count)
|
const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
@ -319,185 +318,11 @@ static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da,
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Due to this struct is declared at lm75.c, it cannot be include
|
|
||||||
* under Sonic environment. I duplicate it from lm75.c.
|
|
||||||
*/
|
|
||||||
struct lm75_data {
|
|
||||||
struct i2c_client *client;
|
|
||||||
struct device *hwmon_dev;
|
|
||||||
struct thermal_zone_device *tz;
|
|
||||||
struct mutex update_lock;
|
|
||||||
u8 orig_conf;
|
|
||||||
u8 resolution; /* In bits, between 9 and 12 */
|
|
||||||
u8 resolution_limits;
|
|
||||||
char valid; /* !=0 if registers are valid */
|
|
||||||
unsigned long last_updated; /* In jiffies */
|
|
||||||
unsigned long sample_time; /* In jiffies */
|
|
||||||
s16 temp[3]; /* Register values,
|
|
||||||
0 = input
|
|
||||||
1 = max
|
|
||||||
2 = hyst */
|
|
||||||
};
|
|
||||||
|
|
||||||
/*Copied from lm75.c*/
|
|
||||||
static inline long lm75_reg_to_mc(s16 temp, u8 resolution)
|
|
||||||
{
|
|
||||||
return ((temp >> (16 - resolution)) * 1000) >> (resolution - 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*Get hwmon_dev from i2c_client, set hwmon_dev = NULL is failed.*/
|
|
||||||
static struct device * get_hwmon_dev(
|
|
||||||
struct i2c_client *client)
|
|
||||||
{
|
|
||||||
struct lm75_data *data = NULL;
|
|
||||||
|
|
||||||
data = i2c_get_clientdata(client);
|
|
||||||
if(data)
|
|
||||||
{
|
|
||||||
if( data->valid == 1 && data->hwmon_dev)
|
|
||||||
{
|
|
||||||
return data->hwmon_dev;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* To find hwmon index by opening hwmon under that i2c address.
|
|
||||||
*/
|
|
||||||
static int find_hwmon_index_by_FileOpen(
|
|
||||||
int bus_nr,
|
|
||||||
unsigned short addr,
|
|
||||||
OUT int *index)
|
|
||||||
{
|
|
||||||
#define MAX_HWMON_DEVICE (10) /* Find hwmon device in 0~10*/
|
|
||||||
struct file *sfd;
|
|
||||||
char client_name[96];
|
|
||||||
int i=0;
|
|
||||||
|
|
||||||
do {
|
|
||||||
snprintf(client_name, sizeof(client_name),
|
|
||||||
"/sys/bus/i2c/devices/%d-%04x/hwmon/hwmon%d/temp1_input",
|
|
||||||
bus_nr, addr, i);
|
|
||||||
|
|
||||||
sfd = filp_open(client_name, O_RDONLY, 0);
|
|
||||||
i++;
|
|
||||||
} while( IS_ERR(sfd) && i < MAX_HWMON_DEVICE);
|
|
||||||
|
|
||||||
if (IS_ERR(sfd)) {
|
|
||||||
pr_err("Failed to open file(%s)#%d\r\n", client_name, __LINE__);
|
|
||||||
return -ENOENT;
|
|
||||||
}
|
|
||||||
filp_close(sfd, 0);
|
|
||||||
*index = i - 1;
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
#undef MAX_HWMON_DEVICE
|
|
||||||
}
|
|
||||||
|
|
||||||
static int get_temp_file_path(
|
|
||||||
int bus_nr, unsigned short addr,
|
|
||||||
struct device *hwmon_dev
|
|
||||||
,char *path, int max_len)
|
|
||||||
{
|
|
||||||
|
|
||||||
if(hwmon_dev && strlen(dev_name(hwmon_dev)))
|
|
||||||
{
|
|
||||||
snprintf(path, max_len,
|
|
||||||
"/sys/bus/i2c/devices/%d-%04x/hwmon/%s/temp1_input",
|
|
||||||
bus_nr, addr, dev_name(hwmon_dev));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int i=0;
|
|
||||||
if(find_hwmon_index_by_FileOpen( bus_nr, addr, &i))
|
|
||||||
{
|
|
||||||
return -EIO;
|
|
||||||
}
|
|
||||||
snprintf(path, max_len,
|
|
||||||
"/sys/bus/i2c/devices/%d-%04x/hwmon/hwmon%d/temp1_input",
|
|
||||||
bus_nr, addr, i);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*File read the dev file at user space.*/
|
|
||||||
static int read_devfile_temp1_input(
|
|
||||||
struct device *dev,
|
|
||||||
int bus_nr,
|
|
||||||
unsigned short addr,
|
|
||||||
struct device *hwmon_dev,
|
|
||||||
int *miniCelsius)
|
|
||||||
{
|
|
||||||
struct file *sfd;
|
|
||||||
char buffer[96];
|
|
||||||
char devfile[96];
|
|
||||||
int rc, status;
|
|
||||||
int rdlen, value;
|
|
||||||
mm_segment_t old_fs;
|
|
||||||
|
|
||||||
rc = 0;
|
|
||||||
get_temp_file_path(bus_nr, addr, hwmon_dev, devfile, sizeof(devfile));
|
|
||||||
sfd = filp_open(devfile, O_RDONLY, 0);
|
|
||||||
if (IS_ERR(sfd)) {
|
|
||||||
pr_err("Failed to open file(%s)#%d\r\n", devfile, __LINE__);
|
|
||||||
return -ENOENT;
|
|
||||||
}
|
|
||||||
dev_dbg(dev, "Found device:%s\n",devfile);
|
|
||||||
|
|
||||||
if(!(sfd->f_op) || !(sfd->f_op->read) ) {
|
|
||||||
pr_err("file %s cann't readable ?\n",devfile);
|
|
||||||
return -ENOENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
old_fs = get_fs();
|
|
||||||
set_fs(KERNEL_DS);
|
|
||||||
rdlen = sfd->f_op->read(sfd, buffer, sizeof(buffer), &sfd->f_pos);
|
|
||||||
if (rdlen == 0) {
|
|
||||||
pr_err( "File(%s) empty!\n", devfile);
|
|
||||||
rc = -EIO;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
status = sscanf(buffer, "%d", &value);
|
|
||||||
if (status != 1) {
|
|
||||||
rc = -EIO;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
*miniCelsius = value;
|
|
||||||
dev_dbg(dev,"found sensors: %d @i2c %d-%04x\n", value, bus_nr, addr);
|
|
||||||
|
|
||||||
exit:
|
|
||||||
set_fs(old_fs);
|
|
||||||
filp_close(sfd, 0);
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
static u8 is_lm75_data_due(struct i2c_client *client)
|
|
||||||
{
|
|
||||||
struct lm75_data *data = NULL;
|
|
||||||
|
|
||||||
data = i2c_get_clientdata(client);
|
|
||||||
if (time_after(jiffies, data->last_updated + data->sample_time))
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
static int get_lm75_temp(struct i2c_client *client, int *miniCelsius)
|
|
||||||
{
|
|
||||||
struct lm75_data *data = NULL;
|
|
||||||
|
|
||||||
data = i2c_get_clientdata(client);
|
|
||||||
*miniCelsius = lm75_reg_to_mc(data->temp[0], data->resolution);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool lm75_addr_mached(unsigned short addr)
|
static bool lm75_addr_mached(unsigned short addr)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
unsigned short addrs[] = THERMAL_SENSORS_ADDRS;
|
unsigned short addrs[] = THERMAL_SENSORS_ADDRS;
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(addrs); i++)
|
for (i = 0; i < ARRAY_SIZE(addrs); i++)
|
||||||
{
|
{
|
||||||
if( addr == addrs[i])
|
if( addr == addrs[i])
|
||||||
@ -506,51 +331,84 @@ static bool lm75_addr_mached(unsigned short addr)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Struct and define are copied from drivers/hwmon/hwmon.c. */
|
||||||
|
struct hwmon_device {
|
||||||
|
const char *name;
|
||||||
|
struct device dev;
|
||||||
|
const struct hwmon_chip_info *chip;
|
||||||
|
|
||||||
|
struct attribute_group group;
|
||||||
|
const struct attribute_group **groups;
|
||||||
|
};
|
||||||
|
#define to_hwmon_device(d) container_of(d, struct hwmon_device, dev)
|
||||||
|
|
||||||
|
/*Find the 1st valid dev of all childs, it supposes to have only 1 child.*/
|
||||||
|
static int is_valid_dev(struct device *dev, void *data)
|
||||||
|
{
|
||||||
|
struct hwmon_device *hwmon_dev;
|
||||||
|
|
||||||
|
if(dev) {
|
||||||
|
hwmon_dev = to_hwmon_device(dev);
|
||||||
|
if(hwmon_dev) {
|
||||||
|
int ret;
|
||||||
|
long t;
|
||||||
|
ret = hwmon_dev->chip->ops->read(dev, hwmon_temp, hwmon_temp_input,
|
||||||
|
0, &t);
|
||||||
|
return !ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int hwmon_get_temp(struct device *dev, long *mini_cel)
|
||||||
|
{
|
||||||
|
struct hwmon_device *hwmon_dev = to_hwmon_device(dev);
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
if(hwmon_dev) {
|
||||||
|
long t;
|
||||||
|
ret = hwmon_dev->chip->ops->read(dev, hwmon_temp, hwmon_temp_input,
|
||||||
|
0, &t);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
*mini_cel = t;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Find devices under i2c_bus which with driver = lm75.
|
||||||
|
* Use the device to find its descendent hwmon_dev and read the temperature.
|
||||||
|
*/
|
||||||
static int _find_lm75_device(struct device *dev, void *data)
|
static int _find_lm75_device(struct device *dev, void *data)
|
||||||
{
|
{
|
||||||
struct device_driver *driver;
|
struct device_driver *driver;
|
||||||
struct as7712_32x_fan_data *prv = data;
|
struct as7712_32x_fan_data *prv = data;
|
||||||
char *driver_name = THERMAL_SENSORS_DRIVER;
|
char *driver_name = THERMAL_SENSORS_DRIVER;
|
||||||
|
struct i2c_client *client;
|
||||||
|
|
||||||
driver = dev->driver;
|
driver = dev->driver;
|
||||||
if (driver && driver->name &&
|
if (driver && driver->name &&
|
||||||
strcmp(driver->name, driver_name) == 0)
|
strcmp(driver->name, driver_name) == 0)
|
||||||
{
|
{
|
||||||
struct i2c_client *client;
|
|
||||||
client = to_i2c_client(dev);
|
client = to_i2c_client(dev);
|
||||||
if (client)
|
if (client)
|
||||||
{
|
{
|
||||||
/*cannot use "struct i2c_adapter *adap = to_i2c_adapter(dev);"*/
|
long miniCelsius = 0;
|
||||||
struct i2c_adapter *adap = client->adapter;
|
struct device *child_dev;
|
||||||
int miniCelsius = 0;
|
|
||||||
|
|
||||||
if (! lm75_addr_mached(client->addr))
|
if (! lm75_addr_mached(client->addr))
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!adap) {
|
child_dev = device_find_child(dev, NULL, is_valid_dev);
|
||||||
return -ENXIO;
|
if(child_dev) {
|
||||||
}
|
int ret = hwmon_get_temp(child_dev, &miniCelsius);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
/* If the data is not updated, read them from devfile
|
|
||||||
to drive them updateing data from chip.*/
|
|
||||||
if (is_lm75_data_due(client))
|
|
||||||
{
|
|
||||||
struct device *hwmon_dev;
|
|
||||||
|
|
||||||
hwmon_dev = get_hwmon_dev(client);
|
|
||||||
if(0 == read_devfile_temp1_input(dev, adap->nr,
|
|
||||||
client->addr, hwmon_dev, &miniCelsius))
|
|
||||||
{
|
|
||||||
prv->system_temp += miniCelsius;
|
|
||||||
prv->sensors_found++;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
get_lm75_temp(client, &miniCelsius);
|
|
||||||
prv->system_temp += miniCelsius;
|
prv->system_temp += miniCelsius;
|
||||||
prv->sensors_found++;
|
prv->sensors_found++;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
ifneq ($(KERNELRELEASE),)
|
ifneq ($(KERNELRELEASE),)
|
||||||
obj-m:= accton_as7716_32x_cpld1.o accton_as7716_32x_fan.o \
|
obj-m:= accton_as7716_32x_cpld1.o accton_as7716_32x_fan.o \
|
||||||
accton_as7716_32x_leds.o accton_as7716_32x_psu.o cpr_4011_4mxx.o ym2651y.o \
|
accton_as7716_32x_leds.o accton_as7716_32x_psu.o cpr_4011_4mxx.o ym2651y.o \
|
||||||
optoe.o accton_i2c_cpld.o
|
accton_i2c_cpld.o
|
||||||
|
|
||||||
else
|
else
|
||||||
ifeq (,$(KERNEL_SRC))
|
ifeq (,$(KERNEL_SRC))
|
||||||
|
409
platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/accton_as7716_32x_fan.c
Executable file → Normal file
409
platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/accton_as7716_32x_fan.c
Executable file → Normal file
@ -34,22 +34,16 @@
|
|||||||
|
|
||||||
#define DRVNAME "as7716_32x_fan"
|
#define DRVNAME "as7716_32x_fan"
|
||||||
|
|
||||||
#define NUM_THERMAL_SENSORS (3) /* Get sum of this number of sensors.*/
|
|
||||||
#define THERMAL_SENSORS_DRIVER "lm75"
|
|
||||||
|
|
||||||
#define IN
|
#define IN
|
||||||
#define OUT
|
#define OUT
|
||||||
|
|
||||||
static struct as7716_32x_fan_data *as7716_32x_fan_update_device(struct device *dev);
|
static struct as7716_32x_fan_data *as7716_32x_fan_update_device(struct device *dev);
|
||||||
static ssize_t fan_show_value(struct device *dev, struct device_attribute *da, char *buf);
|
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,
|
static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da,
|
||||||
const char *buf, size_t count);
|
const char *buf, size_t count);
|
||||||
static ssize_t get_enable(struct device *dev, struct device_attribute *da, char *buf);
|
static ssize_t get_enable(struct device *dev, struct device_attribute *da, char *buf);
|
||||||
static ssize_t set_enable(struct device *dev, struct device_attribute *da,
|
static ssize_t set_enable(struct device *dev, struct device_attribute *da,
|
||||||
const char *buf, size_t count);
|
const char *buf, size_t count);
|
||||||
static ssize_t get_sys_temp(struct device *dev, struct device_attribute *da, char *buf);
|
|
||||||
extern int as7716_32x_cpld_read(unsigned short cpld_addr, u8 reg);
|
|
||||||
extern int as7716_32x_cpld_write(unsigned short cpld_addr, u8 reg, u8 value);
|
|
||||||
|
|
||||||
/* fan related data, the index should match sysfs_fan_attributes
|
/* fan related data, the index should match sysfs_fan_attributes
|
||||||
*/
|
*/
|
||||||
@ -79,8 +73,6 @@ struct as7716_32x_fan_data {
|
|||||||
unsigned long last_updated; /* In jiffies */
|
unsigned long last_updated; /* In jiffies */
|
||||||
u8 reg_val[ARRAY_SIZE(fan_reg)]; /* Register value */
|
u8 reg_val[ARRAY_SIZE(fan_reg)]; /* Register value */
|
||||||
u8 enable;
|
u8 enable;
|
||||||
int system_temp; /*In unit of mini-Celsius*/
|
|
||||||
int sensors_found;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum fan_id {
|
enum fan_id {
|
||||||
@ -149,12 +141,6 @@ enum sysfs_fan_attributes {
|
|||||||
&sensor_dev_attr_pwm##index.dev_attr.attr, \
|
&sensor_dev_attr_pwm##index.dev_attr.attr, \
|
||||||
&sensor_dev_attr_pwm##index##_enable.dev_attr.attr
|
&sensor_dev_attr_pwm##index##_enable.dev_attr.attr
|
||||||
|
|
||||||
#define DECLARE_FAN_SYSTEM_TEMP_SENSOR_DEV_ATTR() \
|
|
||||||
static SENSOR_DEVICE_ATTR(sys_temp, S_IRUGO, get_sys_temp, NULL, FAN_DUTY_CYCLE_PERCENTAGE)
|
|
||||||
|
|
||||||
#define DECLARE_FAN_SYSTEM_TEMP_ATTR() &sensor_dev_attr_sys_temp.dev_attr.attr
|
|
||||||
|
|
||||||
|
|
||||||
#define DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(index) \
|
#define DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(index) \
|
||||||
static SENSOR_DEVICE_ATTR(fan##index##_present, S_IRUGO, fan_show_value, NULL, FAN##index##_PRESENT)
|
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_PRESENT_ATTR(index) &sensor_dev_attr_fan##index##_present.dev_attr.attr
|
||||||
@ -200,8 +186,6 @@ DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(6);
|
|||||||
|
|
||||||
/* 1 fan duty cycle attribute in this platform */
|
/* 1 fan duty cycle attribute in this platform */
|
||||||
DECLARE_FAN_DUTY_CYCLE_SENSOR_DEV_ATTR(1);
|
DECLARE_FAN_DUTY_CYCLE_SENSOR_DEV_ATTR(1);
|
||||||
/* System temperature for fancontrol */
|
|
||||||
DECLARE_FAN_SYSTEM_TEMP_SENSOR_DEV_ATTR();
|
|
||||||
|
|
||||||
static struct attribute *as7716_32x_fan_attributes[] = {
|
static struct attribute *as7716_32x_fan_attributes[] = {
|
||||||
/* fan related attributes */
|
/* fan related attributes */
|
||||||
@ -230,7 +214,6 @@ static struct attribute *as7716_32x_fan_attributes[] = {
|
|||||||
DECLARE_FAN_DIRECTION_ATTR(5),
|
DECLARE_FAN_DIRECTION_ATTR(5),
|
||||||
DECLARE_FAN_DIRECTION_ATTR(6),
|
DECLARE_FAN_DIRECTION_ATTR(6),
|
||||||
DECLARE_FAN_DUTY_CYCLE_ATTR(1),
|
DECLARE_FAN_DUTY_CYCLE_ATTR(1),
|
||||||
DECLARE_FAN_SYSTEM_TEMP_ATTR(),
|
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -250,13 +233,13 @@ static int as7716_32x_fan_write_value(struct i2c_client *client, u8 reg, u8 valu
|
|||||||
|
|
||||||
/* fan utility functions
|
/* fan utility functions
|
||||||
*/
|
*/
|
||||||
static u32 reg_val_to_duty_cycle(u8 reg_val)
|
static u32 reg_val_to_duty_cycle(u8 reg_val)
|
||||||
{
|
{
|
||||||
reg_val &= FAN_DUTY_CYCLE_REG_MASK;
|
reg_val &= FAN_DUTY_CYCLE_REG_MASK;
|
||||||
return ((u32)(reg_val+1) * 625 + 75)/ 100;
|
return ((u32)(reg_val+1) * 625 + 75)/ 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
static u8 duty_cycle_to_reg_val(u8 duty_cycle)
|
static u8 duty_cycle_to_reg_val(u8 duty_cycle)
|
||||||
{
|
{
|
||||||
return ((u32)duty_cycle * 100 / 625) - 1;
|
return ((u32)duty_cycle * 100 / 625) - 1;
|
||||||
}
|
}
|
||||||
@ -289,10 +272,10 @@ static u8 is_fan_fault(struct as7716_32x_fan_data *data, enum fan_id id)
|
|||||||
int front_fan_index = FAN1_FRONT_SPEED_RPM + id;
|
int front_fan_index = FAN1_FRONT_SPEED_RPM + id;
|
||||||
int rear_fan_index = FAN1_REAR_SPEED_RPM + id;
|
int rear_fan_index = FAN1_REAR_SPEED_RPM + id;
|
||||||
|
|
||||||
/* Check if the speed of front or rear fan is ZERO,
|
/* Check if the speed of front or rear fan is ZERO,
|
||||||
*/
|
*/
|
||||||
if (reg_val_to_speed_rpm(data->reg_val[front_fan_index]) &&
|
if (reg_val_to_speed_rpm(data->reg_val[front_fan_index]) &&
|
||||||
reg_val_to_speed_rpm(data->reg_val[rear_fan_index])) {
|
reg_val_to_speed_rpm(data->reg_val[rear_fan_index])) {
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -328,329 +311,87 @@ static ssize_t get_enable(struct device *dev, struct device_attribute *da,
|
|||||||
|
|
||||||
return sprintf(buf, "%u\n", data->enable);
|
return sprintf(buf, "%u\n", data->enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da,
|
static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da,
|
||||||
const char *buf, size_t count)
|
const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
int error, value;
|
int error, value;
|
||||||
struct i2c_client *client = to_i2c_client(dev);
|
struct i2c_client *client = to_i2c_client(dev);
|
||||||
|
|
||||||
error = kstrtoint(buf, 10, &value);
|
error = kstrtoint(buf, 10, &value);
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
if (value < 0 || value > FAN_MAX_DUTY_CYCLE)
|
if (value < 0 || value > FAN_MAX_DUTY_CYCLE)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
as7716_32x_fan_write_value(client, 0x33, 0); /* Disable fan speed watch dog */
|
as7716_32x_fan_write_value(client, 0x33, 0); /* Disable fan speed watch dog */
|
||||||
as7716_32x_fan_write_value(client, fan_reg[FAN_DUTY_CYCLE_PERCENTAGE], duty_cycle_to_reg_val(value));
|
as7716_32x_fan_write_value(client, fan_reg[FAN_DUTY_CYCLE_PERCENTAGE], duty_cycle_to_reg_val(value));
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Due to this struct is declared at lm75.c, it cannot be include
|
|
||||||
* under Sonic environment. I duplicate it from lm75.c.
|
|
||||||
*/
|
|
||||||
struct lm75_data {
|
|
||||||
struct i2c_client *client;
|
|
||||||
struct device *hwmon_dev;
|
|
||||||
struct thermal_zone_device *tz;
|
|
||||||
struct mutex update_lock;
|
|
||||||
u8 orig_conf;
|
|
||||||
u8 resolution; /* In bits, between 9 and 12 */
|
|
||||||
u8 resolution_limits;
|
|
||||||
char valid; /* !=0 if registers are valid */
|
|
||||||
unsigned long last_updated; /* In jiffies */
|
|
||||||
unsigned long sample_time; /* In jiffies */
|
|
||||||
s16 temp[3]; /* Register values,
|
|
||||||
0 = input
|
|
||||||
1 = max
|
|
||||||
2 = hyst */
|
|
||||||
};
|
|
||||||
|
|
||||||
/*Copied from lm75.c*/
|
|
||||||
static inline long lm75_reg_to_mc(s16 temp, u8 resolution)
|
|
||||||
{
|
|
||||||
return ((temp >> (16 - resolution)) * 1000) >> (resolution - 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*Get hwmon_dev from i2c_client, set hwmon_dev = NULL is failed.*/
|
|
||||||
static struct device * get_hwmon_dev(
|
|
||||||
struct i2c_client *client)
|
|
||||||
{
|
|
||||||
struct lm75_data *data = NULL;
|
|
||||||
|
|
||||||
data = i2c_get_clientdata(client);
|
|
||||||
if(data)
|
|
||||||
{
|
|
||||||
if( data->valid == 1 && data->hwmon_dev)
|
|
||||||
{
|
|
||||||
return data->hwmon_dev;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* To find hwmon index by opening hwmon under that i2c address.
|
|
||||||
*/
|
|
||||||
static int find_hwmon_index_by_FileOpen(
|
|
||||||
int bus_nr,
|
|
||||||
unsigned short addr,
|
|
||||||
OUT int *index)
|
|
||||||
{
|
|
||||||
#define MAX_HWMON_DEVICE (10) /* Find hwmon device in 0~10*/
|
|
||||||
struct file *sfd;
|
|
||||||
char client_name[96];
|
|
||||||
int i=0;
|
|
||||||
|
|
||||||
do {
|
|
||||||
snprintf(client_name, sizeof(client_name),
|
|
||||||
"/sys/bus/i2c/devices/%d-%04x/hwmon/hwmon%d/temp1_input",
|
|
||||||
bus_nr, addr, i);
|
|
||||||
|
|
||||||
sfd = filp_open(client_name, O_RDONLY, 0);
|
|
||||||
i++;
|
|
||||||
} while( IS_ERR(sfd) && i < MAX_HWMON_DEVICE);
|
|
||||||
|
|
||||||
if (IS_ERR(sfd)) {
|
|
||||||
pr_err("Failed to open file(%s)#%d\r\n", client_name, __LINE__);
|
|
||||||
return -ENOENT;
|
|
||||||
}
|
|
||||||
filp_close(sfd, 0);
|
|
||||||
*index = i - 1;
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
#undef MAX_HWMON_DEVICE
|
|
||||||
}
|
|
||||||
|
|
||||||
static int get_temp_file_path(
|
|
||||||
int bus_nr, unsigned short addr,
|
|
||||||
struct device *hwmon_dev
|
|
||||||
,char *path, int max_len)
|
|
||||||
{
|
|
||||||
|
|
||||||
if(hwmon_dev && strlen(dev_name(hwmon_dev)))
|
|
||||||
{
|
|
||||||
snprintf(path, max_len,
|
|
||||||
"/sys/bus/i2c/devices/%d-%04x/hwmon/%s/temp1_input",
|
|
||||||
bus_nr, addr, dev_name(hwmon_dev));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int i=0;
|
|
||||||
if(find_hwmon_index_by_FileOpen( bus_nr, addr, &i))
|
|
||||||
{
|
|
||||||
return -EIO;
|
|
||||||
}
|
|
||||||
snprintf(path, max_len,
|
|
||||||
"/sys/bus/i2c/devices/%d-%04x/hwmon/hwmon%d/temp1_input",
|
|
||||||
bus_nr, addr, i);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*File read the dev file at user space.*/
|
|
||||||
static int read_devfile_temp1_input(
|
|
||||||
struct device *dev,
|
|
||||||
int bus_nr,
|
|
||||||
unsigned short addr,
|
|
||||||
struct device *hwmon_dev,
|
|
||||||
int *miniCelsius)
|
|
||||||
{
|
|
||||||
struct file *sfd;
|
|
||||||
char buffer[96];
|
|
||||||
char devfile[96];
|
|
||||||
int rc, status;
|
|
||||||
int rdlen, value;
|
|
||||||
mm_segment_t old_fs;
|
|
||||||
|
|
||||||
rc = 0;
|
|
||||||
get_temp_file_path(bus_nr, addr, hwmon_dev, devfile, sizeof(devfile));
|
|
||||||
sfd = filp_open(devfile, O_RDONLY, 0);
|
|
||||||
if (IS_ERR(sfd)) {
|
|
||||||
pr_err("Failed to open file(%s)#%d\r\n", devfile, __LINE__);
|
|
||||||
return -ENOENT;
|
|
||||||
}
|
|
||||||
dev_dbg(dev, "Found device:%s\n",devfile);
|
|
||||||
|
|
||||||
if(!(sfd->f_op) || !(sfd->f_op->read) ) {
|
|
||||||
pr_err("file %s cann't readable ?\n",devfile);
|
|
||||||
return -ENOENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
old_fs = get_fs();
|
|
||||||
set_fs(KERNEL_DS);
|
|
||||||
rdlen = sfd->f_op->read(sfd, buffer, sizeof(buffer), &sfd->f_pos);
|
|
||||||
if (rdlen == 0) {
|
|
||||||
pr_err( "File(%s) empty!\n", devfile);
|
|
||||||
rc = -EIO;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
status = sscanf(buffer, "%d", &value);
|
|
||||||
if (status != 1) {
|
|
||||||
rc = -EIO;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
*miniCelsius = value;
|
|
||||||
dev_dbg(dev,"found sensors: %d @i2c %d-%04x\n", value, bus_nr, addr);
|
|
||||||
|
|
||||||
exit:
|
|
||||||
set_fs(old_fs);
|
|
||||||
filp_close(sfd, 0);
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
static u8 is_lm75_data_due(struct i2c_client *client)
|
|
||||||
{
|
|
||||||
struct lm75_data *data = NULL;
|
|
||||||
|
|
||||||
data = i2c_get_clientdata(client);
|
|
||||||
if (time_after(jiffies, data->last_updated + data->sample_time))
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
static int get_lm75_temp(struct i2c_client *client, int *miniCelsius)
|
|
||||||
{
|
|
||||||
struct lm75_data *data = NULL;
|
|
||||||
|
|
||||||
data = i2c_get_clientdata(client);
|
|
||||||
*miniCelsius = lm75_reg_to_mc(data->temp[0], data->resolution);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int _find_lm75_device(struct device *dev, void *data)
|
|
||||||
{
|
|
||||||
struct device_driver *driver;
|
|
||||||
struct as7716_32x_fan_data *prv = data;
|
|
||||||
char *driver_name = THERMAL_SENSORS_DRIVER;
|
|
||||||
|
|
||||||
driver = dev->driver;
|
|
||||||
if (driver && driver->name &&
|
|
||||||
strcmp(driver->name, driver_name) == 0)
|
|
||||||
{
|
|
||||||
struct i2c_client *client;
|
|
||||||
client = to_i2c_client(dev);
|
|
||||||
if (client)
|
|
||||||
{
|
|
||||||
/*cannot use "struct i2c_adapter *adap = to_i2c_adapter(dev);"*/
|
|
||||||
struct i2c_adapter *adap = client->adapter;
|
|
||||||
int miniCelsius = 0;
|
|
||||||
|
|
||||||
|
|
||||||
if (!adap) {
|
|
||||||
return -ENXIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If the data is not updated, read them from devfile
|
|
||||||
to drive them updateing data from chip.*/
|
|
||||||
if (is_lm75_data_due(client))
|
|
||||||
{
|
|
||||||
struct device *hwmon_dev;
|
|
||||||
|
|
||||||
hwmon_dev = get_hwmon_dev(client);
|
|
||||||
if(0 == read_devfile_temp1_input(dev, adap->nr,
|
|
||||||
client->addr, hwmon_dev, &miniCelsius))
|
|
||||||
{
|
|
||||||
prv->system_temp += miniCelsius;
|
|
||||||
prv->sensors_found++;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
get_lm75_temp(client, &miniCelsius);
|
|
||||||
prv->system_temp += miniCelsius;
|
|
||||||
prv->sensors_found++;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*Find all lm75 devices and return sum of temperatures.*/
|
|
||||||
static ssize_t get_sys_temp(struct device *dev, struct device_attribute *da,
|
|
||||||
char *buf)
|
|
||||||
{
|
|
||||||
ssize_t ret = 0;
|
|
||||||
struct as7716_32x_fan_data *data = as7716_32x_fan_update_device(dev);
|
|
||||||
|
|
||||||
data->system_temp=0;
|
|
||||||
data->sensors_found=0;
|
|
||||||
i2c_for_each_dev(data, _find_lm75_device);
|
|
||||||
if (NUM_THERMAL_SENSORS != data->sensors_found)
|
|
||||||
{
|
|
||||||
dev_dbg(dev,"only %d of %d temps are found\n",
|
|
||||||
data->sensors_found, NUM_THERMAL_SENSORS);
|
|
||||||
data->system_temp = 0;
|
|
||||||
}
|
|
||||||
ret = sprintf(buf, "%d\n",data->system_temp);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
static ssize_t fan_show_value(struct device *dev, struct device_attribute *da,
|
static ssize_t fan_show_value(struct device *dev, struct device_attribute *da,
|
||||||
char *buf)
|
char *buf)
|
||||||
{
|
{
|
||||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||||
struct as7716_32x_fan_data *data = as7716_32x_fan_update_device(dev);
|
struct as7716_32x_fan_data *data = as7716_32x_fan_update_device(dev);
|
||||||
ssize_t ret = 0;
|
ssize_t ret = 0;
|
||||||
|
|
||||||
if (data->valid) {
|
if (data->valid) {
|
||||||
switch (attr->index) {
|
switch (attr->index) {
|
||||||
case FAN_DUTY_CYCLE_PERCENTAGE:
|
case FAN_DUTY_CYCLE_PERCENTAGE:
|
||||||
{
|
{
|
||||||
u32 duty_cycle = reg_val_to_duty_cycle(data->reg_val[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);
|
ret = sprintf(buf, "%u\n", duty_cycle);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FAN1_FRONT_SPEED_RPM:
|
case FAN1_FRONT_SPEED_RPM:
|
||||||
case FAN2_FRONT_SPEED_RPM:
|
case FAN2_FRONT_SPEED_RPM:
|
||||||
case FAN3_FRONT_SPEED_RPM:
|
case FAN3_FRONT_SPEED_RPM:
|
||||||
case FAN4_FRONT_SPEED_RPM:
|
case FAN4_FRONT_SPEED_RPM:
|
||||||
case FAN5_FRONT_SPEED_RPM:
|
case FAN5_FRONT_SPEED_RPM:
|
||||||
case FAN6_FRONT_SPEED_RPM:
|
case FAN6_FRONT_SPEED_RPM:
|
||||||
case FAN1_REAR_SPEED_RPM:
|
case FAN1_REAR_SPEED_RPM:
|
||||||
case FAN2_REAR_SPEED_RPM:
|
case FAN2_REAR_SPEED_RPM:
|
||||||
case FAN3_REAR_SPEED_RPM:
|
case FAN3_REAR_SPEED_RPM:
|
||||||
case FAN4_REAR_SPEED_RPM:
|
case FAN4_REAR_SPEED_RPM:
|
||||||
case FAN5_REAR_SPEED_RPM:
|
case FAN5_REAR_SPEED_RPM:
|
||||||
case FAN6_REAR_SPEED_RPM:
|
case FAN6_REAR_SPEED_RPM:
|
||||||
ret = sprintf(buf, "%u\n", reg_val_to_speed_rpm(data->reg_val[attr->index]));
|
ret = sprintf(buf, "%u\n", reg_val_to_speed_rpm(data->reg_val[attr->index]));
|
||||||
break;
|
break;
|
||||||
case FAN1_PRESENT:
|
case FAN1_PRESENT:
|
||||||
case FAN2_PRESENT:
|
case FAN2_PRESENT:
|
||||||
case FAN3_PRESENT:
|
case FAN3_PRESENT:
|
||||||
case FAN4_PRESENT:
|
case FAN4_PRESENT:
|
||||||
case FAN5_PRESENT:
|
case FAN5_PRESENT:
|
||||||
case FAN6_PRESENT:
|
case FAN6_PRESENT:
|
||||||
ret = sprintf(buf, "%d\n",
|
ret = sprintf(buf, "%d\n",
|
||||||
reg_val_to_is_present(data->reg_val[FAN_PRESENT_REG],
|
reg_val_to_is_present(data->reg_val[FAN_PRESENT_REG],
|
||||||
attr->index - FAN1_PRESENT));
|
attr->index - FAN1_PRESENT));
|
||||||
break;
|
break;
|
||||||
case FAN1_FAULT:
|
case FAN1_FAULT:
|
||||||
case FAN2_FAULT:
|
case FAN2_FAULT:
|
||||||
case FAN3_FAULT:
|
case FAN3_FAULT:
|
||||||
case FAN4_FAULT:
|
case FAN4_FAULT:
|
||||||
case FAN5_FAULT:
|
case FAN5_FAULT:
|
||||||
case FAN6_FAULT:
|
case FAN6_FAULT:
|
||||||
ret = sprintf(buf, "%d\n", is_fan_fault(data, attr->index - FAN1_FAULT));
|
ret = sprintf(buf, "%d\n", is_fan_fault(data, attr->index - FAN1_FAULT));
|
||||||
break;
|
break;
|
||||||
case FAN1_DIRECTION:
|
case FAN1_DIRECTION:
|
||||||
case FAN2_DIRECTION:
|
case FAN2_DIRECTION:
|
||||||
case FAN3_DIRECTION:
|
case FAN3_DIRECTION:
|
||||||
case FAN4_DIRECTION:
|
case FAN4_DIRECTION:
|
||||||
case FAN5_DIRECTION:
|
case FAN5_DIRECTION:
|
||||||
case FAN6_DIRECTION:
|
case FAN6_DIRECTION:
|
||||||
ret = sprintf(buf, "%d\n",
|
ret = sprintf(buf, "%d\n",
|
||||||
reg_val_to_direction(data->reg_val[FAN_DIRECTION_REG],
|
reg_val_to_direction(data->reg_val[FAN_DIRECTION_REG],
|
||||||
attr->index - FAN1_DIRECTION));
|
attr->index - FAN1_DIRECTION));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -665,18 +406,18 @@ static struct as7716_32x_fan_data *as7716_32x_fan_update_device(struct device *d
|
|||||||
|
|
||||||
mutex_lock(&data->update_lock);
|
mutex_lock(&data->update_lock);
|
||||||
|
|
||||||
if (time_after(jiffies, data->last_updated + HZ + HZ / 2) ||
|
if (time_after(jiffies, data->last_updated + HZ + HZ / 2) ||
|
||||||
!data->valid) {
|
!data->valid) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
dev_dbg(&client->dev, "Starting as7716_32x_fan update\n");
|
dev_dbg(&client->dev, "Starting as7716_32x_fan update\n");
|
||||||
data->valid = 0;
|
data->valid = 0;
|
||||||
|
|
||||||
/* Update fan data
|
/* Update fan data
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < ARRAY_SIZE(data->reg_val); i++) {
|
for (i = 0; i < ARRAY_SIZE(data->reg_val); i++) {
|
||||||
int status = as7716_32x_fan_read_value(client, fan_reg[i]);
|
int status = as7716_32x_fan_read_value(client, fan_reg[i]);
|
||||||
|
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
data->valid = 0;
|
data->valid = 0;
|
||||||
mutex_unlock(&data->update_lock);
|
mutex_unlock(&data->update_lock);
|
||||||
@ -687,18 +428,18 @@ static struct as7716_32x_fan_data *as7716_32x_fan_update_device(struct device *d
|
|||||||
data->reg_val[i] = status;
|
data->reg_val[i] = status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data->last_updated = jiffies;
|
data->last_updated = jiffies;
|
||||||
data->valid = 1;
|
data->valid = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
mutex_unlock(&data->update_lock);
|
mutex_unlock(&data->update_lock);
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int as7716_32x_fan_probe(struct i2c_client *client,
|
static int as7716_32x_fan_probe(struct i2c_client *client,
|
||||||
const struct i2c_device_id *dev_id)
|
const struct i2c_device_id *dev_id)
|
||||||
{
|
{
|
||||||
struct as7716_32x_fan_data *data;
|
struct as7716_32x_fan_data *data;
|
||||||
int status;
|
int status;
|
||||||
@ -733,8 +474,8 @@ static int as7716_32x_fan_probe(struct i2c_client *client,
|
|||||||
}
|
}
|
||||||
|
|
||||||
dev_info(&client->dev, "%s: fan '%s'\n",
|
dev_info(&client->dev, "%s: fan '%s'\n",
|
||||||
dev_name(data->hwmon_dev), client->name);
|
dev_name(data->hwmon_dev), client->name);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
exit_remove:
|
exit_remove:
|
||||||
@ -742,7 +483,7 @@ exit_remove:
|
|||||||
exit_free:
|
exit_free:
|
||||||
kfree(data);
|
kfree(data);
|
||||||
exit:
|
exit:
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -751,7 +492,7 @@ static int as7716_32x_fan_remove(struct i2c_client *client)
|
|||||||
struct as7716_32x_fan_data *data = i2c_get_clientdata(client);
|
struct as7716_32x_fan_data *data = i2c_get_clientdata(client);
|
||||||
hwmon_device_unregister(data->hwmon_dev);
|
hwmon_device_unregister(data->hwmon_dev);
|
||||||
sysfs_remove_group(&client->dev.kobj, &as7716_32x_fan_group);
|
sysfs_remove_group(&client->dev.kobj, &as7716_32x_fan_group);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1136
platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_cpld1.c
Executable file → Normal file
1136
platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_cpld1.c
Executable file → Normal file
File diff suppressed because it is too large
Load Diff
679
platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_fan.c
Executable file → Normal file
679
platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_fan.c
Executable file → Normal file
@ -43,17 +43,15 @@
|
|||||||
|
|
||||||
static struct as7716_32xb_fan_data *as7716_32xb_fan_update_device(struct device *dev);
|
static struct as7716_32xb_fan_data *as7716_32xb_fan_update_device(struct device *dev);
|
||||||
static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da,
|
static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da,
|
||||||
const char *buf, size_t count);
|
const char *buf, size_t count);
|
||||||
static ssize_t get_enable(struct device *dev, struct device_attribute *da, char *buf);
|
static ssize_t get_enable(struct device *dev, struct device_attribute *da, char *buf);
|
||||||
static ssize_t set_enable(struct device *dev, struct device_attribute *da,
|
static ssize_t set_enable(struct device *dev, struct device_attribute *da,
|
||||||
const char *buf, size_t count);
|
const char *buf, size_t count);
|
||||||
static ssize_t get_sys_temp(struct device *dev, struct device_attribute *da, char *buf);
|
|
||||||
|
|
||||||
|
|
||||||
static ssize_t fan_value_show(struct device *dev, struct device_attribute *da,
|
static ssize_t fan_value_show(struct device *dev, struct device_attribute *da,
|
||||||
char *buf);
|
char *buf);
|
||||||
static ssize_t fan_value_store(struct device *dev, struct device_attribute *da,
|
static ssize_t fan_value_store(struct device *dev, struct device_attribute *da,
|
||||||
char *buf, size_t size);
|
const char *buf, size_t size);
|
||||||
|
|
||||||
/* fan related data, the index should match sysfs_fan_attributes
|
/* fan related data, the index should match sysfs_fan_attributes
|
||||||
*/
|
*/
|
||||||
@ -85,12 +83,10 @@ struct as7716_32xb_fan_data {
|
|||||||
u8 reg_val[ARRAY_SIZE(fan_reg)]; /* Register value */
|
u8 reg_val[ARRAY_SIZE(fan_reg)]; /* Register value */
|
||||||
u8 enable;
|
u8 enable;
|
||||||
u8 duty_cycle;
|
u8 duty_cycle;
|
||||||
int system_temp; /*In unit of mini-Celsius*/
|
|
||||||
int sensors_found;
|
|
||||||
unsigned int present[FAN_NUM_MAX];
|
unsigned int present[FAN_NUM_MAX];
|
||||||
unsigned int front_speed_rpm[FAN_NUM_MAX];
|
unsigned int front_speed_rpm[FAN_NUM_MAX];
|
||||||
unsigned int rear_speed_rpm[FAN_NUM_MAX];
|
unsigned int rear_speed_rpm[FAN_NUM_MAX];
|
||||||
unsigned int direction[FAN_NUM_MAX];
|
unsigned int direction[FAN_NUM_MAX];
|
||||||
unsigned int fault[FAN_NUM_MAX];
|
unsigned int fault[FAN_NUM_MAX];
|
||||||
unsigned int input[FAN_NUM_MAX];
|
unsigned int input[FAN_NUM_MAX];
|
||||||
};
|
};
|
||||||
@ -153,7 +149,7 @@ enum sysfs_fan_attributes {
|
|||||||
#define DECLARE_FAN_DIRECTION_ATTR(index) &sensor_dev_attr_fan##index##_direction.dev_attr.attr
|
#define DECLARE_FAN_DIRECTION_ATTR(index) &sensor_dev_attr_fan##index##_direction.dev_attr.attr
|
||||||
|
|
||||||
|
|
||||||
#define DECLARE_FAN_DUTY_CYCLE_SENSOR_DEV_ATTR(index) \
|
#define DECLARE_FAN_DUTY_CYCLE_SENSOR_DEV_ATTR(index) \
|
||||||
static SENSOR_DEVICE_ATTR(fan_duty_cycle_percentage, S_IWUSR | S_IRUGO, fan_value_show, fan_value_store, FAN_DUTY_CYCLE_PERCENTAGE);\
|
static SENSOR_DEVICE_ATTR(fan_duty_cycle_percentage, S_IWUSR | S_IRUGO, fan_value_show, fan_value_store, FAN_DUTY_CYCLE_PERCENTAGE);\
|
||||||
static SENSOR_DEVICE_ATTR(pwm##index, S_IWUSR | S_IRUGO, fan_value_show, set_duty_cycle, FAN_DUTY_CYCLE_PERCENTAGE);\
|
static SENSOR_DEVICE_ATTR(pwm##index, S_IWUSR | S_IRUGO, fan_value_show, set_duty_cycle, FAN_DUTY_CYCLE_PERCENTAGE);\
|
||||||
static SENSOR_DEVICE_ATTR(pwm##index##_enable, S_IWUSR | S_IRUGO, get_enable, set_enable, FAN_DUTY_CYCLE_PERCENTAGE)
|
static SENSOR_DEVICE_ATTR(pwm##index##_enable, S_IWUSR | S_IRUGO, get_enable, set_enable, FAN_DUTY_CYCLE_PERCENTAGE)
|
||||||
@ -162,18 +158,11 @@ enum sysfs_fan_attributes {
|
|||||||
&sensor_dev_attr_pwm##index.dev_attr.attr, \
|
&sensor_dev_attr_pwm##index.dev_attr.attr, \
|
||||||
&sensor_dev_attr_pwm##index##_enable.dev_attr.attr
|
&sensor_dev_attr_pwm##index##_enable.dev_attr.attr
|
||||||
|
|
||||||
#define DECLARE_FAN_SYSTEM_TEMP_SENSOR_DEV_ATTR() \
|
|
||||||
static SENSOR_DEVICE_ATTR(sys_temp, S_IWUSR|S_IRUGO, get_sys_temp, NULL, FAN_DUTY_CYCLE_PERCENTAGE)
|
|
||||||
|
|
||||||
#define DECLARE_FAN_SYSTEM_TEMP_ATTR() &sensor_dev_attr_sys_temp.dev_attr.attr
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(index) \
|
#define DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(index) \
|
||||||
static SENSOR_DEVICE_ATTR(fan##index##_present, S_IWUSR|S_IRUGO, fan_value_show, fan_value_store, FAN##index##_PRESENT)
|
static SENSOR_DEVICE_ATTR(fan##index##_present, S_IWUSR|S_IRUGO, fan_value_show, fan_value_store, FAN##index##_PRESENT)
|
||||||
#define DECLARE_FAN_PRESENT_ATTR(index) &sensor_dev_attr_fan##index##_present.dev_attr.attr
|
#define DECLARE_FAN_PRESENT_ATTR(index) &sensor_dev_attr_fan##index##_present.dev_attr.attr
|
||||||
|
|
||||||
|
|
||||||
#define DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(index, index2) \
|
#define DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(index, index2) \
|
||||||
static SENSOR_DEVICE_ATTR(fan##index##_front_speed_rpm, S_IWUSR|S_IRUGO, fan_value_show, fan_value_store, FAN##index##_FRONT_SPEED_RPM);\
|
static SENSOR_DEVICE_ATTR(fan##index##_front_speed_rpm, S_IWUSR|S_IRUGO, fan_value_show, fan_value_store, FAN##index##_FRONT_SPEED_RPM);\
|
||||||
static SENSOR_DEVICE_ATTR(fan##index##_rear_speed_rpm, S_IWUSR|S_IRUGO, fan_value_show, fan_value_store, FAN##index##_REAR_SPEED_RPM);\
|
static SENSOR_DEVICE_ATTR(fan##index##_rear_speed_rpm, S_IWUSR|S_IRUGO, fan_value_show, fan_value_store, FAN##index##_REAR_SPEED_RPM);\
|
||||||
@ -182,7 +171,7 @@ enum sysfs_fan_attributes {
|
|||||||
#define DECLARE_FAN_SPEED_RPM_ATTR(index, index2) &sensor_dev_attr_fan##index##_front_speed_rpm.dev_attr.attr, \
|
#define DECLARE_FAN_SPEED_RPM_ATTR(index, index2) &sensor_dev_attr_fan##index##_front_speed_rpm.dev_attr.attr, \
|
||||||
&sensor_dev_attr_fan##index##_rear_speed_rpm.dev_attr.attr, \
|
&sensor_dev_attr_fan##index##_rear_speed_rpm.dev_attr.attr, \
|
||||||
&sensor_dev_attr_fan##index##_input.dev_attr.attr, \
|
&sensor_dev_attr_fan##index##_input.dev_attr.attr, \
|
||||||
&sensor_dev_attr_fan##index2##_input.dev_attr.attr
|
&sensor_dev_attr_fan##index2##_input.dev_attr.attr
|
||||||
|
|
||||||
/* 6 fan fault attributes in this platform */
|
/* 6 fan fault attributes in this platform */
|
||||||
DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(1,11);
|
DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(1,11);
|
||||||
@ -215,8 +204,6 @@ DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(6);
|
|||||||
|
|
||||||
/* 1 fan duty cycle attribute in this platform */
|
/* 1 fan duty cycle attribute in this platform */
|
||||||
DECLARE_FAN_DUTY_CYCLE_SENSOR_DEV_ATTR(1);
|
DECLARE_FAN_DUTY_CYCLE_SENSOR_DEV_ATTR(1);
|
||||||
/* System temperature for fancontrol */
|
|
||||||
DECLARE_FAN_SYSTEM_TEMP_SENSOR_DEV_ATTR();
|
|
||||||
|
|
||||||
static struct attribute *as7716_32xb_fan_attributes[] = {
|
static struct attribute *as7716_32xb_fan_attributes[] = {
|
||||||
/* fan related attributes */
|
/* fan related attributes */
|
||||||
@ -245,7 +232,6 @@ static struct attribute *as7716_32xb_fan_attributes[] = {
|
|||||||
DECLARE_FAN_DIRECTION_ATTR(5),
|
DECLARE_FAN_DIRECTION_ATTR(5),
|
||||||
DECLARE_FAN_DIRECTION_ATTR(6),
|
DECLARE_FAN_DIRECTION_ATTR(6),
|
||||||
DECLARE_FAN_DUTY_CYCLE_ATTR(1),
|
DECLARE_FAN_DUTY_CYCLE_ATTR(1),
|
||||||
DECLARE_FAN_SYSTEM_TEMP_ATTR(),
|
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -265,13 +251,13 @@ static int as7716_32xb_fan_write_value(struct i2c_client *client, u8 reg, u8 val
|
|||||||
|
|
||||||
/* fan utility functions
|
/* fan utility functions
|
||||||
*/
|
*/
|
||||||
static u32 reg_val_to_duty_cycle(u8 reg_val)
|
static u32 reg_val_to_duty_cycle(u8 reg_val)
|
||||||
{
|
{
|
||||||
reg_val &= FAN_DUTY_CYCLE_REG_MASK;
|
reg_val &= FAN_DUTY_CYCLE_REG_MASK;
|
||||||
return ((u32)(reg_val+1) * 625 + 75)/ 100;
|
return ((u32)(reg_val+1) * 625 + 75)/ 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
static u8 duty_cycle_to_reg_val(u8 duty_cycle)
|
static u8 duty_cycle_to_reg_val(u8 duty_cycle)
|
||||||
{
|
{
|
||||||
return ((u32)duty_cycle * 100 / 625) - 1;
|
return ((u32)duty_cycle * 100 / 625) - 1;
|
||||||
}
|
}
|
||||||
@ -301,11 +287,11 @@ static u8 reg_val_to_is_present(u8 reg_val, enum FAN_ID id)
|
|||||||
static u8 is_fan_fault(struct as7716_32xb_fan_data *data, enum FAN_ID id)
|
static u8 is_fan_fault(struct as7716_32xb_fan_data *data, enum FAN_ID id)
|
||||||
{
|
{
|
||||||
u8 ret = 0;
|
u8 ret = 0;
|
||||||
|
|
||||||
/* Check if the speed of front or rear fan is ZERO,
|
/* Check if the speed of front or rear fan is ZERO,
|
||||||
*/
|
*/
|
||||||
if (!data->front_speed_rpm[id] &&
|
if (!data->front_speed_rpm[id] &&
|
||||||
!data->rear_speed_rpm[id] )
|
!data->rear_speed_rpm[id] )
|
||||||
{
|
{
|
||||||
ret = 1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
@ -334,7 +320,7 @@ static ssize_t set_enable(struct device *dev, struct device_attribute *da,
|
|||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static ssize_t get_enable(struct device *dev, struct device_attribute *da,
|
static ssize_t get_enable(struct device *dev, struct device_attribute *da,
|
||||||
@ -346,315 +332,70 @@ static ssize_t get_enable(struct device *dev, struct device_attribute *da,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da,
|
static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da,
|
||||||
const char *buf, size_t count)
|
const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
int error, value;
|
int error, value;
|
||||||
struct i2c_client *client = to_i2c_client(dev);
|
struct i2c_client *client = to_i2c_client(dev);
|
||||||
|
|
||||||
error = kstrtoint(buf, 10, &value);
|
error = kstrtoint(buf, 10, &value);
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
if (value < 0 || value > FAN_MAX_DUTY_CYCLE)
|
if (value < 0 || value > FAN_MAX_DUTY_CYCLE)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
as7716_32xb_fan_write_value(client, 0x33, 0); /* Disable fan speed watch dog */
|
as7716_32xb_fan_write_value(client, 0x33, 0); /* Disable fan speed watch dog */
|
||||||
as7716_32xb_fan_write_value(client, fan_reg[FAN_DUTY_CYCLE_PERCENTAGE], duty_cycle_to_reg_val(value));
|
as7716_32xb_fan_write_value(client, fan_reg[FAN_DUTY_CYCLE_PERCENTAGE], duty_cycle_to_reg_val(value));
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Due to this struct is declared at lm75.c, it cannot be include
|
|
||||||
* under Sonic environment. I duplicate it from lm75.c.
|
|
||||||
*/
|
|
||||||
struct lm75_data {
|
|
||||||
struct i2c_client *client;
|
|
||||||
struct device *hwmon_dev;
|
|
||||||
struct thermal_zone_device *tz;
|
|
||||||
struct mutex update_lock;
|
|
||||||
u8 orig_conf;
|
|
||||||
u8 resolution; /* In bits, between 9 and 12 */
|
|
||||||
u8 resolution_limits;
|
|
||||||
char valid; /* !=0 if registers are valid */
|
|
||||||
unsigned long last_updated; /* In jiffies */
|
|
||||||
unsigned long sample_time; /* In jiffies */
|
|
||||||
s16 temp[3]; /* Register values,
|
|
||||||
0 = input
|
|
||||||
1 = max
|
|
||||||
2 = hyst */
|
|
||||||
};
|
|
||||||
|
|
||||||
/*Copied from lm75.c*/
|
|
||||||
static inline long lm75_reg_to_mc(s16 temp, u8 resolution)
|
|
||||||
{
|
|
||||||
return ((temp >> (16 - resolution)) * 1000) >> (resolution - 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*Get hwmon_dev from i2c_client, set hwmon_dev = NULL is failed.*/
|
|
||||||
static struct device * get_hwmon_dev(
|
|
||||||
struct i2c_client *client)
|
|
||||||
{
|
|
||||||
struct lm75_data *data = NULL;
|
|
||||||
|
|
||||||
data = i2c_get_clientdata(client);
|
|
||||||
if(data)
|
|
||||||
{
|
|
||||||
if( data->valid == 1 && data->hwmon_dev)
|
|
||||||
{
|
|
||||||
return data->hwmon_dev;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* To find hwmon index by opening hwmon under that i2c address.
|
|
||||||
*/
|
|
||||||
static int find_hwmon_index_by_FileOpen(
|
|
||||||
int bus_nr,
|
|
||||||
unsigned short addr,
|
|
||||||
OUT int *index)
|
|
||||||
{
|
|
||||||
#define MAX_HWMON_DEVICE (10) /* Find hwmon device in 0~10*/
|
|
||||||
struct file *sfd;
|
|
||||||
char client_name[96];
|
|
||||||
int i=0;
|
|
||||||
|
|
||||||
do {
|
|
||||||
snprintf(client_name, sizeof(client_name),
|
|
||||||
"/sys/bus/i2c/devices/%d-%04x/hwmon/hwmon%d/temp1_input",
|
|
||||||
bus_nr, addr, i);
|
|
||||||
|
|
||||||
sfd = filp_open(client_name, O_RDONLY, 0);
|
|
||||||
i++;
|
|
||||||
} while( IS_ERR(sfd) && i < MAX_HWMON_DEVICE);
|
|
||||||
|
|
||||||
if (IS_ERR(sfd)) {
|
|
||||||
pr_err("Failed to open file(%s)#%d\r\n", client_name, __LINE__);
|
|
||||||
return -ENOENT;
|
|
||||||
}
|
|
||||||
filp_close(sfd, 0);
|
|
||||||
*index = i - 1;
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
#undef MAX_HWMON_DEVICE
|
|
||||||
}
|
|
||||||
|
|
||||||
static int get_temp_file_path(
|
|
||||||
int bus_nr, unsigned short addr,
|
|
||||||
struct device *hwmon_dev
|
|
||||||
,char *path, int max_len)
|
|
||||||
{
|
|
||||||
|
|
||||||
if(hwmon_dev && strlen(dev_name(hwmon_dev)))
|
|
||||||
{
|
|
||||||
snprintf(path, max_len,
|
|
||||||
"/sys/bus/i2c/devices/%d-%04x/hwmon/%s/temp1_input",
|
|
||||||
bus_nr, addr, dev_name(hwmon_dev));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int i=0;
|
|
||||||
if(find_hwmon_index_by_FileOpen( bus_nr, addr, &i))
|
|
||||||
{
|
|
||||||
return -EIO;
|
|
||||||
}
|
|
||||||
snprintf(path, max_len,
|
|
||||||
"/sys/bus/i2c/devices/%d-%04x/hwmon/hwmon%d/temp1_input",
|
|
||||||
bus_nr, addr, i);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*File read the dev file at user space.*/
|
|
||||||
static int read_devfile_temp1_input(
|
|
||||||
struct device *dev,
|
|
||||||
int bus_nr,
|
|
||||||
unsigned short addr,
|
|
||||||
struct device *hwmon_dev,
|
|
||||||
int *miniCelsius)
|
|
||||||
{
|
|
||||||
struct file *sfd;
|
|
||||||
char buffer[96];
|
|
||||||
char devfile[96];
|
|
||||||
int rc, status;
|
|
||||||
int rdlen, value;
|
|
||||||
mm_segment_t old_fs;
|
|
||||||
|
|
||||||
rc = 0;
|
|
||||||
get_temp_file_path(bus_nr, addr, hwmon_dev, devfile, sizeof(devfile));
|
|
||||||
sfd = filp_open(devfile, O_RDONLY, 0);
|
|
||||||
if (IS_ERR(sfd)) {
|
|
||||||
pr_err("Failed to open file(%s)#%d\r\n", devfile, __LINE__);
|
|
||||||
return -ENOENT;
|
|
||||||
}
|
|
||||||
dev_dbg(dev, "Found device:%s\n",devfile);
|
|
||||||
|
|
||||||
if(!(sfd->f_op) || !(sfd->f_op->read) ) {
|
|
||||||
pr_err("file %s cann't readable ?\n",devfile);
|
|
||||||
return -ENOENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
old_fs = get_fs();
|
|
||||||
set_fs(KERNEL_DS);
|
|
||||||
rdlen = sfd->f_op->read(sfd, buffer, sizeof(buffer), &sfd->f_pos);
|
|
||||||
if (rdlen == 0) {
|
|
||||||
pr_err( "File(%s) empty!\n", devfile);
|
|
||||||
rc = -EIO;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
status = sscanf(buffer, "%d", &value);
|
|
||||||
if (status != 1) {
|
|
||||||
rc = -EIO;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
*miniCelsius = value;
|
|
||||||
dev_dbg(dev,"found sensors: %d @i2c %d-%04x\n", value, bus_nr, addr);
|
|
||||||
|
|
||||||
exit:
|
|
||||||
set_fs(old_fs);
|
|
||||||
filp_close(sfd, 0);
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
static u8 is_lm75_data_due(struct i2c_client *client)
|
|
||||||
{
|
|
||||||
struct lm75_data *data = NULL;
|
|
||||||
|
|
||||||
data = i2c_get_clientdata(client);
|
|
||||||
if (time_after(jiffies, data->last_updated + data->sample_time))
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
static int get_lm75_temp(struct i2c_client *client, int *miniCelsius)
|
|
||||||
{
|
|
||||||
struct lm75_data *data = NULL;
|
|
||||||
|
|
||||||
data = i2c_get_clientdata(client);
|
|
||||||
*miniCelsius = lm75_reg_to_mc(data->temp[0], data->resolution);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int _find_lm75_device(struct device *dev, void *data)
|
|
||||||
{
|
|
||||||
struct device_driver *driver;
|
|
||||||
struct as7716_32xb_fan_data *prv = data;
|
|
||||||
char *driver_name = THERMAL_SENSORS_DRIVER;
|
|
||||||
|
|
||||||
driver = dev->driver;
|
|
||||||
if (driver && driver->name &&
|
|
||||||
strcmp(driver->name, driver_name) == 0)
|
|
||||||
{
|
|
||||||
struct i2c_client *client;
|
|
||||||
client = to_i2c_client(dev);
|
|
||||||
if (client)
|
|
||||||
{
|
|
||||||
/*cannot use "struct i2c_adapter *adap = to_i2c_adapter(dev);"*/
|
|
||||||
struct i2c_adapter *adap = client->adapter;
|
|
||||||
int miniCelsius = 0;
|
|
||||||
|
|
||||||
|
|
||||||
if (!adap) {
|
|
||||||
return -ENXIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If the data is not updated, read them from devfile
|
|
||||||
to drive them updateing data from chip.*/
|
|
||||||
if (is_lm75_data_due(client))
|
|
||||||
{
|
|
||||||
struct device *hwmon_dev;
|
|
||||||
|
|
||||||
hwmon_dev = get_hwmon_dev(client);
|
|
||||||
if(0 == read_devfile_temp1_input(dev, adap->nr,
|
|
||||||
client->addr, hwmon_dev, &miniCelsius))
|
|
||||||
{
|
|
||||||
prv->system_temp += miniCelsius;
|
|
||||||
prv->sensors_found++;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
get_lm75_temp(client, &miniCelsius);
|
|
||||||
prv->system_temp += miniCelsius;
|
|
||||||
prv->sensors_found++;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*Find all lm75 devices and return sum of temperatures.*/
|
|
||||||
static ssize_t get_sys_temp(struct device *dev, struct device_attribute *da,
|
|
||||||
char *buf)
|
|
||||||
{
|
|
||||||
ssize_t ret = 0;
|
|
||||||
struct as7716_32xb_fan_data *data = as7716_32xb_fan_update_device(dev);
|
|
||||||
|
|
||||||
data->system_temp=0;
|
|
||||||
data->sensors_found=0;
|
|
||||||
i2c_for_each_dev(data, _find_lm75_device);
|
|
||||||
if (NUM_THERMAL_SENSORS != data->sensors_found)
|
|
||||||
{
|
|
||||||
dev_dbg(dev,"only %d of %d temps are found\n",
|
|
||||||
data->sensors_found, NUM_THERMAL_SENSORS);
|
|
||||||
data->system_temp = 0;
|
|
||||||
}
|
|
||||||
ret = sprintf(buf, "%d\n",data->system_temp);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int fan_array_index_get(int attr_idx)
|
static int fan_array_index_get(int attr_idx)
|
||||||
{
|
{
|
||||||
switch(attr_idx)
|
switch(attr_idx)
|
||||||
{
|
{
|
||||||
case FAN1_PRESENT:
|
case FAN1_PRESENT:
|
||||||
case FAN1_FRONT_SPEED_RPM:
|
case FAN1_FRONT_SPEED_RPM:
|
||||||
case FAN1_REAR_SPEED_RPM:
|
case FAN1_REAR_SPEED_RPM:
|
||||||
case FAN1_FAULT:
|
case FAN1_FAULT:
|
||||||
case FAN1_DIRECTION:
|
case FAN1_DIRECTION:
|
||||||
return FAN1_ID;
|
return FAN1_ID;
|
||||||
case FAN2_PRESENT:
|
case FAN2_PRESENT:
|
||||||
case FAN2_FRONT_SPEED_RPM:
|
case FAN2_FRONT_SPEED_RPM:
|
||||||
case FAN2_REAR_SPEED_RPM:
|
case FAN2_REAR_SPEED_RPM:
|
||||||
case FAN2_FAULT:
|
case FAN2_FAULT:
|
||||||
case FAN2_DIRECTION:
|
case FAN2_DIRECTION:
|
||||||
return FAN2_ID;
|
return FAN2_ID;
|
||||||
case FAN3_PRESENT:
|
case FAN3_PRESENT:
|
||||||
case FAN3_FRONT_SPEED_RPM:
|
case FAN3_FRONT_SPEED_RPM:
|
||||||
case FAN3_REAR_SPEED_RPM:
|
case FAN3_REAR_SPEED_RPM:
|
||||||
case FAN3_FAULT:
|
case FAN3_FAULT:
|
||||||
case FAN3_DIRECTION:
|
case FAN3_DIRECTION:
|
||||||
return FAN3_ID;
|
return FAN3_ID;
|
||||||
case FAN4_PRESENT:
|
case FAN4_PRESENT:
|
||||||
case FAN4_FRONT_SPEED_RPM:
|
case FAN4_FRONT_SPEED_RPM:
|
||||||
case FAN4_REAR_SPEED_RPM:
|
case FAN4_REAR_SPEED_RPM:
|
||||||
case FAN4_FAULT:
|
case FAN4_FAULT:
|
||||||
case FAN4_DIRECTION:
|
case FAN4_DIRECTION:
|
||||||
return FAN4_ID;
|
return FAN4_ID;
|
||||||
case FAN5_PRESENT:
|
case FAN5_PRESENT:
|
||||||
case FAN5_FRONT_SPEED_RPM:
|
case FAN5_FRONT_SPEED_RPM:
|
||||||
case FAN5_REAR_SPEED_RPM:
|
case FAN5_REAR_SPEED_RPM:
|
||||||
case FAN5_FAULT:
|
case FAN5_FAULT:
|
||||||
case FAN5_DIRECTION:
|
case FAN5_DIRECTION:
|
||||||
return FAN5_ID;
|
return FAN5_ID;
|
||||||
case FAN6_PRESENT:
|
case FAN6_PRESENT:
|
||||||
case FAN6_FRONT_SPEED_RPM:
|
case FAN6_FRONT_SPEED_RPM:
|
||||||
case FAN6_REAR_SPEED_RPM:
|
case FAN6_REAR_SPEED_RPM:
|
||||||
case FAN6_FAULT:
|
case FAN6_FAULT:
|
||||||
case FAN6_DIRECTION:
|
case FAN6_DIRECTION:
|
||||||
return FAN6_ID;
|
return FAN6_ID;
|
||||||
default :
|
default :
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t fan_value_store(struct device *dev, struct device_attribute *da,
|
static ssize_t fan_value_store(struct device *dev, struct device_attribute *da,
|
||||||
char *buf, size_t size)
|
const char *buf, size_t size)
|
||||||
{
|
{
|
||||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||||
struct i2c_client *client = to_i2c_client(dev);
|
struct i2c_client *client = to_i2c_client(dev);
|
||||||
@ -667,97 +408,97 @@ static ssize_t fan_value_store(struct device *dev, struct device_attribute *da,
|
|||||||
mutex_lock(&data->update_lock);
|
mutex_lock(&data->update_lock);
|
||||||
switch (attr->index)
|
switch (attr->index)
|
||||||
{
|
{
|
||||||
case FAN_DUTY_CYCLE_PERCENTAGE:
|
case FAN_DUTY_CYCLE_PERCENTAGE:
|
||||||
status = kstrtol(buf, STRING_TO_DEC_VALUE, &keyin);
|
status = kstrtol(buf, STRING_TO_DEC_VALUE, &keyin);
|
||||||
if (status)
|
if (status)
|
||||||
break;
|
|
||||||
if (keyin > 1 || keyin < 0)
|
|
||||||
break;
|
|
||||||
data->duty_cycle=keyin;
|
|
||||||
break;
|
break;
|
||||||
case FAN1_FRONT_SPEED_RPM:
|
if (keyin > 1 || keyin < 0)
|
||||||
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:
|
|
||||||
status = kstrtol(buf, STRING_TO_DEC_VALUE, &keyin);
|
|
||||||
if (status)
|
|
||||||
break;
|
|
||||||
index=fan_array_index_get(attr->index);
|
|
||||||
if(index < 0 || index > (FAN_NUM_MAX-1))
|
|
||||||
break;
|
|
||||||
data->front_speed_rpm[index]=keyin;
|
|
||||||
break;
|
|
||||||
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:
|
|
||||||
status = kstrtol(buf, STRING_TO_DEC_VALUE, &keyin);
|
|
||||||
if (status)
|
|
||||||
break;
|
|
||||||
index=fan_array_index_get(attr->index);
|
|
||||||
if(index < 0 || index > (FAN_NUM_MAX-1))
|
|
||||||
break;
|
|
||||||
data->rear_speed_rpm[index]=keyin;
|
|
||||||
case FAN1_PRESENT:
|
|
||||||
case FAN2_PRESENT:
|
|
||||||
case FAN3_PRESENT:
|
|
||||||
case FAN4_PRESENT:
|
|
||||||
case FAN5_PRESENT:
|
|
||||||
case FAN6_PRESENT:
|
|
||||||
status = kstrtol(buf, STRING_TO_DEC_VALUE, &keyin);
|
|
||||||
if (status)
|
|
||||||
break;
|
|
||||||
index=fan_array_index_get(attr->index);
|
|
||||||
if(index < 0 || index > (FAN_NUM_MAX-1))
|
|
||||||
break;
|
|
||||||
if(keyin < 0 || keyin > 1)
|
|
||||||
break;
|
|
||||||
data->present[index]=keyin;
|
|
||||||
break;
|
break;
|
||||||
case FAN1_FAULT:
|
data->duty_cycle=keyin;
|
||||||
case FAN2_FAULT:
|
break;
|
||||||
case FAN3_FAULT:
|
case FAN1_FRONT_SPEED_RPM:
|
||||||
case FAN4_FAULT:
|
case FAN2_FRONT_SPEED_RPM:
|
||||||
case FAN5_FAULT:
|
case FAN3_FRONT_SPEED_RPM:
|
||||||
case FAN6_FAULT:
|
case FAN4_FRONT_SPEED_RPM:
|
||||||
status = kstrtol(buf, STRING_TO_DEC_VALUE, &keyin);
|
case FAN5_FRONT_SPEED_RPM:
|
||||||
if (status)
|
case FAN6_FRONT_SPEED_RPM:
|
||||||
break;
|
status = kstrtol(buf, STRING_TO_DEC_VALUE, &keyin);
|
||||||
index=fan_array_index_get(attr->index);
|
if (status)
|
||||||
if(index < 0 || index > (FAN_NUM_MAX-1))
|
|
||||||
break;
|
|
||||||
if(keyin < 0 || keyin > 1)
|
|
||||||
break;
|
|
||||||
data->fault[index]=keyin;
|
|
||||||
break;
|
break;
|
||||||
case FAN1_DIRECTION:
|
index=fan_array_index_get(attr->index);
|
||||||
case FAN2_DIRECTION:
|
if(index < 0 || index > (FAN_NUM_MAX-1))
|
||||||
case FAN3_DIRECTION:
|
|
||||||
case FAN4_DIRECTION:
|
|
||||||
case FAN5_DIRECTION:
|
|
||||||
case FAN6_DIRECTION:
|
|
||||||
status = kstrtol(buf, STRING_TO_DEC_VALUE, &keyin);
|
|
||||||
if (status)
|
|
||||||
break;
|
|
||||||
index=fan_array_index_get(attr->index);
|
|
||||||
if(index < 0 || index > (FAN_NUM_MAX-1))
|
|
||||||
break;
|
|
||||||
if(keyin < 0 || keyin > 1)
|
|
||||||
break;
|
|
||||||
data->direction[index]=keyin;
|
|
||||||
break;
|
break;
|
||||||
default:
|
data->front_speed_rpm[index]=keyin;
|
||||||
|
break;
|
||||||
|
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:
|
||||||
|
status = kstrtol(buf, STRING_TO_DEC_VALUE, &keyin);
|
||||||
|
if (status)
|
||||||
break;
|
break;
|
||||||
|
index=fan_array_index_get(attr->index);
|
||||||
|
if(index < 0 || index > (FAN_NUM_MAX-1))
|
||||||
|
break;
|
||||||
|
data->rear_speed_rpm[index]=keyin;
|
||||||
|
case FAN1_PRESENT:
|
||||||
|
case FAN2_PRESENT:
|
||||||
|
case FAN3_PRESENT:
|
||||||
|
case FAN4_PRESENT:
|
||||||
|
case FAN5_PRESENT:
|
||||||
|
case FAN6_PRESENT:
|
||||||
|
status = kstrtol(buf, STRING_TO_DEC_VALUE, &keyin);
|
||||||
|
if (status)
|
||||||
|
break;
|
||||||
|
index=fan_array_index_get(attr->index);
|
||||||
|
if(index < 0 || index > (FAN_NUM_MAX-1))
|
||||||
|
break;
|
||||||
|
if(keyin < 0 || keyin > 1)
|
||||||
|
break;
|
||||||
|
data->present[index]=keyin;
|
||||||
|
break;
|
||||||
|
case FAN1_FAULT:
|
||||||
|
case FAN2_FAULT:
|
||||||
|
case FAN3_FAULT:
|
||||||
|
case FAN4_FAULT:
|
||||||
|
case FAN5_FAULT:
|
||||||
|
case FAN6_FAULT:
|
||||||
|
status = kstrtol(buf, STRING_TO_DEC_VALUE, &keyin);
|
||||||
|
if (status)
|
||||||
|
break;
|
||||||
|
index=fan_array_index_get(attr->index);
|
||||||
|
if(index < 0 || index > (FAN_NUM_MAX-1))
|
||||||
|
break;
|
||||||
|
if(keyin < 0 || keyin > 1)
|
||||||
|
break;
|
||||||
|
data->fault[index]=keyin;
|
||||||
|
break;
|
||||||
|
case FAN1_DIRECTION:
|
||||||
|
case FAN2_DIRECTION:
|
||||||
|
case FAN3_DIRECTION:
|
||||||
|
case FAN4_DIRECTION:
|
||||||
|
case FAN5_DIRECTION:
|
||||||
|
case FAN6_DIRECTION:
|
||||||
|
status = kstrtol(buf, STRING_TO_DEC_VALUE, &keyin);
|
||||||
|
if (status)
|
||||||
|
break;
|
||||||
|
index=fan_array_index_get(attr->index);
|
||||||
|
if(index < 0 || index > (FAN_NUM_MAX-1))
|
||||||
|
break;
|
||||||
|
if(keyin < 0 || keyin > 1)
|
||||||
|
break;
|
||||||
|
data->direction[index]=keyin;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
mutex_unlock(&data->update_lock);
|
mutex_unlock(&data->update_lock);
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
static ssize_t fan_value_show(struct device *dev, struct device_attribute *da,
|
static ssize_t fan_value_show(struct device *dev, struct device_attribute *da,
|
||||||
char *buf)
|
char *buf)
|
||||||
{
|
{
|
||||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||||
struct i2c_client *client = to_i2c_client(dev);
|
struct i2c_client *client = to_i2c_client(dev);
|
||||||
@ -769,66 +510,66 @@ static ssize_t fan_value_show(struct device *dev, struct device_attribute *da,
|
|||||||
mutex_lock(&data->update_lock);
|
mutex_lock(&data->update_lock);
|
||||||
switch (attr->index)
|
switch (attr->index)
|
||||||
{
|
{
|
||||||
case FAN_DUTY_CYCLE_PERCENTAGE:
|
case FAN_DUTY_CYCLE_PERCENTAGE:
|
||||||
status = sprintf(buf, "%u\n", data->duty_cycle);
|
status = sprintf(buf, "%u\n", data->duty_cycle);
|
||||||
break;
|
break;
|
||||||
case FAN1_FRONT_SPEED_RPM:
|
case FAN1_FRONT_SPEED_RPM:
|
||||||
case FAN2_FRONT_SPEED_RPM:
|
case FAN2_FRONT_SPEED_RPM:
|
||||||
case FAN3_FRONT_SPEED_RPM:
|
case FAN3_FRONT_SPEED_RPM:
|
||||||
case FAN4_FRONT_SPEED_RPM:
|
case FAN4_FRONT_SPEED_RPM:
|
||||||
case FAN5_FRONT_SPEED_RPM:
|
case FAN5_FRONT_SPEED_RPM:
|
||||||
case FAN6_FRONT_SPEED_RPM:
|
case FAN6_FRONT_SPEED_RPM:
|
||||||
index=fan_array_index_get(attr->index);
|
index=fan_array_index_get(attr->index);
|
||||||
if(index < 0 || index > (FAN_NUM_MAX-1))
|
if(index < 0 || index > (FAN_NUM_MAX-1))
|
||||||
break;
|
|
||||||
status = sprintf(buf, "%u\n", data->front_speed_rpm[index]);
|
|
||||||
break;
|
|
||||||
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:
|
|
||||||
index=fan_array_index_get(attr->index);
|
|
||||||
if(index < 0 || index > (FAN_NUM_MAX-1))
|
|
||||||
break;
|
|
||||||
status = sprintf(buf, "%u\n", data->rear_speed_rpm[index]);
|
|
||||||
break;
|
|
||||||
case FAN1_PRESENT:
|
|
||||||
case FAN2_PRESENT:
|
|
||||||
case FAN3_PRESENT:
|
|
||||||
case FAN4_PRESENT:
|
|
||||||
case FAN5_PRESENT:
|
|
||||||
case FAN6_PRESENT:
|
|
||||||
index=fan_array_index_get(attr->index);
|
|
||||||
if(index < 0 || index > (FAN_NUM_MAX-1))
|
|
||||||
break;
|
|
||||||
status = sprintf(buf, "%d\n", data->present[index]);
|
|
||||||
break;
|
break;
|
||||||
case FAN1_FAULT:
|
status = sprintf(buf, "%u\n", data->front_speed_rpm[index]);
|
||||||
case FAN2_FAULT:
|
break;
|
||||||
case FAN3_FAULT:
|
case FAN1_REAR_SPEED_RPM:
|
||||||
case FAN4_FAULT:
|
case FAN2_REAR_SPEED_RPM:
|
||||||
case FAN5_FAULT:
|
case FAN3_REAR_SPEED_RPM:
|
||||||
case FAN6_FAULT:
|
case FAN4_REAR_SPEED_RPM:
|
||||||
index=fan_array_index_get(attr->index);
|
case FAN5_REAR_SPEED_RPM:
|
||||||
if(index < 0 || index > (FAN_NUM_MAX-1))
|
case FAN6_REAR_SPEED_RPM:
|
||||||
break;
|
index=fan_array_index_get(attr->index);
|
||||||
status = sprintf(buf, "%d\n", is_fan_fault(data, index));
|
if(index < 0 || index > (FAN_NUM_MAX-1))
|
||||||
break;
|
break;
|
||||||
case FAN1_DIRECTION:
|
status = sprintf(buf, "%u\n", data->rear_speed_rpm[index]);
|
||||||
case FAN2_DIRECTION:
|
break;
|
||||||
case FAN3_DIRECTION:
|
case FAN1_PRESENT:
|
||||||
case FAN4_DIRECTION:
|
case FAN2_PRESENT:
|
||||||
case FAN5_DIRECTION:
|
case FAN3_PRESENT:
|
||||||
case FAN6_DIRECTION:
|
case FAN4_PRESENT:
|
||||||
index=fan_array_index_get(attr->index);;
|
case FAN5_PRESENT:
|
||||||
if(index < 0 || index > (FAN_NUM_MAX-1))
|
case FAN6_PRESENT:
|
||||||
break;
|
index=fan_array_index_get(attr->index);
|
||||||
status = sprintf(buf, "%d\n", data->direction[index]);
|
if(index < 0 || index > (FAN_NUM_MAX-1))
|
||||||
break;
|
break;
|
||||||
default:
|
status = sprintf(buf, "%d\n", data->present[index]);
|
||||||
|
break;
|
||||||
|
case FAN1_FAULT:
|
||||||
|
case FAN2_FAULT:
|
||||||
|
case FAN3_FAULT:
|
||||||
|
case FAN4_FAULT:
|
||||||
|
case FAN5_FAULT:
|
||||||
|
case FAN6_FAULT:
|
||||||
|
index=fan_array_index_get(attr->index);
|
||||||
|
if(index < 0 || index > (FAN_NUM_MAX-1))
|
||||||
break;
|
break;
|
||||||
|
status = sprintf(buf, "%d\n", is_fan_fault(data, index));
|
||||||
|
break;
|
||||||
|
case FAN1_DIRECTION:
|
||||||
|
case FAN2_DIRECTION:
|
||||||
|
case FAN3_DIRECTION:
|
||||||
|
case FAN4_DIRECTION:
|
||||||
|
case FAN5_DIRECTION:
|
||||||
|
case FAN6_DIRECTION:
|
||||||
|
index=fan_array_index_get(attr->index);;
|
||||||
|
if(index < 0 || index > (FAN_NUM_MAX-1))
|
||||||
|
break;
|
||||||
|
status = sprintf(buf, "%d\n", data->direction[index]);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
mutex_unlock(&data->update_lock);
|
mutex_unlock(&data->update_lock);
|
||||||
return status;
|
return status;
|
||||||
@ -845,18 +586,18 @@ static struct as7716_32xb_fan_data *as7716_32xb_fan_update_device(struct device
|
|||||||
|
|
||||||
mutex_lock(&data->update_lock);
|
mutex_lock(&data->update_lock);
|
||||||
|
|
||||||
if (time_after(jiffies, data->last_updated + HZ + HZ / 2) ||
|
if (time_after(jiffies, data->last_updated + HZ + HZ / 2) ||
|
||||||
!data->valid) {
|
!data->valid) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
dev_dbg(&client->dev, "Starting as7716_32xb_fan update\n");
|
dev_dbg(&client->dev, "Starting as7716_32xb_fan update\n");
|
||||||
data->valid = 0;
|
data->valid = 0;
|
||||||
|
|
||||||
/* Update fan data
|
/* Update fan data
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < ARRAY_SIZE(data->reg_val); i++) {
|
for (i = 0; i < ARRAY_SIZE(data->reg_val); i++) {
|
||||||
int status = as7716_32xb_fan_read_value(client, fan_reg[i]);
|
int status = as7716_32xb_fan_read_value(client, fan_reg[i]);
|
||||||
|
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
data->valid = 0;
|
data->valid = 0;
|
||||||
mutex_unlock(&data->update_lock);
|
mutex_unlock(&data->update_lock);
|
||||||
@ -867,18 +608,18 @@ static struct as7716_32xb_fan_data *as7716_32xb_fan_update_device(struct device
|
|||||||
data->reg_val[i] = status;
|
data->reg_val[i] = status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data->last_updated = jiffies;
|
data->last_updated = jiffies;
|
||||||
data->valid = 1;
|
data->valid = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
mutex_unlock(&data->update_lock);
|
mutex_unlock(&data->update_lock);
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int as7716_32xb_fan_probe(struct i2c_client *client,
|
static int as7716_32xb_fan_probe(struct i2c_client *client,
|
||||||
const struct i2c_device_id *dev_id)
|
const struct i2c_device_id *dev_id)
|
||||||
{
|
{
|
||||||
struct as7716_32xb_fan_data *data;
|
struct as7716_32xb_fan_data *data;
|
||||||
int status;
|
int status;
|
||||||
@ -908,8 +649,8 @@ static int as7716_32xb_fan_probe(struct i2c_client *client,
|
|||||||
}
|
}
|
||||||
|
|
||||||
dev_info(&client->dev, "%s: fan '%s'\n",
|
dev_info(&client->dev, "%s: fan '%s'\n",
|
||||||
dev_name(data->hwmon_dev), client->name);
|
dev_name(data->hwmon_dev), client->name);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
exit_remove:
|
exit_remove:
|
||||||
@ -917,7 +658,7 @@ exit_remove:
|
|||||||
exit_free:
|
exit_free:
|
||||||
kfree(data);
|
kfree(data);
|
||||||
exit:
|
exit:
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -926,7 +667,7 @@ static int as7716_32xb_fan_remove(struct i2c_client *client)
|
|||||||
struct as7716_32xb_fan_data *data = i2c_get_clientdata(client);
|
struct as7716_32xb_fan_data *data = i2c_get_clientdata(client);
|
||||||
hwmon_device_unregister(data->hwmon_dev);
|
hwmon_device_unregister(data->hwmon_dev);
|
||||||
sysfs_remove_group(&client->dev.kobj, &as7716_32xb_fan_group);
|
sysfs_remove_group(&client->dev.kobj, &as7716_32xb_fan_group);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user