blob: f65f08beac31487248139e594f16d5f51381e08b [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>
Sergey Lapinb4df0a62009-05-08 19:19:41 +040033
34#include <asm/mach-types.h>
35#include <mach/hardware.h>
36#include <linux/gpio.h>
37
38#include "../codecs/tlv320aic23.h"
39#include "atmel-pcm.h"
40#include "atmel_ssc_dai.h"
41
42#define CODEC_CLOCK 12000000
43
44static int afeb9260_hw_params(struct snd_pcm_substream *substream,
45 struct snd_pcm_hw_params *params)
46{
47 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000048 struct snd_soc_dai *codec_dai = rtd->codec_dai;
Sergey Lapinb4df0a62009-05-08 19:19:41 +040049 int err;
50
Sergey Lapinb4df0a62009-05-08 19:19:41 +040051 /* Set the codec system clock for DAC and ADC */
52 err =
53 snd_soc_dai_set_sysclk(codec_dai, 0, CODEC_CLOCK, SND_SOC_CLOCK_IN);
54
55 if (err < 0) {
56 printk(KERN_ERR "can't set codec system clock\n");
57 return err;
58 }
59
60 return err;
61}
62
63static struct snd_soc_ops afeb9260_ops = {
64 .hw_params = afeb9260_hw_params,
65};
66
67static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = {
68 SND_SOC_DAPM_HP("Headphone Jack", NULL),
69 SND_SOC_DAPM_LINE("Line In", NULL),
70 SND_SOC_DAPM_MIC("Mic Jack", NULL),
71};
72
Axel Linbc6c1172012-01-29 16:52:51 +080073static const struct snd_soc_dapm_route afeb9260_audio_map[] = {
Sergey Lapinb4df0a62009-05-08 19:19:41 +040074 {"Headphone Jack", NULL, "LHPOUT"},
75 {"Headphone Jack", NULL, "RHPOUT"},
76
77 {"LLINEIN", NULL, "Line In"},
78 {"RLINEIN", NULL, "Line In"},
79
80 {"MICIN", NULL, "Mic Jack"},
81};
82
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000083static int afeb9260_tlv320aic23_init(struct snd_soc_pcm_runtime *rtd)
Sergey Lapinb4df0a62009-05-08 19:19:41 +040084{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000085 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +020086 struct snd_soc_dapm_context *dapm = &codec->dapm;
Sergey Lapinb4df0a62009-05-08 19:19:41 +040087
Liam Girdwoodce6120c2010-11-05 15:53:46 +020088 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
89 snd_soc_dapm_enable_pin(dapm, "Line In");
90 snd_soc_dapm_enable_pin(dapm, "Mic Jack");
Sergey Lapinb4df0a62009-05-08 19:19:41 +040091
Sergey Lapinb4df0a62009-05-08 19:19:41 +040092 return 0;
93}
94
95/* Digital audio interface glue - connects codec <--> CPU */
96static struct snd_soc_dai_link afeb9260_dai = {
97 .name = "TLV320AIC23",
98 .stream_name = "AIC23",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000099 .cpu_dai_name = "atmel-ssc-dai.0",
100 .codec_dai_name = "tlv320aic23-hifi",
101 .platform_name = "atmel_pcm-audio",
Lars-Peter Clausen81d7da52011-01-24 22:09:22 +0100102 .codec_name = "tlv320aic23-codec.0-001a",
Sergey Lapinb4df0a62009-05-08 19:19:41 +0400103 .init = afeb9260_tlv320aic23_init,
Axel Lin5813db92012-01-29 16:52:02 +0800104 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_IF |
105 SND_SOC_DAIFMT_CBM_CFM,
Sergey Lapinb4df0a62009-05-08 19:19:41 +0400106 .ops = &afeb9260_ops,
107};
108
109/* Audio machine driver */
110static struct snd_soc_card snd_soc_machine_afeb9260 = {
111 .name = "AFEB9260",
Axel Lin338d68d2011-12-22 21:14:58 +0800112 .owner = THIS_MODULE,
Sergey Lapinb4df0a62009-05-08 19:19:41 +0400113 .dai_link = &afeb9260_dai,
114 .num_links = 1,
Axel Linbc6c1172012-01-29 16:52:51 +0800115
116 .dapm_widgets = tlv320aic23_dapm_widgets,
117 .num_dapm_widgets = ARRAY_SIZE(tlv320aic23_dapm_widgets),
118 .dapm_routes = afeb9260_audio_map,
119 .num_dapm_routes = ARRAY_SIZE(afeb9260_audio_map),
Sergey Lapinb4df0a62009-05-08 19:19:41 +0400120};
121
Sergey Lapinb4df0a62009-05-08 19:19:41 +0400122static struct platform_device *afeb9260_snd_device;
123
124static int __init afeb9260_soc_init(void)
125{
126 int err;
127 struct device *dev;
Sergey Lapinb4df0a62009-05-08 19:19:41 +0400128
129 if (!(machine_is_afeb9260()))
130 return -ENODEV;
131
Sergey Lapinb4df0a62009-05-08 19:19:41 +0400132
133 afeb9260_snd_device = platform_device_alloc("soc-audio", -1);
134 if (!afeb9260_snd_device) {
135 printk(KERN_ERR "ASoC: Platform device allocation failed\n");
136 return -ENOMEM;
137 }
138
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000139 platform_set_drvdata(afeb9260_snd_device, &snd_soc_machine_afeb9260);
Sergey Lapinb4df0a62009-05-08 19:19:41 +0400140 err = platform_device_add(afeb9260_snd_device);
141 if (err)
142 goto err1;
143
144 dev = &afeb9260_snd_device->dev;
145
146 return 0;
147err1:
Sergey Lapinb4df0a62009-05-08 19:19:41 +0400148 platform_device_put(afeb9260_snd_device);
Sergey Lapinb4df0a62009-05-08 19:19:41 +0400149 return err;
Sergey Lapinb4df0a62009-05-08 19:19:41 +0400150}
151
152static void __exit afeb9260_soc_exit(void)
153{
154 platform_device_unregister(afeb9260_snd_device);
155}
156
157module_init(afeb9260_soc_init);
158module_exit(afeb9260_soc_exit);
159
160MODULE_AUTHOR("Sergey Lapin <slapin@ossfans.org>");
161MODULE_DESCRIPTION("ALSA SoC for AFEB9260");
162MODULE_LICENSE("GPL");
163