Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ux500_msp_i2s.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) ST-Ericsson SA 2012
3  *
4  * Author: Ola Lilja <[email protected]>,
5  * for ST-Ericsson.
6  *
7  * License terms:
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as published
11  * by the Free Software Foundation.
12  */
13 
14 
15 #ifndef UX500_MSP_I2S_H
16 #define UX500_MSP_I2S_H
17 
18 #include <linux/platform_device.h>
19 
20 #include <mach/msp.h>
21 
22 #define MSP_INPUT_FREQ_APB 48000000
23 
24 /*** Stereo mode. Used for APB data accesses as 16 bits accesses (mono),
25  * 32 bits accesses (stereo).
26  ***/
30 };
31 
32 /* Direction (Transmit/Receive mode) */
34  MSP_TX = 1,
35  MSP_RX = 2
36 };
37 
38 /* Transmit and receive configuration register */
39 #define MSP_BIG_ENDIAN 0x00000000
40 #define MSP_LITTLE_ENDIAN 0x00001000
41 #define MSP_UNEXPECTED_FS_ABORT 0x00000000
42 #define MSP_UNEXPECTED_FS_IGNORE 0x00008000
43 #define MSP_NON_MODE_BIT_MASK 0x00009000
44 
45 /* Global configuration register */
46 #define RX_ENABLE 0x00000001
47 #define RX_FIFO_ENABLE 0x00000002
48 #define RX_SYNC_SRG 0x00000010
49 #define RX_CLK_POL_RISING 0x00000020
50 #define RX_CLK_SEL_SRG 0x00000040
51 #define TX_ENABLE 0x00000100
52 #define TX_FIFO_ENABLE 0x00000200
53 #define TX_SYNC_SRG_PROG 0x00001800
54 #define TX_SYNC_SRG_AUTO 0x00001000
55 #define TX_CLK_POL_RISING 0x00002000
56 #define TX_CLK_SEL_SRG 0x00004000
57 #define TX_EXTRA_DELAY_ENABLE 0x00008000
58 #define SRG_ENABLE 0x00010000
59 #define FRAME_GEN_ENABLE 0x00100000
60 #define SRG_CLK_SEL_APB 0x00000000
61 #define RX_FIFO_SYNC_HI 0x00000000
62 #define TX_FIFO_SYNC_HI 0x00000000
63 #define SPI_CLK_MODE_NORMAL 0x00000000
64 
65 #define MSP_FRAME_SIZE_AUTO -1
66 
67 #define MSP_DR 0x00
68 #define MSP_GCR 0x04
69 #define MSP_TCF 0x08
70 #define MSP_RCF 0x0c
71 #define MSP_SRG 0x10
72 #define MSP_FLR 0x14
73 #define MSP_DMACR 0x18
74 
75 #define MSP_IMSC 0x20
76 #define MSP_RIS 0x24
77 #define MSP_MIS 0x28
78 #define MSP_ICR 0x2c
79 #define MSP_MCR 0x30
80 #define MSP_RCV 0x34
81 #define MSP_RCM 0x38
82 
83 #define MSP_TCE0 0x40
84 #define MSP_TCE1 0x44
85 #define MSP_TCE2 0x48
86 #define MSP_TCE3 0x4c
87 
88 #define MSP_RCE0 0x60
89 #define MSP_RCE1 0x64
90 #define MSP_RCE2 0x68
91 #define MSP_RCE3 0x6c
92 #define MSP_IODLY 0x70
93 
94 #define MSP_ITCR 0x80
95 #define MSP_ITIP 0x84
96 #define MSP_ITOP 0x88
97 #define MSP_TSTDR 0x8c
98 
99 #define MSP_PID0 0xfe0
100 #define MSP_PID1 0xfe4
101 #define MSP_PID2 0xfe8
102 #define MSP_PID3 0xfec
103 
104 #define MSP_CID0 0xff0
105 #define MSP_CID1 0xff4
106 #define MSP_CID2 0xff8
107 #define MSP_CID3 0xffc
108 
109 /* Protocol dependant parameters list */
110 #define RX_ENABLE_MASK BIT(0)
111 #define RX_FIFO_ENABLE_MASK BIT(1)
112 #define RX_FSYNC_MASK BIT(2)
113 #define DIRECT_COMPANDING_MASK BIT(3)
114 #define RX_SYNC_SEL_MASK BIT(4)
115 #define RX_CLK_POL_MASK BIT(5)
116 #define RX_CLK_SEL_MASK BIT(6)
117 #define LOOPBACK_MASK BIT(7)
118 #define TX_ENABLE_MASK BIT(8)
119 #define TX_FIFO_ENABLE_MASK BIT(9)
120 #define TX_FSYNC_MASK BIT(10)
121 #define TX_MSP_TDR_TSR BIT(11)
122 #define TX_SYNC_SEL_MASK (BIT(12) | BIT(11))
123 #define TX_CLK_POL_MASK BIT(13)
124 #define TX_CLK_SEL_MASK BIT(14)
125 #define TX_EXTRA_DELAY_MASK BIT(15)
126 #define SRG_ENABLE_MASK BIT(16)
127 #define SRG_CLK_POL_MASK BIT(17)
128 #define SRG_CLK_SEL_MASK (BIT(19) | BIT(18))
129 #define FRAME_GEN_EN_MASK BIT(20)
130 #define SPI_CLK_MODE_MASK (BIT(22) | BIT(21))
131 #define SPI_BURST_MODE_MASK BIT(23)
132 
133 #define RXEN_SHIFT 0
134 #define RFFEN_SHIFT 1
135 #define RFSPOL_SHIFT 2
136 #define DCM_SHIFT 3
137 #define RFSSEL_SHIFT 4
138 #define RCKPOL_SHIFT 5
139 #define RCKSEL_SHIFT 6
140 #define LBM_SHIFT 7
141 #define TXEN_SHIFT 8
142 #define TFFEN_SHIFT 9
143 #define TFSPOL_SHIFT 10
144 #define TFSSEL_SHIFT 11
145 #define TCKPOL_SHIFT 13
146 #define TCKSEL_SHIFT 14
147 #define TXDDL_SHIFT 15
148 #define SGEN_SHIFT 16
149 #define SCKPOL_SHIFT 17
150 #define SCKSEL_SHIFT 18
151 #define FGEN_SHIFT 20
152 #define SPICKM_SHIFT 21
153 #define TBSWAP_SHIFT 28
154 
155 #define RCKPOL_MASK BIT(0)
156 #define TCKPOL_MASK BIT(0)
157 #define SPICKM_MASK (BIT(1) | BIT(0))
158 #define MSP_RX_CLKPOL_BIT(n) ((n & RCKPOL_MASK) << RCKPOL_SHIFT)
159 #define MSP_TX_CLKPOL_BIT(n) ((n & TCKPOL_MASK) << TCKPOL_SHIFT)
160 
161 #define P1ELEN_SHIFT 0
162 #define P1FLEN_SHIFT 3
163 #define DTYP_SHIFT 10
164 #define ENDN_SHIFT 12
165 #define DDLY_SHIFT 13
166 #define FSIG_SHIFT 15
167 #define P2ELEN_SHIFT 16
168 #define P2FLEN_SHIFT 19
169 #define P2SM_SHIFT 26
170 #define P2EN_SHIFT 27
171 #define FSYNC_SHIFT 15
172 
173 #define P1ELEN_MASK 0x00000007
174 #define P2ELEN_MASK 0x00070000
175 #define P1FLEN_MASK 0x00000378
176 #define P2FLEN_MASK 0x03780000
177 #define DDLY_MASK 0x00003000
178 #define DTYP_MASK 0x00000600
179 #define P2SM_MASK 0x04000000
180 #define P2EN_MASK 0x08000000
181 #define ENDN_MASK 0x00001000
182 #define TFSPOL_MASK 0x00000400
183 #define TBSWAP_MASK 0x30000000
184 #define COMPANDING_MODE_MASK 0x00000c00
185 #define FSYNC_MASK 0x00008000
186 
187 #define MSP_P1_ELEM_LEN_BITS(n) (n & P1ELEN_MASK)
188 #define MSP_P2_ELEM_LEN_BITS(n) (((n) << P2ELEN_SHIFT) & P2ELEN_MASK)
189 #define MSP_P1_FRAME_LEN_BITS(n) (((n) << P1FLEN_SHIFT) & P1FLEN_MASK)
190 #define MSP_P2_FRAME_LEN_BITS(n) (((n) << P2FLEN_SHIFT) & P2FLEN_MASK)
191 #define MSP_DATA_DELAY_BITS(n) (((n) << DDLY_SHIFT) & DDLY_MASK)
192 #define MSP_DATA_TYPE_BITS(n) (((n) << DTYP_SHIFT) & DTYP_MASK)
193 #define MSP_P2_START_MODE_BIT(n) ((n << P2SM_SHIFT) & P2SM_MASK)
194 #define MSP_P2_ENABLE_BIT(n) ((n << P2EN_SHIFT) & P2EN_MASK)
195 #define MSP_SET_ENDIANNES_BIT(n) ((n << ENDN_SHIFT) & ENDN_MASK)
196 #define MSP_FSYNC_POL(n) ((n << TFSPOL_SHIFT) & TFSPOL_MASK)
197 #define MSP_DATA_WORD_SWAP(n) ((n << TBSWAP_SHIFT) & TBSWAP_MASK)
198 #define MSP_SET_COMPANDING_MODE(n) ((n << DTYP_SHIFT) & \
199  COMPANDING_MODE_MASK)
200 #define MSP_SET_FSYNC_IGNORE(n) ((n << FSYNC_SHIFT) & FSYNC_MASK)
201 
202 /* Flag register */
203 #define RX_BUSY BIT(0)
204 #define RX_FIFO_EMPTY BIT(1)
205 #define RX_FIFO_FULL BIT(2)
206 #define TX_BUSY BIT(3)
207 #define TX_FIFO_EMPTY BIT(4)
208 #define TX_FIFO_FULL BIT(5)
209 
210 #define RBUSY_SHIFT 0
211 #define RFE_SHIFT 1
212 #define RFU_SHIFT 2
213 #define TBUSY_SHIFT 3
214 #define TFE_SHIFT 4
215 #define TFU_SHIFT 5
216 
217 /* Multichannel control register */
218 #define RMCEN_SHIFT 0
219 #define RMCSF_SHIFT 1
220 #define RCMPM_SHIFT 3
221 #define TMCEN_SHIFT 5
222 #define TNCSF_SHIFT 6
223 
224 /* Sample rate generator register */
225 #define SCKDIV_SHIFT 0
226 #define FRWID_SHIFT 10
227 #define FRPER_SHIFT 16
228 
229 #define SCK_DIV_MASK 0x0000003FF
230 #define FRAME_WIDTH_BITS(n) (((n) << FRWID_SHIFT) & 0x0000FC00)
231 #define FRAME_PERIOD_BITS(n) (((n) << FRPER_SHIFT) & 0x1FFF0000)
232 
233 /* DMA controller register */
234 #define RX_DMA_ENABLE BIT(0)
235 #define TX_DMA_ENABLE BIT(1)
236 
237 #define RDMAE_SHIFT 0
238 #define TDMAE_SHIFT 1
239 
240 /* Interrupt Register */
241 #define RX_SERVICE_INT BIT(0)
242 #define RX_OVERRUN_ERROR_INT BIT(1)
243 #define RX_FSYNC_ERR_INT BIT(2)
244 #define RX_FSYNC_INT BIT(3)
245 #define TX_SERVICE_INT BIT(4)
246 #define TX_UNDERRUN_ERR_INT BIT(5)
247 #define TX_FSYNC_ERR_INT BIT(6)
248 #define TX_FSYNC_INT BIT(7)
249 #define ALL_INT 0x000000ff
250 
251 /* MSP test control register */
252 #define MSP_ITCR_ITEN BIT(0)
253 #define MSP_ITCR_TESTFIFO BIT(1)
254 
255 #define RMCEN_BIT 0
256 #define RMCSF_BIT 1
257 #define RCMPM_BIT 3
258 #define TMCEN_BIT 5
259 #define TNCSF_BIT 6
260 
261 /* Single or dual phase mode */
265 };
266 
267 /* Frame length */
279 };
280 
281 /* Element length */
291 };
292 
297 };
298 
302 };
303 
307 };
308 
309 enum msp_btf {
312 };
313 
317 };
318 
319 /* Data delay (in bit clock cycles) */
320 enum msp_delay {
325 };
326 
327 /* Configurations of clocks (transmit, receive or sample rate generator) */
328 enum msp_edge {
331 };
332 
333 enum msp_hws {
338 };
339 
344 };
345 
349 };
350 
356 };
357 
358 #define MSP_FRAME_PERIOD_IN_MONO_MODE 256
359 #define MSP_FRAME_PERIOD_IN_STEREO_MODE 32
360 #define MSP_FRAME_WIDTH_IN_STEREO_MODE 16
361 
367 };
368 
369 /*
370  * No of registers to backup during
371  * suspend resume
372  */
373 #define MAX_MSP_BACKUP_REGS 36
374 
380 };
381 
383  MSP_DIR_TX = 0x01,
384  MSP_DIR_RX = 0x02,
385 };
386 
397 };
398 
399 enum msp_state {
403 };
404 
409 };
410 
426 };
427 
428 struct msp_protdesc {
457 };
458 
459 struct i2s_message {
461  void *txdata;
462  void *rxdata;
463  size_t txbytes;
464  size_t rxbytes;
465  int dma_flag;
470  size_t buf_len;
471  size_t period_len;
472 };
473 
475  struct module *owner;
476  unsigned int id;
477  unsigned int class;
478  const struct i2s_algorithm *algo; /* the algorithm to access the bus */
479  void *data;
480  struct mutex bus_lock;
481  struct device dev; /* the controller device */
482  char name[48];
483 };
484 
486  unsigned int f_inputclk;
487  unsigned int rx_clk_sel;
488  unsigned int tx_clk_sel;
489  unsigned int srg_clk_sel;
490  unsigned int rx_fsync_pol;
491  unsigned int tx_fsync_pol;
492  unsigned int rx_fsync_sel;
493  unsigned int tx_fsync_sel;
494  unsigned int rx_fifo_config;
495  unsigned int tx_fifo_config;
496  unsigned int spi_clk_mode;
497  unsigned int spi_burst_mode;
498  unsigned int loopback_enable;
499  unsigned int tx_data_enable;
500  unsigned int default_protdesc;
504  unsigned int direction;
505  unsigned int protocol;
506  unsigned int frame_freq;
507  unsigned int frame_size;
509  unsigned int def_elem_len;
510  unsigned int iodelay;
511  void (*handler) (void *data);
514 };
515 
516 struct ux500_msp {
519  struct device *dev;
526  int (*transfer) (struct ux500_msp *msp, struct i2s_message *message);
529  unsigned int dir_busy;
532  unsigned int f_bitclk;
533  /* Pin modes */
537  /* Reference Count */
539 };
540 
542  unsigned int data_size;
544 };
545 
546 int ux500_msp_i2s_init_msp(struct platform_device *pdev,
547  struct ux500_msp **msp_p,
550  struct ux500_msp *msp);
551 int ux500_msp_i2s_open(struct ux500_msp *msp, struct ux500_msp_config *config);
552 int ux500_msp_i2s_close(struct ux500_msp *msp,
553  unsigned int dir);
554 int ux500_msp_i2s_trigger(struct ux500_msp *msp, int cmd,
555  int direction);
556 
557 #endif