Re: [RFC PATCH 1/2] ASoC: loongson: Fix IISConfig0 update in hw_params for rev 1

From: Bui Duc Phuc

Date: Wed Oct 28 2026 - 06:17:14 EST


Hi Binbin,

> > On revision 1 controllers, loongson_i2s_hw_params() reads LS_I2S_CFG
> > and ORs the new LR_LEN, BCLK_RATIO and RES_DEPTH values into it
> > without clearing the old ones.
> >
> > The first stream after boot is configured correctly, but any later
> > stream with a different rate or sample width ends up with a mix of
> > old and new bits, so it may run with the wrong rate or sample width.
>
> I tested this patch on a Loongson-2K0300 and Loongson-2K2000 board
> (LoongsonASoC sound card).
>
> I ran consecutive playback and capture tests alternating between
> S16_LE/44100 Hz and S24_LE/48000 Hz, both in stereo. After applying
> this patch, switching between different sample formats and rates, works
> correctly.
>

Thanks for testing this on both boards!

>
> One minor suggestion: would it be possible to define these bit fields via
> macros, or use FIELD_PREP()/FIELD_GET() with GENMASK(), instead of
> open-coded shifts and masks? For example:
>
> #define LS_I2S_CFG_LR_LEN_MASK GENMASK(31, 24)
> #define LS_I2S_CFG_TX_RES_DEPTH_MASK GENMASK(23, 16)
> #define LS_I2S_CFG_BCLK_RATIO_MASK GENMASK(15, 8)
> #define LS_I2S_CFG_RX_RES_DEPTH_MASK GENMASK(7, 0)
>

I'll update the bit-field definitions as suggested and also apply the
same approach
to CFG1 and rev 0 to keep the code consistent in hw_params().

I'll send v2 soon.

Best regards,
Phuc