local.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Copyright (ST) 2012 Rajeev Kumar (rajeevkumar.linux@gmail.com)
  3. *
  4. * This file is licensed under the terms of the GNU General Public
  5. * License version 2. This program is licensed "as is" without any
  6. * warranty of any kind, whether express or implied.
  7. */
  8. #ifndef __DESIGNWARE_LOCAL_H
  9. #define __DESIGNWARE_LOCAL_H
  10. #include <linux/clk.h>
  11. #include <linux/device.h>
  12. #include <linux/types.h>
  13. #include <sound/dmaengine_pcm.h>
  14. #include <sound/pcm.h>
  15. #include <sound/designware_i2s.h>
  16. /* common register for all channel */
  17. #define IER 0x000
  18. #define IRER 0x004
  19. #define ITER 0x008
  20. #define CER 0x00C
  21. #define CCR 0x010
  22. #define RXFFR 0x014
  23. #define TXFFR 0x018
  24. /* Interrupt status register fields */
  25. #define ISR_TXFO BIT(5)
  26. #define ISR_TXFE BIT(4)
  27. #define ISR_RXFO BIT(1)
  28. #define ISR_RXDA BIT(0)
  29. /* I2STxRxRegisters for all channels */
  30. #define LRBR_LTHR(x) (0x40 * x + 0x020)
  31. #define RRBR_RTHR(x) (0x40 * x + 0x024)
  32. #define RER(x) (0x40 * x + 0x028)
  33. #define TER(x) (0x40 * x + 0x02C)
  34. #define RCR(x) (0x40 * x + 0x030)
  35. #define TCR(x) (0x40 * x + 0x034)
  36. #define ISR(x) (0x40 * x + 0x038)
  37. #define IMR(x) (0x40 * x + 0x03C)
  38. #define ROR(x) (0x40 * x + 0x040)
  39. #define TOR(x) (0x40 * x + 0x044)
  40. #define RFCR(x) (0x40 * x + 0x048)
  41. #define TFCR(x) (0x40 * x + 0x04C)
  42. #define RFF(x) (0x40 * x + 0x050)
  43. #define TFF(x) (0x40 * x + 0x054)
  44. /* I2SCOMPRegisters */
  45. #define I2S_COMP_PARAM_2 0x01F0
  46. #define I2S_COMP_PARAM_1 0x01F4
  47. #define I2S_COMP_VERSION 0x01F8
  48. #define I2S_COMP_TYPE 0x01FC
  49. /*
  50. * Component parameter register fields - define the I2S block's
  51. * configuration.
  52. */
  53. #define COMP1_TX_WORDSIZE_3(r) (((r) & GENMASK(27, 25)) >> 25)
  54. #define COMP1_TX_WORDSIZE_2(r) (((r) & GENMASK(24, 22)) >> 22)
  55. #define COMP1_TX_WORDSIZE_1(r) (((r) & GENMASK(21, 19)) >> 19)
  56. #define COMP1_TX_WORDSIZE_0(r) (((r) & GENMASK(18, 16)) >> 16)
  57. #define COMP1_TX_CHANNELS(r) (((r) & GENMASK(10, 9)) >> 9)
  58. #define COMP1_RX_CHANNELS(r) (((r) & GENMASK(8, 7)) >> 7)
  59. #define COMP1_RX_ENABLED(r) (((r) & BIT(6)) >> 6)
  60. #define COMP1_TX_ENABLED(r) (((r) & BIT(5)) >> 5)
  61. #define COMP1_MODE_EN(r) (((r) & BIT(4)) >> 4)
  62. #define COMP1_FIFO_DEPTH_GLOBAL(r) (((r) & GENMASK(3, 2)) >> 2)
  63. #define COMP1_APB_DATA_WIDTH(r) (((r) & GENMASK(1, 0)) >> 0)
  64. #define COMP2_RX_WORDSIZE_3(r) (((r) & GENMASK(12, 10)) >> 10)
  65. #define COMP2_RX_WORDSIZE_2(r) (((r) & GENMASK(9, 7)) >> 7)
  66. #define COMP2_RX_WORDSIZE_1(r) (((r) & GENMASK(5, 3)) >> 3)
  67. #define COMP2_RX_WORDSIZE_0(r) (((r) & GENMASK(2, 0)) >> 0)
  68. /* Number of entries in WORDSIZE and DATA_WIDTH parameter registers */
  69. #define COMP_MAX_WORDSIZE (1 << 3)
  70. #define COMP_MAX_DATA_WIDTH (1 << 2)
  71. #define MAX_CHANNEL_NUM 8
  72. #define MIN_CHANNEL_NUM 2
  73. union dw_i2s_snd_dma_data {
  74. struct i2s_dma_data pd;
  75. struct snd_dmaengine_dai_dma_data dt;
  76. };
  77. struct dw_i2s_dev {
  78. void __iomem *i2s_base;
  79. struct clk *clk;
  80. int active;
  81. unsigned int capability;
  82. unsigned int quirks;
  83. unsigned int i2s_reg_comp1;
  84. unsigned int i2s_reg_comp2;
  85. struct device *dev;
  86. u32 ccr;
  87. u32 xfer_resolution;
  88. u32 fifo_th;
  89. /* data related to DMA transfers b/w i2s and DMAC */
  90. union dw_i2s_snd_dma_data play_dma_data;
  91. union dw_i2s_snd_dma_data capture_dma_data;
  92. struct i2s_clk_config_data config;
  93. int (*i2s_clk_cfg)(struct i2s_clk_config_data *config);
  94. /* data related to PIO transfers (TX) */
  95. bool use_pio;
  96. struct snd_pcm_substream __rcu *tx_substream;
  97. unsigned int (*tx_fn)(struct dw_i2s_dev *dev,
  98. struct snd_pcm_runtime *runtime, unsigned int tx_ptr,
  99. bool *period_elapsed);
  100. unsigned int tx_ptr;
  101. };
  102. #if IS_ENABLED(CONFIG_SND_DESIGNWARE_PCM)
  103. void dw_pcm_push_tx(struct dw_i2s_dev *dev);
  104. int dw_pcm_register(struct platform_device *pdev);
  105. #else
  106. void dw_pcm_push_tx(struct dw_i2s_dev *dev) { }
  107. int dw_pcm_register(struct platform_device *pdev)
  108. {
  109. return -EINVAL;
  110. }
  111. #endif
  112. #endif