smdk_wm8580.c 5.0 KB
Newer Older
1
/*
2
 *  smdk_wm8580.c
3 4
 *
 *  Copyright (c) 2009 Samsung Electronics Co. Ltd
5
 *  Author: Jaswinder Singh <jassisinghbrar@gmail.com>
6 7 8 9 10 11 12
 *
 *  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.
 */

13
#include <linux/module.h>
14
#include <sound/soc.h>
15
#include <sound/pcm_params.h>
16 17

#include "../codecs/wm8580.h"
18
#include "i2s.h"
19

20 21 22 23 24 25
/*
 * Default CFG switch settings to use this driver:
 *
 *   SMDK6410: Set CFG1 1-3 Off, CFG2 1-4 On
 */

26 27
/* SMDK has a 12MHZ crystal attached to WM8580 */
#define SMDK_WM8580_FREQ 12000000
28

29
static int smdk_hw_params(struct snd_pcm_substream *substream,
30 31 32
	struct snd_pcm_hw_params *params)
{
	struct snd_soc_pcm_runtime *rtd = substream->private_data;
33
	struct snd_soc_dai *codec_dai = rtd->codec_dai;
34 35 36
	unsigned int pll_out;
	int bfs, rfs, ret;

37 38
	switch (params_width(params)) {
	case 8:
39 40
		bfs = 16;
		break;
41
	case 16:
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
		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;

M
Mark Brown 已提交
77
	/* Set WM8580 to drive MCLK from its PLLA */
78 79 80 81 82
	ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_MCLK,
					WM8580_CLKSRC_PLLA);
	if (ret < 0)
		return ret;

83
	ret = snd_soc_dai_set_pll(codec_dai, WM8580_PLLA, 0,
84
					SMDK_WM8580_FREQ, pll_out);
85 86 87
	if (ret < 0)
		return ret;

88 89
	ret = snd_soc_dai_set_sysclk(codec_dai, WM8580_CLKSRC_PLLA,
				     pll_out, SND_SOC_CLOCK_IN);
90 91 92 93 94 95 96
	if (ret < 0)
		return ret;

	return 0;
}

/*
97
 * SMDK WM8580 DAI operations.
98
 */
99 100
static struct snd_soc_ops smdk_ops = {
	.hw_params = smdk_hw_params,
101 102
};

103
/* SMDK Playback widgets */
104
static const struct snd_soc_dapm_widget smdk_wm8580_dapm_widgets[] = {
105 106 107
	SND_SOC_DAPM_HP("Front", NULL),
	SND_SOC_DAPM_HP("Center+Sub", NULL),
	SND_SOC_DAPM_HP("Rear", NULL),
108 109 110 111 112 113

	SND_SOC_DAPM_MIC("MicIn", NULL),
	SND_SOC_DAPM_LINE("LineIn", NULL),
};

/* SMDK-PAIFTX connections */
114
static const struct snd_soc_dapm_route smdk_wm8580_audio_map[] = {
115 116 117 118 119 120 121 122
	/* MicIn feeds AINL */
	{"AINL", NULL, "MicIn"},

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

	/* Front Left/Right are fed VOUT1L/R */
123 124
	{"Front", NULL, "VOUT1L"},
	{"Front", NULL, "VOUT1R"},
125 126

	/* Center/Sub are fed VOUT2L/R */
127 128
	{"Center+Sub", NULL, "VOUT2L"},
	{"Center+Sub", NULL, "VOUT2R"},
129 130

	/* Rear Left/Right are fed VOUT3L/R */
131 132
	{"Rear", NULL, "VOUT3L"},
	{"Rear", NULL, "VOUT3R"},
133 134
};

135
static int smdk_wm8580_init_paiftx(struct snd_soc_pcm_runtime *rtd)
136
{
M
Mark Brown 已提交
137 138 139
	/* Enabling the microphone requires the fitting of a 0R
	 * resistor to connect the line from the microphone jack.
	 */
140
	snd_soc_dapm_disable_pin(&rtd->card->dapm, "MicIn");
141 142 143 144

	return 0;
}

145 146 147 148 149
enum {
	PRI_PLAYBACK = 0,
	PRI_CAPTURE,
};

150 151 152
#define SMDK_DAI_FMT (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | \
	SND_SOC_DAIFMT_CBM_CFM)

153
static struct snd_soc_dai_link smdk_dai[] = {
154 155 156
	[PRI_PLAYBACK] = { /* Primary Playback i/f */
		.name = "WM8580 PAIF RX",
		.stream_name = "Playback",
157
		.cpu_dai_name = "samsung-i2s.2",
158
		.codec_dai_name = "wm8580-hifi-playback",
159
		.platform_name = "samsung-i2s.0",
160
		.codec_name = "wm8580.0-001b",
161
		.dai_fmt = SMDK_DAI_FMT,
162 163 164 165 166
		.ops = &smdk_ops,
	},
	[PRI_CAPTURE] = { /* Primary Capture i/f */
		.name = "WM8580 PAIF TX",
		.stream_name = "Capture",
167
		.cpu_dai_name = "samsung-i2s.2",
168
		.codec_dai_name = "wm8580-hifi-capture",
169
		.platform_name = "samsung-i2s.0",
170
		.codec_name = "wm8580.0-001b",
171
		.dai_fmt = SMDK_DAI_FMT,
172 173 174
		.init = smdk_wm8580_init_paiftx,
		.ops = &smdk_ops,
	},
175 176
};

177 178
static struct snd_soc_card smdk = {
	.name = "SMDK-I2S",
179
	.owner = THIS_MODULE,
180
	.dai_link = smdk_dai,
181
	.num_links = ARRAY_SIZE(smdk_dai),
182 183 184 185 186

	.dapm_widgets = smdk_wm8580_dapm_widgets,
	.num_dapm_widgets = ARRAY_SIZE(smdk_wm8580_dapm_widgets),
	.dapm_routes = smdk_wm8580_audio_map,
	.num_dapm_routes = ARRAY_SIZE(smdk_wm8580_audio_map),
187 188
};

189
static struct platform_device *smdk_snd_device;
190

191
static int __init smdk_audio_init(void)
192 193 194
{
	int ret;

195 196
	smdk_snd_device = platform_device_alloc("soc-audio", -1);
	if (!smdk_snd_device)
197 198
		return -ENOMEM;

199 200
	platform_set_drvdata(smdk_snd_device, &smdk);
	ret = platform_device_add(smdk_snd_device);
201 202

	if (ret)
203
		platform_device_put(smdk_snd_device);
204 205 206

	return ret;
}
207
module_init(smdk_audio_init);
208

209 210 211 212 213 214
static void __exit smdk_audio_exit(void)
{
	platform_device_unregister(smdk_snd_device);
}
module_exit(smdk_audio_exit);

215
MODULE_AUTHOR("Jaswinder Singh, jassisinghbrar@gmail.com");
216
MODULE_DESCRIPTION("ALSA SoC SMDK WM8580");
217
MODULE_LICENSE("GPL");