i2s.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (C) 2012 Samsung Electronics
  4. * R. Chandrasekar <rcsekar@samsung.com>
  5. */
  6. #ifndef __I2S_H__
  7. #define __I2S_H__
  8. /*
  9. * DAI hardware audio formats.
  10. *
  11. * Describes the physical PCM data formating and clocking. Add new formats
  12. * to the end.
  13. */
  14. #define SND_SOC_DAIFMT_I2S 1 /* I2S mode */
  15. #define SND_SOC_DAIFMT_RIGHT_J 2 /* Right Justified mode */
  16. #define SND_SOC_DAIFMT_LEFT_J 3 /* Left Justified mode */
  17. #define SND_SOC_DAIFMT_DSP_A 4 /* L data MSB after FRM LRC */
  18. #define SND_SOC_DAIFMT_DSP_B 5 /* L data MSB during FRM LRC */
  19. #define SND_SOC_DAIFMT_AC97 6 /* AC97 */
  20. #define SND_SOC_DAIFMT_PDM 7 /* Pulse density modulation */
  21. /* left and right justified also known as MSB and LSB respectively */
  22. #define SND_SOC_DAIFMT_MSB SND_SOC_DAIFMT_LEFT_J
  23. #define SND_SOC_DAIFMT_LSB SND_SOC_DAIFMT_RIGHT_J
  24. /*
  25. * DAI hardware signal inversions.
  26. *
  27. * Specifies whether the DAI can also support inverted clocks for the specified
  28. * format.
  29. */
  30. #define SND_SOC_DAIFMT_NB_NF (1 << 8) /* normal bit clock + frame */
  31. #define SND_SOC_DAIFMT_NB_IF (2 << 8) /* normal BCLK + inv FRM */
  32. #define SND_SOC_DAIFMT_IB_NF (3 << 8) /* invert BCLK + nor FRM */
  33. #define SND_SOC_DAIFMT_IB_IF (4 << 8) /* invert BCLK + FRM */
  34. /*
  35. * DAI hardware clock masters.
  36. *
  37. * This is wrt the codec, the inverse is true for the interface
  38. * i.e. if the codec is clk and FRM master then the interface is
  39. * clk and frame slave.
  40. */
  41. #define SND_SOC_DAIFMT_CBM_CFM (1 << 12) /* codec clk & FRM master */
  42. #define SND_SOC_DAIFMT_CBS_CFM (2 << 12) /* codec clk slave & FRM master */
  43. #define SND_SOC_DAIFMT_CBM_CFS (3 << 12) /* codec clk master & frame slave */
  44. #define SND_SOC_DAIFMT_CBS_CFS (4 << 12) /* codec clk & FRM slave */
  45. #define SND_SOC_DAIFMT_FORMAT_MASK 0x000f
  46. #define SND_SOC_DAIFMT_CLOCK_MASK 0x00f0
  47. #define SND_SOC_DAIFMT_INV_MASK 0x0f00
  48. #define SND_SOC_DAIFMT_MASTER_MASK 0xf000
  49. /*
  50. * Master Clock Directions
  51. */
  52. #define SND_SOC_CLOCK_IN 0
  53. #define SND_SOC_CLOCK_OUT 1
  54. /* I2S Tx Control */
  55. #define I2S_TX_ON 1
  56. #define I2S_TX_OFF 0
  57. #define FIFO_LENGTH 64
  58. /* I2s Registers */
  59. struct i2s_reg {
  60. unsigned int con; /* base + 0 , Control register */
  61. unsigned int mod; /* Mode register */
  62. unsigned int fic; /* FIFO control register */
  63. unsigned int psr; /* Reserved */
  64. unsigned int txd; /* Transmit data register */
  65. unsigned int rxd; /* Receive Data Register */
  66. };
  67. /* This structure stores the i2s related information */
  68. struct i2s_uc_priv {
  69. unsigned int rfs; /* LR clock frame size */
  70. unsigned int bfs; /* Bit clock frame size */
  71. unsigned int audio_pll_clk; /* Audio pll frequency in Hz */
  72. unsigned int samplingrate; /* sampling rate */
  73. unsigned int bitspersample; /* bits per sample */
  74. unsigned int channels; /* audio channels */
  75. unsigned int base_address; /* I2S Register Base */
  76. unsigned int id; /* I2S controller id */
  77. };
  78. /* Operations for i2s devices */
  79. struct i2s_ops {
  80. /**
  81. * tx_data() - Transmit audio data
  82. *
  83. * @dev: I2C device
  84. * @data: Data buffer to play
  85. * @data_size: Size of data buffer in bytes
  86. * @return 0 if OK, -ve on error
  87. */
  88. int (*tx_data)(struct udevice *dev, void *data, uint data_size);
  89. };
  90. #define i2s_get_ops(dev) ((struct i2s_ops *)(dev)->driver->ops)
  91. /**
  92. * i2s_tx_data() - Transmit audio data
  93. *
  94. * @dev: I2C device
  95. * @data: Data buffer to play
  96. * @data_size: Size of data buffer in bytes
  97. * @return 0 if OK, -ve on error
  98. */
  99. int i2s_tx_data(struct udevice *dev, void *data, uint data_size);
  100. /*
  101. * Sends the given data through i2s tx
  102. *
  103. * @param pi2s_tx pointer of i2s transmitter parameter structure.
  104. * @param data address of the data buffer
  105. * @param data_size size of the data (in bytes)
  106. * @return int value 0 for success, -1 in case of error
  107. */
  108. int i2s_transfer_tx_data(struct i2s_uc_priv *pi2s_tx, void *data,
  109. uint data_size);
  110. #endif /* __I2S_H__ */