Commit 9f2d5e1e authored by Mark Brown's avatar Mark Brown

ASoC: Intel: avs: Machine boards and HDA codec support

Merge series from Cezary Rojewski <cezary.rojewski@intel.com>
From there on is a range of boards appended. All of them follow the same:

This series focuses on populating boards/ subdirectory with supported
configurations by the avs-driver. Note: it is independent of recently
provided "Driver code and PCM operations" series [1], that is, code
found here should not collide with it.

Series starts with a small change that adds a helper to sound pcm
header, allowing for retrieving string naming a direction without the
need of substream pointer. Said helper is used by codec driver code that
follows it but I believe it's generic and helpful enough that it can be
called an independent addition to the sound core.

Code for generic HD-Audio codec driver follows. It is a ASoC wrapper for
existing HD-Audio codec code found in sound/pci/hda/. There is basically
no custom logic involved up to the point that driver follows
HDA_DEV_LEGACY convention, rather than the HDA_DEV_ASOC one. Commit
message for the given patch iterates on this and explains crucial parts
of the implementation.

From there on is a range of boards appended. All of them follow the same
scheme:

- define avs_create_dai_link() so DAI-LINKs can be created dynamically,
  based on the link_mask (I2S) or the number of entries in the
  ->pcm_list_head list (HDA)
- define avs_create_dapm_routes() so DAPM routes can be created
  dynamically, same rules as above apply
- define probe() function that creates new ASoC card, assign all
  required operations and resources along with calling the two above

Changes in v2:
- 'link_mask' usage replaced with 'i2s_link_mask' as requested by
  Pierre
- 'ssp_test' board renamed to 'i2s_test' to match naming convention used
  for other i2s machine boards
- enriched commit message and Kconfig for the 'HD-Audio codec driver'
  patch as requested by Kai

[1]: https://lore.kernel.org/all/20220426172346.3508411-1-cezary.rojewski@intel.com/

Amadeusz Sławiński (1):
  ASoC: Intel: avs: Add max98373 machine board

Cezary Rojewski (13):
  ALSA: Add snd_pcm_direction_name() helper
  ASoC: codecs: Add HD-Audio codec driver
  ASoC: Intel: avs: Add HDAudio machine board
  ASoC: Intel: avs: Add DMIC machine board
  ASoC: Intel: avs: Add I2S-test machine board
  ASoC: Intel: avs: Add rt274 machine board
  ASoC: Intel: avs: Add rt286 machine board
  ASoC: Intel: avs: Add rt298 machine board
  ASoC: Intel: avs: Add rt5682 machine board
  ASoC: Intel: avs: Add nau8825 machine board
  ASoC: Intel: avs: Add ssm4567 machine board
  ASoC: Intel: avs: Add max98357a machine board
  ASoC: Intel: avs: Add da7219 machine board

 include/sound/pcm.h                    |  19 +-
 sound/soc/codecs/Kconfig               |  10 +
 sound/soc/codecs/Makefile              |   2 +
 sound/soc/codecs/hda-dai.c             | 102 +++++++
 sound/soc/codecs/hda.c                 | 395 +++++++++++++++++++++++++
 sound/soc/codecs/hda.h                 |  19 ++
 sound/soc/intel/Kconfig                |   3 +
 sound/soc/intel/avs/Makefile           |   3 +
 sound/soc/intel/avs/boards/Kconfig     | 121 ++++++++
 sound/soc/intel/avs/boards/Makefile    |  27 ++
 sound/soc/intel/avs/boards/da7219.c    | 282 ++++++++++++++++++
 sound/soc/intel/avs/boards/dmic.c      |  93 ++++++
 sound/soc/intel/avs/boards/hdaudio.c   | 294 ++++++++++++++++++
 sound/soc/intel/avs/boards/i2s_test.c  | 180 +++++++++++
 sound/soc/intel/avs/boards/max98357a.c | 154 ++++++++++
 sound/soc/intel/avs/boards/max98373.c  | 239 +++++++++++++++
 sound/soc/intel/avs/boards/nau8825.c   | 353 ++++++++++++++++++++++
 sound/soc/intel/avs/boards/rt274.c     | 310 +++++++++++++++++++
 sound/soc/intel/avs/boards/rt286.c     | 281 ++++++++++++++++++
 sound/soc/intel/avs/boards/rt298.c     | 281 ++++++++++++++++++
 sound/soc/intel/avs/boards/rt5682.c    | 340 +++++++++++++++++++++
 sound/soc/intel/avs/boards/ssm4567.c   | 271 +++++++++++++++++
 22 files changed, 3775 insertions(+), 4 deletions(-)
 create mode 100644 sound/soc/codecs/hda-dai.c
 create mode 100644 sound/soc/codecs/hda.c
 create mode 100644 sound/soc/codecs/hda.h
 create mode 100644 sound/soc/intel/avs/boards/Kconfig
 create mode 100644 sound/soc/intel/avs/boards/Makefile
 create mode 100644 sound/soc/intel/avs/boards/da7219.c
 create mode 100644 sound/soc/intel/avs/boards/dmic.c
 create mode 100644 sound/soc/intel/avs/boards/hdaudio.c
 create mode 100644 sound/soc/intel/avs/boards/i2s_test.c
 create mode 100644 sound/soc/intel/avs/boards/max98357a.c
 create mode 100644 sound/soc/intel/avs/boards/max98373.c
 create mode 100644 sound/soc/intel/avs/boards/nau8825.c
 create mode 100644 sound/soc/intel/avs/boards/rt274.c
 create mode 100644 sound/soc/intel/avs/boards/rt286.c
 create mode 100644 sound/soc/intel/avs/boards/rt298.c
 create mode 100644 sound/soc/intel/avs/boards/rt5682.c
 create mode 100644 sound/soc/intel/avs/boards/ssm4567.c

