From patchwork Fri Oct 5 07:58:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Marco Felsch X-Patchwork-Id: 148141 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp137104lji; Fri, 5 Oct 2018 00:58:27 -0700 (PDT) X-Google-Smtp-Source: ACcGV608BwRTfrbi3E95vuIE3/H8lLTkBNsJ9eca00sKQipceiKjfghtdhh4tiNC2pXVE1FXg/lB X-Received: by 2002:a62:9402:: with SMTP id m2-v6mr10717415pfe.255.1538726307343; Fri, 05 Oct 2018 00:58:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538726307; cv=none; d=google.com; s=arc-20160816; b=qEhZPIbOY0UvqZKOipSmwQT19NIXAjd8Jgsj6xSstWrrEX6iylh7wlUHS7wx9Lvc7b rlxozPeFNH6dHH2yHp2QyvBnG8EIbolWG66xg7a1CgUGYOhQqufrr3YWbwBTGIyRqhjH qkWMfSM/u9xdISgZrqCeNRF9uXcbfQiqPW1zBY+vnhqb6R7KEC2XqaazTKGlNAa2tORt Rgswcz2xeFe5TF2hLDwSCPoVN0bvuvsIduffD7dJwUqv+gOz8eUxySQiaMAesOfLhQQr NzulCqPvbxJbn5cRoI75/myrjFAjNrO9hQmmU3M4biSljgmcdcSCJ7SpLJaRTs4ie/Nu BhsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=y0o41JYkHH8iykkFGDN4ZDywsC6OohTgIM3pSEt7xVY=; b=wMZnuRkGzpvKZ6DuhAKuGOV1FxZKoCrvnb1wuaG0xYoaNBBK9LCKJLXrqrMHTyEAsN nYJAAQQbV6KeJSWenNsDXE8o9RdxUTlzvCu5AVGXoLbF+68fcn0ajZX0dhQezdcK1wqo zmSAWrOzsB1qSTic9VGkHtrYEwkw1gdLMWBd/CPx2eulsjkWEaZkC9LVgjcW5DARwo/T WGatA0WN27yvuLDUp7Iu7hwzxVAaqaECN7Kp4a0rkmyYFiexTptiHbjNl00/p14A3Yle ko2SVhsBuFvthno/VginpwbZoauPrC30aVChkoTnS3dkLQWe79k2+SHmu2nKuKtfLzkq iU0A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-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 y3-v6si7271641pgg.266.2018.10.05.00.58.27; Fri, 05 Oct 2018 00:58:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-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 devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727882AbeJEOz6 (ORCPT + 6 others); Fri, 5 Oct 2018 10:55:58 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:42509 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727942AbeJEOz6 (ORCPT ); Fri, 5 Oct 2018 10:55:58 -0400 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1g8L09-0001Jy-Vw; Fri, 05 Oct 2018 09:58:21 +0200 Received: from mfe by dude.hi.pengutronix.de with local (Exim 4.91) (envelope-from ) id 1g8L08-0003hp-JD; Fri, 05 Oct 2018 09:58:20 +0200 From: Marco Felsch To: lgirdwood@gmail.com, broonie@kernel.org, robh+dt@kernel.org, mark.rutland@arm.com Cc: devicetree@vger.kernel.org, alsa-devel@alsa-project.org, =?utf-8?q?And?= =?utf-8?q?reas_F=C3=A4rber?= , kernel@pengutronix.de, Tushar Behera Subject: [PATCH v2 4/5] ASoC: max98088: Add master clock handling Date: Fri, 5 Oct 2018 09:58:11 +0200 Message-Id: <20181005075812.13986-5-m.felsch@pengutronix.de> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181005075812.13986-1-m.felsch@pengutronix.de> References: <20181005075812.13986-1-m.felsch@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: mfe@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: devicetree@vger.kernel.org Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Andreas Färber If master clock is provided through device tree, then update the master clock frequency during set_sysclk. Cc: Tushar Behera Signed-off-by: Andreas Färber Acked-by: Tushar Behera Reviewed-by: Javier Martinez Canillas [m.felsch@pengutronix.de: move mclk request to i2c_probe] [m.felsch@pengutronix.de: make use of snd_soc_component_get_bias_level()] Signed-off-by: Marco Felsch --- sound/soc/codecs/max98088.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) -- 2.19.0 diff --git a/sound/soc/codecs/max98088.c b/sound/soc/codecs/max98088.c index 9450d5d9c492..ca172a4b6849 100644 --- a/sound/soc/codecs/max98088.c +++ b/sound/soc/codecs/max98088.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -42,6 +43,7 @@ struct max98088_priv { struct regmap *regmap; enum max98088_type devtype; struct max98088_pdata *pdata; + struct clk *mclk; unsigned int sysclk; struct max98088_cdata dai[2]; int eq_textcnt; @@ -1103,6 +1105,11 @@ static int max98088_dai_set_sysclk(struct snd_soc_dai *dai, if (freq == max98088->sysclk) return 0; + if (!IS_ERR(max98088->mclk)) { + freq = clk_round_rate(max98088->mclk, freq); + clk_set_rate(max98088->mclk, freq); + } + /* Setup clocks for slave mode, and using the PLL * PSCLK = 0x01 (when master clk is 10MHz to 20MHz) * 0x02 (when master clk is 20MHz to 30MHz).. @@ -1310,6 +1317,20 @@ static int max98088_set_bias_level(struct snd_soc_component *component, break; case SND_SOC_BIAS_PREPARE: + /* + * SND_SOC_BIAS_PREPARE is called while preparing for a + * transition to ON or away from ON. If current bias_level + * is SND_SOC_BIAS_ON, then it is preparing for a transition + * away from ON. Disable the clock in that case, otherwise + * enable it. + */ + if (!IS_ERR(max98088->mclk)) { + if (snd_soc_component_get_bias_level(component) == + SND_SOC_BIAS_ON) + clk_disable_unprepare(max98088->mclk); + else + clk_prepare_enable(max98088->mclk); + } break; case SND_SOC_BIAS_STANDBY: @@ -1725,6 +1746,11 @@ static int max98088_i2c_probe(struct i2c_client *i2c, if (IS_ERR(max98088->regmap)) return PTR_ERR(max98088->regmap); + max98088->mclk = devm_clk_get(&i2c->dev, "mclk"); + if (IS_ERR(max98088->mclk)) + if (PTR_ERR(max98088->mclk) == -EPROBE_DEFER) + return PTR_ERR(max98088->mclk); + max98088->devtype = id->driver_data; i2c_set_clientdata(i2c, max98088);