From nobody Sat Feb 7 06:35:26 2026 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (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 4CC4E3EBF01; Sat, 24 Jan 2026 12:04:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769256254; cv=pass; b=XqvIVp7OepuujYc3FG3DRk7Pp/nUKRXLFtS7XpapDCqlHuWG3yNwCbc7u++K3ph9sD/F6zhdjkBg1pDVkTYrNun0MnOiD+rMgro8AqY/mfTNDtlVy84/q4Vdsl3aNXFBounpawNBzC3sxy5ZA1WR9xlC5XIafZaY7tNuwIRhm74= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769256254; c=relaxed/simple; bh=SpGeLpEgyM07xuob8S2lBFWXcQOp0Zuis5EE9dPmPLs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WTwVh1xQ9dQExT2Icnqt2IiBEIlHc8G7hZK8chsaRKPkNOjflquRinqZ8L5mJCoIWR5bUvx63MmdiXmVkavtRtOeCUNNejgopbZ3jtfsDm5JpEn1XuY4Y4JPlnvMWnCUGgzxWulGtjTY1E9aOQ1nI6JVH1PE2v3ugJA4nQYygj0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (1024-bit key) header.d=collabora.com header.i=nicolas.frattaroli@collabora.com header.b=dDEGlqS+; arc=pass smtp.client-ip=136.143.188.112 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 (1024-bit key) header.d=collabora.com header.i=nicolas.frattaroli@collabora.com header.b="dDEGlqS+" ARC-Seal: i=1; a=rsa-sha256; t=1769256201; cv=none; d=zohomail.com; s=zohoarc; b=Bf/ocmWs9HP1P9OtBWNHkhKeeFJvpmRI8YvlzsbNb58YepZiz4uiBx1trH8DCupPehRMeHVILNawq0rZlg1li4zVecYWlnmvqVwr3c3S3BswNZQUWWoeSPx7Wvnh0a3tVq4XPqb6AyK2xVGcBNosFfSup18NKHZJtoB+FIOTNJI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769256201; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=65V7XTs18HNx4Cpt1KEkw3iYodmNCBJ2fw83o85Cefk=; b=dGFb8M04Lr+BIY0VXJLU5aW/neMnTiWxJMCHKvyLLzdhvUYUDhYOhOSKtvczgJ4a1lESP2/R8SjmCgIIN1GA0fuPQPBgETRkjdTZAsHySZ7CitLWR0yNOCIfKtsM0dhXEYMU2kDqYjgNR9gHW2VGpORgdJoEF/+Nvdn7+yd2MnA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=nicolas.frattaroli@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1769256201; s=zohomail; d=collabora.com; i=nicolas.frattaroli@collabora.com; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:References:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=65V7XTs18HNx4Cpt1KEkw3iYodmNCBJ2fw83o85Cefk=; b=dDEGlqS+yJT0WMoShXq5kG57clbT6aytISf8hq6yDtKi/SSu1unt7au43kLNfVac U6NeVzjBLC6JrT/zPB3oGu1ehTFaK8jwAZOpta+s4wjTq+EovAmJ1Ns8cVU9rdC6C+3 MH6Ge4atiydsM5uNssnh/S0Sq2tdtCAJ3RJ7b4VA= Received: by mx.zohomail.com with SMTPS id 1769256200138453.012233039315; Sat, 24 Jan 2026 04:03:20 -0800 (PST) From: Nicolas Frattaroli Date: Sat, 24 Jan 2026 13:01:06 +0100 Subject: [PATCH v6 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: quoted-printable Message-Id: <20260124-mt8196-ufs-v6-20-e7c005b60028@collabora.com> References: <20260124-mt8196-ufs-v6-0-e7c005b60028@collabora.com> In-Reply-To: <20260124-mt8196-ufs-v6-0-e7c005b60028@collabora.com> To: Alim Akhtar , Avri Altman , Bart Van Assche , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matthias Brugger , AngeloGioacchino Del Regno , Chunfeng Yun , Vinod Koul , Kishon Vijay Abraham I , Peter Wang , Stanley Jhu , "James E.J. Bottomley" , "Martin K. Petersen" , Philipp Zabel , Liam Girdwood , Mark Brown , Chaotian Jing , Neil Armstrong Cc: Louis-Alexis Eyraud , kernel@collabora.com, linux-scsi@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-phy@lists.infradead.org, Nicolas Frattaroli X-Mailer: b4 0.14.3 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 Signed-off-by: Nicolas Frattaroli --- 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-mediate= k.c index e39412d59847..ee677af6c700 100644 --- a/drivers/ufs/host/ufs-mediatek.c +++ b/drivers/ufs/host/ufs-mediatek.c @@ -797,50 +797,47 @@ static void ufs_mtk_mcq_set_irq_affinity(struct ufs_h= ba *hba, unsigned int cpu) dev_dbg(hba->dev, "set irq %d affinity to CPU %d\n", irq, _cpu); } =20 -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 =3D 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 =3D true; - break; - default: - break; + return true; } - dev_dbg(hba->dev, "IP version 0x%x, legacy =3D %s", hw_ip_ver, - str_true_false(is_legacy)); =20 - return is_legacy; + return false; } =20 -/* - * 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 (0xFF << 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 1MMMmm= mm. + * In order to support version comparisons across these different versioni= ng + * 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 =3D ufshcd_get_variant(hba); - u32 hw_ip_ver; + u32 version =3D ufshcd_readl(hba, REG_UFS_MTK_IP_VER); + u32 prefix =3D FIELD_GET(MTK_UFS_VER_PREFIX_M, version); =20 - hw_ip_ver =3D ufshcd_readl(hba, REG_UFS_MTK_IP_VER); + if (prefix <=3D 1) + FIELD_MODIFY(MTK_UFS_VER_PREFIX_M, &version, BIT(28)); =20 - if (((hw_ip_ver & (0xFF << 24)) =3D=3D (0x1 << 24)) || - ((hw_ip_ver & (0xFF << 24)) =3D=3D 0)) { - hw_ip_ver &=3D ~(0xFF << 24); - hw_ip_ver |=3D (0x1 << 28); - } - - host->ip_ver =3D hw_ip_ver; - - host->legacy_ip_ver =3D ufs_mtk_is_legacy_chipset(hba, hw_ip_ver); + return version; } =20 static void ufs_mtk_get_controller_version(struct ufs_hba *hba) @@ -1191,7 +1188,11 @@ static int ufs_mtk_init(struct ufs_hba *hba) =20 ufs_mtk_setup_clocks(hba, true, POST_CHANGE); =20 - ufs_mtk_get_hw_ip_version(hba); + host->ip_ver =3D ufs_mtk_get_hw_ip_version(hba); + host->legacy_ip_ver =3D ufs_mtk_is_legacy_chipset(host->ip_ver); + + dev_dbg(hba->dev, "IP version 0x%x, legacy =3D %s", host->ip_ver, + str_true_false(host->legacy_ip_ver)); =20 return 0; =20 --=20 2.52.0