.. | .. |
---|
9 | 9 | #include <sound/pcm.h> |
---|
10 | 10 | #include "common.h" |
---|
11 | 11 | |
---|
| 12 | +#define SLIM_MAX_TX_PORTS 16 |
---|
| 13 | +#define SLIM_MAX_RX_PORTS 16 |
---|
| 14 | +#define WCD9335_DEFAULT_MCLK_RATE 9600000 |
---|
| 15 | + |
---|
12 | 16 | static int apq8096_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, |
---|
13 | 17 | struct snd_pcm_hw_params *params) |
---|
14 | 18 | { |
---|
.. | .. |
---|
23 | 27 | return 0; |
---|
24 | 28 | } |
---|
25 | 29 | |
---|
| 30 | +static int msm_snd_hw_params(struct snd_pcm_substream *substream, |
---|
| 31 | + struct snd_pcm_hw_params *params) |
---|
| 32 | +{ |
---|
| 33 | + struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
---|
| 34 | + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); |
---|
| 35 | + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); |
---|
| 36 | + u32 rx_ch[SLIM_MAX_RX_PORTS], tx_ch[SLIM_MAX_TX_PORTS]; |
---|
| 37 | + u32 rx_ch_cnt = 0, tx_ch_cnt = 0; |
---|
| 38 | + int ret = 0; |
---|
| 39 | + |
---|
| 40 | + ret = snd_soc_dai_get_channel_map(codec_dai, |
---|
| 41 | + &tx_ch_cnt, tx_ch, &rx_ch_cnt, rx_ch); |
---|
| 42 | + if (ret != 0 && ret != -ENOTSUPP) { |
---|
| 43 | + pr_err("failed to get codec chan map, err:%d\n", ret); |
---|
| 44 | + goto end; |
---|
| 45 | + } else if (ret == -ENOTSUPP) { |
---|
| 46 | + return 0; |
---|
| 47 | + } |
---|
| 48 | + |
---|
| 49 | + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
---|
| 50 | + ret = snd_soc_dai_set_channel_map(cpu_dai, 0, NULL, |
---|
| 51 | + rx_ch_cnt, rx_ch); |
---|
| 52 | + else |
---|
| 53 | + ret = snd_soc_dai_set_channel_map(cpu_dai, tx_ch_cnt, tx_ch, |
---|
| 54 | + 0, NULL); |
---|
| 55 | + if (ret != 0 && ret != -ENOTSUPP) |
---|
| 56 | + pr_err("Failed to set cpu chan map, err:%d\n", ret); |
---|
| 57 | + else if (ret == -ENOTSUPP) |
---|
| 58 | + ret = 0; |
---|
| 59 | +end: |
---|
| 60 | + return ret; |
---|
| 61 | +} |
---|
| 62 | + |
---|
| 63 | +static struct snd_soc_ops apq8096_ops = { |
---|
| 64 | + .hw_params = msm_snd_hw_params, |
---|
| 65 | +}; |
---|
| 66 | + |
---|
| 67 | +static int apq8096_init(struct snd_soc_pcm_runtime *rtd) |
---|
| 68 | +{ |
---|
| 69 | + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); |
---|
| 70 | + |
---|
| 71 | + /* |
---|
| 72 | + * Codec SLIMBUS configuration |
---|
| 73 | + * RX1, RX2, RX3, RX4, RX5, RX6, RX7, RX8, RX9, RX10, RX11, RX12, RX13 |
---|
| 74 | + * TX1, TX2, TX3, TX4, TX5, TX6, TX7, TX8, TX9, TX10, TX11, TX12, TX13 |
---|
| 75 | + * TX14, TX15, TX16 |
---|
| 76 | + */ |
---|
| 77 | + unsigned int rx_ch[SLIM_MAX_RX_PORTS] = {144, 145, 146, 147, 148, 149, |
---|
| 78 | + 150, 151, 152, 153, 154, 155, 156}; |
---|
| 79 | + unsigned int tx_ch[SLIM_MAX_TX_PORTS] = {128, 129, 130, 131, 132, 133, |
---|
| 80 | + 134, 135, 136, 137, 138, 139, |
---|
| 81 | + 140, 141, 142, 143}; |
---|
| 82 | + |
---|
| 83 | + snd_soc_dai_set_channel_map(codec_dai, ARRAY_SIZE(tx_ch), |
---|
| 84 | + tx_ch, ARRAY_SIZE(rx_ch), rx_ch); |
---|
| 85 | + |
---|
| 86 | + snd_soc_dai_set_sysclk(codec_dai, 0, WCD9335_DEFAULT_MCLK_RATE, |
---|
| 87 | + SNDRV_PCM_STREAM_PLAYBACK); |
---|
| 88 | + |
---|
| 89 | + return 0; |
---|
| 90 | +} |
---|
| 91 | + |
---|
26 | 92 | static void apq8096_add_be_ops(struct snd_soc_card *card) |
---|
27 | 93 | { |
---|
28 | | - struct snd_soc_dai_link *link = card->dai_link; |
---|
29 | | - int i, num_links = card->num_links; |
---|
| 94 | + struct snd_soc_dai_link *link; |
---|
| 95 | + int i; |
---|
30 | 96 | |
---|
31 | | - for (i = 0; i < num_links; i++) { |
---|
32 | | - if (link->no_pcm == 1) |
---|
| 97 | + for_each_card_prelinks(card, i, link) { |
---|
| 98 | + if (link->no_pcm == 1) { |
---|
33 | 99 | link->be_hw_params_fixup = apq8096_be_hw_params_fixup; |
---|
34 | | - link++; |
---|
| 100 | + link->init = apq8096_init; |
---|
| 101 | + link->ops = &apq8096_ops; |
---|
| 102 | + } |
---|
35 | 103 | } |
---|
36 | 104 | } |
---|
37 | 105 | |
---|
.. | .. |
---|
41 | 109 | struct device *dev = &pdev->dev; |
---|
42 | 110 | int ret; |
---|
43 | 111 | |
---|
44 | | - card = kzalloc(sizeof(*card), GFP_KERNEL); |
---|
| 112 | + card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); |
---|
45 | 113 | if (!card) |
---|
46 | 114 | return -ENOMEM; |
---|
47 | 115 | |
---|
.. | .. |
---|
49 | 117 | card->owner = THIS_MODULE; |
---|
50 | 118 | dev_set_drvdata(dev, card); |
---|
51 | 119 | ret = qcom_snd_parse_of(card); |
---|
52 | | - if (ret) { |
---|
53 | | - dev_err(dev, "Error parsing OF data\n"); |
---|
54 | | - goto err; |
---|
55 | | - } |
---|
| 120 | + if (ret) |
---|
| 121 | + return ret; |
---|
56 | 122 | |
---|
57 | 123 | apq8096_add_be_ops(card); |
---|
58 | | - ret = snd_soc_register_card(card); |
---|
59 | | - if (ret) |
---|
60 | | - goto err_card_register; |
---|
61 | | - |
---|
62 | | - return 0; |
---|
63 | | - |
---|
64 | | -err_card_register: |
---|
65 | | - kfree(card->dai_link); |
---|
66 | | -err: |
---|
67 | | - kfree(card); |
---|
68 | | - return ret; |
---|
69 | | -} |
---|
70 | | - |
---|
71 | | -static int apq8096_platform_remove(struct platform_device *pdev) |
---|
72 | | -{ |
---|
73 | | - struct snd_soc_card *card = dev_get_drvdata(&pdev->dev); |
---|
74 | | - |
---|
75 | | - snd_soc_unregister_card(card); |
---|
76 | | - kfree(card->dai_link); |
---|
77 | | - kfree(card); |
---|
78 | | - |
---|
79 | | - return 0; |
---|
| 124 | + return devm_snd_soc_register_card(dev, card); |
---|
80 | 125 | } |
---|
81 | 126 | |
---|
82 | 127 | static const struct of_device_id msm_snd_apq8096_dt_match[] = { |
---|
.. | .. |
---|
88 | 133 | |
---|
89 | 134 | static struct platform_driver msm_snd_apq8096_driver = { |
---|
90 | 135 | .probe = apq8096_platform_probe, |
---|
91 | | - .remove = apq8096_platform_remove, |
---|
92 | 136 | .driver = { |
---|
93 | 137 | .name = "msm-snd-apq8096", |
---|
94 | 138 | .of_match_table = msm_snd_apq8096_dt_match, |
---|