Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp653996rwi; Thu, 27 Oct 2022 06:10:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7Ts2Geyq4cKaU0/SlB4Edil4ez0zdkpSDuHEpvy5Ohr0YvrTs72UBiqiRNHPEJANeC7gLI X-Received: by 2002:a05:6a00:b86:b0:56c:349f:5d4a with SMTP id g6-20020a056a000b8600b0056c349f5d4amr11825942pfj.72.1666876233148; Thu, 27 Oct 2022 06:10:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666876233; cv=none; d=google.com; s=arc-20160816; b=Yy5jjwKlfAsjIDGjuVX054Gaomv1AuvlzQoNYqiEQDoQNiq+1RMktqTHlHRo3L9JRs 5JhEQIH699MRcZyLm6bJrp+U6MBKptBsB7MWYPZ+FVvLrzzRvOXmRe7FSmVsfOmlhCUj 3+lUdPp1wBOFI6JJ6kU9eOGkl215zf6Gpt1IH8kaSSC72OaOAEzOYwusWE1LJwfbJKII /wUrbOE5pe6nWnTJWWXyxwE+rBags8bgPg7oZMByDDEs1eY7Z6OdAVhlTB+VhTImBi0y FWcHSLMiAzNe9zPqlOhHAdo3PV+Kcbx9pp76MOGhUh46AgbUsUQ4RMTSM79MEjqyXrF6 U0AA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:cc:to:subject:from:date :dkim-signature; bh=um9/OS7dgazyiG2HSas0gGeFZisZOzGn8RMAzZOsWsE=; b=VAMu9TvbNpn0+VM4jOgxKmoz3eLKbd1DUp+HtFktigmZYH5FQOlay7TASXUuIpECU/ e3HymB0ocw05LFFaRf/wWalBN3ivMIJsf1ZYcpczeNm0OaRHTCfR81vUtUhN+hY7BbrD L/biwZPYpCEbR5ZS4D/KB0B9Z04Tb/n7V51kENrwfx/IxW4LdMQBzzx+TuModxoNNL6C d8tyYZe1llpgdYqbmukS8eYqh8dglWRCYdBN/1Xv+ezKsjwIn4a9wtRQlGkCSfY1BvCl yrWxMXxsHHmXFoSeW1OvnNRhSPCm0oIYeM+/SmBpS/4lypreBmCNlJLLyRAr9OirYyVw OtJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@crapouillou.net header.s=mail header.b=RnY+S9ci; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s18-20020a056a00195200b00562331a3562si1919798pfk.130.2022.10.27.06.10.21; Thu, 27 Oct 2022 06:10:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@crapouillou.net header.s=mail header.b=RnY+S9ci; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235734AbiJ0Mnn (ORCPT + 99 others); Thu, 27 Oct 2022 08:43:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234140AbiJ0Mnh (ORCPT ); Thu, 27 Oct 2022 08:43:37 -0400 Received: from aposti.net (aposti.net [89.234.176.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37E63167253; Thu, 27 Oct 2022 05:43:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crapouillou.net; s=mail; t=1666874613; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=um9/OS7dgazyiG2HSas0gGeFZisZOzGn8RMAzZOsWsE=; b=RnY+S9citCYf4A1np5gWktC9TFg+p1PTiWCzc4L9VgWrDK0wCyGOeUtjz/W+XiJVmQvfUB Y0fVCq9MlCnU0MI/Tj/ardWiCClOhsrAUoibplJyQdgy059cNaQNfd7+tYH/s9y5QoUJOj xNPUiRUPpe6ZtQBUpW8e89k8yLnLlHc= Date: Thu, 27 Oct 2022 13:43:23 +0100 From: Paul Cercueil Subject: Re: [PATCH v2 5/6] clk: ingenic: Add X1000 audio clocks To: Aidan MacDonald Cc: mturquette@baylibre.com, sboyd@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, zhouyu@wanyeetech.com, linux-mips@vger.kernel.org, linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Message-Id: In-Reply-To: <20221026194345.243007-6-aidanmacdonald.0x0@gmail.com> References: <20221026194345.243007-1-aidanmacdonald.0x0@gmail.com> <20221026194345.243007-6-aidanmacdonald.0x0@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Aidan, Le mer. 26 oct. 2022 =E0 20:43:44 +0100, Aidan MacDonald=20 a =E9crit : > The X1000's CGU supplies the I2S system clock to the AIC module > and ultimately the audio codec, represented by the "i2s" clock. > It is a simple mux which can either pass through EXCLK or a PLL > multiplied by a fractional divider (the "i2s_pll" clock). >=20 > The AIC contains a separate 1/N divider controlled by the I2S > driver, which generates the bit clock from the system clock. > The frame clock is always fixed to 1/64th of the bit clock. >=20 > Signed-off-by: Aidan MacDonald Reviewed-by: Paul Cercueil Cheers, -Paul > --- > v1 -> v2: > * Fix I2SCDR1 refresh to ensure the register is properly initialized > and we don't rely on the reset value. Since the I2SDIV_D field can > be automatically calculated by the hardware we don't need to provide > it, writing 0 triggers the auto calculation. > * Remove redundant -1 entries from parent clocks. >=20 > drivers/clk/ingenic/x1000-cgu.c | 70=20 > +++++++++++++++++++++++++++++++++ > 1 file changed, 70 insertions(+) >=20 > diff --git a/drivers/clk/ingenic/x1000-cgu.c=20 > b/drivers/clk/ingenic/x1000-cgu.c > index b2ce3fb83f54..95d5e3a44cee 100644 > --- a/drivers/clk/ingenic/x1000-cgu.c > +++ b/drivers/clk/ingenic/x1000-cgu.c > @@ -8,6 +8,7 @@ > #include > #include > #include > +#include >=20 > #include >=20 > @@ -168,6 +169,38 @@ static const struct clk_ops x1000_otg_phy_ops =3D { > .is_enabled =3D x1000_usb_phy_is_enabled, > }; >=20 > +static void > +x1000_i2spll_calc_m_n_od(const struct ingenic_cgu_pll_info *pll_info, > + unsigned long rate, unsigned long parent_rate, > + unsigned int *pm, unsigned int *pn, unsigned int *pod) > +{ > + const unsigned long m_max =3D GENMASK(pll_info->m_bits - 1, 0); > + const unsigned long n_max =3D GENMASK(pll_info->n_bits - 1, 0); > + unsigned long m, n; > + > + rational_best_approximation(rate, parent_rate, m_max, n_max, &m,=20 > &n); > + > + /* n should not be less than 2*m */ > + if (n < 2 * m) > + n =3D 2 * m; > + > + *pm =3D m; > + *pn =3D n; > + *pod =3D 1; > +} > + > +static void > +x1000_i2spll_set_rate_hook(const struct ingenic_cgu_pll_info=20 > *pll_info, > + unsigned long rate, unsigned long parent_rate) > +{ > + /* > + * Writing 0 causes I2SCDR1.I2SDIV_D to be automatically=20 > recalculated > + * based on the current value of I2SCDR.I2SDIV_N, which is needed=20 > for > + * the divider to function correctly. > + */ > + writel(0, cgu->base + CGU_REG_I2SCDR1); > +} > + > static const s8 pll_od_encoding[8] =3D { > 0x0, 0x1, -1, 0x2, -1, -1, -1, 0x3, > }; > @@ -319,6 +352,37 @@ static const struct ingenic_cgu_clk_info=20 > x1000_cgu_clocks[] =3D { > .gate =3D { CGU_REG_CLKGR, 25 }, > }, >=20 > + [X1000_CLK_I2SPLLMUX] =3D { > + "i2s_pll_mux", CGU_CLK_MUX, > + .parents =3D { X1000_CLK_SCLKA, X1000_CLK_MPLL }, > + .mux =3D { CGU_REG_I2SCDR, 31, 1 }, > + }, > + > + [X1000_CLK_I2SPLL] =3D { > + "i2s_pll", CGU_CLK_PLL, > + .parents =3D { X1000_CLK_I2SPLLMUX }, > + .pll =3D { > + .reg =3D CGU_REG_I2SCDR, > + .rate_multiplier =3D 1, > + .m_shift =3D 13, > + .m_bits =3D 9, > + .n_shift =3D 0, > + .n_bits =3D 13, > + .calc_m_n_od =3D x1000_i2spll_calc_m_n_od, > + .set_rate_hook =3D x1000_i2spll_set_rate_hook, > + }, > + }, > + > + [X1000_CLK_I2S] =3D { > + "i2s", CGU_CLK_MUX, > + .parents =3D { X1000_CLK_EXCLK, -1, -1, X1000_CLK_I2SPLL }, > + /* > + * NOTE: the mux is at bit 30; bit 29 enables the M/N divider. > + * Therefore, the divider is disabled when EXCLK is selected. > + */ > + .mux =3D { CGU_REG_I2SCDR, 29, 2 }, > + }, > + > [X1000_CLK_LCD] =3D { > "lcd", CGU_CLK_MUX | CGU_CLK_DIV | CGU_CLK_GATE, > .parents =3D { X1000_CLK_SCLKA, X1000_CLK_MPLL }, > @@ -426,6 +490,12 @@ static const struct ingenic_cgu_clk_info=20 > x1000_cgu_clocks[] =3D { > .gate =3D { CGU_REG_CLKGR, 9 }, > }, >=20 > + [X1000_CLK_AIC] =3D { > + "aic", CGU_CLK_GATE, > + .parents =3D { X1000_CLK_EXCLK }, > + .gate =3D { CGU_REG_CLKGR, 11 }, > + }, > + > [X1000_CLK_UART0] =3D { > "uart0", CGU_CLK_GATE, > .parents =3D { X1000_CLK_EXCLK, -1, -1, -1 }, > -- > 2.38.1 >=20