@@ -31,6 +31,82 @@ struct dai_dmic_global_shared dai_dmic_global;
3131
3232int 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+
34110static 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
316393static 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
548628static 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
613693static 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 )
0 commit comments