Skip to content

Commit fd16593

Browse files
wangweidongabroonie
authored andcommitted
ASoC: codecs: Modify awinic amplifier dsp read and write functions
Modify the dsp read and write functions of the chip and normalize the dsp read and write functions of all awinic amplifier Signed-off-by: Weidong Wang <wangweidong.a@awinic.com> Link: https://patch.msgid.link/20251128130323.628091-1-wangweidong.a@awinic.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent b025f01 commit fd16593

7 files changed

Lines changed: 58 additions & 353 deletions

File tree

sound/soc/codecs/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ snd-soc-audio-iio-aux-y := audio-iio-aux.o
5050
snd-soc-aw8738-y := aw8738.o
5151
snd-soc-aw87390-y := aw87390.o
5252
snd-soc-aw88081-y := aw88081.o
53-
snd-soc-aw88395-lib-y := aw88395/aw88395_lib.o
54-
snd-soc-aw88395-y := aw88395/aw88395.o \
53+
snd-soc-aw88395-lib-y := aw88395/aw88395_lib.o \
5554
aw88395/aw88395_device.o
55+
snd-soc-aw88395-y := aw88395/aw88395.o
5656
snd-soc-aw88166-y := aw88166.o
5757
snd-soc-aw88261-y := aw88261.o
5858
snd-soc-aw88399-y := aw88399.o

sound/soc/codecs/aw88166.c

Lines changed: 9 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -41,109 +41,6 @@ static const struct regmap_config aw88166_remap_config = {
4141
.val_format_endian = REGMAP_ENDIAN_BIG,
4242
};
4343

