blob: d213832b0c72ee38b6ccf6f5c49867d6a8294888 [file] [log] [blame]
Arnaud Patard (Rtp)d9064012010-10-21 19:40:03 +02001/*
2 * kirkwood-t5325.c
3 *
4 * (c) 2010 Arnaud Patard <arnaud.patard@rtp-net.org>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 */
11
12#include <linux/module.h>
13#include <linux/moduleparam.h>
14#include <linux/interrupt.h>
15#include <linux/platform_device.h>
16#include <linux/slab.h>
17#include <sound/soc.h>
Arnd Bergmannc02cecb2012-08-24 15:21:54 +020018#include <linux/platform_data/asoc-kirkwood.h>
Arnaud Patard (Rtp)d9064012010-10-21 19:40:03 +020019#include "../codecs/alc5623.h"
20
21static int t5325_hw_params(struct snd_pcm_substream *substream,
22 struct snd_pcm_hw_params *params)
23{
24 struct snd_soc_pcm_runtime *rtd = substream->private_data;
25 struct snd_soc_dai *codec_dai = rtd->codec_dai;
Axel Lin7e0d6ac2011-12-28 18:59:30 +080026 unsigned int freq;
Arnaud Patard (Rtp)d9064012010-10-21 19:40:03 +020027
28 freq = params_rate(params) * 256;
29
30 return snd_soc_dai_set_sysclk(codec_dai, 0, freq, SND_SOC_CLOCK_IN);
31
32}
33
34static struct snd_soc_ops t5325_ops = {
35 .hw_params = t5325_hw_params,
36};
37
38static const struct snd_soc_dapm_widget t5325_dapm_widgets[] = {
39 SND_SOC_DAPM_HP("Headphone Jack", NULL),
40 SND_SOC_DAPM_SPK("Speaker", NULL),
41 SND_SOC_DAPM_MIC("Mic Jack", NULL),
42};
43
44static const struct snd_soc_dapm_route t5325_route[] = {
45 { "Headphone Jack", NULL, "HPL" },
46 { "Headphone Jack", NULL, "HPR" },
47
48 {"Speaker", NULL, "SPKOUT"},
49 {"Speaker", NULL, "SPKOUTN"},
50
51 { "MIC1", NULL, "Mic Jack" },
52 { "MIC2", NULL, "Mic Jack" },
53};
54
55static int t5325_dai_init(struct snd_soc_pcm_runtime *rtd)
56{
57 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +020058 struct snd_soc_dapm_context *dapm = &codec->dapm;
Arnaud Patard (Rtp)d9064012010-10-21 19:40:03 +020059
Liam Girdwoodce6120c2010-11-05 15:53:46 +020060 snd_soc_dapm_enable_pin(dapm, "Mic Jack");
61 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
62 snd_soc_dapm_enable_pin(dapm, "Speaker");
Arnaud Patard (Rtp)d9064012010-10-21 19:40:03 +020063
Arnaud Patard (Rtp)d9064012010-10-21 19:40:03 +020064 return 0;
65}
66
67static struct snd_soc_dai_link t5325_dai[] = {
68{
69 .name = "ALC5621",
70 .stream_name = "ALC5621 HiFi",
Jean-Francois Moine75b9b652013-10-21 10:50:49 +020071 .cpu_dai_name = "i2s",
Russell King64ddf1f2013-08-04 20:27:03 +010072 .platform_name = "mvebu-audio",
Arnaud Patard (Rtp)d9064012010-10-21 19:40:03 +020073 .codec_dai_name = "alc5621-hifi",
74 .codec_name = "alc562x-codec.0-001a",
Axel Lin7e0d6ac2011-12-28 18:59:30 +080075 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS,
Arnaud Patard (Rtp)d9064012010-10-21 19:40:03 +020076 .ops = &t5325_ops,
77 .init = t5325_dai_init,
78},
79};
80
Arnaud Patard (Rtp)d9064012010-10-21 19:40:03 +020081static struct snd_soc_card t5325 = {
82 .name = "t5325",
Axel Lin9b344ce2011-12-23 14:49:28 +080083 .owner = THIS_MODULE,
Arnaud Patard (Rtp)d9064012010-10-21 19:40:03 +020084 .dai_link = t5325_dai,
85 .num_links = ARRAY_SIZE(t5325_dai),
Axel Lin5f5de18a2011-12-28 19:03:23 +080086
87 .dapm_widgets = t5325_dapm_widgets,
88 .num_dapm_widgets = ARRAY_SIZE(t5325_dapm_widgets),
89 .dapm_routes = t5325_route,
90 .num_dapm_routes = ARRAY_SIZE(t5325_route),
Arnaud Patard (Rtp)d9064012010-10-21 19:40:03 +020091};
92
Bill Pemberton34e15fb2012-12-07 09:26:26 -050093static int t5325_probe(struct platform_device *pdev)
Arnaud Patard (Rtp)d9064012010-10-21 19:40:03 +020094{
Axel Lin49915a52011-12-28 20:30:15 +080095 struct snd_soc_card *card = &t5325;
Arnaud Patard (Rtp)d9064012010-10-21 19:40:03 +020096 int ret;
97
Axel Lin49915a52011-12-28 20:30:15 +080098 card->dev = &pdev->dev;
Arnaud Patard (Rtp)d9064012010-10-21 19:40:03 +020099
Axel Lin49915a52011-12-28 20:30:15 +0800100 ret = snd_soc_register_card(card);
101 if (ret)
102 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
103 ret);
Arnaud Patard (Rtp)d9064012010-10-21 19:40:03 +0200104 return ret;
105}
Arnaud Patard (Rtp)d9064012010-10-21 19:40:03 +0200106
Bill Pemberton34e15fb2012-12-07 09:26:26 -0500107static int t5325_remove(struct platform_device *pdev)
Arnaud Patard (Rtp)d9064012010-10-21 19:40:03 +0200108{
Axel Lin49915a52011-12-28 20:30:15 +0800109 struct snd_soc_card *card = platform_get_drvdata(pdev);
110
111 snd_soc_unregister_card(card);
112 return 0;
Arnaud Patard (Rtp)d9064012010-10-21 19:40:03 +0200113}
Axel Lin49915a52011-12-28 20:30:15 +0800114
115static struct platform_driver t5325_driver = {
116 .driver = {
117 .name = "t5325-audio",
118 .owner = THIS_MODULE,
119 },
120 .probe = t5325_probe,
Bill Pemberton34e15fb2012-12-07 09:26:26 -0500121 .remove = t5325_remove,
Axel Lin49915a52011-12-28 20:30:15 +0800122};
123
124module_platform_driver(t5325_driver);
Arnaud Patard (Rtp)d9064012010-10-21 19:40:03 +0200125
126MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>");
127MODULE_DESCRIPTION("ALSA SoC t5325 audio client");
128MODULE_LICENSE("GPL");
Axel Lin49915a52011-12-28 20:30:15 +0800129MODULE_ALIAS("platform:t5325-audio");