From patchwork Wed Sep 20 14:35:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 142435 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp4196201vqi; Wed, 20 Sep 2023 07:50:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFVMpNzHrAoGaKzXFYkZxgTus6u7VEIfuw6rLM9+2vf7lbEb6Kf1VAWzh+4+fpapMQCRr+w X-Received: by 2002:a17:902:74c6:b0:1c5:6dbc:7938 with SMTP id f6-20020a17090274c600b001c56dbc7938mr2196622plt.69.1695221408836; Wed, 20 Sep 2023 07:50:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695221408; cv=none; d=google.com; s=arc-20160816; b=F7QFekeP3IV3pKneBGXnaKpOqVmSoHnQkez/w2vy7TolWC3hyv1KV+be01o32aJPHt KT0WYJuYcD7Rhbn8Tj/H1T2ck8uWEm8Vo0qdQg191720DrsDYl+WtMa1dMkjHMxho9IR ysUcsg6AUI20W3fTyiMnyPgBnrPagvK5j57TpimWnBuJmUELNxptNwG35IP0ZmY8GUOi PSAwA3apd/0niYWZLGioS6+RsJL1el361Vy1V262RtRjTNKPTx77PDMPg+HJ8FvOiooq K4tcOSbuDYDULva8W0+m0WNuyma/WrlgTM2vby2lJ5jH3XVTWAUEFlN1tyan9hQV0SAV 0EzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=Po7uJxr+sbFO6xvcyVH+rUlJlpY/Zkx9xMyKF8jKlbM=; fh=e6/uyeFf2k7v8JUtB6fPyaAS5iN3eSA1hjtg35V2Rzw=; b=gd/l5oYJo6oKpHwkL7sZ/potwxG+X0M/VRIwB8fjlnX99ZFup4v1YriQMVG2hdvv8n w67wGcjyeltryQCs+UXTIENPbIMh/d8Hh25S6LCoLH4BGVmhnF0zJa4LsWKAZ1gxCXYg HvXakSRXBI3hrTVGzosLP7Y219rK3GmIy4Ax9eJwNfQOcjzbnplTNnQSH3bexO6/0n67 btseIKsrg517xL5xq7hNuPP/sF/JN91T3V+AWCsguPO+K/sNSHPNpFmmeh29YZMLek6Y fexsv4sCirgFjnNytfa34oH2u+p/mRmjkLoBvJ5JJMHNkS/h6hEVcHrJW4JhGNcm8Djj SULA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DBADfKi1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id le7-20020a170902fb0700b001bd949bcd75si11588121plb.575.2023.09.20.07.50.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 07:50:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DBADfKi1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 382B38489E44; Wed, 20 Sep 2023 07:38:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236593AbjITOik (ORCPT + 27 others); Wed, 20 Sep 2023 10:38:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236489AbjITOiK (ORCPT ); Wed, 20 Sep 2023 10:38:10 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 770C1195; Wed, 20 Sep 2023 07:37:13 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B958C433C7; Wed, 20 Sep 2023 14:37:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695220632; bh=Ugkk2YNICB85GnhlSqD43ohZlCKXw7eOgoeDoDRfEYo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=DBADfKi1tAz8yUIqUYjfR9AFVt39HvXXl5oWFBuhnJGwkEVwqJMRlYaemBlJEwxmI rj4A4KgwLc3ngzL7pXMcvB6WmxcyAKmo2RG1ZQzMPKFJcTxlZZKiho5uVRtojR5mGA rb0WSFX5Dfgy4Rm3/7WMsk7LVzMS89EJvQEEWLXgx5vbXJr20UQ6/rXlOMv5lIVD7f yzbA/HUGdHA+AQHTJadVEvtMs7WV1xygo+YYahakwc5tI8pEzYZ0HXpNA+hgruN0Ot NaYmaySlAXPahBhIMFG+4lvyWtNXi5frOkbWy9XQjX8TJxhTkEtvjf/SP20ue8LMPL RLjfiof8MdS+Q== From: Maxime Ripard Date: Wed, 20 Sep 2023 16:35:47 +0200 Subject: [PATCH RFC v2 32/37] drm/rockchip: inno_hdmi: Switch to HDMI connector MIME-Version: 1.0 Message-Id: <20230920-kms-hdmi-connector-state-v2-32-17932daddd7d@kernel.org> References: <20230920-kms-hdmi-connector-state-v2-0-17932daddd7d@kernel.org> In-Reply-To: <20230920-kms-hdmi-connector-state-v2-0-17932daddd7d@kernel.org> To: Maarten Lankhorst , Thomas Zimmermann , David Airlie , Daniel Vetter , Emma Anholt , Jonathan Corbet , Sandy Huang , =?utf-8?q?Heiko_St=C3=BCbner?= , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Hans Verkuil , dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-sunxi@lists.linux.dev, Maxime Ripard X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=7097; i=mripard@kernel.org; h=from:subject:message-id; bh=Ugkk2YNICB85GnhlSqD43ohZlCKXw7eOgoeDoDRfEYo=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDKnczFa7fcJ12BIdkva2m61NvfHbLmP//bzCn2tUVn/fl /KmUkSho5SFQYyLQVZMkSVG2HxJ3KlZrzvZ+ObBzGFlAhnCwMUpABMRTmH4HxIvmvrr5HtelXNf 1Pav9Hv26LbXGYZkIQlJvtPhn909ZjMyvD+8s3a15cuFZb9S52dPiK791jx/efJHOynPqKS2z3E 83AA= X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 20 Sep 2023 07:38:57 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777568484448989680 X-GMAIL-MSGID: 1777568484448989680 The new HDMI connector infrastructure allows to remove some boilerplate, especially to generate infoframes. Let's switch to it. Signed-off-by: Maxime Ripard --- drivers/gpu/drm/rockchip/inno_hdmi.c | 101 ++++++++++++++--------------------- 1 file changed, 41 insertions(+), 60 deletions(-) diff --git a/drivers/gpu/drm/rockchip/inno_hdmi.c b/drivers/gpu/drm/rockchip/inno_hdmi.c index d0b463d166fb..d5661ef5e00b 100644 --- a/drivers/gpu/drm/rockchip/inno_hdmi.c +++ b/drivers/gpu/drm/rockchip/inno_hdmi.c @@ -223,9 +223,10 @@ static u32 inno_hdmi_get_frame_enable(struct inno_hdmi *hdmi, return 0; } -static void inno_hdmi_disable_frame(struct inno_hdmi *hdmi, - enum hdmi_infoframe_type type) +static int inno_hdmi_disable_frame(struct drm_connector *connector, + enum hdmi_infoframe_type type) { + struct inno_hdmi *hdmi = connector_to_inno_hdmi(connector); u32 frame_index = inno_hdmi_get_frame_index(hdmi, type); u32 disable = inno_hdmi_get_frame_disable(hdmi, type); u32 mask = inno_hdmi_get_frame_mask(hdmi, type); @@ -234,24 +235,23 @@ static void inno_hdmi_disable_frame(struct inno_hdmi *hdmi, hdmi_modb(hdmi, HDMI_PACKET_SEND_AUTO, mask, disable); hdmi_writeb(hdmi, HDMI_CONTROL_PACKET_BUF_INDEX, frame_index); + + return 0; } -static int inno_hdmi_upload_frame(struct inno_hdmi *hdmi, - union hdmi_infoframe *frame, enum hdmi_infoframe_type type) +static int inno_hdmi_upload_frame(struct drm_connector *connector, + enum hdmi_infoframe_type type, + const u8 *buffer, size_t len) { + struct inno_hdmi *hdmi = connector_to_inno_hdmi(connector); u32 enable = inno_hdmi_get_frame_enable(hdmi, type); u32 mask = inno_hdmi_get_frame_mask(hdmi, type); u8 packed_frame[HDMI_MAXIMUM_INFO_FRAME_SIZE]; - ssize_t rc, i; + ssize_t i; - inno_hdmi_disable_frame(hdmi, type); + inno_hdmi_disable_frame(connector, type); - rc = hdmi_infoframe_pack(frame, packed_frame, - sizeof(packed_frame)); - if (rc < 0) - return rc; - - for (i = 0; i < rc; i++) + for (i = 0; i < len; i++) hdmi_writeb(hdmi, HDMI_CONTROL_PACKET_ADDR + i, packed_frame[i]); @@ -261,41 +261,10 @@ static int inno_hdmi_upload_frame(struct inno_hdmi *hdmi, return 0; } -static int inno_hdmi_config_video_vsi(struct inno_hdmi *hdmi, - struct drm_display_mode *mode) -{ - union hdmi_infoframe frame; - int rc; - - rc = drm_hdmi_vendor_infoframe_from_display_mode(&frame.vendor.hdmi, - &hdmi->connector, - mode); - if (rc) { - inno_hdmi_disable_frame(hdmi, HDMI_INFOFRAME_TYPE_VENDOR); - return rc; - } - - return inno_hdmi_upload_frame(hdmi, &frame, HDMI_INFOFRAME_TYPE_VENDOR); -} - -static int inno_hdmi_config_video_avi(struct inno_hdmi *hdmi, - struct drm_display_mode *mode) -{ - union hdmi_infoframe frame; - int rc; - - rc = drm_hdmi_avi_infoframe_from_display_mode(&frame.avi, - &hdmi->connector, - mode); - if (rc) { - inno_hdmi_disable_frame(hdmi, HDMI_INFOFRAME_TYPE_AVI); - return rc; - } - - frame.avi.colorspace = HDMI_COLORSPACE_RGB; - - return inno_hdmi_upload_frame(hdmi, &frame, HDMI_INFOFRAME_TYPE_AVI); -} +static const struct drm_connector_hdmi_funcs inno_hdmi_hdmi_connector_funcs = { + .clear_infoframe = inno_hdmi_disable_frame, + .write_infoframe = inno_hdmi_upload_frame, +}; static int inno_hdmi_config_video_csc(struct inno_hdmi *hdmi) { @@ -374,9 +343,12 @@ static int inno_hdmi_config_video_timing(struct inno_hdmi *hdmi, } static int inno_hdmi_setup(struct inno_hdmi *hdmi, - struct drm_display_mode *mode) + struct drm_crtc_state *new_crtc_state, + struct drm_connector_state *new_conn_state) { - struct drm_display_info *display = &hdmi->connector.display_info; + struct drm_connector *connector = &hdmi->connector; + struct drm_display_info *display = &connector->display_info; + struct drm_display_mode *mode = &new_crtc_state->adjusted_mode; /* Mute video and audio output */ hdmi_modb(hdmi, HDMI_AV_MUTE, m_AUDIO_MUTE | m_VIDEO_BLACK, @@ -390,10 +362,8 @@ static int inno_hdmi_setup(struct inno_hdmi *hdmi, inno_hdmi_config_video_csc(hdmi); - if (display->is_hdmi) { - inno_hdmi_config_video_avi(hdmi, mode); - inno_hdmi_config_video_vsi(hdmi, mode); - } + drm_atomic_helper_connector_hdmi_update_infoframes(connector, + new_conn_state->state); /* * When IP controller have configured to an accurate video @@ -401,7 +371,7 @@ static int inno_hdmi_setup(struct inno_hdmi *hdmi, * DCLK_LCDC, so we need to init the TMDS rate to mode pixel * clock rate, and reconfigure the DDC clock. */ - inno_hdmi_i2c_init(hdmi, mode->clock * 1000); + inno_hdmi_i2c_init(hdmi, new_conn_state->hdmi.tmds_char_rate); /* Unmute video and audio output */ hdmi_modb(hdmi, HDMI_AV_MUTE, m_AUDIO_MUTE | m_VIDEO_BLACK, @@ -425,7 +395,7 @@ static void inno_hdmi_encoder_enable(struct drm_encoder *encoder, if (WARN_ON(!crtc_state)) return; - inno_hdmi_setup(hdmi, &crtc_state->adjusted_mode); + inno_hdmi_setup(hdmi, crtc_state, conn_state); inno_hdmi_set_pwr_mode(hdmi, NORMAL); } @@ -491,6 +461,12 @@ inno_hdmi_probe_single_connector_modes(struct drm_connector *connector, return drm_helper_probe_single_connector_modes(connector, 1920, 1080); } +static void inno_hdmi_connector_reset(struct drm_connector *connector) +{ + drm_atomic_helper_connector_reset(connector); + __drm_atomic_helper_connector_hdmi_reset(connector, connector->state); +} + static void inno_hdmi_connector_destroy(struct drm_connector *connector) { drm_connector_unregister(connector); @@ -501,12 +477,13 @@ static const struct drm_connector_funcs inno_hdmi_connector_funcs = { .fill_modes = inno_hdmi_probe_single_connector_modes, .detect = inno_hdmi_connector_detect, .destroy = inno_hdmi_connector_destroy, - .reset = drm_atomic_helper_connector_reset, + .reset = inno_hdmi_connector_reset, .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, }; static struct drm_connector_helper_funcs inno_hdmi_connector_helper_funcs = { + .atomic_check = drm_atomic_helper_connector_hdmi_check, .get_modes = inno_hdmi_connector_get_modes, }; @@ -533,10 +510,14 @@ static int inno_hdmi_register(struct drm_device *drm, struct inno_hdmi *hdmi) drm_connector_helper_add(&hdmi->connector, &inno_hdmi_connector_helper_funcs); - drm_connector_init_with_ddc(drm, &hdmi->connector, - &inno_hdmi_connector_funcs, - DRM_MODE_CONNECTOR_HDMIA, - hdmi->ddc); + drmm_connector_hdmi_init(drm, &hdmi->connector, + "Rockchip", "Inno HDMI", + &inno_hdmi_connector_funcs, + &inno_hdmi_hdmi_connector_funcs, + DRM_MODE_CONNECTOR_HDMIA, + hdmi->ddc, + BIT(HDMI_COLORSPACE_RGB), + 8); drm_connector_attach_encoder(&hdmi->connector, encoder);