hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/sound/soc/codecs/rt5514-spi.c
....@@ -1,12 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * rt5514-spi.c -- RT5514 SPI driver
34 *
45 * Copyright 2015 Realtek Semiconductor Corp.
56 * Author: Oder Chiou <oder_chiou@realtek.com>
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License version 2 as
9
- * published by the Free Software Foundation.
107 */
118
129 #include <linux/module.h>
....@@ -91,6 +88,14 @@
9188
9289 runtime = rt5514_dsp->substream->runtime;
9390 period_bytes = snd_pcm_lib_period_bytes(rt5514_dsp->substream);
91
+ if (!period_bytes) {
92
+ schedule_delayed_work(&rt5514_dsp->copy_work, 5);
93
+ goto done;
94
+ }
95
+
96
+ if (rt5514_dsp->buf_size % period_bytes)
97
+ rt5514_dsp->buf_size = (rt5514_dsp->buf_size / period_bytes) *
98
+ period_bytes;
9499
95100 if (rt5514_dsp->get_size >= rt5514_dsp->buf_size) {
96101 rt5514_spi_burst_read(RT5514_BUFFER_VOICE_WP, (u8 *)&buf,
....@@ -149,13 +154,11 @@
149154
150155 static void rt5514_schedule_copy(struct rt5514_dsp *rt5514_dsp)
151156 {
152
- size_t period_bytes;
153157 u8 buf[8];
154158
155159 if (!rt5514_dsp->substream)
156160 return;
157161
158
- period_bytes = snd_pcm_lib_period_bytes(rt5514_dsp->substream);
159162 rt5514_dsp->get_size = 0;
160163
161164 /**
....@@ -183,10 +186,6 @@
183186
184187 rt5514_dsp->buf_size = rt5514_dsp->buf_limit - rt5514_dsp->buf_base;
185188
186
- if (rt5514_dsp->buf_size % period_bytes)
187
- rt5514_dsp->buf_size = (rt5514_dsp->buf_size / period_bytes) *
188
- period_bytes;
189
-
190189 if (rt5514_dsp->buf_base && rt5514_dsp->buf_limit &&
191190 rt5514_dsp->buf_rp && rt5514_dsp->buf_size)
192191 schedule_delayed_work(&rt5514_dsp->copy_work, 0);
....@@ -202,26 +201,23 @@
202201 }
203202
204203 /* PCM for streaming audio from the DSP buffer */
205
-static int rt5514_spi_pcm_open(struct snd_pcm_substream *substream)
204
+static int rt5514_spi_pcm_open(struct snd_soc_component *component,
205
+ struct snd_pcm_substream *substream)
206206 {
207207 snd_soc_set_runtime_hwparams(substream, &rt5514_spi_pcm_hardware);
208208
209209 return 0;
210210 }
211211
212
-static int rt5514_spi_hw_params(struct snd_pcm_substream *substream,
213
- struct snd_pcm_hw_params *hw_params)
212
+static int rt5514_spi_hw_params(struct snd_soc_component *component,
213
+ struct snd_pcm_substream *substream,
214
+ struct snd_pcm_hw_params *hw_params)
214215 {
215
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
216
- struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
217216 struct rt5514_dsp *rt5514_dsp =
218217 snd_soc_component_get_drvdata(component);
219
- int ret;
220218 u8 buf[8];
221219
222220 mutex_lock(&rt5514_dsp->dma_lock);
223
- ret = snd_pcm_lib_alloc_vmalloc_buffer(substream,
224
- params_buffer_bytes(hw_params));
225221 rt5514_dsp->substream = substream;
226222 rt5514_dsp->dma_offset = 0;
227223
....@@ -232,13 +228,12 @@
232228
233229 mutex_unlock(&rt5514_dsp->dma_lock);
234230
235
- return ret;
231
+ return 0;
236232 }
237233
238
-static int rt5514_spi_hw_free(struct snd_pcm_substream *substream)
234
+static int rt5514_spi_hw_free(struct snd_soc_component *component,
235
+ struct snd_pcm_substream *substream)
239236 {
240
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
241
- struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
242237 struct rt5514_dsp *rt5514_dsp =
243238 snd_soc_component_get_drvdata(component);
244239
....@@ -248,28 +243,20 @@
248243
249244 cancel_delayed_work_sync(&rt5514_dsp->copy_work);
250245
251
- return snd_pcm_lib_free_vmalloc_buffer(substream);
246
+ return 0;
252247 }
253248
254249 static snd_pcm_uframes_t rt5514_spi_pcm_pointer(
250
+ struct snd_soc_component *component,
255251 struct snd_pcm_substream *substream)
256252 {
257253 struct snd_pcm_runtime *runtime = substream->runtime;
258
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
259
- struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
260254 struct rt5514_dsp *rt5514_dsp =
261255 snd_soc_component_get_drvdata(component);
262256
263257 return bytes_to_frames(runtime, rt5514_dsp->dma_offset);
264258 }
265259
266
-static const struct snd_pcm_ops rt5514_spi_pcm_ops = {
267
- .open = rt5514_spi_pcm_open,
268
- .hw_params = rt5514_spi_hw_params,
269
- .hw_free = rt5514_spi_hw_free,
270
- .pointer = rt5514_spi_pcm_pointer,
271
- .page = snd_pcm_lib_get_vmalloc_page,
272
-};
273260
274261 static int rt5514_spi_pcm_probe(struct snd_soc_component *component)
275262 {
....@@ -302,10 +289,22 @@
302289 return 0;
303290 }
304291
292
+static int rt5514_spi_pcm_new(struct snd_soc_component *component,
293
+ struct snd_soc_pcm_runtime *rtd)
294
+{
295
+ snd_pcm_set_managed_buffer_all(rtd->pcm, SNDRV_DMA_TYPE_VMALLOC,
296
+ NULL, 0, 0);
297
+ return 0;
298
+}
299
+
305300 static const struct snd_soc_component_driver rt5514_spi_component = {
306
- .name = DRV_NAME,
307
- .probe = rt5514_spi_pcm_probe,
308
- .ops = &rt5514_spi_pcm_ops,
301
+ .name = DRV_NAME,
302
+ .probe = rt5514_spi_pcm_probe,
303
+ .open = rt5514_spi_pcm_open,
304
+ .hw_params = rt5514_spi_hw_params,
305
+ .hw_free = rt5514_spi_hw_free,
306
+ .pointer = rt5514_spi_pcm_pointer,
307
+ .pcm_construct = rt5514_spi_pcm_new,
309308 };
310309
311310 /**
....@@ -471,9 +470,7 @@
471470
472471 static int __maybe_unused rt5514_resume(struct device *dev)
473472 {
474
- struct snd_soc_component *component = snd_soc_lookup_component(dev, DRV_NAME);
475
- struct rt5514_dsp *rt5514_dsp =
476
- snd_soc_component_get_drvdata(component);
473
+ struct rt5514_dsp *rt5514_dsp = dev_get_drvdata(dev);
477474 int irq = to_spi_device(dev)->irq;
478475 u8 buf[8];
479476