| Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 1 | /* | 
|  | 2 | * tegra_alc5632.c  --  Toshiba AC100(PAZ00) machine ASoC driver | 
|  | 3 | * | 
|  | 4 | * Copyright (C) 2011 The AC100 Kernel Team <ac100@lists.lauchpad.net> | 
|  | 5 | * | 
|  | 6 | * Authors:  Leon Romanovsky <leon@leon.nu> | 
|  | 7 | *           Andrey Danin <danindrey@mail.ru> | 
|  | 8 | *           Marc Dietrich <marvin24@gmx.de> | 
|  | 9 | * | 
|  | 10 | * This program is free software; you can redistribute it and/or modify | 
|  | 11 | * it under the terms of the GNU General Public License version 2 as | 
|  | 12 | * published by the Free Software Foundation. | 
|  | 13 | */ | 
|  | 14 |  | 
|  | 15 | #include <asm/mach-types.h> | 
|  | 16 |  | 
|  | 17 | #include <linux/module.h> | 
|  | 18 | #include <linux/platform_device.h> | 
|  | 19 | #include <linux/slab.h> | 
|  | 20 | #include <linux/gpio.h> | 
|  | 21 |  | 
|  | 22 | #include <sound/core.h> | 
|  | 23 | #include <sound/jack.h> | 
|  | 24 | #include <sound/pcm.h> | 
|  | 25 | #include <sound/pcm_params.h> | 
|  | 26 | #include <sound/soc.h> | 
|  | 27 |  | 
|  | 28 | #include "../codecs/alc5632.h" | 
|  | 29 |  | 
|  | 30 | #include "tegra_das.h" | 
|  | 31 | #include "tegra_i2s.h" | 
|  | 32 | #include "tegra_pcm.h" | 
|  | 33 | #include "tegra_asoc_utils.h" | 
|  | 34 |  | 
|  | 35 | #define DRV_NAME "tegra-alc5632" | 
|  | 36 |  | 
|  | 37 | struct tegra_alc5632 { | 
|  | 38 | struct tegra_asoc_utils_data util_data; | 
|  | 39 | }; | 
|  | 40 |  | 
|  | 41 | static int tegra_alc5632_asoc_hw_params(struct snd_pcm_substream *substream, | 
|  | 42 | struct snd_pcm_hw_params *params) | 
|  | 43 | { | 
|  | 44 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 
|  | 45 | struct snd_soc_dai *codec_dai = rtd->codec_dai; | 
|  | 46 | struct snd_soc_codec *codec = rtd->codec; | 
|  | 47 | struct snd_soc_card *card = codec->card; | 
|  | 48 | struct tegra_alc5632 *alc5632 = snd_soc_card_get_drvdata(card); | 
|  | 49 | int srate, mclk; | 
|  | 50 | int err; | 
|  | 51 |  | 
|  | 52 | srate = params_rate(params); | 
|  | 53 | mclk = 512 * srate; | 
|  | 54 |  | 
|  | 55 | err = tegra_asoc_utils_set_rate(&alc5632->util_data, srate, mclk); | 
|  | 56 | if (err < 0) { | 
|  | 57 | dev_err(card->dev, "Can't configure clocks\n"); | 
|  | 58 | return err; | 
|  | 59 | } | 
|  | 60 |  | 
|  | 61 | err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk, | 
|  | 62 | SND_SOC_CLOCK_IN); | 
|  | 63 | if (err < 0) { | 
|  | 64 | dev_err(card->dev, "codec_dai clock not set\n"); | 
|  | 65 | return err; | 
|  | 66 | } | 
|  | 67 |  | 
|  | 68 | return 0; | 
|  | 69 | } | 
|  | 70 |  | 
|  | 71 | static struct snd_soc_ops tegra_alc5632_asoc_ops = { | 
|  | 72 | .hw_params = tegra_alc5632_asoc_hw_params, | 
|  | 73 | }; | 
|  | 74 |  | 
|  | 75 | static struct snd_soc_jack tegra_alc5632_hs_jack; | 
|  | 76 |  | 
|  | 77 | static struct snd_soc_jack_pin tegra_alc5632_hs_jack_pins[] = { | 
|  | 78 | { | 
|  | 79 | .pin = "Headset Mic", | 
|  | 80 | .mask = SND_JACK_MICROPHONE, | 
|  | 81 | }, | 
|  | 82 | { | 
|  | 83 | .pin = "Headset Stereophone", | 
|  | 84 | .mask = SND_JACK_HEADPHONE, | 
|  | 85 | }, | 
|  | 86 | }; | 
|  | 87 |  | 
|  | 88 | static const struct snd_soc_dapm_widget tegra_alc5632_dapm_widgets[] = { | 
|  | 89 | SND_SOC_DAPM_SPK("Int Spk", NULL), | 
|  | 90 | SND_SOC_DAPM_HP("Headset Stereophone", NULL), | 
|  | 91 | SND_SOC_DAPM_MIC("Headset Mic", NULL), | 
|  | 92 | }; | 
|  | 93 |  | 
|  | 94 | static const struct snd_soc_dapm_route tegra_alc5632_audio_map[] = { | 
|  | 95 | /* Internal Speaker */ | 
|  | 96 | {"Int Spk", NULL, "SPKOUT"}, | 
|  | 97 | {"Int Spk", NULL, "SPKOUTN"}, | 
|  | 98 |  | 
|  | 99 | /* Headset Mic */ | 
|  | 100 | {"MIC1", NULL, "MICBIAS1"}, | 
|  | 101 | {"MICBIAS1", NULL, "Headset Mic"}, | 
|  | 102 |  | 
|  | 103 | /* Headset Stereophone */ | 
|  | 104 | {"Headset Stereophone", NULL, "HPR"}, | 
|  | 105 | {"Headset Stereophone", NULL, "HPL"}, | 
|  | 106 | }; | 
|  | 107 |  | 
|  | 108 | static const struct snd_kcontrol_new tegra_alc5632_controls[] = { | 
|  | 109 | SOC_DAPM_PIN_SWITCH("Int Spk"), | 
|  | 110 | }; | 
|  | 111 |  | 
|  | 112 | static int tegra_alc5632_asoc_init(struct snd_soc_pcm_runtime *rtd) | 
|  | 113 | { | 
|  | 114 | struct snd_soc_codec *codec = rtd->codec; | 
|  | 115 | struct snd_soc_dapm_context *dapm = &codec->dapm; | 
|  | 116 |  | 
|  | 117 | snd_soc_jack_new(codec, "Headset Jack", SND_JACK_HEADSET, | 
|  | 118 | &tegra_alc5632_hs_jack); | 
|  | 119 | snd_soc_jack_add_pins(&tegra_alc5632_hs_jack, | 
|  | 120 | ARRAY_SIZE(tegra_alc5632_hs_jack_pins), | 
|  | 121 | tegra_alc5632_hs_jack_pins); | 
|  | 122 |  | 
|  | 123 | snd_soc_dapm_force_enable_pin(dapm, "MICBIAS1"); | 
|  | 124 |  | 
|  | 125 | return 0; | 
|  | 126 | } | 
|  | 127 |  | 
|  | 128 | static struct snd_soc_dai_link tegra_alc5632_dai = { | 
|  | 129 | .name = "ALC5632", | 
|  | 130 | .stream_name = "ALC5632 PCM", | 
|  | 131 | .codec_name = "alc5632.0-001e", | 
|  | 132 | .platform_name = "tegra-pcm-audio", | 
|  | 133 | .cpu_dai_name = "tegra-i2s.0", | 
|  | 134 | .codec_dai_name = "alc5632-hifi", | 
|  | 135 | .init = tegra_alc5632_asoc_init, | 
|  | 136 | .ops = &tegra_alc5632_asoc_ops, | 
|  | 137 | .dai_fmt = SND_SOC_DAIFMT_I2S | 
|  | 138 | | SND_SOC_DAIFMT_NB_NF | 
|  | 139 | | SND_SOC_DAIFMT_CBS_CFS, | 
|  | 140 | }; | 
|  | 141 |  | 
|  | 142 | static struct snd_soc_card snd_soc_tegra_alc5632 = { | 
|  | 143 | .name = "tegra-alc5632", | 
| Axel Lin | b16eaf9 | 2011-12-22 21:23:01 +0800 | [diff] [blame] | 144 | .owner = THIS_MODULE, | 
| Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 145 | .dai_link = &tegra_alc5632_dai, | 
|  | 146 | .num_links = 1, | 
|  | 147 | .controls = tegra_alc5632_controls, | 
|  | 148 | .num_controls = ARRAY_SIZE(tegra_alc5632_controls), | 
|  | 149 | .dapm_widgets = tegra_alc5632_dapm_widgets, | 
|  | 150 | .num_dapm_widgets = ARRAY_SIZE(tegra_alc5632_dapm_widgets), | 
|  | 151 | .dapm_routes = tegra_alc5632_audio_map, | 
|  | 152 | .num_dapm_routes = ARRAY_SIZE(tegra_alc5632_audio_map), | 
|  | 153 | .fully_routed = true, | 
|  | 154 | }; | 
|  | 155 |  | 
|  | 156 | static __devinit int tegra_alc5632_probe(struct platform_device *pdev) | 
|  | 157 | { | 
|  | 158 | struct snd_soc_card *card = &snd_soc_tegra_alc5632; | 
|  | 159 | struct tegra_alc5632 *alc5632; | 
|  | 160 | int ret; | 
|  | 161 |  | 
|  | 162 | alc5632 = devm_kzalloc(&pdev->dev, | 
|  | 163 | sizeof(struct tegra_alc5632), GFP_KERNEL); | 
|  | 164 | if (!alc5632) { | 
|  | 165 | dev_err(&pdev->dev, "Can't allocate tegra_alc5632\n"); | 
|  | 166 | return -ENOMEM; | 
|  | 167 | } | 
|  | 168 |  | 
|  | 169 | ret = tegra_asoc_utils_init(&alc5632->util_data, &pdev->dev); | 
|  | 170 | if (ret) | 
|  | 171 | return ret; | 
|  | 172 |  | 
|  | 173 | card->dev = &pdev->dev; | 
|  | 174 | platform_set_drvdata(pdev, card); | 
|  | 175 | snd_soc_card_set_drvdata(card, alc5632); | 
|  | 176 |  | 
|  | 177 | ret = snd_soc_register_card(card); | 
|  | 178 | if (ret) { | 
|  | 179 | dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", | 
|  | 180 | ret); | 
|  | 181 | tegra_asoc_utils_fini(&alc5632->util_data); | 
|  | 182 | return ret; | 
|  | 183 | } | 
|  | 184 |  | 
|  | 185 | return 0; | 
|  | 186 | } | 
|  | 187 |  | 
|  | 188 | static int __devexit tegra_alc5632_remove(struct platform_device *pdev) | 
|  | 189 | { | 
|  | 190 | struct snd_soc_card *card = platform_get_drvdata(pdev); | 
|  | 191 | struct tegra_alc5632 *alc5632 = snd_soc_card_get_drvdata(card); | 
|  | 192 |  | 
|  | 193 | snd_soc_unregister_card(card); | 
|  | 194 |  | 
|  | 195 | tegra_asoc_utils_fini(&alc5632->util_data); | 
|  | 196 |  | 
|  | 197 | return 0; | 
|  | 198 | } | 
|  | 199 |  | 
|  | 200 | static struct platform_driver tegra_alc5632_driver = { | 
|  | 201 | .driver = { | 
|  | 202 | .name = DRV_NAME, | 
|  | 203 | .owner = THIS_MODULE, | 
|  | 204 | .pm = &snd_soc_pm_ops, | 
|  | 205 | }, | 
|  | 206 | .probe = tegra_alc5632_probe, | 
|  | 207 | .remove = __devexit_p(tegra_alc5632_remove), | 
|  | 208 | }; | 
|  | 209 | module_platform_driver(tegra_alc5632_driver); | 
|  | 210 |  | 
|  | 211 | MODULE_AUTHOR("Leon Romanovsky <leon@leon.nu>"); | 
|  | 212 | MODULE_DESCRIPTION("Tegra+ALC5632 machine ASoC driver"); | 
|  | 213 | MODULE_LICENSE("GPL"); | 
|  | 214 | MODULE_ALIAS("platform:" DRV_NAME); |