The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
To: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Cc: chunkuang.hu@kernel.org, p.zabel@pengutronix.de,
	airlied@gmail.com, simona@ffwll.ch,
	maarten.lankhorst@linux.intel.com, mripard@kernel.org,
	tzimmermann@suse.de, robh@kernel.org, krzk+dt@kernel.org,
	conor+dt@kernel.org, matthias.bgg@gmail.com, ck.hu@mediatek.com,
	jitao.shi@mediatek.com, jie.qiu@mediatek.com,
	junzhi.zhao@mediatek.com, dri-devel@lists.freedesktop.org,
	linux-mediatek@lists.infradead.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, kernel@collabora.com,
	dmitry.baryshkov@linaro.org, lewis.liao@mediatek.com,
	ives.chenjh@mediatek.com, tommyyl.chen@mediatek.com,
	jason-jh.lin@mediatek.com
Subject: Re: [PATCH v9 22/23] drm/mediatek: Introduce HDMI/DDC v2 for MT8195/MT8188
Date: Tue, 22 Apr 2025 15:53:43 +0200	[thread overview]
Message-ID: <7b3713d1-df18-4da1-a1e2-16dcff08fe66@collabora.com> (raw)
In-Reply-To: <aestmu2rblcrcz77tuqgkimaj4stg24skyp2avdstahwr3aa3i@cfv5ov2qjcf6>

