From patchwork Sun Aug 11 21:23:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 819253 Received: from mail.zeus03.de (zeus03.de [194.117.254.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C457D15FCE7 for ; Sun, 11 Aug 2024 21:23:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=194.117.254.33 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723411410; cv=none; b=bRNWZ31fIOGtl46Sn8mlbCpbq5wUB3e8ERz2abF4Dm9PuTF4S6xzVctWNoLU6ZjsxfOG4/BZpTUyFuNsybLUzScdtWudh2bvoC7+myhqBDKDMp5bqbRd/BBGm8H/g34SoD2KbVS/RV+ZEi8Ktv35SqZ5Tabh/3O3ljO1ANulyUc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723411410; c=relaxed/simple; bh=jIOuqhgEBh6VGxaQQdjTBnedyoXCh3aKOlKNnhGoZr4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=besXPeYv6WXGZPomVCIBBh0D3//ADCjvOWsbLJAOdhBI6TIdP8cb0HPgVcxSU3lWGMWIs+naByHtiWbbuCq0Qk8akfJyYXy6F4Hh8KZdCAnuvfVgS3X8feJIBq3iBjYj1bROGXnVw5fPTm+ZzOemNjdKKx6/sR2eWuqpK6qTYMc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com; spf=pass smtp.mailfrom=sang-engineering.com; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b=lg+nJqlt; arc=none smtp.client-ip=194.117.254.33 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b="lg+nJqlt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= sang-engineering.com; h=from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; s=k1; bh=pgj087NucnHKxua0poSb91px8mDb2gODWDuPOmjAJHI=; b=lg+nJq lt3LtiWRh1PtN2E5thmV0e7pwGHE2Y6EjFJUW6FTgfqqhj8+x+4Xht2DFa3c79hy fsX0A/Qh5HU5OM6ngMN4Zkc7ZN9v4l/4Ck1mjhCLcSL4VbTNlMq2m7aDtb0K4YHS Ot8sq7NQiiyyK1MCOE1tQiFHosQHT1//Us8Oy2gJVjARq01b02fqwTH9CCY/SEN6 h/TGFwX2oULXJJ+yNIf4K7JVhb4JSMlQQE1oZGGrvVex71i6uxO2U5MImE/2YSsB JNCFXe4fM6Wlmp4I/OEbiMzfvdvdIHRJYfV6tuq8+kpwcMDwTD4KMbu9pvyhBa/G 546PNG1R8XM3Jmdw== Received: (qmail 1179550 invoked from network); 11 Aug 2024 23:23:23 +0200 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 11 Aug 2024 23:23:23 +0200 X-UD-Smtp-Session: l3s3148p1@iJ96/G4fFpUujnvj From: Wolfram Sang To: linux-i2c@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, Wolfram Sang Subject: [PATCH v2 1/4] i2c: testunit: sort case blocks Date: Sun, 11 Aug 2024 23:23:13 +0200 Message-ID: <20240811212317.16119-2-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240811212317.16119-1-wsa+renesas@sang-engineering.com> References: <20240811212317.16119-1-wsa+renesas@sang-engineering.com> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Because a 'fallthrough' was refactored away, the order of 'case' statements can be sorted better now to ease understanding the flow of events. Signed-off-by: Wolfram Sang --- drivers/i2c/i2c-slave-testunit.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/i2c/i2c-slave-testunit.c b/drivers/i2c/i2c-slave-testunit.c index 4c550306f3ec..be1d2e900aef 100644 --- a/drivers/i2c/i2c-slave-testunit.c +++ b/drivers/i2c/i2c-slave-testunit.c @@ -94,6 +94,14 @@ static int i2c_slave_testunit_slave_cb(struct i2c_client *client, int ret = 0; switch (event) { + case I2C_SLAVE_WRITE_REQUESTED: + if (test_bit(TU_FLAG_IN_PROCESS, &tu->flags)) + return -EBUSY; + + memset(tu->regs, 0, TU_NUM_REGS); + tu->reg_idx = 0; + break; + case I2C_SLAVE_WRITE_RECEIVED: if (test_bit(TU_FLAG_IN_PROCESS, &tu->flags)) return -EBUSY; @@ -127,14 +135,6 @@ static int i2c_slave_testunit_slave_cb(struct i2c_client *client, tu->reg_idx = 0; break; - case I2C_SLAVE_WRITE_REQUESTED: - if (test_bit(TU_FLAG_IN_PROCESS, &tu->flags)) - return -EBUSY; - - memset(tu->regs, 0, TU_NUM_REGS); - tu->reg_idx = 0; - break; - case I2C_SLAVE_READ_PROCESSED: if (is_proc_call && tu->regs[TU_REG_DATAH]) tu->regs[TU_REG_DATAH]--; From patchwork Sun Aug 11 21:23:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 818469 Received: from mail.zeus03.de (zeus03.de [194.117.254.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C460B15FD08 for ; Sun, 11 Aug 2024 21:23:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=194.117.254.33 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723411410; cv=none; b=jQTz2wpr1pYvrTfj1L0Qi1AkrCRS0gq4hW8cfgWl3AvB8sJqwuFQO/VCqr28SOzYznopFgBGKMnQyqDA3PxJG2vXlQJ/6v1mLhzita/6D2OFeJp+BX6x3+1/HAe3mnYAkQ6+6R0zrspbg21nYr8JyUAvoUoCrXlwB27wjX98CCo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723411410; c=relaxed/simple; bh=s+QtlQkN1TBv2DlSLGxKM756HLmt+3SjAIOsYE9q1n0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZlXKEbKGJ+JgUbIqnaeaGc9mMJHYmAkwlU4DL1RtW1J7ceT3sPPzvcLd1aP+koLqKpEOJmhlNRdolRm326JVMUywj/DtE+2WHgXDlPLMDVtmY+xLgfTBPqcc3mslrII8gwTdutE8hLgbxvf6zTCKit3hn9owc8Zq8135GE+pc20= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com; spf=pass smtp.mailfrom=sang-engineering.com; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b=SfHl/wwU; arc=none smtp.client-ip=194.117.254.33 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b="SfHl/wwU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= sang-engineering.com; h=from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; s=k1; bh=d/PFylhViZ8m5LgSnK1jY9LTCD9Ckx8s1nhCAApPX40=; b=SfHl/w wU8XrD0UUBwRijyu4ziJiRMkKnO+aa20xP3cQ36FUQMIXDjt9dhj4TEKcSE/bxqs mdH/zAj8YrIXEo9rpCN7rzqhWgwA3+1aSIhg6o34+3P6A7EN0sP5FXIJiA51YI4p hgFgP5q8npdJbhxVnEQaYfXouLX7Lz9g2dtdOLGDYKIrB85yIYAWZCUeFcsJHXKm Bkj/i2R5wbTNUfcYTIdYtslH9fXoLPBqjTRyT8KkCzpnENSQijm8ghlVA9BhwQ9+ ujzpgrhl9A5X1oTJVbJZjBPLvb+QO51xTLmeNMetMjm0i1OcYUnnLjTY1xtncJ+a M7pFphOBAUjIHwhQ== Received: (qmail 1179573 invoked from network); 11 Aug 2024 23:23:24 +0200 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 11 Aug 2024 23:23:24 +0200 X-UD-Smtp-Session: l3s3148p1@/H6F/G4fHpUujnvj From: Wolfram Sang To: linux-i2c@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, Wolfram Sang Subject: [PATCH v2 2/4] i2c: testunit: use decimal values in docs when appropriate Date: Sun, 11 Aug 2024 23:23:14 +0200 Message-ID: <20240811212317.16119-3-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240811212317.16119-1-wsa+renesas@sang-engineering.com> References: <20240811212317.16119-1-wsa+renesas@sang-engineering.com> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Sometimes decimal values are just shorter (like for cmds), sometimes they are even easier to understand (like for the delay value). Make use of them. Signed-off-by: Wolfram Sang --- Documentation/i2c/slave-testunit-backend.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Documentation/i2c/slave-testunit-backend.rst b/Documentation/i2c/slave-testunit-backend.rst index 37142a48ab35..ee019db53938 100644 --- a/Documentation/i2c/slave-testunit-backend.rst +++ b/Documentation/i2c/slave-testunit-backend.rst @@ -75,7 +75,7 @@ from another device on the bus. If the bus master under test also wants to access the bus at the same time, the bus will be busy. Example to read 128 bytes from device 0x50 after 50ms of delay:: - # i2cset -y 0 0x30 0x01 0x50 0x80 0x05 i + # i2cset -y 0 0x30 1 0x50 0x80 5 i 0x02 SMBUS_HOST_NOTIFY ~~~~~~~~~~~~~~~~~~~~~~ @@ -95,9 +95,9 @@ bytes from device 0x50 after 50ms of delay:: Also needs master mode. This test will send an SMBUS_HOST_NOTIFY message to the host. Note that the status word is currently ignored in the Linux Kernel. -Example to send a notification after 10ms:: +Example to send a notification with status word 0x6442 after 10ms:: - # i2cset -y 0 0x30 0x02 0x42 0x64 0x01 i + # i2cset -y 0 0x30 2 0x42 0x64 1 i If the host controller supports HostNotify, this message with debug level should appear (Linux 6.11 and later):: @@ -116,7 +116,7 @@ should appear (Linux 6.11 and later):: - DELAY * - 0x03 - - must be '1', i.e. one further byte will be written + - 0x01 (i.e. one further byte will be written) - number of bytes to be sent back - leave out, partial command! @@ -131,5 +131,5 @@ from length-1 to 0. Here is an example which emulates i2c_smbus_block_process_call() using i2ctransfer (you need i2c-tools v4.2 or later):: - # i2ctransfer -y 0 w3@0x30 0x03 0x01 0x10 r? + # i2ctransfer -y 0 w3@0x30 3 1 0x10 r? 0x10 0x0f 0x0e 0x0d 0x0c 0x0b 0x0a 0x09 0x08 0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00 From patchwork Sun Aug 11 21:23:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 819254 Received: from mail.zeus03.de (zeus03.de [194.117.254.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 111D715FA92 for ; Sun, 11 Aug 2024 21:23:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=194.117.254.33 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723411410; cv=none; b=DRFVjc45sLEOPJzwewrHQKUaB0qewimbPKosHRpRNyTFTpAsTQpiVAKVyz6njaJijy8NdsKRmyGvZV36wk6rZ22p6JXFUzvaxanuimeLxD13+pljXuSV7J1vDZQzNM3rQqk+fy0ivnv7bX2sIte/uxLisyuYF0jUE4e61qUcRrU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723411410; c=relaxed/simple; bh=LpyQu7kNGcosv+6pao3qxDmABsJkeItav8cMv2qgRoQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rtavFBlC0rL4rrI9eBiAge7/p2d4YS/cf2N9HedcNdrd+JewyAvKMxHJTab6ozcydlvGoBUqsGYufZp5bpakoF34jyu61td8BkxyLURYI8Sv2jAvHKh3wAmGEf7RTe2u9CYyQx8REwi7F57q/dzXB4jKl0xNE4vkGwE9WJHm1v8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com; spf=pass smtp.mailfrom=sang-engineering.com; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b=UIV5N0Lj; arc=none smtp.client-ip=194.117.254.33 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b="UIV5N0Lj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= sang-engineering.com; h=from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; s=k1; bh=+Rvp2y7LDaaKxTe7cqdNuxNFEJbw2sWby+vY5kW/9n0=; b=UIV5N0 Ljs0JwJDAzlYC9Eo6l2rsKufi2A3osARqYYiutnYuqS5hhRd2ikPodwstY7fIynd Ow8PK4TnDAqU38cP1/+yeha60xWLPWGJO4C99hUCIW08IKl/ktmpSxWhSQC2aH/1 bW2Ng7i88fAZXZgNwOjL9UE6qBH5WWka9CQN1NQPLoAjybOkINN/jdOkJt7wAOv9 30gL0ic2OVO0LPDOzjnqURb2zD6lwWuiG9BTU2uSBV4OBNRK9kV+Ja/sygyiIp5q iYdTAOuUUchd42qUpiztE0b00pNOFK6pFYWyweNPH5rfSIZbQW2a+vRRD/uikHRA 89biWmSTZ69+B0uw== Received: (qmail 1179595 invoked from network); 11 Aug 2024 23:23:25 +0200 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 11 Aug 2024 23:23:25 +0200 X-UD-Smtp-Session: l3s3148p1@Fm+X/G4fJpUujnvj From: Wolfram Sang To: linux-i2c@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, Wolfram Sang Subject: [PATCH v2 3/4] i2c: testunit: add command to support versioning and test rep_start Date: Sun, 11 Aug 2024 23:23:15 +0200 Message-ID: <20240811212317.16119-4-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240811212317.16119-1-wsa+renesas@sang-engineering.com> References: <20240811212317.16119-1-wsa+renesas@sang-engineering.com> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 For some devices, it is essential that controllers handle repeated start correctly and do not replace it with a stop/start combination. This addition helps to test that because it will only return a version string if repeated start is done properly. Signed-off-by: Wolfram Sang --- Documentation/i2c/slave-testunit-backend.rst | 38 ++++++++++++++++++++ drivers/i2c/i2c-slave-testunit.c | 25 +++++++++++-- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/Documentation/i2c/slave-testunit-backend.rst b/Documentation/i2c/slave-testunit-backend.rst index ee019db53938..110c0055064f 100644 --- a/Documentation/i2c/slave-testunit-backend.rst +++ b/Documentation/i2c/slave-testunit-backend.rst @@ -133,3 +133,41 @@ later):: # i2ctransfer -y 0 w3@0x30 3 1 0x10 r? 0x10 0x0f 0x0e 0x0d 0x0c 0x0b 0x0a 0x09 0x08 0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00 + +0x04 GET_VERSION_WITH_REP_START +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. list-table:: + :header-rows: 1 + + * - CMD + - DATAL + - DATAH + - DELAY + + * - 0x04 + - currently unused + - currently unused + - leave out, partial command! + +Partial command. After sending this command, the testunit will reply to a read +message with a NUL terminated version string based on UTS_RELEASE. The first +character is always a 'v' and the length of the version string is at maximum +128 bytes. However, it will only respond if the read message is connected to +the write message via repeated start. If your controller driver handles +repeated start correctly, this will work:: + + # i2ctransfer -y 0 w3@0x30 4 0 0 r128 + 0x76 0x36 0x2e 0x31 0x31 0x2e 0x30 0x2d 0x72 0x63 0x31 0x2d 0x30 0x30 0x30 0x30 ... + +If you have i2c-tools 4.4 or later, you can print out the data right away:: + + # i2ctransfer -y -b 0 w3@0x30 4 0 0 r128 + v6.11.0-rc1-00009-gd37a1b4d3fd0 + +STOP/START combinations between the two messages will *not* work because they +are not equivalent to a REPEATED START. As an example, this returns just the +default response:: + + # i2cset -y 0 0x30 4 0 0 i; i2cget -y 0 0x30 + 0x01 diff --git a/drivers/i2c/i2c-slave-testunit.c b/drivers/i2c/i2c-slave-testunit.c index be1d2e900aef..51b399aa09a0 100644 --- a/drivers/i2c/i2c-slave-testunit.c +++ b/drivers/i2c/i2c-slave-testunit.c @@ -6,6 +6,7 @@ * Copyright (C) 2020 by Renesas Electronics Corporation */ +#include #include #include #include @@ -15,11 +16,13 @@ #include /* FIXME: is system_long_wq the best choice? */ #define TU_CUR_VERSION 0x01 +#define TU_VERSION_MAX_LENGTH 128 enum testunit_cmds { TU_CMD_READ_BYTES = 1, /* save 0 for ABORT, RESET or similar */ TU_CMD_SMBUS_HOST_NOTIFY, TU_CMD_SMBUS_BLOCK_PROC_CALL, + TU_CMD_GET_VERSION_WITH_REP_START, TU_NUM_CMDS }; @@ -39,10 +42,13 @@ struct testunit_data { unsigned long flags; u8 regs[TU_NUM_REGS]; u8 reg_idx; + u8 read_idx; struct i2c_client *client; struct delayed_work worker; }; +static char tu_version_info[] = "v" UTS_RELEASE "\n\0"; + static void i2c_slave_testunit_work(struct work_struct *work) { struct testunit_data *tu = container_of(work, struct testunit_data, worker.work); @@ -91,6 +97,8 @@ static int i2c_slave_testunit_slave_cb(struct i2c_client *client, struct testunit_data *tu = i2c_get_clientdata(client); bool is_proc_call = tu->reg_idx == 3 && tu->regs[TU_REG_DATAL] == 1 && tu->regs[TU_REG_CMD] == TU_CMD_SMBUS_BLOCK_PROC_CALL; + bool is_get_version = tu->reg_idx == 3 && + tu->regs[TU_REG_CMD] == TU_CMD_GET_VERSION_WITH_REP_START; int ret = 0; switch (event) { @@ -100,6 +108,7 @@ static int i2c_slave_testunit_slave_cb(struct i2c_client *client, memset(tu->regs, 0, TU_NUM_REGS); tu->reg_idx = 0; + tu->read_idx = 0; break; case I2C_SLAVE_WRITE_RECEIVED: @@ -136,12 +145,21 @@ static int i2c_slave_testunit_slave_cb(struct i2c_client *client, break; case I2C_SLAVE_READ_PROCESSED: - if (is_proc_call && tu->regs[TU_REG_DATAH]) + /* Advance until we reach the NUL character */ + if (is_get_version && tu_version_info[tu->read_idx] != 0) + tu->read_idx++; + else if (is_proc_call && tu->regs[TU_REG_DATAH]) tu->regs[TU_REG_DATAH]--; + fallthrough; case I2C_SLAVE_READ_REQUESTED: - *val = is_proc_call ? tu->regs[TU_REG_DATAH] : TU_CUR_VERSION; + if (is_get_version) + *val = tu_version_info[tu->read_idx]; + else if (is_proc_call) + *val = tu->regs[TU_REG_DATAH]; + else + *val = TU_CUR_VERSION; break; } @@ -160,6 +178,9 @@ static int i2c_slave_testunit_probe(struct i2c_client *client) i2c_set_clientdata(client, tu); INIT_DELAYED_WORK(&tu->worker, i2c_slave_testunit_work); + if (sizeof(tu_version_info) > TU_VERSION_MAX_LENGTH) + tu_version_info[TU_VERSION_MAX_LENGTH - 1] = 0; + return i2c_slave_register(client, i2c_slave_testunit_slave_cb); }; From patchwork Sun Aug 11 21:23:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 818471 Received: from mail.zeus03.de (zeus03.de [194.117.254.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E11A714F109 for ; Sun, 11 Aug 2024 21:23:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=194.117.254.33 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723411410; cv=none; b=ddob+Zk+iotc5O8UqmYZgXdqSifDhFKhV3g1jTRYIahymqN7HGt2VkB/NBa2EhqwYhOS9wLSAwzxO89OlsBQ9VpscZ1if6FpmjEMTQusVVhmVN6Lv8fnB2dW+/D2rD2gXDhnyl1p8lq+hfg172iqGYdeKZcAmruYe9jMoUshyZU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723411410; c=relaxed/simple; bh=TYJRFJT33kUuYRs97MBX+Rxz6oZ/tM9PrPrQzDsL8pE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dGy4S8JktIaXLkRjxdozDYLC27FJ9TfSQSzrM/KLqd2kfQR5IhlU6XqV55zcQ9a9Yukwa5JZ3r1xDpo+FzY709BDD2d+yqvVNH4hXHnWMA7nKj+PgmExRLWMpYbrum+XBlBDM2NaOeTxYddYi0rW938PN6v1sXw9sOSa/5ZHImo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com; spf=pass smtp.mailfrom=sang-engineering.com; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b=jxpCMgiJ; arc=none smtp.client-ip=194.117.254.33 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b="jxpCMgiJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= sang-engineering.com; h=from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; s=k1; bh=TpO1S+bnppNBX7TtCqfy6jWW3YMy11GS8DrfzbIuaNw=; b=jxpCMg iJNbdFJzcTGN99t6fV1BqkWAFx0TneYFI3wJADc9Y41P1Lyyjpn1QRgVIfbx0kAv JmOIhzdzefh9yqiEt6N7/YVlEIKMIGOgUOa7ts/WxtCy3Z9OWqqEYCaIRP5G5Uhk iCPjPqR/mX3XKNKDytTCogwxtrqgy8JISw5j3Y8a9PW9wA73LTPeyMmiVAKt0q23 JNoIKJoN7Q67Ezfz14Md0dNuhjSSSV38x73n+hDP7Z5u05obEm3ZJTC9Ec3D5V1P HCHcll96ZIgqlshYyqeS6mefb3rvLtNUSgvbgmy3LI3aAtpqjYNUNBwDfQJjCRaF 33PvwcuPDRXuHNIw== Received: (qmail 1179615 invoked from network); 11 Aug 2024 23:23:26 +0200 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 11 Aug 2024 23:23:26 +0200 X-UD-Smtp-Session: l3s3148p1@gMGk/G4fLpUujnvj From: Wolfram Sang To: linux-i2c@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, Wolfram Sang Subject: [PATCH v2 4/4] i2c: testunit: return current command on read messages Date: Sun, 11 Aug 2024 23:23:16 +0200 Message-ID: <20240811212317.16119-5-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240811212317.16119-1-wsa+renesas@sang-engineering.com> References: <20240811212317.16119-1-wsa+renesas@sang-engineering.com> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Because the testunit can start tests in the future via the DELAY register, it may happen that a command is still pending. Support detecting that by returning the number of a command in progress (if there is one). Signed-off-by: Wolfram Sang --- Documentation/i2c/slave-testunit-backend.rst | 14 ++++++++------ drivers/i2c/i2c-slave-testunit.c | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Documentation/i2c/slave-testunit-backend.rst b/Documentation/i2c/slave-testunit-backend.rst index 110c0055064f..d3ab5944877d 100644 --- a/Documentation/i2c/slave-testunit-backend.rst +++ b/Documentation/i2c/slave-testunit-backend.rst @@ -20,11 +20,13 @@ Instantiating the device is regular. Example for bus 0, address 0x30:: # echo "slave-testunit 0x1030" > /sys/bus/i2c/devices/i2c-0/new_device -After that, you will have a write-only device listening. Reads will just return -an 8-bit version number of the testunit. When writing, the device consists of 4 -8-bit registers and, except for some "partial" commands, all registers must be -written to start a testcase, i.e. you usually write 4 bytes to the device. The -registers are: +After that, you will have the device listening. Reading will return a single +byte. Its value is 0 if the testunit is idle, otherwise the command number of +the currently running command. + +When writing, the device consists of 4 8-bit registers and, except for some +"partial" commands, all registers must be written to start a testcase, i.e. you +usually write 4 bytes to the device. The registers are: .. csv-table:: :header: "Offset", "Name", "Description" @@ -170,4 +172,4 @@ are not equivalent to a REPEATED START. As an example, this returns just the default response:: # i2cset -y 0 0x30 4 0 0 i; i2cget -y 0 0x30 - 0x01 + 0x00 diff --git a/drivers/i2c/i2c-slave-testunit.c b/drivers/i2c/i2c-slave-testunit.c index 51b399aa09a0..04060bc8a9d0 100644 --- a/drivers/i2c/i2c-slave-testunit.c +++ b/drivers/i2c/i2c-slave-testunit.c @@ -15,7 +15,6 @@ #include #include /* FIXME: is system_long_wq the best choice? */ -#define TU_CUR_VERSION 0x01 #define TU_VERSION_MAX_LENGTH 128 enum testunit_cmds { @@ -159,7 +158,8 @@ static int i2c_slave_testunit_slave_cb(struct i2c_client *client, else if (is_proc_call) *val = tu->regs[TU_REG_DATAH]; else - *val = TU_CUR_VERSION; + *val = test_bit(TU_FLAG_IN_PROCESS, &tu->flags) ? + tu->regs[TU_REG_CMD] : 0; break; }