2019-05-27 06:55:21 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2014-07-14 02:35:40 +00:00
|
|
|
/*
|
2022-06-20 10:13:57 +00:00
|
|
|
* Sound card driver for Intel Broadwell Wildcat Point with Realtek 286
|
2014-07-14 02:35:40 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2013, Intel Corporation. All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <sound/core.h>
|
2014-10-30 13:16:23 +00:00
|
|
|
#include <sound/jack.h>
|
2022-06-20 10:13:56 +00:00
|
|
|
#include <sound/pcm.h>
|
2014-07-14 02:35:40 +00:00
|
|
|
#include <sound/pcm_params.h>
|
2022-06-20 10:13:56 +00:00
|
|
|
#include <sound/soc.h>
|
2019-01-25 20:34:57 +00:00
|
|
|
#include <sound/soc-acpi.h>
|
2015-04-02 07:37:02 +00:00
|
|
|
#include "../../codecs/rt286.h"
|
2014-07-14 02:35:40 +00:00
|
|
|
|
2022-06-20 10:13:54 +00:00
|
|
|
static struct snd_soc_jack card_headset;
|
2022-06-20 10:13:57 +00:00
|
|
|
|
2022-06-20 10:13:54 +00:00
|
|
|
static struct snd_soc_jack_pin card_headset_pins[] = {
|
2014-10-30 13:16:23 +00:00
|
|
|
{
|
|
|
|
.pin = "Mic Jack",
|
|
|
|
.mask = SND_JACK_MICROPHONE,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.pin = "Headphone Jack",
|
|
|
|
.mask = SND_JACK_HEADPHONE,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-06-20 10:13:54 +00:00
|
|
|
static const struct snd_kcontrol_new card_controls[] = {
|
2014-10-30 13:16:23 +00:00
|
|
|
SOC_DAPM_PIN_SWITCH("Speaker"),
|
|
|
|
SOC_DAPM_PIN_SWITCH("Headphone Jack"),
|
|
|
|
};
|
|
|
|
|
2022-06-20 10:13:54 +00:00
|
|
|
static const struct snd_soc_dapm_widget card_widgets[] = {
|
2014-10-30 13:16:23 +00:00
|
|
|
SND_SOC_DAPM_HP("Headphone Jack", NULL),
|
2014-07-14 02:35:40 +00:00
|
|
|
SND_SOC_DAPM_SPK("Speaker", NULL),
|
|
|
|
SND_SOC_DAPM_MIC("Mic Jack", NULL),
|
|
|
|
SND_SOC_DAPM_MIC("DMIC1", NULL),
|
|
|
|
SND_SOC_DAPM_MIC("DMIC2", NULL),
|
|
|
|
SND_SOC_DAPM_LINE("Line Jack", NULL),
|
|
|
|
};
|
|
|
|
|
2022-06-20 10:13:54 +00:00
|
|
|
static const struct snd_soc_dapm_route card_routes[] = {
|
2014-07-14 02:35:40 +00:00
|
|
|
{"Speaker", NULL, "SPOR"},
|
|
|
|
{"Speaker", NULL, "SPOL"},
|
|
|
|
|
2014-10-30 13:16:23 +00:00
|
|
|
{"Headphone Jack", NULL, "HPO Pin"},
|
2014-07-14 02:35:40 +00:00
|
|
|
|
|
|
|
{"MIC1", NULL, "Mic Jack"},
|
|
|
|
{"LINE1", NULL, "Line Jack"},
|
|
|
|
|
|
|
|
{"DMIC1 Pin", NULL, "DMIC1"},
|
|
|
|
{"DMIC2 Pin", NULL, "DMIC2"},
|
|
|
|
|
|
|
|
/* CODEC BE connections */
|
|
|
|
{"SSP0 CODEC IN", NULL, "AIF1 Capture"},
|
|
|
|
{"AIF1 Playback", NULL, "SSP0 CODEC OUT"},
|
|
|
|
};
|
|
|
|
|
2022-06-20 10:13:54 +00:00
|
|
|
static int codec_link_init(struct snd_soc_pcm_runtime *rtd)
|
2014-10-30 13:16:23 +00:00
|
|
|
{
|
2023-09-26 06:24:24 +00:00
|
|
|
struct snd_soc_component *codec = snd_soc_rtd_to_codec(rtd, 0)->component;
|
2022-06-20 10:14:00 +00:00
|
|
|
int ret;
|
2022-06-20 10:13:56 +00:00
|
|
|
|
|
|
|
ret = snd_soc_card_jack_new_pins(rtd->card, "Headset", SND_JACK_HEADSET | SND_JACK_BTN_0,
|
|
|
|
&card_headset, card_headset_pins,
|
|
|
|
ARRAY_SIZE(card_headset_pins));
|
2014-10-30 13:16:23 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2022-06-20 10:14:00 +00:00
|
|
|
return snd_soc_component_set_jack(codec, &card_headset, NULL);
|
2014-10-30 13:16:23 +00:00
|
|
|
}
|
|
|
|
|
2022-11-25 18:40:22 +00:00
|
|
|
static void codec_link_exit(struct snd_soc_pcm_runtime *rtd)
|
|
|
|
{
|
2023-09-26 06:24:24 +00:00
|
|
|
struct snd_soc_component *codec = snd_soc_rtd_to_codec(rtd, 0)->component;
|
2022-11-25 18:40:22 +00:00
|
|
|
|
|
|
|
snd_soc_component_set_jack(codec, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2022-06-20 10:13:54 +00:00
|
|
|
static int codec_link_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
|
2022-06-20 10:13:56 +00:00
|
|
|
struct snd_pcm_hw_params *params)
|
2014-07-14 02:35:40 +00:00
|
|
|
{
|
2022-06-20 10:13:56 +00:00
|
|
|
struct snd_interval *channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
|
|
|
|
struct snd_interval *rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
|
2014-07-14 02:35:40 +00:00
|
|
|
|
2022-06-20 10:13:57 +00:00
|
|
|
/* The ADSP will convert the FE rate to 48kHz, stereo. */
|
2014-07-14 02:35:40 +00:00
|
|
|
rate->min = rate->max = 48000;
|
2022-06-20 10:13:56 +00:00
|
|
|
channels->min = channels->max = 2;
|
2022-06-20 10:13:57 +00:00
|
|
|
/* Set SSP0 to 16 bit. */
|
2015-02-09 08:18:12 +00:00
|
|
|
params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
|
2022-06-20 10:13:56 +00:00
|
|
|
|
2014-07-14 02:35:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-06-20 10:13:54 +00:00
|
|
|
static int codec_link_hw_params(struct snd_pcm_substream *substream,
|
2022-06-20 10:13:56 +00:00
|
|
|
struct snd_pcm_hw_params *params)
|
2014-07-14 02:35:40 +00:00
|
|
|
{
|
2023-09-26 06:24:24 +00:00
|
|
|
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
|
|
|
|
struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
|
2014-07-14 02:35:40 +00:00
|
|
|
int ret;
|
|
|
|
|
2022-06-20 10:13:56 +00:00
|
|
|
ret = snd_soc_dai_set_sysclk(codec_dai, RT286_SCLK_S_PLL, 24000000, SND_SOC_CLOCK_IN);
|
2014-07-14 02:35:40 +00:00
|
|
|
if (ret < 0) {
|
2022-06-20 10:13:59 +00:00
|
|
|
dev_err(rtd->dev, "set codec sysclk failed: %d\n", ret);
|
2014-07-14 02:35:40 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-06-20 10:13:54 +00:00
|
|
|
static const struct snd_soc_ops codec_link_ops = {
|
|
|
|
.hw_params = codec_link_hw_params,
|
2014-07-14 02:35:40 +00:00
|
|
|
};
|
|
|
|
|
2022-06-20 10:13:56 +00:00
|
|
|
SND_SOC_DAILINK_DEF(system, DAILINK_COMP_ARRAY(COMP_CPU("System Pin")));
|
|
|
|
SND_SOC_DAILINK_DEF(offload0, DAILINK_COMP_ARRAY(COMP_CPU("Offload0 Pin")));
|
|
|
|
SND_SOC_DAILINK_DEF(offload1, DAILINK_COMP_ARRAY(COMP_CPU("Offload1 Pin")));
|
|
|
|
SND_SOC_DAILINK_DEF(loopback, DAILINK_COMP_ARRAY(COMP_CPU("Loopback Pin")));
|
2019-06-06 04:19:40 +00:00
|
|
|
|
2022-06-20 10:13:56 +00:00
|
|
|
SND_SOC_DAILINK_DEF(dummy, DAILINK_COMP_ARRAY(COMP_DUMMY()));
|
|
|
|
SND_SOC_DAILINK_DEF(platform, DAILINK_COMP_ARRAY(COMP_PLATFORM("haswell-pcm-audio")));
|
|
|
|
SND_SOC_DAILINK_DEF(codec, DAILINK_COMP_ARRAY(COMP_CODEC("i2c-INT343A:00", "rt286-aif1")));
|
|
|
|
SND_SOC_DAILINK_DEF(ssp0_port, DAILINK_COMP_ARRAY(COMP_CPU("ssp0-port")));
|
2020-01-10 23:57:46 +00:00
|
|
|
|
2022-06-20 10:13:54 +00:00
|
|
|
static struct snd_soc_dai_link card_dai_links[] = {
|
2014-07-14 02:35:40 +00:00
|
|
|
/* Front End DAI links */
|
|
|
|
{
|
|
|
|
.name = "System PCM",
|
2014-11-28 13:52:11 +00:00
|
|
|
.stream_name = "System Playback/Capture",
|
2020-10-04 09:06:08 +00:00
|
|
|
.nonatomic = 1,
|
2014-07-14 02:35:40 +00:00
|
|
|
.dynamic = 1,
|
|
|
|
.trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
|
|
|
|
.dpcm_playback = 1,
|
2014-11-28 13:52:11 +00:00
|
|
|
.dpcm_capture = 1,
|
2019-06-06 04:19:40 +00:00
|
|
|
SND_SOC_DAILINK_REG(system, dummy, platform),
|
2014-07-14 02:35:40 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "Offload0",
|
|
|
|
.stream_name = "Offload0 Playback",
|
2020-10-04 09:06:08 +00:00
|
|
|
.nonatomic = 1,
|
2014-07-14 02:35:40 +00:00
|
|
|
.dynamic = 1,
|
|
|
|
.trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
|
|
|
|
.dpcm_playback = 1,
|
2019-06-06 04:19:40 +00:00
|
|
|
SND_SOC_DAILINK_REG(offload0, dummy, platform),
|
2014-07-14 02:35:40 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "Offload1",
|
|
|
|
.stream_name = "Offload1 Playback",
|
2020-10-04 09:06:08 +00:00
|
|
|
.nonatomic = 1,
|
2014-07-14 02:35:40 +00:00
|
|
|
.dynamic = 1,
|
|
|
|
.trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
|
|
|
|
.dpcm_playback = 1,
|
2019-06-06 04:19:40 +00:00
|
|
|
SND_SOC_DAILINK_REG(offload1, dummy, platform),
|
2014-07-14 02:35:40 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "Loopback PCM",
|
|
|
|
.stream_name = "Loopback",
|
2020-10-04 09:06:08 +00:00
|
|
|
.nonatomic = 1,
|
2018-12-18 08:24:54 +00:00
|
|
|
.dynamic = 1,
|
2014-07-14 02:35:40 +00:00
|
|
|
.trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
|
|
|
|
.dpcm_capture = 1,
|
2019-06-06 04:19:40 +00:00
|
|
|
SND_SOC_DAILINK_REG(loopback, dummy, platform),
|
2014-07-14 02:35:40 +00:00
|
|
|
},
|
|
|
|
/* Back End DAI links */
|
|
|
|
{
|
|
|
|
/* SSP0 - Codec */
|
|
|
|
.name = "Codec",
|
2016-04-19 05:12:35 +00:00
|
|
|
.id = 0,
|
2022-06-24 13:43:15 +00:00
|
|
|
.nonatomic = 1,
|
2014-07-14 02:35:40 +00:00
|
|
|
.no_pcm = 1,
|
2022-06-20 10:13:54 +00:00
|
|
|
.init = codec_link_init,
|
2022-11-25 18:40:22 +00:00
|
|
|
.exit = codec_link_exit,
|
2022-06-20 10:13:56 +00:00
|
|
|
.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBC_CFC,
|
2014-07-14 02:35:40 +00:00
|
|
|
.ignore_pmdown_time = 1,
|
2022-06-20 10:13:54 +00:00
|
|
|
.be_hw_params_fixup = codec_link_hw_params_fixup,
|
|
|
|
.ops = &codec_link_ops,
|
2014-07-14 02:35:40 +00:00
|
|
|
.dpcm_playback = 1,
|
|
|
|
.dpcm_capture = 1,
|
2020-01-10 23:57:46 +00:00
|
|
|
SND_SOC_DAILINK_REG(ssp0_port, codec, platform),
|
2014-07-14 02:35:40 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-11-25 18:40:22 +00:00
|
|
|
static int card_suspend_pre(struct snd_soc_card *card)
|
2020-04-27 16:29:53 +00:00
|
|
|
{
|
2022-11-25 18:40:22 +00:00
|
|
|
struct snd_soc_dai *codec_dai = snd_soc_card_get_codec_dai(card, "rt286-aif1");
|
2022-06-05 15:39:04 +00:00
|
|
|
|
2023-07-31 21:37:46 +00:00
|
|
|
if (!codec_dai)
|
|
|
|
return 0;
|
|
|
|
|
2022-11-25 18:40:22 +00:00
|
|
|
return snd_soc_component_set_jack(codec_dai->component, NULL, NULL);
|
2020-04-27 16:29:53 +00:00
|
|
|
}
|
|
|
|
|
2022-11-25 18:40:22 +00:00
|
|
|
static int card_resume_post(struct snd_soc_card *card)
|
2022-06-20 10:13:56 +00:00
|
|
|
{
|
2022-11-25 18:40:22 +00:00
|
|
|
struct snd_soc_dai *codec_dai = snd_soc_card_get_codec_dai(card, "rt286-aif1");
|
2022-06-20 10:13:56 +00:00
|
|
|
|
2023-07-31 21:37:46 +00:00
|
|
|
if (!codec_dai)
|
|
|
|
return 0;
|
|
|
|
|
2022-11-25 18:40:22 +00:00
|
|
|
return snd_soc_component_set_jack(codec_dai->component, &card_headset, NULL);
|
2015-02-27 04:54:29 +00:00
|
|
|
}
|
|
|
|
|
2022-06-20 10:13:54 +00:00
|
|
|
static struct snd_soc_card bdw_rt286_card = {
|
2014-07-14 02:35:40 +00:00
|
|
|
.owner = THIS_MODULE,
|
2022-11-25 18:40:22 +00:00
|
|
|
.suspend_pre = card_suspend_pre,
|
|
|
|
.resume_post = card_resume_post,
|
2022-06-20 10:13:54 +00:00
|
|
|
.dai_link = card_dai_links,
|
|
|
|
.num_links = ARRAY_SIZE(card_dai_links),
|
|
|
|
.controls = card_controls,
|
|
|
|
.num_controls = ARRAY_SIZE(card_controls),
|
|
|
|
.dapm_widgets = card_widgets,
|
|
|
|
.num_dapm_widgets = ARRAY_SIZE(card_widgets),
|
|
|
|
.dapm_routes = card_routes,
|
|
|
|
.num_dapm_routes = ARRAY_SIZE(card_routes),
|
2014-07-14 02:35:40 +00:00
|
|
|
.fully_routed = true,
|
|
|
|
};
|
|
|
|
|
2022-06-20 10:13:58 +00:00
|
|
|
/* Use space before codec name to simplify card ID, and simplify driver name. */
|
|
|
|
#define SOF_CARD_NAME "bdw rt286" /* card name will be 'sof-bdw rt286' */
|
|
|
|
#define SOF_DRIVER_NAME "SOF"
|
|
|
|
|
|
|
|
#define CARD_NAME "broadwell-rt286"
|
|
|
|
|
2022-06-20 10:13:54 +00:00
|
|
|
static int bdw_rt286_probe(struct platform_device *pdev)
|
2014-07-14 02:35:40 +00:00
|
|
|
{
|
2019-01-25 20:34:57 +00:00
|
|
|
struct snd_soc_acpi_mach *mach;
|
2022-06-20 10:13:58 +00:00
|
|
|
struct device *dev = &pdev->dev;
|
2019-01-25 20:34:57 +00:00
|
|
|
int ret;
|
|
|
|
|
2022-06-20 10:13:58 +00:00
|
|
|
bdw_rt286_card.dev = dev;
|
|
|
|
mach = dev_get_platdata(dev);
|
2022-06-20 10:13:56 +00:00
|
|
|
|
|
|
|
ret = snd_soc_fixup_dai_links_platform_name(&bdw_rt286_card, mach->mach_params.platform);
|
2019-01-25 20:34:57 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2022-06-20 10:13:58 +00:00
|
|
|
if (snd_soc_acpi_sof_parent(dev)) {
|
2022-06-20 10:13:54 +00:00
|
|
|
bdw_rt286_card.name = SOF_CARD_NAME;
|
|
|
|
bdw_rt286_card.driver_name = SOF_DRIVER_NAME;
|
2020-11-12 22:38:22 +00:00
|
|
|
} else {
|
2022-06-20 10:13:54 +00:00
|
|
|
bdw_rt286_card.name = CARD_NAME;
|
2020-11-12 22:38:22 +00:00
|
|
|
}
|
|
|
|
|
2022-06-20 10:13:58 +00:00
|
|
|
return devm_snd_soc_register_card(dev, &bdw_rt286_card);
|
2014-07-14 02:35:40 +00:00
|
|
|
}
|
|
|
|
|
2022-06-20 10:13:54 +00:00
|
|
|
static struct platform_driver bdw_rt286_driver = {
|
|
|
|
.probe = bdw_rt286_probe,
|
2014-07-14 02:35:40 +00:00
|
|
|
.driver = {
|
2022-06-20 10:13:55 +00:00
|
|
|
.name = "bdw_rt286",
|
2020-11-12 22:38:12 +00:00
|
|
|
.pm = &snd_soc_pm_ops
|
2014-07-14 02:35:40 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-06-20 10:13:54 +00:00
|
|
|
module_platform_driver(bdw_rt286_driver)
|
2014-07-14 02:35:40 +00:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Liam Girdwood, Xingchao Wang");
|
2022-06-20 10:13:57 +00:00
|
|
|
MODULE_DESCRIPTION("Sound card driver for Intel Broadwell Wildcat Point with Realtek 286");
|
|
|
|
MODULE_LICENSE("GPL");
|
2022-06-20 10:13:55 +00:00
|
|
|
MODULE_ALIAS("platform:bdw_rt286");
|