diff options
author | Guenter Roeck <linux@roeck-us.net> | 2015-01-16 13:12:50 -0500 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2015-02-02 11:20:06 -0500 |
commit | 7f444bf0a28c030d40925c5d0073d3e5ed8ca1e3 (patch) | |
tree | aabbf3a2c02fc0bf724d03bee8f84992f1d3fdf5 /drivers/hwmon/ads7828.c | |
parent | bea0bab0fcf5a0b97f3545ba35647f0f37dc2475 (diff) |
hwmon: (ads2828) Only keep data in device data structure if needed
The variables diff_input, ext_vref, and vref_mv are only used in the probe
function and therefore don't need to be kept in the device data structure.
Reviewed-and-Tested-by: Robert Rosengren <robert.rosengren@axis.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/ads7828.c')
-rw-r--r-- | drivers/hwmon/ads7828.c | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/drivers/hwmon/ads7828.c b/drivers/hwmon/ads7828.c index 071f779d5e48..bce4e9ff21bf 100644 --- a/drivers/hwmon/ads7828.c +++ b/drivers/hwmon/ads7828.c | |||
@@ -49,9 +49,6 @@ enum ads7828_chips { ads7828, ads7830 }; | |||
49 | /* Client specific data */ | 49 | /* Client specific data */ |
50 | struct ads7828_data { | 50 | struct ads7828_data { |
51 | struct regmap *regmap; | 51 | struct regmap *regmap; |
52 | bool diff_input; /* Differential input */ | ||
53 | bool ext_vref; /* External voltage reference */ | ||
54 | unsigned int vref_mv; /* voltage reference value */ | ||
55 | u8 cmd_byte; /* Command byte without channel bits */ | 52 | u8 cmd_byte; /* Command byte without channel bits */ |
56 | unsigned int lsb_resol; /* Resolution of the ADC sample LSB */ | 53 | unsigned int lsb_resol; /* Resolution of the ADC sample LSB */ |
57 | }; | 54 | }; |
@@ -120,39 +117,38 @@ static int ads7828_probe(struct i2c_client *client, | |||
120 | struct ads7828_platform_data *pdata = dev_get_platdata(dev); | 117 | struct ads7828_platform_data *pdata = dev_get_platdata(dev); |
121 | struct ads7828_data *data; | 118 | struct ads7828_data *data; |
122 | struct device *hwmon_dev; | 119 | struct device *hwmon_dev; |
120 | unsigned int vref_mv = ADS7828_INT_VREF_MV; | ||
121 | bool diff_input = false; | ||
122 | bool ext_vref = false; | ||
123 | 123 | ||
124 | data = devm_kzalloc(dev, sizeof(struct ads7828_data), GFP_KERNEL); | 124 | data = devm_kzalloc(dev, sizeof(struct ads7828_data), GFP_KERNEL); |
125 | if (!data) | 125 | if (!data) |
126 | return -ENOMEM; | 126 | return -ENOMEM; |
127 | 127 | ||
128 | if (pdata) { | 128 | if (pdata) { |
129 | data->diff_input = pdata->diff_input; | 129 | diff_input = pdata->diff_input; |
130 | data->ext_vref = pdata->ext_vref; | 130 | ext_vref = pdata->ext_vref; |
131 | if (data->ext_vref) | 131 | if (ext_vref && pdata->vref_mv) |
132 | data->vref_mv = pdata->vref_mv; | 132 | vref_mv = pdata->vref_mv; |
133 | } | 133 | } |
134 | 134 | ||
135 | /* Bound Vref with min/max values if it was provided */ | 135 | /* Bound Vref with min/max values */ |
136 | if (data->vref_mv) | 136 | vref_mv = clamp_val(vref_mv, ADS7828_EXT_VREF_MV_MIN, |
137 | data->vref_mv = clamp_val(data->vref_mv, | 137 | ADS7828_EXT_VREF_MV_MAX); |
138 | ADS7828_EXT_VREF_MV_MIN, | ||
139 | ADS7828_EXT_VREF_MV_MAX); | ||
140 | else | ||
141 | data->vref_mv = ADS7828_INT_VREF_MV; | ||
142 | 138 | ||
143 | /* ADS7828 uses 12-bit samples, while ADS7830 is 8-bit */ | 139 | /* ADS7828 uses 12-bit samples, while ADS7830 is 8-bit */ |
144 | if (id->driver_data == ads7828) { | 140 | if (id->driver_data == ads7828) { |
145 | data->lsb_resol = DIV_ROUND_CLOSEST(data->vref_mv * 1000, 4096); | 141 | data->lsb_resol = DIV_ROUND_CLOSEST(vref_mv * 1000, 4096); |
146 | data->regmap = devm_regmap_init_i2c(client, | 142 | data->regmap = devm_regmap_init_i2c(client, |
147 | &ads2828_regmap_config); | 143 | &ads2828_regmap_config); |
148 | } else { | 144 | } else { |
149 | data->lsb_resol = DIV_ROUND_CLOSEST(data->vref_mv * 1000, 256); | 145 | data->lsb_resol = DIV_ROUND_CLOSEST(vref_mv * 1000, 256); |
150 | data->regmap = devm_regmap_init_i2c(client, | 146 | data->regmap = devm_regmap_init_i2c(client, |
151 | &ads2830_regmap_config); | 147 | &ads2830_regmap_config); |
152 | } | 148 | } |
153 | 149 | ||
154 | data->cmd_byte = data->ext_vref ? ADS7828_CMD_PD1 : ADS7828_CMD_PD3; | 150 | data->cmd_byte = ext_vref ? ADS7828_CMD_PD1 : ADS7828_CMD_PD3; |
155 | if (!data->diff_input) | 151 | if (!diff_input) |
156 | data->cmd_byte |= ADS7828_CMD_SD_SE; | 152 | data->cmd_byte |= ADS7828_CMD_SD_SE; |
157 | 153 | ||
158 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, | 154 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |