Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2991641rdb; Tue, 6 Feb 2024 04:11:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IEIUS1jo32NuR/iB6B/WvVJDKxfa5nSu2rTs4p2FNPKj2KhDaDO5ngw5uzMuFtSV5Gr+olY X-Received: by 2002:a17:902:c405:b0:1d9:c04c:dfc1 with SMTP id k5-20020a170902c40500b001d9c04cdfc1mr1635513plk.59.1707221514142; Tue, 06 Feb 2024 04:11:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707221514; cv=pass; d=google.com; s=arc-20160816; b=sAIK3cOY3o0RntVhpA+cYXN2uNn9KOBWiZZzLzDQWxk14mfKqOeg33hUbmGB/+VVLL Vd4kSwVnGHTcMwGL6I22NOVGLVxXeDNhlEu1j7yYSi5YcjUIfklAoek8WsYiOdRL0g01 E6GGcJ6qEtAOJRTaJC2shFjlejjliFbO15GhwOaXPQVJVH7yfMES814c1x5X8ERDUKj5 EK06ThITeovF7MfUD3zlOubF9aknQWOhqeWPYSGKxbpCiOXq0ISGqlnJn0xU7p2ZQ/fd a+HVPMe2EtM5IeX8JSReGvUPrihhKUEfEo3m78ooKUiIAA/0oDwx9uFT4lyFaknvjiTc aLGA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=D2Wkj5C546fpT8jt76En1QyD6W14LyKR7LAOg34wM3A=; fh=JeUSsT9n+2KL18uJbFus6VAs6sXkTvwKg0F2krhrRfo=; b=u4mL58MPbkhozXB7tSi9GPKYQ4KkMyay00WMYLJ1NrDTqhlCGuD/fj6aVuyd1l5LEK +y4zn/WwsyQBr/7FshS2KLUhA1EhcYXEIL8Qa4DLeVLPNA7XeoaulIOdejmHZL3K5v5e nl37nscTYN/FiT8Imz+b4GK73GNwjQ2CORwQxegMEAEXOLy7ADT8vMsZ26XkIyqQXKcI 6GaXGrMz432RxEJL2jGYd/REI4aW+7AuRnHOHqkXIkdG2bWLw9XWHtGcIr9/IDMfFVmr XZCGEmvRy5WeabuNGS19ZHAftFY9P8InMNAHGhzLABW/OziT3rLCZVzrqcbwXkLuhAzW 2/Ug==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=ovKTn1GK; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-54866-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54866-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com X-Forwarded-Encrypted: i=1; AJvYcCVn09ARvIxi/hHwMx4TXGTqLxp2J90pIQf2avywlhsBU4lwObIOjQhHOp8jkZC0hbPVOub3Z4HBXWk/+s5SLBA9Sje/JYmgikkhg9iBUg== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id j15-20020a170903024f00b001d8aac2072csi1594239plh.172.2024.02.06.04.11.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:11:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54866-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=ovKTn1GK; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-54866-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54866-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id A65682821B0 for ; Tue, 6 Feb 2024 12:11:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E6F92131E2E; Tue, 6 Feb 2024 12:08:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="ovKTn1GK" Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (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 ADAC8130AE9 for ; Tue, 6 Feb 2024 12:08:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221292; cv=none; b=WQjcXqEUAnvtBtfPnu6crIWmW/XkpovqRuKKwgwCoMkyAGxesEWerorxMpCaevCZZwoibEfFV2qt5CwE7izemjt8TQeKxTW8aNJH+Tws+uG1mCBcrCk2xrdmdo2IojGGXTOE5cMB/3qHHJCaVKiq7pH3LmTbEoNi0K2Opw5/HqI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221292; c=relaxed/simple; bh=VDX7AhydHRhOSNhBFLKBelqucKRnbrmvRDj7DrUlgD0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U31a/qfg0OjZSztT/PKVBxGCbSQoiAhuhxShr8yu2/kyF4fhA9stmUTKVsjUecEbFPomAV8aYrKeHgGORR1T7hZs2/3vVJod7F/yS8bbL6L/K8QHfGyXgfwTnMRGBOwpgM0oasGAsF86+yCvTHCUajFI2pTIaPo2hTCmzMuHz8Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=ovKTn1GK; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1707221281; bh=VDX7AhydHRhOSNhBFLKBelqucKRnbrmvRDj7DrUlgD0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ovKTn1GKOsdkDSM+//FcNhut09sz3Y7AB4VMOlss3fZuDyOJlgSLR7BO0W31sAuaf /HRQf1sKvXb/0Pcgfgz6zPapjGDbA4gAXZjJBe+hBdosMqJ0tXXWwS+olIZ3xvvjqV SiWZ0XcpY+Ekt1+ImYNbsUW8onjPDewkEF4ynIHvpQkIF2TcnkZi/aZW3UeFS1cOa/ L2r7FSNTkn5WG+8jiPanSXTWS5VuHkQSa7x2MkkjjFunxk0vtqBOYo7924Ec2G89kQ 7/5rmw0XDsx0vphhDY+9ybiU8fk2A1esKbiB6EQu7IFrvNADy1XmqvdUNLLtJHzKIW myMD7PJXK4bow== Received: from IcarusMOD.eternityproject.eu (cola.collaboradmins.com [195.201.22.229]) (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: kholk11) by madrid.collaboradmins.com (Postfix) with ESMTPSA id DEAB63781F8E; Tue, 6 Feb 2024 12:08:00 +0000 (UTC) From: AngeloGioacchino Del Regno To: chunkuang.hu@kernel.org Cc: fshao@chromium.org, p.zabel@pengutronix.de, airlied@gmail.com, daniel@ffwll.ch, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, dri-devel@lists.freedesktop.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@collabora.com Subject: [PATCH v4 9/9] drm/mediatek: dsi: Use mipi_dsi_pixel_format_to_bpp() helper function Date: Tue, 6 Feb 2024 13:07:48 +0100 Message-ID: <20240206120748.136610-10-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240206120748.136610-1-angelogioacchino.delregno@collabora.com> References: <20240206120748.136610-1-angelogioacchino.delregno@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Instead of open coding, use the mipi_dsi_pixel_format_to_bpp() helper function from drm_mipi_dsi.h in mtk_dsi_poweron() and for validation in mtk_dsi_bridge_mode_valid(). Note that this function changes the behavior of this driver: previously, in case of unknown formats, it would (wrongly) assume that it should account for a 24-bits format - now it will return an error and refuse to set clocks and/or enable the DSI. This is done because setting the wrong data rate will only produce a garbage output that the display will misinterpret both because this driver doesn't actually provide any extra-spec format support and/or because the data rate (hence, the HS clock) will be wrong. Signed-off-by: AngeloGioacchino Del Regno --- drivers/gpu/drm/mediatek/mtk_dsi.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_dsi.c b/drivers/gpu/drm/mediatek/mtk_dsi.c index 545c5cc071d9..d844a0500e2b 100644 --- a/drivers/gpu/drm/mediatek/mtk_dsi.c +++ b/drivers/gpu/drm/mediatek/mtk_dsi.c @@ -598,19 +598,12 @@ static int mtk_dsi_poweron(struct mtk_dsi *dsi) if (++dsi->refcount != 1) return 0; - switch (dsi->format) { - case MIPI_DSI_FMT_RGB565: - bit_per_pixel = 16; - break; - case MIPI_DSI_FMT_RGB666_PACKED: - bit_per_pixel = 18; - break; - case MIPI_DSI_FMT_RGB666: - case MIPI_DSI_FMT_RGB888: - default: - bit_per_pixel = 24; - break; + ret = mipi_dsi_pixel_format_to_bpp(dsi->format); + if (ret < 0) { + dev_err(dev, "Unknown MIPI DSI format %d\n", dsi->format); + return ret; } + bit_per_pixel = ret; dsi->data_rate = DIV_ROUND_UP_ULL(dsi->vm.pixelclock * bit_per_pixel, dsi->lanes); @@ -793,12 +786,11 @@ mtk_dsi_bridge_mode_valid(struct drm_bridge *bridge, const struct drm_display_mode *mode) { struct mtk_dsi *dsi = bridge_to_dsi(bridge); - u32 bpp; + int bpp; - if (dsi->format == MIPI_DSI_FMT_RGB565) - bpp = 16; - else - bpp = 24; + bpp = mipi_dsi_pixel_format_to_bpp(dsi->format); + if (bpp < 0) + return MODE_ERROR; if (mode->clock * bpp / dsi->lanes > 1500000) return MODE_CLOCK_HIGH; -- 2.43.0