public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Ciprian Regus <ciprian.regus@analog.com>
Cc: jic23@kernel.org, krzysztof.kozlowski+dt@linaro.org,
	robh+dt@kernel.org, linux-kernel@vger.kernel.org,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH 2/2] drivers: iio: dac: Add AD5754 DAC driver
Date: Tue, 4 Oct 2022 11:50:53 +0300	[thread overview]
Message-ID: <Yzvz7ecXcMVp7quF@smile.fi.intel.com> (raw)
In-Reply-To: <20221004071825.791307-3-ciprian.regus@analog.com>

On Tue, Oct 04, 2022 at 10:18:25AM +0300, Ciprian Regus wrote:
> The AD5724/AD5734/AD5754 are quad, 12-/14-/16-bit, serial
> input, voltage output DACs. The devices operate from single-
> supply voltages from +4.5 V up to +16.5 V or dual-supply
> voltages from ±4.5 V up to ±16.5 V. The input coding is
> user-selectable twos complement or offset binary for a bipolar
> output (depending on the state of Pin BIN/2sComp), and straight
> binary for a unipolar output.

...

> +#define AD5754_INT_VREF			2500

Units? (Like _mV or _uV or what? Note, small u is OK to have in such cases)

...

> +#define AD5754_CLEAR_FUNC		BIT(2)
> +#define AD5754_LOAD_FUNC		(BIT(2) | BIT(0))
> +#define AD5754_NOOP_FUNC		GENMASK(4, 3)

Seems like abuse of BIT and GENMASK, use plain numbers as it's probably is.
Otherwise _each_ bit should have it's own descriptive meaning.

...

> +#define AD5754_DAC_REG			0
> +#define AD5754_RANGE_REG		BIT(0)
> +#define AD5754_PWR_REG			BIT(1)

...

> +#define AD5754_CTRL_REG			GENMASK(1, 0)

Why _REG uses GENMASK()?

...

> +struct ad5754_span_tbl {
> +	int min;
> +	int max;
> +};

I'm wondering if linear_range.h can anyhow help with this code.

...

> +struct ad5754_state {
> +	struct regmap *regmap;
> +	struct spi_device *spi;
> +	struct device *dev;

You always can derive dev from regmap, is this one different?

> +
> +	const struct ad5754_chip_info *chip_info;
> +
> +	u32 range_idx[AD5754_MAX_CHANNELS];
> +	int offset[AD5754_MAX_CHANNELS];
> +	u32 dac_max_code;
> +	u32 data_mask;
> +	u32 sub_lsb;
> +	u32 vref;
> +
> +	/*
> +	 * DMA (thus cache coherency maintenance) may require the
> +	 * transfer buffers to live in their own cache lines.
> +	 */
> +	u8 buff[AD5754_FRAME_SIZE] __aligned(IIO_DMA_MINALIGN);
> +};

...

> +static const struct regmap_config ad5754_regmap_config = {
> +	.reg_bits = 8,
> +	.val_bits = 16,
> +	.reg_write = ad5754_reg_write,
> +	.reg_read = ad5754_reg_read,

No max register address?

> +};

...

> +	struct fwnode_handle *channel_node = NULL;

Redundant assignment.

...

> +	fwnode_for_each_available_child_node(dev_fwnode(st->dev), channel_node) {

Why not device_for_each_child_node() ?

(Yes, it uses available ones)

> +	}

...

> +		range = &ad5754_range[st->range_idx[chan->channel]];
> +		gain = (range->max - range->min) / 2500;
> +		*val = st->vref * gain / 1000;
> +		*val2 = st->chip_info->resolution;

Yeah, looks familiar to the linear_range APIs.

...

> +static int ad5754_probe(struct spi_device *spi)
> +{
> +	struct regulator *vref_reg;
> +	struct iio_dev *indio_dev;
> +	struct ad5754_state *st;
> +	struct device *dev;
> +	int ret;

> +	dev = &spi->dev;

Can be done in the definition block (inline).

...

> +	st->chip_info = device_get_match_data(dev);
> +	if (!st->chip_info)
> +		st->chip_info =
> +			(const struct ad5754_chip_info *)spi_get_device_id(spi)->driver_data;

This can look better with a temporary variable. But doesn't matter since we
would like to have these lines to be packed in a new SPI API helper in the
future.

...

> +		st->vref = ret / 1000;

Do we have uV_PER_mV or so?

...

> +static const struct spi_device_id ad5754_id[] = {

> +	{},

No comma for the terminator line.

> +};

...

> +static const struct of_device_id ad5754_dt_id[] = {

> +	{},

Ditto.

> +};

...

> +module_driver(ad5754_driver,
> +	      ad5754_register_driver,
> +	      ad5754_unregister_driver);

Why not module_spi_driver()?

-- 
With Best Regards,
Andy Shevchenko



  parent reply	other threads:[~2022-10-04  8:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-04  7:18 [PATCH 0/2] Add support for the AD5754 DAC Ciprian Regus
2022-10-04  7:18 ` [PATCH 1/2] dt-bindings: iio: dac: add adi,ad5754.yaml Ciprian Regus
2022-10-04 11:26   ` Krzysztof Kozlowski
2022-10-04  7:18 ` [PATCH 2/2] drivers: iio: dac: Add AD5754 DAC driver Ciprian Regus
2022-10-04  8:40   ` Marcus Folkesson
2022-10-04  8:50   ` Andy Shevchenko [this message]
2022-10-09 17:09   ` 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=Yzvz7ecXcMVp7quF@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=ciprian.regus@analog.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jic23@kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh+dt@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