Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp115131lqp; Sun, 9 Jun 2024 20:00:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUQgEr+zIwgzWWQyedSOwFgxzrVkH3TozPz9xzpWesjVqo86OwESEbIcN47B1rFru4oxYxWkOOCIXgW938nlm3+ZdVSrCfIFzwvhkYNbA== X-Google-Smtp-Source: AGHT+IFf9VD7i3HZgWYGYV3Eq3KeasBuwoPAcq2y0fJG+K7dIHfBACyW8eY26mNlSW/aGK0Nq9Y0 X-Received: by 2002:ac8:7d8e:0:b0:43a:ed9c:36f3 with SMTP id d75a77b69052e-44041cb97a2mr92728901cf.42.1717988435859; Sun, 09 Jun 2024 20:00:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717988435; cv=pass; d=google.com; s=arc-20160816; b=uW9EXJwmk0dW2kasaFsplx8NpD3SqDV3V9VFERBFW9bzkoVt/wogvFpGHa7LJRC1IH TRRNVJF7QlG+M5ntbtxX78TV23ss43IRgvncqIyQnM25K5zp8Z4Jukm3bK0HK21FBeLq clF35RIF3oopRVYX5wzMowzWyvNM3nHQExrR3qOn1pcLtO1k7cc3ksEc8yRUV5MQUcH6 EOQ6K/5FzOIEAf5VMiSB1NcbrLu4vxEW3UFgVG5LFr4PV1VSHd13V8deNDYqVO6jCwMH vlGJWXesZ7w7ywroLOMJpk/ZNOk4mdO4r8kfPUCJqCjuGNvRNnyw2B+KaXcx+c0lhxiz Pggw== 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=ud957lKb8asL2PtFHNaW6BR3jvt+Fs1RgfPqFya4nvs=; fh=Fy5P9EDITDu9vXApEYzrgBNhabMGpOtmjVrL9/kGPIY=; b=QS1bKFhC1TvPzp45rdJe9OzKNpvUvPd89g0G7Y6cNKFlogcBalkSPF/QXfb2pLZZGY wd99Fvx8RZGAUh3AFGArP1RomnTBaNTqiqrtA/c5fh76CB04IZFLmp4r7SMp4ijhJYJr SyenkoJBKzQqBfsLFZct5PdBcX2t7HTnHbxBphHAH1oy69AASQJL/VDMXJo9SC+0DwW4 vBTHi4p3Ct/DZGSIbJy64XX6agaVreMa1UrHdNa0TQWCE5vRlOuOdDxL0/EbU756s/Sv Jy9KryJWCNQs2nZwDg9BFYu4YVPYVoqbTyHBfX2aH75rudmHKGHkKwninE/7YPe/RJfN lD6w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@alliedtelesis.co.nz header.s=mail181024 header.b=MN2w66A6; 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-207597-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-207597-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 ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-44038b60b19si96715931cf.547.2024.06.09.20.00.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jun 2024 20:00:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-207597-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@alliedtelesis.co.nz header.s=mail181024 header.b=MN2w66A6; 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-207597-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-207597-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 58E831C20E71 for ; Mon, 10 Jun 2024 03:00:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C6C8D7470; Mon, 10 Jun 2024 03:00:26 +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="MN2w66A6" 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 35934B67F for ; Mon, 10 Jun 2024 03:00:24 +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=1717988425; cv=none; b=N/+bTVSo5Lr2TfX4ehBFI5Lq1rahJQ4wKrroKnElXnF6kj0LnKw5pzNJ/mgm4k1FR0I5xjKweYxp3DteRc1Z+/balYJXpeX6QNkpkbYWPkC5LSxA6u4mj8re2z+7dyqf9HbjhS998e5HzsAHopLt0aPFDdM6bgdjxUclUbWIu64= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717988425; c=relaxed/simple; bh=M6MOKtoJjmhfcp13s5cKdG6H8tEn/QFdSMXntGSR0GM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BdvSGBLMbAajH1E1L8xSBj2IFfLPzpICinBM7F14oi0WV1gX0r5nQ74kHgHTK5UIVuSBrNNwCxmq4aTgMlwI+1zaFkx7+ZVEDtzknMzGjoN0n9/dvmz+PGgyedYpdHE6XhH95DXJBV0ZLajgKom3nZN2PprZPuVl9dj30rVSlmU= 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=MN2w66A6; 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 ECE3D2C04C9; Mon, 10 Jun 2024 15:00:22 +1200 (NZST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail181024; t=1717988422; bh=ud957lKb8asL2PtFHNaW6BR3jvt+Fs1RgfPqFya4nvs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MN2w66A6SxVEuMBEzztOMQXEE3aF6nCvri1cIlNZDidM8kdz6KURZ8jyXs5cQ9ef5 6XtdY6Z4JC8qf//02W26uO9y9OOr98xVjWc7fGGvktTR8dqPk8oCIEXJynfCyELFHk VaDIQq77tKk8sTawOJ/xgJuVVkLjlmTPkkpVa6LJz7OtXLAxUHkB9uX1AJm1n+v/qA KRH9danfPzn1mSaA2cXO5g7hnautdyQUud/gV1Yu8IpWIi7FImTNL1/xVY5F0fanj9 EtelZi2HTIC1GBFnnfdd85MaXdACJ+3QNo8BEs69yfl11fbzuRQIycOx2pffskqS+I g4HkYwY2eDaaw== 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 ; Mon, 10 Jun 2024 15:00:22 +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 C479313EE2B; Mon, 10 Jun 2024 15:00:22 +1200 (NZST) Received: by aryans-dl.ws.atlnz.lc (Postfix, from userid 1844) id C22F52A2270; Mon, 10 Jun 2024 15:00:22 +1200 (NZST) From: Aryan Srivastava To: andi.shyti@kernel.org Cc: aryan.srivastava@alliedtelesis.co.nz, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 1/2] i2c: octeon: refactor hlc r/w operations Date: Mon, 10 Jun 2024 14:59:54 +1200 Message-ID: <20240610025955.2308688-2-aryan.srivastava@alliedtelesis.co.nz> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240610025955.2308688-1-aryan.srivastava@alliedtelesis.co.nz> References: <20240610025955.2308688-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=F9L0dbhN c=1 sm=1 tr=0 ts=66666c46 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