Il 21/04/25 21:16, Dmitry Baryshkov ha scritto:
> On Tue, Apr 15, 2025 at 12:43:20PM +0200, AngeloGioacchino Del Regno wrote:
>> Add support for the newer HDMI-TX (Encoder) v2 and DDC v2 IPs
>> found in MediaTek's MT8195, MT8188 SoC and their variants, and
>> including support for display modes up to 4k60 and for HDMI
>> Audio, as per the HDMI 2.0 spec.
>>
>> HDCP and CEC functionalities are also supported by this hardware,
>> but are not included in this commit and that also poses a slight
>> difference between the V2 and V1 controllers in how they handle
>> Hotplug Detection (HPD).
>>
>> While the v1 controller was using the CEC controller to check
>> HDMI cable connection and disconnection, in this driver the v2
>> one does not.
>>
>> This is due to the fact that on parts with v2 designs, like the
>> MT8195 SoC, there is one CEC controller shared between the HDMI
>> Transmitter (HDMI-TX) and Receiver (HDMI-RX): before eventually
>> adding support to use the CEC HW to wake up the HDMI controllers
>> it is necessary to have support for one TX, one RX *and* for both
>> at the same time.
>>
>> Reviewed-by: CK Hu <ck.hu@mediatek.com>
>> Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
>> ---
>>   drivers/gpu/drm/mediatek/Kconfig            |    7 +
>>   drivers/gpu/drm/mediatek/Makefile           |    2 +
>>   drivers/gpu/drm/mediatek/mtk_hdmi_common.c  |    4 +
>>   drivers/gpu/drm/mediatek/mtk_hdmi_common.h  |    9 +
>>   drivers/gpu/drm/mediatek/mtk_hdmi_ddc_v2.c  |  385 +++++
>>   drivers/gpu/drm/mediatek/mtk_hdmi_regs_v2.h |  263 ++++
>>   drivers/gpu/drm/mediatek/mtk_hdmi_v2.c      | 1396 +++++++++++++++++++
>>   7 files changed, 2066 insertions(+)
>>   create mode 100644 drivers/gpu/drm/mediatek/mtk_hdmi_ddc_v2.c
>>   create mode 100644 drivers/gpu/drm/mediatek/mtk_hdmi_regs_v2.h
>>   create mode 100644 drivers/gpu/drm/mediatek/mtk_hdmi_v2.c
>>
>> +
>> +static int mtk_hdmi_v2_setup_audio_infoframe(struct mtk_hdmi *hdmi)
>> +{
>> +	struct hdmi_codec_params *params = &hdmi->aud_param.codec_params;
>> +	struct hdmi_audio_infoframe frame;
>> +	u8 buffer[14];
>> +	ssize_t ret;
>> +
>> +	memcpy(&frame, &params->cea, sizeof(frame));
>> +
>> +	ret = hdmi_audio_infoframe_pack(&frame, buffer, sizeof(buffer));
>> +	if (ret < 0)
>> +		return ret;
> 
> This should really be done via
> drm_atomic_helper_connector_hdmi_update_audio_infoframe() or
> drm_atomic_helper_connector_hdmi_clear_audio_infoframe().
> 
> Ideally this should come from the .hw_params() / .prepare() calls so
> that you don't need to store the params in the driver data.
> 

When switching to the new hdmi audio helpers yes, but I was planning to do that
later.....

>> +
>> +	mtk_hdmi_v2_hw_write_audio_infoframe(hdmi, buffer);
>> +
>> +	return 0;
>> +}
>> +
>> +static inline void mtk_hdmi_v2_hw_gcp_avmute(struct mtk_hdmi *hdmi, bool mute)
>> +{
>> +	u32 val;
>> +
>> +	regmap_read(hdmi->regs, TOP_CFG01, &val);
>> +	val &= ~(CP_CLR_MUTE_EN | CP_SET_MUTE_EN);
>> +
>> +	if (mute) {
>> +		val |= CP_SET_MUTE_EN;
>> +		val &= ~CP_CLR_MUTE_EN;
>> +	} else {
>> +		val |= CP_CLR_MUTE_EN;
>> +		val &= ~CP_SET_MUTE_EN;
>> +	}
>> +	regmap_write(hdmi->regs, TOP_CFG01, val);
>> +
>> +	regmap_set_bits(hdmi->regs, TOP_INFO_RPT, CP_RPT_EN);
>> +	regmap_set_bits(hdmi->regs, TOP_INFO_EN, CP_EN | CP_EN_WR);
>> +}
>> +
>> +static void mtk_hdmi_v2_hw_ncts_enable(struct mtk_hdmi *hdmi, bool enable)
>> +{
>> +	if (enable)
>> +		regmap_set_bits(hdmi->regs, AIP_CTRL, CTS_SW_SEL);
>> +	else
>> +		regmap_clear_bits(hdmi->regs, AIP_CTRL, CTS_SW_SEL);
>> +}
>> +
>> +static void mtk_hdmi_v2_hw_aud_set_channel_status(struct mtk_hdmi *hdmi)
>> +{
>> +	u8 *ch_status = hdmi->aud_param.codec_params.iec.status;
>> +
>> +	/* Only the first 5 to 7 bytes of Channel Status contain useful information */
>> +	regmap_write(hdmi->regs, AIP_I2S_CHST0, mtk_hdmi_v2_format_hw_packet(&ch_status[0], 4));
>> +	regmap_write(hdmi->regs, AIP_I2S_CHST1, mtk_hdmi_v2_format_hw_packet(&ch_status[4], 3));
>> +}
>> +
>> +static void mtk_hdmi_v2_hw_aud_set_ncts(struct mtk_hdmi *hdmi,
>> +				     unsigned int sample_rate,
>> +				     unsigned int clock)
>> +{
>> +	unsigned int n, cts;
>> +
>> +	mtk_hdmi_get_ncts(sample_rate, clock, &n, &cts);
> 
> drm_hdmi_acr_get_n_cts() ?
> 

I'd have to update both HDMI drivers to use that instead, and I was planning to do
that at a later time when switching to the HDMI audio helpers.

>> +
>> +	regmap_write(hdmi->regs, AIP_N_VAL, n);
>> +	regmap_write(hdmi->regs, AIP_CTS_SVAL, cts);
>> +}
>> +
> 
> [...]
> 
>> +
>> +static int mtk_hdmi_v2_audio_hw_params(struct device *dev, void *data,
>> +				       struct hdmi_codec_daifmt *daifmt,
>> +				       struct hdmi_codec_params *params)
>> +{
>> +	struct mtk_hdmi *hdmi = dev_get_drvdata(dev);
>> +
>> +	if (hdmi->audio_enable) {
>> +		mtk_hdmi_audio_params(hdmi, daifmt, params);
>> +		mtk_hdmi_v2_aud_output_config(hdmi, &hdmi->mode);
>> +	}
>> +	return 0;
>> +}
>> +
>> +static int mtk_hdmi_v2_audio_startup(struct device *dev, void *data)
>> +{
>> +	struct mtk_hdmi *hdmi = dev_get_drvdata(dev);
>> +
>> +	mtk_hdmi_v2_hw_aud_enable(hdmi, true);
>> +	hdmi->audio_enable = true;
>> +
>> +	return 0;
>> +}
>> +
>> +static void mtk_hdmi_v2_audio_shutdown(struct device *dev, void *data)
>> +{
>> +	struct mtk_hdmi *hdmi = dev_get_drvdata(dev);
>> +
>> +	hdmi->audio_enable = false;
>> +	mtk_hdmi_v2_hw_aud_enable(hdmi, false);
> 
> Most likely you need to stop sending the AUDIO packet too. Or is it dome
> by the hardware?
> 

The call to `mtk_hdmi_v2_hw_aud_enable(hdmi, false)` will set HW registers to both
mute and stop sending the audio packet.

>> +}
>> +
>> +static int mtk_hdmi_v2_audio_mute(struct device *dev, void *data, bool enable, int dir)
>> +{
>> +	struct mtk_hdmi *hdmi = dev_get_drvdata(dev);
>> +
>> +	mtk_hdmi_v2_hw_aud_mute(hdmi, enable);
>> +
>> +	return 0;
>> +}
>> +
>> +static const struct hdmi_codec_ops mtk_hdmi_v2_audio_codec_ops = {
>> +	.hw_params = mtk_hdmi_v2_audio_hw_params,
>> +	.audio_startup = mtk_hdmi_v2_audio_startup,
>> +	.audio_shutdown = mtk_hdmi_v2_audio_shutdown,
>> +	.mute_stream = mtk_hdmi_v2_audio_mute,
>> +	.get_eld = mtk_hdmi_audio_get_eld,
>> +	.hook_plugged_cb = mtk_hdmi_v2_audio_hook_plugged_cb,
>> +};
> 
> Do you plan to switch to the OP_HDMI_AUDIO? I'd really like to see
> bridges use the framework instead of implementing everthing on their
> own.
> 

