From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (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 9C92A457E5C; Mon, 14 Sep 2026 11:39:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.105.195 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789385989; cv=none; b=tvqGCZTHQ9yJWpzNVE9phL2EYpisOul0jOWNVRfa6pWldLQjuP7WogjUqgi4T75XK5bgqEebc9Zudv/4ZyQZ0HQAZe/H+Lh4E7XVv6rVkxtMpsSNT/bbXbQT+R45Nfj4pgXcDMKF6qq1bcglNYYAEeGeoVvHXtNg8uIlGnOuhTM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789385989; c=relaxed/simple; bh=MDaT0JEa8hdjv+7ukEcc+FwhW/uIYm4dVdNDr2gKzEI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UASV7lPheuNc8O3bFFsgoF+4kH4isjNYxFGxdZ4NmROlMldy/GIH24NOHiccpAtrdIxnhDA3CdPimllFLf4SMkJzQGtHtf1YLpuqCD/wmpmx2N522i+2vyySKe8uadn4wJc62XpDP/3wsz9bwsgL5R7XtDwEae6kdIfHEFJ+Wco= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=CGxQnX+x; arc=none smtp.client-ip=148.251.105.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="CGxQnX+x" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1789385985; bh=MDaT0JEa8hdjv+7ukEcc+FwhW/uIYm4dVdNDr2gKzEI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=CGxQnX+x3EQLG72rWkl6LXfvaVY4fxQ6c/BHzBtfKonPAwNQJg3JxmSNFIXjv6jeL /CZRV21xnnJJNk8hJJ1YE9uHoxVXI5qfL4/Nr2aF7UzlI2+V8n+tN1PIs4iP5vDkAT rMn4GCNTg3JYglq5SpYESQXTjHzEz5i3ywhbKk7OVigjXEcI5QXdp5YJltzO3r69fP fM00lpW4VTc1PI2hqSjxxCldV5xnDj8NNkRTS1fK1/vUAG/yfo8IutsG6sd5P2vkhI RBSmH8dMu8MHbs/LOjVE+l3hzMX8IJLMVBqbgaqxJMi9uHlz9TxdywUCer8I3wNTKH cC1HihELafKqg== Received: from yukiji.home (unknown [100.64.0.131]) (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) (No client certificate requested) (Authenticated sender: laeyraud) by bali.collaboradmins.com (Postfix) with ESMTPSA id 23B6B17E0CA0; Mon, 14 Sep 2026 13:39:44 +0200 (CEST) From: Louis-Alexis Eyraud Date: Mon, 14 Sep 2026 13:39:06 +0200 Subject: [PATCH v12 20/24] scsi: ufs: mediatek: Rework hardware version reading Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260914-mt8196-ufs-v12-20-9279d7ef814d@collabora.com> References: <20260914-mt8196-ufs-v12-0-9279d7ef814d@collabora.com> In-Reply-To: <20260914-mt8196-ufs-v12-0-9279d7ef814d@collabora.com> To: Chunfeng Yun , Vinod Koul , Neil Armstrong , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matthias Brugger , AngeloGioacchino Del Regno , Peter Wang , Chaotian Jing , Alim Akhtar , Avri Altman , Bart Van Assche , Stanley Jhu , "James E.J. Bottomley" , Philipp Zabel , Liam Girdwood , Mark Brown , Manivannan Sadhasivam , "Martin K. Petersen" Cc: kernel@collabora.com, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-phy@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, Nicolas Frattaroli , Louis-Alexis Eyraud X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1789385943; l=4038; i=louisalexis.eyraud@collabora.com; s=20250113; h=from:subject:message-id; bh=iMniswtHRkz52bS2IOsc2MukEzn1RAz2enUpB9VPkFo=; b=WeTrExNXCU6X8wnMjfVyVt21WlHM2Pj18MpkRDmXLGyNGcHPFpmlMeXStjWkC4oNZTFg6lwms huKGQ5wx383CI7e/oaYw6Ne+ivqL8D4ACzQ12NQOX4KWA63LpX412Zm X-Developer-Key: i=louisalexis.eyraud@collabora.com; a=ed25519; pk=CHFBDB2Kqh4EHc6JIqFn69GhxJJAzc0Zr4e8QxtumuM= From: Nicolas Frattaroli Split assignment to the host struct out from the read function, and utilise bitfield helpers to simplify the code. Also move the debug print out of the legacy version helper, which means it no longer has to take a struct ufs_hba as an input, and can be rewritten as a pure function. Reviewed-by: AngeloGioacchino Del Regno Reviewed-by: Peter Wang Signed-off-by: Nicolas Frattaroli Signed-off-by: Louis-Alexis Eyraud --- drivers/ufs/host/ufs-mediatek.c | 65 +++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/drivers/ufs/host/ufs-mediatek.c b/drivers/ufs/host/ufs-mediatek.c index b599e9f4624e..fc42e6baa47d 100644 --- a/drivers/ufs/host/ufs-mediatek.c +++ b/drivers/ufs/host/ufs-mediatek.c @@ -834,50 +834,47 @@ static void ufs_mtk_mcq_set_irq_affinity(struct ufs_hba *hba, unsigned int cpu) dev_dbg(hba->dev, "set irq %d affinity to CPU %d\n", irq, _cpu); } -static bool ufs_mtk_is_legacy_chipset(struct ufs_hba *hba, u32 hw_ip_ver) +static bool __pure ufs_mtk_is_legacy_chipset(u32 hw_ip_ver) { - bool is_legacy = false; - switch (hw_ip_ver) { case IP_LEGACY_VER_MT6893: case IP_LEGACY_VER_MT6781: /* can add other legacy chipset ID here accordingly */ - is_legacy = true; - break; - default: - break; + return true; } - dev_dbg(hba->dev, "IP version 0x%x, legacy = %s", hw_ip_ver, - str_true_false(is_legacy)); - return is_legacy; + return false; } -/* - * HW version format has been changed from 01MMmmmm to 1MMMmmmm, since - * project MT6878. In order to perform correct version comparison, - * version number is changed by SW for the following projects. - * IP_VER_MT6983 0x00360000 to 0x10360000 - * IP_VER_MT6897 0x01440000 to 0x10440000 - * IP_VER_MT6989 0x01450000 to 0x10450000 - * IP_VER_MT6991 0x01460000 to 0x10460000 +#define MTK_UFS_VER_PREFIX_M GENMASK(31, 24) + +/** + * ufs_mtk_get_hw_ip_version - read and return adjusted hardware version + * @hba: pointer to this device's &struct ufs_hba + * + * Reads, transforms and returns the hardware version. + * + * Since MT6878, the versioning scheme was changed from 01MMmmmm to 1MMMmmmm. + * In order to support version comparisons across these different versioning + * schemes, this function transforms the older style to the newer one. + * + * For example: + * MT6983 is transformed from 0x00360000 to 0x10360000 + * MT6897 is transformed from 0x01440000 to 0x10440000 + * MT6989 is transformed from 0x01450000 to 0x10450000 + * MT6991 is transformed from 0x01460000 to 0x10460000 + * + * Returns a u32 representing the hardware version. */ -static void ufs_mtk_get_hw_ip_version(struct ufs_hba *hba) +static u32 ufs_mtk_get_hw_ip_version(struct ufs_hba *hba) { - struct ufs_mtk_host *host = ufshcd_get_variant(hba); - u32 hw_ip_ver; + u32 version = ufshcd_readl(hba, REG_UFS_MTK_IP_VER); + u32 prefix = FIELD_GET(MTK_UFS_VER_PREFIX_M, version); - hw_ip_ver = ufshcd_readl(hba, REG_UFS_MTK_IP_VER); + if (prefix <= 1) + FIELD_MODIFY(MTK_UFS_VER_PREFIX_M, &version, 0x10); - if (((hw_ip_ver & (0xFF << 24)) == (0x1 << 24)) || - ((hw_ip_ver & (0xFF << 24)) == 0)) { - hw_ip_ver &= ~(0xFF << 24); - hw_ip_ver |= (0x1 << 28); - } - - host->ip_ver = hw_ip_ver; - - host->legacy_ip_ver = ufs_mtk_is_legacy_chipset(hba, hw_ip_ver); + return version; } static void ufs_mtk_get_controller_version(struct ufs_hba *hba) @@ -1242,7 +1239,11 @@ static int ufs_mtk_init(struct ufs_hba *hba) ufs_mtk_setup_clocks(hba, true, POST_CHANGE); - ufs_mtk_get_hw_ip_version(hba); + host->ip_ver = ufs_mtk_get_hw_ip_version(hba); + host->legacy_ip_ver = ufs_mtk_is_legacy_chipset(host->ip_ver); + + dev_dbg(hba->dev, "IP version 0x%x, legacy = %s", host->ip_ver, + str_true_false(host->legacy_ip_ver)); return 0; -- 2.55.0