blob: 92c709ed09656bd3114a5fa020611a5db99a0232 [file] [log] [blame]
Sergey Lapinb4df0a62009-05-08 19:19:41 +04001/*
2 * afeb9260.c -- SoC audio for AFEB9260
3 *
4 * Copyright (C) 2009 Sergey Lapin <slapin@ossfans.org>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * 02110-1301 USA
19 *
20 */
21
22#include <linux/module.h>
23#include <linux/moduleparam.h>
24#include <linux/kernel.h>
25#include <linux/clk.h>
26#include <linux/platform_device.h>
27
28#include <linux/atmel-ssc.h>
29#include <sound/core.h>
30#include <sound/pcm.h>
31#include <sound/pcm_params.h>
32#include <sound/soc.h>
33#include <sound/soc-dapm.h>
34
35#include <asm/mach-types.h>
36#include <mach/hardware.h>
37#include <linux/gpio.h>
38
39#include "../codecs/tlv320aic23.h"
40#include "atmel-pcm.h"
41#include "atmel_ssc_dai.h"
42
43#define CODEC_CLOCK 12000000
44
45static int afeb9260_hw_params(struct snd_pcm_substream *substream,
46 struct snd_pcm_hw_params *params)
47{
48 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000049 struct snd_soc_dai *codec_dai = rtd->codec_dai;
50 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Sergey Lapinb4df0a62009-05-08 19:19:41 +040051 int err;
52
53 /* Set codec DAI configuration */
54 err = snd_soc_dai_set_fmt(codec_dai,
55 SND_SOC_DAIFMT_I2S|
56 SND_SOC_DAIFMT_NB_IF |
57 SND_SOC_DAIFMT_CBM_CFM);
58 if (err < 0) {
59 printk(KERN_ERR "can't set codec DAI configuration\n");
60 return err;
61 }
62
63 /* Set cpu DAI configuration */
64 err = snd_soc_dai_set_fmt(cpu_dai,
65 SND_SOC_DAIFMT_I2S |
66 SND_SOC_DAIFMT_NB_IF |
67 SND_SOC_DAIFMT_CBM_CFM);
68 if (err < 0) {
69 printk(KERN_ERR "can't set cpu DAI configuration\n");
70 return err;
71 }
72
73 /* Set the codec system clock for DAC and ADC */
74 err =
75 snd_soc_dai_set_sysclk(codec_dai, 0, CODEC_CLOCK, SND_SOC_CLOCK_IN);
76
77 if (err < 0) {
78 printk(KERN_ERR "can't set codec system clock\n");
79 return err;
80 }
81
82 return err;
83}
84
85static struct snd_soc_ops afeb9260_ops = {
86 .hw_params = afeb9260_hw_params,
87};
88
89static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = {
90 SND_SOC_DAPM_HP("Headphone Jack", NULL),
91 SND_SOC_DAPM_LINE("Line In", NULL),
92 SND_SOC_DAPM_MIC("Mic Jack", NULL),
93};
94
95static const struct snd_soc_dapm_route audio_map[] = {
96 {"Headphone Jack", NULL, "LHPOUT"},
97 {"Headphone Jack", NULL, "RHPOUT"},
98
99 {"LLINEIN", NULL, "Line In"},
100 {"RLINEIN", NULL, "Line In"},
101
102 {"MICIN", NULL, "Mic Jack"},
103};
104
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000105static int afeb9260_tlv320aic23_init(struct snd_soc_pcm_runtime *rtd)
Sergey Lapinb4df0a62009-05-08 19:19:41 +0400106{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000107 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200108 struct snd_soc_dapm_context *dapm = &codec->dapm;
Sergey Lapinb4df0a62009-05-08 19:19:41 +0400109
110 /* Add afeb9260 specific widgets */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200111 snd_soc_dapm_new_controls(dapm, tlv320aic23_dapm_widgets,
Sergey Lapinb4df0a62009-05-08 19:19:41 +0400112 ARRAY_SIZE(tlv320aic23_dapm_widgets));
113
114 /* Set up afeb9260 specific audio path audio_map */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200115 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
Sergey Lapinb4df0a62009-05-08 19:19:41 +0400116
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200117 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
118 snd_soc_dapm_enable_pin(dapm, "Line In");
119 snd_soc_dapm_enable_pin(dapm, "Mic Jack");
Sergey Lapinb4df0a62009-05-08 19:19:41 +0400120
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200121 snd_soc_dapm_sync(dapm);
Sergey Lapinb4df0a62009-05-08 19:19:41 +0400122
123 return 0;
124}
125
126/* Digital audio interface glue - connects codec <--> CPU */
127static struct snd_soc_dai_link afeb9260_dai = {
128 .name = "TLV320AIC23",
129 .stream_name = "AIC23",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000130 .cpu_dai_name = "atmel-ssc-dai.0",
131 .codec_dai_name = "tlv320aic23-hifi",
132 .platform_name = "atmel_pcm-audio",
133 .codec_name = "tlv320aic23-codec.0-0x1a",
Sergey Lapinb4df0a62009-05-08 19:19:41 +0400134 .init = afeb9260_tlv320aic23_init,
135 .ops = &afeb9260_ops,
136};
137
138/* Audio machine driver */
139static struct snd_soc_card snd_soc_machine_afeb9260 = {
140 .name = "AFEB9260",
Sergey Lapinb4df0a62009-05-08 19:19:41 +0400141 .dai_link = &afeb9260_dai,
142 .num_links = 1,
143};
144
Sergey Lapinb4df0a62009-05-08 19:19:41 +0400145static struct platform_device *afeb9260_snd_device;
146
147static int __init afeb9260_soc_init(void)
148{
149 int err;
150 struct device *dev;
Sergey Lapinb4df0a62009-05-08 19:19:41 +0400151
152 if (!(machine_is_afeb9260()))
153 return -ENODEV;
154
Sergey Lapinb4df0a62009-05-08 19:19:41 +0400155
156 afeb9260_snd_device = platform_device_alloc("soc-audio", -1);
157 if (!afeb9260_snd_device) {
158 printk(KERN_ERR "ASoC: Platform device allocation failed\n");
159 return -ENOMEM;
160 }
161
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000162 platform_set_drvdata(afeb9260_snd_device, &snd_soc_machine_afeb9260);
Sergey Lapinb4df0a62009-05-08 19:19:41 +0400163 err = platform_device_add(afeb9260_snd_device);
164 if (err)
165 goto err1;
166
167 dev = &afeb9260_snd_device->dev;
168
169 return 0;
170err1:
171 platform_device_del(afeb9260_snd_device);
172 platform_device_put(afeb9260_snd_device);
Sergey Lapinb4df0a62009-05-08 19:19:41 +0400173 return err;
Sergey Lapinb4df0a62009-05-08 19:19:41 +0400174}
175
176static void __exit afeb9260_soc_exit(void)
177{
178 platform_device_unregister(afeb9260_snd_device);
179}
180
181module_init(afeb9260_soc_init);
182module_exit(afeb9260_soc_exit);
183
184MODULE_AUTHOR("Sergey Lapin <slapin@ossfans.org>");
185MODULE_DESCRIPTION("ALSA SoC for AFEB9260");
186MODULE_LICENSE("GPL");
187