Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * ALSA Soc PCM3008 codec support
0004  *
0005  * Author:  Hugo Villeneuve
0006  * Copyright (C) 2008 Lyrtech inc
0007  *
0008  * Based on AC97 Soc codec, original copyright follow:
0009  * Copyright 2005 Wolfson Microelectronics PLC.
0010  *
0011  * Generic PCM3008 support.
0012  */
0013 
0014 #include <linux/init.h>
0015 #include <linux/kernel.h>
0016 #include <linux/device.h>
0017 #include <linux/gpio.h>
0018 #include <linux/slab.h>
0019 #include <linux/module.h>
0020 #include <sound/core.h>
0021 #include <sound/pcm.h>
0022 #include <sound/initval.h>
0023 #include <sound/soc.h>
0024 
0025 #include "pcm3008.h"
0026 
0027 static int pcm3008_dac_ev(struct snd_soc_dapm_widget *w,
0028               struct snd_kcontrol *kcontrol,
0029               int event)
0030 {
0031     struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
0032     struct pcm3008_setup_data *setup = component->dev->platform_data;
0033 
0034     gpio_set_value_cansleep(setup->pdda_pin,
0035                 SND_SOC_DAPM_EVENT_ON(event));
0036 
0037     return 0;
0038 }
0039 
0040 static int pcm3008_adc_ev(struct snd_soc_dapm_widget *w,
0041               struct snd_kcontrol *kcontrol,
0042               int event)
0043 {
0044     struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
0045     struct pcm3008_setup_data *setup = component->dev->platform_data;
0046 
0047     gpio_set_value_cansleep(setup->pdad_pin,
0048                 SND_SOC_DAPM_EVENT_ON(event));
0049 
0050     return 0;
0051 }
0052 
0053 static const struct snd_soc_dapm_widget pcm3008_dapm_widgets[] = {
0054 SND_SOC_DAPM_INPUT("VINL"),
0055 SND_SOC_DAPM_INPUT("VINR"),
0056 
0057 SND_SOC_DAPM_DAC_E("DAC", NULL, SND_SOC_NOPM, 0, 0, pcm3008_dac_ev,
0058            SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
0059 SND_SOC_DAPM_ADC_E("ADC", NULL, SND_SOC_NOPM, 0, 0, pcm3008_adc_ev,
0060            SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
0061 
0062 SND_SOC_DAPM_OUTPUT("VOUTL"),
0063 SND_SOC_DAPM_OUTPUT("VOUTR"),
0064 };
0065 
0066 static const struct snd_soc_dapm_route pcm3008_dapm_routes[] = {
0067     { "PCM3008 Capture", NULL, "ADC" },
0068     { "ADC", NULL, "VINL" },
0069     { "ADC", NULL, "VINR" },
0070 
0071     { "DAC", NULL, "PCM3008 Playback" },
0072     { "VOUTL", NULL, "DAC" },
0073     { "VOUTR", NULL, "DAC" },
0074 };
0075 
0076 #define PCM3008_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |    \
0077                SNDRV_PCM_RATE_48000)
0078 
0079 static struct snd_soc_dai_driver pcm3008_dai = {
0080     .name = "pcm3008-hifi",
0081     .playback = {
0082         .stream_name = "PCM3008 Playback",
0083         .channels_min = 1,
0084         .channels_max = 2,
0085         .rates = PCM3008_RATES,
0086         .formats = SNDRV_PCM_FMTBIT_S16_LE,
0087     },
0088     .capture = {
0089         .stream_name = "PCM3008 Capture",
0090         .channels_min = 1,
0091         .channels_max = 2,
0092         .rates = PCM3008_RATES,
0093         .formats = SNDRV_PCM_FMTBIT_S16_LE,
0094     },
0095 };
0096 
0097 static const struct snd_soc_component_driver soc_component_dev_pcm3008 = {
0098     .dapm_widgets       = pcm3008_dapm_widgets,
0099     .num_dapm_widgets   = ARRAY_SIZE(pcm3008_dapm_widgets),
0100     .dapm_routes        = pcm3008_dapm_routes,
0101     .num_dapm_routes    = ARRAY_SIZE(pcm3008_dapm_routes),
0102     .idle_bias_on       = 1,
0103     .use_pmdown_time    = 1,
0104     .endianness     = 1,
0105 };
0106 
0107 static int pcm3008_codec_probe(struct platform_device *pdev)
0108 {
0109     struct pcm3008_setup_data *setup = pdev->dev.platform_data;
0110     int ret;
0111 
0112     if (!setup)
0113         return -EINVAL;
0114 
0115     /* DEM1  DEM0  DE-EMPHASIS_MODE
0116      * Low   Low   De-emphasis 44.1 kHz ON
0117      * Low   High  De-emphasis OFF
0118      * High  Low   De-emphasis 48 kHz ON
0119      * High  High  De-emphasis 32 kHz ON
0120      */
0121 
0122     /* Configure DEM0 GPIO (turning OFF DAC De-emphasis). */
0123     ret = devm_gpio_request_one(&pdev->dev, setup->dem0_pin,
0124                     GPIOF_OUT_INIT_HIGH, "codec_dem0");
0125     if (ret != 0)
0126         return ret;
0127 
0128     /* Configure DEM1 GPIO (turning OFF DAC De-emphasis). */
0129     ret = devm_gpio_request_one(&pdev->dev, setup->dem1_pin,
0130                     GPIOF_OUT_INIT_LOW, "codec_dem1");
0131     if (ret != 0)
0132         return ret;
0133 
0134     /* Configure PDAD GPIO. */
0135     ret = devm_gpio_request_one(&pdev->dev, setup->pdad_pin,
0136                     GPIOF_OUT_INIT_LOW, "codec_pdad");
0137     if (ret != 0)
0138         return ret;
0139 
0140     /* Configure PDDA GPIO. */
0141     ret = devm_gpio_request_one(&pdev->dev, setup->pdda_pin,
0142                     GPIOF_OUT_INIT_LOW, "codec_pdda");
0143     if (ret != 0)
0144         return ret;
0145 
0146     return devm_snd_soc_register_component(&pdev->dev,
0147             &soc_component_dev_pcm3008, &pcm3008_dai, 1);
0148 }
0149 
0150 MODULE_ALIAS("platform:pcm3008-codec");
0151 
0152 static struct platform_driver pcm3008_codec_driver = {
0153     .probe      = pcm3008_codec_probe,
0154     .driver     = {
0155         .name   = "pcm3008-codec",
0156     },
0157 };
0158 
0159 module_platform_driver(pcm3008_codec_driver);
0160 
0161 MODULE_DESCRIPTION("Soc PCM3008 driver");
0162 MODULE_AUTHOR("Hugo Villeneuve");
0163 MODULE_LICENSE("GPL");