| 1 |
// SPDX-License-Identifier: GPL-2.0-only |
| 2 |
// |
| 3 |
// Copyright(c) 2021-2022 Intel Corporation |
| 4 |
// |
| 5 |
// Authors: Cezary Rojewski <[email protected]> |
| 6 |
// Amadeusz Slawinski <[email protected]> |
| 7 |
// |
| 8 |
|
| 9 |
#include <linux/module.h> |
| 10 |
#include <linux/platform_device.h> |
| 11 |
#include <sound/core.h> |
| 12 |
#include <sound/pcm.h> |
| 13 |
#include <sound/pcm_params.h> |
| 14 |
#include <sound/soc.h> |
| 15 |
#include <sound/soc-acpi.h> |
| 16 |
#include "../../../codecs/nau8825.h" |
| 17 |
#include "../utils.h" |
| 18 |
|
| 19 |
#define SKL_SSM_CODEC_DAI "ssm4567-hifi" |
| 20 |
|
| 21 |
static struct snd_soc_codec_conf card_codec_conf[] = { |
| 22 |
{ |
| 23 |
.dlc = COMP_CODEC_CONF("i2c-INT343B:00"), |
| 24 |
.name_prefix = "Left", |
| 25 |
}, |
| 26 |
{ |
| 27 |
.dlc = COMP_CODEC_CONF("i2c-INT343B:01"), |
| 28 |
.name_prefix = "Right", |
| 29 |
}, |
| 30 |
}; |
| 31 |
|
| 32 |
static const struct snd_kcontrol_new card_controls[] = { |
| 33 |
SOC_DAPM_PIN_SWITCH("Left Speaker"), |
| 34 |
SOC_DAPM_PIN_SWITCH("Right Speaker"), |
| 35 |
}; |
| 36 |
|
| 37 |
static const struct snd_soc_dapm_widget card_widgets[] = { |
| 38 |
SND_SOC_DAPM_SPK("Left Speaker", NULL), |
| 39 |
SND_SOC_DAPM_SPK("Right Speaker", NULL), |
| 40 |
}; |
| 41 |
|
| 42 |
static const struct snd_soc_dapm_route card_base_routes[] = { |
| 43 |
{"Left Speaker", NULL, "Left OUT"}, |
| 44 |
{"Right Speaker", NULL, "Right OUT"}, |
| 45 |
}; |
| 46 |
|
| 47 |
static int avs_ssm4567_codec_init(struct snd_soc_pcm_runtime *runtime) |
| 48 |
{ |
| 49 |
int ret; |
| 50 |
|
| 51 |
/* Slot 1 for left */ |
| 52 |
ret = snd_soc_dai_set_tdm_slot(snd_soc_rtd_to_codec(runtime, 0), 0x01, 0x01, 2, 48); |
| 53 |
if (ret < 0) |
| 54 |
return ret; |
| 55 |
|
| 56 |
/* Slot 2 for right */ |
| 57 |
ret = snd_soc_dai_set_tdm_slot(snd_soc_rtd_to_codec(runtime, 1), 0x02, 0x02, 2, 48); |
| 58 |
if (ret < 0) |
| 59 |
return ret; |
| 60 |
|
| 61 |
return 0; |
| 62 |
} |
| 63 |
|
| 64 |
static int |
| 65 |
avs_ssm4567_be_fixup(struct snd_soc_pcm_runtime *runrime, struct snd_pcm_hw_params *params) |
| 66 |
{ |
| 67 |
struct snd_interval *rate, *channels; |
| 68 |
struct snd_mask *fmt; |
| 69 |
|
| 70 |
rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); |
| 71 |
channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); |
| 72 |
fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT); |
| 73 |
|
| 74 |
/* The ADSP will convert the FE rate to 48k, stereo */ |
| 75 |
rate->min = rate->max = 48000; |
| 76 |
channels->min = channels->max = 2; |
| 77 |
|
| 78 |
/* set SSP0 to 24 bit */ |
| 79 |
snd_mask_none(fmt); |
| 80 |
snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE); |
| 81 |
return 0; |
| 82 |
} |
| 83 |
|
| 84 |
static int avs_create_dai_link(struct device *dev, int ssp_port, int tdm_slot, |
| 85 |
struct snd_soc_dai_link **dai_link) |
| 86 |
{ |
| 87 |
struct snd_soc_dai_link_component *platform; |
| 88 |
struct snd_soc_dai_link *dl; |
| 89 |
|
| 90 |
dl = devm_kzalloc(dev, sizeof(*dl), GFP_KERNEL); |
| 91 |
platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL); |
| 92 |
if (!dl || !platform) |
| 93 |
return -ENOMEM; |
| 94 |
|
| 95 |
dl->name = devm_kasprintf(dev, GFP_KERNEL, |
| 96 |
AVS_STRING_FMT("SSP", "-Codec", ssp_port, tdm_slot)); |
| 97 |
dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL); |
| 98 |
dl->codecs = devm_kcalloc(dev, 2, sizeof(*dl->codecs), GFP_KERNEL); |
| 99 |
if (!dl->name || !dl->cpus || !dl->codecs) |
| 100 |
return -ENOMEM; |
| 101 |
|
| 102 |
dl->cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL, |
| 103 |
AVS_STRING_FMT("SSP", " Pin", ssp_port, tdm_slot)); |
| 104 |
dl->codecs[0].name = devm_kasprintf(dev, GFP_KERNEL, "i2c-INT343B:00"); |
| 105 |
dl->codecs[0].dai_name = devm_kasprintf(dev, GFP_KERNEL, "ssm4567-hifi"); |
| 106 |
dl->codecs[1].name = devm_kasprintf(dev, GFP_KERNEL, "i2c-INT343B:01"); |
| 107 |
dl->codecs[1].dai_name = devm_kasprintf(dev, GFP_KERNEL, "ssm4567-hifi"); |
| 108 |
if (!dl->cpus->dai_name || !dl->codecs[0].name || !dl->codecs[0].dai_name || |
| 109 |
!dl->codecs[1].name || !dl->codecs[1].dai_name) |
| 110 |
return -ENOMEM; |
| 111 |
|
| 112 |
platform->name = dev_name(dev); |
| 113 |
dl->num_cpus = 1; |
| 114 |
dl->num_codecs = 2; |
| 115 |
dl->platforms = platform; |
| 116 |
dl->num_platforms = 1; |
| 117 |
dl->id = 0; |
| 118 |
dl->dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF | SND_SOC_DAIFMT_CBC_CFC; |
| 119 |
dl->init = avs_ssm4567_codec_init; |
| 120 |
dl->be_hw_params_fixup = avs_ssm4567_be_fixup; |
| 121 |
dl->nonatomic = 1; |
| 122 |
dl->no_pcm = 1; |
| 123 |
dl->ignore_pmdown_time = 1; |
| 124 |
|
| 125 |
*dai_link = dl; |
| 126 |
|
| 127 |
return 0; |
| 128 |
} |
| 129 |
|
| 130 |
static int avs_ssm4567_probe(struct platform_device *pdev) |
| 131 |
{ |
| 132 |
struct snd_soc_dai_link *dai_link; |
| 133 |
struct snd_soc_acpi_mach *mach; |
| 134 |
struct avs_mach_pdata *pdata; |
| 135 |
struct snd_soc_card *card; |
| 136 |
struct device *dev = &pdev->dev; |
| 137 |
int ssp_port, tdm_slot, ret; |
| 138 |
|
| 139 |
mach = dev_get_platdata(dev); |
| 140 |
pdata = mach->pdata; |
| 141 |
|
| 142 |
ret = avs_mach_get_ssp_tdm(dev, mach, &ssp_port, &tdm_slot); |
| 143 |
if (ret) |
| 144 |
return ret; |
| 145 |
|
| 146 |
ret = avs_create_dai_link(dev, ssp_port, tdm_slot, &dai_link); |
| 147 |
if (ret) { |
| 148 |
dev_err(dev, "Failed to create dai link: %d", ret); |
| 149 |
return ret; |
| 150 |
} |
| 151 |
|
| 152 |
card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); |
| 153 |
if (!card) |
| 154 |
return -ENOMEM; |
| 155 |
|
| 156 |
if (pdata->obsolete_card_names) { |
| 157 |
card->name = "avs_ssm4567"; |
| 158 |
} else { |
| 159 |
card->driver_name = "avs_ssm4567"; |
| 160 |
card->long_name = card->name = "AVS I2S SSM4567"; |
| 161 |
} |
| 162 |
card->dev = dev; |
| 163 |
card->owner = THIS_MODULE; |
| 164 |
card->dai_link = dai_link; |
| 165 |
card->num_links = 1; |
| 166 |
card->codec_conf = card_codec_conf; |
| 167 |
card->num_configs = ARRAY_SIZE(card_codec_conf); |
| 168 |
card->controls = card_controls; |
| 169 |
card->num_controls = ARRAY_SIZE(card_controls); |
| 170 |
card->dapm_widgets = card_widgets; |
| 171 |
card->num_dapm_widgets = ARRAY_SIZE(card_widgets); |
| 172 |
card->dapm_routes = card_base_routes; |
| 173 |
card->num_dapm_routes = ARRAY_SIZE(card_base_routes); |
| 174 |
card->fully_routed = true; |
| 175 |
|
| 176 |
return devm_snd_soc_register_deferrable_card(dev, card); |
| 177 |
} |
| 178 |
|
| 179 |
static const struct platform_device_id avs_ssm4567_driver_ids[] = { |
| 180 |
{ |
| 181 |
.name = "avs_ssm4567", |
| 182 |
}, |
| 183 |
{}, |
| 184 |
}; |
| 185 |
MODULE_DEVICE_TABLE(platform, avs_ssm4567_driver_ids); |
| 186 |
|
| 187 |
static struct platform_driver avs_ssm4567_driver = { |
| 188 |
.probe = avs_ssm4567_probe, |
| 189 |
.driver = { |
| 190 |
.name = "avs_ssm4567", |
| 191 |
.pm = &snd_soc_pm_ops, |
| 192 |
}, |
| 193 |
.id_table = avs_ssm4567_driver_ids, |
| 194 |
}; |
| 195 |
|
| 196 |
module_platform_driver(avs_ssm4567_driver) |
| 197 |
|
| 198 |
MODULE_DESCRIPTION("Intel ssm4567 machine driver"); |
| 199 |
MODULE_LICENSE("GPL"); |