Skip to content

Commit ec0ec72

Browse files
Jaska Uimonencarlescufi
authored andcommitted
drivers: dai: intel: dmic: misc fixes and changes
Fix misc issues and warnings found with sof native drivers compilation. Signed-off-by: Jaska Uimonen <[email protected]>
1 parent 88941a1 commit ec0ec72

File tree

3 files changed

+97
-86
lines changed

3 files changed

+97
-86
lines changed

drivers/dai/intel/dmic/dmic.c

Lines changed: 85 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,82 @@ struct dai_dmic_global_shared dai_dmic_global;
3131

3232
int dai_dmic_set_config_nhlt(struct dai_intel_dmic *dmic, const void *spec_config);
3333

34+
/* Exponent function for small values of x. This function calculates
35+
* fairly accurately exponent for x in range -2.0 .. +2.0. The iteration
36+
* uses first 11 terms of Taylor series approximation for exponent
37+
* function. With the current scaling the numerator just remains under
38+
* 64 bits with the 11 terms.
39+
*
40+
* See https://en.wikipedia.org/wiki/Exponential_function#Computation
41+
*
42+
* The input is Q3.29
43+
* The output is Q9.23
44+
*/
45+
static int32_t exp_small_fixed(int32_t x)
46+
{
47+
int64_t p;
48+
int64_t num = Q_SHIFT_RND(x, 29, 23);
49+
int32_t y = (int32_t)num;
50+
int32_t den = 1;
51+
int32_t inc;
52+
int k;
53+
54+
/* Numerator is x^k, denominator is k! */
55+
for (k = 2; k < 12; k++) {
56+
p = num * x; /* Q9.23 x Q3.29 -> Q12.52 */
57+
num = Q_SHIFT_RND(p, 52, 23);
58+
den = den * k;
59+
inc = (int32_t)(num / den);
60+
y += inc;
61+
}
62+
63+
return y + ONE_Q23;
64+
}
65+
66+
static int32_t exp_fixed(int32_t x)
67+
{
68+
int32_t xs;
69+
int32_t y;
70+
int32_t z;
71+
int i;
72+
int n = 0;
73+
74+
if (x < Q_CONVERT_FLOAT(-11.5, 27))
75+
return 0;
76+
77+
if (x > Q_CONVERT_FLOAT(7.6245, 27))
78+
return INT32_MAX;
79+
80+
/* x is Q5.27 */
81+
xs = x;
82+
while (xs >= TWO_Q27 || xs <= MINUS_TWO_Q27) {
83+
xs >>= 1;
84+
n++;
85+
}
86+
87+
/* exp_small_fixed() input is Q3.29, while x1 is Q5.27
88+
* exp_small_fixed() output is Q9.23, while z is Q12.20
89+
*/
90+
z = Q_SHIFT_RND(exp_small_fixed(Q_SHIFT_LEFT(xs, 27, 29)), 23, 20);
91+
y = ONE_Q20;
92+
for (i = 0; i < (1 << n); i++)
93+
y = (int32_t)Q_MULTSR_32X32((int64_t)y, z, 20, 20, 20);
94+
95+
return y;
96+
}
97+
98+
static int32_t db2lin_fixed(int32_t db)
99+
{
100+
int32_t arg;
101+
102+
if (db < Q_CONVERT_FLOAT(-100.0, 24))
103+
return 0;
104+
105+
/* Q8.24 x Q5.27, result needs to be Q5.27 */
106+
arg = (int32_t)Q_MULTSR_32X32((int64_t)db, LOG10_DIV20_Q27, 24, 27, 27);
107+
return exp_fixed(arg);
108+
}
109+
34110
static void dai_dmic_update_bits(const struct dai_intel_dmic *dmic,
35111
uint32_t reg, uint32_t mask, uint32_t val)
36112
{
@@ -157,7 +233,7 @@ static void dai_dmic_irq_handler(const void *data)
157233
/* Trace OUTSTAT0 register */
158234
val0 = dai_dmic_read(dmic, OUTSTAT0);
159235
val1 = dai_dmic_read(dmic, OUTSTAT1);
160-
LOG_INF("dmic_irq_handler(), OUTSTAT0 = 0x%x, OUTSTAT1 = 0x%x", val0, val1);
236+
LOG_DBG("dmic_irq_handler(), OUTSTAT0 = 0x%x, OUTSTAT1 = 0x%x", val0, val1);
161237

162238
if (val0 & OUTSTAT0_ROR_BIT) {
163239
LOG_ERR("dmic_irq_handler(): full fifo A or PDM overrun");
@@ -243,6 +319,7 @@ static int dai_dmic_probe(struct dai_intel_dmic *dmic)
243319
dai_dmic_claim_ownership(dmic);
244320

245321
irq_enable(dmic->irq);
322+
246323
return 0;
247324
}
248325

@@ -314,7 +391,7 @@ static int dai_timestamp_dmic_stop(const struct device *dev, struct dai_ts_cfg *
314391
}
315392

316393
static int dai_timestamp_dmic_get(const struct device *dev, struct dai_ts_cfg *cfg,
317-
struct dai_ts_data *tsd)
394+
struct dai_ts_data *tsd)
318395
{
319396
/* Read DMIC timestamp registers */
320397
uint32_t tsctrl = TS_DMIC_LOCAL_TSCTRL;
@@ -530,6 +607,9 @@ static void dai_dmic_start(struct dai_intel_dmic *dmic)
530607
for (i = 0; i < CONFIG_DAI_DMIC_HW_CONTROLLERS; i++) {
531608
dai_dmic_update_bits(dmic, base[i] + CIC_CONTROL,
532609
CIC_CONTROL_SOFT_RESET_BIT, 0);
610+
611+
LOG_INF("dmic_start(), cic 0x%08x",
612+
dai_dmic_read(dmic, base[i] + CIC_CONTROL));
533613
}
534614

535615
/* Set bit dai->index */
@@ -542,7 +622,7 @@ static void dai_dmic_start(struct dai_intel_dmic *dmic)
542622
dmic_sync_trigger(dmic);
543623

544624
LOG_INF("dmic_start(), dmic_active_fifos_mask = 0x%x",
545-
dai_dmic_global.active_fifos_mask);
625+
dai_dmic_global.active_fifos_mask);
546626
}
547627

