From nobody Wed Nov 27 14:42:26 2024 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 53089189918 for ; Thu, 10 Oct 2024 02:54:00 +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=1728528842; cv=none; b=OO7j0yvprFW/JumA1aUxALjjGxjOAxpQVterz1c9YMo8uxx7fddtaHDfZcFRqIRW9DXbmTh5UhLMwvlpAvfI9MvG+R8z3mNATkp/5/KPZwIxReAdWbdleEg5xrez9zaO7S0pTth+Wx58pRT4qSgP2gxu5K2mDLM5I/kPPNV51rA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728528842; c=relaxed/simple; bh=Ur38yE0TdHkS43DxSZicHqnAc/15aDuuomFlKgTr0pY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RqaimF6hyIsGxi3KuiW0BcYJTYCsn43mZ3HQ/eImYMV08T65P15EL0H7lbSmX4RGVSS/TuYbOi0/XmqIDvzKpUnE6jTRuqUqmxfMuuvcqHBIvNQMtr80QVYRAbJzb1d27/U7MGBpg0d/TDPPR2UAbN4nhddIq6R7Aij4tqm44zo= 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=yJyrOoh3; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=alliedtelesis.co.nz header.i=@alliedtelesis.co.nz header.b="yJyrOoh3" 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 86D722C0B9B; Thu, 10 Oct 2024 15:53:58 +1300 (NZDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail181024; t=1728528838; bh=LppaIyAQz/Q1iPQjdwFQs6kEfJBrHuEfYxyspqwFeBE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yJyrOoh3anCz4ygmgGN1hwngWNesDHp053vlXklR4qg8b8jP05YLl9mR4WydLm8tq HdYKljSvSbXHSwMHgcRqxDahs4ShEYOxYVKa1aVK7BsE4Am61gqF0uWXbxIco2t8CR 6q6hPexAGQ+khWI9Rb52kQnNvb8fp7lEascwqZoPdwTJ3z0NMinp8PgJtUJPophSfA NUWdc4SzuqWtzUMlxaOa5CbI6y7Oaa5VOS1cbYuJcNBFkKDhrLJDLZb36Y5QlbcoZT 7xTXvSoFQoWVsp8iZHBELVZpCzQjwwFmW01/J7wI6WI5/QpO4jFBDy+Lj5Hlwaj3h/ i5mQQlnS1oFGw== 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, 10 Oct 2024 15:53:58 +1300 Received: from aryans-dl.ws.atlnz.lc (aryans-dl.ws.atlnz.lc [10.33.22.38]) by pat.atlnz.lc (Postfix) with ESMTP id 5326913ED7B; Thu, 10 Oct 2024 15:53:58 +1300 (NZDT) Received: by aryans-dl.ws.atlnz.lc (Postfix, from userid 1844) id 52B452A0BF8; Thu, 10 Oct 2024 15:53:58 +1300 (NZDT) From: Aryan Srivastava To: Andi Shyti , Markus Elfring Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Aryan Srivastava , Robert Richter Subject: [PATCH v10 1/2] i2c: octeon: refactor common i2c operations Date: Thu, 10 Oct 2024 15:53:15 +1300 Message-ID: <20241010025317.2040470-2-aryan.srivastava@alliedtelesis.co.nz> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241010025317.2040470-1-aryan.srivastava@alliedtelesis.co.nz> References: <20241010025317.2040470-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=ca1xrWDM c=1 sm=1 tr=0 ts=670741c6 a=KLBiSEs5mFS1a/PbTCJxuA==:117 a=DAUX931o1VcA:10 a=A-Af6rZeaoc7pdqLdb8A:9 a=3ZKOabzyN94A:10 X-SEG-SpamProfiler-Score: 0 x-atlnz-ls: pat Content-Type: text/plain; charset="utf-8" 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 ops. 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 almost common for all cases, extract these into octeon_i2c_hlc_ext. There is one difference between the extended read and write cases. When performing extended read or writes the SW_TWSI_EXT must be written with an extended internal address, but the data field is only filled in the write case (read back in read case). This results in the original code block for the read case immediately writing this register, while the write case fills in any data and then writes the register. To create a common block of code for both processes remove the SW_TWSI_EXT write from within the code block and instead in it's place a variable is set, set_ext, which is returned and used as a condition to do the register write, in the read command case. 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. This function also reads the return from octeon_i2c_hlc_ext and completes the write to SW_TWSI_EXT if required. 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/i2c-= octeon-core.c index 16cc34a0526e..3fbc828508ab 100644 --- a/drivers/i2c/busses/i2c-octeon-core.c +++ b/drivers/i2c/busses/i2c-octeon-core.c @@ -498,6 +498,50 @@ static int octeon_i2c_hlc_write(struct octeon_i2c *i2c= , 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 + OCTEON_REG_SW_TWSI(i2c)); + + return octeon_i2c_hlc_wait(i2c); +} + +/* Generic consideration for extended internal addresses in i2c hlc r/w op= s */ +static bool octeon_i2c_hlc_ext(struct octeon_i2c *i2c, struct i2c_msg msg,= u64 *cmd_in, u64 *ext) +{ + bool set_ext =3D false; + u64 cmd =3D 0; + + 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_msg = msg, u64 cmd) +{ + u64 ext =3D 0; + + if (octeon_i2c_hlc_ext(i2c, msg, &cmd, &ext)) + octeon_i2c_writeq_flush(ext, i2c->twsi_base + OCTEON_REG_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_msg= *msgs) { @@ -512,26 +556,8 @@ static int octeon_i2c_hlc_comp_read(struct octeon_i2c = *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 + OCTEON_REG_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 + OCTEON_REG_SW_TWSI(i2c)); - - ret =3D octeon_i2c_hlc_wait(i2c); + /* Send core command */ + ret =3D octeon_i2c_hlc_read_cmd(i2c, msgs[0], cmd); if (ret) goto err; =20 @@ -567,19 +593,8 @@ static int octeon_i2c_hlc_comp_write(struct octeon_i2c= *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); @@ -592,10 +607,7 @@ static int octeon_i2c_hlc_comp_write(struct octeon_i2c= *i2c, struct i2c_msg *msg if (set_ext) octeon_i2c_writeq_flush(ext, i2c->twsi_base + OCTEON_REG_SW_TWSI_EXT(i2c= )); =20 - octeon_i2c_hlc_int_clear(i2c); - octeon_i2c_writeq_flush(cmd, i2c->twsi_base + OCTEON_REG_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.46.0