diff options
| -rw-r--r-- | drivers/hwmon/lm85.c | 144 |
1 files changed, 51 insertions, 93 deletions
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c index 9fdf1c021007..2b4b419273fe 100644 --- a/drivers/hwmon/lm85.c +++ b/drivers/hwmon/lm85.c | |||
| @@ -302,7 +302,8 @@ struct lm85_autofan { | |||
| 302 | * The structure is dynamically allocated. | 302 | * The structure is dynamically allocated. |
| 303 | */ | 303 | */ |
| 304 | struct lm85_data { | 304 | struct lm85_data { |
| 305 | struct device *hwmon_dev; | 305 | struct i2c_client *client; |
| 306 | const struct attribute_group *groups[6]; | ||
| 306 | const int *freq_map; | 307 | const int *freq_map; |
| 307 | enum chips type; | 308 | enum chips type; |
| 308 | 309 | ||
| @@ -382,8 +383,8 @@ static void lm85_write_value(struct i2c_client *client, u8 reg, int value) | |||
| 382 | 383 | ||
| 383 | static struct lm85_data *lm85_update_device(struct device *dev) | 384 | static struct lm85_data *lm85_update_device(struct device *dev) |
| 384 | { | 385 | { |
| 385 | struct i2c_client *client = to_i2c_client(dev); | 386 | struct lm85_data *data = dev_get_drvdata(dev); |
| 386 | struct lm85_data *data = i2c_get_clientdata(client); | 387 | struct i2c_client *client = data->client; |
| 387 | int i; | 388 | int i; |
| 388 | 389 | ||
| 389 | mutex_lock(&data->update_lock); | 390 | mutex_lock(&data->update_lock); |
| @@ -584,8 +585,8 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, | |||
| 584 | const char *buf, size_t count) | 585 | const char *buf, size_t count) |
| 585 | { | 586 | { |
| 586 | int nr = to_sensor_dev_attr(attr)->index; | 587 | int nr = to_sensor_dev_attr(attr)->index; |
| 587 | struct i2c_client *client = to_i2c_client(dev); | 588 | struct lm85_data *data = dev_get_drvdata(dev); |
| 588 | struct lm85_data *data = i2c_get_clientdata(client); | 589 | struct i2c_client *client = data->client; |
| 589 | unsigned long val; | 590 | unsigned long val; |
| 590 | int err; | 591 | int err; |
| 591 | 592 | ||
| @@ -708,8 +709,8 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | |||
| 708 | const char *buf, size_t count) | 709 | const char *buf, size_t count) |
| 709 | { | 710 | { |
| 710 | int nr = to_sensor_dev_attr(attr)->index; | 711 | int nr = to_sensor_dev_attr(attr)->index; |
| 711 | struct i2c_client *client = to_i2c_client(dev); | 712 | struct lm85_data *data = dev_get_drvdata(dev); |
| 712 | struct lm85_data *data = i2c_get_clientdata(client); | 713 | struct i2c_client *client = data->client; |
| 713 | unsigned long val; | 714 | unsigned long val; |
| 714 | int err; | 715 | int err; |
| 715 | 716 | ||
| @@ -750,8 +751,8 @@ static ssize_t set_pwm_enable(struct device *dev, struct device_attribute | |||
| 750 | *attr, const char *buf, size_t count) | 751 | *attr, const char *buf, size_t count) |
| 751 | { | 752 | { |
| 752 | int nr = to_sensor_dev_attr(attr)->index; | 753 | int nr = to_sensor_dev_attr(attr)->index; |
| 753 | struct i2c_client *client = to_i2c_client(dev); | 754 | struct lm85_data *data = dev_get_drvdata(dev); |
| 754 | struct lm85_data *data = i2c_get_clientdata(client); | 755 | struct i2c_client *client = data->client; |
| 755 | u8 config; | 756 | u8 config; |
| 756 | unsigned long val; | 757 | unsigned long val; |
| 757 | int err; | 758 | int err; |
| @@ -808,8 +809,8 @@ static ssize_t set_pwm_freq(struct device *dev, | |||
| 808 | struct device_attribute *attr, const char *buf, size_t count) | 809 | struct device_attribute *attr, const char *buf, size_t count) |
| 809 | { | 810 | { |
| 810 | int nr = to_sensor_dev_attr(attr)->index; | 811 | int nr = to_sensor_dev_attr(attr)->index; |
| 811 | struct i2c_client *client = to_i2c_client(dev); | 812 | struct lm85_data *data = dev_get_drvdata(dev); |
| 812 | struct lm85_data *data = i2c_get_clientdata(client); | 813 | struct i2c_client *client = data->client; |
| 813 | unsigned long val; | 814 | unsigned long val; |
| 814 | int err; | 815 | int err; |
| 815 | 816 | ||
| @@ -875,8 +876,8 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, | |||
| 875 | const char *buf, size_t count) | 876 | const char *buf, size_t count) |
| 876 | { | 877 | { |
| 877 | int nr = to_sensor_dev_attr(attr)->index; | 878 | int nr = to_sensor_dev_attr(attr)->index; |
| 878 | struct i2c_client *client = to_i2c_client(dev); | 879 | struct lm85_data *data = dev_get_drvdata(dev); |
| 879 | struct lm85_data *data = i2c_get_clientdata(client); | 880 | struct i2c_client *client = data->client; |
| 880 | long val; | 881 | long val; |
| 881 | int err; | 882 | int err; |
| 882 | 883 | ||
| @@ -903,8 +904,8 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, | |||
| 903 | const char *buf, size_t count) | 904 | const char *buf, size_t count) |
| 904 | { | 905 | { |
| 905 | int nr = to_sensor_dev_attr(attr)->index; | 906 | int nr = to_sensor_dev_attr(attr)->index; |
| 906 | struct i2c_client *client = to_i2c_client(dev); | 907 | struct lm85_data *data = dev_get_drvdata(dev); |
| 907 | struct lm85_data *data = i2c_get_clientdata(client); | 908 | struct i2c_client *client = data->client; |
| 908 | long val; | 909 | long val; |
| 909 | int err; | 910 | int err; |
| 910 | 911 | ||
| @@ -959,8 +960,8 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, | |||
| 959 | const char *buf, size_t count) | 960 | const char *buf, size_t count) |
| 960 | { | 961 | { |
| 961 | int nr = to_sensor_dev_attr(attr)->index; | 962 | int nr = to_sensor_dev_attr(attr)->index; |
| 962 | struct i2c_client *client = to_i2c_client(dev); | 963 | struct lm85_data *data = dev_get_drvdata(dev); |
| 963 | struct lm85_data *data = i2c_get_clientdata(client); | 964 | struct i2c_client *client = data->client; |
| 964 | long val; | 965 | long val; |
| 965 | int err; | 966 | int err; |
| 966 | 967 | ||
| @@ -990,8 +991,8 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | |||
| 990 | const char *buf, size_t count) | 991 | const char *buf, size_t count) |
| 991 | { | 992 | { |
| 992 | int nr = to_sensor_dev_attr(attr)->index; | 993 | int nr = to_sensor_dev_attr(attr)->index; |
| 993 | struct i2c_client *client = to_i2c_client(dev); | 994 | struct lm85_data *data = dev_get_drvdata(dev); |
| 994 | struct lm85_data *data = i2c_get_clientdata(client); | 995 | struct i2c_client *client = data->client; |
| 995 | long val; | 996 | long val; |
| 996 | int err; | 997 | int err; |
| 997 | 998 | ||
| @@ -1036,8 +1037,8 @@ static ssize_t set_pwm_auto_channels(struct device *dev, | |||
| 1036 | struct device_attribute *attr, const char *buf, size_t count) | 1037 | struct device_attribute *attr, const char *buf, size_t count) |
| 1037 | { | 1038 | { |
| 1038 | int nr = to_sensor_dev_attr(attr)->index; | 1039 | int nr = to_sensor_dev_attr(attr)->index; |
| 1039 | struct i2c_client *client = to_i2c_client(dev); | 1040 | struct lm85_data *data = dev_get_drvdata(dev); |
| 1040 | struct lm85_data *data = i2c_get_clientdata(client); | 1041 | struct i2c_client *client = data->client; |
| 1041 | long val; | 1042 | long val; |
| 1042 | int err; | 1043 | int err; |
| 1043 | 1044 | ||
| @@ -1066,8 +1067,8 @@ static ssize_t set_pwm_auto_pwm_min(struct device *dev, | |||
| 1066 | struct device_attribute *attr, const char *buf, size_t count) | 1067 | struct device_attribute *attr, const char *buf, size_t count) |
| 1067 | { | 1068 | { |
| 1068 | int nr = to_sensor_dev_attr(attr)->index; | 1069 | int nr = to_sensor_dev_attr(attr)->index; |
| 1069 | struct i2c_client *client = to_i2c_client(dev); | 1070 | struct lm85_data *data = dev_get_drvdata(dev); |
| 1070 | struct lm85_data *data = i2c_get_clientdata(client); | 1071 | struct i2c_client *client = data->client; |
| 1071 | unsigned long val; | 1072 | unsigned long val; |
| 1072 | int err; | 1073 | int err; |
| 1073 | 1074 | ||
| @@ -1095,8 +1096,8 @@ static ssize_t set_pwm_auto_pwm_minctl(struct device *dev, | |||
| 1095 | struct device_attribute *attr, const char *buf, size_t count) | 1096 | struct device_attribute *attr, const char *buf, size_t count) |
| 1096 | { | 1097 | { |
| 1097 | int nr = to_sensor_dev_attr(attr)->index; | 1098 | int nr = to_sensor_dev_attr(attr)->index; |
| 1098 | struct i2c_client *client = to_i2c_client(dev); | 1099 | struct lm85_data *data = dev_get_drvdata(dev); |
| 1099 | struct lm85_data *data = i2c_get_clientdata(client); | 1100 | struct i2c_client *client = data->client; |
| 1100 | u8 tmp; | 1101 | u8 tmp; |
| 1101 | long val; | 1102 | long val; |
| 1102 | int err; | 1103 | int err; |
| @@ -1146,8 +1147,8 @@ static ssize_t set_temp_auto_temp_off(struct device *dev, | |||
| 1146 | struct device_attribute *attr, const char *buf, size_t count) | 1147 | struct device_attribute *attr, const char *buf, size_t count) |
| 1147 | { | 1148 | { |
| 1148 | int nr = to_sensor_dev_attr(attr)->index; | 1149 | int nr = to_sensor_dev_attr(attr)->index; |
| 1149 | struct i2c_client *client = to_i2c_client(dev); | 1150 | struct lm85_data *data = dev_get_drvdata(dev); |
| 1150 | struct lm85_data *data = i2c_get_clientdata(client); | 1151 | struct i2c_client *client = data->client; |
| 1151 | int min; | 1152 | int min; |
| 1152 | long val; | 1153 | long val; |
| 1153 | int err; | 1154 | int err; |
| @@ -1183,8 +1184,8 @@ static ssize_t set_temp_auto_temp_min(struct device *dev, | |||
| 1183 | struct device_attribute *attr, const char *buf, size_t count) | 1184 | struct device_attribute *attr, const char *buf, size_t count) |
| 1184 | { | 1185 | { |
| 1185 | int nr = to_sensor_dev_attr(attr)->index; | 1186 | int nr = to_sensor_dev_attr(attr)->index; |
| 1186 | struct i2c_client *client = to_i2c_client(dev); | 1187 | struct lm85_data *data = dev_get_drvdata(dev); |
| 1187 | struct lm85_data *data = i2c_get_clientdata(client); | 1188 | struct i2c_client *client = data->client; |
| 1188 | long val; | 1189 | long val; |
| 1189 | int err; | 1190 | int err; |
| 1190 | 1191 | ||
| @@ -1222,8 +1223,8 @@ static ssize_t set_temp_auto_temp_max(struct device *dev, | |||
| 1222 | struct device_attribute *attr, const char *buf, size_t count) | 1223 | struct device_attribute *attr, const char *buf, size_t count) |
| 1223 | { | 1224 | { |
| 1224 | int nr = to_sensor_dev_attr(attr)->index; | 1225 | int nr = to_sensor_dev_attr(attr)->index; |
| 1225 | struct i2c_client *client = to_i2c_client(dev); | 1226 | struct lm85_data *data = dev_get_drvdata(dev); |
| 1226 | struct lm85_data *data = i2c_get_clientdata(client); | 1227 | struct i2c_client *client = data->client; |
| 1227 | int min; | 1228 | int min; |
| 1228 | long val; | 1229 | long val; |
| 1229 | int err; | 1230 | int err; |
| @@ -1256,8 +1257,8 @@ static ssize_t set_temp_auto_temp_crit(struct device *dev, | |||
| 1256 | struct device_attribute *attr, const char *buf, size_t count) | 1257 | struct device_attribute *attr, const char *buf, size_t count) |
| 1257 | { | 1258 | { |
| 1258 | int nr = to_sensor_dev_attr(attr)->index; | 1259 | int nr = to_sensor_dev_attr(attr)->index; |
| 1259 | struct i2c_client *client = to_i2c_client(dev); | 1260 | struct lm85_data *data = dev_get_drvdata(dev); |
| 1260 | struct lm85_data *data = i2c_get_clientdata(client); | 1261 | struct i2c_client *client = data->client; |
| 1261 | long val; | 1262 | long val; |
| 1262 | int err; | 1263 | int err; |
| 1263 | 1264 | ||
| @@ -1548,30 +1549,18 @@ static int lm85_detect(struct i2c_client *client, struct i2c_board_info *info) | |||
| 1548 | return 0; | 1549 | return 0; |
| 1549 | } | 1550 | } |
| 1550 | 1551 | ||
| 1551 | static void lm85_remove_files(struct i2c_client *client, struct lm85_data *data) | 1552 | static int lm85_probe(struct i2c_client *client, const struct i2c_device_id *id) |
| 1552 | { | ||
| 1553 | sysfs_remove_group(&client->dev.kobj, &lm85_group); | ||
| 1554 | if (data->type != emc6d103s) { | ||
| 1555 | sysfs_remove_group(&client->dev.kobj, &lm85_group_minctl); | ||
| 1556 | sysfs_remove_group(&client->dev.kobj, &lm85_group_temp_off); | ||
| 1557 | } | ||
| 1558 | if (!data->has_vid5) | ||
| 1559 | sysfs_remove_group(&client->dev.kobj, &lm85_group_in4); | ||
| 1560 | if (data->type == emc6d100) | ||
| 1561 | sysfs_remove_group(&client->dev.kobj, &lm85_group_in567); | ||
| 1562 | } | ||
| 1563 | |||
| 1564 | static int lm85_probe(struct i2c_client *client, | ||
| 1565 | const struct i2c_device_id *id) | ||
| 1566 | { | 1553 | { |
| 1554 | struct device *dev = &client->dev; | ||
| 1555 | struct device *hwmon_dev; | ||
| 1567 | struct lm85_data *data; | 1556 | struct lm85_data *data; |
| 1568 | int err; | 1557 | int idx = 0; |
| 1569 | 1558 | ||
| 1570 | data = devm_kzalloc(&client->dev, sizeof(struct lm85_data), GFP_KERNEL); | 1559 | data = devm_kzalloc(dev, sizeof(struct lm85_data), GFP_KERNEL); |
| 1571 | if (!data) | 1560 | if (!data) |
| 1572 | return -ENOMEM; | 1561 | return -ENOMEM; |
| 1573 | 1562 | ||
| 1574 | i2c_set_clientdata(client, data); | 1563 | data->client = client; |
| 1575 | data->type = id->driver_data; | 1564 | data->type = id->driver_data; |
| 1576 | mutex_init(&data->update_lock); | 1565 | mutex_init(&data->update_lock); |
| 1577 | 1566 | ||
| @@ -1596,20 +1585,13 @@ static int lm85_probe(struct i2c_client *client, | |||
| 1596 | /* Initialize the LM85 chip */ | 1585 | /* Initialize the LM85 chip */ |
| 1597 | lm85_init_client(client); | 1586 | lm85_init_client(client); |
| 1598 | 1587 | ||
| 1599 | /* Register sysfs hooks */ | 1588 | /* sysfs hooks */ |
| 1600 | err = sysfs_create_group(&client->dev.kobj, &lm85_group); | 1589 | data->groups[idx++] = &lm85_group; |
| 1601 | if (err) | ||
| 1602 | return err; | ||
| 1603 | 1590 | ||
| 1604 | /* minctl and temp_off exist on all chips except emc6d103s */ | 1591 | /* minctl and temp_off exist on all chips except emc6d103s */ |
| 1605 | if (data->type != emc6d103s) { | 1592 | if (data->type != emc6d103s) { |
| 1606 | err = sysfs_create_group(&client->dev.kobj, &lm85_group_minctl); | 1593 | data->groups[idx++] = &lm85_group_minctl; |
| 1607 | if (err) | 1594 | data->groups[idx++] = &lm85_group_temp_off; |
| 1608 | goto err_remove_files; | ||
| 1609 | err = sysfs_create_group(&client->dev.kobj, | ||
| 1610 | &lm85_group_temp_off); | ||
| 1611 | if (err) | ||
| 1612 | goto err_remove_files; | ||
| 1613 | } | 1595 | } |
| 1614 | 1596 | ||
| 1615 | /* | 1597 | /* |
| @@ -1622,39 +1604,16 @@ static int lm85_probe(struct i2c_client *client, | |||
| 1622 | data->has_vid5 = true; | 1604 | data->has_vid5 = true; |
| 1623 | } | 1605 | } |
| 1624 | 1606 | ||
| 1625 | if (!data->has_vid5) { | 1607 | if (!data->has_vid5) |
| 1626 | err = sysfs_create_group(&client->dev.kobj, &lm85_group_in4); | 1608 | data->groups[idx++] = &lm85_group_in4; |
| 1627 | if (err) | ||
| 1628 | goto err_remove_files; | ||
| 1629 | } | ||
| 1630 | 1609 | ||
| 1631 | /* The EMC6D100 has 3 additional voltage inputs */ | 1610 | /* The EMC6D100 has 3 additional voltage inputs */ |
| 1632 | if (data->type == emc6d100) { | 1611 | if (data->type == emc6d100) |
| 1633 | err = sysfs_create_group(&client->dev.kobj, &lm85_group_in567); | 1612 | data->groups[idx++] = &lm85_group_in567; |
| 1634 | if (err) | ||
| 1635 | goto err_remove_files; | ||
| 1636 | } | ||
| 1637 | |||
| 1638 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
| 1639 | if (IS_ERR(data->hwmon_dev)) { | ||
| 1640 | err = PTR_ERR(data->hwmon_dev); | ||
| 1641 | goto err_remove_files; | ||
| 1642 | } | ||
| 1643 | |||
| 1644 | return 0; | ||
| 1645 | |||
| 1646 | /* Error out and cleanup code */ | ||
| 1647 | err_remove_files: | ||
| 1648 | lm85_remove_files(client, data); | ||
| 1649 | return err; | ||
| 1650 | } | ||
| 1651 | 1613 | ||
| 1652 | static int lm85_remove(struct i2c_client *client) | 1614 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
| 1653 | { | 1615 | data, data->groups); |
| 1654 | struct lm85_data *data = i2c_get_clientdata(client); | 1616 | return PTR_ERR_OR_ZERO(hwmon_dev); |
| 1655 | hwmon_device_unregister(data->hwmon_dev); | ||
| 1656 | lm85_remove_files(client, data); | ||
| 1657 | return 0; | ||
| 1658 | } | 1617 | } |
| 1659 | 1618 | ||
| 1660 | static const struct i2c_device_id lm85_id[] = { | 1619 | static const struct i2c_device_id lm85_id[] = { |
| @@ -1679,7 +1638,6 @@ static struct i2c_driver lm85_driver = { | |||
| 1679 | .name = "lm85", | 1638 | .name = "lm85", |
| 1680 | }, | 1639 | }, |
| 1681 | .probe = lm85_probe, | 1640 | .probe = lm85_probe, |
| 1682 | .remove = lm85_remove, | ||
| 1683 | .id_table = lm85_id, | 1641 | .id_table = lm85_id, |
| 1684 | .detect = lm85_detect, | 1642 | .detect = lm85_detect, |
| 1685 | .address_list = normal_i2c, | 1643 | .address_list = normal_i2c, |
