@@ -1030,8 +1030,8 @@ static int wm_coeff_write_acked_control(struct wm_coeff_ctl *ctl,
1030
1030
return - ETIMEDOUT ;
1031
1031
}
1032
1032
1033
- static int wm_coeff_write_control (struct wm_coeff_ctl * ctl ,
1034
- const void * buf , size_t len )
1033
+ static int wm_coeff_write_ctrl_raw (struct wm_coeff_ctl * ctl ,
1034
+ const void * buf , size_t len )
1035
1035
{
1036
1036
struct wm_adsp * dsp = ctl -> dsp ;
1037
1037
void * scratch ;
@@ -1061,6 +1061,23 @@ static int wm_coeff_write_control(struct wm_coeff_ctl *ctl,
1061
1061
return 0 ;
1062
1062
}
1063
1063
1064
+ static int wm_coeff_write_ctrl (struct wm_coeff_ctl * ctl ,
1065
+ const void * buf , size_t len )
1066
+ {
1067
+ int ret = 0 ;
1068
+
1069
+ if (ctl -> flags & WMFW_CTL_FLAG_VOLATILE )
1070
+ ret = - EPERM ;
1071
+ else if (buf != ctl -> cache )
1072
+ memcpy (ctl -> cache , buf , len );
1073
+
1074
+ ctl -> set = 1 ;
1075
+ if (ctl -> enabled && ctl -> dsp -> running )
1076
+ ret = wm_coeff_write_ctrl_raw (ctl , buf , len );
1077
+
1078
+ return ret ;
1079
+ }
1080
+
1064
1081
static int wm_coeff_put (struct snd_kcontrol * kctl ,
1065
1082
struct snd_ctl_elem_value * ucontrol )
1066
1083
{
@@ -1071,16 +1088,7 @@ static int wm_coeff_put(struct snd_kcontrol *kctl,
1071
1088
int ret = 0 ;
1072
1089
1073
1090
mutex_lock (& ctl -> dsp -> pwr_lock );
1074
-
1075
- if (ctl -> flags & WMFW_CTL_FLAG_VOLATILE )
1076
- ret = - EPERM ;
1077
- else
1078
- memcpy (ctl -> cache , p , ctl -> len );
1079
-
1080
- ctl -> set = 1 ;
1081
- if (ctl -> enabled && ctl -> dsp -> running )
1082
- ret = wm_coeff_write_control (ctl , p , ctl -> len );
1083
-
1091
+ ret = wm_coeff_write_ctrl (ctl , p , ctl -> len );
1084
1092
mutex_unlock (& ctl -> dsp -> pwr_lock );
1085
1093
1086
1094
return ret ;
@@ -1096,15 +1104,10 @@ static int wm_coeff_tlv_put(struct snd_kcontrol *kctl,
1096
1104
1097
1105
mutex_lock (& ctl -> dsp -> pwr_lock );
1098
1106
1099
- if (copy_from_user (ctl -> cache , bytes , size )) {
1107
+ if (copy_from_user (ctl -> cache , bytes , size ))
1100
1108
ret = - EFAULT ;
1101
- } else {
1102
- ctl -> set = 1 ;
1103
- if (ctl -> enabled && ctl -> dsp -> running )
1104
- ret = wm_coeff_write_control (ctl , ctl -> cache , size );
1105
- else if (ctl -> flags & WMFW_CTL_FLAG_VOLATILE )
1106
- ret = - EPERM ;
1107
- }
1109
+ else
1110
+ ret = wm_coeff_write_ctrl (ctl , ctl -> cache , size );
1108
1111
1109
1112
mutex_unlock (& ctl -> dsp -> pwr_lock );
1110
1113
@@ -1135,8 +1138,8 @@ static int wm_coeff_put_acked(struct snd_kcontrol *kctl,
1135
1138
return ret ;
1136
1139
}
1137
1140
1138
- static int wm_coeff_read_control (struct wm_coeff_ctl * ctl ,
1139
- void * buf , size_t len )
1141
+ static int wm_coeff_read_ctrl_raw (struct wm_coeff_ctl * ctl ,
1142
+ void * buf , size_t len )
1140
1143
{
1141
1144
struct wm_adsp * dsp = ctl -> dsp ;
1142
1145
void * scratch ;
@@ -1166,29 +1169,37 @@ static int wm_coeff_read_control(struct wm_coeff_ctl *ctl,
1166
1169
return 0 ;
1167
1170
}
1168
1171
1169
- static int wm_coeff_get (struct snd_kcontrol * kctl ,
1170
- struct snd_ctl_elem_value * ucontrol )
1172
+ static int wm_coeff_read_ctrl (struct wm_coeff_ctl * ctl , void * buf , size_t len )
1171
1173
{
1172
- struct soc_bytes_ext * bytes_ext =
1173
- (struct soc_bytes_ext * )kctl -> private_value ;
1174
- struct wm_coeff_ctl * ctl = bytes_ext_to_ctl (bytes_ext );
1175
- char * p = ucontrol -> value .bytes .data ;
1176
1174
int ret = 0 ;
1177
1175
1178
- mutex_lock (& ctl -> dsp -> pwr_lock );
1179
-
1180
1176
if (ctl -> flags & WMFW_CTL_FLAG_VOLATILE ) {
1181
1177
if (ctl -> enabled && ctl -> dsp -> running )
1182
- ret = wm_coeff_read_control (ctl , p , ctl -> len );
1178
+ return wm_coeff_read_ctrl_raw (ctl , buf , len );
1183
1179
else
1184
- ret = - EPERM ;
1180
+ return - EPERM ;
1185
1181
} else {
1186
1182
if (!ctl -> flags && ctl -> enabled && ctl -> dsp -> running )
1187
- ret = wm_coeff_read_control (ctl , ctl -> cache , ctl -> len );
1183
+ ret = wm_coeff_read_ctrl_raw (ctl , ctl -> cache , ctl -> len );
1188
1184
1189
- memcpy (p , ctl -> cache , ctl -> len );
1185
+ if (buf != ctl -> cache )
1186
+ memcpy (buf , ctl -> cache , len );
1190
1187
}
1191
1188
1189
+ return ret ;
1190
+ }
1191
+
1192
+ static int wm_coeff_get (struct snd_kcontrol * kctl ,
1193
+ struct snd_ctl_elem_value * ucontrol )
1194
+ {
1195
+ struct soc_bytes_ext * bytes_ext =
1196
+ (struct soc_bytes_ext * )kctl -> private_value ;
1197
+ struct wm_coeff_ctl * ctl = bytes_ext_to_ctl (bytes_ext );
1198
+ char * p = ucontrol -> value .bytes .data ;
1199
+ int ret ;
1200
+
1201
+ mutex_lock (& ctl -> dsp -> pwr_lock );
1202
+ ret = wm_coeff_read_ctrl (ctl , p , ctl -> len );
1192
1203
mutex_unlock (& ctl -> dsp -> pwr_lock );
1193
1204
1194
1205
return ret ;
@@ -1204,15 +1215,7 @@ static int wm_coeff_tlv_get(struct snd_kcontrol *kctl,
1204
1215
1205
1216
mutex_lock (& ctl -> dsp -> pwr_lock );
1206
1217
1207
- if (ctl -> flags & WMFW_CTL_FLAG_VOLATILE ) {
1208
- if (ctl -> enabled && ctl -> dsp -> running )
1209
- ret = wm_coeff_read_control (ctl , ctl -> cache , size );
1210
- else
1211
- ret = - EPERM ;
1212
- } else {
1213
- if (!ctl -> flags && ctl -> enabled && ctl -> dsp -> running )
1214
- ret = wm_coeff_read_control (ctl , ctl -> cache , size );
1215
- }
1218
+ ret = wm_coeff_read_ctrl_raw (ctl , ctl -> cache , size );
1216
1219
1217
1220
if (!ret && copy_to_user (bytes , ctl -> cache , size ))
1218
1221
ret = - EFAULT ;
@@ -1340,7 +1343,7 @@ static int wm_coeff_init_control_caches(struct wm_adsp *dsp)
1340
1343
* created so we don't need to do anything.
1341
1344
*/
1342
1345
if (!ctl -> flags || (ctl -> flags & WMFW_CTL_FLAG_READABLE )) {
1343
- ret = wm_coeff_read_control (ctl , ctl -> cache , ctl -> len );
1346
+ ret = wm_coeff_read_ctrl_raw (ctl , ctl -> cache , ctl -> len );
1344
1347
if (ret < 0 )
1345
1348
return ret ;
1346
1349
}
@@ -1358,7 +1361,8 @@ static int wm_coeff_sync_controls(struct wm_adsp *dsp)
1358
1361
if (!ctl -> enabled )
1359
1362
continue ;
1360
1363
if (ctl -> set && !(ctl -> flags & WMFW_CTL_FLAG_VOLATILE )) {
1361
- ret = wm_coeff_write_control (ctl , ctl -> cache , ctl -> len );
1364
+ ret = wm_coeff_write_ctrl_raw (ctl , ctl -> cache ,
1365
+ ctl -> len );
1362
1366
if (ret < 0 )
1363
1367
return ret ;
1364
1368
}
@@ -2048,7 +2052,7 @@ int wm_adsp_write_ctl(struct wm_adsp *dsp, const char *name, int type,
2048
2052
if (len > ctl -> len )
2049
2053
return - EINVAL ;
2050
2054
2051
- ret = wm_coeff_write_control (ctl , buf , len );
2055
+ ret = wm_coeff_write_ctrl (ctl , buf , len );
2052
2056
2053
2057
kcontrol = snd_soc_card_get_kcontrol (dsp -> component -> card , ctl -> name );
2054
2058
snd_ctl_notify (dsp -> component -> card -> snd_card ,
@@ -2070,7 +2074,7 @@ int wm_adsp_read_ctl(struct wm_adsp *dsp, const char *name, int type,
2070
2074
if (len > ctl -> len )
2071
2075
return - EINVAL ;
2072
2076
2073
- return wm_coeff_read_control (ctl , buf , len );
2077
+ return wm_coeff_read_ctrl (ctl , buf , len );
2074
2078
}
2075
2079
EXPORT_SYMBOL_GPL (wm_adsp_read_ctl );
2076
2080
0 commit comments