From patchwork Tue Feb 13 16:58:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 128277 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp4460732ljc; Tue, 13 Feb 2018 09:04:21 -0800 (PST) X-Google-Smtp-Source: AH8x2240aqs63+T46YNtrF80+NnrA9Ogb76nwoNuUkb99G0klxd/tEqZKxZQmvG5p4isiHT3hCfX X-Received: by 10.99.120.199 with SMTP id t190mr248937pgc.72.1518541460962; Tue, 13 Feb 2018 09:04:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518541460; cv=none; d=google.com; s=arc-20160816; b=cLsH80VvylbJ4Rx+t+Ypmuc0C7rxxoKirJZqOSr1TuKDxn3hBW8BAckFGHb1NJXQId DbQ7ZD9zVhqeheNp09sbvnX44iN2p54KtvdpGu3oZs7M7GPLkhl9BM5m5Mwiqrn/U8A7 3kYUPXX/eL4zdM2tR4FDsm6h4ARLh10vcM6QBmCdRV48rmx/hRS1pnB/4KfEXNvQnFSW Yz2mowsv0PDJU5Dsf7TydHcEeBxMBNA/4TuLXZ+C2cidKUvfKb/NvhI4wml0cwG5doHv VpSyHbnIUtZYBgaLI299OKSl/HVeUF3uOvwub/InBgfNQgUt6IBXu5/BQVQtJLXmjlij YRpw== 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:dkim-signature:arc-authentication-results; bh=BA7amHDIKknaujBvB3KOcdzGNeIdDsT8b1j5zA+gGvM=; b=CYUahr/mR49wMK72X9DicFBKhh8Bibi5WIoksr0WaVwzjgyb2PhGqX+fYq+v1Ttiq6 VMDBOyvppUpPRUsH6WHzO8RG4kkahjm5Jr6LpBVX78+LdPJA6r70eqlKsbEsylalS7ux FqE2twzTwogdQCpTRPUCkj8ukB+EOFh/NLmsBvmYBCQJ4sxe4MnENM9WVEtGMkTUv+hZ o92pwhTCuSHivNa9WKYRhOGI0jRJOlrFRlNl1+n9L02ek8XpWOmhJl48z+bshBijGih1 a0XMRMFFAxMRtOGfiGcIldRUDj/UYrr+PJJVScW65ZYAMPVsaLj3mBcj65BVZnhS2EMN iGwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NGOUwxEs; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z3-v6si6045419plo.815.2018.02.13.09.04.20; Tue, 13 Feb 2018 09:04:20 -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=@linaro.org header.s=google header.b=NGOUwxEs; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965410AbeBMREC (ORCPT + 28 others); Tue, 13 Feb 2018 12:04:02 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:54924 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965492AbeBMRBn (ORCPT ); Tue, 13 Feb 2018 12:01:43 -0500 Received: by mail-wm0-f67.google.com with SMTP id i186so17317304wmi.4 for ; Tue, 13 Feb 2018 09:01:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=BA7amHDIKknaujBvB3KOcdzGNeIdDsT8b1j5zA+gGvM=; b=NGOUwxEsnRKO/hGpSI9eMuSZ1fIrr0jl9KbTCygsake9iMDb61rVklPgtMbyhhWo5u INi462cC9VbfozpAruHH/GmEUnHeWICsLvEOjg6ON5YY+DZ+B7StfFBRPSU0HsX4KqX5 xTFgSioCJ8Oz3RxRGVa9nRER6faVNHFY0nNIE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=BA7amHDIKknaujBvB3KOcdzGNeIdDsT8b1j5zA+gGvM=; b=FY39ZNf57csXwSUWhSKyYLCnTMz/SwQkh322Joo92nbxvEZDWPGjLwkKEnsVMSxL7u RpM8lGfbr8dxZY83cN1SjI8JoSMtEPYYELHctl11KqS1BLVntgd09F1512G7rQuLUa2N fDoxdIvmytoZldvZh9YsoJgpLBOytG0vMqzrzW4RpSEIi32Pum1ukA0x9pv6t7Lvg+Dl USPlLZ6fAUNKwrcsXXbxMJzKMVyyqcd1Uf00kXqO+HfrY6lCxtx/igdgenLp32rdA1gx HegkXrATMqs4ONfolM2kmjeFK6k2tJMEk6Mv3BdZ0OtQjaCSA/m74ju/Zy3pFuAyxqrm xW1Q== X-Gm-Message-State: APf1xPCPIXi81UnycZEhoXBvPZ6fewl+OeS4RL7DNOz3IP8yZlk1Q08W 9NP+6tvPuZuHET/aY7bEozmZIw== X-Received: by 10.28.138.146 with SMTP id m140mr2013901wmd.85.1518541301950; Tue, 13 Feb 2018 09:01:41 -0800 (PST) Received: from localhost.localdomain (cpc90716-aztw32-2-0-cust92.18-1.cable.virginm.net. [86.26.100.93]) by smtp.gmail.com with ESMTPSA id y145sm7432723wmd.43.2018.02.13.09.01.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Feb 2018 09:01:41 -0800 (PST) From: srinivas.kandagatla@linaro.org To: andy.gross@linaro.org, broonie@kernel.org, linux-arm-msm@vger.kernel.org, alsa-devel@alsa-project.org Cc: david.brown@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, lgirdwood@gmail.com, plai@codeaurora.org, bgoswami@codeaurora.org, perex@perex.cz, tiwai@suse.com, linux-soc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, rohkumar@qti.qualcomm.com, spatakok@qti.qualcomm.com, Srinivas Kandagatla Subject: [PATCH v3 20/25] ASoC: qcom: q6afe: add support to MI2S sysclks Date: Tue, 13 Feb 2018 16:58:32 +0000 Message-Id: <20180213165837.1620-21-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180213165837.1620-1-srinivas.kandagatla@linaro.org> References: <20180213165837.1620-1-srinivas.kandagatla@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Srinivas Kandagatla This patch adds support to LPASS Bit clock, LPASS Digital core clock and OSR clock. These clocks are required for both MI2S and PCM setup. Signed-off-by: Srinivas Kandagatla --- sound/soc/qcom/qdsp6/q6afe.c | 115 +++++++++++++++++++++++++++++++++++++++++++ sound/soc/qcom/qdsp6/q6afe.h | 10 ++++ 2 files changed, 125 insertions(+) -- 2.15.1 diff --git a/sound/soc/qcom/qdsp6/q6afe.c b/sound/soc/qcom/qdsp6/q6afe.c index c04caea5481c..ea6fa3848007 100644 --- a/sound/soc/qcom/qdsp6/q6afe.c +++ b/sound/soc/qcom/qdsp6/q6afe.c @@ -31,6 +31,9 @@ #define AFE_PARAM_ID_CDC_SLIMBUS_SLAVE_CFG 0x00010235 +#define AFE_PARAM_ID_LPAIF_CLK_CONFIG 0x00010238 +#define AFE_PARAM_ID_INTERNAL_DIGITAL_CDC_CLK_CONFIG 0x00010239 + #define AFE_PARAM_ID_SLIMBUS_CONFIG 0x00010212 #define AFE_PARAM_ID_I2S_CONFIG 0x0001020D @@ -94,6 +97,11 @@ #define AFE_PORT_ID_QUATERNARY_MI2S_RX 0x1006 #define AFE_PORT_ID_QUATERNARY_MI2S_TX 0x1007 +#define Q6AFE_LPASS_MODE_CLK1_VALID 1 +#define Q6AFE_LPASS_MODE_CLK2_VALID 2 +#define Q6AFE_LPASS_CLK_SRC_INTERNAL 1 +#define Q6AFE_LPASS_CLK_ROOT_DEFAULT 0 + #define TIMEOUT_MS 1000 #define AFE_CMD_RESP_AVAIL 0 #define AFE_CMD_RESP_NONE 1 @@ -191,6 +199,23 @@ struct afe_param_id_slimbus_cfg { */ } __packed; +struct afe_clk_cfg { + u32 i2s_cfg_minor_version; + u32 clk_val1; + u32 clk_val2; + u16 clk_src; + u16 clk_root; + u16 clk_set_mode; + u16 reserved; +} __packed; + +struct afe_digital_clk_cfg { + u32 i2s_cfg_minor_version; + u32 clk_val; + u16 clk_root; + u16 reserved; +} __packed; + struct afe_param_id_i2s_cfg { u32 i2s_cfg_minor_version; u16 bit_width; @@ -208,6 +233,21 @@ union afe_port_config { struct afe_param_id_i2s_cfg i2s_cfg; } __packed; +struct afe_lpass_clk_config_command { + struct apr_hdr hdr; + struct afe_port_cmd_set_param_v2 param; + struct afe_port_param_data_v2 pdata; + struct afe_clk_cfg clk_cfg; +} __packed; + +struct afe_lpass_digital_clk_config_command { + struct apr_hdr hdr; + struct afe_port_cmd_set_param_v2 param; + struct afe_port_param_data_v2 pdata; + struct afe_digital_clk_cfg clk_cfg; +} __packed; + +/* This param id is used to configure internal clk */ struct q6afe_port { wait_queue_head_t wait; union afe_port_config port_cfg; @@ -425,6 +465,81 @@ static int q6afe_port_set_param_v2(struct q6afe_port *port, void *data, return ret; } +static int q6afe_set_lpass_clock(struct q6afe_port *port, + struct afe_clk_cfg *cfg) +{ + struct afe_lpass_clk_config_command clk_cfg = {0}; + int param_id = AFE_PARAM_ID_LPAIF_CLK_CONFIG; + struct q6afe *afe = port->afe; + + if (!cfg) { + dev_err(afe->dev, "clock cfg is NULL\n"); + return -EINVAL; + } + + clk_cfg.clk_cfg = *cfg; + + return q6afe_port_set_param_v2(port, &clk_cfg, param_id, sizeof(*cfg)); +} + +static int q6afe_set_digital_codec_core_clock(struct q6afe_port *port, + struct afe_digital_clk_cfg *cfg) +{ + struct afe_lpass_digital_clk_config_command clk_cfg = {0}; + int param_id = AFE_PARAM_ID_INTERNAL_DIGITAL_CDC_CLK_CONFIG; + struct q6afe *afe = port->afe; + + if (!cfg) { + dev_err(afe->dev, "clock cfg is NULL\n"); + return -EINVAL; + } + + clk_cfg.clk_cfg = *cfg; + + return q6afe_port_set_param_v2(port, &clk_cfg, param_id, sizeof(*cfg)); +} + +int q6afe_port_set_sysclk(struct q6afe_port *port, int clk_id, + int clk_src, int clk_root, + unsigned int freq, int dir) +{ + struct afe_clk_cfg ccfg = {0,}; + struct afe_digital_clk_cfg dcfg = {0,}; + int ret; + + switch (clk_id) { + case LPAIF_DIG_CLK: + dcfg.i2s_cfg_minor_version = AFE_API_VERSION_I2S_CONFIG; + dcfg.clk_val = freq; + dcfg.clk_root = clk_root; + ret = q6afe_set_digital_codec_core_clock(port, &dcfg); + break; + case LPAIF_BIT_CLK: + ccfg.i2s_cfg_minor_version = AFE_API_VERSION_I2S_CONFIG; + ccfg.clk_val1 = freq; + ccfg.clk_src = clk_src; + ccfg.clk_root = clk_root; + ccfg.clk_set_mode = Q6AFE_LPASS_MODE_CLK1_VALID; + ret = q6afe_set_lpass_clock(port, &ccfg); + break; + + case LPAIF_OSR_CLK: + ccfg.i2s_cfg_minor_version = AFE_API_VERSION_I2S_CONFIG; + ccfg.clk_val2 = freq; + ccfg.clk_src = clk_src; + ccfg.clk_root = clk_root; + ccfg.clk_set_mode = Q6AFE_LPASS_MODE_CLK2_VALID; + ret = q6afe_set_lpass_clock(port, &ccfg); + break; + default: + ret = -EINVAL; + break; + } + + return ret; +} +EXPORT_SYMBOL_GPL(q6afe_port_set_sysclk); + static int afe_port_start(struct q6afe_port *port, union afe_port_config *afe_config) { diff --git a/sound/soc/qcom/qdsp6/q6afe.h b/sound/soc/qcom/qdsp6/q6afe.h index 9114d68a79cb..c469f6de38d2 100644 --- a/sound/soc/qcom/qdsp6/q6afe.h +++ b/sound/soc/qcom/qdsp6/q6afe.h @@ -14,6 +14,13 @@ #define AFE_MAX_CHAN_COUNT 8 #define AFE_PORT_MAX_AUDIO_CHAN_CNT 0x8 +#define Q6AFE_LPASS_CLK_SRC_INTERNAL 1 +#define Q6AFE_LPASS_CLK_ROOT_DEFAULT 0 + +#define LPAIF_DIG_CLK 1 +#define LPAIF_BIT_CLK 2 +#define LPAIF_OSR_CLK 3 + struct q6afe_hdmi_cfg { u16 datatype; u16 channel_allocation; @@ -61,4 +68,7 @@ void q6afe_slim_port_prepare(struct q6afe_port *port, struct q6afe_slim_cfg *cfg); void q6afe_i2s_port_prepare(struct q6afe_port *port, struct q6afe_i2s_cfg *cfg); +int q6afe_port_set_sysclk(struct q6afe_port *port, int clk_id, + int clk_src, int clk_root, + unsigned int freq, int dir); #endif /* __Q6AFE_H__ */