From patchwork Mon Jan 6 09:27:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 13927096 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A2A62E77198 for ; Mon, 6 Jan 2025 09:27:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=mTuP9yWLvgTX7AWXsr3gNvehLx4V/bwQi8Z2u3/J/IM=; b=Qt7w1KJDl2x34v vlt0xb7i+kRs14ckfqVX4yhgr2D0Id7PuQ7MPK2sPl9SieQFBWXqMg+byRN3aK5PPihk/hFXHVplk irFJfZ7HdDdUUiv8cMoiHr5mlRo6etf3wDQ/ScjSg/ePXHUj8c9w+6ijRVmt1t8GtGRxLkPsL9V0Q 9Gv0rHRUL59Gonq6NjdxpP0QEXKf+L7+GJpgnH+le13hlLZ3x/yvJGxcN0iprMNohUhqNOYYh+dV6 YKqWvCvJXA0pnV9MTcXmTjPmmEsNt9g/mSWk4fL+ms9W4B0o5c6kqpgFoF8hy2FDSSZxb/AbkA0PR dqRFele6OWQxhdZa4kkg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tUjOd-00000000gJj-0kkX; Mon, 06 Jan 2025 09:27:39 +0000 Received: from zeus03.de ([194.117.254.33] helo=mail.zeus03.de) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tUjOT-00000000gGp-3gm7 for linux-i3c@lists.infradead.org; Mon, 06 Jan 2025 09:27:32 +0000 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=/HzJlxcDzDQ4BvZyB5ZfxXV6i05giy4HK5Wtt3ukFzE=; b=aPPfy3 5s/163j8j2uLyoDeGPLC6/Qykt2evG8W7DWBim4j7PNHuTry+M1/V7MtK92YE8vZ IBFDBjkvfrDIRCMfK5BdsdrxAUikwOPTGe216Fd7NEn7SA+eWBIthxc/k7tXdi6y gLDkOpXh+3OTqlCGPqpc85wqIoP2t4mssLk1v4ADAEMihgg6IQcm6d7cAcSs+hli 5RLnOcLisX4q/h3BrDcbX9/E+C8LpAvYBgq3ptffVnJLv9gN5wSZFnLTX8RNySYY IhUk3CRQPXSbdInv7GrreMONlnIWBlfLDUlDPQM1BATTV2mzSalkGdSZbuOb5hX9 2hxcFp6C/PtNxf+w== Received: (qmail 1727803 invoked from network); 6 Jan 2025 10:27:26 +0100 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 6 Jan 2025 10:27:26 +0100 X-UD-Smtp-Session: l3s3148p1@HqGXPAYr2psgAwDPXw20AOMQ2KO98fSH From: Wolfram Sang To: linux-i3c@lists.infradead.org Cc: linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Wolfram Sang , Guenter Roeck , Geert Uytterhoeven , Yury Norov , Kuan-Wei Chiu , Rasmus Villemoes Subject: [PATCH v3 1/5] bitops: add generic parity calculation for u8 Date: Mon, 6 Jan 2025 10:27:19 +0100 Message-ID: <20250106092725.22869-2-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250106092725.22869-1-wsa+renesas@sang-engineering.com> References: <20250106092725.22869-1-wsa+renesas@sang-engineering.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250106_012730_797027_EE4F12D5 X-CRM114-Status: GOOD ( 15.90 ) X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org There are multiple open coded implementations for getting the parity of a byte in the kernel, even using different approaches. Take the pretty efficient version from SPD5118 driver and make it generally available by putting it into the bitops header. As long as there is just one parity calculation helper, the creation of a distinct 'parity.h' header was discarded. Also, the usage of hweight8() for architectures having a popcnt instruction is postponed until a use case within hot paths is desired. The motivation for this patch is the frequent use of odd parity in the I3C specification and to simplify drivers there. Changes compared to the original SPD5118 version are the addition of kernel documentation, switching the return type from bool to int, and renaming the argument of the function. Signed-off-by: Wolfram Sang Tested-by: Guenter Roeck Reviewed-by: Geert Uytterhoeven Acked-by: Yury Norov Reviewed-by: Kuan-Wei Chiu Tested-by: Kuan-Wei Chiu --- include/linux/bitops.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/include/linux/bitops.h b/include/linux/bitops.h index ba35bbf07798..c1cb53cf2f0f 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -229,6 +229,37 @@ static inline int get_count_order_long(unsigned long l) return (int)fls_long(--l); } +/** + * parity8 - get the parity of an u8 value + * @value: the value to be examined + * + * Determine the parity of the u8 argument. + * + * Returns: + * 0 for even parity, 1 for odd parity + * + * Note: This function informs you about the current parity. Example to bail + * out when parity is odd: + * + * if (parity8(val) == 1) + * return -EBADMSG; + * + * If you need to calculate a parity bit, you need to draw the conclusion from + * this result yourself. Example to enforce odd parity, parity bit is bit 7: + * + * if (parity8(val) == 0) + * val ^= BIT(7); + */ +static inline int parity8(u8 val) +{ + /* + * One explanation of this algorithm: + * https://funloop.org/codex/problem/parity/README.html + */ + val ^= val >> 4; + return (0x6996 >> (val & 0xf)) & 1; +} + /** * __ffs64 - find first set bit in a 64 bit word * @word: The 64 bit word From patchwork Mon Jan 6 09:27:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 13927099 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 496A9E7719D for ; Mon, 6 Jan 2025 09:27:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=NKebGb7XyGq/ylEOUSUcUsKdeDVW4xUI5cdXeYUzk7g=; b=sfN9cd2oBN33iT Vp0iM2OOFJ+n/6S6+Y2olh30DOa74VVbxMjwhdU3mP7Sqim0yNCDHCoTrYDPYFhKFWPTqtO5g/JeC Aw45f5RttJZZq5dx0CgUeJhSihRrK9XkuNF5Fja+QTPCj9H55AGkjrGkTHRVFLlvO4OCjV8wy5q/q nZ+Q7iTWSAEyNdcEoYKAOCW6X2bioSO/zSwYcgcJjgqYu+v2Ayg+RcjGbquZuSIMTjLSZgV4ZiIEL 7v5JG9FQ6gG6I7NtyQ8qCZ3A4Y8pwxsDSOfKBnBl5wv2xXcBTOqBZczvaz7MeFLK78qHP6UD9Lsdp 93t4biH/R5J6HwKS48og==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tUjOf-00000000gLE-0Ck7; Mon, 06 Jan 2025 09:27:41 +0000 Received: from zeus03.de ([194.117.254.33] helo=mail.zeus03.de) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tUjOT-00000000gGv-3hLn for linux-i3c@lists.infradead.org; Mon, 06 Jan 2025 09:27:33 +0000 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=3esdoiFUb3AEevKBNMcpAJ6KfgvtuQ7LV32gNwqiGFg=; b=TPWk4N fPZcFA8m1Gjf3bWSln46VsZOp5vMeZKXNGqo+2aLWg5gfieLCa+BfBNX3ty3Ls7N E7GWKLWrww3BOUql2/X00NYG6maKN6aHoPkf64myWHYMdRgJBU1oFw1vJYxRdram XhLhz/Sx+LYpnzkxaySdxU6Fpn298bvr6wwxz0WIzu1EE84CpVdLjiS29QeRHxHg iugPAFkwqrAPQb5uIxAGNQJqoeDbPR+LxlNcD8VMOi8elZJ+VWtR0pYftGhS9PdK UQzmQ2hvi8ZH7RAGv61mzSOTG/Gs0VE/rbXkmQi89evDat94dqkWVdpmlmh1dRki a+M0i0qKYqzqgi+w== Received: (qmail 1727852 invoked from network); 6 Jan 2025 10:27:27 +0100 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 6 Jan 2025 10:27:27 +0100 X-UD-Smtp-Session: l3s3148p1@/zGjPAYr4JsgAwDPXw20AOMQ2KO98fSH From: Wolfram Sang To: linux-i3c@lists.infradead.org Cc: linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Wolfram Sang , Guenter Roeck , Geert Uytterhoeven , Kuan-Wei Chiu , Jean Delvare , linux-hwmon@vger.kernel.org Subject: [PATCH v3 2/5] hwmon: (spd5118) Use generic parity calculation Date: Mon, 6 Jan 2025 10:27:20 +0100 Message-ID: <20250106092725.22869-3-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250106092725.22869-1-wsa+renesas@sang-engineering.com> References: <20250106092725.22869-1-wsa+renesas@sang-engineering.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250106_012730_809667_D8C9D97E X-CRM114-Status: UNSURE ( 8.37 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org Make use of the new generic helper for calculating the parity. Signed-off-by: Wolfram Sang Tested-by: Guenter Roeck Acked-by: Guenter Roeck Reviewed-by: Geert Uytterhoeven Reviewed-by: Kuan-Wei Chiu --- drivers/hwmon/spd5118.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/drivers/hwmon/spd5118.c b/drivers/hwmon/spd5118.c index 6cee48a3e5c3..358152868d96 100644 --- a/drivers/hwmon/spd5118.c +++ b/drivers/hwmon/spd5118.c @@ -291,12 +291,6 @@ static umode_t spd5118_is_visible(const void *_data, enum hwmon_sensor_types typ } } -static inline bool spd5118_parity8(u8 w) -{ - w ^= w >> 4; - return (0x6996 >> (w & 0xf)) & 1; -} - /* * Bank and vendor id are 8-bit fields with seven data bits and odd parity. * Vendor IDs 0 and 0x7f are invalid. @@ -304,7 +298,7 @@ static inline bool spd5118_parity8(u8 w) */ static bool spd5118_vendor_valid(u8 bank, u8 id) { - if (!spd5118_parity8(bank) || !spd5118_parity8(id)) + if (parity8(bank) == 0 || parity8(id) == 0) return false; id &= 0x7f; From patchwork Mon Jan 6 09:27:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 13927097 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A070DE77199 for ; Mon, 6 Jan 2025 09:27:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=g8mqbcxqcFrDTstrYk8JZUdQZCm9K7Jzuz6bqWU8L+c=; b=Ms7pnCn+Q9qytg AuJDTaUxFe0rXcfDwZaVOVqPxbkSzOtlPQoqo/euu/b0KdXvN9BxYVibIp+pmuSaWOklGcH9q4AVx AyUOLzZyiBshqYrzwonWEseoxpC3Wmye9/ZHOXKp/aOSqbvP3pYIzOyiPsqxWiKDRlITsHWTukHsj wBQd976mMyUvTCvzeCijoUAjGku78EJ9EnJJkK5ZXLkiGmGEhPPKnzwjwQ+tr4GEJFOneLguXgEUe J+gln+hzojFspoJWzHBk5KbP4WXuLjCLPCGGAnloU1icfbfMo6EH8hoeQnvX6NdYdN0QwzFj3qDb6 KfrV1i+hYQtzvLnS+v/A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tUjOe-00000000gKX-1Vr6; Mon, 06 Jan 2025 09:27:40 +0000 Received: from zeus03.de ([194.117.254.33] helo=mail.zeus03.de) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tUjOU-00000000gH0-0pJG for linux-i3c@lists.infradead.org; Mon, 06 Jan 2025 09:27:33 +0000 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=Py0DoMMuciEt40Q+z4uuudYOKUnz5ppwQn4+cYx5ojg=; b=ML7o2o qVJwx3q7djO/yb2b86sLOlJ2pUI46fIRp/mydZLpsbWK7ylHCePmQY13F+DqlbTH S7tEr/+/FUn+dPMSfpfjFSSwfY2dxDa4w93ME+kI9Unm8vNeGQtVKo/Fb4Zj8q1V M7u2cdiij9yKIPezD3rUDStvbYdjowtmu6VXupZVhdqJRsy8YWmvqxhtoUqQ8oXr kZPzgLS+w05Dw9FhtIvnY0ECpDhqE/20Rus0BgflpVKKQfVluptdoIIPZYJpnlcU UfZPnJk2rdycGX/Fpww5BXDB+byjbKQMgT6HL+aRQe3O1lgkRGaruiHltMOUvS8D xta28EwTyR+Wp26Q== Received: (qmail 1727908 invoked from network); 6 Jan 2025 10:27:28 +0100 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 6 Jan 2025 10:27:28 +0100 X-UD-Smtp-Session: l3s3148p1@r9avPAYr7JsgAwDPXw20AOMQ2KO98fSH From: Wolfram Sang To: linux-i3c@lists.infradead.org Cc: linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Wolfram Sang , Alexandre Belloni Subject: [PATCH v3 3/5] i3c: dw: use parity8 helper instead of open coding it Date: Mon, 6 Jan 2025 10:27:21 +0100 Message-ID: <20250106092725.22869-4-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250106092725.22869-1-wsa+renesas@sang-engineering.com> References: <20250106092725.22869-1-wsa+renesas@sang-engineering.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250106_012730_807174_E8B8A72E X-CRM114-Status: GOOD ( 10.04 ) X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org The kernel has now a generic helper for getting parity with easier to understand semantics. Make use of it. Signed-off-by: Wolfram Sang --- drivers/i3c/master/dw-i3c-master.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/drivers/i3c/master/dw-i3c-master.c b/drivers/i3c/master/dw-i3c-master.c index d4b80eb8cecd..0d4d44458c11 100644 --- a/drivers/i3c/master/dw-i3c-master.c +++ b/drivers/i3c/master/dw-i3c-master.c @@ -251,14 +251,6 @@ struct dw_i3c_i2c_dev_data { struct i3c_generic_ibi_pool *ibi_pool; }; -static u8 even_parity(u8 p) -{ - p ^= p >> 4; - p &= 0xf; - - return (0x9669 >> p) & 1; -} - static bool dw_i3c_master_supports_ccc_cmd(struct i3c_master_controller *m, const struct i3c_ccc_cmd *cmd) { @@ -848,7 +840,7 @@ static int dw_i3c_master_daa(struct i3c_master_controller *m) struct dw_i3c_xfer *xfer; struct dw_i3c_cmd *cmd; u32 olddevs, newdevs; - u8 p, last_addr = 0; + u8 last_addr = 0; int ret, pos; ret = pm_runtime_resume_and_get(master->dev); @@ -873,9 +865,9 @@ static int dw_i3c_master_daa(struct i3c_master_controller *m) } master->devs[pos].addr = ret; - p = even_parity(ret); last_addr = ret; - ret |= (p << 7); + + ret |= parity8(ret) ? 0 : BIT(7); writel(DEV_ADDR_TABLE_DYNAMIC_ADDR(ret), master->regs + From patchwork Mon Jan 6 09:27:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 13927100 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 000F8E7719C for ; Mon, 6 Jan 2025 09:27:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=NFm8l6LPRZ5Id0DiGLpxz8LWyWC5OMEX8ZLLzo+Nlmo=; b=jxowqcgXe4ym+T dzn6MuI2QHXJRWRCnYs1qdvr5wV1BBPwZoLyrdFk6r0EV6n7wWNxUz0KkmuHODJ4r7qHRaLMeQcc8 DLQ0uKktDbbPmUSBZP5DyxT3N0JWVBUDCQpZ9B5M7ef27u6KpnLt2rRq9/3+oStXlw1PDPCnRvkbL tOG+JoGxxM/4lwDikSRIMwQxtC8B1gVMFsYimXXU0fss6U+CQlHkzsTMI6ON7BxrpEWX0tYR7Ltgb QEkjJoI3DMjmV5dAtLZqhtOo7Ne8sHvt8mh/VoicE7QKxelmiECAmzvOdN3N3sfWu6N/Qya1vDBl9 H85A3+RpykmicZ34SeQQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tUjOe-00000000gL0-35ew; Mon, 06 Jan 2025 09:27:40 +0000 Received: from zeus03.de ([194.117.254.33] helo=mail.zeus03.de) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tUjOU-00000000gH3-3r65 for linux-i3c@lists.infradead.org; Mon, 06 Jan 2025 09:27:33 +0000 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=Ta1yRvPmk5gWC8V3XFdegSgto4i6026D0epR4X2xhig=; b=Qij2Cc LM1RRwo4VymSORu7F1VP1pfl+/P/5ihzXTIQ3pRpn7s0AbMSvkfUL7WYdHgE7cuC +upm6jeCmLdl31m9iYkwgQQSbPm7Ke2bLolDl06mD5tJYynbBQc6DZlYSm7Hv8Y0 Cn3/u9NOhlxez0uxP1E1wMEgDvgKWVxt4pW03bJFSbGABFwEWRUQFhDzUF4SXdE6 sx7wGBmzZFp77+Az+Wo4AZyISdRcZ41ZwNk2zRQmf/K8f7V7tmHEKVEz+aPPw65j 5FV4WYpRpRvOWIPLOOUApUmjJooXGgCVVLFbDgtMJiYWVjneqapQynCfuiSUXI/s eN+wjJbiJocPxZ9g== Received: (qmail 1727955 invoked from network); 6 Jan 2025 10:27:29 +0100 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 6 Jan 2025 10:27:29 +0100 X-UD-Smtp-Session: l3s3148p1@rny7PAYr/JsgAwDPXw20AOMQ2KO98fSH From: Wolfram Sang To: linux-i3c@lists.infradead.org Cc: linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Wolfram Sang , Jarkko Nikula , Alexandre Belloni Subject: [PATCH v3 4/5] i3c: mipi-i3c-hci: use parity8 helper instead of open coding it Date: Mon, 6 Jan 2025 10:27:22 +0100 Message-ID: <20250106092725.22869-5-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250106092725.22869-1-wsa+renesas@sang-engineering.com> References: <20250106092725.22869-1-wsa+renesas@sang-engineering.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250106_012731_227444_780FE529 X-CRM114-Status: UNSURE ( 8.62 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org The kernel has now a generic helper for getting parity with easier to understand semantics. Make use of it. Signed-off-by: Wolfram Sang Tested-by: Jarkko Nikula --- drivers/i3c/master/mipi-i3c-hci/dat_v1.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/drivers/i3c/master/mipi-i3c-hci/dat_v1.c b/drivers/i3c/master/mipi-i3c-hci/dat_v1.c index 47b9b4d4ed3f..85c4916972e4 100644 --- a/drivers/i3c/master/mipi-i3c-hci/dat_v1.c +++ b/drivers/i3c/master/mipi-i3c-hci/dat_v1.c @@ -40,15 +40,6 @@ #define dat_w0_write(i, v) writel(v, hci->DAT_regs + (i) * 8) #define dat_w1_write(i, v) writel(v, hci->DAT_regs + (i) * 8 + 4) -static inline bool dynaddr_parity(unsigned int addr) -{ - addr |= 1 << 7; - addr += addr >> 4; - addr += addr >> 2; - addr += addr >> 1; - return (addr & 1); -} - static int hci_dat_v1_init(struct i3c_hci *hci) { unsigned int dat_idx; @@ -123,7 +114,7 @@ static void hci_dat_v1_set_dynamic_addr(struct i3c_hci *hci, dat_w0 = dat_w0_read(dat_idx); dat_w0 &= ~(DAT_0_DYNAMIC_ADDRESS | DAT_0_DYNADDR_PARITY); dat_w0 |= FIELD_PREP(DAT_0_DYNAMIC_ADDRESS, address) | - (dynaddr_parity(address) ? DAT_0_DYNADDR_PARITY : 0); + (parity8(address) ? 0 : DAT_0_DYNADDR_PARITY); dat_w0_write(dat_idx, dat_w0); } From patchwork Mon Jan 6 09:27:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 13927101 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3620FE77188 for ; Mon, 6 Jan 2025 09:27:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=CJG2hTmiJ+2Pgfm6lvsd3IsGJR/Hoi865Ev/nMDa6Gw=; b=FFlgSrUL/ejuit J3dHTbKPZPSAs7iu95A8/QLMCWMyNEveM/J69VBCo+QdbSbgjCNylZefDXKZ6st5kvMlt9tTT31MO MCfSYrJOP1AiPRD68nW2AZ2VJIMOOW7ElR/tA7ZcZNaBq6MvmtKkKBEz+JhNUP2LQKUsTnNBNBBR+ fQXeW9A8WI9I4JrshBWuJIfpksEjkNWW3+tM0JfN+AK2PEqfyRLVdl/mHxBxm3LdXpPxCElMKaSI0 LwXwtFnJu1Gu/5QvpSntCsC7p++Z2HhRAnO/TnfezDQ/VFdlPu8jKuDEfZLOsABo5Ivhr7RiBlvfP FxHN9bd8QJswLs3YaubA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tUjOf-00000000gMK-41a1; Mon, 06 Jan 2025 09:27:41 +0000 Received: from zeus03.de ([194.117.254.33] helo=mail.zeus03.de) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tUjOZ-00000000gIk-0JL5 for linux-i3c@lists.infradead.org; Mon, 06 Jan 2025 09:27:36 +0000 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=4Ve5hf8pI9HFM2zjnWzNNrBkEoJuyyCP7A1G3jT4K4o=; b=RNPmz+ s1OJyMvaf2h72opfmkKaB+XXlnlb0Cj8eqFQOXvJKA+nDFa4XlMUNHUziAmhuZJ2 adB9bZOOBaxcNwXRNYPMdgOfMdFPcvRRv4tHjdxH2ThdeUXtkosq5Ttz6WWOK4RB rtFCCfPICOdxKJDPdMJfEm5+Yyds3UcHnq+wF3L4hZfQMc8G5fFeMOARvFJthgvX QM+V6BrfEmBzZ6iBcR3DnscecEV5X8MmIPx0iAC8RjIxuoHEthQW5SVPZeDdKsK7 1wV9zAMPjYt9UV82van6NqoDDe/p7azNjlV2Es1B7A9kaTlf9fakZSbTXAJdw+MW kMDM2it+fZoy13Qg== Received: (qmail 1727987 invoked from network); 6 Jan 2025 10:27:30 +0100 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 6 Jan 2025 10:27:30 +0100 X-UD-Smtp-Session: l3s3148p1@1QbHPAYrCJwgAwDPXw20AOMQ2KO98fSH From: Wolfram Sang To: linux-i3c@lists.infradead.org Cc: linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Wolfram Sang , =?utf-8?q?Przemys=C5=82aw_?= =?utf-8?q?Gaj?= , Alexandre Belloni Subject: [PATCH v3 5/5] i3c: cdns: use parity8 helper instead of open coding it Date: Mon, 6 Jan 2025 10:27:23 +0100 Message-ID: <20250106092725.22869-6-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250106092725.22869-1-wsa+renesas@sang-engineering.com> References: <20250106092725.22869-1-wsa+renesas@sang-engineering.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250106_012735_404442_FB642453 X-CRM114-Status: UNSURE ( 9.60 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org The kernel has now a generic helper for getting parity with easier to understand semantics. Make use of it. Signed-off-by: Wolfram Sang --- drivers/i3c/master/i3c-master-cdns.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/i3c/master/i3c-master-cdns.c b/drivers/i3c/master/i3c-master-cdns.c index 06c0592487d3..fedbe6624a1c 100644 --- a/drivers/i3c/master/i3c-master-cdns.c +++ b/drivers/i3c/master/i3c-master-cdns.c @@ -889,8 +889,7 @@ static u32 prepare_rr0_dev_address(u32 addr) ret |= (addr & GENMASK(9, 7)) << 6; /* RR0[0] = ~XOR(addr[6:0]) */ - if (!(hweight8(addr & 0x7f) & 1)) - ret |= 1; + ret |= parity8(addr & 0x7f) ? 0 : BIT(0); return ret; }