forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 1f93a7dfd1f8d5ff7a5c53246c7534fe2332d6f4
kernel/sound/soc/jz4740/jz4740-i2s.c
....@@ -1,15 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
3
- *
4
- * This program is free software; you can redistribute it and/or modify it
5
- * under the terms of the GNU General Public License as published by the
6
- * Free Software Foundation; either version 2 of the License, or (at your
7
- * option) any later version.
8
- *
9
- * You should have received a copy of the GNU General Public License along
10
- * with this program; if not, write to the Free Software Foundation, Inc.,
11
- * 675 Mass Ave, Cambridge, MA 02139, USA.
12
- *
134 */
145
156 #include <linux/init.h>
....@@ -58,12 +49,8 @@
5849
5950 #define JZ_AIC_CONF_FIFO_RX_THRESHOLD_OFFSET 12
6051 #define JZ_AIC_CONF_FIFO_TX_THRESHOLD_OFFSET 8
61
-#define JZ4780_AIC_CONF_FIFO_RX_THRESHOLD_OFFSET 24
62
-#define JZ4780_AIC_CONF_FIFO_TX_THRESHOLD_OFFSET 16
63
-#define JZ4780_AIC_CONF_FIFO_RX_THRESHOLD_MASK \
64
- (0xf << JZ4780_AIC_CONF_FIFO_RX_THRESHOLD_OFFSET)
65
-#define JZ4780_AIC_CONF_FIFO_TX_THRESHOLD_MASK \
66
- (0x1f << JZ4780_AIC_CONF_FIFO_TX_THRESHOLD_OFFSET)
52
+#define JZ4760_AIC_CONF_FIFO_RX_THRESHOLD_OFFSET 24
53
+#define JZ4760_AIC_CONF_FIFO_TX_THRESHOLD_OFFSET 16
6754
6855 #define JZ_AIC_CTRL_OUTPUT_SAMPLE_SIZE_MASK (0x7 << 19)
6956 #define JZ_AIC_CTRL_INPUT_SAMPLE_SIZE_MASK (0x7 << 16)
....@@ -99,7 +86,14 @@
9986
10087 enum jz47xx_i2s_version {
10188 JZ_I2S_JZ4740,
89
+ JZ_I2S_JZ4760,
90
+ JZ_I2S_JZ4770,
10291 JZ_I2S_JZ4780,
92
+};
93
+
94
+struct i2s_soc_info {
95
+ enum jz47xx_i2s_version version;
96
+ struct snd_soc_dai_driver *dai;
10397 };
10498
10599 struct jz4740_i2s {
....@@ -113,7 +107,7 @@
113107 struct snd_dmaengine_dai_dma_data playback_dma_data;
114108 struct snd_dmaengine_dai_dma_data capture_dma_data;
115109
116
- enum jz47xx_i2s_version version;
110
+ const struct i2s_soc_info *soc_info;
117111 };
118112
119113 static inline uint32_t jz4740_i2s_read(const struct jz4740_i2s *i2s,
....@@ -135,7 +129,7 @@
135129 uint32_t conf, ctrl;
136130 int ret;
137131
138
- if (dai->active)
132
+ if (snd_soc_dai_active(dai))
139133 return 0;
140134
141135 ctrl = jz4740_i2s_read(i2s, JZ_REG_AIC_CTRL);
....@@ -159,7 +153,7 @@
159153 struct jz4740_i2s *i2s = snd_soc_dai_get_drvdata(dai);
160154 uint32_t conf;
161155
162
- if (dai->active)
156
+ if (snd_soc_dai_active(dai))
163157 return;
164158
165159 conf = jz4740_i2s_read(i2s, JZ_REG_AIC_CONF);
....@@ -293,7 +287,7 @@
293287 ctrl &= ~JZ_AIC_CTRL_INPUT_SAMPLE_SIZE_MASK;
294288 ctrl |= sample_size << JZ_AIC_CTRL_INPUT_SAMPLE_SIZE_OFFSET;
295289
296
- if (i2s->version >= JZ_I2S_JZ4780) {
290
+ if (i2s->soc_info->version >= JZ_I2S_JZ4770) {
297291 div_reg &= ~I2SDIV_IDV_MASK;
298292 div_reg |= (div - 1) << I2SDIV_IDV_SHIFT;
299293 } else {
....@@ -337,12 +331,12 @@
337331 return ret;
338332 }
339333
340
-static int jz4740_i2s_suspend(struct snd_soc_dai *dai)
334
+static int jz4740_i2s_suspend(struct snd_soc_component *component)
341335 {
342
- struct jz4740_i2s *i2s = snd_soc_dai_get_drvdata(dai);
336
+ struct jz4740_i2s *i2s = snd_soc_component_get_drvdata(component);
343337 uint32_t conf;
344338
345
- if (dai->active) {
339
+ if (snd_soc_component_active(component)) {
346340 conf = jz4740_i2s_read(i2s, JZ_REG_AIC_CONF);
347341 conf &= ~JZ_AIC_CONF_ENABLE;
348342 jz4740_i2s_write(i2s, JZ_REG_AIC_CONF, conf);
....@@ -355,9 +349,9 @@
355349 return 0;
356350 }
357351
358
-static int jz4740_i2s_resume(struct snd_soc_dai *dai)
352
+static int jz4740_i2s_resume(struct snd_soc_component *component)
359353 {
360
- struct jz4740_i2s *i2s = snd_soc_dai_get_drvdata(dai);
354
+ struct jz4740_i2s *i2s = snd_soc_component_get_drvdata(component);
361355 uint32_t conf;
362356 int ret;
363357
....@@ -365,7 +359,7 @@
365359 if (ret)
366360 return ret;
367361
368
- if (dai->active) {
362
+ if (snd_soc_component_active(component)) {
369363 ret = clk_prepare_enable(i2s->clk_i2s);
370364 if (ret) {
371365 clk_disable_unprepare(i2s->clk_aic);
....@@ -411,9 +405,9 @@
411405 snd_soc_dai_init_dma_data(dai, &i2s->playback_dma_data,
412406 &i2s->capture_dma_data);
413407
414
- if (i2s->version >= JZ_I2S_JZ4780) {
415
- conf = (7 << JZ4780_AIC_CONF_FIFO_RX_THRESHOLD_OFFSET) |
416
- (8 << JZ4780_AIC_CONF_FIFO_TX_THRESHOLD_OFFSET) |
408
+ if (i2s->soc_info->version >= JZ_I2S_JZ4760) {
409
+ conf = (7 << JZ4760_AIC_CONF_FIFO_RX_THRESHOLD_OFFSET) |
410
+ (8 << JZ4760_AIC_CONF_FIFO_TX_THRESHOLD_OFFSET) |
417411 JZ_AIC_CONF_OVERFLOW_PLAY_LAST |
418412 JZ_AIC_CONF_I2S |
419413 JZ_AIC_CONF_INTERNAL_CODEC;
....@@ -468,11 +462,19 @@
468462 },
469463 .symmetric_rates = 1,
470464 .ops = &jz4740_i2s_dai_ops,
471
- .suspend = jz4740_i2s_suspend,
472
- .resume = jz4740_i2s_resume,
473465 };
474466
475
-static struct snd_soc_dai_driver jz4780_i2s_dai = {
467
+static const struct i2s_soc_info jz4740_i2s_soc_info = {
468
+ .version = JZ_I2S_JZ4740,
469
+ .dai = &jz4740_i2s_dai,
470
+};
471
+
472
+static const struct i2s_soc_info jz4760_i2s_soc_info = {
473
+ .version = JZ_I2S_JZ4760,
474
+ .dai = &jz4740_i2s_dai,
475
+};
476
+
477
+static struct snd_soc_dai_driver jz4770_i2s_dai = {
476478 .probe = jz4740_i2s_dai_probe,
477479 .remove = jz4740_i2s_dai_remove,
478480 .playback = {
....@@ -488,66 +490,69 @@
488490 .formats = JZ4740_I2S_FMTS,
489491 },
490492 .ops = &jz4740_i2s_dai_ops,
491
- .suspend = jz4740_i2s_suspend,
492
- .resume = jz4740_i2s_resume,
493
+};
494
+
495
+static const struct i2s_soc_info jz4770_i2s_soc_info = {
496
+ .version = JZ_I2S_JZ4770,
497
+ .dai = &jz4770_i2s_dai,
498
+};
499
+
500
+static const struct i2s_soc_info jz4780_i2s_soc_info = {
501
+ .version = JZ_I2S_JZ4780,
502
+ .dai = &jz4770_i2s_dai,
493503 };
494504
495505 static const struct snd_soc_component_driver jz4740_i2s_component = {
496506 .name = "jz4740-i2s",
507
+ .suspend = jz4740_i2s_suspend,
508
+ .resume = jz4740_i2s_resume,
497509 };
498510
499
-#ifdef CONFIG_OF
500511 static const struct of_device_id jz4740_of_matches[] = {
501
- { .compatible = "ingenic,jz4740-i2s", .data = (void *)JZ_I2S_JZ4740 },
502
- { .compatible = "ingenic,jz4780-i2s", .data = (void *)JZ_I2S_JZ4780 },
512
+ { .compatible = "ingenic,jz4740-i2s", .data = &jz4740_i2s_soc_info },
513
+ { .compatible = "ingenic,jz4760-i2s", .data = &jz4760_i2s_soc_info },
514
+ { .compatible = "ingenic,jz4770-i2s", .data = &jz4770_i2s_soc_info },
515
+ { .compatible = "ingenic,jz4780-i2s", .data = &jz4780_i2s_soc_info },
503516 { /* sentinel */ }
504517 };
505518 MODULE_DEVICE_TABLE(of, jz4740_of_matches);
506
-#endif
507519
508520 static int jz4740_i2s_dev_probe(struct platform_device *pdev)
509521 {
522
+ struct device *dev = &pdev->dev;
510523 struct jz4740_i2s *i2s;
511524 struct resource *mem;
512525 int ret;
513
- const struct of_device_id *match;
514526
515
- i2s = devm_kzalloc(&pdev->dev, sizeof(*i2s), GFP_KERNEL);
527
+ i2s = devm_kzalloc(dev, sizeof(*i2s), GFP_KERNEL);
516528 if (!i2s)
517529 return -ENOMEM;
518530
519
- match = of_match_device(jz4740_of_matches, &pdev->dev);
520
- if (match)
521
- i2s->version = (enum jz47xx_i2s_version)match->data;
531
+ i2s->soc_info = device_get_match_data(dev);
522532
523533 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
524
- i2s->base = devm_ioremap_resource(&pdev->dev, mem);
534
+ i2s->base = devm_ioremap_resource(dev, mem);
525535 if (IS_ERR(i2s->base))
526536 return PTR_ERR(i2s->base);
527537
528538 i2s->phys_base = mem->start;
529539
530
- i2s->clk_aic = devm_clk_get(&pdev->dev, "aic");
540
+ i2s->clk_aic = devm_clk_get(dev, "aic");
531541 if (IS_ERR(i2s->clk_aic))
532542 return PTR_ERR(i2s->clk_aic);
533543
534
- i2s->clk_i2s = devm_clk_get(&pdev->dev, "i2s");
544
+ i2s->clk_i2s = devm_clk_get(dev, "i2s");
535545 if (IS_ERR(i2s->clk_i2s))
536546 return PTR_ERR(i2s->clk_i2s);
537547
538548 platform_set_drvdata(pdev, i2s);
539549
540
- if (i2s->version == JZ_I2S_JZ4780)
541
- ret = devm_snd_soc_register_component(&pdev->dev,
542
- &jz4740_i2s_component, &jz4780_i2s_dai, 1);
543
- else
544
- ret = devm_snd_soc_register_component(&pdev->dev,
545
- &jz4740_i2s_component, &jz4740_i2s_dai, 1);
546
-
550
+ ret = devm_snd_soc_register_component(dev, &jz4740_i2s_component,
551
+ i2s->soc_info->dai, 1);
547552 if (ret)
548553 return ret;
549554
550
- return devm_snd_dmaengine_pcm_register(&pdev->dev, NULL,
555
+ return devm_snd_dmaengine_pcm_register(dev, NULL,
551556 SND_DMAENGINE_PCM_FLAG_COMPAT);
552557 }
553558
....@@ -555,7 +560,7 @@
555560 .probe = jz4740_i2s_dev_probe,
556561 .driver = {
557562 .name = "jz4740-i2s",
558
- .of_match_table = of_match_ptr(jz4740_of_matches)
563
+ .of_match_table = jz4740_of_matches,
559564 },
560565 };
561566