From patchwork Tue Jan 7 09:01:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 13928475 X-Patchwork-Delegate: geert@linux-m68k.org 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 2FAC21E2844 for ; Tue, 7 Jan 2025 09:02:09 +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=1736240535; cv=none; b=rj/srxMP02OZOUXqMCy0esjeCIArWgO5crTNmuGQKzqtRMM9j25ba1stYInmIQh/ZuG4yy8rFPVW3x/orl4R2fqWCY5ac3TpAghkfN5qJXoHtoWESZ/IEgEnIOh3B/GF53/u7jhAoMamt0sXp+VsY40TU+40Np0jh7WOgWfe8Hc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736240535; c=relaxed/simple; bh=iE2RZGbU/m3GTH5mM4eQ3IKKskw9bZO8Ye67V3av1/s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=clGtt/J9pyezNXqXIJMU7InGSJszkh7O8wwQ56oRnTVVeyDPzA8AzZftzESmddesRwEkoS0T6OIW9uxfGu/bfUzkZAK/f45FaiGxhsf/C2HcDu7sLOYzp5bD5bOlTJDv2WvGkFZGTWyU4NVxYoesVKMtKzElnkbgRMQcL9X/p6Y= 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=PJbMEmFe; 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="PJbMEmFe" 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=PJbMEm FeBJDnwLQstpDw9GMUXk+6Y0U1d7YWzOC+mZ7YSE8aQwze6sLLhzOhOjYpO+dwox cznTO0/eLFRIsFEwSa66lfC3UVAcoxmY2dvjsof5AsTa79SBRVJPbAVfpxdRQST7 xuFTkv7naViu9gsj6XP78wqzZSyiwqrOiLO4pU8oZjKEAuVVoRBuAaafJljbHqgW 73KpszNJ9VEGq45Hi1uVFtBJYUC908ei9tM5DPG9Cesm/SxT/+H45tECbSqStYAD kZjNqEK9cnDy17Q1/kg5na6rgXd08DSTBUMmjMQO/iD3p0pY1AAhKyvWrG11ZyhB yY4Oc8vjA3rUVNgg== Received: (qmail 2125225 invoked from network); 7 Jan 2025 10:02:07 +0100 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 7 Jan 2025 10:02:07 +0100 X-UD-Smtp-Session: l3s3148p1@PhXi/xkrTpMgAwDPXw20AOMQ2KO98fSH 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 v4 1/5] bitops: add generic parity calculation for u8 Date: Tue, 7 Jan 2025 10:01:59 +0100 Message-ID: <20250107090204.6593-2-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250107090204.6593-1-wsa+renesas@sang-engineering.com> References: <20250107090204.6593-1-wsa+renesas@sang-engineering.com> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Tue Jan 7 09:02:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 13928473 X-Patchwork-Delegate: geert@linux-m68k.org 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 B09D81DFD99 for ; Tue, 7 Jan 2025 09:02:10 +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=1736240534; cv=none; b=eIRwiQIKppkMRgYVkaFMG2pxRW1HCYvIrvW34VSiybpab/do712RvBxZjSW4j4WYWUs8EqdMyrSMHP9pp+CiR36AhvTrplPKrFmWNJfODTUCIL6Wtn9DQ/KtbeIwxoCwbmmsSrdM0EX2IgtnUYa8RSxYACsNL4wHLR5m1bywlYo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736240534; c=relaxed/simple; bh=m4dZUh60u/mP9K/YIW4a9JOlkH+HgpGeePQd9+q1fYE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h01Cqh1kZbgccXCdk1DzBGocDy+dUjy+LvoXBIv7BW37NpFcNBsIIA90qZjayRQ1zKhazkp8OxJNTDkoQSP+4PMRlRWlYWCcljyCTxVm3EyfGKftbLxB3xpxbDkuqnKhEFcOe2DwMZ9bR6wXRVf61XF6hryhsHQqY0QkqvX0yME= 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=Jl4M7yTT; 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="Jl4M7yTT" 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=Jl4M7y TTjNgAoBMM0fzgwlpdNwhWedqnlibkxCCVlKu0nJEY5R3AD80JO7w5+dUI115wKT +OtzoIHK7KtHltOseIEQUj1URJweRklK+880BEyl5Jw2R2wzxL52SH4Un1+I+FIi uKNung5c4LxuzIfRV9YeO+IqFxq04DFCnBkUB8jnHK31+WWg8QGZXMzIuLNYz+hZ aVNaYZwqwI9QNXnesom7OQUZ08anvBX7ccToarXwhUvIClpPG1X0dsnRxsh/dOs1 pNVOHuDV/RRFP6oZ+6+jCK9I0W4ozZzZCvX+bkvDurNKZssqCwDQoofoa1XOMaze 2TQFceHsD+BR5QqQ== Received: (qmail 2125271 invoked from network); 7 Jan 2025 10:02:08 +0100 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 7 Jan 2025 10:02:08 +0100 X-UD-Smtp-Session: l3s3148p1@qa3t/xkrXJMgAwDPXw20AOMQ2KO98fSH 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 v4 2/5] hwmon: (spd5118) Use generic parity calculation Date: Tue, 7 Jan 2025 10:02:00 +0100 Message-ID: <20250107090204.6593-3-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250107090204.6593-1-wsa+renesas@sang-engineering.com> References: <20250107090204.6593-1-wsa+renesas@sang-engineering.com> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Tue Jan 7 09:02:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 13928474 X-Patchwork-Delegate: geert@linux-m68k.org 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 8E7881E25FE for ; Tue, 7 Jan 2025 09:02:11 +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=1736240535; cv=none; b=FC604I8bqeXdpx8+q842Zo+whwWRaizlSUre/9zVWrgbiSSdAS1gWCFSNOKb2WPqJu9aN8z2pxmcBjHsCsAEVKtlS1iLtMFaRa16amXwVuTv7OPbcSmNAhsNIKnlH3tKh1hbiYCZxO3LyooDRX/gDD8xydJ6jJGymj7iqWGgE+8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736240535; c=relaxed/simple; bh=4t42AJm9JUZgPf3saXLPRAI14WanKBxsPVyqgD+WlLw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=as/rYub1v99odrNRXDi5foZNSjZechgaQPnS2rOg2JpZQWCnlR8aMP6R1GyFfwDiFbLDPLbyeR0iFrzHavp7SXIh6oBPt3s8NizSbKQCqVT1KSOyAF4o+EFjlo/3yJ+e1YMn/4EClg6AQyr+qAqk0lU9fuNyKX4uNWvC4Xs0nl0= 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=eyDX3qTA; 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="eyDX3qTA" 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=eyDX3q TAD+n/EOt+u/Mbevq3q8Gsf4GnKSJAJqyKHhz9//jF1GRu+0GsQ7FjIXQc2+ZL7O IZQgyoH0KrmN7meBBEEZxpb8fYhgRQvrZQtM9VK/2YoVG4BE5UITV2BWw1nSYGfq VNoDCUBhQJoIVfTfQiiTr/5HkdKElOIGZ3fOM6xn+A1e9UCQQBsA6Jk3Z6+sg0yH UE8vqVOy/dQD5A4NoP5RnATZAN1H++JHCfUl3aD0GfyF9EMg0DyIi1kkIjmvcbAe WKXCrmW4SRcDOd5siPghYn8PRW835Oc8IghjW0Jh9gF6VWkbGox7e3zaJHpaRiQu /gxlFH3uD5S4KwHQ== Received: (qmail 2125336 invoked from network); 7 Jan 2025 10:02:09 +0100 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 7 Jan 2025 10:02:09 +0100 X-UD-Smtp-Session: l3s3148p1@hx36/xkrZpMgAwDPXw20AOMQ2KO98fSH 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 v4 3/5] i3c: dw: use parity8 helper instead of open coding it Date: Tue, 7 Jan 2025 10:02:01 +0100 Message-ID: <20250107090204.6593-4-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250107090204.6593-1-wsa+renesas@sang-engineering.com> References: <20250107090204.6593-1-wsa+renesas@sang-engineering.com> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Tue Jan 7 09:02:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 13928477 X-Patchwork-Delegate: geert@linux-m68k.org 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 7487C1E284C for ; Tue, 7 Jan 2025 09:02:14 +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=1736240538; cv=none; b=nO9BdHxQO7MfT3KUhaoOaL9WXLUhVWohEMDFqF2Yu11ka+gdoEm1aLDFI4Ib54OxXS1eq5WQij74NxthBuZoxzcf2E5IUI+QH6UYcShjh33HFHRqrEaWnRMvIxyM+QNdhPfhMKFEE8gRMd6sViwj6+ada/las7+/TQhEamF2GwA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736240538; c=relaxed/simple; bh=QiBIdouyIx1qglm/e/K6lcFhd3LVDevU6HqldZDWIGo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kd2tAR5WcNPwYFm8U1kDq6Pvc0xpe+1Enxgl2yXIS9G/+ogNSqYvhXyzl+TQk1dXDmocKKG0ZpAsMVPhXYGk0Q/0ShRggpJzAVNRiF/rjn+1bCrgu/Oczg3k716XJD/FzgxckSazjFSgI7AgYUHit2xAV612rzljSFIvXyUkQcs= 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=RbIUaH0X; 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="RbIUaH0X" 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=VK7WWM9T+jjQMMEJxB7ZW7cFigQlqgODHUPmKzMbE/g=; b=RbIUaH 0XwejCD8WqjEc6SDRvifpswXcjkZYtVds+fIXmMydw3hvyYgbeGNykY8yZbiogZd UQQs6CgUu6V979w5obR/HoZG4SoxUUMv5VvoWenv4pKj6Rdob/BLaIuO8gr3wvNI p8wS0aGQYm9m5cnXu+miiGtGCSR4KyciFx7dpyUhqKwcewneUdsEqhAz9Nmo3Msw QDCJ+319Ab3b+1O7PhvjE01N9LWLJyudwjdaMZItIhrGzca5H5BzwAl7p+Xc/Aj6 B8xIRXhzmtS0DDGYbNH4gVJGME9lZIucOYkNbjRob1HTTziYTZDB/dGOVHwOpK3x XB7YiretpcoD2m+Q== Received: (qmail 2125365 invoked from network); 7 Jan 2025 10:02:10 +0100 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 7 Jan 2025 10:02:10 +0100 X-UD-Smtp-Session: l3s3148p1@z1AGABorapMgAwDPXw20AOMQ2KO98fSH 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 v4 4/5] i3c: mipi-i3c-hci: use parity8 helper instead of open coding it Date: Tue, 7 Jan 2025 10:02:02 +0100 Message-ID: <20250107090204.6593-5-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250107090204.6593-1-wsa+renesas@sang-engineering.com> References: <20250107090204.6593-1-wsa+renesas@sang-engineering.com> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The kernel has now a generic helper for getting parity with easier to understand semantics. Make use of it. Here, it also fixes a bug because the correct algorithm is using XOR ('^=') instead of ADD ('+='). Signed-off-by: Wolfram Sang Tested-by: Jarkko Nikula --- Change since v3: * updated commit message to mention the bugfix I intentionally did not add a Fixes tag because this fix depends on patch 1. The proper fix for backporting would change this to XOR, I'd think. 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 Tue Jan 7 09:02:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 13928478 X-Patchwork-Delegate: geert@linux-m68k.org 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 212F81E3DE0 for ; Tue, 7 Jan 2025 09:02:16 +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=1736240541; cv=none; b=mhcrU5RUOHok2G4hZ9b0jyLhXh8o349UUm4iJSB8+AlrHEWHuwtDEeIAMVMvUy4WVqBRAEQZ9IWsNSMm0QtHCq8+cPn/huq+quDIK2//09L5FsPmKWgPnyix5wUmizGJEsBhLvO35jBq/3nhMB1hWQ+BjxP5zO7o64xXMdtIfoI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736240541; c=relaxed/simple; bh=6WBmBJ+wsYTTtFIZUHux4v1UVY1k3Ukb/r0cybJeNGo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e63t1OPUmYM2Bq5pfis2Nz+I+fhM2Y4scvpcL74HgdE1rYkvkkzoIyHMlPkaPvX8coZHlnTENfdGDNf23nz3MgQ+2uNHiHhawPt/HrbDEg30yXBZYPJGEvOjeHzJcHFpiNr56WEdqXwmIbrMWuXRUXe0Yi8MgsA8cjFkTri6N44= 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=Z8gPt1FW; 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="Z8gPt1FW" 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=Z8gPt1 FWquGr7BRS4yH7e39qM/9RQNxP5W+CQKEFLBf1HkzQv7Z8BEfHyfJrElCw8RIqZg cOSxR9iYey/DFG2RUVfNtsV/kEXhPcW4b1kDPr1KAPmRdIHH9qgKugNFJcu3dBGz SFkqyrrX0LdUUKna3mnWKVdAKanSjEQd5Zztg7XCisIuLNUnyBEsQvze/nabB2sA qzY8KGSn89fqw6zDHKEy8BNmnFd/eIraJ+oFNJpH8ZB5t1avPtV90enfFRqmclLI Z7J2bjMwED/ofK6IsQVei9HinikT1XI0ykdRp7xEKVhzHOHQCXtxbxHo5HPUfiNj Cv1+ZdsrBZyVt/Qg== Received: (qmail 2125387 invoked from network); 7 Jan 2025 10:02:10 +0100 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 7 Jan 2025 10:02:10 +0100 X-UD-Smtp-Session: l3s3148p1@oRcSABorbJMgAwDPXw20AOMQ2KO98fSH 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 v4 5/5] i3c: cdns: use parity8 helper instead of open coding it Date: Tue, 7 Jan 2025 10:02:03 +0100 Message-ID: <20250107090204.6593-6-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250107090204.6593-1-wsa+renesas@sang-engineering.com> References: <20250107090204.6593-1-wsa+renesas@sang-engineering.com> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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; }