--
2.25.1
parents 28223889 6b5b0d6f
...@@ -1392,6 +1392,20 @@ static inline void snd_pcm_limit_isa_dma_size(int dma, size_t *max) ...@@ -1392,6 +1392,20 @@ static inline void snd_pcm_limit_isa_dma_size(int dma, size_t *max)
const char *snd_pcm_format_name(snd_pcm_format_t format); const char *snd_pcm_format_name(snd_pcm_format_t format);
/**
* snd_pcm_direction_name - Get a string naming the direction of a stream
* @direction: Stream's direction, one of SNDRV_PCM_STREAM_XXX
*
* Returns a string naming the direction of the stream.
*/
static inline const char *snd_pcm_direction_name(int direction)
{
if (direction == SNDRV_PCM_STREAM_PLAYBACK)
return "Playback";
else
return "Capture";
}
/** /**
* snd_pcm_stream_str - Get a string naming the direction of a stream * snd_pcm_stream_str - Get a string naming the direction of a stream
* @substream: the pcm substream instance * @substream: the pcm substream instance
...@@ -1400,10 +1414,7 @@ const char *snd_pcm_format_name(snd_pcm_format_t format); ...@@ -1400,10 +1414,7 @@ const char *snd_pcm_format_name(snd_pcm_format_t format);
*/ */
static inline const char *snd_pcm_stream_str(struct snd_pcm_substream *substream) static inline const char *snd_pcm_stream_str(struct snd_pcm_substream *substream)
{ {
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) return snd_pcm_direction_name(substream->stream);
return "Playback";
else
return "Capture";
} }
/* /*
......
...@@ -937,6 +937,16 @@ config SND_SOC_HDAC_HDA ...@@ -937,6 +937,16 @@ config SND_SOC_HDAC_HDA
tristate tristate
select SND_HDA select SND_HDA
config SND_SOC_HDA
tristate "HD-Audio codec driver"
select SND_HDA_EXT_CORE
select SND_HDA
help
This enables HD-Audio codec support in ASoC subsystem. Compared
to SND_SOC_HDAC_HDA, driver's behavior is identical to HD-Audio
legacy solution - including the dynamic resource allocation
based on actual codec capabilities.
config SND_SOC_ICS43432 config SND_SOC_ICS43432
tristate "ICS43423 and compatible i2s microphones" tristate "ICS43423 and compatible i2s microphones"
......
...@@ -106,6 +106,7 @@ snd-soc-es8328-spi-objs := es8328-spi.o ...@@ -106,6 +106,7 @@ snd-soc-es8328-spi-objs := es8328-spi.o
snd-soc-gtm601-objs := gtm601.o snd-soc-gtm601-objs := gtm601.o
snd-soc-hdac-hdmi-objs := hdac_hdmi.o snd-soc-hdac-hdmi-objs := hdac_hdmi.o
snd-soc-hdac-hda-objs := hdac_hda.o snd-soc-hdac-hda-objs := hdac_hda.o
snd-soc-hda-codec-objs := hda.o hda-dai.o
snd-soc-ics43432-objs := ics43432.o snd-soc-ics43432-objs := ics43432.o
snd-soc-inno-rk3036-objs := inno_rk3036.o snd-soc-inno-rk3036-objs := inno_rk3036.o
snd-soc-isabelle-objs := isabelle.o snd-soc-isabelle-objs := isabelle.o
...@@ -458,6 +459,7 @@ obj-$(CONFIG_SND_SOC_ES8328_SPI)+= snd-soc-es8328-spi.o ...@@ -458,6 +459,7 @@ obj-$(CONFIG_SND_SOC_ES8328_SPI)+= snd-soc-es8328-spi.o
obj-$(CONFIG_SND_SOC_GTM601) += snd-soc-gtm601.o obj-$(CONFIG_SND_SOC_GTM601) += snd-soc-gtm601.o
obj-$(CONFIG_SND_SOC_HDAC_HDMI) += snd-soc-hdac-hdmi.o obj-$(CONFIG_SND_SOC_HDAC_HDMI) += snd-soc-hdac-hdmi.o
obj-$(CONFIG_SND_SOC_HDAC_HDA) += snd-soc-hdac-hda.o obj-$(CONFIG_SND_SOC_HDAC_HDA) += snd-soc-hdac-hda.o
obj-$(CONFIG_SND_SOC_HDA) += snd-soc-hda-codec.o
obj-$(CONFIG_SND_SOC_ICS43432) += snd-soc-ics43432.o obj-$(CONFIG_SND_SOC_ICS43432) += snd-soc-ics43432.o
obj-$(CONFIG_SND_SOC_INNO_RK3036) += snd-soc-inno-rk3036.o obj-$(CONFIG_SND_SOC_INNO_RK3036) += snd-soc-inno-rk3036.o
obj-$(CONFIG_SND_SOC_ISABELLE) += snd-soc-isabelle.o obj-$(CONFIG_SND_SOC_ISABELLE) += snd-soc-isabelle.o
......
// SPDX-License-Identifier: GPL-2.0
//
// Copyright(c) 2021-2022 Intel Corporation. All rights reserved.
//
// Author: Cezary Rojewski <cezary.rojewski@intel.com>
//
#include <sound/soc.h>
#include <sound/hda_codec.h>
#include "hda.h"
static int hda_codec_dai_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
{
struct hda_pcm_stream *stream_info;
struct hda_codec *codec;
struct hda_pcm *pcm;
int ret;
codec = dev_to_hda_codec(dai->dev);
stream_info = snd_soc_dai_get_dma_data(dai, substream);
pcm = container_of(stream_info, struct hda_pcm, stream[substream->stream]);
dev_dbg(dai->dev, "open stream codec: %08x, info: %p, pcm: %p %s substream: %p\n",
codec->core.vendor_id, stream_info, pcm, pcm->name, substream);
snd_hda_codec_pcm_get(pcm);
ret = stream_info->ops.open(stream_info, codec, substream);
if (ret < 0) {
dev_err(dai->dev, "codec open failed: %d\n", ret);
snd_hda_codec_pcm_put(pcm);
return ret;
}
return 0;
}
static void hda_codec_dai_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
{
struct hda_pcm_stream *stream_info;
struct hda_codec *codec;
struct hda_pcm *pcm;
int ret;
codec = dev_to_hda_codec(dai->dev);
stream_info = snd_soc_dai_get_dma_data(dai, substream);
pcm = container_of(stream_info, struct hda_pcm, stream[substream->stream]);
dev_dbg(dai->dev, "close stream codec: %08x, info: %p, pcm: %p %s substream: %p\n",
codec->core.vendor_id, stream_info, pcm, pcm->name, substream);
ret = stream_info->ops.close(stream_info, codec, substream);
if (ret < 0)
dev_err(dai->dev, "codec close failed: %d\n", ret);
snd_hda_codec_pcm_put(pcm);
}
static int hda_codec_dai_hw_free(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
{
struct hda_pcm_stream *stream_info;
struct hda_codec *codec;
codec = dev_to_hda_codec(dai->dev);
stream_info = snd_soc_dai_get_dma_data(dai, substream);
snd_hda_codec_cleanup(codec, stream_info, substream);
return 0;
}
static int hda_codec_dai_prepare(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
{
struct snd_pcm_runtime *runtime = substream->runtime;
struct hda_pcm_stream *stream_info;
struct hdac_stream *stream;
struct hda_codec *codec;
unsigned int format;
int ret;
codec = dev_to_hda_codec(dai->dev);
stream = substream->runtime->private_data;
stream_info = snd_soc_dai_get_dma_data(dai, substream);
format = snd_hdac_calc_stream_format(runtime->rate, runtime->channels, runtime->format,
runtime->sample_bits, 0);
ret = snd_hda_codec_prepare(codec, stream_info, stream->stream_tag, format, substream);
if (ret < 0) {
dev_err(dai->dev, "codec prepare failed: %d\n", ret);
return ret;
}
return 0;
}
const struct snd_soc_dai_ops snd_soc_hda_codec_dai_ops = {
.startup = hda_codec_dai_startup,
.shutdown = hda_codec_dai_shutdown,
.hw_free = hda_codec_dai_hw_free,
.prepare = hda_codec_dai_prepare,
};
EXPORT_SYMBOL_GPL(snd_soc_hda_codec_dai_ops);
// SPDX-License-Identifier: GPL-2.0
//
// Copyright(c) 2021-2022 Intel Corporation. All rights reserved.
//
// Author: Cezary Rojewski <cezary.rojewski@intel.com>
//
#include <linux/module.h>
#include <linux/pm_runtime.h>
#include <sound/soc.h>
#include <sound/hdaudio_ext.h>
#include <sound/hda_i915.h>
#include <sound/hda_codec.h>
#include "hda.h"
static int hda_codec_create_dais(struct hda_codec *codec, int pcm_count,
struct snd_soc_dai_driver **drivers)
{
struct device *dev = &codec->core.dev;
struct snd_soc_dai_driver *drvs;
struct hda_pcm *pcm;
int i;
drvs = devm_kcalloc(dev, pcm_count, sizeof(*drvs), GFP_KERNEL);
if (!drvs)
return -ENOMEM;
pcm = list_first_entry(&codec->pcm_list_head, struct hda_pcm, list);
for (i = 0; i < pcm_count; i++, pcm = list_next_entry(pcm, list)) {
struct snd_soc_pcm_stream *stream;
int dir;
dev_info(dev, "creating for %s %d\n", pcm->name, i);
drvs[i].id = i;
drvs[i].name = pcm->name;
drvs[i].ops = &snd_soc_hda_codec_dai_ops;
dir = SNDRV_PCM_STREAM_PLAYBACK;
stream = &drvs[i].playback;
if (!pcm->stream[dir].substreams) {
dev_info(dev, "skipping playback dai for %s\n", pcm->name);
goto capture_dais;
}
stream->stream_name =
devm_kasprintf(dev, GFP_KERNEL, "%s %s", pcm->name,
snd_pcm_direction_name(dir));
if (!stream->stream_name)
return -ENOMEM;
stream->channels_min = pcm->stream[dir].channels_min;
stream->channels_max = pcm->stream[dir].channels_max;
stream->rates = pcm->stream[dir].rates;
stream->formats = pcm->stream[dir].formats;
stream->sig_bits = pcm->stream[dir].maxbps;
capture_dais:
dir = SNDRV_PCM_STREAM_CAPTURE;
stream = &drvs[i].capture;
if (!pcm->stream[dir].substreams) {
dev_info(dev, "skipping capture dai for %s\n", pcm->name);
continue;
}
stream->stream_name =
devm_kasprintf(dev, GFP_KERNEL, "%s %s", pcm->name,
snd_pcm_direction_name(dir));
if (!stream->stream_name)
return -ENOMEM;
stream->channels_min = pcm->stream[dir].channels_min;
stream->channels_max = pcm->stream[dir].channels_max;
stream->rates = pcm->stream[dir].rates;
stream->formats = pcm->stream[dir].formats;
stream->sig_bits = pcm->stream[dir].maxbps;
}
*drivers = drvs;
return 0;
}
static int hda_codec_register_dais(struct hda_codec *codec, struct snd_soc_component *component)
{
struct snd_soc_dai_driver *drvs = NULL;
struct snd_soc_dapm_context *dapm;
struct hda_pcm *pcm;
int ret, pcm_count = 0;
if (list_empty(&codec->pcm_list_head))
return -EINVAL;
list_for_each_entry(pcm, &codec->pcm_list_head, list)
pcm_count++;
ret = hda_codec_create_dais(codec, pcm_count, &drvs);
if (ret < 0)
return ret;
dapm = snd_soc_component_get_dapm(component);
list_for_each_entry(pcm, &codec->pcm_list_head, list) {
struct snd_soc_dai *dai;
dai = snd_soc_register_dai(component, drvs, false);
if (!dai) {
dev_err(component->dev, "register dai for %s failed\n", pcm->name);
return -EINVAL;
}
ret = snd_soc_dapm_new_dai_widgets(dapm, dai);
if (ret < 0) {
dev_err(component->dev, "create widgets failed: %d\n", ret);
snd_soc_unregister_dai(dai);
return ret;
}
snd_soc_dai_init_dma_data(dai, &pcm->stream[0], &pcm->stream[1]);
drvs++;
}
return 0;
}
static void hda_codec_unregister_dais(struct hda_codec *codec,
struct snd_soc_component *component)
{
struct snd_soc_dai *dai, *save;
struct hda_pcm *pcm;
for_each_component_dais_safe(component, dai, save) {
list_for_each_entry(pcm, &codec->pcm_list_head, list) {
if (strcmp(dai->driver->name, pcm->name))
continue;
if (dai->playback_widget)
snd_soc_dapm_free_widget(dai->playback_widget);
if (dai->capture_widget)
snd_soc_dapm_free_widget(dai->capture_widget);
snd_soc_unregister_dai(dai);
break;
}
}
}
int hda_codec_probe_complete(struct hda_codec *codec)
{
struct hdac_device *hdev = &codec->core;
struct hdac_bus *bus = hdev->bus;
int ret;
ret = snd_hda_codec_build_controls(codec);
if (ret < 0) {
dev_err(&hdev->dev, "unable to create controls %d\n", ret);
goto out;
}
/* Bus suspended codecs as it does not manage their pm */
pm_runtime_set_active(&hdev->dev);
/* rpm was forbidden in snd_hda_codec_device_new() */
snd_hda_codec_set_power_save(codec, 2000);
snd_hda_codec_register(codec);
out:
/* Complement pm_runtime_get_sync(bus) in probe */
pm_runtime_mark_last_busy(bus->dev);
pm_runtime_put_autosuspend(bus->dev);
return ret;
}
EXPORT_SYMBOL_GPL(hda_codec_probe_complete);
/* Expects codec with usage_count=1 and status=suspended */
static int hda_codec_probe(struct snd_soc_component *component)
{
struct hda_codec *codec = dev_to_hda_codec(component->dev);
struct hdac_device *hdev = &codec->core;
struct hdac_bus *bus = hdev->bus;
struct hdac_ext_link *hlink;
hda_codec_patch_t patch;
int ret;
#ifdef CONFIG_PM
WARN_ON(atomic_read(&hdev->dev.power.usage_count) != 1 ||
!pm_runtime_status_suspended(&hdev->dev));
#endif
hlink = snd_hdac_ext_bus_link_at(bus, hdev->addr);
if (!hlink) {
dev_err(&hdev->dev, "hdac link not found\n");
return -EIO;
}
pm_runtime_get_sync(bus->dev);
if (hda_codec_is_display(codec))
snd_hdac_display_power(bus, hdev->addr, true);
snd_hdac_ext_bus_link_get(bus, hlink);
ret = snd_hda_codec_device_new(codec->bus, component->card->snd_card, hdev->addr, codec,
false);
if (ret < 0) {
dev_err(&hdev->dev, "create hda codec failed: %d\n", ret);
goto device_new_err;
}
ret = snd_hda_codec_set_name(codec, codec->preset->name);
if (ret < 0) {
dev_err(&hdev->dev, "name failed %s\n", codec->preset->name);
goto err;
}
ret = snd_hdac_regmap_init(&codec->core);
if (ret < 0) {
dev_err(&hdev->dev, "regmap init failed\n");
goto err;
}
patch = (hda_codec_patch_t)codec->preset->driver_data;
if (!patch) {
dev_err(&hdev->dev, "no patch specified?\n");
ret = -EINVAL;
goto err;
}
ret = patch(codec);
if (ret < 0) {
dev_err(&hdev->dev, "patch failed %d\n", ret);
goto err;
}
/* configure codec for 1:1 PCM:DAI mapping */
codec->mst_no_extra_pcms = 1;
ret = snd_hda_codec_parse_pcms(codec);
if (ret < 0) {
dev_err(&hdev->dev, "unable to map pcms to dai %d\n", ret);
goto parse_pcms_err;
}
ret = hda_codec_register_dais(codec, component);
if (ret < 0) {
dev_err(&hdev->dev, "update dais failed: %d\n", ret);
goto parse_pcms_err;
}
if (!hda_codec_is_display(codec)) {
ret = hda_codec_probe_complete(codec);
if (ret < 0)
goto complete_err;
}
codec->core.lazy_cache = true;
return 0;
complete_err:
hda_codec_unregister_dais(codec, component);
parse_pcms_err:
if (codec->patch_ops.free)
codec->patch_ops.free(codec);
err:
snd_hda_codec_cleanup_for_unbind(codec);
device_new_err:
if (hda_codec_is_display(codec))
snd_hdac_display_power(bus, hdev->addr, false);
snd_hdac_ext_bus_link_put(bus, hlink);
pm_runtime_mark_last_busy(bus->dev);
pm_runtime_put_autosuspend(bus->dev);
return ret;
}
/* Leaves codec with usage_count=1 and status=suspended */
static void hda_codec_remove(struct snd_soc_component *component)
{
struct hda_codec *codec = dev_to_hda_codec(component->dev);
struct hdac_device *hdev = &codec->core;
struct hdac_bus *bus = hdev->bus;
struct hdac_ext_link *hlink;
bool was_registered = codec->registered;
/* Don't allow any more runtime suspends */
pm_runtime_forbid(&hdev->dev);
hda_codec_unregister_dais(codec, component);
if (codec->patch_ops.free)
codec->patch_ops.free(codec);
snd_hda_codec_cleanup_for_unbind(codec);
pm_runtime_put_noidle(&hdev->dev);
/* snd_hdac_device_exit() is only called on bus remove */
pm_runtime_set_suspended(&hdev->dev);
if (hda_codec_is_display(codec))
snd_hdac_display_power(bus, hdev->addr, false);
hlink = snd_hdac_ext_bus_link_at(bus, hdev->addr);
if (hlink)
snd_hdac_ext_bus_link_put(bus, hlink);
/*
* HDMI card's hda_codec_probe_complete() (see late_probe()) may
* not be called due to early error, leaving bus uc unbalanced
*/
if (!was_registered) {
pm_runtime_mark_last_busy(bus->dev);
pm_runtime_put_autosuspend(bus->dev);
}
#ifdef CONFIG_PM
WARN_ON(atomic_read(&hdev->dev.power.usage_count) != 1 ||
!pm_runtime_status_suspended(&hdev->dev));
#endif
}
static const struct snd_soc_dapm_route hda_dapm_routes[] = {
{"AIF1TX", NULL, "Codec Input Pin1"},
{"AIF2TX", NULL, "Codec Input Pin2"},
{"AIF3TX", NULL, "Codec Input Pin3"},
{"Codec Output Pin1", NULL, "AIF1RX"},
{"Codec Output Pin2", NULL, "AIF2RX"},
{"Codec Output Pin3", NULL, "AIF3RX"},
};
static const struct snd_soc_dapm_widget hda_dapm_widgets[] = {
/* Audio Interface */
SND_SOC_DAPM_AIF_IN("AIF1RX", "Analog Codec Playback", 0, SND_SOC_NOPM, 0, 0),
SND_SOC_DAPM_AIF_IN("AIF2RX", "Digital Codec Playback", 0, SND_SOC_NOPM, 0, 0),
SND_SOC_DAPM_AIF_IN("AIF3RX", "Alt Analog Codec Playback", 0, SND_SOC_NOPM, 0, 0),
SND_SOC_DAPM_AIF_OUT("AIF1TX", "Analog Codec Capture", 0, SND_SOC_NOPM, 0, 0),
SND_SOC_DAPM_AIF_OUT("AIF2TX", "Digital Codec Capture", 0, SND_SOC_NOPM, 0, 0),
SND_SOC_DAPM_AIF_OUT("AIF3TX", "Alt Analog Codec Capture", 0, SND_SOC_NOPM, 0, 0),
/* Input Pins */
SND_SOC_DAPM_INPUT("Codec Input Pin1"),
SND_SOC_DAPM_INPUT("Codec Input Pin2"),
SND_SOC_DAPM_INPUT("Codec Input Pin3"),
/* Output Pins */
SND_SOC_DAPM_OUTPUT("Codec Output Pin1"),
SND_SOC_DAPM_OUTPUT("Codec Output Pin2"),
SND_SOC_DAPM_OUTPUT("Codec Output Pin3"),
};
static struct snd_soc_dai_driver card_binder_dai = {
.id = -1,
.name = "codec-probing-DAI",
};
static int hda_hdev_attach(struct hdac_device *hdev)
{
struct hda_codec *codec = dev_to_hda_codec(&hdev->dev);
struct snd_soc_component_driver *comp_drv;
comp_drv = devm_kzalloc(&hdev->dev, sizeof(*comp_drv), GFP_KERNEL);
if (!comp_drv)
return -ENOMEM;
/*
* It's save to rely on dev_name() rather than a copy as component
* driver's lifetime is directly tied to hda codec one
*/
comp_drv->name = dev_name(&hdev->dev);
comp_drv->probe = hda_codec_probe;
comp_drv->remove = hda_codec_remove;
comp_drv->idle_bias_on = false;
if (!hda_codec_is_display(codec)) {
comp_drv->dapm_widgets = hda_dapm_widgets;
comp_drv->num_dapm_widgets = ARRAY_SIZE(hda_dapm_widgets);
comp_drv->dapm_routes = hda_dapm_routes;
comp_drv->num_dapm_routes = ARRAY_SIZE(hda_dapm_routes);
}
return snd_soc_register_component(&hdev->dev, comp_drv, &card_binder_dai, 1);
}
static int hda_hdev_detach(struct hdac_device *hdev)
{
struct hda_codec *codec = dev_to_hda_codec(&hdev->dev);
if (codec->registered)
cancel_delayed_work_sync(&codec->jackpoll_work);
snd_soc_unregister_component(&hdev->dev);
return 0;
}
const struct hdac_ext_bus_ops soc_hda_ext_bus_ops = {
.hdev_attach = hda_hdev_attach,
.hdev_detach = hda_hdev_detach,
};
EXPORT_SYMBOL_GPL(soc_hda_ext_bus_ops);
MODULE_DESCRIPTION("HD-Audio codec driver");
MODULE_AUTHOR("Cezary Rojewski <cezary.rojewski@intel.com>");
MODULE_LICENSE("GPL");
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright(c) 2021-2022 Intel Corporation. All rights reserved.
*
* Author: Cezary Rojewski <cezary.rojewski@intel.com>
*/
#ifndef SND_SOC_CODECS_HDA_H
#define SND_SOC_CODECS_HDA_H
#define hda_codec_is_display(codec) \
((((codec)->core.vendor_id >> 16) & 0xFFFF) == 0x8086)
extern const struct snd_soc_dai_ops snd_soc_hda_codec_dai_ops;
extern const struct hdac_ext_bus_ops soc_hda_ext_bus_ops;
int hda_codec_probe_complete(struct hda_codec *codec);
#endif
...@@ -226,5 +226,8 @@ config SND_SOC_INTEL_AVS ...@@ -226,5 +226,8 @@ config SND_SOC_INTEL_AVS
capabilities. This includes Skylake, Kabylake, Amberlake and capabilities. This includes Skylake, Kabylake, Amberlake and
Apollolake. Apollolake.
# Machine board drivers
source "sound/soc/intel/avs/boards/Kconfig"
# ASoC codec drivers # ASoC codec drivers
source "sound/soc/intel/boards/Kconfig" source "sound/soc/intel/boards/Kconfig"
...@@ -10,3 +10,6 @@ snd-soc-avs-objs += trace.o ...@@ -10,3 +10,6 @@ snd-soc-avs-objs += trace.o
CFLAGS_trace.o := -I$(src) CFLAGS_trace.o := -I$(src)
obj-$(CONFIG_SND_SOC_INTEL_AVS) += snd-soc-avs.o obj-$(CONFIG_SND_SOC_INTEL_AVS) += snd-soc-avs.o
# Machine support
obj-$(CONFIG_SND_SOC) += boards/
# SPDX-License-Identifier: GPL-2.0-only
menu "Intel AVS Machine drivers"
depends on SND_SOC_INTEL_AVS
comment "Available DSP configurations"
config SND_SOC_INTEL_AVS_MACH_DA7219
tristate "da7219 I2S board"
depends on I2C
depends on MFD_INTEL_LPSS || COMPILE_TEST
select SND_SOC_DA7219
help
This adds support for AVS with DA7219 I2S codec configuration.
Say Y or m if you have such a device. This is a recommended option.
If unsure select "N".
config SND_SOC_INTEL_AVS_MACH_DMIC
tristate "DMIC generic board"
select SND_SOC_DMIC
help
This adds support for AVS with Digital Mic array configuration.
Say Y or m if you have such a device. This is a recommended option.
If unsure select "N".
config SND_SOC_INTEL_AVS_MACH_HDAUDIO
tristate "HD-Audio generic board"
select SND_SOC_HDA
help
This adds support for AVS with HDAudio codec configuration.
Say Y or m if you have such a device. This is a recommended option.
If unsure select "N".
config SND_SOC_INTEL_AVS_MACH_I2S_TEST
tristate "I2S test board"
help
This adds support for I2S test-board which can be used to verify
transfer over I2S interface with SSP loopback scenarios.
config SND_SOC_INTEL_AVS_MACH_MAX98357A
tristate "max98357A I2S board"
depends on I2C
depends on MFD_INTEL_LPSS || COMPILE_TEST
select SND_SOC_MAX98357A
help
This adds support for AVS with MAX98357A I2S codec configuration.
Say Y or m if you have such a device. This is a recommended option.
If unsure select "N".
config SND_SOC_INTEL_AVS_MACH_MAX98373
tristate "max98373 I2S board"
depends on I2C
depends on MFD_INTEL_LPSS || COMPILE_TEST
select SND_SOC_MAX98373
help
This adds support for AVS with MAX98373 I2S codec configuration.
Say Y or m if you have such a device. This is a recommended option.
If unsure select "N".
config SND_SOC_INTEL_AVS_MACH_NAU8825
tristate "nau8825 I2S board"
depends on I2C
depends on MFD_INTEL_LPSS || COMPILE_TEST
select SND_SOC_NAU8825
help
This adds support for ASoC machine driver with NAU8825 I2S audio codec.
It is meant to be used with AVS driver.
Say Y or m if you have such a device. This is a recommended option.
If unsure select "N".
config SND_SOC_INTEL_AVS_MACH_RT274
tristate "rt274 in I2S mode"
depends on I2C
depends on MFD_INTEL_LPSS || COMPILE_TEST
select SND_SOC_RT274
help
This adds support for ASoC machine driver with RT274 I2S audio codec.
Say Y or m if you have such a device. This is a recommended option.
If unsure select "N".
config SND_SOC_INTEL_AVS_MACH_RT286
tristate "rt286 in I2S mode"
depends on I2C
depends on MFD_INTEL_LPSS || COMPILE_TEST
select SND_SOC_RT286
help
This adds support for ASoC machine driver with RT286 I2S audio codec.
Say Y or m if you have such a device. This is a recommended option.
If unsure select "N".
config SND_SOC_INTEL_AVS_MACH_RT298
tristate "rt298 in I2S mode"
depends on I2C
depends on MFD_INTEL_LPSS || COMPILE_TEST
select SND_SOC_RT298
help
This adds support for ASoC machine driver with RT298 I2S audio codec.
Say Y or m if you have such a device. This is a recommended option.
If unsure select "N".
config SND_SOC_INTEL_AVS_MACH_RT5682
tristate "rt5682 in I2S mode"
depends on I2C
depends on MFD_INTEL_LPSS || COMPILE_TEST
select SND_SOC_RT5682_I2C
help
This adds support for ASoC machine driver with RT5682 I2S audio codec.
Say Y or m if you have such a device. This is a recommended option.
If unsure select "N".
config SND_SOC_INTEL_AVS_MACH_SSM4567
tristate "ssm4567 I2S board"
depends on I2C
depends on MFD_INTEL_LPSS || COMPILE_TEST
select SND_SOC_SSM4567
help
This adds support for ASoC machine driver with SSM4567 I2S audio codec.
It is meant to be used with AVS driver.
Say Y or m if you have such a device. This is a recommended option.
If unsure select "N".
endmenu
# SPDX-License-Identifier: GPL-2.0-only
snd-soc-avs-da7219-objs := da7219.o
snd-soc-avs-dmic-objs := dmic.o
snd-soc-avs-hdaudio-objs := hdaudio.o
snd-soc-avs-i2s-test-objs := i2s_test.o
snd-soc-avs-max98357a-objs := max98357a.o
snd-soc-avs-max98373-objs := max98373.o
snd-soc-avs-nau8825-objs := nau8825.o
snd-soc-avs-rt274-objs := rt274.o
snd-soc-avs-rt286-objs := rt286.o
snd-soc-avs-rt298-objs := rt298.o
snd-soc-avs-rt5682-objs := rt5682.o
snd-soc-avs-ssm4567-objs := ssm4567.o
obj-$(CONFIG_SND_SOC_INTEL_AVS_MACH_DA7219) += snd-soc-avs-da7219.o
obj-$(CONFIG_SND_SOC_INTEL_AVS_MACH_DMIC) += snd-soc-avs-dmic.o
obj-$(CONFIG_SND_SOC_INTEL_AVS_MACH_HDAUDIO) += snd-soc-avs-hdaudio.o
obj-$(CONFIG_SND_SOC_INTEL_AVS_MACH_i2s_TEST) += snd-soc-avs-i2s-test.o
obj-$(CONFIG_SND_SOC_INTEL_AVS_MACH_MAX98357A) += snd-soc-avs-max98357a.o
obj-$(CONFIG_SND_SOC_INTEL_AVS_MACH_MAX98373) += snd-soc-avs-max98373.o
obj-$(CONFIG_SND_SOC_INTEL_AVS_MACH_NAU8825) += snd-soc-avs-nau8825.o
obj-$(CONFIG_SND_SOC_INTEL_AVS_MACH_RT274) += snd-soc-avs-rt274.o
obj-$(CONFIG_SND_SOC_INTEL_AVS_MACH_RT286) += snd-soc-avs-rt286.o
obj-$(CONFIG_SND_SOC_INTEL_AVS_MACH_RT298) += snd-soc-avs-rt298.o
obj-$(CONFIG_SND_SOC_INTEL_AVS_MACH_RT5682) += snd-soc-avs-rt5682.o
obj-$(CONFIG_SND_SOC_INTEL_AVS_MACH_SSM4567) += snd-soc-avs-ssm4567.o
// SPDX-License-Identifier: GPL-2.0-only
//
// Copyright(c) 2021-2022 Intel Corporation. All rights reserved.
//
// Author: Cezary Rojewski <cezary.rojewski@intel.com>
//
#include <linux/module.h>
#include <linux/platform_device.h>
#include <sound/jack.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
#include <sound/soc-acpi.h>
#include <sound/soc-dapm.h>
#include <uapi/linux/input-event-codes.h>
#include "../../../codecs/da7219.h"
#include "../../../codecs/da7219-aad.h"
#define DA7219_DAI_NAME "da7219-hifi"
static const struct snd_kcontrol_new card_controls[] = {
SOC_DAPM_PIN_SWITCH("Headphone Jack"),
SOC_DAPM_PIN_SWITCH("Headset Mic"),
};
static int platform_clock_control(struct snd_soc_dapm_widget *w,
struct snd_kcontrol *k, int event)
{
struct snd_soc_dapm_context *dapm = w->dapm;
struct snd_soc_card *card = dapm->card;
struct snd_soc_dai *codec_dai;
int ret = 0;
codec_dai = snd_soc_card_get_codec_dai(card, DA7219_DAI_NAME);
if (!codec_dai) {
dev_err(card->dev, "Codec dai not found. Unable to set/unset codec pll\n");
return -EIO;
}
if (SND_SOC_DAPM_EVENT_OFF(event)) {
ret = snd_soc_dai_set_pll(codec_dai, 0, DA7219_SYSCLK_MCLK, 0, 0);
if (ret)
dev_err(card->dev, "failed to stop PLL: %d\n", ret);
} else if (SND_SOC_DAPM_EVENT_ON(event)) {
ret = snd_soc_dai_set_pll(codec_dai, 0, DA7219_SYSCLK_PLL_SRM,
0, DA7219_PLL_FREQ_OUT_98304);
if (ret)
dev_err(card->dev, "failed to start PLL: %d\n", ret);
}
return ret;
}
static const struct snd_soc_dapm_widget card_widgets[] = {
SND_SOC_DAPM_HP("Headphone Jack", NULL),
SND_SOC_DAPM_MIC("Headset Mic", 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),
};
static const struct snd_soc_dapm_route card_base_routes[] = {
/* HP jack connectors - unknown if we have jack detection */
{"Headphone Jack", NULL, "HPL"},
{"Headphone Jack", NULL, "HPR"},
{"MIC", NULL, "Headset Mic"},
{ "Headphone Jack", NULL, "Platform Clock" },
{ "Headset Mic", NULL, "Platform Clock" },
};
static int avs_da7219_codec_init(struct snd_soc_pcm_runtime *runtime)
{
struct snd_soc_component *component = asoc_rtd_to_codec(runtime, 0)->component;
struct snd_soc_card *card = runtime->card;
struct snd_soc_jack *jack;
struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(runtime, 0);
int clk_freq;
int ret;
jack = snd_soc_card_get_drvdata(card);
clk_freq = 19200000;
ret = snd_soc_dai_set_sysclk(codec_dai, DA7219_CLKSRC_MCLK, clk_freq, SND_SOC_CLOCK_IN);
if (ret) {
dev_err(card->dev, "can't set codec sysclk configuration\n");
return ret;
}
/*
* Headset buttons map to the google Reference headset.
* These can be configured by userspace.
*/
ret = snd_soc_card_jack_new(card, "Headset Jack",
SND_JACK_HEADSET | SND_JACK_BTN_0 |
SND_JACK_BTN_1 | SND_JACK_BTN_2 |
SND_JACK_BTN_3 | SND_JACK_LINEOUT, jack);
if (ret) {
dev_err(card->dev, "Headset Jack creation failed: %d\n", ret);
return ret;
}
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);
da7219_aad_jack_det(component, jack);
return 0;
}
static int avs_create_dai_link(struct device *dev, const char *platform_name, int ssp_port,
struct snd_soc_dai_link **dai_link)
{
struct snd_soc_dai_link_component *platform;
struct snd_soc_dai_link *dl;
dl = devm_kzalloc(dev, sizeof(*dl), GFP_KERNEL);
platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL);
if (!dl || !platform)
return -ENOMEM;
platform->name = platform_name;
dl->name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-Codec", ssp_port);
dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL);
dl->codecs = devm_kzalloc(dev, sizeof(*dl->codecs), GFP_KERNEL);
if (!dl->name || !dl->cpus || !dl->codecs)
return -ENOMEM;
dl->cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d Pin", ssp_port);
dl->codecs->name = devm_kasprintf(dev, GFP_KERNEL, "i2c-DLGS7219:00");
dl->codecs->dai_name = devm_kasprintf(dev, GFP_KERNEL, DA7219_DAI_NAME);
if (!dl->cpus->dai_name || !dl->codecs->name || !dl->codecs->dai_name)
return -ENOMEM;
dl->num_cpus = 1;
dl->num_codecs = 1;
dl->platforms = platform;
dl->num_platforms = 1;
dl->id = 0;
dl->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS;
dl->init = avs_da7219_codec_init;
dl->nonatomic = 1;
dl->no_pcm = 1;
dl->dpcm_capture = 1;
dl->dpcm_playback = 1;
*dai_link = dl;
return 0;
}
static int avs_create_dapm_routes(struct device *dev, int ssp_port,
struct snd_soc_dapm_route **routes, int *num_routes)
{
struct snd_soc_dapm_route *dr;
const int num_base = ARRAY_SIZE(card_base_routes);
const int num_dr = num_base + 2;
int idx;
dr = devm_kcalloc(dev, num_dr, sizeof(*dr), GFP_KERNEL);
if (!dr)
return -ENOMEM;
memcpy(dr, card_base_routes, num_base * sizeof(*dr));
idx = num_base;
dr[idx].sink = devm_kasprintf(dev, GFP_KERNEL, "Playback");
dr[idx].source = devm_kasprintf(dev, GFP_KERNEL, "ssp%d Tx", ssp_port);
if (!dr[idx].sink || !dr[idx].source)
return -ENOMEM;
idx++;
dr[idx].sink = devm_kasprintf(dev, GFP_KERNEL, "ssp%d Rx", ssp_port);
dr[idx].source = devm_kasprintf(dev, GFP_KERNEL, "Capture");
if (!dr[idx].sink || !dr[idx].source)
return -ENOMEM;
*routes = dr;
*num_routes = num_dr;
return 0;
}
static int avs_card_set_jack(struct snd_soc_card *card, struct snd_soc_jack *jack)
{
struct snd_soc_component *component;
for_each_card_components(card, component)
snd_soc_component_set_jack(component, jack, NULL);
return 0;
}
static int avs_card_remove(struct snd_soc_card *card)
{
return avs_card_set_jack(card, NULL);
}
static int avs_card_suspend_pre(struct snd_soc_card *card)
{
return avs_card_set_jack(card, NULL);
}
static int avs_card_resume_post(struct snd_soc_card *card)
{
struct snd_soc_jack *jack = snd_soc_card_get_drvdata(card);
return avs_card_set_jack(card, jack);
}
static int avs_da7219_probe(struct platform_device *pdev)
{
struct snd_soc_dapm_route *routes;
struct snd_soc_dai_link *dai_link;
struct snd_soc_acpi_mach *mach;
struct snd_soc_card *card;
struct snd_soc_jack *jack;
struct device *dev = &pdev->dev;
const char *pname;
int num_routes, ssp_port, ret;
mach = dev_get_platdata(dev);
pname = mach->mach_params.platform;
ssp_port = __ffs(mach->mach_params.i2s_link_mask);
ret = avs_create_dai_link(dev, pname, ssp_port, &dai_link);
if (ret) {
dev_err(dev, "Failed to create dai link: %d", ret);
return ret;
}
ret = avs_create_dapm_routes(dev, ssp_port, &routes, &num_routes);
if (ret) {
dev_err(dev, "Failed to create dapm routes: %d", ret);
return ret;
}
jack = devm_kzalloc(dev, sizeof(*jack), GFP_KERNEL);
card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
if (!jack || !card)
return -ENOMEM;
card->name = "avs_da7219";
card->dev = dev;
card->owner = THIS_MODULE;
card->remove = avs_card_remove;
card->suspend_pre = avs_card_suspend_pre;
card->resume_post = avs_card_resume_post;
card->dai_link = dai_link;
card->num_links = 1;
card->controls = card_controls;
card->num_controls = ARRAY_SIZE(card_controls);
card->dapm_widgets = card_widgets;
card->num_dapm_widgets = ARRAY_SIZE(card_widgets);
card->dapm_routes = routes;
card->num_dapm_routes = num_routes;
card->fully_routed = true;
snd_soc_card_set_drvdata(card, jack);
ret = snd_soc_fixup_dai_links_platform_name(card, pname);
if (ret)
return ret;
return devm_snd_soc_register_card(dev, card);
}
static struct platform_driver avs_da7219_driver = {
.probe = avs_da7219_probe,
.driver = {
.name = "avs_da7219",
.pm = &snd_soc_pm_ops,
},
};
module_platform_driver(avs_da7219_driver);
MODULE_AUTHOR("Cezary Rojewski <cezary.rojewski@intel.com>");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:avs_da7219");
// SPDX-License-Identifier: GPL-2.0-only
//
// Copyright(c) 2021-2022 Intel Corporation. All rights reserved.
//
// Authors: Cezary Rojewski <cezary.rojewski@intel.com>
// Amadeusz Slawinski <amadeuszx.slawinski@linux.intel.com>
//
#include <linux/device.h>
#include <linux/module.h>
#include <sound/soc.h>
#include <sound/soc-acpi.h>
SND_SOC_DAILINK_DEF(dmic_pin, DAILINK_COMP_ARRAY(COMP_CPU("DMIC Pin")));
SND_SOC_DAILINK_DEF(dmic_wov_pin, DAILINK_COMP_ARRAY(COMP_CPU("DMIC WoV Pin")));
SND_SOC_DAILINK_DEF(dmic_codec, DAILINK_COMP_ARRAY(COMP_CODEC("dmic-codec", "dmic-hifi")));
/* Name overridden on probe */
SND_SOC_DAILINK_DEF(platform, DAILINK_COMP_ARRAY(COMP_PLATFORM("")));
static struct snd_soc_dai_link card_dai_links[] = {
/* Back ends */
{
.name = "DMIC",
.id = 0,
.dpcm_capture = 1,
.nonatomic = 1,
.no_pcm = 1,
SND_SOC_DAILINK_REG(dmic_pin, dmic_codec, platform),
},
{
.name = "DMIC WoV",
.id = 1,
.dpcm_capture = 1,
.nonatomic = 1,
.no_pcm = 1,
.ignore_suspend = 1,
SND_SOC_DAILINK_REG(dmic_wov_pin, dmic_codec, platform),
},
};
static const struct snd_soc_dapm_widget card_widgets[] = {
SND_SOC_DAPM_MIC("SoC DMIC", NULL),
};
static const struct snd_soc_dapm_route card_routes[] = {
{"DMic", NULL, "SoC DMIC"},
{"DMIC Rx", NULL, "Capture"},
{"DMIC WoV Rx", NULL, "Capture"},
};
static int avs_dmic_probe(struct platform_device *pdev)
{
struct snd_soc_acpi_mach *mach;
struct snd_soc_card *card;
struct device *dev = &pdev->dev;
int ret;
mach = dev_get_platdata(dev);
card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
if (!card)
return -ENOMEM;
card->name = "avs_dmic";
card->dev = dev;
card->owner = THIS_MODULE;
card->dai_link = card_dai_links;
card->num_links = ARRAY_SIZE(card_dai_links);
card->dapm_widgets = card_widgets;
card->num_dapm_widgets = ARRAY_SIZE(card_widgets);
card->dapm_routes = card_routes;
card->num_dapm_routes = ARRAY_SIZE(card_routes);
card->fully_routed = true;
ret = snd_soc_fixup_dai_links_platform_name(card, mach->mach_params.platform);
if (ret)
return ret;
return devm_snd_soc_register_card(dev, card);
}
static struct platform_driver avs_dmic_driver = {
.probe = avs_dmic_probe,
.driver = {
.name = "avs_dmic",
.pm = &snd_soc_pm_ops,
},
};
module_platform_driver(avs_dmic_driver);
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:avs_dmic");
// SPDX-License-Identifier: GPL-2.0-only
//
// Copyright(c) 2021-2022 Intel Corporation. All rights reserved.
//
// Authors: Cezary Rojewski <cezary.rojewski@intel.com>
// Amadeusz Slawinski <amadeuszx.slawinski@linux.intel.com>
//
#include <linux/platform_device.h>
#include <sound/hda_codec.h>
#include <sound/hda_i915.h>
#include <sound/soc.h>
#include <sound/soc-acpi.h>
#include "../../../codecs/hda.h"
static int avs_create_dai_links(struct device *dev, struct hda_codec *codec, int pcm_count,
const char *platform_name, struct snd_soc_dai_link **links)
{
struct snd_soc_dai_link_component *platform;
struct snd_soc_dai_link *dl;
struct hda_pcm *pcm;
const char *cname = dev_name(&codec->core.dev);
int i;
dl = devm_kcalloc(dev, pcm_count, sizeof(*dl), GFP_KERNEL);
platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL);
if (!dl || !platform)
return -ENOMEM;
platform->name = platform_name;
pcm = list_first_entry(&codec->pcm_list_head, struct hda_pcm, list);
for (i = 0; i < pcm_count; i++, pcm = list_next_entry(pcm, list)) {
dl[i].name = devm_kasprintf(dev, GFP_KERNEL, "%s link%d", cname, i);
if (!dl[i].name)
return -ENOMEM;
dl[i].id = i;
dl[i].nonatomic = 1;
dl[i].no_pcm = 1;
dl[i].dpcm_playback = 1;
dl[i].dpcm_capture = 1;
dl[i].platforms = platform;
dl[i].num_platforms = 1;
dl[i].codecs = devm_kzalloc(dev, sizeof(*dl->codecs), GFP_KERNEL);
dl[i].cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL);
if (!dl[i].codecs || !dl[i].cpus)
return -ENOMEM;
dl[i].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL, "%s-cpu%d", cname, i);
if (!dl[i].cpus->dai_name)
return -ENOMEM;
dl[i].codecs->name = devm_kstrdup(dev, cname, GFP_KERNEL);
dl[i].codecs->dai_name = pcm->name;
dl[i].num_codecs = 1;
dl[i].num_cpus = 1;
}
*links = dl;
return 0;
}
static int avs_create_dapm_routes(struct device *dev, struct hda_codec *codec, int pcm_count,
struct snd_soc_dapm_route **routes, int *num_routes)
{
struct snd_soc_dapm_route *dr;
struct hda_pcm *pcm;
const char *cname = dev_name(&codec->core.dev);
int i, n = 0;
/* at max twice the number of pcms */
dr = devm_kcalloc(dev, pcm_count * 2, sizeof(*dr), GFP_KERNEL);
if (!dr)
return -ENOMEM;
pcm = list_first_entry(&codec->pcm_list_head, struct hda_pcm, list);
for (i = 0; i < pcm_count; i++, pcm = list_next_entry(pcm, list)) {
struct hda_pcm_stream *stream;
int dir;
dir = SNDRV_PCM_STREAM_PLAYBACK;
stream = &pcm->stream[dir];
if (!stream->substreams)
goto capture_routes;
dr[n].sink = devm_kasprintf(dev, GFP_KERNEL, "%s %s", pcm->name,
snd_pcm_direction_name(dir));
dr[n].source = devm_kasprintf(dev, GFP_KERNEL, "%s-cpu%d Tx", cname, i);
if (!dr[n].sink || !dr[n].source)
return -ENOMEM;
n++;
capture_routes:
dir = SNDRV_PCM_STREAM_CAPTURE;
stream = &pcm->stream[dir];
if (!stream->substreams)
continue;
dr[n].sink = devm_kasprintf(dev, GFP_KERNEL, "%s-cpu%d Rx", cname, i);
dr[n].source = devm_kasprintf(dev, GFP_KERNEL, "%s %s", pcm->name,
snd_pcm_direction_name(dir));
if (!dr[n].sink || !dr[n].source)
return -ENOMEM;
n++;
}
*routes = dr;
*num_routes = n;
return 0;
}
/* Should be aligned with SectionPCM's name from topology */
#define FEDAI_NAME_PREFIX "HDMI"
static struct snd_pcm *
avs_card_hdmi_pcm_at(struct snd_soc_card *card, int hdmi_idx)
{
struct snd_soc_pcm_runtime *rtd;
int dir = SNDRV_PCM_STREAM_PLAYBACK;
for_each_card_rtds(card, rtd) {
struct snd_pcm *spcm;
int ret, n;
spcm = rtd->pcm ? rtd->pcm->streams[dir].pcm : NULL;
if (!spcm || !strstr(spcm->id, FEDAI_NAME_PREFIX))
continue;
ret = sscanf(spcm->id, FEDAI_NAME_PREFIX "%d", &n);
if (ret != 1)
continue;
if (n == hdmi_idx)
return rtd->pcm;
}
return NULL;
}
static int avs_card_late_probe(struct snd_soc_card *card)
{
struct snd_soc_acpi_mach *mach = dev_get_platdata(card->dev);
struct hda_codec *codec = mach->pdata;
struct hda_pcm *hpcm;
/* Topology pcm indexing is 1-based */
int i = 1;
list_for_each_entry(hpcm, &codec->pcm_list_head, list) {
struct snd_pcm *spcm;
spcm = avs_card_hdmi_pcm_at(card, i);
if (spcm) {
hpcm->pcm = spcm;
hpcm->device = spcm->device;
dev_info(card->dev, "%s: mapping HDMI converter %d to PCM %d (%p)\n",
__func__, i, hpcm->device, spcm);
} else {
hpcm->pcm = NULL;
hpcm->device = SNDRV_PCM_INVALID_DEVICE;
dev_warn(card->dev, "%s: no PCM in topology for HDMI converter %d\n",
__func__, i);
}
i++;
}
return hda_codec_probe_complete(codec);
}
static int avs_probing_link_init(struct snd_soc_pcm_runtime *rtm)
{
struct snd_soc_dapm_route *routes;
struct snd_soc_acpi_mach *mach;
struct snd_soc_dai_link *links = NULL;
struct snd_soc_card *card = rtm->card;
struct hda_codec *codec;
struct hda_pcm *pcm;
int ret, n, pcm_count = 0;
mach = dev_get_platdata(card->dev);
codec = mach->pdata;
if (list_empty(&codec->pcm_list_head))
return -EINVAL;
list_for_each_entry(pcm, &codec->pcm_list_head, list)
pcm_count++;
ret = avs_create_dai_links(card->dev, codec, pcm_count, mach->mach_params.platform, &links);
if (ret < 0) {
dev_err(card->dev, "create links failed: %d\n", ret);
return ret;
}
for (n = 0; n < pcm_count; n++) {
ret = snd_soc_add_pcm_runtime(card, &links[n]);
if (ret < 0) {
dev_err(card->dev, "add links failed: %d\n", ret);
return ret;
}
}
ret = avs_create_dapm_routes(card->dev, codec, pcm_count, &routes, &n);
if (ret < 0) {
dev_err(card->dev, "create routes failed: %d\n", ret);
return ret;
}
ret = snd_soc_dapm_add_routes(&card->dapm, routes, n);
if (ret < 0) {
dev_err(card->dev, "add routes failed: %d\n", ret);
return ret;
}
return 0;
}
SND_SOC_DAILINK_DEF(dummy, DAILINK_COMP_ARRAY(COMP_DUMMY()));
static struct snd_soc_dai_link probing_link = {
.name = "probing-LINK",
.id = -1,
.nonatomic = 1,
.no_pcm = 1,
.dpcm_playback = 1,
.dpcm_capture = 1,
.cpus = dummy,
.num_cpus = ARRAY_SIZE(dummy),
.init = avs_probing_link_init,
};
static int avs_hdaudio_probe(struct platform_device *pdev)
{
struct snd_soc_dai_link *binder;
struct snd_soc_acpi_mach *mach;
struct snd_soc_card *card;
struct device *dev = &pdev->dev;
struct hda_codec *codec;
mach = dev_get_platdata(dev);
codec = mach->pdata;
/* codec may be unloaded before card's probe() fires */
if (!device_is_registered(&codec->core.dev))
return -ENODEV;
binder = devm_kmemdup(dev, &probing_link, sizeof(probing_link), GFP_KERNEL);
if (!binder)
return -ENOMEM;
binder->platforms = devm_kzalloc(dev, sizeof(*binder->platforms), GFP_KERNEL);
binder->codecs = devm_kzalloc(dev, sizeof(*binder->codecs), GFP_KERNEL);
if (!binder->platforms || !binder->codecs)
return -ENOMEM;
binder->codecs->name = devm_kstrdup(dev, dev_name(&codec->core.dev), GFP_KERNEL);
if (!binder->codecs->name)
return -ENOMEM;
binder->platforms->name = mach->mach_params.platform;
binder->num_platforms = 1;
binder->codecs->dai_name = "codec-probing-DAI";
binder->num_codecs = 1;
card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
if (!card)
return -ENOMEM;
card->name = binder->codecs->name;
card->dev = dev;
card->owner = THIS_MODULE;
card->dai_link = binder;
card->num_links = 1;
card->fully_routed = true;
if (hda_codec_is_display(codec))
card->late_probe = avs_card_late_probe;
return devm_snd_soc_register_card(dev, card);
}
static struct platform_driver avs_hdaudio_driver = {
.probe = avs_hdaudio_probe,
.driver = {
.name = "avs_hdaudio",
.pm = &snd_soc_pm_ops,
},
};
module_platform_driver(avs_hdaudio_driver)
MODULE_DESCRIPTION("Intel HD-Audio machine driver");
MODULE_AUTHOR("Cezary Rojewski <cezary.rojewski@intel.com>");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:avs_hdaudio");
// SPDX-License-Identifier: GPL-2.0-only
//
// Copyright(c) 2021-2022 Intel Corporation. All rights reserved.
//
// Authors: Cezary Rojewski <cezary.rojewski@intel.com>
// Amadeusz Slawinski <amadeuszx.slawinski@linux.intel.com>
//
#include <linux/module.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
#include <sound/soc-acpi.h>
#include <sound/soc-dapm.h>
static int avs_create_dai_link(struct device *dev, const char *platform_name, int ssp_port,
struct snd_soc_dai_link **dai_link)
{
struct snd_soc_dai_link_component *platform;
struct snd_soc_dai_link *dl;
dl = devm_kzalloc(dev, sizeof(*dl), GFP_KERNEL);
platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL);
if (!dl || !platform)
return -ENOMEM;
platform->name = platform_name;
dl->name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-Codec", ssp_port);
dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL);
dl->codecs = devm_kzalloc(dev, sizeof(*dl->codecs), GFP_KERNEL);
if (!dl->name || !dl->cpus || !dl->codecs)
return -ENOMEM;
dl->cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d Pin", ssp_port);
dl->codecs->name = devm_kasprintf(dev, GFP_KERNEL, "snd-soc-dummy");
dl->codecs->dai_name = devm_kasprintf(dev, GFP_KERNEL, "snd-soc-dummy-dai");
if (!dl->cpus->dai_name || !dl->codecs->name || !dl->codecs->dai_name)
return -ENOMEM;
dl->num_cpus = 1;
dl->num_codecs = 1;
dl->platforms = platform;
dl->num_platforms = 1;
dl->id = 0;
dl->nonatomic = 1;
dl->no_pcm = 1;
dl->dpcm_capture = 1;
dl->dpcm_playback = 1;
*dai_link = dl;
return 0;
}
static int avs_create_dapm_routes(struct device *dev, int ssp_port,
struct snd_soc_dapm_route **routes, int *num_routes)
{
struct snd_soc_dapm_route *dr;
const int num_dr = 2;
dr = devm_kcalloc(dev, num_dr, sizeof(*dr), GFP_KERNEL);
if (!dr)
return -ENOMEM;
dr[0].sink = devm_kasprintf(dev, GFP_KERNEL, "ssp%dpb", ssp_port);
dr[0].source = devm_kasprintf(dev, GFP_KERNEL, "ssp%d Tx", ssp_port);
if (!dr[0].sink || !dr[0].source)
return -ENOMEM;
dr[1].sink = devm_kasprintf(dev, GFP_KERNEL, "ssp%d Rx", ssp_port);
dr[1].source = devm_kasprintf(dev, GFP_KERNEL, "ssp%dcp", ssp_port);
if (!dr[1].sink || !dr[1].source)
return -ENOMEM;
*routes = dr;
*num_routes = num_dr;
return 0;
}
static int avs_create_dapm_widgets(struct device *dev, int ssp_port,
struct snd_soc_dapm_widget **widgets, int *num_widgets)
{
struct snd_soc_dapm_widget *dw;
const int num_dw = 2;
dw = devm_kcalloc(dev, num_dw, sizeof(*dw), GFP_KERNEL);
if (!dw)
return -ENOMEM;
dw[0].id = snd_soc_dapm_hp;
dw[0].reg = SND_SOC_NOPM;
dw[0].name = devm_kasprintf(dev, GFP_KERNEL, "ssp%dpb", ssp_port);
if (!dw[0].name)
return -ENOMEM;
dw[1].id = snd_soc_dapm_mic;
dw[1].reg = SND_SOC_NOPM;
dw[1].name = devm_kasprintf(dev, GFP_KERNEL, "ssp%dcp", ssp_port);
if (!dw[1].name)
return -ENOMEM;
*widgets = dw;
*num_widgets = num_dw;
return 0;
}
static int avs_i2s_test_probe(struct platform_device *pdev)
{
struct snd_soc_dapm_widget *widgets;
struct snd_soc_dapm_route *routes;
struct snd_soc_dai_link *dai_link;
struct snd_soc_acpi_mach *mach;
struct snd_soc_card *card;
struct device *dev = &pdev->dev;
const char *pname;
int num_routes, num_widgets;
int ssp_port, ret;
mach = dev_get_platdata(dev);
pname = mach->mach_params.platform;
ssp_port = __ffs(mach->mach_params.i2s_link_mask);
card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
if (!card)
return -ENOMEM;
card->name = devm_kasprintf(dev, GFP_KERNEL, "ssp%ld-loopback", ssp_port);
if (!card->name)
return -ENOMEM;
ret = avs_create_dai_link(dev, pname, ssp_port, &dai_link);
if (ret) {
dev_err(dev, "Failed to create dai link: %d\n", ret);
return ret;
}
ret = avs_create_dapm_routes(dev, ssp_port, &routes, &num_routes);
if (ret) {
dev_err(dev, "Failed to create dapm routes: %d\n", ret);
return ret;
}
ret = avs_create_dapm_widgets(dev, ssp_port, &widgets, &num_widgets);
if (ret) {
dev_err(dev, "Failed to create dapm widgets: %d\n", ret);
return ret;
}
card->dev = dev;
card->owner = THIS_MODULE;
card->dai_link = dai_link;
card->num_links = 1;
card->dapm_routes = routes;
card->num_dapm_routes = num_routes;
card->dapm_widgets = widgets;
card->num_dapm_widgets = num_widgets;
card->fully_routed = true;
ret = snd_soc_fixup_dai_links_platform_name(card, pname);
if (ret)
return ret;
return devm_snd_soc_register_card(dev, card);
}
static struct platform_driver avs_i2s_test_driver = {
.probe = avs_i2s_test_probe,
.driver = {
.name = "avs_i2s_test",
.pm = &snd_soc_pm_ops,
},
};
module_platform_driver(avs_i2s_test_driver);
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:avs_i2s_test");
// SPDX-License-Identifier: GPL-2.0-only
//
// Copyright(c) 2021-2022 Intel Corporation. All rights reserved.
//
// Authors: Cezary Rojewski <cezary.rojewski@intel.com>
// Amadeusz Slawinski <amadeuszx.slawinski@linux.intel.com>
//
#include <linux/module.h>
#include <linux/platform_device.h>
#include <sound/soc.h>
#include <sound/soc-acpi.h>
#include <sound/soc-dapm.h>
static const struct snd_kcontrol_new card_controls[] = {
SOC_DAPM_PIN_SWITCH("Spk"),
};
static const struct snd_soc_dapm_widget card_widgets[] = {
SND_SOC_DAPM_SPK("Spk", NULL),
};
static const struct snd_soc_dapm_route card_base_routes[] = {
{ "Spk", NULL, "Speaker" },
};
static int avs_create_dai_link(struct device *dev, const char *platform_name, int ssp_port,
struct snd_soc_dai_link **dai_link)
{
struct snd_soc_dai_link_component *platform;
struct snd_soc_dai_link *dl;
dl = devm_kzalloc(dev, sizeof(*dl), GFP_KERNEL);
platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL);
if (!dl || !platform)
return -ENOMEM;
platform->name = platform_name;
dl->name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-Codec", ssp_port);
dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL);
dl->codecs = devm_kzalloc(dev, sizeof(*dl->codecs), GFP_KERNEL);
if (!dl->name || !dl->cpus || !dl->codecs)
return -ENOMEM;
dl->cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d Pin", ssp_port);
dl->codecs->name = devm_kasprintf(dev, GFP_KERNEL, "MX98357A:00");
dl->codecs->dai_name = devm_kasprintf(dev, GFP_KERNEL, "HiFi");
if (!dl->cpus->dai_name || !dl->codecs->name || !dl->codecs->dai_name)
return -ENOMEM;
dl->num_cpus = 1;
dl->num_codecs = 1;
dl->platforms = platform;
dl->num_platforms = 1;
dl->id = 0;
dl->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS;
dl->nonatomic = 1;
dl->no_pcm = 1;
dl->dpcm_playback = 1;
*dai_link = dl;
return 0;
}
static int avs_create_dapm_routes(struct device *dev, int ssp_port,
struct snd_soc_dapm_route **routes, int *num_routes)
{
struct snd_soc_dapm_route *dr;
const int num_base = ARRAY_SIZE(card_base_routes);
const int num_dr = num_base + 1;
int idx;
dr = devm_kcalloc(dev, num_dr, sizeof(*dr), GFP_KERNEL);
if (!dr)
return -ENOMEM;
memcpy(dr, card_base_routes, num_base * sizeof(*dr));
idx = num_base;
dr[idx].sink = devm_kasprintf(dev, GFP_KERNEL, "HiFi Playback");
dr[idx].source = devm_kasprintf(dev, GFP_KERNEL, "ssp%d Tx", ssp_port);
if (!dr[idx].sink || !dr[idx].source)
return -ENOMEM;
*routes = dr;
*num_routes = num_dr;
return 0;
}
static int avs_max98357a_probe(struct platform_device *pdev)
{
struct snd_soc_dapm_route *routes;
struct snd_soc_dai_link *dai_link;
struct snd_soc_acpi_mach *mach;
struct snd_soc_card *card;
struct device *dev = &pdev->dev;
const char *pname;
int num_routes, ssp_port, ret;
mach = dev_get_platdata(dev);
pname = mach->mach_params.platform;
ssp_port = __ffs(mach->mach_params.i2s_link_mask);
ret = avs_create_dai_link(dev, pname, ssp_port, &dai_link);
if (ret) {
dev_err(dev, "Failed to create dai link: %d", ret);
return ret;
}
ret = avs_create_dapm_routes(dev, ssp_port, &routes, &num_routes);
if (ret) {
dev_err(dev, "Failed to create dapm routes: %d", ret);
return ret;
}
card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
if (!card)
return -ENOMEM;
card->name = "avs_max98357a";
card->dev = dev;
card->owner = THIS_MODULE;
card->dai_link = dai_link;
card->num_links = 1;
card->controls = card_controls;
card->num_controls = ARRAY_SIZE(card_controls);
card->dapm_widgets = card_widgets;
card->num_dapm_widgets = ARRAY_SIZE(card_widgets);
card->dapm_routes = routes;
card->num_dapm_routes = num_routes;
card->fully_routed = true;
ret = snd_soc_fixup_dai_links_platform_name(card, pname);
if (ret)
return ret;
return devm_snd_soc_register_card(dev, card);
}
static struct platform_driver avs_max98357a_driver = {
.probe = avs_max98357a_probe,
.driver = {
.name = "avs_max98357a",
.pm = &snd_soc_pm_ops,
},
};
module_platform_driver(avs_max98357a_driver)
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:avs_max98357a");
// SPDX-License-Identifier: GPL-2.0-only
//
// Copyright(c) 2022 Intel Corporation. All rights reserved.
//
// Authors: Cezary Rojewski <cezary.rojewski@intel.com>
// Amadeusz Slawinski <amadeuszx.slawinski@linux.intel.com>
//
#include <linux/module.h>
#include <linux/platform_device.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
#include <sound/soc-acpi.h>
#include <sound/soc-dapm.h>
#define MAX98373_DEV0_NAME "i2c-MX98373:00"
#define MAX98373_DEV1_NAME "i2c-MX98373:01"
#define MAX98373_CODEC_NAME "max98373-aif1"
static struct snd_soc_codec_conf card_codec_conf[] = {
{
.dlc = COMP_CODEC_CONF(MAX98373_DEV0_NAME),
.name_prefix = "Right",
},
{
.dlc = COMP_CODEC_CONF(MAX98373_DEV1_NAME),
.name_prefix = "Left",
},
};
static const struct snd_kcontrol_new card_controls[] = {
SOC_DAPM_PIN_SWITCH("Left Spk"),
SOC_DAPM_PIN_SWITCH("Right Spk"),
};
static const struct snd_soc_dapm_widget card_widgets[] = {
SND_SOC_DAPM_SPK("Left Spk", NULL),
SND_SOC_DAPM_SPK("Right Spk", NULL),
};
static const struct snd_soc_dapm_route card_base_routes[] = {
{ "Left Spk", NULL, "Left BE_OUT" },
{ "Right Spk", NULL, "Right BE_OUT" },
};
static int
avs_max98373_be_fixup(struct snd_soc_pcm_runtime *runrime, struct snd_pcm_hw_params *params)
{
struct snd_interval *rate, *channels;
struct snd_mask *fmt;
rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
/* The ADSP will covert the FE rate to 48k, stereo */
rate->min = rate->max = 48000;
channels->min = channels->max = 2;
/* set SSP0 to 16 bit */
snd_mask_none(fmt);
snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE);
return 0;
}
static int avs_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);
struct snd_soc_dai *codec_dai;
int ret, i;
for_each_rtd_codec_dais(runtime, i, codec_dai) {
if (!strcmp(codec_dai->component->name, MAX98373_DEV0_NAME)) {
ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x30, 3, 8, 16);
if (ret < 0) {
dev_err(runtime->dev, "DEV0 TDM slot err:%d\n", ret);
return ret;
}
}
if (!strcmp(codec_dai->component->name, MAX98373_DEV1_NAME)) {
ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xC0, 3, 8, 16);
if (ret < 0) {
dev_err(runtime->dev, "DEV1 TDM slot err:%d\n", ret);
return ret;
}
}
}
return 0;
}
static const struct snd_soc_ops avs_max98373_ops = {
.hw_params = avs_max98373_hw_params,
};
static int avs_create_dai_link(struct device *dev, const char *platform_name, int ssp_port,
struct snd_soc_dai_link **dai_link)
{
struct snd_soc_dai_link_component *platform;
struct snd_soc_dai_link *dl;
dl = devm_kzalloc(dev, sizeof(*dl), GFP_KERNEL);
platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL);
if (!dl || !platform)
return -ENOMEM;
platform->name = platform_name;
dl->name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-Codec", ssp_port);
dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL);
dl->codecs = devm_kzalloc(dev, sizeof(*dl->codecs) * 2, GFP_KERNEL);
if (!dl->name || !dl->cpus || !dl->codecs)
return -ENOMEM;
dl->cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d Pin", ssp_port);
dl->codecs[0].name = devm_kasprintf(dev, GFP_KERNEL, MAX98373_DEV0_NAME);
dl->codecs[0].dai_name = devm_kasprintf(dev, GFP_KERNEL, MAX98373_CODEC_NAME);
dl->codecs[1].name = devm_kasprintf(dev, GFP_KERNEL, MAX98373_DEV1_NAME);
dl->codecs[1].dai_name = devm_kasprintf(dev, GFP_KERNEL, MAX98373_CODEC_NAME);
if (!dl->cpus->dai_name || !dl->codecs[0].name || !dl->codecs[0].dai_name ||
!dl->codecs[1].name || !dl->codecs[1].dai_name)
return -ENOMEM;
dl->num_cpus = 1;
dl->num_codecs = 2;
dl->platforms = platform;
dl->num_platforms = 1;
dl->id = 0;
dl->dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBC_CFC;
dl->be_hw_params_fixup = avs_max98373_be_fixup;
dl->nonatomic = 1;
dl->no_pcm = 1;
dl->dpcm_capture = 1;
dl->dpcm_playback = 1;
dl->ignore_pmdown_time = 1;
dl->ops = &avs_max98373_ops;
*dai_link = dl;
return 0;
}
static int avs_create_dapm_routes(struct device *dev, int ssp_port,
struct snd_soc_dapm_route **routes, int *num_routes)
{
struct snd_soc_dapm_route *dr;
const int num_base = ARRAY_SIZE(card_base_routes);
const int num_dr = num_base + 2;
int idx;
dr = devm_kcalloc(dev, num_dr, sizeof(*dr), GFP_KERNEL);
if (!dr)
return -ENOMEM;
memcpy(dr, card_base_routes, num_base * sizeof(*dr));
idx = num_base;
dr[idx].sink = devm_kasprintf(dev, GFP_KERNEL, "Left HiFi Playback");
dr[idx].source = devm_kasprintf(dev, GFP_KERNEL, "ssp%d Tx", ssp_port);
if (!dr[idx].sink || !dr[idx].source)
return -ENOMEM;
idx++;
dr[idx].sink = devm_kasprintf(dev, GFP_KERNEL, "Right HiFi Playback");
dr[idx].source = devm_kasprintf(dev, GFP_KERNEL, "ssp%d Tx", ssp_port);
if (!dr[idx].sink || !dr[idx].source)
return -ENOMEM;
*routes = dr;
*num_routes = num_dr;
return 0;
}
static int avs_max98373_probe(struct platform_device *pdev)
{
struct snd_soc_dapm_route *routes;
struct snd_soc_dai_link *dai_link;
struct snd_soc_acpi_mach *mach;
struct snd_soc_card *card;
struct device *dev = &pdev->dev;
const char *pname;
int num_routes, ssp_port, ret;
mach = dev_get_platdata(dev);
pname = mach->mach_params.platform;
ssp_port = __ffs(mach->mach_params.i2s_link_mask);
ret = avs_create_dai_link(dev, pname, ssp_port, &dai_link);
if (ret) {
dev_err(dev, "Failed to create dai link: %d", ret);
return ret;
}
ret = avs_create_dapm_routes(dev, ssp_port, &routes, &num_routes);
if (ret) {
dev_err(dev, "Failed to create dapm routes: %d", ret);
return ret;
}
card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
if (!card)
return -ENOMEM;
card->name = "avs_max98373";
card->dev = dev;
card->owner = THIS_MODULE;
card->dai_link = dai_link;
card->num_links = 1;
card->codec_conf = card_codec_conf;
card->num_configs = ARRAY_SIZE(card_codec_conf);
card->controls = card_controls;
card->num_controls = ARRAY_SIZE(card_controls);
card->dapm_widgets = card_widgets;
card->num_dapm_widgets = ARRAY_SIZE(card_widgets);
card->dapm_routes = routes;
card->num_dapm_routes = num_routes;
card->fully_routed = true;
ret = snd_soc_fixup_dai_links_platform_name(card, pname);
if (ret)
return ret;
return devm_snd_soc_register_card(dev, card);
}
static struct platform_driver avs_max98373_driver = {
.probe = avs_max98373_probe,
.driver = {
.name = "avs_max98373",
.pm = &snd_soc_pm_ops,
},
};
module_platform_driver(avs_max98373_driver)
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:avs_max98373");
// SPDX-License-Identifier: GPL-2.0-only
//
// Copyright(c) 2021-2022 Intel Corporation. All rights reserved.
//
// Authors: Cezary Rojewski <cezary.rojewski@intel.com>
// Amadeusz Slawinski <amadeuszx.slawinski@linux.intel.com>
//
#include <linux/input.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <sound/core.h>
#include <sound/jack.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
#include <sound/soc-acpi.h>
#include "../../../codecs/nau8825.h"
#define SKL_NUVOTON_CODEC_DAI "nau8825-hifi"
static int
avs_nau8825_clock_control(struct snd_soc_dapm_widget *w, struct snd_kcontrol *control, int event)
{
struct snd_soc_dapm_context *dapm = w->dapm;
struct snd_soc_card *card = dapm->card;
struct snd_soc_dai *codec_dai;
int ret;
codec_dai = snd_soc_card_get_codec_dai(card, SKL_NUVOTON_CODEC_DAI);
if (!codec_dai) {
dev_err(card->dev, "Codec dai not found\n");
return -EINVAL;
}
if (!SND_SOC_DAPM_EVENT_ON(event)) {
ret = snd_soc_dai_set_sysclk(codec_dai, NAU8825_CLK_INTERNAL, 0, SND_SOC_CLOCK_IN);
if (ret < 0) {
dev_err(card->dev, "set sysclk err = %d\n", ret);
return ret;
}
}
return 0;
}
static const struct snd_kcontrol_new card_controls[] = {
SOC_DAPM_PIN_SWITCH("Headphone Jack"),
SOC_DAPM_PIN_SWITCH("Headset Mic"),
};
static const struct snd_soc_dapm_widget card_widgets[] = {
SND_SOC_DAPM_HP("Headphone Jack", NULL),
SND_SOC_DAPM_MIC("Headset Mic", NULL),
SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0, avs_nau8825_clock_control,
SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
};
static const struct snd_soc_dapm_route card_base_routes[] = {
{ "Headphone Jack", NULL, "HPOL" },
{ "Headphone Jack", NULL, "HPOR" },
{ "MIC", NULL, "Headset Mic" },
{ "Headphone Jack", NULL, "Platform Clock" },
{ "Headset Mic", NULL, "Platform Clock" },
};
static struct snd_soc_jack_pin card_headset_pins[] = {
{
.pin = "Headphone Jack",
.mask = SND_JACK_HEADPHONE,
},
{
.pin = "Headset Mic",
.mask = SND_JACK_MICROPHONE,
},
};
static int avs_nau8825_codec_init(struct snd_soc_pcm_runtime *runtime)
{
struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(runtime, 0);
struct snd_soc_component *component = codec_dai->component;
struct snd_soc_jack_pin *pins;
struct snd_soc_jack *jack;
struct snd_soc_card *card = runtime->card;
int num_pins, ret;
jack = snd_soc_card_get_drvdata(card);
num_pins = ARRAY_SIZE(card_headset_pins);
pins = devm_kmemdup(card->dev, card_headset_pins, sizeof(*pins) * num_pins, GFP_KERNEL);
if (!pins)
return -ENOMEM;
/*
* 4 buttons here map to the google Reference headset.
* The use of these buttons can be decided by the user space.
*/
ret = snd_soc_card_jack_new_pins(card, "Headset", SND_JACK_HEADSET | SND_JACK_BTN_0 |
SND_JACK_BTN_1 | SND_JACK_BTN_2 | SND_JACK_BTN_3,
jack, pins, num_pins);
if (ret)
return ret;
snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
//snd_soc_component_set_jack(component, jack, NULL);
// TODO: Fix nau8825 codec to use .set_jack, like everyone else
nau8825_enable_jack_detect(component, jack);
return 0;
}
static int
avs_nau8825_be_fixup(struct snd_soc_pcm_runtime *runtime, struct snd_pcm_hw_params *params)
{
struct snd_interval *rate, *channels;
struct snd_mask *fmt;
rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
/* The ADSP will convert the FE rate to 48k, stereo */
rate->min = rate->max = 48000;
channels->min = channels->max = 2;
/* set SSP to 24 bit */
snd_mask_none(fmt);
snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE);
return 0;
}
static int avs_nau8825_trigger(struct snd_pcm_substream *substream, int cmd)
{
struct snd_pcm_runtime *runtime = substream->runtime;
struct snd_soc_pcm_runtime *rtm = asoc_substream_to_rtd(substream);
struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtm, 0);
int ret = 0;
switch (cmd) {
case SNDRV_PCM_TRIGGER_START:
ret = snd_soc_dai_set_sysclk(codec_dai, NAU8825_CLK_FLL_FS, 0, SND_SOC_CLOCK_IN);
if (ret < 0) {
dev_err(codec_dai->dev, "can't set FS clock %d\n", ret);
break;
}
ret = snd_soc_dai_set_pll(codec_dai, 0, 0, runtime->rate, runtime->rate * 256);
if (ret < 0)
dev_err(codec_dai->dev, "can't set FLL: %d\n", ret);
break;
case SNDRV_PCM_TRIGGER_RESUME:
ret = snd_soc_dai_set_pll(codec_dai, 0, 0, runtime->rate, runtime->rate * 256);
if (ret < 0)
dev_err(codec_dai->dev, "can't set FLL: %d\n", ret);
break;
}
return ret;
}
static const struct snd_soc_ops avs_nau8825_ops = {
.trigger = avs_nau8825_trigger,
};
static int avs_create_dai_link(struct device *dev, const char *platform_name, int ssp_port,
struct snd_soc_dai_link **dai_link)
{
struct snd_soc_dai_link_component *platform;
struct snd_soc_dai_link *dl;
dl = devm_kzalloc(dev, sizeof(*dl), GFP_KERNEL);
platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL);
if (!dl || !platform)
return -ENOMEM;
platform->name = platform_name;
dl->name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-Codec", ssp_port);
dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL);
dl->codecs = devm_kzalloc(dev, sizeof(*dl->codecs), GFP_KERNEL);
if (!dl->name || !dl->cpus || !dl->codecs)
return -ENOMEM;
dl->cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d Pin", ssp_port);
dl->codecs->name = devm_kasprintf(dev, GFP_KERNEL, "i2c-10508825:00");
dl->codecs->dai_name = devm_kasprintf(dev, GFP_KERNEL, SKL_NUVOTON_CODEC_DAI);
if (!dl->cpus->dai_name || !dl->codecs->name || !dl->codecs->dai_name)
return -ENOMEM;
dl->num_cpus = 1;
dl->num_codecs = 1;
dl->platforms = platform;
dl->num_platforms = 1;
dl->id = 0;
dl->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS;
dl->init = avs_nau8825_codec_init;
dl->be_hw_params_fixup = avs_nau8825_be_fixup;
dl->ops = &avs_nau8825_ops;
dl->nonatomic = 1;
dl->no_pcm = 1;
dl->dpcm_capture = 1;
dl->dpcm_playback = 1;
*dai_link = dl;
return 0;
}
static int avs_create_dapm_routes(struct device *dev, int ssp_port,
struct snd_soc_dapm_route **routes, int *num_routes)
{
struct snd_soc_dapm_route *dr;
const int num_base = ARRAY_SIZE(card_base_routes);
const int num_dr = num_base + 2;
int idx;
dr = devm_kcalloc(dev, num_dr, sizeof(*dr), GFP_KERNEL);
if (!dr)
return -ENOMEM;
memcpy(dr, card_base_routes, num_base * sizeof(*dr));
idx = num_base;
dr[idx].sink = devm_kasprintf(dev, GFP_KERNEL, "Playback");
dr[idx].source = devm_kasprintf(dev, GFP_KERNEL, "ssp%d Tx", ssp_port);
if (!dr[idx].sink || !dr[idx].source)
return -ENOMEM;
idx++;
dr[idx].sink = devm_kasprintf(dev, GFP_KERNEL, "ssp%d Rx", ssp_port);
dr[idx].source = devm_kasprintf(dev, GFP_KERNEL, "Capture");
if (!dr[idx].sink || !dr[idx].source)
return -ENOMEM;
*routes = dr;
*num_routes = num_dr;
return 0;
}
static int avs_card_set_jack(struct snd_soc_card *card, struct snd_soc_jack *jack)
{
struct snd_soc_component *component;
for_each_card_components(card, component)
snd_soc_component_set_jack(component, jack, NULL);
return 0;
}
static int avs_card_remove(struct snd_soc_card *card)
{
return avs_card_set_jack(card, NULL);
}
static int avs_card_suspend_pre(struct snd_soc_card *card)
{
return avs_card_set_jack(card, NULL);
}
static int avs_card_resume_post(struct snd_soc_card *card)
{
struct snd_soc_dai *codec_dai = snd_soc_card_get_codec_dai(card, SKL_NUVOTON_CODEC_DAI);
struct snd_soc_jack *jack = snd_soc_card_get_drvdata(card);
if (!codec_dai) {
dev_err(card->dev, "Codec dai not found\n");
return -EINVAL;
}
if (codec_dai->stream_active[SNDRV_PCM_STREAM_PLAYBACK] &&
codec_dai->playback_widget->active)
snd_soc_dai_set_sysclk(codec_dai, NAU8825_CLK_FLL_FS, 0, SND_SOC_CLOCK_IN);
return avs_card_set_jack(card, jack);
}
static int avs_nau8825_probe(struct platform_device *pdev)
{
struct snd_soc_dapm_route *routes;
struct snd_soc_dai_link *dai_link;
struct snd_soc_acpi_mach *mach;
struct snd_soc_card *card;
struct snd_soc_jack *jack;
struct device *dev = &pdev->dev;
const char *pname;
int num_routes, ssp_port, ret;
mach = dev_get_platdata(dev);
pname = mach->mach_params.platform;
ssp_port = __ffs(mach->mach_params.i2s_link_mask);
ret = avs_create_dai_link(dev, pname, ssp_port, &dai_link);
if (ret) {
dev_err(dev, "Failed to create dai link: %d", ret);
return ret;
}
ret = avs_create_dapm_routes(dev, ssp_port, &routes, &num_routes);
if (ret) {
dev_err(dev, "Failed to create dapm routes: %d", ret);
return ret;
}
jack = devm_kzalloc(dev, sizeof(*jack), GFP_KERNEL);
card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
if (!jack || !card)
return -ENOMEM;
card->name = "avs_nau8825";
card->dev = dev;
card->owner = THIS_MODULE;
card->remove = avs_card_remove;
card->suspend_pre = avs_card_suspend_pre;
card->resume_post = avs_card_resume_post;
card->dai_link = dai_link;
card->num_links = 1;
card->controls = card_controls;
card->num_controls = ARRAY_SIZE(card_controls);
card->dapm_widgets = card_widgets;
card->num_dapm_widgets = ARRAY_SIZE(card_widgets);
card->dapm_routes = routes;
card->num_dapm_routes = num_routes;
card->fully_routed = true;
snd_soc_card_set_drvdata(card, jack);
ret = snd_soc_fixup_dai_links_platform_name(card, pname);
if (ret)
return ret;
return devm_snd_soc_register_card(dev, card);
}
static struct platform_driver avs_nau8825_driver = {
.probe = avs_nau8825_probe,
.driver = {
.name = "avs_nau8825",
.pm = &snd_soc_pm_ops,
},
};
module_platform_driver(avs_nau8825_driver)
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:avs_nau8825");
// SPDX-License-Identifier: GPL-2.0-only
//
// Copyright(c) 2021-2022 Intel Corporation. All rights reserved.
//
// Authors: Cezary Rojewski <cezary.rojewski@intel.com>
// Amadeusz Slawinski <amadeuszx.slawinski@linux.intel.com>
//
#include <linux/module.h>
#include <sound/jack.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
#include <sound/soc-acpi.h>
#include "../../../codecs/rt274.h"
#define AVS_RT274_FREQ_OUT 24000000
#define AVS_RT274_BE_FIXUP_RATE 48000
#define RT274_CODEC_DAI "rt274-aif1"
static const struct snd_kcontrol_new card_controls[] = {
SOC_DAPM_PIN_SWITCH("Headphone Jack"),
SOC_DAPM_PIN_SWITCH("Mic Jack"),
};
static int
avs_rt274_clock_control(struct snd_soc_dapm_widget *w, struct snd_kcontrol *control, int event)
{
struct snd_soc_dapm_context *dapm = w->dapm;
struct snd_soc_card *card = dapm->card;
struct snd_soc_dai *codec_dai;
int ret;
codec_dai = snd_soc_card_get_codec_dai(card, RT274_CODEC_DAI);
if (!codec_dai)
return -EINVAL;
/* Codec needs clock for Jack detection and button press */
ret = snd_soc_dai_set_sysclk(codec_dai, RT274_SCLK_S_PLL2, AVS_RT274_FREQ_OUT,
SND_SOC_CLOCK_IN);
if (ret < 0) {
dev_err(codec_dai->dev, "set codec sysclk failed: %d\n", ret);
return ret;
}
if (SND_SOC_DAPM_EVENT_ON(event)) {
int ratio = 100;
snd_soc_dai_set_bclk_ratio(codec_dai, ratio);
ret = snd_soc_dai_set_pll(codec_dai, 0, RT274_PLL2_S_BCLK,
AVS_RT274_BE_FIXUP_RATE * ratio, AVS_RT274_FREQ_OUT);
if (ret) {
dev_err(codec_dai->dev, "failed to enable PLL2: %d\n", ret);
return ret;
}
}
return 0;
}
static const struct snd_soc_dapm_widget card_widgets[] = {
SND_SOC_DAPM_HP("Headphone Jack", NULL),
SND_SOC_DAPM_MIC("Mic Jack", NULL),
SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0, avs_rt274_clock_control,
SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
};
static const struct snd_soc_dapm_route card_base_routes[] = {
{"Headphone Jack", NULL, "HPO Pin"},
{"MIC", NULL, "Mic Jack"},
{"Headphone Jack", NULL, "Platform Clock"},
{"MIC", NULL, "Platform Clock"},
};
static struct snd_soc_jack_pin card_headset_pins[] = {
{
.pin = "Headphone Jack",
.mask = SND_JACK_HEADPHONE,
},
{
.pin = "Mic Jack",
.mask = SND_JACK_MICROPHONE,
},
};
static int avs_rt274_codec_init(struct snd_soc_pcm_runtime *runtime)
{
struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(runtime, 0);
struct snd_soc_component *component = codec_dai->component;
struct snd_soc_jack_pin *pins;
struct snd_soc_jack *jack;
struct snd_soc_card *card = runtime->card;
int num_pins, ret;
jack = snd_soc_card_get_drvdata(card);
num_pins = ARRAY_SIZE(card_headset_pins);
pins = devm_kmemdup(card->dev, card_headset_pins, sizeof(*pins) * num_pins, GFP_KERNEL);
if (!pins)
return -ENOMEM;
ret = snd_soc_card_jack_new_pins(card, "Headset", SND_JACK_HEADSET, jack, pins, num_pins);
if (ret)
return ret;
snd_soc_component_set_jack(component, jack, NULL);
/* TDM 4 slots 24 bit, set Rx & Tx bitmask to 4 active slots */
ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xF, 0xF, 4, 24);
if (ret < 0) {
dev_err(card->dev, "can't set codec pcm format %d\n", ret);
return ret;
}
card->dapm.idle_bias_off = true;
return 0;
}
static int avs_rt274_be_fixup(struct snd_soc_pcm_runtime *runtime, struct snd_pcm_hw_params *params)
{
struct snd_interval *rate, *channels;
struct snd_mask *fmt;
rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
/* The ADSP will convert the FE rate to 48k, stereo */
rate->min = rate->max = AVS_RT274_BE_FIXUP_RATE;
channels->min = channels->max = 2;
/* set SSPN to 24 bit */
snd_mask_none(fmt);
snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE);
return 0;
}
static int avs_create_dai_link(struct device *dev, const char *platform_name, int ssp_port,
struct snd_soc_dai_link **dai_link)
{
struct snd_soc_dai_link_component *platform;
struct snd_soc_dai_link *dl;
dl = devm_kzalloc(dev, sizeof(*dl), GFP_KERNEL);
platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL);
if (!dl || !platform)
return -ENOMEM;
platform->name = platform_name;
dl->name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-Codec", ssp_port);
dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL);
dl->codecs = devm_kzalloc(dev, sizeof(*dl->codecs), GFP_KERNEL);
if (!dl->name || !dl->cpus || !dl->codecs)
return -ENOMEM;
dl->cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d Pin", ssp_port);
dl->codecs->name = devm_kasprintf(dev, GFP_KERNEL, "i2c-INT34C2:00");
dl->codecs->dai_name = devm_kasprintf(dev, GFP_KERNEL, "rt274-aif1");
if (!dl->cpus->dai_name || !dl->codecs->name || !dl->codecs->dai_name)
return -ENOMEM;
dl->num_cpus = 1;
dl->num_codecs = 1;
dl->platforms = platform;
dl->num_platforms = 1;
dl->id = 0;
dl->dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS;
dl->init = avs_rt274_codec_init;
dl->be_hw_params_fixup = avs_rt274_be_fixup;
dl->nonatomic = 1;
dl->no_pcm = 1;
dl->dpcm_capture = 1;
dl->dpcm_playback = 1;
*dai_link = dl;
return 0;
}
static int avs_create_dapm_routes(struct device *dev, int ssp_port,
struct snd_soc_dapm_route **routes, int *num_routes)
{
struct snd_soc_dapm_route *dr;
const int num_base = ARRAY_SIZE(card_base_routes);
const int num_dr = num_base + 2;
int idx;
dr = devm_kcalloc(dev, num_dr, sizeof(*dr), GFP_KERNEL);
if (!dr)
return -ENOMEM;
memcpy(dr, card_base_routes, num_base * sizeof(*dr));
idx = num_base;
dr[idx].sink = devm_kasprintf(dev, GFP_KERNEL, "AIF1 Playback");
dr[idx].source = devm_kasprintf(dev, GFP_KERNEL, "ssp%d Tx", ssp_port);
if (!dr[idx].sink || !dr[idx].source)
return -ENOMEM;
idx++;
dr[idx].sink = devm_kasprintf(dev, GFP_KERNEL, "ssp%d Rx", ssp_port);
dr[idx].source = devm_kasprintf(dev, GFP_KERNEL, "AIF1 Capture");
if (!dr[idx].sink || !dr[idx].source)
return -ENOMEM;
*routes = dr;
*num_routes = num_dr;
return 0;
}
static int avs_card_set_jack(struct snd_soc_card *card, struct snd_soc_jack *jack)
{
struct snd_soc_component *component;
for_each_card_components(card, component)
snd_soc_component_set_jack(component, jack, NULL);
return 0;
}
static int avs_card_remove(struct snd_soc_card *card)
{
return avs_card_set_jack(card, NULL);
}
static int avs_card_suspend_pre(struct snd_soc_card *card)
{
return avs_card_set_jack(card, NULL);
}
static int avs_card_resume_post(struct snd_soc_card *card)
{
struct snd_soc_jack *jack = snd_soc_card_get_drvdata(card);
return avs_card_set_jack(card, jack);
}
static int avs_rt274_probe(struct platform_device *pdev)
{
struct snd_soc_dapm_route *routes;
struct snd_soc_dai_link *dai_link;
struct snd_soc_acpi_mach *mach;
struct snd_soc_card *card;
struct snd_soc_jack *jack;
struct device *dev = &pdev->dev;
const char *pname;
int num_routes, ssp_port, ret;
mach = dev_get_platdata(dev);
pname = mach->mach_params.platform;
ssp_port = __ffs(mach->mach_params.i2s_link_mask);
ret = avs_create_dai_link(dev, pname, ssp_port, &dai_link);
if (ret) {
dev_err(dev, "Failed to create dai link: %d", ret);
return ret;
}
ret = avs_create_dapm_routes(dev, ssp_port, &routes, &num_routes);
if (ret) {
dev_err(dev, "Failed to create dapm routes: %d", ret);
return ret;
}
jack = devm_kzalloc(dev, sizeof(*jack), GFP_KERNEL);
card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
if (!jack || !card)
return -ENOMEM;
card->name = "avs_rt274";
card->dev = dev;
card->owner = THIS_MODULE;
card->remove = avs_card_remove;
card->suspend_pre = avs_card_suspend_pre;
card->resume_post = avs_card_resume_post;
card->dai_link = dai_link;
card->num_links = 1;
card->controls = card_controls;
card->num_controls = ARRAY_SIZE(card_controls);
card->dapm_widgets = card_widgets;
card->num_dapm_widgets = ARRAY_SIZE(card_widgets);
card->dapm_routes = routes;
card->num_dapm_routes = num_routes;
card->fully_routed = true;
snd_soc_card_set_drvdata(card, jack);
ret = snd_soc_fixup_dai_links_platform_name(card, pname);
if (ret)
return ret;
return devm_snd_soc_register_card(dev, card);
}
static struct platform_driver avs_rt274_driver = {
.probe = avs_rt274_probe,
.driver = {
.name = "avs_rt274",
.pm = &snd_soc_pm_ops,
},
};
module_platform_driver(avs_rt274_driver);
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:avs_rt274");
// SPDX-License-Identifier: GPL-2.0-only
//
// Copyright(c) 2021-2022 Intel Corporation. All rights reserved.
//
// Authors: Cezary Rojewski <cezary.rojewski@intel.com>
// Amadeusz Slawinski <amadeuszx.slawinski@linux.intel.com>
//
#include <linux/module.h>
#include <sound/jack.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
#include <sound/soc-acpi.h>
#include "../../../codecs/rt286.h"
static const struct snd_kcontrol_new card_controls[] = {
SOC_DAPM_PIN_SWITCH("Headphone Jack"),
SOC_DAPM_PIN_SWITCH("Mic Jack"),
SOC_DAPM_PIN_SWITCH("Speaker"),
};
static const struct snd_soc_dapm_widget card_widgets[] = {
SND_SOC_DAPM_HP("Headphone Jack", NULL),
SND_SOC_DAPM_MIC("Mic Jack", NULL),
SND_SOC_DAPM_SPK("Speaker", NULL),
};
static const struct snd_soc_dapm_route card_base_routes[] = {
/* HP jack connectors - unknown if we have jack detect */
{"Headphone Jack", NULL, "HPO Pin"},
{"MIC1", NULL, "Mic Jack"},
{"Speaker", NULL, "SPOR"},
{"Speaker", NULL, "SPOL"},
};
static struct snd_soc_jack_pin card_headset_pins[] = {
{
.pin = "Headphone Jack",
.mask = SND_JACK_HEADPHONE,
},
{
.pin = "Mic Jack",
.mask = SND_JACK_MICROPHONE,
},
};
static int avs_rt286_codec_init(struct snd_soc_pcm_runtime *runtime)
{
struct snd_soc_component *component = asoc_rtd_to_codec(runtime, 0)->component;
struct snd_soc_jack_pin *pins;
struct snd_soc_jack *jack;
struct snd_soc_card *card = runtime->card;
int num_pins, ret;
jack = snd_soc_card_get_drvdata(card);
num_pins = ARRAY_SIZE(card_headset_pins);
pins = devm_kmemdup(card->dev, card_headset_pins, sizeof(*pins) * num_pins, GFP_KERNEL);
if (!pins)
return -ENOMEM;
ret = snd_soc_card_jack_new_pins(card, "Headset", SND_JACK_HEADSET | SND_JACK_BTN_0, jack,
pins, num_pins);
if (ret)
return ret;
snd_soc_component_set_jack(component, jack, NULL);
return 0;
}
static int avs_rt286_be_fixup(struct snd_soc_pcm_runtime *runtime, struct snd_pcm_hw_params *params)
{
struct snd_interval *rate, *channels;
struct snd_mask *fmt;
rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
/* The ADSP will convert the FE rate to 48k, stereo */
rate->min = rate->max = 48000;
channels->min = channels->max = 2;
/* set SSP0 to 24 bit */
snd_mask_none(fmt);
snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE);
return 0;
}
static int
avs_rt286_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
{
struct snd_soc_pcm_runtime *runtime = substream->private_data;
struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(runtime, 0);
int ret;
ret = snd_soc_dai_set_sysclk(codec_dai, RT286_SCLK_S_PLL, 24000000, SND_SOC_CLOCK_IN);
if (ret < 0)
dev_err(runtime->dev, "Set codec sysclk failed: %d\n", ret);
return ret;
}
static const struct snd_soc_ops avs_rt286_ops = {
.hw_params = avs_rt286_hw_params,
};
static int avs_create_dai_link(struct device *dev, const char *platform_name, int ssp_port,
struct snd_soc_dai_link **dai_link)
{
struct snd_soc_dai_link_component *platform;
struct snd_soc_dai_link *dl;
dl = devm_kzalloc(dev, sizeof(*dl), GFP_KERNEL);
platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL);
if (!dl || !platform)
return -ENOMEM;
platform->name = platform_name;
dl->name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-Codec", ssp_port);
dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL);
dl->codecs = devm_kzalloc(dev, sizeof(*dl->codecs), GFP_KERNEL);
if (!dl->name || !dl->cpus || !dl->codecs)
return -ENOMEM;
dl->cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d Pin", ssp_port);
dl->codecs->name = devm_kasprintf(dev, GFP_KERNEL, "i2c-INT343A:00");
dl->codecs->dai_name = devm_kasprintf(dev, GFP_KERNEL, "rt286-aif1");
if (!dl->cpus->dai_name || !dl->codecs->name || !dl->codecs->dai_name)
return -ENOMEM;
dl->num_cpus = 1;
dl->num_codecs = 1;
dl->platforms = platform;
dl->num_platforms = 1;
dl->id = 0;
dl->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS;
dl->init = avs_rt286_codec_init;
dl->be_hw_params_fixup = avs_rt286_be_fixup;
dl->ops = &avs_rt286_ops;
dl->nonatomic = 1;
dl->no_pcm = 1;
dl->dpcm_capture = 1;
dl->dpcm_playback = 1;
*dai_link = dl;
return 0;
}
static int avs_create_dapm_routes(struct device *dev, int ssp_port,
struct snd_soc_dapm_route **routes, int *num_routes)
{
struct snd_soc_dapm_route *dr;
const int num_base = ARRAY_SIZE(card_base_routes);
const int num_dr = num_base + 2;
int idx;
dr = devm_kcalloc(dev, num_dr, sizeof(*dr), GFP_KERNEL);
if (!dr)
return -ENOMEM;
memcpy(dr, card_base_routes, num_base * sizeof(*dr));
idx = num_base;
dr[idx].sink = devm_kasprintf(dev, GFP_KERNEL, "AIF1 Playback");
dr[idx].source = devm_kasprintf(dev, GFP_KERNEL, "ssp%d Tx", ssp_port);
if (!dr[idx].sink || !dr[idx].source)
return -ENOMEM;
idx++;
dr[idx].sink = devm_kasprintf(dev, GFP_KERNEL, "ssp%d Rx", ssp_port);
dr[idx].source = devm_kasprintf(dev, GFP_KERNEL, "AIF1 Capture");
if (!dr[idx].sink || !dr[idx].source)
return -ENOMEM;
*routes = dr;
*num_routes = num_dr;
return 0;
}
static int avs_card_set_jack(struct snd_soc_card *card, struct snd_soc_jack *jack)
{
struct snd_soc_component *component;
for_each_card_components(card, component)
snd_soc_component_set_jack(component, jack, NULL);
return 0;
}
static int avs_card_remove(struct snd_soc_card *card)
{
return avs_card_set_jack(card, NULL);
}
static int avs_card_suspend_pre(struct snd_soc_card *card)
{
return avs_card_set_jack(card, NULL);
}
static int avs_card_resume_post(struct snd_soc_card *card)
{
struct snd_soc_jack *jack = snd_soc_card_get_drvdata(card);
return avs_card_set_jack(card, jack);
}
static int avs_rt286_probe(struct platform_device *pdev)
{
struct snd_soc_dapm_route *routes;
struct snd_soc_dai_link *dai_link;
struct snd_soc_acpi_mach *mach;
struct snd_soc_card *card;
struct snd_soc_jack *jack;
struct device *dev = &pdev->dev;
const char *pname;
int num_routes, ssp_port, ret;
mach = dev_get_platdata(dev);
pname = mach->mach_params.platform;
ssp_port = __ffs(mach->mach_params.i2s_link_mask);
ret = avs_create_dai_link(dev, pname, ssp_port, &dai_link);
if (ret) {
dev_err(dev, "Failed to create dai link: %d", ret);
return ret;
}
ret = avs_create_dapm_routes(dev, ssp_port, &routes, &num_routes);
if (ret) {
dev_err(dev, "Failed to create dapm routes: %d", ret);
return ret;
}
jack = devm_kzalloc(dev, sizeof(*jack), GFP_KERNEL);
card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
if (!jack || !card)
return -ENOMEM;
card->name = "avs_rt286";
card->dev = dev;
card->owner = THIS_MODULE;
card->remove = avs_card_remove;
card->suspend_pre = avs_card_suspend_pre;
card->resume_post = avs_card_resume_post;
card->dai_link = dai_link;
card->num_links = 1;
card->controls = card_controls;
card->num_controls = ARRAY_SIZE(card_controls);
card->dapm_widgets = card_widgets;
card->num_dapm_widgets = ARRAY_SIZE(card_widgets);
card->dapm_routes = routes;
card->num_dapm_routes = num_routes;
card->fully_routed = true;
snd_soc_card_set_drvdata(card, jack);
ret = snd_soc_fixup_dai_links_platform_name(card, pname);
if (ret)
return ret;
return devm_snd_soc_register_card(dev, card);
}
static struct platform_driver avs_rt286_driver = {
.probe = avs_rt286_probe,
.driver = {
.name = "avs_rt286",
.pm = &snd_soc_pm_ops,
},
};
module_platform_driver(avs_rt286_driver);
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:avs_rt286");
// SPDX-License-Identifier: GPL-2.0-only
//
// Copyright(c) 2021-2022 Intel Corporation. All rights reserved.
//
// Authors: Cezary Rojewski <cezary.rojewski@intel.com>
// Amadeusz Slawinski <amadeuszx.slawinski@linux.intel.com>
//
#include <linux/module.h>
#include <sound/jack.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
#include <sound/soc-acpi.h>
#include "../../../codecs/rt298.h"
static const struct snd_kcontrol_new card_controls[] = {
SOC_DAPM_PIN_SWITCH("Headphone Jack"),
SOC_DAPM_PIN_SWITCH("Mic Jack"),
SOC_DAPM_PIN_SWITCH("Speaker"),
};
static const struct snd_soc_dapm_widget card_widgets[] = {
SND_SOC_DAPM_HP("Headphone Jack", NULL),
SND_SOC_DAPM_MIC("Mic Jack", NULL),
SND_SOC_DAPM_SPK("Speaker", NULL),
};
static const struct snd_soc_dapm_route card_base_routes[] = {
/* HP jack connectors - unknown if we have jack detect */
{"Headphone Jack", NULL, "HPO Pin"},
{"MIC1", NULL, "Mic Jack"},
{"Speaker", NULL, "SPOR"},
{"Speaker", NULL, "SPOL"},
};
static struct snd_soc_jack_pin card_headset_pins[] = {
{
.pin = "Headphone Jack",
.mask = SND_JACK_HEADPHONE,
},
{
.pin = "Mic Jack",
.mask = SND_JACK_MICROPHONE,
},
};
static int avs_rt298_codec_init(struct snd_soc_pcm_runtime *runtime)
{
struct snd_soc_component *component = asoc_rtd_to_codec(runtime, 0)->component;
struct snd_soc_jack_pin *pins;
struct snd_soc_jack *jack;
struct snd_soc_card *card = runtime->card;
int num_pins, ret;
jack = snd_soc_card_get_drvdata(card);
num_pins = ARRAY_SIZE(card_headset_pins);
pins = devm_kmemdup(card->dev, card_headset_pins, sizeof(*pins) * num_pins, GFP_KERNEL);
if (!pins)
return -ENOMEM;
ret = snd_soc_card_jack_new_pins(card, "Headset", SND_JACK_HEADSET | SND_JACK_BTN_0, jack,
pins, num_pins);
if (ret)
return ret;
snd_soc_component_set_jack(component, jack, NULL);
return 0;
}
static int avs_rt298_be_fixup(struct snd_soc_pcm_runtime *runtime, struct snd_pcm_hw_params *params)
{
struct snd_interval *rate, *channels;
struct snd_mask *fmt;
rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
/* The ADSP will convert the FE rate to 48k, stereo */
rate->min = rate->max = 48000;
channels->min = channels->max = 2;
/* set SSP0 to 24 bit */
snd_mask_none(fmt);
snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE);
return 0;
}
static int
avs_rt298_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
int ret;
ret = snd_soc_dai_set_sysclk(codec_dai, RT298_SCLK_S_PLL, 19200000, SND_SOC_CLOCK_IN);
if (ret < 0)
dev_err(rtd->dev, "Set codec sysclk failed: %d\n", ret);
return ret;
}
static const struct snd_soc_ops avs_rt298_ops = {
.hw_params = avs_rt298_hw_params,
};
static int avs_create_dai_link(struct device *dev, const char *platform_name, int ssp_port,
struct snd_soc_dai_link **dai_link)
{
struct snd_soc_dai_link_component *platform;
struct snd_soc_dai_link *dl;
dl = devm_kzalloc(dev, sizeof(*dl), GFP_KERNEL);
platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL);
if (!dl || !platform)
return -ENOMEM;
platform->name = platform_name;
dl->name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-Codec", ssp_port);
dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL);
dl->codecs = devm_kzalloc(dev, sizeof(*dl->codecs), GFP_KERNEL);
if (!dl->name || !dl->cpus || !dl->codecs)
return -ENOMEM;
dl->cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d Pin", ssp_port);
dl->codecs->name = devm_kasprintf(dev, GFP_KERNEL, "i2c-INT343A:00");
dl->codecs->dai_name = devm_kasprintf(dev, GFP_KERNEL, "rt298-aif1");
if (!dl->cpus->dai_name || !dl->codecs->name || !dl->codecs->dai_name)
return -ENOMEM;
dl->num_cpus = 1;
dl->num_codecs = 1;
dl->platforms = platform;
dl->num_platforms = 1;
dl->id = 0;
dl->dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS;
dl->init = avs_rt298_codec_init;
dl->be_hw_params_fixup = avs_rt298_be_fixup;
dl->ops = &avs_rt298_ops;
dl->nonatomic = 1;
dl->no_pcm = 1;
dl->dpcm_capture = 1;
dl->dpcm_playback = 1;
*dai_link = dl;
return 0;
}
static int avs_create_dapm_routes(struct device *dev, int ssp_port,
struct snd_soc_dapm_route **routes, int *num_routes)
{
struct snd_soc_dapm_route *dr;
const int num_base = ARRAY_SIZE(card_base_routes);
const int num_dr = num_base + 2;
int idx;
dr = devm_kcalloc(dev, num_dr, sizeof(*dr), GFP_KERNEL);
if (!dr)
return -ENOMEM;
memcpy(dr, card_base_routes, num_base * sizeof(*dr));
idx = num_base;
dr[idx].sink = devm_kasprintf(dev, GFP_KERNEL, "AIF1 Playback");
dr[idx].source = devm_kasprintf(dev, GFP_KERNEL, "ssp%d Tx", ssp_port);
if (!dr[idx].sink || !dr[idx].source)
return -ENOMEM;
idx++;
dr[idx].sink = devm_kasprintf(dev, GFP_KERNEL, "ssp%d Rx", ssp_port);
dr[idx].source = devm_kasprintf(dev, GFP_KERNEL, "AIF1 Capture");
if (!dr[idx].sink || !dr[idx].source)
return -ENOMEM;
*routes = dr;
*num_routes = num_dr;
return 0;
}
static int avs_card_set_jack(struct snd_soc_card *card, struct snd_soc_jack *jack)
{
struct snd_soc_component *component;
for_each_card_components(card, component)
snd_soc_component_set_jack(component, jack, NULL);
return 0;
}
static int avs_card_remove(struct snd_soc_card *card)
{
return avs_card_set_jack(card, NULL);
}
static int avs_card_suspend_pre(struct snd_soc_card *card)
{
return avs_card_set_jack(card, NULL);
}
static int avs_card_resume_post(struct snd_soc_card *card)
{
struct snd_soc_jack *jack = snd_soc_card_get_drvdata(card);
return avs_card_set_jack(card, jack);
}
static int avs_rt298_probe(struct platform_device *pdev)
{
struct snd_soc_dapm_route *routes;
struct snd_soc_dai_link *dai_link;
struct snd_soc_acpi_mach *mach;
struct snd_soc_card *card;
struct snd_soc_jack *jack;
struct device *dev = &pdev->dev;
const char *pname;
int num_routes, ssp_port, ret;
mach = dev_get_platdata(dev);
pname = mach->mach_params.platform;
ssp_port = __ffs(mach->mach_params.i2s_link_mask);
ret = avs_create_dai_link(dev, pname, ssp_port, &dai_link);
if (ret) {
dev_err(dev, "Failed to create dai link: %d", ret);
return ret;
}
ret = avs_create_dapm_routes(dev, ssp_port, &routes, &num_routes);
if (ret) {
dev_err(dev, "Failed to create dapm routes: %d", ret);
return ret;
}
jack = devm_kzalloc(dev, sizeof(*jack), GFP_KERNEL);
card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
if (!jack || !card)
return -ENOMEM;
card->name = "avs_rt298";
card->dev = dev;
card->owner = THIS_MODULE;
card->remove = avs_card_remove;
card->suspend_pre = avs_card_suspend_pre;
card->resume_post = avs_card_resume_post;
card->dai_link = dai_link;
card->num_links = 1;
card->controls = card_controls;
card->num_controls = ARRAY_SIZE(card_controls);
card->dapm_widgets = card_widgets;
card->num_dapm_widgets = ARRAY_SIZE(card_widgets);
card->dapm_routes = routes;
card->num_dapm_routes = num_routes;
card->fully_routed = true;
snd_soc_card_set_drvdata(card, jack);
ret = snd_soc_fixup_dai_links_platform_name(card, pname);
if (ret)
return ret;
return devm_snd_soc_register_card(dev, card);
}
static struct platform_driver avs_rt298_driver = {
.probe = avs_rt298_probe,
.driver = {
.name = "avs_rt298",
.pm = &snd_soc_pm_ops,
},
};
module_platform_driver(avs_rt298_driver);
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:avs_rt298");
// SPDX-License-Identifier: GPL-2.0-only
//
// Copyright(c) 2021-2022 Intel Corporation. All rights reserved.
//
// Authors: Cezary Rojewski <cezary.rojewski@intel.com>
// Amadeusz Slawinski <amadeuszx.slawinski@linux.intel.com>
//
#include <linux/clk.h>
#include <linux/dmi.h>
#include <linux/i2c.h>
#include <linux/input.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <sound/core.h>
#include <sound/jack.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/rt5682.h>
#include <sound/soc.h>
#include <sound/soc-acpi.h>
#include "../../common/soc-intel-quirks.h"
#include "../../../codecs/rt5682.h"
#define AVS_RT5682_SSP_CODEC(quirk) ((quirk) & GENMASK(2, 0))
#define AVS_RT5682_SSP_CODEC_MASK (GENMASK(2, 0))
#define AVS_RT5682_MCLK_EN BIT(3)
#define AVS_RT5682_MCLK_24MHZ BIT(4)
/* Default: MCLK on, MCLK 19.2M, SSP0 */
static unsigned long avs_rt5682_quirk = AVS_RT5682_MCLK_EN | AVS_RT5682_SSP_CODEC(0);
static int avs_rt5682_quirk_cb(const struct dmi_system_id *id)
{
avs_rt5682_quirk = (unsigned long)id->driver_data;
return 1;
}
static const struct dmi_system_id avs_rt5682_quirk_table[] = {
{
.callback = avs_rt5682_quirk_cb,
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
DMI_MATCH(DMI_PRODUCT_NAME, "WhiskeyLake Client"),
},
.driver_data = (void *)(AVS_RT5682_MCLK_EN |
AVS_RT5682_MCLK_24MHZ |
AVS_RT5682_SSP_CODEC(1)),
},
{
.callback = avs_rt5682_quirk_cb,
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
DMI_MATCH(DMI_PRODUCT_NAME, "Ice Lake Client"),
},
.driver_data = (void *)(AVS_RT5682_MCLK_EN |
AVS_RT5682_SSP_CODEC(0)),
},
{}
};
static const struct snd_kcontrol_new card_controls[] = {
SOC_DAPM_PIN_SWITCH("Headphone Jack"),
SOC_DAPM_PIN_SWITCH("Headset Mic"),
};
static const struct snd_soc_dapm_widget card_widgets[] = {
SND_SOC_DAPM_HP("Headphone Jack", NULL),
SND_SOC_DAPM_MIC("Headset Mic", NULL),
};
static const struct snd_soc_dapm_route card_base_routes[] = {
/* HP jack connectors - unknown if we have jack detect */
{ "Headphone Jack", NULL, "HPOL" },
{ "Headphone Jack", NULL, "HPOR" },
/* other jacks */
{ "IN1P", NULL, "Headset Mic" },
};
static int avs_rt5682_codec_init(struct snd_soc_pcm_runtime *runtime)
{
struct snd_soc_component *component = asoc_rtd_to_codec(runtime, 0)->component;
struct snd_soc_jack *jack;
struct snd_soc_card *card = runtime->card;
int ret;
jack = snd_soc_card_get_drvdata(card);
/* Need to enable ASRC function for 24MHz mclk rate */
if ((avs_rt5682_quirk & AVS_RT5682_MCLK_EN) &&
(avs_rt5682_quirk & AVS_RT5682_MCLK_24MHZ)) {
rt5682_sel_asrc_clk_src(component, RT5682_DA_STEREO1_FILTER |
RT5682_AD_STEREO1_FILTER, RT5682_CLK_SEL_I2S1_ASRC);
}
/*
* Headset buttons map to the google Reference headset.
* These can be configured by userspace.
*/
ret = snd_soc_card_jack_new(card, "Headset", SND_JACK_HEADSET | SND_JACK_BTN_0 |
SND_JACK_BTN_1 | SND_JACK_BTN_2 | SND_JACK_BTN_3, jack);
if (ret) {
dev_err(card->dev, "Headset Jack creation failed: %d\n", ret);
return ret;
}
snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
ret = snd_soc_component_set_jack(component, jack, NULL);
if (ret) {
dev_err(card->dev, "Headset Jack call-back failed: %d\n", ret);
return ret;
}
return 0;
};
static int
avs_rt5682_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
{
struct snd_soc_pcm_runtime *runtime = asoc_substream_to_rtd(substream);
struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(runtime, 0);
int clk_id, clk_freq;
int pll_out, ret;
if (avs_rt5682_quirk & AVS_RT5682_MCLK_EN) {
clk_id = RT5682_PLL1_S_MCLK;
if (avs_rt5682_quirk & AVS_RT5682_MCLK_24MHZ)
clk_freq = 24000000;
else
clk_freq = 19200000;
} else {
clk_id = RT5682_PLL1_S_BCLK1;
clk_freq = params_rate(params) * 50;
}
pll_out = params_rate(params) * 512;
ret = snd_soc_dai_set_pll(codec_dai, 0, clk_id, clk_freq, pll_out);
if (ret < 0)
dev_err(runtime->dev, "snd_soc_dai_set_pll err = %d\n", ret);
/* Configure sysclk for codec */
ret = snd_soc_dai_set_sysclk(codec_dai, RT5682_SCLK_S_PLL1, pll_out, SND_SOC_CLOCK_IN);
if (ret < 0)
dev_err(runtime->dev, "snd_soc_dai_set_sysclk err = %d\n", ret);
/* slot_width should equal or large than data length, set them be the same */
ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x0, 0x0, 2, params_width(params));
if (ret < 0) {
dev_err(runtime->dev, "set TDM slot err:%d\n", ret);
return ret;
}
return 0;
}
static const struct snd_soc_ops avs_rt5682_ops = {
.hw_params = avs_rt5682_hw_params,
};
static int avs_create_dai_link(struct device *dev, const char *platform_name, int ssp_port,
struct snd_soc_dai_link **dai_link)
{
struct snd_soc_dai_link_component *platform;
struct snd_soc_dai_link *dl;
dl = devm_kzalloc(dev, sizeof(*dl), GFP_KERNEL);
platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL);
if (!dl || !platform)
return -ENOMEM;
platform->name = platform_name;
dl->name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-Codec", ssp_port);
dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL);
dl->codecs = devm_kzalloc(dev, sizeof(*dl->codecs), GFP_KERNEL);
if (!dl->name || !dl->cpus || !dl->codecs)
return -ENOMEM;
dl->cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d Pin", ssp_port);
dl->codecs->name = devm_kasprintf(dev, GFP_KERNEL, "i2c-10EC5682:00");
dl->codecs->dai_name = devm_kasprintf(dev, GFP_KERNEL, "rt5682-aif1");
if (!dl->cpus->dai_name || !dl->codecs->name || !dl->codecs->dai_name)
return -ENOMEM;
dl->num_cpus = 1;
dl->num_codecs = 1;
dl->platforms = platform;
dl->num_platforms = 1;
dl->id = 0;
dl->init = avs_rt5682_codec_init;
dl->ops = &avs_rt5682_ops;
dl->nonatomic = 1;
dl->no_pcm = 1;
dl->dpcm_capture = 1;
dl->dpcm_playback = 1;
*dai_link = dl;
return 0;
}
static int avs_create_dapm_routes(struct device *dev, int ssp_port,
struct snd_soc_dapm_route **routes, int *num_routes)
{
struct snd_soc_dapm_route *dr;
const int num_base = ARRAY_SIZE(card_base_routes);
const int num_dr = num_base + 2;
int idx;
dr = devm_kcalloc(dev, num_dr, sizeof(*dr), GFP_KERNEL);
if (!dr)
return -ENOMEM;
memcpy(dr, card_base_routes, num_base * sizeof(*dr));
idx = num_base;
dr[idx].sink = devm_kasprintf(dev, GFP_KERNEL, "AIF1 Playback");
dr[idx].source = devm_kasprintf(dev, GFP_KERNEL, "ssp%d Tx", ssp_port);
if (!dr[idx].sink || !dr[idx].source)
return -ENOMEM;
idx++;
dr[idx].sink = devm_kasprintf(dev, GFP_KERNEL, "ssp%d Rx", ssp_port);
dr[idx].source = devm_kasprintf(dev, GFP_KERNEL, "AIF1 Capture");
if (!dr[idx].sink || !dr[idx].source)
return -ENOMEM;
*routes = dr;
*num_routes = num_dr;
return 0;
}
static int avs_card_set_jack(struct snd_soc_card *card, struct snd_soc_jack *jack)
{
struct snd_soc_component *component;
for_each_card_components(card, component)
snd_soc_component_set_jack(component, jack, NULL);
return 0;
}
static int avs_card_remove(struct snd_soc_card *card)
{
return avs_card_set_jack(card, NULL);
}
static int avs_card_suspend_pre(struct snd_soc_card *card)
{
return avs_card_set_jack(card, NULL);
}
static int avs_card_resume_post(struct snd_soc_card *card)
{
struct snd_soc_jack *jack = snd_soc_card_get_drvdata(card);
return avs_card_set_jack(card, jack);
}
static int avs_rt5682_probe(struct platform_device *pdev)
{
struct snd_soc_dapm_route *routes;
struct snd_soc_dai_link *dai_link;
struct snd_soc_acpi_mach *mach;
struct snd_soc_card *card;
struct snd_soc_jack *jack;
struct device *dev = &pdev->dev;
const char *pname;
int num_routes, ssp_port, ret;
if (pdev->id_entry && pdev->id_entry->driver_data)
avs_rt5682_quirk = (unsigned long)pdev->id_entry->driver_data;
dmi_check_system(avs_rt5682_quirk_table);
dev_dbg(dev, "avs_rt5682_quirk = %lx\n", avs_rt5682_quirk);
mach = dev_get_platdata(dev);
pname = mach->mach_params.platform;
ssp_port = __ffs(mach->mach_params.i2s_link_mask);
ret = avs_create_dai_link(dev, pname, ssp_port, &dai_link);
if (ret) {
dev_err(dev, "Failed to create dai link: %d", ret);
return ret;
}
ret = avs_create_dapm_routes(dev, ssp_port, &routes, &num_routes);
if (ret) {
dev_err(dev, "Failed to create dapm routes: %d", ret);
return ret;
}
jack = devm_kzalloc(dev, sizeof(*jack), GFP_KERNEL);
card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
if (!jack || !card)
return -ENOMEM;
card->name = "avs_rt5682";
card->dev = dev;
card->owner = THIS_MODULE;
card->remove = avs_card_remove;
card->suspend_pre = avs_card_suspend_pre;
card->resume_post = avs_card_resume_post;
card->dai_link = dai_link;
card->num_links = 1;
card->controls = card_controls;
card->num_controls = ARRAY_SIZE(card_controls);
card->dapm_widgets = card_widgets;
card->num_dapm_widgets = ARRAY_SIZE(card_widgets);
card->dapm_routes = routes;
card->num_dapm_routes = num_routes;
card->fully_routed = true;
snd_soc_card_set_drvdata(card, jack);
ret = snd_soc_fixup_dai_links_platform_name(card, pname);
if (ret)
return ret;
return devm_snd_soc_register_card(dev, card);
}
static struct platform_driver avs_rt5682_driver = {
.probe = avs_rt5682_probe,
.driver = {
.name = "avs_rt5682",
.pm = &snd_soc_pm_ops,
},
};
module_platform_driver(avs_rt5682_driver)
MODULE_AUTHOR("Cezary Rojewski <cezary.rojewski@intel.com>");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:avs_rt5682");
// SPDX-License-Identifier: GPL-2.0-only
//
// Copyright(c) 2021-2022 Intel Corporation. All rights reserved.
//
// Authors: Cezary Rojewski <cezary.rojewski@intel.com>
// Amadeusz Slawinski <amadeuszx.slawinski@linux.intel.com>
//
#include <linux/module.h>
#include <linux/platform_device.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
#include <sound/soc-acpi.h>
#include "../../../codecs/nau8825.h"
#define SKL_NUVOTON_CODEC_DAI "nau8825-hifi"
#define SKL_SSM_CODEC_DAI "ssm4567-hifi"
static struct snd_soc_codec_conf card_codec_conf[] = {
{
.dlc = COMP_CODEC_CONF("i2c-INT343B:00"),
.name_prefix = "Left",
},
{
.dlc = COMP_CODEC_CONF("i2c-INT343B:01"),
.name_prefix = "Right",
},
};
static const struct snd_kcontrol_new card_controls[] = {
SOC_DAPM_PIN_SWITCH("Left Speaker"),
SOC_DAPM_PIN_SWITCH("Right Speaker"),
};
static int
platform_clock_control(struct snd_soc_dapm_widget *w, struct snd_kcontrol *control, int event)
{
struct snd_soc_dapm_context *dapm = w->dapm;
struct snd_soc_card *card = dapm->card;
struct snd_soc_dai *codec_dai;
int ret;
codec_dai = snd_soc_card_get_codec_dai(card, SKL_NUVOTON_CODEC_DAI);
if (!codec_dai) {
dev_err(card->dev, "Codec dai not found\n");
return -EINVAL;
}
if (SND_SOC_DAPM_EVENT_ON(event)) {
ret = snd_soc_dai_set_sysclk(codec_dai, NAU8825_CLK_MCLK, 24000000,
SND_SOC_CLOCK_IN);
if (ret < 0)
dev_err(card->dev, "set sysclk err = %d\n", ret);
} else {
ret = snd_soc_dai_set_sysclk(codec_dai, NAU8825_CLK_INTERNAL, 0, SND_SOC_CLOCK_IN);
if (ret < 0)
dev_err(card->dev, "set sysclk err = %d\n", ret);
}
return ret;
}
static const struct snd_soc_dapm_widget card_widgets[] = {
SND_SOC_DAPM_SPK("Left Speaker", NULL),
SND_SOC_DAPM_SPK("Right Speaker", NULL),
SND_SOC_DAPM_SPK("DP1", NULL),
SND_SOC_DAPM_SPK("DP2", NULL),
SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0, platform_clock_control,
SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
};
static const struct snd_soc_dapm_route card_base_routes[] = {
{"Left Speaker", NULL, "Left OUT"},
{"Right Speaker", NULL, "Right OUT"},
};
static int avs_ssm4567_codec_init(struct snd_soc_pcm_runtime *runtime)
{
int ret;
/* Slot 1 for left */
ret = snd_soc_dai_set_tdm_slot(asoc_rtd_to_codec(runtime, 0), 0x01, 0x01, 2, 48);
if (ret < 0)
return ret;
/* Slot 2 for right */
ret = snd_soc_dai_set_tdm_slot(asoc_rtd_to_codec(runtime, 1), 0x02, 0x02, 2, 48);
if (ret < 0)
return ret;
return 0;
}
static int
avs_ssm4567_be_fixup(struct snd_soc_pcm_runtime *runrime, struct snd_pcm_hw_params *params)
{
struct snd_interval *rate, *channels;
struct snd_mask *fmt;
rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
/* The ADSP will covert the FE rate to 48k, stereo */
rate->min = rate->max = 48000;
channels->min = channels->max = 2;
/* set SSP0 to 24 bit */
snd_mask_none(fmt);
snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE);
return 0;
}
static int avs_create_dai_link(struct device *dev, const char *platform_name, int ssp_port,
struct snd_soc_dai_link **dai_link)
{
struct snd_soc_dai_link_component *platform;
struct snd_soc_dai_link *dl;
dl = devm_kzalloc(dev, sizeof(*dl), GFP_KERNEL);
platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL);
if (!dl || !platform)
return -ENOMEM;
platform->name = platform_name;
dl->name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-Codec", ssp_port);
dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL);
dl->codecs = devm_kzalloc(dev, sizeof(*dl->codecs) * 2, GFP_KERNEL);
if (!dl->name || !dl->cpus || !dl->codecs)
return -ENOMEM;
dl->cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d Pin", ssp_port);
dl->codecs[0].name = devm_kasprintf(dev, GFP_KERNEL, "i2c-INT343B:00");
dl->codecs[0].dai_name = devm_kasprintf(dev, GFP_KERNEL, "ssm4567-hifi");
dl->codecs[1].name = devm_kasprintf(dev, GFP_KERNEL, "i2c-INT343B:01");
dl->codecs[1].dai_name = devm_kasprintf(dev, GFP_KERNEL, "ssm4567-hifi");
if (!dl->cpus->dai_name || !dl->codecs[0].name || !dl->codecs[0].dai_name ||
!dl->codecs[1].name || !dl->codecs[1].dai_name)
return -ENOMEM;
dl->num_cpus = 1;
dl->num_codecs = 2;
dl->platforms = platform;
dl->num_platforms = 1;
dl->id = 0;
dl->dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF | SND_SOC_DAIFMT_CBS_CFS;
dl->init = avs_ssm4567_codec_init;
dl->be_hw_params_fixup = avs_ssm4567_be_fixup;
dl->nonatomic = 1;
dl->no_pcm = 1;
dl->dpcm_capture = 1;
dl->dpcm_playback = 1;
dl->ignore_pmdown_time = 1;
*dai_link = dl;
return 0;
}
static int avs_create_dapm_routes(struct device *dev, int ssp_port,
struct snd_soc_dapm_route **routes, int *num_routes)
{
struct snd_soc_dapm_route *dr;
const int num_base = ARRAY_SIZE(card_base_routes);
const int num_dr = num_base + 4;
int idx;
dr = devm_kcalloc(dev, num_dr, sizeof(*dr), GFP_KERNEL);
if (!dr)
return -ENOMEM;
memcpy(dr, card_base_routes, num_base * sizeof(*dr));
idx = num_base;
dr[idx].sink = devm_kasprintf(dev, GFP_KERNEL, "Left Playback");
dr[idx].source = devm_kasprintf(dev, GFP_KERNEL, "ssp%d Tx", ssp_port);
if (!dr[idx].sink || !dr[idx].source)
return -ENOMEM;
idx++;
dr[idx].sink = devm_kasprintf(dev, GFP_KERNEL, "Right Playback");
dr[idx].source = devm_kasprintf(dev, GFP_KERNEL, "ssp%d Tx", ssp_port);
if (!dr[idx].sink || !dr[idx].source)
return -ENOMEM;
idx++;
dr[idx].sink = devm_kasprintf(dev, GFP_KERNEL, "ssp%d Rx", ssp_port);
dr[idx].source = devm_kasprintf(dev, GFP_KERNEL, "Left Capture Sense");
if (!dr[idx].sink || !dr[idx].source)
return -ENOMEM;
idx++;
dr[idx].sink = devm_kasprintf(dev, GFP_KERNEL, "ssp%d Rx", ssp_port);
dr[idx].source = devm_kasprintf(dev, GFP_KERNEL, "Right Capture Sense");
if (!dr[idx].sink || !dr[idx].source)
return -ENOMEM;
*routes = dr;
*num_routes = num_dr;
return 0;
}
static int avs_ssm4567_probe(struct platform_device *pdev)
{
struct snd_soc_dapm_route *routes;
struct snd_soc_dai_link *dai_link;
struct snd_soc_acpi_mach *mach;
struct snd_soc_card *card;
struct device *dev = &pdev->dev;
const char *pname;
int num_routes, ssp_port, ret;
mach = dev_get_platdata(dev);
pname = mach->mach_params.platform;
ssp_port = __ffs(mach->mach_params.i2s_link_mask);
ret = avs_create_dai_link(dev, pname, ssp_port, &dai_link);
if (ret) {
dev_err(dev, "Failed to create dai link: %d", ret);
return ret;
}
ret = avs_create_dapm_routes(dev, ssp_port, &routes, &num_routes);
if (ret) {
dev_err(dev, "Failed to create dapm routes: %d", ret);
return ret;
}
card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
if (!card)
return -ENOMEM;
card->name = "avs_ssm4567-adi";
card->dev = dev;
card->owner = THIS_MODULE;
card->dai_link = dai_link;
card->num_links = 1;
card->codec_conf = card_codec_conf;
card->num_configs = ARRAY_SIZE(card_codec_conf);
card->controls = card_controls;
card->num_controls = ARRAY_SIZE(card_controls);
card->dapm_widgets = card_widgets;
card->num_dapm_widgets = ARRAY_SIZE(card_widgets);
card->dapm_routes = routes;
card->num_dapm_routes = num_routes;
card->fully_routed = true;
card->disable_route_checks = true;
ret = snd_soc_fixup_dai_links_platform_name(card, pname);
if (ret)
return ret;
return devm_snd_soc_register_card(dev, card);
}
static struct platform_driver avs_ssm4567_driver = {
.probe = avs_ssm4567_probe,
.driver = {
.name = "avs_ssm4567",
.pm = &snd_soc_pm_ops,
},
};
module_platform_driver(avs_ssm4567_driver)
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:avs_ssm4567");
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment