summaryrefslogtreecommitdiff
path: root/sound/soc/fsl/fsl_xcvr.c
blob: 9abd74250f2040c3a736cd8e58730787fa10af28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
// SPDX-License-Identifier: GPL-2.0
// Copyright 2019 NXP

#include <linux/bitrev.h>
#include <linux/clk.h>
#include <linux/firmware.h>
#include <linux/interrupt.h>
#include <linux/module.h>
#include <linux/of_platform.h>
#include <linux/pm_runtime.h>
#include <linux/regmap.h>
#include <linux/reset.h>
#include <sound/dmaengine_pcm.h>

#include "fsl_xcvr.h"
#include "imx-pcm.h"

struct fsl_xcvr {
	struct platform_device *pdev;
	struct regmap *regmap;
	struct clk *ipg_clk;
	struct clk *phy_clk;
	struct clk *spba_clk;
	struct reset_control *reset;
	const char *fw_name;
	u8 streams;
	u32 mode;
	void __iomem *ram_addr;
	struct snd_dmaengine_dai_dma_data dma_prms_rx;
	struct snd_dmaengine_dai_dma_data dma_prms_tx;
	struct snd_aes_iec958 rx_iec958;
	struct snd_aes_iec958 tx_iec958;
};

static const u32 fsl_xcvr_earc_channels[] = { 1, 2, 8, 16, 32, }; /* one bit 6, 12 ? */
static const struct snd_pcm_hw_constraint_list fsl_xcvr_earc_channels_constr = {
	.count = ARRAY_SIZE(fsl_xcvr_earc_channels),
	.list = fsl_xcvr_earc_channels,
};

static const u32 fsl_xcvr_earc_bits[] = { 24, };
static const struct snd_pcm_hw_constraint_list fsl_xcvr_earc_bits_constr = {
	.count = ARRAY_SIZE(fsl_xcvr_earc_bits),
	.list = fsl_xcvr_earc_bits,
};

static const u32 fsl_xcvr_earc_rates[] = {
	32000, 44100, 48000, 64000, 88200, 96000,
	128000, 176400, 192000, 256000, 352800, 384000,
	512000, 705600, 768000, 1024000, 1411200, 1536000,
};
static const struct snd_pcm_hw_constraint_list fsl_xcvr_earc_rates_constr = {
	.count = ARRAY_SIZE(fsl_xcvr_earc_rates),
	.list = fsl_xcvr_earc_rates,
};

static const u32 fsl_xcvr_spdif_channels[] = { 2, };
static const u32 fsl_xcvr_spdif_bits[] = { 16, 20, 24, };

/*
 * pll_phy:  pll 0; phy 1;
*/
static int fsl_xcvr_phy_write(struct fsl_xcvr *xcvr, int reg, int data, int pll_phy)
{
	int val;
	int idx0, idx1;

	idx0 = pll_phy > 0 ? 26 : 24;
	idx1 = pll_phy > 0 ? 24 : 26;

	regmap_write(xcvr->regmap, FSL_XCVR_PHY_AI_WDATA, data);
	regmap_read(xcvr->regmap, FSL_XCVR_PHY_AI_CTRL, &val);

	val = ((~(val & BIT(idx0))) & BIT(idx0)) | (val & BIT(idx1)) | reg | BIT(15);

	regmap_write(xcvr->regmap, FSL_XCVR_PHY_AI_CTRL, val);

	do {
		regmap_read(xcvr->regmap, FSL_XCVR_PHY_AI_CTRL, &val);
	} while ((val & BIT(idx0)) != ((val & BIT(idx0 + 1)) >> 1));

	return 0;
}

static int fsl_xcvr_prepare(struct snd_pcm_substream *substream,
			    struct snd_soc_dai *dai)
{
	struct fsl_xcvr *xcvr = snd_soc_dai_get_drvdata(dai);
	bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
	u32 m_ctl = 0, v_ctl = 0, m_isr = 0, v_isr = 0;
	int ret = 0;

	ret = regmap_update_bits(xcvr->regmap, FSL_XCVR_EXT_IER0,
				 FSL_XCVR_IRQ_EARC_ALL, FSL_XCVR_IRQ_EARC_ALL);
	if (ret < 0) {
		dev_err(dai->dev, "Error while setting IER0: %d\n", ret);
		return ret;
	}

	/* configure EXT_CTRL */
	switch (xcvr->mode & FSL_XCVR_AMODE_MASK) {
	case FSL_XCVR_AMODE_SPDIF:
		/* set SPDIF MODE */
		m_ctl |= FSL_XCVR_EXT_CTRL_SPDIF_MODE;
		v_ctl |= FSL_XCVR_EXT_CTRL_SPDIF_MODE;
		m_isr |= FSL_XCVR_ISR_SET_SPDIF_MODE(tx);
		v_isr |= FSL_XCVR_ISR_SET_SPDIF_MODE(tx);
		if (xcvr->streams == 3) { // both Tx and Rx are in use
			m_isr |= FSL_XCVR_ISR_DMAC_SPARE_INT;
			v_isr |= FSL_XCVR_ISR_DMAC_SPARE_INT;
		}
		break;
	case FSL_XCVR_AMODE_ARC:
		/* Enable ISR */
		break;
	case FSL_XCVR_AMODE_EARC:
		/* clear CMDC RESET */
		m_ctl |= FSL_XCVR_EXT_CTRL_CMDC_RESET(tx);
		/* set TX_RX_MODE */
		m_ctl |= FSL_XCVR_EXT_CTRL_TX_RX_MODE;
		v_ctl |= (tx ? FSL_XCVR_EXT_CTRL_TX_RX_MODE : 0);
		break;
	}

	/* clear DPATH RESET */
	m_ctl |= FSL_XCVR_EXT_CTRL_DPTH_RESET(tx);
	ret = regmap_update_bits(xcvr->regmap, FSL_XCVR_EXT_CTRL, m_ctl, v_ctl);
	if (ret < 0) {
		dev_err(dai->dev, "Error while setting EXT_CTRL: %d\n", ret);
		return ret;
	}

