static int ina233_probe(struct i2c_client *client)
{
struct device *dev = &client->dev;
+ const char *propname;
int ret, m, R;
u32 rshunt;
u32 max_current;
/* If INA233 skips current/power, shunt-resistor and current-lsb aren't needed. */
/* read rshunt value (uOhm) */
- ret = device_property_read_u32(dev, "shunt-resistor", &rshunt);
- if (ret) {
- if (ret != -EINVAL)
- return dev_err_probe(dev, ret, "Shunt resistor property read fail.\n");
+ propname = "shunt-resistor";
+ if (device_property_present(dev, propname)) {
+ ret = device_property_read_u32(dev, propname, &rshunt);
+ if (ret)
+ return dev_err_probe(dev, ret, "%s property read fail.\n", propname);
+ } else {
rshunt = INA233_RSHUNT_DEFAULT;
}
if (!rshunt)
- return dev_err_probe(dev, -EINVAL,
- "Shunt resistor cannot be zero.\n");
+ return dev_err_probe(dev, -EINVAL, "%s cannot be zero.\n", propname);
/* read Maximum expected current value (uA) */
- ret = device_property_read_u32(dev, "ti,maximum-expected-current-microamp", &max_current);
- if (ret) {
- if (ret != -EINVAL)
- return dev_err_probe(dev, ret,
- "Maximum expected current property read fail.\n");
+ propname = "ti,maximum-expected-current-microamp";
+ if (device_property_present(dev, propname)) {
+ ret = device_property_read_u32(dev, propname, &max_current);
+ if (ret)
+ return dev_err_probe(dev, ret, "%s property read fail.\n", propname);
+ } else {
max_current = INA233_MAX_CURRENT_DEFAULT;
}
if (max_current < 32768)
- return dev_err_probe(dev, -EINVAL,
- "Maximum expected current cannot less then 32768.\n");
+ return dev_err_probe(dev, -EINVAL, "%s cannot be less than 32768.\n", propname);
/* Calculate Current_LSB according to the spec formula */
current_lsb = max_current / 32768;