Arnaud Patard (Rtp) | d906401 | 2010-10-21 19:40:03 +0200 | [diff] [blame] | 1 | /* |
| 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> |
Arnaud Patard (Rtp) | d906401 | 2010-10-21 19:40:03 +0200 | [diff] [blame] | 18 | #include <mach/kirkwood.h> |
Arnd Bergmann | c02cecb | 2012-08-24 15:21:54 +0200 | [diff] [blame] | 19 | #include <linux/platform_data/asoc-kirkwood.h> |
Arnaud Patard (Rtp) | d906401 | 2010-10-21 19:40:03 +0200 | [diff] [blame] | 20 | #include <asm/mach-types.h> |
| 21 | #include "../codecs/alc5623.h" |
| 22 | |
| 23 | static int t5325_hw_params(struct snd_pcm_substream *substream, |
| 24 | struct snd_pcm_hw_params *params) |
| 25 | { |
| 26 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 27 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
Axel Lin | 7e0d6ac | 2011-12-28 18:59:30 +0800 | [diff] [blame] | 28 | unsigned int freq; |
Arnaud Patard (Rtp) | d906401 | 2010-10-21 19:40:03 +0200 | [diff] [blame] | 29 | |
| 30 | freq = params_rate(params) * 256; |
| 31 | |
| 32 | return snd_soc_dai_set_sysclk(codec_dai, 0, freq, SND_SOC_CLOCK_IN); |
| 33 | |
| 34 | } |
| 35 | |
| 36 | static struct snd_soc_ops t5325_ops = { |
| 37 | .hw_params = t5325_hw_params, |
| 38 | }; |
| 39 | |
| 40 | static const struct snd_soc_dapm_widget t5325_dapm_widgets[] = { |
| 41 | SND_SOC_DAPM_HP("Headphone Jack", NULL), |
| 42 | SND_SOC_DAPM_SPK("Speaker", NULL), |
| 43 | SND_SOC_DAPM_MIC("Mic Jack", NULL), |
| 44 | }; |
| 45 | |
| 46 | static const struct snd_soc_dapm_route t5325_route[] = { |
| 47 | { "Headphone Jack", NULL, "HPL" }, |
| 48 | { "Headphone Jack", NULL, "HPR" }, |
| 49 | |
| 50 | {"Speaker", NULL, "SPKOUT"}, |
| 51 | {"Speaker", NULL, "SPKOUTN"}, |
| 52 | |
| 53 | { "MIC1", NULL, "Mic Jack" }, |
| 54 | { "MIC2", NULL, "Mic Jack" }, |
| 55 | }; |
| 56 | |
| 57 | static int t5325_dai_init(struct snd_soc_pcm_runtime *rtd) |
| 58 | { |
| 59 | struct snd_soc_codec *codec = rtd->codec; |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 60 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
Arnaud Patard (Rtp) | d906401 | 2010-10-21 19:40:03 +0200 | [diff] [blame] | 61 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 62 | snd_soc_dapm_enable_pin(dapm, "Mic Jack"); |
| 63 | snd_soc_dapm_enable_pin(dapm, "Headphone Jack"); |
| 64 | snd_soc_dapm_enable_pin(dapm, "Speaker"); |
Arnaud Patard (Rtp) | d906401 | 2010-10-21 19:40:03 +0200 | [diff] [blame] | 65 | |
Arnaud Patard (Rtp) | d906401 | 2010-10-21 19:40:03 +0200 | [diff] [blame] | 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | static struct snd_soc_dai_link t5325_dai[] = { |
| 70 | { |
| 71 | .name = "ALC5621", |
| 72 | .stream_name = "ALC5621 HiFi", |
| 73 | .cpu_dai_name = "kirkwood-i2s", |
| 74 | .platform_name = "kirkwood-pcm-audio", |
| 75 | .codec_dai_name = "alc5621-hifi", |
| 76 | .codec_name = "alc562x-codec.0-001a", |
Axel Lin | 7e0d6ac | 2011-12-28 18:59:30 +0800 | [diff] [blame] | 77 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS, |
Arnaud Patard (Rtp) | d906401 | 2010-10-21 19:40:03 +0200 | [diff] [blame] | 78 | .ops = &t5325_ops, |
| 79 | .init = t5325_dai_init, |
| 80 | }, |
| 81 | }; |
| 82 | |
Arnaud Patard (Rtp) | d906401 | 2010-10-21 19:40:03 +0200 | [diff] [blame] | 83 | static struct snd_soc_card t5325 = { |
| 84 | .name = "t5325", |
Axel Lin | 9b344ce | 2011-12-23 14:49:28 +0800 | [diff] [blame] | 85 | .owner = THIS_MODULE, |
Arnaud Patard (Rtp) | d906401 | 2010-10-21 19:40:03 +0200 | [diff] [blame] | 86 | .dai_link = t5325_dai, |
| 87 | .num_links = ARRAY_SIZE(t5325_dai), |
Axel Lin | 5f5de18a | 2011-12-28 19:03:23 +0800 | [diff] [blame] | 88 | |
| 89 | .dapm_widgets = t5325_dapm_widgets, |
| 90 | .num_dapm_widgets = ARRAY_SIZE(t5325_dapm_widgets), |
| 91 | .dapm_routes = t5325_route, |
| 92 | .num_dapm_routes = ARRAY_SIZE(t5325_route), |
Arnaud Patard (Rtp) | d906401 | 2010-10-21 19:40:03 +0200 | [diff] [blame] | 93 | }; |
| 94 | |
Axel Lin | 49915a5 | 2011-12-28 20:30:15 +0800 | [diff] [blame] | 95 | static int __devinit t5325_probe(struct platform_device *pdev) |
Arnaud Patard (Rtp) | d906401 | 2010-10-21 19:40:03 +0200 | [diff] [blame] | 96 | { |
Axel Lin | 49915a5 | 2011-12-28 20:30:15 +0800 | [diff] [blame] | 97 | struct snd_soc_card *card = &t5325; |
Arnaud Patard (Rtp) | d906401 | 2010-10-21 19:40:03 +0200 | [diff] [blame] | 98 | int ret; |
| 99 | |
Axel Lin | 49915a5 | 2011-12-28 20:30:15 +0800 | [diff] [blame] | 100 | card->dev = &pdev->dev; |
Arnaud Patard (Rtp) | d906401 | 2010-10-21 19:40:03 +0200 | [diff] [blame] | 101 | |
Axel Lin | 49915a5 | 2011-12-28 20:30:15 +0800 | [diff] [blame] | 102 | ret = snd_soc_register_card(card); |
| 103 | if (ret) |
| 104 | dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", |
| 105 | ret); |
Arnaud Patard (Rtp) | d906401 | 2010-10-21 19:40:03 +0200 | [diff] [blame] | 106 | return ret; |
| 107 | } |
Arnaud Patard (Rtp) | d906401 | 2010-10-21 19:40:03 +0200 | [diff] [blame] | 108 | |
Axel Lin | 49915a5 | 2011-12-28 20:30:15 +0800 | [diff] [blame] | 109 | static int __devexit t5325_remove(struct platform_device *pdev) |
Arnaud Patard (Rtp) | d906401 | 2010-10-21 19:40:03 +0200 | [diff] [blame] | 110 | { |
Axel Lin | 49915a5 | 2011-12-28 20:30:15 +0800 | [diff] [blame] | 111 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
| 112 | |
| 113 | snd_soc_unregister_card(card); |
| 114 | return 0; |
Arnaud Patard (Rtp) | d906401 | 2010-10-21 19:40:03 +0200 | [diff] [blame] | 115 | } |
Axel Lin | 49915a5 | 2011-12-28 20:30:15 +0800 | [diff] [blame] | 116 | |
| 117 | static struct platform_driver t5325_driver = { |
| 118 | .driver = { |
| 119 | .name = "t5325-audio", |
| 120 | .owner = THIS_MODULE, |
| 121 | }, |
| 122 | .probe = t5325_probe, |
| 123 | .remove = __devexit_p(t5325_remove), |
| 124 | }; |
| 125 | |
| 126 | module_platform_driver(t5325_driver); |
Arnaud Patard (Rtp) | d906401 | 2010-10-21 19:40:03 +0200 | [diff] [blame] | 127 | |
| 128 | MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>"); |
| 129 | MODULE_DESCRIPTION("ALSA SoC t5325 audio client"); |
| 130 | MODULE_LICENSE("GPL"); |
Axel Lin | 49915a5 | 2011-12-28 20:30:15 +0800 | [diff] [blame] | 131 | MODULE_ALIAS("platform:t5325-audio"); |