Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Sound card driver for Intel Haswell Lynx Point with Realtek 5640
0004  *
0005  * Copyright (C) 2013, Intel Corporation. All rights reserved.
0006  */
0007 
0008 #include <linux/module.h>
0009 #include <linux/platform_device.h>
0010 #include <sound/core.h>
0011 #include <sound/pcm.h>
0012 #include <sound/pcm_params.h>
0013 #include <sound/soc.h>
0014 #include <sound/soc-acpi.h>
0015 #include "../../codecs/rt5640.h"
0016 
0017 static const struct snd_soc_dapm_widget card_widgets[] = {
0018     SND_SOC_DAPM_HP("Headphones", NULL),
0019     SND_SOC_DAPM_MIC("Mic", NULL),
0020 };
0021 
0022 static const struct snd_soc_dapm_route card_routes[] = {
0023     {"Headphones", NULL, "HPOR"},
0024     {"Headphones", NULL, "HPOL"},
0025     {"IN2P", NULL, "Mic"},
0026 
0027     /* CODEC BE connections */
0028     {"SSP0 CODEC IN", NULL, "AIF1 Capture"},
0029     {"AIF1 Playback", NULL, "SSP0 CODEC OUT"},
0030 };
0031 
0032 static int codec_link_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
0033                       struct snd_pcm_hw_params *params)
0034 {
0035     struct snd_interval *channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
0036     struct snd_interval *rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
0037 
0038     /* The ADSP will convert the FE rate to 48k, stereo. */
0039     rate->min = rate->max = 48000;
0040     channels->min = channels->max = 2;
0041     /* Set SSP0 to 16 bit. */
0042     params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
0043 
0044     return 0;
0045 }
0046 
0047 static int codec_link_hw_params(struct snd_pcm_substream *substream,
0048                 struct snd_pcm_hw_params *params)
0049 {
0050     struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
0051     struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
0052     int ret;
0053 
0054     ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_MCLK, 12288000, SND_SOC_CLOCK_IN);
0055     if (ret < 0) {
0056         dev_err(rtd->dev, "set codec sysclk failed: %d\n", ret);
0057         return ret;
0058     }
0059 
0060     /* Set correct codec filter for DAI format and clock config. */
0061     snd_soc_component_update_bits(codec_dai->component, 0x83, 0xffff, 0x8000);
0062 
0063     return ret;
0064 }
0065 
0066 static const struct snd_soc_ops codec_link_ops = {
0067     .hw_params = codec_link_hw_params,
0068 };
0069 
0070 SND_SOC_DAILINK_DEF(system, DAILINK_COMP_ARRAY(COMP_CPU("System Pin")));
0071 SND_SOC_DAILINK_DEF(offload0, DAILINK_COMP_ARRAY(COMP_CPU("Offload0 Pin")));
0072 SND_SOC_DAILINK_DEF(offload1, DAILINK_COMP_ARRAY(COMP_CPU("Offload1 Pin")));
0073 SND_SOC_DAILINK_DEF(loopback, DAILINK_COMP_ARRAY(COMP_CPU("Loopback Pin")));
0074 
0075 SND_SOC_DAILINK_DEF(dummy, DAILINK_COMP_ARRAY(COMP_DUMMY()));
0076 SND_SOC_DAILINK_DEF(codec, DAILINK_COMP_ARRAY(COMP_CODEC("i2c-INT33CA:00", "rt5640-aif1")));
0077 SND_SOC_DAILINK_DEF(platform, DAILINK_COMP_ARRAY(COMP_PLATFORM("haswell-pcm-audio")));
0078 SND_SOC_DAILINK_DEF(ssp0_port, DAILINK_COMP_ARRAY(COMP_CPU("ssp0-port")));
0079 
0080 static struct snd_soc_dai_link card_dai_links[] = {
0081     /* Front End DAI links */
0082     {
0083         .name = "System",
0084         .stream_name = "System Playback/Capture",
0085         .nonatomic = 1,
0086         .dynamic = 1,
0087         .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
0088         .dpcm_playback = 1,
0089         .dpcm_capture = 1,
0090         SND_SOC_DAILINK_REG(system, dummy, platform),
0091     },
0092     {
0093         .name = "Offload0",
0094         .stream_name = "Offload0 Playback",
0095         .nonatomic = 1,
0096         .dynamic = 1,
0097         .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
0098         .dpcm_playback = 1,
0099         SND_SOC_DAILINK_REG(offload0, dummy, platform),
0100     },
0101     {
0102         .name = "Offload1",
0103         .stream_name = "Offload1 Playback",
0104         .nonatomic = 1,
0105         .dynamic = 1,
0106         .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
0107         .dpcm_playback = 1,
0108         SND_SOC_DAILINK_REG(offload1, dummy, platform),
0109     },
0110     {
0111         .name = "Loopback",
0112         .stream_name = "Loopback",
0113         .nonatomic = 1,
0114         .dynamic = 1,
0115         .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
0116         .dpcm_capture = 1,
0117         SND_SOC_DAILINK_REG(loopback, dummy, platform),
0118     },
0119     /* Back End DAI links */
0120     {
0121         /* SSP0 - Codec */
0122         .name = "Codec",
0123         .id = 0,
0124         .nonatomic = 1,
0125         .no_pcm = 1,
0126         .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBC_CFC,
0127         .ignore_pmdown_time = 1,
0128         .be_hw_params_fixup = codec_link_hw_params_fixup,
0129         .ops = &codec_link_ops,
0130         .dpcm_playback = 1,
0131         .dpcm_capture = 1,
0132         SND_SOC_DAILINK_REG(ssp0_port, codec, platform),
0133     },
0134 };
0135 
0136 static struct snd_soc_card hsw_rt5640_card = {
0137     .name = "haswell-rt5640",
0138     .owner = THIS_MODULE,
0139     .dai_link = card_dai_links,
0140     .num_links = ARRAY_SIZE(card_dai_links),
0141     .dapm_widgets = card_widgets,
0142     .num_dapm_widgets = ARRAY_SIZE(card_widgets),
0143     .dapm_routes = card_routes,
0144     .num_dapm_routes = ARRAY_SIZE(card_routes),
0145     .fully_routed = true,
0146 };
0147 
0148 static int hsw_rt5640_probe(struct platform_device *pdev)
0149 {
0150     struct snd_soc_acpi_mach *mach;
0151     struct device *dev = &pdev->dev;
0152     int ret;
0153 
0154     hsw_rt5640_card.dev = dev;
0155     mach = dev_get_platdata(dev);
0156 
0157     ret = snd_soc_fixup_dai_links_platform_name(&hsw_rt5640_card, mach->mach_params.platform);
0158     if (ret)
0159         return ret;
0160 
0161     return devm_snd_soc_register_card(dev, &hsw_rt5640_card);
0162 }
0163 
0164 static struct platform_driver hsw_rt5640_driver = {
0165     .probe = hsw_rt5640_probe,
0166     .driver = {
0167         .name = "hsw_rt5640",
0168         .pm = &snd_soc_pm_ops,
0169     },
0170 };
0171 
0172 module_platform_driver(hsw_rt5640_driver)
0173 
0174 MODULE_AUTHOR("Liam Girdwood, Xingchao Wang");
0175 MODULE_DESCRIPTION("Sound card driver for Intel Haswell Lynx Point with Realtek 5640");
0176 MODULE_LICENSE("GPL");
0177 MODULE_ALIAS("platform:hsw_rt5640");