Zhangfei Gao | 5ebf20a | 2012-06-11 18:04:40 +0800 | [diff] [blame] | 1 | /* |
| 2 | * linux/sound/soc/pxa/brownstone.c |
| 3 | * |
| 4 | * Copyright (C) 2011 Marvell International Ltd. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #include <linux/module.h> |
| 14 | #include <sound/core.h> |
| 15 | #include <sound/pcm.h> |
| 16 | #include <sound/soc.h> |
| 17 | #include <sound/jack.h> |
| 18 | |
| 19 | #include "../codecs/wm8994.h" |
| 20 | #include "mmp-sspa.h" |
| 21 | |
| 22 | static const struct snd_kcontrol_new brownstone_dapm_control[] = { |
| 23 | SOC_DAPM_PIN_SWITCH("Ext Spk"), |
| 24 | }; |
| 25 | |
| 26 | static const struct snd_soc_dapm_widget brownstone_dapm_widgets[] = { |
| 27 | SND_SOC_DAPM_SPK("Ext Spk", NULL), |
| 28 | SND_SOC_DAPM_HP("Headset Stereophone", NULL), |
| 29 | SND_SOC_DAPM_MIC("Headset Mic", NULL), |
| 30 | SND_SOC_DAPM_MIC("Main Mic", NULL), |
| 31 | }; |
| 32 | |
| 33 | static const struct snd_soc_dapm_route brownstone_audio_map[] = { |
| 34 | {"Ext Spk", NULL, "SPKOUTLP"}, |
| 35 | {"Ext Spk", NULL, "SPKOUTLN"}, |
| 36 | {"Ext Spk", NULL, "SPKOUTRP"}, |
| 37 | {"Ext Spk", NULL, "SPKOUTRN"}, |
| 38 | |
| 39 | {"Headset Stereophone", NULL, "HPOUT1L"}, |
| 40 | {"Headset Stereophone", NULL, "HPOUT1R"}, |
| 41 | |
| 42 | {"IN1RN", NULL, "Headset Mic"}, |
| 43 | |
| 44 | {"DMIC1DAT", NULL, "MICBIAS1"}, |
| 45 | {"MICBIAS1", NULL, "Main Mic"}, |
| 46 | }; |
| 47 | |
| 48 | static int brownstone_wm8994_init(struct snd_soc_pcm_runtime *rtd) |
| 49 | { |
| 50 | struct snd_soc_codec *codec = rtd->codec; |
| 51 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
| 52 | |
| 53 | snd_soc_dapm_enable_pin(dapm, "Ext Spk"); |
| 54 | snd_soc_dapm_enable_pin(dapm, "Headset Stereophone"); |
| 55 | snd_soc_dapm_enable_pin(dapm, "Headset Mic"); |
| 56 | snd_soc_dapm_enable_pin(dapm, "Main Mic"); |
| 57 | |
| 58 | /* set endpoints to not connected */ |
| 59 | snd_soc_dapm_nc_pin(dapm, "HPOUT2P"); |
| 60 | snd_soc_dapm_nc_pin(dapm, "HPOUT2N"); |
| 61 | snd_soc_dapm_nc_pin(dapm, "LINEOUT1N"); |
| 62 | snd_soc_dapm_nc_pin(dapm, "LINEOUT1P"); |
| 63 | snd_soc_dapm_nc_pin(dapm, "LINEOUT2N"); |
| 64 | snd_soc_dapm_nc_pin(dapm, "LINEOUT2P"); |
| 65 | snd_soc_dapm_nc_pin(dapm, "IN1LN"); |
| 66 | snd_soc_dapm_nc_pin(dapm, "IN1LP"); |
| 67 | snd_soc_dapm_nc_pin(dapm, "IN1RP"); |
| 68 | snd_soc_dapm_nc_pin(dapm, "IN2LP:VXRN"); |
| 69 | snd_soc_dapm_nc_pin(dapm, "IN2RN"); |
| 70 | snd_soc_dapm_nc_pin(dapm, "IN2RP:VXRP"); |
| 71 | snd_soc_dapm_nc_pin(dapm, "IN2LN"); |
| 72 | |
| 73 | snd_soc_dapm_sync(dapm); |
| 74 | |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | static int brownstone_wm8994_hw_params(struct snd_pcm_substream *substream, |
| 79 | struct snd_pcm_hw_params *params) |
| 80 | { |
| 81 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 82 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 83 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 84 | int freq_out, sspa_mclk, sysclk; |
| 85 | int sspa_div; |
| 86 | |
| 87 | if (params_rate(params) > 11025) { |
| 88 | freq_out = params_rate(params) * 512; |
| 89 | sysclk = params_rate(params) * 256; |
| 90 | sspa_mclk = params_rate(params) * 64; |
| 91 | } else { |
| 92 | freq_out = params_rate(params) * 1024; |
| 93 | sysclk = params_rate(params) * 512; |
| 94 | sspa_mclk = params_rate(params) * 64; |
| 95 | } |
| 96 | sspa_div = freq_out; |
| 97 | do_div(sspa_div, sspa_mclk); |
| 98 | |
| 99 | snd_soc_dai_set_sysclk(cpu_dai, MMP_SSPA_CLK_AUDIO, freq_out, 0); |
| 100 | snd_soc_dai_set_pll(cpu_dai, MMP_SYSCLK, 0, freq_out, sysclk); |
| 101 | snd_soc_dai_set_pll(cpu_dai, MMP_SSPA_CLK, 0, freq_out, sspa_mclk); |
| 102 | |
| 103 | /* set wm8994 sysclk */ |
| 104 | snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_MCLK1, sysclk, 0); |
| 105 | |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | /* machine stream operations */ |
| 110 | static struct snd_soc_ops brownstone_ops = { |
| 111 | .hw_params = brownstone_wm8994_hw_params, |
| 112 | }; |
| 113 | |
| 114 | static struct snd_soc_dai_link brownstone_wm8994_dai[] = { |
| 115 | { |
| 116 | .name = "WM8994", |
| 117 | .stream_name = "WM8994 HiFi", |
| 118 | .cpu_dai_name = "mmp-sspa-dai.0", |
| 119 | .codec_dai_name = "wm8994-aif1", |
| 120 | .platform_name = "mmp-pcm-audio", |
| 121 | .codec_name = "wm8994-codec", |
| 122 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
| 123 | SND_SOC_DAIFMT_CBS_CFS, |
| 124 | .ops = &brownstone_ops, |
| 125 | .init = brownstone_wm8994_init, |
| 126 | }, |
| 127 | }; |
| 128 | |
| 129 | /* audio machine driver */ |
| 130 | static struct snd_soc_card brownstone = { |
| 131 | .name = "brownstone", |
Wei Yongjun | 0d61786 | 2013-07-02 17:26:21 +0800 | [diff] [blame] | 132 | .owner = THIS_MODULE, |
Zhangfei Gao | 5ebf20a | 2012-06-11 18:04:40 +0800 | [diff] [blame] | 133 | .dai_link = brownstone_wm8994_dai, |
| 134 | .num_links = ARRAY_SIZE(brownstone_wm8994_dai), |
| 135 | |
| 136 | .controls = brownstone_dapm_control, |
| 137 | .num_controls = ARRAY_SIZE(brownstone_dapm_control), |
| 138 | .dapm_widgets = brownstone_dapm_widgets, |
| 139 | .num_dapm_widgets = ARRAY_SIZE(brownstone_dapm_widgets), |
| 140 | .dapm_routes = brownstone_audio_map, |
| 141 | .num_dapm_routes = ARRAY_SIZE(brownstone_audio_map), |
| 142 | }; |
| 143 | |
Bill Pemberton | 570f6fe | 2012-12-07 09:26:17 -0500 | [diff] [blame] | 144 | static int brownstone_probe(struct platform_device *pdev) |
Zhangfei Gao | 5ebf20a | 2012-06-11 18:04:40 +0800 | [diff] [blame] | 145 | { |
| 146 | int ret; |
| 147 | |
| 148 | brownstone.dev = &pdev->dev; |
| 149 | ret = snd_soc_register_card(&brownstone); |
| 150 | if (ret) |
| 151 | dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", |
| 152 | ret); |
| 153 | return ret; |
| 154 | } |
| 155 | |
Bill Pemberton | 570f6fe | 2012-12-07 09:26:17 -0500 | [diff] [blame] | 156 | static int brownstone_remove(struct platform_device *pdev) |
Zhangfei Gao | 5ebf20a | 2012-06-11 18:04:40 +0800 | [diff] [blame] | 157 | { |
| 158 | snd_soc_unregister_card(&brownstone); |
| 159 | return 0; |
| 160 | } |
| 161 | |
| 162 | static struct platform_driver mmp_driver = { |
| 163 | .driver = { |
| 164 | .name = "brownstone-audio", |
| 165 | .owner = THIS_MODULE, |
Dmitry Eremin-Solenikov | 7db1698 | 2013-10-17 14:01:37 +0400 | [diff] [blame] | 166 | .pm = &snd_soc_pm_ops, |
Zhangfei Gao | 5ebf20a | 2012-06-11 18:04:40 +0800 | [diff] [blame] | 167 | }, |
| 168 | .probe = brownstone_probe, |
Bill Pemberton | 570f6fe | 2012-12-07 09:26:17 -0500 | [diff] [blame] | 169 | .remove = brownstone_remove, |
Zhangfei Gao | 5ebf20a | 2012-06-11 18:04:40 +0800 | [diff] [blame] | 170 | }; |
| 171 | |
| 172 | module_platform_driver(mmp_driver); |
| 173 | |
| 174 | MODULE_AUTHOR("Leo Yan <leoy@marvell.com>"); |
| 175 | MODULE_DESCRIPTION("ALSA SoC Brownstone"); |
| 176 | MODULE_LICENSE("GPL"); |