All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Peter Meerwald <pmeerw@pmeerw.net>
Cc: linux-iio@vger.kernel.org
Subject: Re: [PATCH 1/4] iio: add store_eeprom to mcp4725 dac driver
Date: Sat, 29 Jun 2013 13:22:58 +0100	[thread overview]
Message-ID: <51CED1A2.1070707@kernel.org> (raw)
In-Reply-To: <1372023020-18742-1-git-send-email-pmeerw@pmeerw.net>

On 06/23/2013 10:30 PM, Peter Meerwald wrote:
> Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
Applied to the togreg branch of iio.git
> ---
>  drivers/iio/dac/mcp4725.c | 64 +++++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 62 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/dac/mcp4725.c b/drivers/iio/dac/mcp4725.c
> index a612ec7..cb9db90 100644
> --- a/drivers/iio/dac/mcp4725.c
> +++ b/drivers/iio/dac/mcp4725.c
> @@ -12,14 +12,13 @@
>   * driver for the Microchip I2C 12-bit digital-to-analog converter (DAC)
>   * (7-bit I2C slave address 0x60, the three LSBs can be configured in
>   * hardware)
> - *
> - * writing the DAC value to EEPROM is not supported
>   */
>  
>  #include <linux/module.h>
>  #include <linux/init.h>
>  #include <linux/i2c.h>
>  #include <linux/err.h>
> +#include <linux/delay.h>
>  
>  #include <linux/iio/iio.h>
>  #include <linux/iio/sysfs.h>
> @@ -64,6 +63,66 @@ static SIMPLE_DEV_PM_OPS(mcp4725_pm_ops, mcp4725_suspend, mcp4725_resume);
>  #define MCP4725_PM_OPS NULL
>  #endif
>  
> +static int mcp4725_store_eeprom(struct device *dev,
> +	struct device_attribute *attr, const char *buf, size_t len)
> +{
> +	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> +	struct mcp4725_data *data = iio_priv(indio_dev);
> +	int tries = 20;
> +	u8 inoutbuf[3];
> +	bool state;
> +	int ret;
> +
> +	ret = strtobool(buf, &state);
> +	if (ret < 0)
> +		return ret;
> +
> +	if (!state)
> +		return 0;
> +
> +	inoutbuf[0] = 0x60; /* write EEPROM */
> +	inoutbuf[1] = data->dac_value >> 4;
> +	inoutbuf[2] = (data->dac_value & 0xf) << 4;
> +
> +	ret = i2c_master_send(data->client, inoutbuf, 3);
> +	if (ret < 0)
> +		return ret;
> +	else if (ret != 3)
> +		return -EIO;
> +
> +	/* wait for write complete, takes up to 50ms */
> +	while (tries--) {
> +		msleep(20);
> +		ret = i2c_master_recv(data->client, inoutbuf, 3);
> +		if (ret < 0)
> +			return ret;
> +		else if (ret != 3)
> +			return -EIO;
> +
> +		if (inoutbuf[0] & 0x80)
> +			break;
> +	}
> +
> +	if (tries < 0) {
> +		dev_err(&data->client->dev,
> +			"mcp4725_store_eeprom() failed, incomplete\n");
> +		return -EIO;
> +	}
> +
> +	return len;
> +}
> +
> +static IIO_DEVICE_ATTR(store_eeprom, S_IWUSR, NULL, mcp4725_store_eeprom, 0);
> +
> +static struct attribute *mcp4725_attributes[] = {
> +	&iio_dev_attr_store_eeprom.dev_attr.attr,
> +	NULL,
> +};
> +
> +static const struct attribute_group mcp4725_attribute_group = {
> +	.attrs = mcp4725_attributes,
> +};
> +
>  static const struct iio_chan_spec mcp4725_channel = {
>  	.type		= IIO_VOLTAGE,
>  	.indexed	= 1,
> @@ -138,6 +197,7 @@ static int mcp4725_write_raw(struct iio_dev *indio_dev,
>  static const struct iio_info mcp4725_info = {
>  	.read_raw = mcp4725_read_raw,
>  	.write_raw = mcp4725_write_raw,
> +	.attrs = &mcp4725_attribute_group,
>  	.driver_module = THIS_MODULE,
>  };
>  
> 

      parent reply	other threads:[~2013-06-29 12:22 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-23 21:30 [PATCH 1/4] iio: add store_eeprom to mcp4725 dac driver Peter Meerwald
2013-06-23 21:30 ` [PATCH 2/4] iio: add powerdown to mcp4725 dac drive Peter Meerwald
2013-06-29 12:23   ` Jonathan Cameron
2013-06-23 21:30 ` [PATCH 3/4] iio: add DAC 500kohm_to_gnd to possible powerdown_modes Peter Meerwald
2013-06-29 12:23   ` Jonathan Cameron
2013-06-29 13:32     ` Lars-Peter Clausen
2013-06-29 15:13       ` Jonathan Cameron
2013-06-23 21:30 ` [PATCH 4/4] iio: move ABI specification for store_eeprom; is used by ad9523, mcp4725 and ds1077 devices Peter Meerwald
2013-06-29 12:23   ` Jonathan Cameron
2013-06-24 16:05 ` [PATCH 1/4] iio: add store_eeprom to mcp4725 dac driver Jonathan Cameron
2013-06-24 16:10   ` Peter Meerwald
2013-06-24 16:14     ` Jonathan Cameron
2013-06-29 12:22 ` Jonathan Cameron [this message]

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=51CED1A2.1070707@kernel.org \
    --to=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.