mirror of
https://github.com/adulau/aha.git
synced 2024-12-28 19:56:18 +00:00
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: Jean Delvare <khali@linux-fr.org> Signed-off-by: Mark M. Hoffman <mhoffman@lightlink.com>
This commit is contained in:
parent
bbf25010f1
commit
b237eb25d8
1 changed files with 257 additions and 232 deletions
|
@ -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)
|
||||
{
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct dme1737_data *data = i2c_get_clientdata(client);
|
||||
struct dme1737_data *data = dev_get_drvdata(dev);
|
||||
struct i2c_client *client = &data->client;
|
||||
int ix;
|
||||
u8 lsb[5];
|
||||
|
||||
|
@ -674,7 +674,7 @@ static ssize_t show_in(struct device *dev, struct device_attribute *attr,
|
|||
break;
|
||||
default:
|
||||
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);
|
||||
|
@ -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,
|
||||
const char *buf, size_t count)
|
||||
{
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct dme1737_data *data = i2c_get_clientdata(client);
|
||||
struct dme1737_data *data = dev_get_drvdata(dev);
|
||||
struct i2c_client *client = &data->client;
|
||||
struct sensor_device_attribute_2
|
||||
*sensor_attr_2 = to_sensor_dev_attr_2(attr);
|
||||
int ix = sensor_attr_2->index;
|
||||
|
@ -704,7 +704,7 @@ static ssize_t set_in(struct device *dev, struct device_attribute *attr,
|
|||
data->in_max[ix]);
|
||||
break;
|
||||
default:
|
||||
dev_dbg(dev, "Unknown attr fetch (%d)\n", fn);
|
||||
dev_dbg(dev, "Unknown function %d.\n", fn);
|
||||
}
|
||||
mutex_unlock(&data->update_lock);
|
||||
|
||||
|
@ -754,7 +754,7 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
|
|||
break;
|
||||
default:
|
||||
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);
|
||||
|
@ -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,
|
||||
const char *buf, size_t count)
|
||||
{
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct dme1737_data *data = i2c_get_clientdata(client);
|
||||
struct dme1737_data *data = dev_get_drvdata(dev);
|
||||
struct i2c_client *client = &data->client;
|
||||
struct sensor_device_attribute_2
|
||||
*sensor_attr_2 = to_sensor_dev_attr_2(attr);
|
||||
int ix = sensor_attr_2->index;
|
||||
|
@ -789,7 +789,7 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
|
|||
data->temp_offset[ix]);
|
||||
break;
|
||||
default:
|
||||
dev_dbg(dev, "Unknown attr fetch (%d)\n", fn);
|
||||
dev_dbg(dev, "Unknown function %d.\n", fn);
|
||||
}
|
||||
mutex_unlock(&data->update_lock);
|
||||
|
||||
|
@ -843,7 +843,7 @@ static ssize_t show_zone(struct device *dev, struct device_attribute *attr,
|
|||
break;
|
||||
default:
|
||||
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);
|
||||
|
@ -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,
|
||||
const char *buf, size_t count)
|
||||
{
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct dme1737_data *data = i2c_get_clientdata(client);
|
||||
struct dme1737_data *data = dev_get_drvdata(dev);
|
||||
struct i2c_client *client = &data->client;
|
||||
struct sensor_device_attribute_2
|
||||
*sensor_attr_2 = to_sensor_dev_attr_2(attr);
|
||||
int ix = sensor_attr_2->index;
|
||||
|
@ -898,7 +898,7 @@ static ssize_t set_zone(struct device *dev, struct device_attribute *attr,
|
|||
data->zone_abs[ix]);
|
||||
break;
|
||||
default:
|
||||
dev_dbg(dev, "Unknown attr fetch (%d)\n", fn);
|
||||
dev_dbg(dev, "Unknown function %d.\n", fn);
|
||||
}
|
||||
mutex_unlock(&data->update_lock);
|
||||
|
||||
|
@ -950,7 +950,7 @@ static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
|
|||
break;
|
||||
default:
|
||||
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);
|
||||
|
@ -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,
|
||||
const char *buf, size_t count)
|
||||
{
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct dme1737_data *data = i2c_get_clientdata(client);
|
||||
struct dme1737_data *data = dev_get_drvdata(dev);
|
||||
struct i2c_client *client = &data->client;
|
||||
struct sensor_device_attribute_2
|
||||
*sensor_attr_2 = to_sensor_dev_attr_2(attr);
|
||||
int ix = sensor_attr_2->index;
|
||||
|
@ -1006,7 +1006,7 @@ static ssize_t set_fan(struct device *dev, struct device_attribute *attr,
|
|||
data->fan_opt[ix]);
|
||||
break;
|
||||
default:
|
||||
dev_dbg(dev, "Unknown attr fetch (%d)\n", fn);
|
||||
dev_dbg(dev, "Unknown function %d.\n", fn);
|
||||
}
|
||||
exit:
|
||||
mutex_unlock(&data->update_lock);
|
||||
|
@ -1086,20 +1086,20 @@ static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
|
|||
break;
|
||||
default:
|
||||
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);
|
||||
}
|
||||
|
||||
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,
|
||||
const char *buf, size_t count)
|
||||
{
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct dme1737_data *data = i2c_get_clientdata(client);
|
||||
struct dme1737_data *data = dev_get_drvdata(dev);
|
||||
struct i2c_client *client = &data->client;
|
||||
struct sensor_device_attribute_2
|
||||
*sensor_attr_2 = to_sensor_dev_attr_2(attr);
|
||||
int ix = sensor_attr_2->index;
|
||||
|
@ -1156,7 +1156,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
|
|||
switch (val) {
|
||||
case 0:
|
||||
/* 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);
|
||||
/* Turn fan fully on */
|
||||
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,
|
|||
dme1737_write(client, DME1737_REG_PWM_CONFIG(ix),
|
||||
data->pwm_config[ix]);
|
||||
/* 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);
|
||||
break;
|
||||
case 2:
|
||||
/* 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);
|
||||
/* Turn on auto mode using the saved zone channel
|
||||
* assignment */
|
||||
|
@ -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,
|
||||
dme1737_read(client,
|
||||
DME1737_REG_PWM_RR(0)));
|
||||
|
||||
} else {
|
||||
data->pwm_rr[0] = PWM_OFF_TO_REG(0, ix,
|
||||
dme1737_read(client,
|
||||
DME1737_REG_PWM_RR(0)));
|
||||
|
||||
}
|
||||
dme1737_write(client, DME1737_REG_PWM_RR(0),
|
||||
data->pwm_rr[0]);
|
||||
|
@ -1274,7 +1272,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
|
|||
data->pwm_min[ix]);
|
||||
break;
|
||||
default:
|
||||
dev_dbg(dev, "Unknown attr fetch (%d)\n", fn);
|
||||
dev_dbg(dev, "Unknown function %d.\n", fn);
|
||||
}
|
||||
exit:
|
||||
mutex_unlock(&data->update_lock);
|
||||
|
@ -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,
|
||||
const char *buf, size_t count)
|
||||
{
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct dme1737_data *data = i2c_get_clientdata(client);
|
||||
struct dme1737_data *data = dev_get_drvdata(dev);
|
||||
long val = simple_strtol(buf, NULL, 10);
|
||||
|
||||
data->vrm = val;
|
||||
|
@ -1678,6 +1675,16 @@ static struct attribute *dme1737_attr_pwm[] = {
|
|||
* 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);
|
||||
|
@ -1690,14 +1697,12 @@ static inline void dme1737_sio_outb(int sio_cip, int reg, int val)
|
|||
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;
|
||||
u16 addr;
|
||||
|
||||
/* Enter configuration mode */
|
||||
outb(0x55, sio_cip);
|
||||
dme1737_sio_enter(sio_cip);
|
||||
|
||||
/* Check 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)
|
|||
}
|
||||
|
||||
exit:
|
||||
/* Exit configuration mode */
|
||||
outb(0xaa, sio_cip);
|
||||
dme1737_sio_exit(sio_cip);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
@ -1744,31 +1748,122 @@ exit:
|
|||
* 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)
|
||||
{
|
||||
if (sysfs_chmod_file(&client->dev.kobj, attr, mode)) {
|
||||
dev_warn(&client->dev, "Failed to change permissions of %s.\n",
|
||||
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 i2c_client *client,
|
||||
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(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;
|
||||
u8 reg;
|
||||
|
||||
|
@ -1776,7 +1871,7 @@ static int dme1737_init_client(struct i2c_client *client)
|
|||
/* Inform if part is not monitoring/started */
|
||||
if (!(data->config & 0x01)) {
|
||||
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 "
|
||||
"override.\n");
|
||||
return -EFAULT;
|
||||
|
@ -1788,7 +1883,7 @@ static int dme1737_init_client(struct i2c_client *client)
|
|||
}
|
||||
/* Inform if part is not ready */
|
||||
if (!(data->config & 0x04)) {
|
||||
dev_err(&client->dev, "Device is not ready.\n");
|
||||
dev_err(dev, "Device is not ready.\n");
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
* For this, we need to query the runtime registers through the
|
||||
* Super-IO LPC interface. Try both config ports 0x2e and 0x4e. */
|
||||
if (dme1737_sio_get_features(0x2e, client) &&
|
||||
dme1737_sio_get_features(0x4e, client)) {
|
||||
dev_warn(&client->dev, "Failed to query Super-IO for optional "
|
||||
if (dme1737_i2c_get_features(0x2e, data) &&
|
||||
dme1737_i2c_get_features(0x4e, data)) {
|
||||
dev_warn(dev, "Failed to query Super-IO for optional "
|
||||
"features.\n");
|
||||
}
|
||||
|
||||
|
@ -1819,7 +1914,7 @@ static int dme1737_init_client(struct i2c_client *client)
|
|||
data->has_fan |= 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",
|
||||
(data->has_pwm & (1 << 2)) ? "yes" : "no",
|
||||
(data->has_pwm & (1 << 4)) ? "yes" : "no",
|
||||
|
@ -1832,7 +1927,7 @@ static int dme1737_init_client(struct i2c_client *client)
|
|||
reg = dme1737_read(client, DME1737_REG_TACH_PWM);
|
||||
/* Inform if fan-to-pwm mapping differs from the default */
|
||||
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, "
|
||||
"fan4->pwm%d. Please report to the driver "
|
||||
"maintainer.\n",
|
||||
|
@ -1849,7 +1944,7 @@ static int dme1737_init_client(struct i2c_client *client)
|
|||
DME1737_REG_PWM_CONFIG(ix));
|
||||
if ((data->has_pwm & (1 << ix)) &&
|
||||
(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);
|
||||
data->pwm_config[ix] = PWM_EN_TO_REG(1,
|
||||
data->pwm_config[ix]);
|
||||
|
@ -1872,13 +1967,14 @@ static int dme1737_init_client(struct i2c_client *client)
|
|||
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)
|
||||
{
|
||||
u8 company, verstep = 0;
|
||||
struct i2c_client *client;
|
||||
struct dme1737_data *data;
|
||||
int ix, err = 0;
|
||||
struct device *dev;
|
||||
int err = 0;
|
||||
const char *name;
|
||||
|
||||
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
|
||||
|
@ -1894,7 +1990,8 @@ static int dme1737_detect(struct i2c_adapter *adapter, int address,
|
|||
i2c_set_clientdata(client, data);
|
||||
client->addr = address;
|
||||
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
|
||||
* parameter (default), so we must identify the chip. */
|
||||
|
@ -1922,92 +2019,33 @@ static int dme1737_detect(struct i2c_adapter *adapter, int address,
|
|||
goto exit_kfree;
|
||||
}
|
||||
|
||||
dev_info(dev, "Found a DME1737 chip at 0x%02x (rev 0x%02x).\n",
|
||||
client->addr, verstep);
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/* Create standard sysfs attributes */
|
||||
if ((err = sysfs_create_group(&client->dev.kobj, &dme1737_group))) {
|
||||
/* Create sysfs files */
|
||||
if ((err = dme1737_create_files(dev))) {
|
||||
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 */
|
||||
data->class_dev = hwmon_device_register(&client->dev);
|
||||
data->class_dev = hwmon_device_register(dev);
|
||||
if (IS_ERR(data->class_dev)) {
|
||||
dev_err(dev, "Failed to register device.\n");
|
||||
err = PTR_ERR(data->class_dev);
|
||||
goto exit_remove;
|
||||
}
|
||||
|
||||
dev_info(&adapter->dev, "Found a DME1737 chip at 0x%02x "
|
||||
"(rev 0x%02x)\n", client->addr, verstep);
|
||||
|
||||
return 0;
|
||||
|
||||
exit_remove:
|
||||
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);
|
||||
dme1737_remove_files(dev);
|
||||
exit_detach:
|
||||
i2c_detach_client(client);
|
||||
exit_kfree:
|
||||
|
@ -2016,35 +2054,22 @@ exit:
|
|||
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)) {
|
||||
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);
|
||||
int ix, err;
|
||||
int err;
|
||||
|
||||
hwmon_device_unregister(data->class_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);
|
||||
dme1737_remove_files(&client->dev);
|
||||
|
||||
if ((err = i2c_detach_client(client))) {
|
||||
return err;
|
||||
|
@ -2054,22 +2079,22 @@ static int dme1737_detach_client(struct i2c_client *client)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static struct i2c_driver dme1737_driver = {
|
||||
static struct i2c_driver dme1737_i2c_driver = {
|
||||
.driver = {
|
||||
.name = "dme1737",
|
||||
},
|
||||
.attach_adapter = dme1737_attach_adapter,
|
||||
.detach_client = dme1737_detach_client,
|
||||
.attach_adapter = dme1737_i2c_attach_adapter,
|
||||
.detach_client = dme1737_i2c_detach_client,
|
||||
};
|
||||
|
||||
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)
|
||||
{
|
||||
i2c_del_driver(&dme1737_driver);
|
||||
i2c_del_driver(&dme1737_i2c_driver);
|
||||
}
|
||||
|
||||
MODULE_AUTHOR("Juerg Haefliger <juergh@gmail.com>");
|
||||
|
|
Loading…
Reference in a new issue