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>
This commit is contained in:
parent
4e66cd13ff
commit
8e35762fd5
|
@ -184,20 +184,18 @@ static int ads1015_get_channels_config_of(struct i2c_client *client)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
for_each_child_of_node(client->dev.of_node, node) {
|
for_each_child_of_node(client->dev.of_node, node) {
|
||||||
const __be32 *property;
|
u32 pval;
|
||||||
int len;
|
|
||||||
unsigned int channel;
|
unsigned int channel;
|
||||||
unsigned int pga = ADS1015_DEFAULT_PGA;
|
unsigned int pga = ADS1015_DEFAULT_PGA;
|
||||||
unsigned int data_rate = ADS1015_DEFAULT_DATA_RATE;
|
unsigned int data_rate = ADS1015_DEFAULT_DATA_RATE;
|
||||||
|
|
||||||
property = of_get_property(node, "reg", &len);
|
if (of_property_read_u32(node, "reg", &pval)) {
|
||||||
if (!property || len != sizeof(int)) {
|
|
||||||
dev_err(&client->dev, "invalid reg on %s\n",
|
dev_err(&client->dev, "invalid reg on %s\n",
|
||||||
node->full_name);
|
node->full_name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
channel = be32_to_cpup(property);
|
channel = pval;
|
||||||
if (channel >= ADS1015_CHANNELS) {
|
if (channel >= ADS1015_CHANNELS) {
|
||||||
dev_err(&client->dev,
|
dev_err(&client->dev,
|
||||||
"invalid channel index %d on %s\n",
|
"invalid channel index %d on %s\n",
|
||||||
|
@ -205,20 +203,17 @@ static int ads1015_get_channels_config_of(struct i2c_client *client)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
property = of_get_property(node, "ti,gain", &len);
|
if (!of_property_read_u32(node, "ti,gain", &pval)) {
|
||||||
if (property && len == sizeof(int)) {
|
pga = pval;
|
||||||
pga = be32_to_cpup(property);
|
|
||||||
if (pga > 6) {
|
if (pga > 6) {
|
||||||
dev_err(&client->dev,
|
dev_err(&client->dev, "invalid gain on %s\n",
|
||||||
"invalid gain on %s\n",
|
|
||||||
node->full_name);
|
node->full_name);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
property = of_get_property(node, "ti,datarate", &len);
|
if (!of_property_read_u32(node, "ti,datarate", &pval)) {
|
||||||
if (property && len == sizeof(int)) {
|
data_rate = pval;
|
||||||
data_rate = be32_to_cpup(property);
|
|
||||||
if (data_rate > 7) {
|
if (data_rate > 7) {
|
||||||
dev_err(&client->dev,
|
dev_err(&client->dev,
|
||||||
"invalid data_rate on %s\n",
|
"invalid data_rate on %s\n",
|
||||||
|
|
Loading…
Reference in a new issue