Unverified Commit 5a7d9aaf authored by Mark Brown's avatar Mark Brown
Browse files

ASoC: Intel: machine driver update

Merge series from Bard Liao <yung-chuan.liao@linux.intel.com>:

Some cleanups from Brent Lu for I2S platforms. And minor additions for
RVPs and Chromebooks.
parents 925819c7 5f017134
Loading
Loading
Loading
Loading
+17 −7
Original line number Diff line number Diff line
@@ -38,6 +38,12 @@ config SND_SOC_INTEL_SOF_REALTEK_COMMON
config SND_SOC_INTEL_SOF_CIRRUS_COMMON
	tristate

config SND_SOC_INTEL_SOF_NUVOTON_COMMON
	tristate

config SND_SOC_INTEL_SOF_SSP_COMMON
	tristate

if SND_SOC_INTEL_CATPT

config SND_SOC_INTEL_HASWELL_MACH
@@ -493,6 +499,7 @@ config SND_SOC_INTEL_SOF_RT5682_MACH
	select SND_SOC_INTEL_HDA_DSP_COMMON
	select SND_SOC_INTEL_SOF_MAXIM_COMMON
	select SND_SOC_INTEL_SOF_REALTEK_COMMON
	select SND_SOC_INTEL_SOF_SSP_COMMON
	help
	   This adds support for ASoC machine driver for SOF platforms
	   with rt5650 or rt5682 codec.
@@ -510,6 +517,7 @@ config SND_SOC_INTEL_SOF_CS42L42_MACH
	select SND_SOC_HDAC_HDMI
	select SND_SOC_INTEL_HDA_DSP_COMMON
	select SND_SOC_INTEL_SOF_MAXIM_COMMON
	select SND_SOC_INTEL_SOF_SSP_COMMON
	help
	   This adds support for ASoC machine driver for SOF platforms
	   with cs42l42 codec.
@@ -560,7 +568,9 @@ config SND_SOC_INTEL_SOF_NAU8825_MACH
	select SND_SOC_HDAC_HDMI
	select SND_SOC_INTEL_HDA_DSP_COMMON
	select SND_SOC_INTEL_SOF_MAXIM_COMMON
	select SND_SOC_INTEL_SOF_NUVOTON_COMMON
	select SND_SOC_INTEL_SOF_REALTEK_COMMON
	select SND_SOC_INTEL_SOF_SSP_COMMON
	help
	   This adds support for ASoC machine driver for SOF platforms
	   with nau8825 codec.
@@ -600,25 +610,24 @@ config SND_SOC_INTEL_SOF_CML_RT1011_RT5682_MACH

endif ## SND_SOC_SOF_COMETLAKE && SND_SOC_SOF_HDA_LINK

if SND_SOC_SOF_JASPERLAKE

config SND_SOC_INTEL_SOF_DA7219_MAX98373_MACH
	tristate "SOF with DA7219 and MAX98373/MAX98360A in I2S Mode"
config SND_SOC_INTEL_SOF_DA7219_MACH
	tristate "SOF with DA7219 codec in I2S Mode"
	depends on I2C && ACPI
	depends on MFD_INTEL_LPSS || COMPILE_TEST
	depends on SND_HDA_CODEC_HDMI && SND_SOC_SOF_HDA_AUDIO_CODEC
	select SND_SOC_INTEL_HDA_DSP_COMMON
	select SND_SOC_DA7219
	select SND_SOC_MAX98357A
	select SND_SOC_MAX98373_I2C
	select SND_SOC_DMIC
	select SND_SOC_INTEL_SOF_MAXIM_COMMON
	select SND_SOC_INTEL_SOF_SSP_COMMON
	help
	  This adds support for ASoC machine driver for SOF platforms
	  with DA7219 + MAX98373/MAX98360A I2S audio codec.
	  with Dialog DA7219 I2S audio codec.
	  Say Y if you have such a device.
	  If unsure select "N".

endif ## SND_SOC_SOF_JASPERLAKE

if SND_SOC_SOF_HDA_LINK

config SND_SOC_INTEL_SOF_SSP_AMP_MACH
@@ -632,6 +641,7 @@ config SND_SOC_INTEL_SOF_SSP_AMP_MACH
	select SND_SOC_INTEL_HDA_DSP_COMMON
	select SND_SOC_INTEL_SOF_REALTEK_COMMON
	select SND_SOC_INTEL_SOF_CIRRUS_COMMON
	select SND_SOC_INTEL_SOF_SSP_COMMON
	help
	   This adds support for ASoC machine driver for SOF platforms
	   with RT1308/CS35L41 I2S audio codec.