	ret = regmap_update_bits(xcvr->regmap, FSL_XCVR_ISR_SET, m_isr, v_isr);
	if (ret < 0) {
		dev_err(dai->dev, "Error while setting MO ISR: %d\n", ret);
		return ret;
	}

	return 0;
}

static int fsl_xcvr_constr(const struct snd_pcm_substream *substream,
			   const struct snd_pcm_hw_constraint_list *bits,
			   const struct snd_pcm_hw_constraint_list *channels,
			   const struct snd_pcm_hw_constraint_list *rates)
{
	struct snd_pcm_runtime *rt = substream->runtime;
	int ret;

	ret = snd_pcm_hw_constraint_list(rt, 0, SNDRV_PCM_HW_PARAM_SAMPLE_BITS,
					 bits);
	if (ret < 0)
		return ret;

	ret = snd_pcm_hw_constraint_list(rt, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
					 channels);
	if (ret < 0)
		return ret;

	ret = snd_pcm_hw_constraint_list(rt, 0, SNDRV_PCM_HW_PARAM_RATE,
					 rates);
	if (ret < 0)
		return ret;

	return 0;
}

static int fsl_xcvr_startup(struct snd_pcm_substream *substream,
			    struct snd_soc_dai *dai)
{
	struct fsl_xcvr *xcvr = snd_soc_dai_get_drvdata(dai);
	bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
	int ret = 0;

	/* check stream direction is enabled in DTS */
	if (!(xcvr->mode & BIT(substream->stream))) {
		dev_err(dai->dev, "%sX not supported\n", tx ? "T" : "R");
		return -EINVAL;
	}

	if (xcvr->streams & BIT(substream->stream)) {
		dev_err(dai->dev, "%sX busy\n", tx ? "T" : "R");
		return -EBUSY;
	}

	switch (xcvr->mode & FSL_XCVR_AMODE_MASK) {
	case FSL_XCVR_AMODE_SPDIF:
	case FSL_XCVR_AMODE_ARC:
		ret = 0; /* @todo */
		break;
	case FSL_XCVR_AMODE_EARC:
		ret = fsl_xcvr_constr(substream, &fsl_xcvr_earc_bits_constr,
				      &fsl_xcvr_earc_channels_constr,
				      &fsl_xcvr_earc_rates_constr);
		break;
	}
	if (ret < 0)
		return ret;

	xcvr->streams |= BIT(substream->stream);

	switch (xcvr->mode & FSL_XCVR_AMODE_MASK) {
	case FSL_XCVR_AMODE_SPDIF:
		if (tx) {
			fsl_xcvr_phy_write(xcvr, 0x54, 0x1, 0);
			fsl_xcvr_phy_write(xcvr, 0x4, 0x1, 1);
			fsl_xcvr_phy_write(xcvr, 0x0, 0x28, 0);
			fsl_xcvr_phy_write(xcvr, 0x20, 0x60, 0);
			fsl_xcvr_phy_write(xcvr, 0x30, 0x64, 0);
			fsl_xcvr_phy_write(xcvr, 0x4, 0x1006000, 0);
			udelay(25);
			fsl_xcvr_phy_write(xcvr, 0x8, 0x2000, 0);
			udelay(100);
			fsl_xcvr_phy_write(xcvr, 0x40, 0x5, 0);

			fsl_xcvr_phy_write(xcvr, 0x4,  0x20, 1);
			fsl_xcvr_phy_write(xcvr, 0x74, 0x4000, 1);
		}
		break;
	case FSL_XCVR_AMODE_EARC:
		if (tx) {
			fsl_xcvr_phy_write(xcvr, 0x54, 0x1, 0);
			fsl_xcvr_phy_write(xcvr, 0x4, 0x1, 1);
			fsl_xcvr_phy_write(xcvr, 0x0, 0x28, 0);
			fsl_xcvr_phy_write(xcvr, 0x20, 0x60, 0);
			fsl_xcvr_phy_write(xcvr, 0x30, 0x64, 0);
			fsl_xcvr_phy_write(xcvr, 0x4, 0x1006000, 0);
			udelay(25);
			fsl_xcvr_phy_write(xcvr, 0x8, 0x2000, 0);
			udelay(100);
			fsl_xcvr_phy_write(xcvr, 0x40, 0x1, 0);

			fsl_xcvr_phy_write(xcvr, 0x4,  0x20, 1);
			fsl_xcvr_phy_write(xcvr, 0x74, 0x4000, 1);
		}
		break;
	default:
		break;
	}

	return 0;
}

static void fsl_xcvr_shutdown(struct snd_pcm_substream *substream,
			      struct snd_soc_dai *dai)
{
	struct fsl_xcvr *xcvr = snd_soc_dai_get_drvdata(dai);
	bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
	u32 mask = 0, val = 0;
	int ret;

	xcvr->streams &= ~BIT(substream->stream);
	ret = regmap_update_bits(xcvr->regmap, FSL_XCVR_EXT_IER0,
				 FSL_XCVR_IRQ_EARC_ALL, 0);
	if (ret < 0) {
		dev_err(dai->dev, "Failed to set IER0: %d\n", ret);
		return;
	}

	switch (xcvr->mode & FSL_XCVR_AMODE_MASK) {
	case FSL_XCVR_AMODE_SPDIF:
		/* clear SPDIF MODE */
		mask |= FSL_XCVR_EXT_CTRL_SPDIF_MODE;
		break;
	case FSL_XCVR_AMODE_EARC:
		/* set CMDC RESET */
		mask |= FSL_XCVR_EXT_CTRL_CMDC_RESET(tx);
		val  |= FSL_XCVR_EXT_CTRL_CMDC_RESET(tx);
		break;
	}

	/* set DPATH RESET */
	mask |= FSL_XCVR_EXT_CTRL_DPTH_RESET(tx);
	val  |= FSL_XCVR_EXT_CTRL_DPTH_RESET(tx);

	ret = regmap_update_bits(xcvr->regmap, FSL_XCVR_EXT_CTRL, mask, val);
	if (ret < 0) {
		dev_err(dai->dev, "Err setting DPATH RESET: %d\n", ret);
		return;
	}
}

