From nobody Sun Nov 24 01:12:43 2024 Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (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 DFA791990C8 for ; Sat, 9 Nov 2024 12:48:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731156528; cv=none; b=VbW7dgmqE98LTbQMx1SfdnVTNiHextkjFXEs3GntCaIxpjRsyGnPih1iSW0latvryNJ8BH1BRGQ5Jufe/jV7OjVi0PzAKbUeW5Za+566DhDxs9qr1GlH5BB9YF6hvG8oye39m8kq7RktoAFQNUa5k9Te3prHHZWt6t0m6CFOSog= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731156528; c=relaxed/simple; bh=b9CjlXHFjClXWt0twlUk/5oI0wepnqrV5DObVEdOLnI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TdYcEgwsIC3b4tHHxPNHml5WcaNm1CzfJZNneNVFaPopvAnisGx8ABeMoF1Zz6o6N/jB64PQcYZtH7BNJMh3FUPCwuylA5WtRyYWzQuo0b7mkMX+fSizjzFlSNnTBaRV3Vr9W8iZIiChCHOax3feA2FAqLjlDCdpwvcWrkueRqU= 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=yy10n4Ri; arc=none smtp.client-ip=209.85.167.47 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="yy10n4Ri" Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-539fe02c386so4004950e87.0 for ; Sat, 09 Nov 2024 04:48:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1731156525; x=1731761325; 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=n+9MtGcN2xrmwOXfB2jupKXdcgjG7Kpy3ckztHv28T8=; b=yy10n4RiD8SMLJhXmgt5NUxRkDizjAOdUEn4qcidV2FEcJcwX7AcYKUUJT5RxnOM8w J7N53DSR7cvWCNF+p81myGhPblKPGP+A3DwCcDU56Jbs6M62dG7dT5XDGCcMA1qsIvfH baTW2+MgZgJJqw8/HANEttyngpDST2lq3S+WTlbv9gvxqLgMjbpoGaV0LKiLKlko1/xW 8V1LJ+CVhLKD+PlrJJdtXSNOxLwWCLsyjxaWBkrCoaLR9Y81/NSp8zQn0rnFKOP4vpcj egDoZ7XQknh7Et7LkymTEEDaZv+lnPEDuTByC1UFOuqPBGSgl7vTCzDeoVUZ2BR7b66p ADBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731156525; x=1731761325; 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=n+9MtGcN2xrmwOXfB2jupKXdcgjG7Kpy3ckztHv28T8=; b=oWNWRKGktjSw0aoLt16sThElSvtzmJNuyPuYWfOkIc763sICAABomFjkZ1K+knGXx3 tsJibEesQ2uoV8ohFCTHnZdDJFlYeLRKC1rqu454Xc26ObhWdl0TaoFV4yTxkr82CyOs kRpViwR/hfmIunRig8BdagrPsnGAyLGOMIczg0kqzc3L1jj+pKBToG9IKgY2ynsChnnW 9Ll0zQArnsMM96oKa4zpRQN2wM8WgrnXngGRaxxF5nwdjjhYEpfKuf393GXzbOcICd6B B/54NapK3c+uOkJxr3g1WC7gfbiT4pHfd0PNplv9Wpx5FqqAON3ycMKcFyD7Etkb6iCX s8Mw== X-Forwarded-Encrypted: i=1; AJvYcCWllkJaPutkI2cjn06DnvJyZphdIWb8e6Mau86PVpsKmLP21BSZDhRh+IYHVvLL2g3qhNPoZ/Pk+Jnmfp4=@vger.kernel.org X-Gm-Message-State: AOJu0YzDDZG9o4QOPT9XQsOAYXpY0C6nGm6FtO9BYAS8uxMg9RjbvSUH YVTTAxFZJdrsrLxGWUbypilTcDXCJ2Wi6hpbWD79Gv4Oq/KmwT7rzcdmSsjXFaI= X-Google-Smtp-Source: AGHT+IFf9n5NHldBuP/OGgykvud8gSj4Ywm7YufDUFdN4oApHLJmSdvzGKFj7k90+L50woPgRHJDUQ== X-Received: by 2002:a05:6512:75:b0:53d:8c94:4ef7 with SMTP id 2adb3069b0e04-53d8c94500amr452687e87.6.1731156524965; Sat, 09 Nov 2024 04:48:44 -0800 (PST) Received: from umbar.lan ([192.130.178.90]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53d826a9b76sm929967e87.172.2024.11.09.04.48.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Nov 2024 04:48:43 -0800 (PST) From: Dmitry Baryshkov Date: Sat, 09 Nov 2024 14:48:31 +0200 Subject: [PATCH v3 5/7] drm/bridge: lt9611: switch to using the DRM HDMI codec 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: <20241109-drm-bridge-hdmi-connector-v3-5-c15afdca5884@linaro.org> References: <20241109-drm-bridge-hdmi-connector-v3-0-c15afdca5884@linaro.org> In-Reply-To: <20241109-drm-bridge-hdmi-connector-v3-0-c15afdca5884@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 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=7869; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=b9CjlXHFjClXWt0twlUk/5oI0wepnqrV5DObVEdOLnI=; b=owEBbQGS/pANAwAKAYs8ij4CKSjVAcsmYgBnL1odlOiS14Z5iLPHFTRt4jAyTTrxmp6tTh38m vHDx02wi+2JATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCZy9aHQAKCRCLPIo+Aiko 1crTB/9RFFeSwX9N+nc0tM960m3RkR9N6tZfMa3Hu4Eb3r65Fibw+Vn5eHv7kyxWeR6jpcw9fCQ a2V2wP2MdBE01Dur5ZKMqM/JFqrYCiVmCdfz5kaZzsqcbEeULinZXFhdrjzMjZLzYCfYe9hYQfY 1zQYuvzWIMbWHtUmRE0M4GR6MPla+cUgHsReRNaPLYEIaO68o3gTknJ8g06rLgGeRpUFj8RYKl0 kjAlOKtWyRZLs+2sGg8syUS2na5dDwuSZpKYUennRS/M62JqJL0hPwcdfLo37gZHkPpmIfBOfJb 0WzhgI7CVYohTt/XI2cx56CyMQBipxldahtdkbhapTN4NjuQ X-Developer-Key: i=dmitry.baryshkov@linaro.org; a=openpgp; fpr=8F88381DD5C873E4AE487DA5199BF1243632046A Make the Lontium LT9611 DSI-to-HDMI bridge driver use the DRM HDMI Codec framework. This enables programming of Audio InfoFrames using the HDMI Connector interface and also enables support for the missing features, including the ELD retrieval and better hotplug support. Signed-off-by: Dmitry Baryshkov --- drivers/gpu/drm/bridge/lontium-lt9611.c | 171 +++++++++++++---------------= ---- 1 file changed, 69 insertions(+), 102 deletions(-) diff --git a/drivers/gpu/drm/bridge/lontium-lt9611.c b/drivers/gpu/drm/brid= ge/lontium-lt9611.c index 4fa0dfc5539a5786278221f7c13b6473ab320a9a..9d8b1c8d533c79bd91ae956aa4c= b74f3bab6de78 100644 --- a/drivers/gpu/drm/bridge/lontium-lt9611.c +++ b/drivers/gpu/drm/bridge/lontium-lt9611.c @@ -45,7 +45,6 @@ struct lt9611 { struct device_node *dsi1_node; struct mipi_dsi_device *dsi0; struct mipi_dsi_device *dsi1; - struct platform_device *audio_pdev; =20 bool ac_mode; =20 @@ -866,6 +865,10 @@ static int lt9611_hdmi_clear_infoframe(struct drm_brid= ge *bridge, unsigned int mask; =20 switch (type) { + case HDMI_INFOFRAME_TYPE_AUDIO: + mask =3D LT9611_INFOFRAME_AUDIO; + break; + case HDMI_INFOFRAME_TYPE_AVI: mask =3D LT9611_INFOFRAME_AVI; break; @@ -899,6 +902,11 @@ static int lt9611_hdmi_write_infoframe(struct drm_brid= ge *bridge, int i; =20 switch (type) { + case HDMI_INFOFRAME_TYPE_AUDIO: + mask =3D LT9611_INFOFRAME_AUDIO; + addr =3D 0x84b2; + break; + case HDMI_INFOFRAME_TYPE_AVI: mask =3D LT9611_INFOFRAME_AVI; addr =3D 0x8440; @@ -942,6 +950,55 @@ lt9611_hdmi_tmds_char_rate_valid(const struct drm_brid= ge *bridge, return MODE_OK; } =20 +static int lt9611_hdmi_codec_audio_startup(struct drm_connector *connector, + struct drm_bridge *bridge) +{ + struct lt9611 *lt9611 =3D bridge_to_lt9611(bridge); + + regmap_write(lt9611->regmap, 0x82d6, 0x8c); + regmap_write(lt9611->regmap, 0x82d7, 0x04); + + regmap_write(lt9611->regmap, 0x8406, 0x08); + regmap_write(lt9611->regmap, 0x8407, 0x10); + + regmap_write(lt9611->regmap, 0x8434, 0xd5); + + return 0; +} + +static int lt9611_hdmi_codec_prepare(struct drm_connector *connector, + struct drm_bridge *bridge, + struct hdmi_codec_daifmt *fmt, + struct hdmi_codec_params *hparms) +{ + struct lt9611 *lt9611 =3D bridge_to_lt9611(bridge); + + if (hparms->sample_rate =3D=3D 48000) + regmap_write(lt9611->regmap, 0x840f, 0x2b); + else if (hparms->sample_rate =3D=3D 96000) + regmap_write(lt9611->regmap, 0x840f, 0xab); + else + return -EINVAL; + + regmap_write(lt9611->regmap, 0x8435, 0x00); + regmap_write(lt9611->regmap, 0x8436, 0x18); + regmap_write(lt9611->regmap, 0x8437, 0x00); + + return drm_atomic_helper_connector_hdmi_update_audio_infoframe(connector, + &hparms->cea); +} + +static void lt9611_hdmi_codec_audio_shutdown(struct drm_connector *connect= or, + struct drm_bridge *bridge) +{ + struct lt9611 *lt9611 =3D bridge_to_lt9611(bridge); + + drm_atomic_helper_connector_hdmi_clear_audio_infoframe(connector); + + regmap_write(lt9611->regmap, 0x8406, 0x00); + regmap_write(lt9611->regmap, 0x8407, 0x00); +} + static const struct drm_bridge_funcs lt9611_bridge_funcs =3D { .attach =3D lt9611_bridge_attach, .mode_valid =3D lt9611_bridge_mode_valid, @@ -962,6 +1019,10 @@ static const struct drm_bridge_funcs lt9611_bridge_fu= ncs =3D { .hdmi_tmds_char_rate_valid =3D lt9611_hdmi_tmds_char_rate_valid, .hdmi_write_infoframe =3D lt9611_hdmi_write_infoframe, .hdmi_clear_infoframe =3D lt9611_hdmi_clear_infoframe, + + .hdmi_codec_audio_startup =3D lt9611_hdmi_codec_audio_startup, + .hdmi_codec_prepare =3D lt9611_hdmi_codec_prepare, + .hdmi_codec_audio_shutdown =3D lt9611_hdmi_codec_audio_shutdown, }; =20 static int lt9611_parse_dt(struct device *dev, @@ -1015,102 +1076,6 @@ static int lt9611_read_device_rev(struct lt9611 *lt= 9611) return ret; } =20 -static int lt9611_hdmi_hw_params(struct device *dev, void *data, - struct hdmi_codec_daifmt *fmt, - struct hdmi_codec_params *hparms) -{ - struct lt9611 *lt9611 =3D data; - - if (hparms->sample_rate =3D=3D 48000) - regmap_write(lt9611->regmap, 0x840f, 0x2b); - else if (hparms->sample_rate =3D=3D 96000) - regmap_write(lt9611->regmap, 0x840f, 0xab); - else - return -EINVAL; - - regmap_write(lt9611->regmap, 0x8435, 0x00); - regmap_write(lt9611->regmap, 0x8436, 0x18); - regmap_write(lt9611->regmap, 0x8437, 0x00); - - return 0; -} - -static int lt9611_audio_startup(struct device *dev, void *data) -{ - struct lt9611 *lt9611 =3D data; - - regmap_write(lt9611->regmap, 0x82d6, 0x8c); - regmap_write(lt9611->regmap, 0x82d7, 0x04); - - regmap_write(lt9611->regmap, 0x8406, 0x08); - regmap_write(lt9611->regmap, 0x8407, 0x10); - - regmap_write(lt9611->regmap, 0x8434, 0xd5); - - return 0; -} - -static void lt9611_audio_shutdown(struct device *dev, void *data) -{ - struct lt9611 *lt9611 =3D data; - - regmap_write(lt9611->regmap, 0x8406, 0x00); - regmap_write(lt9611->regmap, 0x8407, 0x00); -} - -static int lt9611_hdmi_i2s_get_dai_id(struct snd_soc_component *component, - struct device_node *endpoint, - void *data) -{ - struct of_endpoint of_ep; - int ret; - - ret =3D of_graph_parse_endpoint(endpoint, &of_ep); - if (ret < 0) - return ret; - - /* - * HDMI sound should be located as reg =3D <2> - * Then, it is sound port 0 - */ - if (of_ep.port =3D=3D 2) - return 0; - - return -EINVAL; -} - -static const struct hdmi_codec_ops lt9611_codec_ops =3D { - .hw_params =3D lt9611_hdmi_hw_params, - .audio_shutdown =3D lt9611_audio_shutdown, - .audio_startup =3D lt9611_audio_startup, - .get_dai_id =3D lt9611_hdmi_i2s_get_dai_id, -}; - -static struct hdmi_codec_pdata codec_data =3D { - .ops =3D <9611_codec_ops, - .max_i2s_channels =3D 8, - .i2s =3D 1, -}; - -static int lt9611_audio_init(struct device *dev, struct lt9611 *lt9611) -{ - codec_data.data =3D lt9611; - lt9611->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(lt9611->audio_pdev); -} - -static void lt9611_audio_exit(struct lt9611 *lt9611) -{ - if (lt9611->audio_pdev) { - platform_device_unregister(lt9611->audio_pdev); - lt9611->audio_pdev =3D NULL; - } -} - static int lt9611_probe(struct i2c_client *client) { struct lt9611 *lt9611; @@ -1174,6 +1139,9 @@ static int lt9611_probe(struct i2c_client *client) =20 i2c_set_clientdata(client, lt9611); =20 + /* Disable Audio InfoFrame, enabled by default */ + regmap_update_bits(lt9611->regmap, 0x843d, LT9611_INFOFRAME_AUDIO, 0); + lt9611->bridge.funcs =3D <9611_bridge_funcs; lt9611->bridge.of_node =3D client->dev.of_node; lt9611->bridge.ops =3D DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_EDID | @@ -1182,6 +1150,10 @@ static int lt9611_probe(struct i2c_client *client) lt9611->bridge.type =3D DRM_MODE_CONNECTOR_HDMIA; lt9611->bridge.vendor =3D "Lontium"; lt9611->bridge.product =3D "LT9611"; + lt9611->bridge.hdmi_codec_max_i2s_channels =3D 8; + lt9611->bridge.hdmi_codec_i2s =3D 1; + lt9611->bridge.hdmi_codec_dev =3D dev; + lt9611->bridge.hdmi_codec_dai_port =3D 2; =20 drm_bridge_add(<9611->bridge); =20 @@ -1203,10 +1175,6 @@ static int lt9611_probe(struct i2c_client *client) =20 lt9611_enable_hpd_interrupts(lt9611); =20 - ret =3D lt9611_audio_init(dev, lt9611); - if (ret) - goto err_remove_bridge; - return 0; =20 err_remove_bridge: @@ -1227,7 +1195,6 @@ static void lt9611_remove(struct i2c_client *client) struct lt9611 *lt9611 =3D i2c_get_clientdata(client); =20 disable_irq(client->irq); - lt9611_audio_exit(lt9611); drm_bridge_remove(<9611->bridge); =20 regulator_bulk_disable(ARRAY_SIZE(lt9611->supplies), lt9611->supplies); --=20 2.39.5