diff options
author | Axel Lin <axel.lin@ingics.com> | 2014-08-04 22:56:47 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2014-09-22 14:14:51 -0400 |
commit | 8e35762fd5f2b074cff3e5c176c80008c70cc8f3 (patch) | |
tree | 1c7fbf7251b8caafe71aa6877e959f729e1d9281 | |
parent | 4e66cd13ff9cd7eaae69e2fae0335d8d99d8afdf (diff) |
hwmon: (ads1015) Use of_property_read_u32 at appropriate places
Simplify the code a bit and also improve readability.
Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r-- | drivers/hwmon/ads1015.c | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/drivers/hwmon/ads1015.c b/drivers/hwmon/ads1015.c index 126516414c11..f155b8380481 100644 --- a/drivers/hwmon/ads1015.c +++ b/drivers/hwmon/ads1015.c | |||
@@ -184,20 +184,18 @@ static int ads1015_get_channels_config_of(struct i2c_client *client) | |||
184 | return -EINVAL; | 184 | return -EINVAL; |
185 | 185 | ||
186 | for_each_child_of_node(client->dev.of_node, node) { | 186 | for_each_child_of_node(client->dev.of_node, node) { |
187 | const __be32 *property; | 187 | u32 pval; |
188 | int len; | ||
189 | unsigned int channel; | 188 | unsigned int channel; |
190 | unsigned int pga = ADS1015_DEFAULT_PGA; | 189 | unsigned int pga = ADS1015_DEFAULT_PGA; |
191 | unsigned int data_rate = ADS1015_DEFAULT_DATA_RATE; | 190 | unsigned int data_rate = ADS1015_DEFAULT_DATA_RATE; |
192 | 191 | ||
193 | property = of_get_property(node, "reg", &len); | 192 | if (of_property_read_u32(node, "reg", &pval)) { |
194 | if (!property || len != sizeof(int)) { | ||
195 | dev_err(&client->dev, "invalid reg on %s\n", | 193 | dev_err(&client->dev, "invalid reg on %s\n", |
196 | node->full_name); | 194 | node->full_name); |
197 | continue; | 195 | continue; |
198 | } | 196 | } |
199 | 197 | ||
200 | channel = be32_to_cpup(property); | 198 | channel = pval; |
201 | if (channel >= ADS1015_CHANNELS) { | 199 | if (channel >= ADS1015_CHANNELS) { |
202 | dev_err(&client->dev, | 200 | dev_err(&client->dev, |
203 | "invalid channel index %d on %s\n", | 201 | "invalid channel index %d on %s\n", |
@@ -205,20 +203,17 @@ static int ads1015_get_channels_config_of(struct i2c_client *client) | |||
205 | continue; | 203 | continue; |
206 | } | 204 | } |
207 | 205 | ||
208 | property = of_get_property(node, "ti,gain", &len); | 206 | if (!of_property_read_u32(node, "ti,gain", &pval)) { |
209 | if (property && len == sizeof(int)) { | 207 | pga = pval; |
210 | pga = be32_to_cpup(property); | ||
211 | if (pga > 6) { | 208 | if (pga > 6) { |
212 | dev_err(&client->dev, | 209 | dev_err(&client->dev, "invalid gain on %s\n", |
213 | "invalid gain on %s\n", | ||
214 | node->full_name); | 210 | node->full_name); |
215 | return -EINVAL; | 211 | return -EINVAL; |
216 | } | 212 | } |
217 | } | 213 | } |
218 | 214 | ||
219 | property = of_get_property(node, "ti,datarate", &len); | 215 | if (!of_property_read_u32(node, "ti,datarate", &pval)) { |
220 | if (property && len == sizeof(int)) { | 216 | data_rate = pval; |
221 | data_rate = be32_to_cpup(property); | ||
222 | if (data_rate > 7) { | 217 | if (data_rate > 7) { |
223 | dev_err(&client->dev, | 218 | dev_err(&client->dev, |
224 | "invalid data_rate on %s\n", | 219 | "invalid data_rate on %s\n", |