static int fsl_xcvr_hw_params(struct snd_pcm_substream *substream,
			      struct snd_pcm_hw_params *params,
			      struct snd_soc_dai *dai)
{
	struct fsl_xcvr *xcvr = snd_soc_dai_get_drvdata(dai);
	bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
	u32 mask, val, r = params_rate(params), ch = params_channels(params);
	int ret;

	if (tx) {
		mask  = FSL_XCVR_CS_DATA_0_FS_MASK;
		mask |= FSL_XCVR_CS_DATA_0_CH_MASK;

		switch (r) {
		case 32000:  val = FSL_XCVR_CS_DATA_0_FS_32000;  break;
		case 44100:  val = FSL_XCVR_CS_DATA_0_FS_44100;  break;
		case 48000:  val = FSL_XCVR_CS_DATA_0_FS_48000;  break;
		case 64000:  val = FSL_XCVR_CS_DATA_0_FS_64000;  break;
		case 88200:  val = FSL_XCVR_CS_DATA_0_FS_88200;  break;
		case 96000:  val = FSL_XCVR_CS_DATA_0_FS_96000;  break;
		case 176400: val = FSL_XCVR_CS_DATA_0_FS_176400; break;
		case 192000: val = FSL_XCVR_CS_DATA_0_FS_192000; break;
		default:
			dev_err(dai->dev, "Unsupported rate: %u\n", r);
			return -EINVAL;
		}
		val |= FSL_XCVR_CS_DATA_0_CH_UMLPCM;

		/* Update TX CS data bits 0 */
		ret = regmap_update_bits(xcvr->regmap, FSL_XCVR_TX_CS_DATA_0,
					 mask, val);
		if (ret < 0) {
			dev_err(dai->dev, "Failed to set TX CS 0: %d\n", ret);
			return ret;
		}

		switch (ch) {
		case 2:  val = FSL_XCVR_CS_DATA_1_CH_2;  break;
		case 8:  val = FSL_XCVR_CS_DATA_1_CH_8;  break;
		case 16: val = FSL_XCVR_CS_DATA_1_CH_16; break;
		case 32: val = FSL_XCVR_CS_DATA_1_CH_32; break;
		default:
			dev_err(dai->dev, "Unsupported channels: %u\n", ch);
			return -EINVAL;
		}

		/* Update TX CS data bits 1 */
		ret = regmap_update_bits(xcvr->regmap, FSL_XCVR_TX_CS_DATA_1,
					 FSL_XCVR_CS_DATA_1_CH_MASK, val);
		if (ret < 0) {
			dev_err(dai->dev, "Failed to set TX CS 1: %d\n", ret);
			return ret;
		}
	}

	return 0;
}

static int fsl_xcvr_trigger(struct snd_pcm_substream *substream, int cmd,
			    struct snd_soc_dai *dai)
{
	struct fsl_xcvr *xcvr = snd_soc_dai_get_drvdata(dai);
	bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
	int ret;

	switch (cmd) {
	case SNDRV_PCM_TRIGGER_START:
	case SNDRV_PCM_TRIGGER_RESUME:
	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
		if (tx) {
			switch (xcvr->mode & FSL_XCVR_AMODE_MASK) {
			case FSL_XCVR_AMODE_EARC:
				/* set isr_cmdc_tx_en, w1c */
				ret = regmap_update_bits(xcvr->regmap,
							 FSL_XCVR_ISR_SET,
							 FSL_XCVR_ISR_CMDC_TX_EN,
							 FSL_XCVR_ISR_CMDC_TX_EN);
				if (ret < 0) {
					dev_err(dai->dev,
						"err updating isr %d\n", ret);
					return ret;
				}
				/* fall through */

			case FSL_XCVR_AMODE_SPDIF:
				ret = regmap_update_bits(xcvr->regmap,
					 FSL_XCVR_TX_DPTH_CTRL_SET,
					 FSL_XCVR_TX_DPTH_CTRL_STRT_DATA_TX,
					 FSL_XCVR_TX_DPTH_CTRL_STRT_DATA_TX);
				if (ret < 0) {
					dev_err(dai->dev, "Failed to set TX_DPTH_CTRL_STRT_DATA_TX: %d\n", ret);
					return ret;
				}
				break;
			}
		} else {
			/* Clear RX FIFO */
			ret = regmap_update_bits(xcvr->regmap,
					 FSL_XCVR_RX_DPTH_CTRL_SET,
					 FSL_XCVR_RX_DPTH_CTRL_CLR_RX_FIFO,
					 FSL_XCVR_RX_DPTH_CTRL_CLR_RX_FIFO);
			if (ret < 0) {
				dev_err(dai->dev, "Failed to clear RX FIFO: %d\n", ret);
				return ret;
			}

			/* Flip RX FIFO bits */
			ret = regmap_update_bits(xcvr->regmap,
					 FSL_XCVR_RX_DPTH_CTRL_SET,
					 FSL_XCVR_RX_DPTH_CTRL_STORE_FMT,
					 FSL_XCVR_RX_DPTH_CTRL_STORE_FMT);
			if (ret < 0) {
				dev_err(dai->dev, "Failed to set reverse bit in RX FIFO: %d\n", ret);
				return ret;
			}
		}

		/* enable DMA RD/WR */
		ret = regmap_update_bits(xcvr->regmap, FSL_XCVR_EXT_CTRL,
					 FSL_XCVR_EXT_CTRL_DMA_DIS(tx), 0);
		if (ret < 0) {
			dev_err(dai->dev, "Failed to enable DMA: %d\n", ret);
			return ret;
		}
		break;
	case SNDRV_PCM_TRIGGER_STOP:
	case SNDRV_PCM_TRIGGER_SUSPEND:
	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
		/* disable DMA RD/WR */
		ret = regmap_update_bits(xcvr->regmap, FSL_XCVR_EXT_CTRL,
					 FSL_XCVR_EXT_CTRL_DMA_DIS(tx),
					 FSL_XCVR_EXT_CTRL_DMA_DIS(tx));
		if (ret < 0) {
			dev_err(dai->dev, "Failed to disable DMA: %d\n", ret);
			return ret;
		}

		if (tx) {
			switch (xcvr->mode & FSL_XCVR_AMODE_MASK) {
			case FSL_XCVR_AMODE_SPDIF:
				ret = regmap_update_bits(xcvr->regmap,
					 FSL_XCVR_TX_DPTH_CTRL_CLR,
					 FSL_XCVR_TX_DPTH_CTRL_STRT_DATA_TX,
					 FSL_XCVR_TX_DPTH_CTRL_STRT_DATA_TX);
				if (ret < 0) {
					dev_err(dai->dev, "Failed to clr TX_DPTH_CTRL_STRT_DATA_TX: %d\n", ret);
					return ret;
				}
				/* fall through ...*/
			case FSL_XCVR_AMODE_EARC:
				/* clear ISR_CMDC_TX_EN, W1C */
				ret = regmap_update_bits(xcvr->regmap,
							 FSL_XCVR_ISR_CLR,
							 FSL_XCVR_ISR_CMDC_TX_EN,
							 FSL_XCVR_ISR_CMDC_TX_EN);
				if (ret < 0) {
					dev_err(dai->dev,
						"Err updating ISR %d\n", ret);
					return ret;
				}
				break;
			}
		}
		break;
	default:
		return -EINVAL;
	}

