i2s.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Copyright (C) 2012 Samsung Electronics
  3. * R. Chandrasekar <rcsekar@samsung.com>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #ifndef __I2S_H__
  24. #define __I2S_H__
  25. /*
  26. * DAI hardware audio formats.
  27. *
  28. * Describes the physical PCM data formating and clocking. Add new formats
  29. * to the end.
  30. */
  31. #define SND_SOC_DAIFMT_I2S 1 /* I2S mode */
  32. #define SND_SOC_DAIFMT_RIGHT_J 2 /* Right Justified mode */
  33. #define SND_SOC_DAIFMT_LEFT_J 3 /* Left Justified mode */
  34. #define SND_SOC_DAIFMT_DSP_A 4 /* L data MSB after FRM LRC */
  35. #define SND_SOC_DAIFMT_DSP_B 5 /* L data MSB during FRM LRC */
  36. #define SND_SOC_DAIFMT_AC97 6 /* AC97 */
  37. #define SND_SOC_DAIFMT_PDM 7 /* Pulse density modulation */
  38. /* left and right justified also known as MSB and LSB respectively */
  39. #define SND_SOC_DAIFMT_MSB SND_SOC_DAIFMT_LEFT_J
  40. #define SND_SOC_DAIFMT_LSB SND_SOC_DAIFMT_RIGHT_J
  41. /*
  42. * DAI hardware signal inversions.
  43. *
  44. * Specifies whether the DAI can also support inverted clocks for the specified
  45. * format.
  46. */
  47. #define SND_SOC_DAIFMT_NB_NF (1 << 8) /* normal bit clock + frame */
  48. #define SND_SOC_DAIFMT_NB_IF (2 << 8) /* normal BCLK + inv FRM */
  49. #define SND_SOC_DAIFMT_IB_NF (3 << 8) /* invert BCLK + nor FRM */
  50. #define SND_SOC_DAIFMT_IB_IF (4 << 8) /* invert BCLK + FRM */
  51. /*
  52. * DAI hardware clock masters.
  53. *
  54. * This is wrt the codec, the inverse is true for the interface
  55. * i.e. if the codec is clk and FRM master then the interface is
  56. * clk and frame slave.
  57. */
  58. #define SND_SOC_DAIFMT_CBM_CFM (1 << 12) /* codec clk & FRM master */
  59. #define SND_SOC_DAIFMT_CBS_CFM (2 << 12) /* codec clk slave & FRM master */
  60. #define SND_SOC_DAIFMT_CBM_CFS (3 << 12) /* codec clk master & frame slave */
  61. #define SND_SOC_DAIFMT_CBS_CFS (4 << 12) /* codec clk & FRM slave */
  62. #define SND_SOC_DAIFMT_FORMAT_MASK 0x000f
  63. #define SND_SOC_DAIFMT_CLOCK_MASK 0x00f0
  64. #define SND_SOC_DAIFMT_INV_MASK 0x0f00
  65. #define SND_SOC_DAIFMT_MASTER_MASK 0xf000
  66. /*
  67. * Master Clock Directions
  68. */
  69. #define SND_SOC_CLOCK_IN 0
  70. #define SND_SOC_CLOCK_OUT 1
  71. /* I2S Tx Control */
  72. #define I2S_TX_ON 1
  73. #define I2S_TX_OFF 0
  74. #define FIFO_LENGTH 64
  75. /* I2s Registers */
  76. struct i2s_reg {
  77. unsigned int con; /* base + 0 , Control register */
  78. unsigned int mod; /* Mode register */
  79. unsigned int fic; /* FIFO control register */
  80. unsigned int psr; /* Reserved */
  81. unsigned int txd; /* Transmit data register */
  82. unsigned int rxd; /* Receive Data Register */
  83. };
  84. /* This structure stores the i2s related information */
  85. struct i2stx_info {
  86. unsigned int rfs; /* LR clock frame size */
  87. unsigned int bfs; /* Bit slock frame size */
  88. unsigned int audio_pll_clk; /* Audio pll frequency in Hz */
  89. unsigned int samplingrate; /* sampling rate */
  90. unsigned int bitspersample; /* bits per sample */
  91. unsigned int channels; /* audio channels */
  92. unsigned int base_address; /* I2S Register Base */
  93. };
  94. /*
  95. * Sends the given data through i2s tx
  96. *
  97. * @param pi2s_tx pointer of i2s transmitter parameter structure.
  98. * @param data address of the data buffer
  99. * @param data_size array size of the int buffer (total size / size of int)
  100. *
  101. * @return int value 0 for success, -1 in case of error
  102. */
  103. int i2s_transfer_tx_data(struct i2stx_info *pi2s_tx, unsigned *data,
  104. unsigned long data_size);
  105. /*
  106. * Initialise i2s transmiter
  107. *
  108. * @param pi2s_tx pointer of i2s transmitter parameter structure.
  109. *
  110. * @return int value 0 for success, -1 in case of error
  111. */
  112. int i2s_tx_init(struct i2stx_info *pi2s_tx);
  113. #endif /* __I2S_H__ */