From: shawnguo@kernel.org (Shawn Guo)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] drm: zte: support hdmi audio through spdif
Date: Thu, 29 Dec 2016 19:12:32 +0800 [thread overview]
Message-ID: <20161229111230.GA6177@dragon> (raw)
In-Reply-To: <CAOw6vbJzKeiTW9haRmiFhJv44pRSMNvvpFUg-4LcfxSuRzo17w@mail.gmail.com>
On Thu, Dec 22, 2016 at 10:18:00AM -0500, Sean Paul wrote:
> On Thu, Dec 22, 2016 at 8:11 AM, Shawn Guo <shawnguo@kernel.org> wrote:
> > +static int zx_hdmi_audio_get_n(unsigned int fs)
> > +{
> > + unsigned int n;
> > +
> > + switch (fs) {
> > + case 32000:
> > + n = 4096;
> > + break;
> > + case 44100:
> > + n = 6272;
> > + break;
> > + case 48000:
> > + n = 6144;
> > + break;
> > + case 88200:
> > + n = 6272 * 2;
> > + break;
> > + case 96000:
> > + n = 6144 * 2;
> > + break;
> > + case 176400:
> > + n = 6272 * 4;
> > + break;
> > + case 192000:
> > + n = 6144 * 4;
> > + break;
> > + default:
> > + n = fs * 128 / 1000;
>
> It seems like this could be distilled down to:
>
> if (fs && (fs % 44100) == 0)
> n = 6272 * (fs / 44100);
> else
> n = fs * 128 / 1000;
Nice! Thanks for the suggestion.
>
> > + }
> > +
> > + return n;
> > +}
> > +
> > +static int zx_hdmi_audio_hw_params(struct device *dev,
> > + void *data,
> > + struct hdmi_codec_daifmt *daifmt,
> > + struct hdmi_codec_params *params)
> > +{
> > + struct zx_hdmi *hdmi = dev_get_drvdata(dev);
> > + struct hdmi_audio_infoframe *cea = ¶ms->cea;
> > + union hdmi_infoframe frame;
> > + int n;
> > +
> > + /* We only support spdif for now */
> > + if (daifmt->fmt != HDMI_SPDIF) {
> > + DRM_DEV_ERROR(hdmi->dev, "invalid daifmt %d\n", daifmt->fmt);
> > + return -EINVAL;
> > + }
> > +
> > + switch (params->sample_width) {
> > + case 16:
> > + hdmi_writeb_mask(hdmi, TPI_AUD_CONFIG, SPDIF_SAMPLE_SIZE_MASK,
> > + SPDIF_SAMPLE_SIZE_16BIT);
> > + break;
> > + case 20:
> > + hdmi_writeb_mask(hdmi, TPI_AUD_CONFIG, SPDIF_SAMPLE_SIZE_MASK,
> > + SPDIF_SAMPLE_SIZE_20BIT);
> > + break;
> > + case 24:
> > + hdmi_writeb_mask(hdmi, TPI_AUD_CONFIG, SPDIF_SAMPLE_SIZE_MASK,
> > + SPDIF_SAMPLE_SIZE_24BIT);
> > + break;
> > + default:
> > + DRM_DEV_ERROR(hdmi->dev, "invalid sample width %d\n",
> > + params->sample_width);
> > + return -EINVAL;
> > + }
> > +
> > + /* CTS is calculated by hardware, and we only need to take care of N */
> > + n = zx_hdmi_audio_get_n(params->sample_rate);
> > + hdmi_writeb(hdmi, N_SVAL1, n & 0xff);
> > + hdmi_writeb(hdmi, N_SVAL2, (n >> 8) && 0xff);
>
> s/&&/&/ ?
Oops! Thanks for catching it.
Shawn
>
> > + hdmi_writeb(hdmi, N_SVAL3, (n >> 16) & 0xf);
> > +
> > + /* Enable spdif mode */
> > + hdmi_writeb_mask(hdmi, AUD_MODE, SPDIF_EN, SPDIF_EN);
> > +
> > + /* Enable audio input */
> > + hdmi_writeb_mask(hdmi, AUD_EN, AUD_IN_EN, AUD_IN_EN);
> > +
> > + memcpy(&frame.audio, cea, sizeof(*cea));
> > +
> > + return zx_hdmi_infoframe_trans(hdmi, &frame, FSEL_AUDIO);
> > +}
WARNING: multiple messages have this Message-ID (diff)
From: Shawn Guo <shawnguo@kernel.org>
To: Sean Paul <seanpaul@chromium.org>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>,
Baoyou Xie <xie.baoyou@zte.com.cn>,
dri-devel <dri-devel@lists.freedesktop.org>,
Jun Nie <jun.nie@linaro.org>,
Linux ARM Kernel <linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH] drm: zte: support hdmi audio through spdif
Date: Thu, 29 Dec 2016 19:12:32 +0800 [thread overview]
Message-ID: <20161229111230.GA6177@dragon> (raw)
In-Reply-To: <CAOw6vbJzKeiTW9haRmiFhJv44pRSMNvvpFUg-4LcfxSuRzo17w@mail.gmail.com>
On Thu, Dec 22, 2016 at 10:18:00AM -0500, Sean Paul wrote:
> On Thu, Dec 22, 2016 at 8:11 AM, Shawn Guo <shawnguo@kernel.org> wrote:
> > +static int zx_hdmi_audio_get_n(unsigned int fs)
> > +{
> > + unsigned int n;
> > +
> > + switch (fs) {
> > + case 32000:
> > + n = 4096;
> > + break;
> > + case 44100:
> > + n = 6272;
> > + break;
> > + case 48000:
> > + n = 6144;
> > + break;
> > + case 88200:
> > + n = 6272 * 2;
> > + break;
> > + case 96000:
> > + n = 6144 * 2;
> > + break;
> > + case 176400:
> > + n = 6272 * 4;
> > + break;
> > + case 192000:
> > + n = 6144 * 4;
> > + break;
> > + default:
> > + n = fs * 128 / 1000;
>
> It seems like this could be distilled down to:
>
> if (fs && (fs % 44100) == 0)
> n = 6272 * (fs / 44100);
> else
> n = fs * 128 / 1000;
Nice! Thanks for the suggestion.
>
> > + }
> > +
> > + return n;
> > +}
> > +
> > +static int zx_hdmi_audio_hw_params(struct device *dev,
> > + void *data,
> > + struct hdmi_codec_daifmt *daifmt,
> > + struct hdmi_codec_params *params)
> > +{
> > + struct zx_hdmi *hdmi = dev_get_drvdata(dev);
> > + struct hdmi_audio_infoframe *cea = ¶ms->cea;
> > + union hdmi_infoframe frame;
> > + int n;
> > +
> > + /* We only support spdif for now */
> > + if (daifmt->fmt != HDMI_SPDIF) {
> > + DRM_DEV_ERROR(hdmi->dev, "invalid daifmt %d\n", daifmt->fmt);
> > + return -EINVAL;
> > + }
> > +
> > + switch (params->sample_width) {
> > + case 16:
> > + hdmi_writeb_mask(hdmi, TPI_AUD_CONFIG, SPDIF_SAMPLE_SIZE_MASK,
> > + SPDIF_SAMPLE_SIZE_16BIT);
> > + break;
> > + case 20:
> > + hdmi_writeb_mask(hdmi, TPI_AUD_CONFIG, SPDIF_SAMPLE_SIZE_MASK,
> > + SPDIF_SAMPLE_SIZE_20BIT);
> > + break;
> > + case 24:
> > + hdmi_writeb_mask(hdmi, TPI_AUD_CONFIG, SPDIF_SAMPLE_SIZE_MASK,
> > + SPDIF_SAMPLE_SIZE_24BIT);
> > + break;
> > + default:
> > + DRM_DEV_ERROR(hdmi->dev, "invalid sample width %d\n",
> > + params->sample_width);
> > + return -EINVAL;
> > + }
> > +
> > + /* CTS is calculated by hardware, and we only need to take care of N */
> > + n = zx_hdmi_audio_get_n(params->sample_rate);
> > + hdmi_writeb(hdmi, N_SVAL1, n & 0xff);
> > + hdmi_writeb(hdmi, N_SVAL2, (n >> 8) && 0xff);
>
> s/&&/&/ ?
Oops! Thanks for catching it.
Shawn
>
> > + hdmi_writeb(hdmi, N_SVAL3, (n >> 16) & 0xf);
> > +
> > + /* Enable spdif mode */
> > + hdmi_writeb_mask(hdmi, AUD_MODE, SPDIF_EN, SPDIF_EN);
> > +
> > + /* Enable audio input */
> > + hdmi_writeb_mask(hdmi, AUD_EN, AUD_IN_EN, AUD_IN_EN);
> > +
> > + memcpy(&frame.audio, cea, sizeof(*cea));
> > +
> > + return zx_hdmi_infoframe_trans(hdmi, &frame, FSEL_AUDIO);
> > +}
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2016-12-29 11:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-22 13:11 [PATCH] drm: zte: support hdmi audio through spdif Shawn Guo
2016-12-22 13:11 ` Shawn Guo
2016-12-22 15:18 ` Sean Paul
2016-12-22 15:18 ` Sean Paul
2016-12-29 11:12 ` Shawn Guo [this message]
2016-12-29 11:12 ` Shawn Guo
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=20161229111230.GA6177@dragon \
--to=shawnguo@kernel.org \
--cc=linux-arm-kernel@lists.infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.