From patchwork Tue Jul 4 11:59:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Schulz X-Patchwork-Id: 106954 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp911069qge; Tue, 4 Jul 2017 04:59:56 -0700 (PDT) X-Received: by 10.99.97.78 with SMTP id v75mr15607628pgb.158.1499169596846; Tue, 04 Jul 2017 04:59:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499169596; cv=none; d=google.com; s=arc-20160816; b=DlI6NEmMy4vjCw3wur8c/eQanvPDvIJ1gShPv0MjbATlX/F4WBzbMz3BEPrEOIY2rQ 9xWVxZpvfkbkeRbHvS0lOfeN/08Nz69h+LBdsnPnAZ4+zPV/k70NJ9FCe5SWSWigSw6L 70EhtCr6pppZJPmEwN87XL3jQeaBn/SeG5uRHKb+VvE/RBqXYya5mZzWTmfCbtX+AX7X 3Hlg0X/gQrnJ4ZfbwuC+yZksTnV+JdKsZnFXGdhFn6rwkDcIRLpX/JDNq34uuuSTSnfQ mNLENk9t5kkDJJg1hT/w3XlNu3fkRjNkIBVGaqlE5KwvrzLZ5Em9W6CzJmz6G5nILLzY Ipmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=w4Vktw9XHhsiqNvoGgwO93TLKVRQHN+LAvnjUx4ICWM=; b=qhEMb5Rf55u0hvPKEgGjmRE+PA7Lt75MLo3iuNDVE/nbLsQNcTqDvQvZT/0e+5hDA+ yI6OzyxJbezK1Cz9wLt65ISPNWvw99cVfFqxPuSzM1zdzAUDHhONclln6fpmYnZjLEI4 zLenkLLkdRlizx3jnaqp+GnWda+rnhrX0iVsZyFYCQzuIxn/DMZVy6/d4D8moVxTekzC bmxxfPTMcIiwfXL69yI75jONfB7G3c5mTqAub/QREjF236R43NHH08/rs5y2R9+o5uCk VIhCsRbEfAXze/Ztj5w9Qx9KEyA2dR2hk8ryGYVw/LxfaWOMha0eN3QMbG8uT4tRL+Z0 n86w== ARC-Authentication-Results: i=1; mx.google.com; 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 13si10159654pfm.355.2017.07.04.04.59.56; Tue, 04 Jul 2017 04:59:56 -0700 (PDT) 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; 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 S1752180AbdGDL7w (ORCPT + 25 others); Tue, 4 Jul 2017 07:59:52 -0400 Received: from mail.free-electrons.com ([62.4.15.54]:43560 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752143AbdGDL7q (ORCPT ); Tue, 4 Jul 2017 07:59:46 -0400 Received: by mail.free-electrons.com (Postfix, from userid 110) id 7CE0721E0D; Tue, 4 Jul 2017 13:59:43 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost.localdomain (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.free-electrons.com (Postfix) with ESMTPSA id 1ADC321D3F; Tue, 4 Jul 2017 13:59:43 +0200 (CEST) From: Quentin Schulz To: mturquette@baylibre.com, sboyd@codeaurora.org, robh+dt@kernel.org, mark.rutland@arm.com, lgirdwood@gmail.com, broonie@kernel.org, nicolas.ferre@microchip.com, alexandre.belloni@free-electrons.com, linux@armlinux.org.uk, boris.brezillon@free-electrons.com, perex@perex.cz, tiwai@suse.com Cc: Quentin Schulz , cyrille.pitchen@wedev4u.fr, thomas.petazzoni@free-electrons.com, linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 1/9] clk: at91: clk-generated: remove useless divisor loop Date: Tue, 4 Jul 2017 13:59:19 +0200 Message-Id: <20170704115927.32662-2-quentin.schulz@free-electrons.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170704115927.32662-1-quentin.schulz@free-electrons.com> References: <20170704115927.32662-1-quentin.schulz@free-electrons.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The driver requests the current clk rate of each of its parent clocks to decide whether a clock rate is suitable or not. It does not request determine_rate from a parent clock which could request a rate change in parent clock (i.e. there is no parent rate propagation). We know the rate we want (passed along req argument of the function) and the parent clock rate, thus we know the closest rounded divisor, we don't need to iterate over the available divisors to find the best one for a given clock. Signed-off-by: Quentin Schulz Acked-by: Boris Brezillon --- drivers/clk/at91/clk-generated.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) -- 2.11.0 diff --git a/drivers/clk/at91/clk-generated.c b/drivers/clk/at91/clk-generated.c index 07c8f701e51c..dab7002937e6 100644 --- a/drivers/clk/at91/clk-generated.c +++ b/drivers/clk/at91/clk-generated.c @@ -124,19 +124,18 @@ static int clk_generated_determine_rate(struct clk_hw *hw, (gck->range.max && min_rate > gck->range.max)) continue; - for (div = 1; div < GENERATED_MAX_DIV + 2; div++) { - tmp_rate = DIV_ROUND_CLOSEST(parent_rate, div); - tmp_diff = abs(req->rate - tmp_rate); - - if (best_diff < 0 || best_diff > tmp_diff) { - best_rate = tmp_rate; - best_diff = tmp_diff; - req->best_parent_rate = parent_rate; - req->best_parent_hw = parent; - } - - if (!best_diff || tmp_rate < req->rate) - break; + div = DIV_ROUND_CLOSEST(parent_rate, req->rate); + if (!div) + tmp_rate = parent_rate; + else + tmp_rate = parent_rate / div; + tmp_diff = abs(req->rate - tmp_rate); + + if (best_diff < 0 || best_diff > tmp_diff) { + best_rate = tmp_rate; + best_diff = tmp_diff; + req->best_parent_rate = parent_rate; + req->best_parent_hw = parent; } if (!best_diff) From patchwork Tue Jul 4 11:59:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Schulz X-Patchwork-Id: 106959 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp914249qge; Tue, 4 Jul 2017 05:02:13 -0700 (PDT) X-Received: by 10.84.171.132 with SMTP id l4mr16177822plb.175.1499169733726; Tue, 04 Jul 2017 05:02:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499169733; cv=none; d=google.com; s=arc-20160816; b=KAYdDf0NsgmwVspauK1H0hoffG0j+4NKQJRN0duB/gyuEkWdMmRC9LJyZnnVPuE0Ct Y7f8CNzOlDW3jgzC1X9+oVIni/6t9ojHemEB249qtWwfGCg9uihZdNHQFbRaMU0zjH2N M0593Frv4Ujv89PjRpE0AwgBtoL97dU9ppvq/cOqHnGkne+YYwHIzyMfCLZR8YQ262ql tVWXx2AppiYTMtd2Ec5MEkGp3Sv2bnMqCNovpVWMBlti4vmOhvhUH/XndFIaPLQonTxv DyyS9XpRBgOXVk8KWctVwrlBKVN+9rUNWafs9mxu8GgBlrsUpNcBN9dskHaV/Wd2xkch j+pA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=YJkSSF7gNuGWldQEfhsTlodcgFM5ECXg5eFiHXNSMRs=; b=CqHYGmcFfFnSm4H1A4MYfVLtOWeyRVT3iQTaYvXnTACl4MGTStKcD9GbbC0H5B2K3J UVPn+Dv+2JQp8jAnApGQ8PpqpNudEoV32NZlf8CsXx6wLT6P121HbOklXGcFTvTztrOh l2w+vy2qPHWpJeb4IXkADKWln8eXdseqDWP8TU57sbn8g0pg92rubjOEOML2vp7wBbRO 7uoiiBclffKRQ6XIpj/GjHIPGoSurwzfl4+oOZlHnaEBBF1B5Gj4HNCrfbDKY7iTK9P0 9gKjmLZMwJASKBwuqfoDeaQ+4neCMy1ScsQsZGAV3fK6SWdnY4EfoTDl3DXu/S4/eIa5 p7tA== ARC-Authentication-Results: i=1; mx.google.com; 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 a91si16079970pld.188.2017.07.04.05.02.13; Tue, 04 Jul 2017 05:02:13 -0700 (PDT) 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; 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 S1752644AbdGDMB4 (ORCPT + 25 others); Tue, 4 Jul 2017 08:01:56 -0400 Received: from mail.free-electrons.com ([62.4.15.54]:43612 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752169AbdGDL7r (ORCPT ); Tue, 4 Jul 2017 07:59:47 -0400 Received: by mail.free-electrons.com (Postfix, from userid 110) id A024521FBF; Tue, 4 Jul 2017 13:59:44 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost.localdomain (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.free-electrons.com (Postfix) with ESMTPSA id 3D59721D40; Tue, 4 Jul 2017 13:59:44 +0200 (CEST) From: Quentin Schulz To: mturquette@baylibre.com, sboyd@codeaurora.org, robh+dt@kernel.org, mark.rutland@arm.com, lgirdwood@gmail.com, broonie@kernel.org, nicolas.ferre@microchip.com, alexandre.belloni@free-electrons.com, linux@armlinux.org.uk, boris.brezillon@free-electrons.com, perex@perex.cz, tiwai@suse.com Cc: Cyrille Pitchen , cyrille.pitchen@wedev4u.fr, thomas.petazzoni@free-electrons.com, linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, linux-arm-kernel@lists.infradead.org, Nicolas Ferre , Quentin Schulz Subject: [PATCH v2 4/9] ARM: dts: at91: sama5d2: add classd nodes Date: Tue, 4 Jul 2017 13:59:22 +0200 Message-Id: <20170704115927.32662-5-quentin.schulz@free-electrons.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170704115927.32662-1-quentin.schulz@free-electrons.com> References: <20170704115927.32662-1-quentin.schulz@free-electrons.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Cyrille Pitchen This patch adds nodes for the classd device and its generated clock. Signed-off-by: Cyrille Pitchen Signed-off-by: Nicolas Ferre Signed-off-by: Quentin Schulz --- arch/arm/boot/dts/sama5d2.dtsi | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) -- 2.11.0 diff --git a/arch/arm/boot/dts/sama5d2.dtsi b/arch/arm/boot/dts/sama5d2.dtsi index cc06da394366..a564cd1ba327 100644 --- a/arch/arm/boot/dts/sama5d2.dtsi +++ b/arch/arm/boot/dts/sama5d2.dtsi @@ -494,6 +494,24 @@ clocks = <&plla>; }; + audio_pll_frac: audiopll_fracck { + compatible = "atmel,sama5d2-clk-audio-pll-frac"; + #clock-cells = <0>; + clocks = <&main>; + }; + + audio_pll_pad: audiopll_padck { + compatible = "atmel,sama5d2-clk-audio-pll-pad"; + #clock-cells = <0>; + clocks = <&audio_pll_frac>; + }; + + audio_pll_pmc: audiopll_pmcck { + compatible = "atmel,sama5d2-clk-audio-pll-pmc"; + #clock-cells = <0>; + clocks = <&audio_pll_frac>; + }; + utmi: utmick { compatible = "atmel,at91sam9x5-clk-utmi"; #clock-cells = <0>; @@ -895,7 +913,7 @@ #address-cells = <1>; #size-cells = <0>; interrupt-parent = <&pmc>; - clocks = <&clk32k>, <&main>, <&plladiv>, <&utmi>, <&mck>; + clocks = <&clk32k>, <&main>, <&plladiv>, <&utmi>, <&mck>, <&audio_pll_pmc>; sdmmc0_gclk: sdmmc0_gclk { #clock-cells = <0>; @@ -951,6 +969,12 @@ reg = <57>; atmel,clk-output-range = <0 80000000>; }; + + classd_gclk: classd_gclk { + #clock-cells = <0>; + reg = <59>; + atmel,clk-output-range = <0 100000000>; + }; }; }; @@ -1406,6 +1430,19 @@ status = "okay"; }; + classd: classd@fc048000 { + compatible = "atmel,sama5d2-classd"; + reg = <0xfc048000 0x100>; + interrupts = <59 IRQ_TYPE_LEVEL_HIGH 7>; + dmas = <&dma0 + (AT91_XDMAC_DT_MEM_IF(0) | AT91_XDMAC_DT_PER_IF(1) | + AT91_XDMAC_DT_PERID(47))>; + dma-names = "tx"; + clocks = <&classd_clk>, <&classd_gclk>; + clock-names = "pclk", "gclk"; + status = "disabled"; + }; + can1: can@fc050000 { compatible = "bosch,m_can"; reg = <0xfc050000 0x4000>, <0x210000 0x4000>; From patchwork Tue Jul 4 11:59:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Schulz X-Patchwork-Id: 106958 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp913592qge; Tue, 4 Jul 2017 05:01:46 -0700 (PDT) X-Received: by 10.98.152.25 with SMTP id q25mr14657943pfd.47.1499169706270; Tue, 04 Jul 2017 05:01:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499169706; cv=none; d=google.com; s=arc-20160816; b=og/aNTL3e7KwvgpEHkucfbLr8s/5sxnwANVKZn1mN3BjdI/zoJlM3+pWw6lNhMcbyC SusI7aOYxqyHIwnXFfZl+JMQ1xBdhLPaAHfx9uiL8IRld+kVFMUvaGYTitWNY/kkyFuc JeMWnvNz3+1cAClxeI1zMpXPQOxtWUTxsdziqvAi5S+b97K9nj5O4Vept/FU0xoGbNvH JDFTvzMQeUnOWH8NrboGmXh2ule1a0ZjyayLb+OUiO+qb4b1HMJg4uHTqMx9kZGgaT+T 7QRiS8Iw6iRG6Z1Z0J1eHaRWVKasOSKfxLyVt8yINrz3H1+Q1XSff/36vw5R8YLQDVbD FwEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=YA51fIanGtGRQtoIS0+LM/27QcuzQEFvA/W7vzyk7H4=; b=IW2eEcMImOCPOHr2mAOR14RrNfov1lsRjG03k6vmt2iluDrLkVhNqEtpcDrqtczGQM EkXtO2kSAupfc47iQeJotURjSdUF2VsRBSum3ACVMfQEETi1GrssOA9E9XOkUffYrFT2 7jkuVpbnoLQY2VGDDWEm/rqP6wbwza8jc4XBcEn6/2Pl4g2DRvP7fvb+5xwXnceCNRs+ aD72ekmzImoT5zQMJnfJD1WkKnqcyGGl2b9RMrCk9iE8Q0UWdWD37zisoOFZss2DzGR+ 8fH8VHUrmE0B6AltmlAqihkExw6+d4nc19wmREZm0iq3ZiFwhFcc7eGd9B/vk4bfJAHJ qXTg== ARC-Authentication-Results: i=1; mx.google.com; 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 o5si7429934plh.543.2017.07.04.05.01.45; Tue, 04 Jul 2017 05:01:46 -0700 (PDT) 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; 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 S1752409AbdGDMBl (ORCPT + 25 others); Tue, 4 Jul 2017 08:01:41 -0400 Received: from mail.free-electrons.com ([62.4.15.54]:43623 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752194AbdGDL7s (ORCPT ); Tue, 4 Jul 2017 07:59:48 -0400 Received: by mail.free-electrons.com (Postfix, from userid 110) id 5E9BC21FC1; Tue, 4 Jul 2017 13:59:45 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost.localdomain (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.free-electrons.com (Postfix) with ESMTPSA id F026721D40; Tue, 4 Jul 2017 13:59:44 +0200 (CEST) From: Quentin Schulz To: mturquette@baylibre.com, sboyd@codeaurora.org, robh+dt@kernel.org, mark.rutland@arm.com, lgirdwood@gmail.com, broonie@kernel.org, nicolas.ferre@microchip.com, alexandre.belloni@free-electrons.com, linux@armlinux.org.uk, boris.brezillon@free-electrons.com, perex@perex.cz, tiwai@suse.com Cc: Quentin Schulz , cyrille.pitchen@wedev4u.fr, thomas.petazzoni@free-electrons.com, linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 6/9] clk: at91: clk-generated: make gclk determine audio_pll rate Date: Tue, 4 Jul 2017 13:59:24 +0200 Message-Id: <20170704115927.32662-7-quentin.schulz@free-electrons.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170704115927.32662-1-quentin.schulz@free-electrons.com> References: <20170704115927.32662-1-quentin.schulz@free-electrons.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This allows gclk to determine audio_pll rate and set the parent rate accordingly. However, there are multiple children clocks that could technically change the rate of audio_pll (via gck). With the rate locking, the first consumer to enable the clock will be the one definitely setting the rate of the clock. Since audio IPs are most likely to request the same rate, we enforce that the only clks able to modify gck rate are those of audio IPs. To remain consistent, we deny other clocks to be children of audio_pll. Signed-off-by: Quentin Schulz --- v2: - added conditions for audio pll rate setting restriction for SSC and I2S, drivers/clk/at91/clk-generated.c | 48 +++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 6 deletions(-) -- 2.11.0 diff --git a/drivers/clk/at91/clk-generated.c b/drivers/clk/at91/clk-generated.c index 6530a2e7e84d..87866786a6ab 100644 --- a/drivers/clk/at91/clk-generated.c +++ b/drivers/clk/at91/clk-generated.c @@ -26,6 +26,13 @@ #define GENERATED_SOURCE_MAX 6 #define GENERATED_MAX_DIV 255 +#define GCK_ID_SSC0 43 +#define GCK_ID_SSC1 44 +#define GCK_ID_I2S0 54 +#define GCK_ID_I2S1 55 +#define GCK_ID_CLASSD 59 +#define GCK_INDEX_DT_AUDIO_PLL 5 + struct clk_generated { struct clk_hw hw; struct regmap *regmap; @@ -126,15 +133,14 @@ static int clk_generated_determine_rate(struct clk_hw *hw, { struct clk_generated *gck = to_clk_generated(hw); struct clk_hw *parent = NULL; + struct clk_rate_request req_parent = *req; long best_rate = -EINVAL; - unsigned long min_rate; + unsigned long min_rate, parent_rate; int best_diff = -1; int i; + u32 div; - for (i = 0; i < clk_hw_get_num_parents(hw); i++) { - u32 div; - unsigned long parent_rate; - + for (i = 0; i < clk_hw_get_num_parents(hw) - 1; i++) { parent = clk_hw_get_parent_by_index(hw, i); if (!parent) continue; @@ -150,11 +156,40 @@ static int clk_generated_determine_rate(struct clk_hw *hw, clk_generated_best_diff(req, parent, parent_rate, div, &best_diff, &best_rate); + if (!best_diff) + break; + } + + /* + * The audio_pll rate can be modified, unlike the five others clocks + * that should never be altered. + * The audio_pll can technically be used by multiple consumers. However, + * with the rate locking, the first consumer to enable to clock will be + * the one definitely setting the rate of the clock. + * Since audio IPs are most likely to request the same rate, we enforce + * that the only clks able to modify gck rate are those of audio IPs. + */ + + if (gck->id != GCK_ID_SSC0 && gck->id != GCK_ID_SSC1 && + gck->id != GCK_ID_I2S0 && gck->id != GCK_ID_I2S1 && + gck->id != GCK_ID_CLASSD) + goto end; + + parent = clk_hw_get_parent_by_index(hw, GCK_INDEX_DT_AUDIO_PLL); + if (!parent) + goto end; + + for (div = 1; div < GENERATED_MAX_DIV + 2; div++) { + req_parent.rate = req->rate * div; + __clk_determine_rate(parent, &req_parent); + clk_generated_best_diff(req, parent, req_parent.rate, div, + &best_diff, &best_rate); if (!best_diff) break; } +end: pr_debug("GCLK: %s, best_rate = %ld, parent clk: %s @ %ld\n", __func__, best_rate, __clk_get_name((req->best_parent_hw)->clk), @@ -264,7 +299,8 @@ at91_clk_register_generated(struct regmap *regmap, spinlock_t *lock, init.ops = &generated_ops; init.parent_names = parent_names; init.num_parents = num_parents; - init.flags = CLK_SET_RATE_GATE | CLK_SET_PARENT_GATE; + init.flags = CLK_SET_RATE_GATE | CLK_SET_PARENT_GATE | + CLK_SET_RATE_PARENT; gck->id = id; gck->hw.init = &init; From patchwork Tue Jul 4 11:59:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Schulz X-Patchwork-Id: 106957 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp913556qge; Tue, 4 Jul 2017 05:01:44 -0700 (PDT) X-Received: by 10.84.198.36 with SMTP id o33mr15742283pld.79.1499169704539; Tue, 04 Jul 2017 05:01:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499169704; cv=none; d=google.com; s=arc-20160816; b=Wh8E4mKn/S45ZZHRym6DX1dfrJOwQI6Za0KPMmo2hUh4X7PYUhxqA6bM2TyCA5v5yN XJDmdZOv0UMHre/E44HHg0z+HUv9YLmLfIuasBoczO/cHZJ1MRuWWo+y8lJOdIhtlXM1 2vnDRFv4QbPkgbxxkn0evakDLIZW0dYj787D/7ULWGiEnpzi/U4RSun9ifIPKrU5Tx5P K9NHONE+szb3mhkzZm6D8iHPT4ge1nZrUTwtnzF8zOyy6hNutgufr6sRiRBbPxfp0CNH KJcnOGct+3Jwl94m2SXowDEnYNPbSaXKZSpWaD5x5ddtdRWlgmOtlcObeLdveFJ2qka7 llaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=pB9dXoCXA68UypSok+X+Uou+9hja2DidgNSjTOOvb6Q=; b=XBehDQlXuORSvJUCv2kD8+f79uIZwMrsYFMo6B0mOnaYi9qQ0HDp76KZ5A1VP7LiT6 gaUhat3iuDCm12vdpP2idMOuoAthHjXg4QaFxgeY1wqwMGdevA74WoFIs3DiiX104S5t Fbg4dflp3nGvPHSTuW81+VajHhqdxXxn1yPJlodt2WENg8KraqKgau5HiO8U15STiRHG WJqgCyNpL1wNUjRnuSBFYGNEAbvH2f46US3F9tyei13fXWNheQ+Wid0MOlxICjWNk6Gf +ThlQAsYHNZYWhgG5ZUX6FQC8LWxI5Llbmg6Pf3mncyCUdZSrnDXOZwNehk+NOHsq0nK VoJg== ARC-Authentication-Results: i=1; mx.google.com; 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 o5si7429934plh.543.2017.07.04.05.01.44; Tue, 04 Jul 2017 05:01:44 -0700 (PDT) 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; 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 S1752608AbdGDMBO (ORCPT + 25 others); Tue, 4 Jul 2017 08:01:14 -0400 Received: from mail.free-electrons.com ([62.4.15.54]:43641 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752204AbdGDL7t (ORCPT ); Tue, 4 Jul 2017 07:59:49 -0400 Received: by mail.free-electrons.com (Postfix, from userid 110) id 1D5E421FC7; Tue, 4 Jul 2017 13:59:46 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost.localdomain (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.free-electrons.com (Postfix) with ESMTPSA id ABE6621D40; Tue, 4 Jul 2017 13:59:45 +0200 (CEST) From: Quentin Schulz To: mturquette@baylibre.com, sboyd@codeaurora.org, robh+dt@kernel.org, mark.rutland@arm.com, lgirdwood@gmail.com, broonie@kernel.org, nicolas.ferre@microchip.com, alexandre.belloni@free-electrons.com, linux@armlinux.org.uk, boris.brezillon@free-electrons.com, perex@perex.cz, tiwai@suse.com Cc: Quentin Schulz , cyrille.pitchen@wedev4u.fr, thomas.petazzoni@free-electrons.com, linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 8/9] ASoC: atmel-classd: remove aclk clock Date: Tue, 4 Jul 2017 13:59:26 +0200 Message-Id: <20170704115927.32662-9-quentin.schulz@free-electrons.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170704115927.32662-1-quentin.schulz@free-electrons.com> References: <20170704115927.32662-1-quentin.schulz@free-electrons.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since gclk (generated-clk) is now able to determine the rate of the audio_pll, there is no need for classd to have a direct phandle to the audio_pll while already having a phandle to gclk. Thus, remove all mentions to aclk in classd driver and update macros and variable names. Signed-off-by: Quentin Schulz --- added in v2: - split from bigger patch with audio PLLs and DT binding, - updated all variables and macros named ACLK to GCLK, sound/soc/atmel/atmel-classd.c | 47 +++++++++++++----------------------------- 1 file changed, 14 insertions(+), 33 deletions(-) -- 2.11.0 diff --git a/sound/soc/atmel/atmel-classd.c b/sound/soc/atmel/atmel-classd.c index b7ef8c59b49a..be6b775b6f46 100644 --- a/sound/soc/atmel/atmel-classd.c +++ b/sound/soc/atmel/atmel-classd.c @@ -32,7 +32,6 @@ struct atmel_classd { struct regmap *regmap; struct clk *pclk; struct clk *gclk; - struct clk *aclk; int irq; const struct atmel_classd_pdata *pdata; }; @@ -330,11 +329,6 @@ static int atmel_classd_codec_dai_startup(struct snd_pcm_substream *substream, { struct snd_soc_pcm_runtime *rtd = substream->private_data; struct atmel_classd *dd = snd_soc_card_get_drvdata(rtd->card); - int ret; - - ret = clk_prepare_enable(dd->aclk); - if (ret) - return ret; return clk_prepare_enable(dd->gclk); } @@ -357,31 +351,31 @@ static int atmel_classd_codec_dai_digital_mute(struct snd_soc_dai *codec_dai, return 0; } -#define CLASSD_ACLK_RATE_11M2896_MPY_8 (112896 * 100 * 8) -#define CLASSD_ACLK_RATE_12M288_MPY_8 (12288 * 1000 * 8) +#define CLASSD_GCLK_RATE_11M2896_MPY_8 (112896 * 100 * 8) +#define CLASSD_GCLK_RATE_12M288_MPY_8 (12288 * 1000 * 8) static struct { int rate; int sample_rate; int dsp_clk; - unsigned long aclk_rate; + unsigned long gclk_rate; } const sample_rates[] = { { 8000, CLASSD_INTPMR_FRAME_8K, - CLASSD_INTPMR_DSP_CLK_FREQ_12M288, CLASSD_ACLK_RATE_12M288_MPY_8 }, + CLASSD_INTPMR_DSP_CLK_FREQ_12M288, CLASSD_GCLK_RATE_12M288_MPY_8 }, { 16000, CLASSD_INTPMR_FRAME_16K, - CLASSD_INTPMR_DSP_CLK_FREQ_12M288, CLASSD_ACLK_RATE_12M288_MPY_8 }, + CLASSD_INTPMR_DSP_CLK_FREQ_12M288, CLASSD_GCLK_RATE_12M288_MPY_8 }, { 32000, CLASSD_INTPMR_FRAME_32K, - CLASSD_INTPMR_DSP_CLK_FREQ_12M288, CLASSD_ACLK_RATE_12M288_MPY_8 }, + CLASSD_INTPMR_DSP_CLK_FREQ_12M288, CLASSD_GCLK_RATE_12M288_MPY_8 }, { 48000, CLASSD_INTPMR_FRAME_48K, - CLASSD_INTPMR_DSP_CLK_FREQ_12M288, CLASSD_ACLK_RATE_12M288_MPY_8 }, + CLASSD_INTPMR_DSP_CLK_FREQ_12M288, CLASSD_GCLK_RATE_12M288_MPY_8 }, { 96000, CLASSD_INTPMR_FRAME_96K, - CLASSD_INTPMR_DSP_CLK_FREQ_12M288, CLASSD_ACLK_RATE_12M288_MPY_8 }, + CLASSD_INTPMR_DSP_CLK_FREQ_12M288, CLASSD_GCLK_RATE_12M288_MPY_8 }, { 22050, CLASSD_INTPMR_FRAME_22K, - CLASSD_INTPMR_DSP_CLK_FREQ_11M2896, CLASSD_ACLK_RATE_11M2896_MPY_8 }, + CLASSD_INTPMR_DSP_CLK_FREQ_11M2896, CLASSD_GCLK_RATE_11M2896_MPY_8 }, { 44100, CLASSD_INTPMR_FRAME_44K, - CLASSD_INTPMR_DSP_CLK_FREQ_11M2896, CLASSD_ACLK_RATE_11M2896_MPY_8 }, + CLASSD_INTPMR_DSP_CLK_FREQ_11M2896, CLASSD_GCLK_RATE_11M2896_MPY_8 }, { 88200, CLASSD_INTPMR_FRAME_88K, - CLASSD_INTPMR_DSP_CLK_FREQ_11M2896, CLASSD_ACLK_RATE_11M2896_MPY_8 }, + CLASSD_INTPMR_DSP_CLK_FREQ_11M2896, CLASSD_GCLK_RATE_11M2896_MPY_8 }, }; static int @@ -410,13 +404,12 @@ atmel_classd_codec_dai_hw_params(struct snd_pcm_substream *substream, } dev_dbg(codec->dev, - "Selected SAMPLE_RATE of %dHz, ACLK_RATE of %ldHz\n", - sample_rates[best].rate, sample_rates[best].aclk_rate); + "Selected SAMPLE_RATE of %dHz, GCLK_RATE of %ldHz\n", + sample_rates[best].rate, sample_rates[best].gclk_rate); clk_disable_unprepare(dd->gclk); - clk_disable_unprepare(dd->aclk); - ret = clk_set_rate(dd->aclk, sample_rates[best].aclk_rate); + ret = clk_set_rate(dd->gclk, sample_rates[best].gclk_rate); if (ret) return ret; @@ -426,10 +419,6 @@ atmel_classd_codec_dai_hw_params(struct snd_pcm_substream *substream, snd_soc_update_bits(codec, CLASSD_INTPMR, mask, val); - ret = clk_prepare_enable(dd->aclk); - if (ret) - return ret; - return clk_prepare_enable(dd->gclk); } @@ -441,7 +430,6 @@ atmel_classd_codec_dai_shutdown(struct snd_pcm_substream *substream, struct atmel_classd *dd = snd_soc_card_get_drvdata(rtd->card); clk_disable_unprepare(dd->gclk); - clk_disable_unprepare(dd->aclk); } static int atmel_classd_codec_dai_prepare(struct snd_pcm_substream *substream, @@ -596,13 +584,6 @@ static int atmel_classd_probe(struct platform_device *pdev) return ret; } - dd->aclk = devm_clk_get(dev, "aclk"); - if (IS_ERR(dd->aclk)) { - ret = PTR_ERR(dd->aclk); - dev_err(dev, "failed to get audio clock: %d\n", ret); - return ret; - } - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); io_base = devm_ioremap_resource(dev, res); if (IS_ERR(io_base)) { From patchwork Tue Jul 4 11:59:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Schulz X-Patchwork-Id: 106955 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp912801qge; Tue, 4 Jul 2017 05:01:15 -0700 (PDT) X-Received: by 10.99.122.3 with SMTP id v3mr15197881pgc.98.1499169675223; Tue, 04 Jul 2017 05:01:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499169675; cv=none; d=google.com; s=arc-20160816; b=RDaqscgcPbMmGIR7/EDqmhdPFEPzBXW9yauYaM9Vgz2VQP8fmg0eOSB+G+9gtjlvM1 dE/9a0i++3GouLvwDj80eiWHAXIWl/Z7mDAtRMVlhP+WdxSDDy2d5BCd4NequW3l25M2 NIEOyVyZfzP7iuw1nY8Znoo4cobHm9uv9CxHw0Mp6ZFG8bkMDCGdNaBaYoO/w46vYy3e gnz88uI6QjahuWcxvQR3kADMQUAFdyzWp9beLHki3UDYx6IbxfiDftZh3h7O0c4et548 bgWthDAnUGwlGgb/ORr0KGwsCDYMB3LEZ94OnRLJ7E7tlY4jTDJy1jqTvgRsyrzV8m2O BgJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=ofKL4D+hNaequF5Bx9IBipYMfQT8kvXw+KP8O/CfXHM=; b=GYPzo/xjzhGh6XOVdi4rulgYXfj6nwe6iNJAcBnbCQfjCAptzMrigpK24kgFV9/mHi 3QH5/MwU4C7846SL1eX1pNu8tTPiFZWMK3MD8/kK3dZywPMmkuMQ4Jan5A0NZkbJIJqu 9wa0pH/nt/vi6XerG6MKaB7wSLIixAOoegxcLIJxHCFkNbJwKHPdOC/eQ/e6FyfsbMhO K2I09O5vvkHE8Zvm+xQDQ610Kb8h3Uijco6WCyJihqs5f9IurCDsNH5CaYWb+u1leHgm pZ9i2EpZXhkW+4WwklgE7Nmh9Y1IquYQpLXlx2UBICo8Mnm3FI3GHtIknELg80LRGNFg /Lbw== ARC-Authentication-Results: i=1; mx.google.com; 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 m39si9935199plg.5.2017.07.04.05.01.14; Tue, 04 Jul 2017 05:01:15 -0700 (PDT) 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; 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 S1752575AbdGDMBB (ORCPT + 25 others); Tue, 4 Jul 2017 08:01:01 -0400 Received: from mail.free-electrons.com ([62.4.15.54]:43647 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752207AbdGDL7t (ORCPT ); Tue, 4 Jul 2017 07:59:49 -0400 Received: by mail.free-electrons.com (Postfix, from userid 110) id 7A86D21FC5; Tue, 4 Jul 2017 13:59:46 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost.localdomain (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.free-electrons.com (Postfix) with ESMTPSA id 0E21621D3F; Tue, 4 Jul 2017 13:59:46 +0200 (CEST) From: Quentin Schulz To: mturquette@baylibre.com, sboyd@codeaurora.org, robh+dt@kernel.org, mark.rutland@arm.com, lgirdwood@gmail.com, broonie@kernel.org, nicolas.ferre@microchip.com, alexandre.belloni@free-electrons.com, linux@armlinux.org.uk, boris.brezillon@free-electrons.com, perex@perex.cz, tiwai@suse.com Cc: Cyrille Pitchen , cyrille.pitchen@wedev4u.fr, thomas.petazzoni@free-electrons.com, linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, linux-arm-kernel@lists.infradead.org, Nicolas Ferre , Quentin Schulz Subject: [PATCH v2 9/9] ARM: dts: at91: sama5d2_xplained: add pin muxing and enable classd Date: Tue, 4 Jul 2017 13:59:27 +0200 Message-Id: <20170704115927.32662-10-quentin.schulz@free-electrons.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170704115927.32662-1-quentin.schulz@free-electrons.com> References: <20170704115927.32662-1-quentin.schulz@free-electrons.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Cyrille Pitchen This patch adds the pin muxing for classd and enables it. Signed-off-by: Cyrille Pitchen Signed-off-by: Nicolas Ferre Signed-off-by: Quentin Schulz --- arch/arm/boot/dts/at91-sama5d2_xplained.dts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) -- 2.11.0 diff --git a/arch/arm/boot/dts/at91-sama5d2_xplained.dts b/arch/arm/boot/dts/at91-sama5d2_xplained.dts index 2e2c3d1a1fa2..e92b030ca45a 100644 --- a/arch/arm/boot/dts/at91-sama5d2_xplained.dts +++ b/arch/arm/boot/dts/at91-sama5d2_xplained.dts @@ -355,6 +355,14 @@ bias-pull-up; }; + pinctrl_classd_default: classd_default { + pinmux = , + , + , + ; + bias-pull-up; + }; + pinctrl_flx0_default: flx0_default { pinmux = , ; @@ -488,6 +496,14 @@ }; + classd: classd@fc048000 { + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_classd_default>; + atmel,pwm-type = "diff"; + atmel,non-overlap-time = <10>; + status = "okay"; + }; + can1: can@fc050000 { pinctrl-names = "default"; pinctrl-0 = <&pinctrl_can1_default>;