mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nikolaus Voss <nv@vosn.de>
To: Markus Pargmann <mpa@pengutronix.de>
Cc: Mark Brown <broonie@kernel.org>, Wolfram Sang <wsa@the-dreams.de>,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, kernel@pengutronix.de,
	Irina Tirdea <irina.tirdea@intel.com>,
	nikolaus.voss@loewensteinmedical.de
Subject: Re: [PATCH v3 4/4] regmap-i2c: Add smbus i2c block support
Date: Thu, 6 Sep 2018 11:06:06 +0200 (CEST)	[thread overview]
Message-ID: <alpine.DEB.2.20.1809061101560.24070@fox.voss.local> (raw)
In-Reply-To: <1440657872-24554-5-git-send-email-mpa@pengutronix.de>

[-- Attachment #1: Type: text/plain, Size: 3426 bytes --]

Hi Markus,

On Thu, 27 Aug 2015, Markus Pargmann wrote:
> This allows to read/write up to 32 bytes of data and is to be prefered
> if supported before the register read/write smbus support.
>
> Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
> ---
> drivers/base/regmap/regmap-i2c.c | 49 ++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 49 insertions(+)
>
> diff --git a/drivers/base/regmap/regmap-i2c.c b/drivers/base/regmap/regmap-i2c.c
> index 4b76e33110a2..ddb9b0efb724 100644
> --- a/drivers/base/regmap/regmap-i2c.c
> +++ b/drivers/base/regmap/regmap-i2c.c
> @@ -209,11 +209,60 @@ static struct regmap_bus regmap_i2c = {
> 	.val_format_endian_default = REGMAP_ENDIAN_BIG,
> };
>
> +static int regmap_i2c_smbus_i2c_write(void *context, const void *data,
> +				      size_t count)
> +{
> +	struct device *dev = context;
> +	struct i2c_client *i2c = to_i2c_client(dev);
> +
> +	if (count < 1)
> +		return -EINVAL;
> +	if (count >= I2C_SMBUS_BLOCK_MAX)
> +		return -E2BIG;
> +
> +	--count;
> +	return i2c_smbus_write_i2c_block_data(i2c, ((u8 *)data)[0], count,
> +					      ((u8 *)data + 1));
> +}
> +
> +static int regmap_i2c_smbus_i2c_read(void *context, const void *reg,
> +				     size_t reg_size, void *val,
> +				     size_t val_size)
> +{
> +	struct device *dev = context;
> +	struct i2c_client *i2c = to_i2c_client(dev);
> +	int ret;
> +
> +	if (reg_size != 1 || val_size < 1)
> +		return -EINVAL;
> +	if (val_size >= I2C_SMBUS_BLOCK_MAX)
> +		return -E2BIG;
> +
> +	ret = i2c_smbus_read_i2c_block_data(i2c, ((u8 *)reg)[0], val_size, val);
> +	if (ret == val_size)
> +		return 0;
> +	else if (ret < 0)
> +		return ret;
> +	else
> +		return -EIO;
> +}
> +
> +static struct regmap_bus regmap_i2c_smbus_i2c_block = {
> +	.write = regmap_i2c_smbus_i2c_write,
> +	.read = regmap_i2c_smbus_i2c_read,
> +	.max_raw_read = I2C_SMBUS_BLOCK_MAX,
> +	.max_raw_write = I2C_SMBUS_BLOCK_MAX,
> +};
> +
> static const struct regmap_bus *regmap_get_i2c_bus(struct i2c_client *i2c,
> 					const struct regmap_config *config)
> {
> 	if (i2c_check_functionality(i2c->adapter, I2C_FUNC_I2C))
> 		return &regmap_i2c;
> +	else if (config->reg_bits == 8 &&
> +		 i2c_check_functionality(i2c->adapter,
> +					 I2C_FUNC_SMBUS_I2C_BLOCK))
> +		return &regmap_i2c_smbus_i2c_block;
> 	else if (config->val_bits == 16 && config->reg_bits == 8 &&
> 		 i2c_check_functionality(i2c->adapter,
> 					 I2C_FUNC_SMBUS_WORD_DATA))
>

using i2c_smbus_read/write_i2c_block_data() instead of
read/write_word_data() or i2c_transfer() actually changes what is
transferred on the bus. SMBus block transfers have a different
register model, they additionally read or write the byte count after
transmitting the register/command code, see SMBus spec:

+---+-------------+---+--+-------------+--+---------------+--+------------+----+
| S | Slave Addr  | Wr| A| Command Code| A| Byte Count = N| A| Data Byte 1| A  |
+---+-------------+---+--+-------------+--+---------------+--+------------+----+

So a driver using regmap must implement different transfers depending on
the i2c adapter capabilities, is this intentionally done so?

Specifically, there is no way of getting rid of the additional byte count
field if the adapter doesn't support I2C_FUNC_I2C although it would be
technically possible.

I would prefer regmap to always use the same register model (i.e. without
the byte count field), can you explain the rationale for this?

Niko

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 3493 bytes --]

  reply	other threads:[~2018-09-06  9:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-27  6:44 [PATCH v3 0/4] regmap: " Markus Pargmann
2015-08-27  6:44 ` [PATCH v3 1/4] regmap: Introduce max_raw_read/write for regmap_bulk_read/write Markus Pargmann
2015-08-27  6:44 ` [PATCH v3 2/4] regmap: regmap max_raw_read/write getter functions Markus Pargmann
2015-08-27  6:44 ` [PATCH v3 3/4] regmap: Add raw_write/read checks for max_raw_write/read sizes Markus Pargmann
2015-08-27  6:44 ` [PATCH v3 4/4] regmap-i2c: Add smbus i2c block support Markus Pargmann
2018-09-06  9:06   ` Nikolaus Voss [this message]
2015-08-28 17:33 ` [PATCH v3 0/4] regmap: " Mark Brown
2015-08-29  9:35 ` Mark Brown

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=alpine.DEB.2.20.1809061101560.24070@fox.voss.local \
    --to=nv@vosn.de \
    --cc=broonie@kernel.org \
    --cc=irina.tirdea@intel.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpa@pengutronix.de \
    --cc=nikolaus.voss@loewensteinmedical.de \
    --cc=wsa@the-dreams.de \
    /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®