hdmi.h 10 KB

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