forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/sound/soc/codecs/wm8958-dsp2.c
....@@ -1,13 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * wm8958-dsp2.c -- WM8958 DSP2 support
34 *
45 * Copyright 2011 Wolfson Microelectronics plc
56 *
67 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License version 2 as
10
- * published by the Free Software Foundation.
118 */
129
1310 #include <linux/module.h>
....@@ -27,6 +24,8 @@
2724 #include <linux/mfd/wm8994/registers.h>
2825 #include <linux/mfd/wm8994/pdata.h>
2926 #include <linux/mfd/wm8994/gpio.h>
27
+
28
+#include <asm/unaligned.h>
3029
3130 #include "wm8994.h"
3231
....@@ -61,18 +60,15 @@
6160 }
6261
6362 if (memcmp(fw->data, "WMFW", 4) != 0) {
64
- memcpy(&data32, fw->data, sizeof(data32));
65
- data32 = be32_to_cpu(data32);
63
+ data32 = get_unaligned_be32(fw->data);
6664 dev_err(component->dev, "%s: firmware has bad file magic %08x\n",
6765 name, data32);
6866 goto err;
6967 }
7068
71
- memcpy(&data32, fw->data + 4, sizeof(data32));
72
- len = be32_to_cpu(data32);
69
+ len = get_unaligned_be32(fw->data + 4);
70
+ data32 = get_unaligned_be32(fw->data + 8);
7371
74
- memcpy(&data32, fw->data + 8, sizeof(data32));
75
- data32 = be32_to_cpu(data32);
7672 if ((data32 >> 24) & 0xff) {
7773 dev_err(component->dev, "%s: unsupported firmware version %d\n",
7874 name, (data32 >> 24) & 0xff);
....@@ -90,9 +86,8 @@
9086 }
9187
9288 if (check) {
93
- memcpy(&data64, fw->data + 24, sizeof(u64));
94
- dev_info(component->dev, "%s timestamp %llx\n",
95
- name, be64_to_cpu(data64));
89
+ data64 = get_unaligned_be64(fw->data + 24);
90
+ dev_info(component->dev, "%s timestamp %llx\n", name, data64);
9691 } else {
9792 snd_soc_component_write(component, 0x102, 0x2);
9893 snd_soc_component_write(component, 0x900, 0x2);
....@@ -107,8 +102,7 @@
107102 goto err;
108103 }
109104
110
- memcpy(&data32, data + 4, sizeof(data32));
111
- block_len = be32_to_cpu(data32);
105
+ block_len = get_unaligned_be32(data + 4);
112106 if (block_len + 8 > len) {
113107 dev_err(component->dev, "%zd byte block longer than file\n",
114108 block_len);
....@@ -119,8 +113,7 @@
119113 goto err;
120114 }
121115
122
- memcpy(&data32, data, sizeof(data32));
123
- data32 = be32_to_cpu(data32);
116
+ data32 = get_unaligned_be32(data);
124117
125118 switch ((data32 >> 24) & 0xff) {
126119 case WM_FW_BLOCK_INFO:
....@@ -199,7 +192,7 @@
199192 int i;
200193
201194 /* If the DSP is already running then noop */
202
- if (snd_soc_component_read32(component, WM8958_DSP2_PROGRAM) & WM8958_DSP2_ENA)
195
+ if (snd_soc_component_read(component, WM8958_DSP2_PROGRAM) & WM8958_DSP2_ENA)
203196 return;
204197
205198 /* If we have MBC firmware download it */
....@@ -331,7 +324,7 @@
331324 static void wm8958_dsp_apply(struct snd_soc_component *component, int path, int start)
332325 {
333326 struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
334
- int pwr_reg = snd_soc_component_read32(component, WM8994_POWER_MANAGEMENT_5);
327
+ int pwr_reg = snd_soc_component_read(component, WM8994_POWER_MANAGEMENT_5);
335328 int ena, reg, aif;
336329
337330 switch (path) {
....@@ -359,7 +352,7 @@
359352 if (!pwr_reg)
360353 ena = 0;
361354
362
- reg = snd_soc_component_read32(component, WM8958_DSP2_PROGRAM);
355
+ reg = snd_soc_component_read(component, WM8958_DSP2_PROGRAM);
363356
364357 dev_dbg(component->dev, "DSP path %d %d startup: %d, power: %x, DSP: %x\n",
365358 path, wm8994->dsp_active, start, pwr_reg, reg);
....@@ -370,9 +363,9 @@
370363 return;
371364
372365 /* If either AIFnCLK is not yet enabled postpone */
373
- if (!(snd_soc_component_read32(component, WM8994_AIF1_CLOCKING_1)
366
+ if (!(snd_soc_component_read(component, WM8994_AIF1_CLOCKING_1)
374367 & WM8994_AIF1CLK_ENA_MASK) &&
375
- !(snd_soc_component_read32(component, WM8994_AIF2_CLOCKING_1)
368
+ !(snd_soc_component_read(component, WM8994_AIF2_CLOCKING_1)
376369 & WM8994_AIF2CLK_ENA_MASK))
377370 return;
378371
....@@ -467,7 +460,7 @@
467460 int reg;
468461
469462 /* Don't allow on the fly reconfiguration */
470
- reg = snd_soc_component_read32(component, WM8994_CLOCKING_1);
463
+ reg = snd_soc_component_read(component, WM8994_CLOCKING_1);
471464 if (reg < 0 || reg & WM8958_DSP2CLK_ENA)
472465 return -EBUSY;
473466
....@@ -537,7 +530,7 @@
537530
538531 wm8958_dsp_apply(component, mbc, wm8994->mbc_ena[mbc]);
539532
540
- return 0;
533
+ return 1;
541534 }
542535
543536 #define WM8958_MBC_SWITCH(xname, xval) {\
....@@ -557,7 +550,7 @@
557550 int reg;
558551
559552 /* Don't allow on the fly reconfiguration */
560
- reg = snd_soc_component_read32(component, WM8994_CLOCKING_1);
553
+ reg = snd_soc_component_read(component, WM8994_CLOCKING_1);
561554 if (reg < 0 || reg & WM8958_DSP2CLK_ENA)
562555 return -EBUSY;
563556
....@@ -590,7 +583,7 @@
590583 int reg;
591584
592585 /* Don't allow on the fly reconfiguration */
593
- reg = snd_soc_component_read32(component, WM8994_CLOCKING_1);
586
+ reg = snd_soc_component_read(component, WM8994_CLOCKING_1);
594587 if (reg < 0 || reg & WM8958_DSP2CLK_ENA)
595588 return -EBUSY;
596589
....@@ -663,7 +656,7 @@
663656
664657 wm8958_dsp_apply(component, vss, wm8994->vss_ena[vss]);
665658
666
- return 0;
659
+ return 1;
667660 }
668661
669662
....@@ -737,7 +730,7 @@
737730
738731 wm8958_dsp_apply(component, hpf % 3, ucontrol->value.integer.value[0]);
739732
740
- return 0;
733
+ return 1;
741734 }
742735
743736 #define WM8958_HPF_SWITCH(xname, xval) {\
....@@ -757,7 +750,7 @@
757750 int reg;
758751
759752 /* Don't allow on the fly reconfiguration */
760
- reg = snd_soc_component_read32(component, WM8994_CLOCKING_1);
753
+ reg = snd_soc_component_read(component, WM8994_CLOCKING_1);
761754 if (reg < 0 || reg & WM8958_DSP2CLK_ENA)
762755 return -EBUSY;
763756
....@@ -831,7 +824,7 @@
831824
832825 wm8958_dsp_apply(component, eq, ucontrol->value.integer.value[0]);
833826
834
- return 0;
827
+ return 1;
835828 }
836829
837830 #define WM8958_ENH_EQ_SWITCH(xname, xval) {\