From: Detlev Casanova <detlev.casanova@collabora.com>
To: linux-kernel@vger.kernel.org, Quentin Schulz <quentin.schulz@cherry.de>
Cc: Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Heiko Stuebner <heiko@sntech.de>,
Andrzej Hajda <andrzej.hajda@intel.com>,
Neil Armstrong <neil.armstrong@linaro.org>,
Robert Foss <rfoss@kernel.org>,
Laurent Pinchart <Laurent.pinchart@ideasonboard.com>,
Jonas Karlman <jonas@kwiboo.se>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
Sebastian Reichel <sebastian.reichel@collabora.com>,
Alexey Charkov <alchark@gmail.com>,
Cristian Ciocaltea <cristian.ciocaltea@collabora.com>,
Dragan Simic <dsimic@manjaro.org>,
Jianfeng Liu <liujianfeng1994@gmail.com>,
Niklas Cassel <cassel@kernel.org>,
FUKAUMI Naoki <naoki@radxa.com>,
Kever Yang <kever.yang@rock-chips.com>,
Johan Jonker <jbx6244@gmail.com>,
Geert Uytterhoeven <geert+renesas@glider.be>,
Dmitry Baryshkov <dmitry.baryshkov@linaro.org>,
Algea Cao <algea.cao@rock-chips.com>,
Chen-Yu Tsai <wens@csie.org>,
Sugar Zhang <sugar.zhang@rock-chips.com>,
devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-rockchip@lists.infradead.org,
dri-devel@lists.freedesktop.org, kernel@collabora.com
Subject: Re: [PATCH v5 1/3] drm/bridge: synopsys: Add audio support for dw-hdmi-qp
Date: Thu, 06 Feb 2025 15:40:15 -0500 [thread overview]
Message-ID: <13709044.uLZWGnKmhe@earth> (raw)
In-Reply-To: <db29945e-565a-490f-8a8c-387ecd47a198@cherry.de>
Hi Quentin,
On Tuesday, 4 February 2025 04:59:12 EST Quentin Schulz wrote:
> Hi Detlev,
>
> Just some drive-by comment inline.
>
> On 2/3/25 6:16 PM, Detlev Casanova wrote:
> > From: Sugar Zhang <sugar.zhang@rock-chips.com>
> >
> > Register the dw-hdmi-qp bridge driver as an HDMI audio codec.
> >
> > The register values computation functions (for n) are based on the
> > downstream driver, as well as the register writing functions.
> >
> > The driver uses the generic HDMI Codec framework in order to implement
> > the HDMI audio support.
> >
> > Signed-off-by: Sugar Zhang <sugar.zhang@rock-chips.com>
> > Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> > Tested-by: Quentin Schulz <quentin.schulz@cherry.de>
> > Signed-off-by: Detlev Casanova <detlev.casanova@collabora.com>
> > ---
> >
> > drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c | 497 +++++++++++++++++++
> > 1 file changed, 497 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c
> > b/drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c index
> > b281cabfe992e..ea5d8599cb56a 100644
> > --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c
> > +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c
>
> [...]
>
> > +static int dw_hdmi_qp_match_tmds_n_table(struct dw_hdmi_qp *hdmi,
> > + unsigned long pixel_clk,
> > + unsigned long freq)
> > +{
> > + const struct dw_hdmi_audio_tmds_n *tmds_n = NULL;
> > + int i;
> > +
> > + for (i = 0; common_tmds_n_table[i].tmds != 0; i++) {
> > + if (pixel_clk == common_tmds_n_table[i].tmds) {
> > + tmds_n = &common_tmds_n_table[i];
> > + break;
> > + }
> > + }
> > +
> > + if (tmds_n == NULL)
> > + return -ENOENT;
> > +
> > + switch (freq) {
> > + case 32000:
> > + return tmds_n->n_32k;
> > + case 44100:
> > + case 88200:
> > + case 176400:
> > + return (freq / 44100) * tmds_n->n_44k1;
> > + case 48000:
> > + case 96000:
> > + case 192000:
> > + return (freq / 48000) * tmds_n->n_48k;
> > + default:
> > + return -ENOENT;
> > + }
> > +}
> > +
> > +static u64 dw_hdmi_qp_audio_math_diff(unsigned int freq, unsigned int n,
> > + unsigned int pixel_clk)
> > +{
> > + u64 final, diff;
> > + u64 cts;
> > +
> > + final = (u64)pixel_clk * n;
> > +
> > + cts = final;
> > + do_div(cts, 128 * freq);
> > +
> > + diff = final - (u64)cts * (128 * freq);
> > +
> > + return diff;
>
> I believe
>
> final = (u64)pixel_clk * n;
> do_div(cts, 128 * freq);
> diff = final - (u64)cts * (128 * freq);
>
> is just an elaborate way of doing
>
> ((u64)pixel_clk * n) % (128 * freq)
>
> ? If that's the case, then I believe do_div(a, b) actually already
> returns the remainder of a by b.
>
> If that's the case, isn't that function simply:
>
> return do_div(mul_u32_u32(pixel_clk, n), mul_u32_u32(freq, 128))
>
> ?
>
> We could probably replace mul_u32_u32(freq, 128) with freq * 128
> considering that dw_hdmi_qp_match_tmds_n_table expects freq to be <
> 192000, so we won't get an overflow with that.
>
> mul_u32_u32(pixel_clk, n) does the u32*u32->u64 without a temporary C
> variable.
I tested this and it is indeed doing the same. I'll change it and also change
the function return type to u32 as that is what do_div() returns.
That makes sense as the reminder of a/b can't be wider than the size of b.
We just need one variable as the first argument of do_div() is used to store
the integer division result.
> [...]
>
> > +static void dw_hdmi_qp_set_audio_interface(struct dw_hdmi_qp *hdmi,
> > + struct hdmi_codec_daifmt
*fmt,
> > + struct hdmi_codec_params
*hparms)
> > +{
> > + u32 conf0 = 0;
> > +
> > + /* Reset the audio data path of the AVP */
> > + dw_hdmi_qp_write(hdmi, AVP_DATAPATH_PACKET_AUDIO_SWINIT_P,
> > GLOBAL_SWRESET_REQUEST); +
> > + /* Disable AUDS, ACR, AUDI */
> > + dw_hdmi_qp_mod(hdmi, 0,
> > + PKTSCHED_ACR_TX_EN | PKTSCHED_AUDS_TX_EN |
PKTSCHED_AUDI_TX_EN,
> > + PKTSCHED_PKT_EN);
> > +
> > + /* Clear the audio FIFO */
> > + dw_hdmi_qp_write(hdmi, AUDIO_FIFO_CLR_P, AUDIO_INTERFACE_CONTROL0);
> > +
> > + /* Select I2S interface as the audio source */
> > + dw_hdmi_qp_mod(hdmi, AUD_IF_I2S, AUD_IF_SEL_MSK,
> > AUDIO_INTERFACE_CONFIG0); +
> > + /* Enable the active i2s lanes */
> > + switch (hparms->channels) {
> > + case 7 ... 8:
> > + conf0 |= I2S_LINES_EN(3);
> > + fallthrough;
> > + case 5 ... 6:
> > + conf0 |= I2S_LINES_EN(2);
> > + fallthrough;
> > + case 3 ... 4:
> > + conf0 |= I2S_LINES_EN(1);
> > + fallthrough;
> > + default:
> > + conf0 |= I2S_LINES_EN(0);
> > + break;
> > + }
> > +
> > + dw_hdmi_qp_mod(hdmi, conf0, I2S_LINES_EN_MSK,
AUDIO_INTERFACE_CONFIG0);
> > +
> > + /*
> > + * Enable bpcuv generated internally for L-PCM, or received
> > + * from stream for NLPCM/HBR.
> > + */
> > + switch (fmt->bit_fmt) {
> > + case SNDRV_PCM_FORMAT_IEC958_SUBFRAME_LE:
> > + conf0 = (hparms->channels == 8) ? AUD_HBR : AUD_ASP;
> > + conf0 |= I2S_BPCUV_RCV_EN;
> > + break;
> > + default:
> > + conf0 = AUD_ASP | I2S_BPCUV_RCV_DIS;
> > + break;
> > + }
> > +
> > + dw_hdmi_qp_mod(hdmi, conf0, I2S_BPCUV_RCV_MSK | AUD_FORMAT_MSK,
> > + AUDIO_INTERFACE_CONFIG0);
> > +
> > + /* Enable audio FIFO auto clear when overflow */
> > + dw_hdmi_qp_mod(hdmi, AUD_FIFO_INIT_ON_OVF_EN,
AUD_FIFO_INIT_ON_OVF_MSK,
> > + AUDIO_INTERFACE_CONFIG0);
>
> This is all very I2S-centric while the HDMI controllers on RK3588 do
> have the ability (according to the TRM) to use S/PDIF instead of I2S. I
> assume the driver should be able to know which format to use based on
> simple-audio-card,format property? Is that correct? Then current support
> which doesn't even check for I2S would be fine and not conflict with a
> later commit which would add support for S/PDIF? (Essentially asking if
> we need another DT property for the HDMI controller node or elsewhere to
> specify which mode to run in instead of expecting it to always be I2S).
The hdmi_codec_daifmt::fmt field already has this information, based on the
simple-audio-card,format = "i2s"; field in the device tree.
I could add a condition in dw_hdmi_qp_audio_prepare() to fail with -EINVAL if
the devicetree specifies anything else than "i2s" for now.
I'm not willing to implement support for the SPDIF path for now, mainly
because there's no need for that yet (I2S works well) and the downstream
kernel doesn't implemented it, meaning it hasn't been tested a lot anyway.
Regards,
Detlev.
next prev parent reply other threads:[~2025-02-06 20:42 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-03 17:16 [PATCH v5 0/3] Add HDMI audio on the rk3588 SoC Detlev Casanova
2025-02-03 17:16 ` [PATCH v5 1/3] drm/bridge: synopsys: Add audio support for dw-hdmi-qp Detlev Casanova
2025-02-04 9:59 ` Quentin Schulz
2025-02-06 20:40 ` Detlev Casanova [this message]
2025-02-07 8:46 ` Quentin Schulz
2025-02-03 17:16 ` [PATCH v5 2/3] arm64: dts: rockchip: Add HDMI0 audio output for rk3588 SoC Detlev Casanova
2025-02-04 10:14 ` Quentin Schulz
2025-02-06 17:17 ` Detlev Casanova
2025-02-07 10:23 ` Heiko Stübner
2025-02-03 17:16 ` [PATCH v5 3/3] arm64: dts: rockchip: Enable HDMI0 audio output for Rock 5B Detlev Casanova
2025-02-04 10:15 ` Quentin Schulz
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=13709044.uLZWGnKmhe@earth \
--to=detlev.casanova@collabora.com \
--cc=Laurent.pinchart@ideasonboard.com \
--cc=airlied@gmail.com \
--cc=alchark@gmail.com \
--cc=algea.cao@rock-chips.com \
--cc=andrzej.hajda@intel.com \
--cc=cassel@kernel.org \
--cc=conor+dt@kernel.org \
--cc=cristian.ciocaltea@collabora.com \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.baryshkov@linaro.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=dsimic@manjaro.org \
--cc=geert+renesas@glider.be \
--cc=heiko@sntech.de \
--cc=jbx6244@gmail.com \
--cc=jernej.skrabec@gmail.com \
--cc=jonas@kwiboo.se \
--cc=kernel@collabora.com \
--cc=kever.yang@rock-chips.com \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=liujianfeng1994@gmail.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=naoki@radxa.com \
--cc=neil.armstrong@linaro.org \
--cc=quentin.schulz@cherry.de \
--cc=rfoss@kernel.org \
--cc=robh@kernel.org \
--cc=sebastian.reichel@collabora.com \
--cc=simona@ffwll.ch \
--cc=sugar.zhang@rock-chips.com \
--cc=tzimmermann@suse.de \
--cc=wens@csie.org \
/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;
as well as URLs for NNTP newsgroup(s).