Loading drivers/hwmon/dme1737.c +312 −277 Original line number Diff line number Diff line Loading @@ -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]; Loading Loading @@ -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); Loading @@ -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; Loading @@ -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); Loading Loading @@ -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); Loading @@ -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; Loading @@ -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); Loading Loading @@ -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); Loading @@ -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; Loading Loading @@ -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); Loading Loading @@ -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); Loading @@ -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; Loading Loading @@ -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); Loading Loading @@ -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; Loading Loading @@ -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, Loading @@ -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 */ Loading Loading @@ -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]); Loading @@ -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); Loading @@ -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; Loading Loading @@ -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); Loading @@ -1690,85 +1697,126 @@ 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) { struct dme1737_data *data = i2c_get_clientdata(client); int err = 0, reg; u16 addr; if (sysfs_chmod_file(&dev->kobj, attr, mode)) { dev_warn(dev, "Failed to change permissions of %s.\n", attr->name); } } /* Enter configuration mode */ outb(0x55, sio_cip); static void dme1737_chmod_group(struct device *dev, const struct attribute_group *group, mode_t mode) { struct attribute **attr; /* Check device ID * The DME1737 can return either 0x78 or 0x77 as its device ID. */ reg = dme1737_sio_inb(sio_cip, 0x20); if (!(reg == 0x77 || reg == 0x78)) { err = -ENODEV; goto exit; for (attr = group->attrs; *attr; attr++) { dme1737_chmod_file(dev, *attr, mode); } } /* Select logical device A (runtime registers) */ dme1737_sio_outb(sio_cip, 0x07, 0x0a); static void dme1737_remove_files(struct device *dev) { struct dme1737_data *data = dev_get_drvdata(dev); int ix; /* Get the base address of the runtime registers */ if (!(addr = (dme1737_sio_inb(sio_cip, 0x60) << 8) | dme1737_sio_inb(sio_cip, 0x61))) { err = -ENODEV; goto exit; 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]); } } /* Read the runtime registers to determine which optional features * are enabled and available. Bits [3:2] of registers 0x43-0x46 are set * to '10' if the respective feature is enabled. */ if ((inb(addr + 0x43) & 0x0c) == 0x08) { /* fan6 */ data->has_fan |= (1 << 5); 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]); } if ((inb(addr + 0x44) & 0x0c) == 0x08) { /* pwm6 */ data->has_pwm |= (1 << 5); } if ((inb(addr + 0x45) & 0x0c) == 0x08) { /* fan5 */ data->has_fan |= (1 << 4); sysfs_remove_group(&dev->kobj, &dme1737_group); } if ((inb(addr + 0x46) & 0x0c) == 0x08) { /* pwm5 */ data->has_pwm |= (1 << 4); 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; } exit: /* Exit configuration mode */ outb(0xaa, sio_cip); /* 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; } } } return err; /* 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; } } } /* --------------------------------------------------------------------- * Device detection, registration and initialization * --------------------------------------------------------------------- */ /* 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); static struct i2c_driver dme1737_driver; /* 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); } } 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); /* 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); } } } static void dme1737_chmod_group(struct i2c_client *client, const struct attribute_group *group, mode_t mode) { struct attribute **attr; return 0; for (attr = group->attrs; *attr; attr++) { dme1737_chmod_file(client, *attr, mode); } exit_remove: dme1737_remove_files(dev); exit: return err; } static int dme1737_init_client(struct i2c_client *client) static int dme1737_init_device(struct device *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 reg; Loading @@ -1776,7 +1824,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; Loading @@ -1788,7 +1836,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; } Loading @@ -1809,9 +1857,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"); } Loading @@ -1819,7 +1867,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", Loading @@ -1832,7 +1880,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", Loading @@ -1849,7 +1897,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]); Loading @@ -1872,13 +1920,67 @@ static int dme1737_init_client(struct i2c_client *client) return 0; } static int dme1737_detect(struct i2c_adapter *adapter, int address, /* --------------------------------------------------------------------- * 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) { int err = 0, reg; u16 addr; dme1737_sio_enter(sio_cip); /* Check device ID * The DME1737 can return either 0x78 or 0x77 as its device ID. */ reg = dme1737_sio_inb(sio_cip, 0x20); if (!(reg == 0x77 || reg == 0x78)) { err = -ENODEV; goto exit; } /* Select logical device A (runtime registers) */ dme1737_sio_outb(sio_cip, 0x07, 0x0a); /* Get the base address of the runtime registers */ if (!(addr = (dme1737_sio_inb(sio_cip, 0x60) << 8) | dme1737_sio_inb(sio_cip, 0x61))) { err = -ENODEV; goto exit; } /* Read the runtime registers to determine which optional features * are enabled and available. Bits [3:2] of registers 0x43-0x46 are set * to '10' if the respective feature is enabled. */ if ((inb(addr + 0x43) & 0x0c) == 0x08) { /* fan6 */ data->has_fan |= (1 << 5); } if ((inb(addr + 0x44) & 0x0c) == 0x08) { /* pwm6 */ data->has_pwm |= (1 << 5); } if ((inb(addr + 0x45) & 0x0c) == 0x08) { /* fan5 */ data->has_fan |= (1 << 4); } if ((inb(addr + 0x46) & 0x0c) == 0x08) { /* pwm5 */ data->has_pwm |= (1 << 4); } exit: dme1737_sio_exit(sio_cip); return err; } 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)) { Loading @@ -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. */ Loading Loading @@ -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: Loading @@ -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; Loading @@ -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>"); Loading Loading
drivers/hwmon/dme1737.c +312 −277 Original line number Diff line number Diff line Loading @@ -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]; Loading Loading @@ -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); Loading @@ -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; Loading @@ -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); Loading Loading @@ -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); Loading @@ -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; Loading @@ -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); Loading Loading @@ -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); Loading @@ -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; Loading Loading @@ -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); Loading Loading @@ -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); Loading @@ -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; Loading Loading @@ -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); Loading Loading @@ -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; Loading Loading @@ -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, Loading @@ -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 */ Loading Loading @@ -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]); Loading @@ -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); Loading @@ -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; Loading Loading @@ -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); Loading @@ -1690,85 +1697,126 @@ 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) { struct dme1737_data *data = i2c_get_clientdata(client); int err = 0, reg; u16 addr; if (sysfs_chmod_file(&dev->kobj, attr, mode)) { dev_warn(dev, "Failed to change permissions of %s.\n", attr->name); } } /* Enter configuration mode */ outb(0x55, sio_cip); static void dme1737_chmod_group(struct device *dev, const struct attribute_group *group, mode_t mode) { struct attribute **attr; /* Check device ID * The DME1737 can return either 0x78 or 0x77 as its device ID. */ reg = dme1737_sio_inb(sio_cip, 0x20); if (!(reg == 0x77 || reg == 0x78)) { err = -ENODEV; goto exit; for (attr = group->attrs; *attr; attr++) { dme1737_chmod_file(dev, *attr, mode); } } /* Select logical device A (runtime registers) */ dme1737_sio_outb(sio_cip, 0x07, 0x0a); static void dme1737_remove_files(struct device *dev) { struct dme1737_data *data = dev_get_drvdata(dev); int ix; /* Get the base address of the runtime registers */ if (!(addr = (dme1737_sio_inb(sio_cip, 0x60) << 8) | dme1737_sio_inb(sio_cip, 0x61))) { err = -ENODEV; goto exit; 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]); } } /* Read the runtime registers to determine which optional features * are enabled and available. Bits [3:2] of registers 0x43-0x46 are set * to '10' if the respective feature is enabled. */ if ((inb(addr + 0x43) & 0x0c) == 0x08) { /* fan6 */ data->has_fan |= (1 << 5); 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]); } if ((inb(addr + 0x44) & 0x0c) == 0x08) { /* pwm6 */ data->has_pwm |= (1 << 5); } if ((inb(addr + 0x45) & 0x0c) == 0x08) { /* fan5 */ data->has_fan |= (1 << 4); sysfs_remove_group(&dev->kobj, &dme1737_group); } if ((inb(addr + 0x46) & 0x0c) == 0x08) { /* pwm5 */ data->has_pwm |= (1 << 4); 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; } exit: /* Exit configuration mode */ outb(0xaa, sio_cip); /* 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; } } } return err; /* 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; } } } /* --------------------------------------------------------------------- * Device detection, registration and initialization * --------------------------------------------------------------------- */ /* 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); static struct i2c_driver dme1737_driver; /* 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); } } 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); /* 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); } } } static void dme1737_chmod_group(struct i2c_client *client, const struct attribute_group *group, mode_t mode) { struct attribute **attr; return 0; for (attr = group->attrs; *attr; attr++) { dme1737_chmod_file(client, *attr, mode); } exit_remove: dme1737_remove_files(dev); exit: return err; } static int dme1737_init_client(struct i2c_client *client) static int dme1737_init_device(struct device *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 reg; Loading @@ -1776,7 +1824,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; Loading @@ -1788,7 +1836,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; } Loading @@ -1809,9 +1857,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"); } Loading @@ -1819,7 +1867,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", Loading @@ -1832,7 +1880,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", Loading @@ -1849,7 +1897,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]); Loading @@ -1872,13 +1920,67 @@ static int dme1737_init_client(struct i2c_client *client) return 0; } static int dme1737_detect(struct i2c_adapter *adapter, int address, /* --------------------------------------------------------------------- * 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) { int err = 0, reg; u16 addr; dme1737_sio_enter(sio_cip); /* Check device ID * The DME1737 can return either 0x78 or 0x77 as its device ID. */ reg = dme1737_sio_inb(sio_cip, 0x20); if (!(reg == 0x77 || reg == 0x78)) { err = -ENODEV; goto exit; } /* Select logical device A (runtime registers) */ dme1737_sio_outb(sio_cip, 0x07, 0x0a); /* Get the base address of the runtime registers */ if (!(addr = (dme1737_sio_inb(sio_cip, 0x60) << 8) | dme1737_sio_inb(sio_cip, 0x61))) { err = -ENODEV; goto exit; } /* Read the runtime registers to determine which optional features * are enabled and available. Bits [3:2] of registers 0x43-0x46 are set * to '10' if the respective feature is enabled. */ if ((inb(addr + 0x43) & 0x0c) == 0x08) { /* fan6 */ data->has_fan |= (1 << 5); } if ((inb(addr + 0x44) & 0x0c) == 0x08) { /* pwm6 */ data->has_pwm |= (1 << 5); } if ((inb(addr + 0x45) & 0x0c) == 0x08) { /* fan5 */ data->has_fan |= (1 << 4); } if ((inb(addr + 0x46) & 0x0c) == 0x08) { /* pwm5 */ data->has_pwm |= (1 << 4); } exit: dme1737_sio_exit(sio_cip); return err; } 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)) { Loading @@ -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. */ Loading Loading @@ -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: Loading @@ -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; Loading @@ -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>"); Loading