From patchwork Sun Jan 13 20:16:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dimitris Papavasiliou X-Patchwork-Id: 10761409 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4EE82746 for ; Sun, 13 Jan 2019 20:16:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35961287C5 for ; Sun, 13 Jan 2019 20:16:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 25F73287F2; Sun, 13 Jan 2019 20:16:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E499287C5 for ; Sun, 13 Jan 2019 20:16:33 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id E2F13266A73; Sun, 13 Jan 2019 21:16:31 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 6C5A9266A7C; Sun, 13 Jan 2019 21:16:29 +0100 (CET) Received: from mail-ed1-f68.google.com (mail-ed1-f68.google.com [209.85.208.68]) by alsa0.perex.cz (Postfix) with ESMTP id 5B25D2669BD for ; Sun, 13 Jan 2019 21:16:24 +0100 (CET) Received: by mail-ed1-f68.google.com with SMTP id b14so17069584edt.6 for ; Sun, 13 Jan 2019 12:16:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:cc:from:subject:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=yfwEVaky0FLoR+IHJU1V9N1Exv/SyD9K95uhnbYzOQ0=; b=cqEGAsQR6L9uXvMbIaEFYeVQ9seC9RamkiqGeT09zIGBiqSU4Ea+XgNAw16XAfNS+M 8eqT110IHlknORMgVMhebP94CqqFFY/2aj25X1dlXgtc12Q0z8D1jPF1LhDzTrqCkv49 9OBc6IH5RW1Uiw3qa+pvsKL+/USOCVa1yRZz8DOqDlLSjGQ4baaxK3XvJowC2YZXyRAd 0qM5o1Msb/xYnfmKX3H2rNnFQEuZg3kKTS6Es93Gci2nkLt4Gs4NizZvo1+XRj/Rl6+U fzIL+VyKZizenWazho+ISMy2bXn1oOCh0iMO5JtSNIFe+uOiTSezlqhygd745rJ78B1g LK/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=yfwEVaky0FLoR+IHJU1V9N1Exv/SyD9K95uhnbYzOQ0=; b=QmNXBie8Ifb9TSY1xrhL73KL/UP8i5J9CL/pO1FwbZKDEZVwv8u/oaWotBtff1nFh5 Uhp3AOPWUOBzHBrqmEC9YXhV/C2kPiN40zdbtFjH6Ae6WDD1VEgyFPRyhS9d+beh0msF DhXfpkyuL4y09/DsT9TQXYFOjfrdcpygUV/kmyxYK8DuaeEAsUDxTtAKI2vj5ZXiSHyA GzqlaWpbmcz9EZbsNi5879qv9nk8iNOFsQMekMa6RLUmh/sjINpF0uSrv0rJAbcgywWO 8PIfADjjszQnt8+vjeOawo0gQ6FA9aZFKMz3SeRd8igKOD/PAlHAtlJJMYEJyMMxmdUo hM5A== X-Gm-Message-State: AJcUukf8UPn/tkp2p2jhOgEnbmoyZccEwnSD2TS0Dxvtc2qtKZNFn21F I1Zs0RaU/XEowVH6RBpWkfY= X-Google-Smtp-Source: ALg8bN4MH8dG4iA0PRX6quGEhBOrSFvqxvku8SP383zCKvQtpuw9nKjDuAbYeD1Pj7lY3VQGrTC47Q== X-Received: by 2002:a05:6402:1347:: with SMTP id y7mr20557172edw.114.1547410584290; Sun, 13 Jan 2019 12:16:24 -0800 (PST) Received: from [192.168.1.2] (ppp079167217081.access.hol.gr. [79.167.217.81]) by smtp.googlemail.com with ESMTPSA id gg9-v6sm2206194ejb.66.2019.01.13.12.16.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 Jan 2019 12:16:23 -0800 (PST) To: alsa-devel@alsa-project.org From: Dimitris Papavasiliou Message-ID: <900a4f74-9312-58d8-a5b3-035305fe184e@gmail.com> Date: Sun, 13 Jan 2019 22:16:21 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 Content-Language: en-US Cc: Kuninori Morimoto , Takashi Iwai , Liam Girdwood , Mark Brown , Peter Rosin Subject: [alsa-devel] [RFC PATCH] ASoC: pcm512x: Implement the set_bclk_ratio interface X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP From 5e6ad135fd063d4b22cd962de43499a161bbc7db Mon Sep 17 00:00:00 2001 From: Dimitris Papavasiliou Date: Fri, 11 Jan 2019 22:13:27 +0200 Subject: [RFC PATCH] ASoC: pcm512x: Implement the set_bclk_ratio interface Some boards, such as the HiFiBerry DAC+ Pro, use a pair of external oscillators, to generate 44.1 or 48kHz multiples and are forced to resort to hacks[1] in order to support 24-bit data without ending up with fractional dividers. This patch allows the machine driver to use 32-bit frames for 24-bit data to avoid such issues. [1] http://mailman.alsa-project.org/pipermail/alsa-devel/2018-December/143442.html Signed-off-by: Dimitris Papavasiliou --- Notes: The patch also includes a related change in the calculation of the bclk divider. The current calculation is not very clear to me, as I can't find much concrete information on what this sample rate fraction is, how it's calculated and how, therefore, its denominator would fit into the calculation. It also yields slightly wrong dividers in certain cases, which the machine driver for my HiFiBerry DAC+ Pro board seemingly tries to circumvent, by updating the rate fraction so as to suit this calculation. The updated calculation seems to work fine in my tests and, as far as I can see, should correctly yield the smallest bit clock rate that would fit the frame. Please comment if anything looks off. sound/soc/codecs/pcm512x.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/sound/soc/codecs/pcm512x.c b/sound/soc/codecs/pcm512x.c index 4cc24a5d5c31..8cd728f9a1eb 100644 --- a/sound/soc/codecs/pcm512x.c +++ b/sound/soc/codecs/pcm512x.c @@ -55,6 +55,7 @@ struct pcm512x_priv { unsigned long overclock_dsp; int mute; struct mutex mutex; + unsigned int bclk_ratio; }; /* @@ -915,16 +916,21 @@ static int pcm512x_set_dividers(struct snd_soc_dai *dai, int fssp; int gpio; - lrclk_div = snd_soc_params_to_frame_size(params); - if (lrclk_div == 0) { - dev_err(dev, "No LRCLK?\n"); - return -EINVAL; + if (pcm512x->bclk_ratio > 0) { + lrclk_div = pcm512x->bclk_ratio; + } else { + lrclk_div = snd_soc_params_to_frame_size(params); + + if (lrclk_div == 0) { + dev_err(dev, "No LRCLK?\n"); + return -EINVAL; + } } if (!pcm512x->pll_out) { sck_rate = clk_get_rate(pcm512x->sclk); - bclk_div = params->rate_den * 64 / lrclk_div; - bclk_rate = DIV_ROUND_CLOSEST(sck_rate, bclk_div); + bclk_rate = params_rate(params) * lrclk_div; + bclk_div = DIV_ROUND_CLOSEST(sck_rate, bclk_rate); mck_rate = sck_rate; } else { @@ -1383,6 +1389,16 @@ static int pcm512x_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) return 0; } +static int pcm512x_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio) +{ + struct snd_soc_component *component = dai->component; + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component); + + pcm512x->bclk_ratio = ratio; + + return 0; +} + static int pcm512x_digital_mute(struct snd_soc_dai *dai, int mute) { struct snd_soc_component *component = dai->component; @@ -1435,6 +1451,7 @@ static const struct snd_soc_dai_ops pcm512x_dai_ops = { .hw_params = pcm512x_hw_params, .set_fmt = pcm512x_set_fmt, .digital_mute = pcm512x_digital_mute, + .set_bclk_ratio = pcm512x_set_bclk_ratio, }; static struct snd_soc_dai_driver pcm512x_dai = {