From 483bd9bbd882b8d4fb0513067f55104ed5efb1f7 Mon Sep 17 00:00:00 2001 From: Roy Lee Date: Sat, 27 Oct 2018 07:34:07 +0800 Subject: [PATCH] [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 * Refine codes by formatter. Signed-off-by: roy_lee --- .../modules/accton_as7712_32x_fan.c | 248 +--- .../as7716-32x/modules/Makefile | 2 +- .../modules/accton_as7716_32x_fan.c | 409 ++---- .../modules/accton_as7716_32xb_cpld1.c | 1154 ++++++++--------- .../modules/accton_as7716_32xb_fan.c | 673 +++------- 5 files changed, 913 insertions(+), 1573 deletions(-) mode change 100644 => 100755 platform/broadcom/sonic-platform-modules-accton/as7712-32x/modules/accton_as7712_32x_fan.c mode change 100755 => 100644 platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/accton_as7716_32x_fan.c mode change 100755 => 100644 platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_cpld1.c mode change 100755 => 100644 platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_fan.c diff --git a/platform/broadcom/sonic-platform-modules-accton/as7712-32x/modules/accton_as7712_32x_fan.c b/platform/broadcom/sonic-platform-modules-accton/as7712-32x/modules/accton_as7712_32x_fan.c old mode 100644 new mode 100755 index 3eae51cbcea7..73dd36c2883e --- a/platform/broadcom/sonic-platform-modules-accton/as7712-32x/modules/accton_as7712_32x_fan.c +++ b/platform/broadcom/sonic-platform-modules-accton/as7712-32x/modules/accton_as7712_32x_fan.c @@ -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, const char *buf, size_t count); 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 */ @@ -291,7 +290,6 @@ static ssize_t set_enable(struct device *dev, struct device_attribute *da, return count; } - static ssize_t get_enable(struct device *dev, struct device_attribute *da, 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); } + static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da, const char *buf, size_t count) { @@ -319,238 +318,97 @@ static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da, 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) +static bool lm75_addr_mached(unsigned short addr) { - struct lm75_data *data = NULL; + int i; + unsigned short addrs[] = THERMAL_SENSORS_ADDRS; - data = i2c_get_clientdata(client); - if(data) + for (i = 0; i < ARRAY_SIZE(addrs); i++) { - if( data->valid == 1 && data->hwmon_dev) - { - return data->hwmon_dev; - } - + if( addr == addrs[i]) + return 1; } - return NULL; + return 0; } -/* 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; +/* 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; -#undef MAX_HWMON_DEVICE -} + struct attribute_group group; + const struct attribute_group **groups; +}; +#define to_hwmon_device(d) container_of(d, struct hwmon_device, dev) -static int get_temp_file_path( - int bus_nr, unsigned short addr, - struct device *hwmon_dev - ,char *path, int max_len) +/*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) { - - 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; + 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; } - 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) +static int hwmon_get_temp(struct device *dev, long *mini_cel) { - struct lm75_data *data = NULL; + struct hwmon_device *hwmon_dev = to_hwmon_device(dev); + int ret = 0; - data = i2c_get_clientdata(client); - *miniCelsius = lm75_reg_to_mc(data->temp[0], data->resolution); + if(hwmon_dev) { + long t; + ret = hwmon_dev->chip->ops->read(dev, hwmon_temp, hwmon_temp_input, + 0, &t); + if (ret < 0) + return ret; - return 0; -} - -static bool lm75_addr_mached(unsigned short addr) -{ - int i; - unsigned short addrs[] = THERMAL_SENSORS_ADDRS; - - for (i = 0; i < ARRAY_SIZE(addrs); i++) - { - if( addr == addrs[i]) - return 1; + *mini_cel = t; } - return 0; + 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) { struct device_driver *driver; struct as7712_32x_fan_data *prv = data; char *driver_name = THERMAL_SENSORS_DRIVER; + struct i2c_client *client; 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; + long miniCelsius = 0; + struct device *child_dev; if (! lm75_addr_mached(client->addr)) { return 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++; - } + child_dev = device_find_child(dev, NULL, is_valid_dev); + if(child_dev) { + int ret = hwmon_get_temp(child_dev, &miniCelsius); + if (ret < 0) + return ret; - } - else - { - get_lm75_temp(client, &miniCelsius); prv->system_temp += miniCelsius; prv->sensors_found++; diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/Makefile b/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/Makefile index 4c0942afb97e..6cdbdd81ac1e 100755 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/Makefile +++ b/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/Makefile @@ -1,7 +1,7 @@ ifneq ($(KERNELRELEASE),) 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 \ - optoe.o accton_i2c_cpld.o + accton_i2c_cpld.o else ifeq (,$(KERNEL_SRC)) diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/accton_as7716_32x_fan.c b/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/accton_as7716_32x_fan.c old mode 100755 new mode 100644 index 83b7bceeb99e..3a0610fe370d --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/accton_as7716_32x_fan.c +++ b/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/accton_as7716_32x_fan.c @@ -34,22 +34,16 @@ #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 OUT 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 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 set_enable(struct device *dev, struct device_attribute *da, 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 */ @@ -79,8 +73,6 @@ struct as7716_32x_fan_data { unsigned long last_updated; /* In jiffies */ u8 reg_val[ARRAY_SIZE(fan_reg)]; /* Register value */ u8 enable; - int system_temp; /*In unit of mini-Celsius*/ - int sensors_found; }; enum fan_id { @@ -149,12 +141,6 @@ enum sysfs_fan_attributes { &sensor_dev_attr_pwm##index.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) \ 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 @@ -200,8 +186,6 @@ DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(6); /* 1 fan duty cycle attribute in this platform */ 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[] = { /* fan related attributes */ @@ -230,7 +214,6 @@ static struct attribute *as7716_32x_fan_attributes[] = { DECLARE_FAN_DIRECTION_ATTR(5), DECLARE_FAN_DIRECTION_ATTR(6), DECLARE_FAN_DUTY_CYCLE_ATTR(1), - DECLARE_FAN_SYSTEM_TEMP_ATTR(), NULL }; @@ -250,13 +233,13 @@ static int as7716_32x_fan_write_value(struct i2c_client *client, u8 reg, u8 valu /* 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; 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; } @@ -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 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]) && - reg_val_to_speed_rpm(data->reg_val[rear_fan_index])) { + reg_val_to_speed_rpm(data->reg_val[rear_fan_index])) { 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); } + 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; 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; - + 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)); 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, - char *buf) + char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(da); struct as7716_32x_fan_data *data = as7716_32x_fan_update_device(dev); ssize_t ret = 0; - + if (data->valid) { switch (attr->index) { - case FAN_DUTY_CYCLE_PERCENTAGE: - { - u32 duty_cycle = reg_val_to_duty_cycle(data->reg_val[FAN_DUTY_CYCLE_PERCENTAGE]); - ret = sprintf(buf, "%u\n", duty_cycle); - break; - } - case FAN1_FRONT_SPEED_RPM: - case FAN2_FRONT_SPEED_RPM: - case FAN3_FRONT_SPEED_RPM: - case FAN4_FRONT_SPEED_RPM: - case FAN5_FRONT_SPEED_RPM: - case FAN6_FRONT_SPEED_RPM: - case FAN1_REAR_SPEED_RPM: - case FAN2_REAR_SPEED_RPM: - case FAN3_REAR_SPEED_RPM: - case FAN4_REAR_SPEED_RPM: - case FAN5_REAR_SPEED_RPM: - case FAN6_REAR_SPEED_RPM: - ret = sprintf(buf, "%u\n", reg_val_to_speed_rpm(data->reg_val[attr->index])); - break; - case FAN1_PRESENT: - case FAN2_PRESENT: - case FAN3_PRESENT: - case FAN4_PRESENT: - case FAN5_PRESENT: - case FAN6_PRESENT: - ret = sprintf(buf, "%d\n", - reg_val_to_is_present(data->reg_val[FAN_PRESENT_REG], - attr->index - FAN1_PRESENT)); - break; - case FAN1_FAULT: - case FAN2_FAULT: - case FAN3_FAULT: - case FAN4_FAULT: - case FAN5_FAULT: - case FAN6_FAULT: - ret = sprintf(buf, "%d\n", is_fan_fault(data, attr->index - FAN1_FAULT)); - break; - case FAN1_DIRECTION: - case FAN2_DIRECTION: - case FAN3_DIRECTION: - case FAN4_DIRECTION: - case FAN5_DIRECTION: - case FAN6_DIRECTION: - ret = sprintf(buf, "%d\n", - reg_val_to_direction(data->reg_val[FAN_DIRECTION_REG], - attr->index - FAN1_DIRECTION)); - break; - default: - break; - } + case FAN_DUTY_CYCLE_PERCENTAGE: + { + u32 duty_cycle = reg_val_to_duty_cycle(data->reg_val[FAN_DUTY_CYCLE_PERCENTAGE]); + ret = sprintf(buf, "%u\n", duty_cycle); + break; + } + case FAN1_FRONT_SPEED_RPM: + case FAN2_FRONT_SPEED_RPM: + case FAN3_FRONT_SPEED_RPM: + case FAN4_FRONT_SPEED_RPM: + case FAN5_FRONT_SPEED_RPM: + case FAN6_FRONT_SPEED_RPM: + case FAN1_REAR_SPEED_RPM: + case FAN2_REAR_SPEED_RPM: + case FAN3_REAR_SPEED_RPM: + case FAN4_REAR_SPEED_RPM: + case FAN5_REAR_SPEED_RPM: + case FAN6_REAR_SPEED_RPM: + ret = sprintf(buf, "%u\n", reg_val_to_speed_rpm(data->reg_val[attr->index])); + break; + case FAN1_PRESENT: + case FAN2_PRESENT: + case FAN3_PRESENT: + case FAN4_PRESENT: + case FAN5_PRESENT: + case FAN6_PRESENT: + ret = sprintf(buf, "%d\n", + reg_val_to_is_present(data->reg_val[FAN_PRESENT_REG], + attr->index - FAN1_PRESENT)); + break; + case FAN1_FAULT: + case FAN2_FAULT: + case FAN3_FAULT: + case FAN4_FAULT: + case FAN5_FAULT: + case FAN6_FAULT: + ret = sprintf(buf, "%d\n", is_fan_fault(data, attr->index - FAN1_FAULT)); + break; + case FAN1_DIRECTION: + case FAN2_DIRECTION: + case FAN3_DIRECTION: + case FAN4_DIRECTION: + case FAN5_DIRECTION: + case FAN6_DIRECTION: + ret = sprintf(buf, "%d\n", + reg_val_to_direction(data->reg_val[FAN_DIRECTION_REG], + attr->index - FAN1_DIRECTION)); + break; + default: + break; + } } - + return ret; } @@ -665,18 +406,18 @@ static struct as7716_32x_fan_data *as7716_32x_fan_update_device(struct device *d mutex_lock(&data->update_lock); - if (time_after(jiffies, data->last_updated + HZ + HZ / 2) || - !data->valid) { + if (time_after(jiffies, data->last_updated + HZ + HZ / 2) || + !data->valid) { int i; dev_dbg(&client->dev, "Starting as7716_32x_fan update\n"); data->valid = 0; - + /* Update fan data */ for (i = 0; i < ARRAY_SIZE(data->reg_val); i++) { int status = as7716_32x_fan_read_value(client, fan_reg[i]); - + if (status < 0) { data->valid = 0; 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->last_updated = jiffies; data->valid = 1; } - + mutex_unlock(&data->update_lock); return data; } 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; 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_name(data->hwmon_dev), client->name); - + dev_name(data->hwmon_dev), client->name); + return 0; exit_remove: @@ -742,7 +483,7 @@ static int as7716_32x_fan_probe(struct i2c_client *client, exit_free: kfree(data); exit: - + 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); hwmon_device_unregister(data->hwmon_dev); sysfs_remove_group(&client->dev.kobj, &as7716_32x_fan_group); - + return 0; } diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_cpld1.c b/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_cpld1.c old mode 100755 new mode 100644 index d2db4fb1f484..c322972481ba --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_cpld1.c +++ b/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_cpld1.c @@ -38,8 +38,8 @@ static LIST_HEAD(cpld_client_list); static struct mutex list_lock; struct cpld_client_node { - struct i2c_client *client; - struct list_head list; + struct i2c_client *client; + struct list_head list; }; #define I2C_RW_RETRY_COUNT 10 @@ -47,25 +47,25 @@ struct cpld_client_node { #define STRING_TO_DEC_VALUE 10 static ssize_t show_present(struct device *dev, struct device_attribute *da, - char *buf); + char *buf); static ssize_t show_present_all(struct device *dev, struct device_attribute *da, - char *buf); + char *buf); static ssize_t access(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); + const char *buf, size_t count); static ssize_t show_version(struct device *dev, struct device_attribute *da, - char *buf); + char *buf); static ssize_t get_mode_reset(struct device *dev, struct device_attribute *da, - char *buf); + char *buf); static ssize_t set_mode_reset(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); + const char *buf, size_t count); static int as7716_32xb_cpld_read_internal(struct i2c_client *client, u8 reg); static int as7716_32xb_cpld_write_internal(struct i2c_client *client, u8 reg, u8 value); static ssize_t sfp_value_show(struct device *dev, struct device_attribute *da, - char *buf); + char *buf); static ssize_t sfp_value_store(struct device *dev, struct device_attribute *da, - char *buf, size_t size); + const char *buf, size_t size); #define PORT_NUM_MAX 32 @@ -119,77 +119,77 @@ static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; #define TRANSCEIVER_RESET_ATTR_ID(index) MODULE_RESET_##index enum as7716_32xb_cpld_sysfs_attributes { - CPLD_VERSION, - ACCESS, - MODULE_PRESENT_ALL, - /* transceiver attributes */ - TRANSCEIVER_PRESENT_ATTR_ID(1), - TRANSCEIVER_PRESENT_ATTR_ID(2), - TRANSCEIVER_PRESENT_ATTR_ID(3), - TRANSCEIVER_PRESENT_ATTR_ID(4), - TRANSCEIVER_PRESENT_ATTR_ID(5), - TRANSCEIVER_PRESENT_ATTR_ID(6), - TRANSCEIVER_PRESENT_ATTR_ID(7), - TRANSCEIVER_PRESENT_ATTR_ID(8), - TRANSCEIVER_PRESENT_ATTR_ID(9), - TRANSCEIVER_PRESENT_ATTR_ID(10), - TRANSCEIVER_PRESENT_ATTR_ID(11), - TRANSCEIVER_PRESENT_ATTR_ID(12), - TRANSCEIVER_PRESENT_ATTR_ID(13), - TRANSCEIVER_PRESENT_ATTR_ID(14), - TRANSCEIVER_PRESENT_ATTR_ID(15), - TRANSCEIVER_PRESENT_ATTR_ID(16), - TRANSCEIVER_PRESENT_ATTR_ID(17), - TRANSCEIVER_PRESENT_ATTR_ID(18), - TRANSCEIVER_PRESENT_ATTR_ID(19), - TRANSCEIVER_PRESENT_ATTR_ID(20), - TRANSCEIVER_PRESENT_ATTR_ID(21), - TRANSCEIVER_PRESENT_ATTR_ID(22), - TRANSCEIVER_PRESENT_ATTR_ID(23), - TRANSCEIVER_PRESENT_ATTR_ID(24), - TRANSCEIVER_PRESENT_ATTR_ID(25), - TRANSCEIVER_PRESENT_ATTR_ID(26), - TRANSCEIVER_PRESENT_ATTR_ID(27), - TRANSCEIVER_PRESENT_ATTR_ID(28), - TRANSCEIVER_PRESENT_ATTR_ID(29), - TRANSCEIVER_PRESENT_ATTR_ID(30), - TRANSCEIVER_PRESENT_ATTR_ID(31), - TRANSCEIVER_PRESENT_ATTR_ID(32), - TRANSCEIVER_RESET_ATTR_ID(1), - TRANSCEIVER_RESET_ATTR_ID(2), - TRANSCEIVER_RESET_ATTR_ID(3), - TRANSCEIVER_RESET_ATTR_ID(4), - TRANSCEIVER_RESET_ATTR_ID(5), - TRANSCEIVER_RESET_ATTR_ID(6), - TRANSCEIVER_RESET_ATTR_ID(7), - TRANSCEIVER_RESET_ATTR_ID(8), - TRANSCEIVER_RESET_ATTR_ID(9), - TRANSCEIVER_RESET_ATTR_ID(10), - TRANSCEIVER_RESET_ATTR_ID(11), - TRANSCEIVER_RESET_ATTR_ID(12), - TRANSCEIVER_RESET_ATTR_ID(13), - TRANSCEIVER_RESET_ATTR_ID(14), - TRANSCEIVER_RESET_ATTR_ID(15), - TRANSCEIVER_RESET_ATTR_ID(16), - TRANSCEIVER_RESET_ATTR_ID(17), - TRANSCEIVER_RESET_ATTR_ID(18), - TRANSCEIVER_RESET_ATTR_ID(19), - TRANSCEIVER_RESET_ATTR_ID(20), - TRANSCEIVER_RESET_ATTR_ID(21), - TRANSCEIVER_RESET_ATTR_ID(22), - TRANSCEIVER_RESET_ATTR_ID(23), - TRANSCEIVER_RESET_ATTR_ID(24), - TRANSCEIVER_RESET_ATTR_ID(25), - TRANSCEIVER_RESET_ATTR_ID(26), - TRANSCEIVER_RESET_ATTR_ID(27), - TRANSCEIVER_RESET_ATTR_ID(28), - TRANSCEIVER_RESET_ATTR_ID(29), - TRANSCEIVER_RESET_ATTR_ID(30), - TRANSCEIVER_RESET_ATTR_ID(31), - TRANSCEIVER_RESET_ATTR_ID(32), + CPLD_VERSION, + ACCESS, + MODULE_PRESENT_ALL, + /* transceiver attributes */ + TRANSCEIVER_PRESENT_ATTR_ID(1), + TRANSCEIVER_PRESENT_ATTR_ID(2), + TRANSCEIVER_PRESENT_ATTR_ID(3), + TRANSCEIVER_PRESENT_ATTR_ID(4), + TRANSCEIVER_PRESENT_ATTR_ID(5), + TRANSCEIVER_PRESENT_ATTR_ID(6), + TRANSCEIVER_PRESENT_ATTR_ID(7), + TRANSCEIVER_PRESENT_ATTR_ID(8), + TRANSCEIVER_PRESENT_ATTR_ID(9), + TRANSCEIVER_PRESENT_ATTR_ID(10), + TRANSCEIVER_PRESENT_ATTR_ID(11), + TRANSCEIVER_PRESENT_ATTR_ID(12), + TRANSCEIVER_PRESENT_ATTR_ID(13), + TRANSCEIVER_PRESENT_ATTR_ID(14), + TRANSCEIVER_PRESENT_ATTR_ID(15), + TRANSCEIVER_PRESENT_ATTR_ID(16), + TRANSCEIVER_PRESENT_ATTR_ID(17), + TRANSCEIVER_PRESENT_ATTR_ID(18), + TRANSCEIVER_PRESENT_ATTR_ID(19), + TRANSCEIVER_PRESENT_ATTR_ID(20), + TRANSCEIVER_PRESENT_ATTR_ID(21), + TRANSCEIVER_PRESENT_ATTR_ID(22), + TRANSCEIVER_PRESENT_ATTR_ID(23), + TRANSCEIVER_PRESENT_ATTR_ID(24), + TRANSCEIVER_PRESENT_ATTR_ID(25), + TRANSCEIVER_PRESENT_ATTR_ID(26), + TRANSCEIVER_PRESENT_ATTR_ID(27), + TRANSCEIVER_PRESENT_ATTR_ID(28), + TRANSCEIVER_PRESENT_ATTR_ID(29), + TRANSCEIVER_PRESENT_ATTR_ID(30), + TRANSCEIVER_PRESENT_ATTR_ID(31), + TRANSCEIVER_PRESENT_ATTR_ID(32), + TRANSCEIVER_RESET_ATTR_ID(1), + TRANSCEIVER_RESET_ATTR_ID(2), + TRANSCEIVER_RESET_ATTR_ID(3), + TRANSCEIVER_RESET_ATTR_ID(4), + TRANSCEIVER_RESET_ATTR_ID(5), + TRANSCEIVER_RESET_ATTR_ID(6), + TRANSCEIVER_RESET_ATTR_ID(7), + TRANSCEIVER_RESET_ATTR_ID(8), + TRANSCEIVER_RESET_ATTR_ID(9), + TRANSCEIVER_RESET_ATTR_ID(10), + TRANSCEIVER_RESET_ATTR_ID(11), + TRANSCEIVER_RESET_ATTR_ID(12), + TRANSCEIVER_RESET_ATTR_ID(13), + TRANSCEIVER_RESET_ATTR_ID(14), + TRANSCEIVER_RESET_ATTR_ID(15), + TRANSCEIVER_RESET_ATTR_ID(16), + TRANSCEIVER_RESET_ATTR_ID(17), + TRANSCEIVER_RESET_ATTR_ID(18), + TRANSCEIVER_RESET_ATTR_ID(19), + TRANSCEIVER_RESET_ATTR_ID(20), + TRANSCEIVER_RESET_ATTR_ID(21), + TRANSCEIVER_RESET_ATTR_ID(22), + TRANSCEIVER_RESET_ATTR_ID(23), + TRANSCEIVER_RESET_ATTR_ID(24), + TRANSCEIVER_RESET_ATTR_ID(25), + TRANSCEIVER_RESET_ATTR_ID(26), + TRANSCEIVER_RESET_ATTR_ID(27), + TRANSCEIVER_RESET_ATTR_ID(28), + TRANSCEIVER_RESET_ATTR_ID(29), + TRANSCEIVER_RESET_ATTR_ID(30), + TRANSCEIVER_RESET_ATTR_ID(31), + TRANSCEIVER_RESET_ATTR_ID(32), }; -/* sysfs attributes for hwmon +/* sysfs attributes for hwmon */ /* transceiver attributes */ @@ -283,93 +283,93 @@ DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(32); static struct attribute *as7716_32xb_cpld_attributes[] = { &sensor_dev_attr_version.dev_attr.attr, &sensor_dev_attr_access.dev_attr.attr, - /* transceiver attributes */ - &sensor_dev_attr_module_present_all.dev_attr.attr, - DECLARE_TRANSCEIVER_ATTR(1), - DECLARE_TRANSCEIVER_ATTR(2), - DECLARE_TRANSCEIVER_ATTR(3), - DECLARE_TRANSCEIVER_ATTR(4), - DECLARE_TRANSCEIVER_ATTR(5), - DECLARE_TRANSCEIVER_ATTR(6), - DECLARE_TRANSCEIVER_ATTR(7), - DECLARE_TRANSCEIVER_ATTR(8), - DECLARE_TRANSCEIVER_ATTR(9), - DECLARE_TRANSCEIVER_ATTR(10), - DECLARE_TRANSCEIVER_ATTR(11), - DECLARE_TRANSCEIVER_ATTR(12), - DECLARE_TRANSCEIVER_ATTR(13), - DECLARE_TRANSCEIVER_ATTR(14), - DECLARE_TRANSCEIVER_ATTR(15), - DECLARE_TRANSCEIVER_ATTR(16), - DECLARE_TRANSCEIVER_ATTR(17), - DECLARE_TRANSCEIVER_ATTR(18), - DECLARE_TRANSCEIVER_ATTR(19), - DECLARE_TRANSCEIVER_ATTR(20), - DECLARE_TRANSCEIVER_ATTR(21), - DECLARE_TRANSCEIVER_ATTR(22), - DECLARE_TRANSCEIVER_ATTR(23), - DECLARE_TRANSCEIVER_ATTR(24), - DECLARE_TRANSCEIVER_ATTR(25), - DECLARE_TRANSCEIVER_ATTR(26), - DECLARE_TRANSCEIVER_ATTR(27), - DECLARE_TRANSCEIVER_ATTR(28), - DECLARE_TRANSCEIVER_ATTR(29), - DECLARE_TRANSCEIVER_ATTR(30), - DECLARE_TRANSCEIVER_ATTR(31), - DECLARE_TRANSCEIVER_ATTR(32), - DECLARE_TRANSCEIVER_RESET_ATTR(1), - DECLARE_TRANSCEIVER_RESET_ATTR(2), - DECLARE_TRANSCEIVER_RESET_ATTR(3), - DECLARE_TRANSCEIVER_RESET_ATTR(4), - DECLARE_TRANSCEIVER_RESET_ATTR(5), - DECLARE_TRANSCEIVER_RESET_ATTR(6), - DECLARE_TRANSCEIVER_RESET_ATTR(7), - DECLARE_TRANSCEIVER_RESET_ATTR(8), - DECLARE_TRANSCEIVER_RESET_ATTR(9), - DECLARE_TRANSCEIVER_RESET_ATTR(10), - DECLARE_TRANSCEIVER_RESET_ATTR(11), - DECLARE_TRANSCEIVER_RESET_ATTR(12), - DECLARE_TRANSCEIVER_RESET_ATTR(13), - DECLARE_TRANSCEIVER_RESET_ATTR(14), - DECLARE_TRANSCEIVER_RESET_ATTR(15), - DECLARE_TRANSCEIVER_RESET_ATTR(16), - DECLARE_TRANSCEIVER_RESET_ATTR(17), - DECLARE_TRANSCEIVER_RESET_ATTR(18), - DECLARE_TRANSCEIVER_RESET_ATTR(19), - DECLARE_TRANSCEIVER_RESET_ATTR(20), - DECLARE_TRANSCEIVER_RESET_ATTR(21), - DECLARE_TRANSCEIVER_RESET_ATTR(22), - DECLARE_TRANSCEIVER_RESET_ATTR(23), - DECLARE_TRANSCEIVER_RESET_ATTR(24), - DECLARE_TRANSCEIVER_RESET_ATTR(25), - DECLARE_TRANSCEIVER_RESET_ATTR(26), - DECLARE_TRANSCEIVER_RESET_ATTR(27), - DECLARE_TRANSCEIVER_RESET_ATTR(28), - DECLARE_TRANSCEIVER_RESET_ATTR(29), - DECLARE_TRANSCEIVER_RESET_ATTR(30), - DECLARE_TRANSCEIVER_RESET_ATTR(31), - DECLARE_TRANSCEIVER_RESET_ATTR(32), - NULL + /* transceiver attributes */ + &sensor_dev_attr_module_present_all.dev_attr.attr, + DECLARE_TRANSCEIVER_ATTR(1), + DECLARE_TRANSCEIVER_ATTR(2), + DECLARE_TRANSCEIVER_ATTR(3), + DECLARE_TRANSCEIVER_ATTR(4), + DECLARE_TRANSCEIVER_ATTR(5), + DECLARE_TRANSCEIVER_ATTR(6), + DECLARE_TRANSCEIVER_ATTR(7), + DECLARE_TRANSCEIVER_ATTR(8), + DECLARE_TRANSCEIVER_ATTR(9), + DECLARE_TRANSCEIVER_ATTR(10), + DECLARE_TRANSCEIVER_ATTR(11), + DECLARE_TRANSCEIVER_ATTR(12), + DECLARE_TRANSCEIVER_ATTR(13), + DECLARE_TRANSCEIVER_ATTR(14), + DECLARE_TRANSCEIVER_ATTR(15), + DECLARE_TRANSCEIVER_ATTR(16), + DECLARE_TRANSCEIVER_ATTR(17), + DECLARE_TRANSCEIVER_ATTR(18), + DECLARE_TRANSCEIVER_ATTR(19), + DECLARE_TRANSCEIVER_ATTR(20), + DECLARE_TRANSCEIVER_ATTR(21), + DECLARE_TRANSCEIVER_ATTR(22), + DECLARE_TRANSCEIVER_ATTR(23), + DECLARE_TRANSCEIVER_ATTR(24), + DECLARE_TRANSCEIVER_ATTR(25), + DECLARE_TRANSCEIVER_ATTR(26), + DECLARE_TRANSCEIVER_ATTR(27), + DECLARE_TRANSCEIVER_ATTR(28), + DECLARE_TRANSCEIVER_ATTR(29), + DECLARE_TRANSCEIVER_ATTR(30), + DECLARE_TRANSCEIVER_ATTR(31), + DECLARE_TRANSCEIVER_ATTR(32), + DECLARE_TRANSCEIVER_RESET_ATTR(1), + DECLARE_TRANSCEIVER_RESET_ATTR(2), + DECLARE_TRANSCEIVER_RESET_ATTR(3), + DECLARE_TRANSCEIVER_RESET_ATTR(4), + DECLARE_TRANSCEIVER_RESET_ATTR(5), + DECLARE_TRANSCEIVER_RESET_ATTR(6), + DECLARE_TRANSCEIVER_RESET_ATTR(7), + DECLARE_TRANSCEIVER_RESET_ATTR(8), + DECLARE_TRANSCEIVER_RESET_ATTR(9), + DECLARE_TRANSCEIVER_RESET_ATTR(10), + DECLARE_TRANSCEIVER_RESET_ATTR(11), + DECLARE_TRANSCEIVER_RESET_ATTR(12), + DECLARE_TRANSCEIVER_RESET_ATTR(13), + DECLARE_TRANSCEIVER_RESET_ATTR(14), + DECLARE_TRANSCEIVER_RESET_ATTR(15), + DECLARE_TRANSCEIVER_RESET_ATTR(16), + DECLARE_TRANSCEIVER_RESET_ATTR(17), + DECLARE_TRANSCEIVER_RESET_ATTR(18), + DECLARE_TRANSCEIVER_RESET_ATTR(19), + DECLARE_TRANSCEIVER_RESET_ATTR(20), + DECLARE_TRANSCEIVER_RESET_ATTR(21), + DECLARE_TRANSCEIVER_RESET_ATTR(22), + DECLARE_TRANSCEIVER_RESET_ATTR(23), + DECLARE_TRANSCEIVER_RESET_ATTR(24), + DECLARE_TRANSCEIVER_RESET_ATTR(25), + DECLARE_TRANSCEIVER_RESET_ATTR(26), + DECLARE_TRANSCEIVER_RESET_ATTR(27), + DECLARE_TRANSCEIVER_RESET_ATTR(28), + DECLARE_TRANSCEIVER_RESET_ATTR(29), + DECLARE_TRANSCEIVER_RESET_ATTR(30), + DECLARE_TRANSCEIVER_RESET_ATTR(31), + DECLARE_TRANSCEIVER_RESET_ATTR(32), + NULL }; static const struct attribute_group as7716_32xb_cpld_group = { - .attrs = as7716_32xb_cpld_attributes, + .attrs = as7716_32xb_cpld_attributes, }; static ssize_t show_present_all(struct device *dev, struct device_attribute *da, - char *buf) + char *buf) { - int i, status; - u8 values[4] = {0}; - u8 regs[] = {0x30, 0x31, 0x32, 0x33}; - struct i2c_client *client = to_i2c_client(dev); - struct as7716_32xb_cpld_data *data = i2c_get_clientdata(client); + int i, status; + u8 values[4] = {0}; + u8 regs[] = {0x30, 0x31, 0x32, 0x33}; + struct i2c_client *client = to_i2c_client(dev); + struct as7716_32xb_cpld_data *data = i2c_get_clientdata(client); - mutex_lock(&data->update_lock); + mutex_lock(&data->update_lock); for (i = 0; i < ARRAY_SIZE(regs); i++) { status = as7716_32xb_cpld_read_internal(client, regs[i]); - + if (status < 0) { goto exit; } @@ -377,7 +377,7 @@ static ssize_t show_present_all(struct device *dev, struct device_attribute *da, values[i] = ~(u8)status; } - mutex_unlock(&data->update_lock); + mutex_unlock(&data->update_lock); /* Return values 1 -> 32 in order */ return sprintf(buf, "%.2x %.2x %.2x %.2x\n", @@ -385,118 +385,118 @@ static ssize_t show_present_all(struct device *dev, struct device_attribute *da, values[3]); exit: - mutex_unlock(&data->update_lock); - return status; + mutex_unlock(&data->update_lock); + return status; } static int sfp_array_index_get(int attr_idx) -{ - switch(attr_idx) - { - case TRANSCEIVER_PRESENT_ATTR_ID(1): - case TRANSCEIVER_RESET_ATTR_ID(1): - return PORT1_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(2): - case TRANSCEIVER_RESET_ATTR_ID(2): - return PORT2_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(3): - case TRANSCEIVER_RESET_ATTR_ID(3): - return PORT3_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(4): - case TRANSCEIVER_RESET_ATTR_ID(4): - return PORT4_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(5): - case TRANSCEIVER_RESET_ATTR_ID(5): - return PORT5_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(6): - case TRANSCEIVER_RESET_ATTR_ID(6): - return PORT6_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(7): - case TRANSCEIVER_RESET_ATTR_ID(7): - return PORT7_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(8): - case TRANSCEIVER_RESET_ATTR_ID(8): - return PORT8_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(9): - case TRANSCEIVER_RESET_ATTR_ID(9): - return PORT9_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(10): - case TRANSCEIVER_RESET_ATTR_ID(10): - return PORT10_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(11): - case TRANSCEIVER_RESET_ATTR_ID(11): - return PORT11_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(12): - case TRANSCEIVER_RESET_ATTR_ID(12): - return PORT12_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(13): - case TRANSCEIVER_RESET_ATTR_ID(13): - return PORT13_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(14): - case TRANSCEIVER_RESET_ATTR_ID(14): - return PORT14_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(15): - case TRANSCEIVER_RESET_ATTR_ID(15): - return PORT15_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(16): - case TRANSCEIVER_RESET_ATTR_ID(16): - return PORT16_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(17): - case TRANSCEIVER_RESET_ATTR_ID(17): - return PORT17_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(18): - case TRANSCEIVER_RESET_ATTR_ID(18): - return PORT18_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(19): - case TRANSCEIVER_RESET_ATTR_ID(19): - return PORT19_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(20): - case TRANSCEIVER_RESET_ATTR_ID(20): - return PORT20_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(21): - case TRANSCEIVER_RESET_ATTR_ID(21): - return PORT21_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(22): - case TRANSCEIVER_RESET_ATTR_ID(22): - return PORT22_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(23): - case TRANSCEIVER_RESET_ATTR_ID(23): - return PORT23_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(24): - case TRANSCEIVER_RESET_ATTR_ID(24): - return PORT24_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(25): - case TRANSCEIVER_RESET_ATTR_ID(25): - return PORT25_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(26): - case TRANSCEIVER_RESET_ATTR_ID(26): - return PORT26_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(27): - case TRANSCEIVER_RESET_ATTR_ID(27): - return PORT27_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(28): - case TRANSCEIVER_RESET_ATTR_ID(28): - return PORT28_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(29): - case TRANSCEIVER_RESET_ATTR_ID(29): - return PORT29_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(30): - case TRANSCEIVER_RESET_ATTR_ID(30): - return PORT30_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(31): - case TRANSCEIVER_RESET_ATTR_ID(31): - return PORT31_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(32): - case TRANSCEIVER_RESET_ATTR_ID(32): - return PORT32_ID; - default : - return -1; - } +{ + switch(attr_idx) + { + case TRANSCEIVER_PRESENT_ATTR_ID(1): + case TRANSCEIVER_RESET_ATTR_ID(1): + return PORT1_ID; + case TRANSCEIVER_PRESENT_ATTR_ID(2): + case TRANSCEIVER_RESET_ATTR_ID(2): + return PORT2_ID; + case TRANSCEIVER_PRESENT_ATTR_ID(3): + case TRANSCEIVER_RESET_ATTR_ID(3): + return PORT3_ID; + case TRANSCEIVER_PRESENT_ATTR_ID(4): + case TRANSCEIVER_RESET_ATTR_ID(4): + return PORT4_ID; + case TRANSCEIVER_PRESENT_ATTR_ID(5): + case TRANSCEIVER_RESET_ATTR_ID(5): + return PORT5_ID; + case TRANSCEIVER_PRESENT_ATTR_ID(6): + case TRANSCEIVER_RESET_ATTR_ID(6): + return PORT6_ID; + case TRANSCEIVER_PRESENT_ATTR_ID(7): + case TRANSCEIVER_RESET_ATTR_ID(7): + return PORT7_ID; + case TRANSCEIVER_PRESENT_ATTR_ID(8): + case TRANSCEIVER_RESET_ATTR_ID(8): + return PORT8_ID; + case TRANSCEIVER_PRESENT_ATTR_ID(9): + case TRANSCEIVER_RESET_ATTR_ID(9): + return PORT9_ID; + case TRANSCEIVER_PRESENT_ATTR_ID(10): + case TRANSCEIVER_RESET_ATTR_ID(10): + return PORT10_ID; + case TRANSCEIVER_PRESENT_ATTR_ID(11): + case TRANSCEIVER_RESET_ATTR_ID(11): + return PORT11_ID; + case TRANSCEIVER_PRESENT_ATTR_ID(12): + case TRANSCEIVER_RESET_ATTR_ID(12): + return PORT12_ID; + case TRANSCEIVER_PRESENT_ATTR_ID(13): + case TRANSCEIVER_RESET_ATTR_ID(13): + return PORT13_ID; + case TRANSCEIVER_PRESENT_ATTR_ID(14): + case TRANSCEIVER_RESET_ATTR_ID(14): + return PORT14_ID; + case TRANSCEIVER_PRESENT_ATTR_ID(15): + case TRANSCEIVER_RESET_ATTR_ID(15): + return PORT15_ID; + case TRANSCEIVER_PRESENT_ATTR_ID(16): + case TRANSCEIVER_RESET_ATTR_ID(16): + return PORT16_ID; + case TRANSCEIVER_PRESENT_ATTR_ID(17): + case TRANSCEIVER_RESET_ATTR_ID(17): + return PORT17_ID; + case TRANSCEIVER_PRESENT_ATTR_ID(18): + case TRANSCEIVER_RESET_ATTR_ID(18): + return PORT18_ID; + case TRANSCEIVER_PRESENT_ATTR_ID(19): + case TRANSCEIVER_RESET_ATTR_ID(19): + return PORT19_ID; + case TRANSCEIVER_PRESENT_ATTR_ID(20): + case TRANSCEIVER_RESET_ATTR_ID(20): + return PORT20_ID; + case TRANSCEIVER_PRESENT_ATTR_ID(21): + case TRANSCEIVER_RESET_ATTR_ID(21): + return PORT21_ID; + case TRANSCEIVER_PRESENT_ATTR_ID(22): + case TRANSCEIVER_RESET_ATTR_ID(22): + return PORT22_ID; + case TRANSCEIVER_PRESENT_ATTR_ID(23): + case TRANSCEIVER_RESET_ATTR_ID(23): + return PORT23_ID; + case TRANSCEIVER_PRESENT_ATTR_ID(24): + case TRANSCEIVER_RESET_ATTR_ID(24): + return PORT24_ID; + case TRANSCEIVER_PRESENT_ATTR_ID(25): + case TRANSCEIVER_RESET_ATTR_ID(25): + return PORT25_ID; + case TRANSCEIVER_PRESENT_ATTR_ID(26): + case TRANSCEIVER_RESET_ATTR_ID(26): + return PORT26_ID; + case TRANSCEIVER_PRESENT_ATTR_ID(27): + case TRANSCEIVER_RESET_ATTR_ID(27): + return PORT27_ID; + case TRANSCEIVER_PRESENT_ATTR_ID(28): + case TRANSCEIVER_RESET_ATTR_ID(28): + return PORT28_ID; + case TRANSCEIVER_PRESENT_ATTR_ID(29): + case TRANSCEIVER_RESET_ATTR_ID(29): + return PORT29_ID; + case TRANSCEIVER_PRESENT_ATTR_ID(30): + case TRANSCEIVER_RESET_ATTR_ID(30): + return PORT30_ID; + case TRANSCEIVER_PRESENT_ATTR_ID(31): + case TRANSCEIVER_RESET_ATTR_ID(31): + return PORT31_ID; + case TRANSCEIVER_PRESENT_ATTR_ID(32): + case TRANSCEIVER_RESET_ATTR_ID(32): + return PORT32_ID; + default : + return -1; + } } - + static ssize_t sfp_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 i2c_client *client = to_i2c_client(dev); @@ -504,272 +504,272 @@ static ssize_t sfp_value_store(struct device *dev, struct device_attribute *da, int status = -EINVAL; int index; long keyin = 0; - + //printk("sfp_value_store\n"); //printk("attr->index=%d\n", attr->index); mutex_lock(&data->update_lock); switch (attr->index) - { - case MODULE_PRESENT_1 ... MODULE_PRESENT_8: - case MODULE_PRESENT_9 ... MODULE_PRESENT_16: - case MODULE_PRESENT_17 ... MODULE_PRESENT_24: - case MODULE_PRESENT_25 ... MODULE_PRESENT_32: - index=sfp_array_index_get(attr->index); - if(index < 0 || index > PORT_NUM_MAX -1) - break; - status = kstrtol(buf, STRING_TO_DEC_VALUE, &keyin); - if(keyin < 0 || keyin > 1) - break; - data->present[index]=keyin; - break; - case MODULE_RESET_1 ... MODULE_RESET_8: - case MODULE_RESET_9 ... MODULE_RESET_16: - case MODULE_RESET_17 ... MODULE_RESET_24: - case MODULE_RESET_25 ... MODULE_RESET_32: - index=sfp_array_index_get(attr->index); - if(index < 0 || index > PORT_NUM_MAX -1) - break; - status = kstrtol(buf, STRING_TO_DEC_VALUE, &keyin); - if(keyin < 0 || keyin > 1) - break; - data->reset[index]=keyin; - break; - default : - break; + { + case MODULE_PRESENT_1 ... MODULE_PRESENT_8: + case MODULE_PRESENT_9 ... MODULE_PRESENT_16: + case MODULE_PRESENT_17 ... MODULE_PRESENT_24: + case MODULE_PRESENT_25 ... MODULE_PRESENT_32: + index=sfp_array_index_get(attr->index); + if(index < 0 || index > PORT_NUM_MAX -1) + break; + status = kstrtol(buf, STRING_TO_DEC_VALUE, &keyin); + if(keyin < 0 || keyin > 1) + break; + data->present[index]=keyin; + break; + case MODULE_RESET_1 ... MODULE_RESET_8: + case MODULE_RESET_9 ... MODULE_RESET_16: + case MODULE_RESET_17 ... MODULE_RESET_24: + case MODULE_RESET_25 ... MODULE_RESET_32: + index=sfp_array_index_get(attr->index); + if(index < 0 || index > PORT_NUM_MAX -1) + break; + status = kstrtol(buf, STRING_TO_DEC_VALUE, &keyin); + if(keyin < 0 || keyin > 1) + break; + data->reset[index]=keyin; + break; + default : + break; } - mutex_unlock(&data->update_lock); + mutex_unlock(&data->update_lock); return size; } static ssize_t sfp_value_show(struct device *dev, struct device_attribute *da, - char *buf) + char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(da); struct i2c_client *client = to_i2c_client(dev); struct as7716_32xb_cpld_data *data = i2c_get_clientdata(client); ssize_t ret = 0; - int index; + int index; int status = -EINVAL; - + //printk("sfp_value_show, attr->index=%d\n", attr->index); //printk("TRANSCEIVER_PRESENT_ATTR_ID(1)=%d, TRANSCEIVER_RESET_ATTR_ID(1)=%d\n", TRANSCEIVER_PRESENT_ATTR_ID(1), TRANSCEIVER_RESET_ATTR_ID(1)); mutex_lock(&data->update_lock); switch (attr->index) { - case MODULE_PRESENT_1 ... MODULE_PRESENT_8: - case MODULE_PRESENT_9 ... MODULE_PRESENT_16: - case MODULE_PRESENT_17 ... MODULE_PRESENT_24: - case MODULE_PRESENT_25 ... MODULE_PRESENT_32: - index=sfp_array_index_get(attr->index); - if(index < 0 || index > PORT_NUM_MAX -1) - break; - status = sprintf(buf, "%u\n", data->present[index]); - break; - case MODULE_RESET_1 ... MODULE_RESET_8: - case MODULE_RESET_9 ... MODULE_RESET_16: - case MODULE_RESET_17 ... MODULE_RESET_24: - case MODULE_RESET_25 ... MODULE_RESET_32: - index=sfp_array_index_get(attr->index); - //printk("rst:attr->index=%d, index=%d\n",attr->index, index); - if(index < 0 || index > PORT_NUM_MAX -1) - break; - status = sprintf(buf, "%u\n", data->reset[index]); - break; - default : - break; - } - + case MODULE_PRESENT_1 ... MODULE_PRESENT_8: + case MODULE_PRESENT_9 ... MODULE_PRESENT_16: + case MODULE_PRESENT_17 ... MODULE_PRESENT_24: + case MODULE_PRESENT_25 ... MODULE_PRESENT_32: + index=sfp_array_index_get(attr->index); + if(index < 0 || index > PORT_NUM_MAX -1) + break; + status = sprintf(buf, "%u\n", data->present[index]); + break; + case MODULE_RESET_1 ... MODULE_RESET_8: + case MODULE_RESET_9 ... MODULE_RESET_16: + case MODULE_RESET_17 ... MODULE_RESET_24: + case MODULE_RESET_25 ... MODULE_RESET_32: + index=sfp_array_index_get(attr->index); + //printk("rst:attr->index=%d, index=%d\n",attr->index, index); + if(index < 0 || index > PORT_NUM_MAX -1) + break; + status = sprintf(buf, "%u\n", data->reset[index]); + break; + default : + break; + } + mutex_unlock(&data->update_lock); return status; } static ssize_t show_present(struct device *dev, struct device_attribute *da, - char *buf) + char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(da); struct i2c_client *client = to_i2c_client(dev); struct as7716_32xb_cpld_data *data = i2c_get_clientdata(client); - int status = 0; - u8 reg = 0, mask = 0; - - switch (attr->index) { - case MODULE_PRESENT_1 ... MODULE_PRESENT_8: - reg = 0x30; - mask = 0x1 << (attr->index - MODULE_PRESENT_1); - break; - case MODULE_PRESENT_9 ... MODULE_PRESENT_16: - reg = 0x31; - mask = 0x1 << (attr->index - MODULE_PRESENT_9); - break; - case MODULE_PRESENT_17 ... MODULE_PRESENT_24: - reg = 0x32; - mask = 0x1 << (attr->index - MODULE_PRESENT_17); - break; - case MODULE_PRESENT_25 ... MODULE_PRESENT_32: - reg = 0x33; - mask = 0x1 << (attr->index - MODULE_PRESENT_25); - break; - default: - return 0; - } + int status = 0; + u8 reg = 0, mask = 0; + + switch (attr->index) { + case MODULE_PRESENT_1 ... MODULE_PRESENT_8: + reg = 0x30; + mask = 0x1 << (attr->index - MODULE_PRESENT_1); + break; + case MODULE_PRESENT_9 ... MODULE_PRESENT_16: + reg = 0x31; + mask = 0x1 << (attr->index - MODULE_PRESENT_9); + break; + case MODULE_PRESENT_17 ... MODULE_PRESENT_24: + reg = 0x32; + mask = 0x1 << (attr->index - MODULE_PRESENT_17); + break; + case MODULE_PRESENT_25 ... MODULE_PRESENT_32: + reg = 0x33; + mask = 0x1 << (attr->index - MODULE_PRESENT_25); + break; + default: + return 0; + } mutex_lock(&data->update_lock); - status = as7716_32xb_cpld_read_internal(client, reg); - if (unlikely(status < 0)) { - goto exit; - } - mutex_unlock(&data->update_lock); + status = as7716_32xb_cpld_read_internal(client, reg); + if (unlikely(status < 0)) { + goto exit; + } + mutex_unlock(&data->update_lock); - return sprintf(buf, "%d\n", !(status & mask)); + return sprintf(buf, "%d\n", !(status & mask)); exit: - mutex_unlock(&data->update_lock); - return status; + mutex_unlock(&data->update_lock); + return status; } static ssize_t show_version(struct device *dev, struct device_attribute *da, - char *buf) + char *buf) { - u8 reg = 0, mask = 0; + u8 reg = 0, mask = 0; struct sensor_device_attribute *attr = to_sensor_dev_attr(da); struct i2c_client *client = to_i2c_client(dev); struct as7716_32xb_cpld_data *data = i2c_get_clientdata(client); - int status = 0; + int status = 0; - switch (attr->index) { - case CPLD_VERSION: - reg = 0x1; - mask = 0xFF; - break; - default: - break; - } + switch (attr->index) { + case CPLD_VERSION: + reg = 0x1; + mask = 0xFF; + break; + default: + break; + } mutex_lock(&data->update_lock); - status = as7716_32xb_cpld_read_internal(client, reg); - if (unlikely(status < 0)) { - goto exit; - } - mutex_unlock(&data->update_lock); - return sprintf(buf, "%d\n", (status & mask)); + status = as7716_32xb_cpld_read_internal(client, reg); + if (unlikely(status < 0)) { + goto exit; + } + mutex_unlock(&data->update_lock); + return sprintf(buf, "%d\n", (status & mask)); exit: - mutex_unlock(&data->update_lock); - return status; + mutex_unlock(&data->update_lock); + return status; } static ssize_t access(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) + const char *buf, size_t count) { - int status; - u32 addr, val; + int status; + u32 addr, val; struct i2c_client *client = to_i2c_client(dev); struct as7716_32xb_cpld_data *data = i2c_get_clientdata(client); - if (sscanf(buf, "0x%x 0x%x", &addr, &val) != 2) { - return -EINVAL; - } + if (sscanf(buf, "0x%x 0x%x", &addr, &val) != 2) { + return -EINVAL; + } - if (addr > 0xFF || val > 0xFF) { - return -EINVAL; - } + if (addr > 0xFF || val > 0xFF) { + return -EINVAL; + } - mutex_lock(&data->update_lock); - status = as7716_32xb_cpld_write_internal(client, addr, val); - if (unlikely(status < 0)) { - goto exit; - } - mutex_unlock(&data->update_lock); - return count; + mutex_lock(&data->update_lock); + status = as7716_32xb_cpld_write_internal(client, addr, val); + if (unlikely(status < 0)) { + goto exit; + } + mutex_unlock(&data->update_lock); + return count; exit: - mutex_unlock(&data->update_lock); - return status; + mutex_unlock(&data->update_lock); + return status; } static int as7716_32xb_cpld_read_internal(struct i2c_client *client, u8 reg) { - int status = 0, retry = I2C_RW_RETRY_COUNT; - - while (retry) { - status = i2c_smbus_read_byte_data(client, reg); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } + int status = 0, retry = I2C_RW_RETRY_COUNT; + + while (retry) { + status = i2c_smbus_read_byte_data(client, reg); + if (unlikely(status < 0)) { + msleep(I2C_RW_RETRY_INTERVAL); + retry--; + continue; + } - break; - } + break; + } return status; } static int as7716_32xb_cpld_write_internal(struct i2c_client *client, u8 reg, u8 value) { - int status = 0, retry = I2C_RW_RETRY_COUNT; - - while (retry) { - status = i2c_smbus_write_byte_data(client, reg, value); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } + int status = 0, retry = I2C_RW_RETRY_COUNT; + + while (retry) { + status = i2c_smbus_write_byte_data(client, reg, value); + if (unlikely(status < 0)) { + msleep(I2C_RW_RETRY_INTERVAL); + retry--; + continue; + } - break; - } + break; + } return status; } static void as7716_32xb_cpld_add_client(struct i2c_client *client) { - struct cpld_client_node *node = kzalloc(sizeof(struct cpld_client_node), GFP_KERNEL); - - if (!node) { - dev_dbg(&client->dev, "Can't allocate cpld_client_node (0x%x)\n", client->addr); - return; - } - - node->client = client; - - mutex_lock(&list_lock); - list_add(&node->list, &cpld_client_list); - mutex_unlock(&list_lock); + struct cpld_client_node *node = kzalloc(sizeof(struct cpld_client_node), GFP_KERNEL); + + if (!node) { + dev_dbg(&client->dev, "Can't allocate cpld_client_node (0x%x)\n", client->addr); + return; + } + + node->client = client; + + mutex_lock(&list_lock); + list_add(&node->list, &cpld_client_list); + mutex_unlock(&list_lock); } static void as7716_32xb_cpld_remove_client(struct i2c_client *client) { - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int found = 0; - - mutex_lock(&list_lock); - - list_for_each(list_node, &cpld_client_list) - { - cpld_node = list_entry(list_node, struct cpld_client_node, list); - - if (cpld_node->client == client) { - found = 1; - break; - } - } - - if (found) { - list_del(list_node); - kfree(cpld_node); - } - - mutex_unlock(&list_lock); + struct list_head *list_node = NULL; + struct cpld_client_node *cpld_node = NULL; + int found = 0; + + mutex_lock(&list_lock); + + list_for_each(list_node, &cpld_client_list) + { + cpld_node = list_entry(list_node, struct cpld_client_node, list); + + if (cpld_node->client == client) { + found = 1; + break; + } + } + + if (found) { + list_del(list_node); + kfree(cpld_node); + } + + mutex_unlock(&list_lock); } static int as7716_32xb_cpld_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) + const struct i2c_device_id *dev_id) { int status; - struct as7716_32xb_cpld_data *data = NULL; + struct as7716_32xb_cpld_data *data = NULL; data = kzalloc(sizeof(struct as7716_32xb_cpld_data), GFP_KERNEL); if (!data) { @@ -781,22 +781,22 @@ static int as7716_32xb_cpld_probe(struct i2c_client *client, mutex_init(&data->update_lock); dev_info(&client->dev, "chip found\n"); - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &as7716_32xb_cpld_group); - if (status) { - goto exit_free; - } + /* Register sysfs hooks */ + status = sysfs_create_group(&client->dev.kobj, &as7716_32xb_cpld_group); + if (status) { + goto exit_free; + } - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } + data->hwmon_dev = hwmon_device_register(&client->dev); + if (IS_ERR(data->hwmon_dev)) { + status = PTR_ERR(data->hwmon_dev); + goto exit_remove; + } - as7716_32xb_cpld_add_client(client); + as7716_32xb_cpld_add_client(client); - dev_info(&client->dev, "%s: cpld '%s'\n", - dev_name(data->hwmon_dev), client->name); + dev_info(&client->dev, "%s: cpld '%s'\n", + dev_name(data->hwmon_dev), client->name); return 0; @@ -805,7 +805,7 @@ static int as7716_32xb_cpld_probe(struct i2c_client *client, exit_free: kfree(data); exit: - + return status; } @@ -816,115 +816,115 @@ static int as7716_32xb_cpld_remove(struct i2c_client *client) hwmon_device_unregister(data->hwmon_dev); sysfs_remove_group(&client->dev.kobj, &as7716_32xb_cpld_group); kfree(data); - as7716_32xb_cpld_remove_client(client); + as7716_32xb_cpld_remove_client(client); return 0; } int as7716_32xb_cpld_read(unsigned short cpld_addr, u8 reg) { - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int ret = -EPERM; - - mutex_lock(&list_lock); - - list_for_each(list_node, &cpld_client_list) - { - cpld_node = list_entry(list_node, struct cpld_client_node, list); - - if (cpld_node->client->addr == cpld_addr) { - ret = i2c_smbus_read_byte_data(cpld_node->client, reg); - break; - } - } - - mutex_unlock(&list_lock); - - return ret; + struct list_head *list_node = NULL; + struct cpld_client_node *cpld_node = NULL; + int ret = -EPERM; + + mutex_lock(&list_lock); + + list_for_each(list_node, &cpld_client_list) + { + cpld_node = list_entry(list_node, struct cpld_client_node, list); + + if (cpld_node->client->addr == cpld_addr) { + ret = i2c_smbus_read_byte_data(cpld_node->client, reg); + break; + } + } + + mutex_unlock(&list_lock); + + return ret; } EXPORT_SYMBOL(as7716_32xb_cpld_read); int as7716_32xb_cpld_write(unsigned short cpld_addr, u8 reg, u8 value) { - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int ret = -EIO; - - mutex_lock(&list_lock); - - list_for_each(list_node, &cpld_client_list) - { - cpld_node = list_entry(list_node, struct cpld_client_node, list); - - if (cpld_node->client->addr == cpld_addr) { - ret = i2c_smbus_write_byte_data(cpld_node->client, reg, value); - break; - } - } - - mutex_unlock(&list_lock); - - return ret; + struct list_head *list_node = NULL; + struct cpld_client_node *cpld_node = NULL; + int ret = -EIO; + + mutex_lock(&list_lock); + + list_for_each(list_node, &cpld_client_list) + { + cpld_node = list_entry(list_node, struct cpld_client_node, list); + + if (cpld_node->client->addr == cpld_addr) { + ret = i2c_smbus_write_byte_data(cpld_node->client, reg, value); + break; + } + } + + mutex_unlock(&list_lock); + + return ret; } EXPORT_SYMBOL(as7716_32xb_cpld_write); static ssize_t get_mode_reset(struct device *dev, struct device_attribute *da, - char *buf) + char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(da); struct i2c_client *client = to_i2c_client(dev); struct as7716_32xb_cpld_data *data = i2c_get_clientdata(client); - int status = 0; - u8 reg = 0, mask = 0; - - switch (attr->index) { - case MODULE_RESET_1 ... MODULE_RESET_8: - reg = 0x04; - mask = 0x1 << (attr->index - MODULE_RESET_1); - break; - case MODULE_RESET_9 ... MODULE_RESET_16: - reg = 0x05; - mask = 0x1 << (attr->index - MODULE_RESET_9); - break; - case MODULE_RESET_17 ... MODULE_RESET_24: - reg = 0x06; - mask = 0x1 << (attr->index - MODULE_RESET_17); - break; - case MODULE_RESET_25 ... MODULE_RESET_32: - reg = 0x07; - mask = 0x1 << (attr->index - MODULE_RESET_25); - break; - default: - return 0; - } + int status = 0; + u8 reg = 0, mask = 0; + + switch (attr->index) { + case MODULE_RESET_1 ... MODULE_RESET_8: + reg = 0x04; + mask = 0x1 << (attr->index - MODULE_RESET_1); + break; + case MODULE_RESET_9 ... MODULE_RESET_16: + reg = 0x05; + mask = 0x1 << (attr->index - MODULE_RESET_9); + break; + case MODULE_RESET_17 ... MODULE_RESET_24: + reg = 0x06; + mask = 0x1 << (attr->index - MODULE_RESET_17); + break; + case MODULE_RESET_25 ... MODULE_RESET_32: + reg = 0x07; + mask = 0x1 << (attr->index - MODULE_RESET_25); + break; + default: + return 0; + } mutex_lock(&data->update_lock); - status = as7716_32xb_cpld_read_internal(client, reg); - - if (unlikely(status < 0)) { - goto exit; - } - mutex_unlock(&data->update_lock); - - return sprintf(buf, "%d\r\n", !(status & mask)); - + status = as7716_32xb_cpld_read_internal(client, reg); + + if (unlikely(status < 0)) { + goto exit; + } + mutex_unlock(&data->update_lock); + + return sprintf(buf, "%d\r\n", !(status & mask)); + exit: - mutex_unlock(&data->update_lock); - return status; + mutex_unlock(&data->update_lock); + return status; } static ssize_t set_mode_reset(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ + const char *buf, size_t count) +{ struct sensor_device_attribute *attr = to_sensor_dev_attr(da); struct i2c_client *client = to_i2c_client(dev); struct as7716_32xb_cpld_data *data = i2c_get_clientdata(client); long reset; int status=0, val, error; - u8 reg = 0, mask = 0; - + u8 reg = 0, mask = 0; + error = kstrtol(buf, 10, &reset); if (error) { @@ -932,54 +932,54 @@ static ssize_t set_mode_reset(struct device *dev, struct device_attribute *da, } //printk("set_mode_reset:attr->index=%d\n",attr->index); switch (attr->index) { - case MODULE_RESET_1 ... MODULE_RESET_8: - reg = 0x04; - mask = 0x1 << (attr->index - MODULE_RESET_1); - break; - case MODULE_RESET_9 ... MODULE_RESET_16: - reg = 0x05; - mask = 0x1 << (attr->index - MODULE_RESET_9); - break; - case MODULE_RESET_17 ... MODULE_RESET_24: - reg = 0x06; - mask = 0x1 << (attr->index - MODULE_RESET_17); - break; - case MODULE_RESET_25 ... MODULE_RESET_32: - reg = 0x07; - mask = 0x1 << (attr->index - MODULE_RESET_25); - break; - default: - return 0; - } - mutex_lock(&data->update_lock); - - status = as7716_32xb_cpld_read_internal(client, reg); - if (unlikely(status < 0)) { - goto exit; - } - //printk("set_mode_reset:reset=%d, reg=0x%x, mask=0x%x, ori_val=0x%x\n", reset, reg, mask, status); - /* Update lp_mode status */ + case MODULE_RESET_1 ... MODULE_RESET_8: + reg = 0x04; + mask = 0x1 << (attr->index - MODULE_RESET_1); + break; + case MODULE_RESET_9 ... MODULE_RESET_16: + reg = 0x05; + mask = 0x1 << (attr->index - MODULE_RESET_9); + break; + case MODULE_RESET_17 ... MODULE_RESET_24: + reg = 0x06; + mask = 0x1 << (attr->index - MODULE_RESET_17); + break; + case MODULE_RESET_25 ... MODULE_RESET_32: + reg = 0x07; + mask = 0x1 << (attr->index - MODULE_RESET_25); + break; + default: + return 0; + } + mutex_lock(&data->update_lock); + + status = as7716_32xb_cpld_read_internal(client, reg); + if (unlikely(status < 0)) { + goto exit; + } + //printk("set_mode_reset:reset=%d, reg=0x%x, mask=0x%x, ori_val=0x%x\n", reset, reg, mask, status); + /* Update lp_mode status */ if (reset) - { + { val = status&(~mask); //printk("1:new val=0x%x\n", val); } else - { + { val =status | (mask); //printk("0:new val=0x%x\n", val); } - - status = as7716_32xb_cpld_write_internal(client, reg, val); - if (unlikely(status < 0)) { - goto exit; - } - mutex_unlock(&data->update_lock); - return count; + + status = as7716_32xb_cpld_write_internal(client, reg, val); + if (unlikely(status < 0)) { + goto exit; + } + mutex_unlock(&data->update_lock); + return count; exit: - mutex_unlock(&data->update_lock); - return status; + mutex_unlock(&data->update_lock); + return status; } @@ -1003,13 +1003,13 @@ static struct i2c_driver as7716_32xb_cpld_driver = { static int __init as7716_32xb_cpld_init(void) { - mutex_init(&list_lock); - return i2c_add_driver(&as7716_32xb_cpld_driver); + mutex_init(&list_lock); + return i2c_add_driver(&as7716_32xb_cpld_driver); } static void __exit as7716_32xb_cpld_exit(void) { - i2c_del_driver(&as7716_32xb_cpld_driver); + i2c_del_driver(&as7716_32xb_cpld_driver); } module_init(as7716_32xb_cpld_init); diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_fan.c b/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_fan.c old mode 100755 new mode 100644 index 5c1c3016c3a1..65f3251c00ec --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_fan.c +++ b/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_fan.c @@ -43,17 +43,15 @@ 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, - 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 set_enable(struct device *dev, struct device_attribute *da, 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, - char *buf); + char *buf); 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 */ @@ -85,12 +83,10 @@ struct as7716_32xb_fan_data { u8 reg_val[ARRAY_SIZE(fan_reg)]; /* Register value */ u8 enable; u8 duty_cycle; - int system_temp; /*In unit of mini-Celsius*/ - int sensors_found; unsigned int present[FAN_NUM_MAX]; unsigned int front_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 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_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(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) @@ -162,18 +158,11 @@ enum sysfs_fan_attributes { &sensor_dev_attr_pwm##index.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) \ 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_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##_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, \ &sensor_dev_attr_fan##index##_rear_speed_rpm.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 */ 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 */ 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[] = { /* fan related attributes */ @@ -245,7 +232,6 @@ static struct attribute *as7716_32xb_fan_attributes[] = { DECLARE_FAN_DIRECTION_ATTR(5), DECLARE_FAN_DIRECTION_ATTR(6), DECLARE_FAN_DUTY_CYCLE_ATTR(1), - DECLARE_FAN_SYSTEM_TEMP_ATTR(), NULL }; @@ -265,13 +251,13 @@ static int as7716_32xb_fan_write_value(struct i2c_client *client, u8 reg, u8 val /* 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; 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; } @@ -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) { 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] && - !data->rear_speed_rpm[id] ) + !data->rear_speed_rpm[id] ) { ret = 1; } @@ -334,7 +320,7 @@ static ssize_t set_enable(struct device *dev, struct device_attribute *da, } return count; } - + 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, - const char *buf, size_t count) + 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; - + 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)); 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) +static int fan_array_index_get(int attr_idx) { - 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) + switch(attr_idx) { - dev_dbg(dev,"only %d of %d temps are found\n", - data->sensors_found, NUM_THERMAL_SENSORS); - data->system_temp = 0; + case FAN1_PRESENT: + case FAN1_FRONT_SPEED_RPM: + case FAN1_REAR_SPEED_RPM: + case FAN1_FAULT: + case FAN1_DIRECTION: + return FAN1_ID; + case FAN2_PRESENT: + case FAN2_FRONT_SPEED_RPM: + case FAN2_REAR_SPEED_RPM: + case FAN2_FAULT: + case FAN2_DIRECTION: + return FAN2_ID; + case FAN3_PRESENT: + case FAN3_FRONT_SPEED_RPM: + case FAN3_REAR_SPEED_RPM: + case FAN3_FAULT: + case FAN3_DIRECTION: + return FAN3_ID; + case FAN4_PRESENT: + case FAN4_FRONT_SPEED_RPM: + case FAN4_REAR_SPEED_RPM: + case FAN4_FAULT: + case FAN4_DIRECTION: + return FAN4_ID; + case FAN5_PRESENT: + case FAN5_FRONT_SPEED_RPM: + case FAN5_REAR_SPEED_RPM: + case FAN5_FAULT: + case FAN5_DIRECTION: + return FAN5_ID; + case FAN6_PRESENT: + case FAN6_FRONT_SPEED_RPM: + case FAN6_REAR_SPEED_RPM: + case FAN6_FAULT: + case FAN6_DIRECTION: + return FAN6_ID; + default : + return -1; } - ret = sprintf(buf, "%d\n",data->system_temp); - return ret; } - -static int fan_array_index_get(int attr_idx) -{ - switch(attr_idx) - { - case FAN1_PRESENT: - case FAN1_FRONT_SPEED_RPM: - case FAN1_REAR_SPEED_RPM: - case FAN1_FAULT: - case FAN1_DIRECTION: - return FAN1_ID; - case FAN2_PRESENT: - case FAN2_FRONT_SPEED_RPM: - case FAN2_REAR_SPEED_RPM: - case FAN2_FAULT: - case FAN2_DIRECTION: - return FAN2_ID; - case FAN3_PRESENT: - case FAN3_FRONT_SPEED_RPM: - case FAN3_REAR_SPEED_RPM: - case FAN3_FAULT: - case FAN3_DIRECTION: - return FAN3_ID; - case FAN4_PRESENT: - case FAN4_FRONT_SPEED_RPM: - case FAN4_REAR_SPEED_RPM: - case FAN4_FAULT: - case FAN4_DIRECTION: - return FAN4_ID; - case FAN5_PRESENT: - case FAN5_FRONT_SPEED_RPM: - case FAN5_REAR_SPEED_RPM: - case FAN5_FAULT: - case FAN5_DIRECTION: - return FAN5_ID; - case FAN6_PRESENT: - case FAN6_FRONT_SPEED_RPM: - case FAN6_REAR_SPEED_RPM: - case FAN6_FAULT: - case FAN6_DIRECTION: - return FAN6_ID; - default : - return -1; - } -} - 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 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); switch (attr->index) { - case FAN_DUTY_CYCLE_PERCENTAGE: - status = kstrtol(buf, STRING_TO_DEC_VALUE, &keyin); - if (status) - break; - if (keyin > 1 || keyin < 0) - break; - data->duty_cycle=keyin; + case FAN_DUTY_CYCLE_PERCENTAGE: + status = kstrtol(buf, STRING_TO_DEC_VALUE, &keyin); + if (status) + break; + if (keyin > 1 || keyin < 0) + break; + data->duty_cycle=keyin; + 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: + 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; - 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: - 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; + index=fan_array_index_get(attr->index); + if(index < 0 || index > (FAN_NUM_MAX-1)) 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; + if(keyin < 0 || keyin > 1) 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; + 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; - default: + 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; } 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 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); switch (attr->index) { - case FAN_DUTY_CYCLE_PERCENTAGE: - status = sprintf(buf, "%u\n", data->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: - index=fan_array_index_get(attr->index); - 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]); + case FAN_DUTY_CYCLE_PERCENTAGE: + status = sprintf(buf, "%u\n", data->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: + index=fan_array_index_get(attr->index); + 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; - 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; - status = sprintf(buf, "%d\n", is_fan_fault(data, index)); + 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; - 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]); + 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; - default: + 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); return status; @@ -845,18 +586,18 @@ static struct as7716_32xb_fan_data *as7716_32xb_fan_update_device(struct device mutex_lock(&data->update_lock); - if (time_after(jiffies, data->last_updated + HZ + HZ / 2) || - !data->valid) { + if (time_after(jiffies, data->last_updated + HZ + HZ / 2) || + !data->valid) { int i; dev_dbg(&client->dev, "Starting as7716_32xb_fan update\n"); data->valid = 0; - + /* Update fan data */ for (i = 0; i < ARRAY_SIZE(data->reg_val); i++) { int status = as7716_32xb_fan_read_value(client, fan_reg[i]); - + if (status < 0) { data->valid = 0; 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->last_updated = jiffies; data->valid = 1; } - + mutex_unlock(&data->update_lock); return data; } 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; 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_name(data->hwmon_dev), client->name); - + dev_name(data->hwmon_dev), client->name); + return 0; exit_remove: @@ -917,7 +658,7 @@ static int as7716_32xb_fan_probe(struct i2c_client *client, exit_free: kfree(data); exit: - + 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); hwmon_device_unregister(data->hwmon_dev); sysfs_remove_group(&client->dev.kobj, &as7716_32xb_fan_group); - + return 0; }