blob: ccae34a3f280dc08d8e33942389f46b27215ec87 [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>
Paul Gortmakerda155d52011-07-15 12:38:28 -040015#include <linux/module.h>
Ryan Mallon315f7da2010-06-08 22:01:12 +120016#include <sound/core.h>
17#include <sound/pcm.h>
18#include <sound/soc.h>
Ryan Mallon315f7da2010-06-08 22:01:12 +120019
20#include <asm/mach-types.h>
21#include <mach/hardware.h>
22
23#include "../codecs/tlv320aic23.h"
24#include "ep93xx-pcm.h"
Ryan Mallon315f7da2010-06-08 22:01:12 +120025
26#define CODEC_CLOCK 5644800
27
28static int snappercl15_hw_params(struct snd_pcm_substream *substream,
29 struct snd_pcm_hw_params *params)
30{
31 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000032 struct snd_soc_dai *codec_dai = rtd->codec_dai;
33 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Ryan Mallon315f7da2010-06-08 22:01:12 +120034 int err;
35
Ryan Mallon315f7da2010-06-08 22:01:12 +120036 err = snd_soc_dai_set_sysclk(codec_dai, 0, CODEC_CLOCK,
37 SND_SOC_CLOCK_IN);
38 if (err)
39 return err;
40
41 err = snd_soc_dai_set_sysclk(cpu_dai, 0, CODEC_CLOCK,
42 SND_SOC_CLOCK_OUT);
43 if (err)
44 return err;
45
46 return 0;
47}
48
49static struct snd_soc_ops snappercl15_ops = {
50 .hw_params = snappercl15_hw_params,
51};
52
53static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = {
54 SND_SOC_DAPM_HP("Headphone Jack", NULL),
55 SND_SOC_DAPM_LINE("Line In", NULL),
56 SND_SOC_DAPM_MIC("Mic Jack", NULL),
57};
58
59static const struct snd_soc_dapm_route audio_map[] = {
60 {"Headphone Jack", NULL, "LHPOUT"},
61 {"Headphone Jack", NULL, "RHPOUT"},
62
63 {"LLINEIN", NULL, "Line In"},
64 {"RLINEIN", NULL, "Line In"},
65
66 {"MICIN", NULL, "Mic Jack"},
67};
68
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000069static int snappercl15_tlv320aic23_init(struct snd_soc_pcm_runtime *rtd)
Ryan Mallon315f7da2010-06-08 22:01:12 +120070{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000071 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +020072 struct snd_soc_dapm_context *dapm = &codec->dapm;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000073
Liam Girdwoodce6120c2010-11-05 15:53:46 +020074 snd_soc_dapm_new_controls(dapm, tlv320aic23_dapm_widgets,
Ryan Mallon315f7da2010-06-08 22:01:12 +120075 ARRAY_SIZE(tlv320aic23_dapm_widgets));
76
Liam Girdwoodce6120c2010-11-05 15:53:46 +020077 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
Ryan Mallon315f7da2010-06-08 22:01:12 +120078 return 0;
79}
80
81static struct snd_soc_dai_link snappercl15_dai = {
82 .name = "tlv320aic23",
83 .stream_name = "AIC23",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000084 .cpu_dai_name = "ep93xx-i2s",
85 .codec_dai_name = "tlv320aic23-hifi",
86 .codec_name = "tlv320aic23-codec.0-001a",
87 .platform_name = "ep93xx-pcm-audio",
Ryan Mallon315f7da2010-06-08 22:01:12 +120088 .init = snappercl15_tlv320aic23_init,
Axel Linf49f8512011-12-17 15:41:11 +080089 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_IF |
90 SND_SOC_DAIFMT_CBS_CFS,
Ryan Mallon315f7da2010-06-08 22:01:12 +120091 .ops = &snappercl15_ops,
92};
93
94static struct snd_soc_card snd_soc_snappercl15 = {
95 .name = "Snapper CL15",
Axel Lina76a7022011-12-22 21:21:37 +080096 .owner = THIS_MODULE,
Ryan Mallon315f7da2010-06-08 22:01:12 +120097 .dai_link = &snappercl15_dai,
98 .num_links = 1,
99};
100
Mika Westerberg62e4f7d2011-09-11 12:28:52 +0300101static int __devinit snappercl15_probe(struct platform_device *pdev)
Ryan Mallon315f7da2010-06-08 22:01:12 +1200102{
Mika Westerberg62e4f7d2011-09-11 12:28:52 +0300103 struct snd_soc_card *card = &snd_soc_snappercl15;
Ryan Mallon315f7da2010-06-08 22:01:12 +1200104 int ret;
105
Ryan Mallon315f7da2010-06-08 22:01:12 +1200106 ret = ep93xx_i2s_acquire(EP93XX_SYSCON_DEVCFG_I2SONAC97,
107 EP93XX_SYSCON_I2SCLKDIV_ORIDE |
108 EP93XX_SYSCON_I2SCLKDIV_SPOL);
109 if (ret)
110 return ret;
111
Mika Westerberg62e4f7d2011-09-11 12:28:52 +0300112 card->dev = &pdev->dev;
113
114 ret = snd_soc_register_card(card);
115 if (ret) {
116 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
117 ret);
118 ep93xx_i2s_release();
119 }
Ryan Mallon315f7da2010-06-08 22:01:12 +1200120
121 return ret;
122}
123
Mika Westerberg62e4f7d2011-09-11 12:28:52 +0300124static int __devexit snappercl15_remove(struct platform_device *pdev)
125{
126 struct snd_soc_card *card = platform_get_drvdata(pdev);
127
128 snd_soc_unregister_card(card);
129 ep93xx_i2s_release();
130
131 return 0;
132}
133
134static struct platform_driver snappercl15_driver = {
135 .driver = {
136 .name = "snappercl15-audio",
137 .owner = THIS_MODULE,
138 },
139 .probe = snappercl15_probe,
140 .remove = __devexit_p(snappercl15_remove),
141};
142
Axel Linee18f632011-11-24 12:07:55 +0800143module_platform_driver(snappercl15_driver);
Ryan Mallon315f7da2010-06-08 22:01:12 +1200144
Ryan Mallon1c5454e2011-06-15 14:45:36 +1000145MODULE_AUTHOR("Ryan Mallon");
Ryan Mallon315f7da2010-06-08 22:01:12 +1200146MODULE_DESCRIPTION("ALSA SoC Snapper CL15");
147MODULE_LICENSE("GPL");
Mika Westerberg62e4f7d2011-09-11 12:28:52 +0300148MODULE_ALIAS("platform:snappercl15-audio");