548628
static void dai_dmic_stop(struct dai_intel_dmic *dmic, bool stop_is_pause)
@@ -611,7 +691,7 @@ const struct dai_properties *dai_dmic_get_properties(const struct device *dev,
611691
}
612692

613693
static int dai_dmic_trigger(const struct device *dev, enum dai_dir dir,
614-
enum dai_trigger_cmd cmd)
694+
enum dai_trigger_cmd cmd)
615695
{
616696
struct dai_intel_dmic *dmic = (struct dai_intel_dmic *)dev->data;
617697

@@ -800,4 +880,4 @@ static int dai_dmic_initialize_device(const struct device *dev)
800880
CONFIG_DAI_INIT_PRIORITY, \
801881
&dai_dmic_ops);
802882

803-
DT_INST_FOREACH_STATUS_OKAY(DAI_INTEL_DMIC_DEVICE_INIT);
883+
DT_INST_FOREACH_STATUS_OKAY(DAI_INTEL_DMIC_DEVICE_INIT)

drivers/dai/intel/dmic/dmic.h

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -558,82 +558,6 @@ struct dai_intel_dmic {
558558
uint32_t flags;
559559
};
560560

561-
/* Exponent function for small values of x. This function calculates
562-
* fairly accurately exponent for x in range -2.0 .. +2.0. The iteration
563-
* uses first 11 terms of Taylor series approximation for exponent
564-
* function. With the current scaling the numerator just remains under
565-
* 64 bits with the 11 terms.
566-
*
567-
* See https://en.wikipedia.org/wiki/Exponential_function#Computation
568-
*
569-
* The input is Q3.29
570-
* The output is Q9.23
571-
*/
572-
static int32_t exp_small_fixed(int32_t x)
573-
{
574-
int64_t p;
575-
int64_t num = Q_SHIFT_RND(x, 29, 23);
576-
int32_t y = (int32_t)num;
577-
int32_t den = 1;
578-
int32_t inc;
579-
int k;
580-
581-
/* Numerator is x^k, denominator is k! */
582-
for (k = 2; k < 12; k++) {
583-
p = num * x; /* Q9.23 x Q3.29 -> Q12.52 */
584-
num = Q_SHIFT_RND(p, 52, 23);
585-
den = den * k;
586-
inc = (int32_t)(num / den);
587-
y += inc;
588-
}
589-
590-
return y + ONE_Q23;
591-
}
592-
593-
static int32_t exp_fixed(int32_t x)
594-
{
595-
int32_t xs;
596-
int32_t y;
597-
int32_t z;
598-
int i;
599-
int n = 0;
600-
601-
if (x < Q_CONVERT_FLOAT(-11.5, 27))
602-
return 0;
603-
604-
if (x > Q_CONVERT_FLOAT(7.6245, 27))
605-
return INT32_MAX;
606-
607-
/* x is Q5.27 */
608-
xs = x;
609-
while (xs >= TWO_Q27 || xs <= MINUS_TWO_Q27) {
610-
xs >>= 1;
611-
n++;
612-
}
613-
614-
/* exp_small_fixed() input is Q3.29, while x1 is Q5.27
615-
* exp_small_fixed() output is Q9.23, while z is Q12.20
616-
*/
617-
z = Q_SHIFT_RND(exp_small_fixed(Q_SHIFT_LEFT(xs, 27, 29)), 23, 20);
618-
y = ONE_Q20;
619-
for (i = 0; i < (1 << n); i++)
620-
y = (int32_t)Q_MULTSR_32X32((int64_t)y, z, 20, 20, 20);
621-
622-
return y;
623-
}
624-
625-
static int32_t db2lin_fixed(int32_t db)
626-
{
627-
int32_t arg;
628-
629-
if (db < Q_CONVERT_FLOAT(-100.0, 24))
630-
return 0;
631-
632-
/* Q8.24 x Q5.27, result needs to be Q5.27 */
633-
arg = (int32_t)Q_MULTSR_32X32((int64_t)db, LOG10_DIV20_Q27, 24, 27, 27);
634-
return exp_fixed(arg);
635-
}
636-
637561
static inline int32_t sat_int32(int64_t x)
638562
{
639563
if (x > INT32_MAX)

drivers/dai/intel/dmic/dmic_nhlt.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static const uint32_t coef_base_b[4] = {PDM0_COEFFICIENT_B, PDM1_COEFFICIENT_B,
2525
PDM2_COEFFICIENT_B, PDM3_COEFFICIENT_B};
2626

2727
static inline void dai_dmic_write(const struct dai_intel_dmic *dmic,
28-
uint32_t reg, uint32_t val)
28+
uint32_t reg, uint32_t val)
2929
{
3030
sys_write32(val, dmic->reg_base + reg);
3131
}
@@ -54,9 +54,9 @@ static int dai_ipm_source_to_enable(struct dai_intel_dmic *dmic,
5454
}
5555

