ux500_msp_i2s.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. /*
  2. * Copyright (C) ST-Ericsson SA 2012
  3. *
  4. * Author: Ola Lilja <ola.o.lilja@stericsson.com>,
  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. #ifndef UX500_MSP_I2S_H
  14. #define UX500_MSP_I2S_H
  15. #include <linux/platform_device.h>
  16. #include <linux/platform_data/asoc-ux500-msp.h>
  17. #define MSP_INPUT_FREQ_APB 48000000
  18. /*** Stereo mode. Used for APB data accesses as 16 bits accesses (mono),
  19. * 32 bits accesses (stereo).
  20. ***/
  21. enum msp_stereo_mode {
  22. MSP_MONO,
  23. MSP_STEREO
  24. };
  25. /* Direction (Transmit/Receive mode) */
  26. enum msp_direction {
  27. MSP_TX = 1,
  28. MSP_RX = 2
  29. };
  30. /* Transmit and receive configuration register */
  31. #define MSP_BIG_ENDIAN 0x00000000
  32. #define MSP_LITTLE_ENDIAN 0x00001000
  33. #define MSP_UNEXPECTED_FS_ABORT 0x00000000
  34. #define MSP_UNEXPECTED_FS_IGNORE 0x00008000
  35. #define MSP_NON_MODE_BIT_MASK 0x00009000
  36. /* Global configuration register */
  37. #define RX_ENABLE 0x00000001
  38. #define RX_FIFO_ENABLE 0x00000002
  39. #define RX_SYNC_SRG 0x00000010
  40. #define RX_CLK_POL_RISING 0x00000020
  41. #define RX_CLK_SEL_SRG 0x00000040
  42. #define TX_ENABLE 0x00000100
  43. #define TX_FIFO_ENABLE 0x00000200
  44. #define TX_SYNC_SRG_PROG 0x00001800
  45. #define TX_SYNC_SRG_AUTO 0x00001000
  46. #define TX_CLK_POL_RISING 0x00002000
  47. #define TX_CLK_SEL_SRG 0x00004000
  48. #define TX_EXTRA_DELAY_ENABLE 0x00008000
  49. #define SRG_ENABLE 0x00010000
  50. #define FRAME_GEN_ENABLE 0x00100000
  51. #define SRG_CLK_SEL_APB 0x00000000
  52. #define RX_FIFO_SYNC_HI 0x00000000
  53. #define TX_FIFO_SYNC_HI 0x00000000
  54. #define SPI_CLK_MODE_NORMAL 0x00000000
  55. #define MSP_FRAME_SIZE_AUTO -1
  56. #define MSP_DR 0x00
  57. #define MSP_GCR 0x04
  58. #define MSP_TCF 0x08
  59. #define MSP_RCF 0x0c
  60. #define MSP_SRG 0x10
  61. #define MSP_FLR 0x14
  62. #define MSP_DMACR 0x18
  63. #define MSP_IMSC 0x20
  64. #define MSP_RIS 0x24
  65. #define MSP_MIS 0x28
  66. #define MSP_ICR 0x2c
  67. #define MSP_MCR 0x30
  68. #define MSP_RCV 0x34
  69. #define MSP_RCM 0x38
  70. #define MSP_TCE0 0x40
  71. #define MSP_TCE1 0x44
  72. #define MSP_TCE2 0x48
  73. #define MSP_TCE3 0x4c
  74. #define MSP_RCE0 0x60
  75. #define MSP_RCE1 0x64
  76. #define MSP_RCE2 0x68
  77. #define MSP_RCE3 0x6c
  78. #define MSP_IODLY 0x70
  79. #define MSP_ITCR 0x80
  80. #define MSP_ITIP 0x84
  81. #define MSP_ITOP 0x88
  82. #define MSP_TSTDR 0x8c
  83. #define MSP_PID0 0xfe0
  84. #define MSP_PID1 0xfe4
  85. #define MSP_PID2 0xfe8
  86. #define MSP_PID3 0xfec
  87. #define MSP_CID0 0xff0
  88. #define MSP_CID1 0xff4
  89. #define MSP_CID2 0xff8
  90. #define MSP_CID3 0xffc
  91. /* Protocol dependant parameters list */
  92. #define RX_ENABLE_MASK BIT(0)
  93. #define RX_FIFO_ENABLE_MASK BIT(1)
  94. #define RX_FSYNC_MASK BIT(2)
  95. #define DIRECT_COMPANDING_MASK BIT(3)
  96. #define RX_SYNC_SEL_MASK BIT(4)
  97. #define RX_CLK_POL_MASK BIT(5)
  98. #define RX_CLK_SEL_MASK BIT(6)
  99. #define LOOPBACK_MASK BIT(7)
  100. #define TX_ENABLE_MASK BIT(8)
  101. #define TX_FIFO_ENABLE_MASK BIT(9)
  102. #define TX_FSYNC_MASK BIT(10)
  103. #define TX_MSP_TDR_TSR BIT(11)
  104. #define TX_SYNC_SEL_MASK (BIT(12) | BIT(11))
  105. #define TX_CLK_POL_MASK BIT(13)
  106. #define TX_CLK_SEL_MASK BIT(14)
  107. #define TX_EXTRA_DELAY_MASK BIT(15)
  108. #define SRG_ENABLE_MASK BIT(16)
  109. #define SRG_CLK_POL_MASK BIT(17)
  110. #define SRG_CLK_SEL_MASK (BIT(19) | BIT(18))
  111. #define FRAME_GEN_EN_MASK BIT(20)
  112. #define SPI_CLK_MODE_MASK (BIT(22) | BIT(21))
  113. #define SPI_BURST_MODE_MASK BIT(23)
  114. #define RXEN_SHIFT 0
  115. #define RFFEN_SHIFT 1
  116. #define RFSPOL_SHIFT 2
  117. #define DCM_SHIFT 3
  118. #define RFSSEL_SHIFT 4
  119. #define RCKPOL_SHIFT 5
  120. #define RCKSEL_SHIFT 6
  121. #define LBM_SHIFT 7
  122. #define TXEN_SHIFT 8
  123. #define TFFEN_SHIFT 9
  124. #define TFSPOL_SHIFT 10
  125. #define TFSSEL_SHIFT 11
  126. #define TCKPOL_SHIFT 13
  127. #define TCKSEL_SHIFT 14
  128. #define TXDDL_SHIFT 15
  129. #define SGEN_SHIFT 16
  130. #define SCKPOL_SHIFT 17
  131. #define SCKSEL_SHIFT 18
  132. #define FGEN_SHIFT 20
  133. #define SPICKM_SHIFT 21
  134. #define TBSWAP_SHIFT 28
  135. #define RCKPOL_MASK BIT(0)
  136. #define TCKPOL_MASK BIT(0)
  137. #define SPICKM_MASK (BIT(1) | BIT(0))
  138. #define MSP_RX_CLKPOL_BIT(n) ((n & RCKPOL_MASK) << RCKPOL_SHIFT)
  139. #define MSP_TX_CLKPOL_BIT(n) ((n & TCKPOL_MASK) << TCKPOL_SHIFT)
  140. #define P1ELEN_SHIFT 0
  141. #define P1FLEN_SHIFT 3
  142. #define DTYP_SHIFT 10
  143. #define ENDN_SHIFT 12
  144. #define DDLY_SHIFT 13
  145. #define FSIG_SHIFT 15
  146. #define P2ELEN_SHIFT 16
  147. #define P2FLEN_SHIFT 19
  148. #define P2SM_SHIFT 26
  149. #define P2EN_SHIFT 27
  150. #define FSYNC_SHIFT 15
  151. #define P1ELEN_MASK 0x00000007
  152. #define P2ELEN_MASK 0x00070000
  153. #define P1FLEN_MASK 0x00000378
  154. #define P2FLEN_MASK 0x03780000
  155. #define DDLY_MASK 0x00003000
  156. #define DTYP_MASK 0x00000600
  157. #define P2SM_MASK 0x04000000
  158. #define P2EN_MASK 0x08000000
  159. #define ENDN_MASK 0x00001000
  160. #define TFSPOL_MASK 0x00000400
  161. #define TBSWAP_MASK 0x30000000
  162. #define COMPANDING_MODE_MASK 0x00000c00
  163. #define FSYNC_MASK 0x00008000
  164. #define MSP_P1_ELEM_LEN_BITS(n) (n & P1ELEN_MASK)
  165. #define MSP_P2_ELEM_LEN_BITS(n) (((n) << P2ELEN_SHIFT) & P2ELEN_MASK)
  166. #define MSP_P1_FRAME_LEN_BITS(n) (((n) << P1FLEN_SHIFT) & P1FLEN_MASK)
  167. #define MSP_P2_FRAME_LEN_BITS(n) (((n) << P2FLEN_SHIFT) & P2FLEN_MASK)
  168. #define MSP_DATA_DELAY_BITS(n) (((n) << DDLY_SHIFT) & DDLY_MASK)
  169. #define MSP_DATA_TYPE_BITS(n) (((n) << DTYP_SHIFT) & DTYP_MASK)
  170. #define MSP_P2_START_MODE_BIT(n) ((n << P2SM_SHIFT) & P2SM_MASK)
  171. #define MSP_P2_ENABLE_BIT(n) ((n << P2EN_SHIFT) & P2EN_MASK)
  172. #define MSP_SET_ENDIANNES_BIT(n) ((n << ENDN_SHIFT) & ENDN_MASK)
  173. #define MSP_FSYNC_POL(n) ((n << TFSPOL_SHIFT) & TFSPOL_MASK)
  174. #define MSP_DATA_WORD_SWAP(n) ((n << TBSWAP_SHIFT) & TBSWAP_MASK)
  175. #define MSP_SET_COMPANDING_MODE(n) ((n << DTYP_SHIFT) & \
  176. COMPANDING_MODE_MASK)
  177. #define MSP_SET_FSYNC_IGNORE(n) ((n << FSYNC_SHIFT) & FSYNC_MASK)
  178. /* Flag register */
  179. #define RX_BUSY BIT(0)
  180. #define RX_FIFO_EMPTY BIT(1)
  181. #define RX_FIFO_FULL BIT(2)
  182. #define TX_BUSY BIT(3)
  183. #define TX_FIFO_EMPTY BIT(4)
  184. #define TX_FIFO_FULL BIT(5)
  185. #define RBUSY_SHIFT 0
  186. #define RFE_SHIFT 1
  187. #define RFU_SHIFT 2
  188. #define TBUSY_SHIFT 3
  189. #define TFE_SHIFT 4
  190. #define TFU_SHIFT 5
  191. /* Multichannel control register */
  192. #define RMCEN_SHIFT 0
  193. #define RMCSF_SHIFT 1
  194. #define RCMPM_SHIFT 3
  195. #define TMCEN_SHIFT 5
  196. #define TNCSF_SHIFT 6
  197. /* Sample rate generator register */
  198. #define SCKDIV_SHIFT 0
  199. #define FRWID_SHIFT 10
  200. #define FRPER_SHIFT 16
  201. #define SCK_DIV_MASK 0x0000003FF
  202. #define FRAME_WIDTH_BITS(n) (((n) << FRWID_SHIFT) & 0x0000FC00)
  203. #define FRAME_PERIOD_BITS(n) (((n) << FRPER_SHIFT) & 0x1FFF0000)
  204. /* DMA controller register */
  205. #define RX_DMA_ENABLE BIT(0)
  206. #define TX_DMA_ENABLE BIT(1)
  207. #define RDMAE_SHIFT 0
  208. #define TDMAE_SHIFT 1
  209. /* Interrupt Register */
  210. #define RX_SERVICE_INT BIT(0)
  211. #define RX_OVERRUN_ERROR_INT BIT(1)
  212. #define RX_FSYNC_ERR_INT BIT(2)
  213. #define RX_FSYNC_INT BIT(3)
  214. #define TX_SERVICE_INT BIT(4)
  215. #define TX_UNDERRUN_ERR_INT BIT(5)
  216. #define TX_FSYNC_ERR_INT BIT(6)
  217. #define TX_FSYNC_INT BIT(7)
  218. #define ALL_INT 0x000000ff
  219. /* MSP test control register */
  220. #define MSP_ITCR_ITEN BIT(0)
  221. #define MSP_ITCR_TESTFIFO BIT(1)
  222. #define RMCEN_BIT 0
  223. #define RMCSF_BIT 1
  224. #define RCMPM_BIT 3
  225. #define TMCEN_BIT 5
  226. #define TNCSF_BIT 6
  227. /* Single or dual phase mode */
  228. enum msp_phase_mode {
  229. MSP_SINGLE_PHASE,
  230. MSP_DUAL_PHASE
  231. };
  232. /* Frame length */
  233. enum msp_frame_length {
  234. MSP_FRAME_LEN_1 = 0,
  235. MSP_FRAME_LEN_2 = 1,
  236. MSP_FRAME_LEN_4 = 3,
  237. MSP_FRAME_LEN_8 = 7,
  238. MSP_FRAME_LEN_12 = 11,
  239. MSP_FRAME_LEN_16 = 15,
  240. MSP_FRAME_LEN_20 = 19,
  241. MSP_FRAME_LEN_32 = 31,
  242. MSP_FRAME_LEN_48 = 47,
  243. MSP_FRAME_LEN_64 = 63
  244. };
  245. /* Element length */
  246. enum msp_elem_length {
  247. MSP_ELEM_LEN_8 = 0,
  248. MSP_ELEM_LEN_10 = 1,
  249. MSP_ELEM_LEN_12 = 2,
  250. MSP_ELEM_LEN_14 = 3,
  251. MSP_ELEM_LEN_16 = 4,
  252. MSP_ELEM_LEN_20 = 5,
  253. MSP_ELEM_LEN_24 = 6,
  254. MSP_ELEM_LEN_32 = 7
  255. };
  256. enum msp_data_xfer_width {
  257. MSP_DATA_TRANSFER_WIDTH_BYTE,
  258. MSP_DATA_TRANSFER_WIDTH_HALFWORD,
  259. MSP_DATA_TRANSFER_WIDTH_WORD
  260. };
  261. enum msp_frame_sync {
  262. MSP_FSYNC_UNIGNORE = 0,
  263. MSP_FSYNC_IGNORE = 1,
  264. };
  265. enum msp_phase2_start_mode {
  266. MSP_PHASE2_START_MODE_IMEDIATE,
  267. MSP_PHASE2_START_MODE_FSYNC
  268. };
  269. enum msp_btf {
  270. MSP_BTF_MS_BIT_FIRST = 0,
  271. MSP_BTF_LS_BIT_FIRST = 1
  272. };
  273. enum msp_fsync_pol {
  274. MSP_FSYNC_POL_ACT_HI = 0,
  275. MSP_FSYNC_POL_ACT_LO = 1
  276. };
  277. /* Data delay (in bit clock cycles) */
  278. enum msp_delay {
  279. MSP_DELAY_0 = 0,
  280. MSP_DELAY_1 = 1,
  281. MSP_DELAY_2 = 2,
  282. MSP_DELAY_3 = 3
  283. };
  284. /* Configurations of clocks (transmit, receive or sample rate generator) */
  285. enum msp_edge {
  286. MSP_FALLING_EDGE = 0,
  287. MSP_RISING_EDGE = 1,
  288. };
  289. enum msp_hws {
  290. MSP_SWAP_NONE = 0,
  291. MSP_SWAP_BYTE_PER_WORD = 1,
  292. MSP_SWAP_BYTE_PER_HALF_WORD = 2,
  293. MSP_SWAP_HALF_WORD_PER_WORD = 3
  294. };
  295. enum msp_compress_mode {
  296. MSP_COMPRESS_MODE_LINEAR = 0,
  297. MSP_COMPRESS_MODE_MU_LAW = 2,
  298. MSP_COMPRESS_MODE_A_LAW = 3
  299. };
  300. enum msp_expand_mode {
  301. MSP_EXPAND_MODE_LINEAR = 0,
  302. MSP_EXPAND_MODE_LINEAR_SIGNED = 1,
  303. MSP_EXPAND_MODE_MU_LAW = 2,
  304. MSP_EXPAND_MODE_A_LAW = 3
  305. };
  306. #define MSP_FRAME_PERIOD_IN_MONO_MODE 256
  307. #define MSP_FRAME_PERIOD_IN_STEREO_MODE 32
  308. #define MSP_FRAME_WIDTH_IN_STEREO_MODE 16
  309. enum msp_protocol {
  310. MSP_I2S_PROTOCOL,
  311. MSP_PCM_PROTOCOL,
  312. MSP_PCM_COMPAND_PROTOCOL,
  313. MSP_INVALID_PROTOCOL
  314. };
  315. /*
  316. * No of registers to backup during
  317. * suspend resume
  318. */
  319. #define MAX_MSP_BACKUP_REGS 36
  320. enum i2s_direction_t {
  321. MSP_DIR_TX = 0x01,
  322. MSP_DIR_RX = 0x02,
  323. };
  324. enum msp_data_size {
  325. MSP_DATA_BITS_DEFAULT = -1,
  326. MSP_DATA_BITS_8 = 0x00,
  327. MSP_DATA_BITS_10,
  328. MSP_DATA_BITS_12,
  329. MSP_DATA_BITS_14,
  330. MSP_DATA_BITS_16,
  331. MSP_DATA_BITS_20,
  332. MSP_DATA_BITS_24,
  333. MSP_DATA_BITS_32,
  334. };
  335. enum msp_state {
  336. MSP_STATE_IDLE = 0,
  337. MSP_STATE_CONFIGURED = 1,
  338. MSP_STATE_RUNNING = 2,
  339. };
  340. enum msp_rx_comparison_enable_mode {
  341. MSP_COMPARISON_DISABLED = 0,
  342. MSP_COMPARISON_NONEQUAL_ENABLED = 2,
  343. MSP_COMPARISON_EQUAL_ENABLED = 3
  344. };
  345. struct msp_multichannel_config {
  346. bool rx_multichannel_enable;
  347. bool tx_multichannel_enable;
  348. enum msp_rx_comparison_enable_mode rx_comparison_enable_mode;
  349. u8 padding;
  350. u32 comparison_value;
  351. u32 comparison_mask;
  352. u32 rx_channel_0_enable;
  353. u32 rx_channel_1_enable;
  354. u32 rx_channel_2_enable;
  355. u32 rx_channel_3_enable;
  356. u32 tx_channel_0_enable;
  357. u32 tx_channel_1_enable;
  358. u32 tx_channel_2_enable;
  359. u32 tx_channel_3_enable;
  360. };
  361. struct msp_protdesc {
  362. u32 rx_phase_mode;
  363. u32 tx_phase_mode;
  364. u32 rx_phase2_start_mode;
  365. u32 tx_phase2_start_mode;
  366. u32 rx_byte_order;
  367. u32 tx_byte_order;
  368. u32 rx_frame_len_1;
  369. u32 rx_frame_len_2;
  370. u32 tx_frame_len_1;
  371. u32 tx_frame_len_2;
  372. u32 rx_elem_len_1;
  373. u32 rx_elem_len_2;
  374. u32 tx_elem_len_1;
  375. u32 tx_elem_len_2;
  376. u32 rx_data_delay;
  377. u32 tx_data_delay;
  378. u32 rx_clk_pol;
  379. u32 tx_clk_pol;
  380. u32 rx_fsync_pol;
  381. u32 tx_fsync_pol;
  382. u32 rx_half_word_swap;
  383. u32 tx_half_word_swap;
  384. u32 compression_mode;
  385. u32 expansion_mode;
  386. u32 frame_sync_ignore;
  387. u32 frame_period;
  388. u32 frame_width;
  389. u32 clocks_per_frame;
  390. };
  391. struct ux500_msp_config {
  392. unsigned int f_inputclk;
  393. unsigned int rx_clk_sel;
  394. unsigned int tx_clk_sel;
  395. unsigned int srg_clk_sel;
  396. unsigned int rx_fsync_pol;
  397. unsigned int tx_fsync_pol;
  398. unsigned int rx_fsync_sel;
  399. unsigned int tx_fsync_sel;
  400. unsigned int rx_fifo_config;
  401. unsigned int tx_fifo_config;
  402. unsigned int loopback_enable;
  403. unsigned int tx_data_enable;
  404. unsigned int default_protdesc;
  405. struct msp_protdesc protdesc;
  406. int multichannel_configured;
  407. struct msp_multichannel_config multichannel_config;
  408. unsigned int direction;
  409. unsigned int protocol;
  410. unsigned int frame_freq;
  411. enum msp_data_size data_size;
  412. unsigned int def_elem_len;
  413. unsigned int iodelay;
  414. };
  415. struct ux500_msp_dma_params {
  416. unsigned int data_size;
  417. dma_addr_t tx_rx_addr;
  418. struct stedma40_chan_cfg *dma_cfg;
  419. };
  420. struct ux500_msp {
  421. int id;
  422. void __iomem *registers;
  423. struct device *dev;
  424. struct ux500_msp_dma_params playback_dma_data;
  425. struct ux500_msp_dma_params capture_dma_data;
  426. enum msp_state msp_state;
  427. int def_elem_len;
  428. unsigned int dir_busy;
  429. int loopback_enable;
  430. unsigned int f_bitclk;
  431. };
  432. struct msp_i2s_platform_data;
  433. int ux500_msp_i2s_init_msp(struct platform_device *pdev,
  434. struct ux500_msp **msp_p,
  435. struct msp_i2s_platform_data *platform_data);
  436. void ux500_msp_i2s_cleanup_msp(struct platform_device *pdev,
  437. struct ux500_msp *msp);
  438. int ux500_msp_i2s_open(struct ux500_msp *msp, struct ux500_msp_config *config);
  439. int ux500_msp_i2s_close(struct ux500_msp *msp,
  440. unsigned int dir);
  441. int ux500_msp_i2s_trigger(struct ux500_msp *msp, int cmd,
  442. int direction);
  443. #endif