Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp398950imn; Fri, 29 Jul 2022 10:13:07 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sFGfKHsWxcWcIm5HzctynZp9vksz1zYEpQkW4BzPZIsYyEomKeX+WL5uwLSTMAJ7qlwMQL X-Received: by 2002:a05:6a00:989:b0:52b:1d96:a8da with SMTP id u9-20020a056a00098900b0052b1d96a8damr4434055pfg.86.1659114787585; Fri, 29 Jul 2022 10:13:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659114787; cv=none; d=google.com; s=arc-20160816; b=auOaF3svXzbjnBtPQ/FoU6SKjvJWcih3TPAFGIgGGN1o2rthev8PqZugbrNLad+j/y Ebs1ka2SH7wxSHIcZkwq9D7A6nyplvuKBFXsNMsP93WYhvI1i4JL+MP69bUdooMt3w59 FL0T1eFhRwIW0R7vMgHjBVNK5MRN1+kVDJqejDVb9mJuk/+golqsLQl5nj2PVUPjRuda IfIOwevYbp8F2tzeB/Fcy/enALsIkzYaIqH29CFrAmZy7/gJLicn9U4ePGPirQuG4y7I /BSVj/9jE/HMO5NQlnyc/I+mrPxzaWmZZRJLTeP2DYYxjFH0nl1pK/zMwR1FV6hVyDHm swhA== 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=hg5QKv8NbRSHVN7ZEIfcxpXI9EV/gE+w/pkOe6RNsRY=; b=WFz3c40ggApnNVjgig0G1CZUtA/16eVcztr7HPatam1WMiolv9o7bUfXNexQfL+GGU QitYYlx0N1DXPfigaENUBNwfjPY36GPEoaqrPD2pGowKfw8Ep5PScaey0XcV6QejENPY ieUn41DWgQrUWlEgKwdGYdVicco5pf1gh6BWSKLpj7p6edfDRRcSQ2t+P8ikRuTAq5gl UzsEnQF9tb+aFbE8Y+rSosg3OKTRHbzV6aoIfMntxFJh+0IGDIDvHIvS3h67siYABZnM Eu9rut58w4GVN4B95CvZiUdUhW1OWOYnG1O+6n7AN4QcAxMj4phK/WsQjfw000jT4vaK iK6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cerno.tech header.s=fm2 header.b=njOmDTqI; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=XWv3hmwj; 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 16-20020a630d50000000b00419d4533627si4230643pgn.123.2022.07.29.10.12.51; Fri, 29 Jul 2022 10:13:07 -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=fm2 header.b=njOmDTqI; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=XWv3hmwj; 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 S237757AbiG2QiA (ORCPT + 99 others); Fri, 29 Jul 2022 12:38:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237769AbiG2Qhf (ORCPT ); Fri, 29 Jul 2022 12:37:35 -0400 Received: from new4-smtp.messagingengine.com (new4-smtp.messagingengine.com [66.111.4.230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3D2688E25 for ; Fri, 29 Jul 2022 09:37:27 -0700 (PDT) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailnew.nyi.internal (Postfix) with ESMTP id 060B258099A; Fri, 29 Jul 2022 12:37:27 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Fri, 29 Jul 2022 12:37:27 -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=fm2; t=1659112647; x= 1659119847; bh=hg5QKv8NbRSHVN7ZEIfcxpXI9EV/gE+w/pkOe6RNsRY=; b=n jOmDTqIpXdBYkBi12VmqzQHToPHqtXav6pR2pJZJDpdYHKr3+lS2M9UZDxHBokDk AcvnkZ0HZKYp8ib31yiznXvCiJlC+UCBtjLeYC4ceA7m6xvyGPxkBDsyHAZcY0ep XTBIF+oubKgI4KqyuI30MxRJFIjNCR7GixlcWk5BO2ENcVDGn0nC6aXwFey99JVY ysAq7m6e9WO5VnjR5yHAtITlgis3j0e1J9IQXaC/Q1A1zMOzWf+i0dQpd9ijzZQy 34XlCEt0+ufDACga7oarLOGCHiNWE4bHDhYt1QBq3MxmYxTkWXJGyXsN/r+v67+t y5QIF/CpJCB67GR99G11A== 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=fm3; t=1659112647; x= 1659119847; bh=hg5QKv8NbRSHVN7ZEIfcxpXI9EV/gE+w/pkOe6RNsRY=; b=X Wv3hmwjqzaQ573Lm+3GIMEkbF9C8V3U78tc1p7IfUVkceHZKohZAWnJMOAeoga1s dYpg9r4eBO7a7D4YGvksc5e00zcicJu6tkO2b1bgw/FFejGBA5ojPsJyPw9Gfkfk oDYIkL/W9VUJCbiRcOZ6tR0pYMOB0oAi44A1hFwCMhpiq5Lyum6bVYMhHXXtSQMC SYVoVr1Hz0gkul2/lXmsU+/NqZebLj2LlXGAJBYprh/Oxc9l2cdklbT4F/d8OqjU V1/cPC1wnWrXi1GmJkp2DOL7wjwD7LBd3Wvri30s8Gq9jW5uFgY34mB6ewYd6/c4 My4svEtxTwY28ecrHoj4A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvddujedguddtgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvfevufffkffojghfgggtoffgsehtkeertdertdejnecuhfhrohhmpefo rgigihhmvgcutfhiphgrrhguuceomhgrgihimhgvsegtvghrnhhordhtvggthheqnecugg ftrfgrthhtvghrnhepgfffgfetffduudelhfevieffffduleevgfegkeeutefgffejheel leekjeefhfejnecuvehluhhsthgvrhfuihiivgepgeenucfrrghrrghmpehmrghilhhfrh homhepmhgrgihimhgvsegtvghrnhhordhtvggthh X-ME-Proxy: Feedback-ID: i8771445c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 29 Jul 2022 12:37:25 -0400 (EDT) From: Maxime Ripard To: Jernej Skrabec , Martin Blumenstingl , Chen-Yu Tsai , Philipp Zabel , Jerome Brunet , Samuel Holland , Thomas Zimmermann , Daniel Vetter , Emma Anholt , David Airlie , Maarten Lankhorst , =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= , Kevin Hilman , Neil Armstrong , Maxime Ripard Cc: Maxime Ripard , linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Phil Elwell , Mateusz Kwiatkowski , linux-arm-kernel@lists.infradead.org, Geert Uytterhoeven , Dave Stevenson , linux-amlogic@lists.infradead.org, dri-devel@lists.freedesktop.org, Dom Cobley Subject: [PATCH v1 32/35] drm/sun4i: tv: Convert to the new TV mode property Date: Fri, 29 Jul 2022 18:35:15 +0200 Message-Id: <20220728-rpi-analog-tv-properties-v1-32-3d53ae722097@cerno.tech> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220728-rpi-analog-tv-properties-v1-0-3d53ae722097@cerno.tech> References: <20220728-rpi-analog-tv-properties-v1-0-3d53ae722097@cerno.tech> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.10.0-dev-49460 X-Developer-Signature: v=1; a=openpgp-sha256; l=7148; i=maxime@cerno.tech; h=from:subject:message-id; bh=SyP1xwAWJTOv/oxkLn62sRTeR45GyJtXgGwYAUCpYeQ=; b=owGbwMvMwCHc4XzqmfnC7acZT6slMSQ94VFKuXulpapVdptb/LS5h63jCv2sAoUUt33Inc6b8O1G +r+wjlIWBmEOBlkxRZbrgm/t+MKi3CJ4PmyGmcPKBDKEgYtTACaSZsfwzzq0SW5G3epHp0PnXJqwzE HZvpfreNV5lk9XY4PWt69dmsvwP+Di3u8pTWFc0unf+H5yu3UnJdjURPz6/Sb37A7rWN3JIgA= X-Developer-Key: i=maxime@cerno.tech; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D Content-Transfer-Encoding: 8bit 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 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 sun4i TV driver to leverage those new features. Signed-off-by: Maxime Ripard diff --git a/drivers/gpu/drm/sun4i/sun4i_tv.c b/drivers/gpu/drm/sun4i/sun4i_tv.c index 74ff5ad6a8b9..bed52423776e 100644 --- a/drivers/gpu/drm/sun4i/sun4i_tv.c +++ b/drivers/gpu/drm/sun4i/sun4i_tv.c @@ -140,23 +140,15 @@ struct resync_parameters { struct tv_mode { char *name; + unsigned int tv_mode; + const struct drm_display_mode *display_mode; + u32 mode; u32 chroma_freq; u16 back_porch; u16 front_porch; - u16 line_number; u16 vblank_level; - u32 hdisplay; - u16 hfront_porch; - u16 hsync_len; - u16 hback_porch; - - u32 vdisplay; - u16 vfront_porch; - u16 vsync_len; - u16 vback_porch; - bool yc_en; bool dac3_en; bool dac_bit25_en; @@ -212,7 +204,8 @@ static const struct resync_parameters pal_resync_parameters = { static const struct tv_mode tv_modes[] = { { - .name = "NTSC", + .tv_mode = DRM_MODE_TV_NORM_NTSC_M, + .display_mode = &drm_mode_480i, .mode = SUN4I_TVE_CFG0_RES_480i, .chroma_freq = 0x21f07c1f, .yc_en = true, @@ -221,17 +214,6 @@ static const struct tv_mode tv_modes[] = { .back_porch = 118, .front_porch = 32, - .line_number = 525, - - .hdisplay = 720, - .hfront_porch = 18, - .hsync_len = 2, - .hback_porch = 118, - - .vdisplay = 480, - .vfront_porch = 26, - .vsync_len = 2, - .vback_porch = 17, .vblank_level = 240, @@ -241,23 +223,13 @@ static const struct tv_mode tv_modes[] = { .resync_params = &ntsc_resync_parameters, }, { - .name = "PAL", + .tv_mode = DRM_MODE_TV_NORM_PAL_B, + .display_mode = &drm_mode_576i, .mode = SUN4I_TVE_CFG0_RES_576i, .chroma_freq = 0x2a098acb, .back_porch = 138, .front_porch = 24, - .line_number = 625, - - .hdisplay = 720, - .hfront_porch = 3, - .hsync_len = 2, - .hback_porch = 139, - - .vdisplay = 576, - .vfront_porch = 28, - .vsync_len = 2, - .vback_porch = 19, .vblank_level = 252, @@ -275,63 +247,21 @@ drm_encoder_to_sun4i_tv(struct drm_encoder *encoder) encoder); } -/* - * FIXME: If only the drm_display_mode private field was usable, this - * could go away... - * - * So far, it doesn't seem to be preserved when the mode is passed by - * to mode_set for some reason. - */ -static const struct tv_mode *sun4i_tv_find_tv_by_mode(const struct drm_display_mode *mode) +static const struct tv_mode * +sun4i_tv_find_tv_by_mode(unsigned int mode) { int i; - /* First try to identify the mode by name */ for (i = 0; i < ARRAY_SIZE(tv_modes); i++) { const struct tv_mode *tv_mode = &tv_modes[i]; - DRM_DEBUG_DRIVER("Comparing mode %s vs %s", - mode->name, tv_mode->name); - - if (!strcmp(mode->name, tv_mode->name)) - return tv_mode; - } - - /* Then by number of lines */ - for (i = 0; i < ARRAY_SIZE(tv_modes); i++) { - const struct tv_mode *tv_mode = &tv_modes[i]; - - DRM_DEBUG_DRIVER("Comparing mode %s vs %s (X: %d vs %d)", - mode->name, tv_mode->name, - mode->vdisplay, tv_mode->vdisplay); - - if (mode->vdisplay == tv_mode->vdisplay) + if (tv_mode->tv_mode == mode) return tv_mode; } return NULL; } -static void sun4i_tv_mode_to_drm_mode(const struct tv_mode *tv_mode, - struct drm_display_mode *mode) -{ - DRM_DEBUG_DRIVER("Creating mode %s\n", mode->name); - - mode->type = DRM_MODE_TYPE_DRIVER; - mode->clock = 13500; - mode->flags = DRM_MODE_FLAG_INTERLACE; - - mode->hdisplay = tv_mode->hdisplay; - mode->hsync_start = mode->hdisplay + tv_mode->hfront_porch; - mode->hsync_end = mode->hsync_start + tv_mode->hsync_len; - mode->htotal = mode->hsync_end + tv_mode->hback_porch; - - mode->vdisplay = tv_mode->vdisplay; - mode->vsync_start = mode->vdisplay + tv_mode->vfront_porch; - mode->vsync_end = mode->vsync_start + tv_mode->vsync_len; - mode->vtotal = mode->vsync_end + tv_mode->vback_porch; -} - static void sun4i_tv_disable(struct drm_encoder *encoder, struct drm_atomic_state *state) { @@ -355,7 +285,11 @@ static void sun4i_tv_enable(struct drm_encoder *encoder, struct drm_crtc_state *crtc_state = drm_atomic_get_new_crtc_state(state, encoder->crtc); struct drm_display_mode *mode = &crtc_state->mode; - const struct tv_mode *tv_mode = sun4i_tv_find_tv_by_mode(mode); + struct drm_connector *connector = &tv->connector; + struct drm_connector_state *conn_state = + drm_atomic_get_new_connector_state(state, connector); + const struct tv_mode *tv_mode = + sun4i_tv_find_tv_by_mode(conn_state->tv.norm); DRM_DEBUG_DRIVER("Enabling the TV Output\n"); @@ -403,7 +337,7 @@ static void sun4i_tv_enable(struct drm_encoder *encoder, /* Set the lines setup */ regmap_write(tv->regs, SUN4I_TVE_LINE_REG, SUN4I_TVE_LINE_FIRST(22) | - SUN4I_TVE_LINE_NUMBER(tv_mode->line_number)); + SUN4I_TVE_LINE_NUMBER(mode->vtotal)); regmap_write(tv->regs, SUN4I_TVE_LEVEL_REG, SUN4I_TVE_LEVEL_BLANK(tv_mode->video_levels->blank) | @@ -472,15 +406,12 @@ static int sun4i_tv_comp_get_modes(struct drm_connector *connector) struct drm_display_mode *mode; const struct tv_mode *tv_mode = &tv_modes[i]; - mode = drm_mode_create(connector->dev); + mode = drm_mode_duplicate(connector->dev, tv_mode->display_mode); if (!mode) { DRM_ERROR("Failed to create a new display mode\n"); return 0; } - strcpy(mode->name, tv_mode->name); - - sun4i_tv_mode_to_drm_mode(tv_mode, mode); drm_mode_probed_add(connector, mode); } @@ -488,13 +419,20 @@ static int sun4i_tv_comp_get_modes(struct drm_connector *connector) } static const struct drm_connector_helper_funcs sun4i_tv_comp_connector_helper_funcs = { + .atomic_check = drm_atomic_helper_connector_tv_check, .get_modes = sun4i_tv_comp_get_modes, }; +static void sun4i_tv_connector_reset(struct drm_connector *connector) +{ + drm_atomic_helper_connector_reset(connector); + drm_atomic_helper_connector_tv_reset(connector); +} + static const struct drm_connector_funcs sun4i_tv_comp_connector_funcs = { .fill_modes = drm_helper_probe_single_connector_modes, .destroy = drm_connector_cleanup, - .reset = drm_atomic_helper_connector_reset, + .reset = sun4i_tv_connector_reset, .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, }; @@ -586,8 +524,17 @@ static int sun4i_tv_bind(struct device *dev, struct device *master, drm_connector_attach_encoder(&tv->connector, &tv->encoder); + ret = drm_mode_create_tv_properties(drm, + DRM_MODE_TV_NORM_NTSC_M | + DRM_MODE_TV_NORM_PAL_B, + 0, NULL); + if (ret) + goto err_cleanup_connector; + return 0; +err_cleanup_connector: + drm_connector_cleanup(&tv->connector); err_cleanup_encoder: drm_encoder_cleanup(&tv->encoder); err_disable_clk: -- b4 0.10.0-dev-49460