hwmon: (dme1737) Fix some merge conflicts

class_dev -> hwmon_dev

Signed-off-by: Mark M. Hoffman <mhoffman@lightlink.com>
This commit is contained in:
Mark M. Hoffman 2007-10-10 22:32:50 -04:00
commit 62ee3e10d3

View file

@ -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,241 @@ 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)
/* ---------------------------------------------------------------------
* Device detection, registration and 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);
}
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;
data->config = dme1737_read(client, DME1737_REG_CONFIG);
/* Inform if part is not monitoring/started */
if (!(data->config & 0x01)) {
if (!force_start) {
dev_err(dev, "Device is not monitoring. "
"Use the force_start load parameter to "
"override.\n");
return -EFAULT;
}
/* Force monitoring */
data->config |= 0x01;
dme1737_write(client, DME1737_REG_CONFIG, data->config);
}
/* Inform if part is not ready */
if (!(data->config & 0x04)) {
dev_err(dev, "Device is not ready.\n");
return -EFAULT;
}
data->config2 = dme1737_read(client, DME1737_REG_CONFIG2);
/* Check if optional fan3 input is enabled */
if (data->config2 & 0x04) {
data->has_fan |= (1 << 2);
}
/* Fan4 and pwm3 are only available if the client's I2C address
* is the default 0x2e. Otherwise the I/Os associated with these
* functions are used for addr enable/select. */
if (client->addr == 0x2e) {
data->has_fan |= (1 << 3);
data->has_pwm |= (1 << 2);
}
/* 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_i2c_get_features(0x2e, data) &&
dme1737_i2c_get_features(0x4e, data)) {
dev_warn(dev, "Failed to query Super-IO for optional "
"features.\n");
}
/* Fan1, fan2, pwm1, and pwm2 are always present */
data->has_fan |= 0x03;
data->has_pwm |= 0x03;
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",
(data->has_pwm & (1 << 5)) ? "yes" : "no",
(data->has_fan & (1 << 2)) ? "yes" : "no",
(data->has_fan & (1 << 3)) ? "yes" : "no",
(data->has_fan & (1 << 4)) ? "yes" : "no",
(data->has_fan & (1 << 5)) ? "yes" : "no");
reg = dme1737_read(client, DME1737_REG_TACH_PWM);
/* Inform if fan-to-pwm mapping differs from the default */
if (reg != 0xa4) {
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",
(reg & 0x03) + 1, ((reg >> 2) & 0x03) + 1,
((reg >> 4) & 0x03) + 1, ((reg >> 6) & 0x03) + 1);
}
/* Switch pwm[1-3] to manual mode if they are currently disabled and
* set the duty-cycles to 0% (which is identical to the PWMs being
* disabled). */
if (!(data->config & 0x02)) {
for (ix = 0; ix < 3; ix++) {
data->pwm_config[ix] = dme1737_read(client,
DME1737_REG_PWM_CONFIG(ix));
if ((data->has_pwm & (1 << ix)) &&
(PWM_EN_FROM_REG(data->pwm_config[ix]) == -1)) {
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]);
dme1737_write(client, DME1737_REG_PWM(ix), 0);
dme1737_write(client,
DME1737_REG_PWM_CONFIG(ix),
data->pwm_config[ix]);
}
}
}
/* Initialize the default PWM auto channels zone (acz) assignments */
data->pwm_acz[0] = 1; /* pwm1 -> zone1 */
data->pwm_acz[1] = 2; /* pwm2 -> zone2 */
data->pwm_acz[2] = 4; /* pwm3 -> zone3 */
/* Set VRM */
data->vrm = vid_which_vrm();
return 0;
}
/* ---------------------------------------------------------------------
* I2C device detection and registration
* --------------------------------------------------------------------- */
static struct i2c_driver dme1737_i2c_driver;
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,151 +1968,19 @@ 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;
}
/* ---------------------------------------------------------------------
* Device detection, registration and initialization
* --------------------------------------------------------------------- */
static struct i2c_driver dme1737_driver;
static void dme1737_chmod_file(struct i2c_client *client,
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",
attr->name);
}
}
static void dme1737_chmod_group(struct i2c_client *client,
const struct attribute_group *group,
mode_t mode)
{
struct attribute **attr;
for (attr = group->attrs; *attr; attr++) {
dme1737_chmod_file(client, *attr, mode);
}
}
static int dme1737_init_client(struct i2c_client *client)
{
struct dme1737_data *data = i2c_get_clientdata(client);
int ix;
u8 reg;
data->config = dme1737_read(client, DME1737_REG_CONFIG);
/* Inform if part is not monitoring/started */
if (!(data->config & 0x01)) {
if (!force_start) {
dev_err(&client->dev, "Device is not monitoring. "
"Use the force_start load parameter to "
"override.\n");
return -EFAULT;
}
/* Force monitoring */
data->config |= 0x01;
dme1737_write(client, DME1737_REG_CONFIG, data->config);
}
/* Inform if part is not ready */
if (!(data->config & 0x04)) {
dev_err(&client->dev, "Device is not ready.\n");
return -EFAULT;
}
data->config2 = dme1737_read(client, DME1737_REG_CONFIG2);
/* Check if optional fan3 input is enabled */
if (data->config2 & 0x04) {
data->has_fan |= (1 << 2);
}
/* Fan4 and pwm3 are only available if the client's I2C address
* is the default 0x2e. Otherwise the I/Os associated with these
* functions are used for addr enable/select. */
if (client->addr == 0x2e) {
data->has_fan |= (1 << 3);
data->has_pwm |= (1 << 2);
}
/* 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 "
"features.\n");
}
/* Fan1, fan2, pwm1, and pwm2 are always present */
data->has_fan |= 0x03;
data->has_pwm |= 0x03;
dev_info(&client->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",
(data->has_pwm & (1 << 5)) ? "yes" : "no",
(data->has_fan & (1 << 2)) ? "yes" : "no",
(data->has_fan & (1 << 3)) ? "yes" : "no",
(data->has_fan & (1 << 4)) ? "yes" : "no",
(data->has_fan & (1 << 5)) ? "yes" : "no");
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: "
"fan1->pwm%d, fan2->pwm%d, fan3->pwm%d, "
"fan4->pwm%d. Please report to the driver "
"maintainer.\n",
(reg & 0x03) + 1, ((reg >> 2) & 0x03) + 1,
((reg >> 4) & 0x03) + 1, ((reg >> 6) & 0x03) + 1);
}
/* Switch pwm[1-3] to manual mode if they are currently disabled and
* set the duty-cycles to 0% (which is identical to the PWMs being
* disabled). */
if (!(data->config & 0x02)) {
for (ix = 0; ix < 3; ix++) {
data->pwm_config[ix] = dme1737_read(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 "
"manual mode.\n", ix + 1);
data->pwm_config[ix] = PWM_EN_TO_REG(1,
data->pwm_config[ix]);
dme1737_write(client, DME1737_REG_PWM(ix), 0);
dme1737_write(client,
DME1737_REG_PWM_CONFIG(ix),
data->pwm_config[ix]);
}
}
}
/* Initialize the default PWM auto channels zone (acz) assignments */
data->pwm_acz[0] = 1; /* pwm1 -> zone1 */
data->pwm_acz[1] = 2; /* pwm2 -> zone2 */
data->pwm_acz[2] = 4; /* pwm3 -> zone3 */
/* Set VRM */
data->vrm = vid_which_vrm();
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 +1996,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 +2025,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->hwmon_dev = hwmon_device_register(&client->dev);
data->hwmon_dev = hwmon_device_register(dev);
if (IS_ERR(data->hwmon_dev)) {
dev_err(dev, "Failed to register device.\n");
err = PTR_ERR(data->hwmon_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 +2060,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->hwmon_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 +2085,26 @@ 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,
};
/* ---------------------------------------------------------------------
* Module initialization and cleanup
* --------------------------------------------------------------------- */
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>");