Commit b237eb25 authored by Juerg Haefliger's avatar Juerg Haefliger Committed by Mark M. Hoffman

hwmon: (dme1737) cleanups

This patch cleans up and prepares the dme1737 driver for support of the sch311x
chips. (Almost) no functional changes.

- Replaced whitespaces with tabs.
- Removed empty lines.
- Added _i2c_ to names of functions that are strictly I2C related.
- Added 4 new functions: dme1737_create_files, dme1737_remove_files,
  dme1737_sio_enter, and dme1737_sio_exit.
- Added error messages in case client attach/detach fails.

Signed-off-by: Juerg Haefliger <juergh at gmail.com>
Acked-by: default avatarJean Delvare <khali@linux-fr.org>
Signed-off-by: default avatarMark M. Hoffman <mhoffman@lightlink.com>
parent bbf25010
...@@ -493,8 +493,8 @@ static s32 dme1737_write(struct i2c_client *client, u8 reg, u8 value) ...@@ -493,8 +493,8 @@ static s32 dme1737_write(struct i2c_client *client, u8 reg, u8 value)
static struct dme1737_data *dme1737_update_device(struct device *dev) static struct dme1737_data *dme1737_update_device(struct device *dev)
{ {
struct i2c_client *client = to_i2c_client(dev); struct dme1737_data *data = dev_get_drvdata(dev);
struct dme1737_data *data = i2c_get_clientdata(client); struct i2c_client *client = &data->client;
int ix; int ix;
u8 lsb[5]; u8 lsb[5];
...@@ -674,7 +674,7 @@ static ssize_t show_in(struct device *dev, struct device_attribute *attr, ...@@ -674,7 +674,7 @@ static ssize_t show_in(struct device *dev, struct device_attribute *attr,
break; break;
default: default:
res = 0; res = 0;
dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); dev_dbg(dev, "Unknown function %d.\n", fn);
} }
return sprintf(buf, "%d\n", res); return sprintf(buf, "%d\n", res);
...@@ -683,8 +683,8 @@ static ssize_t show_in(struct device *dev, struct device_attribute *attr, ...@@ -683,8 +683,8 @@ static ssize_t show_in(struct device *dev, struct device_attribute *attr,
static ssize_t set_in(struct device *dev, struct device_attribute *attr, static ssize_t set_in(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct i2c_client *client = to_i2c_client(dev); struct dme1737_data *data = dev_get_drvdata(dev);
struct dme1737_data *data = i2c_get_clientdata(client); struct i2c_client *client = &data->client;
struct sensor_device_attribute_2 struct sensor_device_attribute_2
*sensor_attr_2 = to_sensor_dev_attr_2(attr); *sensor_attr_2 = to_sensor_dev_attr_2(attr);
int ix = sensor_attr_2->index; int ix = sensor_attr_2->index;
...@@ -704,7 +704,7 @@ static ssize_t set_in(struct device *dev, struct device_attribute *attr, ...@@ -704,7 +704,7 @@ static ssize_t set_in(struct device *dev, struct device_attribute *attr,
data->in_max[ix]); data->in_max[ix]);
break; break;
default: default:
dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); dev_dbg(dev, "Unknown function %d.\n", fn);
} }
mutex_unlock(&data->update_lock); mutex_unlock(&data->update_lock);
...@@ -754,7 +754,7 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *attr, ...@@ -754,7 +754,7 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
break; break;
default: default:
res = 0; res = 0;
dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); dev_dbg(dev, "Unknown function %d.\n", fn);
} }
return sprintf(buf, "%d\n", res); return sprintf(buf, "%d\n", res);
...@@ -763,8 +763,8 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *attr, ...@@ -763,8 +763,8 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
static ssize_t set_temp(struct device *dev, struct device_attribute *attr, static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct i2c_client *client = to_i2c_client(dev); struct dme1737_data *data = dev_get_drvdata(dev);
struct dme1737_data *data = i2c_get_clientdata(client); struct i2c_client *client = &data->client;
struct sensor_device_attribute_2 struct sensor_device_attribute_2
*sensor_attr_2 = to_sensor_dev_attr_2(attr); *sensor_attr_2 = to_sensor_dev_attr_2(attr);
int ix = sensor_attr_2->index; int ix = sensor_attr_2->index;
...@@ -789,7 +789,7 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *attr, ...@@ -789,7 +789,7 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
data->temp_offset[ix]); data->temp_offset[ix]);
break; break;
default: default:
dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); dev_dbg(dev, "Unknown function %d.\n", fn);
} }
mutex_unlock(&data->update_lock); mutex_unlock(&data->update_lock);
...@@ -843,7 +843,7 @@ static ssize_t show_zone(struct device *dev, struct device_attribute *attr, ...@@ -843,7 +843,7 @@ static ssize_t show_zone(struct device *dev, struct device_attribute *attr,
break; break;
default: default:
res = 0; res = 0;
dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); dev_dbg(dev, "Unknown function %d.\n", fn);
} }
return sprintf(buf, "%d\n", res); return sprintf(buf, "%d\n", res);
...@@ -852,8 +852,8 @@ static ssize_t show_zone(struct device *dev, struct device_attribute *attr, ...@@ -852,8 +852,8 @@ static ssize_t show_zone(struct device *dev, struct device_attribute *attr,
static ssize_t set_zone(struct device *dev, struct device_attribute *attr, static ssize_t set_zone(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct i2c_client *client = to_i2c_client(dev); struct dme1737_data *data = dev_get_drvdata(dev);
struct dme1737_data *data = i2c_get_clientdata(client); struct i2c_client *client = &data->client;
struct sensor_device_attribute_2 struct sensor_device_attribute_2
*sensor_attr_2 = to_sensor_dev_attr_2(attr); *sensor_attr_2 = to_sensor_dev_attr_2(attr);
int ix = sensor_attr_2->index; int ix = sensor_attr_2->index;
...@@ -898,7 +898,7 @@ static ssize_t set_zone(struct device *dev, struct device_attribute *attr, ...@@ -898,7 +898,7 @@ static ssize_t set_zone(struct device *dev, struct device_attribute *attr,
data->zone_abs[ix]); data->zone_abs[ix]);
break; break;
default: default:
dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); dev_dbg(dev, "Unknown function %d.\n", fn);
} }
mutex_unlock(&data->update_lock); mutex_unlock(&data->update_lock);
...@@ -950,7 +950,7 @@ static ssize_t show_fan(struct device *dev, struct device_attribute *attr, ...@@ -950,7 +950,7 @@ static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
break; break;
default: default:
res = 0; res = 0;
dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); dev_dbg(dev, "Unknown function %d.\n", fn);
} }
return sprintf(buf, "%d\n", res); return sprintf(buf, "%d\n", res);
...@@ -959,8 +959,8 @@ static ssize_t show_fan(struct device *dev, struct device_attribute *attr, ...@@ -959,8 +959,8 @@ static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
static ssize_t set_fan(struct device *dev, struct device_attribute *attr, static ssize_t set_fan(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct i2c_client *client = to_i2c_client(dev); struct dme1737_data *data = dev_get_drvdata(dev);
struct dme1737_data *data = i2c_get_clientdata(client); struct i2c_client *client = &data->client;
struct sensor_device_attribute_2 struct sensor_device_attribute_2
*sensor_attr_2 = to_sensor_dev_attr_2(attr); *sensor_attr_2 = to_sensor_dev_attr_2(attr);
int ix = sensor_attr_2->index; int ix = sensor_attr_2->index;
...@@ -1006,7 +1006,7 @@ static ssize_t set_fan(struct device *dev, struct device_attribute *attr, ...@@ -1006,7 +1006,7 @@ static ssize_t set_fan(struct device *dev, struct device_attribute *attr,
data->fan_opt[ix]); data->fan_opt[ix]);
break; break;
default: default:
dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); dev_dbg(dev, "Unknown function %d.\n", fn);
} }
exit: exit:
mutex_unlock(&data->update_lock); mutex_unlock(&data->update_lock);
...@@ -1086,20 +1086,20 @@ static ssize_t show_pwm(struct device *dev, struct device_attribute *attr, ...@@ -1086,20 +1086,20 @@ static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
break; break;
default: default:
res = 0; res = 0;
dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); dev_dbg(dev, "Unknown function %d.\n", fn);
} }
return sprintf(buf, "%d\n", res); return sprintf(buf, "%d\n", res);
} }
static struct attribute *dme1737_attr_pwm[]; static struct attribute *dme1737_attr_pwm[];
static void dme1737_chmod_file(struct i2c_client*, struct attribute*, mode_t); static void dme1737_chmod_file(struct device*, struct attribute*, mode_t);
static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct i2c_client *client = to_i2c_client(dev); struct dme1737_data *data = dev_get_drvdata(dev);
struct dme1737_data *data = i2c_get_clientdata(client); struct i2c_client *client = &data->client;
struct sensor_device_attribute_2 struct sensor_device_attribute_2
*sensor_attr_2 = to_sensor_dev_attr_2(attr); *sensor_attr_2 = to_sensor_dev_attr_2(attr);
int ix = sensor_attr_2->index; int ix = sensor_attr_2->index;
...@@ -1156,7 +1156,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, ...@@ -1156,7 +1156,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
switch (val) { switch (val) {
case 0: case 0:
/* Change permissions of pwm[ix] to read-only */ /* Change permissions of pwm[ix] to read-only */
dme1737_chmod_file(client, dme1737_attr_pwm[ix], dme1737_chmod_file(dev, dme1737_attr_pwm[ix],
S_IRUGO); S_IRUGO);
/* Turn fan fully on */ /* Turn fan fully on */
data->pwm_config[ix] = PWM_EN_TO_REG(0, data->pwm_config[ix] = PWM_EN_TO_REG(0,
...@@ -1171,12 +1171,12 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, ...@@ -1171,12 +1171,12 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
dme1737_write(client, DME1737_REG_PWM_CONFIG(ix), dme1737_write(client, DME1737_REG_PWM_CONFIG(ix),
data->pwm_config[ix]); data->pwm_config[ix]);
/* Change permissions of pwm[ix] to read-writeable */ /* Change permissions of pwm[ix] to read-writeable */
dme1737_chmod_file(client, dme1737_attr_pwm[ix], dme1737_chmod_file(dev, dme1737_attr_pwm[ix],
S_IRUGO | S_IWUSR); S_IRUGO | S_IWUSR);
break; break;
case 2: case 2:
/* Change permissions of pwm[ix] to read-only */ /* Change permissions of pwm[ix] to read-only */
dme1737_chmod_file(client, dme1737_attr_pwm[ix], dme1737_chmod_file(dev, dme1737_attr_pwm[ix],
S_IRUGO); S_IRUGO);
/* Turn on auto mode using the saved zone channel /* Turn on auto mode using the saved zone channel
* assignment */ * assignment */
...@@ -1257,12 +1257,10 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, ...@@ -1257,12 +1257,10 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
data->pwm_rr[0] = PWM_OFF_TO_REG(1, ix, data->pwm_rr[0] = PWM_OFF_TO_REG(1, ix,
dme1737_read(client, dme1737_read(client,
DME1737_REG_PWM_RR(0))); DME1737_REG_PWM_RR(0)));
} else { } else {
data->pwm_rr[0] = PWM_OFF_TO_REG(0, ix, data->pwm_rr[0] = PWM_OFF_TO_REG(0, ix,
dme1737_read(client, dme1737_read(client,
DME1737_REG_PWM_RR(0))); DME1737_REG_PWM_RR(0)));
} }
dme1737_write(client, DME1737_REG_PWM_RR(0), dme1737_write(client, DME1737_REG_PWM_RR(0),
data->pwm_rr[0]); data->pwm_rr[0]);
...@@ -1274,7 +1272,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, ...@@ -1274,7 +1272,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
data->pwm_min[ix]); data->pwm_min[ix]);
break; break;
default: default:
dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); dev_dbg(dev, "Unknown function %d.\n", fn);
} }
exit: exit:
mutex_unlock(&data->update_lock); mutex_unlock(&data->update_lock);
...@@ -1298,8 +1296,7 @@ static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, ...@@ -1298,8 +1296,7 @@ static ssize_t show_vrm(struct device *dev, struct device_attribute *attr,
static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct i2c_client *client = to_i2c_client(dev); struct dme1737_data *data = dev_get_drvdata(dev);
struct dme1737_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
data->vrm = val; data->vrm = val;
...@@ -1322,13 +1319,13 @@ static ssize_t show_vid(struct device *dev, struct device_attribute *attr, ...@@ -1322,13 +1319,13 @@ static ssize_t show_vid(struct device *dev, struct device_attribute *attr,
#define SENSOR_DEVICE_ATTR_IN(ix) \ #define SENSOR_DEVICE_ATTR_IN(ix) \
static SENSOR_DEVICE_ATTR_2(in##ix##_input, S_IRUGO, \ static SENSOR_DEVICE_ATTR_2(in##ix##_input, S_IRUGO, \
show_in, NULL, SYS_IN_INPUT, ix); \ show_in, NULL, SYS_IN_INPUT, ix); \
static SENSOR_DEVICE_ATTR_2(in##ix##_min, S_IRUGO | S_IWUSR, \ static SENSOR_DEVICE_ATTR_2(in##ix##_min, S_IRUGO | S_IWUSR, \
show_in, set_in, SYS_IN_MIN, ix); \ show_in, set_in, SYS_IN_MIN, ix); \
static SENSOR_DEVICE_ATTR_2(in##ix##_max, S_IRUGO | S_IWUSR, \ static SENSOR_DEVICE_ATTR_2(in##ix##_max, S_IRUGO | S_IWUSR, \
show_in, set_in, SYS_IN_MAX, ix); \ show_in, set_in, SYS_IN_MAX, ix); \
static SENSOR_DEVICE_ATTR_2(in##ix##_alarm, S_IRUGO, \ static SENSOR_DEVICE_ATTR_2(in##ix##_alarm, S_IRUGO, \
show_in, NULL, SYS_IN_ALARM, ix) show_in, NULL, SYS_IN_ALARM, ix)
SENSOR_DEVICE_ATTR_IN(0); SENSOR_DEVICE_ATTR_IN(0);
SENSOR_DEVICE_ATTR_IN(1); SENSOR_DEVICE_ATTR_IN(1);
...@@ -1342,17 +1339,17 @@ SENSOR_DEVICE_ATTR_IN(6); ...@@ -1342,17 +1339,17 @@ SENSOR_DEVICE_ATTR_IN(6);
#define SENSOR_DEVICE_ATTR_TEMP(ix) \ #define SENSOR_DEVICE_ATTR_TEMP(ix) \
static SENSOR_DEVICE_ATTR_2(temp##ix##_input, S_IRUGO, \ static SENSOR_DEVICE_ATTR_2(temp##ix##_input, S_IRUGO, \
show_temp, NULL, SYS_TEMP_INPUT, ix-1); \ show_temp, NULL, SYS_TEMP_INPUT, ix-1); \
static SENSOR_DEVICE_ATTR_2(temp##ix##_min, S_IRUGO | S_IWUSR, \ static SENSOR_DEVICE_ATTR_2(temp##ix##_min, S_IRUGO | S_IWUSR, \
show_temp, set_temp, SYS_TEMP_MIN, ix-1); \ show_temp, set_temp, SYS_TEMP_MIN, ix-1); \
static SENSOR_DEVICE_ATTR_2(temp##ix##_max, S_IRUGO | S_IWUSR, \ static SENSOR_DEVICE_ATTR_2(temp##ix##_max, S_IRUGO | S_IWUSR, \
show_temp, set_temp, SYS_TEMP_MAX, ix-1); \ show_temp, set_temp, SYS_TEMP_MAX, ix-1); \
static SENSOR_DEVICE_ATTR_2(temp##ix##_offset, S_IRUGO, \ static SENSOR_DEVICE_ATTR_2(temp##ix##_offset, S_IRUGO, \
show_temp, set_temp, SYS_TEMP_OFFSET, ix-1); \ show_temp, set_temp, SYS_TEMP_OFFSET, ix-1); \
static SENSOR_DEVICE_ATTR_2(temp##ix##_alarm, S_IRUGO, \ static SENSOR_DEVICE_ATTR_2(temp##ix##_alarm, S_IRUGO, \
show_temp, NULL, SYS_TEMP_ALARM, ix-1); \ show_temp, NULL, SYS_TEMP_ALARM, ix-1); \
static SENSOR_DEVICE_ATTR_2(temp##ix##_fault, S_IRUGO, \ static SENSOR_DEVICE_ATTR_2(temp##ix##_fault, S_IRUGO, \
show_temp, NULL, SYS_TEMP_FAULT, ix-1) show_temp, NULL, SYS_TEMP_FAULT, ix-1)
SENSOR_DEVICE_ATTR_TEMP(1); SENSOR_DEVICE_ATTR_TEMP(1);
SENSOR_DEVICE_ATTR_TEMP(2); SENSOR_DEVICE_ATTR_TEMP(2);
...@@ -1362,15 +1359,15 @@ SENSOR_DEVICE_ATTR_TEMP(3); ...@@ -1362,15 +1359,15 @@ SENSOR_DEVICE_ATTR_TEMP(3);
#define SENSOR_DEVICE_ATTR_ZONE(ix) \ #define SENSOR_DEVICE_ATTR_ZONE(ix) \
static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_channels_temp, S_IRUGO, \ static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_channels_temp, S_IRUGO, \
show_zone, NULL, SYS_ZONE_AUTO_CHANNELS_TEMP, ix-1); \ show_zone, NULL, SYS_ZONE_AUTO_CHANNELS_TEMP, ix-1); \
static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point1_temp_hyst, S_IRUGO, \ 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); \ show_zone, set_zone, SYS_ZONE_AUTO_POINT1_TEMP_HYST, ix-1); \
static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point1_temp, S_IRUGO, \ static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point1_temp, S_IRUGO, \
show_zone, set_zone, SYS_ZONE_AUTO_POINT1_TEMP, ix-1); \ show_zone, set_zone, SYS_ZONE_AUTO_POINT1_TEMP, ix-1); \
static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point2_temp, S_IRUGO, \ static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point2_temp, S_IRUGO, \
show_zone, set_zone, SYS_ZONE_AUTO_POINT2_TEMP, ix-1); \ show_zone, set_zone, SYS_ZONE_AUTO_POINT2_TEMP, ix-1); \
static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point3_temp, S_IRUGO, \ static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point3_temp, S_IRUGO, \
show_zone, set_zone, SYS_ZONE_AUTO_POINT3_TEMP, ix-1) show_zone, set_zone, SYS_ZONE_AUTO_POINT3_TEMP, ix-1)
SENSOR_DEVICE_ATTR_ZONE(1); SENSOR_DEVICE_ATTR_ZONE(1);
SENSOR_DEVICE_ATTR_ZONE(2); SENSOR_DEVICE_ATTR_ZONE(2);
...@@ -1380,13 +1377,13 @@ SENSOR_DEVICE_ATTR_ZONE(3); ...@@ -1380,13 +1377,13 @@ SENSOR_DEVICE_ATTR_ZONE(3);
#define SENSOR_DEVICE_ATTR_FAN_1TO4(ix) \ #define SENSOR_DEVICE_ATTR_FAN_1TO4(ix) \
static SENSOR_DEVICE_ATTR_2(fan##ix##_input, S_IRUGO, \ static SENSOR_DEVICE_ATTR_2(fan##ix##_input, S_IRUGO, \
show_fan, NULL, SYS_FAN_INPUT, ix-1); \ show_fan, NULL, SYS_FAN_INPUT, ix-1); \
static SENSOR_DEVICE_ATTR_2(fan##ix##_min, S_IRUGO | S_IWUSR, \ static SENSOR_DEVICE_ATTR_2(fan##ix##_min, S_IRUGO | S_IWUSR, \
show_fan, set_fan, SYS_FAN_MIN, ix-1); \ show_fan, set_fan, SYS_FAN_MIN, ix-1); \
static SENSOR_DEVICE_ATTR_2(fan##ix##_alarm, S_IRUGO, \ static SENSOR_DEVICE_ATTR_2(fan##ix##_alarm, S_IRUGO, \
show_fan, NULL, SYS_FAN_ALARM, ix-1); \ show_fan, NULL, SYS_FAN_ALARM, ix-1); \
static SENSOR_DEVICE_ATTR_2(fan##ix##_type, S_IRUGO | S_IWUSR, \ static SENSOR_DEVICE_ATTR_2(fan##ix##_type, S_IRUGO | S_IWUSR, \
show_fan, set_fan, SYS_FAN_TYPE, ix-1) show_fan, set_fan, SYS_FAN_TYPE, ix-1)
SENSOR_DEVICE_ATTR_FAN_1TO4(1); SENSOR_DEVICE_ATTR_FAN_1TO4(1);
SENSOR_DEVICE_ATTR_FAN_1TO4(2); SENSOR_DEVICE_ATTR_FAN_1TO4(2);
...@@ -1397,13 +1394,13 @@ SENSOR_DEVICE_ATTR_FAN_1TO4(4); ...@@ -1397,13 +1394,13 @@ SENSOR_DEVICE_ATTR_FAN_1TO4(4);
#define SENSOR_DEVICE_ATTR_FAN_5TO6(ix) \ #define SENSOR_DEVICE_ATTR_FAN_5TO6(ix) \
static SENSOR_DEVICE_ATTR_2(fan##ix##_input, S_IRUGO, \ static SENSOR_DEVICE_ATTR_2(fan##ix##_input, S_IRUGO, \
show_fan, NULL, SYS_FAN_INPUT, ix-1); \ show_fan, NULL, SYS_FAN_INPUT, ix-1); \
static SENSOR_DEVICE_ATTR_2(fan##ix##_min, S_IRUGO | S_IWUSR, \ static SENSOR_DEVICE_ATTR_2(fan##ix##_min, S_IRUGO | S_IWUSR, \
show_fan, set_fan, SYS_FAN_MIN, ix-1); \ show_fan, set_fan, SYS_FAN_MIN, ix-1); \
static SENSOR_DEVICE_ATTR_2(fan##ix##_alarm, S_IRUGO, \ static SENSOR_DEVICE_ATTR_2(fan##ix##_alarm, S_IRUGO, \
show_fan, NULL, SYS_FAN_ALARM, ix-1); \ show_fan, NULL, SYS_FAN_ALARM, ix-1); \
static SENSOR_DEVICE_ATTR_2(fan##ix##_max, S_IRUGO | S_IWUSR, \ static SENSOR_DEVICE_ATTR_2(fan##ix##_max, S_IRUGO | S_IWUSR, \
show_fan, set_fan, SYS_FAN_MAX, ix-1) show_fan, set_fan, SYS_FAN_MAX, ix-1)
SENSOR_DEVICE_ATTR_FAN_5TO6(5); SENSOR_DEVICE_ATTR_FAN_5TO6(5);
SENSOR_DEVICE_ATTR_FAN_5TO6(6); SENSOR_DEVICE_ATTR_FAN_5TO6(6);
...@@ -1412,21 +1409,21 @@ SENSOR_DEVICE_ATTR_FAN_5TO6(6); ...@@ -1412,21 +1409,21 @@ SENSOR_DEVICE_ATTR_FAN_5TO6(6);
#define SENSOR_DEVICE_ATTR_PWM_1TO3(ix) \ #define SENSOR_DEVICE_ATTR_PWM_1TO3(ix) \
static SENSOR_DEVICE_ATTR_2(pwm##ix, S_IRUGO, \ static SENSOR_DEVICE_ATTR_2(pwm##ix, S_IRUGO, \
show_pwm, set_pwm, SYS_PWM, ix-1); \ show_pwm, set_pwm, SYS_PWM, ix-1); \
static SENSOR_DEVICE_ATTR_2(pwm##ix##_freq, S_IRUGO, \ static SENSOR_DEVICE_ATTR_2(pwm##ix##_freq, S_IRUGO, \
show_pwm, set_pwm, SYS_PWM_FREQ, ix-1); \ show_pwm, set_pwm, SYS_PWM_FREQ, ix-1); \
static SENSOR_DEVICE_ATTR_2(pwm##ix##_enable, S_IRUGO, \ static SENSOR_DEVICE_ATTR_2(pwm##ix##_enable, S_IRUGO, \
show_pwm, set_pwm, SYS_PWM_ENABLE, ix-1); \ show_pwm, set_pwm, SYS_PWM_ENABLE, ix-1); \
static SENSOR_DEVICE_ATTR_2(pwm##ix##_ramp_rate, S_IRUGO, \ static SENSOR_DEVICE_ATTR_2(pwm##ix##_ramp_rate, S_IRUGO, \
show_pwm, set_pwm, SYS_PWM_RAMP_RATE, ix-1); \ show_pwm, set_pwm, SYS_PWM_RAMP_RATE, ix-1); \
static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_channels_zone, S_IRUGO, \ static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_channels_zone, S_IRUGO, \
show_pwm, set_pwm, SYS_PWM_AUTO_CHANNELS_ZONE, ix-1); \ show_pwm, set_pwm, SYS_PWM_AUTO_CHANNELS_ZONE, ix-1); \
static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_pwm_min, S_IRUGO, \ static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_pwm_min, S_IRUGO, \
show_pwm, set_pwm, SYS_PWM_AUTO_PWM_MIN, ix-1); \ show_pwm, set_pwm, SYS_PWM_AUTO_PWM_MIN, ix-1); \
static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_point1_pwm, S_IRUGO, \ static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_point1_pwm, S_IRUGO, \
show_pwm, set_pwm, SYS_PWM_AUTO_POINT1_PWM, ix-1); \ show_pwm, set_pwm, SYS_PWM_AUTO_POINT1_PWM, ix-1); \
static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_point2_pwm, S_IRUGO, \ static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_point2_pwm, S_IRUGO, \
show_pwm, NULL, SYS_PWM_AUTO_POINT2_PWM, ix-1) show_pwm, NULL, SYS_PWM_AUTO_POINT2_PWM, ix-1)
SENSOR_DEVICE_ATTR_PWM_1TO3(1); SENSOR_DEVICE_ATTR_PWM_1TO3(1);
SENSOR_DEVICE_ATTR_PWM_1TO3(2); SENSOR_DEVICE_ATTR_PWM_1TO3(2);
...@@ -1436,11 +1433,11 @@ SENSOR_DEVICE_ATTR_PWM_1TO3(3); ...@@ -1436,11 +1433,11 @@ SENSOR_DEVICE_ATTR_PWM_1TO3(3);
#define SENSOR_DEVICE_ATTR_PWM_5TO6(ix) \ #define SENSOR_DEVICE_ATTR_PWM_5TO6(ix) \
static SENSOR_DEVICE_ATTR_2(pwm##ix, S_IRUGO | S_IWUSR, \ static SENSOR_DEVICE_ATTR_2(pwm##ix, S_IRUGO | S_IWUSR, \
show_pwm, set_pwm, SYS_PWM, ix-1); \ show_pwm, set_pwm, SYS_PWM, ix-1); \
static SENSOR_DEVICE_ATTR_2(pwm##ix##_freq, S_IRUGO | S_IWUSR, \ static SENSOR_DEVICE_ATTR_2(pwm##ix##_freq, S_IRUGO | S_IWUSR, \
show_pwm, set_pwm, SYS_PWM_FREQ, ix-1); \ show_pwm, set_pwm, SYS_PWM_FREQ, ix-1); \
static SENSOR_DEVICE_ATTR_2(pwm##ix##_enable, S_IRUGO, \ static SENSOR_DEVICE_ATTR_2(pwm##ix##_enable, S_IRUGO, \
show_pwm, NULL, SYS_PWM_ENABLE, ix-1) show_pwm, NULL, SYS_PWM_ENABLE, ix-1)
SENSOR_DEVICE_ATTR_PWM_5TO6(5); SENSOR_DEVICE_ATTR_PWM_5TO6(5);
SENSOR_DEVICE_ATTR_PWM_5TO6(6); SENSOR_DEVICE_ATTR_PWM_5TO6(6);
...@@ -1519,53 +1516,53 @@ SENSOR_DEV_ATTR_PWM_5TO6_LOCK(ix), \ ...@@ -1519,53 +1516,53 @@ SENSOR_DEV_ATTR_PWM_5TO6_LOCK(ix), \
* permissions are created read-only and write permissions are added or removed * permissions are created read-only and write permissions are added or removed
* on the fly when required */ * on the fly when required */
static struct attribute *dme1737_attr[] ={ static struct attribute *dme1737_attr[] ={
/* Voltages */ /* Voltages */
SENSOR_DEV_ATTR_IN(0), SENSOR_DEV_ATTR_IN(0),
SENSOR_DEV_ATTR_IN(1), SENSOR_DEV_ATTR_IN(1),
SENSOR_DEV_ATTR_IN(2), SENSOR_DEV_ATTR_IN(2),
SENSOR_DEV_ATTR_IN(3), SENSOR_DEV_ATTR_IN(3),
SENSOR_DEV_ATTR_IN(4), SENSOR_DEV_ATTR_IN(4),
SENSOR_DEV_ATTR_IN(5), SENSOR_DEV_ATTR_IN(5),
SENSOR_DEV_ATTR_IN(6), SENSOR_DEV_ATTR_IN(6),
/* Temperatures */ /* Temperatures */
SENSOR_DEV_ATTR_TEMP(1), SENSOR_DEV_ATTR_TEMP(1),
SENSOR_DEV_ATTR_TEMP(2), SENSOR_DEV_ATTR_TEMP(2),
SENSOR_DEV_ATTR_TEMP(3), SENSOR_DEV_ATTR_TEMP(3),
/* Zones */ /* Zones */
SENSOR_DEV_ATTR_ZONE(1), SENSOR_DEV_ATTR_ZONE(1),
SENSOR_DEV_ATTR_ZONE(2), SENSOR_DEV_ATTR_ZONE(2),
SENSOR_DEV_ATTR_ZONE(3), SENSOR_DEV_ATTR_ZONE(3),
/* Misc */ /* Misc */
&dev_attr_vrm.attr, &dev_attr_vrm.attr,
&dev_attr_cpu0_vid.attr, &dev_attr_cpu0_vid.attr,
NULL NULL
}; };
static const struct attribute_group dme1737_group = { static const struct attribute_group dme1737_group = {
.attrs = dme1737_attr, .attrs = dme1737_attr,
}; };
/* The following structs hold the PWM attributes, some of which are optional. /* The following structs hold the PWM attributes, some of which are optional.
* Their creation depends on the chip configuration which is determined during * Their creation depends on the chip configuration which is determined during
* module load. */ * module load. */
static struct attribute *dme1737_attr_pwm1[] = { static struct attribute *dme1737_attr_pwm1[] = {
SENSOR_DEV_ATTR_PWM_1TO3(1), SENSOR_DEV_ATTR_PWM_1TO3(1),
NULL NULL
}; };
static struct attribute *dme1737_attr_pwm2[] = { static struct attribute *dme1737_attr_pwm2[] = {
SENSOR_DEV_ATTR_PWM_1TO3(2), SENSOR_DEV_ATTR_PWM_1TO3(2),
NULL NULL
}; };
static struct attribute *dme1737_attr_pwm3[] = { static struct attribute *dme1737_attr_pwm3[] = {
SENSOR_DEV_ATTR_PWM_1TO3(3), SENSOR_DEV_ATTR_PWM_1TO3(3),
NULL NULL
}; };
static struct attribute *dme1737_attr_pwm5[] = { static struct attribute *dme1737_attr_pwm5[] = {
SENSOR_DEV_ATTR_PWM_5TO6(5), SENSOR_DEV_ATTR_PWM_5TO6(5),
NULL NULL
}; };
static struct attribute *dme1737_attr_pwm6[] = { static struct attribute *dme1737_attr_pwm6[] = {
SENSOR_DEV_ATTR_PWM_5TO6(6), SENSOR_DEV_ATTR_PWM_5TO6(6),
NULL NULL
}; };
...@@ -1582,27 +1579,27 @@ static const struct attribute_group dme1737_pwm_group[] = { ...@@ -1582,27 +1579,27 @@ static const struct attribute_group dme1737_pwm_group[] = {
* Their creation depends on the chip configuration which is determined during * Their creation depends on the chip configuration which is determined during
* module load. */ * module load. */
static struct attribute *dme1737_attr_fan1[] = { static struct attribute *dme1737_attr_fan1[] = {
SENSOR_DEV_ATTR_FAN_1TO4(1), SENSOR_DEV_ATTR_FAN_1TO4(1),
NULL NULL
}; };
static struct attribute *dme1737_attr_fan2[] = { static struct attribute *dme1737_attr_fan2[] = {
SENSOR_DEV_ATTR_FAN_1TO4(2), SENSOR_DEV_ATTR_FAN_1TO4(2),
NULL NULL
}; };
static struct attribute *dme1737_attr_fan3[] = { static struct attribute *dme1737_attr_fan3[] = {
SENSOR_DEV_ATTR_FAN_1TO4(3), SENSOR_DEV_ATTR_FAN_1TO4(3),
NULL NULL
}; };
static struct attribute *dme1737_attr_fan4[] = { static struct attribute *dme1737_attr_fan4[] = {
SENSOR_DEV_ATTR_FAN_1TO4(4), SENSOR_DEV_ATTR_FAN_1TO4(4),
NULL NULL
}; };
static struct attribute *dme1737_attr_fan5[] = { static struct attribute *dme1737_attr_fan5[] = {
SENSOR_DEV_ATTR_FAN_5TO6(5), SENSOR_DEV_ATTR_FAN_5TO6(5),
NULL NULL
}; };
static struct attribute *dme1737_attr_fan6[] = { static struct attribute *dme1737_attr_fan6[] = {
SENSOR_DEV_ATTR_FAN_5TO6(6), SENSOR_DEV_ATTR_FAN_5TO6(6),
NULL NULL
}; };
...@@ -1637,23 +1634,23 @@ static const struct attribute_group dme1737_lock_group = { ...@@ -1637,23 +1634,23 @@ static const struct attribute_group dme1737_lock_group = {
* writeable if the chip is *not* locked and the respective PWM is available. * writeable if the chip is *not* locked and the respective PWM is available.
* Otherwise they stay read-only. */ * Otherwise they stay read-only. */
static struct attribute *dme1737_attr_pwm1_lock[] = { static struct attribute *dme1737_attr_pwm1_lock[] = {
SENSOR_DEV_ATTR_PWM_1TO3_LOCK(1), SENSOR_DEV_ATTR_PWM_1TO3_LOCK(1),
NULL NULL
}; };
static struct attribute *dme1737_attr_pwm2_lock[] = { static struct attribute *dme1737_attr_pwm2_lock[] = {
SENSOR_DEV_ATTR_PWM_1TO3_LOCK(2), SENSOR_DEV_ATTR_PWM_1TO3_LOCK(2),
NULL NULL
}; };
static struct attribute *dme1737_attr_pwm3_lock[] = { static struct attribute *dme1737_attr_pwm3_lock[] = {
SENSOR_DEV_ATTR_PWM_1TO3_LOCK(3), SENSOR_DEV_ATTR_PWM_1TO3_LOCK(3),
NULL NULL
}; };
static struct attribute *dme1737_attr_pwm5_lock[] = { static struct attribute *dme1737_attr_pwm5_lock[] = {
SENSOR_DEV_ATTR_PWM_5TO6_LOCK(5), SENSOR_DEV_ATTR_PWM_5TO6_LOCK(5),
NULL NULL
}; };
static struct attribute *dme1737_attr_pwm6_lock[] = { static struct attribute *dme1737_attr_pwm6_lock[] = {
SENSOR_DEV_ATTR_PWM_5TO6_LOCK(6), SENSOR_DEV_ATTR_PWM_5TO6_LOCK(6),
NULL NULL
}; };
...@@ -1678,6 +1675,16 @@ static struct attribute *dme1737_attr_pwm[] = { ...@@ -1678,6 +1675,16 @@ static struct attribute *dme1737_attr_pwm[] = {
* Super-IO functions * 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) static inline int dme1737_sio_inb(int sio_cip, int reg)
{ {
outb(reg, sio_cip); outb(reg, sio_cip);
...@@ -1690,14 +1697,12 @@ static inline void dme1737_sio_outb(int sio_cip, int reg, int val) ...@@ -1690,14 +1697,12 @@ static inline void dme1737_sio_outb(int sio_cip, int reg, int val)
outb(val, sio_cip + 1); outb(val, sio_cip + 1);
} }
static int dme1737_sio_get_features(int sio_cip, struct i2c_client *client) static int dme1737_i2c_get_features(int sio_cip, struct dme1737_data *data)
{ {
struct dme1737_data *data = i2c_get_clientdata(client);
int err = 0, reg; int err = 0, reg;
u16 addr; u16 addr;
/* Enter configuration mode */ dme1737_sio_enter(sio_cip);
outb(0x55, sio_cip);
/* Check device ID /* Check device ID
* The DME1737 can return either 0x78 or 0x77 as its device ID. */ * The DME1737 can return either 0x78 or 0x77 as its device ID. */
...@@ -1734,8 +1739,7 @@ static int dme1737_sio_get_features(int sio_cip, struct i2c_client *client) ...@@ -1734,8 +1739,7 @@ static int dme1737_sio_get_features(int sio_cip, struct i2c_client *client)
} }
exit: exit:
/* Exit configuration mode */ dme1737_sio_exit(sio_cip);
outb(0xaa, sio_cip);
return err; return err;
} }
...@@ -1744,51 +1748,142 @@ static int dme1737_sio_get_features(int sio_cip, struct i2c_client *client) ...@@ -1744,51 +1748,142 @@ static int dme1737_sio_get_features(int sio_cip, struct i2c_client *client)
* Device detection, registration and initialization * Device detection, registration and initialization
* --------------------------------------------------------------------- */ * --------------------------------------------------------------------- */
static struct i2c_driver dme1737_driver; static struct i2c_driver dme1737_i2c_driver;
static void dme1737_chmod_file(struct i2c_client *client, static void dme1737_chmod_file(struct device *dev,
struct attribute *attr, mode_t mode) struct attribute *attr, mode_t mode)
{ {
if (sysfs_chmod_file(&client->dev.kobj, attr, mode)) { if (sysfs_chmod_file(&dev->kobj, attr, mode)) {
dev_warn(&client->dev, "Failed to change permissions of %s.\n", dev_warn(dev, "Failed to change permissions of %s.\n",
attr->name); attr->name);
} }
} }
static void dme1737_chmod_group(struct i2c_client *client, static void dme1737_chmod_group(struct device *dev,
const struct attribute_group *group, const struct attribute_group *group,
mode_t mode) mode_t mode)
{ {
struct attribute **attr; struct attribute **attr;
for (attr = group->attrs; *attr; attr++) { for (attr = group->attrs; *attr; attr++) {
dme1737_chmod_file(client, *attr, mode); dme1737_chmod_file(dev, *attr, mode);
} }
} }
static int dme1737_init_client(struct i2c_client *client) static void dme1737_remove_files(struct device *dev)
{ {
struct dme1737_data *data = i2c_get_clientdata(client); 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);
}
static int dme1737_create_files(struct device *dev)
{
struct dme1737_data *data = dev_get_drvdata(dev);
int err, ix;
/* Create standard sysfs attributes */
if ((err = sysfs_create_group(&dev->kobj, &dme1737_group))) {
goto exit;
}
/* Create fan sysfs attributes */
for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) {
if (data->has_fan & (1 << ix)) {
if ((err = sysfs_create_group(&dev->kobj,
&dme1737_fan_group[ix]))) {
goto exit_remove;
}
}
}
/* Create PWM sysfs attributes */
for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) {
if (data->has_pwm & (1 << ix)) {
if ((err = sysfs_create_group(&dev->kobj,
&dme1737_pwm_group[ix]))) {
goto exit_remove;
}
}
}
/* Inform if the device is locked. Otherwise change the permissions of
* selected attributes from read-only to read-writeable. */
if (data->config & 0x02) {
dev_info(dev, "Device is locked. Some attributes "
"will be read-only.\n");
} else {
/* Change permissions of standard attributes */
dme1737_chmod_group(dev, &dme1737_lock_group,
S_IRUGO | S_IWUSR);
/* Change permissions of PWM attributes */
for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_lock_group); ix++) {
if (data->has_pwm & (1 << ix)) {
dme1737_chmod_group(dev,
&dme1737_pwm_lock_group[ix],
S_IRUGO | S_IWUSR);
}
}
/* Change permissions of pwm[1-3] if in manual mode */
for (ix = 0; ix < 3; ix++) {
if ((data->has_pwm & (1 << ix)) &&
(PWM_EN_FROM_REG(data->pwm_config[ix]) == 1)) {
dme1737_chmod_file(dev,
dme1737_attr_pwm[ix],
S_IRUGO | S_IWUSR);
}
}
}
return 0;
exit_remove:
dme1737_remove_files(dev);
exit:
return err;
}
static int dme1737_init_device(struct device *dev)
{
struct dme1737_data *data = dev_get_drvdata(dev);
struct i2c_client *client = &data->client;
int ix; int ix;
u8 reg; u8 reg;
data->config = dme1737_read(client, DME1737_REG_CONFIG); data->config = dme1737_read(client, DME1737_REG_CONFIG);
/* Inform if part is not monitoring/started */ /* Inform if part is not monitoring/started */
if (!(data->config & 0x01)) { if (!(data->config & 0x01)) {
if (!force_start) { if (!force_start) {
dev_err(&client->dev, "Device is not monitoring. " dev_err(dev, "Device is not monitoring. "
"Use the force_start load parameter to " "Use the force_start load parameter to "
"override.\n"); "override.\n");
return -EFAULT; return -EFAULT;
} }
/* Force monitoring */ /* Force monitoring */
data->config |= 0x01; data->config |= 0x01;
dme1737_write(client, DME1737_REG_CONFIG, data->config); dme1737_write(client, DME1737_REG_CONFIG, data->config);
} }
/* Inform if part is not ready */ /* Inform if part is not ready */
if (!(data->config & 0x04)) { if (!(data->config & 0x04)) {
dev_err(&client->dev, "Device is not ready.\n"); dev_err(dev, "Device is not ready.\n");
return -EFAULT; return -EFAULT;
} }
...@@ -1809,9 +1904,9 @@ static int dme1737_init_client(struct i2c_client *client) ...@@ -1809,9 +1904,9 @@ static int dme1737_init_client(struct i2c_client *client)
/* Determine if the optional fan[5-6] and/or pwm[5-6] are enabled. /* Determine if the optional fan[5-6] and/or pwm[5-6] are enabled.
* For this, we need to query the runtime registers through the * For this, we need to query the runtime registers through the
* Super-IO LPC interface. Try both config ports 0x2e and 0x4e. */ * Super-IO LPC interface. Try both config ports 0x2e and 0x4e. */
if (dme1737_sio_get_features(0x2e, client) && if (dme1737_i2c_get_features(0x2e, data) &&
dme1737_sio_get_features(0x4e, client)) { dme1737_i2c_get_features(0x4e, data)) {
dev_warn(&client->dev, "Failed to query Super-IO for optional " dev_warn(dev, "Failed to query Super-IO for optional "
"features.\n"); "features.\n");
} }
...@@ -1819,7 +1914,7 @@ static int dme1737_init_client(struct i2c_client *client) ...@@ -1819,7 +1914,7 @@ static int dme1737_init_client(struct i2c_client *client)
data->has_fan |= 0x03; data->has_fan |= 0x03;
data->has_pwm |= 0x03; data->has_pwm |= 0x03;
dev_info(&client->dev, "Optional features: pwm3=%s, pwm5=%s, pwm6=%s, " dev_info(dev, "Optional features: pwm3=%s, pwm5=%s, pwm6=%s, "
"fan3=%s, fan4=%s, fan5=%s, fan6=%s.\n", "fan3=%s, fan4=%s, fan5=%s, fan6=%s.\n",
(data->has_pwm & (1 << 2)) ? "yes" : "no", (data->has_pwm & (1 << 2)) ? "yes" : "no",
(data->has_pwm & (1 << 4)) ? "yes" : "no", (data->has_pwm & (1 << 4)) ? "yes" : "no",
...@@ -1832,7 +1927,7 @@ static int dme1737_init_client(struct i2c_client *client) ...@@ -1832,7 +1927,7 @@ static int dme1737_init_client(struct i2c_client *client)
reg = dme1737_read(client, DME1737_REG_TACH_PWM); reg = dme1737_read(client, DME1737_REG_TACH_PWM);
/* Inform if fan-to-pwm mapping differs from the default */ /* Inform if fan-to-pwm mapping differs from the default */
if (reg != 0xa4) { if (reg != 0xa4) {
dev_warn(&client->dev, "Non-standard fan to pwm mapping: " dev_warn(dev, "Non-standard fan to pwm mapping: "
"fan1->pwm%d, fan2->pwm%d, fan3->pwm%d, " "fan1->pwm%d, fan2->pwm%d, fan3->pwm%d, "
"fan4->pwm%d. Please report to the driver " "fan4->pwm%d. Please report to the driver "
"maintainer.\n", "maintainer.\n",
...@@ -1849,7 +1944,7 @@ static int dme1737_init_client(struct i2c_client *client) ...@@ -1849,7 +1944,7 @@ static int dme1737_init_client(struct i2c_client *client)
DME1737_REG_PWM_CONFIG(ix)); DME1737_REG_PWM_CONFIG(ix));
if ((data->has_pwm & (1 << ix)) && if ((data->has_pwm & (1 << ix)) &&
(PWM_EN_FROM_REG(data->pwm_config[ix]) == -1)) { (PWM_EN_FROM_REG(data->pwm_config[ix]) == -1)) {
dev_info(&client->dev, "Switching pwm%d to " dev_info(dev, "Switching pwm%d to "
"manual mode.\n", ix + 1); "manual mode.\n", ix + 1);
data->pwm_config[ix] = PWM_EN_TO_REG(1, data->pwm_config[ix] = PWM_EN_TO_REG(1,
data->pwm_config[ix]); data->pwm_config[ix]);
...@@ -1872,13 +1967,14 @@ static int dme1737_init_client(struct i2c_client *client) ...@@ -1872,13 +1967,14 @@ static int dme1737_init_client(struct i2c_client *client)
return 0; return 0;
} }
static int dme1737_detect(struct i2c_adapter *adapter, int address, static int dme1737_i2c_detect(struct i2c_adapter *adapter, int address,
int kind) int kind)
{ {
u8 company, verstep = 0; u8 company, verstep = 0;
struct i2c_client *client; struct i2c_client *client;
struct dme1737_data *data; struct dme1737_data *data;
int ix, err = 0; struct device *dev;
int err = 0;
const char *name; const char *name;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
...@@ -1894,7 +1990,8 @@ static int dme1737_detect(struct i2c_adapter *adapter, int address, ...@@ -1894,7 +1990,8 @@ static int dme1737_detect(struct i2c_adapter *adapter, int address,
i2c_set_clientdata(client, data); i2c_set_clientdata(client, data);
client->addr = address; client->addr = address;
client->adapter = adapter; client->adapter = adapter;
client->driver = &dme1737_driver; client->driver = &dme1737_i2c_driver;
dev = &client->dev;
/* A negative kind means that the driver was loaded with no force /* A negative kind means that the driver was loaded with no force
* parameter (default), so we must identify the chip. */ * parameter (default), so we must identify the chip. */
...@@ -1922,92 +2019,33 @@ static int dme1737_detect(struct i2c_adapter *adapter, int address, ...@@ -1922,92 +2019,33 @@ static int dme1737_detect(struct i2c_adapter *adapter, int address,
goto exit_kfree; goto exit_kfree;
} }
dev_info(dev, "Found a DME1737 chip at 0x%02x (rev 0x%02x).\n",
client->addr, verstep);
/* Initialize the DME1737 chip */ /* Initialize the DME1737 chip */
if ((err = dme1737_init_client(client))) { if ((err = dme1737_init_device(dev))) {
dev_err(dev, "Failed to initialize device.\n");
goto exit_detach; goto exit_detach;
} }
/* Create standard sysfs attributes */ /* Create sysfs files */
if ((err = sysfs_create_group(&client->dev.kobj, &dme1737_group))) { if ((err = dme1737_create_files(dev))) {
goto exit_detach; dev_err(dev, "Failed to create sysfs files.\n");
} goto exit_detach;
/* Create fan sysfs attributes */
for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) {
if (data->has_fan & (1 << ix)) {
if ((err = sysfs_create_group(&client->dev.kobj,
&dme1737_fan_group[ix]))) {
goto exit_remove;
}
}
}
/* Create PWM sysfs attributes */
for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) {
if (data->has_pwm & (1 << ix)) {
if ((err = sysfs_create_group(&client->dev.kobj,
&dme1737_pwm_group[ix]))) {
goto exit_remove;
}
}
}
/* Inform if the device is locked. Otherwise change the permissions of
* selected attributes from read-only to read-writeable. */
if (data->config & 0x02) {
dev_info(&client->dev, "Device is locked. Some attributes "
"will be read-only.\n");
} else {
/* Change permissions of standard attributes */
dme1737_chmod_group(client, &dme1737_lock_group,
S_IRUGO | S_IWUSR);
/* Change permissions of PWM attributes */
for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_lock_group); ix++) {
if (data->has_pwm & (1 << ix)) {
dme1737_chmod_group(client,
&dme1737_pwm_lock_group[ix],
S_IRUGO | S_IWUSR);
}
}
/* Change permissions of pwm[1-3] if in manual mode */
for (ix = 0; ix < 3; ix++) {
if ((data->has_pwm & (1 << ix)) &&
(PWM_EN_FROM_REG(data->pwm_config[ix]) == 1)) {
dme1737_chmod_file(client,
dme1737_attr_pwm[ix],
S_IRUGO | S_IWUSR);
}
}
} }
/* Register device */ /* Register device */
data->class_dev = hwmon_device_register(&client->dev); data->class_dev = hwmon_device_register(dev);
if (IS_ERR(data->class_dev)) { if (IS_ERR(data->class_dev)) {
dev_err(dev, "Failed to register device.\n");
err = PTR_ERR(data->class_dev); err = PTR_ERR(data->class_dev);
goto exit_remove; goto exit_remove;
} }
dev_info(&adapter->dev, "Found a DME1737 chip at 0x%02x "
"(rev 0x%02x)\n", client->addr, verstep);
return 0; return 0;
exit_remove: exit_remove:
for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) { dme1737_remove_files(dev);
if (data->has_fan & (1 << ix)) {
sysfs_remove_group(&client->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(&client->dev.kobj,
&dme1737_pwm_group[ix]);
}
}
sysfs_remove_group(&client->dev.kobj, &dme1737_group);
exit_detach: exit_detach:
i2c_detach_client(client); i2c_detach_client(client);
exit_kfree: exit_kfree:
...@@ -2016,35 +2054,22 @@ static int dme1737_detect(struct i2c_adapter *adapter, int address, ...@@ -2016,35 +2054,22 @@ static int dme1737_detect(struct i2c_adapter *adapter, int address,
return err; return err;
} }
static int dme1737_attach_adapter(struct i2c_adapter *adapter) static int dme1737_i2c_attach_adapter(struct i2c_adapter *adapter)
{ {
if (!(adapter->class & I2C_CLASS_HWMON)) { if (!(adapter->class & I2C_CLASS_HWMON)) {
return 0; return 0;
} }
return i2c_probe(adapter, &addr_data, dme1737_detect); return i2c_probe(adapter, &addr_data, dme1737_i2c_detect);
} }
static int dme1737_detach_client(struct i2c_client *client) static int dme1737_i2c_detach_client(struct i2c_client *client)
{ {
struct dme1737_data *data = i2c_get_clientdata(client); struct dme1737_data *data = i2c_get_clientdata(client);
int ix, err; int err;
hwmon_device_unregister(data->class_dev); hwmon_device_unregister(data->class_dev);
dme1737_remove_files(&client->dev);
for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) {
if (data->has_fan & (1 << ix)) {
sysfs_remove_group(&client->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(&client->dev.kobj,
&dme1737_pwm_group[ix]);
}
}
sysfs_remove_group(&client->dev.kobj, &dme1737_group);
if ((err = i2c_detach_client(client))) { if ((err = i2c_detach_client(client))) {
return err; return err;
...@@ -2054,22 +2079,22 @@ static int dme1737_detach_client(struct i2c_client *client) ...@@ -2054,22 +2079,22 @@ static int dme1737_detach_client(struct i2c_client *client)
return 0; return 0;
} }
static struct i2c_driver dme1737_driver = { static struct i2c_driver dme1737_i2c_driver = {
.driver = { .driver = {
.name = "dme1737", .name = "dme1737",
}, },
.attach_adapter = dme1737_attach_adapter, .attach_adapter = dme1737_i2c_attach_adapter,
.detach_client = dme1737_detach_client, .detach_client = dme1737_i2c_detach_client,
}; };
static int __init dme1737_init(void) static int __init dme1737_init(void)
{ {
return i2c_add_driver(&dme1737_driver); return i2c_add_driver(&dme1737_i2c_driver);
} }
static void __exit dme1737_exit(void) static void __exit dme1737_exit(void)
{ {
i2c_del_driver(&dme1737_driver); i2c_del_driver(&dme1737_i2c_driver);
} }
MODULE_AUTHOR("Juerg Haefliger <juergh@gmail.com>"); MODULE_AUTHOR("Juerg Haefliger <juergh@gmail.com>");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment