Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2017140ybv; Fri, 21 Feb 2020 07:23:45 -0800 (PST) X-Google-Smtp-Source: APXvYqxtiw5Oe7M2rYCmEzInxwtHYUMn36uSvRDN9nNO5rInJDNPz2ozxfmYIXXnpTJAyzraWHol X-Received: by 2002:aca:2207:: with SMTP id b7mr2470491oic.109.1582298625248; Fri, 21 Feb 2020 07:23:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582298625; cv=none; d=google.com; s=arc-20160816; b=PcqV5szaH0rF4Y1u9FCwHD74pUmc4s5pVyp9lQnsYLpCa7l/bLmXxrzoHwW9Z8GqRK JVKA+i7IPb/1rujAklp2AuzKs48009gkOQ8lZ3ZKTvGnwiFUYjKJyixXjX5O8QHTb17q 4z+abk1BKj8neXe2aGsqQWZBaMz2Baz54YdmJrGiLz23notq5sheO9WE8cDPfPh6cHOn wox5Qt8TK4XHXX3VAARuVj4nPpudDB+ej2l36o33cELx3Tvq3RIkiDOy5mKT43LOvgIs RJai9lheZU3hh1Mu1Xmb9cqafoVBs9vlUlPI8O7Ddo9RM38LApttuQ8NXP4zToJMp93V Na8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:in-reply-to :subject:cc:to:from:user-agent:references:dkim-signature; bh=MWznUWcF0+GyJXpKc77sr8V6T2rancb73H0vzc+QLOc=; b=fJMsyqoloi+qUq146EyLDKTXmf17kk8W9L8Udg8iyh2KGujGLQNGitLGvXi6uOcgvN AIq60rbwLnmd7Nu3b4aQ/p7Ra+xFitN4n48xz+SKOBoJ3Yu0YkHSSBugSsHHdX/KMkqu p2FdReyJ4+K8iblS0csFMecTvx4S8ng+yxEegcl1LJTXdHXtPSOo9qMBJZT0FSPGahey knt67luibIGWxSehRFZ8h84MjL/6Etd5DySQsikT8U1j6JgviDekQ8lqvV5bzbit0cpd XrpdFfz5WJaQiHS2uvoaZDRsax5lZuqJ/6r2j11xTjFurBlm3P4XFv6wfn+gp2dstzJw 0Aeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=zYcfxKYh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t22si1545605otc.167.2020.02.21.07.23.31; Fri, 21 Feb 2020 07:23:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=zYcfxKYh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728976AbgBUPWo (ORCPT + 99 others); Fri, 21 Feb 2020 10:22:44 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:44371 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727851AbgBUPWn (ORCPT ); Fri, 21 Feb 2020 10:22:43 -0500 Received: by mail-wr1-f66.google.com with SMTP id m16so2471005wrx.11 for ; Fri, 21 Feb 2020 07:22:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=references:user-agent:from:to:cc:subject:in-reply-to:date :message-id:mime-version; bh=MWznUWcF0+GyJXpKc77sr8V6T2rancb73H0vzc+QLOc=; b=zYcfxKYh5GVdsZmg/VVJtJjJHidVAdAv1fnWLBYz9Qrz9X2tuzafr/TrwUnnZgrVJ0 oo/BGktTtz5M5+iAIBxO/IZGYNX5JtB/f0qTHFByoAUnTTSWHZyr/vy4DNdhXAAnrd6p w9UC8cXQyanPoaRPr57NkWERkM+O7GE+0v3vDXHYVz7yirmIDpPSlTLARtU9LAKMwDGc AEGrmIdAQreDdhoms69YXG+cNkuylJ81TqDCurkrK8BVsmuNIz2Gmm92vbpHfdExJeNh kiivhGNsMa7XBrLqrpIuZCXL/vk00lxZEJ19nL9AqHm9selU5roj/NJmSNle5A+btUU8 B/OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject :in-reply-to:date:message-id:mime-version; bh=MWznUWcF0+GyJXpKc77sr8V6T2rancb73H0vzc+QLOc=; b=pZ7nMvZ0W02LtCAzRXAyKLp6bMcan8RN5eS05YZo5sPcJhJ2DS536BDYDRCG+9WOH5 dUmXBYbs+8cCZ+Epq/snHhsKzpHlqaurHKLrSUSGAHeHwm57bYAd+scVKqTKTGGfANr1 ap+0JMO7yIXEz09HNs+0QrRPV3e1VgDfG8EYmCstmMk96RMybRgbQx40BmZgA5Ew3HhL VJg2EbEJOK4nwNN2Ih13oC/KBQ/wJ+mY+a7exwk58SmA8YRnKscB/dSjXobCWAtBXbfU 9Ju05fIRUTkXWIDMGCsY6Tgj2PbdnufAs980RCK3C8xanjd8DHWNiWk/Gz0hngGYEIAM T4HQ== X-Gm-Message-State: APjAAAX5suRWBSK4F1qhlZbuB8Oz6Iqg78ZnvdE0zut0LU3qitrAITG0 A3z5qc6Memun8Qzm76G3Pz7Ugg== X-Received: by 2002:adf:e8ca:: with SMTP id k10mr46562839wrn.50.1582298561100; Fri, 21 Feb 2020 07:22:41 -0800 (PST) Received: from localhost (cag06-3-82-243-161-21.fbx.proxad.net. [82.243.161.21]) by smtp.gmail.com with ESMTPSA id z6sm4367616wrw.36.2020.02.21.07.22.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2020 07:22:40 -0800 (PST) References: <20200220205711.77953-1-martin.blumenstingl@googlemail.com> <20200220205711.77953-4-martin.blumenstingl@googlemail.com> User-agent: mu4e 1.3.3; emacs 26.3 From: Jerome Brunet To: Martin Blumenstingl , broonie@kernel.org, robh+dt@kernel.org, mark.rutland@arm.com, alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-amlogic@lists.infradead.org Cc: lgirdwood@gmail.com, perex@perex.cz, tiwai@suse.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH 3/3] ASoC: meson: aiu: add support for the Meson8 and Meson8b SoC families In-reply-to: <20200220205711.77953-4-martin.blumenstingl@googlemail.com> Date: Fri, 21 Feb 2020 16:22:39 +0100 Message-ID: <1jmu9c2ce8.fsf@starbuckisacylon.baylibre.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 20 Feb 2020 at 21:57, Martin Blumenstingl wrote: > The AIU audio controller on the Meson8 and Meson8b SoC families is > compatible with the one found in the later GXBB family. Add compatible > strings for these two older SoC families so the driver can be loaded for > them. > > Instead of using the I2S divider from the AIU_CLK_CTRL_MORE register we > need to use the I2S divider from the AIU_CLK_CTRL register. This older > register is less flexible because it only supports four divider settings > (1, 2, 4, 8) compared to the AIU_CLK_CTRL_MORE register (which supports > dividers in the range 0..64). > > Signed-off-by: Martin Blumenstingl > --- > sound/soc/meson/Kconfig | 2 +- > sound/soc/meson/aiu-encoder-i2s.c | 92 +++++++++++++++++++++++-------- > sound/soc/meson/aiu.c | 9 +++ > sound/soc/meson/aiu.h | 1 + > 4 files changed, 81 insertions(+), 23 deletions(-) > > diff --git a/sound/soc/meson/Kconfig b/sound/soc/meson/Kconfig > index 897a706dcda0..d27e9180b453 100644 > --- a/sound/soc/meson/Kconfig > +++ b/sound/soc/meson/Kconfig > @@ -10,7 +10,7 @@ config SND_MESON_AIU > imply SND_SOC_HDMI_CODEC if DRM_MESON_DW_HDMI > help > Select Y or M to add support for the Audio output subsystem found > - in the Amlogic GX SoC family > + in the Amlogic Meson8, Meson8b and GX SoC families > > config SND_MESON_AXG_FIFO > tristate > diff --git a/sound/soc/meson/aiu-encoder-i2s.c b/sound/soc/meson/aiu-encoder-i2s.c > index 4900e38e7e49..cc73b5d5c2b7 100644 > --- a/sound/soc/meson/aiu-encoder-i2s.c > +++ b/sound/soc/meson/aiu-encoder-i2s.c > @@ -111,34 +111,40 @@ static int aiu_encoder_i2s_setup_desc(struct snd_soc_component *component, > return 0; > } > > -static int aiu_encoder_i2s_set_clocks(struct snd_soc_component *component, > - struct snd_pcm_hw_params *params) > +static int aiu_encoder_i2s_set_legacy_div(struct snd_soc_component *component, > + struct snd_pcm_hw_params *params, > + unsigned int bs) > { > - struct aiu *aiu = snd_soc_component_get_drvdata(component); > - unsigned int srate = params_rate(params); > - unsigned int fs, bs; > - > - /* Get the oversampling factor */ > - fs = DIV_ROUND_CLOSEST(clk_get_rate(aiu->i2s.clks[MCLK].clk), srate); > + switch (bs) { > + case 1: > + case 2: > + case 4: > + case 8: > + /* These are the only valid legacy dividers */ > + break; > > - if (fs % 64) > + default: > + dev_err(component->dev, "Unsupported i2s divider: %u\n", bs); > return -EINVAL; > + }; Not major but this semicolon should be removed (Thx coccinelle!) > > - /* Send data MSB first */ > - snd_soc_component_update_bits(component, AIU_I2S_DAC_CFG, > - AIU_I2S_DAC_CFG_MSB_FIRST, > - AIU_I2S_DAC_CFG_MSB_FIRST); > + snd_soc_component_update_bits(component, AIU_CLK_CTRL, > + AIU_CLK_CTRL_I2S_DIV, > + FIELD_PREP(AIU_CLK_CTRL_I2S_DIV, > + __ffs(bs))); > > - /* Set bclk to lrlck ratio */ > - snd_soc_component_update_bits(component, AIU_CODEC_DAC_LRCLK_CTRL, > - AIU_CODEC_DAC_LRCLK_CTRL_DIV, > - FIELD_PREP(AIU_CODEC_DAC_LRCLK_CTRL_DIV, > - 64 - 1)); > + snd_soc_component_update_bits(component, AIU_CLK_CTRL_MORE, > + AIU_CLK_CTRL_MORE_I2S_DIV, > + FIELD_PREP(AIU_CLK_CTRL_MORE_I2S_DIV, > + 0)); > > - /* Use CLK_MORE for mclk to bclk divider */ > - snd_soc_component_update_bits(component, AIU_CLK_CTRL, > - AIU_CLK_CTRL_I2S_DIV, 0); > + return 0; > +} > > +static int aiu_encoder_i2s_set_more_div(struct snd_soc_component *component, > + struct snd_pcm_hw_params *params, > + unsigned int bs) > +{ > /* > * NOTE: this HW is odd. > * In most configuration, the i2s divider is 'mclk / blck'. > @@ -146,7 +152,6 @@ static int aiu_encoder_i2s_set_clocks(struct snd_soc_component *component, > * increased by 50% to get the correct output rate. > * No idea why ! > */ > - bs = fs / 64; > if (params_width(params) == 16 && params_channels(params) == 8) { > if (bs % 2) { > dev_err(component->dev, > @@ -156,11 +161,54 @@ static int aiu_encoder_i2s_set_clocks(struct snd_soc_component *component, > bs += bs / 2; > } > > + /* Use CLK_MORE for mclk to bclk divider */ > + snd_soc_component_update_bits(component, AIU_CLK_CTRL, > + AIU_CLK_CTRL_I2S_DIV, > + FIELD_PREP(AIU_CLK_CTRL_I2S_DIV, 0)); > + > snd_soc_component_update_bits(component, AIU_CLK_CTRL_MORE, > AIU_CLK_CTRL_MORE_I2S_DIV, > FIELD_PREP(AIU_CLK_CTRL_MORE_I2S_DIV, > bs - 1)); > > + return 0; > +} > + > +static int aiu_encoder_i2s_set_clocks(struct snd_soc_component *component, > + struct snd_pcm_hw_params *params) > +{ > + struct aiu *aiu = snd_soc_component_get_drvdata(component); > + unsigned int srate = params_rate(params); > + unsigned int fs, bs; > + int ret; > + > + /* Get the oversampling factor */ > + fs = DIV_ROUND_CLOSEST(clk_get_rate(aiu->i2s.clks[MCLK].clk), srate); > + > + if (fs % 64) > + return -EINVAL; > + > + /* Send data MSB first */ > + snd_soc_component_update_bits(component, AIU_I2S_DAC_CFG, > + AIU_I2S_DAC_CFG_MSB_FIRST, > + AIU_I2S_DAC_CFG_MSB_FIRST); > + > + /* Set bclk to lrlck ratio */ > + snd_soc_component_update_bits(component, AIU_CODEC_DAC_LRCLK_CTRL, > + AIU_CODEC_DAC_LRCLK_CTRL_DIV, > + FIELD_PREP(AIU_CODEC_DAC_LRCLK_CTRL_DIV, > + 64 - 1)); > + > + bs = fs / 64; > + > + if (aiu->platform->has_clk_ctrl_more_i2s_div) > + ret = aiu_encoder_i2s_set_more_div(component, params, bs); > + else > + ret = aiu_encoder_i2s_set_legacy_div(component, params, bs); > + > + if (ret) > + return ret; > + > /* Make sure amclk is used for HDMI i2s as well */ > snd_soc_component_update_bits(component, AIU_CLK_CTRL_MORE, > AIU_CLK_CTRL_MORE_HDMI_AMCLK, > diff --git a/sound/soc/meson/aiu.c b/sound/soc/meson/aiu.c > index 38209312a8c3..dc35ca79021c 100644 > --- a/sound/soc/meson/aiu.c > +++ b/sound/soc/meson/aiu.c > @@ -351,15 +351,24 @@ static int aiu_remove(struct platform_device *pdev) > > static const struct aiu_platform_data aiu_gxbb_pdata = { > .has_acodec = false, > + .has_clk_ctrl_more_i2s_div = true, > }; > > static const struct aiu_platform_data aiu_gxl_pdata = { > .has_acodec = true, > + .has_clk_ctrl_more_i2s_div = true, > +}; > + > +static const struct aiu_platform_data aiu_meson8_pdata = { > + .has_acodec = false, > + .has_clk_ctrl_more_i2s_div = false, > }; > > static const struct of_device_id aiu_of_match[] = { > { .compatible = "amlogic,aiu-gxbb", .data = &aiu_gxbb_pdata }, > { .compatible = "amlogic,aiu-gxl", .data = &aiu_gxl_pdata }, > + { .compatible = "amlogic,aiu-meson8", .data = &aiu_meson8_pdata }, > + { .compatible = "amlogic,aiu-meson8b", .data = &aiu_meson8_pdata }, > {} > }; > MODULE_DEVICE_TABLE(of, aiu_of_match); > diff --git a/sound/soc/meson/aiu.h b/sound/soc/meson/aiu.h > index ab003638d5e5..87aa19ac4af3 100644 > --- a/sound/soc/meson/aiu.h > +++ b/sound/soc/meson/aiu.h > @@ -29,6 +29,7 @@ struct aiu_interface { > > struct aiu_platform_data { > bool has_acodec; > + bool has_clk_ctrl_more_i2s_div; > }; > > struct aiu {