From nobody Tue Feb 10 12:42:38 2026 Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 875A91865F0 for ; Sat, 8 Feb 2025 00:27:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738974446; cv=none; b=SyS8qI1SbEUgP9GEWSSQBp0gfT37d1Olv1REl8flYoFEDiVjH8x9/NaPj0wQ1nqxVtwjcLXYAUpczeVsUT6CUpX/+REwd8JANqCX08sgho7KOvVsRuWkjcqN+4X9iAN46oo2sflnAjUatuj4Dw0ld18jPTczVNhfyRc44GM+o+4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738974446; c=relaxed/simple; bh=mmljonIq4bmX1OF/1IouRRVjrYkdx+Ed4/wrzZ3byT8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aWo8DBoQn+atfeCuN9FW0cnEq+lgkmXHlDuZOZWvSb/ImRVXqNXyMH8CjXGhWzIPrY+ZLNUHU97ezNMg3R4+4javc2LTJr9ImBUY5Aij/uQ/gc3/gqgdGGU3Qbld7I4zH6fPA+zfedMMzXlZryyIWR58zlE6nwjKTLrrFggCQeY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=x/bHIogz; arc=none smtp.client-ip=209.85.167.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="x/bHIogz" Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-54410d769f7so2584205e87.3 for ; Fri, 07 Feb 2025 16:27:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1738974443; x=1739579243; darn=vger.kernel.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=RKBfihIb/7toQsuPMJ42zqQSv8Lp5KmiSybZXSECDfY=; b=x/bHIogzkgeONs0LmcfOv+gJ1t89AMHR3GY53sMOQe4x0A6XkLcpZIK8t1v072ERH+ aeBb05oxnaVrMOYOlECwL6yNdIJyUk2xjfjhSsirrN+n0CqmIVWZu+4Tu4otque9ZEbi coYr7Lqe+gSP4P9CJdosloVv9pF9I1HtOYzxnWJjJ3EdxQ3OCUvLilTaQLBb3pPk5BIX 4P3DsBDGz2j1R/ZQLMIe78hlDMytfim1lB3w7edv3E194rOrTE2SYW0xdGL9qU56rUph WJFRZRUTolQE/6snfJii9XtFVhEh8ChqkIvyj+pGxxZ0sokkxu+wdAOYMMbR5U5hf24R 5q/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738974443; x=1739579243; 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=RKBfihIb/7toQsuPMJ42zqQSv8Lp5KmiSybZXSECDfY=; b=JRYOiHX4oqJUMpnym2uKBVKSJGQPIzqiyRrq+4Vh+3AeU9YymirIU5RkKxKqb7CrvM JZhikLDv+dstwOnpEcUpNOVocNHC68MWwlMApk2moxa3COIKsLBCGJDwcDqsp0ln14Xm 9EpEZNEtuPHX8O5Z4chNPrYV6qG9FCRtgH8qbzKWOAhFZhca84AXMARGuvmVPY4PEIkZ +apq3+SjsZAST+2rgr4Sw4k4weRyPKzbu4gFYu6Gczy/Qj+IjDquWK/jQQ3DPRDT+7m+ 1d4G1S1XLAP6Ncd1sLIDEoCKlGAzhWkk718VLzFDxKV5B9L6hWR6MQSFo6dNohZcOW5N vtfw== X-Forwarded-Encrypted: i=1; AJvYcCXAE69eL71WnKsnmsmKqVEJI/QUHp4Slk1k4n3TFskLv96eIQoigllFkzJmsYrkT/fyh/v4m6PrYTXMPxI=@vger.kernel.org X-Gm-Message-State: AOJu0YzntYX1zOj/IUStsUfaVsBefcxBGU3zRUZatHvegW/0zvkEM+Qh hrX6qORkcw641Ob1kmY8kMYj4o/UBYkrLA8l28P6xoqAv2TCRHxIxAYIjAwJxCA= X-Gm-Gg: ASbGncszI4HPvBp1dgeXfMRx4kYcMf8VaoWT6G1eIjLLt2N8tEb2cGReY81HZt+2kuq /eCE9f68CoGUp56t/vaxrdz/9DEtG4FUo6IhfJgO56TqVgHSVd6nyhHv8WmPoAuPR/8NNuO2VrE poOpNo62Iy2fVxxtazeGqXL5PbvxovM4RwhUZ99ISi+5bCLgtZ9/CcEppSSfUGvZEpHTojB30F5 Mort/kzLG4yY3fWQqtIO0O7Rq3LWyvrHL1XEcxl5FHjKGkD1Gs6Dmvo41J0bGu4fA7st7N3phCf EL8mOlIoyYg2BiSRWgv/gxE= X-Google-Smtp-Source: AGHT+IHZSW4Dkfz7HURQi0tLhTK84rJtDghh8lEJ0rbz/uo2oI/zXnEvOcA2okiZEs8sAKjV9XPpeQ== X-Received: by 2002:a05:6512:70e:b0:544:1429:966b with SMTP id 2adb3069b0e04-54414ae6304mr1353119e87.50.1738974442559; Fri, 07 Feb 2025 16:27:22 -0800 (PST) Received: from umbar.lan ([192.130.178.90]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5441060413asm588785e87.222.2025.02.07.16.27.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Feb 2025 16:27:21 -0800 (PST) From: Dmitry Baryshkov Date: Sat, 08 Feb 2025 02:27:06 +0200 Subject: [PATCH v7 7/7] drm/msm/hdmi: use DRM HDMI Audio framework 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: quoted-printable Message-Id: <20250208-bridge-hdmi-connector-v7-7-0c3837f00258@linaro.org> References: <20250208-bridge-hdmi-connector-v7-0-0c3837f00258@linaro.org> In-Reply-To: <20250208-bridge-hdmi-connector-v7-0-0c3837f00258@linaro.org> To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Rob Clark , Abhinav Kumar , Sean Paul , Marijn Suijten , Simona Vetter , Simona Vetter Cc: dri-devel@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=9768; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=mmljonIq4bmX1OF/1IouRRVjrYkdx+Ed4/wrzZ3byT8=; b=owEBbQGS/pANAwAKAYs8ij4CKSjVAcsmYgBnpqTWkEs9L1fxTSs1igqv+ShEHJooNjO8pNQ9s F4jUjrUx9aJATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCZ6ak1gAKCRCLPIo+Aiko 1X2HCACkBByn92WsrGJqa5QaM/8pWvBtmUs9SmuLwIsjn++TDN7FD3Ukh0c4NbF+MYJvGt2jOuv KFW6Dp4lOUIDm+CUArHlNIja+vCSpv7h5Czyh8Nv5TlMIjJH+RcZVoyPa9610EWusOABoDluSMA POoJ+PrYrYkht0iBrIhot9LHW8zm7H0g+/0t0O5y8j5bSasAjYADTqaHc+Q9TOUd4TLuckZCbfN m9QHw/izPjI2lCtYk/QM6Y9IGJXePtvydKY2JGH2oHedJiXVbUSI413JzkrkN8kVz6lU+5s8ifz MeatTUaZ9JEMLjhIhodifpye8BwnLqSb2112Jpzc2J6F8uXY X-Developer-Key: i=dmitry.baryshkov@linaro.org; a=openpgp; fpr=8F88381DD5C873E4AE487DA5199BF1243632046A In order to simplify the driver even further and to remove the boilerplate code, rewrite the audio interface to use the DRM HDMI Audio framework. Audio InfoFames are controlled centrally via the DRM HDMI framework. Correct InfoFrame data is programmed at the atomic_pre_enable() time (if it was set before, drm_atomic_helper_connector_hdmi_update_infoframes() takes care of writing all InfoFrames, including the Audio one.) or during msm_hdmi_bridge_audio_prepare() when the new stream is started. All audio data frame management is deferred to msm_hdmi_bridge_audio_prepare() and msm_hdmi_bridge_audio_shutdown(). Reviewed-by: Maxime Ripard Signed-off-by: Dmitry Baryshkov Reviewed-by: Abhinav Kumar --- drivers/gpu/drm/msm/hdmi/hdmi.c | 91 ------------------------------= ---- drivers/gpu/drm/msm/hdmi/hdmi.h | 18 +++---- drivers/gpu/drm/msm/hdmi/hdmi_audio.c | 68 +++++++++++++++++++++---- drivers/gpu/drm/msm/hdmi/hdmi_bridge.c | 5 ++ 4 files changed, 71 insertions(+), 111 deletions(-) diff --git a/drivers/gpu/drm/msm/hdmi/hdmi.c b/drivers/gpu/drm/msm/hdmi/hdm= i.c index 6b77e0fb8d5ec218dfbf58215e2e12ad1dfb1b85..248541ff449204c72cd444458da= db9ae4a0a53d1 100644 --- a/drivers/gpu/drm/msm/hdmi/hdmi.c +++ b/drivers/gpu/drm/msm/hdmi/hdmi.c @@ -14,7 +14,6 @@ #include #include =20 -#include #include "hdmi.h" =20 void msm_hdmi_set_mode(struct hdmi *hdmi, bool power_on) @@ -245,87 +244,6 @@ static const struct hdmi_platform_config hdmi_tx_8974_= config =3D { .hpd_freq =3D hpd_clk_freq_8x74, }; =20 -/* - * HDMI audio codec callbacks - */ -static int msm_hdmi_audio_hw_params(struct device *dev, void *data, - struct hdmi_codec_daifmt *daifmt, - struct hdmi_codec_params *params) -{ - struct hdmi *hdmi =3D dev_get_drvdata(dev); - unsigned int rate; - int ret; - - DRM_DEV_DEBUG(dev, "%u Hz, %d bit, %d channels\n", params->sample_rate, - params->sample_width, params->cea.channels); - - switch (params->sample_rate) { - case 32000: - rate =3D HDMI_SAMPLE_RATE_32KHZ; - break; - case 44100: - rate =3D HDMI_SAMPLE_RATE_44_1KHZ; - break; - case 48000: - rate =3D HDMI_SAMPLE_RATE_48KHZ; - break; - case 88200: - rate =3D HDMI_SAMPLE_RATE_88_2KHZ; - break; - case 96000: - rate =3D HDMI_SAMPLE_RATE_96KHZ; - break; - case 176400: - rate =3D HDMI_SAMPLE_RATE_176_4KHZ; - break; - case 192000: - rate =3D HDMI_SAMPLE_RATE_192KHZ; - break; - default: - DRM_DEV_ERROR(dev, "rate[%d] not supported!\n", - params->sample_rate); - return -EINVAL; - } - - ret =3D drm_atomic_helper_connector_hdmi_update_audio_infoframe(hdmi->con= nector, - ¶ms->cea); - if (ret) - return ret; - - msm_hdmi_audio_info_setup(hdmi, rate, params->cea.channels); - - return 0; -} - -static void msm_hdmi_audio_shutdown(struct device *dev, void *data) -{ - struct hdmi *hdmi =3D dev_get_drvdata(dev); - - drm_atomic_helper_connector_hdmi_clear_audio_infoframe(hdmi->connector); - msm_hdmi_audio_disable(hdmi); -} - -static const struct hdmi_codec_ops msm_hdmi_audio_codec_ops =3D { - .hw_params =3D msm_hdmi_audio_hw_params, - .audio_shutdown =3D msm_hdmi_audio_shutdown, -}; - -static struct hdmi_codec_pdata codec_data =3D { - .ops =3D &msm_hdmi_audio_codec_ops, - .max_i2s_channels =3D 8, - .i2s =3D 1, -}; - -static int msm_hdmi_register_audio_driver(struct hdmi *hdmi, struct device= *dev) -{ - hdmi->audio_pdev =3D platform_device_register_data(dev, - HDMI_CODEC_DRV_NAME, - PLATFORM_DEVID_AUTO, - &codec_data, - sizeof(codec_data)); - return PTR_ERR_OR_ZERO(hdmi->audio_pdev); -} - static int msm_hdmi_bind(struct device *dev, struct device *master, void *= data) { struct msm_drm_private *priv =3D dev_get_drvdata(master); @@ -337,12 +255,6 @@ static int msm_hdmi_bind(struct device *dev, struct de= vice *master, void *data) return err; priv->hdmi =3D hdmi; =20 - err =3D msm_hdmi_register_audio_driver(hdmi, dev); - if (err) { - DRM_ERROR("Failed to attach an audio codec %d\n", err); - hdmi->audio_pdev =3D NULL; - } - return 0; } =20 @@ -352,9 +264,6 @@ static void msm_hdmi_unbind(struct device *dev, struct = device *master, struct msm_drm_private *priv =3D dev_get_drvdata(master); =20 if (priv->hdmi) { - if (priv->hdmi->audio_pdev) - platform_device_unregister(priv->hdmi->audio_pdev); - if (priv->hdmi->bridge) msm_hdmi_hpd_disable(priv->hdmi); =20 diff --git a/drivers/gpu/drm/msm/hdmi/hdmi.h b/drivers/gpu/drm/msm/hdmi/hdm= i.h index cdd3bd4f37831f9a606a4c3627a48364f5d4025f..a5f481c39277631b7a19d294b08= 6d6208be26511 100644 --- a/drivers/gpu/drm/msm/hdmi/hdmi.h +++ b/drivers/gpu/drm/msm/hdmi/hdmi.h @@ -33,7 +33,6 @@ struct hdmi_hdcp_ctrl; struct hdmi { struct drm_device *dev; struct platform_device *pdev; - struct platform_device *audio_pdev; =20 const struct hdmi_platform_config *config; =20 @@ -205,17 +204,16 @@ static inline int msm_hdmi_pll_8998_init(struct platf= orm_device *pdev) /* * audio: */ -#define HDMI_SAMPLE_RATE_32KHZ 0 -#define HDMI_SAMPLE_RATE_44_1KHZ 1 -#define HDMI_SAMPLE_RATE_48KHZ 2 -#define HDMI_SAMPLE_RATE_88_2KHZ 3 -#define HDMI_SAMPLE_RATE_96KHZ 4 -#define HDMI_SAMPLE_RATE_176_4KHZ 5 -#define HDMI_SAMPLE_RATE_192KHZ 6 +struct hdmi_codec_daifmt; +struct hdmi_codec_params; =20 int msm_hdmi_audio_update(struct hdmi *hdmi); -int msm_hdmi_audio_info_setup(struct hdmi *hdmi, int rate, int channels); -int msm_hdmi_audio_disable(struct hdmi *hdmi); +int msm_hdmi_bridge_audio_prepare(struct drm_connector *connector, + struct drm_bridge *bridge, + struct hdmi_codec_daifmt *daifmt, + struct hdmi_codec_params *params); +void msm_hdmi_bridge_audio_shutdown(struct drm_connector *connector, + struct drm_bridge *bridge); =20 /* * hdmi bridge: diff --git a/drivers/gpu/drm/msm/hdmi/hdmi_audio.c b/drivers/gpu/drm/msm/hd= mi/hdmi_audio.c index 0b91ed5eabd234ff3bca0c2dfaa159dd2e6a9df5..8bb975e82c17c1d77217128e9dd= bd6a0575bb33d 100644 --- a/drivers/gpu/drm/msm/hdmi/hdmi_audio.c +++ b/drivers/gpu/drm/msm/hdmi/hdmi_audio.c @@ -4,7 +4,12 @@ * Author: Rob Clark */ =20 +#include + #include + +#include + #include "hdmi.h" =20 /* Supported HDMI Audio sample rates */ @@ -192,29 +197,72 @@ int msm_hdmi_audio_update(struct hdmi *hdmi) return 0; } =20 -int msm_hdmi_audio_info_setup(struct hdmi *hdmi, int rate, int channels) +int msm_hdmi_bridge_audio_prepare(struct drm_connector *connector, + struct drm_bridge *bridge, + struct hdmi_codec_daifmt *daifmt, + struct hdmi_codec_params *params) { - if (!hdmi) - return -ENXIO; - - if ((rate < 0) || (rate >=3D MSM_HDMI_SAMPLE_RATE_MAX)) + struct hdmi_bridge *hdmi_bridge =3D to_hdmi_bridge(bridge); + struct hdmi *hdmi =3D hdmi_bridge->hdmi; + unsigned int rate; + int ret; + + drm_dbg_driver(bridge->dev, "%u Hz, %d bit, %d channels\n", + params->sample_rate, + params->sample_width, + params->cea.channels); + + switch (params->sample_rate) { + case 32000: + rate =3D MSM_HDMI_SAMPLE_RATE_32KHZ; + break; + case 44100: + rate =3D MSM_HDMI_SAMPLE_RATE_44_1KHZ; + break; + case 48000: + rate =3D MSM_HDMI_SAMPLE_RATE_48KHZ; + break; + case 88200: + rate =3D MSM_HDMI_SAMPLE_RATE_88_2KHZ; + break; + case 96000: + rate =3D MSM_HDMI_SAMPLE_RATE_96KHZ; + break; + case 176400: + rate =3D MSM_HDMI_SAMPLE_RATE_176_4KHZ; + break; + case 192000: + rate =3D MSM_HDMI_SAMPLE_RATE_192KHZ; + break; + default: + drm_err(bridge->dev, "rate[%d] not supported!\n", + params->sample_rate); return -EINVAL; + } + + ret =3D drm_atomic_helper_connector_hdmi_update_audio_infoframe(connector, + ¶ms->cea); + if (ret) + return ret; =20 hdmi->audio.rate =3D rate; - hdmi->audio.channels =3D channels; + hdmi->audio.channels =3D params->cea.channels; hdmi->audio.enabled =3D true; =20 return msm_hdmi_audio_update(hdmi); } =20 -int msm_hdmi_audio_disable(struct hdmi *hdmi) +void msm_hdmi_bridge_audio_shutdown(struct drm_connector *connector, + struct drm_bridge *bridge) { - if (!hdmi) - return -ENXIO; + struct hdmi_bridge *hdmi_bridge =3D to_hdmi_bridge(bridge); + struct hdmi *hdmi =3D hdmi_bridge->hdmi; + + drm_atomic_helper_connector_hdmi_clear_audio_infoframe(connector); =20 hdmi->audio.rate =3D 0; hdmi->audio.channels =3D 2; hdmi->audio.enabled =3D false; =20 - return msm_hdmi_audio_update(hdmi); + msm_hdmi_audio_update(hdmi); } diff --git a/drivers/gpu/drm/msm/hdmi/hdmi_bridge.c b/drivers/gpu/drm/msm/h= dmi/hdmi_bridge.c index aee75eee3d4244cd95e44df46d65b8e3e53de735..c6659e62594558b3c0c25de36aa= 8c459aa253834 100644 --- a/drivers/gpu/drm/msm/hdmi/hdmi_bridge.c +++ b/drivers/gpu/drm/msm/hdmi/hdmi_bridge.c @@ -478,6 +478,8 @@ static const struct drm_bridge_funcs msm_hdmi_bridge_fu= ncs =3D { .hdmi_tmds_char_rate_valid =3D msm_hdmi_bridge_tmds_char_rate_valid, .hdmi_clear_infoframe =3D msm_hdmi_bridge_clear_infoframe, .hdmi_write_infoframe =3D msm_hdmi_bridge_write_infoframe, + .hdmi_audio_prepare =3D msm_hdmi_bridge_audio_prepare, + .hdmi_audio_shutdown =3D msm_hdmi_bridge_audio_shutdown, }; =20 static void @@ -515,6 +517,9 @@ int msm_hdmi_bridge_init(struct hdmi *hdmi) DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_HDMI | DRM_BRIDGE_OP_EDID; + bridge->hdmi_audio_max_i2s_playback_channels =3D 8; + bridge->hdmi_audio_dev =3D &hdmi->pdev->dev; + bridge->hdmi_audio_dai_port =3D -1; =20 ret =3D devm_drm_bridge_add(hdmi->dev->dev, bridge); if (ret) --=20 2.39.5