	return 0;
}

static int fsl_xcvr_load_firmware(struct fsl_xcvr *xcvr)
{
	struct device *dev = &xcvr->pdev->dev;
	const struct firmware *fw;
	int ret = 0, rem, off, out, page = 0, size = FSL_XCVR_REG_OFFSET;
	u32 mask, val;

	ret = request_firmware(&fw, xcvr->fw_name, dev);
	if (ret) {
		dev_err(dev, "failed to request firmware.\n");
		return ret;
	}

	rem = fw->size;

	/* RAM is 20KiB => max 10 pages 2KiB each */
	for (page = 0; page < 10; page++)
	{
		ret = regmap_update_bits(xcvr->regmap, FSL_XCVR_EXT_CTRL,
					 FSL_XCVR_EXT_CTRL_PAGE_MASK,
					 FSL_XCVR_EXT_CTRL_PAGE(page));
		if (ret < 0) {
			dev_err(dev, "FW: failed to set page %d, err=%d \n",
				page, ret);
			goto err_firmware;
		}

		off = page * size;
		out = min(rem, size);
		/* IPG clock is assumed to be running, otherwise it will hang */
		if (out > 0) {
			/* write firmware into code memory */
			memcpy_toio(xcvr->ram_addr, fw->data + off, out);
			rem -= out;
			if (rem == 0) {
				/* last part of firmware written */
				/* clean remaining part of code memory page */
				memset_io(xcvr->ram_addr + out, 0, size - out);
			}
		} else {
			/* clean current page, including data memory */
			memset_io(xcvr->ram_addr, 0, size);
		}
	};

err_firmware:
	release_firmware(fw);
	if (ret < 0)
		return ret;

	/* configure watermarks */
	mask = FSL_XCVR_EXT_CTRL_RX_FWM_MASK | FSL_XCVR_EXT_CTRL_TX_FWM_MASK;
	val  = FSL_XCVR_EXT_CTRL_RX_FWM(FSL_XCVR_FIFO_WMK_RX);
	val |= FSL_XCVR_EXT_CTRL_TX_FWM(FSL_XCVR_FIFO_WMK_TX);
	/* disable DMA RD/WR */
	mask |= FSL_XCVR_EXT_CTRL_DMA_RD_DIS | FSL_XCVR_EXT_CTRL_DMA_WR_DIS;
	val |= FSL_XCVR_EXT_CTRL_DMA_RD_DIS | FSL_XCVR_EXT_CTRL_DMA_WR_DIS;
	ret = regmap_update_bits(xcvr->regmap, FSL_XCVR_EXT_CTRL, mask, val);
	if (ret < 0) {
		dev_err(dev, "Failed to set watermarks: %d\n", ret);
		return ret;
	}

	/* configure RX DATAPATH */
	mask = FSL_XCVR_RX_DPTH_CTRL_CSA | FSL_XCVR_RX_DPTH_CTRL_UDA;
	ret = regmap_update_bits(xcvr->regmap, FSL_XCVR_RX_DPTH_CTRL_SET, mask,
				 mask);
	if (ret < 0) {
		dev_err(dev, "Failed to configure RX DPATH: %d\n", ret);
		return ret;
	}

	return 0;
}

static int fsl_xcvr_type_iec958_info(struct snd_kcontrol *kcontrol,
				     struct snd_ctl_elem_info *uinfo)
{
	uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
	uinfo->count = 1;

	return 0;
}

static int fsl_xcvr_rx_cs_get(struct snd_kcontrol *kcontrol,
			      struct snd_ctl_elem_value *ucontrol)
{
	struct snd_soc_dai *dai = snd_kcontrol_chip(kcontrol);
	struct fsl_xcvr *xcvr = snd_soc_dai_get_drvdata(dai);

	memcpy(ucontrol->value.iec958.status, xcvr->rx_iec958.status, 24);

	return 0;
}

static int fsl_xcvr_tx_cs_get(struct snd_kcontrol *kcontrol,
			      struct snd_ctl_elem_value *ucontrol)
{
	struct snd_soc_dai *dai = snd_kcontrol_chip(kcontrol);
	struct fsl_xcvr *xcvr = snd_soc_dai_get_drvdata(dai);

	memcpy(ucontrol->value.iec958.status, xcvr->tx_iec958.status, 24);

	return 0;
}

static int fsl_xcvr_tx_cs_put(struct snd_kcontrol *kcontrol,
			      struct snd_ctl_elem_value *ucontrol)
{
	struct snd_soc_dai *dai = snd_kcontrol_chip(kcontrol);
	struct fsl_xcvr *xcvr = snd_soc_dai_get_drvdata(dai);

	memcpy(xcvr->tx_iec958.status, ucontrol->value.iec958.status, 24);

