Skip to content

Commit 2d13fe4

Browse files
committed
[Accton][as7326-56x] Removed unused codes
1. removed fs_set() and mm_segment_t related codes in x86-64-accton-as7326-56x-fan.c Signed-off-by: Alex Lai <alex_lai@accton.com>
1 parent 800e123 commit 2d13fe4

1 file changed

Lines changed: 1 addition & 276 deletions

File tree

packages/platforms/accton/x86-64/as7326-56x/modules/builds/x86-64-accton-as7326-56x-fan.c

Lines changed: 1 addition & 276 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static ssize_t show_wdt_max_pwm(struct device *dev, struct device_attribute *da,
5757
static ssize_t get_enable(struct device *dev, struct device_attribute *da, char *buf);
5858
static ssize_t set_enable(struct device *dev, struct device_attribute *da,
5959
const char *buf, size_t count);
60-
static ssize_t get_sys_temp(struct device *dev, struct device_attribute *da, char *buf);
60+
6161
extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg);
6262
extern int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value);
6363

@@ -165,12 +165,6 @@ enum sysfs_fan_attributes {
165165
&sensor_dev_attr_pwm##index.dev_attr.attr, \
166166
&sensor_dev_attr_pwm##index##_enable.dev_attr.attr
167167

168-
#define DECLARE_FAN_SYSTEM_TEMP_SENSOR_DEV_ATTR() \
169-
static SENSOR_DEVICE_ATTR(sys_temp, S_IRUGO, get_sys_temp, NULL, FAN_DUTY_CYCLE_PERCENTAGE)
170-
171-
#define DECLARE_FAN_SYSTEM_TEMP_ATTR() &sensor_dev_attr_sys_temp.dev_attr.attr
172-
173-
174168
#define DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(index) \
175169
static SENSOR_DEVICE_ATTR(fan##index##_present, S_IRUGO, fan_show_value, NULL, FAN##index##_PRESENT)
176170
#define DECLARE_FAN_PRESENT_ATTR(index) &sensor_dev_attr_fan##index##_present.dev_attr.attr
@@ -223,8 +217,6 @@ DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(5);
223217
DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(6);
224218
/* 1 fan duty cycle attribute in this platform */
225219
DECLARE_FAN_DUTY_CYCLE_SENSOR_DEV_ATTR(1);
226-
/* System temperature for fancontrol */
227-
DECLARE_FAN_SYSTEM_TEMP_SENSOR_DEV_ATTR();
228220
/* 3 fan wdt attribute in this platform */
229221
DECLARE_FAN_WDT_SENSOR_DEV_ATTR();
230222

@@ -256,7 +248,6 @@ static struct attribute *as7326_56x_fan_attributes[] = {
256248
DECLARE_FAN_DIRECTION_ATTR(5),
257249
DECLARE_FAN_DIRECTION_ATTR(6),
258250
DECLARE_FAN_DUTY_CYCLE_ATTR(1),
259-
DECLARE_FAN_SYSTEM_TEMP_ATTR(),
260251
DECLARE_FAN_WDT_TIMER_ATTR(),
261252
DECLARE_FAN_WDT_MAX_PWM_ATTR(),
262253
DECLARE_FAN_WDT_STATUS_ATTR(),
@@ -393,272 +384,6 @@ static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da,
393384
return count;
394385
}
395386

396-
/* Due to this struct is declared at lm75.c, it cannot be include
397-
* under Sonic environment. I duplicate it from lm75.c.
398-
*/
399-
struct lm75_data {
400-
struct i2c_client *client;
401-
struct device *hwmon_dev;
402-
struct thermal_zone_device *tz;
403-
struct mutex update_lock;
404-
u8 orig_conf;
405-
u8 resolution; /* In bits, between 9 and 12 */
406-
u8 resolution_limits;
407-
char valid; /* !=0 if registers are valid */
408-
unsigned long last_updated; /* In jiffies */
409-
unsigned long sample_time; /* In jiffies */
410-
s16 temp[3]; /* Register values,
411-
0 = input
412-
1 = max
413-
2 = hyst */
414-
};
415-
416-
/*Copied from lm75.c*/
417-
static inline long lm75_reg_to_mc(s16 temp, u8 resolution)
418-
{
419-
return ((temp >> (16 - resolution)) * 1000) >> (resolution - 8);
420-
}
421-
422-
/*Get hwmon_dev from i2c_client, set hwmon_dev = NULL is failed.*/
423-
static struct device * get_hwmon_dev(
424-
struct i2c_client *client)
425-
{
426-
struct lm75_data *data = NULL;
427-
428-
data = i2c_get_clientdata(client);
429-
if(data)
430-
{
431-
if( data->valid == 1 && data->hwmon_dev)
432-
{
433-
return data->hwmon_dev;
434-
}
435-
436-
}
437-
return NULL;
438-
}
439-
440-
/* To find hwmon index by opening hwmon under that i2c address.
441-
*/
442-
static int find_hwmon_index_by_FileOpen(
443-
int bus_nr,
444-
unsigned short addr,
445-
OUT int *index)
446-
{
447-
#define MAX_HWMON_DEVICE (10) /* Find hwmon device in 0~10*/
448-
struct file *sfd;
449-
char client_name[96];
450-
int i=0;
451-
452-
do {
453-
snprintf(client_name, sizeof(client_name),
454-
"/sys/bus/i2c/devices/%d-%04x/hwmon/hwmon%d/temp1_input",
455-
bus_nr, addr, i);
456-
457-
sfd = filp_open(client_name, O_RDONLY, 0);
458-
i++;
459-
} while( IS_ERR(sfd) && i < MAX_HWMON_DEVICE);
460-
461-
if (IS_ERR(sfd)) {
462-
pr_err("Failed to open file(%s)#%d\r\n", client_name, __LINE__);
463-
return -ENOENT;
464-
}
465-
filp_close(sfd, 0);
466-
*index = i - 1;
467-
return 0;
468-
469-
#undef MAX_HWMON_DEVICE
470-
}
471-
472-
static int get_temp_file_path(
473-
int bus_nr, unsigned short addr,
474-
struct device *hwmon_dev
475-
,char *path, int max_len)
476-
{
477-
478-
if(hwmon_dev && strlen(dev_name(hwmon_dev)))
479-
{
480-
snprintf(path, max_len,
481-
"/sys/bus/i2c/devices/%d-%04x/hwmon/%s/temp1_input",
482-
bus_nr, addr, dev_name(hwmon_dev));
483-
}
484-
else
485-
{
486-
int i=0;
487-
if(find_hwmon_index_by_FileOpen( bus_nr, addr, &i))
488-
{
489-
return -EIO;
490-
}
491-
snprintf(path, max_len,
492-
"/sys/bus/i2c/devices/%d-%04x/hwmon/hwmon%d/temp1_input",
493-
bus_nr, addr, i);
494-
}
495-
return 0;
496-
}
497-
498-
/*File read the dev file at user space.*/
499-
static int read_devfile_temp1_input(
500-
struct device *dev,
501-
int bus_nr,
502-
unsigned short addr,
503-
struct device *hwmon_dev,
504-
int *miniCelsius)
505-
{
506-
struct file *sfd;
507-
char buffer[96];
508-
char devfile[96];
509-
int rc, status;
510-
int rdlen, value;
511-
mm_segment_t old_fs;
512-
513-
rc = 0;
514-
get_temp_file_path(bus_nr, addr, hwmon_dev, devfile, sizeof(devfile));
515-
sfd = filp_open(devfile, O_RDONLY, 0);
516-
if (IS_ERR(sfd)) {
517-
pr_err("Failed to open file(%s)#%d\r\n", devfile, __LINE__);
518-
return -ENOENT;
519-
}
520-
dev_dbg(dev, "Found device:%s\n",devfile);
521-
522-
if(!(sfd->f_op) || !(sfd->f_op->read) ) {
523-
pr_err("file %s cann't readable ?\n",devfile);
524-
return -ENOENT;
525-
}
526-
527-
old_fs = get_fs();
528-
set_fs(KERNEL_DS);
529-
rdlen = sfd->f_op->read(sfd, buffer, sizeof(buffer), &sfd->f_pos);
530-
if (rdlen == 0) {
531-
pr_err( "File(%s) empty!\n", devfile);
532-
rc = -EIO;
533-
goto exit;
534-
}
535-
status = sscanf(buffer, "%d", &value);
536-
if (status != 1) {
537-
rc = -EIO;
538-
goto exit;
539-
}
540-
*miniCelsius = value;
541-
dev_dbg(dev,"found sensors: %d @i2c %d-%04x\n", value, bus_nr, addr);
542-
543-
exit:
544-
set_fs(old_fs);
545-
filp_close(sfd, 0);
546-
return rc;
547-
}
548-
549-
static u8 is_lm75_data_due(struct i2c_client *client)
550-
{
551-
struct lm75_data *data = NULL;
552-
553-
data = i2c_get_clientdata(client);
554-
if (time_after(jiffies, data->last_updated + data->sample_time))
555-
{
556-
return 1;
557-
}
558-
return 0;
559-
}
560-
static int get_lm75_temp(struct i2c_client *client, int *miniCelsius)
561-
{
562-
struct lm75_data *data = NULL;
563-
564-
data = i2c_get_clientdata(client);
565-
*miniCelsius = lm75_reg_to_mc(data->temp[0], data->resolution);
566-
567-
return 0;
568-
}
569-
570-
static bool lm75_addr_mached(unsigned short addr)
571-
{
572-
int i;
573-
unsigned short addrs[] = THERMAL_SENSORS_ADDRS;
574-
575-
for (i = 0; i < ARRAY_SIZE(addrs); i++)
576-
{
577-
if( addr == addrs[i])
578-
return 1;
579-
}
580-
return 0;
581-
}
582-
583-
static int _find_lm75_device(struct device *dev, void *data)
584-
{
585-
struct device_driver *driver;
586-
struct as7326_56x_fan_data *prv = data;
587-
char *driver_name = THERMAL_SENSORS_DRIVER;
588-
589-
driver = dev->driver;
590-
if (driver && driver->name &&
591-
strcmp(driver->name, driver_name) == 0)
592-
{
593-
struct i2c_client *client;
594-
client = to_i2c_client(dev);
595-
if (client)
596-
{
597-
/*cannot use "struct i2c_adapter *adap = to_i2c_adapter(dev);"*/
598-
struct i2c_adapter *adap = client->adapter;
599-
int miniCelsius = 0;
600-
601-
if (! lm75_addr_mached(client->addr))
602-
{
603-
return 0;
604-
}
605-
606-
if (!adap) {
607-
return -ENXIO;
608-
}
609-
610-
/* If the data is not updated, read them from devfile
611-
to drive them updateing data from chip.*/
612-
if (is_lm75_data_due(client))
613-
{
614-
struct device *hwmon_dev;
615-
616-
hwmon_dev = get_hwmon_dev(client);
617-
if(0 == read_devfile_temp1_input(dev, adap->nr,
618-
client->addr, hwmon_dev, &miniCelsius))
619-
{
620-
prv->system_temp += miniCelsius;
621-
prv->sensors_found++;
622-
}
623-
624-
}
625-
else
626-
{
627-
get_lm75_temp(client, &miniCelsius);
628-
prv->system_temp += miniCelsius;
629-
prv->sensors_found++;
630-
631-
}
632-
}
633-
}
634-
return 0;
635-
}
636-
637-
/*Find all lm75 devices and return sum of temperatures.*/
638-
static ssize_t get_sys_temp(struct device *dev, struct device_attribute *da,
639-
char *buf)
640-
{
641-
ssize_t ret = 0;
642-
struct i2c_client *client = to_i2c_client(dev);
643-
struct as7326_56x_fan_data *data = i2c_get_clientdata(client);
644-
645-
mutex_lock(&data->update_lock);
646-
data = as7326_56x_fan_update_device(dev);
647-
648-
data->system_temp=0;
649-
data->sensors_found=0;
650-
i2c_for_each_dev(data, _find_lm75_device);
651-
if (NUM_THERMAL_SENSORS != data->sensors_found)
652-
{
653-
dev_dbg(dev,"only %d of %d temps are found\n",
654-
data->sensors_found, NUM_THERMAL_SENSORS);
655-
data->system_temp = INT_MAX;
656-
}
657-
ret = sprintf(buf, "%d\n",data->system_temp);
658-
mutex_unlock(&data->update_lock);
659-
return ret;
660-
}
661-
662387
static ssize_t set_wdt_status(struct device *dev, struct device_attribute *da,
663388
const char *buf, size_t count)
664389
{

0 commit comments

Comments
 (0)