Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 1 | /* |
| 2 | * zoom2.c -- SoC audio for Zoom2 |
| 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> |
| 24 | #include <sound/core.h> |
| 25 | #include <sound/pcm.h> |
| 26 | #include <sound/soc.h> |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 27 | |
| 28 | #include <asm/mach-types.h> |
| 29 | #include <mach/hardware.h> |
| 30 | #include <mach/gpio.h> |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 31 | #include <mach/board-zoom.h> |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 32 | #include <plat/mcbsp.h> |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 33 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 34 | /* Register descriptions for twl4030 codec part */ |
Peter Ujfalusi | 57fe725 | 2011-05-31 12:02:49 +0300 | [diff] [blame] | 35 | #include <linux/mfd/twl4030-audio.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 36 | #include <linux/module.h> |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 37 | |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 38 | #include "omap-mcbsp.h" |
| 39 | #include "omap-pcm.h" |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 40 | |
Candelaria Villareal, Jorge | 1b6ebdd | 2009-07-02 19:04:07 -0500 | [diff] [blame] | 41 | #define ZOOM2_HEADSET_MUX_GPIO (OMAP_MAX_GPIO_LINES + 15) |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 42 | |
| 43 | static int zoom2_hw_params(struct snd_pcm_substream *substream, |
| 44 | struct snd_pcm_hw_params *params) |
| 45 | { |
| 46 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 47 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 48 | int ret; |
| 49 | |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 50 | /* Set the codec system clock for DAC and ADC */ |
| 51 | ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000, |
| 52 | SND_SOC_CLOCK_IN); |
| 53 | if (ret < 0) { |
| 54 | printk(KERN_ERR "can't set codec system clock\n"); |
| 55 | return ret; |
| 56 | } |
| 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | static struct snd_soc_ops zoom2_ops = { |
| 62 | .hw_params = zoom2_hw_params, |
| 63 | }; |
| 64 | |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 65 | /* Zoom2 machine DAPM */ |
| 66 | static const struct snd_soc_dapm_widget zoom2_twl4030_dapm_widgets[] = { |
| 67 | SND_SOC_DAPM_MIC("Ext Mic", NULL), |
| 68 | SND_SOC_DAPM_SPK("Ext Spk", NULL), |
| 69 | SND_SOC_DAPM_MIC("Headset Mic", NULL), |
| 70 | SND_SOC_DAPM_HP("Headset Stereophone", NULL), |
| 71 | SND_SOC_DAPM_LINE("Aux In", NULL), |
| 72 | }; |
| 73 | |
| 74 | static const struct snd_soc_dapm_route audio_map[] = { |
| 75 | /* External Mics: MAINMIC, SUBMIC with bias*/ |
| 76 | {"MAINMIC", NULL, "Mic Bias 1"}, |
| 77 | {"SUBMIC", NULL, "Mic Bias 2"}, |
| 78 | {"Mic Bias 1", NULL, "Ext Mic"}, |
| 79 | {"Mic Bias 2", NULL, "Ext Mic"}, |
| 80 | |
| 81 | /* External Speakers: HFL, HFR */ |
| 82 | {"Ext Spk", NULL, "HFL"}, |
| 83 | {"Ext Spk", NULL, "HFR"}, |
| 84 | |
| 85 | /* Headset Stereophone: HSOL, HSOR */ |
| 86 | {"Headset Stereophone", NULL, "HSOL"}, |
| 87 | {"Headset Stereophone", NULL, "HSOR"}, |
| 88 | |
| 89 | /* Headset Mic: HSMIC with bias */ |
| 90 | {"HSMIC", NULL, "Headset Mic Bias"}, |
| 91 | {"Headset Mic Bias", NULL, "Headset Mic"}, |
| 92 | |
| 93 | /* Aux In: AUXL, AUXR */ |
| 94 | {"Aux In", NULL, "AUXL"}, |
| 95 | {"Aux In", NULL, "AUXR"}, |
| 96 | }; |
| 97 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 98 | static int zoom2_twl4030_init(struct snd_soc_pcm_runtime *rtd) |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 99 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 100 | struct snd_soc_codec *codec = rtd->codec; |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 101 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 102 | |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 103 | /* TWL4030 not connected pins */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 104 | snd_soc_dapm_nc_pin(dapm, "CARKITMIC"); |
| 105 | snd_soc_dapm_nc_pin(dapm, "DIGIMIC0"); |
| 106 | snd_soc_dapm_nc_pin(dapm, "DIGIMIC1"); |
| 107 | snd_soc_dapm_nc_pin(dapm, "EARPIECE"); |
| 108 | snd_soc_dapm_nc_pin(dapm, "PREDRIVEL"); |
| 109 | snd_soc_dapm_nc_pin(dapm, "PREDRIVER"); |
| 110 | snd_soc_dapm_nc_pin(dapm, "CARKITL"); |
| 111 | snd_soc_dapm_nc_pin(dapm, "CARKITR"); |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 112 | |
Peter Ujfalusi | cb42487 | 2011-10-10 15:34:08 +0300 | [diff] [blame] | 113 | return 0; |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 114 | } |
| 115 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 116 | static int zoom2_twl4030_voice_init(struct snd_soc_pcm_runtime *rtd) |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 117 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 118 | struct snd_soc_codec *codec = rtd->codec; |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 119 | unsigned short reg; |
| 120 | |
| 121 | /* Enable voice interface */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 122 | reg = codec->driver->read(codec, TWL4030_REG_VOICE_IF); |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 123 | reg |= TWL4030_VIF_DIN_EN | TWL4030_VIF_DOUT_EN | TWL4030_VIF_EN; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 124 | codec->driver->write(codec, TWL4030_REG_VOICE_IF, reg); |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 125 | |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | /* Digital audio interface glue - connects codec <--> CPU */ |
| 130 | static struct snd_soc_dai_link zoom2_dai[] = { |
| 131 | { |
| 132 | .name = "TWL4030 I2S", |
| 133 | .stream_name = "TWL4030 Audio", |
Peter Ujfalusi | 45656b4 | 2012-02-14 18:20:58 +0200 | [diff] [blame] | 134 | .cpu_dai_name = "omap-mcbsp.2", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 135 | .codec_dai_name = "twl4030-hifi", |
| 136 | .platform_name = "omap-pcm-audio", |
| 137 | .codec_name = "twl4030-codec", |
Jarkko Nikula | cf9feff | 2011-09-30 16:07:45 +0300 | [diff] [blame] | 138 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
| 139 | SND_SOC_DAIFMT_CBM_CFM, |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 140 | .init = zoom2_twl4030_init, |
| 141 | .ops = &zoom2_ops, |
| 142 | }, |
| 143 | { |
| 144 | .name = "TWL4030 PCM", |
| 145 | .stream_name = "TWL4030 Voice", |
Peter Ujfalusi | 45656b4 | 2012-02-14 18:20:58 +0200 | [diff] [blame] | 146 | .cpu_dai_name = "omap-mcbsp.3", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 147 | .codec_dai_name = "twl4030-voice", |
| 148 | .platform_name = "omap-pcm-audio", |
| 149 | .codec_name = "twl4030-codec", |
Jarkko Nikula | cf9feff | 2011-09-30 16:07:45 +0300 | [diff] [blame] | 150 | .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF | |
| 151 | SND_SOC_DAIFMT_CBM_CFM, |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 152 | .init = zoom2_twl4030_voice_init, |
Jarkko Nikula | a3c6dac | 2011-09-30 16:07:46 +0300 | [diff] [blame] | 153 | .ops = &zoom2_ops, |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 154 | }, |
| 155 | }; |
| 156 | |
| 157 | /* Audio machine driver */ |
| 158 | static struct snd_soc_card snd_soc_zoom2 = { |
| 159 | .name = "Zoom2", |
Axel Lin | b425b88 | 2011-12-22 11:08:59 +0800 | [diff] [blame] | 160 | .owner = THIS_MODULE, |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 161 | .dai_link = zoom2_dai, |
| 162 | .num_links = ARRAY_SIZE(zoom2_dai), |
Peter Ujfalusi | 1083dbd | 2011-10-10 15:34:13 +0300 | [diff] [blame] | 163 | |
| 164 | .dapm_widgets = zoom2_twl4030_dapm_widgets, |
| 165 | .num_dapm_widgets = ARRAY_SIZE(zoom2_twl4030_dapm_widgets), |
| 166 | .dapm_routes = audio_map, |
| 167 | .num_dapm_routes = ARRAY_SIZE(audio_map), |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 168 | }; |
| 169 | |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 170 | static struct platform_device *zoom2_snd_device; |
| 171 | |
| 172 | static int __init zoom2_soc_init(void) |
| 173 | { |
| 174 | int ret; |
| 175 | |
Jarkko Nikula | ec588ae | 2010-10-06 16:47:26 +0300 | [diff] [blame] | 176 | if (!machine_is_omap_zoom2()) |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 177 | return -ENODEV; |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 178 | printk(KERN_INFO "Zoom2 SoC init\n"); |
| 179 | |
| 180 | zoom2_snd_device = platform_device_alloc("soc-audio", -1); |
| 181 | if (!zoom2_snd_device) { |
| 182 | printk(KERN_ERR "Platform device allocation failed\n"); |
| 183 | return -ENOMEM; |
| 184 | } |
| 185 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 186 | platform_set_drvdata(zoom2_snd_device, &snd_soc_zoom2); |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 187 | ret = platform_device_add(zoom2_snd_device); |
| 188 | if (ret) |
| 189 | goto err1; |
| 190 | |
| 191 | BUG_ON(gpio_request(ZOOM2_HEADSET_MUX_GPIO, "hs_mux") < 0); |
| 192 | gpio_direction_output(ZOOM2_HEADSET_MUX_GPIO, 0); |
| 193 | |
Candelaria Villareal, Jorge | 1b6ebdd | 2009-07-02 19:04:07 -0500 | [diff] [blame] | 194 | BUG_ON(gpio_request(ZOOM2_HEADSET_EXTMUTE_GPIO, "ext_mute") < 0); |
| 195 | gpio_direction_output(ZOOM2_HEADSET_EXTMUTE_GPIO, 0); |
| 196 | |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 197 | return 0; |
| 198 | |
| 199 | err1: |
| 200 | printk(KERN_ERR "Unable to add platform device\n"); |
| 201 | platform_device_put(zoom2_snd_device); |
| 202 | |
| 203 | return ret; |
| 204 | } |
| 205 | module_init(zoom2_soc_init); |
| 206 | |
| 207 | static void __exit zoom2_soc_exit(void) |
| 208 | { |
| 209 | gpio_free(ZOOM2_HEADSET_MUX_GPIO); |
Candelaria Villareal, Jorge | 1b6ebdd | 2009-07-02 19:04:07 -0500 | [diff] [blame] | 210 | gpio_free(ZOOM2_HEADSET_EXTMUTE_GPIO); |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 211 | |
| 212 | platform_device_unregister(zoom2_snd_device); |
| 213 | } |
| 214 | module_exit(zoom2_soc_exit); |
| 215 | |
| 216 | MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>"); |
| 217 | MODULE_DESCRIPTION("ALSA SoC Zoom2"); |
| 218 | MODULE_LICENSE("GPL"); |
| 219 | |