Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp6783680rwd; Tue, 6 Jun 2023 01:41:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4/G5p/ub0bxh06gheO9UtWy0WwF6307sb2FvsVM3BEYDJTbv2ogPkjjdMevCzUQriZIw1H X-Received: by 2002:a05:622a:1449:b0:3f6:a7c2:63d6 with SMTP id v9-20020a05622a144900b003f6a7c263d6mr1326361qtx.44.1686040875443; Tue, 06 Jun 2023 01:41:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686040875; cv=none; d=google.com; s=arc-20160816; b=qh/icS7OE4/1WmSImEOjocSy31G3XpshO/H5ZR6erYRgL08LwgmD/vYaIOsPAsAoee Cthl9JCK4FMkKmaCMtiuFcD4MkP2tc3W9C2R1cE6B/+juwykz1Q4V1/pW9sJi2GBPSuF n8Ict0W13KkMz2skIb2HkO7yFh8aDvWC6ATBmfdGELweL7g/boOyQXp4Hh1tiVW+76WQ z3TWZseUBBPYAoFbDKNDYQPr+PTYfBxVGCGAWh2KX1bwyZdHSdk7yxPLrBcPUI3yrcWU IRr4WAEVsmVdbv6j3wxPYbpmCxQKgEQVBg0JUEUWeWQT++gauYaohLRTTpZaREkgWvfl Hxnw== 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=ZFTuDRCNh0K2sxCkjXJOFdyKf3fRWYBGiUnO3q2fd4Q=; b=I+AZZ5H+cF2NlYjzSas0LVD1PVe29m3SEroIXMP/Oipgt42fg03OkDYPd28uvz4bn7 O2FOx12LGEHdTis8ORYdtRl2a50d7k/nIgPuKgqd+lPFUZWeS6K2O2fCsLfY6nPWs0m1 cwNThyDdZLUDI4Cd4boeWGXIkgFHgyhnuyYmTLhMarswvCXl7vrNYdonQrOd3MUDE6ZA gGCZJvI3mBlSqkfxFc4KjdRslvENpoH6IhihGXvykDhNl/f6oNuA7GYP7vtfk63G95M9 jJFQS14VVVyfNOWt2q6XTP99gv2nV4l8TgtVU4z2rNDhZxUz9W7NRK9HOKYeB7fNjEJr CO+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=E3+fJdfg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id eo4-20020ad45944000000b006262d38e8efsi5896062qvb.527.2023.06.06.01.41.01; Tue, 06 Jun 2023 01:41:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=E3+fJdfg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236452AbjFFIWs (ORCPT + 99 others); Tue, 6 Jun 2023 04:22:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236409AbjFFIWV (ORCPT ); Tue, 6 Jun 2023 04:22:21 -0400 Received: from fllv0015.ext.ti.com (fllv0015.ext.ti.com [198.47.19.141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A97D3AF for ; Tue, 6 Jun 2023 01:22:18 -0700 (PDT) Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 3568Lse3038662; Tue, 6 Jun 2023 03:21:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1686039714; bh=ZFTuDRCNh0K2sxCkjXJOFdyKf3fRWYBGiUnO3q2fd4Q=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=E3+fJdfg6JrTVqO2/K1qWkriVmYPDbL4GteKGTxbJBSXTSc/jmNczCyRwaUIpOiZH EDEQLduqvzKjHIRsRRI0MVfXy8eUVa/jooJ/EaLeESsmkELLIMmNsySElbm/d+bpmU o00A5vrPWzdrvdnhlZrHRqI1Ti3zpM+0xYUKTywI= Received: from DLEE108.ent.ti.com (dlee108.ent.ti.com [157.170.170.38]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 3568LsQ8032040 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 6 Jun 2023 03:21:54 -0500 Received: from DLEE112.ent.ti.com (157.170.170.23) by DLEE108.ent.ti.com (157.170.170.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Tue, 6 Jun 2023 03:21:53 -0500 Received: from fllv0039.itg.ti.com (10.64.41.19) by DLEE112.ent.ti.com (157.170.170.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Tue, 6 Jun 2023 03:21:53 -0500 Received: from localhost (ileaxei01-snat.itg.ti.com [10.180.69.5]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 3568Lr2L090266; Tue, 6 Jun 2023 03:21:53 -0500 From: Aradhya Bhatia To: Tomi Valkeinen , Jyri Sarha , David Airlie , Daniel Vetter , Laurent Pinchart , Andrzej Hajda , Neil Armstrong , Robert Foss , Jonas Karlman , Jernej Skrabec , Swapnil Jakhade , Boris Brezillon , Francesco Dolcini CC: DRI Development List , Linux Kernel List , Nishanth Menon , Vignesh Raghavendra , Rahul T R , Devarsh Thakkar , Jayesh Choudhary , Aradhya Bhatia Subject: [PATCH v7 7/8] drm/tidss: Update encoder/bridge chain connect model Date: Tue, 6 Jun 2023 13:51:41 +0530 Message-ID: <20230606082142.23760-8-a-bhatia1@ti.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230606082142.23760-1-a-bhatia1@ti.com> References: <20230606082142.23760-1-a-bhatia1@ti.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With the new encoder/bridge chain model, the display controller driver is required to create a drm_connector entity instead of asking the bridge to do so during drm_bridge_attach. Moreover, the controller driver should create a drm_bridge entity to negotiate bus formats and a 'simple' drm_encoder entity to expose it to userspace. Update the encoder/bridge initialization sequence in tidss as per the new model. Signed-off-by: Aradhya Bhatia --- Notes: changes from v5: * Drop patches 5 and 6 from the original series. * Instead add this patch that addresses Boris Brezillon's comments of creating bridge, simple encoder and connector. drivers/gpu/drm/tidss/tidss_encoder.c | 140 ++++++++++++++++---------- drivers/gpu/drm/tidss/tidss_encoder.h | 5 +- drivers/gpu/drm/tidss/tidss_kms.c | 12 +-- 3 files changed, 94 insertions(+), 63 deletions(-) diff --git a/drivers/gpu/drm/tidss/tidss_encoder.c b/drivers/gpu/drm/tidss/tidss_encoder.c index 0d4865e9c03d..17a86bed8054 100644 --- a/drivers/gpu/drm/tidss/tidss_encoder.c +++ b/drivers/gpu/drm/tidss/tidss_encoder.c @@ -6,91 +6,125 @@ #include +#include +#include +#include #include #include #include #include +#include #include "tidss_crtc.h" #include "tidss_drv.h" #include "tidss_encoder.h" -static int tidss_encoder_atomic_check(struct drm_encoder *encoder, - struct drm_crtc_state *crtc_state, - struct drm_connector_state *conn_state) +struct tidss_encoder { + struct drm_bridge bridge; + struct drm_encoder encoder; + struct drm_connector *connector; + struct drm_bridge *next_bridge; + struct tidss_device *tidss; +}; + +static inline struct tidss_encoder +*bridge_to_tidss_encoder(struct drm_bridge *b) +{ + return container_of(b, struct tidss_encoder, bridge); +} + +static int tidss_bridge_attach(struct drm_bridge *bridge, + enum drm_bridge_attach_flags flags) +{ + struct tidss_encoder *t_enc = bridge_to_tidss_encoder(bridge); + + return drm_bridge_attach(bridge->encoder, t_enc->next_bridge, + bridge, flags); +} + +static int tidss_bridge_atomic_check(struct drm_bridge *bridge, + struct drm_bridge_state *bridge_state, + struct drm_crtc_state *crtc_state, + struct drm_connector_state *conn_state) { - struct drm_device *ddev = encoder->dev; + struct tidss_encoder *t_enc = bridge_to_tidss_encoder(bridge); + struct tidss_device *tidss = t_enc->tidss; struct tidss_crtc_state *tcrtc_state = to_tidss_crtc_state(crtc_state); struct drm_display_info *di = &conn_state->connector->display_info; - struct drm_bridge *bridge; - bool bus_flags_set = false; - - dev_dbg(ddev->dev, "%s\n", __func__); - - /* - * Take the bus_flags from the first bridge that defines - * bridge timings, or from the connector's display_info if no - * bridge defines the timings. - */ - drm_for_each_bridge_in_chain(encoder, bridge) { - if (!bridge->timings) - continue; - - tcrtc_state->bus_flags = bridge->timings->input_bus_flags; - bus_flags_set = true; - break; - } + struct drm_bridge_state *next_bridge_state = NULL; + + if (t_enc->next_bridge) + next_bridge_state = drm_atomic_get_new_bridge_state(crtc_state->state, + t_enc->next_bridge); - if (!di->bus_formats || di->num_bus_formats == 0) { - dev_err(ddev->dev, "%s: No bus_formats in connected display\n", + if (next_bridge_state) { + tcrtc_state->bus_flags = next_bridge_state->input_bus_cfg.flags; + tcrtc_state->bus_format = next_bridge_state->input_bus_cfg.format; + } else if (di->num_bus_formats) { + tcrtc_state->bus_format = di->bus_formats[0]; + tcrtc_state->bus_flags = di->bus_flags; + } else { + dev_err(tidss->dev, "%s: No bus_formats in connected display\n", __func__); return -EINVAL; } - // XXX any cleaner way to set bus format and flags? - tcrtc_state->bus_format = di->bus_formats[0]; - if (!bus_flags_set) - tcrtc_state->bus_flags = di->bus_flags; - return 0; } -static void tidss_encoder_destroy(struct drm_encoder *encoder) -{ - drm_encoder_cleanup(encoder); - kfree(encoder); -} - -static const struct drm_encoder_helper_funcs encoder_helper_funcs = { - .atomic_check = tidss_encoder_atomic_check, -}; - -static const struct drm_encoder_funcs encoder_funcs = { - .destroy = tidss_encoder_destroy, +static const struct drm_bridge_funcs tidss_bridge_funcs = { + .attach = tidss_bridge_attach, + .atomic_check = tidss_bridge_atomic_check, + .atomic_reset = drm_atomic_helper_bridge_reset, + .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state, + .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state, }; -struct drm_encoder *tidss_encoder_create(struct tidss_device *tidss, - u32 encoder_type, u32 possible_crtcs) +int tidss_encoder_create(struct tidss_device *tidss, + struct drm_bridge *next_bridge, + u32 encoder_type, u32 possible_crtcs) { + struct tidss_encoder *t_enc; struct drm_encoder *enc; + struct drm_connector *connector; int ret; - enc = kzalloc(sizeof(*enc), GFP_KERNEL); - if (!enc) - return ERR_PTR(-ENOMEM); + t_enc = drmm_simple_encoder_alloc(&tidss->ddev, struct tidss_encoder, + encoder, encoder_type); + if (IS_ERR(t_enc)) + return PTR_ERR(t_enc); + + t_enc->tidss = tidss; + t_enc->next_bridge = next_bridge; + t_enc->bridge.funcs = &tidss_bridge_funcs; + enc = &t_enc->encoder; enc->possible_crtcs = possible_crtcs; - ret = drm_encoder_init(&tidss->ddev, enc, &encoder_funcs, - encoder_type, NULL); - if (ret < 0) { - kfree(enc); - return ERR_PTR(ret); + /* Attaching first bridge to the encoder */ + ret = drm_bridge_attach(enc, &t_enc->bridge, NULL, + DRM_BRIDGE_ATTACH_NO_CONNECTOR); + if (ret) { + dev_err(tidss->dev, "bridge attach failed: %d\n", ret); + return ret; + } + + /* Initializing the connector at the end of bridge-chain */ + connector = drm_bridge_connector_init(&tidss->ddev, enc); + if (IS_ERR(connector)) { + dev_err(tidss->dev, "bridge_connector create failed\n"); + return PTR_ERR(connector); + } + + ret = drm_connector_attach_encoder(connector, enc); + if (ret) { + dev_err(tidss->dev, "attaching encoder to connector failed\n"); + return ret; } - drm_encoder_helper_add(enc, &encoder_helper_funcs); + t_enc->connector = connector; dev_dbg(tidss->dev, "Encoder create done\n"); - return enc; + return ret; } diff --git a/drivers/gpu/drm/tidss/tidss_encoder.h b/drivers/gpu/drm/tidss/tidss_encoder.h index ace877c0e0fd..3e561d6b1e83 100644 --- a/drivers/gpu/drm/tidss/tidss_encoder.h +++ b/drivers/gpu/drm/tidss/tidss_encoder.h @@ -11,7 +11,8 @@ struct tidss_device; -struct drm_encoder *tidss_encoder_create(struct tidss_device *tidss, - u32 encoder_type, u32 possible_crtcs); +int tidss_encoder_create(struct tidss_device *tidss, + struct drm_bridge *next_bridge, + u32 encoder_type, u32 possible_crtcs); #endif diff --git a/drivers/gpu/drm/tidss/tidss_kms.c b/drivers/gpu/drm/tidss/tidss_kms.c index ad2fa3c3d4a7..c979ad1af236 100644 --- a/drivers/gpu/drm/tidss/tidss_kms.c +++ b/drivers/gpu/drm/tidss/tidss_kms.c @@ -193,7 +193,6 @@ static int tidss_dispc_modeset_init(struct tidss_device *tidss) for (i = 0; i < num_pipes; ++i) { struct tidss_plane *tplane; struct tidss_crtc *tcrtc; - struct drm_encoder *enc; u32 hw_plane_id = feat->vid_order[tidss->num_planes]; int ret; @@ -216,16 +215,13 @@ static int tidss_dispc_modeset_init(struct tidss_device *tidss) tidss->crtcs[tidss->num_crtcs++] = &tcrtc->crtc; - enc = tidss_encoder_create(tidss, pipes[i].enc_type, + ret = tidss_encoder_create(tidss, pipes[i].bridge, + pipes[i].enc_type, 1 << tcrtc->crtc.index); - if (IS_ERR(enc)) { + if (ret) { dev_err(tidss->dev, "encoder create failed\n"); - return PTR_ERR(enc); - } - - ret = drm_bridge_attach(enc, pipes[i].bridge, NULL, 0); - if (ret) return ret; + } } /* create overlay planes of the leftover planes */ -- 2.40.1