	return 0;
}

static struct snd_kcontrol_new fsl_xcvr_rx_ctls[] = {
	/* Status chanel controller */
	{
		.iface = SNDRV_CTL_ELEM_IFACE_PCM,
		.name = SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT),
		.access = SNDRV_CTL_ELEM_ACCESS_READ,
		.info = fsl_xcvr_type_iec958_info,
		.get = fsl_xcvr_rx_cs_get,
	},
};

static struct snd_kcontrol_new fsl_xcvr_tx_ctls[] = {
	/* Status chanel controller */
	{
		.iface = SNDRV_CTL_ELEM_IFACE_PCM,
		.name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
		.info = fsl_xcvr_type_iec958_info,
		.get = fsl_xcvr_tx_cs_get,
		.put = fsl_xcvr_tx_cs_put,
	},
};

static struct snd_soc_dai_ops fsl_xcvr_dai_ops = {
	.prepare = fsl_xcvr_prepare,
	.startup = fsl_xcvr_startup,
	.shutdown = fsl_xcvr_shutdown,
	.trigger = fsl_xcvr_trigger,
	.hw_params = fsl_xcvr_hw_params,
};

static int fsl_xcvr_dai_probe(struct snd_soc_dai *dai)
{
	struct fsl_xcvr *xcvr = snd_soc_dai_get_drvdata(dai);

	snd_soc_dai_init_dma_data(dai, &xcvr->dma_prms_tx, &xcvr->dma_prms_rx);
	snd_soc_dai_set_drvdata(dai, xcvr);

	if (xcvr->mode & FSL_XCVR_DMODE_TX)
		snd_soc_add_dai_controls(dai, fsl_xcvr_tx_ctls,
					 ARRAY_SIZE(fsl_xcvr_tx_ctls));
	if (xcvr->mode & FSL_XCVR_DMODE_RX)
		snd_soc_add_dai_controls(dai, fsl_xcvr_rx_ctls,
					 ARRAY_SIZE(fsl_xcvr_rx_ctls));
	return 0;
}

static const struct snd_soc_pcm_stream playback = {
	.stream_name = "CPU-Playback",
	.channels_min = 1,
	.channels_max = 32,
	.rate_min = 32000,
	.rate_max = 1536000,
	.rates = SNDRV_PCM_RATE_KNOT,
	.formats = FSL_XCVR_FORMATS,
};

static const struct snd_soc_pcm_stream capture = {
	.stream_name = "CPU-Capture",
	.channels_min = 1,
	.channels_max = 32,
	.rate_min = 32000,
	.rate_max = 1536000,
	.rates = SNDRV_PCM_RATE_KNOT,
	.formats = FSL_XCVR_FORMATS,
};

static struct snd_soc_dai_driver fsl_xcvr_dai = {
	.probe  = fsl_xcvr_dai_probe,
	.ops = &fsl_xcvr_dai_ops,
};

static const struct snd_soc_component_driver fsl_xcvr_comp = {
	.name = "fsl-xcvr-dai",
};

static const struct reg_default fsl_xcvr_reg_defaults[] = {
	{ FSL_XCVR_VERSION,	0x00000000 },
	{ FSL_XCVR_EXT_CTRL,	0xF8204040 },
	{ FSL_XCVR_EXT_STATUS,	0x00000000 },
	{ FSL_XCVR_EXT_IER0,	0x00000000 },
	{ FSL_XCVR_EXT_IER1,	0x00000000 },
	{ FSL_XCVR_EXT_ISR,	0x00000000 },
	{ FSL_XCVR_EXT_ISR_SET,	0x00000000 },
	{ FSL_XCVR_EXT_ISR_CLR,	0x00000000 },
	{ FSL_XCVR_EXT_ISR_TOG,	0x00000000 },
	{ FSL_XCVR_IER,		0x00000000 },
	{ FSL_XCVR_ISR,		0x00000000 },
	{ FSL_XCVR_ISR_SET,	0x00000000 },
	{ FSL_XCVR_ISR_CLR,	0x00000000 },
	{ FSL_XCVR_ISR_TOG,	0x00000000 },
	{ FSL_XCVR_RX_DPTH_CTRL,	0x00002C89 },
	{ FSL_XCVR_RX_DPTH_CTRL_SET,	0x00002C89 },
	{ FSL_XCVR_RX_DPTH_CTRL_CLR,	0x00002C89 },
	{ FSL_XCVR_RX_DPTH_CTRL_TOG,	0x00002C89 },
	{ FSL_XCVR_RX_CS_DATA_0,	0x00000000 },
	{ FSL_XCVR_RX_CS_DATA_1,	0x00000000 },
	{ FSL_XCVR_RX_CS_DATA_2,	0x00000000 },
	{ FSL_XCVR_RX_CS_DATA_3,	0x00000000 },
	{ FSL_XCVR_RX_CS_DATA_4,	0x00000000 },
	{ FSL_XCVR_RX_CS_DATA_5,	0x00000000 },
	{ FSL_XCVR_TX_DPTH_CTRL,	0x00000000 },
	{ FSL_XCVR_TX_DPTH_CTRL_SET,	0x00000000 },
	{ FSL_XCVR_TX_DPTH_CTRL_CLR,	0x00000000 },
	{ FSL_XCVR_TX_DPTH_CTRL_TOG,	0x00000000 },
	{ FSL_XCVR_TX_CS_DATA_0,	0x00000000 },
	{ FSL_XCVR_TX_CS_DATA_1,	0x00000000 },
	{ FSL_XCVR_TX_CS_DATA_2,	0x00000000 },
	{ FSL_XCVR_TX_CS_DATA_3,	0x00000000 },
	{ FSL_XCVR_TX_CS_DATA_4,	0x00000000 },
	{ FSL_XCVR_TX_CS_DATA_5,	0x00000000 },
	{ FSL_XCVR_DEBUG_REG_0,		0x00000000 },
	{ FSL_XCVR_DEBUG_REG_1,		0x00000000 },
};

