linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Ardelean, Alexandru" <alexandru.Ardelean@analog.com>
To: "andriy.shevchenko@intel.com" <andriy.shevchenko@intel.com>,
	"Tachici, Alexandru" <Alexandru.Tachici@analog.com>
Cc: "jic23@kernel.org" <jic23@kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
	"Caprioru, Mircea" <Mircea.Caprioru@analog.com>
Subject: Re: [PATCH v4 1/2] iio: dac: ad5770r: Add AD5770R support
Date: Sun, 22 Mar 2020 09:17:06 +0000	[thread overview]
Message-ID: <2942e900ab01957027b918b2a5fdbd665fe6b2ed.camel@analog.com> (raw)
In-Reply-To: <20200321210921.GA2814584@smile.fi.intel.com>

On Sat, 2020-03-21 at 23:09 +0200, Andy Shevchenko wrote:
> [External]
> 
> On Tue, Feb 18, 2020 at 02:10:30PM +0200, Alexandru Tachici wrote:
> > The AD5770R is a 6-channel, 14-bit resolution, low noise, programmable
> > current output digital-to-analog converter (DAC) for photonics control
> > applications.
> > 
> > It contains five 14-bit resolution current sourcing DAC channels and one
> > 14-bit resolution current sourcing/sinking DAC channel.
> 

This patch made it into linux-next.
Doing a v2 now may be a bit noisy.

Maybe we can tidy-this-up later.
To be honest, it won't be the highest on our list.
[ I know how that sounds ]

We can probably leave it for other people to clean it up.
[ People that want to start contributing to the kernel ]


