Re: [PATCH v1 2/4] ASoC: tac5xx2-sdw: add soundwire based codec driver
From: Charles Keepax
Date: Tue Mar 24 2026 - 06:06:18 EST
On Mon, Mar 23, 2026 at 02:40:42PM -0700, Pierre-Louis Bossart wrote:
> > +/* Convert dB to Q7.8 format (16-bit signed value) */
> > +static inline u16 db_to_q7_8(int db_value_times_100)
> > +{
> > + u16 result = (u16)(((db_value_times_100 * 256) / 100) & 0xFFFF);
> > + return result;
> > +}
> > +
> > +/* Convert Q7.8 format to dB*100 */
> > +static inline int q7_8_to_db_times_100(u16 q7_8_value)
> > +{
> > + s16 signed_val = (s16)q7_8_value;
> > +
> > + return (signed_val * 100) / 256;
> > +}
>
> Didn't Charles Keepax add some macros for the Q7.8 format?
Me and Shuming Fan did some work on this in the SDCA class driver,
it is currently based on a slightly different system using the
TLV to map to dB's where as this code seems to present 100ths
of a dB directly. The problem with that approach however is you
tend to loose some precision as you generally don't end up with
a 1-to-1 mapping from control values to register values.
The helpers are not currently seperately exported although
no reason they couldn't be. q78_put_volsw and q78_get_volsw
in sdca_asoc.c.
Thanks,
Charles