smdk_wm8580.c 7.1 KB
Newer Older
1
/*
2
 *  smdk_wm8580.c
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 *  Copyright (c) 2009 Samsung Electronics Co. Ltd
 *  Author: Jaswinder Singh <jassi.brar@samsung.com>
 *
 *  This program is free software; you can redistribute  it and/or modify it
 *  under  the terms of  the GNU General  Public License as published by the
 *  Free Software Foundation;  either version 2 of the  License, or (at your
 *  option) any later version.
 */

#include <linux/platform_device.h>
#include <linux/clk.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>

20 21
#include <asm/mach-types.h>

22
#include "../codecs/wm8580.h"
J
Jassi Brar 已提交
23
#include "dma.h"
24
#include "i2s.h"
25

26 27 28 29 30 31
/*
 * Default CFG switch settings to use this driver:
 *
 *   SMDK6410: Set CFG1 1-3 Off, CFG2 1-4 On
 */

32 33
/* SMDK has a 12MHZ crystal attached to WM8580 */
#define SMDK_WM8580_FREQ 12000000
34

35
static int smdk_hw_params(struct snd_pcm_substream *substream,
36 37 38
	struct snd_pcm_hw_params *params)
{
	struct snd_soc_pcm_runtime *rtd = substream->private_data;
39 40
	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
	struct snd_soc_dai *codec_dai = rtd->codec_dai;
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
	unsigned int pll_out;
	int bfs, rfs, ret;

	switch (params_format(params)) {
	case SNDRV_PCM_FORMAT_U8:
	case SNDRV_PCM_FORMAT_S8:
		bfs = 16;
		break;
	case SNDRV_PCM_FORMAT_U16_LE:
	case SNDRV_PCM_FORMAT_S16_LE:
		bfs = 32;
		break;
	default:
		return -EINVAL;
	}

	/* The Fvco for WM8580 PLLs must fall within [90,100]MHz.
	 * This criterion can't be met if we request PLL output
	 * as {8000x256, 64000x256, 11025x256}Hz.
	 * As a wayout, we rather change rfs to a minimum value that
	 * results in (params_rate(params) * rfs), and itself, acceptable
	 * to both - the CODEC and the CPU.
	 */
	switch (params_rate(params)) {
	case 16000:
	case 22050:
	case 32000:
	case 44100:
	case 48000:
	case 88200:
	case 96000:
		rfs = 256;
		break;
	case 64000:
		rfs = 384;
		break;
	case 8000:
	case 11025:
		rfs = 512;
		break;
	default:
		return -EINVAL;
	}
	pll_out = params_rate(params) * rfs;

	/* Set the Codec DAI configuration */
	ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
					 | SND_SOC_DAIFMT_NB_NF
					 | SND_SOC_DAIFMT_CBM_CFM);
	if (ret < 0)
		return ret;

	/* Set the AP DAI configuration */
	ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
					 | SND_SOC_DAIFMT_NB_NF
					 | SND_SOC_DAIFMT_CBM_CFM);
	if (ret < 0)
		return ret;

M
Mark Brown 已提交
100
	/* Set WM8580 to drive MCLK from its PLLA */
101 102 103 104 105
	ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_MCLK,
					WM8580_CLKSRC_PLLA);
	if (ret < 0)
		return ret;

106
	ret = snd_soc_dai_set_pll(codec_dai, WM8580_PLLA, 0,
107
					SMDK_WM8580_FREQ, pll_out);
108 109 110
	if (ret < 0)
		return ret;

111 112
	ret = snd_soc_dai_set_sysclk(codec_dai, WM8580_CLKSRC_PLLA,
				     pll_out, SND_SOC_CLOCK_IN);
113 114 115 116 117 118 119
	if (ret < 0)
		return ret;

	return 0;
}

/*
120
 * SMDK WM8580 DAI operations.
121
 */
122 123
static struct snd_soc_ops smdk_ops = {
	.hw_params = smdk_hw_params,
124 125
};

126
/* SMDK Playback widgets */
127
static const struct snd_soc_dapm_widget wm8580_dapm_widgets_pbk[] = {
128 129 130
	SND_SOC_DAPM_HP("Front", NULL),
	SND_SOC_DAPM_HP("Center+Sub", NULL),
	SND_SOC_DAPM_HP("Rear", NULL),
131 132
};

133
/* SMDK Capture widgets */
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
static const struct snd_soc_dapm_widget wm8580_dapm_widgets_cpt[] = {
	SND_SOC_DAPM_MIC("MicIn", NULL),
	SND_SOC_DAPM_LINE("LineIn", NULL),
};

/* SMDK-PAIFTX connections */
static const struct snd_soc_dapm_route audio_map_tx[] = {
	/* MicIn feeds AINL */
	{"AINL", NULL, "MicIn"},

	/* LineIn feeds AINL/R */
	{"AINL", NULL, "LineIn"},
	{"AINR", NULL, "LineIn"},
};

/* SMDK-PAIFRX connections */
static const struct snd_soc_dapm_route audio_map_rx[] = {
	/* Front Left/Right are fed VOUT1L/R */
152 153
	{"Front", NULL, "VOUT1L"},
	{"Front", NULL, "VOUT1R"},
154 155

	/* Center/Sub are fed VOUT2L/R */
156 157
	{"Center+Sub", NULL, "VOUT2L"},
	{"Center+Sub", NULL, "VOUT2R"},
158 159

	/* Rear Left/Right are fed VOUT3L/R */
160 161
	{"Rear", NULL, "VOUT3L"},
	{"Rear", NULL, "VOUT3R"},
162 163
};

