linux/sound/soc/samsung/lowland.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0+
   2//
   3// Lowland audio support
   4//
   5// Copyright 2011 Wolfson Microelectronics
   6
   7#include <sound/soc.h>
   8#include <sound/soc-dapm.h>
   9#include <sound/jack.h>
  10#include <linux/gpio.h>
  11#include <linux/module.h>
  12
  13#include "../codecs/wm5100.h"
  14#include "../codecs/wm9081.h"
  15
  16#define MCLK1_RATE (44100 * 512)
  17#define CLKOUT_RATE (44100 * 256)
  18
  19static struct snd_soc_jack lowland_headset;
  20
  21/* Headset jack detection DAPM pins */
  22static struct snd_soc_jack_pin lowland_headset_pins[] = {
  23        {
  24                .pin = "Headphone",
  25                .mask = SND_JACK_HEADPHONE | SND_JACK_LINEOUT,
  26        },
  27        {
  28                .pin = "Headset Mic",
  29                .mask = SND_JACK_MICROPHONE,
  30        },
  31};
  32
  33static int lowland_wm5100_init(struct snd_soc_pcm_runtime *rtd)
  34{
  35        struct snd_soc_component *component = rtd->codec_dai->component;
  36        int ret;
  37
  38        ret = snd_soc_component_set_sysclk(component, WM5100_CLK_SYSCLK,
  39                                       WM5100_CLKSRC_MCLK1, MCLK1_RATE,
  40                                       SND_SOC_CLOCK_IN);
  41        if (ret < 0) {
  42                pr_err("Failed to set SYSCLK clock source: %d\n", ret);
  43                return ret;
  44        }
  45
  46        /* Clock OPCLK, used by the other audio components. */
  47        ret = snd_soc_component_set_sysclk(component, WM5100_CLK_OPCLK, 0,
  48                                       CLKOUT_RATE, 0);
  49        if (ret < 0) {
  50                pr_err("Failed to set OPCLK rate: %d\n", ret);
  51                return ret;
  52        }
  53
  54        ret = snd_soc_card_jack_new(rtd->card, "Headset", SND_JACK_LINEOUT |
  55                                    SND_JACK_HEADSET | SND_JACK_BTN_0,
  56                                    &lowland_headset, lowland_headset_pins,
  57                                    ARRAY_SIZE(lowland_headset_pins));
  58        if (ret)
  59                return ret;
  60
  61        wm5100_detect(component, &lowland_headset);
  62
  63        return 0;
  64}
  65
  66static int lowland_wm9081_init(struct snd_soc_pcm_runtime *rtd)
  67{
  68        struct snd_soc_component *component = rtd->codec_dai->component;
  69
  70        snd_soc_dapm_nc_pin(&rtd->card->dapm, "LINEOUT");
  71
  72        /* At any time the WM9081 is active it will have this clock */
  73        return snd_soc_component_set_sysclk(component, WM9081_SYSCLK_MCLK, 0,
  74                                        CLKOUT_RATE, 0);
  75}
  76
  77static const struct snd_soc_pcm_stream sub_params = {
  78        .formats = SNDRV_PCM_FMTBIT_S32_LE,
  79        .rate_min = 44100,
  80        .rate_max = 44100,
  81        .channels_min = 2,
  82        .channels_max = 2,
  83};
  84
  85static struct snd_soc_dai_link lowland_dai[] = {
  86        {
  87                .name = "CPU",
  88                .stream_name = "CPU",
  89                .cpu_dai_name = "samsung-i2s.0",
  90                .codec_dai_name = "wm5100-aif1",
  91                .platform_name = "samsung-i2s.0",
  92                .codec_name = "wm5100.1-001a",
  93                .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  94                                SND_SOC_DAIFMT_CBM_CFM,
  95                .init = lowland_wm5100_init,
  96        },
  97        {
  98                .name = "Baseband",
  99                .stream_name = "Baseband",
 100                .cpu_dai_name = "wm5100-aif2",
 101                .codec_dai_name = "wm1250-ev1",
 102                .codec_name = "wm1250-ev1.1-0027",
 103                .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
 104                                SND_SOC_DAIFMT_CBM_CFM,
 105                .ignore_suspend = 1,
 106        },
 107        {
 108                .name = "Sub Speaker",
 109                .stream_name = "Sub Speaker",
 110                .cpu_dai_name = "wm5100-aif3",
 111                .codec_dai_name = "wm9081-hifi",
 112                .codec_name = "wm9081.1-006c",
 113                .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
 114                                SND_SOC_DAIFMT_CBM_CFM,
 115                .ignore_suspend = 1,
 116                .params = &sub_params,
 117                .init = lowland_wm9081_init,
 118        },
 119};
 120
 121static struct snd_soc_codec_conf lowland_codec_conf[] = {
 122        {
 123                .dev_name = "wm9081.1-006c",
 124                .name_prefix = "Sub",
 125        },
 126};
 127
 128static const struct snd_kcontrol_new controls[] = {
 129        SOC_DAPM_PIN_SWITCH("Main Speaker"),
 130        SOC_DAPM_PIN_SWITCH("Main DMIC"),
 131        SOC_DAPM_PIN_SWITCH("Main AMIC"),
 132        SOC_DAPM_PIN_SWITCH("WM1250 Input"),
 133        SOC_DAPM_PIN_SWITCH("WM1250 Output"),
 134        SOC_DAPM_PIN_SWITCH("Headphone"),
 135};
 136
 137static struct snd_soc_dapm_widget widgets[] = {
 138        SND_SOC_DAPM_HP("Headphone", NULL),
 139        SND_SOC_DAPM_MIC("Headset Mic", NULL),
 140
 141        SND_SOC_DAPM_SPK("Main Speaker", NULL),
 142
 143        SND_SOC_DAPM_MIC("Main AMIC", NULL),
 144        SND_SOC_DAPM_MIC("Main DMIC", NULL),
 145};
 146
 147static struct snd_soc_dapm_route audio_paths[] = {
 148        { "Sub IN1", NULL, "HPOUT2L" },
 149        { "Sub IN2", NULL, "HPOUT2R" },
 150
 151        { "Main Speaker", NULL, "Sub SPKN" },
 152        { "Main Speaker", NULL, "Sub SPKP" },
 153        { "Main Speaker", NULL, "SPKDAT1" },
 154};
 155
 156static struct snd_soc_card lowland = {
 157        .name = "Lowland",
 158        .owner = THIS_MODULE,
 159        .dai_link = lowland_dai,
 160        .num_links = ARRAY_SIZE(lowland_dai),
 161        .codec_conf = lowland_codec_conf,
 162        .num_configs = ARRAY_SIZE(lowland_codec_conf),
 163
 164        .controls = controls,
 165        .num_controls = ARRAY_SIZE(controls),
 166        .dapm_widgets = widgets,
 167        .num_dapm_widgets = ARRAY_SIZE(widgets),
 168        .dapm_routes = audio_paths,
 169        .num_dapm_routes = ARRAY_SIZE(audio_paths),
 170};
 171
 172static int lowland_probe(struct platform_device *pdev)
 173{
 174        struct snd_soc_card *card = &lowland;
 175        int ret;
 176
 177        card->dev = &pdev->dev;
 178
 179        ret = devm_snd_soc_register_card(&pdev->dev, card);
 180        if (ret)
 181                dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
 182                        ret);
 183
 184        return ret;
 185}
 186
 187static struct platform_driver lowland_driver = {
 188        .driver = {
 189                .name = "lowland",
 190                .pm = &snd_soc_pm_ops,
 191        },
 192        .probe = lowland_probe,
 193};
 194
 195module_platform_driver(lowland_driver);
 196
 197MODULE_DESCRIPTION("Lowland audio support");
 198MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
 199MODULE_LICENSE("GPL");
 200MODULE_ALIAS("platform:lowland");
 201