static bool fsl_xcvr_readable_reg(struct device *dev, unsigned int reg)
{
	switch (reg) {
	case FSL_XCVR_VERSION:
	case FSL_XCVR_EXT_CTRL:
	case FSL_XCVR_EXT_STATUS:
	case FSL_XCVR_EXT_IER0:
	case FSL_XCVR_EXT_IER1:
	case FSL_XCVR_EXT_ISR:
	case FSL_XCVR_EXT_ISR_SET:
	case FSL_XCVR_EXT_ISR_CLR:
	case FSL_XCVR_EXT_ISR_TOG:
	case FSL_XCVR_IER:
	case FSL_XCVR_ISR:
	case FSL_XCVR_ISR_SET:
	case FSL_XCVR_ISR_CLR:
	case FSL_XCVR_ISR_TOG:
	case FSL_XCVR_PHY_AI_CTRL:
	case FSL_XCVR_PHY_AI_CTRL_SET:
	case FSL_XCVR_PHY_AI_CTRL_CLR:
	case FSL_XCVR_PHY_AI_CTRL_TOG:
	case FSL_XCVR_PHY_AI_RDATA:
	case FSL_XCVR_CLK_CTRL:
	case FSL_XCVR_RX_DPTH_CTRL:
	case FSL_XCVR_RX_DPTH_CTRL_SET:
	case FSL_XCVR_RX_DPTH_CTRL_CLR:
	case FSL_XCVR_RX_DPTH_CTRL_TOG:
	case FSL_XCVR_RX_CS_DATA_0:
	case FSL_XCVR_RX_CS_DATA_1:
	case FSL_XCVR_RX_CS_DATA_2:
	case FSL_XCVR_RX_CS_DATA_3:
	case FSL_XCVR_RX_CS_DATA_4:
	case FSL_XCVR_RX_CS_DATA_5:
	case FSL_XCVR_TX_DPTH_CTRL:
	case FSL_XCVR_TX_DPTH_CTRL_SET:
	case FSL_XCVR_TX_DPTH_CTRL_CLR:
	case FSL_XCVR_TX_DPTH_CTRL_TOG:
	case FSL_XCVR_TX_CS_DATA_0:
	case FSL_XCVR_TX_CS_DATA_1:
	case FSL_XCVR_TX_CS_DATA_2:
	case FSL_XCVR_TX_CS_DATA_3:
	case FSL_XCVR_TX_CS_DATA_4:
	case FSL_XCVR_TX_CS_DATA_5:
	case FSL_XCVR_DEBUG_REG_0:
	case FSL_XCVR_DEBUG_REG_1:
		return true;
	default:
		return false;
	}
}

static bool fsl_xcvr_writeable_reg(struct device *dev, unsigned int reg)
{
	switch (reg) {
	case FSL_XCVR_EXT_CTRL:
	case FSL_XCVR_EXT_IER0:
	case FSL_XCVR_EXT_IER1:
	case FSL_XCVR_EXT_ISR:
	case FSL_XCVR_EXT_ISR_SET:
	case FSL_XCVR_EXT_ISR_CLR:
	case FSL_XCVR_EXT_ISR_TOG:
	case FSL_XCVR_IER:
	case FSL_XCVR_ISR_SET:
	case FSL_XCVR_ISR_CLR:
	case FSL_XCVR_ISR_TOG:
	case FSL_XCVR_PHY_AI_CTRL:
	case FSL_XCVR_PHY_AI_CTRL_SET:
	case FSL_XCVR_PHY_AI_CTRL_CLR:
	case FSL_XCVR_PHY_AI_CTRL_TOG:
	case FSL_XCVR_PHY_AI_WDATA:
	case FSL_XCVR_CLK_CTRL:
	case FSL_XCVR_RX_DPTH_CTRL:
	case FSL_XCVR_RX_DPTH_CTRL_SET:
	case FSL_XCVR_RX_DPTH_CTRL_CLR:
	case FSL_XCVR_RX_DPTH_CTRL_TOG:
	case FSL_XCVR_TX_DPTH_CTRL_SET:
	case FSL_XCVR_TX_DPTH_CTRL_CLR:
	case FSL_XCVR_TX_DPTH_CTRL_TOG:
	case FSL_XCVR_TX_CS_DATA_0:
	case FSL_XCVR_TX_CS_DATA_1:
	case FSL_XCVR_TX_CS_DATA_2:
	case FSL_XCVR_TX_CS_DATA_3:
	case FSL_XCVR_TX_CS_DATA_4:
	case FSL_XCVR_TX_CS_DATA_5:
		return true;
	default:
		return false;
	}
}

static bool fsl_xcvr_volatile_reg(struct device *dev, unsigned int reg)
{
	return fsl_xcvr_readable_reg(dev, reg);
}

static const struct regmap_config fsl_xcvr_regmap_cfg = {
	.reg_bits = 32,
	.reg_stride = 4,
	.val_bits = 32,
	.max_register = FSL_XCVR_MAX_REG,
	.reg_defaults = fsl_xcvr_reg_defaults,
	.num_reg_defaults = ARRAY_SIZE(fsl_xcvr_reg_defaults),
	.readable_reg = fsl_xcvr_readable_reg,
	.volatile_reg = fsl_xcvr_volatile_reg,
	.writeable_reg = fsl_xcvr_writeable_reg,
	.cache_type = REGCACHE_FLAT,
};

