Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 1 | /* |
| 2 | * tosa.c -- SoC audio for Tosa |
| 3 | * |
| 4 | * Copyright 2005 Wolfson Microelectronics PLC. |
| 5 | * Copyright 2005 Openedhand Ltd. |
| 6 | * |
Liam Girdwood | d331124 | 2008-10-12 13:17:36 +0100 | [diff] [blame] | 7 | * Authors: Liam Girdwood <lrg@slimlogic.co.uk> |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 8 | * Richard Purdie <richard@openedhand.com> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License as published by the |
| 12 | * Free Software Foundation; either version 2 of the License, or (at your |
| 13 | * option) any later version. |
| 14 | * |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 15 | * GPIO's |
| 16 | * 1 - Jack Insertion |
| 17 | * 5 - Hookswitch (headset answer/hang up switch) |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/moduleparam.h> |
| 23 | #include <linux/device.h> |
Dmitry Baryshkov | 4440cbd | 2008-06-14 11:42:57 +0100 | [diff] [blame] | 24 | #include <linux/gpio.h> |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 25 | |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 26 | #include <sound/core.h> |
| 27 | #include <sound/pcm.h> |
| 28 | #include <sound/soc.h> |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 29 | |
| 30 | #include <asm/mach-types.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 31 | #include <mach/tosa.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 32 | #include <mach/audio.h> |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 33 | |
| 34 | #include "../codecs/wm9712.h" |
Liam Girdwood | cb4c048 | 2007-02-02 17:23:11 +0100 | [diff] [blame] | 35 | #include "pxa2xx-ac97.h" |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 36 | |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 37 | #define TOSA_HP 0 |
| 38 | #define TOSA_MIC_INT 1 |
| 39 | #define TOSA_HEADSET 2 |
| 40 | #define TOSA_HP_OFF 3 |
| 41 | #define TOSA_SPK_ON 0 |
| 42 | #define TOSA_SPK_OFF 1 |
| 43 | |
| 44 | static int tosa_jack_func; |
| 45 | static int tosa_spk_func; |
| 46 | |
| 47 | static void tosa_ext_control(struct snd_soc_codec *codec) |
| 48 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 49 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
| 50 | |
Charles Keepax | 26e24dd | 2014-02-18 15:22:28 +0000 | [diff] [blame^] | 51 | snd_soc_dapm_mutex_lock(dapm); |
| 52 | |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 53 | /* set up jack connection */ |
| 54 | switch (tosa_jack_func) { |
| 55 | case TOSA_HP: |
Charles Keepax | 26e24dd | 2014-02-18 15:22:28 +0000 | [diff] [blame^] | 56 | snd_soc_dapm_disable_pin_unlocked(dapm, "Mic (Internal)"); |
| 57 | snd_soc_dapm_enable_pin_unlocked(dapm, "Headphone Jack"); |
| 58 | snd_soc_dapm_disable_pin_unlocked(dapm, "Headset Jack"); |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 59 | break; |
| 60 | case TOSA_MIC_INT: |
Charles Keepax | 26e24dd | 2014-02-18 15:22:28 +0000 | [diff] [blame^] | 61 | snd_soc_dapm_enable_pin_unlocked(dapm, "Mic (Internal)"); |
| 62 | snd_soc_dapm_disable_pin_unlocked(dapm, "Headphone Jack"); |
| 63 | snd_soc_dapm_disable_pin_unlocked(dapm, "Headset Jack"); |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 64 | break; |
| 65 | case TOSA_HEADSET: |
Charles Keepax | 26e24dd | 2014-02-18 15:22:28 +0000 | [diff] [blame^] | 66 | snd_soc_dapm_disable_pin_unlocked(dapm, "Mic (Internal)"); |
| 67 | snd_soc_dapm_disable_pin_unlocked(dapm, "Headphone Jack"); |
| 68 | snd_soc_dapm_enable_pin_unlocked(dapm, "Headset Jack"); |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 69 | break; |
| 70 | } |
| 71 | |
| 72 | if (tosa_spk_func == TOSA_SPK_ON) |
Charles Keepax | 26e24dd | 2014-02-18 15:22:28 +0000 | [diff] [blame^] | 73 | snd_soc_dapm_enable_pin_unlocked(dapm, "Speaker"); |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 74 | else |
Charles Keepax | 26e24dd | 2014-02-18 15:22:28 +0000 | [diff] [blame^] | 75 | snd_soc_dapm_disable_pin_unlocked(dapm, "Speaker"); |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 76 | |
Charles Keepax | 26e24dd | 2014-02-18 15:22:28 +0000 | [diff] [blame^] | 77 | snd_soc_dapm_sync_unlocked(dapm); |
| 78 | |
| 79 | snd_soc_dapm_mutex_unlock(dapm); |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | static int tosa_startup(struct snd_pcm_substream *substream) |
| 83 | { |
| 84 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Eric Miao | cb99062 | 2010-11-02 05:10:07 +0800 | [diff] [blame] | 85 | struct snd_soc_codec *codec = rtd->codec; |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 86 | |
Mark Brown | 71a2956 | 2010-11-05 13:50:48 -0400 | [diff] [blame] | 87 | mutex_lock(&codec->mutex); |
| 88 | |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 89 | /* check the jack status at stream startup */ |
| 90 | tosa_ext_control(codec); |
Mark Brown | 71a2956 | 2010-11-05 13:50:48 -0400 | [diff] [blame] | 91 | |
| 92 | mutex_unlock(&codec->mutex); |
| 93 | |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | static struct snd_soc_ops tosa_ops = { |
| 98 | .startup = tosa_startup, |
| 99 | }; |
| 100 | |
| 101 | static int tosa_get_jack(struct snd_kcontrol *kcontrol, |
| 102 | struct snd_ctl_elem_value *ucontrol) |
| 103 | { |
| 104 | ucontrol->value.integer.value[0] = tosa_jack_func; |
| 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | static int tosa_set_jack(struct snd_kcontrol *kcontrol, |
| 109 | struct snd_ctl_elem_value *ucontrol) |
| 110 | { |
| 111 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 112 | |
| 113 | if (tosa_jack_func == ucontrol->value.integer.value[0]) |
| 114 | return 0; |
| 115 | |
| 116 | tosa_jack_func = ucontrol->value.integer.value[0]; |
| 117 | tosa_ext_control(codec); |
| 118 | return 1; |
| 119 | } |
| 120 | |
| 121 | static int tosa_get_spk(struct snd_kcontrol *kcontrol, |
| 122 | struct snd_ctl_elem_value *ucontrol) |
| 123 | { |
| 124 | ucontrol->value.integer.value[0] = tosa_spk_func; |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | static int tosa_set_spk(struct snd_kcontrol *kcontrol, |
| 129 | struct snd_ctl_elem_value *ucontrol) |
| 130 | { |
| 131 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 132 | |
| 133 | if (tosa_spk_func == ucontrol->value.integer.value[0]) |
| 134 | return 0; |
| 135 | |
| 136 | tosa_spk_func = ucontrol->value.integer.value[0]; |
| 137 | tosa_ext_control(codec); |
| 138 | return 1; |
| 139 | } |
| 140 | |
| 141 | /* tosa dapm event handlers */ |
Jarkko Nikula | 338c7ed | 2008-02-28 12:34:48 +0100 | [diff] [blame] | 142 | static int tosa_hp_event(struct snd_soc_dapm_widget *w, |
| 143 | struct snd_kcontrol *k, int event) |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 144 | { |
Dmitry Baryshkov | 4440cbd | 2008-06-14 11:42:57 +0100 | [diff] [blame] | 145 | gpio_set_value(TOSA_GPIO_L_MUTE, SND_SOC_DAPM_EVENT_ON(event) ? 1 :0); |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 146 | return 0; |
| 147 | } |
| 148 | |
| 149 | /* tosa machine dapm widgets */ |
| 150 | static const struct snd_soc_dapm_widget tosa_dapm_widgets[] = { |
| 151 | SND_SOC_DAPM_HP("Headphone Jack", tosa_hp_event), |
| 152 | SND_SOC_DAPM_HP("Headset Jack", NULL), |
| 153 | SND_SOC_DAPM_MIC("Mic (Internal)", NULL), |
| 154 | SND_SOC_DAPM_SPK("Speaker", NULL), |
| 155 | }; |
| 156 | |
| 157 | /* tosa audio map */ |
Dmitry Baryshkov | 76d39d0 | 2008-07-08 19:45:20 +0400 | [diff] [blame] | 158 | static const struct snd_soc_dapm_route audio_map[] = { |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 159 | |
| 160 | /* headphone connected to HPOUTL, HPOUTR */ |
| 161 | {"Headphone Jack", NULL, "HPOUTL"}, |
| 162 | {"Headphone Jack", NULL, "HPOUTR"}, |
| 163 | |
| 164 | /* ext speaker connected to LOUT2, ROUT2 */ |
| 165 | {"Speaker", NULL, "LOUT2"}, |
| 166 | {"Speaker", NULL, "ROUT2"}, |
| 167 | |
| 168 | /* internal mic is connected to mic1, mic2 differential - with bias */ |
| 169 | {"MIC1", NULL, "Mic Bias"}, |
| 170 | {"MIC2", NULL, "Mic Bias"}, |
| 171 | {"Mic Bias", NULL, "Mic (Internal)"}, |
| 172 | |
| 173 | /* headset is connected to HPOUTR, and LINEINR with bias */ |
| 174 | {"Headset Jack", NULL, "HPOUTR"}, |
| 175 | {"LINEINR", NULL, "Mic Bias"}, |
| 176 | {"Mic Bias", NULL, "Headset Jack"}, |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 177 | }; |
| 178 | |
| 179 | static const char *jack_function[] = {"Headphone", "Mic", "Line", "Headset", |
| 180 | "Off"}; |
| 181 | static const char *spk_function[] = {"On", "Off"}; |
| 182 | static const struct soc_enum tosa_enum[] = { |
| 183 | SOC_ENUM_SINGLE_EXT(5, jack_function), |
| 184 | SOC_ENUM_SINGLE_EXT(2, spk_function), |
| 185 | }; |
| 186 | |
| 187 | static const struct snd_kcontrol_new tosa_controls[] = { |
| 188 | SOC_ENUM_EXT("Jack Function", tosa_enum[0], tosa_get_jack, |
| 189 | tosa_set_jack), |
| 190 | SOC_ENUM_EXT("Speaker Function", tosa_enum[1], tosa_get_spk, |
| 191 | tosa_set_spk), |
| 192 | }; |
| 193 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 194 | static int tosa_ac97_init(struct snd_soc_pcm_runtime *rtd) |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 195 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 196 | struct snd_soc_codec *codec = rtd->codec; |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 197 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
Philipp Zabel | eb5f6d75 | 2009-03-12 11:07:54 +0100 | [diff] [blame] | 198 | int err; |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 199 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 200 | snd_soc_dapm_nc_pin(dapm, "OUT3"); |
| 201 | snd_soc_dapm_nc_pin(dapm, "MONOOUT"); |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 202 | |
| 203 | /* add tosa specific controls */ |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 204 | err = snd_soc_add_codec_controls(codec, tosa_controls, |
Philipp Zabel | eb5f6d75 | 2009-03-12 11:07:54 +0100 | [diff] [blame] | 205 | ARRAY_SIZE(tosa_controls)); |
| 206 | if (err < 0) |
| 207 | return err; |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 208 | |
| 209 | /* add tosa specific widgets */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 210 | snd_soc_dapm_new_controls(dapm, tosa_dapm_widgets, |
Mark Brown | 25191c4 | 2008-05-13 14:55:48 +0200 | [diff] [blame] | 211 | ARRAY_SIZE(tosa_dapm_widgets)); |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 212 | |
| 213 | /* set up tosa specific audio path audio_map */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 214 | snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map)); |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 215 | |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 216 | return 0; |
| 217 | } |
| 218 | |
| 219 | static struct snd_soc_dai_link tosa_dai[] = { |
| 220 | { |
| 221 | .name = "AC97", |
| 222 | .stream_name = "AC97 HiFi", |
Dmitry Eremin-Solenikov | 4bfc4e2 | 2011-02-23 02:29:11 +0300 | [diff] [blame] | 223 | .cpu_dai_name = "pxa2xx-ac97", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 224 | .codec_dai_name = "wm9712-hifi", |
| 225 | .platform_name = "pxa-pcm-audio", |
| 226 | .codec_name = "wm9712-codec", |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 227 | .init = tosa_ac97_init, |
Liam Girdwood | cb4c048 | 2007-02-02 17:23:11 +0100 | [diff] [blame] | 228 | .ops = &tosa_ops, |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 229 | }, |
| 230 | { |
| 231 | .name = "AC97 Aux", |
| 232 | .stream_name = "AC97 Aux", |
Dmitry Eremin-Solenikov | 4bfc4e2 | 2011-02-23 02:29:11 +0300 | [diff] [blame] | 233 | .cpu_dai_name = "pxa2xx-ac97-aux", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 234 | .codec_dai_name = "wm9712-aux", |
| 235 | .platform_name = "pxa-pcm-audio", |
| 236 | .codec_name = "wm9712-codec", |
Liam Girdwood | cb4c048 | 2007-02-02 17:23:11 +0100 | [diff] [blame] | 237 | .ops = &tosa_ops, |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 238 | }, |
| 239 | }; |
| 240 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 241 | static struct snd_soc_card tosa = { |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 242 | .name = "Tosa", |
Axel Lin | 561c6a1 | 2011-12-22 09:44:43 +0800 | [diff] [blame] | 243 | .owner = THIS_MODULE, |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 244 | .dai_link = tosa_dai, |
| 245 | .num_links = ARRAY_SIZE(tosa_dai), |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 246 | }; |
| 247 | |
Bill Pemberton | 570f6fe | 2012-12-07 09:26:17 -0500 | [diff] [blame] | 248 | static int tosa_probe(struct platform_device *pdev) |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 249 | { |
Axel Lin | f285b8c | 2011-12-15 10:57:22 +0800 | [diff] [blame] | 250 | struct snd_soc_card *card = ⤩ |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 251 | int ret; |
| 252 | |
Axel Lin | f285b8c | 2011-12-15 10:57:22 +0800 | [diff] [blame] | 253 | ret = gpio_request_one(TOSA_GPIO_L_MUTE, GPIOF_OUT_INIT_LOW, |
| 254 | "Headphone Jack"); |
| 255 | if (ret) |
| 256 | return ret; |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 257 | |
Axel Lin | f285b8c | 2011-12-15 10:57:22 +0800 | [diff] [blame] | 258 | card->dev = &pdev->dev; |
| 259 | |
| 260 | ret = snd_soc_register_card(card); |
| 261 | if (ret) { |
| 262 | dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", |
| 263 | ret); |
| 264 | gpio_free(TOSA_GPIO_L_MUTE); |
Dmitry Baryshkov | 4440cbd | 2008-06-14 11:42:57 +0100 | [diff] [blame] | 265 | } |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 266 | return ret; |
| 267 | } |
| 268 | |
Bill Pemberton | 570f6fe | 2012-12-07 09:26:17 -0500 | [diff] [blame] | 269 | static int tosa_remove(struct platform_device *pdev) |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 270 | { |
Axel Lin | f285b8c | 2011-12-15 10:57:22 +0800 | [diff] [blame] | 271 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
| 272 | |
| 273 | gpio_free(TOSA_GPIO_L_MUTE); |
| 274 | snd_soc_unregister_card(card); |
| 275 | return 0; |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 276 | } |
| 277 | |
Axel Lin | f285b8c | 2011-12-15 10:57:22 +0800 | [diff] [blame] | 278 | static struct platform_driver tosa_driver = { |
| 279 | .driver = { |
| 280 | .name = "tosa-audio", |
| 281 | .owner = THIS_MODULE, |
Dmitry Eremin-Solenikov | 7db1698 | 2013-10-17 14:01:37 +0400 | [diff] [blame] | 282 | .pm = &snd_soc_pm_ops, |
Axel Lin | f285b8c | 2011-12-15 10:57:22 +0800 | [diff] [blame] | 283 | }, |
| 284 | .probe = tosa_probe, |
Bill Pemberton | 570f6fe | 2012-12-07 09:26:17 -0500 | [diff] [blame] | 285 | .remove = tosa_remove, |
Axel Lin | f285b8c | 2011-12-15 10:57:22 +0800 | [diff] [blame] | 286 | }; |
| 287 | |
| 288 | module_platform_driver(tosa_driver); |
Liam Girdwood | 1b49cb9 | 2006-10-12 14:33:09 +0200 | [diff] [blame] | 289 | |
| 290 | /* Module information */ |
| 291 | MODULE_AUTHOR("Richard Purdie"); |
| 292 | MODULE_DESCRIPTION("ALSA SoC Tosa"); |
| 293 | MODULE_LICENSE("GPL"); |
Axel Lin | f285b8c | 2011-12-15 10:57:22 +0800 | [diff] [blame] | 294 | MODULE_ALIAS("platform:tosa-audio"); |