From mboxrd@z Thu Jan 1 00:00:00 1970 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 9E28DC54FDF for ; Thu, 30 Jul 2026 09:53:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=je4v04mcu2gtps1FRrMUtc2k+5hwSvuQjThYE2UIQlE=; b=s5h/RPFou5wSiKJ+5ZXtItQTPK sIRU/YNWj+nO4Pdx7PvkdGNm+s89gCD3+d1jYlAephkyVjM/FAP6EsfvJ/iCJvRFVGDBvWagk24Yz hr1deHxIfFYvwg20h7agIK9vSdQsUCCXJY4s5fSyxNl8u7yCRki1Ti4kHyZY6dM6gec5MJSaMAuQ0 QGOl3F6a2i1w4AM7gObAhXdMxWsF2cttY2xBE6BG0GdIHU+BxZLbOCUGlWf9/fwggnFamccBpOmt/ CfCki/IcSZ6oLZPijCTZHhg1YSg2QsCqwsj5J2X3frYJqTX92NiY/nWYvGVkQ7r/BZHWgdDL5MCZd 8fVbI4NQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wpNRx-0000000A5et-2abR; Thu, 30 Jul 2026 09:53:13 +0000 Received: from bali.collaboradmins.com ([148.251.105.195]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wpNPG-0000000A3ga-0qSv; Thu, 30 Jul 2026 09:50:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1785405024; bh=bgu/KwI3G3X8GZS8sun3AS8LU9HKFM+Lh2qCn8+SwpQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=RV5hxyXflQ4aTZeyPLIH+gfJJ02mQVf6ot/KTyhT+ivt3zMvkN7uhkEm0vvI9I2la ONLH2iL3CY/eVpf2BBZnE/x/p0R9V+kDZA2QgSVOJD/tsJ5Jxz0qYOnVEArZg3eeGt nfTmBZxchBbvAUSvAqytOaMCM52SC+vYVoQoD/ZWJELsv4EMevB/NhkQUt2tZE14Qf 3F9nQpqMiWhTjklwdd6I41IXsX/1b4fS65WlVc1kT9BEoeCne0McHPp3JWfFk8+ekC hagsnR2i9pPbRzYksCcrBcOM+G+tVtCvOGkJbZAQnw3csXtkosW2FM9/Dh2ozmcsvv rwOAC7oftZRcQ== 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 E3A0017E0966; Thu, 30 Jul 2026 11:50:22 +0200 (CEST) From: Louis-Alexis Eyraud Date: Thu, 30 Jul 2026 11:49:15 +0200 Subject: [PATCH v10 19/26] scsi: ufs: mediatek: Rework hardware version reading MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260730-mt8196-ufs-v10-19-bc5ecef202dc@collabora.com> References: <20260730-mt8196-ufs-v10-0-bc5ecef202dc@collabora.com> In-Reply-To: <20260730-mt8196-ufs-v10-0-bc5ecef202dc@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" , "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=1785404993; l=4038; i=louisalexis.eyraud@collabora.com; s=20250113; h=from:subject:message-id; bh=vvZBUfGhF8GqLpVwK0ApC5UyBXgOdyjlgOXN1LjN1Mw=; b=8TuUgV2tAPFsA0X5KIuPYkH1C5/kDmgGNYlzcIxY2RjtOad7vDg8T8bjKs8Ys9Z5TToRx/BD2 ZujD2zTS2xYDPRQQpKzcnP/Y5K+X07iLSeriawE1GC35TEyNBOvadyA X-Developer-Key: i=louisalexis.eyraud@collabora.com; a=ed25519; pk=CHFBDB2Kqh4EHc6JIqFn69GhxJJAzc0Zr4e8QxtumuM= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260730_025026_446930_8863F502 X-CRM114-Status: GOOD ( 14.67 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 8214cf0b3a16..c784ecb30e74 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_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) @@ -1191,7 +1188,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