From patchwork Tue Jun 8 15:28:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean Delvare X-Patchwork-Id: 456205 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_SANE_2 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CAD78C4743D for ; Tue, 8 Jun 2021 15:29:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B09A56108E for ; Tue, 8 Jun 2021 15:29:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231175AbhFHPay (ORCPT ); Tue, 8 Jun 2021 11:30:54 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:51784 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231268AbhFHPax (ORCPT ); Tue, 8 Jun 2021 11:30:53 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 86C8C219C4; Tue, 8 Jun 2021 15:28:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623166139; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TVppNiYg3WFjPCXVq3b1HpIZqBzgMgsb2spfM92q1yQ=; b=NVSBMoDaGEUGtwBxLo3kgG9QEGmrEL+h61SbCfQKG5GNcIhdyAzzEOHiMPJWNFFb6OhWFC lzHzWowvJR4zFMbnSj/s+IYREg+yZ5cLNMuf3HOq7aK7c0YkJkdZniuQ/fgLD3SBanyiAK IhlHEvsrX5TqTU3arT6VaN0fQHCbbes= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623166139; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TVppNiYg3WFjPCXVq3b1HpIZqBzgMgsb2spfM92q1yQ=; b=EToG/9/svHqUNkOeuGi2PL1E0fINvGHYCojNh0lPx2ECK287ciXqeBCRtaAlYEKQxCkQG1 nwvmIltIsV3VpvDQ== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 506B3118DD; Tue, 8 Jun 2021 15:28:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623166139; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TVppNiYg3WFjPCXVq3b1HpIZqBzgMgsb2spfM92q1yQ=; b=NVSBMoDaGEUGtwBxLo3kgG9QEGmrEL+h61SbCfQKG5GNcIhdyAzzEOHiMPJWNFFb6OhWFC lzHzWowvJR4zFMbnSj/s+IYREg+yZ5cLNMuf3HOq7aK7c0YkJkdZniuQ/fgLD3SBanyiAK IhlHEvsrX5TqTU3arT6VaN0fQHCbbes= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623166139; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TVppNiYg3WFjPCXVq3b1HpIZqBzgMgsb2spfM92q1yQ=; b=EToG/9/svHqUNkOeuGi2PL1E0fINvGHYCojNh0lPx2ECK287ciXqeBCRtaAlYEKQxCkQG1 nwvmIltIsV3VpvDQ== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id 3f62EbuMv2DmMgAALh3uQQ (envelope-from ); Tue, 08 Jun 2021 15:28:59 +0000 Date: Tue, 8 Jun 2021 17:28:58 +0200 From: Jean Delvare To: Linux I2C Cc: Wolfram Sang Subject: [PATCH 1/7] i2cget: Add support for I2C block data Message-ID: <20210608172858.0fbd301f@endymion> In-Reply-To: <20210608172338.0cf520a1@endymion> References: <20210608172338.0cf520a1@endymion> Organization: SUSE Linux X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.32; x86_64-suse-linux-gnu) MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org From: Crestez Dan Leonard This adds mode 'i' for I2C_SMBUS_I2C_BLOCK_DATA. This is the same mode letter from i2cdump. Length is optional and defaults to 32 (maximum). The intended use is debugging i2c devices with shell commands. [JD: Fix the build (wrong variable name) Ensure PEC isn't used in I2C block mode Don't print the lenth (doesn't add value and could be mistaken as an offset Various cleanups] Signed-off-by: Crestez Dan Leonard Signed-off-by: Jean Delvare --- tools/i2cget.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 55 insertions(+), 10 deletions(-) --- i2c-tools.orig/tools/i2cget.c 2021-06-08 16:49:55.025098861 +0200 +++ i2c-tools/tools/i2cget.c 2021-06-08 16:54:15.707669058 +0200 @@ -41,14 +41,16 @@ static void help(void) __attribute__ ((n static void help(void) { fprintf(stderr, - "Usage: i2cget [-f] [-y] [-a] I2CBUS CHIP-ADDRESS [DATA-ADDRESS [MODE]]\n" + "Usage: i2cget [-f] [-y] [-a] I2CBUS CHIP-ADDRESS [DATA-ADDRESS [MODE [LENGTH]]]\n" " I2CBUS is an integer or an I2C bus name\n" " ADDRESS is an integer (0x08 - 0x77, or 0x00 - 0x7f if -a is given)\n" " MODE is one of:\n" " b (read byte data, default)\n" " w (read word data)\n" " c (write byte/read byte)\n" - " Append p for SMBus PEC\n"); + " i (read I2C block data)\n" + " Append p for SMBus PEC\n" + " LENGTH is the I2C block data length\n"); exit(1); } @@ -89,6 +91,13 @@ static int check_funcs(int file, int siz return -1; } break; + + case I2C_SMBUS_I2C_BLOCK_DATA: + if (!(funcs & I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { + fprintf(stderr, MISSING_FUNC_FMT, "SMBus read I2C block data"); + return -1; + } + break; } if (pec @@ -101,7 +110,7 @@ static int check_funcs(int file, int siz } static int confirm(const char *filename, int address, int size, int daddress, - int pec) + int length, int pec) { int dont = 0; @@ -132,11 +141,15 @@ static int confirm(const char *filename, fprintf(stderr, "current data\naddress"); else fprintf(stderr, "data address\n0x%02x", daddress); - fprintf(stderr, ", using %s.\n", - size == I2C_SMBUS_BYTE ? (daddress < 0 ? - "read byte" : "write byte/read byte") : - size == I2C_SMBUS_BYTE_DATA ? "read byte data" : - "read word data"); + if (size == I2C_SMBUS_I2C_BLOCK_DATA) + fprintf(stderr, ", %d %s using read I2C block data.\n", + length, length > 1 ? "bytes" : "byte"); + else + fprintf(stderr, ", using %s.\n", + size == I2C_SMBUS_BYTE ? (daddress < 0 ? + "read byte" : "write byte/read byte") : + size == I2C_SMBUS_BYTE_DATA ? "read byte data" : + "read word data"); if (pec) fprintf(stderr, "PEC checking enabled.\n"); @@ -159,6 +172,8 @@ int main(int argc, char *argv[]) int pec = 0; int flags = 0; int force = 0, yes = 0, version = 0, all_addrs = 0; + int length; + unsigned char block_data[I2C_SMBUS_BLOCK_MAX]; /* handle (optional) flags first */ while (1+flags < argc && argv[1+flags][0] == '-') { @@ -209,11 +224,30 @@ int main(int argc, char *argv[]) case 'b': size = I2C_SMBUS_BYTE_DATA; break; case 'w': size = I2C_SMBUS_WORD_DATA; break; case 'c': size = I2C_SMBUS_BYTE; break; + case 'i': size = I2C_SMBUS_I2C_BLOCK_DATA; break; default: fprintf(stderr, "Error: Invalid mode!\n"); help(); } pec = argv[flags+4][1] == 'p'; + if (size == I2C_SMBUS_I2C_BLOCK_DATA && pec) { + fprintf(stderr, "Error: PEC not supported for I2C block data!\n"); + help(); + } + } + + if (argc > flags + 5) { + if (size != I2C_SMBUS_I2C_BLOCK_DATA) { + fprintf(stderr, "Error: Length only valid for I2C block data!\n"); + help(); + } + length = strtol(argv[flags+5], &end, 0); + if (*end || length < 1 || length > I2C_SMBUS_BLOCK_MAX) { + fprintf(stderr, "Error: Length invalid!\n"); + help(); + } + } else { + length = I2C_SMBUS_BLOCK_MAX; } file = open_i2c_dev(i2cbus, filename, sizeof(filename), 0); @@ -222,7 +256,7 @@ int main(int argc, char *argv[]) || set_slave_addr(file, address, force)) exit(1); - if (!yes && !confirm(filename, address, size, daddress, pec)) + if (!yes && !confirm(filename, address, size, daddress, length, pec)) exit(0); if (pec && ioctl(file, I2C_PEC, 1) < 0) { @@ -244,6 +278,9 @@ int main(int argc, char *argv[]) case I2C_SMBUS_WORD_DATA: res = i2c_smbus_read_word_data(file, daddress); break; + case I2C_SMBUS_I2C_BLOCK_DATA: + res = i2c_smbus_read_i2c_block_data(file, daddress, length, block_data); + break; default: /* I2C_SMBUS_BYTE_DATA */ res = i2c_smbus_read_byte_data(file, daddress); } @@ -254,7 +291,15 @@ int main(int argc, char *argv[]) exit(2); } - printf("0x%0*x\n", size == I2C_SMBUS_WORD_DATA ? 4 : 2, res); + if (size == I2C_SMBUS_I2C_BLOCK_DATA) { + int i; + + for (i = 0; i < res - 1; ++i) + printf("0x%02hhx ", block_data[i]); + printf("0x%02hhx\n", block_data[res - 1]); + } else { + printf("0x%0*x\n", size == I2C_SMBUS_WORD_DATA ? 4 : 2, res); + } exit(0); } From patchwork Tue Jun 8 15:29:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean Delvare X-Patchwork-Id: 457169 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_SANE_2 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79BA7C47082 for ; Tue, 8 Jun 2021 15:29:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5F1B261285 for ; Tue, 8 Jun 2021 15:29:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230460AbhFHPbS (ORCPT ); Tue, 8 Jun 2021 11:31:18 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:51814 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231165AbhFHPbS (ORCPT ); Tue, 8 Jun 2021 11:31:18 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 4FBA5219C4; Tue, 8 Jun 2021 15:29:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623166164; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LpwTCTTu9kkJoBbA4UbgmL2nBFTnlYhg6LgSVv53tYk=; b=wXXXFSfk5WpkNed7yAs0Q+ICBQ5xVZOaFWMflnGRGvxXKo+9mpA3LXwRoynoICDQiAY7q3 8CFlmPCwUwY9PtaBsI+S8o7AvWUSNjb/iX44Qaga5EnjpmEQX3owTHB6z87mNAoEYmLFlc mVp4wTIHWbSwXhBKF1rKOTddm4kaVeA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623166164; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LpwTCTTu9kkJoBbA4UbgmL2nBFTnlYhg6LgSVv53tYk=; b=7At+Ui2N1129bAJFCTtqNLYFLB68k5mpl+RIbrTMiQY9TpjDQWF2RK3Wrjah6RdkKGVk8H 6F3K3thcIfPi25CA== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 1E6A6118DD; Tue, 8 Jun 2021 15:29:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623166164; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LpwTCTTu9kkJoBbA4UbgmL2nBFTnlYhg6LgSVv53tYk=; b=wXXXFSfk5WpkNed7yAs0Q+ICBQ5xVZOaFWMflnGRGvxXKo+9mpA3LXwRoynoICDQiAY7q3 8CFlmPCwUwY9PtaBsI+S8o7AvWUSNjb/iX44Qaga5EnjpmEQX3owTHB6z87mNAoEYmLFlc mVp4wTIHWbSwXhBKF1rKOTddm4kaVeA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623166164; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LpwTCTTu9kkJoBbA4UbgmL2nBFTnlYhg6LgSVv53tYk=; b=7At+Ui2N1129bAJFCTtqNLYFLB68k5mpl+RIbrTMiQY9TpjDQWF2RK3Wrjah6RdkKGVk8H 6F3K3thcIfPi25CA== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id LNaNBdSMv2AlMwAALh3uQQ (envelope-from ); Tue, 08 Jun 2021 15:29:24 +0000 Date: Tue, 8 Jun 2021 17:29:23 +0200 From: Jean Delvare To: Linux I2C Cc: Wolfram Sang Subject: [PATCH 2/7] i2cget: Document the support of I2C block reads Message-ID: <20210608172923.0d3f9296@endymion> In-Reply-To: <20210608172338.0cf520a1@endymion> References: <20210608172338.0cf520a1@endymion> Organization: SUSE Linux X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.32; x86_64-suse-linux-gnu) MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Mention I2C block read support in the i2cget(8) manual page, together with an example. Signed-off-by: Jean Delvare --- tools/i2cget.8 | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) --- i2c-tools.orig/tools/i2cget.8 2021-06-08 16:49:54.910097286 +0200 +++ i2c-tools/tools/i2cget.8 2021-06-08 16:56:26.416459188 +0200 @@ -1,4 +1,4 @@ -.TH I2CGET 8 "October 2017" +.TH I2CGET 8 "June 2021" .SH "NAME" i2cget \- read from I2C/SMBus chip registers @@ -9,7 +9,7 @@ i2cget \- read from I2C/SMBus chip regis .RB [ -a ] .I i2cbus .I chip-address -.RI [ "data-address " [ mode ]] +.RI [ "data-address " [ "mode " [ length ]]] .br .B i2cget .B -V @@ -49,9 +49,11 @@ an integer between 0x00 and 0xFF. If omi will be read (if that makes sense for the considered chip). .PP The \fImode\fR parameter, if specified, is one of the letters \fBb\fP, -\fBw\fP or \fBc\fP, corresponding to a read byte data, a read word data or a -write byte/read byte transaction, respectively. A \fBp\fP can also be appended -to the \fImode\fR parameter to enable PEC. If the \fImode\fR parameter is omitted, +\fBw\fP, \fBc\fP, or \fBi\fP, corresponding to a read byte data, a read +word data, a write byte/read byte, or a read I2C block transaction, +respectively. A \fBp\fP can also be appended to the \fImode\fR parameter to +enable PEC, except for I2C block transactions. If the \fImode\fR +parameter is omitted, i2cget defaults to a read byte data transaction, unless \fIdata-address\fR is also omitted, in which case the default (and only valid) transaction is a single read byte. @@ -112,6 +114,14 @@ concerns raised above still stand, howev equivalent, so this is the only way to read data from a large EEPROM if your master isn't fully I2C capable. With a fully I2C capable master, you would use \fIi2ctransfer\fR to achieve the same in a safe and faster way. +.PP +Read the first 8 bytes of an EEPROM device at 7-bit address 0x50 +on bus 4 (i2c-4): +.nf +.RS +# i2cget -y 4 0x50 0x00 i 8 +.RE +.fi .SH BUGS To report bugs or send fixes, please write to the Linux I2C mailing list From patchwork Tue Jun 8 15:29:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean Delvare X-Patchwork-Id: 456204 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_SANE_2 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF3C7C47082 for ; Tue, 8 Jun 2021 15:30:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D460561285 for ; Tue, 8 Jun 2021 15:30:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231472AbhFHPbz (ORCPT ); Tue, 8 Jun 2021 11:31:55 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:52274 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231175AbhFHPby (ORCPT ); Tue, 8 Jun 2021 11:31:54 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id D40C0219D0; Tue, 8 Jun 2021 15:30:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623166200; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i/afHxPhQV20efhzBDcuW0F0S+e6lx5Qx3SwkNzz57s=; b=cZQjWdQzXOewiPRDU9dutZQNMVkaiTkNb8qnzR6J5U4C9M0VT/Z26TiKfEH7Ph2V2NPAxr pB/DKIPtYU4A/OUGhBeyyUJ8V9ATXhmCwCW24K25jGRRAqA6BgSDiDWwK8jlDwhJLXUeIE kyd4LZMzg22naCIW706F0UveJqY+z5o= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623166200; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i/afHxPhQV20efhzBDcuW0F0S+e6lx5Qx3SwkNzz57s=; b=zYUpy8yjQ/NAlmt6Xme7zxHDO3HA0bbIjzcMpAE8o+FG2RdDepfW9ehqtp32BR2ztAZuHk XhJePqLvvF4X9TBA== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id A00EF118DD; Tue, 8 Jun 2021 15:30:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623166200; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i/afHxPhQV20efhzBDcuW0F0S+e6lx5Qx3SwkNzz57s=; b=cZQjWdQzXOewiPRDU9dutZQNMVkaiTkNb8qnzR6J5U4C9M0VT/Z26TiKfEH7Ph2V2NPAxr pB/DKIPtYU4A/OUGhBeyyUJ8V9ATXhmCwCW24K25jGRRAqA6BgSDiDWwK8jlDwhJLXUeIE kyd4LZMzg22naCIW706F0UveJqY+z5o= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623166200; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i/afHxPhQV20efhzBDcuW0F0S+e6lx5Qx3SwkNzz57s=; b=zYUpy8yjQ/NAlmt6Xme7zxHDO3HA0bbIjzcMpAE8o+FG2RdDepfW9ehqtp32BR2ztAZuHk XhJePqLvvF4X9TBA== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id SgcmJfiMv2CGMwAALh3uQQ (envelope-from ); Tue, 08 Jun 2021 15:30:00 +0000 Date: Tue, 8 Jun 2021 17:29:59 +0200 From: Jean Delvare To: Linux I2C Cc: Wolfram Sang Subject: [PATCH 3/7] i2cget: Add support for SMBus block read Message-ID: <20210608172959.6d773000@endymion> In-Reply-To: <20210608172338.0cf520a1@endymion> References: <20210608172338.0cf520a1@endymion> Organization: SUSE Linux X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.32; x86_64-suse-linux-gnu) MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Now that i2cget supports I2C block read, adding support for SMBus block read is trivial. This restores the symmetry between i2cset and i2cget, and paves the road for the removal of SMBus block read support from i2cdump. Signed-off-by: Jean Delvare --- tools/i2cget.8 | 6 +++--- tools/i2cget.c | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) --- i2c-tools.orig/tools/i2cget.c 2021-06-08 16:47:56.290473081 +0200 +++ i2c-tools/tools/i2cget.c 2021-06-08 16:47:58.553503929 +0200 @@ -1,6 +1,6 @@ /* i2cget.c - A user-space program to read an I2C register. - Copyright (C) 2005-2012 Jean Delvare + Copyright (C) 2005-2021 Jean Delvare Based on i2cset.c: Copyright (C) 2001-2003 Frodo Looijaard , and @@ -48,6 +48,7 @@ static void help(void) " b (read byte data, default)\n" " w (read word data)\n" " c (write byte/read byte)\n" + " s (read SMBus block data)\n" " i (read I2C block data)\n" " Append p for SMBus PEC\n" " LENGTH is the I2C block data length\n"); @@ -92,6 +93,13 @@ static int check_funcs(int file, int siz } break; + case I2C_SMBUS_BLOCK_DATA: + if (!(funcs & I2C_FUNC_SMBUS_READ_BLOCK_DATA)) { + fprintf(stderr, MISSING_FUNC_FMT, "SMBus read block data"); + return -1; + } + break; + case I2C_SMBUS_I2C_BLOCK_DATA: if (!(funcs & I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { fprintf(stderr, MISSING_FUNC_FMT, "SMBus read I2C block data"); @@ -149,6 +157,7 @@ static int confirm(const char *filename, size == I2C_SMBUS_BYTE ? (daddress < 0 ? "read byte" : "write byte/read byte") : size == I2C_SMBUS_BYTE_DATA ? "read byte data" : + size == I2C_SMBUS_BLOCK_DATA ? "read SMBus block data" : "read word data"); if (pec) fprintf(stderr, "PEC checking enabled.\n"); @@ -224,6 +233,7 @@ int main(int argc, char *argv[]) case 'b': size = I2C_SMBUS_BYTE_DATA; break; case 'w': size = I2C_SMBUS_WORD_DATA; break; case 'c': size = I2C_SMBUS_BYTE; break; + case 's': size = I2C_SMBUS_BLOCK_DATA; break; case 'i': size = I2C_SMBUS_I2C_BLOCK_DATA; break; default: fprintf(stderr, "Error: Invalid mode!\n"); @@ -278,6 +288,9 @@ int main(int argc, char *argv[]) case I2C_SMBUS_WORD_DATA: res = i2c_smbus_read_word_data(file, daddress); break; + case I2C_SMBUS_BLOCK_DATA: + res = i2c_smbus_read_block_data(file, daddress, block_data); + break; case I2C_SMBUS_I2C_BLOCK_DATA: res = i2c_smbus_read_i2c_block_data(file, daddress, length, block_data); break; @@ -291,7 +304,8 @@ int main(int argc, char *argv[]) exit(2); } - if (size == I2C_SMBUS_I2C_BLOCK_DATA) { + if (size == I2C_SMBUS_BLOCK_DATA || + size == I2C_SMBUS_I2C_BLOCK_DATA) { int i; for (i = 0; i < res - 1; ++i) --- i2c-tools.orig/tools/i2cget.8 2021-06-08 16:47:58.553503929 +0200 +++ i2c-tools/tools/i2cget.8 2021-06-08 16:48:35.473009351 +0200 @@ -50,9 +50,9 @@ will be read (if that makes sense for th .PP The \fImode\fR parameter, if specified, is one of the letters \fBb\fP, \fBw\fP, \fBc\fP, or \fBi\fP, corresponding to a read byte data, a read -word data, a write byte/read byte, or a read I2C block transaction, -respectively. A \fBp\fP can also be appended to the \fImode\fR parameter to -enable PEC, except for I2C block transactions. If the \fImode\fR +word data, a write byte/read byte, a read SMBus block, or a read I2C block +transaction, respectively. A \fBp\fP can also be appended to the \fImode\fR +parameter to enable PEC, except for I2C block transactions. If the \fImode\fR parameter is omitted, i2cget defaults to a read byte data transaction, unless \fIdata-address\fR is also omitted, in which case the default (and only valid) transaction is a From patchwork Tue Jun 8 15:30:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean Delvare X-Patchwork-Id: 457168 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_SANE_2 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B976C47082 for ; Tue, 8 Jun 2021 15:30:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4E9AC6108E for ; Tue, 8 Jun 2021 15:30:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231253AbhFHPcX (ORCPT ); Tue, 8 Jun 2021 11:32:23 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:41750 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231231AbhFHPcX (ORCPT ); Tue, 8 Jun 2021 11:32:23 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 9B0E21FD33; Tue, 8 Jun 2021 15:30:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623166228; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T/knX/ZSYSUAFmHDG/AaoURfts2vyOMZPDY1Un3fuyI=; b=vcC+qIf9VHwDiWtHhu2V3F3KWx5U5V41Ne39gfpC/mDTTRZE/O58iKm0Rsj663iQrq5ixO vcSv+3BEHJ7YLXl9iyaHNyEx/gcK2zRwvGGXaIIiyn0J1Sn3fGUWQA2cz/Y7I8FA/BPAAf b6Ml+caIrZSh1bX+kvbUvY1L68XzpYY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623166228; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T/knX/ZSYSUAFmHDG/AaoURfts2vyOMZPDY1Un3fuyI=; b=5WBsdbFGv5llM8gl1AYfAf1+ttz1DqpTFtJsNdjVWoDn/7lNE2Jn8BpELy5OItMmETCC8K GWWU5MSpRob+6QDA== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 6A78A118DD; Tue, 8 Jun 2021 15:30:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623166228; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T/knX/ZSYSUAFmHDG/AaoURfts2vyOMZPDY1Un3fuyI=; b=vcC+qIf9VHwDiWtHhu2V3F3KWx5U5V41Ne39gfpC/mDTTRZE/O58iKm0Rsj663iQrq5ixO vcSv+3BEHJ7YLXl9iyaHNyEx/gcK2zRwvGGXaIIiyn0J1Sn3fGUWQA2cz/Y7I8FA/BPAAf b6Ml+caIrZSh1bX+kvbUvY1L68XzpYY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623166228; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T/knX/ZSYSUAFmHDG/AaoURfts2vyOMZPDY1Un3fuyI=; b=5WBsdbFGv5llM8gl1AYfAf1+ttz1DqpTFtJsNdjVWoDn/7lNE2Jn8BpELy5OItMmETCC8K GWWU5MSpRob+6QDA== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id xMUNGBSNv2AHNAAALh3uQQ (envelope-from ); Tue, 08 Jun 2021 15:30:28 +0000 Date: Tue, 8 Jun 2021 17:30:27 +0200 From: Jean Delvare To: Linux I2C Cc: Wolfram Sang Subject: [PATCH 4/7] i2cdump: Remove dead code Message-ID: <20210608173027.163e1eec@endymion> In-Reply-To: <20210608172338.0cf520a1@endymion> References: <20210608172338.0cf520a1@endymion> Organization: SUSE Linux X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.32; x86_64-suse-linux-gnu) MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Considering that we exit immediately if an error happens during a block read, the code filling the remaining bytes with -1 so that they will be displayed as "XX" is effectively dead code, so let's remove it. We might want to revisit the whole logic later, as there's in fact little reason why block read errors would be fatal when all other read errors are not. But I'd rather remove SMBus block support from the tool before attempting to clean up the code. Fixes: 7abc52d7792e ("Return the correct error code on I2C block read failure.") Signed-off-by: Jean Delvare --- tools/i2cdump.c | 3 --- 1 file changed, 3 deletions(-) --- i2c-tools.orig/tools/i2cdump.c 2021-06-08 14:35:45.372892494 +0200 +++ i2c-tools/tools/i2cdump.c 2021-06-08 14:35:52.271986056 +0200 @@ -360,9 +360,6 @@ int main(int argc, char *argv[]) res = 256; for (i = 0; i < res; i++) block[i] = cblock[i]; - if (size != I2C_SMBUS_BLOCK_DATA) - for (i = res; i < 256; i++) - block[i] = -1; } if (size == I2C_SMBUS_BYTE) { From patchwork Tue Jun 8 15:30:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean Delvare X-Patchwork-Id: 456203 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_SANE_2 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09479C47082 for ; Tue, 8 Jun 2021 15:30:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DF52B61285 for ; Tue, 8 Jun 2021 15:30:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231276AbhFHPcv (ORCPT ); Tue, 8 Jun 2021 11:32:51 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:41870 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231231AbhFHPcu (ORCPT ); Tue, 8 Jun 2021 11:32:50 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 1F9D31FD3D; Tue, 8 Jun 2021 15:30:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623166257; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lOjvViznXR+j69RGfr2oV/poiSMmP/Z89fPcILbXoMo=; b=Gt2aegCrskgmoRF723rkqBs+t1UAM4RKw7LdxzYXXmslE0SCm1meLOB6nI1G9NsLA7vd8k jvc1dxcVGl7rZDh50ei2JYqoQDpFcZSAwxIXcyZDgwAXWpI2YnsdmEo7SXlLJbMMTyOaJ+ 9syYAzljCVOQdFdQNpX2Bbr2wEZlkSU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623166257; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lOjvViznXR+j69RGfr2oV/poiSMmP/Z89fPcILbXoMo=; b=HQlT45pzlCBqHA9brPxxT03QMbBvjJ8WO8XR5A42u4NfhfXAgh+CU8wryRW/0Frk5nEyj4 ZzzPYteu2RIEDYAQ== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id EAA80118DD; Tue, 8 Jun 2021 15:30:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623166257; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lOjvViznXR+j69RGfr2oV/poiSMmP/Z89fPcILbXoMo=; b=Gt2aegCrskgmoRF723rkqBs+t1UAM4RKw7LdxzYXXmslE0SCm1meLOB6nI1G9NsLA7vd8k jvc1dxcVGl7rZDh50ei2JYqoQDpFcZSAwxIXcyZDgwAXWpI2YnsdmEo7SXlLJbMMTyOaJ+ 9syYAzljCVOQdFdQNpX2Bbr2wEZlkSU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623166257; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lOjvViznXR+j69RGfr2oV/poiSMmP/Z89fPcILbXoMo=; b=HQlT45pzlCBqHA9brPxxT03QMbBvjJ8WO8XR5A42u4NfhfXAgh+CU8wryRW/0Frk5nEyj4 ZzzPYteu2RIEDYAQ== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id QexnNzCNv2BHNAAALh3uQQ (envelope-from ); Tue, 08 Jun 2021 15:30:56 +0000 Date: Tue, 8 Jun 2021 17:30:56 +0200 From: Jean Delvare To: Linux I2C Cc: Wolfram Sang Subject: [PATCH 5/7] i2cdump: Add range support with mode i (I2C block) Message-ID: <20210608173056.1c35beab@endymion> In-Reply-To: <20210608172338.0cf520a1@endymion> References: <20210608172338.0cf520a1@endymion> Organization: SUSE Linux X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.32; x86_64-suse-linux-gnu) MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Implementing range support for I2C block reads (mode i) isn't particularly difficult so let's just do that. Signed-off-by: Jean Delvare --- tools/i2cdump.8 | 6 +++--- tools/i2cdump.c | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) --- i2c-tools.orig/tools/i2cdump.c 2021-06-08 14:56:02.047402610 +0200 +++ i2c-tools/tools/i2cdump.c 2021-06-08 15:02:52.697979744 +0200 @@ -2,7 +2,7 @@ i2cdump.c - a user-space program to dump I2C registers Copyright (C) 2002-2003 Frodo Looijaard , and Mark D. Studebaker - Copyright (C) 2004-2012 Jean Delvare + Copyright (C) 2004-2021 Jean Delvare This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -251,6 +251,7 @@ int main(int argc, char *argv[]) switch (size) { case I2C_SMBUS_BYTE: case I2C_SMBUS_BYTE_DATA: + case I2C_SMBUS_I2C_BLOCK_DATA: break; case I2C_SMBUS_WORD_DATA: if (!even || (!(first%2) && last%2)) @@ -341,8 +342,9 @@ int main(int argc, char *argv[]) /* Remember returned block length for a nicer display later */ s_length = res; + last = res - 1; } else { - for (res = 0; res < 256; res += i) { + for (res = first; res <= last; res += i) { i = i2c_smbus_read_i2c_block_data(file, res, 32, cblock + res); if (i <= 0) { @@ -356,9 +358,7 @@ int main(int argc, char *argv[]) "return code %d\n", res); exit(1); } - if (res >= 256) - res = 256; - for (i = 0; i < res; i++) + for (i = first; i <= last; i++) block[i] = cblock[i]; } --- i2c-tools.orig/tools/i2cdump.8 2021-06-08 14:56:02.047402610 +0200 +++ i2c-tools/tools/i2cdump.8 2021-06-08 15:02:46.451894913 +0200 @@ -1,4 +1,4 @@ -.TH I2CDUMP 8 "October 2017" +.TH I2CDUMP 8 "June 2021" .SH NAME i2cdump \- examine I2C registers @@ -32,8 +32,8 @@ kernel driver in question. It can also c results. So use at your own risk and only if you know what you're doing. .TP .B -r first-last -Limit the range of registers being accessed. This option is only available -with modes \fBb\fP, \fBw\fP, \fBc\fP and \fBW\fP. For mode \fBW\fP, +Limit the range of registers being accessed. This option is not available +with mode \fBs\fP. For mode \fBW\fP, \fBfirst\fR must be even and \fBlast\fR must be odd. .TP .B -y From patchwork Tue Jun 8 15:31:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean Delvare X-Patchwork-Id: 457167 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_SANE_2 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69AA0C47082 for ; Tue, 8 Jun 2021 15:31:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 44C3E60FE9 for ; Tue, 8 Jun 2021 15:31:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231308AbhFHPd1 (ORCPT ); Tue, 8 Jun 2021 11:33:27 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:42062 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231231AbhFHPd1 (ORCPT ); Tue, 8 Jun 2021 11:33:27 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 661371FD2A; Tue, 8 Jun 2021 15:31:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623166293; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eQrVNM2IXhcChDkb8JLOaOzYBFTDSxXSS4+ytkEClj4=; b=h6wTwWEhwGyFcb5cb0+ceSOxGpsXlnM2UITYQSvfFtwWNmyHUtHMEwqXidYYAsulW4Y3Fv o0iPayXVquBErCMkXaoeM/RKIdoAENKbQB6BucvmjFnhUgg56lIW/2M2QLTtRYqfxbYzNq pID33V8RN9mgUHHZ2Eqa9z66CYUYWvU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623166293; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eQrVNM2IXhcChDkb8JLOaOzYBFTDSxXSS4+ytkEClj4=; b=GIHe5Vmdlrl6Aei8xDLScmkpx01ShlnwNP6CUHksDXqEyJkoNs2+Vf/E3/fUujpVxYPS0d itdAwoJEKiEtuoBA== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 360D1118DD; Tue, 8 Jun 2021 15:31:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623166293; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eQrVNM2IXhcChDkb8JLOaOzYBFTDSxXSS4+ytkEClj4=; b=h6wTwWEhwGyFcb5cb0+ceSOxGpsXlnM2UITYQSvfFtwWNmyHUtHMEwqXidYYAsulW4Y3Fv o0iPayXVquBErCMkXaoeM/RKIdoAENKbQB6BucvmjFnhUgg56lIW/2M2QLTtRYqfxbYzNq pID33V8RN9mgUHHZ2Eqa9z66CYUYWvU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623166293; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eQrVNM2IXhcChDkb8JLOaOzYBFTDSxXSS4+ytkEClj4=; b=GIHe5Vmdlrl6Aei8xDLScmkpx01ShlnwNP6CUHksDXqEyJkoNs2+Vf/E3/fUujpVxYPS0d itdAwoJEKiEtuoBA== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id UbdSC1WNv2CyNAAALh3uQQ (envelope-from ); Tue, 08 Jun 2021 15:31:33 +0000 Date: Tue, 8 Jun 2021 17:31:32 +0200 From: Jean Delvare To: Linux I2C Cc: Wolfram Sang Subject: [PATCH 6/7] i2cdump: Deprecate SMBus block mode Message-ID: <20210608173132.3bdeced2@endymion> In-Reply-To: <20210608172338.0cf520a1@endymion> References: <20210608172338.0cf520a1@endymion> Organization: SUSE Linux X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.32; x86_64-suse-linux-gnu) MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org i2cget is a better fit for this mode. Having it in i2cdump requires special-casing in various places, which makes the code harder to read and maintain. Signed-off-by: Jean Delvare --- tools/i2cdump.8 | 13 ++++--------- tools/i2cdump.c | 4 +++- 2 files changed, 7 insertions(+), 10 deletions(-) --- i2c-tools.orig/tools/i2cdump.8 2021-06-08 17:04:22.538979958 +0200 +++ i2c-tools/tools/i2cdump.8 2021-06-08 17:13:28.996481415 +0200 @@ -106,21 +106,16 @@ bus 1 (i2c-1), using the default read me # i2cdump -r 0x00-0x3f 1 0x2d .RE .fi -.PP -Dump the registers of the SMBus device at address 0x69 on bus 0 (i2c-0), -using one SMBus block read transaction with error checking enabled, after -user confirmation: -.nf -.RS -# i2cdump 0 0x69 sp -.RE -.fi .SH BUGS To report bugs or send fixes, please write to the Linux I2C mailing list with Cc to the current maintainer: Jean Delvare . +SMBus block mode is deprecated and will be removed in a future version +of this tool. +Please use \fIi2cget\fR instead. + .SH SEE ALSO i2cdetect(8), i2cget(8), i2cset(8), i2ctransfer(8), isadump(8) --- i2c-tools.orig/tools/i2cdump.c 2021-06-08 17:04:22.538979958 +0200 +++ i2c-tools/tools/i2cdump.c 2021-06-08 17:13:21.787382423 +0200 @@ -43,7 +43,7 @@ static void help(void) " b (byte, default)\n" " w (word)\n" " W (word on even register addresses)\n" - " s (SMBus block)\n" + " s (SMBus block, deprecated)\n" " i (I2C block)\n" " c (consecutive byte)\n" " Append p for SMBus PEC\n"); @@ -181,6 +181,8 @@ int main(int argc, char *argv[]) even = 1; } else if (!strncmp(argv[flags+3], "s", 1)) { size = I2C_SMBUS_BLOCK_DATA; + fprintf(stderr, + "SMBus Block mode is deprecated, please use i2cget instead\n"); pec = argv[flags+3][1] == 'p'; } else if (!strncmp(argv[flags+3], "c", 1)) { size = I2C_SMBUS_BYTE; From patchwork Tue Jun 8 15:32:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean Delvare X-Patchwork-Id: 456202 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_SANE_2 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D830C47082 for ; Tue, 8 Jun 2021 15:32:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2459861002 for ; Tue, 8 Jun 2021 15:32:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231192AbhFHPeX (ORCPT ); Tue, 8 Jun 2021 11:34:23 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:52646 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231401AbhFHPeW (ORCPT ); Tue, 8 Jun 2021 11:34:22 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 0BE4921997; Tue, 8 Jun 2021 15:32:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623166349; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YDufNYGZuYfdbDyWs/YJsw8RxtOSF/7gyGi+HITIuV0=; b=E0nXkVMxe+nSn+QdmnQIh4MgU4eceNF++AhTO6s7pcg1NJAM/W2WXTar6SHGjKBx3bWi6t wPOM5sA45I90FMCPngobVt1/IvpPYUAoB8wjHyK9GYW+TCWIilM+H+THG/0UM7Rc6zBjJ3 Q1ld+Kc0VWNNs0xdrFqo/koJGPRbEMc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623166349; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YDufNYGZuYfdbDyWs/YJsw8RxtOSF/7gyGi+HITIuV0=; b=MkW+sFrwYF5MbxroYY3lVLHqIJlau+1bDKotR4Kdrl8FfH/Lkvw9huh2AODrbq+OBvgaYo dDMfajgVaLdSn3DA== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id D0CF5118DD; Tue, 8 Jun 2021 15:32:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623166349; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YDufNYGZuYfdbDyWs/YJsw8RxtOSF/7gyGi+HITIuV0=; b=E0nXkVMxe+nSn+QdmnQIh4MgU4eceNF++AhTO6s7pcg1NJAM/W2WXTar6SHGjKBx3bWi6t wPOM5sA45I90FMCPngobVt1/IvpPYUAoB8wjHyK9GYW+TCWIilM+H+THG/0UM7Rc6zBjJ3 Q1ld+Kc0VWNNs0xdrFqo/koJGPRbEMc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623166349; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YDufNYGZuYfdbDyWs/YJsw8RxtOSF/7gyGi+HITIuV0=; b=MkW+sFrwYF5MbxroYY3lVLHqIJlau+1bDKotR4Kdrl8FfH/Lkvw9huh2AODrbq+OBvgaYo dDMfajgVaLdSn3DA== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id O94eMYyNv2AuNQAALh3uQQ (envelope-from ); Tue, 08 Jun 2021 15:32:28 +0000 Date: Tue, 8 Jun 2021 17:32:28 +0200 From: Jean Delvare To: Linux I2C Cc: Wolfram Sang Subject: [PATCH 7/7] i2cdump: Remove support for SMBus block mode Message-ID: <20210608173228.6cd2284c@endymion> In-Reply-To: <20210608172338.0cf520a1@endymion> References: <20210608172338.0cf520a1@endymion> Organization: SUSE Linux X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.32; x86_64-suse-linux-gnu) MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Users can turn to i2cget for this feature. Signed-off-by: Jean Delvare --- tools/i2cdump.8 | 7 ++-- tools/i2cdump.c | 81 +++++++++++--------------------------------------------- 2 files changed, 20 insertions(+), 68 deletions(-) --- i2c-tools.orig/tools/i2cdump.8 2021-06-08 17:13:32.294526703 +0200 +++ i2c-tools/tools/i2cdump.8 2021-06-08 17:13:50.600778075 +0200 @@ -51,8 +51,8 @@ of the busses listed by \fIi2cdetect -l\ address to be scanned on that bus, and is an integer between 0x08 and 0x77. .PP The \fImode\fR parameter, if specified, is one of the letters \fBb\fP, \fBw\fP, -\fBs\fP, or \fBi\fP, corresponding to a read size of a single byte, a 16-bit -word, an SMBus block, an I2C block, respectively. The \fBc\fP mode is a +or \fBi\fP, corresponding to a read size of a single byte, a 16-bit +word, an I2C block, respectively. The \fBc\fP mode is a little different, it reads all bytes consecutively, and is useful for chips that have an address auto-increment feature, such as EEPROMs. The \fBW\fP mode is also special, it is similar to \fBw\fP except that a read command will only @@ -112,8 +112,7 @@ To report bugs or send fixes, please wri with Cc to the current maintainer: Jean Delvare . -SMBus block mode is deprecated and will be removed in a future version -of this tool. +SMBus block mode used to be supported by this tool. Please use \fIi2cget\fR instead. .SH SEE ALSO --- i2c-tools.orig/tools/i2cdump.c 2021-06-08 17:13:21.787382423 +0200 +++ i2c-tools/tools/i2cdump.c 2021-06-08 17:13:33.613544815 +0200 @@ -43,7 +43,6 @@ static void help(void) " b (byte, default)\n" " w (word)\n" " W (word on even register addresses)\n" - " s (SMBus block, deprecated)\n" " i (I2C block)\n" " c (consecutive byte)\n" " Append p for SMBus PEC\n"); @@ -86,13 +85,6 @@ static int check_funcs(int file, int siz } break; - case I2C_SMBUS_BLOCK_DATA: - if (!(funcs & I2C_FUNC_SMBUS_READ_BLOCK_DATA)) { - fprintf(stderr, MISSING_FUNC_FMT, "SMBus block read"); - return -1; - } - break; - case I2C_SMBUS_I2C_BLOCK_DATA: if (!(funcs & I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { fprintf(stderr, MISSING_FUNC_FMT, "I2C block read"); @@ -116,7 +108,7 @@ int main(int argc, char *argv[]) int i, j, res, i2cbus, address, size, file; int bank = 0, bankreg = 0x4E, old_bank = 0; char filename[20]; - int block[256], s_length = 0; + int block[256]; int pec = 0, even = 0; int flags = 0; int force = 0, yes = 0, version = 0, all_addrs = 0; @@ -180,10 +172,9 @@ int main(int argc, char *argv[]) size = I2C_SMBUS_WORD_DATA; even = 1; } else if (!strncmp(argv[flags+3], "s", 1)) { - size = I2C_SMBUS_BLOCK_DATA; fprintf(stderr, - "SMBus Block mode is deprecated, please use i2cget instead\n"); - pec = argv[flags+3][1] == 'p'; + "SMBus Block mode is no longer supported, please use i2cget instead\n"); + exit(1); } else if (!strncmp(argv[flags+3], "c", 1)) { size = I2C_SMBUS_BYTE; pec = argv[flags+3][1] == 'p'; @@ -208,16 +199,10 @@ int main(int argc, char *argv[]) help(); exit(1); } - if (size == I2C_SMBUS_BLOCK_DATA - && (bank < 0 || bank > 0xff)) { - fprintf(stderr, "Error: block command out of range!\n"); - help(); - exit(1); - } if (argc > flags + 5) { bankreg = strtol(argv[flags+5], &end, 0); - if (*end || size == I2C_SMBUS_BLOCK_DATA) { + if (*end) { fprintf(stderr, "Error: Invalid bank register " "number!\n"); help(); @@ -250,16 +235,7 @@ int main(int argc, char *argv[]) } /* Check mode constraints */ - switch (size) { - case I2C_SMBUS_BYTE: - case I2C_SMBUS_BYTE_DATA: - case I2C_SMBUS_I2C_BLOCK_DATA: - break; - case I2C_SMBUS_WORD_DATA: - if (!even || (!(first%2) && last%2)) - break; - /* Fall through */ - default: + if (size == I2C_SMBUS_WORD_DATA && even && (first%2 || !(last%2))) { fprintf(stderr, "Error: Range parameter not compatible with selected mode!\n"); exit(1); @@ -286,7 +262,6 @@ int main(int argc, char *argv[]) fprintf(stderr, "I will probe file %s, address 0x%x, mode " "%s\n", filename, address, - size == I2C_SMBUS_BLOCK_DATA ? "smbus block" : size == I2C_SMBUS_I2C_BLOCK_DATA ? "i2c block" : size == I2C_SMBUS_BYTE ? "byte consecutive read" : size == I2C_SMBUS_BYTE_DATA ? "byte" : "word"); @@ -296,12 +271,8 @@ int main(int argc, char *argv[]) fprintf(stderr, "Only probing even register " "addresses.\n"); if (bank) { - if (size == I2C_SMBUS_BLOCK_DATA) - fprintf(stderr, "Using command 0x%02x.\n", - bank); - else - fprintf(stderr, "Probing bank %d using bank " - "register 0x%02x.\n", bank, bankreg); + fprintf(stderr, "Probing bank %d using bank " + "register 0x%02x.\n", bank, bankreg); } if (range) { fprintf(stderr, @@ -318,7 +289,7 @@ int main(int argc, char *argv[]) } /* See Winbond w83781d data sheet for bank details */ - if (bank && size != I2C_SMBUS_BLOCK_DATA) { + if (bank) { res = i2c_smbus_read_byte_data(file, bankreg); if (res >= 0) { old_bank = res; @@ -334,25 +305,15 @@ int main(int argc, char *argv[]) /* handle all but word data */ if (size != I2C_SMBUS_WORD_DATA || even) { /* do the block transaction */ - if (size == I2C_SMBUS_BLOCK_DATA - || size == I2C_SMBUS_I2C_BLOCK_DATA) { + if (size == I2C_SMBUS_I2C_BLOCK_DATA) { unsigned char cblock[288]; - if (size == I2C_SMBUS_BLOCK_DATA) { - res = i2c_smbus_read_block_data(file, bank, - cblock); - /* Remember returned block length for a nicer - display later */ - s_length = res; - last = res - 1; - } else { - for (res = first; res <= last; res += i) { - i = i2c_smbus_read_i2c_block_data(file, - res, 32, cblock + res); - if (i <= 0) { - res = i; - break; - } + for (res = first; res <= last; res += i) { + i = i2c_smbus_read_i2c_block_data(file, + res, 32, cblock + res); + if (i <= 0) { + res = i; + break; } } if (res <= 0) { @@ -376,8 +337,6 @@ int main(int argc, char *argv[]) printf(" 0 1 2 3 4 5 6 7 8 9 a b c d e f" " 0123456789abcdef\n"); for (i = 0; i < 256; i+=16) { - if (size == I2C_SMBUS_BLOCK_DATA && i >= s_length) - break; if (i/16 < first/16) continue; if (i/16 > last/16) @@ -415,10 +374,7 @@ int main(int argc, char *argv[]) } else res = block[i+j]; - if (size == I2C_SMBUS_BLOCK_DATA - && i+j >= s_length) { - printf(" "); - } else if (res < 0) { + if (res < 0) { printf("XX "); if (size == I2C_SMBUS_WORD_DATA) printf("XX "); @@ -433,9 +389,6 @@ int main(int argc, char *argv[]) printf(" "); for (j = 0; j < 16; j++) { - if (size == I2C_SMBUS_BLOCK_DATA - && i+j >= s_length) - break; /* Skip unwanted registers */ if (i+j < first || i+j > last) { printf(" "); @@ -483,7 +436,7 @@ int main(int argc, char *argv[]) printf("\n"); } } - if (bank && size != I2C_SMBUS_BLOCK_DATA) { + if (bank) { i2c_smbus_write_byte_data(file, bankreg, old_bank); } exit(0);