From patchwork Tue Feb 16 17:33:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 62064 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp1799220lbl; Tue, 16 Feb 2016 09:33:30 -0800 (PST) X-Received: by 10.66.124.131 with SMTP id mi3mr32261911pab.7.1455644009877; Tue, 16 Feb 2016 09:33:29 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ut6si2493780pac.241.2016.02.16.09.33.29; Tue, 16 Feb 2016 09:33:29 -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; 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; dkim=pass header.i=@linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755734AbcBPRd1 (ORCPT + 30 others); Tue, 16 Feb 2016 12:33:27 -0500 Received: from mail-wm0-f50.google.com ([74.125.82.50]:37050 "EHLO mail-wm0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755710AbcBPRdX (ORCPT ); Tue, 16 Feb 2016 12:33:23 -0500 Received: by mail-wm0-f50.google.com with SMTP id g62so163309004wme.0 for ; Tue, 16 Feb 2016 09:33:22 -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=v489QaONwfqtGRxP5X9Ub/J8V/IgQYPpvaV0UGz+GDU=; b=RTV4hwooLQLMGJmqrqvFHnVswTmTdjquKNTa38D0JeoMDtYT8zxaBIYly04ugWQuiJ KSz79qpET5zADX/7Jk99jJWysU/1dc6I+zDmWx1+EbT7tseQRf6nWJ58EDmF9QSAHsEB KRD5Pku7ZuJ5HjyDwkZ2d32gJ2qSt7ypp9l5M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=v489QaONwfqtGRxP5X9Ub/J8V/IgQYPpvaV0UGz+GDU=; b=T40OmwaZrvrcUek/Ejjwh7C1e8PicQC7ihIUX9YB/7Aigy8bcigoffXS4bNYRvo276 HD8GZHbR5sn1bjlLMP+8hRsa2RxcM+iI+3RrQH2/rGBojITOfHh6fgv6Hco0lh/sZUwP 8U9KindN6KWWlX91I5Yeqw0xFH7O4JbG95qnfbQO322apPhnhfKeoIt5aPJud/JV45zW gWtvHZC7Ix+EcPs6Ear1lDeRPdEkkiJGNFRZ9ahqSC5C6d9AxL4ixUjBkF6pkqpUrnTr uR1qY6ob6YFS2irO8tMYG97I8t4ipnowZCTCxOEnUqYk+4k8m55fTfXawBf4uTW4xBIJ RfpA== X-Gm-Message-State: AG10YOQ6ISEpTyLYERW52tgoCSFQ2TWIxdflwVDUBDFsHSm/Gb2sH8FATRFS1WLueAIi81hA X-Received: by 10.28.179.84 with SMTP id c81mr19914194wmf.13.1455644002172; Tue, 16 Feb 2016 09:33:22 -0800 (PST) Received: from localhost.localdomain (host-92-17-247-99.as13285.net. [92.17.247.99]) by smtp.gmail.com with ESMTPSA id u201sm21436944wmu.11.2016.02.16.09.33.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Feb 2016 09:33:21 -0800 (PST) From: Srinivas Kandagatla To: alsa-devel@alsa-project.org, Mark Brown Cc: Rob Herring , Mark Rutland , Pawel Moll , Patrick Lai , Liam Girdwood , Jaroslav Kysela , Takashi Iwai , linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, kwestfie@codeaurora.org, Srinivas Kandagatla Subject: [RFC v1 6/9] ASoC: msm8x16: add codec dais Date: Tue, 16 Feb 2016 17:33:10 +0000 Message-Id: <1455643990-1870-1-git-send-email-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1455643880-1611-1-git-send-email-srinivas.kandagatla@linaro.org> References: <1455643880-1611-1-git-send-email-srinivas.kandagatla@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds two codec DAI's one Playback and other capture on the i2s bus. Signed-off-by: Srinivas Kandagatla --- include/dt-bindings/sound/msm8x16-wcd.h | 7 ++ sound/soc/codecs/msm8x16-wcd.c | 180 ++++++++++++++++++++++++++++++++ 2 files changed, 187 insertions(+) create mode 100644 include/dt-bindings/sound/msm8x16-wcd.h -- 1.9.1 diff --git a/include/dt-bindings/sound/msm8x16-wcd.h b/include/dt-bindings/sound/msm8x16-wcd.h new file mode 100644 index 0000000..f3257ab --- /dev/null +++ b/include/dt-bindings/sound/msm8x16-wcd.h @@ -0,0 +1,7 @@ +#ifndef __DT_MSM8x16_WCD_H +#define __DT_MSM8x16_WCD_H + +#define MSM8x16_WCD_PLAYBACK_DAI 0 +#define MSM8x16_WCD_CAPTURE_DAI 1 + +#endif /* __DT_MSM8x16_WCD_H */ diff --git a/sound/soc/codecs/msm8x16-wcd.c b/sound/soc/codecs/msm8x16-wcd.c index bc8b38a..4bc8274 100644 --- a/sound/soc/codecs/msm8x16-wcd.c +++ b/sound/soc/codecs/msm8x16-wcd.c @@ -11,9 +11,17 @@ #include #include #include +#include +#include #include "msm8x16-wcd-registers.h" #include "msm8x16-wcd.h" +#include "dt-bindings/sound/msm8x16-wcd.h" + +#define MSM8X16_WCD_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\ + SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000) +#define MSM8X16_WCD_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\ + SNDRV_PCM_FMTBIT_S24_LE) /* Cap mode for micbias */ #define MICBIAS_EXT_BYP_CAP 0x00 @@ -282,6 +290,19 @@ static const struct msm8x16_wcd_reg_mask_val {MSM8X16_WCD_A_ANALOG_RX_COM_OCP_COUNT, 0xFF, 0xFF}, }; +static int msm8x16_wcd_set_interpolator_rate(struct snd_soc_dai *dai, + u8 rx_fs_rate_reg_val, u32 sample_rate) +{ + return 0; +} + +static int msm8x16_wcd_set_decimator_rate(struct snd_soc_dai *dai, + u8 tx_fs_rate_reg_val, u32 sample_rate) +{ + + return 0; +} + static int msm8x16_wcd_device_up(struct snd_soc_codec *codec) { struct msm8x16_wcd_chip *msm8x16_wcd = snd_soc_codec_get_drvdata(codec); @@ -360,7 +381,166 @@ static int msm8x16_wcd_codec_remove(struct snd_soc_codec *codec) return 0; }; +static int msm8x16_wcd_startup(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + return 0; +} + +static void msm8x16_wcd_shutdown(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ +} + +static int msm8x16_wcd_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params, + struct snd_soc_dai *dai) +{ + u8 tx_fs_rate, rx_fs_rate; + int ret; + + switch (params_rate(params)) { + case 8000: + tx_fs_rate = 0x00; + rx_fs_rate = 0x00; + break; + case 16000: + tx_fs_rate = 0x01; + rx_fs_rate = 0x20; + break; + case 32000: + tx_fs_rate = 0x02; + rx_fs_rate = 0x40; + break; + case 48000: + tx_fs_rate = 0x03; + rx_fs_rate = 0x60; + break; + case 96000: + tx_fs_rate = 0x04; + rx_fs_rate = 0x80; + break; + case 192000: + tx_fs_rate = 0x05; + rx_fs_rate = 0xA0; + break; + default: + dev_err(dai->codec->dev, + "%s: Invalid sampling rate %d\n", __func__, + params_rate(params)); + return -EINVAL; + } + + switch (substream->stream) { + case SNDRV_PCM_STREAM_CAPTURE: + snd_soc_update_bits(dai->codec, + MSM8X16_WCD_A_CDC_CLK_TX_I2S_CTL, + 0x07, tx_fs_rate); + ret = msm8x16_wcd_set_decimator_rate(dai, tx_fs_rate, + params_rate(params)); + if (ret < 0) { + dev_err(dai->codec->dev, + "%s: set decimator rate failed %d\n", __func__, + ret); + return ret; + } + break; + case SNDRV_PCM_STREAM_PLAYBACK: + ret = msm8x16_wcd_set_interpolator_rate(dai, rx_fs_rate, + params_rate(params)); + if (ret < 0) { + dev_err(dai->codec->dev, + "%s: set decimator rate failed %d\n", __func__, + ret); + return ret; + } + break; + default: + dev_err(dai->codec->dev, + "%s: Invalid stream type %d\n", __func__, + substream->stream); + return -EINVAL; + } + + switch (params_format(params)) { + case SNDRV_PCM_FORMAT_S16_LE: + snd_soc_update_bits(dai->codec, + MSM8X16_WCD_A_CDC_CLK_TX_I2S_CTL, 0x20, 0x20); + snd_soc_update_bits(dai->codec, + MSM8X16_WCD_A_CDC_CLK_RX_I2S_CTL, 0x20, 0x20); + break; + case SNDRV_PCM_FORMAT_S24_LE: + snd_soc_update_bits(dai->codec, + MSM8X16_WCD_A_CDC_CLK_TX_I2S_CTL, 0x20, 0x00); + snd_soc_update_bits(dai->codec, + MSM8X16_WCD_A_CDC_CLK_RX_I2S_CTL, 0x20, 0x00); + break; + default: + dev_err(dai->dev, "%s: wrong format selected\n", + __func__); + return -EINVAL; + } + + return 0; +} + +static int msm8x16_wcd_set_dai_sysclk(struct snd_soc_dai *dai, + int clk_id, unsigned int freq, int dir) +{ + return 0; +} + +static int msm8x16_wcd_set_channel_map(struct snd_soc_dai *dai, + unsigned int tx_num, unsigned int *tx_slot, + unsigned int rx_num, unsigned int *rx_slot) + +{ + return 0; +} + +static int msm8x16_wcd_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) +{ + return 0; +} + +static struct snd_soc_dai_ops msm8x16_wcd_dai_ops = { + .startup = msm8x16_wcd_startup, + .shutdown = msm8x16_wcd_shutdown, + .hw_params = msm8x16_wcd_hw_params, + .set_sysclk = msm8x16_wcd_set_dai_sysclk, + .set_fmt = msm8x16_wcd_set_dai_fmt, + .set_channel_map = msm8x16_wcd_set_channel_map, +}; + static struct snd_soc_dai_driver msm8x16_wcd_codec_dai[] = { + [0] = { + .name = "msm8x16_wcd_i2s_rx1", + .id = MSM8x16_WCD_PLAYBACK_DAI, + .playback = { + .stream_name = "AIF1 Playback", + .rates = MSM8X16_WCD_RATES, + .formats = MSM8X16_WCD_FORMATS, + .rate_max = 192000, + .rate_min = 8000, + .channels_min = 1, + .channels_max = 3, + }, + .ops = &msm8x16_wcd_dai_ops, + }, + [1] = { + .name = "msm8x16_wcd_i2s_tx1", + .id = MSM8x16_WCD_CAPTURE_DAI, + .capture = { + .stream_name = "AIF1 Capture", + .rates = MSM8X16_WCD_RATES, + .formats = MSM8X16_WCD_FORMATS, + .rate_max = 192000, + .rate_min = 8000, + .channels_min = 1, + .channels_max = 4, + }, + .ops = &msm8x16_wcd_dai_ops, + }, }; static struct snd_soc_codec_driver msm8x16_wcd_codec = {