linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: wsa@the-dreams.de (Wolfram Sang)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 02/12] eeprom: at24: remove nvmem regmap dependency
Date: Mon, 2 May 2016 09:32:54 +0200	[thread overview]
Message-ID: <20160502073254.GA2015@tetsubishi> (raw)
In-Reply-To: <1461526096-29584-3-git-send-email-srinivas.kandagatla@linaro.org>

On Sun, Apr 24, 2016 at 08:28:06PM +0100, Srinivas Kandagatla wrote:
> This patch moves to nvmem support in the driver to use callback instead
> of regmap.
> 
> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>

Andrew, since you did the NVMEM implementation, could you have a look at
this? That would be awesome. Thanks!

> ---
>  drivers/misc/eeprom/Kconfig |   1 -
>  drivers/misc/eeprom/at24.c  | 103 ++++++++++----------------------------------
>  2 files changed, 22 insertions(+), 82 deletions(-)
> 
> diff --git a/drivers/misc/eeprom/Kconfig b/drivers/misc/eeprom/Kconfig
> index cfc493c..2d70464 100644
> --- a/drivers/misc/eeprom/Kconfig
> +++ b/drivers/misc/eeprom/Kconfig
> @@ -3,7 +3,6 @@ menu "EEPROM support"
>  config EEPROM_AT24
>  	tristate "I2C EEPROMs / RAMs / ROMs from most vendors"
>  	depends on I2C && SYSFS
> -	select REGMAP
>  	select NVMEM
>  	help
>  	  Enable this driver to get read/write support to most I2C EEPROMs
> diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
> index 089d694..de550a6 100644
> --- a/drivers/misc/eeprom/at24.c
> +++ b/drivers/misc/eeprom/at24.c
> @@ -23,7 +23,6 @@
>  #include <linux/acpi.h>
>  #include <linux/i2c.h>
>  #include <linux/nvmem-provider.h>
> -#include <linux/regmap.h>
>  #include <linux/platform_data/at24.h>
>  
>  /*
> @@ -69,7 +68,6 @@ struct at24_data {
>  	unsigned write_max;
>  	unsigned num_addresses;
>  
> -	struct regmap_config regmap_config;
>  	struct nvmem_config nvmem_config;
>  	struct nvmem_device *nvmem;
>  
> @@ -252,10 +250,10 @@ static ssize_t at24_eeprom_read(struct at24_data *at24, char *buf,
>  	return -ETIMEDOUT;
>  }
>  
> -static ssize_t at24_read(struct at24_data *at24,
> -		char *buf, loff_t off, size_t count)
> +static int at24_read(void *priv, unsigned int off, void *val, size_t count)
>  {
> -	ssize_t retval = 0;
> +	struct at24_data *at24 = priv;
> +	char *buf = val;
>  
>  	if (unlikely(!count))
>  		return count;
> @@ -267,23 +265,21 @@ static ssize_t at24_read(struct at24_data *at24,
>  	mutex_lock(&at24->lock);
>  
>  	while (count) {
> -		ssize_t	status;
> +		int	status;
>  
>  		status = at24_eeprom_read(at24, buf, off, count);
> -		if (status <= 0) {
> -			if (retval == 0)
> -				retval = status;
> -			break;
> +		if (status < 0) {
> +			mutex_unlock(&at24->lock);
> +			return status;
>  		}
>  		buf += status;
>  		off += status;
>  		count -= status;
> -		retval += status;
>  	}
>  
>  	mutex_unlock(&at24->lock);
>  
> -	return retval;
> +	return 0;
>  }
>  
>  /*
> @@ -372,13 +368,13 @@ static ssize_t at24_eeprom_write(struct at24_data *at24, const char *buf,
>  	return -ETIMEDOUT;
>  }
>  
> -static ssize_t at24_write(struct at24_data *at24, const char *buf, loff_t off,
> -			  size_t count)
> +static int at24_write(void *priv, unsigned int off, void *val, size_t count)
>  {
> -	ssize_t retval = 0;
> +	struct at24_data *at24 = priv;
> +	char *buf = val;
>  
>  	if (unlikely(!count))
> -		return count;
> +		return -EINVAL;
>  
>  	/*
>  	 * Write data to chip, protecting against concurrent updates
> @@ -387,70 +383,23 @@ static ssize_t at24_write(struct at24_data *at24, const char *buf, loff_t off,
>  	mutex_lock(&at24->lock);
>  
>  	while (count) {
> -		ssize_t	status;
> +		int status;
>  
>  		status = at24_eeprom_write(at24, buf, off, count);
> -		if (status <= 0) {
> -			if (retval == 0)
> -				retval = status;
> -			break;
> +		if (status < 0) {
> +			mutex_unlock(&at24->lock);
> +			return status;
>  		}
>  		buf += status;
>  		off += status;
>  		count -= status;
> -		retval += status;
>  	}
>  
>  	mutex_unlock(&at24->lock);
>  
> -	return retval;
> -}
> -
> -/*-------------------------------------------------------------------------*/
> -
> -/*
> - * Provide a regmap interface, which is registered with the NVMEM
> - * framework
> -*/
> -static int at24_regmap_read(void *context, const void *reg, size_t reg_size,
> -			    void *val, size_t val_size)
> -{
> -	struct at24_data *at24 = context;
> -	off_t offset = *(u32 *)reg;
> -	int err;
> -
> -	err = at24_read(at24, val, offset, val_size);
> -	if (err)
> -		return err;
> -	return 0;
> -}
> -
> -static int at24_regmap_write(void *context, const void *data, size_t count)
> -{
> -	struct at24_data *at24 = context;
> -	const char *buf;
> -	u32 offset;
> -	size_t len;
> -	int err;
> -
> -	memcpy(&offset, data, sizeof(offset));
> -	buf = (const char *)data + sizeof(offset);
> -	len = count - sizeof(offset);
> -
> -	err = at24_write(at24, buf, offset, len);
> -	if (err)
> -		return err;
>  	return 0;
>  }
>  
> -static const struct regmap_bus at24_regmap_bus = {
> -	.read = at24_regmap_read,
> -	.write = at24_regmap_write,
> -	.reg_format_endian_default = REGMAP_ENDIAN_NATIVE,
> -};
> -
> -/*-------------------------------------------------------------------------*/
> -
>  #ifdef CONFIG_OF
>  static void at24_get_ofdata(struct i2c_client *client,
>  		struct at24_platform_data *chip)
> @@ -482,7 +431,6 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
>  	struct at24_data *at24;
>  	int err;
>  	unsigned i, num_addresses;
> -	struct regmap *regmap;
>  
>  	if (client->dev.platform_data) {
>  		chip = *(struct at24_platform_data *)client->dev.platform_data;
> @@ -612,19 +560,6 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
>  		}
>  	}
>  
> -	at24->regmap_config.reg_bits = 32;
> -	at24->regmap_config.val_bits = 8;
> -	at24->regmap_config.reg_stride = 1;
> -	at24->regmap_config.max_register = chip.byte_len - 1;
> -
> -	regmap = devm_regmap_init(&client->dev, &at24_regmap_bus, at24,
> -				  &at24->regmap_config);
> -	if (IS_ERR(regmap)) {
> -		dev_err(&client->dev, "regmap init failed\n");
> -		err = PTR_ERR(regmap);
> -		goto err_clients;
> -	}
> -
>  	at24->nvmem_config.name = dev_name(&client->dev);
>  	at24->nvmem_config.dev = &client->dev;
>  	at24->nvmem_config.read_only = !writable;
> @@ -632,6 +567,12 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
>  	at24->nvmem_config.owner = THIS_MODULE;
>  	at24->nvmem_config.compat = true;
>  	at24->nvmem_config.base_dev = &client->dev;
> +	at24->nvmem_config.reg_read = at24_read;
> +	at24->nvmem_config.reg_write = at24_write;
> +	at24->nvmem_config.priv = at24;
> +	at24->nvmem_config.stride = 4;
> +	at24->nvmem_config.word_size = 1;
> +	at24->nvmem_config.size = chip.byte_len;
>  
>  	at24->nvmem = nvmem_register(&at24->nvmem_config);
>  
> -- 
> 2.5.0
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160502/d9123fc5/attachment.sig>

  reply	other threads:[~2016-05-02  7:32 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-24 19:28 [PATCH 00/12] nvmem: remove regmap dependency Srinivas Kandagatla
2016-04-24 19:28 ` [PATCH 01/12] nvmem: core: " Srinivas Kandagatla
2016-04-24 19:28 ` [PATCH 02/12] eeprom: at24: remove nvmem " Srinivas Kandagatla
2016-05-02  7:32   ` Wolfram Sang [this message]
2016-05-04  1:32     ` Andrew Lunn
2016-04-24 19:28 ` [PATCH 03/12] eeprom: at25: " Srinivas Kandagatla
2016-04-24 19:28 ` [PATCH 04/12] nvmem: qfprom: " Srinivas Kandagatla
2016-04-24 19:28 ` [PATCH 05/12] nvmem: vif610-ocotp: " Srinivas Kandagatla
2016-04-27  5:36   ` maitysanchayan at gmail.com
2016-04-24 19:28 ` [PATCH 06/12] nvmem: sunxi-sid: " Srinivas Kandagatla
2016-04-24 19:28 ` [PATCH 07/12] nvmem: rockchip-efuse: " Srinivas Kandagatla
2016-04-24 19:28 ` [PATCH 08/12] nvmem: mtk-efuse: " Srinivas Kandagatla
2016-04-27  6:30   ` andrew-ct chen
2016-05-01 21:01   ` Greg Kroah-Hartman
2016-04-24 19:28 ` [PATCH 09/12] nvmem: imx-ocotp: " Srinivas Kandagatla
2016-04-24 19:28 ` [PATCH 10/12] nvmem: lpc18xx-eeprom: " Srinivas Kandagatla
2016-04-24 19:28 ` [PATCH 11/12] nvmem: mxs-ocotp: " Srinivas Kandagatla
2016-04-28  6:50   ` Stefan Wahren
2016-04-24 19:28 ` [PATCH 12/12] nvmem: 93xx46: " Srinivas Kandagatla

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=20160502073254.GA2015@tetsubishi \
    --to=wsa@the-dreams.de \
    --cc=linux-arm-kernel@lists.infradead.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).