Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2073386lqb; Mon, 27 May 2024 07:07:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXKDvo231g/urfelE2WO4GENnhjTNtr2euC1ztOlduKDdRPMjtUjtrUVJZJkb7z6MzJ8I2z+dn3uEIrUnwabX8HZK2aV2o7lPTZrqN7zA== X-Google-Smtp-Source: AGHT+IHnO94GGH6hJqZ8mSoDEVJLYWARuinUfaVUWYmahadwcARk7Qv5sqiQ2wnCdRyLT1r0ZGjg X-Received: by 2002:a50:9505:0:b0:572:a4eb:6678 with SMTP id 4fb4d7f45d1cf-57843f2d31fmr11905504a12.19.1716818856896; Mon, 27 May 2024 07:07:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716818856; cv=pass; d=google.com; s=arc-20160816; b=aAcybXoE6qto6oW/V7MdXK/pnZiS1yoQfD6uKsvTPoLRnDyS3bQgmmaHsoVkDP0xp2 Fg+p95OPPb+7m9X7m1hcm6/LIbjq5MD2zF17X+W6CqK6DCQ1Pvja+J20DHPCWsMNfRCR 9Ld2b6+X886tb1jDs5CSCOUAZmiqY23s682UQxVUikZwVI9dEeN0y6XC7IOyurSu+Idn XZ2EdN8M0FsxkWpaoBcwRYR3CWzG9LADonDE6MQl+UMOIRZ7oC77CYQHp6mjQgK34m8Z aJ1F8pgiU9s5KDtgNXcjicVDCuHzhVhnFfSTUKruHzkgMgOpLAWlK1fYU/6ukghfnX2O mxGg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=KJlt5GiHeM56E3HjxTdsA+0PbviKFU8oAuPVV/kY4uw=; fh=KcRiIXgS7fm26NoU+2dsmXh6SEQAfLtyDYKNJlNPkCU=; b=X/pyZdBpa71VLzyMYQYfvXzdhQpNXZiRb0oA+/hHpTx4YNioyP9SjKqfdNFLlftX9Y BlryHVT7RQF5Y1gW3d4iV+Iu4o1BkwFwPPMiKPpbZB2PcCVCJlqn4WmKbOcTPiat0iz8 gaM6z0TIdZacg08w3CtyrtmKahrxkZYOuwsGjI0/gkSuS5I3IX+8nyDAlu/FWhJZLcic /vRC7T7pMppUKvPEndgFnLCFt0kqDhzGgvL4FJnRgPIA6cpUuzpXWF/6ckR0+Fl0JT91 amST5B6z+jtQqpYVhp0NsSzdbUUhOOxWeHNUhDqYu7FVjXuZg0N+IitcfpT6FNN71AaR 62PQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=M7BNdM2b; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-190792-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190792-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-579c6166f52si1971027a12.572.2024.05.27.07.07.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 07:07:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-190792-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=M7BNdM2b; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-190792-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190792-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 77A7D1F2160E for ; Mon, 27 May 2024 14:07:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 54DC116F820; Mon, 27 May 2024 13:59:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="M7BNdM2b" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A13016F286; Mon, 27 May 2024 13:59:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716818369; cv=none; b=jCJs244ESKFzAWYPEZYhBf0faiR2SO1VnA8Uph7HxdZvzv1CxaVYxzfviL1Dw6IVUkc1slEtYjbW3L1rDg8FfcQzHtOhb4WjPQQKo2svf9Rhf9ZpBFKF2p9RSAPHy+On83evhZbTvrlHrpPIPIoBGIoED7AfOC9h37QGwq3JDm4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716818369; c=relaxed/simple; bh=N2lpXB9UWDHdmAGzrdaI6LVuOjJs/cip2IvGEZbGBKc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=erOZW4+Jm4NC6hmW/X5/Z25+sgobY38PL6DDfNjp/927yX3LvtRpptXu4Ybl1ZjYp9F2c7/CN+w2bYjd5CMfoSSmvM28Jrhvlu02lq36bG3pZSiTjuO0u7lKS2bbC9AQzCtCgmg5Q55/59f0hhl+vsdBMRdk/zYqnGrel0wENWM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=M7BNdM2b; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4FA68C2BBFC; Mon, 27 May 2024 13:59:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716818368; bh=N2lpXB9UWDHdmAGzrdaI6LVuOjJs/cip2IvGEZbGBKc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=M7BNdM2bIbJVm6RG52TEjAeRhu5hFUOnoVAvXOM6bvq4tBUGLFdFoupXbQtWY9HIq f4xcv2I3AuE4QRqrg/EH//m3zuXtVZYGp5xtLvMQZ9CCxsb2B0In//umkgLPpsBbLH jPUCX4hQ0NHaFYSmGPl8DadcRV73OJKYxlV/6BaghtedopKFIfE2MUUMvGVmSWY0c1 Q+V9cGwJTT90OLVKZIdXEU6y8OHwETdIOMdiXDNWA5g46rMBl8x1kTZyF+cUuYudtJ F5WM2Hn56TI7vvMT8kLKeYoNYXX1e7CXCKRXxOaqf20hdQ+AR1L7fhPjiYtwoMwx+A MAanplSKD8vZA== From: Maxime Ripard Date: Mon, 27 May 2024 15:58:18 +0200 Subject: [PATCH v15 29/29] drm/sun4i: hdmi: Switch to HDMI connector Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240527-kms-hdmi-connector-state-v15-29-c5af16c3aae2@kernel.org> References: <20240527-kms-hdmi-connector-state-v15-0-c5af16c3aae2@kernel.org> In-Reply-To: <20240527-kms-hdmi-connector-state-v15-0-c5af16c3aae2@kernel.org> To: Maarten Lankhorst , Thomas Zimmermann , David Airlie , Daniel Vetter , Jonathan Corbet , Sandy Huang , =?utf-8?q?Heiko_St=C3=BCbner?= , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Andy Yan Cc: Hans Verkuil , Sebastian Wick , =?utf-8?q?Ville_Syrj=C3=A4l=C3=A4?= , 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 , Sui Jingfeng , Andy Yan X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=8119; i=mripard@kernel.org; h=from:subject:message-id; bh=N2lpXB9UWDHdmAGzrdaI6LVuOjJs/cip2IvGEZbGBKc=; b=owGbwMvMwCmsHn9OcpHtvjLG02pJDGkhE3NX+i/p/RW6hc3NT4rFR3/inX8NPctea8732ziZb c28X/U7O6ayMAhzMsiKKbI8kQk7vbx9cZWD/cofMHNYmUCGMHBxCsBEzKcz1tlLiD9Y0+YUsy2y 9rjH9y2KNo2xvM/2J79NsRF242nm3H6Ot3rLI5kayeWPmyY+fqO/nLHhrZWX0rJli09wfNhqezf W1zdq0rdNmtuDTmktSlp8f9m6g99k/rQlSLPkTFu/XE5v0xppAA== X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D The new HDMI connector infrastructure allows to remove some boilerplate, especially to generate infoframes. Let's switch to it. Reviewed-by: Jernej Skrabec Acked-by: Sui Jingfeng Reviewed-by: Andy Yan Signed-off-by: Maxime Ripard --- drivers/gpu/drm/sun4i/Kconfig | 3 ++ drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c | 84 ++++++++++++++++++++++------------ 2 files changed, 57 insertions(+), 30 deletions(-) diff --git a/drivers/gpu/drm/sun4i/Kconfig b/drivers/gpu/drm/sun4i/Kconfig index 4741d9f6544c..4037e085430e 100644 --- a/drivers/gpu/drm/sun4i/Kconfig +++ b/drivers/gpu/drm/sun4i/Kconfig @@ -16,10 +16,13 @@ config DRM_SUN4I if DRM_SUN4I config DRM_SUN4I_HDMI tristate "Allwinner A10/A10s/A20/A31 HDMI Controller Support" depends on ARM || COMPILE_TEST + select DRM_DISPLAY_HDMI_HELPER + select DRM_DISPLAY_HDMI_STATE_HELPER + select DRM_DISPLAY_HELPER default DRM_SUN4I help Choose this option if you have an Allwinner A10/A10s/A20/A31 SoC with an HDMI controller. diff --git a/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c b/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c index 245b34adca5a..0e652dd480c9 100644 --- a/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c +++ b/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c @@ -24,10 +24,13 @@ #include #include #include #include +#include +#include + #include "sun4i_backend.h" #include "sun4i_crtc.h" #include "sun4i_drv.h" #include "sun4i_hdmi.h" @@ -35,34 +38,28 @@ container_of_const(e, struct sun4i_hdmi, encoder) #define drm_connector_to_sun4i_hdmi(c) \ container_of_const(c, struct sun4i_hdmi, connector) -static int sun4i_hdmi_setup_avi_infoframes(struct sun4i_hdmi *hdmi, - struct drm_display_mode *mode) +static int sun4i_hdmi_write_infoframe(struct drm_connector *connector, + enum hdmi_infoframe_type type, + const u8 *buffer, size_t len) { - struct hdmi_avi_infoframe frame; - u8 buffer[17]; - int i, ret; + struct sun4i_hdmi *hdmi = drm_connector_to_sun4i_hdmi(connector); + int i; - ret = drm_hdmi_avi_infoframe_from_display_mode(&frame, - &hdmi->connector, mode); - if (ret < 0) { - DRM_ERROR("Failed to get infoframes from mode\n"); - return ret; + if (type != HDMI_INFOFRAME_TYPE_AVI) { + drm_err(connector->dev, + "Unsupported infoframe type: %u\n", type); + return 0; } - ret = hdmi_avi_infoframe_pack(&frame, buffer, sizeof(buffer)); - if (ret < 0) { - DRM_ERROR("Failed to pack infoframes\n"); - return ret; - } - - for (i = 0; i < sizeof(buffer); i++) + for (i = 0; i < len; i++) writeb(buffer[i], hdmi->base + SUN4I_HDMI_AVI_INFOFRAME_REG(i)); return 0; + } static void sun4i_hdmi_disable(struct drm_encoder *encoder, struct drm_atomic_state *state) { @@ -81,18 +78,22 @@ static void sun4i_hdmi_disable(struct drm_encoder *encoder, static void sun4i_hdmi_enable(struct drm_encoder *encoder, struct drm_atomic_state *state) { struct drm_display_mode *mode = &encoder->crtc->state->adjusted_mode; struct sun4i_hdmi *hdmi = drm_encoder_to_sun4i_hdmi(encoder); - 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_connector_state *conn_state = + drm_atomic_get_new_connector_state(state, connector); + unsigned long long tmds_rate = conn_state->hdmi.tmds_char_rate; unsigned int x, y; u32 val = 0; DRM_DEBUG_DRIVER("Enabling the HDMI Output\n"); - clk_set_rate(hdmi->mod_clk, mode->crtc_clock * 1000); - clk_set_rate(hdmi->tmds_clk, mode->crtc_clock * 1000); + clk_set_rate(hdmi->mod_clk, tmds_rate); + clk_set_rate(hdmi->tmds_clk, tmds_rate); /* Set input sync enable */ writel(SUN4I_HDMI_UNKNOWN_INPUT_SYNC, hdmi->base + SUN4I_HDMI_UNKNOWN_REG); @@ -141,11 +142,12 @@ static void sun4i_hdmi_enable(struct drm_encoder *encoder, writel(val, hdmi->base + SUN4I_HDMI_VID_TIMING_POL_REG); clk_prepare_enable(hdmi->tmds_clk); - sun4i_hdmi_setup_avi_infoframes(hdmi, mode); + drm_atomic_helper_connector_hdmi_update_infoframes(connector, state); + val |= SUN4I_HDMI_PKT_CTRL_TYPE(0, SUN4I_HDMI_PKT_AVI); val |= SUN4I_HDMI_PKT_CTRL_TYPE(1, SUN4I_HDMI_PKT_END); writel(val, hdmi->base + SUN4I_HDMI_PKT_CTRL_REG(0)); val = SUN4I_HDMI_VID_CTRL_ENABLE; @@ -194,23 +196,26 @@ static int sun4i_hdmi_connector_atomic_check(struct drm_connector *connector, struct drm_crtc_state *crtc_state = crtc->state; struct drm_display_mode *mode = &crtc_state->adjusted_mode; enum drm_mode_status status; status = sun4i_hdmi_connector_clock_valid(connector, mode, - mode->clock * 1000); + conn_state->hdmi.tmds_char_rate); if (status != MODE_OK) return -EINVAL; return 0; } static enum drm_mode_status sun4i_hdmi_connector_mode_valid(struct drm_connector *connector, struct drm_display_mode *mode) { - return sun4i_hdmi_connector_clock_valid(connector, mode, - mode->clock * 1000); + unsigned long long rate = + drm_connector_hdmi_compute_mode_clock(mode, 8, + HDMI_COLORSPACE_RGB); + + return sun4i_hdmi_connector_clock_valid(connector, mode, rate); } static int sun4i_hdmi_get_modes(struct drm_connector *connector) { struct sun4i_hdmi *hdmi = drm_connector_to_sun4i_hdmi(connector); @@ -256,10 +261,15 @@ static struct i2c_adapter *sun4i_hdmi_get_ddc(struct device *dev) return ERR_PTR(-EPROBE_DEFER); return ddc; } +static const struct drm_connector_hdmi_funcs sun4i_hdmi_hdmi_connector_funcs = { + .tmds_char_rate_valid = sun4i_hdmi_connector_clock_valid, + .write_infoframe = sun4i_hdmi_write_infoframe, +}; + static const struct drm_connector_helper_funcs sun4i_hdmi_connector_helper_funcs = { .atomic_check = sun4i_hdmi_connector_atomic_check, .mode_valid = sun4i_hdmi_connector_mode_valid, .get_modes = sun4i_hdmi_get_modes, }; @@ -277,15 +287,20 @@ sun4i_hdmi_connector_detect(struct drm_connector *connector, bool force) } return connector_status_connected; } +static void sun4i_hdmi_connector_reset(struct drm_connector *connector) +{ + drm_atomic_helper_connector_reset(connector); + __drm_atomic_helper_connector_hdmi_reset(connector, connector->state); +} + static const struct drm_connector_funcs sun4i_hdmi_connector_funcs = { .detect = sun4i_hdmi_connector_detect, .fill_modes = drm_helper_probe_single_connector_modes, - .destroy = drm_connector_cleanup, - .reset = drm_atomic_helper_connector_reset, + .reset = sun4i_hdmi_connector_reset, .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, }; #ifdef CONFIG_DRM_SUN4I_HDMI_CEC @@ -640,14 +655,23 @@ static int sun4i_hdmi_bind(struct device *dev, struct device *master, hdmi->base + SUN4I_HDMI_CEC); #endif drm_connector_helper_add(&hdmi->connector, &sun4i_hdmi_connector_helper_funcs); - ret = drm_connector_init_with_ddc(drm, &hdmi->connector, - &sun4i_hdmi_connector_funcs, - DRM_MODE_CONNECTOR_HDMIA, - hdmi->ddc_i2c); + ret = drmm_connector_hdmi_init(drm, &hdmi->connector, + /* + * NOTE: Those are likely to be + * wrong, but I couldn't find the + * actual ones in the BSP. + */ + "AW", "HDMI", + &sun4i_hdmi_connector_funcs, + &sun4i_hdmi_hdmi_connector_funcs, + DRM_MODE_CONNECTOR_HDMIA, + hdmi->ddc_i2c, + BIT(HDMI_COLORSPACE_RGB), + 8); if (ret) { dev_err(dev, "Couldn't initialise the HDMI connector\n"); goto err_cleanup_connector; } -- 2.45.0