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 70F4948592C; Fri, 16 Oct 2026 12:33:54 +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=1792154036; cv=none; b=j/7k/eitJf68+tDyFoOk0JQF4J7gKgmrCCVqxIjyW11fmnM/QcE9QIyMhFUZjAMKSZ7foXkX72vwTTL5Sefq0dXUrOtMlCxGiV+UJVdA8Xd34E3OtZyzxu020Lp7SN3mGXjn0X4Sfu4eG9TZHEd7Rv+Mmw4PQjIicYGqepowfTg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792154036; c=relaxed/simple; bh=bbEIh+X3HC5HCrHhNKiTKPkuVkNBY0tw3B8DCVeoxdY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=u+AF50u/FFO8uyoP2yQVL0wyP67B6gAcaxGCAZaQW+48SyyeJcM2rtSLAqOzvLHSE9uBKYJ/JzvHaqIRmYSbewk1NvuQOqFmtswvgXm+wbb3lVlpvaSlwwLgWLD4urQoKACP2+fbdiSggwdDJ9AXbtPBJLenDpG9YVLM9my9I1I= 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=m86mHs5p; 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="m86mHs5p" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1792154032; bh=bbEIh+X3HC5HCrHhNKiTKPkuVkNBY0tw3B8DCVeoxdY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=m86mHs5pb7CGwo5VzHJnWmPohYLbqwnYe02ulanmk9bRw8qTMFXoEr2lOK5jMp5f3 Xvls5hKSQ7J9QN7Cez+AZd6lfD+rKDEoplpERI+yUcDM1H/FsLPg8enWj/oFdNSOb0 HNgZr8RNggL1zEy1TQIQfvcuyhirB618IialmRhCRAlbeeV5U5i3eufOvFVeLMCSSm e22oJUWyR88a2CjKhCf9AZmX1D/rjaefGcOfcSOO/dfBJ/zo0de1H9P+38zXJJxpEV HAwkErKuzvpn78zW+C2z1mpwxz0PlglxpXlxxqE8+dhlELrcS++n9zkvSw28wL2j07 e/iJnQukXRrqQ== 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 D1E7C17E05D6; Fri, 16 Oct 2026 14:33:51 +0200 (CEST) From: Louis-Alexis Eyraud Date: Fri, 16 Oct 2026 14:33:12 +0200 Subject: [PATCH v14 20/23] 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: <20261016-mt8196-ufs-v14-20-e8d565e0cd45@collabora.com> References: <20261016-mt8196-ufs-v14-0-e8d565e0cd45@collabora.com> In-Reply-To: <20261016-mt8196-ufs-v14-0-e8d565e0cd45@collabora.com> To: Chunfeng Yun , Vinod Koul , Neil Armstrong , Manivannan Sadhasivam , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matthias Brugger , AngeloGioacchino Del Regno , Peter Wang , Chaotian Jing , Alim Akhtar , Bart Van Assche , Bean Huo , Stanley Jhu , Stanley Jhu , "James E.J. Bottomley" , "Martin K. Petersen" , Philipp Zabel , Liam Girdwood , Mark Brown 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=1792154009; l=4038; i=louisalexis.eyraud@collabora.com; s=20250113; h=from:subject:message-id; bh=5bLPVDNmIWfLbje8tieHKqNNl72wtwXs6ka6gdDYhco=; b=cxql22CMKbzRhPKfdOlqmCq9i4Y1I6MVGzmYf6gKIgOYV9jF+8SOon72JXt3FbJ3QWGNTSbKR aPvLKhoUm4sBkCac/LyKKQic6w508g52iwDOzQ7PfCwfOj7mf/UQICR 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 43b19179d024..328df4521a02 100644 --- a/drivers/ufs/host/ufs-mediatek.c +++ b/drivers/ufs/host/ufs-mediatek.c @@ -847,50 +847,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) @@ -1257,7 +1254,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.56.0