From patchwork Tue Dec 17 00:40:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13910737 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C9FCFE77186 for ; Tue, 17 Dec 2024 00:40:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2D91B10E7FB; Tue, 17 Dec 2024 00:40:45 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="E5Igvo5J"; dkim-atps=neutral Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5E9EE10E7FB for ; Tue, 17 Dec 2024 00:40:40 +0000 (UTC) Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-5401c52000fso4726396e87.2 for ; Mon, 16 Dec 2024 16:40:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1734396039; x=1735000839; darn=lists.freedesktop.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=9/uHPXK/8E1yESmbWnhFymql7tY9M8diwZIDgU0aHhE=; b=E5Igvo5JN9JrXthKVDP2TZfeF9AHXfaKnTR63UWTXywOdg7tfijbR9PbIkCh7qyrJE wEtZKa07uo30n1wV0pmGbH9iReyGW4KHOLddbuTAqhdB6V1xWyfkCDUTUDTeASozztv6 CfKUsfNdh8BQQlt0v2O8/pZUPN65zbnQl42F0FXrb5UvuK8YEiGFCfx+tvWhHxdOGvro q0P2EP4mKEurMLyK4KK36ZotWWM1+G164y7QK9hhnwOKANMvc7R3y6zip9jLx8j1GzoS jU6lglHhyzfIdpvy6tBvrNEBpbsBGFXeWZm6KNR3ZcWdswfEIrKdfhUP52uUO/LR1U73 bu/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734396039; x=1735000839; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9/uHPXK/8E1yESmbWnhFymql7tY9M8diwZIDgU0aHhE=; b=BueCON5Vr19SBSvdHUo/jpWrNL5imtVTHUDMcjt5fK+FgS7GvqkbZb6OMn2q7TQkMy 1RPID1pCBMmG/gCozL7Qk+LYxnRp2YrBaZfx7lzlkX++XeCNjbi3n6RdvImfA+oao6V/ dU+jvAOCOwbvnu+RgNqAOHcBnbBiGjgrX7aqV0f+4QjKYc5oGgtHG73lwxcEm4hhMWyV oX0Ooe0MC4YLKkhb87khmt+QUeHc6KKoV/huBP8dOv30hSQuqJpEb+48pK08RiBcfoVn STvvCxQE9vc5fI8ChKirZn4Hjw4AxlaBOQH/XgFvuU90KT1O0ltB1X5osL6gaqlyReKt F12w== X-Forwarded-Encrypted: i=1; AJvYcCUd6hg33IqIlkUFu8YJ38/etRC7WgbccHGeShKpaSnA0HVnrrdcKEoXfERka8iPD9UBgEBk7CyfRLA=@lists.freedesktop.org X-Gm-Message-State: AOJu0Yxro4qzEQ3Pf8pTYou4TRkzQLC6IR7gHlocGiFUc99hoBRxm9kA ZX6jlZjIKkyg+ttmBRPf7GYQGa30SZQfoyZxBoZ9IYBW2McSBFkc8Vuqa0LRSkw= X-Gm-Gg: ASbGncsJOLj61MIGymEyfpCdljduHqOiAtaLRpBqAINSdZJE5fxUj2a6ENmLbui3Fvz 9yBA+Qf7OiAmPPqpMnzthHUTvJJozqeTuzabPNd4YlvzSeDA0D8HdExSky5N8Z/bMztMfyBluYg m/LE69XvRM9rPz6bj+p3oQLqMViq6Ah1qe6EcR0/fXbchL7LFOkCRluhXxirUFDtTGjHD8+2Lam miayhL7V1k1BCVhIsI3iQ+7ImsdmPsini2lGg67QxGQW+qiNkZ4kxTD4EAfIUOG X-Google-Smtp-Source: AGHT+IFYrXFMGnhjQ3bQDb7oI+kO+vAQWTCO7iUyJKhslsY9vA02Ya9MFO24iaLirmiV7N9WURYCMA== X-Received: by 2002:a05:6512:3b8d:b0:53e:395c:6887 with SMTP id 2adb3069b0e04-5408ad7f875mr4185848e87.2.1734396038601; Mon, 16 Dec 2024 16:40:38 -0800 (PST) Received: from umbar.lan ([192.130.178.90]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-54120ba9ab2sm1009122e87.74.2024.12.16.16.40.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2024 16:40:37 -0800 (PST) From: Dmitry Baryshkov Date: Tue, 17 Dec 2024 02:40:26 +0200 Subject: [PATCH v7 04/10] drm/bridge: connector: add support for HDMI codec framework MIME-Version: 1.0 Message-Id: <20241217-drm-bridge-hdmi-connector-v7-4-cb9df2b6a515@linaro.org> References: <20241217-drm-bridge-hdmi-connector-v7-0-cb9df2b6a515@linaro.org> In-Reply-To: <20241217-drm-bridge-hdmi-connector-v7-0-cb9df2b6a515@linaro.org> To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Jaroslav Kysela , Takashi Iwai , Liam Girdwood , Mark Brown , Phong LE , Inki Dae , Seung-Woo Kim , Kyungmin Park , Krzysztof Kozlowski , Alim Akhtar , Russell King , Chun-Kuang Hu , Philipp Zabel , Matthias Brugger , AngeloGioacchino Del Regno , Sandy Huang , =?utf-8?q?Heiko_St=C3=BCbner?= , Andy Yan , Alain Volmat , Raphael Gallais-Pou , Dave Stevenson , =?utf-8?q?Ma=C3=ADra_Cana?= =?utf-8?q?l?= , Raspberry Pi Kernel Maintenance Cc: Jani Nikula , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=6797; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=oRt1uc2dMf9+pijMkP+eCrRG9ChsIEKJSkVSymmIkws=; b=owGbwMvMwMXYbdNlx6SpcZXxtFoSQ3rCicop/Y/Omi8IsuboCzqw982my1pzWO9vL/VREtwjd 6NhZ1BGJ6MxCwMjF4OsmCKLT0HL1JhNyWEfdkythxnEygQyhYGLUwAmIi/A/j/KRUnowBerA/qn TIV+LpBlndnK1Jdgr+gQ9KjfS81i2sqLvbxfNWo1t1ouzmWf0lTHfLo+dPsvpyC73qXNjfUyzEu D9hzj4Oy9nKUwRbnNLjJkn1n6Gz7zdl19CS6W20XK8vvjKzUnLm9sfzbjQEWF9sSzGcKM/28fZg l6V/Jvnx/z+cYL7BVzq3PlU11r7pya7K5i9mhHNtcX/Yx3R7t2Vjqnf0/y/P1k7+TqWsWy39+DO 6zYZIKm7J12T/7DNS4e/27ThJazLt8580LfHZdiPCf/ovp2L8vl9RoSZRHfJmjsq2tWe6yyyODm qUV2wS1JMyxs5OZpdQV/N8r/1m13bVrz9q1MU43O1YkAAA== X-Developer-Key: i=dmitry.baryshkov@linaro.org; a=openpgp; fpr=8F88381DD5C873E4AE487DA5199BF1243632046A X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Add necessary glue code to be able to use new HDMI codec framework from the DRM bridge drivers. The drm_bridge implements a limited set of the hdmi_codec_ops interface, with the functions accepting both drm_connector and drm_bridge instead of just a generic void pointer. This framework is integrated with the DRM HDMI Connector framework, but can also be used for DisplayPort connectors. Reviewed-by: Maxime Ripard Signed-off-by: Dmitry Baryshkov --- drivers/gpu/drm/display/drm_bridge_connector.c | 98 ++++++++++++++++++++++++-- include/drm/drm_bridge.h | 38 ++++++++++ 2 files changed, 132 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/display/drm_bridge_connector.c b/drivers/gpu/drm/display/drm_bridge_connector.c index 512ced87ea18c74e182a558a686ddd83de891814..be46d2e7cb5cec262ca5dd6f42f8f31b0187a0f7 100644 --- a/drivers/gpu/drm/display/drm_bridge_connector.c +++ b/drivers/gpu/drm/display/drm_bridge_connector.c @@ -374,6 +374,75 @@ static const struct drm_connector_hdmi_funcs drm_bridge_connector_hdmi_funcs = { .write_infoframe = drm_bridge_connector_write_infoframe, }; +static int drm_bridge_connector_audio_startup(struct drm_connector *connector) +{ + struct drm_bridge_connector *bridge_connector = + to_drm_bridge_connector(connector); + struct drm_bridge *bridge; + + bridge = bridge_connector->bridge_hdmi; + if (!bridge) + return -EINVAL; + + if (!bridge->funcs->hdmi_codec_audio_startup) + return 0; + + return bridge->funcs->hdmi_codec_audio_startup(connector, bridge); +} + +static int drm_bridge_connector_prepare(struct drm_connector *connector, + struct hdmi_codec_daifmt *fmt, + struct hdmi_codec_params *hparms) +{ + struct drm_bridge_connector *bridge_connector = + to_drm_bridge_connector(connector); + struct drm_bridge *bridge; + + bridge = bridge_connector->bridge_hdmi; + if (!bridge) + return -EINVAL; + + return bridge->funcs->hdmi_codec_prepare(connector, bridge, fmt, hparms); +} + +static void drm_bridge_connector_audio_shutdown(struct drm_connector *connector) +{ + struct drm_bridge_connector *bridge_connector = + to_drm_bridge_connector(connector); + struct drm_bridge *bridge; + + bridge = bridge_connector->bridge_hdmi; + if (!bridge) + return; + + bridge->funcs->hdmi_codec_audio_shutdown(connector, bridge); +} + +static int drm_bridge_connector_mute_stream(struct drm_connector *connector, + bool enable, int direction) +{ + struct drm_bridge_connector *bridge_connector = + to_drm_bridge_connector(connector); + struct drm_bridge *bridge; + + bridge = bridge_connector->bridge_hdmi; + if (!bridge) + return -EINVAL; + + if (bridge->funcs->hdmi_codec_mute_stream) + return bridge->funcs->hdmi_codec_mute_stream(connector, bridge, + enable, direction); + else + return -ENOTSUPP; +} + +static const struct drm_connector_hdmi_codec_funcs drm_bridge_connector_hdmi_codec_funcs = { + .audio_startup = drm_bridge_connector_audio_startup, + .prepare = drm_bridge_connector_prepare, + .audio_shutdown = drm_bridge_connector_audio_shutdown, + .mute_stream = drm_bridge_connector_mute_stream, +}; + /* ----------------------------------------------------------------------------- * Bridge Connector Initialisation */ @@ -473,7 +542,9 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm, if (connector_type == DRM_MODE_CONNECTOR_Unknown) return ERR_PTR(-EINVAL); - if (bridge_connector->bridge_hdmi) + if (bridge_connector->bridge_hdmi) { + bridge = bridge_connector->bridge_hdmi; + ret = drmm_connector_hdmi_init(drm, connector, bridge_connector->bridge_hdmi->vendor, bridge_connector->bridge_hdmi->product, @@ -482,12 +553,31 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm, connector_type, ddc, supported_formats, max_bpc); - else + if (ret) + return ERR_PTR(ret); + + if (bridge->hdmi_codec_max_i2s_playback_channels || + bridge->hdmi_codec_spdif_playback) { + if (!bridge->funcs->hdmi_codec_prepare || + !bridge->funcs->hdmi_codec_audio_shutdown) + return ERR_PTR(-EINVAL); + + ret = drm_connector_hdmi_audio_init(connector, + bridge->hdmi_codec_dev, + &drm_bridge_connector_hdmi_codec_funcs, + bridge->hdmi_codec_max_i2s_playback_channels, + bridge->hdmi_codec_spdif_playback, + bridge->hdmi_codec_dai_port); + if (ret) + return ERR_PTR(ret); + } + } else { ret = drmm_connector_init(drm, connector, &drm_bridge_connector_funcs, connector_type, ddc); - if (ret) - return ERR_PTR(ret); + if (ret) + return ERR_PTR(ret); + } drm_connector_helper_add(connector, &drm_bridge_connector_helper_funcs); diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h index e8d735b7f6a480468c88287e2517b387ceec0f22..fd7ad7315a8bfda90f02b0704c33ba0e356899fb 100644 --- a/include/drm/drm_bridge.h +++ b/include/drm/drm_bridge.h @@ -41,6 +41,8 @@ struct drm_display_info; struct drm_minor; struct drm_panel; struct edid; +struct hdmi_codec_daifmt; +struct hdmi_codec_params; struct i2c_adapter; /** @@ -676,6 +678,21 @@ struct drm_bridge_funcs { enum hdmi_infoframe_type type, const u8 *buffer, size_t len); + int (*hdmi_codec_audio_startup)(struct drm_connector *connector, + struct drm_bridge *bridge); + + int (*hdmi_codec_prepare)(struct drm_connector *connector, + struct drm_bridge *bridge, + struct hdmi_codec_daifmt *fmt, + struct hdmi_codec_params *hparms); + + void (*hdmi_codec_audio_shutdown)(struct drm_connector *connector, + struct drm_bridge *bridge); + + int (*hdmi_codec_mute_stream)(struct drm_connector *connector, + struct drm_bridge *bridge, + bool enable, int direction); + /** * @debugfs_init: * @@ -859,6 +876,27 @@ struct drm_bridge { * @DRM_BRIDGE_OP_HDMI is set. */ unsigned int max_bpc; + + /** + * @hdmi_codec_dev: device to be used as a parent for the HDMI Codec + */ + struct device *hdmi_codec_dev; + + /** + * @hdmi_codec_max_i2s_playback_channels: maximum number of playback + * I2S channels for the HDMI codec + */ + int hdmi_codec_max_i2s_playback_channels; + + /** + * @hdmi_codec_spdif_playback: set if HDMI codec has S/PDIF playback port + */ + unsigned int hdmi_codec_spdif_playback : 1; + + /** + * @hdmi_codec_dai_port: sound DAI port, -1 if it is not enabled + */ + int hdmi_codec_dai_port; }; static inline struct drm_bridge *