Jonathan Cameron | a195b51 | 2009-05-04 14:54:11 +0000 | [diff] [blame] | 1 | |
| 2 | #include <linux/module.h> |
| 3 | #include <sound/soc.h> |
| 4 | |
| 5 | #include <asm/mach-types.h> |
| 6 | |
| 7 | #include "../codecs/wm8940.h" |
| 8 | #include "pxa2xx-i2s.h" |
Jonathan Cameron | a195b51 | 2009-05-04 14:54:11 +0000 | [diff] [blame] | 9 | |
| 10 | static int imote2_asoc_hw_params(struct snd_pcm_substream *substream, |
| 11 | struct snd_pcm_hw_params *params) |
| 12 | { |
| 13 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 14 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 15 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Jonathan Cameron | a195b51 | 2009-05-04 14:54:11 +0000 | [diff] [blame] | 16 | unsigned int clk = 0; |
| 17 | int ret; |
| 18 | |
| 19 | switch (params_rate(params)) { |
| 20 | case 8000: |
| 21 | case 16000: |
| 22 | case 48000: |
| 23 | case 96000: |
| 24 | clk = 12288000; |
| 25 | break; |
| 26 | case 11025: |
| 27 | case 22050: |
| 28 | case 44100: |
| 29 | clk = 11289600; |
| 30 | break; |
| 31 | } |
| 32 | |
| 33 | /* set codec DAI configuration */ |
| 34 | ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
| 35 | | SND_SOC_DAIFMT_NB_NF |
| 36 | | SND_SOC_DAIFMT_CBS_CFS); |
| 37 | if (ret < 0) |
| 38 | return ret; |
| 39 | |
| 40 | /* CPU should be clock master */ |
| 41 | ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
| 42 | | SND_SOC_DAIFMT_NB_NF |
| 43 | | SND_SOC_DAIFMT_CBS_CFS); |
| 44 | if (ret < 0) |
| 45 | return ret; |
| 46 | |
| 47 | ret = snd_soc_dai_set_sysclk(codec_dai, 0, clk, |
| 48 | SND_SOC_CLOCK_IN); |
| 49 | if (ret < 0) |
| 50 | return ret; |
| 51 | |
| 52 | /* set the I2S system clock as input (unused) */ |
| 53 | ret = snd_soc_dai_set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, clk, |
| 54 | SND_SOC_CLOCK_OUT); |
| 55 | |
| 56 | return ret; |
| 57 | } |
| 58 | |
| 59 | static struct snd_soc_ops imote2_asoc_ops = { |
| 60 | .hw_params = imote2_asoc_hw_params, |
| 61 | }; |
| 62 | |
| 63 | static struct snd_soc_dai_link imote2_dai = { |
| 64 | .name = "WM8940", |
| 65 | .stream_name = "WM8940", |
Ian Lartey | a2a0086 | 2010-08-20 17:18:43 +0100 | [diff] [blame] | 66 | .cpu_dai_name = "pxa2xx-i2s", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 67 | .codec_dai_name = "wm8940-hifi", |
| 68 | .platform_name = "pxa-pcm-audio", |
| 69 | .codec_name = "wm8940-codec.0-0034", |
Jonathan Cameron | a195b51 | 2009-05-04 14:54:11 +0000 | [diff] [blame] | 70 | .ops = &imote2_asoc_ops, |
| 71 | }; |
| 72 | |
Axel Lin | ac1e898 | 2011-12-15 10:55:24 +0800 | [diff] [blame^] | 73 | static struct snd_soc_card imote2 = { |
Jonathan Cameron | a195b51 | 2009-05-04 14:54:11 +0000 | [diff] [blame] | 74 | .name = "Imote2", |
Jonathan Cameron | a195b51 | 2009-05-04 14:54:11 +0000 | [diff] [blame] | 75 | .dai_link = &imote2_dai, |
| 76 | .num_links = 1, |
| 77 | }; |
| 78 | |
Axel Lin | ac1e898 | 2011-12-15 10:55:24 +0800 | [diff] [blame^] | 79 | static int __devinit imote2_probe(struct platform_device *pdev) |
Jonathan Cameron | a195b51 | 2009-05-04 14:54:11 +0000 | [diff] [blame] | 80 | { |
Axel Lin | ac1e898 | 2011-12-15 10:55:24 +0800 | [diff] [blame^] | 81 | struct snd_soc_card *card = &imote2; |
Jonathan Cameron | a195b51 | 2009-05-04 14:54:11 +0000 | [diff] [blame] | 82 | int ret; |
| 83 | |
Axel Lin | ac1e898 | 2011-12-15 10:55:24 +0800 | [diff] [blame^] | 84 | card->dev = &pdev->dev; |
Jonathan Cameron | a195b51 | 2009-05-04 14:54:11 +0000 | [diff] [blame] | 85 | |
Axel Lin | ac1e898 | 2011-12-15 10:55:24 +0800 | [diff] [blame^] | 86 | ret = snd_soc_register_card(card); |
Jonathan Cameron | a195b51 | 2009-05-04 14:54:11 +0000 | [diff] [blame] | 87 | if (ret) |
Axel Lin | ac1e898 | 2011-12-15 10:55:24 +0800 | [diff] [blame^] | 88 | dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", |
| 89 | ret); |
Jonathan Cameron | a195b51 | 2009-05-04 14:54:11 +0000 | [diff] [blame] | 90 | return ret; |
| 91 | } |
Jonathan Cameron | a195b51 | 2009-05-04 14:54:11 +0000 | [diff] [blame] | 92 | |
Axel Lin | ac1e898 | 2011-12-15 10:55:24 +0800 | [diff] [blame^] | 93 | static int __devexit imote2_remove(struct platform_device *pdev) |
Jonathan Cameron | a195b51 | 2009-05-04 14:54:11 +0000 | [diff] [blame] | 94 | { |
Axel Lin | ac1e898 | 2011-12-15 10:55:24 +0800 | [diff] [blame^] | 95 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
| 96 | |
| 97 | snd_soc_unregister_card(card); |
| 98 | return 0; |
Jonathan Cameron | a195b51 | 2009-05-04 14:54:11 +0000 | [diff] [blame] | 99 | } |
Axel Lin | ac1e898 | 2011-12-15 10:55:24 +0800 | [diff] [blame^] | 100 | |
| 101 | static struct platform_driver imote2_driver = { |
| 102 | .driver = { |
| 103 | .name = "imote2-audio", |
| 104 | .owner = THIS_MODULE, |
| 105 | }, |
| 106 | .probe = imote2_probe, |
| 107 | .remove = __devexit_p(imote2_remove), |
| 108 | }; |
| 109 | |
| 110 | module_platform_driver(imote2_driver); |
Jonathan Cameron | a195b51 | 2009-05-04 14:54:11 +0000 | [diff] [blame] | 111 | |
| 112 | MODULE_AUTHOR("Jonathan Cameron"); |
| 113 | MODULE_DESCRIPTION("ALSA SoC Imote 2"); |
| 114 | MODULE_LICENSE("GPL"); |
Axel Lin | ac1e898 | 2011-12-15 10:55:24 +0800 | [diff] [blame^] | 115 | MODULE_ALIAS("platform:imote2-audio"); |