Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2632447rdg; Mon, 16 Oct 2023 09:57:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHTwArtLYOpjl+VZS6qHo75FkJ8+r9fHh/R5HEYVmKuoCS7B7iYxfbneGDP6faJt9dzh8aJ X-Received: by 2002:a05:6830:1459:b0:6b9:3f64:4e8c with SMTP id w25-20020a056830145900b006b93f644e8cmr39860760otp.9.1697475466784; Mon, 16 Oct 2023 09:57:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697475466; cv=none; d=google.com; s=arc-20160816; b=SHycimwaZssJHUzdyL7Bb8QLT97oyYIRaZ0yxsI5PFAnzXkr7urmrLZF5cBZeHBQ2w pmPo1uweIsOnjhR0mr/dGMNumBImXzDO/gv5KV25Z6jWa8jMWv3FJfGvUIGHSqXz6NlF cnAb8Y8gv0B7J1LfoZBORE0z69waUZ/qP8Mf42yS5l6Cj0qopt3QV+kdWIRtGhXy4CYV F+ulpw+dott8nU3fng0DZbdICT1CncK9GiHIOo7rBKo5mEkmAYQweg9il5N7kgybr1UZ dYhlpcDRQouhITQ3Ni8tOrptXZ9aSlMIecmhCgJS4htvesLR0vGx4wuS9Pkoe4EOOUL3 WVig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jimH2tfDdFWkB0SZHBV7Ktkx0rri8vXGCD3VUxA9GeA=; fh=OT/8nNJKNCzw+WY7QnVxvWUM5gQckqwqCjGb4xh5RlI=; b=vhOAI106+u9kTHOiEVX3Q4GVdzPOPWkaFY3JlhmhJ+UkBxkpo6gzWkM+0Gq3z93Taa y7lLBDXPQkdsHyq3oLHEPnX9YkrBqQc977Kg+ircs0Ilgh+smIAysHRC+664lVpckXte cuXsUjT/NIxGPWV0XSCp22YqP1CeiYQqbOrPeW67DQ7/8WDndLjymcx7QB9SFMjh/9OQ ZCeODW+ppqumUNdDGcu05TaXfZqKhvn7LxjfcQwie1thAyp9Q7XeD5QCGgYNja0hRexw ZrqNzs9CGBfziCIIdBYQu8boYQLxfDefShhhod4AcW7qvlujTVInkbkjnp/v3+yB4V06 BVkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yHjvUQmx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id u11-20020a056a00124b00b006be1fc3ee73si193069pfi.358.2023.10.16.09.57.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 09:57:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yHjvUQmx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id A559E8021201; Mon, 16 Oct 2023 09:57:43 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234422AbjJPQ53 (ORCPT + 99 others); Mon, 16 Oct 2023 12:57:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234011AbjJPQ4l (ORCPT ); Mon, 16 Oct 2023 12:56:41 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B72F5262A for ; Mon, 16 Oct 2023 09:54:08 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-40684f53bfcso44071585e9.0 for ; Mon, 16 Oct 2023 09:54:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697475247; x=1698080047; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jimH2tfDdFWkB0SZHBV7Ktkx0rri8vXGCD3VUxA9GeA=; b=yHjvUQmxK1Kaums4YIdQCsa+OqESqk8P3PMH/OCkPUkgHlLNyJj39LqHFyVwGiHAMc qy3dMopCMCLyt1sYYCVnuqH7VsdaOaHJVvXasX+YeeUnGxJnxmptHWyjS2dm+1e1ucVL dxHKa7IiJZ1y1W3Xx+FpxVmcau4drvMksrYP8ceWYE8iN001oumg/2wdPPFOfE3gt8QY jClpyoP6+ITv05o++JvjzzANcaZaL3w79wltt2fdYd4I77e+IErkdASD4IbcQkxaQ7uJ 8dEwyIRu+FgbkUbga3nFxlfXlUZxG1r7MKwfVV0t0OCToLwrzMC/JHyIW6BX1FRgYJHf Ga4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697475247; x=1698080047; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jimH2tfDdFWkB0SZHBV7Ktkx0rri8vXGCD3VUxA9GeA=; b=NojH5VX6Gw6/1gxN8nlczLJXmCHb8Zi+1D2qLNYrExQiQNnlSFQMIrQG5Nc+9GuAtO uzbtWE7z5ep6QS74tp7gDWsfZMMowxwfqzme/Kdx+8evvvSxmjbESFsiAgVZgmGt1E1P Di8AqrJ1UdOnDMFLV2sM429HHblVy/CZlR9TivmcNi3g8bmsFNJDsLC1qisloTxkTbMS E76Y4oE1We8ldXezDwQFN5H3eXtY98ufMXxwISzfmOFtFvNp3BVwXJpgk84AT9optc0+ gzsg4SOjn4M17yKTdjKKxib3So1SUSGXosBrW9esGYEJO5oRMUISXeFslfZum/zSKkCk b3iQ== X-Gm-Message-State: AOJu0YzxclZYBw+t+rXIuBTpsdpb0ANtaNXUwaNpGjztU6NLDCR21M+l wGsnSMzewfqcaCkc3pgcMwl/1w== X-Received: by 2002:a05:600c:2a4e:b0:405:49aa:d578 with SMTP id x14-20020a05600c2a4e00b0040549aad578mr30626127wme.37.1697475247221; Mon, 16 Oct 2023 09:54:07 -0700 (PDT) Received: from eriador.lumag.spb.ru ([45.84.211.189]) by smtp.gmail.com with ESMTPSA id s19-20020a05600c45d300b0040648217f4fsm7638996wmo.39.2023.10.16.09.54.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 09:54:06 -0700 (PDT) From: Dmitry Baryshkov To: Dave Stevenson , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Douglas Anderson , Rob Clark , Abhinav Kumar , Dmitry Baryshkov , Sean Paul , Marijn Suijten , Konrad Dybcio , Jessica Zhang Cc: Marek Vasut , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org Subject: [RFC PATCH 05/10] drm/msm/dsi: implement manual power control Date: Mon, 16 Oct 2023 19:53:50 +0300 Message-ID: <20231016165355.1327217-6-dmitry.baryshkov@linaro.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016165355.1327217-1-dmitry.baryshkov@linaro.org> References: <20231016165355.1327217-1-dmitry.baryshkov@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 16 Oct 2023 09:57:43 -0700 (PDT) Implement new API for tight control over the DSI link's power state. This allows bridge and panel drivers to send DSI commands at a proper time. Note, this also brings back the ps8640 workaround (to be removed later, once ps8640 driver sets up the MIPI_DSI_MANUAL_POWERUP flag).. We have to make sure that the DSI link stays disabled in case of this bridge, otherwise it will not work. Signed-off-by: Dmitry Baryshkov --- drivers/gpu/drm/msm/dsi/dsi.h | 4 ++ drivers/gpu/drm/msm/dsi/dsi_host.c | 44 +++++++++++++++++ drivers/gpu/drm/msm/dsi/dsi_manager.c | 68 +++++++++++++++++++++++---- 3 files changed, 106 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/msm/dsi/dsi.h b/drivers/gpu/drm/msm/dsi/dsi.h index a01c326774a6..e0ae2cb144de 100644 --- a/drivers/gpu/drm/msm/dsi/dsi.h +++ b/drivers/gpu/drm/msm/dsi/dsi.h @@ -63,6 +63,8 @@ bool msm_dsi_manager_cmd_xfer_trigger(int id, u32 dma_base, u32 len); int msm_dsi_manager_register(struct msm_dsi *msm_dsi); void msm_dsi_manager_unregister(struct msm_dsi *msm_dsi); void msm_dsi_manager_tpg_enable(void); +int msm_dsi_manager_power_up(int id); +void msm_dsi_manager_power_down(int id); /* msm dsi */ static inline bool msm_dsi_device_connected(struct msm_dsi *msm_dsi) @@ -108,6 +110,8 @@ void msm_dsi_host_get_phy_clk_req(struct mipi_dsi_host *host, void msm_dsi_host_destroy(struct mipi_dsi_host *host); int msm_dsi_host_modeset_init(struct mipi_dsi_host *host, struct drm_device *dev); +bool msm_dsi_host_auto_powerup(struct mipi_dsi_host *host); +bool msm_dsi_host_early_powerup(struct mipi_dsi_host *host); int msm_dsi_host_init(struct msm_dsi *msm_dsi); int msm_dsi_runtime_suspend(struct device *dev); int msm_dsi_runtime_resume(struct device *dev); diff --git a/drivers/gpu/drm/msm/dsi/dsi_host.c b/drivers/gpu/drm/msm/dsi/dsi_host.c index fd2201cb62db..7010a6f17c5f 100644 --- a/drivers/gpu/drm/msm/dsi/dsi_host.c +++ b/drivers/gpu/drm/msm/dsi/dsi_host.c @@ -1671,10 +1671,54 @@ static ssize_t dsi_host_transfer(struct mipi_dsi_host *host, return ret; } +static bool msm_dsi_host_manual_powerup(struct mipi_dsi_host *host) +{ + struct msm_dsi_host *msm_host = to_msm_dsi_host(host); + + return msm_host->mode_flags & MIPI_DSI_MANUAL_POWERUP; +} + +bool msm_dsi_host_auto_powerup(struct mipi_dsi_host *host) +{ + struct msm_dsi_host *msm_host = to_msm_dsi_host(host); + + return msm_host->mode_flags & MIPI_DSI_AUTO_POWERUP; +} + +bool msm_dsi_host_early_powerup(struct mipi_dsi_host *host) +{ + struct msm_dsi_host *msm_host = to_msm_dsi_host(host); + + return !msm_dsi_host_manual_powerup(host) && + !msm_dsi_host_auto_powerup(host); +} + +static int msm_dsi_host_power_up(struct mipi_dsi_host *host) +{ + struct msm_dsi_host *msm_host = to_msm_dsi_host(host); + + if (msm_dsi_host_auto_powerup(host)) + return 0; + + return msm_dsi_manager_power_up(msm_host->id); +} + +static void msm_dsi_host_power_down(struct mipi_dsi_host *host) +{ + struct msm_dsi_host *msm_host = to_msm_dsi_host(host); + + if (!msm_dsi_host_manual_powerup(host)) + return; + + msm_dsi_manager_power_down(msm_host->id); +} + static const struct mipi_dsi_host_ops dsi_host_ops = { .attach = dsi_host_attach, .detach = dsi_host_detach, .transfer = dsi_host_transfer, + .power_up = msm_dsi_host_power_up, + .power_down = msm_dsi_host_power_down, }; /* diff --git a/drivers/gpu/drm/msm/dsi/dsi_manager.c b/drivers/gpu/drm/msm/dsi/dsi_manager.c index 9fa1f29ec11a..2d7040d21239 100644 --- a/drivers/gpu/drm/msm/dsi/dsi_manager.c +++ b/drivers/gpu/drm/msm/dsi/dsi_manager.c @@ -198,6 +198,44 @@ static int dsi_mgr_bridge_get_id(struct drm_bridge *bridge) return dsi_bridge->id; } +/* + * If the next bridge in the chain is the Parade ps8640 bridge chip then don't + * power on early since it seems to violate the expectations of the firmware + * that the bridge chip is running. + */ +static bool dsi_mgr_next_is_ps8640(struct drm_bridge *bridge) +{ + struct drm_bridge *next_bridge = drm_bridge_get_next_bridge(bridge); + + return next_bridge && + next_bridge->of_node && + of_device_is_compatible(next_bridge->of_node, "parade,ps8640"); +} + +static bool dsi_mgr_auto_powerup(struct drm_bridge *bridge) +{ + int id = dsi_mgr_bridge_get_id(bridge); + struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id); + struct mipi_dsi_host *host = msm_dsi->host; + + if (dsi_mgr_next_is_ps8640(bridge)) + return true; + + return msm_dsi_host_auto_powerup(host); +} + +static bool dsi_mgr_early_powerup(struct drm_bridge *bridge) +{ + int id = dsi_mgr_bridge_get_id(bridge); + struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id); + struct mipi_dsi_host *host = msm_dsi->host; + + if (dsi_mgr_next_is_ps8640(bridge)) + return false; + + return msm_dsi_host_early_powerup(host); +} + static void msm_dsi_manager_set_split_display(u8 id) { struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id); @@ -228,9 +266,8 @@ static void msm_dsi_manager_set_split_display(u8 id) } } -static int dsi_mgr_bridge_power_on(struct drm_bridge *bridge) +int msm_dsi_manager_power_up(int id) { - int id = dsi_mgr_bridge_get_id(bridge); struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id); struct msm_dsi *msm_dsi1 = dsi_mgr_get_dsi(DSI_1); struct mipi_dsi_host *host = msm_dsi->host; @@ -240,6 +277,10 @@ static int dsi_mgr_bridge_power_on(struct drm_bridge *bridge) DBG("id=%d", id); + /* Do nothing with the host if it is slave-DSI in case of bonded DSI */ + if (is_bonded_dsi && !IS_MASTER_DSI_LINK(id)) + return 0; + ret = dsi_mgr_phy_enable(id, phy_shared_timings); if (ret) goto phy_en_fail; @@ -278,9 +319,8 @@ static int dsi_mgr_bridge_power_on(struct drm_bridge *bridge) return ret; } -static void dsi_mgr_bridge_power_off(struct drm_bridge *bridge) +void msm_dsi_manager_power_down(int id) { - int id = dsi_mgr_bridge_get_id(bridge); struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id); struct msm_dsi *msm_dsi1 = dsi_mgr_get_dsi(DSI_1); struct mipi_dsi_host *host = msm_dsi->host; @@ -312,10 +352,12 @@ static void dsi_mgr_bridge_pre_enable(struct drm_bridge *bridge) if (is_bonded_dsi && !IS_MASTER_DSI_LINK(id)) return; - ret = dsi_mgr_bridge_power_on(bridge); - if (ret) { - dev_err(&msm_dsi->pdev->dev, "Power on failed: %d\n", ret); - return; + if (dsi_mgr_auto_powerup(bridge)) { + ret = msm_dsi_manager_power_up(id); + if (ret) { + dev_err(&msm_dsi->pdev->dev, "Power on failed: %d\n", ret); + return; + } } ret = msm_dsi_host_enable(host); @@ -337,7 +379,8 @@ static void dsi_mgr_bridge_pre_enable(struct drm_bridge *bridge) host1_en_fail: msm_dsi_host_disable(host); host_en_fail: - dsi_mgr_bridge_power_off(bridge); + if (dsi_mgr_auto_powerup(bridge)) + msm_dsi_manager_power_down(id); } void msm_dsi_manager_tpg_enable(void) @@ -390,7 +433,9 @@ static void dsi_mgr_bridge_post_disable(struct drm_bridge *bridge) /* Save PHY status if it is a clock source */ msm_dsi_phy_pll_save_state(msm_dsi->phy); - dsi_mgr_bridge_power_off(bridge); + if (dsi_mgr_auto_powerup(bridge) || + dsi_mgr_early_powerup(bridge)) + msm_dsi_manager_power_down(id); } static void dsi_mgr_bridge_mode_set(struct drm_bridge *bridge, @@ -411,6 +456,9 @@ static void dsi_mgr_bridge_mode_set(struct drm_bridge *bridge, msm_dsi_host_set_display_mode(host, adjusted_mode); if (is_bonded_dsi && other_dsi) msm_dsi_host_set_display_mode(other_dsi->host, adjusted_mode); + + if (dsi_mgr_early_powerup(bridge)) + msm_dsi_manager_power_up(id); } static enum drm_mode_status dsi_mgr_bridge_mode_valid(struct drm_bridge *bridge, -- 2.42.0