blob: f74ac54c285a8a2c7598c336b988f85612f83365 [file] [log] [blame]
Ryan Mallon315f7da2010-06-08 22:01:12 +12001/*
2 * snappercl15.c -- SoC audio for Bluewater Systems Snapper CL15 module
3 *
4 * Copyright (C) 2008 Bluewater Systems Ltd
Ryan Mallon1c5454e2011-06-15 14:45:36 +10005 * Author: Ryan Mallon
Ryan Mallon315f7da2010-06-08 22:01:12 +12006 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 */
13
14#include <linux/platform_device.h>
15#include <sound/core.h>
16#include <sound/pcm.h>
17#include <sound/soc.h>
Ryan Mallon315f7da2010-06-08 22:01:12 +120018
19#include <asm/mach-types.h>
20#include <mach/hardware.h>
21
22#include "../codecs/tlv320aic23.h"
23#include "ep93xx-pcm.h"
Ryan Mallon315f7da2010-06-08 22:01:12 +120024
25#define CODEC_CLOCK 5644800
26
27static int snappercl15_hw_params(struct snd_pcm_substream *substream,
28 struct snd_pcm_hw_params *params)
29{
30 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000031 struct snd_soc_dai *codec_dai = rtd->codec_dai;
32 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Ryan Mallon315f7da2010-06-08 22:01:12 +120033 int err;
34
35 err = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
36 SND_SOC_DAIFMT_NB_IF |
37 SND_SOC_DAIFMT_CBS_CFS);
38
39 err = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
40 SND_SOC_DAIFMT_NB_IF |
41 SND_SOC_DAIFMT_CBS_CFS);
42 if (err)
43 return err;
44
45 err = snd_soc_dai_set_sysclk(codec_dai, 0, CODEC_CLOCK,
46 SND_SOC_CLOCK_IN);
47 if (err)
48 return err;
49
50 err = snd_soc_dai_set_sysclk(cpu_dai, 0, CODEC_CLOCK,
51 SND_SOC_CLOCK_OUT);
52 if (err)
53 return err;
54
55 return 0;
56}
57
58static struct snd_soc_ops snappercl15_ops = {
59 .hw_params = snappercl15_hw_params,
60};
61
62static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = {
63 SND_SOC_DAPM_HP("Headphone Jack", NULL),
64 SND_SOC_DAPM_LINE("Line In", NULL),
65 SND_SOC_DAPM_MIC("Mic Jack", NULL),
66};
67
68static const struct snd_soc_dapm_route audio_map[] = {
69 {"Headphone Jack", NULL, "LHPOUT"},
70 {"Headphone Jack", NULL, "RHPOUT"},
71
72 {"LLINEIN", NULL, "Line In"},
73 {"RLINEIN", NULL, "Line In"},
74
75 {"MICIN", NULL, "Mic Jack"},
76};
77
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000078static int snappercl15_tlv320aic23_init(struct snd_soc_pcm_runtime *rtd)
Ryan Mallon315f7da2010-06-08 22:01:12 +120079{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000080 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +020081 struct snd_soc_dapm_context *dapm = &codec->dapm;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000082
Liam Girdwoodce6120c2010-11-05 15:53:46 +020083 snd_soc_dapm_new_controls(dapm, tlv320aic23_dapm_widgets,
Ryan Mallon315f7da2010-06-08 22:01:12 +120084 ARRAY_SIZE(tlv320aic23_dapm_widgets));
85
Liam Girdwoodce6120c2010-11-05 15:53:46 +020086 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
Ryan Mallon315f7da2010-06-08 22:01:12 +120087 return 0;
88}
89
90static struct snd_soc_dai_link snappercl15_dai = {
91 .name = "tlv320aic23",
92 .stream_name = "AIC23",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000093 .cpu_dai_name = "ep93xx-i2s",
94 .codec_dai_name = "tlv320aic23-hifi",
95 .codec_name = "tlv320aic23-codec.0-001a",
96 .platform_name = "ep93xx-pcm-audio",
Ryan Mallon315f7da2010-06-08 22:01:12 +120097 .init = snappercl15_tlv320aic23_init,
98 .ops = &snappercl15_ops,
99};
100
101static struct snd_soc_card snd_soc_snappercl15 = {
102 .name = "Snapper CL15",
Ryan Mallon315f7da2010-06-08 22:01:12 +1200103 .dai_link = &snappercl15_dai,
104 .num_links = 1,
105};
106
Mika Westerberg62e4f7d2011-09-11 12:28:52 +0300107static int __devinit snappercl15_probe(struct platform_device *pdev)
Ryan Mallon315f7da2010-06-08 22:01:12 +1200108{
Mika Westerberg62e4f7d2011-09-11 12:28:52 +0300109 struct snd_soc_card *card = &snd_soc_snappercl15;
Ryan Mallon315f7da2010-06-08 22:01:12 +1200110 int ret;
111
Ryan Mallon315f7da2010-06-08 22:01:12 +1200112 ret = ep93xx_i2s_acquire(EP93XX_SYSCON_DEVCFG_I2SONAC97,
113 EP93XX_SYSCON_I2SCLKDIV_ORIDE |
114 EP93XX_SYSCON_I2SCLKDIV_SPOL);
115 if (ret)
116 return ret;
117
Mika Westerberg62e4f7d2011-09-11 12:28:52 +0300118 card->dev = &pdev->dev;
119
120 ret = snd_soc_register_card(card);
121 if (ret) {
122 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
123 ret);
124 ep93xx_i2s_release();
125 }
Ryan Mallon315f7da2010-06-08 22:01:12 +1200126
127 return ret;
128}
129
Mika Westerberg62e4f7d2011-09-11 12:28:52 +0300130static int __devexit snappercl15_remove(struct platform_device *pdev)
131{
132 struct snd_soc_card *card = platform_get_drvdata(pdev);
133
134 snd_soc_unregister_card(card);
135 ep93xx_i2s_release();
136
137 return 0;
138}
139
140static struct platform_driver snappercl15_driver = {
141 .driver = {
142 .name = "snappercl15-audio",
143 .owner = THIS_MODULE,
144 },
145 .probe = snappercl15_probe,
146 .remove = __devexit_p(snappercl15_remove),
147};
148
149static int __init snappercl15_init(void)
150{
151 return platform_driver_register(&snappercl15_driver);
152}
153
Ryan Mallon315f7da2010-06-08 22:01:12 +1200154static void __exit snappercl15_exit(void)
155{
Mika Westerberg62e4f7d2011-09-11 12:28:52 +0300156 platform_driver_unregister(&snappercl15_driver);
Ryan Mallon315f7da2010-06-08 22:01:12 +1200157}
158
159module_init(snappercl15_init);
160module_exit(snappercl15_exit);
161
Ryan Mallon1c5454e2011-06-15 14:45:36 +1000162MODULE_AUTHOR("Ryan Mallon");
Ryan Mallon315f7da2010-06-08 22:01:12 +1200163MODULE_DESCRIPTION("ALSA SoC Snapper CL15");
164MODULE_LICENSE("GPL");
Mika Westerberg62e4f7d2011-09-11 12:28:52 +0300165MODULE_ALIAS("platform:snappercl15-audio");