| 1 |
// SPDX-License-Identifier: GPL-2.0-only |
| 2 |
// This file incorporates work covered by the following copyright notice: |
| 3 |
// Copyright (c) 2024 Intel Corporation |
| 4 |
// Copyright (c) 2024 Advanced Micro Devices, Inc. |
| 5 |
|
| 6 |
/* |
| 7 |
* soc_sdw_bridge_cs35l56 - codec helper functions for handling CS35L56 Smart AMP |
| 8 |
*/ |
| 9 |
|
| 10 |
#include <linux/module.h> |
| 11 |
#include <linux/platform_device.h> |
| 12 |
#include <sound/core.h> |
| 13 |
#include <sound/pcm.h> |
| 14 |
#include <sound/pcm_params.h> |
| 15 |
#include <sound/soc.h> |
| 16 |
#include <sound/soc-acpi.h> |
| 17 |
#include <sound/soc_sdw_utils.h> |
| 18 |
|
| 19 |
static const struct snd_soc_dapm_widget bridge_widgets[] = { |
| 20 |
SND_SOC_DAPM_SPK("Bridge Speaker", NULL), |
| 21 |
}; |
| 22 |
|
| 23 |
static const struct snd_soc_dapm_route bridge_map[] = { |
| 24 |
{"Bridge Speaker", NULL, "AMPL SPK"}, |
| 25 |
{"Bridge Speaker", NULL, "AMPR SPK"}, |
| 26 |
}; |
| 27 |
|
| 28 |
static const char * const bridge_cs35l56_name_prefixes[] = { |
| 29 |
"AMPL", |
| 30 |
"AMPR", |
| 31 |
}; |
| 32 |
|
| 33 |
static int asoc_sdw_bridge_cs35l56_asp_init(struct snd_soc_pcm_runtime *rtd) |
| 34 |
{ |
| 35 |
struct snd_soc_card *card = rtd->card; |
| 36 |
struct snd_soc_dapm_context *dapm = snd_soc_card_to_dapm(card); |
| 37 |
int i, ret; |
| 38 |
unsigned int rx_mask = 3; // ASP RX1, RX2 |
| 39 |
unsigned int tx_mask = 3; // ASP TX1, TX2 |
| 40 |
struct snd_soc_dai *codec_dai; |
| 41 |
struct snd_soc_dai *cpu_dai; |
| 42 |
|
| 43 |
ret = snd_soc_dapm_new_controls(dapm, bridge_widgets, |
| 44 |
ARRAY_SIZE(bridge_widgets)); |
| 45 |
if (ret) { |
| 46 |
dev_err(card->dev, "widgets addition failed: %d\n", ret); |
| 47 |
return ret; |
| 48 |
} |
| 49 |
|
| 50 |
ret = snd_soc_dapm_add_routes(dapm, bridge_map, ARRAY_SIZE(bridge_map)); |
| 51 |
if (ret) { |
| 52 |
dev_err(card->dev, "map addition failed: %d\n", ret); |
| 53 |
return ret; |
| 54 |
} |
| 55 |
|
| 56 |
/* 4 x 16-bit sample slots and FSYNC=48000, BCLK=3.072 MHz */ |
| 57 |
for_each_rtd_codec_dais(rtd, i, codec_dai) { |
| 58 |
ret = asoc_sdw_cs35l56_volume_limit(card, codec_dai->component->name_prefix); |
| 59 |
if (ret) |
| 60 |
return ret; |
| 61 |
|
| 62 |
ret = snd_soc_dai_set_tdm_slot(codec_dai, tx_mask, rx_mask, 4, 16); |
| 63 |
if (ret < 0) |
| 64 |
return ret; |
| 65 |
|
| 66 |
ret = snd_soc_dai_set_sysclk(codec_dai, 0, 3072000, SND_SOC_CLOCK_IN); |
| 67 |
if (ret < 0) |
| 68 |
return ret; |
| 69 |
} |
| 70 |
|
| 71 |
for_each_rtd_cpu_dais(rtd, i, cpu_dai) { |
| 72 |
ret = snd_soc_dai_set_tdm_slot(cpu_dai, tx_mask, rx_mask, 4, 16); |
| 73 |
if (ret < 0) |
| 74 |
return ret; |
| 75 |
} |
| 76 |
|
| 77 |
return 0; |
| 78 |
} |
| 79 |
|
| 80 |
static const struct snd_soc_pcm_stream asoc_sdw_bridge_params = { |
| 81 |
.formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 82 |
.rate_min = 48000, |
| 83 |
.rate_max = 48000, |
| 84 |
.channels_min = 2, |
| 85 |
.channels_max = 2, |
| 86 |
}; |
| 87 |
|
| 88 |
SND_SOC_DAILINK_DEFS(asoc_sdw_bridge_dai, |
| 89 |
DAILINK_COMP_ARRAY(COMP_CODEC("cs42l43-codec", "cs42l43-asp")), |
| 90 |
DAILINK_COMP_ARRAY(COMP_CODEC("spi-cs35l56-left", "cs35l56-asp1"), |
| 91 |
COMP_CODEC("spi-cs35l56-right", "cs35l56-asp1")), |
| 92 |
DAILINK_COMP_ARRAY(COMP_PLATFORM("cs42l43-codec"))); |
| 93 |
|
| 94 |
static const struct snd_soc_dai_link bridge_dai_template = { |
| 95 |
.name = "cs42l43-cs35l56", |
| 96 |
.init = asoc_sdw_bridge_cs35l56_asp_init, |
| 97 |
.c2c_params = &asoc_sdw_bridge_params, |
| 98 |
.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_IB_IF | SND_SOC_DAIFMT_CBC_CFC, |
| 99 |
SND_SOC_DAILINK_REG(asoc_sdw_bridge_dai), |
| 100 |
}; |
| 101 |
|
| 102 |
int asoc_sdw_bridge_cs35l56_count_sidecar(struct snd_soc_card *card, |
| 103 |
int *num_dais, int *num_devs) |
| 104 |
{ |
| 105 |
struct asoc_sdw_mc_private *ctx = snd_soc_card_get_drvdata(card); |
| 106 |
|
| 107 |
if (ctx->mc_quirk & SOC_SDW_SIDECAR_AMPS) { |
| 108 |
(*num_dais)++; |
| 109 |
(*num_devs) += ARRAY_SIZE(bridge_cs35l56_name_prefixes); |
| 110 |
} |
| 111 |
|
| 112 |
return 0; |
| 113 |
} |
| 114 |
EXPORT_SYMBOL_NS(asoc_sdw_bridge_cs35l56_count_sidecar, "SND_SOC_SDW_UTILS"); |
| 115 |
|
| 116 |
int asoc_sdw_bridge_cs35l56_add_sidecar(struct snd_soc_card *card, |
| 117 |
struct snd_soc_dai_link **dai_links, |
| 118 |
struct snd_soc_codec_conf **codec_conf) |
| 119 |
{ |
| 120 |
struct asoc_sdw_mc_private *ctx = snd_soc_card_get_drvdata(card); |
| 121 |
|
| 122 |
if (ctx->mc_quirk & SOC_SDW_SIDECAR_AMPS) { |
| 123 |
**dai_links = bridge_dai_template; |
| 124 |
|
| 125 |
for (int i = 0; i < ARRAY_SIZE(bridge_cs35l56_name_prefixes); i++) { |
| 126 |
(*codec_conf)->dlc.name = (*dai_links)->codecs[i].name; |
| 127 |
(*codec_conf)->name_prefix = bridge_cs35l56_name_prefixes[i]; |
| 128 |
(*codec_conf)++; |
| 129 |
} |
| 130 |
|
| 131 |
(*dai_links)++; |
| 132 |
} |
| 133 |
|
| 134 |
return 0; |
| 135 |
} |
| 136 |
EXPORT_SYMBOL_NS(asoc_sdw_bridge_cs35l56_add_sidecar, "SND_SOC_SDW_UTILS"); |
| 137 |
|
| 138 |
int asoc_sdw_bridge_cs35l56_spk_init(struct snd_soc_card *card, |
| 139 |
struct snd_soc_dai_link *dai_links, |
| 140 |
struct asoc_sdw_codec_info *info, |
| 141 |
bool playback) |
| 142 |
{ |
| 143 |
struct asoc_sdw_mc_private *ctx = snd_soc_card_get_drvdata(card); |
| 144 |
|
| 145 |
if (ctx->mc_quirk & SOC_SDW_SIDECAR_AMPS) |
| 146 |
info->amp_num += ARRAY_SIZE(bridge_cs35l56_name_prefixes); |
| 147 |
|
| 148 |
return 0; |
| 149 |
} |
| 150 |
EXPORT_SYMBOL_NS(asoc_sdw_bridge_cs35l56_spk_init, "SND_SOC_SDW_UTILS"); |