static irqreturn_t irq0_isr(int irq, void *devid)
{
	struct fsl_xcvr *xcvr = (struct fsl_xcvr *)devid;
	struct device *dev = &xcvr->pdev->dev;
	struct regmap *regmap = xcvr->regmap;
	u32 isr, val, csv, i;

	regmap_read(regmap, FSL_XCVR_EXT_ISR, &isr);
	regmap_write(regmap, FSL_XCVR_EXT_ISR_CLR, isr);

	if (isr & FSL_XCVR_IRQ_NEW_CS) {
		dev_dbg(dev, "Received new CS block\n");
		for (i = 0; i < 6; i++) {
			regmap_read(regmap, FSL_XCVR_RX_CS_DATA_0 + 4*i, &val);
			csv = bitrev32(val);
			xcvr->rx_iec958.status[0 + (i*4)] = (csv >> 24) & 0xFF;
			xcvr->rx_iec958.status[1 + (i*4)] = (csv >> 16) & 0xFF;
			xcvr->rx_iec958.status[2 + (i*4)] = (csv >>  8) & 0xFF;
			xcvr->rx_iec958.status[3 + (i*4)] = (csv >>  0) & 0xFF;
		}
	}
	if (isr & FSL_XCVR_IRQ_NEW_UD)
		dev_dbg(dev, "Received new UD block\n");
	if (isr & FSL_XCVR_IRQ_MUTE)
		dev_dbg(dev, "HW mute bit detected\n");
	if (isr & FSL_XCVR_IRQ_FIFO_UOFL_ERR)
		dev_dbg(dev, "RX/TX FIFO full/empty\n");
	if (isr & FSL_XCVR_IRQ_ARC_MODE)
		dev_dbg(dev, "CMDC SM falls out of eARC mode\n");
	if (isr & FSL_XCVR_IRQ_DMA_RD_REQ)
		dev_dbg(dev, "DMA read request\n");
	if (isr & FSL_XCVR_IRQ_DMA_WR_REQ)
		dev_dbg(dev, "DMA write request\n");

	return IRQ_HANDLED;
}

static irqreturn_t irq1_isr(int irq, void *devid)
{
	struct fsl_xcvr *xcvr = (struct fsl_xcvr *)devid;
	struct device *dev = &xcvr->pdev->dev;

	dev_dbg(dev, "irq[1]: %d\n", irq);

	return IRQ_HANDLED;
}

static irqreturn_t irq2_isr(int irq, void *devid)
{
	struct fsl_xcvr *xcvr = (struct fsl_xcvr *)devid;
	struct device *dev = &xcvr->pdev->dev;

	dev_dbg(dev, "irq[2]: %d\n", irq);

	return IRQ_HANDLED;
}

static const struct of_device_id fsl_xcvr_dt_ids[] = {
	{ .compatible = "fsl,imx8mp-xcvr", },
	{ }
};
MODULE_DEVICE_TABLE(of, fsl_xcvr_dt_ids);

static int fsl_xcvr_probe(struct platform_device *pdev)
{
	struct device *dev = &pdev->dev;
	struct device_node *np = dev->of_node;
	const struct of_device_id *of_id;
	struct fsl_xcvr *xcvr;
	struct resource *res,
		ram_res = { .flags = IORESOURCE_MEM, },
		regs_res = { .flags = IORESOURCE_MEM, };
	void __iomem *regs;
	int ret, irq;

	of_id = of_match_device(fsl_xcvr_dt_ids, dev);
	if (!of_id)
		return -EINVAL;

	xcvr = devm_kzalloc(dev, sizeof(*xcvr), GFP_KERNEL);
	if (!xcvr)
		return -ENOMEM;

	xcvr->pdev = pdev;
	xcvr->ipg_clk = devm_clk_get(dev, "ipg");
	if (IS_ERR(xcvr->ipg_clk)) {
		dev_err(dev, "failed to get ipg clock\n");
		return PTR_ERR(xcvr->ipg_clk);
	}

	xcvr->phy_clk = devm_clk_get(dev, "phy");
	if (IS_ERR(xcvr->phy_clk)) {
		dev_err(dev, "failed to get phy clock\n");
		return PTR_ERR(xcvr->phy_clk);
	}

	xcvr->spba_clk = devm_clk_get(dev, "spba");
	if (IS_ERR(xcvr->spba_clk)) {
		dev_err(dev, "failed to get spba clock\n");
		return PTR_ERR(xcvr->spba_clk);
	}

	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);

	ram_res.start = res->start;
	ram_res.end = res->start + FSL_XCVR_REG_OFFSET - 1;
	xcvr->ram_addr = devm_ioremap_resource(dev, &ram_res);
	if (IS_ERR(xcvr->ram_addr))
		return PTR_ERR(xcvr->ram_addr);

	regs_res.start = res->start + FSL_XCVR_REG_OFFSET;
	regs_res.end = res->end;
	regs = devm_ioremap_resource(dev, &regs_res);
	if (IS_ERR(regs))
		return PTR_ERR(regs);

	xcvr->regmap = devm_regmap_init_mmio_clk(dev, NULL, regs,
						 &fsl_xcvr_regmap_cfg);
	if (IS_ERR(xcvr->regmap)) {
		dev_err(dev, "failed to init XCVR regmap: %ld\n",
			PTR_ERR(xcvr->regmap));
		return PTR_ERR(xcvr->regmap);
	}

	xcvr->reset = of_reset_control_get(np, NULL);

	ret = of_property_read_string(np, "fsl,xcvr-fw", &xcvr->fw_name);
	if (ret) {
		dev_err(dev, "failed to get fsl,xcvr-fw: %d\n", ret);
		return ret;
	}

	ret = of_property_read_u32(np, "fsl,xcvr-mode", &xcvr->mode);
	if (ret) {
		dev_err(dev, "failed to get fsl,xcvr-mode: %d\n", ret);
		return ret;
	}

	dev_info(dev, "fsl,xcvr-mode: %x\n", xcvr->mode);
	switch (xcvr->mode & FSL_XCVR_AMODE_MASK) {
	case FSL_XCVR_AMODE_SPDIF:
		dev_info(dev, "Setting SPDIF mode ...\n");
		break;
	case FSL_XCVR_AMODE_ARC:
		dev_info(dev, "Setting ARC mode ...\n");
		break;
	case FSL_XCVR_AMODE_EARC:
		dev_info(dev, "Setting EARC mode ...\n");
		break;
	default:
		dev_err(dev, "Unknown mode ...\n");
		break;
	}

	if (!(xcvr->mode & FSL_XCVR_DMODE_MASK)) {
		dev_err(dev, "RX, TX or both must be set, mode=%x\n",
			xcvr->mode);
		return -EINVAL;
	}

	if ((xcvr->mode & FSL_XCVR_AMODE_MASK) == FSL_XCVR_AMODE_RESERVED) {
		dev_err(dev, "wrong AMODE set, mode=%x\n", xcvr->mode);
		return -EINVAL;
	}

	/* get IRQs */
	irq = platform_get_irq(pdev, 0);
	if (irq < 0) {
		dev_err(dev, "no irq[0]: %d\n", irq);
		return irq;
	}

	ret = devm_request_irq(dev, irq, irq0_isr, 0, pdev->name, xcvr);
	if (ret) {
		dev_err(dev, "failed to claim IRQ0: %i\n", ret);
		return ret;
	}

	irq = platform_get_irq(pdev, 1);
	if (irq < 0) {
		dev_err(dev, "no irq[1]: %d\n", irq);
		return irq;
	}

	ret = devm_request_irq(dev, irq, irq1_isr, 0, pdev->name, xcvr);
	if (ret) {
		dev_err(dev, "failed to claim IRQ1: %i\n", ret);
		return ret;
	}

	irq = platform_get_irq(pdev, 2);
	if (irq < 0) {
		dev_err(dev, "no irq[2]: %d\n", irq);
		return irq;
	}

	ret = devm_request_irq(dev, irq, irq2_isr, 0, pdev->name, xcvr);
	if (ret) {
		dev_err(dev, "failed to claim IRQ2: %i\n", ret);
		return ret;
	}

	xcvr->dma_prms_rx.chan_name = "rx";
	xcvr->dma_prms_tx.chan_name = "tx";
	xcvr->dma_prms_rx.addr = res->start + FSL_XCVR_RX_FIFO_ADDR;
	xcvr->dma_prms_tx.addr = res->start + FSL_XCVR_TX_FIFO_ADDR;
	xcvr->dma_prms_rx.maxburst = FSL_XCVR_MAXBURST_RX;
	xcvr->dma_prms_tx.maxburst = FSL_XCVR_MAXBURST_TX;

	platform_set_drvdata(pdev, xcvr);
	pm_runtime_enable(dev);

	if (xcvr->mode & FSL_XCVR_DMODE_TX)
		fsl_xcvr_dai.playback = playback;

	if (xcvr->mode & FSL_XCVR_DMODE_RX)
		fsl_xcvr_dai.capture = capture;

	ret = devm_snd_soc_register_component(dev, &fsl_xcvr_comp,
					      &fsl_xcvr_dai, 1);
	if (ret) {
		dev_err(dev, "failed to register component %s\n",
			fsl_xcvr_comp.name);
		return ret;
	}

	ret = imx_pcm_platform_register(dev);
	if (ret)
		dev_err(dev, "failed to pcm register\n");

	return ret;
}

