Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 1 | /* |
| 2 | * sdp4430.c -- SoC audio for TI OMAP4430 SDP |
| 3 | * |
| 4 | * Author: Misael Lopez Cruz <x0052729@ti.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * version 2 as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 18 | * 02110-1301 USA |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <linux/clk.h> |
| 23 | #include <linux/platform_device.h> |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 24 | #include <linux/mfd/twl6040.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 25 | #include <linux/module.h> |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 26 | |
Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 27 | #include <sound/core.h> |
| 28 | #include <sound/pcm.h> |
| 29 | #include <sound/soc.h> |
Jorge Eduardo Candelaria | 96dc227 | 2010-12-10 20:45:19 -0600 | [diff] [blame] | 30 | #include <sound/jack.h> |
Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 31 | |
| 32 | #include <asm/mach-types.h> |
| 33 | #include <plat/hardware.h> |
| 34 | #include <plat/mux.h> |
| 35 | |
Misael Lopez Cruz | f5f9d7b | 2011-07-05 19:50:45 +0300 | [diff] [blame] | 36 | #include "omap-mcpdm.h" |
Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 37 | #include "omap-pcm.h" |
| 38 | #include "../codecs/twl6040.h" |
| 39 | |
Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 40 | static int sdp4430_hw_params(struct snd_pcm_substream *substream, |
| 41 | struct snd_pcm_hw_params *params) |
| 42 | { |
| 43 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 44 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 45 | int clk_id, freq; |
| 46 | int ret; |
| 47 | |
Peter Ujfalusi | af958c7 | 2011-06-27 17:03:14 +0300 | [diff] [blame] | 48 | clk_id = twl6040_get_clk_id(rtd->codec); |
| 49 | if (clk_id == TWL6040_SYSCLK_SEL_HPPLL) |
Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 50 | freq = 38400000; |
Peter Ujfalusi | af958c7 | 2011-06-27 17:03:14 +0300 | [diff] [blame] | 51 | else if (clk_id == TWL6040_SYSCLK_SEL_LPPLL) |
Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 52 | freq = 32768; |
Peter Ujfalusi | af958c7 | 2011-06-27 17:03:14 +0300 | [diff] [blame] | 53 | else |
| 54 | return -EINVAL; |
Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 55 | |
| 56 | /* set the codec mclk */ |
| 57 | ret = snd_soc_dai_set_sysclk(codec_dai, clk_id, freq, |
| 58 | SND_SOC_CLOCK_IN); |
| 59 | if (ret) { |
| 60 | printk(KERN_ERR "can't set codec system clock\n"); |
| 61 | return ret; |
| 62 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 63 | return ret; |
Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | static struct snd_soc_ops sdp4430_ops = { |
| 67 | .hw_params = sdp4430_hw_params, |
| 68 | }; |
| 69 | |
Jorge Eduardo Candelaria | 96dc227 | 2010-12-10 20:45:19 -0600 | [diff] [blame] | 70 | /* Headset jack */ |
| 71 | static struct snd_soc_jack hs_jack; |
| 72 | |
| 73 | /*Headset jack detection DAPM pins */ |
| 74 | static struct snd_soc_jack_pin hs_jack_pins[] = { |
| 75 | { |
| 76 | .pin = "Headset Mic", |
| 77 | .mask = SND_JACK_MICROPHONE, |
| 78 | }, |
| 79 | { |
| 80 | .pin = "Headset Stereophone", |
| 81 | .mask = SND_JACK_HEADPHONE, |
| 82 | }, |
| 83 | }; |
| 84 | |
Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 85 | /* SDP4430 machine DAPM */ |
| 86 | static const struct snd_soc_dapm_widget sdp4430_twl6040_dapm_widgets[] = { |
| 87 | SND_SOC_DAPM_MIC("Ext Mic", NULL), |
| 88 | SND_SOC_DAPM_SPK("Ext Spk", NULL), |
| 89 | SND_SOC_DAPM_MIC("Headset Mic", NULL), |
| 90 | SND_SOC_DAPM_HP("Headset Stereophone", NULL), |
Jorge Eduardo Candelaria | 7254e2b | 2010-05-18 12:44:17 -0500 | [diff] [blame] | 91 | SND_SOC_DAPM_SPK("Earphone Spk", NULL), |
Ujfalusi, Peter | 5382ffb | 2011-09-30 11:39:50 +0300 | [diff] [blame] | 92 | SND_SOC_DAPM_INPUT("FM Stereo In"), |
Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | static const struct snd_soc_dapm_route audio_map[] = { |
| 96 | /* External Mics: MAINMIC, SUBMIC with bias*/ |
| 97 | {"MAINMIC", NULL, "Main Mic Bias"}, |
| 98 | {"SUBMIC", NULL, "Main Mic Bias"}, |
| 99 | {"Main Mic Bias", NULL, "Ext Mic"}, |
| 100 | |
| 101 | /* External Speakers: HFL, HFR */ |
| 102 | {"Ext Spk", NULL, "HFL"}, |
| 103 | {"Ext Spk", NULL, "HFR"}, |
| 104 | |
| 105 | /* Headset Mic: HSMIC with bias */ |
| 106 | {"HSMIC", NULL, "Headset Mic Bias"}, |
| 107 | {"Headset Mic Bias", NULL, "Headset Mic"}, |
| 108 | |
| 109 | /* Headset Stereophone (Headphone): HSOL, HSOR */ |
| 110 | {"Headset Stereophone", NULL, "HSOL"}, |
| 111 | {"Headset Stereophone", NULL, "HSOR"}, |
Jorge Eduardo Candelaria | 7254e2b | 2010-05-18 12:44:17 -0500 | [diff] [blame] | 112 | |
| 113 | /* Earphone speaker */ |
| 114 | {"Earphone Spk", NULL, "EP"}, |
Jorge Eduardo Candelaria | 23ac3b6 | 2010-12-08 10:55:05 -0600 | [diff] [blame] | 115 | |
| 116 | /* Aux/FM Stereo In: AFML, AFMR */ |
Ujfalusi, Peter | 5382ffb | 2011-09-30 11:39:50 +0300 | [diff] [blame] | 117 | {"AFML", NULL, "FM Stereo In"}, |
| 118 | {"AFMR", NULL, "FM Stereo In"}, |
Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 119 | }; |
| 120 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 121 | static int sdp4430_twl6040_init(struct snd_soc_pcm_runtime *rtd) |
Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 122 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 123 | struct snd_soc_codec *codec = rtd->codec; |
Peter Ujfalusi | 7bf3d92 | 2011-09-26 16:05:59 +0300 | [diff] [blame] | 124 | int ret, hs_trim; |
Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 125 | |
Peter Ujfalusi | 7bf3d92 | 2011-09-26 16:05:59 +0300 | [diff] [blame] | 126 | /* |
| 127 | * Configure McPDM offset cancellation based on the HSOTRIM value from |
| 128 | * twl6040. |
| 129 | */ |
| 130 | hs_trim = twl6040_get_trim_value(codec, TWL6040_TRIM_HSOTRIM); |
| 131 | omap_mcpdm_configure_dn_offsets(rtd, TWL6040_HSF_TRIM_LEFT(hs_trim), |
| 132 | TWL6040_HSF_TRIM_RIGHT(hs_trim)); |
| 133 | |
Jorge Eduardo Candelaria | 96dc227 | 2010-12-10 20:45:19 -0600 | [diff] [blame] | 134 | /* Headset jack detection */ |
| 135 | ret = snd_soc_jack_new(codec, "Headset Jack", |
| 136 | SND_JACK_HEADSET, &hs_jack); |
| 137 | if (ret) |
| 138 | return ret; |
| 139 | |
| 140 | ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins), |
| 141 | hs_jack_pins); |
| 142 | |
| 143 | if (machine_is_omap_4430sdp()) |
| 144 | twl6040_hs_jack_detect(codec, &hs_jack, SND_JACK_HEADSET); |
| 145 | else |
| 146 | snd_soc_jack_report(&hs_jack, SND_JACK_HEADSET, SND_JACK_HEADSET); |
Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 147 | |
| 148 | return ret; |
| 149 | } |
| 150 | |
| 151 | /* Digital audio interface glue - connects codec <--> CPU */ |
| 152 | static struct snd_soc_dai_link sdp4430_dai = { |
| 153 | .name = "TWL6040", |
| 154 | .stream_name = "TWL6040", |
Peter Ujfalusi | 3a98cd6 | 2011-08-02 14:04:26 +0300 | [diff] [blame] | 155 | .cpu_dai_name = "omap-mcpdm", |
Peter Ujfalusi | d13f1fe | 2011-09-22 11:05:53 +0300 | [diff] [blame] | 156 | .codec_dai_name = "twl6040-legacy", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 157 | .platform_name = "omap-pcm-audio", |
| 158 | .codec_name = "twl6040-codec", |
Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 159 | .init = sdp4430_twl6040_init, |
Liam Girdwood | d8b55d2 | 2010-05-19 14:14:51 +0100 | [diff] [blame] | 160 | .ops = &sdp4430_ops, |
Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 161 | }; |
| 162 | |
| 163 | /* Audio machine driver */ |
| 164 | static struct snd_soc_card snd_soc_sdp4430 = { |
| 165 | .name = "SDP4430", |
Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 166 | .dai_link = &sdp4430_dai, |
| 167 | .num_links = 1, |
Peter Ujfalusi | fc8e5b4 | 2011-10-10 15:34:15 +0300 | [diff] [blame] | 168 | |
| 169 | .dapm_widgets = sdp4430_twl6040_dapm_widgets, |
| 170 | .num_dapm_widgets = ARRAY_SIZE(sdp4430_twl6040_dapm_widgets), |
| 171 | .dapm_routes = audio_map, |
| 172 | .num_dapm_routes = ARRAY_SIZE(audio_map), |
Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 173 | }; |
| 174 | |
Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 175 | static struct platform_device *sdp4430_snd_device; |
| 176 | |
| 177 | static int __init sdp4430_soc_init(void) |
| 178 | { |
| 179 | int ret; |
| 180 | |
Jarkko Nikula | ec588ae | 2010-10-06 16:47:26 +0300 | [diff] [blame] | 181 | if (!machine_is_omap_4430sdp()) |
Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 182 | return -ENODEV; |
Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 183 | printk(KERN_INFO "SDP4430 SoC init\n"); |
| 184 | |
| 185 | sdp4430_snd_device = platform_device_alloc("soc-audio", -1); |
| 186 | if (!sdp4430_snd_device) { |
| 187 | printk(KERN_ERR "Platform device allocation failed\n"); |
| 188 | return -ENOMEM; |
| 189 | } |
| 190 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 191 | platform_set_drvdata(sdp4430_snd_device, &snd_soc_sdp4430); |
Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 192 | |
| 193 | ret = platform_device_add(sdp4430_snd_device); |
| 194 | if (ret) |
| 195 | goto err; |
| 196 | |
Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 197 | return 0; |
| 198 | |
| 199 | err: |
| 200 | printk(KERN_ERR "Unable to add platform device\n"); |
| 201 | platform_device_put(sdp4430_snd_device); |
| 202 | return ret; |
| 203 | } |
| 204 | module_init(sdp4430_soc_init); |
| 205 | |
| 206 | static void __exit sdp4430_soc_exit(void) |
| 207 | { |
| 208 | platform_device_unregister(sdp4430_snd_device); |
| 209 | } |
| 210 | module_exit(sdp4430_soc_exit); |
| 211 | |
| 212 | MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>"); |
| 213 | MODULE_DESCRIPTION("ALSA SoC SDP4430"); |
| 214 | MODULE_LICENSE("GPL"); |
| 215 | |