Received: by 2002:ab2:6f44:0:b0:1fd:c486:4f03 with SMTP id l4csp126132lqq; Wed, 12 Jun 2024 19:54:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX8KPWaDBvoymejwuFpMJ5uI+pBAMRFBhJeIy3c7naSWYtMpL8vm3CUGyELId4E+uMiZD65YiPM5esSHuXTgOMs1gG7efyqvtglCzVJ0w== X-Google-Smtp-Source: AGHT+IHUDwXQKm6N+zOHSLeZJtBK580eY8QfvulquyrrunUlYsyyX0iJb2cMeMGGqorafeP5se7u X-Received: by 2002:a05:6902:2185:b0:dfd:b4c1:fa0c with SMTP id 3f1490d57ef6-dfe66a6a7ddmr4057322276.28.1718247284183; Wed, 12 Jun 2024 19:54:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718247284; cv=pass; d=google.com; s=arc-20160816; b=bFGxWS9GqIHsMOSP4vSyN23yhx/HybWrXK9HLov0/Q4DLwE1kCzenwaScGRXOScwxB WpG3wBEWxotPPA3XS/qaO2XO/zcHaLSlTUORtspCvmGF3ujJMNhqJ0D4+E/JUCGZsGVy NkxnAOkd0viusvZTY6/eSzdgC4G6z2VxOHTF5a6sf695FWjUPGZP4bupqs+XzCljhoVV H6FpIikU5qNsI0U5qXpYSrxmh4HOYS61bMR+rtgeNItdwCU71xBRWQVdE3eEl9fSz9Jr 6doiBojbWEHxiu+9Eg52BEmaOEvPLh6o6ekW27r+ExPW7FEjBEvYkJQQ4y+91Cuk3GJS WyeA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=KQSpoL/gBZiTOqoKkh+T2V82Nqs0vKqOwXVJZ858dR0=; fh=JfWGSbslHwFhhiMJpYnc6jL18LJ3m+AjklzLyAtim6A=; b=z9F79lvR46Vrd3APxV5lGe0WkO+0PNJfdXiuPRTg9xMevoTvFWNUc4/S/6BnI585Xi DFJiBP9YrpgqChf+OFab/i3efMPfdC9FarELf4vf2vA0JXuQR831hQr+mGZLSzOtCB0n VM1TzSbLRER/FrmFDrE7oNRPVtNyNjNtJsP2W14cCfFNDk/MGx+GhVsCMDHjE40glcCn 4NOAoeoZHJ7rjbXXxkmbBFm4zg8GBPQQ1Lr8Sk6nObctS5v3vzI0IVjidy0fX3+gPE9G c7z3EOZAwuR9feQn68etrTSPiJjoNHUsapH2INXZB5EFgyn1kzUcUdtj/9Sn3eAQKoqT Lueg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@alliedtelesis.co.nz header.s=mail181024 header.b=JHwAPIsB; arc=pass (i=1 spf=pass spfdomain=alliedtelesis.co.nz dkim=pass dkdomain=alliedtelesis.co.nz dmarc=pass fromdomain=alliedtelesis.co.nz); spf=pass (google.com: domain of linux-kernel+bounces-212504-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212504-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=REJECT dis=NONE) header.from=alliedtelesis.co.nz Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6fee453c424si365343a12.571.2024.06.12.19.54.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 19:54:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-212504-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@alliedtelesis.co.nz header.s=mail181024 header.b=JHwAPIsB; arc=pass (i=1 spf=pass spfdomain=alliedtelesis.co.nz dkim=pass dkdomain=alliedtelesis.co.nz dmarc=pass fromdomain=alliedtelesis.co.nz); spf=pass (google.com: domain of linux-kernel+bounces-212504-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212504-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=REJECT dis=NONE) header.from=alliedtelesis.co.nz Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 2FC3628327A for ; Thu, 13 Jun 2024 02:54:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 561D612DD9D; Thu, 13 Jun 2024 02:54:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=alliedtelesis.co.nz header.i=@alliedtelesis.co.nz header.b="JHwAPIsB" Received: from gate2.alliedtelesis.co.nz (gate2.alliedtelesis.co.nz [202.36.163.20]) (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 2918F33062 for ; Thu, 13 Jun 2024 02:54:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.36.163.20 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718247260; cv=none; b=lsRizY1vrOe/Cy81eOvHZZBD7ukU0xGhmY2DNXhiDEZ+UorikPmttoTs/rFKLw0lUZY8OI8/Sthg9uNP2ihCh0Gt2HQnJGsvfByVctJflpkyEoJeEgjCzLmpqSfKZLNEDi5yEqrQ+W1F5J6DRcr/cQFTq6B86Rz+pI1LDaKXvG8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718247260; c=relaxed/simple; bh=hh1dptDgafzw7sDQeq3QkOAuKG4MFZcQiKoWQYOWYqk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QiAUo4E+pvmitsnfhKnndI8zTiJgiFKJJ58LHN1gzDSu+3trOv9psyMP54hf+a03Nb/iZxsHVRkq6Al5dq2aBD2P5/3E706RoPLXJxEMoLgqzFDc62pflqf6j9afT0hFnvy0mgDNKsnuP66jI6XIbV9DKcT6pmSHpfrS/olFhok= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=alliedtelesis.co.nz; spf=pass smtp.mailfrom=alliedtelesis.co.nz; dkim=pass (2048-bit key) header.d=alliedtelesis.co.nz header.i=@alliedtelesis.co.nz header.b=JHwAPIsB; arc=none smtp.client-ip=202.36.163.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=alliedtelesis.co.nz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=alliedtelesis.co.nz Received: from svr-chch-seg1.atlnz.lc (mmarshal3.atlnz.lc [10.32.18.43]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by gate2.alliedtelesis.co.nz (Postfix) with ESMTPS id 5929A2C04C9; Thu, 13 Jun 2024 14:54:15 +1200 (NZST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail181024; t=1718247255; bh=KQSpoL/gBZiTOqoKkh+T2V82Nqs0vKqOwXVJZ858dR0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JHwAPIsBEYrNxes4zbjOWym0Exh3H+ZjWXVIb8dcvHAAnN6HA0uws5mL3dn7gUerh nudGftVf6UPawqc+/Lul94mHJUdP++X5L2Z3igANd+AdzTPFJis3m+zOneElvPmjee ywH2o1GLgEs8dSrM7m0xAaeuKnzMQL/tcNC9lLm/uXvTqHldETe7Ehad/CreHntPxi sEuqpwMgbwsEqFhwMH2yXCUpXO6E+wwKB9GAEU5HBojxSPyE/bI69UkXTKauUelHbr O9gKykqwfUjUfyqdpkAfvKF+rzI7IUd2aDzyPNXZ1HvBv69/s1H5AgGYAH/Z0afKgT ff0IbxziVau1A== Received: from pat.atlnz.lc (Not Verified[10.32.16.33]) by svr-chch-seg1.atlnz.lc with Trustwave SEG (v8,2,6,11305) id ; Thu, 13 Jun 2024 14:54:15 +1200 Received: from aryans-dl.ws.atlnz.lc (aryans-dl.ws.atlnz.lc [10.33.22.38]) by pat.atlnz.lc (Postfix) with ESMTP id 2FCE913EDE9; Thu, 13 Jun 2024 14:54:15 +1200 (NZST) Received: by aryans-dl.ws.atlnz.lc (Postfix, from userid 1844) id 2D3B72A2270; Thu, 13 Jun 2024 14:54:15 +1200 (NZST) From: Aryan Srivastava To: Markus Elfring Cc: Andi Shyti , Aryan Srivastava , Robert Richter , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 1/2] i2c: octeon: refactor hlc r/w operations Date: Thu, 13 Jun 2024 14:54:10 +1200 Message-ID: <20240613025412.3848629-2-aryan.srivastava@alliedtelesis.co.nz> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240613025412.3848629-1-aryan.srivastava@alliedtelesis.co.nz> References: <20240613025412.3848629-1-aryan.srivastava@alliedtelesis.co.nz> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SEG-SpamProfiler-Analysis: v=2.4 cv=CvQccW4D c=1 sm=1 tr=0 ts=666a5f57 a=KLBiSEs5mFS1a/PbTCJxuA==:117 a=T1WGqf2p2xoA:10 a=a7gkLlzbLAVbDXTTgMMA:9 a=3ZKOabzyN94A:10 X-SEG-SpamProfiler-Score: 0 x-atlnz-ls: pat Refactor the current implementation of the high-level composite read and write operations in preparation of the addition of block-mode read/write operations. The sending of the i2c command is generic and will apply for both the block-mode and non-block-mode R/W. Extract this from the current hlc ops, and place into a generic function, octeon_i2c_hlc_cmd_send. The considerations made for extended addresses in the command construction are common for all r/w cases, extract these into octeon_i2c_hlc_ext. There are parts of the commands construction which are common (only in the read case), extract this and place into generic function octeon_i2c_hlc_read_cmd. The write commands cannot be made entirely into common code as there are distinct differences in the block mode and non-block-mode process. Particularly the writing of data into the buffer. Signed-off-by: Aryan Srivastava --- drivers/i2c/busses/i2c-octeon-core.c | 86 ++++++++++++++++------------ 1 file changed, 49 insertions(+), 37 deletions(-) diff --git a/drivers/i2c/busses/i2c-octeon-core.c b/drivers/i2c/busses/i2= c-octeon-core.c index 845eda70b8ca..6772359ca6c8 100644 --- a/drivers/i2c/busses/i2c-octeon-core.c +++ b/drivers/i2c/busses/i2c-octeon-core.c @@ -485,6 +485,50 @@ static int octeon_i2c_hlc_write(struct octeon_i2c *i= 2c, struct i2c_msg *msgs) return ret; } =20 +/* Process hlc transaction */ +static int octeon_i2c_hlc_cmd_send(struct octeon_i2c *i2c, u64 cmd) +{ + octeon_i2c_hlc_int_clear(i2c); + octeon_i2c_writeq_flush(cmd, i2c->twsi_base + SW_TWSI(i2c)); + + return octeon_i2c_hlc_wait(i2c); +} + +/* Generic consideration for extended internal addresses in i2c hlc r/w = ops */ +static bool octeon_i2c_hlc_ext(struct octeon_i2c *i2c, struct i2c_msg ms= g, u64 *cmd_in, u64 *ext) +{ + bool set_ext =3D false; + u64 cmd; + + if (msg.flags & I2C_M_TEN) + cmd |=3D SW_TWSI_OP_10_IA; + else + cmd |=3D SW_TWSI_OP_7_IA; + + if (msg.len =3D=3D 2) { + cmd |=3D SW_TWSI_EIA; + *ext =3D (u64)msg.buf[0] << SW_TWSI_IA_SHIFT; + cmd |=3D (u64)msg.buf[1] << SW_TWSI_IA_SHIFT; + set_ext =3D true; + } else { + cmd |=3D (u64)msg.buf[0] << SW_TWSI_IA_SHIFT; + } + + *cmd_in |=3D cmd; + return set_ext; +} + +/* Construct and send i2c transaction core cmd for read ops */ +static int octeon_i2c_hlc_read_cmd(struct octeon_i2c *i2c, struct i2c_ms= g msg, u64 cmd) +{ + u64 ext =3D 0; + + if (octeon_i2c_hlc_ext(i2c, msg, &cmd, &ext)) + octeon_i2c_writeq_flush(ext, i2c->twsi_base + SW_TWSI_EXT(i2c)); + + return octeon_i2c_hlc_cmd_send(i2c, cmd); +} + /* high-level-controller composite write+read, msg0=3Daddr, msg1=3Ddata = */ static int octeon_i2c_hlc_comp_read(struct octeon_i2c *i2c, struct i2c_m= sg *msgs) { @@ -499,26 +543,8 @@ static int octeon_i2c_hlc_comp_read(struct octeon_i2= c *i2c, struct i2c_msg *msgs /* A */ cmd |=3D (u64)(msgs[0].addr & 0x7full) << SW_TWSI_ADDR_SHIFT; =20 - if (msgs[0].flags & I2C_M_TEN) - cmd |=3D SW_TWSI_OP_10_IA; - else - cmd |=3D SW_TWSI_OP_7_IA; - - if (msgs[0].len =3D=3D 2) { - u64 ext =3D 0; - - cmd |=3D SW_TWSI_EIA; - ext =3D (u64)msgs[0].buf[0] << SW_TWSI_IA_SHIFT; - cmd |=3D (u64)msgs[0].buf[1] << SW_TWSI_IA_SHIFT; - octeon_i2c_writeq_flush(ext, i2c->twsi_base + SW_TWSI_EXT(i2c)); - } else { - cmd |=3D (u64)msgs[0].buf[0] << SW_TWSI_IA_SHIFT; - } - - octeon_i2c_hlc_int_clear(i2c); - octeon_i2c_writeq_flush(cmd, i2c->twsi_base + SW_TWSI(i2c)); - - ret =3D octeon_i2c_hlc_wait(i2c); + /* Send core command */ + ret =3D octeon_i2c_hlc_cmd(i2c, msgs[0], cmd); if (ret) goto err; =20 @@ -554,19 +580,8 @@ static int octeon_i2c_hlc_comp_write(struct octeon_i= 2c *i2c, struct i2c_msg *msg /* A */ cmd |=3D (u64)(msgs[0].addr & 0x7full) << SW_TWSI_ADDR_SHIFT; =20 - if (msgs[0].flags & I2C_M_TEN) - cmd |=3D SW_TWSI_OP_10_IA; - else - cmd |=3D SW_TWSI_OP_7_IA; - - if (msgs[0].len =3D=3D 2) { - cmd |=3D SW_TWSI_EIA; - ext |=3D (u64)msgs[0].buf[0] << SW_TWSI_IA_SHIFT; - set_ext =3D true; - cmd |=3D (u64)msgs[0].buf[1] << SW_TWSI_IA_SHIFT; - } else { - cmd |=3D (u64)msgs[0].buf[0] << SW_TWSI_IA_SHIFT; - } + /* Set parameters for extended message (if required) */ + set_ext =3D octeon_i2c_hlc_ext(i2c, msgs[0], &cmd, &ext); =20 for (i =3D 0, j =3D msgs[1].len - 1; i < msgs[1].len && i < 4; i++, j-= -) cmd |=3D (u64)msgs[1].buf[j] << (8 * i); @@ -579,10 +594,7 @@ static int octeon_i2c_hlc_comp_write(struct octeon_i= 2c *i2c, struct i2c_msg *msg if (set_ext) octeon_i2c_writeq_flush(ext, i2c->twsi_base + SW_TWSI_EXT(i2c)); =20 - octeon_i2c_hlc_int_clear(i2c); - octeon_i2c_writeq_flush(cmd, i2c->twsi_base + SW_TWSI(i2c)); - - ret =3D octeon_i2c_hlc_wait(i2c); + ret =3D octeon_i2c_hlc_cmd_send(i2c, cmd); if (ret) goto err; =20 --=20 2.43.2