1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
|
/*
* Copyright (c) 2019, The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <dsp/q6audio-v2.h>
#include <dsp/q6afe-v2.h>
#include <linux/msm_audio_calibration.h>
#include <dsp/sp_params.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/device.h>
/* export or show spk params at /sys/class/spk_params/cal_data */
#define SPK_PARAMS "spk_params"
#define CLASS_NAME "cal_data"
#define BUF_SZ 20
#define Q22 (1<<22)
#define Q13 (1<<13)
#define Q7 (1<<7)
struct afe_spk_ctl {
struct class *p_class;
struct device *p_dev;
struct afe_sp_rx_tmax_xmax_logging_param xt_logging;
int32_t max_temperature_rd[SP_V2_NUM_MAX_SPKR];
};
struct afe_spk_ctl this_afe_spk;
static ssize_t sp_count_exceeded_temperature_l_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
ssize_t ret = 0;
ret = snprintf(buf, BUF_SZ, "%d\n",
this_afe_spk.xt_logging.count_exceeded_temperature[SP_V2_SPKR_1]);
this_afe_spk.xt_logging.count_exceeded_temperature[SP_V2_SPKR_1] = 0;
return ret;
}
static DEVICE_ATTR(count_exceeded_temperature, 0644,
sp_count_exceeded_temperature_l_show, NULL);
static ssize_t sp_count_exceeded_temperature_r_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
ssize_t ret = 0;
ret = snprintf(buf, BUF_SZ, "%d\n",
this_afe_spk.xt_logging.count_exceeded_temperature[SP_V2_SPKR_2]);
this_afe_spk.xt_logging.count_exceeded_temperature[SP_V2_SPKR_2] = 0;
return ret;
}
static DEVICE_ATTR(count_exceeded_temperature_r, 0644,
sp_count_exceeded_temperature_r_show, NULL);
static ssize_t sp_count_exceeded_excursion_l_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
ssize_t ret = 0;
ret = snprintf(buf, BUF_SZ, "%d\n",
this_afe_spk.xt_logging.count_exceeded_excursion[SP_V2_SPKR_1]);
this_afe_spk.xt_logging.count_exceeded_excursion[SP_V2_SPKR_1] = 0;
return ret;
}
static DEVICE_ATTR(count_exceeded_excursion, 0644,
sp_count_exceeded_excursion_l_show, NULL);
static ssize_t sp_count_exceeded_excursion_r_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
ssize_t ret = 0;
ret = snprintf(buf, BUF_SZ, "%d\n",
this_afe_spk.xt_logging.count_exceeded_excursion[SP_V2_SPKR_2]);
this_afe_spk.xt_logging.count_exceeded_excursion[SP_V2_SPKR_2] = 0;
return ret;
}
static DEVICE_ATTR(count_exceeded_excursion_r, 0644,
sp_count_exceeded_excursion_r_show, NULL);
static ssize_t sp_max_excursion_l_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
ssize_t ret = 0;
int32_t ex_val_frac;
int32_t ex_q27 = this_afe_spk.xt_logging.max_excursion[SP_V2_SPKR_1];
ex_val_frac = ex_q27/Q13;
ex_val_frac = (ex_val_frac * 10000)/(Q7 * Q7);
ex_val_frac /= 100;
ret = snprintf(buf, BUF_SZ, "%d.%02d\n", 0, ex_val_frac);
this_afe_spk.xt_logging.max_excursion[SP_V2_SPKR_1] = 0;
return ret;
}
static DEVICE_ATTR(max_excursion, 0644, sp_max_excursion_l_show, NULL);
static ssize_t sp_max_excursion_r_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
ssize_t ret = 0;
int32_t ex_val_frac;
int32_t ex_q27 = this_afe_spk.xt_logging.max_excursion[SP_V2_SPKR_2];
ex_val_frac = ex_q27/Q13;
ex_val_frac = (ex_val_frac * 10000)/(Q7 * Q7);
ex_val_frac /= 100;
ret = snprintf(buf, BUF_SZ, "%d.%02d\n", 0, ex_val_frac);
this_afe_spk.xt_logging.max_excursion[SP_V2_SPKR_2] = 0;
return ret;
}
static DEVICE_ATTR(max_excursion_r, 0644, sp_max_excursion_r_show, NULL);
static ssize_t sp_max_temperature_l_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
ssize_t ret = 0;
ret = snprintf(buf, BUF_SZ, "%d\n",
this_afe_spk.xt_logging.max_temperature[SP_V2_SPKR_1]/Q22);
this_afe_spk.xt_logging.max_temperature[SP_V2_SPKR_1] = 0;
return ret;
}
static DEVICE_ATTR(max_temperature, 0644, sp_max_temperature_l_show, NULL);
static ssize_t sp_max_temperature_r_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
ssize_t ret = 0;
ret = snprintf(buf, BUF_SZ, "%d\n",
this_afe_spk.xt_logging.max_temperature[SP_V2_SPKR_2]/Q22);
this_afe_spk.xt_logging.max_temperature[SP_V2_SPKR_2] = 0;
return ret;
}
static DEVICE_ATTR(max_temperature_r, 0644, sp_max_temperature_r_show, NULL);
static ssize_t sp_max_temperature_rd_l_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
return snprintf(buf, BUF_SZ, "%d\n",
this_afe_spk.max_temperature_rd[SP_V2_SPKR_1]/Q22);
}
static DEVICE_ATTR(max_temperature_rd, 0644,
sp_max_temperature_rd_l_show, NULL);
static ssize_t sp_max_temperature_rd_r_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
return snprintf(buf, BUF_SZ, "%d\n",
this_afe_spk.max_temperature_rd[SP_V2_SPKR_2]/Q22);
}
static DEVICE_ATTR(max_temperature_rd_r, 0644,
sp_max_temperature_rd_r_show, NULL);
static ssize_t q6afe_initial_cal_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
return snprintf(buf, BUF_SZ, "%d\n", afe_get_spk_initial_cal());
}
static ssize_t q6afe_initial_cal_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t size)
{
int initial_cal = 0;
if (!kstrtou32(buf, 0, &initial_cal)) {
initial_cal = initial_cal > 0 ? 1 : 0;
if (initial_cal == afe_get_spk_initial_cal())
dev_dbg(dev, "%s: same value already present\n",
__func__);
else
afe_set_spk_initial_cal(initial_cal);
}
return size;
}
static DEVICE_ATTR(initial_cal, 0644,
q6afe_initial_cal_show, q6afe_initial_cal_store);
static ssize_t q6afe_v_vali_flag_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
return snprintf(buf, BUF_SZ, "%d\n", afe_get_spk_v_vali_flag());
}
static ssize_t q6afe_v_vali_flag_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t size)
{
int v_vali_flag = 0;
if (!kstrtou32(buf, 0, &v_vali_flag)) {
v_vali_flag = v_vali_flag > 0 ? 1 : 0;
if (v_vali_flag == afe_get_spk_v_vali_flag())
dev_dbg(dev, "%s: same value already present\n",
__func__);
else
afe_set_spk_v_vali_flag(v_vali_flag);
}
return size;
}
static DEVICE_ATTR(v_vali_flag, 0644,
q6afe_v_vali_flag_show, q6afe_v_vali_flag_store);
static ssize_t q6afe_spk_r0_l_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
int r0[SP_V2_NUM_MAX_SPKRS];
afe_get_spk_r0(r0);
return snprintf(buf, BUF_SZ, "%d\n", r0[SP_V2_SPKR_1]);
}
static DEVICE_ATTR(spk_r0, 0644, q6afe_spk_r0_l_show, NULL);
static ssize_t q6afe_spk_t0_l_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
int t0[SP_V2_NUM_MAX_SPKRS];
afe_get_spk_t0(t0);
return snprintf(buf, BUF_SZ, "%d\n", t0[SP_V2_SPKR_1]);
}
static DEVICE_ATTR(spk_t0, 0644, q6afe_spk_t0_l_show, NULL);
static ssize_t q6afe_spk_r0_r_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
int r0[SP_V2_NUM_MAX_SPKRS];
afe_get_spk_r0(r0);
return snprintf(buf, BUF_SZ, "%d\n", r0[SP_V2_SPKR_2]);
}
static DEVICE_ATTR(spk_r0_r, 0644, q6afe_spk_r0_r_show, NULL);
static ssize_t q6afe_spk_t0_r_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
int t0[SP_V2_NUM_MAX_SPKRS];
afe_get_spk_t0(t0);
return snprintf(buf, BUF_SZ, "%d\n", t0[SP_V2_SPKR_2]);
}
static DEVICE_ATTR(spk_t0_r, 0644, q6afe_spk_t0_r_show, NULL);
static ssize_t q6afe_spk_v_vali_l_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
int v_vali_sts[SP_V2_NUM_MAX_SPKRS];
afe_get_spk_v_vali_sts(v_vali_sts);
return snprintf(buf, BUF_SZ, "%d\n", v_vali_sts[SP_V2_SPKR_1]);
}
static DEVICE_ATTR(spk_v_vali_status, 0644, q6afe_spk_v_vali_l_show, NULL);
static ssize_t q6afe_spk_v_vali_r_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
int v_vali_sts[SP_V2_NUM_MAX_SPKRS];
afe_get_spk_v_vali_sts(v_vali_sts);
return snprintf(buf, BUF_SZ, "%d\n", v_vali_sts[SP_V2_SPKR_2]);
}
static DEVICE_ATTR(spk_v_vali_r_status, 0644, q6afe_spk_v_vali_r_show, NULL);
static struct attribute *afe_spk_cal_attr[] = {
&dev_attr_max_excursion.attr,
&dev_attr_max_excursion_r.attr,
&dev_attr_max_temperature.attr,
&dev_attr_max_temperature_r.attr,
&dev_attr_count_exceeded_excursion.attr,
&dev_attr_count_exceeded_excursion_r.attr,
&dev_attr_count_exceeded_temperature.attr,
&dev_attr_count_exceeded_temperature_r.attr,
&dev_attr_max_temperature_rd.attr,
&dev_attr_max_temperature_rd_r.attr,
&dev_attr_initial_cal.attr,
&dev_attr_spk_r0.attr,
&dev_attr_spk_t0.attr,
&dev_attr_spk_r0_r.attr,
&dev_attr_spk_t0_r.attr,
&dev_attr_v_vali_flag.attr,
&dev_attr_spk_v_vali_status.attr,
&dev_attr_spk_v_vali_r_status.attr,
NULL,
};
static struct attribute_group afe_spk_cal_attr_grp = {
.attrs = afe_spk_cal_attr,
};
/**
* afe_get_sp_xt_logging_data -
* to get excursion logging data from DSP
*
* @port: AFE port ID
*
* Returns 0 on success or error on failure
*/
int afe_get_sp_xt_logging_data(u16 port_id)
{
int ret = 0;
struct afe_sp_rx_tmax_xmax_logging_param xt_logging_data;
ret = afe_get_sp_rx_tmax_xmax_logging_data(&xt_logging_data, port_id);
if (ret) {
pr_err("%s Excursion logging fail\n", __func__);
return ret;
}
/* storing max sp param value */
if (this_afe_spk.xt_logging.max_temperature[SP_V2_SPKR_1] <
xt_logging_data.max_temperature[SP_V2_SPKR_1])
this_afe_spk.xt_logging.max_temperature[SP_V2_SPKR_1] =
xt_logging_data.max_temperature[SP_V2_SPKR_1];
if (this_afe_spk.xt_logging.max_temperature[SP_V2_SPKR_2] <
xt_logging_data.max_temperature[SP_V2_SPKR_2])
this_afe_spk.xt_logging.max_temperature[SP_V2_SPKR_2] =
xt_logging_data.max_temperature[SP_V2_SPKR_2];
/* update temp for max_temperature_rd node */
if (this_afe_spk.max_temperature_rd[SP_V2_SPKR_1] <
xt_logging_data.max_temperature[SP_V2_SPKR_1])
this_afe_spk.max_temperature_rd[SP_V2_SPKR_1] =
xt_logging_data.max_temperature[SP_V2_SPKR_1];
if (this_afe_spk.max_temperature_rd[SP_V2_SPKR_2] <
xt_logging_data.max_temperature[SP_V2_SPKR_2])
this_afe_spk.max_temperature_rd[SP_V2_SPKR_2] =
xt_logging_data.max_temperature[SP_V2_SPKR_2];
if (this_afe_spk.xt_logging.max_excursion[SP_V2_SPKR_1] <
xt_logging_data.max_excursion[SP_V2_SPKR_1])
this_afe_spk.xt_logging.max_excursion[SP_V2_SPKR_1] =
xt_logging_data.max_excursion[SP_V2_SPKR_1];
if (this_afe_spk.xt_logging.max_excursion[SP_V2_SPKR_2] <
xt_logging_data.max_excursion[SP_V2_SPKR_2])
this_afe_spk.xt_logging.max_excursion[SP_V2_SPKR_2] =
xt_logging_data.max_excursion[SP_V2_SPKR_2];
if (this_afe_spk.xt_logging.count_exceeded_temperature[SP_V2_SPKR_1] <
xt_logging_data.count_exceeded_temperature[SP_V2_SPKR_1])
this_afe_spk.xt_logging.count_exceeded_temperature[SP_V2_SPKR_1]
+= xt_logging_data.count_exceeded_temperature[SP_V2_SPKR_1];
if (this_afe_spk.xt_logging.count_exceeded_temperature[SP_V2_SPKR_2] <
xt_logging_data.count_exceeded_temperature[SP_V2_SPKR_2])
this_afe_spk.xt_logging.count_exceeded_temperature[SP_V2_SPKR_2]
+= xt_logging_data.count_exceeded_temperature[SP_V2_SPKR_2];
if (this_afe_spk.xt_logging.count_exceeded_excursion[SP_V2_SPKR_1] <
xt_logging_data.count_exceeded_excursion[SP_V2_SPKR_1])
this_afe_spk.xt_logging.count_exceeded_excursion[SP_V2_SPKR_1]
+= xt_logging_data.count_exceeded_excursion[SP_V2_SPKR_1];
if (this_afe_spk.xt_logging.count_exceeded_excursion[SP_V2_SPKR_2] <
xt_logging_data.count_exceeded_excursion[SP_V2_SPKR_2])
this_afe_spk.xt_logging.count_exceeded_excursion[SP_V2_SPKR_2]
+= xt_logging_data.count_exceeded_excursion[SP_V2_SPKR_2];
return ret;
}
EXPORT_SYMBOL(afe_get_sp_xt_logging_data);
int __init spk_params_init(void)
{
/* initialize xt param value with 0 */
this_afe_spk.xt_logging.max_temperature[SP_V2_SPKR_1] = 0;
this_afe_spk.xt_logging.max_temperature[SP_V2_SPKR_2] = 0;
this_afe_spk.xt_logging.max_excursion[SP_V2_SPKR_1] = 0;
this_afe_spk.xt_logging.max_excursion[SP_V2_SPKR_2] = 0;
this_afe_spk.xt_logging.count_exceeded_temperature[SP_V2_SPKR_1] = 0;
this_afe_spk.xt_logging.count_exceeded_temperature[SP_V2_SPKR_2] = 0;
this_afe_spk.xt_logging.count_exceeded_excursion[SP_V2_SPKR_1] = 0;
this_afe_spk.xt_logging.count_exceeded_excursion[SP_V2_SPKR_2] = 0;
this_afe_spk.p_class = class_create(THIS_MODULE, SPK_PARAMS);
if (this_afe_spk.p_class) {
this_afe_spk.p_dev = device_create(this_afe_spk.p_class, NULL,
1, NULL, CLASS_NAME);
if (!IS_ERR(this_afe_spk.p_dev)) {
if (sysfs_create_group(&this_afe_spk.p_dev->kobj,
&afe_spk_cal_attr_grp))
pr_err("%s: Failed to create sysfs group\n",
__func__);
}
}
return 0;
}
void spk_params_exit(void)
{
pr_debug("%s\n", __func__);
}
|