2 * Copyright (c) 2010-2011,2013-2015 The Linux Foundation. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * lpass-apq8016.c -- ALSA SoC CPU DAI driver for APQ8016 LPASS
18 #include <linux/clk.h>
19 #include <linux/device.h>
20 #include <linux/err.h>
21 #include <linux/kernel.h>
22 #include <linux/module.h>
24 #include <linux/platform_device.h>
25 #include <sound/pcm.h>
26 #include <sound/pcm_params.h>
27 #include <sound/soc.h>
28 #include <sound/soc-dai.h>
30 #include <dt-bindings/sound/apq8016-lpass.h>
31 #include "lpass-lpaif-reg.h"
34 static struct snd_soc_dai_driver apq8016_lpass_cpu_dai_driver
[] = {
37 .name
= "Primary MI2S",
39 .stream_name
= "Primary Playback",
40 .formats
= SNDRV_PCM_FMTBIT_S16
|
41 SNDRV_PCM_FMTBIT_S24
|
43 .rates
= SNDRV_PCM_RATE_8000
|
44 SNDRV_PCM_RATE_16000
|
45 SNDRV_PCM_RATE_32000
|
46 SNDRV_PCM_RATE_48000
|
53 .probe
= &asoc_qcom_lpass_cpu_dai_probe
,
54 .ops
= &asoc_qcom_lpass_cpu_dai_ops
,
58 .name
= "Secondary MI2S",
60 .stream_name
= "Secondary Playback",
61 .formats
= SNDRV_PCM_FMTBIT_S16
|
62 SNDRV_PCM_FMTBIT_S24
|
64 .rates
= SNDRV_PCM_RATE_8000
|
65 SNDRV_PCM_RATE_16000
|
66 SNDRV_PCM_RATE_32000
|
67 SNDRV_PCM_RATE_48000
|
74 .probe
= &asoc_qcom_lpass_cpu_dai_probe
,
75 .ops
= &asoc_qcom_lpass_cpu_dai_ops
,
79 .name
= "Tertiary MI2S",
81 .stream_name
= "Tertiary Capture",
82 .formats
= SNDRV_PCM_FMTBIT_S16
|
83 SNDRV_PCM_FMTBIT_S24
|
85 .rates
= SNDRV_PCM_RATE_8000
|
86 SNDRV_PCM_RATE_16000
|
87 SNDRV_PCM_RATE_32000
|
88 SNDRV_PCM_RATE_48000
|
95 .probe
= &asoc_qcom_lpass_cpu_dai_probe
,
96 .ops
= &asoc_qcom_lpass_cpu_dai_ops
,
99 .id
= MI2S_QUATERNARY
,
100 .name
= "Quatenary MI2S",
102 .stream_name
= "Quatenary Playback",
103 .formats
= SNDRV_PCM_FMTBIT_S16
|
104 SNDRV_PCM_FMTBIT_S24
|
105 SNDRV_PCM_FMTBIT_S32
,
106 .rates
= SNDRV_PCM_RATE_8000
|
107 SNDRV_PCM_RATE_16000
|
108 SNDRV_PCM_RATE_32000
|
109 SNDRV_PCM_RATE_48000
|
110 SNDRV_PCM_RATE_96000
,
117 .stream_name
= "Quatenary Capture",
118 .formats
= SNDRV_PCM_FMTBIT_S16
|
119 SNDRV_PCM_FMTBIT_S24
|
120 SNDRV_PCM_FMTBIT_S32
,
121 .rates
= SNDRV_PCM_RATE_8000
|
122 SNDRV_PCM_RATE_16000
|
123 SNDRV_PCM_RATE_32000
|
124 SNDRV_PCM_RATE_48000
|
125 SNDRV_PCM_RATE_96000
,
131 .probe
= &asoc_qcom_lpass_cpu_dai_probe
,
132 .ops
= &asoc_qcom_lpass_cpu_dai_ops
,
136 static int apq8016_lpass_alloc_dma_channel(struct lpass_data
*drvdata
,
139 struct lpass_variant
*v
= drvdata
->variant
;
142 if (direction
== SNDRV_PCM_STREAM_PLAYBACK
) {
143 chan
= find_first_zero_bit(&drvdata
->dma_ch_bit_map
,
146 if (chan
>= v
->rdma_channels
)
149 chan
= find_next_zero_bit(&drvdata
->dma_ch_bit_map
,
150 v
->wrdma_channel_start
+
152 v
->wrdma_channel_start
);
154 if (chan
>= v
->wrdma_channel_start
+ v
->wrdma_channels
)
158 set_bit(chan
, &drvdata
->dma_ch_bit_map
);
163 static int apq8016_lpass_free_dma_channel(struct lpass_data
*drvdata
, int chan
)
165 clear_bit(chan
, &drvdata
->dma_ch_bit_map
);
170 static int apq8016_lpass_init(struct platform_device
*pdev
)
172 struct lpass_data
*drvdata
= platform_get_drvdata(pdev
);
173 struct device
*dev
= &pdev
->dev
;
176 drvdata
->pcnoc_mport_clk
= devm_clk_get(dev
, "pcnoc-mport-clk");
177 if (IS_ERR(drvdata
->pcnoc_mport_clk
)) {
178 dev_err(&pdev
->dev
, "error getting pcnoc-mport-clk: %ld\n",
179 PTR_ERR(drvdata
->pcnoc_mport_clk
));
180 return PTR_ERR(drvdata
->pcnoc_mport_clk
);
183 ret
= clk_prepare_enable(drvdata
->pcnoc_mport_clk
);
185 dev_err(&pdev
->dev
, "Error enabling pcnoc-mport-clk: %d\n",
190 drvdata
->pcnoc_sway_clk
= devm_clk_get(dev
, "pcnoc-sway-clk");
191 if (IS_ERR(drvdata
->pcnoc_sway_clk
)) {
192 dev_err(&pdev
->dev
, "error getting pcnoc-sway-clk: %ld\n",
193 PTR_ERR(drvdata
->pcnoc_sway_clk
));
194 return PTR_ERR(drvdata
->pcnoc_sway_clk
);
197 ret
= clk_prepare_enable(drvdata
->pcnoc_sway_clk
);
199 dev_err(&pdev
->dev
, "Error enabling pcnoc_sway_clk: %d\n", ret
);
206 static int apq8016_lpass_exit(struct platform_device
*pdev
)
208 struct lpass_data
*drvdata
= platform_get_drvdata(pdev
);
210 clk_disable_unprepare(drvdata
->pcnoc_mport_clk
);
211 clk_disable_unprepare(drvdata
->pcnoc_sway_clk
);
217 static struct lpass_variant apq8016_data
= {
218 .i2sctrl_reg_base
= 0x1000,
219 .i2sctrl_reg_stride
= 0x1000,
221 .irq_reg_base
= 0x6000,
222 .irq_reg_stride
= 0x1000,
224 .rdma_reg_base
= 0x8400,
225 .rdma_reg_stride
= 0x1000,
227 .dmactl_audif_start
= 1,
228 .wrdma_reg_base
= 0xB000,
229 .wrdma_reg_stride
= 0x1000,
230 .wrdma_channel_start
= 5,
232 .dai_driver
= apq8016_lpass_cpu_dai_driver
,
233 .num_dai
= ARRAY_SIZE(apq8016_lpass_cpu_dai_driver
),
234 .dai_osr_clk_names
= (const char *[]) {
240 .dai_bit_clk_names
= (const char *[]) {
246 .init
= apq8016_lpass_init
,
247 .exit
= apq8016_lpass_exit
,
248 .alloc_dma_channel
= apq8016_lpass_alloc_dma_channel
,
249 .free_dma_channel
= apq8016_lpass_free_dma_channel
,
252 static const struct of_device_id apq8016_lpass_cpu_device_id
[] = {
253 { .compatible
= "qcom,lpass-cpu-apq8016", .data
= &apq8016_data
},
256 MODULE_DEVICE_TABLE(of
, apq8016_lpass_cpu_device_id
);
258 static struct platform_driver apq8016_lpass_cpu_platform_driver
= {
260 .name
= "apq8016-lpass-cpu",
261 .of_match_table
= of_match_ptr(apq8016_lpass_cpu_device_id
),
263 .probe
= asoc_qcom_lpass_cpu_platform_probe
,
264 .remove
= asoc_qcom_lpass_cpu_platform_remove
,
266 module_platform_driver(apq8016_lpass_cpu_platform_driver
);
268 MODULE_DESCRIPTION("APQ8016 LPASS CPU Driver");
269 MODULE_LICENSE("GPL v2");