Re: [PATCH v5 4/7] iio: adc: ad7380: add support for pseudo-differential parts

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> > > +     /*
> > > +      * pseudo-differential chips have common mode supplies for the negative
> > > +      * input pin.
> > > +      */
> > > +     for (i = 0; i < st->chip_info->num_vcm_supplies; i++) {
> > > +             struct regulator *vcm;
> > > +
> > > +             vcm = devm_regulator_get_optional(&spi->dev,  
> >
> > Why optional?
> >  
> > > +                                               st->chip_info->vcm_supplies[i]);
> > > +             if (IS_ERR(vcm))  
> >
> > This will fail if it's not there, so I'm guessing you are using this to avoid
> > getting to the regulator_get_voltage?  If it's not present I'd rely on that
> > failing rather than the confusing handling here.
> >
> > When the read of voltage wasn't in probe this would have resulted in a problem
> > much later than initial setup, now it is, we are just pushing it down a few lines.
> >
> > Arguably we could have a devm_regulator_get_not_dummy()
> > that had same implementation to as get_optional() but whilst it's called that
> > I think it's confusing to use like this.  
> 
> Despite the misleading naming, I guess I am used to
> devm_regulator_get_optional() by now having used it enough times.
> Since it fails either way though, technically both ways seem fine so I
> can't really argue for one over the other.
> 
> But given that this is a common pattern in many IIO drivers, maybe we
> make a devm_regulator_get_enable_get_voltage()? This would return the
> voltage on success or an error code. (If the regulator subsystem
> doesn't want this maybe we could have
> devm_iio_regulator_get_enable_get_voltage()).
> 
> If the dev_err_probe() calls were included in
> devm_regulator_get_enable_get_voltage(), then the 10+ lines of code
> here and in many other drivers to get the regulator, enable it, add
> the reset action and get the voltage could be reduced to 3 lines.

I like this proposal a lot. RFC, so it's visible outside the depths
of this thread?
Particularly good as it will keep the regulator opaque in the same
fashion as devm_regulator_get_enabled()

As you say, we have a 'lot' of instances of this (quick grep
suggests > 50 in IIO alone and smaller numbers elsewhere).

Jonathan


> 
> >  
> > > +                     return dev_err_probe(&spi->dev, PTR_ERR(vcm),
> > > +                                          "Failed to get %s regulator\n",
> > > +                                          st->chip_info->vcm_supplies[i]);
> > > +
> > > +             ret = regulator_enable(vcm);
> > > +             if (ret)
> > > +                     return ret;
> > > +
> > > +             ret = devm_add_action_or_reset(&spi->dev,
> > > +                                            ad7380_regulator_disable, vcm);
> > > +             if (ret)
> > > +                     return ret;
> > > +
> > > +             ret = regulator_get_voltage(vcm);  
> >
> > I'd let this fail if we have a dummy regulator.
> >  
> > > +             if (ret < 0)
> > > +                     return ret;
> > > +
> > > +             st->vcm_mv[i] = ret / 1000;
> > > +     }
> > > +  
> 





[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux