summaryrefslogtreecommitdiff
path: root/sound/soc/ux500/ux500_cg29xx.c
blob: 456262c6c0b7fa818b988895fbe7bdb867b877f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/*
 * Copyright (C) ST-Ericsson SA 2010
 *
 * Author: Ola Lilja <ola.o.lilja@stericsson.com>,
 *         Roger Nilsson <roger.xr.nilsson@stericsson.com>
 *         for ST-Ericsson.
 *
 * License terms:
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as published
 * by the Free Software Foundation.
 */

#include <sound/soc.h>
#include "../codecs/cg29xx.h"
#include "ux500_msp_dai.h"

#define UX500_CG29XX_MSP_CLOCK_FREQ	18900000
#define U5500_CG29XX_MSP_CLOCK_FREQ 13000000
#define UX500_CG29XX_DAI_SLOT_WIDTH	16
#define UX500_CG29XX_DAI_SLOTS	2
#define UX500_CG29XX_DAI_ACTIVE_SLOTS	0x02

int ux500_cg29xx_hw_params(struct snd_pcm_substream *substream,
			struct snd_pcm_hw_params *params)
{
	struct snd_soc_pcm_runtime *rtd = substream->private_data;
	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
	struct snd_soc_dai *codec_dai = rtd->codec_dai;
	int channels = params_channels(params);
	int err;

	pr_debug("%s: Enter.\n", __func__);
	pr_debug("%s: substream->pcm->name = %s.\n", __func__, substream->pcm->name);
	pr_debug("%s: substream->pcm->id = %s.\n", __func__, substream->pcm->id);
	pr_debug("%s: substream->name = %s.\n", __func__, substream->name);
	pr_debug("%s: substream->number = %d.\n", __func__, substream->number);
	pr_debug("%s: channels = %d.\n", __func__, channels);
	pr_debug("%s: DAI-index (Codec): %d\n", __func__, codec_dai->id);
	pr_debug("%s: DAI-index (Platform): %d\n", __func__, cpu_dai->id);

	err = snd_soc_dai_set_fmt(codec_dai,
				SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBS_CFS);

	if (err) {
		pr_err("%s: snd_soc_dai_set_fmt(codec) failed with %d.\n",
			__func__,
			err);
		goto out_err;
	}

	err = snd_soc_dai_set_tdm_slot(codec_dai,
				1 << CG29XX_DAI_SLOT0_SHIFT,
				1 << CG29XX_DAI_SLOT0_SHIFT,
				UX500_CG29XX_DAI_SLOTS,
				UX500_CG29XX_DAI_SLOT_WIDTH);

	if (err) {
		pr_err("%s: cg29xx_set_tdm_slot(codec_dai) failed with %d.\n",
				__func__,
				err);
		goto out_err;
	}

	err = snd_soc_dai_set_fmt(cpu_dai,
				SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBS_CFS |
				SND_SOC_DAIFMT_NB_NF);

	if (err) {
		pr_err("%s: snd_soc_dai_set_fmt(cpu_dai) failed with %d.\n",
			__func__,
			err);
		goto out_err;
	}

	err = snd_soc_dai_set_sysclk(cpu_dai,
		UX500_MSP_MASTER_CLOCK,
		UX500_CG29XX_MSP_CLOCK_FREQ,
		0);

	if (err) {
		pr_err("%s: snd_soc_dai_set_sysclk(cpu_dai) failed with %d.\n",
			__func__,
			err);
		goto out_err;
	}

	err = snd_soc_dai_set_tdm_slot(cpu_dai,
				UX500_CG29XX_DAI_ACTIVE_SLOTS,
				UX500_CG29XX_DAI_ACTIVE_SLOTS,
				UX500_CG29XX_DAI_SLOTS,
				UX500_CG29XX_DAI_SLOT_WIDTH);

	if (err) {
		pr_err("%s: cg29xx_set_tdm_slot(cpu_dai) failed with %d.\n",
			__func__,
			err);
		goto out_err;
	}

out_err:
	return err;
}

int u5500_cg29xx_hw_params(struct snd_pcm_substream *substream,
			struct snd_pcm_hw_params *params)