> ...
> 
> > +#define AD5770R_CFG_CH0_SINK_EN(x)		(((x) & 0x1) << 7)
> > +#define AD5770R_CFG_SHUTDOWN_B(x, ch)		(((x) & 0x1) << (ch))
> 
> BIT(0) ?
> 
> > +#define AD5770R_REF_RESISTOR_SEL(x)		(((x) & 0x1) << 2)
> 
> Ditto.
> 
> > +#define AD5770R_CH_SET(x, ch)		(((x) & 0x1) << (ch))
> 
> Ditto.
> 
> ...
> 
> > +enum ad5770r_ch0_modes {
> > +	AD5770R_CH0_0_300 = 0,
> > +	AD5770R_CH0_NEG_60_0,
> > +	AD5770R_CH0_NEG_60_300
> > +};
> > +
> > +enum ad5770r_ch1_modes {
> > +	AD5770R_CH1_0_140_LOW_HEAD = 1,
> > +	AD5770R_CH1_0_140_LOW_NOISE,
> > +	AD5770R_CH1_0_250
> > +};
> > +
> > +enum ad5770r_ch2_5_modes {
> > +	AD5770R_CH_LOW_RANGE = 0,
> > +	AD5770R_CH_HIGH_RANGE
> > +};
> > +
> > +enum ad5770r_ref_v {
> > +	AD5770R_EXT_2_5_V = 0,
> > +	AD5770R_INT_1_25_V_OUT_ON,
> > +	AD5770R_EXT_1_25_V,
> > +	AD5770R_INT_1_25_V_OUT_OFF
> > +};
> > +
> > +enum ad5770r_output_filter_resistor {
> > +	AD5770R_FILTER_60_OHM = 0x0,
> > +	AD5770R_FILTER_5_6_KOHM = 0x5,
> > +	AD5770R_FILTER_11_2_KOHM,
> > +	AD5770R_FILTER_22_2_KOHM,
> > +	AD5770R_FILTER_44_4_KOHM,
> > +	AD5770R_FILTER_104_KOHM,
> 
> It would be nice to go consistent about last entry in enums. Are they
> terminators? For me it doesn't look like it (new revision of hardware
> always can use extended lists of modes, etc).
> 
> So, I think leaving comma for all above is a right thing to do.
> 
> > +};
> 
> ...
> 
> > +static const unsigned int ad5770r_filter_reg_vals[] = {
> > +	AD5770R_FILTER_104_KOHM,
> > +	AD5770R_FILTER_44_4_KOHM,
> > +	AD5770R_FILTER_22_2_KOHM,
> > +	AD5770R_FILTER_11_2_KOHM,
> > +	AD5770R_FILTER_5_6_KOHM,
> > +	AD5770R_FILTER_60_OHM
> > +};
> 
> Ditto.
> 
> ...
> 
> > +	return regmap_write(st->regmap,
> > +			    AD5770R_OUTPUT_RANGE(channel), regval);
> 
> It fits one line (even has room for one character more)
> Perhaps you may consider to amend settings of your text editor?
> Please fix all similar places in all of your patches.
> 
> ...
> 
> > +static int ad5770r_reset(struct ad5770r_state *st)
> > +{
> > +	/* Perform software reset if no GPIO provided */
> > +	if (!st->gpio_reset)
> > +		return ad5770r_soft_reset(st);
> 
> Perhaps split this to _reset_gpio() and do
> 
> 	if (gpio)
> 		return _reset_gpio();
> 	else // It's redundant, but some people use for a style
> 		return _soft_reset();
> 
> > +
> > +	gpiod_set_value_cansleep(st->gpio_reset, 0);
> > +	usleep_range(10, 20);
> > +	gpiod_set_value_cansleep(st->gpio_reset, 1);
> > +
> > +	/* data must not be written during reset timeframe */
> > +	usleep_range(100, 200);
> > +
> > +	return 0;
> > +}
> 
> ...
> 
> > +		ret = regmap_bulk_read(st->regmap,
> > +				       chan->address,
> > +				       st->transf_buf, 2);
> 
> sizeof() ?
> 
> > +		if (ret)
> > +			return 0;
> 
> ...
> 
> > +		st->transf_buf[0] = ((u16)val >> 6);
> 
> Why explicit casting?
> 
> > +		st->transf_buf[1] = (val & GENMASK(5, 0)) << 2;
> > +		return regmap_bulk_write(st->regmap, chan->address,
> > +					 st->transf_buf, 2);
> 
> sizeof() ?
> 
> ...
> 
> > +static int ad5770r_read_freq_avail(struct iio_dev *indio_dev,
> > +				   struct iio_chan_spec const *chan,
> > +				   const int **vals, int *type, int *length,
> > +				   long mask)
> > +{
> > +	switch (mask) {
> > +	case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
> > +		*type = IIO_VAL_INT;
> > +		*vals = ad5770r_filter_freqs;
> > +		*length = ARRAY_SIZE(ad5770r_filter_freqs);
> > +		return IIO_AVAIL_LIST;
> > +	}
> > +
> > +	return -EINVAL;
> 
> default case?
> 
> > +}
> 
> ...
> 
> > +	ret = kstrtobool(buf, &readin);
> > +	if (ret)
> > +		return ret;
> > +
> > +	readin = !readin;
> 
> I think using ! directly in places where it's needed will be helpful ti
> understand the code.
> 
> > +
> > +	regval = AD5770R_CFG_SHUTDOWN_B(readin, chan->channel);
> > +	if (chan->channel == 0 &&
> > +	    st->output_mode[0].out_range_mode > AD5770R_CH0_0_300) {
> > +		regval |= AD5770R_CFG_CH0_SINK_EN(readin);
> > +		mask = BIT(chan->channel) + BIT(7);
> > +	} else {
> > +		mask = BIT(chan->channel);
> > +	}
> > +	ret = regmap_update_bits(st->regmap, AD5770R_CHANNEL_CONFIG, mask,
> > +				 regval);
> > +	if (ret)
> > +		return ret;
> > +
> > +	regval = AD5770R_CH_SET(readin, chan->channel);
> > +	ret = regmap_update_bits(st->regmap, AD5770R_CH_ENABLE,
> > +				 BIT(chan->channel), regval);
> > +	if (ret)
> > +		return ret;
> > +
> > +	st->ch_pwr_down[chan->channel] = !readin;
> 
> ...
> 
> > +	int ret, tmp[2], min, max;
> > +	unsigned int num;
> > +	struct fwnode_handle *child;
> > +
> > +	num = device_get_child_node_count(&st->spi->dev);
> > +	if (num != AD5770R_MAX_CHANNELS)
> > +		return -EINVAL;
> > +
> > +	device_for_each_child_node(&st->spi->dev, child) {
> > +		ret = fwnode_property_read_u32(child, "num", &num);
> > +		if (ret)
> > +			return ret;
> > +		if (num > AD5770R_MAX_CHANNELS)
> > +			return -EINVAL;
> > +
> > +		ret = fwnode_property_read_u32_array(child,
> > +						     "adi,range-microamp",
> > +						     tmp, 2);
> 
> sizeof()?
> 
> And perhaps
> 	u32 tmp[2];
> 
> > +		if (ret)
> > +			return ret;
> > +
> > +		min = tmp[0] / 1000;
> > +		max = tmp[1] / 1000;
> > +		ret = ad5770r_store_output_range(st, min, max, num);
> > +		if (ret)
> > +			return ret;
> > +	}
> > +	return ret;
> 
> ret might be uninitialized?
> 
> In any case, shouldn't be
> 	return 0;
> ?
> 
> > +}
> 
> ...
> 
> > +	st->external_res = fwnode_property_read_bool(st->spi->dev.fwnode,
> > +						     "adi,external-resistor");
> 
> Use of fwnode (and esp. w/o dev_fwnode() helper) looks inconsistent here.
> Why not device_property_...()?
> 
> > +	return ret;
> 
> return 0;
> 
> ...
> 
> > +static const struct of_device_id ad5770r_of_id[] = {
> > +	{ .compatible = "adi,ad5770r", },
> > +	{},
> 
> No need comma in terminator line.
> 
> > +};
> > +MODULE_DEVICE_TABLE(of, ad5770r_of_id);
> > +
> > +static const struct spi_device_id ad5770r_id[] = {
> > +	{ "ad5770r", 0 },
> > +	{},
> 
> Ditto.
> 
> > +};

  reply	other threads:[~2020-03-22  9:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-18 12:10 [PATCH v4 0/2] iio: dac: AD5770R: Add support Alexandru Tachici
2020-02-18 12:10 ` [PATCH v4 1/2] iio: dac: ad5770r: Add AD5770R support Alexandru Tachici
2020-02-21 15:05   ` Jonathan Cameron
2020-03-21 21:09   ` Andy Shevchenko
2020-03-22  9:17     ` Ardelean, Alexandru [this message]
2020-03-22 22:19       ` andriy.shevchenko
2020-02-18 12:10 ` [PATCH v4 2/2] dt-bindings: iio: dac: Add docs for AD5770R DAC Alexandru Tachici
2020-02-21 15:07   ` Jonathan Cameron
2020-03-20  0:49   ` Rob Herring
2020-03-21 10:38     ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2942e900ab01957027b918b2a5fdbd665fe6b2ed.camel@analog.com \
    --to=alexandru.ardelean@analog.com \
    --cc=Alexandru.Tachici@analog.com \
    --cc=Mircea.Caprioru@analog.com \
    --cc=andriy.shevchenko@intel.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).