linux/sound/soc/intel/boards/haswell.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0-only
   2/*
   3 * Intel Haswell Lynxpoint SST Audio
   4 *
   5 * Copyright (C) 2013, Intel Corporation. All rights reserved.
   6 */
   7
   8#include <linux/module.h>
   9#include <linux/platform_device.h>
  10#include <sound/core.h>
  11#include <sound/pcm.h>
  12#include <sound/soc.h>
  13#include <sound/soc-acpi.h>
  14#include <sound/pcm_params.h>
  15
  16#include "../common/sst-dsp.h"
  17#include "../haswell/sst-haswell-ipc.h"
  18
  19#include "../../codecs/rt5640.h"
  20
  21/* Haswell ULT platforms have a Headphone and Mic jack */
  22static const struct snd_soc_dapm_widget haswell_widgets[] = {
  23        SND_SOC_DAPM_HP("Headphones", NULL),
  24        SND_SOC_DAPM_MIC("Mic", NULL),
  25};
  26
  27static const struct snd_soc_dapm_route haswell_rt5640_map[] = {
  28
  29        {"Headphones", NULL, "HPOR"},
  30        {"Headphones", NULL, "HPOL"},
  31        {"IN2P", NULL, "Mic"},
  32
  33        /* CODEC BE connections */
  34        {"SSP0 CODEC IN", NULL, "AIF1 Capture"},
  35        {"AIF1 Playback", NULL, "SSP0 CODEC OUT"},
  36};
  37
  38static int haswell_ssp0_fixup(struct snd_soc_pcm_runtime *rtd,
  39                        struct snd_pcm_hw_params *params)
  40{
  41        struct snd_interval *rate = hw_param_interval(params,
  42                        SNDRV_PCM_HW_PARAM_RATE);
  43        struct snd_interval *channels = hw_param_interval(params,
  44                                                SNDRV_PCM_HW_PARAM_CHANNELS);
  45
  46        /* The ADSP will covert the FE rate to 48k, stereo */
  47        rate->min = rate->max = 48000;
  48        channels->min = channels->max = 2;
  49
  50        /* set SSP0 to 16 bit */
  51        params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
  52        return 0;
  53}
  54
  55static int haswell_rt5640_hw_params(struct snd_pcm_substream *substream,
  56        struct snd_pcm_hw_params *params)
  57{
  58        struct snd_soc_pcm_runtime *rtd = substream->private_data;
  59        struct snd_soc_dai *codec_dai = rtd->codec_dai;
  60        int ret;
  61
  62        ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_MCLK, 12288000,
  63                SND_SOC_CLOCK_IN);
  64
  65        if (ret < 0) {
  66                dev_err(rtd->dev, "can't set codec sysclk configuration\n");
  67                return ret;
  68        }
  69
  70        /* set correct codec filter for DAI format and clock config */
  71        snd_soc_component_update_bits(codec_dai->component, 0x83, 0xffff, 0x8000);
  72
  73        return ret;
  74}
  75
  76static const struct snd_soc_ops haswell_rt5640_ops = {
  77        .hw_params = haswell_rt5640_hw_params,
  78};
  79
  80static int haswell_rtd_init(struct snd_soc_pcm_runtime *rtd)
  81{
  82        struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
  83        struct sst_pdata *pdata = dev_get_platdata(component->dev);
  84        struct sst_hsw *haswell = pdata->dsp;
  85        int ret;
  86
  87        /* Set ADSP SSP port settings */
  88        ret = sst_hsw_device_set_config(haswell, SST_HSW_DEVICE_SSP_0,
  89                SST_HSW_DEVICE_MCLK_FREQ_24_MHZ,
  90                SST_HSW_DEVICE_CLOCK_MASTER, 9);
  91        if (ret < 0) {
  92                dev_err(rtd->dev, "failed to set device config\n");
  93                return ret;
  94        }
  95
  96        return 0;
  97}
  98
  99static struct snd_soc_dai_link haswell_rt5640_dais[] = {
 100        /* Front End DAI links */
 101        {
 102                .name = "System",
 103                .stream_name = "System Playback/Capture",
 104                .cpu_dai_name = "System Pin",
 105                .platform_name = "haswell-pcm-audio",
 106                .dynamic = 1,
 107                .codec_name = "snd-soc-dummy",
 108                .codec_dai_name = "snd-soc-dummy-dai",
 109                .init = haswell_rtd_init,
 110                .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
 111                .dpcm_playback = 1,
 112                .dpcm_capture = 1,
 113        },
 114        {
 115                .name = "Offload0",
 116                .stream_name = "Offload0 Playback",
 117                .cpu_dai_name = "Offload0 Pin",
 118                .platform_name = "haswell-pcm-audio",
 119                .dynamic = 1,
 120                .codec_name = "snd-soc-dummy",
 121                .codec_dai_name = "snd-soc-dummy-dai",
 122                .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
 123                .dpcm_playback = 1,
 124        },
 125        {
 126                .name = "Offload1",
 127                .stream_name = "Offload1 Playback",
 128                .cpu_dai_name = "Offload1 Pin",
 129                .platform_name = "haswell-pcm-audio",
 130                .dynamic = 1,
 131                .codec_name = "snd-soc-dummy",
 132                .codec_dai_name = "snd-soc-dummy-dai",
 133                .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
 134                .dpcm_playback = 1,
 135        },
 136        {
 137                .name = "Loopback",
 138                .stream_name = "Loopback",
 139                .cpu_dai_name = "Loopback Pin",
 140                .platform_name = "haswell-pcm-audio",
 141                .dynamic = 1,
 142                .codec_name = "snd-soc-dummy",
 143                .codec_dai_name = "snd-soc-dummy-dai",
 144                .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
 145                .dpcm_capture = 1,
 146        },
 147
 148        /* Back End DAI links */
 149        {
 150                /* SSP0 - Codec */
 151                .name = "Codec",
 152                .id = 0,
 153                .cpu_dai_name = "snd-soc-dummy-dai",
 154                .platform_name = "snd-soc-dummy",
 155                .no_pcm = 1,
 156                .codec_name = "i2c-INT33CA:00",
 157                .codec_dai_name = "rt5640-aif1",
 158                .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
 159                        SND_SOC_DAIFMT_CBS_CFS,
 160                .ignore_suspend = 1,
 161                .ignore_pmdown_time = 1,
 162                .be_hw_params_fixup = haswell_ssp0_fixup,
 163                .ops = &haswell_rt5640_ops,
 164                .dpcm_playback = 1,
 165                .dpcm_capture = 1,
 166        },
 167};
 168
 169/* audio machine driver for Haswell Lynxpoint DSP + RT5640 */
 170static struct snd_soc_card haswell_rt5640 = {
 171        .name = "haswell-rt5640",
 172        .owner = THIS_MODULE,
 173        .dai_link = haswell_rt5640_dais,
 174        .num_links = ARRAY_SIZE(haswell_rt5640_dais),
 175        .dapm_widgets = haswell_widgets,
 176        .num_dapm_widgets = ARRAY_SIZE(haswell_widgets),
 177        .dapm_routes = haswell_rt5640_map,
 178        .num_dapm_routes = ARRAY_SIZE(haswell_rt5640_map),
 179        .fully_routed = true,
 180};
 181
 182static int haswell_audio_probe(struct platform_device *pdev)
 183{
 184        struct snd_soc_acpi_mach *mach;
 185        const char *platform_name = NULL;
 186        int ret;
 187
 188        haswell_rt5640.dev = &pdev->dev;
 189
 190        /* override plaform name, if required */
 191        mach = (&pdev->dev)->platform_data;
 192        if (mach) /* extra check since legacy does not pass parameters */
 193                platform_name = mach->mach_params.platform;
 194
 195        ret = snd_soc_fixup_dai_links_platform_name(&haswell_rt5640,
 196                                                    platform_name);
 197        if (ret)
 198                return ret;
 199
 200        return devm_snd_soc_register_card(&pdev->dev, &haswell_rt5640);
 201}
 202
 203static struct platform_driver haswell_audio = {
 204        .probe = haswell_audio_probe,
 205        .driver = {
 206                .name = "haswell-audio",
 207        },
 208};
 209
 210module_platform_driver(haswell_audio)
 211
 212/* Module information */
 213MODULE_AUTHOR("Liam Girdwood, Xingchao Wang");
 214MODULE_DESCRIPTION("Intel SST Audio for Haswell Lynxpoint");
 215MODULE_LICENSE("GPL v2");
 216MODULE_ALIAS("platform:haswell-audio");
 217