intel_hdmi_audio.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * Copyright (C) 2016 Intel Corporation
  3. * Authors: Sailaja Bandarupalli <sailaja.bandarupalli@intel.com>
  4. * Ramesh Babu K V <ramesh.babu@intel.com>
  5. * Vaibhav Agarwal <vaibhav.agarwal@intel.com>
  6. * Jerome Anand <jerome.anand@intel.com>
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining
  9. * a copy of this software and associated documentation files
  10. * (the "Software"), to deal in the Software without restriction,
  11. * including without limitation the rights to use, copy, modify, merge,
  12. * publish, distribute, sublicense, and/or sell copies of the Software,
  13. * and to permit persons to whom the Software is furnished to do so,
  14. * subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice (including the
  17. * next paragraph) shall be included in all copies or substantial
  18. * portions of the Software.
  19. *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  24. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  25. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  26. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  27. * SOFTWARE.
  28. */
  29. #ifndef _INTEL_HDMI_AUDIO_H_
  30. #define _INTEL_HDMI_AUDIO_H_
  31. #include <linux/types.h>
  32. #include <sound/initval.h>
  33. #include <linux/version.h>
  34. #include <linux/pm_runtime.h>
  35. #include <sound/asoundef.h>
  36. #include <sound/control.h>
  37. #include <sound/pcm.h>
  38. #include "intel_hdmi_lpe_audio.h"
  39. struct platform_device;
  40. #define PCM_INDEX 0
  41. #define MAX_PB_STREAMS 1
  42. #define MAX_CAP_STREAMS 0
  43. #define HDMI_AUDIO_DRIVER "hdmi-audio"
  44. #define HDMI_INFO_FRAME_WORD1 0x000a0184
  45. #define DP_INFO_FRAME_WORD1 0x00441b84
  46. #define FIFO_THRESHOLD 0xFE
  47. #define DMA_FIFO_THRESHOLD 0x7
  48. #define BYTES_PER_WORD 0x4
  49. /* Sampling rate as per IEC60958 Ver 3 */
  50. #define CH_STATUS_MAP_32KHZ 0x3
  51. #define CH_STATUS_MAP_44KHZ 0x0
  52. #define CH_STATUS_MAP_48KHZ 0x2
  53. #define CH_STATUS_MAP_88KHZ 0x8
  54. #define CH_STATUS_MAP_96KHZ 0xA
  55. #define CH_STATUS_MAP_176KHZ 0xC
  56. #define CH_STATUS_MAP_192KHZ 0xE
  57. #define MAX_SMPL_WIDTH_20 0x0
  58. #define MAX_SMPL_WIDTH_24 0x1
  59. #define SMPL_WIDTH_16BITS 0x1
  60. #define SMPL_WIDTH_24BITS 0x5
  61. #define CHANNEL_ALLOCATION 0x1F
  62. #define MASK_BYTE0 0x000000FF
  63. #define VALID_DIP_WORDS 3
  64. #define LAYOUT0 0
  65. #define LAYOUT1 1
  66. #define SWAP_LFE_CENTER 0x00fac4c8
  67. #define AUD_CONFIG_CH_MASK_V2 0x70
  68. struct pcm_stream_info {
  69. int str_id;
  70. void *had_substream;
  71. void (*period_elapsed)(void *had_substream);
  72. u32 buffer_ptr;
  73. u64 buffer_rendered;
  74. u32 ring_buf_size;
  75. int sfreq;
  76. };
  77. struct ring_buf_info {
  78. u32 buf_addr;
  79. u32 buf_size;
  80. u8 is_valid;
  81. };
  82. struct had_stream_pvt {
  83. enum had_stream_status stream_status;
  84. int stream_ops;
  85. ssize_t dbg_cum_bytes;
  86. };
  87. struct had_stream_data {
  88. enum had_status_stream stream_type;
  89. };
  90. /**
  91. * struct snd_intelhad - intelhad driver structure
  92. *
  93. * @card: ptr to hold card details
  94. * @card_index: sound card index
  95. * @card_id: detected sound card id
  96. * @drv_status: driver status
  97. * @buf_info: ring buffer info
  98. * @stream_info: stream information
  99. * @eeld: holds EELD info
  100. * @curr_buf: pointer to hold current active ring buf
  101. * @valid_buf_cnt: ring buffer count for stream
  102. * @had_spinlock: driver lock
  103. * @aes_bits: IEC958 status bits
  104. * @buff_done: id of current buffer done intr
  105. * @dev: platoform device handle
  106. * @kctl: holds kctl ptrs used for channel map
  107. * @chmap: holds channel map info
  108. * @audio_reg_base: hdmi audio register base offset
  109. * @underrun_count: PCM stream underrun counter
  110. */
  111. struct snd_intelhad {
  112. struct snd_card *card;
  113. int card_index;
  114. char *card_id;
  115. enum had_drv_status drv_status;
  116. struct ring_buf_info buf_info[HAD_NUM_OF_RING_BUFS];
  117. struct pcm_stream_info stream_info;
  118. union otm_hdmi_eld_t eeld;
  119. bool dp_output;
  120. enum intel_had_aud_buf_type curr_buf;
  121. int valid_buf_cnt;
  122. unsigned int aes_bits;
  123. int flag_underrun;
  124. struct had_stream_data stream_data;
  125. spinlock_t had_spinlock;
  126. enum intel_had_aud_buf_type buff_done;
  127. struct device *dev;
  128. struct snd_kcontrol *kctl;
  129. struct snd_pcm_chmap *chmap;
  130. unsigned int *audio_reg_base;
  131. unsigned int audio_cfg_offset;
  132. int underrun_count;
  133. };
  134. int had_event_handler(enum had_event_type event_type, void *data);
  135. int hdmi_audio_query(void *drv_data, struct hdmi_audio_event event);
  136. int hdmi_audio_suspend(void *drv_data);
  137. int hdmi_audio_resume(void *drv_data);
  138. int hdmi_audio_mode_change(struct snd_pcm_substream *substream);
  139. extern struct snd_pcm_ops snd_intelhad_playback_ops;
  140. int snd_intelhad_init_audio_ctrl(struct snd_pcm_substream *substream,
  141. struct snd_intelhad *intelhaddata,
  142. int flag_silence);
  143. int snd_intelhad_prog_buffer(struct snd_intelhad *intelhaddata,
  144. int start, int end);
  145. int snd_intelhad_invd_buffer(int start, int end);
  146. int snd_intelhad_read_len(struct snd_intelhad *intelhaddata);
  147. void had_build_channel_allocation_map(struct snd_intelhad *intelhaddata);
  148. void snd_intelhad_enable_audio(struct snd_pcm_substream *substream, u8 enable);
  149. void snd_intelhad_handle_underrun(struct snd_intelhad *intelhaddata);
  150. /* Register access functions */
  151. int had_get_hwstate(struct snd_intelhad *intelhaddata);
  152. int had_get_caps(struct snd_intelhad *intelhaddata,
  153. enum had_caps_list query_element, void *capabilties);
  154. int had_set_caps(struct snd_intelhad *intelhaddata,
  155. enum had_caps_list set_element, void *capabilties);
  156. int had_read_register(struct snd_intelhad *intelhaddata,
  157. u32 reg_addr, u32 *data);
  158. int had_write_register(struct snd_intelhad *intelhaddata,
  159. u32 reg_addr, u32 data);
  160. int had_read_modify(struct snd_intelhad *intelhaddata,
  161. u32 reg_addr, u32 data, u32 mask);
  162. int hdmi_audio_probe(struct platform_device *devptr,
  163. struct snd_intelhad **had_ret);
  164. int hdmi_audio_remove(struct snd_intelhad *intelhaddata);
  165. #endif /* _INTEL_HDMI_AUDIO_ */