164
static int smdk_wm8580_init_paiftx(struct snd_soc_pcm_runtime *rtd)
165
{
166
	struct snd_soc_codec *codec = rtd->codec;
L
Liam Girdwood 已提交
167
	struct snd_soc_dapm_context *dapm = &codec->dapm;
168

169
	/* Add smdk specific Capture widgets */
L
Liam Girdwood 已提交
170
	snd_soc_dapm_new_controls(dapm, wm8580_dapm_widgets_cpt,
171 172 173
				  ARRAY_SIZE(wm8580_dapm_widgets_cpt));

	/* Set up PAIFTX audio path */
L
Liam Girdwood 已提交
174
	snd_soc_dapm_add_routes(dapm, audio_map_tx, ARRAY_SIZE(audio_map_tx));
175

M
Mark Brown 已提交
176 177 178
	/* Enabling the microphone requires the fitting of a 0R
	 * resistor to connect the line from the microphone jack.
	 */
L
Liam Girdwood 已提交
179
	snd_soc_dapm_disable_pin(dapm, "MicIn");
180 181

	/* signal a DAPM event */
L
Liam Girdwood 已提交
182
	snd_soc_dapm_sync(dapm);
183 184 185 186

	return 0;
}

187
static int smdk_wm8580_init_paifrx(struct snd_soc_pcm_runtime *rtd)
188
{
189
	struct snd_soc_codec *codec = rtd->codec;
L
Liam Girdwood 已提交
190
	struct snd_soc_dapm_context *dapm = &codec->dapm;
191

192
	/* Add smdk specific Playback widgets */
L
Liam Girdwood 已提交
193
	snd_soc_dapm_new_controls(dapm, wm8580_dapm_widgets_pbk,
194 195 196
				  ARRAY_SIZE(wm8580_dapm_widgets_pbk));

	/* Set up PAIFRX audio path */
L
Liam Girdwood 已提交
197
	snd_soc_dapm_add_routes(dapm, audio_map_rx, ARRAY_SIZE(audio_map_rx));
198 199

	/* signal a DAPM event */
L
Liam Girdwood 已提交
200
	snd_soc_dapm_sync(dapm);
201 202 203 204

	return 0;
}

205 206 207 208 209 210
enum {
	PRI_PLAYBACK = 0,
	PRI_CAPTURE,
	SEC_PLAYBACK,
};

211
static struct snd_soc_dai_link smdk_dai[] = {
212 213 214
	[PRI_PLAYBACK] = { /* Primary Playback i/f */
		.name = "WM8580 PAIF RX",
		.stream_name = "Playback",
215
		.cpu_dai_name = "samsung-i2s.0",
216 217 218 219 220 221 222 223 224
		.codec_dai_name = "wm8580-hifi-playback",
		.platform_name = "samsung-audio",
		.codec_name = "wm8580-codec.0-001b",
		.init = smdk_wm8580_init_paifrx,
		.ops = &smdk_ops,
	},
	[PRI_CAPTURE] = { /* Primary Capture i/f */
		.name = "WM8580 PAIF TX",
		.stream_name = "Capture",
225
		.cpu_dai_name = "samsung-i2s.0",
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
		.codec_dai_name = "wm8580-hifi-capture",
		.platform_name = "samsung-audio",
		.codec_name = "wm8580-codec.0-001b",
		.init = smdk_wm8580_init_paiftx,
		.ops = &smdk_ops,
	},
	[SEC_PLAYBACK] = { /* Sec_Fifo Playback i/f */
		.name = "Sec_FIFO TX",
		.stream_name = "Playback",
		.cpu_dai_name = "samsung-i2s.x",
		.codec_dai_name = "wm8580-hifi-playback",
		.platform_name = "samsung-audio",
		.codec_name = "wm8580-codec.0-001b",
		.init = smdk_wm8580_init_paifrx,
		.ops = &smdk_ops,
	},
242 243
};

244 245 246
static struct snd_soc_card smdk = {
	.name = "SMDK-I2S",
	.dai_link = smdk_dai,
247
	.num_links = 2,
248 249
};

250
static struct platform_device *smdk_snd_device;
251

252
static int __init smdk_audio_init(void)
253 254
{
	int ret;
255 256
	char *str;

J
Jassi Brar 已提交
257
	if (machine_is_smdkc100() || machine_is_smdk6442()
J
Jassi Brar 已提交
258
			|| machine_is_smdkv210() || machine_is_smdkc110()) {
259 260 261 262
		smdk.num_links = 3;
		/* Secondary is at offset SAMSUNG_I2S_SECOFF from Primary */
		str = (char *)smdk_dai[SEC_PLAYBACK].cpu_dai_name;
		str[strlen(str) - 1] = '0' + SAMSUNG_I2S_SECOFF;
263 264 265 266 267
	} else if (machine_is_smdk6410()) {
		str = (char *)smdk_dai[PRI_PLAYBACK].cpu_dai_name;
		str[strlen(str) - 1] = '2';
		str = (char *)smdk_dai[PRI_CAPTURE].cpu_dai_name;
		str[strlen(str) - 1] = '2';
268
	}
269

270 271
	smdk_snd_device = platform_device_alloc("soc-audio", -1);
	if (!smdk_snd_device)
272 273
		return -ENOMEM;

274 275
	platform_set_drvdata(smdk_snd_device, &smdk);
	ret = platform_device_add(smdk_snd_device);
276 277

	if (ret)
278
		platform_device_put(smdk_snd_device);
279 280 281

	return ret;
}
282
module_init(smdk_audio_init);
283

284 285 286 287 288 289
static void __exit smdk_audio_exit(void)
{
	platform_device_unregister(smdk_snd_device);
}
module_exit(smdk_audio_exit);

290
MODULE_AUTHOR("Jaswinder Singh, jassi.brar@samsung.com");
291
MODULE_DESCRIPTION("ALSA SoC SMDK WM8580");
292
MODULE_LICENSE("GPL");