{
        struct snd_soc_component *component = dai->component;
        struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
+       int afmt;
+       int offset = 0;
        int clock_output;
        int master_mode;
        int ret;
                return ret;
        }
 
+       switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
+       case SND_SOC_DAIFMT_I2S:
+               afmt = PCM512x_AFMT_I2S;
+               break;
+       case SND_SOC_DAIFMT_RIGHT_J:
+               afmt = PCM512x_AFMT_RTJ;
+               break;
+       case SND_SOC_DAIFMT_LEFT_J:
+               afmt = PCM512x_AFMT_LTJ;
+               break;
+       case SND_SOC_DAIFMT_DSP_A:
+               offset = 1;
+               fallthrough;
+       case SND_SOC_DAIFMT_DSP_B:
+               afmt = PCM512x_AFMT_DSP;
+               break;
+       default:
+               dev_err(component->dev, "unsupported DAI format: 0x%x\n",
+                       pcm512x->fmt);
+               return -EINVAL;
+       }
+
+       ret = regmap_update_bits(pcm512x->regmap, PCM512x_I2S_1,
+                                PCM512x_AFMT, afmt);
+       if (ret != 0) {
+               dev_err(component->dev, "Failed to set data format: %d\n", ret);
+               return ret;
+       }
+
+       ret = regmap_update_bits(pcm512x->regmap, PCM512x_I2S_2,
+                                0xFF, offset);
+       if (ret != 0) {
+               dev_err(component->dev, "Failed to set data offset: %d\n", ret);
+               return ret;
+       }
+
        pcm512x->fmt = fmt;
 
        return 0;