#ifdef CONFIG_PM
static int fsl_xcvr_runtime_suspend(struct device *dev)
{
	struct fsl_xcvr *xcvr = dev_get_drvdata(dev);
	int ret;

	/* Assert M0+ reset */
	ret = regmap_update_bits(xcvr->regmap, FSL_XCVR_EXT_CTRL,
				 FSL_XCVR_EXT_CTRL_CORE_RESET,
				 FSL_XCVR_EXT_CTRL_CORE_RESET);
	if (ret < 0)
		dev_err(dev, "Failed to assert M0+ core: %d\n", ret);

	regcache_cache_only(xcvr->regmap, true);

	clk_disable_unprepare(xcvr->spba_clk);
	clk_disable_unprepare(xcvr->phy_clk);
	clk_disable_unprepare(xcvr->ipg_clk);

	return 0;
}

static int fsl_xcvr_runtime_resume(struct device *dev)
{
	struct fsl_xcvr *xcvr = dev_get_drvdata(dev);
	int ret;

	ret = clk_prepare_enable(xcvr->ipg_clk);
	if (ret) {
		dev_err(dev, "failed to start IPG clock.\n");
		return ret;
	}

	ret = clk_prepare_enable(xcvr->phy_clk);
	if (ret) {
		dev_err(dev, "failed to start PHY clock.\n");
		clk_disable_unprepare(xcvr->ipg_clk);
		return ret;
	}

	ret = clk_prepare_enable(xcvr->spba_clk);
	if (ret) {
		dev_err(dev, "failed to start SPBA clock.\n");
		clk_disable_unprepare(xcvr->phy_clk);
		clk_disable_unprepare(xcvr->ipg_clk);
		return ret;
	}

	regcache_cache_only(xcvr->regmap, false);
	regcache_mark_dirty(xcvr->regmap);
	ret = regcache_sync(xcvr->regmap);

	if (ret) {
		dev_err(dev, "failed to sync regcache.\n");
		return ret;
	}

	reset_control_assert(xcvr->reset);
	reset_control_deassert(xcvr->reset);

	ret = fsl_xcvr_load_firmware(xcvr);
	if (ret) {
		dev_err(dev, "failed to load firmware.\n");
		return ret;
	}

	/* Release M0+ reset */
	ret = regmap_update_bits(xcvr->regmap, FSL_XCVR_EXT_CTRL,
				 FSL_XCVR_EXT_CTRL_CORE_RESET, 0);
	if (ret < 0) {
		dev_err(dev, "Failed to release M0+ core: %d\n", ret);
		return ret;
	}

	return 0;
}
#endif /* CONFIG_PM*/

static const struct dev_pm_ops fsl_xcvr_pm_ops = {
	SET_RUNTIME_PM_OPS(fsl_xcvr_runtime_suspend,
			   fsl_xcvr_runtime_resume,
			   NULL)
	SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
				pm_runtime_force_resume)
};

static struct platform_driver fsl_xcvr_driver = {
	.probe = fsl_xcvr_probe,
	.driver = {
		.name = "fsl,imx8mp-audio-xcvr",
		.pm = &fsl_xcvr_pm_ops,
		.of_match_table = fsl_xcvr_dt_ids,
	},
};
module_platform_driver(fsl_xcvr_driver);

MODULE_AUTHOR("Viorel Suman <viorel.suman@nxp.com>");
MODULE_DESCRIPTION("NXP Audio Transceiver (XCVR) driver");
MODULE_LICENSE("GPL v2");