+8 −2
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ snd-soc-sof_rt5682-objs := sof_rt5682.o
snd-soc-sof_cs42l42-objs := sof_cs42l42.o
snd-soc-sof_es8336-objs := sof_es8336.o
snd-soc-sof_nau8825-objs := sof_nau8825.o
snd-soc-sof_da7219-objs := sof_da7219.o
snd-soc-cml_rt1011_rt5682-objs := cml_rt1011_rt5682.o
snd-soc-kbl_da7219_max98357a-objs := kbl_da7219_max98357a.o
snd-soc-kbl_da7219_max98927-objs := kbl_da7219_max98927.o
@@ -33,7 +34,6 @@ snd-soc-skl_rt286-objs := skl_rt286.o
snd-soc-skl_hda_dsp-objs := skl_hda_dsp_generic.o skl_hda_dsp_common.o
snd-skl_nau88l25_max98357a-objs := skl_nau88l25_max98357a.o
snd-soc-skl_nau88l25_ssm4567-objs := skl_nau88l25_ssm4567.o
snd-soc-sof_da7219_max98373-objs := sof_da7219_max98373.o
snd-soc-ehl-rt5660-objs := ehl_rt5660.o
snd-soc-sof-ssp-amp-objs := sof_ssp_amp.o
snd-soc-sof-sdw-objs += sof_sdw.o				\
@@ -48,6 +48,7 @@ obj-$(CONFIG_SND_SOC_INTEL_SOF_RT5682_MACH) += snd-soc-sof_rt5682.o
obj-$(CONFIG_SND_SOC_INTEL_SOF_CS42L42_MACH) += snd-soc-sof_cs42l42.o
obj-$(CONFIG_SND_SOC_INTEL_SOF_ES8336_MACH) += snd-soc-sof_es8336.o
obj-$(CONFIG_SND_SOC_INTEL_SOF_NAU8825_MACH) += snd-soc-sof_nau8825.o
obj-$(CONFIG_SND_SOC_INTEL_SOF_DA7219_MACH) += snd-soc-sof_da7219.o
obj-$(CONFIG_SND_SOC_INTEL_HASWELL_MACH) += snd-soc-hsw-rt5640.o
obj-$(CONFIG_SND_SOC_INTEL_BXT_DA7219_MAX98357A_COMMON) += snd-soc-sst-bxt-da7219_max98357a.o
obj-$(CONFIG_SND_SOC_INTEL_BXT_RT298_MACH) += snd-soc-sst-bxt-rt298.o
@@ -78,7 +79,6 @@ obj-$(CONFIG_SND_SOC_INTEL_SKL_RT286_MACH) += snd-soc-skl_rt286.o
obj-$(CONFIG_SND_SOC_INTEL_SKL_NAU88L25_MAX98357A_MACH) += snd-skl_nau88l25_max98357a.o
obj-$(CONFIG_SND_SOC_INTEL_SKL_NAU88L25_SSM4567_MACH) += snd-soc-skl_nau88l25_ssm4567.o
obj-$(CONFIG_SND_SOC_INTEL_SKL_HDA_DSP_GENERIC_MACH) += snd-soc-skl_hda_dsp.o
obj-$(CONFIG_SND_SOC_INTEL_SOF_DA7219_MAX98373_MACH) += snd-soc-sof_da7219_max98373.o
obj-$(CONFIG_SND_SOC_INTEL_EHL_RT5660_MACH) += snd-soc-ehl-rt5660.o
obj-$(CONFIG_SND_SOC_INTEL_SOUNDWIRE_SOF_MACH) += snd-soc-sof-sdw.o
obj-$(CONFIG_SND_SOC_INTEL_SOF_SSP_AMP_MACH) += snd-soc-sof-ssp-amp.o
@@ -95,3 +95,9 @@ obj-$(CONFIG_SND_SOC_INTEL_SOF_REALTEK_COMMON) += snd-soc-intel-sof-realtek-comm

snd-soc-intel-sof-cirrus-common-objs += sof_cirrus_common.o
obj-$(CONFIG_SND_SOC_INTEL_SOF_CIRRUS_COMMON) += snd-soc-intel-sof-cirrus-common.o

snd-soc-intel-sof-nuvoton-common-objs += sof_nuvoton_common.o
obj-$(CONFIG_SND_SOC_INTEL_SOF_NUVOTON_COMMON) += snd-soc-intel-sof-nuvoton-common.o

snd-soc-intel-sof-ssp-common-objs += sof_ssp_common.o
obj-$(CONFIG_SND_SOC_INTEL_SOF_SSP_COMMON) += snd-soc-intel-sof-ssp-common.o
+5 −4
Original line number Diff line number Diff line
@@ -9,15 +9,16 @@
#define __SOF_CIRRUS_COMMON_H

#include <sound/soc.h>
#include "sof_ssp_common.h"

/*
 * Cirrus Logic CS35L41/CS35L53
 */
#define CS35L41_CODEC_DAI	"cs35l41-pcm"
#define CS35L41_DEV0_NAME	"i2c-CSC3541:00"
#define CS35L41_DEV1_NAME	"i2c-CSC3541:01"
#define CS35L41_DEV2_NAME	"i2c-CSC3541:02"
#define CS35L41_DEV3_NAME	"i2c-CSC3541:03"
#define CS35L41_DEV0_NAME	"i2c-" CS35L41_ACPI_HID ":00"
#define CS35L41_DEV1_NAME	"i2c-" CS35L41_ACPI_HID ":01"
#define CS35L41_DEV2_NAME	"i2c-" CS35L41_ACPI_HID ":02"
#define CS35L41_DEV3_NAME	"i2c-" CS35L41_ACPI_HID ":03"