I do, but since I've already reached v9, I really don't want to do that right now
and delay this driver for another two months.

I plan to do the switch after we at least get this in: as the V1 driver would also
need the same cleanup, I may even find a way to throw more stuff in the hdmi_common
when cleaning up both at the same time.

Cheers,
Angelo



  reply	other threads:[~2025-04-22 13:53 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-15 10:42 [PATCH v9 00/23] Add support for MT8195/88 HDMIv2 and DDCv2 AngeloGioacchino Del Regno
2025-04-15 10:42 ` [PATCH v9 01/23] dt-bindings: display: mediatek: Add binding for HDMIv2 DDC AngeloGioacchino Del Regno
2025-04-15 10:43 ` [PATCH v9 02/23] dt-bindings: display: mediatek: Add binding for MT8195 HDMI-TX v2 AngeloGioacchino Del Regno
2025-04-15 10:43 ` [PATCH v9 03/23] drm/mediatek/hdmi: Use syscon_regmap_lookup_by_phandle_args AngeloGioacchino Del Regno
2025-04-15 10:43 ` [PATCH v9 04/23] drm/mediatek: mtk_cec: Switch to register as module_platform_driver AngeloGioacchino Del Regno
2025-04-15 10:43 ` [PATCH v9 05/23] drm/mediatek: mtk_hdmi_ddc: " AngeloGioacchino Del Regno
2025-04-15 10:43 ` [PATCH v9 06/23] drm/mediatek: mtk_hdmi: Convert to module_platform_driver macro AngeloGioacchino Del Regno
2025-04-15 10:43 ` [PATCH v9 07/23] drm/mediatek: hdmi: Use regmap instead of iomem for main registers AngeloGioacchino Del Regno
2025-04-15 10:43 ` [PATCH v9 08/23] drm/mediatek: mtk_hdmi: Disgregate function mtk_hdmi_audio_set_param() AngeloGioacchino Del Regno
2025-04-15 10:43 ` [PATCH v9 09/23] drm/mediatek: mtk_hdmi: Move audio params selection to new function AngeloGioacchino Del Regno
2025-04-15 10:43 ` [PATCH v9 10/23] drm/mediatek: mtk_hdmi: Move plugged_cb/codec_dev setting " AngeloGioacchino Del Regno
2025-04-15 10:43 ` [PATCH v9 11/23] drm/mediatek: mtk_hdmi: Move N/CTS " AngeloGioacchino Del Regno
2025-04-15 10:43 ` [PATCH v9 12/23] drm/mediatek: mtk_hdmi: Use dev_err_probe() in mtk_hdmi_dt_parse_pdata() AngeloGioacchino Del Regno
2025-04-15 10:43 ` [PATCH v9 13/23] drm/mediatek: mtk_hdmi: Move CEC device parsing in new function AngeloGioacchino Del Regno
2025-04-15 10:43 ` [PATCH v9 14/23] drm/mediatek: mtk_hdmi: Move output init to mtk_hdmi_register_audio_driver() AngeloGioacchino Del Regno
2025-04-15 10:43 ` [PATCH v9 15/23] drm/mediatek: mtk_hdmi: Improve mtk_hdmi_get_all_clk() flexibility AngeloGioacchino Del Regno
2025-04-21 14:10   ` Chun-Kuang Hu
2025-04-15 10:43 ` [PATCH v9 16/23] drm/mediatek: mtk_hdmi: Add HDMI IP version configuration to pdata AngeloGioacchino Del Regno
2025-04-15 10:43 ` [PATCH v9 17/23] drm/mediatek: mtk_hdmi: Split driver and add common probe function AngeloGioacchino Del Regno
2025-04-15 10:48   ` AngeloGioacchino Del Regno
2025-04-16  6:44     ` CK Hu (胡俊光)
2025-04-16  8:36       ` AngeloGioacchino Del Regno
2025-04-15 10:43 ` [PATCH v9 18/23] drm/mediatek: mtk_hdmi_common: Make CEC support optional AngeloGioacchino Del Regno
2025-04-15 10:43 ` [PATCH v9 19/23] drm/mediatek: mtk_hdmi_common: Assign DDC adapter pointer to bridge AngeloGioacchino Del Regno
2025-04-15 10:43 ` [PATCH v9 20/23] drm/mediatek: mtk_hdmi_common: Add OP_HDMI if helper funcs assigned AngeloGioacchino Del Regno
2025-04-15 10:43 ` [PATCH v9 21/23] drm/mediatek: mtk_hdmi_common: Add var to enable interlaced modes AngeloGioacchino Del Regno
2025-04-15 10:43 ` [PATCH v9 22/23] drm/mediatek: Introduce HDMI/DDC v2 for MT8195/MT8188 AngeloGioacchino Del Regno
2025-04-21 19:16   ` Dmitry Baryshkov
2025-04-22 13:53     ` AngeloGioacchino Del Regno [this message]
2025-04-22 14:16       ` Dmitry Baryshkov
2025-04-15 10:43 ` [PATCH v9 23/23] drm/mediatek: mtk_hdmi_v2: Add debugfs ops and implement ABIST AngeloGioacchino Del Regno
2025-08-02 22:23 ` [PATCH v9 00/23] Add support for MT8195/88 HDMIv2 and DDCv2 Dmitry Baryshkov
2025-08-04  7:50   ` AngeloGioacchino Del Regno

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7b3713d1-df18-4da1-a1e2-16dcff08fe66@collabora.com \
    --to=angelogioacchino.delregno@collabora.com \
    --cc=airlied@gmail.com \
    --cc=chunkuang.hu@kernel.org \
    --cc=ck.hu@mediatek.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.baryshkov@linaro.org \
    --cc=dmitry.baryshkov@oss.qualcomm.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=ives.chenjh@mediatek.com \
    --cc=jason-jh.lin@mediatek.com \
    --cc=jie.qiu@mediatek.com \
    --cc=jitao.shi@mediatek.com \
    --cc=junzhi.zhao@mediatek.com \
    --cc=kernel@collabora.com \
    --cc=krzk+dt@kernel.org \
    --cc=lewis.liao@mediatek.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=matthias.bgg@gmail.com \
    --cc=mripard@kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=robh@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=tommyyl.chen@mediatek.com \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox