mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Joshua Crofts <joshua.crofts1@gmail.com>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] iio: dac: mcp47a1: add support for new device
Date: Tue, 21 Jul 2026 23:47:58 +0300	[thread overview]
Message-ID: <al_a_pbITuYMg0KH@ashevche-desk.local> (raw)
In-Reply-To: <20260721-mcp47a1-add-support-v1-2-da045a2567e3@gmail.com>

On Tue, Jul 21, 2026 at 08:24:39PM +0200, Joshua Crofts wrote:
> The Microchip MCP47A1 is a 6-bit volatile Digital-to-Analog converted
> which communicates via I2C.

...

> +#include <linux/array_size.h>
> +#include <linux/err.h>
> +#include <linux/i2c.h>
> +#include <linux/module.h>
> +#include <linux/regmap.h>
> +#include <linux/regulator/consumer.h>
> +#include <linux/types.h>
> +#include <linux/units.h>


> +struct mcp47a1_data {
> +	struct regmap *regmap;
> +	int vref_mv;

_mV

...

> +static const struct regmap_config mcp47a1_regmap_config = {
> +	.name = "mcp47a1",
> +	.reg_bits = 8,
> +	.val_bits = 8,
> +	.max_register = MCP47A1_CMD_CODE,
> +};

No cache?

...

> +static int mcp47a1_probe(struct i2c_client *client)
> +{
> +	struct device *dev = &client->dev;
> +	struct mcp47a1_data *data;
> +	struct iio_dev *indio_dev;
> +	int reg_val;
> +	int ret;
> +
> +	indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
> +	if (!indio_dev)
> +		return -ENOMEM;
> +
> +	data = iio_priv(indio_dev);

> +	i2c_set_clientdata(client, indio_dev);

Is it used?

> +	data->regmap = devm_regmap_init_i2c(client, &mcp47a1_regmap_config);
> +	if (IS_ERR(data->regmap))
> +		return dev_err_probe(dev, PTR_ERR(data->regmap),
> +				     "Failed to initialize regmap\n");
> +
> +	ret = devm_regulator_get_enable(dev, "vdd");
> +	if (ret)
> +		return dev_err_probe(dev, ret, "Failed to enable regulator\n");
> +
> +	ret = devm_regulator_get_enable_read_voltage(dev, "vref");
> +	if (ret < 0)
> +		return dev_err_probe(dev, ret, "Failed to read vref\n");
> +
> +	data->vref_mv = ret / MILLI;

(MICRO / MILLI)

> +	/*
> +	 * This is a volatile DAC which doesn't have an ID register, instead
> +	 * the value register is set to 0x20 every Power-on-Reset (table 4-1).
> +	 * Any other read value at startup could indicate that the device is
> +	 * damaged etc.
> +	 */
> +	ret = regmap_read(data->regmap, MCP47A1_CMD_CODE, &reg_val);
> +	if (ret)
> +		return dev_err_probe(dev, ret,
> +				     "Failed to read register on startup\n");
> +
> +	if (reg_val != 0x20)
> +		dev_info(dev, "Read value 0x%02x at startup\n", reg_val);
> +
> +	indio_dev->name = "mcp47a1";
> +	indio_dev->modes = INDIO_DIRECT_MODE;
> +	indio_dev->info = &mcp47a1_info;
> +	indio_dev->channels = mcp47a1_channels;
> +	indio_dev->num_channels = ARRAY_SIZE(mcp47a1_channels);
> +
> +	return devm_iio_device_register(dev, indio_dev);
> +}

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2026-07-21 20:48 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-21 18:24 [PATCH 0/2] " Joshua Crofts
2026-07-21 18:24 ` [PATCH 1/2] dt-bindings: iio: dac: add support for mcp47a1 Joshua Crofts
2026-07-22 16:47   ` Conor Dooley
2026-07-24 23:04   ` Jonathan Cameron
2026-07-24 23:04     ` Jonathan Cameron
2026-07-25  8:12     ` Joshua Crofts
2026-07-25 15:41       ` David Lechner
2026-07-25 21:54         ` Jonathan Cameron
2026-07-21 18:24 ` [PATCH 2/2] iio: dac: mcp47a1: add support for new device Joshua Crofts
2026-07-21 20:47   ` Andy Shevchenko [this message]
2026-07-22  6:30     ` Joshua Crofts
2026-07-25 16:52       ` David Lechner
2026-07-24 23:14   ` Jonathan Cameron
2026-07-25 10:17     ` Joshua Crofts

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=al_a_pbITuYMg0KH@ashevche-desk.local \
    --to=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=joshua.crofts1@gmail.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=robh@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

all inboxes | Powered by JetHome®