44-
static int aw_dev_dsp_write_16bit(struct aw_device *aw_dev,
45-
unsigned short dsp_addr, unsigned int dsp_data)
46-
{
47-
int ret;
48-
49-
ret = regmap_write(aw_dev->regmap, AW88166_DSPMADD_REG, dsp_addr);
50-
if (ret) {
51-
dev_err(aw_dev->dev, "%s write addr error, ret=%d", __func__, ret);
52-
return ret;
53-
}
54-
55-
ret = regmap_write(aw_dev->regmap, AW88166_DSPMDAT_REG, (u16)dsp_data);
56-
if (ret) {
57-
dev_err(aw_dev->dev, "%s write data error, ret=%d", __func__, ret);
58-
return ret;
59-
}
60-
61-
return 0;
62-
}
63-
64-
static int aw_dev_dsp_read_16bit(struct aw_device *aw_dev,
65-
unsigned short dsp_addr, unsigned int *dsp_data)
66-
{
67-
unsigned int temp_data;
68-
int ret;
69-
70-
ret = regmap_write(aw_dev->regmap, AW88166_DSPMADD_REG, dsp_addr);
71-
if (ret) {
72-
dev_err(aw_dev->dev, "%s write error, ret=%d", __func__, ret);
73-
return ret;
74-
}
75-
76-
ret = regmap_read(aw_dev->regmap, AW88166_DSPMDAT_REG, &temp_data);
77-
if (ret) {
78-
dev_err(aw_dev->dev, "%s read error, ret=%d", __func__, ret);
79-
return ret;
80-
}
81-
*dsp_data = temp_data;
82-
83-
return 0;
84-
}
85-
86-
static int aw_dev_dsp_read_32bit(struct aw_device *aw_dev,
87-
unsigned short dsp_addr, unsigned int *dsp_data)
88-
{
89-
unsigned int temp_data;
90-
int ret;
91-
92-
ret = regmap_write(aw_dev->regmap, AW88166_DSPMADD_REG, dsp_addr);
93-
if (ret) {
94-
dev_err(aw_dev->dev, "%s write error, ret=%d", __func__, ret);
95-
return ret;
96-
}
97-
98-
ret = regmap_read(aw_dev->regmap, AW88166_DSPMDAT_REG, &temp_data);
99-
if (ret) {
100-
dev_err(aw_dev->dev, "%s read error, ret=%d", __func__, ret);
101-
return ret;
102-
}
103-
*dsp_data = temp_data;
104-
105-
ret = regmap_read(aw_dev->regmap, AW88166_DSPMDAT_REG, &temp_data);
106-
if (ret) {
107-
dev_err(aw_dev->dev, "%s read error, ret=%d", __func__, ret);
108-
return ret;
109-
}
110-
*dsp_data |= (temp_data << 16);
111-
112-
return 0;
113-
}
114-
115-
static int aw_dev_dsp_read(struct aw_device *aw_dev,
116-
unsigned short dsp_addr, unsigned int *dsp_data, unsigned char data_type)
117-
{
118-
u32 reg_value;
119-
int ret;
120-
121-
mutex_lock(&aw_dev->dsp_lock);
122-
switch (data_type) {
123-
case AW88166_DSP_16_DATA:
124-
ret = aw_dev_dsp_read_16bit(aw_dev, dsp_addr, dsp_data);
125-
if (ret)
126-
dev_err(aw_dev->dev, "read dsp_addr[0x%x] 16-bit failed", (u32)dsp_addr);
127-
break;
128-
case AW88166_DSP_32_DATA:
129-
ret = aw_dev_dsp_read_32bit(aw_dev, dsp_addr, dsp_data);
130-
if (ret)
131-
dev_err(aw_dev->dev, "read dsp_addr[0x%x] 32-bit failed", (u32)dsp_addr);
132-
break;
133-
default:
134-
dev_err(aw_dev->dev, "data type[%d] unsupported", data_type);
135-
ret = -EINVAL;
136-
break;
137-
}
138-
139-
/* clear dsp chip select state */
140-
if (regmap_read(aw_dev->regmap, AW88166_ID_REG, &reg_value))
141-
dev_err(aw_dev->dev, "%s fail to clear chip state. ret=%d\n", __func__, ret);
142-
mutex_unlock(&aw_dev->dsp_lock);
143-
144-
return ret;
145-
}
146-
14744
static void aw_dev_pwd(struct aw_device *aw_dev, bool pwd)
14845
{
14946
int ret;
@@ -904,25 +801,19 @@ static int aw_dev_dsp_update_container(struct aw_device *aw_dev,
904801
u32 tmp_len;
905802
int i, ret;
906803

907-
mutex_lock(&aw_dev->dsp_lock);
908804
ret = regmap_write(aw_dev->regmap, AW88166_DSPMADD_REG, base);
909805
if (ret)
910-
goto error_operation;
806+
return ret;
911807

912808
for (i = 0; i < len; i += AW88166_MAX_RAM_WRITE_BYTE_SIZE) {
913809
tmp_len = min(len - i, AW88166_MAX_RAM_WRITE_BYTE_SIZE);
914810
ret = regmap_raw_write(aw_dev->regmap, AW88166_DSPMDAT_REG,
915811
&data[i], tmp_len);
916812
if (ret)
917-
goto error_operation;
813+
return ret;
918814
}
919-
mutex_unlock(&aw_dev->dsp_lock);
920815

921816
return 0;
922-
923-
error_operation:
924-
mutex_unlock(&aw_dev->dsp_lock);
925-
return ret;
926817
}
927818

928819
static int aw_dev_get_ra(struct aw_cali_desc *cali_desc)
@@ -933,7 +824,7 @@ static int aw_dev_get_ra(struct aw_cali_desc *cali_desc)
933824
int ret;
934825

935826
ret = aw_dev_dsp_read(aw_dev, AW88166_DSP_REG_CFG_ADPZ_RA,
936-
&dsp_ra, AW88166_DSP_32_DATA);
827+
&dsp_ra, AW_DSP_32_DATA);
937828
if (ret) {
938829
dev_err(aw_dev->dev, "read ra error\n");
939830
return ret;
@@ -990,29 +881,25 @@ static int aw_dev_check_sram(struct aw_device *aw_dev)
990881
{
991882
unsigned int reg_val;
992883

993-
mutex_lock(&aw_dev->dsp_lock);
994884
/* read dsp_rom_check_reg */
995-
aw_dev_dsp_read_16bit(aw_dev, AW88166_DSP_ROM_CHECK_ADDR, &reg_val);
885+
aw_dev_dsp_read(aw_dev, AW88166_DSP_ROM_CHECK_ADDR, &reg_val, AW_DSP_16_DATA);
996886
if (reg_val != AW88166_DSP_ROM_CHECK_DATA) {
997887
dev_err(aw_dev->dev, "check dsp rom failed, read[0x%x] != check[0x%x]\n",
998888
reg_val, AW88166_DSP_ROM_CHECK_DATA);
999-
goto error;
889+
return -EPERM;
1000890
}
1001891

1002892
/* check dsp_cfg_base_addr */
1003-
aw_dev_dsp_write_16bit(aw_dev, AW88166_DSP_CFG_ADDR, AW88166_DSP_ODD_NUM_BIT_TEST);
1004-
aw_dev_dsp_read_16bit(aw_dev, AW88166_DSP_CFG_ADDR, &reg_val);
893+
aw_dev_dsp_write(aw_dev, AW88166_DSP_CFG_ADDR,
894+
AW88166_DSP_ODD_NUM_BIT_TEST, AW_DSP_16_DATA);
895+
aw_dev_dsp_read(aw_dev, AW88166_DSP_CFG_ADDR, &reg_val, AW_DSP_16_DATA);
1005896
if (reg_val != AW88166_DSP_ODD_NUM_BIT_TEST) {
1006897
dev_err(aw_dev->dev, "check dsp cfg failed, read[0x%x] != write[0x%x]\n",
1007898
reg_val, AW88166_DSP_ODD_NUM_BIT_TEST);
1008-
goto error;
899+
return -EPERM;
1009900
}
1010-
mutex_unlock(&aw_dev->dsp_lock);
1011901

1012902
return 0;
1013-
error:
1014-
mutex_unlock(&aw_dev->dsp_lock);
1015-
return -EPERM;
1016903
}
1017904

1018905
static void aw_dev_select_memclk(struct aw_device *aw_dev, unsigned char flag)

sound/soc/codecs/aw88166.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -516,11 +516,6 @@ enum AW88166_DEV_DSP_CFG {
516516
AW88166_DEV_DSP_BYPASS = 1,
517517
};
518518

519-
enum {
520-
AW88166_DSP_16_DATA = 0,
521-
AW88166_DSP_32_DATA = 1,
522-
};
523-
524519
enum {
525520
AW88166_SYNC_START = 0,
526521
AW88166_ASYNC_START,

sound/soc/codecs/aw88395/aw88395_device.c

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,21 @@ static int aw_dev_dsp_write_32bit(struct aw_device *aw_dev,
6464
return 0;
6565
}
6666

67-
static int aw_dev_dsp_write(struct aw_device *aw_dev,
67+
int aw_dev_dsp_write(struct aw_device *aw_dev,
6868
unsigned short dsp_addr, unsigned int dsp_data, unsigned char data_type)
6969
{
7070
u32 reg_value;
7171
int ret;
7272

7373
mutex_lock(&aw_dev->dsp_lock);
7474
switch (data_type) {
75-
case AW88395_DSP_16_DATA:
75+
case AW_DSP_16_DATA:
7676
ret = aw_dev_dsp_write_16bit(aw_dev, dsp_addr, dsp_data);
7777
if (ret)
7878
dev_err(aw_dev->dev, "write dsp_addr[0x%x] 16-bit dsp_data[0x%x] failed",
7979
(u32)dsp_addr, dsp_data);
8080
break;
81-
case AW88395_DSP_32_DATA:
81+
case AW_DSP_32_DATA:
8282
ret = aw_dev_dsp_write_32bit(aw_dev, dsp_addr, dsp_data);
8383
if (ret)
8484
dev_err(aw_dev->dev, "write dsp_addr[0x%x] 32-bit dsp_data[0x%x] failed",
@@ -97,6 +97,7 @@ static int aw_dev_dsp_write(struct aw_device *aw_dev,
9797

9898
return ret;
9999
}
100+
EXPORT_SYMBOL_GPL(aw_dev_dsp_write);
100101

101102
static int aw_dev_dsp_read_16bit(struct aw_device *aw_dev,
102103
unsigned short dsp_addr, unsigned int *dsp_data)
@@ -149,21 +150,21 @@ static int aw_dev_dsp_read_32bit(struct aw_device *aw_dev,
149150
return 0;
150151
}
151152

152-
static int aw_dev_dsp_read(struct aw_device *aw_dev,
153+
int aw_dev_dsp_read(struct aw_device *aw_dev,
153154
unsigned short dsp_addr, unsigned int *dsp_data, unsigned char data_type)
154155
{
155156
u32 reg_value;
156157
int ret;
157158

158159
mutex_lock(&aw_dev->dsp_lock);
159160
switch (data_type) {
160-
case AW88395_DSP_16_DATA:
161+
case AW_DSP_16_DATA:
161162
ret = aw_dev_dsp_read_16bit(aw_dev, dsp_addr, dsp_data);
162163
if (ret)
163164
dev_err(aw_dev->dev, "read dsp_addr[0x%x] 16-bit dsp_data[0x%x] failed",
164165
(u32)dsp_addr, *dsp_data);
165166
break;
166-
case AW88395_DSP_32_DATA:
167+
case AW_DSP_32_DATA:
167168
ret = aw_dev_dsp_read_32bit(aw_dev, dsp_addr, dsp_data);
168169
if (ret)
169170
dev_err(aw_dev->dev, "read dsp_addr[0x%x] 32r-bit dsp_data[0x%x] failed",
@@ -182,7 +183,7 @@ static int aw_dev_dsp_read(struct aw_device *aw_dev,
182183

183184
return ret;
184185
}
185-
186+
EXPORT_SYMBOL_GPL(aw_dev_dsp_read);
186187

187188
static int aw_dev_read_chipid(struct aw_device *aw_dev, u16 *chip_id)
188189
{
@@ -231,7 +232,7 @@ static int aw_dev_dsp_fw_check(struct aw_device *aw_dev)
231232
dsp_fw_desc = &set_prof_desc->sec_desc[AW88395_DATA_TYPE_DSP_FW];
232233

233234
for (i = 0; i < AW88395_FW_CHECK_PART; i++) {
234-
ret = aw_dev_dsp_read(aw_dev, addr, &dsp_val, AW88395_DSP_16_DATA);
235+
ret = aw_dev_dsp_read(aw_dev, addr, &dsp_val, AW_DSP_16_DATA);
235236
if (ret) {
236237
dev_err(aw_dev->dev, "dsp read failed");
237238
return ret;
@@ -351,11 +352,11 @@ static int aw_dev_modify_dsp_cfg(struct aw_device *aw_dev,
351352
return -EINVAL;
352353
}
353354
switch (data_type) {
354-
case AW88395_DSP_16_DATA:
355+
case AW_DSP_16_DATA:
355356
data1 = cpu_to_le16((u16)dsp_data);
356357
memcpy(crc_dsp_cfg->data + addr_offset, (u8 *)&data1, 2);
357358
break;
358-
case AW88395_DSP_32_DATA:
359+
case AW_DSP_32_DATA:
359360
data2 = cpu_to_le32(dsp_data);
360361
memcpy(crc_dsp_cfg->data + addr_offset, (u8 *)&data2, 4);
361362
break;
@@ -377,14 +378,14 @@ static int aw_dev_dsp_set_cali_re(struct aw_device *aw_dev)
377378

378379
/* set cali re to device */
379380
ret = aw_dev_dsp_write(aw_dev,
380-
AW88395_DSP_REG_CFG_ADPZ_RE, cali_re, AW88395_DSP_32_DATA);
381+
AW88395_DSP_REG_CFG_ADPZ_RE, cali_re, AW_DSP_32_DATA);
381382
if (ret) {
382383
dev_err(aw_dev->dev, "set cali re error");
383384
return ret;
384385
}
385386

386387
ret = aw_dev_modify_dsp_cfg(aw_dev, AW88395_DSP_REG_CFG_ADPZ_RE,
387-
cali_re, AW88395_DSP_32_DATA);
388+
cali_re, AW_DSP_32_DATA);
388389
if (ret)
389390
dev_err(aw_dev->dev, "modify dsp cfg failed");
390391

@@ -428,7 +429,7 @@ static int aw_dev_dsp_set_crc32(struct aw_device *aw_dev)
428429
crc_value = crc32c(0xFFFFFFFF, crc_dsp_cfg->data, crc_data_len) ^ 0xFFFFFFFF;
429430

430431
return aw_dev_dsp_write(aw_dev, AW88395_DSP_REG_CRC_ADDR, crc_value,
431-
AW88395_DSP_32_DATA);
432+
AW_DSP_32_DATA);
432433
}
433434

434435
static void aw_dev_dsp_check_crc_enable(struct aw_device *aw_dev, bool flag)
@@ -663,7 +664,7 @@ static int aw_dev_set_vcalb(struct aw_device *aw_dev)
663664
int vcalb, vcalk;
664665
int ret;
665666

666-
ret = aw_dev_dsp_read(aw_dev, AW88395_DSP_REG_VCALB, &vcalb_adj, AW88395_DSP_16_DATA);
667+
ret = aw_dev_dsp_read(aw_dev, AW88395_DSP_REG_VCALB, &vcalb_adj, AW_DSP_16_DATA);
667668
if (ret) {
668669
dev_err(aw_dev->dev, "read vcalb_adj failed");
669670
return ret;
@@ -720,14 +721,14 @@ static int aw_dev_set_vcalb(struct aw_device *aw_dev)
720721
dev_dbg(aw_dev->dev, "vcalb=%d, reg_val=0x%x, vcalb_adj =0x%x",
721722
vcalb, reg_val, vcalb_adj);
722723

723-
ret = aw_dev_dsp_write(aw_dev, AW88395_DSP_REG_VCALB, reg_val, AW88395_DSP_16_DATA);
724+
ret = aw_dev_dsp_write(aw_dev, AW88395_DSP_REG_VCALB, reg_val, AW_DSP_16_DATA);
724725
if (ret) {
725726
dev_err(aw_dev->dev, "write vcalb failed");
726727
return ret;
727728
}
728729

729730
ret = aw_dev_modify_dsp_cfg(aw_dev, AW88395_DSP_REG_VCALB,
730-
(u32)reg_val, AW88395_DSP_16_DATA);
731+
(u32)reg_val, AW_DSP_16_DATA);
731732
if (ret)
732733
dev_err(aw_dev->dev, "modify dsp cfg failed");
733734

@@ -741,7 +742,7 @@ static int aw_dev_get_cali_f0_delay(struct aw_device *aw_dev)
741742
int ret;
742743

743744
ret = aw_dev_dsp_read(aw_dev,
744-
AW88395_DSP_CALI_F0_DELAY, &cali_delay, AW88395_DSP_16_DATA);
745+
AW88395_DSP_CALI_F0_DELAY, &cali_delay, AW_DSP_16_DATA);
745746
if (ret)
746747
dev_err(aw_dev->dev, "read cali delay failed, ret=%d", ret);
747748
else
@@ -991,7 +992,7 @@ static int aw_dev_get_dsp_status(struct aw_device *aw_dev)
991992

992993
static int aw_dev_get_vmax(struct aw_device *aw_dev, unsigned int *vmax)
993994
{
994-
return aw_dev_dsp_read(aw_dev, AW88395_DSP_REG_VMAX, vmax, AW88395_DSP_16_DATA);
995+
return aw_dev_dsp_read(aw_dev, AW88395_DSP_REG_VMAX, vmax, AW_DSP_16_DATA);
995996
}
996997

997998
static int aw_dev_update_reg_container(struct aw_device *aw_dev,
@@ -1089,7 +1090,7 @@ static int aw_dev_get_ra(struct aw_cali_desc *cali_desc)
10891090
int ret;
10901091

10911092
ret = aw_dev_dsp_read(aw_dev, AW88395_DSP_REG_CFG_ADPZ_RA,
1092-
&dsp_ra, AW88395_DSP_32_DATA);
1093+
&dsp_ra, AW_DSP_32_DATA);
10931094
if (ret) {
10941095
dev_err(aw_dev->dev, "read ra error");
10951096
return ret;

sound/soc/codecs/aw88395/aw88395_device.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ enum AW88395_DEV_DSP_CFG {
8989
};
9090

9191
enum {
92-
AW88395_DSP_16_DATA = 0,
93-
AW88395_DSP_32_DATA = 1,
92+
AW_DSP_16_DATA = 0,
93+
AW_DSP_32_DATA = 1,
9494
};
9595

9696
enum {
@@ -210,5 +210,9 @@ int aw88395_dev_get_profile_count(struct aw_device *aw_dev);
210210
int aw88395_dev_load_acf_check(struct aw_device *aw_dev, struct aw_container *aw_cfg);
211211
int aw88395_dev_cfg_load(struct aw_device *aw_dev, struct aw_container *aw_cfg);
212212
void aw88395_dev_mute(struct aw_device *aw_dev, bool is_mute);
213+
int aw_dev_dsp_write(struct aw_device *aw_dev,
214+
unsigned short dsp_addr, unsigned int dsp_data, unsigned char data_type);
215+
int aw_dev_dsp_read(struct aw_device *aw_dev,
216+
unsigned short dsp_addr, unsigned int *dsp_data, unsigned char data_type);
213217

214218
#endif

0 commit comments

Comments
 (0)