intel_hdmi_lpe_audio.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. /*
  2. * intel_hdmi_lpe_audio.h - Intel HDMI LPE audio driver
  3. *
  4. * Copyright (C) 2016 Intel Corp
  5. * Authors: Sailaja Bandarupalli <sailaja.bandarupalli@intel.com>
  6. * Ramesh Babu K V <ramesh.babu@intel.com>
  7. * Vaibhav Agarwal <vaibhav.agarwal@intel.com>
  8. * Jerome Anand <jerome.anand@intel.com>
  9. * Aravind Siddappaji <aravindx.siddappaji@intel.com>
  10. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; version 2 of the License.
  15. *
  16. * This program is distributed in the hope that it will be useful, but
  17. * WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * General Public License for more details.
  20. *
  21. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  22. */
  23. #ifndef __INTEL_HDMI_LPE_AUDIO_H
  24. #define __INTEL_HDMI_LPE_AUDIO_H
  25. #include <linux/types.h>
  26. #include <sound/initval.h>
  27. #include <linux/version.h>
  28. #include <linux/pm_runtime.h>
  29. #include <linux/platform_device.h>
  30. #include <sound/asoundef.h>
  31. #include <sound/control.h>
  32. #include <sound/pcm.h>
  33. #define AUD_CONFIG_VALID_BIT (1<<9)
  34. #define AUD_CONFIG_DP_MODE (1<<15)
  35. #define AUD_CONFIG_BLOCK_BIT (1<<7)
  36. #define HMDI_LPE_AUDIO_DRIVER_NAME "intel-hdmi-lpe-audio"
  37. #define HAD_MAX_DEVICES 1
  38. #define HAD_MIN_CHANNEL 2
  39. #define HAD_MAX_CHANNEL 8
  40. #define HAD_NUM_OF_RING_BUFS 4
  41. /* Assume 192KHz, 8channel, 25msec period */
  42. #define HAD_MAX_BUFFER (600*1024)
  43. #define HAD_MIN_BUFFER (32*1024)
  44. #define HAD_MAX_PERIODS 4
  45. #define HAD_MIN_PERIODS 4
  46. #define HAD_MAX_PERIOD_BYTES (HAD_MAX_BUFFER/HAD_MIN_PERIODS)
  47. #define HAD_MIN_PERIOD_BYTES 256
  48. #define HAD_FIFO_SIZE 0 /* fifo not being used */
  49. #define MAX_SPEAKERS 8
  50. #define AUD_SAMPLE_RATE_32 32000
  51. #define AUD_SAMPLE_RATE_44_1 44100
  52. #define AUD_SAMPLE_RATE_48 48000
  53. #define AUD_SAMPLE_RATE_88_2 88200
  54. #define AUD_SAMPLE_RATE_96 96000
  55. #define AUD_SAMPLE_RATE_176_4 176400
  56. #define AUD_SAMPLE_RATE_192 192000
  57. #define HAD_MIN_RATE AUD_SAMPLE_RATE_32
  58. #define HAD_MAX_RATE AUD_SAMPLE_RATE_192
  59. #define DIS_SAMPLE_RATE_25_2 25200
  60. #define DIS_SAMPLE_RATE_27 27000
  61. #define DIS_SAMPLE_RATE_54 54000
  62. #define DIS_SAMPLE_RATE_74_25 74250
  63. #define DIS_SAMPLE_RATE_148_5 148500
  64. #define HAD_REG_WIDTH 0x08
  65. #define HAD_MAX_HW_BUFS 0x04
  66. #define HAD_MAX_DIP_WORDS 16
  67. #define INTEL_HAD "IntelHdmiLpeAudio"
  68. /* DP Link Rates */
  69. #define DP_2_7_GHZ 270000
  70. #define DP_1_62_GHZ 162000
  71. /* Maud Values */
  72. #define AUD_SAMPLE_RATE_32_DP_2_7_MAUD_VAL 1988
  73. #define AUD_SAMPLE_RATE_44_1_DP_2_7_MAUD_VAL 2740
  74. #define AUD_SAMPLE_RATE_48_DP_2_7_MAUD_VAL 2982
  75. #define AUD_SAMPLE_RATE_88_2_DP_2_7_MAUD_VAL 5480
  76. #define AUD_SAMPLE_RATE_96_DP_2_7_MAUD_VAL 5965
  77. #define AUD_SAMPLE_RATE_176_4_DP_2_7_MAUD_VAL 10961
  78. #define HAD_MAX_RATE_DP_2_7_MAUD_VAL 11930
  79. #define AUD_SAMPLE_RATE_32_DP_1_62_MAUD_VAL 3314
  80. #define AUD_SAMPLE_RATE_44_1_DP_1_62_MAUD_VAL 4567
  81. #define AUD_SAMPLE_RATE_48_DP_1_62_MAUD_VAL 4971
  82. #define AUD_SAMPLE_RATE_88_2_DP_1_62_MAUD_VAL 9134
  83. #define AUD_SAMPLE_RATE_96_DP_1_62_MAUD_VAL 9942
  84. #define AUD_SAMPLE_RATE_176_4_DP_1_62_MAUD_VAL 18268
  85. #define HAD_MAX_RATE_DP_1_62_MAUD_VAL 19884
  86. /* Naud Value */
  87. #define DP_NAUD_VAL 32768
  88. /* _AUD_CONFIG register MASK */
  89. #define AUD_CONFIG_MASK_UNDERRUN 0xC0000000
  90. #define AUD_CONFIG_MASK_SRDBG 0x00000002
  91. #define AUD_CONFIG_MASK_FUNCRST 0x00000001
  92. #define MAX_CNT 0xFF
  93. #define HAD_SUSPEND_DELAY 1000
  94. #define OTM_HDMI_ELD_SIZE 128
  95. union otm_hdmi_eld_t {
  96. unsigned char eld_data[OTM_HDMI_ELD_SIZE];
  97. struct {
  98. /* Byte[0] = ELD Version Number */
  99. union {
  100. unsigned char byte0;
  101. struct {
  102. unsigned char reserved:3; /* Reserf */
  103. unsigned char eld_ver:5; /* ELD Version Number */
  104. /* 00000b - reserved
  105. * 00001b - first rev, obsoleted
  106. * 00010b - version 2, supporting CEA version
  107. * 861D or below
  108. * 00011b:11111b - reserved
  109. * for future
  110. */
  111. };
  112. };
  113. /* Byte[1] = Vendor Version Field */
  114. union {
  115. unsigned char vendor_version;
  116. struct {
  117. unsigned char reserved1:3;
  118. unsigned char veld_ver:5; /* Version number of the ELD
  119. * extension. This value is
  120. * provisioned and unique to
  121. * each vendor.
  122. */
  123. };
  124. };
  125. /* Byte[2] = Baseline Length field */
  126. unsigned char baseline_eld_length; /* Length of the Baseline structure
  127. * divided by Four.
  128. */
  129. /* Byte [3] = Reserved for future use */
  130. unsigned char byte3;
  131. /* Starting of the BaseLine EELD structure
  132. * Byte[4] = Monitor Name Length
  133. */
  134. union {
  135. unsigned char byte4;
  136. struct {
  137. unsigned char mnl:5;
  138. unsigned char cea_edid_rev_id:3;
  139. };
  140. };
  141. /* Byte[5] = Capabilities */
  142. union {
  143. unsigned char capabilities;
  144. struct {
  145. unsigned char hdcp:1; /* HDCP support */
  146. unsigned char ai_support:1; /* AI support */
  147. unsigned char connection_type:2; /* Connection type
  148. * 00 - HDMI
  149. * 01 - DP
  150. * 10 -11 Reserved
  151. * for future
  152. * connection types
  153. */
  154. unsigned char sadc:4; /* Indicates number of 3 bytes
  155. * Short Audio Descriptors.
  156. */
  157. };
  158. };
  159. /* Byte[6] = Audio Synch Delay */
  160. unsigned char audio_synch_delay; /* Amount of time reported by the
  161. * sink that the video trails audio
  162. * in milliseconds.
  163. */
  164. /* Byte[7] = Speaker Allocation Block */
  165. union {
  166. unsigned char speaker_allocation_block;
  167. struct {
  168. unsigned char flr:1; /*Front Left and Right channels*/
  169. unsigned char lfe:1; /*Low Frequency Effect channel*/
  170. unsigned char fc:1; /*Center transmission channel*/
  171. unsigned char rlr:1; /*Rear Left and Right channels*/
  172. unsigned char rc:1; /*Rear Center channel*/
  173. unsigned char flrc:1; /*Front left and Right of Center
  174. *transmission channels
  175. */
  176. unsigned char rlrc:1; /*Rear left and Right of Center
  177. *transmission channels
  178. */
  179. unsigned char reserved3:1; /* Reserved */
  180. };
  181. };
  182. /* Byte[8 - 15] - 8 Byte port identification value */
  183. unsigned char port_id_value[8];
  184. /* Byte[16 - 17] - 2 Byte Manufacturer ID */
  185. unsigned char manufacturer_id[2];
  186. /* Byte[18 - 19] - 2 Byte Product ID */
  187. unsigned char product_id[2];
  188. /* Byte [20-83] - 64 Bytes of BaseLine Data */
  189. unsigned char mn_sand_sads[64]; /* This will include
  190. * - ASCII string of Monitor name
  191. * - List of 3 byte SADs
  192. * - Zero padding
  193. */
  194. /* Vendor ELD Block should continue here!
  195. * No Vendor ELD block defined as of now.
  196. */
  197. } __packed;
  198. };
  199. /**
  200. * enum had_status - Audio stream states
  201. *
  202. * @STREAM_INIT: Stream initialized
  203. * @STREAM_RUNNING: Stream running
  204. * @STREAM_PAUSED: Stream paused
  205. * @STREAM_DROPPED: Stream dropped
  206. */
  207. enum had_stream_status {
  208. STREAM_INIT = 0,
  209. STREAM_RUNNING = 1,
  210. STREAM_PAUSED = 2,
  211. STREAM_DROPPED = 3
  212. };
  213. /**
  214. * enum had_status_stream - HAD stream states
  215. */
  216. enum had_status_stream {
  217. HAD_INIT = 0,
  218. HAD_RUNNING_STREAM,
  219. };
  220. enum had_drv_status {
  221. HAD_DRV_CONNECTED,
  222. HAD_DRV_RUNNING,
  223. HAD_DRV_DISCONNECTED,
  224. HAD_DRV_SUSPENDED,
  225. HAD_DRV_ERR,
  226. };
  227. /* enum intel_had_aud_buf_type - HDMI controller ring buffer types */
  228. enum intel_had_aud_buf_type {
  229. HAD_BUF_TYPE_A = 0,
  230. HAD_BUF_TYPE_B = 1,
  231. HAD_BUF_TYPE_C = 2,
  232. HAD_BUF_TYPE_D = 3,
  233. };
  234. enum num_aud_ch {
  235. CH_STEREO = 0,
  236. CH_THREE_FOUR = 1,
  237. CH_FIVE_SIX = 2,
  238. CH_SEVEN_EIGHT = 3
  239. };
  240. /* HDMI Controller register offsets - audio domain common */
  241. /* Base address for below regs = 0x65000 */
  242. enum hdmi_ctrl_reg_offset_common {
  243. AUDIO_HDMI_CONFIG_A = 0x000,
  244. AUDIO_HDMI_CONFIG_B = 0x800,
  245. AUDIO_HDMI_CONFIG_C = 0x900,
  246. };
  247. /* HDMI controller register offsets */
  248. enum hdmi_ctrl_reg_offset {
  249. AUD_CONFIG = 0x0,
  250. AUD_CH_STATUS_0 = 0x08,
  251. AUD_CH_STATUS_1 = 0x0C,
  252. AUD_HDMI_CTS = 0x10,
  253. AUD_N_ENABLE = 0x14,
  254. AUD_SAMPLE_RATE = 0x18,
  255. AUD_BUF_CONFIG = 0x20,
  256. AUD_BUF_CH_SWAP = 0x24,
  257. AUD_BUF_A_ADDR = 0x40,
  258. AUD_BUF_A_LENGTH = 0x44,
  259. AUD_BUF_B_ADDR = 0x48,
  260. AUD_BUF_B_LENGTH = 0x4c,
  261. AUD_BUF_C_ADDR = 0x50,
  262. AUD_BUF_C_LENGTH = 0x54,
  263. AUD_BUF_D_ADDR = 0x58,
  264. AUD_BUF_D_LENGTH = 0x5c,
  265. AUD_CNTL_ST = 0x60,
  266. AUD_HDMI_STATUS = 0x64, /* v2 */
  267. AUD_HDMIW_INFOFR = 0x68, /* v2 */
  268. };
  269. /*
  270. * CEA speaker placement:
  271. *
  272. * FL FLC FC FRC FR
  273. *
  274. * LFE
  275. *
  276. * RL RLC RC RRC RR
  277. *
  278. * The Left/Right Surround channel _notions_ LS/RS in SMPTE 320M
  279. * corresponds to CEA RL/RR; The SMPTE channel _assignment_ C/LFE is
  280. * swapped to CEA LFE/FC.
  281. */
  282. enum cea_speaker_placement {
  283. FL = (1 << 0), /* Front Left */
  284. FC = (1 << 1), /* Front Center */
  285. FR = (1 << 2), /* Front Right */
  286. FLC = (1 << 3), /* Front Left Center */
  287. FRC = (1 << 4), /* Front Right Center */
  288. RL = (1 << 5), /* Rear Left */
  289. RC = (1 << 6), /* Rear Center */
  290. RR = (1 << 7), /* Rear Right */
  291. RLC = (1 << 8), /* Rear Left Center */
  292. RRC = (1 << 9), /* Rear Right Center */
  293. LFE = (1 << 10), /* Low Frequency Effect */
  294. };
  295. struct cea_channel_speaker_allocation {
  296. int ca_index;
  297. int speakers[8];
  298. /* derived values, just for convenience */
  299. int channels;
  300. int spk_mask;
  301. };
  302. struct channel_map_table {
  303. unsigned char map; /* ALSA API channel map position */
  304. unsigned char cea_slot; /* CEA slot value */
  305. int spk_mask; /* speaker position bit mask */
  306. };
  307. /**
  308. * union aud_cfg - Audio configuration
  309. *
  310. * @cfg_regx: individual register bits
  311. * @cfg_regval: full register value
  312. *
  313. */
  314. union aud_cfg {
  315. struct {
  316. u32 aud_en:1;
  317. u32 layout:1;
  318. u32 fmt:2;
  319. u32 num_ch:3;
  320. u32 set:1;
  321. u32 flat:1;
  322. u32 val_bit:1;
  323. u32 user_bit:1;
  324. u32 underrun:1;
  325. u32 packet_mode:1;
  326. u32 left_align:1;
  327. u32 bogus_sample:1;
  328. u32 dp_modei:1;
  329. u32 rsvd:16;
  330. } cfg_regx;
  331. u32 cfg_regval;
  332. };
  333. /**
  334. * union aud_ch_status_0 - Audio Channel Status 0 Attributes
  335. *
  336. * @status_0_regx:individual register bits
  337. * @status_0_regval:full register value
  338. *
  339. */
  340. union aud_ch_status_0 {
  341. struct {
  342. u32 ch_status:1;
  343. u32 lpcm_id:1;
  344. u32 cp_info:1;
  345. u32 format:3;
  346. u32 mode:2;
  347. u32 ctg_code:8;
  348. u32 src_num:4;
  349. u32 ch_num:4;
  350. u32 samp_freq:4;
  351. u32 clk_acc:2;
  352. u32 rsvd:2;
  353. } status_0_regx;
  354. u32 status_0_regval;
  355. };
  356. /**
  357. * union aud_ch_status_1 - Audio Channel Status 1 Attributes
  358. *
  359. * @status_1_regx: individual register bits
  360. * @status_1_regval: full register value
  361. *
  362. */
  363. union aud_ch_status_1 {
  364. struct {
  365. u32 max_wrd_len:1;
  366. u32 wrd_len:3;
  367. u32 rsvd:28;
  368. } status_1_regx;
  369. u32 status_1_regval;
  370. };
  371. /**
  372. * union aud_hdmi_cts - CTS register
  373. *
  374. * @cts_regx: individual register bits
  375. * @cts_regval: full register value
  376. *
  377. */
  378. union aud_hdmi_cts {
  379. struct {
  380. u32 cts_val:24;
  381. u32 en_cts_prog:1;
  382. u32 rsvd:7;
  383. } cts_regx;
  384. u32 cts_regval;
  385. };
  386. /**
  387. * union aud_hdmi_n_enable - N register
  388. *
  389. * @n_regx: individual register bits
  390. * @n_regval: full register value
  391. *
  392. */
  393. union aud_hdmi_n_enable {
  394. struct {
  395. u32 n_val:24;
  396. u32 en_n_prog:1;
  397. u32 rsvd:7;
  398. } n_regx;
  399. u32 n_regval;
  400. };
  401. /**
  402. * union aud_buf_config - Audio Buffer configurations
  403. *
  404. * @buf_cfg_regx: individual register bits
  405. * @buf_cfgval: full register value
  406. *
  407. */
  408. union aud_buf_config {
  409. struct {
  410. u32 audio_fifo_watermark:8;
  411. u32 dma_fifo_watermark:3;
  412. u32 rsvd0:5;
  413. u32 aud_delay:8;
  414. u32 rsvd1:8;
  415. } buf_cfg_regx;
  416. u32 buf_cfgval;
  417. };
  418. /**
  419. * union aud_buf_ch_swap - Audio Sample Swapping offset
  420. *
  421. * @buf_ch_swap_regx: individual register bits
  422. * @buf_ch_swap_val: full register value
  423. *
  424. */
  425. union aud_buf_ch_swap {
  426. struct {
  427. u32 first_0:3;
  428. u32 second_0:3;
  429. u32 first_1:3;
  430. u32 second_1:3;
  431. u32 first_2:3;
  432. u32 second_2:3;
  433. u32 first_3:3;
  434. u32 second_3:3;
  435. u32 rsvd:8;
  436. } buf_ch_swap_regx;
  437. u32 buf_ch_swap_val;
  438. };
  439. /**
  440. * union aud_buf_addr - Address for Audio Buffer
  441. *
  442. * @buf_addr_regx: individual register bits
  443. * @buf_addr_val: full register value
  444. *
  445. */
  446. union aud_buf_addr {
  447. struct {
  448. u32 valid:1;
  449. u32 intr_en:1;
  450. u32 rsvd:4;
  451. u32 addr:26;
  452. } buf_addr_regx;
  453. u32 buf_addr_val;
  454. };
  455. /**
  456. * union aud_buf_len - Length of Audio Buffer
  457. *
  458. * @buf_len_regx: individual register bits
  459. * @buf_len_val: full register value
  460. *
  461. */
  462. union aud_buf_len {
  463. struct {
  464. u32 buf_len:20;
  465. u32 rsvd:12;
  466. } buf_len_regx;
  467. u32 buf_len_val;
  468. };
  469. /**
  470. * union aud_ctrl_st - Audio Control State Register offset
  471. *
  472. * @ctrl_regx: individual register bits
  473. * @ctrl_val: full register value
  474. *
  475. */
  476. union aud_ctrl_st {
  477. struct {
  478. u32 ram_addr:4;
  479. u32 eld_ack:1;
  480. u32 eld_addr:4;
  481. u32 eld_buf_size:5;
  482. u32 eld_valid:1;
  483. u32 cp_ready:1;
  484. u32 dip_freq:2;
  485. u32 dip_idx:3;
  486. u32 dip_en_sta:4;
  487. u32 rsvd:7;
  488. } ctrl_regx;
  489. u32 ctrl_val;
  490. };
  491. /**
  492. * union aud_info_frame1 - Audio HDMI Widget Data Island Packet offset
  493. *
  494. * @fr1_regx: individual register bits
  495. * @fr1_val: full register value
  496. *
  497. */
  498. union aud_info_frame1 {
  499. struct {
  500. u32 pkt_type:8;
  501. u32 ver_num:8;
  502. u32 len:5;
  503. u32 rsvd:11;
  504. } fr1_regx;
  505. u32 fr1_val;
  506. };
  507. /**
  508. * union aud_info_frame2 - DIP frame 2
  509. *
  510. * @fr2_regx: individual register bits
  511. * @fr2_val: full register value
  512. *
  513. */
  514. union aud_info_frame2 {
  515. struct {
  516. u32 chksum:8;
  517. u32 chnl_cnt:3;
  518. u32 rsvd0:1;
  519. u32 coding_type:4;
  520. u32 smpl_size:2;
  521. u32 smpl_freq:3;
  522. u32 rsvd1:3;
  523. u32 format:8;
  524. } fr2_regx;
  525. u32 fr2_val;
  526. };
  527. /**
  528. * union aud_info_frame3 - DIP frame 3
  529. *
  530. * @fr3_regx: individual register bits
  531. * @fr3_val: full register value
  532. *
  533. */
  534. union aud_info_frame3 {
  535. struct {
  536. u32 chnl_alloc:8;
  537. u32 rsvd0:3;
  538. u32 lsv:4;
  539. u32 dm_inh:1;
  540. u32 rsvd1:16;
  541. } fr3_regx;
  542. u32 fr3_val;
  543. };
  544. enum hdmi_connector_status {
  545. hdmi_connector_status_connected = 1,
  546. hdmi_connector_status_disconnected = 2,
  547. hdmi_connector_status_unknown = 3,
  548. };
  549. #define HDMI_AUDIO_UNDERRUN (1UL<<31)
  550. #define HDMI_AUDIO_BUFFER_DONE (1UL<<29)
  551. #define PORT_ENABLE (1 << 31)
  552. #define SDVO_AUDIO_ENABLE (1 << 6)
  553. enum had_caps_list {
  554. HAD_GET_ELD = 1,
  555. HAD_GET_DISPLAY_RATE,
  556. HAD_GET_DP_OUTPUT,
  557. HAD_GET_LINK_RATE,
  558. HAD_SET_ENABLE_AUDIO,
  559. HAD_SET_DISABLE_AUDIO,
  560. HAD_SET_ENABLE_AUDIO_INT,
  561. HAD_SET_DISABLE_AUDIO_INT,
  562. };
  563. enum had_event_type {
  564. HAD_EVENT_HOT_PLUG = 1,
  565. HAD_EVENT_HOT_UNPLUG,
  566. HAD_EVENT_MODE_CHANGING,
  567. HAD_EVENT_AUDIO_BUFFER_DONE,
  568. HAD_EVENT_AUDIO_BUFFER_UNDERRUN,
  569. HAD_EVENT_QUERY_IS_AUDIO_BUSY,
  570. HAD_EVENT_QUERY_IS_AUDIO_SUSPENDED,
  571. };
  572. #endif