hdmi.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * HDMI driver definition for TI OMAP4 Processor.
  4. *
  5. * Copyright (C) 2010-2011 Texas Instruments Incorporated - https://www.ti.com/
  6. */
  7. #ifndef _HDMI_H
  8. #define _HDMI_H
  9. #include <linux/delay.h>
  10. #include <linux/io.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/hdmi.h>
  13. #include <sound/omap-hdmi-audio.h>
  14. #include <media/cec.h>
  15. #include <drm/drm_bridge.h>
  16. #include "omapdss.h"
  17. #include "dss.h"
  18. struct dss_device;
  19. /* HDMI Wrapper */
  20. #define HDMI_WP_REVISION 0x0
  21. #define HDMI_WP_SYSCONFIG 0x10
  22. #define HDMI_WP_IRQSTATUS_RAW 0x24
  23. #define HDMI_WP_IRQSTATUS 0x28
  24. #define HDMI_WP_IRQENABLE_SET 0x2C
  25. #define HDMI_WP_IRQENABLE_CLR 0x30
  26. #define HDMI_WP_IRQWAKEEN 0x34
  27. #define HDMI_WP_PWR_CTRL 0x40
  28. #define HDMI_WP_DEBOUNCE 0x44
  29. #define HDMI_WP_VIDEO_CFG 0x50
  30. #define HDMI_WP_VIDEO_SIZE 0x60
  31. #define HDMI_WP_VIDEO_TIMING_H 0x68
  32. #define HDMI_WP_VIDEO_TIMING_V 0x6C
  33. #define HDMI_WP_CLK 0x70
  34. #define HDMI_WP_AUDIO_CFG 0x80
  35. #define HDMI_WP_AUDIO_CFG2 0x84
  36. #define HDMI_WP_AUDIO_CTRL 0x88
  37. #define HDMI_WP_AUDIO_DATA 0x8C
  38. /* HDMI WP IRQ flags */
  39. #define HDMI_IRQ_CORE (1 << 0)
  40. #define HDMI_IRQ_OCP_TIMEOUT (1 << 4)
  41. #define HDMI_IRQ_AUDIO_FIFO_UNDERFLOW (1 << 8)
  42. #define HDMI_IRQ_AUDIO_FIFO_OVERFLOW (1 << 9)
  43. #define HDMI_IRQ_AUDIO_FIFO_SAMPLE_REQ (1 << 10)
  44. #define HDMI_IRQ_VIDEO_VSYNC (1 << 16)
  45. #define HDMI_IRQ_VIDEO_FRAME_DONE (1 << 17)
  46. #define HDMI_IRQ_PHY_LINE5V_ASSERT (1 << 24)
  47. #define HDMI_IRQ_LINK_CONNECT (1 << 25)
  48. #define HDMI_IRQ_LINK_DISCONNECT (1 << 26)
  49. #define HDMI_IRQ_PLL_LOCK (1 << 29)
  50. #define HDMI_IRQ_PLL_UNLOCK (1 << 30)
  51. #define HDMI_IRQ_PLL_RECAL (1 << 31)
  52. /* HDMI PLL */
  53. #define PLLCTRL_PLL_CONTROL 0x0
  54. #define PLLCTRL_PLL_STATUS 0x4
  55. #define PLLCTRL_PLL_GO 0x8
  56. #define PLLCTRL_CFG1 0xC
  57. #define PLLCTRL_CFG2 0x10
  58. #define PLLCTRL_CFG3 0x14
  59. #define PLLCTRL_SSC_CFG1 0x18
  60. #define PLLCTRL_SSC_CFG2 0x1C
  61. #define PLLCTRL_CFG4 0x20
  62. /* HDMI PHY */
  63. #define HDMI_TXPHY_TX_CTRL 0x0
  64. #define HDMI_TXPHY_DIGITAL_CTRL 0x4
  65. #define HDMI_TXPHY_POWER_CTRL 0x8
  66. #define HDMI_TXPHY_PAD_CFG_CTRL 0xC
  67. #define HDMI_TXPHY_BIST_CONTROL 0x1C
  68. enum hdmi_pll_pwr {
  69. HDMI_PLLPWRCMD_ALLOFF = 0,
  70. HDMI_PLLPWRCMD_PLLONLY = 1,
  71. HDMI_PLLPWRCMD_BOTHON_ALLCLKS = 2,
  72. HDMI_PLLPWRCMD_BOTHON_NOPHYCLK = 3
  73. };
  74. enum hdmi_phy_pwr {
  75. HDMI_PHYPWRCMD_OFF = 0,
  76. HDMI_PHYPWRCMD_LDOON = 1,
  77. HDMI_PHYPWRCMD_TXON = 2
  78. };
  79. enum hdmi_core_hdmi_dvi {
  80. HDMI_DVI = 0,
  81. HDMI_HDMI = 1
  82. };
  83. enum hdmi_packing_mode {
  84. HDMI_PACK_10b_RGB_YUV444 = 0,
  85. HDMI_PACK_24b_RGB_YUV444_YUV422 = 1,
  86. HDMI_PACK_20b_YUV422 = 2,
  87. HDMI_PACK_ALREADYPACKED = 7
  88. };
  89. enum hdmi_stereo_channels {
  90. HDMI_AUDIO_STEREO_NOCHANNELS = 0,
  91. HDMI_AUDIO_STEREO_ONECHANNEL = 1,
  92. HDMI_AUDIO_STEREO_TWOCHANNELS = 2,
  93. HDMI_AUDIO_STEREO_THREECHANNELS = 3,
  94. HDMI_AUDIO_STEREO_FOURCHANNELS = 4
  95. };
  96. enum hdmi_audio_type {
  97. HDMI_AUDIO_TYPE_LPCM = 0,
  98. HDMI_AUDIO_TYPE_IEC = 1
  99. };
  100. enum hdmi_audio_justify {
  101. HDMI_AUDIO_JUSTIFY_LEFT = 0,
  102. HDMI_AUDIO_JUSTIFY_RIGHT = 1
  103. };
  104. enum hdmi_audio_sample_order {
  105. HDMI_AUDIO_SAMPLE_RIGHT_FIRST = 0,
  106. HDMI_AUDIO_SAMPLE_LEFT_FIRST = 1
  107. };
  108. enum hdmi_audio_samples_perword {
  109. HDMI_AUDIO_ONEWORD_ONESAMPLE = 0,
  110. HDMI_AUDIO_ONEWORD_TWOSAMPLES = 1
  111. };
  112. enum hdmi_audio_sample_size_omap {
  113. HDMI_AUDIO_SAMPLE_16BITS = 0,
  114. HDMI_AUDIO_SAMPLE_24BITS = 1
  115. };
  116. enum hdmi_audio_transf_mode {
  117. HDMI_AUDIO_TRANSF_DMA = 0,
  118. HDMI_AUDIO_TRANSF_IRQ = 1
  119. };
  120. enum hdmi_audio_blk_strt_end_sig {
  121. HDMI_AUDIO_BLOCK_SIG_STARTEND_ON = 0,
  122. HDMI_AUDIO_BLOCK_SIG_STARTEND_OFF = 1
  123. };
  124. enum hdmi_core_audio_layout {
  125. HDMI_AUDIO_LAYOUT_2CH = 0,
  126. HDMI_AUDIO_LAYOUT_8CH = 1,
  127. HDMI_AUDIO_LAYOUT_6CH = 2
  128. };
  129. enum hdmi_core_cts_mode {
  130. HDMI_AUDIO_CTS_MODE_HW = 0,
  131. HDMI_AUDIO_CTS_MODE_SW = 1
  132. };
  133. enum hdmi_audio_mclk_mode {
  134. HDMI_AUDIO_MCLK_128FS = 0,
  135. HDMI_AUDIO_MCLK_256FS = 1,
  136. HDMI_AUDIO_MCLK_384FS = 2,
  137. HDMI_AUDIO_MCLK_512FS = 3,
  138. HDMI_AUDIO_MCLK_768FS = 4,
  139. HDMI_AUDIO_MCLK_1024FS = 5,
  140. HDMI_AUDIO_MCLK_1152FS = 6,
  141. HDMI_AUDIO_MCLK_192FS = 7
  142. };
  143. struct hdmi_video_format {
  144. enum hdmi_packing_mode packing_mode;
  145. u32 y_res; /* Line per panel */
  146. u32 x_res; /* pixel per line */
  147. };
  148. struct hdmi_config {
  149. struct videomode vm;
  150. struct hdmi_avi_infoframe infoframe;
  151. enum hdmi_core_hdmi_dvi hdmi_dvi_mode;
  152. };
  153. struct hdmi_audio_format {
  154. enum hdmi_stereo_channels stereo_channels;
  155. u8 active_chnnls_msk;
  156. enum hdmi_audio_type type;
  157. enum hdmi_audio_justify justification;
  158. enum hdmi_audio_sample_order sample_order;
  159. enum hdmi_audio_samples_perword samples_per_word;
  160. enum hdmi_audio_sample_size_omap sample_size;
  161. enum hdmi_audio_blk_strt_end_sig en_sig_blk_strt_end;
  162. };
  163. struct hdmi_audio_dma {
  164. u8 transfer_size;
  165. u8 block_size;
  166. enum hdmi_audio_transf_mode mode;
  167. u16 fifo_threshold;
  168. };
  169. struct hdmi_core_audio_i2s_config {
  170. u8 in_length_bits;
  171. u8 justification;
  172. u8 sck_edge_mode;
  173. u8 vbit;
  174. u8 direction;
  175. u8 shift;
  176. u8 active_sds;
  177. };
  178. struct hdmi_core_audio_config {
  179. struct hdmi_core_audio_i2s_config i2s_cfg;
  180. struct snd_aes_iec958 *iec60958_cfg;
  181. bool fs_override;
  182. u32 n;
  183. u32 cts;
  184. u32 aud_par_busclk;
  185. enum hdmi_core_audio_layout layout;
  186. enum hdmi_core_cts_mode cts_mode;
  187. bool use_mclk;
  188. enum hdmi_audio_mclk_mode mclk_mode;
  189. bool en_acr_pkt;
  190. bool en_dsd_audio;
  191. bool en_parallel_aud_input;
  192. bool en_spdif;
  193. };
  194. struct hdmi_wp_data {
  195. void __iomem *base;
  196. phys_addr_t phys_base;
  197. unsigned int version;
  198. };
  199. struct hdmi_pll_data {
  200. struct dss_pll pll;
  201. void __iomem *base;
  202. struct platform_device *pdev;
  203. struct hdmi_wp_data *wp;
  204. };
  205. struct hdmi_phy_features {
  206. bool bist_ctrl;
  207. bool ldo_voltage;
  208. unsigned long max_phy;
  209. };
  210. struct hdmi_phy_data {
  211. void __iomem *base;
  212. const struct hdmi_phy_features *features;
  213. u8 lane_function[4];
  214. u8 lane_polarity[4];
  215. };
  216. struct hdmi_core_data {
  217. void __iomem *base;
  218. bool cts_swmode;
  219. bool audio_use_mclk;
  220. struct hdmi_wp_data *wp;
  221. unsigned int core_pwr_cnt;
  222. struct cec_adapter *adap;
  223. };
  224. static inline void hdmi_write_reg(void __iomem *base_addr, const u32 idx,
  225. u32 val)
  226. {
  227. __raw_writel(val, base_addr + idx);
  228. }
  229. static inline u32 hdmi_read_reg(void __iomem *base_addr, const u32 idx)
  230. {
  231. return __raw_readl(base_addr + idx);
  232. }
  233. #define REG_FLD_MOD(base, idx, val, start, end) \
  234. hdmi_write_reg(base, idx, FLD_MOD(hdmi_read_reg(base, idx),\
  235. val, start, end))
  236. #define REG_GET(base, idx, start, end) \
  237. FLD_GET(hdmi_read_reg(base, idx), start, end)
  238. static inline int hdmi_wait_for_bit_change(void __iomem *base_addr,
  239. const u32 idx, int b2, int b1, u32 val)
  240. {
  241. u32 t = 0, v;
  242. while (val != (v = REG_GET(base_addr, idx, b2, b1))) {
  243. if (t++ > 10000)
  244. return v;
  245. udelay(1);
  246. }
  247. return v;
  248. }
  249. /* HDMI wrapper funcs */
  250. int hdmi_wp_video_start(struct hdmi_wp_data *wp);
  251. void hdmi_wp_video_stop(struct hdmi_wp_data *wp);
  252. void hdmi_wp_dump(struct hdmi_wp_data *wp, struct seq_file *s);
  253. u32 hdmi_wp_get_irqstatus(struct hdmi_wp_data *wp);
  254. void hdmi_wp_set_irqstatus(struct hdmi_wp_data *wp, u32 irqstatus);
  255. void hdmi_wp_set_irqenable(struct hdmi_wp_data *wp, u32 mask);
  256. void hdmi_wp_clear_irqenable(struct hdmi_wp_data *wp, u32 mask);
  257. int hdmi_wp_set_phy_pwr(struct hdmi_wp_data *wp, enum hdmi_phy_pwr val);
  258. int hdmi_wp_set_pll_pwr(struct hdmi_wp_data *wp, enum hdmi_pll_pwr val);
  259. void hdmi_wp_video_config_format(struct hdmi_wp_data *wp,
  260. const struct hdmi_video_format *video_fmt);
  261. void hdmi_wp_video_config_interface(struct hdmi_wp_data *wp,
  262. const struct videomode *vm);
  263. void hdmi_wp_video_config_timing(struct hdmi_wp_data *wp,
  264. const struct videomode *vm);
  265. void hdmi_wp_init_vid_fmt_timings(struct hdmi_video_format *video_fmt,
  266. struct videomode *vm, const struct hdmi_config *param);
  267. int hdmi_wp_init(struct platform_device *pdev, struct hdmi_wp_data *wp,
  268. unsigned int version);
  269. phys_addr_t hdmi_wp_get_audio_dma_addr(struct hdmi_wp_data *wp);
  270. /* HDMI PLL funcs */
  271. void hdmi_pll_dump(struct hdmi_pll_data *pll, struct seq_file *s);
  272. int hdmi_pll_init(struct dss_device *dss, struct platform_device *pdev,
  273. struct hdmi_pll_data *pll, struct hdmi_wp_data *wp);
  274. void hdmi_pll_uninit(struct hdmi_pll_data *hpll);
  275. /* HDMI PHY funcs */
  276. int hdmi_phy_configure(struct hdmi_phy_data *phy, unsigned long hfbitclk,
  277. unsigned long lfbitclk);
  278. void hdmi_phy_dump(struct hdmi_phy_data *phy, struct seq_file *s);
  279. int hdmi_phy_init(struct platform_device *pdev, struct hdmi_phy_data *phy,
  280. unsigned int version);
  281. int hdmi_phy_parse_lanes(struct hdmi_phy_data *phy, const u32 *lanes);
  282. /* HDMI common funcs */
  283. int hdmi_parse_lanes_of(struct platform_device *pdev, struct device_node *ep,
  284. struct hdmi_phy_data *phy);
  285. /* Audio funcs */
  286. int hdmi_compute_acr(u32 pclk, u32 sample_freq, u32 *n, u32 *cts);
  287. int hdmi_wp_audio_enable(struct hdmi_wp_data *wp, bool enable);
  288. int hdmi_wp_audio_core_req_enable(struct hdmi_wp_data *wp, bool enable);
  289. void hdmi_wp_audio_config_format(struct hdmi_wp_data *wp,
  290. struct hdmi_audio_format *aud_fmt);
  291. void hdmi_wp_audio_config_dma(struct hdmi_wp_data *wp,
  292. struct hdmi_audio_dma *aud_dma);
  293. static inline bool hdmi_mode_has_audio(struct hdmi_config *cfg)
  294. {
  295. return cfg->hdmi_dvi_mode == HDMI_HDMI ? true : false;
  296. }
  297. /* HDMI DRV data */
  298. struct omap_hdmi {
  299. struct mutex lock;
  300. struct platform_device *pdev;
  301. struct dss_device *dss;
  302. struct dss_debugfs_entry *debugfs;
  303. struct hdmi_wp_data wp;
  304. struct hdmi_pll_data pll;
  305. struct hdmi_phy_data phy;
  306. struct hdmi_core_data core;
  307. struct hdmi_config cfg;
  308. struct regulator *vdda_reg;
  309. bool core_enabled;
  310. struct omap_dss_device output;
  311. struct drm_bridge bridge;
  312. struct platform_device *audio_pdev;
  313. void (*audio_abort_cb)(struct device *dev);
  314. int wp_idlemode;
  315. bool audio_configured;
  316. struct omap_dss_audio audio_config;
  317. /* This lock should be taken when booleans below are touched. */
  318. spinlock_t audio_playing_lock;
  319. bool audio_playing;
  320. bool display_enabled;
  321. };
  322. #define drm_bridge_to_hdmi(b) container_of(b, struct omap_hdmi, bridge)
  323. #endif