--- zzzz-none-000/linux-3.10.107/drivers/hwmon/max6697.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/hwmon/max6697.c 2021-02-04 17:41:59.000000000 +0000 @@ -77,7 +77,7 @@ }; struct max6697_data { - struct device *hwmon_dev; + struct i2c_client *client; enum chips type; const struct max6697_chip_data *chip; @@ -181,8 +181,8 @@ static struct max6697_data *max6697_update_device(struct device *dev) { - struct i2c_client *client = to_i2c_client(dev); - struct max6697_data *data = i2c_get_clientdata(client); + struct max6697_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; struct max6697_data *ret = data; int val; int i; @@ -303,8 +303,7 @@ { int nr = to_sensor_dev_attr_2(devattr)->nr; int index = to_sensor_dev_attr_2(devattr)->index; - struct i2c_client *client = to_i2c_client(dev); - struct max6697_data *data = i2c_get_clientdata(client); + struct max6697_data *data = dev_get_drvdata(dev); long temp; int ret; @@ -316,7 +315,7 @@ temp = DIV_ROUND_CLOSEST(temp, 1000) + data->temp_offset; temp = clamp_val(temp, 0, data->type == max6581 ? 255 : 127); data->temp[nr][index] = temp; - ret = i2c_smbus_write_byte_data(client, + ret = i2c_smbus_write_byte_data(data->client, index == 2 ? MAX6697_REG_MAX[nr] : MAX6697_REG_CRIT[nr], temp); @@ -405,8 +404,7 @@ int index) { struct device *dev = container_of(kobj, struct device, kobj); - struct i2c_client *client = to_i2c_client(dev); - struct max6697_data *data = i2c_get_clientdata(client); + struct max6697_data *data = dev_get_drvdata(dev); const struct max6697_chip_data *chip = data->chip; int channel = index / 6; /* channel number */ int nr = index % 6; /* attribute index within channel */ @@ -489,6 +487,7 @@ static const struct attribute_group max6697_group = { .attrs = max6697_attributes, .is_visible = max6697_is_visible, }; +__ATTRIBUTE_GROUPS(max6697); static void max6697_get_config_of(struct device_node *node, struct max6697_platform_data *pdata) @@ -496,15 +495,13 @@ int len; const __be32 *prop; - prop = of_get_property(node, "smbus-timeout-disable", &len); - if (prop) - pdata->smbus_timeout_disable = true; - prop = of_get_property(node, "extended-range-enable", &len); - if (prop) - pdata->extended_range_enable = true; - prop = of_get_property(node, "beta-compensation-enable", &len); - if (prop) - pdata->beta_compensation = true; + pdata->smbus_timeout_disable = + of_property_read_bool(node, "smbus-timeout-disable"); + pdata->extended_range_enable = + of_property_read_bool(node, "extended-range-enable"); + pdata->beta_compensation = + of_property_read_bool(node, "beta-compensation-enable"); + prop = of_get_property(node, "alert-mask", &len); if (prop && len == sizeof(u32)) pdata->alert_mask = be32_to_cpu(prop[0]); @@ -525,9 +522,9 @@ } } -static int max6697_init_chip(struct i2c_client *client) +static int max6697_init_chip(struct max6697_data *data, + struct i2c_client *client) { - struct max6697_data *data = i2c_get_clientdata(client); struct max6697_platform_data *pdata = dev_get_platdata(&client->dev); struct max6697_platform_data p; const struct max6697_chip_data *chip = data->chip; @@ -625,6 +622,7 @@ struct i2c_adapter *adapter = client->adapter; struct device *dev = &client->dev; struct max6697_data *data; + struct device *hwmon_dev; int err; if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) @@ -636,39 +634,17 @@ data->type = id->driver_data; data->chip = &max6697_chip_data[data->type]; - - i2c_set_clientdata(client, data); + data->client = client; mutex_init(&data->update_lock); - err = max6697_init_chip(client); + err = max6697_init_chip(data, client); if (err) return err; - err = sysfs_create_group(&client->dev.kobj, &max6697_group); - if (err) - return err; - - data->hwmon_dev = hwmon_device_register(dev); - if (IS_ERR(data->hwmon_dev)) { - err = PTR_ERR(data->hwmon_dev); - goto error; - } - - return 0; - -error: - sysfs_remove_group(&client->dev.kobj, &max6697_group); - return err; -} - -static int max6697_remove(struct i2c_client *client) -{ - struct max6697_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &max6697_group); - - return 0; + hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, + data, + max6697_groups); + return PTR_ERR_OR_ZERO(hwmon_dev); } static const struct i2c_device_id max6697_id[] = { @@ -692,7 +668,6 @@ .name = "max6697", }, .probe = max6697_probe, - .remove = max6697_remove, .id_table = max6697_id, };