Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 // Copyright (c) 2018, Linaro Limited
0003 
0004 #include <linux/module.h>
0005 #include <linux/platform_device.h>
0006 #include <linux/of_device.h>
0007 #include <sound/soc.h>
0008 #include <sound/soc-dapm.h>
0009 #include <sound/pcm.h>
0010 #include "common.h"
0011 
0012 #define SLIM_MAX_TX_PORTS 16
0013 #define SLIM_MAX_RX_PORTS 16
0014 #define WCD9335_DEFAULT_MCLK_RATE   9600000
0015 
0016 static int apq8096_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
0017                       struct snd_pcm_hw_params *params)
0018 {
0019     struct snd_interval *rate = hw_param_interval(params,
0020                     SNDRV_PCM_HW_PARAM_RATE);
0021     struct snd_interval *channels = hw_param_interval(params,
0022                     SNDRV_PCM_HW_PARAM_CHANNELS);
0023 
0024     rate->min = rate->max = 48000;
0025     channels->min = channels->max = 2;
0026 
0027     return 0;
0028 }
0029 
0030 static int msm_snd_hw_params(struct snd_pcm_substream *substream,
0031                  struct snd_pcm_hw_params *params)
0032 {
0033     struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
0034     struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
0035     struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
0036     u32 rx_ch[SLIM_MAX_RX_PORTS], tx_ch[SLIM_MAX_TX_PORTS];
0037     u32 rx_ch_cnt = 0, tx_ch_cnt = 0;
0038     int ret = 0;
0039 
0040     ret = snd_soc_dai_get_channel_map(codec_dai,
0041                 &tx_ch_cnt, tx_ch, &rx_ch_cnt, rx_ch);
0042     if (ret != 0 && ret != -ENOTSUPP) {
0043         pr_err("failed to get codec chan map, err:%d\n", ret);
0044         goto end;
0045     } else if (ret == -ENOTSUPP) {
0046         return 0;
0047     }
0048 
0049     if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
0050         ret = snd_soc_dai_set_channel_map(cpu_dai, 0, NULL,
0051                           rx_ch_cnt, rx_ch);
0052     else
0053         ret = snd_soc_dai_set_channel_map(cpu_dai, tx_ch_cnt, tx_ch,
0054                           0, NULL);
0055     if (ret != 0 && ret != -ENOTSUPP)
0056         pr_err("Failed to set cpu chan map, err:%d\n", ret);
0057     else if (ret == -ENOTSUPP)
0058         ret = 0;
0059 end:
0060     return ret;
0061 }
0062 
0063 static const struct snd_soc_ops apq8096_ops = {
0064     .hw_params = msm_snd_hw_params,
0065 };
0066 
0067 static int apq8096_init(struct snd_soc_pcm_runtime *rtd)
0068 {
0069     struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
0070 
0071     /*
0072      * Codec SLIMBUS configuration
0073      * RX1, RX2, RX3, RX4, RX5, RX6, RX7, RX8, RX9, RX10, RX11, RX12, RX13
0074      * TX1, TX2, TX3, TX4, TX5, TX6, TX7, TX8, TX9, TX10, TX11, TX12, TX13
0075      * TX14, TX15, TX16
0076      */
0077     unsigned int rx_ch[SLIM_MAX_RX_PORTS] = {144, 145, 146, 147, 148, 149,
0078                     150, 151, 152, 153, 154, 155, 156};
0079     unsigned int tx_ch[SLIM_MAX_TX_PORTS] = {128, 129, 130, 131, 132, 133,
0080                         134, 135, 136, 137, 138, 139,
0081                         140, 141, 142, 143};
0082 
0083     snd_soc_dai_set_channel_map(codec_dai, ARRAY_SIZE(tx_ch),
0084                     tx_ch, ARRAY_SIZE(rx_ch), rx_ch);
0085 
0086     snd_soc_dai_set_sysclk(codec_dai, 0, WCD9335_DEFAULT_MCLK_RATE,
0087                 SNDRV_PCM_STREAM_PLAYBACK);
0088 
0089     return 0;
0090 }
0091 
0092 static void apq8096_add_be_ops(struct snd_soc_card *card)
0093 {
0094     struct snd_soc_dai_link *link;
0095     int i;
0096 
0097     for_each_card_prelinks(card, i, link) {
0098         if (link->no_pcm == 1) {
0099             link->be_hw_params_fixup = apq8096_be_hw_params_fixup;
0100             link->init = apq8096_init;
0101             link->ops = &apq8096_ops;
0102         }
0103     }
0104 }
0105 
0106 static int apq8096_platform_probe(struct platform_device *pdev)
0107 {
0108     struct snd_soc_card *card;
0109     struct device *dev = &pdev->dev;
0110     int ret;
0111 
0112     card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
0113     if (!card)
0114         return -ENOMEM;
0115 
0116     card->dev = dev;
0117     card->owner = THIS_MODULE;
0118     dev_set_drvdata(dev, card);
0119     ret = qcom_snd_parse_of(card);
0120     if (ret)
0121         return ret;
0122 
0123     apq8096_add_be_ops(card);
0124     return devm_snd_soc_register_card(dev, card);
0125 }
0126 
0127 static const struct of_device_id msm_snd_apq8096_dt_match[] = {
0128     {.compatible = "qcom,apq8096-sndcard"},
0129     {}
0130 };
0131 
0132 MODULE_DEVICE_TABLE(of, msm_snd_apq8096_dt_match);
0133 
0134 static struct platform_driver msm_snd_apq8096_driver = {
0135     .probe  = apq8096_platform_probe,
0136     .driver = {
0137         .name = "msm-snd-apq8096",
0138         .of_match_table = msm_snd_apq8096_dt_match,
0139     },
0140 };
0141 module_platform_driver(msm_snd_apq8096_driver);
0142 MODULE_AUTHOR("Srinivas Kandagatla <srinivas.kandagatla@linaro.org");
0143 MODULE_DESCRIPTION("APQ8096 ASoC Machine Driver");
0144 MODULE_LICENSE("GPL v2");