interface.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * i2sbus driver -- interface register definitions
  4. *
  5. * Copyright 2006 Johannes Berg <[email protected]>
  6. */
  7. #ifndef __I2SBUS_INTERFACE_H
  8. #define __I2SBUS_INTERFACE_H
  9. /* i2s bus control registers, at least what we know about them */
  10. #define __PAD(m,n) u8 __pad##m[n]
  11. #define _PAD(line, n) __PAD(line, n)
  12. #define PAD(n) _PAD(__LINE__, (n))
  13. struct i2s_interface_regs {
  14. __le32 intr_ctl; /* 0x00 */
  15. PAD(12);
  16. __le32 serial_format; /* 0x10 */
  17. PAD(12);
  18. __le32 codec_msg_out; /* 0x20 */
  19. PAD(12);
  20. __le32 codec_msg_in; /* 0x30 */
  21. PAD(12);
  22. __le32 frame_count; /* 0x40 */
  23. PAD(12);
  24. __le32 frame_match; /* 0x50 */
  25. PAD(12);
  26. __le32 data_word_sizes; /* 0x60 */
  27. PAD(12);
  28. __le32 peak_level_sel; /* 0x70 */
  29. PAD(12);
  30. __le32 peak_level_in0; /* 0x80 */
  31. PAD(12);
  32. __le32 peak_level_in1; /* 0x90 */
  33. PAD(12);
  34. /* total size: 0x100 bytes */
  35. } __attribute__((__packed__));
  36. /* interrupt register is just a bitfield with
  37. * interrupt enable and pending bits */
  38. #define I2S_REG_INTR_CTL 0x00
  39. # define I2S_INT_FRAME_COUNT (1<<31)
  40. # define I2S_PENDING_FRAME_COUNT (1<<30)
  41. # define I2S_INT_MESSAGE_FLAG (1<<29)
  42. # define I2S_PENDING_MESSAGE_FLAG (1<<28)
  43. # define I2S_INT_NEW_PEAK (1<<27)
  44. # define I2S_PENDING_NEW_PEAK (1<<26)
  45. # define I2S_INT_CLOCKS_STOPPED (1<<25)
  46. # define I2S_PENDING_CLOCKS_STOPPED (1<<24)
  47. # define I2S_INT_EXTERNAL_SYNC_ERROR (1<<23)
  48. # define I2S_PENDING_EXTERNAL_SYNC_ERROR (1<<22)
  49. # define I2S_INT_EXTERNAL_SYNC_OK (1<<21)
  50. # define I2S_PENDING_EXTERNAL_SYNC_OK (1<<20)
  51. # define I2S_INT_NEW_SAMPLE_RATE (1<<19)
  52. # define I2S_PENDING_NEW_SAMPLE_RATE (1<<18)
  53. # define I2S_INT_STATUS_FLAG (1<<17)
  54. # define I2S_PENDING_STATUS_FLAG (1<<16)
  55. /* serial format register is more interesting :)
  56. * It contains:
  57. * - clock source
  58. * - MClk divisor
  59. * - SClk divisor
  60. * - SClk master flag
  61. * - serial format (sony, i2s 64x, i2s 32x, dav, silabs)
  62. * - external sample frequency interrupt (don't understand)
  63. * - external sample frequency
  64. */
  65. #define I2S_REG_SERIAL_FORMAT 0x10
  66. /* clock source. You get either 18.432, 45.1584 or 49.1520 MHz */
  67. # define I2S_SF_CLOCK_SOURCE_SHIFT 30
  68. # define I2S_SF_CLOCK_SOURCE_MASK (3<<I2S_SF_CLOCK_SOURCE_SHIFT)
  69. # define I2S_SF_CLOCK_SOURCE_18MHz (0<<I2S_SF_CLOCK_SOURCE_SHIFT)
  70. # define I2S_SF_CLOCK_SOURCE_45MHz (1<<I2S_SF_CLOCK_SOURCE_SHIFT)
  71. # define I2S_SF_CLOCK_SOURCE_49MHz (2<<I2S_SF_CLOCK_SOURCE_SHIFT)
  72. /* also, let's define the exact clock speeds here, in Hz */
  73. #define I2S_CLOCK_SPEED_18MHz 18432000
  74. #define I2S_CLOCK_SPEED_45MHz 45158400
  75. #define I2S_CLOCK_SPEED_49MHz 49152000
  76. /* MClk is the clock that drives the codec, usually called its 'system clock'.
  77. * It is derived by taking only every 'divisor' tick of the clock.
  78. */
  79. # define I2S_SF_MCLKDIV_SHIFT 24
  80. # define I2S_SF_MCLKDIV_MASK (0x1F<<I2S_SF_MCLKDIV_SHIFT)
  81. # define I2S_SF_MCLKDIV_1 (0x14<<I2S_SF_MCLKDIV_SHIFT)
  82. # define I2S_SF_MCLKDIV_3 (0x13<<I2S_SF_MCLKDIV_SHIFT)
  83. # define I2S_SF_MCLKDIV_5 (0x12<<I2S_SF_MCLKDIV_SHIFT)
  84. # define I2S_SF_MCLKDIV_14 (0x0E<<I2S_SF_MCLKDIV_SHIFT)
  85. # define I2S_SF_MCLKDIV_OTHER(div) (((div/2-1)<<I2S_SF_MCLKDIV_SHIFT)&I2S_SF_MCLKDIV_MASK)
  86. static inline int i2s_sf_mclkdiv(int div, int *out)
  87. {
  88. int d;
  89. switch(div) {
  90. case 1: *out |= I2S_SF_MCLKDIV_1; return 0;
  91. case 3: *out |= I2S_SF_MCLKDIV_3; return 0;
  92. case 5: *out |= I2S_SF_MCLKDIV_5; return 0;
  93. case 14: *out |= I2S_SF_MCLKDIV_14; return 0;
  94. default:
  95. if (div%2) return -1;
  96. d = div/2-1;
  97. if (d == 0x14 || d == 0x13 || d == 0x12 || d == 0x0E)
  98. return -1;
  99. *out |= I2S_SF_MCLKDIV_OTHER(div);
  100. return 0;
  101. }
  102. }
  103. /* SClk is the clock that drives the i2s wire bus. Note that it is
  104. * derived from the MClk above by taking only every 'divisor' tick
  105. * of MClk.
  106. */
  107. # define I2S_SF_SCLKDIV_SHIFT 20
  108. # define I2S_SF_SCLKDIV_MASK (0xF<<I2S_SF_SCLKDIV_SHIFT)
  109. # define I2S_SF_SCLKDIV_1 (8<<I2S_SF_SCLKDIV_SHIFT)
  110. # define I2S_SF_SCLKDIV_3 (9<<I2S_SF_SCLKDIV_SHIFT)
  111. # define I2S_SF_SCLKDIV_OTHER(div) (((div/2-1)<<I2S_SF_SCLKDIV_SHIFT)&I2S_SF_SCLKDIV_MASK)
  112. static inline int i2s_sf_sclkdiv(int div, int *out)
  113. {
  114. int d;
  115. switch(div) {
  116. case 1: *out |= I2S_SF_SCLKDIV_1; return 0;
  117. case 3: *out |= I2S_SF_SCLKDIV_3; return 0;
  118. default:
  119. if (div%2) return -1;
  120. d = div/2-1;
  121. if (d == 8 || d == 9) return -1;
  122. *out |= I2S_SF_SCLKDIV_OTHER(div);
  123. return 0;
  124. }
  125. }
  126. # define I2S_SF_SCLK_MASTER (1<<19)
  127. /* serial format is the way the data is put to the i2s wire bus */
  128. # define I2S_SF_SERIAL_FORMAT_SHIFT 16
  129. # define I2S_SF_SERIAL_FORMAT_MASK (7<<I2S_SF_SERIAL_FORMAT_SHIFT)
  130. # define I2S_SF_SERIAL_FORMAT_SONY (0<<I2S_SF_SERIAL_FORMAT_SHIFT)
  131. # define I2S_SF_SERIAL_FORMAT_I2S_64X (1<<I2S_SF_SERIAL_FORMAT_SHIFT)
  132. # define I2S_SF_SERIAL_FORMAT_I2S_32X (2<<I2S_SF_SERIAL_FORMAT_SHIFT)
  133. # define I2S_SF_SERIAL_FORMAT_I2S_DAV (4<<I2S_SF_SERIAL_FORMAT_SHIFT)
  134. # define I2S_SF_SERIAL_FORMAT_I2S_SILABS (5<<I2S_SF_SERIAL_FORMAT_SHIFT)
  135. /* unknown */
  136. # define I2S_SF_EXT_SAMPLE_FREQ_INT_SHIFT 12
  137. # define I2S_SF_EXT_SAMPLE_FREQ_INT_MASK (0xF<<I2S_SF_SAMPLE_FREQ_INT_SHIFT)
  138. /* probably gives external frequency? */
  139. # define I2S_SF_EXT_SAMPLE_FREQ_MASK 0xFFF
  140. /* used to send codec messages, but how isn't clear */
  141. #define I2S_REG_CODEC_MSG_OUT 0x20
  142. /* used to receive codec messages, but how isn't clear */
  143. #define I2S_REG_CODEC_MSG_IN 0x30
  144. /* frame count reg isn't clear to me yet, but probably useful */
  145. #define I2S_REG_FRAME_COUNT 0x40
  146. /* program to some value, and get interrupt if frame count reaches it */
  147. #define I2S_REG_FRAME_MATCH 0x50
  148. /* this register describes how the bus transfers data */
  149. #define I2S_REG_DATA_WORD_SIZES 0x60
  150. /* number of interleaved input channels */
  151. # define I2S_DWS_NUM_CHANNELS_IN_SHIFT 24
  152. # define I2S_DWS_NUM_CHANNELS_IN_MASK (0x1F<<I2S_DWS_NUM_CHANNELS_IN_SHIFT)
  153. /* word size of input data */
  154. # define I2S_DWS_DATA_IN_SIZE_SHIFT 16
  155. # define I2S_DWS_DATA_IN_16BIT (0<<I2S_DWS_DATA_IN_SIZE_SHIFT)
  156. # define I2S_DWS_DATA_IN_24BIT (3<<I2S_DWS_DATA_IN_SIZE_SHIFT)
  157. /* number of interleaved output channels */
  158. # define I2S_DWS_NUM_CHANNELS_OUT_SHIFT 8
  159. # define I2S_DWS_NUM_CHANNELS_OUT_MASK (0x1F<<I2S_DWS_NUM_CHANNELS_OUT_SHIFT)
  160. /* word size of output data */
  161. # define I2S_DWS_DATA_OUT_SIZE_SHIFT 0
  162. # define I2S_DWS_DATA_OUT_16BIT (0<<I2S_DWS_DATA_OUT_SIZE_SHIFT)
  163. # define I2S_DWS_DATA_OUT_24BIT (3<<I2S_DWS_DATA_OUT_SIZE_SHIFT)
  164. /* unknown */
  165. #define I2S_REG_PEAK_LEVEL_SEL 0x70
  166. /* unknown */
  167. #define I2S_REG_PEAK_LEVEL_IN0 0x80
  168. /* unknown */
  169. #define I2S_REG_PEAK_LEVEL_IN1 0x90
  170. #endif /* __I2SBUS_INTERFACE_H */