From patchwork Mon Sep 21 13:19:52 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud POULIQUEN X-Patchwork-Id: 7253441 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 07E319F44C for ; Thu, 24 Sep 2015 02:28:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8A88C20840 for ; Thu, 24 Sep 2015 02:28:28 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id D02D8208DA for ; Thu, 24 Sep 2015 02:28:26 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5CC337A08C; Wed, 23 Sep 2015 19:28:07 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [62.209.51.94]) by gabe.freedesktop.org (Postfix) with ESMTPS id 80B8F6E410 for ; Mon, 21 Sep 2015 06:39:23 -0700 (PDT) Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.14.5/8.14.5) with SMTP id t8LDEBFK032148; Mon, 21 Sep 2015 15:21:16 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 1x29c22tdh-1 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Mon, 21 Sep 2015 15:21:16 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 8867731; Mon, 21 Sep 2015 13:20:58 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas21.st.com [10.75.90.44]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 9B2F05730; Mon, 21 Sep 2015 13:21:12 +0000 (GMT) Received: from localhost (10.201.23.162) by Webmail-ga.st.com (10.75.90.48) with Microsoft SMTP Server (TLS) id 14.3.224.2; Mon, 21 Sep 2015 15:21:12 +0200 From: Arnaud Pouliquen To: , Subject: [RFC 1/5] video: hdmi: add help function for N and CTS Date: Mon, 21 Sep 2015 15:19:52 +0200 Message-ID: <1442841596-1323-2-git-send-email-arnaud.pouliquen@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1442841596-1323-1-git-send-email-arnaud.pouliquen@st.com> References: <1442841596-1323-1-git-send-email-arnaud.pouliquen@st.com> MIME-Version: 1.0 X-Originating-IP: [10.201.23.162] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.14.151, 1.0.33, 0.0.0000 definitions=2015-09-21_05:2015-09-21, 2015-09-21, 1970-01-01 signatures=0 X-Mailman-Approved-At: Wed, 23 Sep 2015 19:27:53 -0700 Cc: linux@arm.linux.org.uk, tomi.valkeinen@ti.com, arnaud.pouliquen@st.com, lgirdwood@gmail.com, Jyri Sarha , peter.ujfalusi@ti.com, tony@atomide.com, broonie@kernel.org, bcousson@baylibre.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add helper function to compute CTS and N parameters base on table described in HDMI specification 1.4b Signed-off-by: Arnaud Pouliquen --- drivers/video/hdmi.c | 148 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/hdmi.h | 8 +++ 2 files changed, 156 insertions(+) diff --git a/drivers/video/hdmi.c b/drivers/video/hdmi.c index 1626892..9c487fb 100644 --- a/drivers/video/hdmi.c +++ b/drivers/video/hdmi.c @@ -1242,3 +1242,151 @@ int hdmi_infoframe_unpack(union hdmi_infoframe *frame, void *buffer) return ret; } EXPORT_SYMBOL(hdmi_infoframe_unpack); + +/* + * audio clock regeneration (acr) parameters + * N and CTS computation are based on HDMI specification 1.4b + */ + +enum audio_rate { + HDMI_AUDIO_N_CTS_32KHZ, + HDMI_AUDIO_N_CTS_44_1KHZ, + HDMI_AUDIO_N_CTS_48KHZ, +}; + +struct hdmi_audio_acr { + unsigned long pixel_clk; + struct hdmi_audio_n_cts n_cts; +}; + +static const struct hdmi_audio_acr hdmi_audio_standard_acr[3][12] = { + { /*32 kHz*/ + { 25175, { 4576, 28125 } }, /* 25,20/1.001 MHz */ + { 25200, { 4096, 25200 } }, /* 25.20 MHz */ + { 27000, { 4096, 27000 } }, /* 27.00 MHz */ + { 27027, { 4096, 27027 } }, /* 27.00*1.001 MHz */ + { 54000, { 4096, 54000 } }, /* 54.00 MHz */ + { 54054, { 4096, 54054 } }, /* 54.00*1.001 MHz */ + { 74176, { 11648, 310938 } }, /* 74.25/1.001 MHz */ + { 74250, { 4096, 74250 } }, /* 74.25 MHz */ + { 148352, { 11648, 421875 } }, /* 148.50/1.001 MHz */ + { 148500, { 4096, 148500 } }, /* 148.50 MHz */ + { 296703, { 5824, 421875 } }, /* 297/1.001 MHz */ + { 297000, { 3072, 222750 } }, /* 297 MHz */ + }, + { /*44.1 kHz, 88.2 kHz 176.4 kHz*/ + { 25175, { 7007, 31250 } }, /* 25,20/1.001 MHz */ + { 25200, { 6272, 28000 } }, /* 25.20 MHz */ + { 27000, { 6272, 30000 } }, /* 27.00 MHz */ + { 27027, { 6272, 30030 } }, /* 27.00*1.001 MHz */ + { 54000, { 6272, 60000 } }, /* 54.00 MHz */ + { 54054, { 6272, 60060 } }, /* 54.00*1.001 MHz */ + { 74176, { 17836, 234375 } }, /* 74.25/1.001 MHz */ + { 74250, { 6272, 82500 } }, /* 74.25 MHz */ + { 148352, { 8918, 234375 } }, /* 148.50/1.001 MHz */ + { 148500, { 6272, 165000 } }, /* 148.50 MHz */ + { 296703, { 4459, 234375 } }, /* 297/1.001 MHz */ + { 297000, { 4704, 247500 } }, /* 297 MHz */ + }, + { /*48 kHz, 96 kHz 192 kHz*/ + { 25175, { 6864, 28125 } }, /* 25,20/1.001 MHz */ + { 25200, { 6144, 25200 } }, /* 25.20 MHz */ + { 27000, { 6144, 27000 } }, /* 27.00 MHz */ + { 27027, { 6144, 27027 } }, /* 27.00*1.001 MHz */ + { 54000, { 6144, 54000 } }, /* 54.00 MHz */ + { 54054, { 6144, 54054 } }, /* 54.00*1.001 MHz */ + { 74176, { 11648, 140625 } }, /* 74.25/1.001 MHz */ + { 74250, { 6144, 74250 } }, /* 74.25 MHz */ + { 148352, { 5824, 140625 } }, /* 148.50/1.001 MHz */ + { 148500, { 6144, 148500 } }, /* 148.50 MHz */ + { 296703, { 5824, 281250 } }, /* 297/1.001 MHz */ + { 297000, { 5120, 247500 } }, /* 297 MHz */ + } +}; + +/** + * hdmi_compute_n_cts() - compute N and CTS parameters + * @audio_clk: audio frame clock frequency in KHz + * @pixel_clk: pixel cloack frequency in kHz + * @n_cts: N and CTS parameter returned to user + * + * Values computed are based on table described in HDMI specification 1.4b + * + * Returns 0 on success or a negative error code on failure. + */ + +int hdmi_audio_compute_n_cts(unsigned int audio_fs, unsigned long pixel_clk, + struct hdmi_audio_n_cts *n_cts) +{ + int audio_freq_id, i; + int ratio = 1; + const struct hdmi_audio_acr *acr_table; + const struct hdmi_audio_n_cts *predef_n_cts = NULL; + + switch (audio_fs) { + case 32000: + audio_freq_id = HDMI_AUDIO_N_CTS_32KHZ; + n_cts->n = 4096; + break; + + case 44100: + audio_freq_id = HDMI_AUDIO_N_CTS_44_1KHZ; + n_cts->n = 6272; + break; + + case 48000: + audio_freq_id = HDMI_AUDIO_N_CTS_48KHZ; + n_cts->n = 6144; + break; + + case 88200: + audio_freq_id = HDMI_AUDIO_N_CTS_44_1KHZ; + ratio = 2; + n_cts->n = 6272 * 2; + break; + + case 96000: + audio_freq_id = HDMI_AUDIO_N_CTS_48KHZ; + ratio = 2; + n_cts->n = 6144 * 2; + break; + + case 176400: + audio_freq_id = HDMI_AUDIO_N_CTS_44_1KHZ; + ratio = 2; + n_cts->n = 6272 * 4; + break; + + case 192000: + audio_freq_id = HDMI_AUDIO_N_CTS_48KHZ; + ratio = 4; + n_cts->n = 6144 * 4; + break; + + default: + return -EINVAL; + } + + acr_table = hdmi_audio_standard_acr[audio_freq_id]; + for (i = 0; i < ARRAY_SIZE(hdmi_audio_standard_acr[0]); i++) { + if (pixel_clk == acr_table[i].pixel_clk) { + predef_n_cts = &acr_table[i].n_cts; + break; + } + } + + if (!predef_n_cts) { + /* + * predifined frequency not found compute CTS using formula: + * CTS = (Ftdms_clk * N) / (128* audio_fs) + */ + n_cts->cts = pixel_clk * n_cts->n / (128 * audio_fs); + } else { + n_cts->n = predef_n_cts->n * ratio; + n_cts->cts = predef_n_cts->cts; + } + + return 0; +} +EXPORT_SYMBOL(hdmi_audio_compute_n_cts); + diff --git a/include/linux/hdmi.h b/include/linux/hdmi.h index e974420..32107a0 100644 --- a/include/linux/hdmi.h +++ b/include/linux/hdmi.h @@ -333,4 +333,12 @@ int hdmi_infoframe_unpack(union hdmi_infoframe *frame, void *buffer); void hdmi_infoframe_log(const char *level, struct device *dev, union hdmi_infoframe *frame); +struct hdmi_audio_n_cts { + unsigned int n; + unsigned int cts; +}; + +int hdmi_audio_compute_n_cts(unsigned int audio_fs, unsigned long pixel_clk, + struct hdmi_audio_n_cts *n_cts); + #endif /* _DRM_HDMI_H */