Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3156559rwe; Mon, 29 Aug 2022 06:50:38 -0700 (PDT) X-Google-Smtp-Source: AA6agR4NPHyQepQRaVvMhjMtt60Bl1jllSwDLrogWDBoqvaniRxgNo/0AIixAYZRAYRUbayjdk+A X-Received: by 2002:a17:90b:4a88:b0:1fb:36b7:7f8e with SMTP id lp8-20020a17090b4a8800b001fb36b77f8emr18076825pjb.22.1661781038525; Mon, 29 Aug 2022 06:50:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661781038; cv=none; d=google.com; s=arc-20160816; b=mHWmqB36nwTd4FcXpT1LxtOomCr17xLyAzsoATUCzw7T71kae5qEIWnzPhsq/pgTYq b0ZN4tupDRWZw6qTYFQzOTN5QQJk1WQ5VLelaBI1hwrcQ51peIMG5BtME2HYGriwDTvf viT/Ub9TR3OVaivtijfEHh2JHoOmwUqSEaIy2J26LkyiE0P7J+Mj6ceaG0WzbdSZgvw0 xO71GSrpQLmABkVmY1yx/ajs3vfzv0V6PXZxvhC0+nNqosPjb7a0Z05ynlzM7hF3mF4s S3AQBFoTutCBLIvMcjXim5Nwscc0F4Y2khB38lHPMNmxfL59n53DbOseaLW5yBtjpFOO u3uQ== 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 :feedback-id:dkim-signature:dkim-signature; bh=tVvgEA3a0r+6vtlMZVtwbeURRb1tj232wXwVtdz5EAA=; b=DusVkzFdxpofPyMbZNI0u1V5zgfeu0Ze0WLc24Isy7JgCt012QPBg6xbP8BA4Clh/K 4mfFKBQrq4oEH7phLN1yHaDYNMwiXAkCuwD1t4jzpogSAizcU5U0cYz0b25HTfN4Yvra Aflzfcf+yM9squcFpRoY48RxdZrzrX8WJ4/Kgkhn4BuNAt0mMYSSSPF+GfOFj5AAShb8 z5XfSkZpwmlbdsNCV4THrnps+PlI2Zw/iXuI6KK+E+GYm9DYcf7tfmIWMQ7Ap+juAgdP wlyLai/p/YC2qQmMt771iwvVX6AsZXauR7dUaYC0qdQmYq0ErelffUq60i7s1cg8Om1W ImGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cerno.tech header.s=fm3 header.b=YDYhrpZL; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=YJCz9842; 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=NONE sp=NONE dis=NONE) header.from=cerno.tech Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id rm9-20020a17090b3ec900b001fd59fe1b96si9586158pjb.86.2022.08.29.06.50.27; Mon, 29 Aug 2022 06:50:38 -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=@cerno.tech header.s=fm3 header.b=YDYhrpZL; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=YJCz9842; 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=NONE sp=NONE dis=NONE) header.from=cerno.tech Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230457AbiH2NT4 (ORCPT + 99 others); Mon, 29 Aug 2022 09:19:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231157AbiH2NSv (ORCPT ); Mon, 29 Aug 2022 09:18:51 -0400 Received: from wnew2-smtp.messagingengine.com (wnew2-smtp.messagingengine.com [64.147.123.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22ABA81B3F for ; Mon, 29 Aug 2022 06:17:30 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailnew.west.internal (Postfix) with ESMTP id 41E262B06090; Mon, 29 Aug 2022 09:16:32 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Mon, 29 Aug 2022 09:16:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cerno.tech; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1661778991; x= 1661786191; bh=tVvgEA3a0r+6vtlMZVtwbeURRb1tj232wXwVtdz5EAA=; b=Y DYhrpZLyx6Cu7gyUw5RfgeBtn+vgeUVVHKm7O+6muotDy5gnRm+B3QouFqtRYjem pqINcrgzNuK+BiS9pvhc1OvRWL/z8iFgFebQkRYpHMhoKWikOLVSilCdIKiUCKTD YsnVD1SsWLTZ3ETC+WWMt0CsjJCGFFg99n8sF2cw8TlTw0f57Mg3ENC0Sh2meIiT X12JkCahvWQeU/dIoBwGmrbAiwjJDetDY+iwbBYPrc+fZXMRp/oZ/xc7ICqbukZm eAYzjLHMy9rEW6cGyNfzEWz/kTD8sRG0jWGhqygeqttaVqOhtrT1wnxfEEmRqf7O LUQBAXbqcDJZ6dWHIKdzA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1661778991; x= 1661786191; bh=tVvgEA3a0r+6vtlMZVtwbeURRb1tj232wXwVtdz5EAA=; b=Y JCz984246F6DBA+LiY4JypkuMjvR08r2x1tvinmXECHpK4O1G6Yh5NXpvW9hYWGB RmpB9oX+Cif2uyV/xgbtw/Uu90iU+vn8YhCN53UCFbs4hbWyP5I3PcieYJYMlAst TRoZK1k5slZEAlY2xZtExNiqz57kCadMXYzscSRkmp4x48BXAOrZd/6/TkeeZHXt fcR51daVHwEcUbvr/BOULLD810yUGnJg0f5vYz3R3gRXOkOy9jt9ksCCp0eF99Hr Z4HkR6yx35yGsktrPmumsKUwMutD3mgyqJVyyVqDfVTgsGfHlcsmCFSoy3oGlRUz OsRpCth5gieuFSL9+9Uug== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvdekuddgieegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhggtgfogfesthhqredtredtjeenucfhrhhomhepofgr gihimhgvucftihhprghrugcuoehmrgigihhmvgestggvrhhnohdrthgvtghhqeenucggtf frrghtthgvrhhnpeefiedvfefggffgffehveejieffuddtgffhjefggeetieduvdeileet lefgveegtdenucevlhhushhtvghrufhiiigvpedutdenucfrrghrrghmpehmrghilhhfrh homhepmhgrgihimhgvsegtvghrnhhordhtvggthh X-ME-Proxy: Feedback-ID: i8771445c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 29 Aug 2022 09:16:30 -0400 (EDT) From: Maxime Ripard To: Maxime Ripard , Ben Skeggs , David Airlie , Chen-Yu Tsai , Thomas Zimmermann , Jani Nikula , Lyude Paul , Philipp Zabel , Maarten Lankhorst , Rodrigo Vivi , Tvrtko Ursulin , Jernej Skrabec , Samuel Holland , Karol Herbst , =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= , Emma Anholt , Daniel Vetter , Joonas Lahtinen Cc: Maxime Ripard , Hans de Goede , linux-arm-kernel@lists.infradead.org, Phil Elwell , intel-gfx@lists.freedesktop.org, Dave Stevenson , dri-devel@lists.freedesktop.org, Dom Cobley , linux-kernel@vger.kernel.org, nouveau@lists.freedesktop.org, linux-sunxi@lists.linux.dev, Mateusz Kwiatkowski , Geert Uytterhoeven Subject: [PATCH v2 41/41] drm/sun4i: tv: Convert to the new TV mode property Date: Mon, 29 Aug 2022 15:11:55 +0200 Message-Id: <20220728-rpi-analog-tv-properties-v2-41-459522d653a7@cerno.tech> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220728-rpi-analog-tv-properties-v2-0-459522d653a7@cerno.tech> References: <20220728-rpi-analog-tv-properties-v2-0-459522d653a7@cerno.tech> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.10.0-dev-65ba7 X-Developer-Signature: v=1; a=openpgp-sha256; l=7619; i=maxime@cerno.tech; h=from:subject:message-id; bh=d9NyAFsgWE8A2NZjwZ98RGHmubqiSFwy9+VurUoUxG0=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDMk8uxQf7bWudXhyo1pYmyFXTLjggZ9+a376X+cky225yTWK TswdpSwMYlwMsmKKLDHC5kviTs163cnGNw9mDisTyBAGLk4BmAjXNEaGT+UujTzbSh+db4gQ7FcRu1 zH8+QNR3fYlQeXK/w564szGBmW5G1qV7G3Ydz78+1+xjV//P2bDDMsBHZq7p37Rldklw4XAA== X-Developer-Key: i=maxime@cerno.tech; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Now that the core can deal fine with analog TV modes, let's convert the=0D sun4i TV driver to leverage those new features.=0D =0D Signed-off-by: Maxime Ripard =0D =0D diff --git a/drivers/gpu/drm/sun4i/sun4i_tv.c b/drivers/gpu/drm/sun4i/sun4i= _tv.c=0D index 74ff5ad6a8b9..10c0d727d700 100644=0D --- a/drivers/gpu/drm/sun4i/sun4i_tv.c=0D +++ b/drivers/gpu/drm/sun4i/sun4i_tv.c=0D @@ -140,23 +140,14 @@ struct resync_parameters {=0D struct tv_mode {=0D char *name;=0D =0D + unsigned int tv_mode;=0D +=0D u32 mode;=0D u32 chroma_freq;=0D u16 back_porch;=0D u16 front_porch;=0D - u16 line_number;=0D u16 vblank_level;=0D =0D - u32 hdisplay;=0D - u16 hfront_porch;=0D - u16 hsync_len;=0D - u16 hback_porch;=0D -=0D - u32 vdisplay;=0D - u16 vfront_porch;=0D - u16 vsync_len;=0D - u16 vback_porch;=0D -=0D bool yc_en;=0D bool dac3_en;=0D bool dac_bit25_en;=0D @@ -212,7 +203,7 @@ static const struct resync_parameters pal_resync_parame= ters =3D {=0D =0D static const struct tv_mode tv_modes[] =3D {=0D {=0D - .name =3D "NTSC",=0D + .tv_mode =3D DRM_MODE_TV_MODE_NTSC_M,=0D .mode =3D SUN4I_TVE_CFG0_RES_480i,=0D .chroma_freq =3D 0x21f07c1f,=0D .yc_en =3D true,=0D @@ -221,17 +212,6 @@ static const struct tv_mode tv_modes[] =3D {=0D =0D .back_porch =3D 118,=0D .front_porch =3D 32,=0D - .line_number =3D 525,=0D -=0D - .hdisplay =3D 720,=0D - .hfront_porch =3D 18,=0D - .hsync_len =3D 2,=0D - .hback_porch =3D 118,=0D -=0D - .vdisplay =3D 480,=0D - .vfront_porch =3D 26,=0D - .vsync_len =3D 2,=0D - .vback_porch =3D 17,=0D =0D .vblank_level =3D 240,=0D =0D @@ -241,23 +221,12 @@ static const struct tv_mode tv_modes[] =3D {=0D .resync_params =3D &ntsc_resync_parameters,=0D },=0D {=0D - .name =3D "PAL",=0D + .tv_mode =3D DRM_MODE_TV_MODE_PAL_B,=0D .mode =3D SUN4I_TVE_CFG0_RES_576i,=0D .chroma_freq =3D 0x2a098acb,=0D =0D .back_porch =3D 138,=0D .front_porch =3D 24,=0D - .line_number =3D 625,=0D -=0D - .hdisplay =3D 720,=0D - .hfront_porch =3D 3,=0D - .hsync_len =3D 2,=0D - .hback_porch =3D 139,=0D -=0D - .vdisplay =3D 576,=0D - .vfront_porch =3D 28,=0D - .vsync_len =3D 2,=0D - .vback_porch =3D 19,=0D =0D .vblank_level =3D 252,=0D =0D @@ -275,63 +244,21 @@ drm_encoder_to_sun4i_tv(struct drm_encoder *encoder)= =0D encoder);=0D }=0D =0D -/*=0D - * FIXME: If only the drm_display_mode private field was usable, this=0D - * could go away...=0D - *=0D - * So far, it doesn't seem to be preserved when the mode is passed by=0D - * to mode_set for some reason.=0D - */=0D -static const struct tv_mode *sun4i_tv_find_tv_by_mode(const struct drm_dis= play_mode *mode)=0D +static const struct tv_mode *=0D +sun4i_tv_find_tv_by_mode(unsigned int mode)=0D {=0D int i;=0D =0D - /* First try to identify the mode by name */=0D for (i =3D 0; i < ARRAY_SIZE(tv_modes); i++) {=0D const struct tv_mode *tv_mode =3D &tv_modes[i];=0D =0D - DRM_DEBUG_DRIVER("Comparing mode %s vs %s",=0D - mode->name, tv_mode->name);=0D -=0D - if (!strcmp(mode->name, tv_mode->name))=0D - return tv_mode;=0D - }=0D -=0D - /* Then by number of lines */=0D - for (i =3D 0; i < ARRAY_SIZE(tv_modes); i++) {=0D - const struct tv_mode *tv_mode =3D &tv_modes[i];=0D -=0D - DRM_DEBUG_DRIVER("Comparing mode %s vs %s (X: %d vs %d)",=0D - mode->name, tv_mode->name,=0D - mode->vdisplay, tv_mode->vdisplay);=0D -=0D - if (mode->vdisplay =3D=3D tv_mode->vdisplay)=0D + if (tv_mode->tv_mode =3D=3D mode)=0D return tv_mode;=0D }=0D =0D return NULL;=0D }=0D =0D -static void sun4i_tv_mode_to_drm_mode(const struct tv_mode *tv_mode,=0D - struct drm_display_mode *mode)=0D -{=0D - DRM_DEBUG_DRIVER("Creating mode %s\n", mode->name);=0D -=0D - mode->type =3D DRM_MODE_TYPE_DRIVER;=0D - mode->clock =3D 13500;=0D - mode->flags =3D DRM_MODE_FLAG_INTERLACE;=0D -=0D - mode->hdisplay =3D tv_mode->hdisplay;=0D - mode->hsync_start =3D mode->hdisplay + tv_mode->hfront_porch;=0D - mode->hsync_end =3D mode->hsync_start + tv_mode->hsync_len;=0D - mode->htotal =3D mode->hsync_end + tv_mode->hback_porch;=0D -=0D - mode->vdisplay =3D tv_mode->vdisplay;=0D - mode->vsync_start =3D mode->vdisplay + tv_mode->vfront_porch;=0D - mode->vsync_end =3D mode->vsync_start + tv_mode->vsync_len;=0D - mode->vtotal =3D mode->vsync_end + tv_mode->vback_porch;=0D -}=0D -=0D static void sun4i_tv_disable(struct drm_encoder *encoder,=0D struct drm_atomic_state *state)=0D {=0D @@ -355,7 +282,11 @@ static void sun4i_tv_enable(struct drm_encoder *encode= r,=0D struct drm_crtc_state *crtc_state =3D=0D drm_atomic_get_new_crtc_state(state, encoder->crtc);=0D struct drm_display_mode *mode =3D &crtc_state->mode;=0D - const struct tv_mode *tv_mode =3D sun4i_tv_find_tv_by_mode(mode);=0D + struct drm_connector *connector =3D &tv->connector;=0D + struct drm_connector_state *conn_state =3D=0D + drm_atomic_get_new_connector_state(state, connector);=0D + const struct tv_mode *tv_mode =3D=0D + sun4i_tv_find_tv_by_mode(conn_state->tv.mode);=0D =0D DRM_DEBUG_DRIVER("Enabling the TV Output\n");=0D =0D @@ -403,7 +334,7 @@ static void sun4i_tv_enable(struct drm_encoder *encoder= ,=0D /* Set the lines setup */=0D regmap_write(tv->regs, SUN4I_TVE_LINE_REG,=0D SUN4I_TVE_LINE_FIRST(22) |=0D - SUN4I_TVE_LINE_NUMBER(tv_mode->line_number));=0D + SUN4I_TVE_LINE_NUMBER(mode->vtotal));=0D =0D regmap_write(tv->regs, SUN4I_TVE_LEVEL_REG,=0D SUN4I_TVE_LEVEL_BLANK(tv_mode->video_levels->blank) |=0D @@ -466,35 +397,45 @@ static const struct drm_encoder_helper_funcs sun4i_tv= _helper_funcs =3D {=0D =0D static int sun4i_tv_comp_get_modes(struct drm_connector *connector)=0D {=0D - int i;=0D + struct drm_display_mode *mode;=0D + int count =3D 0;=0D =0D - for (i =3D 0; i < ARRAY_SIZE(tv_modes); i++) {=0D - struct drm_display_mode *mode;=0D - const struct tv_mode *tv_mode =3D &tv_modes[i];=0D -=0D - mode =3D drm_mode_create(connector->dev);=0D - if (!mode) {=0D - DRM_ERROR("Failed to create a new display mode\n");=0D - return 0;=0D - }=0D + mode =3D drm_mode_analog_ntsc_480i(connector->dev);=0D + if (!mode) {=0D + DRM_ERROR("Failed to create a new display mode\n");=0D + return -ENOMEM;=0D + }=0D =0D - strcpy(mode->name, tv_mode->name);=0D + drm_mode_probed_add(connector, mode);=0D + count +=3D 1;=0D =0D - sun4i_tv_mode_to_drm_mode(tv_mode, mode);=0D - drm_mode_probed_add(connector, mode);=0D + mode =3D drm_mode_analog_pal_576i(connector->dev);=0D + if (!mode) {=0D + DRM_ERROR("Failed to create a new display mode\n");=0D + return -ENOMEM;=0D }=0D =0D - return i;=0D + drm_mode_probed_add(connector, mode);=0D + count +=3D 1;=0D +=0D + return count;=0D }=0D =0D static const struct drm_connector_helper_funcs sun4i_tv_comp_connector_hel= per_funcs =3D {=0D + .atomic_check =3D drm_atomic_helper_connector_tv_check,=0D .get_modes =3D sun4i_tv_comp_get_modes,=0D };=0D =0D +static void sun4i_tv_connector_reset(struct drm_connector *connector)=0D +{=0D + drm_atomic_helper_connector_reset(connector);=0D + drm_atomic_helper_connector_tv_reset(connector);=0D +}=0D +=0D static const struct drm_connector_funcs sun4i_tv_comp_connector_funcs =3D = {=0D .fill_modes =3D drm_helper_probe_single_connector_modes,=0D .destroy =3D drm_connector_cleanup,=0D - .reset =3D drm_atomic_helper_connector_reset,=0D + .reset =3D sun4i_tv_connector_reset,=0D .atomic_duplicate_state =3D drm_atomic_helper_connector_duplicate_state,= =0D .atomic_destroy_state =3D drm_atomic_helper_connector_destroy_state,=0D };=0D @@ -586,8 +527,20 @@ static int sun4i_tv_bind(struct device *dev, struct de= vice *master,=0D =0D drm_connector_attach_encoder(&tv->connector, &tv->encoder);=0D =0D + ret =3D drm_mode_create_tv_properties(drm,=0D + BIT(DRM_MODE_TV_MODE_NTSC_M) |=0D + BIT(DRM_MODE_TV_MODE_PAL_B));=0D + if (ret)=0D + goto err_cleanup_connector;=0D +=0D + drm_object_attach_property(&connector->base,=0D + dev->mode_config.tv_mode_property,=0D + DRM_MODE_TV_MODE_NTSC_M);=0D +=0D return 0;=0D =0D +err_cleanup_connector:=0D + drm_connector_cleanup(&tv->connector);=0D err_cleanup_encoder:=0D drm_encoder_cleanup(&tv->encoder);=0D err_disable_clk:=0D =0D -- =0D b4 0.10.0-dev-65ba7=0D