From patchwork Fri Jan 9 17:21:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 5602101 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id DDC62C058D for ; Fri, 9 Jan 2015 17:27:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E6E5520609 for ; Fri, 9 Jan 2015 17:27:06 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 75F3220606 for ; Fri, 9 Jan 2015 17:27:05 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Y9dIX-0001u8-2S; Fri, 09 Jan 2015 17:24:33 +0000 Received: from sauhun.de ([89.238.76.85] helo=pokefinder.org) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Y9dGl-0000iu-4E for linux-arm-kernel@lists.infradead.org; Fri, 09 Jan 2015 17:22:48 +0000 Received: from p4fe257be.dip0.t-ipconnect.de ([79.226.87.190]:48231 helo=localhost) by pokefinder.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1Y9dGH-0000Lv-QJ; Fri, 09 Jan 2015 18:22:14 +0100 From: Wolfram Sang To: linux-i2c@vger.kernel.org Subject: [RFC 01/11] i2c: add quirk structure to describe adapter flaws Date: Fri, 9 Jan 2015 18:21:31 +0100 Message-Id: <1420824103-24169-2-git-send-email-wsa@the-dreams.de> X-Mailer: git-send-email 2.1.3 In-Reply-To: <1420824103-24169-1-git-send-email-wsa@the-dreams.de> References: <1420824103-24169-1-git-send-email-wsa@the-dreams.de> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150109_092243_448017_48795671 X-CRM114-Status: GOOD ( 13.32 ) X-Spam-Score: -0.0 (/) Cc: linux-mips@linux-mips.org, Wolfram Sang , Benjamin Herrenschmidt , linux-kernel@vger.kernel.org, Ludovic Desroches , Yingjoe Chen , linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The number of I2C adapters which are not fully I2C compatible is rising, sadly. Drivers usually do handle the flaws, still the user receives only some errno for a transfer which normally can be expected to work. This patch introduces a formal description of flaws. One advantage is that the core can check before the actual transfer if the messages could be transferred at all. This is done in the next patch. Another advantage is that we can pass this information to the user so the restrictions are exactly known and further actions can be based on that. This will be done later after some stabilization period for this description. Signed-off-by: Wolfram Sang --- include/linux/i2c.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/include/linux/i2c.h b/include/linux/i2c.h index e3a1721c8354..f8a642713706 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -447,6 +447,40 @@ int i2c_recover_bus(struct i2c_adapter *adap); int i2c_generic_gpio_recovery(struct i2c_adapter *adap); int i2c_generic_scl_recovery(struct i2c_adapter *adap); +/** + * struct i2c_adapter_quirks - describe flaws of an i2c adapter + * @flags: see I2C_ADAPTER_QUIRK_* for possible flags + * @max_num_msgs: maximum number of messages per transfer + * @max_write_len: maximum length of a write message + * @max_read_len: maximum length of a read message + * @max_comb_write_len: maximum length of a write in a combined message + * @max_comb_read_len: maximum length of a read in a combined message + * + * Note about combined messages: Some I2C controllers can only send one + * message per transfer, plus something called combined message or + * write-then-read. This is a (usually) small write message followed by + * a read message and barely enough to access register based slaves like + * EEPROMs. There is a flag to support this mode. It implies max_num_msg = 2 + * and does the length checks with max_comb_*_len because combined message mode + * usually has its own limitations. Read/write flags of the messages are also + * checked to be proper. Because of HW implementation, some controllers can + * actually do write-then-anything. To support that, write-then-read has been + * broken out into write-first and read-second. + */ +struct i2c_adapter_quirks { + u64 flags; + int max_num_msgs; + u16 max_write_len; + u16 max_read_len; + u16 max_comb_write_len; + u16 max_comb_read_len; +}; + +#define I2C_ADAPTER_QUIRK_COMB_WRITE_FIRST BIT(0) +#define I2C_ADAPTER_QUIRK_COMB_READ_SECOND BIT(1) +#define I2C_ADAPTER_QUIRK_COMB_WRITE_THEN_READ (I2C_ADAPTER_QUIRK_COMB_WRITE_FIRST | \ + I2C_ADAPTER_QUIRK_COMB_READ_SECOND) + /* * i2c_adapter is the structure used to identify a physical i2c bus along * with the access algorithms necessary to access it. @@ -472,6 +506,7 @@ struct i2c_adapter { struct list_head userspace_clients; struct i2c_bus_recovery_info *bus_recovery_info; + struct i2c_adapter_quirks *quirks; }; #define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev)