⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dme1737.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
			char *buf){	struct dme1737_data *data = dme1737_update_device(dev);	return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm));}static ssize_t show_name(struct device *dev, struct device_attribute *attr,			 char *buf){	struct dme1737_data *data = dev_get_drvdata(dev);	return sprintf(buf, "%s\n", data->client.name);}/* --------------------------------------------------------------------- * Sysfs device attribute defines and structs * --------------------------------------------------------------------- *//* Voltages 0-6 */#define SENSOR_DEVICE_ATTR_IN(ix) \static SENSOR_DEVICE_ATTR_2(in##ix##_input, S_IRUGO, \	show_in, NULL, SYS_IN_INPUT, ix); \static SENSOR_DEVICE_ATTR_2(in##ix##_min, S_IRUGO | S_IWUSR, \	show_in, set_in, SYS_IN_MIN, ix); \static SENSOR_DEVICE_ATTR_2(in##ix##_max, S_IRUGO | S_IWUSR, \	show_in, set_in, SYS_IN_MAX, ix); \static SENSOR_DEVICE_ATTR_2(in##ix##_alarm, S_IRUGO, \	show_in, NULL, SYS_IN_ALARM, ix)SENSOR_DEVICE_ATTR_IN(0);SENSOR_DEVICE_ATTR_IN(1);SENSOR_DEVICE_ATTR_IN(2);SENSOR_DEVICE_ATTR_IN(3);SENSOR_DEVICE_ATTR_IN(4);SENSOR_DEVICE_ATTR_IN(5);SENSOR_DEVICE_ATTR_IN(6);/* Temperatures 1-3 */#define SENSOR_DEVICE_ATTR_TEMP(ix) \static SENSOR_DEVICE_ATTR_2(temp##ix##_input, S_IRUGO, \	show_temp, NULL, SYS_TEMP_INPUT, ix-1); \static SENSOR_DEVICE_ATTR_2(temp##ix##_min, S_IRUGO | S_IWUSR, \	show_temp, set_temp, SYS_TEMP_MIN, ix-1); \static SENSOR_DEVICE_ATTR_2(temp##ix##_max, S_IRUGO | S_IWUSR, \	show_temp, set_temp, SYS_TEMP_MAX, ix-1); \static SENSOR_DEVICE_ATTR_2(temp##ix##_offset, S_IRUGO, \	show_temp, set_temp, SYS_TEMP_OFFSET, ix-1); \static SENSOR_DEVICE_ATTR_2(temp##ix##_alarm, S_IRUGO, \	show_temp, NULL, SYS_TEMP_ALARM, ix-1); \static SENSOR_DEVICE_ATTR_2(temp##ix##_fault, S_IRUGO, \	show_temp, NULL, SYS_TEMP_FAULT, ix-1)SENSOR_DEVICE_ATTR_TEMP(1);SENSOR_DEVICE_ATTR_TEMP(2);SENSOR_DEVICE_ATTR_TEMP(3);/* Zones 1-3 */#define SENSOR_DEVICE_ATTR_ZONE(ix) \static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_channels_temp, S_IRUGO, \	show_zone, NULL, SYS_ZONE_AUTO_CHANNELS_TEMP, ix-1); \static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point1_temp_hyst, S_IRUGO, \	show_zone, set_zone, SYS_ZONE_AUTO_POINT1_TEMP_HYST, ix-1); \static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point1_temp, S_IRUGO, \	show_zone, set_zone, SYS_ZONE_AUTO_POINT1_TEMP, ix-1); \static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point2_temp, S_IRUGO, \	show_zone, set_zone, SYS_ZONE_AUTO_POINT2_TEMP, ix-1); \static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point3_temp, S_IRUGO, \	show_zone, set_zone, SYS_ZONE_AUTO_POINT3_TEMP, ix-1)SENSOR_DEVICE_ATTR_ZONE(1);SENSOR_DEVICE_ATTR_ZONE(2);SENSOR_DEVICE_ATTR_ZONE(3);/* Fans 1-4 */#define SENSOR_DEVICE_ATTR_FAN_1TO4(ix) \static SENSOR_DEVICE_ATTR_2(fan##ix##_input, S_IRUGO, \	show_fan, NULL, SYS_FAN_INPUT, ix-1); \static SENSOR_DEVICE_ATTR_2(fan##ix##_min, S_IRUGO | S_IWUSR, \	show_fan, set_fan, SYS_FAN_MIN, ix-1); \static SENSOR_DEVICE_ATTR_2(fan##ix##_alarm, S_IRUGO, \	show_fan, NULL, SYS_FAN_ALARM, ix-1); \static SENSOR_DEVICE_ATTR_2(fan##ix##_type, S_IRUGO | S_IWUSR, \	show_fan, set_fan, SYS_FAN_TYPE, ix-1)SENSOR_DEVICE_ATTR_FAN_1TO4(1);SENSOR_DEVICE_ATTR_FAN_1TO4(2);SENSOR_DEVICE_ATTR_FAN_1TO4(3);SENSOR_DEVICE_ATTR_FAN_1TO4(4);/* Fans 5-6 */#define SENSOR_DEVICE_ATTR_FAN_5TO6(ix) \static SENSOR_DEVICE_ATTR_2(fan##ix##_input, S_IRUGO, \	show_fan, NULL, SYS_FAN_INPUT, ix-1); \static SENSOR_DEVICE_ATTR_2(fan##ix##_min, S_IRUGO | S_IWUSR, \	show_fan, set_fan, SYS_FAN_MIN, ix-1); \static SENSOR_DEVICE_ATTR_2(fan##ix##_alarm, S_IRUGO, \	show_fan, NULL, SYS_FAN_ALARM, ix-1); \static SENSOR_DEVICE_ATTR_2(fan##ix##_max, S_IRUGO | S_IWUSR, \	show_fan, set_fan, SYS_FAN_MAX, ix-1)SENSOR_DEVICE_ATTR_FAN_5TO6(5);SENSOR_DEVICE_ATTR_FAN_5TO6(6);/* PWMs 1-3 */#define SENSOR_DEVICE_ATTR_PWM_1TO3(ix) \static SENSOR_DEVICE_ATTR_2(pwm##ix, S_IRUGO, \	show_pwm, set_pwm, SYS_PWM, ix-1); \static SENSOR_DEVICE_ATTR_2(pwm##ix##_freq, S_IRUGO, \	show_pwm, set_pwm, SYS_PWM_FREQ, ix-1); \static SENSOR_DEVICE_ATTR_2(pwm##ix##_enable, S_IRUGO, \	show_pwm, set_pwm, SYS_PWM_ENABLE, ix-1); \static SENSOR_DEVICE_ATTR_2(pwm##ix##_ramp_rate, S_IRUGO, \	show_pwm, set_pwm, SYS_PWM_RAMP_RATE, ix-1); \static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_channels_zone, S_IRUGO, \	show_pwm, set_pwm, SYS_PWM_AUTO_CHANNELS_ZONE, ix-1); \static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_pwm_min, S_IRUGO, \	show_pwm, set_pwm, SYS_PWM_AUTO_PWM_MIN, ix-1); \static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_point1_pwm, S_IRUGO, \	show_pwm, set_pwm, SYS_PWM_AUTO_POINT1_PWM, ix-1); \static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_point2_pwm, S_IRUGO, \	show_pwm, NULL, SYS_PWM_AUTO_POINT2_PWM, ix-1)SENSOR_DEVICE_ATTR_PWM_1TO3(1);SENSOR_DEVICE_ATTR_PWM_1TO3(2);SENSOR_DEVICE_ATTR_PWM_1TO3(3);/* PWMs 5-6 */#define SENSOR_DEVICE_ATTR_PWM_5TO6(ix) \static SENSOR_DEVICE_ATTR_2(pwm##ix, S_IRUGO | S_IWUSR, \	show_pwm, set_pwm, SYS_PWM, ix-1); \static SENSOR_DEVICE_ATTR_2(pwm##ix##_freq, S_IRUGO | S_IWUSR, \	show_pwm, set_pwm, SYS_PWM_FREQ, ix-1); \static SENSOR_DEVICE_ATTR_2(pwm##ix##_enable, S_IRUGO, \	show_pwm, NULL, SYS_PWM_ENABLE, ix-1)SENSOR_DEVICE_ATTR_PWM_5TO6(5);SENSOR_DEVICE_ATTR_PWM_5TO6(6);/* Misc */static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);   /* for ISA devices */#define SENSOR_DEV_ATTR_IN(ix) \&sensor_dev_attr_in##ix##_input.dev_attr.attr, \&sensor_dev_attr_in##ix##_min.dev_attr.attr, \&sensor_dev_attr_in##ix##_max.dev_attr.attr, \&sensor_dev_attr_in##ix##_alarm.dev_attr.attr/* These attributes are read-writeable only if the chip is *not* locked */#define SENSOR_DEV_ATTR_TEMP_LOCK(ix) \&sensor_dev_attr_temp##ix##_offset.dev_attr.attr#define SENSOR_DEV_ATTR_TEMP(ix) \SENSOR_DEV_ATTR_TEMP_LOCK(ix), \&sensor_dev_attr_temp##ix##_input.dev_attr.attr, \&sensor_dev_attr_temp##ix##_min.dev_attr.attr, \&sensor_dev_attr_temp##ix##_max.dev_attr.attr, \&sensor_dev_attr_temp##ix##_alarm.dev_attr.attr, \&sensor_dev_attr_temp##ix##_fault.dev_attr.attr/* These attributes are read-writeable only if the chip is *not* locked */#define SENSOR_DEV_ATTR_ZONE_LOCK(ix) \&sensor_dev_attr_zone##ix##_auto_point1_temp_hyst.dev_attr.attr, \&sensor_dev_attr_zone##ix##_auto_point1_temp.dev_attr.attr, \&sensor_dev_attr_zone##ix##_auto_point2_temp.dev_attr.attr, \&sensor_dev_attr_zone##ix##_auto_point3_temp.dev_attr.attr#define SENSOR_DEV_ATTR_ZONE(ix) \SENSOR_DEV_ATTR_ZONE_LOCK(ix), \&sensor_dev_attr_zone##ix##_auto_channels_temp.dev_attr.attr#define SENSOR_DEV_ATTR_FAN_1TO4(ix) \&sensor_dev_attr_fan##ix##_input.dev_attr.attr, \&sensor_dev_attr_fan##ix##_min.dev_attr.attr, \&sensor_dev_attr_fan##ix##_alarm.dev_attr.attr, \&sensor_dev_attr_fan##ix##_type.dev_attr.attr#define SENSOR_DEV_ATTR_FAN_5TO6(ix) \&sensor_dev_attr_fan##ix##_input.dev_attr.attr, \&sensor_dev_attr_fan##ix##_min.dev_attr.attr, \&sensor_dev_attr_fan##ix##_alarm.dev_attr.attr, \&sensor_dev_attr_fan##ix##_max.dev_attr.attr/* These attributes are read-writeable only if the chip is *not* locked */#define SENSOR_DEV_ATTR_PWM_1TO3_LOCK(ix) \&sensor_dev_attr_pwm##ix##_freq.dev_attr.attr, \&sensor_dev_attr_pwm##ix##_enable.dev_attr.attr, \&sensor_dev_attr_pwm##ix##_ramp_rate.dev_attr.attr, \&sensor_dev_attr_pwm##ix##_auto_channels_zone.dev_attr.attr, \&sensor_dev_attr_pwm##ix##_auto_pwm_min.dev_attr.attr, \&sensor_dev_attr_pwm##ix##_auto_point1_pwm.dev_attr.attr#define SENSOR_DEV_ATTR_PWM_1TO3(ix) \SENSOR_DEV_ATTR_PWM_1TO3_LOCK(ix), \&sensor_dev_attr_pwm##ix.dev_attr.attr, \&sensor_dev_attr_pwm##ix##_auto_point2_pwm.dev_attr.attr/* These attributes are read-writeable only if the chip is *not* locked */#define SENSOR_DEV_ATTR_PWM_5TO6_LOCK(ix) \&sensor_dev_attr_pwm##ix.dev_attr.attr, \&sensor_dev_attr_pwm##ix##_freq.dev_attr.attr#define SENSOR_DEV_ATTR_PWM_5TO6(ix) \SENSOR_DEV_ATTR_PWM_5TO6_LOCK(ix), \&sensor_dev_attr_pwm##ix##_enable.dev_attr.attr/* This struct holds all the attributes that are always present and need to be * created unconditionally. The attributes that need modification of their * permissions are created read-only and write permissions are added or removed * on the fly when required */static struct attribute *dme1737_attr[] ={	/* Voltages */	SENSOR_DEV_ATTR_IN(0),	SENSOR_DEV_ATTR_IN(1),	SENSOR_DEV_ATTR_IN(2),	SENSOR_DEV_ATTR_IN(3),	SENSOR_DEV_ATTR_IN(4),	SENSOR_DEV_ATTR_IN(5),	SENSOR_DEV_ATTR_IN(6),	/* Temperatures */	SENSOR_DEV_ATTR_TEMP(1),	SENSOR_DEV_ATTR_TEMP(2),	SENSOR_DEV_ATTR_TEMP(3),	/* Zones */	SENSOR_DEV_ATTR_ZONE(1),	SENSOR_DEV_ATTR_ZONE(2),	SENSOR_DEV_ATTR_ZONE(3),	/* Misc */	&dev_attr_vrm.attr,	&dev_attr_cpu0_vid.attr,	NULL};static const struct attribute_group dme1737_group = {	.attrs = dme1737_attr,};/* The following structs hold the PWM attributes, some of which are optional. * Their creation depends on the chip configuration which is determined during * module load. */static struct attribute *dme1737_attr_pwm1[] = {	SENSOR_DEV_ATTR_PWM_1TO3(1),	NULL};static struct attribute *dme1737_attr_pwm2[] = {	SENSOR_DEV_ATTR_PWM_1TO3(2),	NULL};static struct attribute *dme1737_attr_pwm3[] = {	SENSOR_DEV_ATTR_PWM_1TO3(3),	NULL};static struct attribute *dme1737_attr_pwm5[] = {	SENSOR_DEV_ATTR_PWM_5TO6(5),	NULL};static struct attribute *dme1737_attr_pwm6[] = {	SENSOR_DEV_ATTR_PWM_5TO6(6),	NULL};static const struct attribute_group dme1737_pwm_group[] = {	{ .attrs = dme1737_attr_pwm1 },	{ .attrs = dme1737_attr_pwm2 },	{ .attrs = dme1737_attr_pwm3 },	{ .attrs = NULL },	{ .attrs = dme1737_attr_pwm5 },	{ .attrs = dme1737_attr_pwm6 },};/* The following structs hold the fan attributes, some of which are optional. * Their creation depends on the chip configuration which is determined during * module load. */static struct attribute *dme1737_attr_fan1[] = {	SENSOR_DEV_ATTR_FAN_1TO4(1),	NULL};static struct attribute *dme1737_attr_fan2[] = {	SENSOR_DEV_ATTR_FAN_1TO4(2),	NULL};static struct attribute *dme1737_attr_fan3[] = {	SENSOR_DEV_ATTR_FAN_1TO4(3),	NULL};static struct attribute *dme1737_attr_fan4[] = {	SENSOR_DEV_ATTR_FAN_1TO4(4),	NULL};static struct attribute *dme1737_attr_fan5[] = {	SENSOR_DEV_ATTR_FAN_5TO6(5),	NULL};static struct attribute *dme1737_attr_fan6[] = {	SENSOR_DEV_ATTR_FAN_5TO6(6),	NULL};static const struct attribute_group dme1737_fan_group[] = {	{ .attrs = dme1737_attr_fan1 },	{ .attrs = dme1737_attr_fan2 },	{ .attrs = dme1737_attr_fan3 },	{ .attrs = dme1737_attr_fan4 },	{ .attrs = dme1737_attr_fan5 },	{ .attrs = dme1737_attr_fan6 },};/* The permissions of all of the following attributes are changed to read- * writeable if the chip is *not* locked. Otherwise they stay read-only. */static struct attribute *dme1737_attr_lock[] = {	/* Temperatures */	SENSOR_DEV_ATTR_TEMP_LOCK(1),	SENSOR_DEV_ATTR_TEMP_LOCK(2),	SENSOR_DEV_ATTR_TEMP_LOCK(3),	/* Zones */	SENSOR_DEV_ATTR_ZONE_LOCK(1),	SENSOR_DEV_ATTR_ZONE_LOCK(2),	SENSOR_DEV_ATTR_ZONE_LOCK(3),	NULL};static const struct attribute_group dme1737_lock_group = {	.attrs = dme1737_attr_lock,};/* The permissions of the following PWM attributes are changed to read- * writeable if the chip is *not* locked and the respective PWM is available. * Otherwise they stay read-only. */static struct attribute *dme1737_attr_pwm1_lock[] = {	SENSOR_DEV_ATTR_PWM_1TO3_LOCK(1),	NULL};static struct attribute *dme1737_attr_pwm2_lock[] = {	SENSOR_DEV_ATTR_PWM_1TO3_LOCK(2),	NULL};static struct attribute *dme1737_attr_pwm3_lock[] = {	SENSOR_DEV_ATTR_PWM_1TO3_LOCK(3),	NULL};static struct attribute *dme1737_attr_pwm5_lock[] = {	SENSOR_DEV_ATTR_PWM_5TO6_LOCK(5),	NULL};static struct attribute *dme1737_attr_pwm6_lock[] = {	SENSOR_DEV_ATTR_PWM_5TO6_LOCK(6),	NULL};static const struct attribute_group dme1737_pwm_lock_group[] = {	{ .attrs = dme1737_attr_pwm1_lock },	{ .attrs = dme1737_attr_pwm2_lock },	{ .attrs = dme1737_attr_pwm3_lock },	{ .attrs = NULL },	{ .attrs = dme1737_attr_pwm5_lock },	{ .attrs = dme1737_attr_pwm6_lock },};/* Pwm[1-3] are read-writeable if the associated pwm is in manual mode and the * chip is not locked. Otherwise they are read-only. */static struct attribute *dme1737_attr_pwm[] = {	&sensor_dev_attr_pwm1.dev_attr.attr,	&sensor_dev_attr_pwm2.dev_attr.attr,	&sensor_dev_attr_pwm3.dev_attr.attr,};/* --------------------------------------------------------------------- * Super-IO functions * --------------------------------------------------------------------- */static inline void dme1737_sio_enter(int sio_cip){	outb(0x55, sio_cip);}static inline void dme1737_sio_exit(int sio_cip){	outb(0xaa, sio_cip);}static inline int dme1737_sio_inb(int sio_cip, int reg){	outb(reg, sio_cip);	return inb(sio_cip + 1);}static inline void dme1737_sio_outb(int sio_cip, int reg, int val){	outb(reg, sio_cip);	outb(val, sio_cip + 1);}/* --------------------------------------------------------------------- * Device initialization * --------------------------------------------------------------------- */static int dme1737_i2c_get_features(int, struct dme1737_data*);static void dme1737_chmod_file(struct device *dev,			       struct attribute *attr, mode_t mode){	if (sysfs_chmod_file(&dev->kobj, attr, mode)) {		dev_warn(dev, "Failed to change permissions of %s.\n",			 attr->name);	}}static void dme1737_chmod_group(struct device *dev,				const struct attribute_group *group,				mode_t mode){	struct attribute **attr;	for (attr = group->attrs; *attr; attr++) {		dme1737_chmod_file(dev, *attr, mode);	}}static void dme1737_remove_files(struct device *dev){	struct dme1737_data *data = dev_get_drvdata(dev);	int ix;	for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) {		if (data->has_fan & (1 << ix)) {			sysfs_remove_group(&dev->kobj,					   &dme1737_fan_group[ix]);		}	}	for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) {		if (data->has_pwm & (1 << ix)) {			sysfs_remove_group(&dev->kobj,					   &dme1737_pwm_group[ix]);		}	}	sysfs_remove_group(&dev->kobj, &dme1737_group);	if (!data->client.driver) {		sysfs_remove_file(&dev->kobj, &dev_attr_name.attr);	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -