From patchwork Sat Jan 26 13:17:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dimitris Papavasiliou X-Patchwork-Id: 10782457 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 07AEA1390 for ; Sat, 26 Jan 2019 13:23:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D9C7D28795 for ; Sat, 26 Jan 2019 13:23:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C97B6287D2; Sat, 26 Jan 2019 13:23:51 +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 C492228795 for ; Sat, 26 Jan 2019 13:23:50 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 3EE7E26744B; Sat, 26 Jan 2019 14:17:10 +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 D038B267967; Sat, 26 Jan 2019 14:17:07 +0100 (CET) Received: from mail-ed1-f65.google.com (mail-ed1-f65.google.com [209.85.208.65]) by alsa0.perex.cz (Postfix) with ESMTP id 52981267418 for ; Sat, 26 Jan 2019 14:17:05 +0100 (CET) Received: by mail-ed1-f65.google.com with SMTP id y20so9469179edw.9 for ; Sat, 26 Jan 2019 05:17:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:cc:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=JjEvrmEhSj1rAlV3T7oecJjj2I/v8Sku0Y2ADmvbZz0=; b=rlGDUmOrWXIHsxL35EUlP8UooXum1QjNuFd3PhbfxYh2KGs6UXCF5Gcz1C8NBz/IUc +WTE3R5QQSrmyOt9n0KNfMnLqfNuswyHDcqDQ+Z/+a4sSm2nwRgmxfaKIzcfCykWn6DK dLhzXwfDcnmSlsWKx57mRznnHYhXMIcmZGpy9cg9huHn1TqLRAD8sfqOHonwkKrhvoxf n2hvRw4/72O+f1YvAK3HhjCfCxpWjheh1pUvdMr+Y7hSyjRe2nm8XdlSyx24/FfBfuIh QsMGer6NeLg912Rjj8dsvrzE/b/VuowCrvAK6R3Ea2gP8JkJjCMYM9HeVJdmSdr9Qglc 6zRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=JjEvrmEhSj1rAlV3T7oecJjj2I/v8Sku0Y2ADmvbZz0=; b=enNjtus/znobCl0fXJYV9D4NniOIOikPkYZsKdXjtvs9yiddwHx2GL302zozJHCd0z mzb89Lc6LT6piUmaHCJ073k8Xtsf2P7jQP41AtTg+nd26n7vmX9d9zzKLk6qxA77U7pJ XDAzmIN/mBjiWDVOWjcOkN30AHt+6A4WqFk+/aYM+DfvL4ynXW0uv9EjK+Vzq9Q3zwIH 3TTDycPYjhvLzzM2vZd8RCn3rqbunmOlXE9iouAP7Hgqfuzl4hVUGAnMI3xlnezMuAoF sUssShhSJ9dmR5d5NZH5KBe6ezcUZTGz8jB9F866oPchzdGmHw78ZQd8DFPa9BYNO5KY iVoA== X-Gm-Message-State: AJcUukdbJNSYSi5bvq5DS9VUGuzi4LUNGDG9l6QpiC3AV8HDrls2NeZU sLvxgbww8YbrlFKWRkEHAu8= X-Google-Smtp-Source: ALg8bN4GPl3nZRXWjAu9t13P25sPuSAkS2G5uFAMA/Zq4e0/76afNvjd4bmSSIrRZiS4HjoQxJTMWg== X-Received: by 2002:a50:a7c4:: with SMTP id i62mr14545083edc.162.1548508624581; Sat, 26 Jan 2019 05:17:04 -0800 (PST) Received: from [192.168.1.2] (ppp141237191004.access.hol.gr. [141.237.191.4]) by smtp.googlemail.com with ESMTPSA id l51sm12471447edb.36.2019.01.26.05.17.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 26 Jan 2019 05:17:03 -0800 (PST) From: Dimitris Papavasiliou To: alsa-devel@alsa-project.org Message-ID: <9b758d09-9b9b-77a1-6651-43755c67e6fd@gmail.com> Date: Sat, 26 Jan 2019 15:17:01 +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 , Matthias Reichl , Mark Brown , Peter Rosin Subject: [alsa-devel] [PATCH 1/2] 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 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. Although the datasheet (p. 15) seems to suggest that only a handful of ratios are supported, it's not very explicit about it, so we allow the full range of values supported by the underlying register in the callback, to avoid needlessly rejecting potentially usable configurations. [1] http://mailman.alsa-project.org/pipermail/alsa-devel/2018-December/143442.html Signed-off-by: Dimitris Papavasiliou --- Notes: This is essentially the same patch submitted previously as an RFC[1]. It has been split in two, in order to separate the set_bclk_ratio implementation from the clocking calculation fix and some conservative checking has been added to the argument of the callback. [1] http://mailman.alsa-project.org/pipermail/alsa-devel/2019-January/144213.html sound/soc/codecs/pcm512x.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/sound/soc/codecs/pcm512x.c b/sound/soc/codecs/pcm512x.c index 6cb1653be804..b63d9392bae3 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,10 +916,15 @@ 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) { @@ -1383,6 +1389,19 @@ 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); + + if (ratio > 256) + return -EINVAL; + + 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; @@ -1438,6 +1457,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 = {