void cs35l41_set_dai_link(struct snd_soc_dai_link *link);
void cs35l41_set_codec_conf(struct snd_soc_card *card);
+28 −27
Original line number Diff line number Diff line
@@ -23,12 +23,12 @@
#include "../common/soc-intel-quirks.h"
#include "hda_dsp_common.h"
#include "sof_maxim_common.h"
#include "sof_ssp_common.h"

#define NAME_SIZE 32

#define SOF_CS42L42_SSP_CODEC(quirk)		((quirk) & GENMASK(2, 0))
#define SOF_CS42L42_SSP_CODEC_MASK		(GENMASK(2, 0))
#define SOF_SPEAKER_AMP_PRESENT			BIT(3)
#define SOF_CS42L42_SSP_AMP_SHIFT		4
#define SOF_CS42L42_SSP_AMP_MASK		(GENMASK(6, 4))
#define SOF_CS42L42_SSP_AMP(quirk)	\
@@ -46,8 +46,6 @@
#define SOF_CS42L42_SSP_BT_MASK			(GENMASK(28, 26))
#define SOF_CS42L42_SSP_BT(quirk)	\
	(((quirk) << SOF_CS42L42_SSP_BT_SHIFT) & SOF_CS42L42_SSP_BT_MASK)
#define SOF_MAX98357A_SPEAKER_AMP_PRESENT	BIT(29)
#define SOF_MAX98360A_SPEAKER_AMP_PRESENT	BIT(30)

