aboutsummaryrefslogtreecommitdiff
path: root/arch/arm/mach-ux500/include/mach/msp.h
blob: a8b61173062d08d5406e1d5c209e73e1a4384383 (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
/*
 * Copyright (c) 2009 STMicroelectronics
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2
 * as published by the Free Software Foundation.
 */

#ifndef _STM_MSP_HEADER
#define _STM_MSP_HEADER
#include <linux/device.h>
#include <linux/spinlock.h>
#include <linux/i2s/i2s.h>
#include <asm/dma.h>
#include <mach/dma.h>
#include <linux/irqreturn.h>
/* Generic config struct. Use the actual values defined below for global
 * control register
 */
typedef enum {
	MSP_INF_TRANSFER_DISABLED = 0,
	MSP_INF_TRANSFER_ENABLED = 1
} t_msp_inf_transfer_enable;

typedef enum {
	MSP_MULTICHANNEL_DISABLED = 0,
	MSP_MULTICHANNEL_ENABLED = 1
} t_msp_multichannel_enable;

typedef enum {
	MSP_STATE_IDLE = 0,
	MSP_STATE_CONFIGURED = 1,
	MSP_STATE_RUN = 2,
} t_msp_state;

typedef enum {
	MSP_COMPARISON_DISABLED = 0,
	MSP_COMPARISON_NONEQUAL_ENABLED = 2,
	MSP_COMPARISON_EQUAL_ENABLED = 3
} t_msp_rx_comparison_enable_mode;

#define RMCEN_BIT   0
#define RMCSF_BIT   1
#define RCMPM_BIT   3
#define TMCEN_BIT   5
#define TNCSF_BIT   6

typedef struct {
	t_msp_multichannel_enable rx_multichannel_enable;
	t_msp_multichannel_enable tx_multichannel_enable;
	t_msp_rx_comparison_enable_mode rx_comparison_enable_mode;
	u8 padding;
	u32 comparison_value;
	u32 comparison_mask;
	u32 rx_channel_0_enable;
	u32 rx_channel_1_enable;
	u32 rx_channel_2_enable;
	u32 rx_channel_3_enable;
	u32 tx_channel_0_enable;
	u32 tx_channel_1_enable;
	u32 tx_channel_2_enable;
	u32 tx_channel_3_enable;
} t_msp_multichannel_config;

enum msp_data_size {
	MSP_DATA_SIZE_DEFAULT = -1,
	MSP_DATA_SIZE_8BIT,
	MSP_DATA_SIZE_10BIT,
	MSP_DATA_SIZE_12BIT,
	MSP_DATA_SIZE_14BIT,
	MSP_DATA_SIZE_16BIT,
	MSP_DATA_SIZE_20BIT,
	MSP_DATA_SIZE_24BIT,
	MSP_DATA_SIZE_32BIT,
};

/**
 * struct msp_protocol_desc- MSP Protocol desc structure per MSP.
 * @rx_phase_mode: rx_phase_mode whether single or dual.
 * @tx_phase_mode: tx_phase_mode whether single or dual.
 * @rx_phase2_start_mode: rx_phase2_start_mode whether imediate or after
 * some delay.
 * @tx_phase2_start_mode: tx_phase2_start_mode whether imediate or after
 * some delay.
 * @rx_bit_transfer_format: MSP or LSB.
 * @tx_bit_transfer_format: MSP or LSB.
 * @rx_frame_length_1: Frame1 length 1,2,3..
 * @rx_frame_length_2: Frame2 length 1,2,3..
 * @tx_frame_length_1: Frame1 length 1,2,3..
 * @tx_frame_length_2: Frame2 length 1,2,3..
 * @rx_element_length_1: Element1 length 1,2,...
 * @rx_element_length_2: Element2 length 1,2,...
 * @tx_element_length_1: Element1 length 1,2,...
 * @tx_element_length_2: Element2 length 1,2,...
 * @rx_data_delay: Delay in clk cycle after frame sync
 * @tx_data_delay: Delay in clk cycle after frame sync
 * @rx_clock_pol: Rxpol whether rising or falling.It indicates pol of bit clock.
 * @tx_clock_pol: Txpol whether rising or falling.It indicates pol of bit clock.
 * @rx_frame_sync_pol: Frame sync pol whether rising or Falling.
 * @tx_frame_sync_pol: Frame sync pol whether rising or Falling.
 * @rx_half_word_swap: Word swap half word, full word.
 * @tx_half_word_swap: Word swap half word, full word.
 * @compression_mode: Compression mode whether Alaw or Ulaw or disabled.
 * @expansion_mode: Compression mode whether Alaw or Ulaw or disabled.
 * @spi_clk_mode: Spi clock mode to be enabled or not.
 * @spi_burst_mode: Spi burst mode to be enabled or not.
 * @frame_sync_ignore: Frame sync to be ignored or not. Ignore in case of Audio
 * codec acting as Master.
 * @frame_period: Frame period (clk cycles) after which new frame sync occurs.
 * @frame_width: Frame width (clk cycles) after which frame sycn changes state.
 * @total_clocks_for_one_frame: No. of clk cycles per frame.
 *
 * Main Msp protocol descriptor data structure to be used to store various info
 * in transmit or recevie configuration registers of an MSP.
 */

struct msp_protocol_desc {
	u32 rx_phase_mode;
	u32 tx_phase_mode;
	u32 rx_phase2_start_mode;
	u32 tx_phase2_start_mode;
	u32 rx_bit_transfer_format;
	u32 tx_bit_transfer_format;
	u32 rx_frame_length_1;
	u32 rx_frame_length_2;
	u32 tx_frame_length_1;
	u32 tx_frame_length_2;
	u32 rx_element_length_1;
	u32 rx_element_length_2;
	u32 tx_element_length_1;
	u32 tx_element_length_2;
	u32 rx_data_delay;
	u32 tx_data_delay;
	u32 rx_clock_pol;
	u32 tx_clock_pol;
	u32 rx_frame_sync_pol;
	u32 tx_frame_sync_pol;
	u32 rx_half_word_swap;
	u32 tx_half_word_swap;
	u32 compression_mode;
	u32 expansion_mode;
	u32 spi_clk_mode;
	u32 spi_burst_mode;
	u32 frame_sync_ignore;
	u32 frame_period;
	u32 frame_width;
	u32 total_clocks_for_one_frame;
};

/**
 * struct trans_data - MSP transfer data structure used during xfer.
 * @message: i2s message.
 * @msp: msp structure.
 * @tx_handler: callback handler for transmit path.
 * @rx_handler: callback handler for receive path.
 * @tx_callback_data: callback data for transmit.
 * @rx_callback_data: callback data for receive.
 *
 */
struct trans_data {
	struct i2s_message message;
	struct msp_struct *msp;
	 irqreturn_t(*tx_handler) (void *data, int irq);
	 irqreturn_t(*rx_handler) (void *data, int irq);
	void *tx_callback_data;
	void *rx_callback_data;
};

/**
 * struct msp_generic_config- MSP configuration structure used by i2s client.
 * @input_clock_freq: Input clock frequency default is 48MHz.
 * @rx_clock_sel: Receive clock selection (Provided by Sample Gen or external
 * source).
 * @tx_clock_sel: Transmit clock selection (Provided by Sample Gen or external.
 * source).
 * @srg_clock_sel: APB clock or clock dervied from Slave (Audio codec).
 * @rx_frame_sync_pol: Receive frame sync polarity.
 * @tx_frame_sync_pol: Transmit frame sync polarity.
 * @rx_frame_sync_sel: Rx frame sync signal is provided by which source.
 * External source or by frame generator logic.
 * @tx_frame_sync_sel: Tx frame sync signal is provided by which source.
 * External source or by frame generator logic.
 * @rx_fifo_config: Receive fifo enable or not.
 * @tx_fifo_config: Transmit fifo enable or not.
 * @spi_clk_mode: In case of SPI protocol spi modes: Normal, Zero delay or
 * half cycle delay.
 * @spi_burst_mode: Spi burst mode is enabled or not.
 * @loopback_enable: Loopback mode.
 * @tx_data_enable: Transmit extra delay enable.
 * @default_protocol_desc: Flag to indicate client defined protocol desc or
 * statically defined in msp.h.
 * @protocol_desc: Protocol desc structure filled by i2s client driver.
 * In case client defined default_prtocol_desc as 0.
 * @multichannel_configured: multichannel configuration structure.
 * @multichannel_config: multichannel is enabled or not.
 * @direction: Transmit, Receive or Both.
 * @work_mode: Dma, Polling or Interrupt.
 * @protocol: I2S, PCM, etc.
 * @frame_freq: Sampling freq at which data is sampled.
 * @frame_size: size of element.
 * @data_size: data size which defines the format in which data is written on
 * transmit or receive fifo. Only three modes 8,16,32 are supported.
 * @def_elem_len: Flag to indicate whether default element length is to be used
 * or should be changed acc to data size defined by user at run time.
 * @handler: callback handler in case of interrupt or dma.
 * @tx_callback_data: Callback data for transmit.
 * @rx_callback_data: Callback data for receive.
 *
 * Main Msp configuration data structure used by i2s client driver to fill
 * various info like data size, frequency etc.
 */
struct msp_generic_config {
	unsigned int input_clock_freq;
	unsigned int rx_clock_sel;
	unsigned int tx_clock_sel;
	unsigned int srg_clock_sel;
	unsigned int rx_frame_sync_pol;
	unsigned int tx_frame_sync_pol;
	unsigned int rx_frame_sync_sel;
	unsigned int tx_frame_sync_sel;
	unsigned int rx_fifo_config;
	unsigned int tx_fifo_config;
	unsigned int spi_clk_mode;
	unsigned int spi_burst_mode;
	unsigned int loopback_enable;
	unsigned int tx_data_enable;
	unsigned int default_protocol_desc;
	struct msp_protocol_desc protocol_desc;
	int multichannel_configured;
	t_msp_multichannel_config multichannel_config;
	unsigned int direction;
	unsigned int work_mode;
	unsigned int protocol;
	unsigned int frame_freq;
	unsigned int frame_size;
	enum msp_data_size data_size;
	unsigned int def_elem_len;
	 irqreturn_t(*handler) (void *data, int err_or_data);
	void *tx_callback_data;
	void *rx_callback_data;

};

/*** Protocols ***/
enum {
	MSP_I2S_PROTOCOL,
	MSP_PCM_PROTOCOL,
	MSP_PCM_COMPAND_PROTOCOL,
	MSP_AC97_PROTOCOL,
	MSP_MASTER_SPI_PROTOCOL,
	MSP_SLAVE_SPI_PROTOCOL,
	MSP_INVALID_PROTOCOL
};

/*** Sample Frequencies ***/
/* These are no longer required, frequencies in Hz can be used directly */
enum {
	MSP_SAMPLE_FREQ_NOT_SUPPORTED = -1,
	MSP_SAMPLE_FREQ_8KHZ = 8000,
	MSP_SAMPLE_FREQ_12KHZ = 12000,
	MSP_SAMPLE_FREQ_16KHZ = 16000,
	MSP_SAMPLE_FREQ_24KHZ = 24000,
	MSP_SAMPLE_FREQ_32KHZ = 32000,
	MSP_SAMPLE_FREQ_44KHZ = 44000,
	MSP_SAMPLE_FREQ_48KHZ = 48000,
	MSP_SAMPLE_FREQ_64KHZ = 64000,
	MSP_SAMPLE_FREQ_88KHZ = 88000,
	MSP_SAMPLE_FREQ_96KHZ = 96000,
	MSP_SAMPLE_FREQ_22KHZ = 22000,
	MSP_SAMPLE_FREQ_11KHZ = 11000
};

/*** Input Frequencies ***/
/* These are no longer required, frequencies in Hz can be used directly */
typedef enum {
	MSP_INPUT_FREQ_1MHZ = 1000,
	MSP_INPUT_FREQ_2MHZ = 2000,
	MSP_INPUT_FREQ_3MHZ = 3000,
	MSP_INPUT_FREQ_4MHZ = 4000,
	MSP_INPUT_FREQ_5MHZ = 5000,
	MSP_INPUT_FREQ_6MHZ = 6000,
	MSP_INPUT_FREQ_8MHZ = 8000,
	MSP_INPUT_FREQ_11MHZ = 11000,
	MSP_INPUT_FREQ_12MHZ = 12000,
	MSP_INPUT_FREQ_16MHZ = 16000,
	MSP_INPUT_FREQ_22MHZ = 22000,
	MSP_INPUT_FREQ_24MHZ = 24000,
	MSP_INPUT_FREQ_48MHZ = 48000
} t_msp_in_clock_freq;

#define MSP_INPUT_FREQ_APB 48000000

/*** Stereo mode. Used for APB data accesses as 16 bits accesses (mono),
 *   32 bits accesses (stereo).
 ***/
enum {
	MSP_MONO,
	MSP_STEREO
};

/* Direction (Transmit/Receive mode) */
enum {
	MSP_TRANSMIT_MODE,
	MSP_RECEIVE_MODE,
	MSP_BOTH_T_R_MODE
};

/* Dma mode should be used for large transfers,
 * polling mode should be used for transfers of a few bytes
 */
enum {
	MSP_DMA_MODE,
	MSP_POLLING_MODE,
	MSP_INTERRUPT_MODE
};

/* User client for the MSP */
typedef enum {
	MSP_NO_USER = 0,
	MSP_USER_SPI,
	MSP_USER_ALSA,
	MSP_USER_SAA,
} t_msp_user;

/*Flag structure for MSPx*/
typedef struct {
	struct semaphore lock;
	t_msp_user user;
} msp_flag;

/* User client for the MSP */
typedef enum {
	MSP_NO_MODE = 0,
	MSP_MODE_SPI,
	MSP_MODE_NON_SPI,
} t_msp_mode;

/* Transmit and receive configuration register */
#define MSP_BIG_ENDIAN           0x00000000
#define MSP_LITTLE_ENDIAN        0x00001000
#define MSP_UNEXPECTED_FS_ABORT  0x00000000
#define MSP_UNEXPECTED_FS_IGNORE 0x00008000
#define MSP_NON_MODE_BIT_MASK    0x00009000

/* Global configuration register
--------------------------------*/
#define RX_ENABLE             0x00000001
#define RX_FIFO_ENABLE        0x00000002
#define RX_SYNC_SRG           0x00000010
#define RX_CLK_POL_RISING     0x00000020
#define RX_CLK_SEL_SRG        0x00000040
#define TX_ENABLE             0x00000100
#define TX_FIFO_ENABLE        0x00000200
#define TX_SYNC_SRG_PROG      0x00001800
#define TX_SYNC_SRG_AUTO      0x00001000
#define TX_CLK_POL_RISING     0x00002000
#define TX_CLK_SEL_SRG        0x00004000
#define TX_EXTRA_DELAY_ENABLE 0x00008000
#define SRG_ENABLE            0x00010000
#define FRAME_GEN_ENABLE      0x00100000
#define SRG_CLK_SEL_APB       0x00000000
#define RX_FIFO_SYNC_HI       0x00000000
#define TX_FIFO_SYNC_HI       0x00000000
#define SPI_CLK_MODE_NORMAL   0x00000000

/* SPI Clock Modes enumertion
 * SPI clock modes of MSP provides compatibility with
 * the SPI protocol.MSP supports 2 SPI transfer formats.
 * MSP_ZERO_DELAY_SPI_MODE:MSP transmits data over Tx/Rx
 * Lines immediately after MSPTCK/MSPRCK rising/falling edge.
 * MSP_HALF_CYCLE_DELY_SPI_MODE:MSP transmits data  one-half cycle
 * ahead of the rising/falling edge of the MSPTCK
 */
enum {
	MSP_NON_SPI_PROTOCOL = 0,
	MSP_ZERO_DELAY_SPI_MODE = 2,
	MSP_HALF_CYCLE_DELY_SPI_MODE = 3
};

#define MSP_FRAME_SIZE_AUTO -1


#define MSP_DR 		0x00
#define MSP_GCR		0x04
#define MSP_TCF		0x08
#define MSP_RCF		0x0c
#define MSP_SRG		0x10
#define MSP_FLR		0x14
#define MSP_DMACR	0x18

#define MSP_IMSC	0x20
#define MSP_RIS		0x24
#define MSP_MIS 	0x28
#define MSP_ICR		0x2c
#define MSP_MCR		0x30
#define MSP_RCV 	0x34
#define MSP_RCM 	0x38

#define MSP_TCE0	0x40
#define MSP_TCE1	0x44
#define MSP_TCE2 	0x48
#define MSP_TCE3 	0x4c

#define MSP_RCE0	0x60
#define MSP_RCE1	0x64
#define MSP_RCE2	0x68
#define MSP_RCE3 	0x6c

#define MSP_ITCR	0x80
#define MSP_ITIP	0x84
#define MSP_ITOP	0x88
#define MSP_TSTDR	0x8c

#define MSP_PID0	0xfe0
#define MSP_PID1	0xfe4
#define MSP_PID2 	0xfe8
#define MSP_PID3	0xfec

#define MSP_CID0	0xff0
#define MSP_CID1 	0xff4
#define MSP_CID2	0xff8
#define MSP_CID3 	0xffc

/* Single or dual phase mode */
enum {
	MSP_SINGLE_PHASE,
	MSP_DUAL_PHASE
};

/* Frame length
------------------*/
enum {
	MSP_FRAME_LENGTH_1 = 0,
	MSP_FRAME_LENGTH_2 = 1,
	MSP_FRAME_LENGTH_4 = 3,
	MSP_FRAME_LENGTH_8 = 7,
	MSP_FRAME_LENGTH_12 = 11,
	MSP_FRAME_LENGTH_16 = 15,
	MSP_FRAME_LENGTH_20 = 19,
	MSP_FRAME_LENGTH_32 = 31,
	MSP_FRAME_LENGTH_48 = 47,
	MSP_FRAME_LENGTH_64 = 63
};

/* Element length */
enum {
	MSP_ELEM_LENGTH_8 = 0,
	MSP_ELEM_LENGTH_10 = 1,
	MSP_ELEM_LENGTH_12 = 2,
	MSP_ELEM_LENGTH_14 = 3,
	MSP_ELEM_LENGTH_16 = 4,
	MSP_ELEM_LENGTH_20 = 5,
	MSP_ELEM_LENGTH_24 = 6,
	MSP_ELEM_LENGTH_32 = 7
};
enum {
	MSP_DATA_TRANSFER_WIDTH_BYTE,
	MSP_DATA_TRANSFER_WIDTH_HALFWORD,
	MSP_DATA_TRANSFER_WIDTH_WORD
};
enum {
	MSP_FRAME_SYNC_UNIGNORE = 0,
	MSP_FRAME_SYNC_IGNORE = 1,

};
enum {
	MSP_PHASE2_START_MODE_IMEDIATE,
	MSP_PHASE2_START_MODE_FRAME_SYNC
};
enum {
	MSP_BTF_MS_BIT_FIRST = 0,
	MSP_BTF_LS_BIT_FIRST = 1
};

enum {
	MSP_FRAME_SYNC_POL_ACTIVE_HIGH = 0,
	MSP_FRAME_SYNC_POL_ACTIVE_LOW = 1
};
/* Data delay (in bit clock cycles)
---------------------------------------*/
enum {
	MSP_DELAY_0 = 0,
	MSP_DELAY_1 = 1,
	MSP_DELAY_2 = 2,
	MSP_DELAY_3 = 3
};

/* Configurations of clocks (transmit, receive or sample rate generator)
-------------------------------------------------------------------------*/
enum {
	MSP_FALLING_EDGE = 0,
	MSP_RISING_EDGE = 1,
};

enum {
	MSP_HWS_NO_SWAP = 0,
	MSP_HWS_BYTE_SWAP_IN_WORD = 1,
	MSP_HWS_BYTE_SWAP_IN_EACH_HALF_WORD = 2,
	MSP_HWS_HALF_WORD_SWAP_IN_WORD = 3
};
enum {
	MSP_COMPRESS_MODE_LINEAR = 0,
	MSP_COMPRESS_MODE_MU_LAW = 2,
	MSP_COMPRESS_MODE_A_LAW = 3
};
enum {
	MSP_SPI_CLOCK_MODE_NON_SPI = 0,
	MSP_SPI_CLOCK_MODE_ZERO_DELAY = 2,
	MSP_SPI_CLOCK_MODE_HALF_CYCLE_DELAY = 3
};
enum {
	MSP_SPI_BURST_MODE_DISABLE = 0,
	MSP_SPI_BURST_MODE_ENABLE = 1
};
enum {
	MSP_EXPAND_MODE_LINEAR = 0,
	MSP_EXPAND_MODE_LINEAR_SIGNED = 1,
	MSP_EXPAND_MODE_MU_LAW = 2,
	MSP_EXPAND_MODE_A_LAW = 3
};
/* Protocol dependant parameters list */
#define RX_ENABLE_MASK         0x00000001
#define RX_FIFO_ENABLE_MASK    0x00000002
#define RX_FRAME_SYNC_MASK     0x00000004
#define DIRECT_COMPANDING_MASK 0x00000008
#define RX_SYNC_SEL_MASK       0x00000010
#define RX_CLK_POL_MASK        0x00000020
#define RX_CLK_SEL_MASK        0x00000040
#define LOOPBACK_MASK          0x00000080
#define TX_ENABLE_MASK         0x00000100
#define TX_FIFO_ENABLE_MASK    0x00000200
#define TX_FRAME_SYNC_MASK     0x00000400
#define TX_MSP_TDR_TSR         0x00000800
#define TX_SYNC_SEL_MASK       0x00001800
#define TX_CLK_POL_MASK        0x00002000
#define TX_CLK_SEL_MASK        0x00004000
#define TX_EXTRA_DELAY_MASK    0x00008000
#define SRG_ENABLE_MASK        0x00010000
#define SRG_CLK_POL_MASK       0x00020000
#define SRG_CLK_SEL_MASK       0x000C0000
#define FRAME_GEN_EN_MASK      0x00100000
#define SPI_CLK_MODE_MASK      0x00600000
#define SPI_BURST_MODE_MASK    0x00800000

#define RXEN_BIT		0
#define RFFEN_BIT		1
#define RFSPOL_BIT		2
#define DCM_BIT		3
#define RFSSEL_BIT		4
#define RCKPOL_BIT		5
#define RCKSEL_BIT		6
#define LBM_BIT		7
#define TXEN_BIT		8
#define TFFEN_BIT		9
#define TFSPOL_BIT		10
#define TFSSEL_BIT		11
#define TCKPOL_BIT		13
#define TCKSEL_BIT		14
#define TXDDL_BIT		15
#define SGEN_BIT		16
#define SCKPOL_BIT		17
#define SCKSEL_BIT		18
#define FGEN_BIT		20
#define SPICKM_BIT		21
#define TBSWAP_BIT      28

#define msp_rx_clkpol_bit(n)     ((n & 1) << RCKPOL_BIT)
#define msp_tx_clkpol_bit(n)     ((n & 1) << TCKPOL_BIT)
#define msp_spi_clk_mode_bits(n) ((n & 3) << SPICKM_BIT)

/* Use this to clear the clock mode bits to non-spi */
#define MSP_NON_SPI_CLK_MASK 0x00600000

#define P1ELEN_BIT		0
#define P1FLEN_BIT		3
#define DTYP_BIT		10
#define ENDN_BIT		12
#define DDLY_BIT		13
#define FSIG_BIT		15
#define P2ELEN_BIT		16
#define P2FLEN_BIT		19
#define P2SM_BIT		26
#define P2EN_BIT		27
#define FRAME_SYNC_BIT		15

#define msp_p1_elem_len_bits(n) (n & 0x00000007)
#define msp_p2_elem_len_bits(n)  (((n) << P2ELEN_BIT) & 0x00070000)
#define msp_p1_frame_len_bits(n) (((n) << P1FLEN_BIT) & 0x00000378)
#define msp_p2_frame_len_bits(n) (((n) << P2FLEN_BIT) & 0x03780000)
#define msp_data_delay_bits(n)   (((n) << DDLY_BIT) & 0x00003000)
#define msp_data_type_bits(n)    (((n) << DTYP_BIT) & 0x00000600)
#define msp_p2_start_mode_bit(n) ((n << P2SM_BIT) & 0x04000000)
#define msp_p2_enable_bit(n)     ((n << P2EN_BIT) & 0x08000000)
#define msp_set_endiannes_bit(n) ((n << ENDN_BIT) & 0x00001000)
#define msp_frame_sync_pol(n)	((n << TFSPOL_BIT) & 0x00000400)
#define msp_data_word_swap(n)	((n << TBSWAP_BIT) & 0x30000000)
#define msp_set_companding_mode(n) ((n << DTYP_BIT) & 0x00000c00)
#define msp_set_frame_sync_ignore(n) ((n << FRAME_SYNC_BIT) & 0x00008000)

/* Flag register
--------------------*/
#define RX_BUSY       0x00000001
#define RX_FIFO_EMPTY 0x00000002
#define RX_FIFO_FULL  0x00000004
#define TX_BUSY       0x00000008
#define TX_FIFO_EMPTY 0x00000010
#define TX_FIFO_FULL  0x00000020

#define RBUSY_BIT		0
#define RFE_BIT			1
#define RFU_BIT			2
#define TBUSY_BIT		3
#define TFE_BIT			4
#define TFU_BIT			5

/* Multichannel control register
---------------------------------*/
#define RMCEN_BIT		0
#define RMCSF_BIT		1
#define RCMPM_BIT		3
#define TMCEN_BIT		5
#define TNCSF_BIT		6

/* Sample rate generator register
------------------------------------*/
#define SCKDIV_BIT		0
#define FRWID_BIT		10
#define FRPER_BIT		16

#define SCK_DIV_MASK 0x0000003FF
#define frame_width_bits(n) (((n) << FRWID_BIT)  & 0x0000FC00)
#define frame_period_bits(n) (((n) << FRPER_BIT) & 0x1FFF0000)

/* DMA controller register
---------------------------*/
#define RX_DMA_ENABLE 0x00000001
#define TX_DMA_ENABLE 0x00000002

#define RDMAE_BIT		0
#define TDMAE_BIT		1

/*Interrupt Register
-----------------------------------------*/
#define RECEIVE_SERVICE_INT         0x00000001
#define RECEIVE_OVERRUN_ERROR_INT   0x00000002
#define RECEIVE_FRAME_SYNC_ERR_INT  0x00000004
#define RECEIVE_FRAME_SYNC_INT      0x00000008
#define TRANSMIT_SERVICE_INT        0x00000010
#define TRANSMIT_UNDERRUN_ERR_INT   0x00000020
#define TRANSMIT_FRAME_SYNC_ERR_INT 0x00000040
#define TRANSMIT_FRAME_SYNC_INT     0x00000080
#define ALL_INT                     0x000000ff

/* Protocol configuration values
* I2S: Single phase, 16 bits, 2 words per frame
-----------------------------------------------*/
#define I2S_PROTOCOL_DESC				\
{							\
	MSP_SINGLE_PHASE,				\
	MSP_SINGLE_PHASE,				\
	MSP_PHASE2_START_MODE_IMEDIATE, 		\
	MSP_PHASE2_START_MODE_IMEDIATE, 		\
	MSP_BTF_MS_BIT_FIRST,				\
	MSP_BTF_MS_BIT_FIRST,				\
	MSP_FRAME_LENGTH_1,				\
	MSP_FRAME_LENGTH_1,				\
	MSP_FRAME_LENGTH_1,				\
	MSP_FRAME_LENGTH_1,				\
	MSP_ELEM_LENGTH_32,				\
	MSP_ELEM_LENGTH_32,				\
	MSP_ELEM_LENGTH_32,				\
	MSP_ELEM_LENGTH_32,				\
	MSP_DELAY_1,					\
	MSP_DELAY_1,					\
	MSP_RISING_EDGE,				\
	MSP_RISING_EDGE,				\
	MSP_FRAME_SYNC_POL_ACTIVE_HIGH,			\
	MSP_FRAME_SYNC_POL_ACTIVE_HIGH,			\
	MSP_HWS_NO_SWAP,				\
	MSP_HWS_NO_SWAP,				\
	MSP_COMPRESS_MODE_LINEAR,			\
	MSP_EXPAND_MODE_LINEAR,				\
	MSP_SPI_CLOCK_MODE_NON_SPI,			\
	MSP_SPI_BURST_MODE_DISABLE,			\
	MSP_FRAME_SYNC_IGNORE,			\
	31,						\
	15,						\
	32,						\
}
#define PCM_PROTOCOL_DESC				\
{							\
	MSP_DUAL_PHASE,				\
	MSP_DUAL_PHASE,				\
	MSP_PHASE2_START_MODE_FRAME_SYNC, 		\
	MSP_PHASE2_START_MODE_FRAME_SYNC, 		\
	MSP_BTF_MS_BIT_FIRST,				\
	MSP_BTF_MS_BIT_FIRST,				\
	MSP_FRAME_LENGTH_1,				\
	MSP_FRAME_LENGTH_1,				\
	MSP_FRAME_LENGTH_1,				\
	MSP_FRAME_LENGTH_1,				\
	MSP_ELEM_LENGTH_16,				\
	MSP_ELEM_LENGTH_16,				\
	MSP_ELEM_LENGTH_16,				\
	MSP_ELEM_LENGTH_16,				\
	MSP_DELAY_0,					\
	MSP_DELAY_0,					\
	MSP_FALLING_EDGE,				\
	MSP_FALLING_EDGE,				\
	MSP_FRAME_SYNC_POL_ACTIVE_HIGH,			\
	MSP_FRAME_SYNC_POL_ACTIVE_HIGH,			\
	MSP_HWS_NO_SWAP,				\
	MSP_HWS_NO_SWAP,				\
	MSP_COMPRESS_MODE_LINEAR,			\
	MSP_EXPAND_MODE_LINEAR,				\
	MSP_SPI_CLOCK_MODE_NON_SPI,			\
	MSP_SPI_BURST_MODE_DISABLE,			\
	MSP_FRAME_SYNC_IGNORE,			\
	255,						\
	0,						\
	256,						\
}
/* Companded PCM: Single phase, 8 bits, 1 word per frame
--------------------------------------------------------*/
#define PCM_COMPAND_PROTOCOL_DESC				\
{							\
	MSP_SINGLE_PHASE,				\
	MSP_SINGLE_PHASE,				\
	MSP_PHASE2_START_MODE_FRAME_SYNC, 		\
	MSP_PHASE2_START_MODE_FRAME_SYNC, 		\
	MSP_BTF_MS_BIT_FIRST,				\
	MSP_BTF_MS_BIT_FIRST,				\
	MSP_FRAME_LENGTH_1,				\
	MSP_FRAME_LENGTH_1,				\
	MSP_FRAME_LENGTH_1,				\
	MSP_FRAME_LENGTH_1,				\
	MSP_ELEM_LENGTH_8,				\
	MSP_ELEM_LENGTH_8,				\
	MSP_ELEM_LENGTH_8,				\
	MSP_ELEM_LENGTH_8,				\
	MSP_DELAY_0,					\
	MSP_DELAY_0,					\
	MSP_FALLING_EDGE,				\
	MSP_RISING_EDGE,				\
	MSP_FRAME_SYNC_POL_ACTIVE_HIGH,			\
	MSP_FRAME_SYNC_POL_ACTIVE_HIGH,			\
	MSP_HWS_NO_SWAP,				\
	MSP_HWS_NO_SWAP,				\
	MSP_COMPRESS_MODE_LINEAR,			\
	MSP_EXPAND_MODE_LINEAR,				\
	MSP_SPI_CLOCK_MODE_NON_SPI,			\
	MSP_SPI_BURST_MODE_DISABLE,			\
	MSP_FRAME_SYNC_IGNORE,			\
	255,						\
	0,						\
	256,						\
}

/* AC97: Double phase, 1 element of 16 bits during first phase,
* 12 elements of 20 bits in second phase.
--------------------------------------------------------------*/
#define AC97_PROTOCOL_DESC				\
{							\
	MSP_DUAL_PHASE,				\
	MSP_DUAL_PHASE,				\
	MSP_PHASE2_START_MODE_FRAME_SYNC, 		\
	MSP_PHASE2_START_MODE_FRAME_SYNC, 		\
	MSP_BTF_MS_BIT_FIRST,				\
	MSP_BTF_MS_BIT_FIRST,				\
	MSP_FRAME_LENGTH_1,				\
	MSP_FRAME_LENGTH_12,				\
	MSP_FRAME_LENGTH_1,				\
	MSP_FRAME_LENGTH_12,				\
	MSP_ELEM_LENGTH_16,				\
	MSP_ELEM_LENGTH_20,				\
	MSP_ELEM_LENGTH_16,				\
	MSP_ELEM_LENGTH_20,				\
	MSP_DELAY_1,					\
	MSP_DELAY_1,					\
	MSP_FALLING_EDGE,				\
	MSP_RISING_EDGE,				\
	MSP_FRAME_SYNC_POL_ACTIVE_HIGH,			\
	MSP_FRAME_SYNC_POL_ACTIVE_HIGH,			\
	MSP_HWS_NO_SWAP,				\
	MSP_HWS_NO_SWAP,				\
	MSP_COMPRESS_MODE_LINEAR,			\
	MSP_EXPAND_MODE_LINEAR,				\
	MSP_SPI_CLOCK_MODE_NON_SPI,			\
	MSP_SPI_BURST_MODE_DISABLE,			\
	MSP_FRAME_SYNC_IGNORE,			\
	255,						\
	0,						\
	256,						\
}

#define SPI_MASTER_PROTOCOL_DESC				\
{							\
	MSP_SINGLE_PHASE,				\
	MSP_SINGLE_PHASE,				\
	MSP_PHASE2_START_MODE_FRAME_SYNC, 		\
	MSP_PHASE2_START_MODE_FRAME_SYNC, 		\
	MSP_BTF_MS_BIT_FIRST,				\
	MSP_BTF_MS_BIT_FIRST,				\
	MSP_FRAME_LENGTH_1,				\
	MSP_FRAME_LENGTH_1,				\
	MSP_FRAME_LENGTH_1,				\
	MSP_FRAME_LENGTH_1,				\
	MSP_ELEM_LENGTH_8,				\
	MSP_ELEM_LENGTH_8,				\
	MSP_ELEM_LENGTH_8,				\
	MSP_ELEM_LENGTH_8,				\
	MSP_DELAY_1,					\
	MSP_DELAY_1,					\
	MSP_RISING_EDGE,				\
	MSP_FALLING_EDGE,				\
	MSP_FRAME_SYNC_POL_ACTIVE_HIGH,			\
	MSP_FRAME_SYNC_POL_ACTIVE_HIGH,			\
	MSP_HWS_NO_SWAP,				\
	MSP_HWS_NO_SWAP,				\
	MSP_COMPRESS_MODE_LINEAR,			\
	MSP_EXPAND_MODE_LINEAR,				\
	MSP_SPI_CLOCK_MODE_NON_SPI,			\
	MSP_SPI_BURST_MODE_DISABLE,			\
	MSP_FRAME_SYNC_IGNORE,			\
	255,						\
	0,						\
	256,						\
}

#define SPI_SLAVE_PROTOCOL_DESC				\
{							\
	MSP_SINGLE_PHASE,				\
	MSP_SINGLE_PHASE,				\
	MSP_PHASE2_START_MODE_FRAME_SYNC, 		\
	MSP_PHASE2_START_MODE_FRAME_SYNC, 		\
	MSP_BTF_MS_BIT_FIRST,				\
	MSP_BTF_MS_BIT_FIRST,				\
	MSP_FRAME_LENGTH_1,				\
	MSP_FRAME_LENGTH_1,				\
	MSP_FRAME_LENGTH_1,				\
	MSP_FRAME_LENGTH_1,				\
	MSP_ELEM_LENGTH_8,				\
	MSP_ELEM_LENGTH_8,				\
	MSP_ELEM_LENGTH_8,				\
	MSP_ELEM_LENGTH_8,				\
	MSP_DELAY_1,					\
	MSP_DELAY_1,					\
	MSP_RISING_EDGE,				\
	MSP_FALLING_EDGE,				\
	MSP_FRAME_SYNC_POL_ACTIVE_HIGH,			\
	MSP_FRAME_SYNC_POL_ACTIVE_HIGH,			\
	MSP_HWS_NO_SWAP,				\
	MSP_HWS_NO_SWAP,				\
	MSP_COMPRESS_MODE_LINEAR,			\
	MSP_EXPAND_MODE_LINEAR,				\
	MSP_SPI_CLOCK_MODE_NON_SPI,			\
	MSP_SPI_BURST_MODE_DISABLE,			\
	MSP_FRAME_SYNC_IGNORE,			\
	255,						\
	0,						\
	256,						\
}

#define MSP_FRAME_PERIOD_IN_MONO_MODE 256
#define MSP_FRAME_PERIOD_IN_STEREO_MODE 32
#define MSP_FRAME_WIDTH_IN_STEREO_MODE 16

/* No of registers to backup during
 * suspend resume */
#define MAX_MSP_BACKUP_REGS 36

typedef enum {
	MSP_0_I2S_CONTROLLER = 1,
	MSP_1_I2S_CONTROLLER,
	MSP_2_I2S_CONTROLLER,
} t_i2s_controller;

/**
 * struct msp_struct - Main msp controller data structure per MSP.
 * @work_mode: Mode i.e dma, polling or interrupt.
 * @id: Controller id like MSP1 or MSP2 etc.
 * @msp_io_error: To indicate error while transferring.
 * @registers: MSP's register base address.
 * @actual_data_size: Data size in which data needs to send or receive.
 * @irq:  MSP's irq number.
 * @i2s_cont: MSP's Controller's structure pointer created per MSP.
 * @gpio_alt_func: Gpio Alt function id of particular msp.
 * @lock: semaphore lock acquired while configuring msp.
 * @pipe_params_rx: Receive dma pipe structure.
 * @pipe_params_tx: Transmit dma pipe structure.
 * @msp_tx_dma_addr: Transmit Base Address of msp for DMA.
 * @msp_rx_dma_addr: Receive Base Address of msp for DMA.
 * @msp_base_addr: Physical Base Address of msp.
 * @tx_pipeid: Txpipeid for DMA.
 * @rx_pipeid: Rxpipeid for DMA.
 * @msp_state: Current state of msp.
 * @read: Function pointer for read, u8_msp_read,u16_msp_read,u32_msp_read.
 * @write: Function pointer for write, u8_msp_write,u16_msp_write,u32_msp_write.
 * @transfer: Function pointer for type of transfer i.e dma,polling or interrupt
 * @xfer_data: MSP's transfer data structure. Contains info about current xfer.
 * @plat_init: MSP's initialization function.
 * @plat_exit: MSP's Exit function.
 * @notify_timer: Timer used in Polling mode to prevent hang.
 * @polling_flag: Flag used in error handling while polling.
 * @def_elem_len: Flag indicates whether default elem len to be used in
 * protocol_desc or not.
 * @vape_opp_constraint: 1 if constraint is applied to have vape at 100OPP; 0 otherwise
 *
 * Main Msp private data structure to be used to store various info of a
 * particular MSP.Longer description
 */
struct msp_struct {
	int work_mode;
	t_i2s_controller id;
	int msp_io_error;
	void __iomem *registers;
	enum msp_data_size actual_data_size;
	int irq;
	struct i2s_controller *i2s_cont;
	u32 gpio_alt_func;
	struct semaphore lock;
	struct stm_dma_pipe_info pipe_params_rx;
	struct stm_dma_pipe_info pipe_params_tx;
	u32 msp_tx_dma_addr;
	u32 msp_rx_dma_addr;
	u32 msp_base_addr;
	dmach_t tx_pipeid;
	dmach_t rx_pipeid;
	struct scatterlist *rx_sglist;
	struct scatterlist *tx_sglist;
	struct scatterlist *sglist;
	t_msp_state msp_state;
	void (*read) (struct trans_data *xfer_data);
	void (*write) (struct trans_data *xfer_data);
	int (*transfer) (struct msp_struct *msp, struct i2s_message *message);
	struct trans_data xfer_data;
	int (*plat_init) (u32);
	int (*plat_exit) (u32);
	struct timer_list notify_timer;
	int polling_flag;
	int def_elem_len;
	struct clk *clk;
	unsigned int direction;
	int users;
	int loopback_enable;
	u32 backup_regs[MAX_MSP_BACKUP_REGS];
	t_msp_inf_transfer_enable inf_loopback_xfer;
	int vape_opp_constraint;
};

/**
 * struct msp_i2s_platform_datat - Main msp controller platform data structure.
 * @id: Controller id like MSP1 or MSP2 etc.
 * @gpio_alt_func: Gpio Alt function id of particular msp.
 * @msp_tx_dma_addr: Transmit Base Address of msp for DMA.
 * @msp_rx_dma_addr: Receive Base Address of msp for DMA.
 * @msp_base_addr: Physical Base Address of msp.
 * msp_i2s_init@: MSP's initialization function.
 * @msp_i2s_exit: MSP's Exit function.
 * @backup_regs: used for backup registers during suspend resume.
 *
 * Platform data structure passed by devices.c file.
 */
struct msp_i2s_platform_data {
	t_i2s_controller id;
	u32 gpio_alt_func;
	u32 msp_tx_dma_addr;
	u32 msp_rx_dma_addr;
	u32 msp_base_addr;
	int (*msp_i2s_init) (u32);
	int (*msp_i2s_exit) (u32);
};

#endif