Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/sound/soc/amd/acp/acp70.c
26481 views
1
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
2
//
3
// This file is provided under a dual BSD/GPLv2 license. When using or
4
// redistributing this file, you may do so under either license.
5
//
6
// Copyright(c) 2023 Advanced Micro Devices, Inc.
7
//
8
// Authors: Syed Saba kareem <[email protected]>
9
/*
10
* Hardware interface for ACP7.0 block
11
*/
12
13
#include <linux/platform_device.h>
14
#include <linux/module.h>
15
#include <linux/err.h>
16
#include <linux/io.h>
17
#include <sound/pcm_params.h>
18
#include <sound/soc.h>
19
#include <sound/soc-dai.h>
20
#include <linux/dma-mapping.h>
21
#include <linux/pm_runtime.h>
22
#include <linux/pci.h>
23
#include "amd.h"
24
#include "acp-mach.h"
25
26
#include <asm/amd/node.h>
27
28
#define DRV_NAME "acp_asoc_acp70"
29
30
#define CLK7_CLK0_DFS_CNTL_N1 0X0006C1A4
31
#define CLK0_DIVIDER 0X19
32
33
static struct snd_soc_dai_driver acp70_dai[] = {
34
{
35
.name = "acp-i2s-sp",
36
.id = I2S_SP_INSTANCE,
37
.playback = {
38
.stream_name = "I2S SP Playback",
39
.rates = SNDRV_PCM_RATE_8000_192000,
40
.formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S8 |
41
SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE,
42
.channels_min = 2,
43
.channels_max = 32,
44
.rate_min = 8000,
45
.rate_max = 192000,
46
},
47
.capture = {
48
.stream_name = "I2S SP Capture",
49
.rates = SNDRV_PCM_RATE_8000_192000,
50
.formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S8 |
51
SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE,
52
.channels_min = 2,
53
.channels_max = 32,
54
.rate_min = 8000,
55
.rate_max = 192000,
56
},
57
.ops = &asoc_acp_cpu_dai_ops,
58
},
59
{
60
.name = "acp-i2s-bt",
61
.id = I2S_BT_INSTANCE,
62
.playback = {
63
.stream_name = "I2S BT Playback",
64
.rates = SNDRV_PCM_RATE_8000_192000,
65
.formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S8 |
66
SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE,
67
.channels_min = 2,
68
.channels_max = 32,
69
.rate_min = 8000,
70
.rate_max = 192000,
71
},
72
.capture = {
73
.stream_name = "I2S BT Capture",
74
.rates = SNDRV_PCM_RATE_8000_192000,
75
.formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S8 |
76
SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE,
77
.channels_min = 2,
78
.channels_max = 32,
79
.rate_min = 8000,
80
.rate_max = 192000,
81
},
82
.ops = &asoc_acp_cpu_dai_ops,
83
},
84
{
85
.name = "acp-i2s-hs",
86
.id = I2S_HS_INSTANCE,
87
.playback = {
88
.stream_name = "I2S HS Playback",
89
.rates = SNDRV_PCM_RATE_8000_192000,
90
.formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S8 |
91
SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE,
92
.channels_min = 2,
93
.channels_max = 32,
94
.rate_min = 8000,
95
.rate_max = 192000,
96
},
97
.capture = {
98
.stream_name = "I2S HS Capture",
99
.rates = SNDRV_PCM_RATE_8000_192000,
100
.formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S8 |
101
SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE,
102
.channels_min = 2,
103
.channels_max = 32,
104
.rate_min = 8000,
105
.rate_max = 192000,
106
},
107
.ops = &asoc_acp_cpu_dai_ops,
108
},
109
{
110
.name = "acp-pdm-dmic",
111
.id = DMIC_INSTANCE,
112
.capture = {
113
.rates = SNDRV_PCM_RATE_8000_48000,
114
.formats = SNDRV_PCM_FMTBIT_S32_LE,
115
.channels_min = 2,
116
.channels_max = 2,
117
.rate_min = 8000,
118
.rate_max = 48000,
119
},
120
.ops = &acp_dmic_dai_ops,
121
},
122
};
123
124
static int acp_acp70_audio_probe(struct platform_device *pdev)
125
{
126
struct device *dev = &pdev->dev;
127
struct acp_chip_info *chip;
128
int ret;
129
130
chip = dev_get_platdata(&pdev->dev);
131
if (!chip || !chip->base) {
132
dev_err(&pdev->dev, "ACP chip data is NULL\n");
133
return -ENODEV;
134
}
135
136
switch (chip->acp_rev) {
137
case ACP70_PCI_ID:
138
case ACP71_PCI_ID:
139
case ACP72_PCI_ID:
140
break;
141
default:
142
dev_err(&pdev->dev, "Un-supported ACP Revision %d\n", chip->acp_rev);
143
return -ENODEV;
144
}
145
146
chip->dev = dev;
147
chip->dai_driver = acp70_dai;
148
chip->num_dai = ARRAY_SIZE(acp70_dai);
149
150
/* Set clk7 DFS clock divider register value to get mclk as 196.608MHz*/
151
ret = amd_smn_write(0, CLK7_CLK0_DFS_CNTL_N1, CLK0_DIVIDER);
152
if (ret) {
153
dev_err(&pdev->dev, "Failed to set I2S master clock as 196.608MHz\n");
154
return ret;
155
}
156
ret = acp_hw_en_interrupts(chip);
157
if (ret) {
158
dev_err(dev, "ACP en-interrupts failed\n");
159
return ret;
160
}
161
acp_platform_register(dev);
162
pm_runtime_set_autosuspend_delay(&pdev->dev, ACP_SUSPEND_DELAY_MS);
163
pm_runtime_use_autosuspend(&pdev->dev);
164
pm_runtime_mark_last_busy(&pdev->dev);
165
pm_runtime_set_active(&pdev->dev);
166
pm_runtime_enable(&pdev->dev);
167
return 0;
168
}
169
170
static void acp_acp70_audio_remove(struct platform_device *pdev)
171
{
172
struct device *dev = &pdev->dev;
173
struct acp_chip_info *chip = dev_get_platdata(dev);
174
int ret;
175
176
ret = acp_hw_dis_interrupts(chip);
177
if (ret)
178
dev_err(dev, "ACP dis-interrupts failed\n");
179
180
acp_platform_unregister(dev);
181
pm_runtime_disable(&pdev->dev);
182
}
183
184
static int acp70_pcm_resume(struct device *dev)
185
{
186
struct acp_chip_info *chip = dev_get_drvdata(dev->parent);
187
struct acp_stream *stream;
188
struct snd_pcm_substream *substream;
189
snd_pcm_uframes_t buf_in_frames;
190
u64 buf_size;
191
192
spin_lock(&chip->acp_lock);
193
list_for_each_entry(stream, &chip->stream_list, list) {
194
substream = stream->substream;
195
if (substream && substream->runtime) {
196
buf_in_frames = (substream->runtime->buffer_size);
197
buf_size = frames_to_bytes(substream->runtime, buf_in_frames);
198
config_pte_for_stream(chip, stream);
199
config_acp_dma(chip, stream, buf_size);
200
if (stream->dai_id)
201
restore_acp_i2s_params(substream, chip, stream);
202
else
203
restore_acp_pdm_params(substream, chip);
204
}
205
}
206
spin_unlock(&chip->acp_lock);
207
return 0;
208
}
209
210
static const struct dev_pm_ops acp70_dma_pm_ops = {
211
SYSTEM_SLEEP_PM_OPS(NULL, acp70_pcm_resume)
212
};
213
214
static struct platform_driver acp70_driver = {
215
.probe = acp_acp70_audio_probe,
216
.remove = acp_acp70_audio_remove,
217
.driver = {
218
.name = "acp_asoc_acp70",
219
.pm = pm_ptr(&acp70_dma_pm_ops),
220
},
221
};
222
223
module_platform_driver(acp70_driver);
224
225
MODULE_DESCRIPTION("AMD ACP ACP70 Driver");
226
MODULE_IMPORT_NS("SND_SOC_ACP_COMMON");
227
MODULE_LICENSE("Dual BSD/GPL");
228
MODULE_ALIAS("platform:" DRV_NAME);
229
230