enum {
	LINK_NONE = 0,
@@ -83,6 +81,8 @@ struct sof_card_private {
	struct snd_soc_jack headset_jack;
	struct list_head hdmi_pcm_list;
	bool common_hdmi_codec_drv;
	enum sof_ssp_codec codec_type;
	enum sof_ssp_codec amp_type;
};

static int sof_hdmi_init(struct snd_soc_pcm_runtime *rtd)
@@ -299,12 +299,13 @@ static struct snd_soc_dai_link_component dmic_component[] = {
static int create_spk_amp_dai_links(struct device *dev,
				    struct snd_soc_dai_link *links,
				    struct snd_soc_dai_link_component *cpus,
				    int *id, int ssp_amp)
				    int *id, enum sof_ssp_codec amp_type,
				    int ssp_amp)
{
	int ret = 0;

	/* speaker amp */
	if (!(sof_cs42l42_quirk & SOF_SPEAKER_AMP_PRESENT))
	if (amp_type == CODEC_NONE)
		return 0;

	links[*id].name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-Codec",
@@ -316,14 +317,16 @@ static int create_spk_amp_dai_links(struct device *dev,

	links[*id].id = *id;

	if (sof_cs42l42_quirk & SOF_MAX98357A_SPEAKER_AMP_PRESENT) {
	switch (amp_type) {
	case CODEC_MAX98357A:
		max_98357a_dai_link(&links[*id]);
	} else if (sof_cs42l42_quirk & SOF_MAX98360A_SPEAKER_AMP_PRESENT) {
		break;
	case CODEC_MAX98360A:
		max_98360a_dai_link(&links[*id]);
	} else {
		dev_err(dev, "no amp defined\n");
		ret = -EINVAL;
		goto devm_err;
		break;
	default:
		dev_err(dev, "invalid amp type %d\n", amp_type);
		return -EINVAL;
	}

	links[*id].platforms = platform_component;
@@ -528,12 +531,10 @@ static int create_bt_offload_dai_links(struct device *dev,
	return -ENOMEM;
}

static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev,
							  int ssp_codec,
							  int ssp_amp,
							  int ssp_bt,
							  int dmic_be_num,
							  int hdmi_num)
static struct snd_soc_dai_link *
sof_card_dai_links_create(struct device *dev, enum sof_ssp_codec amp_type,
			  int ssp_codec, int ssp_amp, int ssp_bt,
			  int dmic_be_num, int hdmi_num)
{
	struct snd_soc_dai_link_component *cpus;
	struct snd_soc_dai_link *links;
@@ -561,7 +562,8 @@ static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev,
			}
			break;
		case LINK_SPK:
			ret = create_spk_amp_dai_links(dev, links, cpus, &id, ssp_amp);
			ret = create_spk_amp_dai_links(dev, links, cpus, &id,
						       amp_type, ssp_amp);
			if (ret < 0) {
				dev_err(dev, "fail to create spk amp dai links, ret %d\n",
					ret);
@@ -624,6 +626,9 @@ static int sof_audio_probe(struct platform_device *pdev)

	mach = pdev->dev.platform_data;

	ctx->codec_type = sof_ssp_detect_codec_type(&pdev->dev);
	ctx->amp_type = sof_ssp_detect_amp_type(&pdev->dev);

	if (soc_intel_is_glk()) {
		dmic_be_num = 1;
		hdmi_num = 3;
@@ -649,13 +654,14 @@ static int sof_audio_probe(struct platform_device *pdev)
	/* compute number of dai links */
	sof_audio_card_cs42l42.num_links = 1 + dmic_be_num + hdmi_num;

	if (sof_cs42l42_quirk & SOF_SPEAKER_AMP_PRESENT)
	if (ctx->amp_type != CODEC_NONE)
		sof_audio_card_cs42l42.num_links++;
	if (sof_cs42l42_quirk & SOF_BT_OFFLOAD_PRESENT)
		sof_audio_card_cs42l42.num_links++;

	dai_links = sof_card_dai_links_create(&pdev->dev, ssp_codec, ssp_amp,
					      ssp_bt, dmic_be_num, hdmi_num);
	dai_links = sof_card_dai_links_create(&pdev->dev, ctx->amp_type,
					      ssp_codec, ssp_amp, ssp_bt,
					      dmic_be_num, hdmi_num);
	if (!dai_links)
		return -ENOMEM;

@@ -683,24 +689,18 @@ static const struct platform_device_id board_ids[] = {
	{
		.name = "glk_cs4242_mx98357a",
		.driver_data = (kernel_ulong_t)(SOF_CS42L42_SSP_CODEC(2) |
					SOF_SPEAKER_AMP_PRESENT |
					SOF_MAX98357A_SPEAKER_AMP_PRESENT |
					SOF_CS42L42_SSP_AMP(1)) |
					SOF_CS42L42_DAILINK(LINK_SPK, LINK_HP, LINK_DMIC, LINK_HDMI, LINK_NONE),
	},
	{
		.name = "jsl_cs4242_mx98360a",
		.driver_data = (kernel_ulong_t)(SOF_CS42L42_SSP_CODEC(0) |
					SOF_SPEAKER_AMP_PRESENT |
					SOF_MAX98360A_SPEAKER_AMP_PRESENT |
					SOF_CS42L42_SSP_AMP(1)) |
					SOF_CS42L42_DAILINK(LINK_HP, LINK_DMIC, LINK_HDMI, LINK_SPK, LINK_NONE),
	},
	{
		.name = "adl_mx98360a_cs4242",
		.driver_data = (kernel_ulong_t)(SOF_CS42L42_SSP_CODEC(0) |
				SOF_SPEAKER_AMP_PRESENT |
				SOF_MAX98360A_SPEAKER_AMP_PRESENT |
				SOF_CS42L42_SSP_AMP(1) |
				SOF_CS42L42_NUM_HDMIDEV(4) |
				SOF_BT_OFFLOAD_PRESENT |
@@ -727,3 +727,4 @@ MODULE_AUTHOR("Brent Lu <brent.lu@intel.com>");
MODULE_LICENSE("GPL");
MODULE_IMPORT_NS(SND_SOC_INTEL_HDA_DSP_COMMON);
MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_MAXIM_COMMON);
MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_SSP_COMMON);
+232 −129
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@
// Copyright(c) 2019 Intel Corporation.

/*
 * Intel SOF Machine driver for DA7219 + MAX98373/MAX98360A codec
 * Intel SOF Machine driver for Dialog headphone codec
 */

#include <linux/input.h>
@@ -13,13 +13,16 @@
#include <linux/platform_device.h>
#include <sound/soc.h>
#include <sound/soc-acpi.h>
#include <sound/sof.h>
#include "../../codecs/da7219.h"
#include "hda_dsp_common.h"
#include "sof_maxim_common.h"
#include "sof_ssp_common.h"

/* Board Quirks */
#define SOF_DA7219_JSL_BOARD			BIT(2)

#define DIALOG_CODEC_DAI	"da7219-hifi"
#define MAX98373_CODEC_DAI	"max98373-aif1"
#define MAXIM_DEV0_NAME		"i2c-MX98373:00"
#define MAXIM_DEV1_NAME		"i2c-MX98373:01"

struct hdmi_pcm {
	struct list_head head;
@@ -28,9 +31,13 @@ struct hdmi_pcm {
};

struct card_private {
	struct snd_soc_jack headset;
	struct snd_soc_jack headset_jack;
	struct list_head hdmi_pcm_list;
	struct snd_soc_jack hdmi[3];
	enum sof_ssp_codec codec_type;
	enum sof_ssp_codec amp_type;

	unsigned int pll_bypass:1;
};

static int platform_clock_control(struct snd_soc_dapm_widget *w,
@@ -38,9 +45,14 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w,
{
	struct snd_soc_dapm_context *dapm = w->dapm;
	struct snd_soc_card *card = dapm->card;
	struct card_private *ctx = snd_soc_card_get_drvdata(card);
	struct snd_soc_dai *codec_dai;
	int ret = 0;

	if (ctx->pll_bypass)
		return ret;

	/* PLL SRM mode */
	codec_dai = snd_soc_card_get_codec_dai(card, DIALOG_CODEC_DAI);
	if (!codec_dai) {
		dev_err(card->dev, "Codec dai not found; Unable to set/unset codec pll\n");
@@ -53,6 +65,8 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w,
		if (ret)
			dev_err(card->dev, "failed to stop PLL: %d\n", ret);
	} else if (SND_SOC_DAPM_EVENT_ON(event)) {
		dev_dbg(card->dev, "pll srm mode\n");

		ret = snd_soc_dai_set_pll(codec_dai, 0, DA7219_SYSCLK_PLL_SRM,
					  0, DA7219_PLL_FREQ_OUT_98304);
		if (ret)
@@ -70,14 +84,6 @@ static const struct snd_kcontrol_new controls[] = {
	SOC_DAPM_PIN_SWITCH("Right Spk"),
};

static const struct snd_kcontrol_new m98360a_controls[] = {
	SOC_DAPM_PIN_SWITCH("Headphone Jack"),
	SOC_DAPM_PIN_SWITCH("Headset Mic"),
	SOC_DAPM_PIN_SWITCH("Line Out"),
	SOC_DAPM_PIN_SWITCH("Spk"),
};

/* For MAX98373 amp */
static const struct snd_soc_dapm_widget widgets[] = {
	SND_SOC_DAPM_HP("Headphone Jack", NULL),
	SND_SOC_DAPM_MIC("Headset Mic", NULL),
@@ -103,40 +109,6 @@ static const struct snd_soc_dapm_route audio_map[] = {
	{ "Headset Mic", NULL, "Platform Clock" },
	{ "Line Out", NULL, "Platform Clock" },

	{ "Left Spk", NULL, "Left BE_OUT" },
	{ "Right Spk", NULL, "Right BE_OUT" },

	/* digital mics */
	{"DMic", NULL, "SoC DMIC"},
};

/* For MAX98360A amp */
static const struct snd_soc_dapm_widget max98360a_widgets[] = {
	SND_SOC_DAPM_HP("Headphone Jack", NULL),
	SND_SOC_DAPM_MIC("Headset Mic", NULL),
	SND_SOC_DAPM_LINE("Line Out", NULL),

	SND_SOC_DAPM_SPK("Spk", NULL),

	SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
			    platform_clock_control, SND_SOC_DAPM_POST_PMD |
			    SND_SOC_DAPM_PRE_PMU),

	SND_SOC_DAPM_MIC("SoC DMIC", NULL),
};

static const struct snd_soc_dapm_route max98360a_map[] = {
	{ "Headphone Jack", NULL, "HPL" },
	{ "Headphone Jack", NULL, "HPR" },

	{ "MIC", NULL, "Headset Mic" },

	{ "Headphone Jack", NULL, "Platform Clock" },
	{ "Headset Mic", NULL, "Platform Clock" },
	{ "Line Out", NULL, "Platform Clock" },

	{"Spk", NULL, "Speaker"},

	/* digital mics */
	{"DMic", NULL, "SoC DMIC"},
};
@@ -156,23 +128,44 @@ static struct snd_soc_jack_pin jack_pins[] = {
	},
};

static struct snd_soc_jack headset;

static int da7219_codec_init(struct snd_soc_pcm_runtime *rtd)
{
	struct card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
	struct snd_soc_component *component = codec_dai->component;
	struct snd_soc_jack *jack;
	int ret;
	struct snd_soc_jack *jack = &ctx->headset_jack;
	int mclk_rate, ret;

	/* Configure sysclk for codec */
	ret = snd_soc_dai_set_sysclk(codec_dai, DA7219_CLKSRC_MCLK, 24000000,
	mclk_rate = sof_dai_get_mclk(rtd);
	if (mclk_rate <= 0) {
		dev_err(rtd->dev, "invalid mclk freq %d\n", mclk_rate);
		return -EINVAL;
	}

	ret = snd_soc_dai_set_sysclk(codec_dai, DA7219_CLKSRC_MCLK, mclk_rate,
				     SND_SOC_CLOCK_IN);
	if (ret) {
		dev_err(rtd->dev, "can't set codec sysclk configuration\n");
		dev_err(rtd->dev, "fail to set sysclk, ret %d\n", ret);
		return ret;
	}

	/*
	 * Use PLL bypass mode if MCLK is available, be sure to set the
	 * frequency of MCLK to 12.288 or 24.576MHz on topology side.
	 */
	if (mclk_rate == 12288000 || mclk_rate == 24576000) {
		/* PLL bypass mode */
		dev_dbg(rtd->dev, "pll bypass mode, mclk rate %d\n", mclk_rate);

		ret = snd_soc_dai_set_pll(codec_dai, 0, DA7219_SYSCLK_MCLK, 0, 0);
		if (ret) {
			dev_err(rtd->dev, "fail to set pll, ret %d\n", ret);
			return ret;
		}

		ctx->pll_bypass = 1;
	}

	/*
	 * Headset buttons map to the google Reference headset.
	 * These can be configured by userspace.
@@ -181,25 +174,27 @@ static int da7219_codec_init(struct snd_soc_pcm_runtime *rtd)
					 SND_JACK_HEADSET | SND_JACK_BTN_0 |
					 SND_JACK_BTN_1 | SND_JACK_BTN_2 |
					 SND_JACK_BTN_3 | SND_JACK_LINEOUT,
					 &headset,
					 jack_pins,
					 ARRAY_SIZE(jack_pins));
					 jack, jack_pins, ARRAY_SIZE(jack_pins));
	if (ret) {
		dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
		return ret;
	}

	jack = &headset;
	snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
	snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOLUMEUP);
	snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN);
	snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOICECOMMAND);
	snd_soc_component_set_jack(component, jack, NULL);

	ret = snd_soc_component_set_jack(component, jack, NULL);
	if (ret) {
		dev_err(rtd->dev, "fail to set component jack, ret %d\n", ret);
		return ret;
	}

	return ret;
}

static int ssp1_hw_params(struct snd_pcm_substream *substream,
static int max98373_hw_params(struct snd_pcm_substream *substream,
			      struct snd_pcm_hw_params *params)
{
	struct snd_soc_pcm_runtime *runtime = asoc_substream_to_rtd(substream);
@@ -208,7 +203,7 @@ static int ssp1_hw_params(struct snd_pcm_substream *substream,
	for (j = 0; j < runtime->dai_link->num_codecs; j++) {
		struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(runtime, j);

		if (!strcmp(codec_dai->component->name, MAXIM_DEV0_NAME)) {
		if (!strcmp(codec_dai->component->name, MAX_98373_DEV0_NAME)) {
			/* vmon_slot_no = 0 imon_slot_no = 1 for TX slots */
			ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x3, 3, 4, 16);
			if (ret < 0) {
@@ -216,7 +211,7 @@ static int ssp1_hw_params(struct snd_pcm_substream *substream,
				return ret;
			}
		}
		if (!strcmp(codec_dai->component->name, MAXIM_DEV1_NAME)) {
		if (!strcmp(codec_dai->component->name, MAX_98373_DEV1_NAME)) {
			/* vmon_slot_no = 2 imon_slot_no = 3 for TX slots */
			ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xC, 3, 4, 16);
			if (ret < 0) {
@@ -229,19 +224,8 @@ static int ssp1_hw_params(struct snd_pcm_substream *substream,
	return 0;
}

static struct snd_soc_ops ssp1_ops = {
	.hw_params = ssp1_hw_params,
};

static struct snd_soc_codec_conf max98373_codec_conf[] = {
	{
		.dlc = COMP_CODEC_CONF(MAXIM_DEV0_NAME),
		.name_prefix = "Right",
	},
	{
		.dlc = COMP_CODEC_CONF(MAXIM_DEV1_NAME),
		.name_prefix = "Left",
	},
static const struct snd_soc_ops max98373_ops = {
	.hw_params = max98373_hw_params,
};

static int hdmi_init(struct snd_soc_pcm_runtime *rtd)
@@ -285,13 +269,11 @@ SND_SOC_DAILINK_DEF(ssp0_codec,

SND_SOC_DAILINK_DEF(ssp1_pin,
	DAILINK_COMP_ARRAY(COMP_CPU("SSP1 Pin")));
SND_SOC_DAILINK_DEF(ssp1_amps,
	DAILINK_COMP_ARRAY(
	/* Left */	COMP_CODEC(MAXIM_DEV0_NAME, MAX98373_CODEC_DAI),
	/* Right */	COMP_CODEC(MAXIM_DEV1_NAME, MAX98373_CODEC_DAI)));

SND_SOC_DAILINK_DEF(ssp1_m98360a,
	DAILINK_COMP_ARRAY(COMP_CODEC("MX98360A:00", "HiFi")));
SND_SOC_DAILINK_DEF(ssp2_pin,
	DAILINK_COMP_ARRAY(COMP_CPU("SSP2 Pin")));
SND_SOC_DAILINK_DEF(dummy_codec,
	DAILINK_COMP_ARRAY(COMP_CODEC("snd-soc-dummy", "snd-soc-dummy-dai")));

SND_SOC_DAILINK_DEF(dmic_pin,
	DAILINK_COMP_ARRAY(COMP_CPU("DMIC01 Pin")));
@@ -316,10 +298,15 @@ SND_SOC_DAILINK_DEF(idisp3_pin,
SND_SOC_DAILINK_DEF(idisp3_codec,
	DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi3")));

SND_SOC_DAILINK_DEF(idisp4_pin,
	DAILINK_COMP_ARRAY(COMP_CPU("iDisp4 Pin")));
SND_SOC_DAILINK_DEF(idisp4_codec,
	DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi4")));

SND_SOC_DAILINK_DEF(platform, /* subject to be overridden during probe */
	DAILINK_COMP_ARRAY(COMP_PLATFORM("0000:00:1f.3")));

static struct snd_soc_dai_link dais[] = {
static struct snd_soc_dai_link jsl_dais[] = {
	/* Back End DAI links */
	{
		.name = "SSP1-Codec",
@@ -328,8 +315,7 @@ static struct snd_soc_dai_link dais[] = {
		.no_pcm = 1,
		.dpcm_playback = 1,
		.dpcm_capture = 1, /* IV feedback */
		.ops = &ssp1_ops,
		SND_SOC_DAILINK_REG(ssp1_pin, ssp1_amps, platform),
		SND_SOC_DAILINK_REG(ssp1_pin, max_98373_components, platform),
	},
	{
		.name = "SSP0-Codec",
@@ -383,83 +369,197 @@ static struct snd_soc_dai_link dais[] = {
	}
};

static struct snd_soc_card card_da7219_m98373 = {
	.name = "da7219max",
static struct snd_soc_dai_link adl_dais[] = {
	/* Back End DAI links */
	{
		.name = "SSP0-Codec",
		.id = 0,
		.no_pcm = 1,
		.init = da7219_codec_init,
		.ignore_pmdown_time = 1,
		.dpcm_playback = 1,
		.dpcm_capture = 1,
		SND_SOC_DAILINK_REG(ssp0_pin, ssp0_codec, platform),
	},
	{
		.name = "dmic01",
		.id = 1,
		.ignore_suspend = 1,
		.dpcm_capture = 1,
		.no_pcm = 1,
		SND_SOC_DAILINK_REG(dmic_pin, dmic_codec, platform),
	},
	{
		.name = "dmic16k",
		.id = 2,
		.ignore_suspend = 1,
		.dpcm_capture = 1,
		.no_pcm = 1,
		SND_SOC_DAILINK_REG(dmic16k_pin, dmic_codec, platform),
	},
	{
		.name = "iDisp1",
		.id = 3,
		.init = hdmi_init,
		.dpcm_playback = 1,
		.no_pcm = 1,
		SND_SOC_DAILINK_REG(idisp1_pin, idisp1_codec, platform),
	},
	{
		.name = "iDisp2",
		.id = 4,
		.init = hdmi_init,
		.dpcm_playback = 1,
		.no_pcm = 1,
		SND_SOC_DAILINK_REG(idisp2_pin, idisp2_codec, platform),
	},
	{
		.name = "iDisp3",
		.id = 5,
		.init = hdmi_init,
		.dpcm_playback = 1,
		.no_pcm = 1,
		SND_SOC_DAILINK_REG(idisp3_pin, idisp3_codec, platform),
	},
	{
		.name = "iDisp4",
		.id = 6,
		.init = hdmi_init,
		.dpcm_playback = 1,
		.no_pcm = 1,
		SND_SOC_DAILINK_REG(idisp4_pin, idisp4_codec, platform),
	},
	{
		.name = "SSP1-Codec",
		.id = 7,
		.no_pcm = 1,
		.dpcm_playback = 1,
		/* feedback stream or firmware-generated echo reference */
		.dpcm_capture = 1,
		SND_SOC_DAILINK_REG(ssp1_pin, max_98373_components, platform),
	},
	{
		.name = "SSP2-BT",
		.id = 8,
		.no_pcm = 1,
		.dpcm_playback = 1,
		.dpcm_capture = 1,
		SND_SOC_DAILINK_REG(ssp2_pin, dummy_codec, platform),
	},
};

static struct snd_soc_card card_da7219 = {
	.name = "da7219", /* the sof- prefix is added by the core */
	.owner = THIS_MODULE,
	.dai_link = dais,
	.num_links = ARRAY_SIZE(dais),
	.controls = controls,
	.num_controls = ARRAY_SIZE(controls),
	.dapm_widgets = widgets,
	.num_dapm_widgets = ARRAY_SIZE(widgets),
	.dapm_routes = audio_map,
	.num_dapm_routes = ARRAY_SIZE(audio_map),
	.codec_conf = max98373_codec_conf,
	.num_configs = ARRAY_SIZE(max98373_codec_conf),
	.fully_routed = true,
	.late_probe = card_late_probe,
};

static struct snd_soc_card card_da7219_m98360a = {
	.name = "da7219max98360a",
	.owner = THIS_MODULE,
	.dai_link = dais,
	.num_links = ARRAY_SIZE(dais),
	.controls = m98360a_controls,
	.num_controls = ARRAY_SIZE(m98360a_controls),
	.dapm_widgets = max98360a_widgets,
	.num_dapm_widgets = ARRAY_SIZE(max98360a_widgets),
	.dapm_routes = max98360a_map,
	.num_dapm_routes = ARRAY_SIZE(max98360a_map),
	.fully_routed = true,
	.late_probe = card_late_probe,
};

static int audio_probe(struct platform_device *pdev)
{
	static struct snd_soc_card *card;
	struct snd_soc_acpi_mach *mach;
	struct snd_soc_acpi_mach *mach = pdev->dev.platform_data;
	struct snd_soc_dai_link *dai_links;
	struct card_private *ctx;
	int ret;
	unsigned long board_quirk = 0;
	int ret, amp_idx;

	ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
	if (!ctx)
		return -ENOMEM;

	/* By default dais[0] is configured for max98373 */
	if (!strcmp(pdev->name, "sof_da7219_mx98360a")) {
		dais[0] = (struct snd_soc_dai_link) {
			.name = "SSP1-Codec",
			.id = 0,
			.no_pcm = 1,
			.dpcm_playback = 1,
			.ignore_pmdown_time = 1,
			SND_SOC_DAILINK_REG(ssp1_pin, ssp1_m98360a, platform) };
	if (pdev->id_entry && pdev->id_entry->driver_data)
		board_quirk = (unsigned long)pdev->id_entry->driver_data;

	ctx->codec_type = sof_ssp_detect_codec_type(&pdev->dev);
	ctx->amp_type = sof_ssp_detect_amp_type(&pdev->dev);

	if (board_quirk & SOF_DA7219_JSL_BOARD) {
		/* backward-compatible with existing devices */
		switch (ctx->amp_type) {
		case CODEC_MAX98360A:
			card_da7219.name = devm_kstrdup(&pdev->dev,
							"da7219max98360a",
							GFP_KERNEL);
			break;
		case CODEC_MAX98373:
			card_da7219.name = devm_kstrdup(&pdev->dev, "da7219max",
							GFP_KERNEL);
			break;
		default:
			break;
		}

		dai_links = jsl_dais;
		amp_idx = 0;

		card_da7219.num_links = ARRAY_SIZE(jsl_dais);
	} else {
		dai_links = adl_dais;
		amp_idx = 7;

		card_da7219.num_links = ARRAY_SIZE(adl_dais);
	}

	dev_dbg(&pdev->dev, "board_quirk = %lx\n", board_quirk);

	/* speaker amp */
	switch (ctx->amp_type) {
	case CODEC_MAX98360A:
		max_98360a_dai_link(&dai_links[amp_idx]);
		break;
	case CODEC_MAX98373:
		dai_links[amp_idx].codecs = max_98373_components;
		dai_links[amp_idx].num_codecs = ARRAY_SIZE(max_98373_components);
		dai_links[amp_idx].init = max_98373_spk_codec_init;
		if (board_quirk & SOF_DA7219_JSL_BOARD) {
			dai_links[amp_idx].ops = &max98373_ops; /* use local ops */
		} else {
			/* TBD: implement the amp for later platform */
			dev_err(&pdev->dev, "max98373 not support yet\n");
			return -EINVAL;
		}

		max_98373_set_codec_conf(&card_da7219);
		break;
	default:
		dev_err(&pdev->dev, "invalid amp type %d\n", ctx->amp_type);
		return -EINVAL;
	}

	card_da7219.dai_link = dai_links;

	INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
	card = (struct snd_soc_card *)pdev->id_entry->driver_data;
	card->dev = &pdev->dev;

	mach = pdev->dev.platform_data;
	ret = snd_soc_fixup_dai_links_platform_name(card,
	card_da7219.dev = &pdev->dev;

	ret = snd_soc_fixup_dai_links_platform_name(&card_da7219,
						    mach->mach_params.platform);
	if (ret)
		return ret;

	snd_soc_card_set_drvdata(card, ctx);
	snd_soc_card_set_drvdata(&card_da7219, ctx);

	return devm_snd_soc_register_card(&pdev->dev, card);
	return devm_snd_soc_register_card(&pdev->dev, &card_da7219);
}

static const struct platform_device_id board_ids[] = {
	{
		.name = "sof_da7219_mx98373",
		.driver_data = (kernel_ulong_t)&card_da7219_m98373,
		.name = "jsl_mx98373_da7219",
		.driver_data = (kernel_ulong_t)(SOF_DA7219_JSL_BOARD),
	},
	{
		.name = "jsl_mx98360_da7219",
		.driver_data = (kernel_ulong_t)(SOF_DA7219_JSL_BOARD),
	},
	{
		.name = "sof_da7219_mx98360a",
		.driver_data = (kernel_ulong_t)&card_da7219_m98360a,
		.name = "adl_mx98360_da7219",
		/* no quirk needed for this board */
	},
	{ }
};
@@ -468,7 +568,7 @@ MODULE_DEVICE_TABLE(platform, board_ids);
static struct platform_driver audio = {
	.probe = audio_probe,
	.driver = {
		.name = "sof_da7219_max98_360a_373",
		.name = "sof_da7219",
		.pm = &snd_soc_pm_ops,
	},
	.id_table = board_ids,
@@ -476,7 +576,10 @@ static struct platform_driver audio = {
module_platform_driver(audio)

/* Module information */
MODULE_DESCRIPTION("ASoC Intel(R) SOF Machine driver");
MODULE_DESCRIPTION("ASoC Intel(R) SOF Machine driver for Dialog codec");
MODULE_AUTHOR("Yong Zhi <yong.zhi@intel.com>");
MODULE_AUTHOR("Brent Lu <brent.lu@intel.com>");
MODULE_LICENSE("GPL v2");
MODULE_IMPORT_NS(SND_SOC_INTEL_HDA_DSP_COMMON);
MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_MAXIM_COMMON);
MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_SSP_COMMON);
Loading