{
	struct snd_soc_pcm_runtime *rtd = substream->private_data;
	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
	struct snd_soc_dai *codec_dai = rtd->codec_dai;
	int channels = params_channels(params);
	int err;
	struct snd_soc_codec *codec = codec_dai->codec;
	int dai_id = codec_dai->id;
	struct cg29xx_codec_dai_data *codec_drvdata =
				snd_soc_codec_get_drvdata(codec);
	struct cg29xx_codec_dai_data *dai_data = &codec_drvdata[dai_id];

	pr_debug("%s: Enter.\n", __func__);
	pr_debug("%s: substream->pcm->name=%s\n",
						__func__, substream->pcm->name);
	pr_debug("%s: substream->pcm->id = %s\n", __func__, substream->pcm->id);
	pr_debug("%s: substream->name = %s.\n", __func__, substream->name);
	pr_debug("%s: substream->number = %d.\n", __func__, substream->number);
	pr_debug("%s: channels = %d.\n", __func__, channels);
	pr_debug("%s: DAI-index (Codec): %d\n", __func__, codec_dai->id);
	pr_debug("%s: DAI-index (Platform): %d\n", __func__, cpu_dai->id);

	if (dai_data->config.port == PORT_0_I2S) {
		err = snd_soc_dai_set_fmt(codec_dai,
				SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS);
		if (err) {
			pr_err("%s: snd_soc_dai_set_fmt (codec) failed with %d.\n",
				__func__,
				err);
			goto out_err;
		}

		err = snd_soc_dai_set_fmt(cpu_dai,
			SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS);

		if (err) {
			pr_err("%s: snd_soc_dai_set_sysclk(cpu_dai) failed with %d.\n",
				__func__,
				err);
			goto out_err;
		}
	}	else {
		err = snd_soc_dai_set_fmt(codec_dai,
			SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBS_CFS);
		if (err) {
			pr_err("%s: snd_soc_dai_set_fmt(codec) failed with %d.\n",
				__func__,
				err);
			goto out_err;
			}

		err = snd_soc_dai_set_tdm_slot(codec_dai,
					1 << CG29XX_DAI_SLOT0_SHIFT,
					1 << CG29XX_DAI_SLOT0_SHIFT,
					UX500_CG29XX_DAI_SLOTS,
					UX500_CG29XX_DAI_SLOT_WIDTH);

		if (err) {
			pr_err("%s: cg29xx_set_tdm_slot(codec_dai) failed with %d.\n",
					__func__,
					err);
			goto out_err;
		}

		err = snd_soc_dai_set_fmt(cpu_dai,
					SND_SOC_DAIFMT_DSP_B |
					SND_SOC_DAIFMT_CBS_CFS |
					SND_SOC_DAIFMT_NB_NF);

		if (err) {
			pr_err("%s: snd_soc_dai_set_fmt(cpu_dai) failed with %d.\n",
				__func__,
				err);
			goto out_err;
		}

		err = snd_soc_dai_set_sysclk(cpu_dai,
			UX500_MSP_MASTER_CLOCK,
			U5500_CG29XX_MSP_CLOCK_FREQ,
			0);

		if (err) {
			pr_err("%s: snd_soc_dai_set_sysclk(cpu_dai) failed with %d.\n",
				__func__,
				err);
			goto out_err;
		}

		err = snd_soc_dai_set_tdm_slot(cpu_dai,
					UX500_CG29XX_DAI_ACTIVE_SLOTS,
					UX500_CG29XX_DAI_ACTIVE_SLOTS,
					UX500_CG29XX_DAI_SLOTS,
					UX500_CG29XX_DAI_SLOT_WIDTH);

		if (err) {
			pr_err("%s: cg29xx_set_tdm_slot(cpu_dai) failed with %d.\n",
				__func__,
				err);
			goto out_err;
		}

	}
	ux500_msp_dai_set_data_delay(cpu_dai, MSP_DELAY_0);
out_err:
	return err;
}

struct snd_soc_ops ux500_cg29xx_ops[] = {
	{
		.hw_params = ux500_cg29xx_hw_params,
	}
};

struct snd_soc_ops u5500_cg29xx_ops[] = {
	{
		.hw_params = u5500_cg29xx_hw_params,
	}
};