struct snd_mask *f_old = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
        unsigned int channels = params_channels(params);
        unsigned int slot_width;
+       snd_pcm_format_t format;
        struct snd_mask f_new;
-       unsigned int i;
 
        if (!channels || channels > nb_ts) {
                dev_err(qmc_dai->dev, "channels %u not supported\n",
        slot_width = (nb_ts / channels) * 8;
 
        snd_mask_none(&f_new);
-       for (i = 0; i <= SNDRV_PCM_FORMAT_LAST; i++) {
-               if (snd_mask_test(f_old, i)) {
-                       if (snd_pcm_format_physical_width(i) <= slot_width)
-                               snd_mask_set(&f_new, i);
+       pcm_for_each_format(format) {
+               if (snd_mask_test_format(f_old, format)) {
+                       if (snd_pcm_format_physical_width(format) <= slot_width)
+                               snd_mask_set_format(&f_new, format);
                }
        }
 
 
 static u64 qmc_audio_formats(u8 nb_ts)
 {
-       u64 formats;
-       unsigned int chan_width;
        unsigned int format_width;
-       int i;
+       unsigned int chan_width;
+       snd_pcm_format_t format;
+       u64 formats_mask;
 
        if (!nb_ts)
                return 0;
 
-       formats = 0;
+       formats_mask = 0;
        chan_width = nb_ts * 8;
-       for (i = 0; i <= SNDRV_PCM_FORMAT_LAST; i++) {
+       pcm_for_each_format(format) {
                /*
                 * Support format other than little-endian (ie big-endian or
                 * without endianness such as 8bit formats)
                 */
-               if (snd_pcm_format_little_endian(i) == 1)
+               if (snd_pcm_format_little_endian(format) == 1)
                        continue;
 
                /* Support physical width multiple of 8bit */
-               format_width = snd_pcm_format_physical_width(i);
+               format_width = snd_pcm_format_physical_width(format);
                if (format_width == 0 || format_width % 8)
                        continue;
 
                if (format_width > chan_width || chan_width % format_width)
                        continue;
 
-               formats |= (1ULL << i);
+               formats_mask |= pcm_format_to_bits(format);
        }
-       return formats;
+       return formats_mask;
 }
 
 static int qmc_audio_dai_parse(struct qmc_audio *qmc_audio, struct device_node *np,