Re: [PATCH 4/4] iio: dac: mcp4922: add support for mcp48xx series chips

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

 



On Wed, 5 Apr 2023 07:18:46 -0700
Lars-Peter Clausen <lars@xxxxxxxxxx> wrote:

> Hi,
> 
> Looks very good. A few small comments inline.
> [...]
> > @@ -50,6 +58,35 @@ struct mcp4922_state {
> >   	},						\
> >   }
> >   
> > +static bool mcp4922_needs_vref(int device_id)  
> 
> `enum mcp4922_supported_device_ids` instead of `int`. Same for num_channels() below.
> 
> > +{
> > +	switch (device_id) {
> > +	case ID_MCP4902:
> > +	case ID_MCP4912:
> > +	case ID_MCP4921:
> > +	case ID_MCP4922:
> > +		return true;
> > +	default:
> > +		return false;
> > +	}
> > +}
> > [...]
> >   static int mcp4922_spi_write(struct mcp4922_state *state, u8 addr, u32 val)
> >   {
> >   	state->mosi[1] = val & 0xff;
> > @@ -108,11 +145,17 @@ static int mcp4922_write_raw(struct iio_dev *indio_dev,
> >   	}
> >   }
> >   
> > -static const struct iio_chan_spec mcp4922_channels[4][MCP4922_NUM_CHANNELS] = {
> > +static const struct iio_chan_spec mcp4922_channels[10][MCP4922_NUM_CHANNELS] = {  
> 
> mcp4922_channels[][MCP4922_NUM_CHANNELS]
> 
> So it does not have to be changed again when adding additional devices 
> in the future.
> 
> > [...]
> > @@ -197,11 +244,14 @@ static void mcp4922_remove(struct spi_device *spi)
> >   {
> >   	struct iio_dev *indio_dev = spi_get_drvdata(spi);
> >   	struct mcp4922_state *state;
> > +	const struct spi_device_id *id = spi_get_device_id(spi);
> >   
> >   	iio_device_unregister(indio_dev);
> >   	state = iio_priv(indio_dev);
> >   	regulator_disable(state->vdd_reg);
> > -	regulator_disable(state->vref_reg);
> > +	if (mcp4922_needs_vref(id->driver_data)) {  
> Could be `if (state->vref_reg)`, this way you don't need to lookup the 
> spi_device_id. But either way is fine.

Even better would be to make this driver use devm_ for all unwinding.
That way the regulator_disable() callback registered via
devm_add_action_or_reset() will only be registered if you enabled such
a regulator in the first place.

The rest of this remove is trivial so it would be a nice addition to this
series to get rid of the need to have it at all.

> > +		regulator_disable(state->vref_reg);
> > +	}
> >   }
> >   
> > [...]  
> 
> 




[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