Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/sound/soc/intel/avs/boards/rt5514.c
26607 views
1
// SPDX-License-Identifier: GPL-2.0-only
2
//
3
// Copyright(c) 2021-2023 Intel Corporation
4
//
5
// Authors: Cezary Rojewski <[email protected]>
6
// Amadeusz Slawinski <[email protected]>
7
//
8
9
#include <linux/clk.h>
10
#include <linux/input.h>
11
#include <linux/module.h>
12
#include <sound/jack.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 "../../../codecs/rt5514.h"
18
#include "../utils.h"
19
20
#define RT5514_CODEC_DAI "rt5514-aif1"
21
22
static const struct snd_soc_dapm_widget card_widgets[] = {
23
SND_SOC_DAPM_MIC("DMIC", NULL),
24
};
25
26
static const struct snd_soc_dapm_route card_base_routes[] = {
27
/* DMIC */
28
{ "DMIC1L", NULL, "DMIC" },
29
{ "DMIC1R", NULL, "DMIC" },
30
{ "DMIC2L", NULL, "DMIC" },
31
{ "DMIC2R", NULL, "DMIC" },
32
};
33
34
static int avs_rt5514_codec_init(struct snd_soc_pcm_runtime *runtime)
35
{
36
int ret = snd_soc_dapm_ignore_suspend(&runtime->card->dapm, "DMIC");
37
38
if (ret)
39
dev_err(runtime->dev, "DMIC - Ignore suspend failed = %d\n", ret);
40
41
return ret;
42
}
43
44
static int avs_rt5514_be_fixup(struct snd_soc_pcm_runtime *runtime,
45
struct snd_pcm_hw_params *params)
46
{
47
struct snd_interval *rate, *channels;
48
struct snd_mask *fmt;
49
50
rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
51
channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
52
fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
53
54
rate->min = rate->max = 48000;
55
channels->min = channels->max = 4;
56
57
snd_mask_none(fmt);
58
snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE);
59
60
return 0;
61
}
62
63
static int avs_rt5514_hw_params(struct snd_pcm_substream *substream,
64
struct snd_pcm_hw_params *params)
65
{
66
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
67
struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
68
int ret;
69
70
ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xF, 0, 8, 16);
71
if (ret < 0) {
72
dev_err(rtd->dev, "set TDM slot err:%d\n", ret);
73
return ret;
74
}
75
76
ret = snd_soc_dai_set_sysclk(codec_dai, RT5514_SCLK_S_MCLK, 24576000, SND_SOC_CLOCK_IN);
77
if (ret < 0)
78
dev_err(rtd->dev, "set sysclk err: %d\n", ret);
79
80
return ret;
81
}
82
83
static const struct snd_soc_ops avs_rt5514_ops = {
84
.hw_params = avs_rt5514_hw_params,
85
};
86
87
static int avs_create_dai_link(struct device *dev, const char *platform_name, int ssp_port,
88
int tdm_slot, struct snd_soc_dai_link **dai_link)
89
{
90
struct snd_soc_dai_link_component *platform;
91
struct snd_soc_dai_link *dl;
92
93
dl = devm_kzalloc(dev, sizeof(*dl), GFP_KERNEL);
94
platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL);
95
if (!dl || !platform)
96
return -ENOMEM;
97
98
platform->name = platform_name;
99
100
dl->name = devm_kasprintf(dev, GFP_KERNEL,
101
AVS_STRING_FMT("SSP", "-Codec", ssp_port, tdm_slot));
102
dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL);
103
dl->codecs = devm_kzalloc(dev, sizeof(*dl->codecs), GFP_KERNEL);
104
if (!dl->name || !dl->cpus || !dl->codecs)
105
return -ENOMEM;
106
107
dl->cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
108
AVS_STRING_FMT("SSP", " Pin", ssp_port, tdm_slot));
109
dl->codecs->name = devm_kasprintf(dev, GFP_KERNEL, "i2c-10EC5514:00");
110
dl->codecs->dai_name = devm_kasprintf(dev, GFP_KERNEL, RT5514_CODEC_DAI);
111
if (!dl->cpus->dai_name || !dl->codecs->name || !dl->codecs->dai_name)
112
return -ENOMEM;
113
114
dl->num_cpus = 1;
115
dl->num_codecs = 1;
116
dl->platforms = platform;
117
dl->num_platforms = 1;
118
dl->id = 0;
119
dl->dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBC_CFC;
120
dl->init = avs_rt5514_codec_init;
121
dl->be_hw_params_fixup = avs_rt5514_be_fixup;
122
dl->nonatomic = 1;
123
dl->no_pcm = 1;
124
dl->capture_only = 1;
125
dl->ops = &avs_rt5514_ops;
126
127
*dai_link = dl;
128
129
return 0;
130
}
131
132
static int avs_rt5514_probe(struct platform_device *pdev)
133
{
134
struct snd_soc_dai_link *dai_link;
135
struct snd_soc_acpi_mach *mach;
136
struct avs_mach_pdata *pdata;
137
struct snd_soc_card *card;
138
struct device *dev = &pdev->dev;
139
const char *pname;
140
int ssp_port, tdm_slot, ret;
141
142
mach = dev_get_platdata(dev);
143
pname = mach->mach_params.platform;
144
pdata = mach->pdata;
145
146
ret = avs_mach_get_ssp_tdm(dev, mach, &ssp_port, &tdm_slot);
147
if (ret)
148
return ret;
149
150
ret = avs_create_dai_link(dev, pname, ssp_port, tdm_slot, &dai_link);
151
if (ret) {
152
dev_err(dev, "Failed to create dai link: %d", ret);
153
return ret;
154
}
155
156
card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
157
if (!card)
158
return -ENOMEM;
159
160
if (pdata->obsolete_card_names) {
161
card->name = "avs_rt5514";
162
} else {
163
card->driver_name = "avs_rt5514";
164
card->long_name = card->name = "AVS I2S ALC5514";
165
}
166
card->dev = dev;
167
card->owner = THIS_MODULE;
168
card->dai_link = dai_link;
169
card->num_links = 1;
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
ret = snd_soc_fixup_dai_links_platform_name(card, pname);
177
if (ret)
178
return ret;
179
180
return devm_snd_soc_register_deferrable_card(dev, card);
181
}
182
183
static const struct platform_device_id avs_rt5514_driver_ids[] = {
184
{
185
.name = "avs_rt5514",
186
},
187
{},
188
};
189
MODULE_DEVICE_TABLE(platform, avs_rt5514_driver_ids);
190
191
static struct platform_driver avs_rt5514_driver = {
192
.probe = avs_rt5514_probe,
193
.driver = {
194
.name = "avs_rt5514",
195
.pm = &snd_soc_pm_ops,
196
},
197
.id_table = avs_rt5514_driver_ids,
198
};
199
200
module_platform_driver(avs_rt5514_driver);
201
202
MODULE_DESCRIPTION("Intel rt5514 machine driver");
203
MODULE_LICENSE("GPL");
204
205