5656
static int dai_nhlt_dmic_dai_params_get(struct dai_intel_dmic *dmic,
57-
int32_t *outcontrol,
58-
struct nhlt_pdm_ctrl_cfg **pdm_cfg,
59-
struct nhlt_pdm_ctrl_fir_cfg **fir_cfg)
57+
int32_t *outcontrol,
58+
struct nhlt_pdm_ctrl_cfg **pdm_cfg,
59+
struct nhlt_pdm_ctrl_fir_cfg **fir_cfg)
6060
{
6161
uint32_t outcontrol_val = outcontrol[dmic->dai_config_params.dai_index];
6262
int num_pdm;
@@ -82,7 +82,8 @@ static int dai_nhlt_dmic_dai_params_get(struct dai_intel_dmic *dmic,
8282

8383
num_pdm = OUTCONTROL0_IPM_GET(outcontrol_val);
8484
if (num_pdm > CONFIG_DAI_DMIC_HW_CONTROLLERS) {
85-
LOG_ERR("nhlt_dmic_dai_params_get(): Illegal IPM PDM controllers count");
85+
LOG_ERR("nhlt_dmic_dai_params_get(): Illegal IPM PDM controllers count %d",
86+
num_pdm);
8687
return -EINVAL;
8788
}
8889

@@ -588,5 +589,11 @@ int dai_dmic_set_config_nhlt(struct dai_intel_dmic *dmic, const void *bespoke_cf
588589
LOG_INF("dmic_set_config_nhlt(): rate = %d, channels = %d, format = %d",
589590
dmic->dai_config_params.rate, dmic->dai_config_params.channels,
590591
dmic->dai_config_params.format);
592+
593+
LOG_INF("dmic_set_config_nhlt(): io_clk %u, rate_div %d",
594+
CONFIG_DAI_DMIC_HW_IOCLK, rate_div);
595+
596+
LOG_INF("dmic_set_config_nhlt(): enable0 %u, enable1 %u",
597+
dmic->enable[0], dmic->enable[1]);
591598
return 0;
592599
}

0 commit comments

Comments
 (0)