Merge tag 'powerpc-4.4-1' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc...
[firefly-linux-kernel-4.4.55.git] / drivers / hwmon / ina2xx.c
index 96862c6eae7434f717dd911e06c39bea51f26ea1..b24f1d3045f04386f7dc3a1c5af4b7ee7724e891 100644 (file)
@@ -109,7 +109,6 @@ struct ina2xx_data {
        struct mutex config_lock;
        struct regmap *regmap;
 
-       int kind;
        const struct attribute_group *groups[INA2XX_MAX_ATTRIBUTE_GROUPS];
 };
 
@@ -420,7 +419,6 @@ static const struct attribute_group ina226_group = {
 static int ina2xx_probe(struct i2c_client *client,
                        const struct i2c_device_id *id)
 {
-       struct ina2xx_platform_data *pdata;
        struct device *dev = &client->dev;
        struct ina2xx_data *data;
        struct device *hwmon_dev;
@@ -431,24 +429,23 @@ static int ina2xx_probe(struct i2c_client *client,
        if (!data)
                return -ENOMEM;
 
-       if (dev_get_platdata(dev)) {
-               pdata = dev_get_platdata(dev);
-               data->rshunt = pdata->shunt_uohms;
-       } else if (!of_property_read_u32(dev->of_node,
-                                        "shunt-resistor", &val)) {
-               data->rshunt = val;
-       } else {
-               data->rshunt = INA2XX_RSHUNT_DEFAULT;
-       }
-
        /* set the device type */
-       data->kind = id->driver_data;
-       data->config = &ina2xx_config[data->kind];
+       data->config = &ina2xx_config[id->driver_data];
 
-       if (data->rshunt <= 0 ||
-           data->rshunt > data->config->calibration_factor)
+       if (of_property_read_u32(dev->of_node, "shunt-resistor", &val) < 0) {
+               struct ina2xx_platform_data *pdata = dev_get_platdata(dev);
+
+               if (pdata)
+                       val = pdata->shunt_uohms;
+               else
+                       val = INA2XX_RSHUNT_DEFAULT;
+       }
+
+       if (val <= 0 || val > data->config->calibration_factor)
                return -ENODEV;
 
+       data->rshunt = val;
+
        ina2xx_regmap_config.max_register = data->config->registers;
 
        data->regmap = devm_regmap_init_i2c(client, &ina2xx_regmap_config);
@@ -466,7 +463,7 @@ static int ina2xx_probe(struct i2c_client *client,
        mutex_init(&data->config_lock);
 
        data->groups[group++] = &ina2xx_group;
-       if (data->kind == ina226)
+       if (id->driver_data == ina226)
                data->groups[group++] = &ina226_group;
 
        hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,