Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * e800-wm9712.c  --  SoC audio for e800
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 <asm/mach-types.h>
0017 #include <linux/platform_data/asoc-pxa.h>
0018 
0019 static struct gpio_desc *gpiod_spk_amp, *gpiod_hp_amp;
0020 
0021 static int e800_spk_amp_event(struct snd_soc_dapm_widget *w,
0022                 struct snd_kcontrol *kcontrol, int event)
0023 {
0024     if (event & SND_SOC_DAPM_PRE_PMU)
0025         gpiod_set_value(gpiod_spk_amp, 1);
0026     else if (event & SND_SOC_DAPM_POST_PMD)
0027         gpiod_set_value(gpiod_spk_amp, 0);
0028 
0029     return 0;
0030 }
0031 
0032 static int e800_hp_amp_event(struct snd_soc_dapm_widget *w,
0033                 struct snd_kcontrol *kcontrol, int event)
0034 {
0035     if (event & SND_SOC_DAPM_PRE_PMU)
0036         gpiod_set_value(gpiod_hp_amp, 1);
0037     else if (event & SND_SOC_DAPM_POST_PMD)
0038         gpiod_set_value(gpiod_hp_amp, 0);
0039 
0040     return 0;
0041 }
0042 
0043 static const struct snd_soc_dapm_widget e800_dapm_widgets[] = {
0044     SND_SOC_DAPM_HP("Headphone Jack", NULL),
0045     SND_SOC_DAPM_MIC("Mic (Internal1)", NULL),
0046     SND_SOC_DAPM_MIC("Mic (Internal2)", NULL),
0047     SND_SOC_DAPM_SPK("Speaker", NULL),
0048     SND_SOC_DAPM_PGA_E("Headphone Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
0049             e800_hp_amp_event, SND_SOC_DAPM_PRE_PMU |
0050             SND_SOC_DAPM_POST_PMD),
0051     SND_SOC_DAPM_PGA_E("Speaker Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
0052             e800_spk_amp_event, SND_SOC_DAPM_PRE_PMU |
0053             SND_SOC_DAPM_POST_PMD),
0054 };
0055 
0056 static const struct snd_soc_dapm_route audio_map[] = {
0057     {"Headphone Jack", NULL, "HPOUTL"},
0058     {"Headphone Jack", NULL, "HPOUTR"},
0059     {"Headphone Jack", NULL, "Headphone Amp"},
0060 
0061     {"Speaker Amp", NULL, "MONOOUT"},
0062     {"Speaker", NULL, "Speaker Amp"},
0063 
0064     {"MIC1", NULL, "Mic (Internal1)"},
0065     {"MIC2", NULL, "Mic (Internal2)"},
0066 };
0067 
0068 
0069 SND_SOC_DAILINK_DEFS(ac97,
0070     DAILINK_COMP_ARRAY(COMP_CPU("pxa2xx-ac97")),
0071     DAILINK_COMP_ARRAY(COMP_CODEC("wm9712-codec", "wm9712-hifi")),
0072     DAILINK_COMP_ARRAY(COMP_PLATFORM("pxa-pcm-audio")));
0073 
0074 SND_SOC_DAILINK_DEFS(ac97_aux,
0075     DAILINK_COMP_ARRAY(COMP_CPU("pxa2xx-ac97-aux")),
0076     DAILINK_COMP_ARRAY(COMP_CODEC("wm9712-codec", "wm9712-aux")),
0077     DAILINK_COMP_ARRAY(COMP_PLATFORM("pxa-pcm-audio")));
0078 
0079 static struct snd_soc_dai_link e800_dai[] = {
0080     {
0081         .name = "AC97",
0082         .stream_name = "AC97 HiFi",
0083         SND_SOC_DAILINK_REG(ac97),
0084     },
0085     {
0086         .name = "AC97 Aux",
0087         .stream_name = "AC97 Aux",
0088         SND_SOC_DAILINK_REG(ac97_aux),
0089     },
0090 };
0091 
0092 static struct snd_soc_card e800 = {
0093     .name = "Toshiba e800",
0094     .owner = THIS_MODULE,
0095     .dai_link = e800_dai,
0096     .num_links = ARRAY_SIZE(e800_dai),
0097 
0098     .dapm_widgets = e800_dapm_widgets,
0099     .num_dapm_widgets = ARRAY_SIZE(e800_dapm_widgets),
0100     .dapm_routes = audio_map,
0101     .num_dapm_routes = ARRAY_SIZE(audio_map),
0102 };
0103 
0104 static int e800_probe(struct platform_device *pdev)
0105 {
0106     struct snd_soc_card *card = &e800;
0107     int ret;
0108 
0109     gpiod_hp_amp  = devm_gpiod_get(&pdev->dev, "Headphone amp", GPIOD_OUT_LOW);
0110     ret = PTR_ERR_OR_ZERO(gpiod_hp_amp);
0111     if (ret)
0112         return ret;
0113     gpiod_spk_amp  = devm_gpiod_get(&pdev->dev, "Speaker amp", GPIOD_OUT_LOW);
0114     ret = PTR_ERR_OR_ZERO(gpiod_spk_amp);
0115     if (ret)
0116         return ret;
0117 
0118     card->dev = &pdev->dev;
0119 
0120     ret = devm_snd_soc_register_card(&pdev->dev, card);
0121     if (ret)
0122         dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
0123             ret);
0124     return ret;
0125 }
0126 
0127 static int e800_remove(struct platform_device *pdev)
0128 {
0129     return 0;
0130 }
0131 
0132 static struct platform_driver e800_driver = {
0133     .driver     = {
0134         .name   = "e800-audio",
0135         .pm     = &snd_soc_pm_ops,
0136     },
0137     .probe      = e800_probe,
0138     .remove     = e800_remove,
0139 };
0140 
0141 module_platform_driver(e800_driver);
0142 
0143 /* Module information */
0144 MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
0145 MODULE_DESCRIPTION("ALSA SoC driver for e800");
0146 MODULE_LICENSE("GPL v2");
0147 MODULE_ALIAS("platform:e800-audio");