Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * e740-wm9705.c  --  SoC audio for e740
0004  *
0005  * Copyright 2007 (c) Ian Molton <spyro@f2s.com>
0006  */
0007 
0008 #include <linux/module.h>
0009 #include <linux/moduleparam.h>
0010 #include <linux/gpio/consumer.h>
0011 
0012 #include <sound/core.h>
0013 #include <sound/pcm.h>
0014 #include <sound/soc.h>
0015 
0016 #include <linux/platform_data/asoc-pxa.h>
0017 
0018 #include <asm/mach-types.h>
0019 
0020 static struct gpio_desc *gpiod_output_amp, *gpiod_input_amp;
0021 static struct gpio_desc *gpiod_audio_power;
0022 
0023 #define E740_AUDIO_OUT 1
0024 #define E740_AUDIO_IN  2
0025 
0026 static int e740_audio_power;
0027 
0028 static void e740_sync_audio_power(int status)
0029 {
0030     gpiod_set_value(gpiod_audio_power, !status);
0031     gpiod_set_value(gpiod_output_amp, (status & E740_AUDIO_OUT) ? 1 : 0);
0032     gpiod_set_value(gpiod_input_amp, (status & E740_AUDIO_IN) ? 1 : 0);
0033 }
0034 
0035 static int e740_mic_amp_event(struct snd_soc_dapm_widget *w,
0036                 struct snd_kcontrol *kcontrol, int event)
0037 {
0038     if (event & SND_SOC_DAPM_PRE_PMU)
0039         e740_audio_power |= E740_AUDIO_IN;
0040     else if (event & SND_SOC_DAPM_POST_PMD)
0041         e740_audio_power &= ~E740_AUDIO_IN;
0042 
0043     e740_sync_audio_power(e740_audio_power);
0044 
0045     return 0;
0046 }
0047 
0048 static int e740_output_amp_event(struct snd_soc_dapm_widget *w,
0049                 struct snd_kcontrol *kcontrol, int event)
0050 {
0051     if (event & SND_SOC_DAPM_PRE_PMU)
0052         e740_audio_power |= E740_AUDIO_OUT;
0053     else if (event & SND_SOC_DAPM_POST_PMD)
0054         e740_audio_power &= ~E740_AUDIO_OUT;
0055 
0056     e740_sync_audio_power(e740_audio_power);
0057 
0058     return 0;
0059 }
0060 
0061 static const struct snd_soc_dapm_widget e740_dapm_widgets[] = {
0062     SND_SOC_DAPM_HP("Headphone Jack", NULL),
0063     SND_SOC_DAPM_SPK("Speaker", NULL),
0064     SND_SOC_DAPM_MIC("Mic (Internal)", NULL),
0065     SND_SOC_DAPM_PGA_E("Output Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
0066             e740_output_amp_event, SND_SOC_DAPM_PRE_PMU |
0067             SND_SOC_DAPM_POST_PMD),
0068     SND_SOC_DAPM_PGA_E("Mic Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
0069             e740_mic_amp_event, SND_SOC_DAPM_PRE_PMU |
0070             SND_SOC_DAPM_POST_PMD),
0071 };
0072 
0073 static const struct snd_soc_dapm_route audio_map[] = {
0074     {"Output Amp", NULL, "LOUT"},
0075     {"Output Amp", NULL, "ROUT"},
0076     {"Output Amp", NULL, "MONOOUT"},
0077 
0078     {"Speaker", NULL, "Output Amp"},
0079     {"Headphone Jack", NULL, "Output Amp"},
0080 
0081     {"MIC1", NULL, "Mic Amp"},
0082     {"Mic Amp", NULL, "Mic (Internal)"},
0083 };
0084 
0085 SND_SOC_DAILINK_DEFS(ac97,
0086     DAILINK_COMP_ARRAY(COMP_CPU("pxa2xx-ac97")),
0087     DAILINK_COMP_ARRAY(COMP_CODEC("wm9705-codec", "wm9705-hifi")),
0088     DAILINK_COMP_ARRAY(COMP_PLATFORM("pxa-pcm-audio")));
0089 
0090 SND_SOC_DAILINK_DEFS(ac97_aux,
0091     DAILINK_COMP_ARRAY(COMP_CPU("pxa2xx-ac97-aux")),
0092     DAILINK_COMP_ARRAY(COMP_CODEC("wm9705-codec", "wm9705-aux")),
0093     DAILINK_COMP_ARRAY(COMP_PLATFORM("pxa-pcm-audio")));
0094 
0095 static struct snd_soc_dai_link e740_dai[] = {
0096     {
0097         .name = "AC97",
0098         .stream_name = "AC97 HiFi",
0099         SND_SOC_DAILINK_REG(ac97),
0100     },
0101     {
0102         .name = "AC97 Aux",
0103         .stream_name = "AC97 Aux",
0104         SND_SOC_DAILINK_REG(ac97_aux),
0105     },
0106 };
0107 
0108 static struct snd_soc_card e740 = {
0109     .name = "Toshiba e740",
0110     .owner = THIS_MODULE,
0111     .dai_link = e740_dai,
0112     .num_links = ARRAY_SIZE(e740_dai),
0113 
0114     .dapm_widgets = e740_dapm_widgets,
0115     .num_dapm_widgets = ARRAY_SIZE(e740_dapm_widgets),
0116     .dapm_routes = audio_map,
0117     .num_dapm_routes = ARRAY_SIZE(audio_map),
0118     .fully_routed = true,
0119 };
0120 
0121 static int e740_probe(struct platform_device *pdev)
0122 {
0123     struct snd_soc_card *card = &e740;
0124     int ret;
0125 
0126     gpiod_input_amp  = devm_gpiod_get(&pdev->dev, "Mic amp", GPIOD_OUT_LOW);
0127     ret = PTR_ERR_OR_ZERO(gpiod_input_amp);
0128     if (ret)
0129         return ret;
0130     gpiod_output_amp  = devm_gpiod_get(&pdev->dev, "Output amp", GPIOD_OUT_LOW);
0131     ret = PTR_ERR_OR_ZERO(gpiod_output_amp);
0132     if (ret)
0133         return ret;
0134     gpiod_audio_power = devm_gpiod_get(&pdev->dev, "Audio power", GPIOD_OUT_HIGH);
0135     ret = PTR_ERR_OR_ZERO(gpiod_audio_power);
0136     if (ret)
0137         return ret;
0138 
0139     card->dev = &pdev->dev;
0140 
0141     ret = devm_snd_soc_register_card(&pdev->dev, card);
0142     if (ret)
0143         dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
0144             ret);
0145     return ret;
0146 }
0147 
0148 static int e740_remove(struct platform_device *pdev)
0149 {
0150     return 0;
0151 }
0152 
0153 static struct platform_driver e740_driver = {
0154     .driver     = {
0155         .name   = "e740-audio",
0156         .pm     = &snd_soc_pm_ops,
0157     },
0158     .probe      = e740_probe,
0159     .remove     = e740_remove,
0160 };
0161 
0162 module_platform_driver(e740_driver);
0163 
0164 /* Module information */
0165 MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
0166 MODULE_DESCRIPTION("ALSA SoC driver for e740");
0167 MODULE_LICENSE("GPL v2");
0168 MODULE_ALIAS("platform:e740-audio");