Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp277589imm; Thu, 6 Sep 2018 02:13:46 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZfMDCENS2lKaFHtRoPMruvKjqOH1IUSy2HhNz0s2PPJF2Mvc13+Zk2Maq9cjIidClFR03L X-Received: by 2002:a63:4306:: with SMTP id q6-v6mr1771022pga.181.1536225226624; Thu, 06 Sep 2018 02:13:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536225226; cv=none; d=google.com; s=arc-20160816; b=VY01q+MZyELDfI27WsFnYr40zqnXvTmU8M/dvNaZQmzsUEFs8eOSW9DQsvoT40yg4N /XC2c8/RUFyXM3ddvQWGQgnUFBrNNuENhjEEIJxPfwMAijfVhjr/ZWVcJ1o5sYhhr5T9 5VUrlg3e2BVlFU3qPNNDmQ2MgRz6jnBCkEXUtcRfUhVfjtHVqvbPXAb+JSXU0HRUi7fw rx1BMP3ndzI7A5/YqDPod4BAxjwvu0GR2zv3d/RhE7zozpFExpLCH0JmSPYg4wS+RkdQ eoiFQL7zy1daOzCOwKEYnNVL4aLIfmUJ07xUAcFvt/f92qXttosymQshuIMpfyH6gHas zflw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=byTuyog3nM3+c+WWHo63OFDO+ekRKy8gSawPSC1cjwg=; b=Dc8QyDGTqgN4Xj0ITPxSeuXqLh5Tl1DNaCriCO/Xav6PGcw8YRX2+4ls3p6qT9y5xk /8wpIHawFgUO7+VZJC1INTz/NyTOOTZfi8PiWozJ+lPlXaYg4Og4uv7Dc6njec8pOpJp /sHNf0gCImszYpjSg35XoNiDANeQ6UYYqMT2lzNHy2NSVutpT7lIJiUBlaa9hMXdRghi gzEvdrSjABqn2/kWBm3TGzCucharkkNfx4uSaepjP9LnYsKs1MhoLNQaeKMjvCBebrpU RE47FH0bx/glm3N4weZitf0Evv44cmQwlUBPpkZp/SBxRlqtQGG6YzZMToLboBWIDAMt cRVA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b10-v6si5055549plk.302.2018.09.06.02.13.31; Thu, 06 Sep 2018 02:13:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728411AbeIFNqh (ORCPT + 99 others); Thu, 6 Sep 2018 09:46:37 -0400 Received: from mail.steuer-voss.de ([85.183.69.95]:55286 "EHLO mail.steuer-voss.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727817AbeIFNqh (ORCPT ); Thu, 6 Sep 2018 09:46:37 -0400 X-Greylist: delayed 357 seconds by postgrey-1.27 at vger.kernel.org; Thu, 06 Sep 2018 09:46:36 EDT X-Virus-Scanned: Debian amavisd-new at mail.steuer-voss.de Received: by mail.steuer-voss.de (Postfix, from userid 1000) id 7F5E747707; Thu, 6 Sep 2018 11:06:06 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.steuer-voss.de (Postfix) with ESMTP id 76D3D476FB; Thu, 6 Sep 2018 11:06:06 +0200 (CEST) Date: Thu, 6 Sep 2018 11:06:06 +0200 (CEST) From: Nikolaus Voss X-X-Sender: nv@fox.voss.local To: Markus Pargmann cc: Mark Brown , Wolfram Sang , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@pengutronix.de, Irina Tirdea , nikolaus.voss@loewensteinmedical.de Subject: Re: [PATCH v3 4/4] regmap-i2c: Add smbus i2c block support In-Reply-To: <1440657872-24554-5-git-send-email-mpa@pengutronix.de> Message-ID: References: <1440657872-24554-1-git-send-email-mpa@pengutronix.de> <1440657872-24554-5-git-send-email-mpa@pengutronix.de> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha1; BOUNDARY="8323329-1313206152-1536224766=:24070" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --8323329-1313206152-1536224766=:24070 Content-Type: text/plain; charset=US-ASCII; format=flowed 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 > --- > 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 ®map_i2c; > + else if (config->reg_bits == 8 && > + i2c_check_functionality(i2c->adapter, > + I2C_FUNC_SMBUS_I2C_BLOCK)) > + return ®map_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 --8323329-1313206152-1536224766=:24070 Content-Type: application/pkcs7-signature; name=smime.p7s Content-Transfer-Encoding: BASE64 Content-Description: S/MIME Cryptographic Signature Content-Disposition: attachment; filename=smime.p7s MIINoQYJKoZIhvcNAQcCoI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