Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Avionic Design GmbH |
| 3 | * Copyright (C) 2012 NVIDIA CORPORATION. All rights reserved. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation. |
| 8 | */ |
| 9 | |
| 10 | #include <linux/clk.h> |
Thierry Reding | 9eb9b22 | 2013-09-24 16:32:47 +0200 | [diff] [blame] | 11 | #include <linux/debugfs.h> |
Thierry Reding | 5968271 | 2014-11-28 16:50:59 +0100 | [diff] [blame] | 12 | #include <linux/gpio.h> |
Thierry Reding | 9eb9b22 | 2013-09-24 16:32:47 +0200 | [diff] [blame] | 13 | #include <linux/hdmi.h> |
Thierry Reding | 5e4acd3 | 2017-08-21 18:05:10 +0200 | [diff] [blame^] | 14 | #include <linux/of_device.h> |
Thierry Reding | 5234549 | 2015-08-07 16:00:43 +0200 | [diff] [blame] | 15 | #include <linux/pm_runtime.h> |
Thierry Reding | 9eb9b22 | 2013-09-24 16:32:47 +0200 | [diff] [blame] | 16 | #include <linux/regulator/consumer.h> |
Stephen Warren | ca48080 | 2013-11-06 16:20:54 -0700 | [diff] [blame] | 17 | #include <linux/reset.h> |
Thierry Reding | ac24c22 | 2012-11-23 15:14:00 +0100 | [diff] [blame] | 18 | |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame] | 19 | #include <drm/drm_atomic_helper.h> |
Thierry Reding | 5968271 | 2014-11-28 16:50:59 +0100 | [diff] [blame] | 20 | #include <drm/drm_crtc.h> |
| 21 | #include <drm/drm_crtc_helper.h> |
| 22 | |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 23 | #include <sound/hda_verbs.h> |
| 24 | |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 25 | #include "hdmi.h" |
| 26 | #include "drm.h" |
| 27 | #include "dc.h" |
Thierry Reding | 07a8aab | 2017-08-15 15:41:11 +0200 | [diff] [blame] | 28 | #include "trace.h" |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 29 | |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 30 | #define HDMI_ELD_BUFFER_SIZE 96 |
| 31 | |
Thierry Reding | 59af059 | 2013-10-14 09:43:05 +0200 | [diff] [blame] | 32 | struct tmds_config { |
| 33 | unsigned int pclk; |
| 34 | u32 pll0; |
| 35 | u32 pll1; |
| 36 | u32 pe_current; |
| 37 | u32 drive_current; |
Mikko Perttunen | 7d1d28a | 2013-09-30 16:54:47 +0200 | [diff] [blame] | 38 | u32 peak_current; |
Thierry Reding | 59af059 | 2013-10-14 09:43:05 +0200 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | struct tegra_hdmi_config { |
| 42 | const struct tmds_config *tmds; |
| 43 | unsigned int num_tmds; |
| 44 | |
| 45 | unsigned long fuse_override_offset; |
Thierry Reding | 4ee8cee | 2014-12-08 16:25:14 +0100 | [diff] [blame] | 46 | u32 fuse_override_value; |
Mikko Perttunen | 7d1d28a | 2013-09-30 16:54:47 +0200 | [diff] [blame] | 47 | |
| 48 | bool has_sor_io_peak_current; |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 49 | bool has_hda; |
| 50 | bool has_hbr; |
Thierry Reding | 59af059 | 2013-10-14 09:43:05 +0200 | [diff] [blame] | 51 | }; |
| 52 | |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 53 | struct tegra_hdmi { |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 54 | struct host1x_client client; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 55 | struct tegra_output output; |
| 56 | struct device *dev; |
| 57 | |
Thierry Reding | fb50a11 | 2014-02-28 16:57:34 +0100 | [diff] [blame] | 58 | struct regulator *hdmi; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 59 | struct regulator *pll; |
Thierry Reding | 8868568 | 2014-04-16 10:24:12 +0200 | [diff] [blame] | 60 | struct regulator *vdd; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 61 | |
| 62 | void __iomem *regs; |
| 63 | unsigned int irq; |
| 64 | |
| 65 | struct clk *clk_parent; |
| 66 | struct clk *clk; |
Stephen Warren | ca48080 | 2013-11-06 16:20:54 -0700 | [diff] [blame] | 67 | struct reset_control *rst; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 68 | |
Thierry Reding | 59af059 | 2013-10-14 09:43:05 +0200 | [diff] [blame] | 69 | const struct tegra_hdmi_config *config; |
| 70 | |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 71 | unsigned int audio_source; |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 72 | unsigned int audio_sample_rate; |
| 73 | unsigned int audio_channels; |
| 74 | |
| 75 | unsigned int pixel_clock; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 76 | bool stereo; |
| 77 | bool dvi; |
| 78 | |
| 79 | struct drm_info_list *debugfs_files; |
| 80 | struct drm_minor *minor; |
| 81 | struct dentry *debugfs; |
| 82 | }; |
| 83 | |
| 84 | static inline struct tegra_hdmi * |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 85 | host1x_client_to_hdmi(struct host1x_client *client) |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 86 | { |
| 87 | return container_of(client, struct tegra_hdmi, client); |
| 88 | } |
| 89 | |
| 90 | static inline struct tegra_hdmi *to_hdmi(struct tegra_output *output) |
| 91 | { |
| 92 | return container_of(output, struct tegra_hdmi, output); |
| 93 | } |
| 94 | |
| 95 | #define HDMI_AUDIOCLK_FREQ 216000000 |
| 96 | #define HDMI_REKEY_DEFAULT 56 |
| 97 | |
| 98 | enum { |
| 99 | AUTO = 0, |
| 100 | SPDIF, |
| 101 | HDA, |
| 102 | }; |
| 103 | |
Thierry Reding | 4ee8cee | 2014-12-08 16:25:14 +0100 | [diff] [blame] | 104 | static inline u32 tegra_hdmi_readl(struct tegra_hdmi *hdmi, |
Thierry Reding | 7efe20c | 2017-08-15 15:41:08 +0200 | [diff] [blame] | 105 | unsigned int offset) |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 106 | { |
Thierry Reding | 07a8aab | 2017-08-15 15:41:11 +0200 | [diff] [blame] | 107 | u32 value = readl(hdmi->regs + (offset << 2)); |
| 108 | |
| 109 | trace_hdmi_readl(hdmi->dev, offset, value); |
| 110 | |
| 111 | return value; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 112 | } |
| 113 | |
Thierry Reding | 4ee8cee | 2014-12-08 16:25:14 +0100 | [diff] [blame] | 114 | static inline void tegra_hdmi_writel(struct tegra_hdmi *hdmi, u32 value, |
Thierry Reding | 7efe20c | 2017-08-15 15:41:08 +0200 | [diff] [blame] | 115 | unsigned int offset) |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 116 | { |
Thierry Reding | 07a8aab | 2017-08-15 15:41:11 +0200 | [diff] [blame] | 117 | trace_hdmi_writel(hdmi->dev, offset, value); |
Thierry Reding | 4ee8cee | 2014-12-08 16:25:14 +0100 | [diff] [blame] | 118 | writel(value, hdmi->regs + (offset << 2)); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | struct tegra_hdmi_audio_config { |
| 122 | unsigned int pclk; |
| 123 | unsigned int n; |
| 124 | unsigned int cts; |
| 125 | unsigned int aval; |
| 126 | }; |
| 127 | |
| 128 | static const struct tegra_hdmi_audio_config tegra_hdmi_audio_32k[] = { |
| 129 | { 25200000, 4096, 25200, 24000 }, |
| 130 | { 27000000, 4096, 27000, 24000 }, |
| 131 | { 74250000, 4096, 74250, 24000 }, |
| 132 | { 148500000, 4096, 148500, 24000 }, |
| 133 | { 0, 0, 0, 0 }, |
| 134 | }; |
| 135 | |
| 136 | static const struct tegra_hdmi_audio_config tegra_hdmi_audio_44_1k[] = { |
| 137 | { 25200000, 5880, 26250, 25000 }, |
| 138 | { 27000000, 5880, 28125, 25000 }, |
| 139 | { 74250000, 4704, 61875, 20000 }, |
| 140 | { 148500000, 4704, 123750, 20000 }, |
| 141 | { 0, 0, 0, 0 }, |
| 142 | }; |
| 143 | |
| 144 | static const struct tegra_hdmi_audio_config tegra_hdmi_audio_48k[] = { |
| 145 | { 25200000, 6144, 25200, 24000 }, |
| 146 | { 27000000, 6144, 27000, 24000 }, |
| 147 | { 74250000, 6144, 74250, 24000 }, |
| 148 | { 148500000, 6144, 148500, 24000 }, |
| 149 | { 0, 0, 0, 0 }, |
| 150 | }; |
| 151 | |
| 152 | static const struct tegra_hdmi_audio_config tegra_hdmi_audio_88_2k[] = { |
| 153 | { 25200000, 11760, 26250, 25000 }, |
| 154 | { 27000000, 11760, 28125, 25000 }, |
| 155 | { 74250000, 9408, 61875, 20000 }, |
| 156 | { 148500000, 9408, 123750, 20000 }, |
| 157 | { 0, 0, 0, 0 }, |
| 158 | }; |
| 159 | |
| 160 | static const struct tegra_hdmi_audio_config tegra_hdmi_audio_96k[] = { |
| 161 | { 25200000, 12288, 25200, 24000 }, |
| 162 | { 27000000, 12288, 27000, 24000 }, |
| 163 | { 74250000, 12288, 74250, 24000 }, |
| 164 | { 148500000, 12288, 148500, 24000 }, |
| 165 | { 0, 0, 0, 0 }, |
| 166 | }; |
| 167 | |
| 168 | static const struct tegra_hdmi_audio_config tegra_hdmi_audio_176_4k[] = { |
| 169 | { 25200000, 23520, 26250, 25000 }, |
| 170 | { 27000000, 23520, 28125, 25000 }, |
| 171 | { 74250000, 18816, 61875, 20000 }, |
| 172 | { 148500000, 18816, 123750, 20000 }, |
| 173 | { 0, 0, 0, 0 }, |
| 174 | }; |
| 175 | |
| 176 | static const struct tegra_hdmi_audio_config tegra_hdmi_audio_192k[] = { |
| 177 | { 25200000, 24576, 25200, 24000 }, |
| 178 | { 27000000, 24576, 27000, 24000 }, |
| 179 | { 74250000, 24576, 74250, 24000 }, |
| 180 | { 148500000, 24576, 148500, 24000 }, |
| 181 | { 0, 0, 0, 0 }, |
| 182 | }; |
| 183 | |
Thierry Reding | f27db96 | 2013-09-30 15:14:41 +0200 | [diff] [blame] | 184 | static const struct tmds_config tegra20_tmds_config[] = { |
Lucas Stach | fa416dd | 2012-12-19 21:38:55 +0000 | [diff] [blame] | 185 | { /* slow pixel clock modes */ |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 186 | .pclk = 27000000, |
| 187 | .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) | |
| 188 | SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(0) | |
| 189 | SOR_PLL_TX_REG_LOAD(3), |
| 190 | .pll1 = SOR_PLL_TMDS_TERM_ENABLE, |
| 191 | .pe_current = PE_CURRENT0(PE_CURRENT_0_0_mA) | |
| 192 | PE_CURRENT1(PE_CURRENT_0_0_mA) | |
| 193 | PE_CURRENT2(PE_CURRENT_0_0_mA) | |
| 194 | PE_CURRENT3(PE_CURRENT_0_0_mA), |
| 195 | .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_7_125_mA) | |
| 196 | DRIVE_CURRENT_LANE1(DRIVE_CURRENT_7_125_mA) | |
| 197 | DRIVE_CURRENT_LANE2(DRIVE_CURRENT_7_125_mA) | |
| 198 | DRIVE_CURRENT_LANE3(DRIVE_CURRENT_7_125_mA), |
Lucas Stach | fa416dd | 2012-12-19 21:38:55 +0000 | [diff] [blame] | 199 | }, |
| 200 | { /* high pixel clock modes */ |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 201 | .pclk = UINT_MAX, |
| 202 | .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) | |
| 203 | SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(1) | |
| 204 | SOR_PLL_TX_REG_LOAD(3), |
| 205 | .pll1 = SOR_PLL_TMDS_TERM_ENABLE | SOR_PLL_PE_EN, |
| 206 | .pe_current = PE_CURRENT0(PE_CURRENT_6_0_mA) | |
| 207 | PE_CURRENT1(PE_CURRENT_6_0_mA) | |
| 208 | PE_CURRENT2(PE_CURRENT_6_0_mA) | |
| 209 | PE_CURRENT3(PE_CURRENT_6_0_mA), |
| 210 | .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_7_125_mA) | |
| 211 | DRIVE_CURRENT_LANE1(DRIVE_CURRENT_7_125_mA) | |
| 212 | DRIVE_CURRENT_LANE2(DRIVE_CURRENT_7_125_mA) | |
| 213 | DRIVE_CURRENT_LANE3(DRIVE_CURRENT_7_125_mA), |
| 214 | }, |
| 215 | }; |
| 216 | |
Thierry Reding | f27db96 | 2013-09-30 15:14:41 +0200 | [diff] [blame] | 217 | static const struct tmds_config tegra30_tmds_config[] = { |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 218 | { /* 480p modes */ |
| 219 | .pclk = 27000000, |
| 220 | .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) | |
| 221 | SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(0) | |
| 222 | SOR_PLL_TX_REG_LOAD(0), |
| 223 | .pll1 = SOR_PLL_TMDS_TERM_ENABLE, |
| 224 | .pe_current = PE_CURRENT0(PE_CURRENT_0_0_mA) | |
| 225 | PE_CURRENT1(PE_CURRENT_0_0_mA) | |
| 226 | PE_CURRENT2(PE_CURRENT_0_0_mA) | |
| 227 | PE_CURRENT3(PE_CURRENT_0_0_mA), |
| 228 | .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_5_250_mA) | |
| 229 | DRIVE_CURRENT_LANE1(DRIVE_CURRENT_5_250_mA) | |
| 230 | DRIVE_CURRENT_LANE2(DRIVE_CURRENT_5_250_mA) | |
| 231 | DRIVE_CURRENT_LANE3(DRIVE_CURRENT_5_250_mA), |
| 232 | }, { /* 720p modes */ |
| 233 | .pclk = 74250000, |
| 234 | .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) | |
| 235 | SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(1) | |
| 236 | SOR_PLL_TX_REG_LOAD(0), |
| 237 | .pll1 = SOR_PLL_TMDS_TERM_ENABLE | SOR_PLL_PE_EN, |
| 238 | .pe_current = PE_CURRENT0(PE_CURRENT_5_0_mA) | |
| 239 | PE_CURRENT1(PE_CURRENT_5_0_mA) | |
| 240 | PE_CURRENT2(PE_CURRENT_5_0_mA) | |
| 241 | PE_CURRENT3(PE_CURRENT_5_0_mA), |
| 242 | .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_5_250_mA) | |
| 243 | DRIVE_CURRENT_LANE1(DRIVE_CURRENT_5_250_mA) | |
| 244 | DRIVE_CURRENT_LANE2(DRIVE_CURRENT_5_250_mA) | |
| 245 | DRIVE_CURRENT_LANE3(DRIVE_CURRENT_5_250_mA), |
| 246 | }, { /* 1080p modes */ |
| 247 | .pclk = UINT_MAX, |
| 248 | .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) | |
| 249 | SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(3) | |
| 250 | SOR_PLL_TX_REG_LOAD(0), |
| 251 | .pll1 = SOR_PLL_TMDS_TERM_ENABLE | SOR_PLL_PE_EN, |
| 252 | .pe_current = PE_CURRENT0(PE_CURRENT_5_0_mA) | |
| 253 | PE_CURRENT1(PE_CURRENT_5_0_mA) | |
| 254 | PE_CURRENT2(PE_CURRENT_5_0_mA) | |
| 255 | PE_CURRENT3(PE_CURRENT_5_0_mA), |
| 256 | .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_5_250_mA) | |
| 257 | DRIVE_CURRENT_LANE1(DRIVE_CURRENT_5_250_mA) | |
| 258 | DRIVE_CURRENT_LANE2(DRIVE_CURRENT_5_250_mA) | |
| 259 | DRIVE_CURRENT_LANE3(DRIVE_CURRENT_5_250_mA), |
| 260 | }, |
| 261 | }; |
| 262 | |
Mikko Perttunen | 7d1d28a | 2013-09-30 16:54:47 +0200 | [diff] [blame] | 263 | static const struct tmds_config tegra114_tmds_config[] = { |
| 264 | { /* 480p/576p / 25.2MHz/27MHz modes */ |
| 265 | .pclk = 27000000, |
| 266 | .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) | |
| 267 | SOR_PLL_VCOCAP(0) | SOR_PLL_RESISTORSEL, |
| 268 | .pll1 = SOR_PLL_LOADADJ(3) | SOR_PLL_TMDS_TERMADJ(0), |
| 269 | .pe_current = PE_CURRENT0(PE_CURRENT_0_mA_T114) | |
| 270 | PE_CURRENT1(PE_CURRENT_0_mA_T114) | |
| 271 | PE_CURRENT2(PE_CURRENT_0_mA_T114) | |
| 272 | PE_CURRENT3(PE_CURRENT_0_mA_T114), |
| 273 | .drive_current = |
| 274 | DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_10_400_mA_T114) | |
| 275 | DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_10_400_mA_T114) | |
| 276 | DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_10_400_mA_T114) | |
| 277 | DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_10_400_mA_T114), |
| 278 | .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA) | |
| 279 | PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA) | |
| 280 | PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA) | |
| 281 | PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA), |
| 282 | }, { /* 720p / 74.25MHz modes */ |
| 283 | .pclk = 74250000, |
| 284 | .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) | |
| 285 | SOR_PLL_VCOCAP(1) | SOR_PLL_RESISTORSEL, |
| 286 | .pll1 = SOR_PLL_PE_EN | SOR_PLL_LOADADJ(3) | |
| 287 | SOR_PLL_TMDS_TERMADJ(0), |
| 288 | .pe_current = PE_CURRENT0(PE_CURRENT_15_mA_T114) | |
| 289 | PE_CURRENT1(PE_CURRENT_15_mA_T114) | |
| 290 | PE_CURRENT2(PE_CURRENT_15_mA_T114) | |
| 291 | PE_CURRENT3(PE_CURRENT_15_mA_T114), |
| 292 | .drive_current = |
| 293 | DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_10_400_mA_T114) | |
| 294 | DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_10_400_mA_T114) | |
| 295 | DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_10_400_mA_T114) | |
| 296 | DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_10_400_mA_T114), |
| 297 | .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA) | |
| 298 | PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA) | |
| 299 | PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA) | |
| 300 | PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA), |
| 301 | }, { /* 1080p / 148.5MHz modes */ |
| 302 | .pclk = 148500000, |
| 303 | .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) | |
| 304 | SOR_PLL_VCOCAP(3) | SOR_PLL_RESISTORSEL, |
| 305 | .pll1 = SOR_PLL_PE_EN | SOR_PLL_LOADADJ(3) | |
| 306 | SOR_PLL_TMDS_TERMADJ(0), |
| 307 | .pe_current = PE_CURRENT0(PE_CURRENT_10_mA_T114) | |
| 308 | PE_CURRENT1(PE_CURRENT_10_mA_T114) | |
| 309 | PE_CURRENT2(PE_CURRENT_10_mA_T114) | |
| 310 | PE_CURRENT3(PE_CURRENT_10_mA_T114), |
| 311 | .drive_current = |
| 312 | DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_12_400_mA_T114) | |
| 313 | DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_12_400_mA_T114) | |
| 314 | DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_12_400_mA_T114) | |
| 315 | DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_12_400_mA_T114), |
| 316 | .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA) | |
| 317 | PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA) | |
| 318 | PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA) | |
| 319 | PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA), |
| 320 | }, { /* 225/297MHz modes */ |
| 321 | .pclk = UINT_MAX, |
| 322 | .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) | |
| 323 | SOR_PLL_VCOCAP(0xf) | SOR_PLL_RESISTORSEL, |
| 324 | .pll1 = SOR_PLL_LOADADJ(3) | SOR_PLL_TMDS_TERMADJ(7) |
| 325 | | SOR_PLL_TMDS_TERM_ENABLE, |
| 326 | .pe_current = PE_CURRENT0(PE_CURRENT_0_mA_T114) | |
| 327 | PE_CURRENT1(PE_CURRENT_0_mA_T114) | |
| 328 | PE_CURRENT2(PE_CURRENT_0_mA_T114) | |
| 329 | PE_CURRENT3(PE_CURRENT_0_mA_T114), |
| 330 | .drive_current = |
| 331 | DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_25_200_mA_T114) | |
| 332 | DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_25_200_mA_T114) | |
| 333 | DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_25_200_mA_T114) | |
| 334 | DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_19_200_mA_T114), |
| 335 | .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_3_000_mA) | |
| 336 | PEAK_CURRENT_LANE1(PEAK_CURRENT_3_000_mA) | |
| 337 | PEAK_CURRENT_LANE2(PEAK_CURRENT_3_000_mA) | |
| 338 | PEAK_CURRENT_LANE3(PEAK_CURRENT_0_800_mA), |
| 339 | }, |
| 340 | }; |
| 341 | |
Thierry Reding | fb7be70 | 2013-11-15 16:07:32 +0100 | [diff] [blame] | 342 | static const struct tmds_config tegra124_tmds_config[] = { |
| 343 | { /* 480p/576p / 25.2MHz/27MHz modes */ |
| 344 | .pclk = 27000000, |
| 345 | .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) | |
| 346 | SOR_PLL_VCOCAP(0) | SOR_PLL_RESISTORSEL, |
| 347 | .pll1 = SOR_PLL_LOADADJ(3) | SOR_PLL_TMDS_TERMADJ(0), |
| 348 | .pe_current = PE_CURRENT0(PE_CURRENT_0_mA_T114) | |
| 349 | PE_CURRENT1(PE_CURRENT_0_mA_T114) | |
| 350 | PE_CURRENT2(PE_CURRENT_0_mA_T114) | |
| 351 | PE_CURRENT3(PE_CURRENT_0_mA_T114), |
| 352 | .drive_current = |
| 353 | DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_10_400_mA_T114) | |
| 354 | DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_10_400_mA_T114) | |
| 355 | DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_10_400_mA_T114) | |
| 356 | DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_10_400_mA_T114), |
| 357 | .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA) | |
| 358 | PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA) | |
| 359 | PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA) | |
| 360 | PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA), |
| 361 | }, { /* 720p / 74.25MHz modes */ |
| 362 | .pclk = 74250000, |
| 363 | .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) | |
| 364 | SOR_PLL_VCOCAP(1) | SOR_PLL_RESISTORSEL, |
| 365 | .pll1 = SOR_PLL_PE_EN | SOR_PLL_LOADADJ(3) | |
| 366 | SOR_PLL_TMDS_TERMADJ(0), |
| 367 | .pe_current = PE_CURRENT0(PE_CURRENT_15_mA_T114) | |
| 368 | PE_CURRENT1(PE_CURRENT_15_mA_T114) | |
| 369 | PE_CURRENT2(PE_CURRENT_15_mA_T114) | |
| 370 | PE_CURRENT3(PE_CURRENT_15_mA_T114), |
| 371 | .drive_current = |
| 372 | DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_10_400_mA_T114) | |
| 373 | DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_10_400_mA_T114) | |
| 374 | DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_10_400_mA_T114) | |
| 375 | DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_10_400_mA_T114), |
| 376 | .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA) | |
| 377 | PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA) | |
| 378 | PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA) | |
| 379 | PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA), |
| 380 | }, { /* 1080p / 148.5MHz modes */ |
| 381 | .pclk = 148500000, |
| 382 | .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) | |
| 383 | SOR_PLL_VCOCAP(3) | SOR_PLL_RESISTORSEL, |
| 384 | .pll1 = SOR_PLL_PE_EN | SOR_PLL_LOADADJ(3) | |
| 385 | SOR_PLL_TMDS_TERMADJ(0), |
| 386 | .pe_current = PE_CURRENT0(PE_CURRENT_10_mA_T114) | |
| 387 | PE_CURRENT1(PE_CURRENT_10_mA_T114) | |
| 388 | PE_CURRENT2(PE_CURRENT_10_mA_T114) | |
| 389 | PE_CURRENT3(PE_CURRENT_10_mA_T114), |
| 390 | .drive_current = |
| 391 | DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_12_400_mA_T114) | |
| 392 | DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_12_400_mA_T114) | |
| 393 | DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_12_400_mA_T114) | |
| 394 | DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_12_400_mA_T114), |
| 395 | .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA) | |
| 396 | PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA) | |
| 397 | PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA) | |
| 398 | PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA), |
| 399 | }, { /* 225/297MHz modes */ |
| 400 | .pclk = UINT_MAX, |
| 401 | .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) | |
| 402 | SOR_PLL_VCOCAP(0xf) | SOR_PLL_RESISTORSEL, |
| 403 | .pll1 = SOR_PLL_LOADADJ(3) | SOR_PLL_TMDS_TERMADJ(7) |
| 404 | | SOR_PLL_TMDS_TERM_ENABLE, |
| 405 | .pe_current = PE_CURRENT0(PE_CURRENT_0_mA_T114) | |
| 406 | PE_CURRENT1(PE_CURRENT_0_mA_T114) | |
| 407 | PE_CURRENT2(PE_CURRENT_0_mA_T114) | |
| 408 | PE_CURRENT3(PE_CURRENT_0_mA_T114), |
| 409 | .drive_current = |
| 410 | DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_25_200_mA_T114) | |
| 411 | DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_25_200_mA_T114) | |
| 412 | DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_25_200_mA_T114) | |
| 413 | DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_19_200_mA_T114), |
| 414 | .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_3_000_mA) | |
| 415 | PEAK_CURRENT_LANE1(PEAK_CURRENT_3_000_mA) | |
| 416 | PEAK_CURRENT_LANE2(PEAK_CURRENT_3_000_mA) | |
| 417 | PEAK_CURRENT_LANE3(PEAK_CURRENT_0_800_mA), |
| 418 | }, |
| 419 | }; |
| 420 | |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 421 | static const struct tegra_hdmi_audio_config * |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 422 | tegra_hdmi_get_audio_config(unsigned int sample_rate, unsigned int pclk) |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 423 | { |
| 424 | const struct tegra_hdmi_audio_config *table; |
| 425 | |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 426 | switch (sample_rate) { |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 427 | case 32000: |
| 428 | table = tegra_hdmi_audio_32k; |
| 429 | break; |
| 430 | |
| 431 | case 44100: |
| 432 | table = tegra_hdmi_audio_44_1k; |
| 433 | break; |
| 434 | |
| 435 | case 48000: |
| 436 | table = tegra_hdmi_audio_48k; |
| 437 | break; |
| 438 | |
| 439 | case 88200: |
| 440 | table = tegra_hdmi_audio_88_2k; |
| 441 | break; |
| 442 | |
| 443 | case 96000: |
| 444 | table = tegra_hdmi_audio_96k; |
| 445 | break; |
| 446 | |
| 447 | case 176400: |
| 448 | table = tegra_hdmi_audio_176_4k; |
| 449 | break; |
| 450 | |
| 451 | case 192000: |
| 452 | table = tegra_hdmi_audio_192k; |
| 453 | break; |
| 454 | |
| 455 | default: |
| 456 | return NULL; |
| 457 | } |
| 458 | |
| 459 | while (table->pclk) { |
| 460 | if (table->pclk == pclk) |
| 461 | return table; |
| 462 | |
| 463 | table++; |
| 464 | } |
| 465 | |
| 466 | return NULL; |
| 467 | } |
| 468 | |
| 469 | static void tegra_hdmi_setup_audio_fs_tables(struct tegra_hdmi *hdmi) |
| 470 | { |
| 471 | const unsigned int freqs[] = { |
| 472 | 32000, 44100, 48000, 88200, 96000, 176400, 192000 |
| 473 | }; |
| 474 | unsigned int i; |
| 475 | |
| 476 | for (i = 0; i < ARRAY_SIZE(freqs); i++) { |
| 477 | unsigned int f = freqs[i]; |
| 478 | unsigned int eight_half; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 479 | unsigned int delta; |
Thierry Reding | 4ee8cee | 2014-12-08 16:25:14 +0100 | [diff] [blame] | 480 | u32 value; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 481 | |
| 482 | if (f > 96000) |
| 483 | delta = 2; |
Thierry Reding | 17a8b6b | 2013-12-16 10:01:24 +0100 | [diff] [blame] | 484 | else if (f > 48000) |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 485 | delta = 6; |
| 486 | else |
| 487 | delta = 9; |
| 488 | |
| 489 | eight_half = (8 * HDMI_AUDIOCLK_FREQ) / (f * 128); |
| 490 | value = AUDIO_FS_LOW(eight_half - delta) | |
| 491 | AUDIO_FS_HIGH(eight_half + delta); |
| 492 | tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_FS(i)); |
| 493 | } |
| 494 | } |
| 495 | |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 496 | static void tegra_hdmi_write_aval(struct tegra_hdmi *hdmi, u32 value) |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 497 | { |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 498 | static const struct { |
| 499 | unsigned int sample_rate; |
| 500 | unsigned int offset; |
| 501 | } regs[] = { |
| 502 | { 32000, HDMI_NV_PDISP_SOR_AUDIO_AVAL_0320 }, |
| 503 | { 44100, HDMI_NV_PDISP_SOR_AUDIO_AVAL_0441 }, |
| 504 | { 48000, HDMI_NV_PDISP_SOR_AUDIO_AVAL_0480 }, |
| 505 | { 88200, HDMI_NV_PDISP_SOR_AUDIO_AVAL_0882 }, |
| 506 | { 96000, HDMI_NV_PDISP_SOR_AUDIO_AVAL_0960 }, |
| 507 | { 176400, HDMI_NV_PDISP_SOR_AUDIO_AVAL_1764 }, |
| 508 | { 192000, HDMI_NV_PDISP_SOR_AUDIO_AVAL_1920 }, |
| 509 | }; |
| 510 | unsigned int i; |
| 511 | |
| 512 | for (i = 0; i < ARRAY_SIZE(regs); i++) { |
| 513 | if (regs[i].sample_rate == hdmi->audio_sample_rate) { |
| 514 | tegra_hdmi_writel(hdmi, value, regs[i].offset); |
| 515 | break; |
| 516 | } |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | static int tegra_hdmi_setup_audio(struct tegra_hdmi *hdmi) |
| 521 | { |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 522 | const struct tegra_hdmi_audio_config *config; |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 523 | u32 source, value; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 524 | |
| 525 | switch (hdmi->audio_source) { |
| 526 | case HDA: |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 527 | if (hdmi->config->has_hda) |
| 528 | source = SOR_AUDIO_CNTRL0_SOURCE_SELECT_HDAL; |
| 529 | else |
| 530 | return -EINVAL; |
| 531 | |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 532 | break; |
| 533 | |
| 534 | case SPDIF: |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 535 | if (hdmi->config->has_hda) |
| 536 | source = SOR_AUDIO_CNTRL0_SOURCE_SELECT_SPDIF; |
| 537 | else |
| 538 | source = AUDIO_CNTRL0_SOURCE_SELECT_SPDIF; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 539 | break; |
| 540 | |
| 541 | default: |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 542 | if (hdmi->config->has_hda) |
| 543 | source = SOR_AUDIO_CNTRL0_SOURCE_SELECT_AUTO; |
| 544 | else |
| 545 | source = AUDIO_CNTRL0_SOURCE_SELECT_AUTO; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 546 | break; |
| 547 | } |
| 548 | |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 549 | /* |
| 550 | * Tegra30 and later use a slightly modified version of the register |
| 551 | * layout to accomodate for changes related to supporting HDA as the |
| 552 | * audio input source for HDMI. The source select field has moved to |
| 553 | * the SOR_AUDIO_CNTRL0 register, but the error tolerance and frames |
| 554 | * per block fields remain in the AUDIO_CNTRL0 register. |
| 555 | */ |
| 556 | if (hdmi->config->has_hda) { |
| 557 | /* |
| 558 | * Inject null samples into the audio FIFO for every frame in |
| 559 | * which the codec did not receive any samples. This applies |
| 560 | * to stereo LPCM only. |
| 561 | * |
| 562 | * XXX: This seems to be a remnant of MCP days when this was |
| 563 | * used to work around issues with monitors not being able to |
| 564 | * play back system startup sounds early. It is possibly not |
| 565 | * needed on Linux at all. |
| 566 | */ |
| 567 | if (hdmi->audio_channels == 2) |
| 568 | value = SOR_AUDIO_CNTRL0_INJECT_NULLSMPL; |
| 569 | else |
| 570 | value = 0; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 571 | |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 572 | value |= source; |
| 573 | |
| 574 | tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_AUDIO_CNTRL0); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 575 | } |
| 576 | |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 577 | /* |
| 578 | * On Tegra20, HDA is not a supported audio source and the source |
| 579 | * select field is part of the AUDIO_CNTRL0 register. |
| 580 | */ |
| 581 | value = AUDIO_CNTRL0_FRAMES_PER_BLOCK(0xc0) | |
| 582 | AUDIO_CNTRL0_ERROR_TOLERANCE(6); |
| 583 | |
| 584 | if (!hdmi->config->has_hda) |
| 585 | value |= source; |
| 586 | |
| 587 | tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_CNTRL0); |
| 588 | |
| 589 | /* |
| 590 | * Advertise support for High Bit-Rate on Tegra114 and later. |
| 591 | */ |
| 592 | if (hdmi->config->has_hbr) { |
| 593 | value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_AUDIO_SPARE0); |
| 594 | value |= SOR_AUDIO_SPARE0_HBR_ENABLE; |
| 595 | tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_AUDIO_SPARE0); |
| 596 | } |
| 597 | |
| 598 | config = tegra_hdmi_get_audio_config(hdmi->audio_sample_rate, |
| 599 | hdmi->pixel_clock); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 600 | if (!config) { |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 601 | dev_err(hdmi->dev, |
| 602 | "cannot set audio to %u Hz at %u Hz pixel clock\n", |
| 603 | hdmi->audio_sample_rate, hdmi->pixel_clock); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 604 | return -EINVAL; |
| 605 | } |
| 606 | |
| 607 | tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_HDMI_ACR_CTRL); |
| 608 | |
| 609 | value = AUDIO_N_RESETF | AUDIO_N_GENERATE_ALTERNATE | |
| 610 | AUDIO_N_VALUE(config->n - 1); |
| 611 | tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_N); |
| 612 | |
| 613 | tegra_hdmi_writel(hdmi, ACR_SUBPACK_N(config->n) | ACR_ENABLE, |
| 614 | HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_HIGH); |
| 615 | |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 616 | tegra_hdmi_writel(hdmi, ACR_SUBPACK_CTS(config->cts), |
| 617 | HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_LOW); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 618 | |
| 619 | value = SPARE_HW_CTS | SPARE_FORCE_SW_CTS | SPARE_CTS_RESET_VAL(1); |
| 620 | tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_SPARE); |
| 621 | |
| 622 | value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_AUDIO_N); |
| 623 | value &= ~AUDIO_N_RESETF; |
| 624 | tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_N); |
| 625 | |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 626 | if (hdmi->config->has_hda) |
| 627 | tegra_hdmi_write_aval(hdmi, config->aval); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 628 | |
| 629 | tegra_hdmi_setup_audio_fs_tables(hdmi); |
| 630 | |
| 631 | return 0; |
| 632 | } |
| 633 | |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 634 | static void tegra_hdmi_disable_audio(struct tegra_hdmi *hdmi) |
| 635 | { |
| 636 | u32 value; |
| 637 | |
| 638 | value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_GENERIC_CTRL); |
| 639 | value &= ~GENERIC_CTRL_AUDIO; |
| 640 | tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_GENERIC_CTRL); |
| 641 | } |
| 642 | |
| 643 | static void tegra_hdmi_enable_audio(struct tegra_hdmi *hdmi) |
| 644 | { |
| 645 | u32 value; |
| 646 | |
| 647 | value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_GENERIC_CTRL); |
| 648 | value |= GENERIC_CTRL_AUDIO; |
| 649 | tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_GENERIC_CTRL); |
| 650 | } |
| 651 | |
Thierry Reding | 5234549 | 2015-08-07 16:00:43 +0200 | [diff] [blame] | 652 | static void tegra_hdmi_write_eld(struct tegra_hdmi *hdmi) |
| 653 | { |
| 654 | size_t length = drm_eld_size(hdmi->output.connector.eld), i; |
| 655 | u32 value; |
| 656 | |
| 657 | for (i = 0; i < length; i++) |
| 658 | tegra_hdmi_writel(hdmi, i << 8 | hdmi->output.connector.eld[i], |
| 659 | HDMI_NV_PDISP_SOR_AUDIO_HDA_ELD_BUFWR); |
| 660 | |
| 661 | /* |
| 662 | * The HDA codec will always report an ELD buffer size of 96 bytes and |
| 663 | * the HDA codec driver will check that each byte read from the buffer |
| 664 | * is valid. Therefore every byte must be written, even if no 96 bytes |
| 665 | * were parsed from EDID. |
| 666 | */ |
| 667 | for (i = length; i < HDMI_ELD_BUFFER_SIZE; i++) |
| 668 | tegra_hdmi_writel(hdmi, i << 8 | 0, |
| 669 | HDMI_NV_PDISP_SOR_AUDIO_HDA_ELD_BUFWR); |
| 670 | |
| 671 | value = SOR_AUDIO_HDA_PRESENSE_VALID | SOR_AUDIO_HDA_PRESENSE_PRESENT; |
| 672 | tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_AUDIO_HDA_PRESENSE); |
| 673 | } |
| 674 | |
Thierry Reding | 4ee8cee | 2014-12-08 16:25:14 +0100 | [diff] [blame] | 675 | static inline u32 tegra_hdmi_subpack(const u8 *ptr, size_t size) |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 676 | { |
Thierry Reding | 4ee8cee | 2014-12-08 16:25:14 +0100 | [diff] [blame] | 677 | u32 value = 0; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 678 | size_t i; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 679 | |
Thierry Reding | ac24c22 | 2012-11-23 15:14:00 +0100 | [diff] [blame] | 680 | for (i = size; i > 0; i--) |
| 681 | value = (value << 8) | ptr[i - 1]; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 682 | |
Thierry Reding | ac24c22 | 2012-11-23 15:14:00 +0100 | [diff] [blame] | 683 | return value; |
| 684 | } |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 685 | |
Thierry Reding | ac24c22 | 2012-11-23 15:14:00 +0100 | [diff] [blame] | 686 | static void tegra_hdmi_write_infopack(struct tegra_hdmi *hdmi, const void *data, |
| 687 | size_t size) |
| 688 | { |
| 689 | const u8 *ptr = data; |
| 690 | unsigned long offset; |
Thierry Reding | ac24c22 | 2012-11-23 15:14:00 +0100 | [diff] [blame] | 691 | size_t i, j; |
Thierry Reding | 4ee8cee | 2014-12-08 16:25:14 +0100 | [diff] [blame] | 692 | u32 value; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 693 | |
Thierry Reding | ac24c22 | 2012-11-23 15:14:00 +0100 | [diff] [blame] | 694 | switch (ptr[0]) { |
| 695 | case HDMI_INFOFRAME_TYPE_AVI: |
| 696 | offset = HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_HEADER; |
| 697 | break; |
| 698 | |
| 699 | case HDMI_INFOFRAME_TYPE_AUDIO: |
| 700 | offset = HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_HEADER; |
| 701 | break; |
| 702 | |
| 703 | case HDMI_INFOFRAME_TYPE_VENDOR: |
| 704 | offset = HDMI_NV_PDISP_HDMI_GENERIC_HEADER; |
| 705 | break; |
| 706 | |
| 707 | default: |
| 708 | dev_err(hdmi->dev, "unsupported infoframe type: %02x\n", |
| 709 | ptr[0]); |
| 710 | return; |
| 711 | } |
| 712 | |
| 713 | value = INFOFRAME_HEADER_TYPE(ptr[0]) | |
| 714 | INFOFRAME_HEADER_VERSION(ptr[1]) | |
| 715 | INFOFRAME_HEADER_LEN(ptr[2]); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 716 | tegra_hdmi_writel(hdmi, value, offset); |
Thierry Reding | ac24c22 | 2012-11-23 15:14:00 +0100 | [diff] [blame] | 717 | offset++; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 718 | |
Thierry Reding | ac24c22 | 2012-11-23 15:14:00 +0100 | [diff] [blame] | 719 | /* |
| 720 | * Each subpack contains 7 bytes, divided into: |
| 721 | * - subpack_low: bytes 0 - 3 |
| 722 | * - subpack_high: bytes 4 - 6 (with byte 7 padded to 0x00) |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 723 | */ |
Thierry Reding | ac24c22 | 2012-11-23 15:14:00 +0100 | [diff] [blame] | 724 | for (i = 3, j = 0; i < size; i += 7, j += 8) { |
| 725 | size_t rem = size - i, num = min_t(size_t, rem, 4); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 726 | |
Thierry Reding | ac24c22 | 2012-11-23 15:14:00 +0100 | [diff] [blame] | 727 | value = tegra_hdmi_subpack(&ptr[i], num); |
| 728 | tegra_hdmi_writel(hdmi, value, offset++); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 729 | |
Thierry Reding | ac24c22 | 2012-11-23 15:14:00 +0100 | [diff] [blame] | 730 | num = min_t(size_t, rem - num, 3); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 731 | |
Thierry Reding | ac24c22 | 2012-11-23 15:14:00 +0100 | [diff] [blame] | 732 | value = tegra_hdmi_subpack(&ptr[i + 4], num); |
| 733 | tegra_hdmi_writel(hdmi, value, offset++); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 734 | } |
| 735 | } |
| 736 | |
| 737 | static void tegra_hdmi_setup_avi_infoframe(struct tegra_hdmi *hdmi, |
| 738 | struct drm_display_mode *mode) |
| 739 | { |
| 740 | struct hdmi_avi_infoframe frame; |
Thierry Reding | ac24c22 | 2012-11-23 15:14:00 +0100 | [diff] [blame] | 741 | u8 buffer[17]; |
| 742 | ssize_t err; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 743 | |
Shashank Sharma | 0c1f528 | 2017-07-13 21:03:07 +0530 | [diff] [blame] | 744 | err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode, false); |
Thierry Reding | ac24c22 | 2012-11-23 15:14:00 +0100 | [diff] [blame] | 745 | if (err < 0) { |
| 746 | dev_err(hdmi->dev, "failed to setup AVI infoframe: %zd\n", err); |
| 747 | return; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 748 | } |
| 749 | |
Thierry Reding | ac24c22 | 2012-11-23 15:14:00 +0100 | [diff] [blame] | 750 | err = hdmi_avi_infoframe_pack(&frame, buffer, sizeof(buffer)); |
| 751 | if (err < 0) { |
| 752 | dev_err(hdmi->dev, "failed to pack AVI infoframe: %zd\n", err); |
| 753 | return; |
| 754 | } |
| 755 | |
| 756 | tegra_hdmi_write_infopack(hdmi, buffer, err); |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 757 | } |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 758 | |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 759 | static void tegra_hdmi_disable_avi_infoframe(struct tegra_hdmi *hdmi) |
| 760 | { |
| 761 | u32 value; |
| 762 | |
| 763 | value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL); |
| 764 | value &= ~INFOFRAME_CTRL_ENABLE; |
| 765 | tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL); |
| 766 | } |
| 767 | |
| 768 | static void tegra_hdmi_enable_avi_infoframe(struct tegra_hdmi *hdmi) |
| 769 | { |
| 770 | u32 value; |
| 771 | |
| 772 | value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL); |
| 773 | value |= INFOFRAME_CTRL_ENABLE; |
| 774 | tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | static void tegra_hdmi_setup_audio_infoframe(struct tegra_hdmi *hdmi) |
| 778 | { |
| 779 | struct hdmi_audio_infoframe frame; |
Thierry Reding | ac24c22 | 2012-11-23 15:14:00 +0100 | [diff] [blame] | 780 | u8 buffer[14]; |
| 781 | ssize_t err; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 782 | |
Thierry Reding | ac24c22 | 2012-11-23 15:14:00 +0100 | [diff] [blame] | 783 | err = hdmi_audio_infoframe_init(&frame); |
| 784 | if (err < 0) { |
Thierry Reding | ef284c7 | 2013-10-16 19:51:22 +0200 | [diff] [blame] | 785 | dev_err(hdmi->dev, "failed to setup audio infoframe: %zd\n", |
Thierry Reding | ac24c22 | 2012-11-23 15:14:00 +0100 | [diff] [blame] | 786 | err); |
| 787 | return; |
| 788 | } |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 789 | |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 790 | frame.channels = hdmi->audio_channels; |
Thierry Reding | ac24c22 | 2012-11-23 15:14:00 +0100 | [diff] [blame] | 791 | |
| 792 | err = hdmi_audio_infoframe_pack(&frame, buffer, sizeof(buffer)); |
| 793 | if (err < 0) { |
| 794 | dev_err(hdmi->dev, "failed to pack audio infoframe: %zd\n", |
| 795 | err); |
| 796 | return; |
| 797 | } |
| 798 | |
| 799 | /* |
| 800 | * The audio infoframe has only one set of subpack registers, so the |
| 801 | * infoframe needs to be truncated. One set of subpack registers can |
| 802 | * contain 7 bytes. Including the 3 byte header only the first 10 |
| 803 | * bytes can be programmed. |
| 804 | */ |
Thierry Reding | ef284c7 | 2013-10-16 19:51:22 +0200 | [diff] [blame] | 805 | tegra_hdmi_write_infopack(hdmi, buffer, min_t(size_t, 10, err)); |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 806 | } |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 807 | |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 808 | static void tegra_hdmi_disable_audio_infoframe(struct tegra_hdmi *hdmi) |
| 809 | { |
| 810 | u32 value; |
| 811 | |
| 812 | value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL); |
| 813 | value &= ~INFOFRAME_CTRL_ENABLE; |
| 814 | tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL); |
| 815 | } |
| 816 | |
| 817 | static void tegra_hdmi_enable_audio_infoframe(struct tegra_hdmi *hdmi) |
| 818 | { |
| 819 | u32 value; |
| 820 | |
| 821 | value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL); |
| 822 | value |= INFOFRAME_CTRL_ENABLE; |
| 823 | tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | static void tegra_hdmi_setup_stereo_infoframe(struct tegra_hdmi *hdmi) |
| 827 | { |
Lespiau, Damien | ae84b90 | 2013-08-19 16:59:02 +0100 | [diff] [blame] | 828 | struct hdmi_vendor_infoframe frame; |
Thierry Reding | ac24c22 | 2012-11-23 15:14:00 +0100 | [diff] [blame] | 829 | u8 buffer[10]; |
| 830 | ssize_t err; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 831 | |
Lespiau, Damien | ae84b90 | 2013-08-19 16:59:02 +0100 | [diff] [blame] | 832 | hdmi_vendor_infoframe_init(&frame); |
Lespiau, Damien | a26a58e8 | 2013-08-19 16:58:59 +0100 | [diff] [blame] | 833 | frame.s3d_struct = HDMI_3D_STRUCTURE_FRAME_PACKING; |
Thierry Reding | ac24c22 | 2012-11-23 15:14:00 +0100 | [diff] [blame] | 834 | |
Lespiau, Damien | ae84b90 | 2013-08-19 16:59:02 +0100 | [diff] [blame] | 835 | err = hdmi_vendor_infoframe_pack(&frame, buffer, sizeof(buffer)); |
Thierry Reding | ac24c22 | 2012-11-23 15:14:00 +0100 | [diff] [blame] | 836 | if (err < 0) { |
| 837 | dev_err(hdmi->dev, "failed to pack vendor infoframe: %zd\n", |
| 838 | err); |
| 839 | return; |
| 840 | } |
| 841 | |
| 842 | tegra_hdmi_write_infopack(hdmi, buffer, err); |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | static void tegra_hdmi_disable_stereo_infoframe(struct tegra_hdmi *hdmi) |
| 846 | { |
| 847 | u32 value; |
| 848 | |
| 849 | value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_GENERIC_CTRL); |
| 850 | value &= ~GENERIC_CTRL_ENABLE; |
| 851 | tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_GENERIC_CTRL); |
| 852 | } |
| 853 | |
| 854 | static void tegra_hdmi_enable_stereo_infoframe(struct tegra_hdmi *hdmi) |
| 855 | { |
| 856 | u32 value; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 857 | |
| 858 | value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_GENERIC_CTRL); |
| 859 | value |= GENERIC_CTRL_ENABLE; |
| 860 | tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_GENERIC_CTRL); |
| 861 | } |
| 862 | |
| 863 | static void tegra_hdmi_setup_tmds(struct tegra_hdmi *hdmi, |
| 864 | const struct tmds_config *tmds) |
| 865 | { |
Thierry Reding | 4ee8cee | 2014-12-08 16:25:14 +0100 | [diff] [blame] | 866 | u32 value; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 867 | |
| 868 | tegra_hdmi_writel(hdmi, tmds->pll0, HDMI_NV_PDISP_SOR_PLL0); |
| 869 | tegra_hdmi_writel(hdmi, tmds->pll1, HDMI_NV_PDISP_SOR_PLL1); |
| 870 | tegra_hdmi_writel(hdmi, tmds->pe_current, HDMI_NV_PDISP_PE_CURRENT); |
| 871 | |
Thierry Reding | 59af059 | 2013-10-14 09:43:05 +0200 | [diff] [blame] | 872 | tegra_hdmi_writel(hdmi, tmds->drive_current, |
| 873 | HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT); |
| 874 | |
| 875 | value = tegra_hdmi_readl(hdmi, hdmi->config->fuse_override_offset); |
| 876 | value |= hdmi->config->fuse_override_value; |
| 877 | tegra_hdmi_writel(hdmi, value, hdmi->config->fuse_override_offset); |
Mikko Perttunen | 7d1d28a | 2013-09-30 16:54:47 +0200 | [diff] [blame] | 878 | |
| 879 | if (hdmi->config->has_sor_io_peak_current) |
| 880 | tegra_hdmi_writel(hdmi, tmds->peak_current, |
| 881 | HDMI_NV_PDISP_SOR_IO_PEAK_CURRENT); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 882 | } |
| 883 | |
Mikko Perttunen | 9f15912 | 2013-08-28 18:48:38 +0300 | [diff] [blame] | 884 | static bool tegra_output_is_hdmi(struct tegra_output *output) |
| 885 | { |
| 886 | struct edid *edid; |
| 887 | |
| 888 | if (!output->connector.edid_blob_ptr) |
| 889 | return false; |
| 890 | |
| 891 | edid = (struct edid *)output->connector.edid_blob_ptr->data; |
| 892 | |
| 893 | return drm_detect_hdmi_monitor(edid); |
| 894 | } |
| 895 | |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 896 | static enum drm_connector_status |
| 897 | tegra_hdmi_connector_detect(struct drm_connector *connector, bool force) |
| 898 | { |
| 899 | struct tegra_output *output = connector_to_output(connector); |
| 900 | struct tegra_hdmi *hdmi = to_hdmi(output); |
| 901 | enum drm_connector_status status; |
| 902 | |
| 903 | status = tegra_output_connector_detect(connector, force); |
| 904 | if (status == connector_status_connected) |
| 905 | return status; |
| 906 | |
| 907 | tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_SOR_AUDIO_HDA_PRESENSE); |
| 908 | return status; |
| 909 | } |
| 910 | |
Thierry Reding | 5968271 | 2014-11-28 16:50:59 +0100 | [diff] [blame] | 911 | static const struct drm_connector_funcs tegra_hdmi_connector_funcs = { |
Thierry Reding | 9d44189 | 2014-11-24 17:02:53 +0100 | [diff] [blame] | 912 | .reset = drm_atomic_helper_connector_reset, |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 913 | .detect = tegra_hdmi_connector_detect, |
Thierry Reding | 5968271 | 2014-11-28 16:50:59 +0100 | [diff] [blame] | 914 | .fill_modes = drm_helper_probe_single_connector_modes, |
| 915 | .destroy = tegra_output_connector_destroy, |
Thierry Reding | 9d44189 | 2014-11-24 17:02:53 +0100 | [diff] [blame] | 916 | .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame] | 917 | .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, |
Thierry Reding | 5968271 | 2014-11-28 16:50:59 +0100 | [diff] [blame] | 918 | }; |
| 919 | |
| 920 | static enum drm_mode_status |
| 921 | tegra_hdmi_connector_mode_valid(struct drm_connector *connector, |
| 922 | struct drm_display_mode *mode) |
| 923 | { |
| 924 | struct tegra_output *output = connector_to_output(connector); |
| 925 | struct tegra_hdmi *hdmi = to_hdmi(output); |
| 926 | unsigned long pclk = mode->clock * 1000; |
| 927 | enum drm_mode_status status = MODE_OK; |
| 928 | struct clk *parent; |
| 929 | long err; |
| 930 | |
| 931 | parent = clk_get_parent(hdmi->clk_parent); |
| 932 | |
| 933 | err = clk_round_rate(parent, pclk * 4); |
| 934 | if (err <= 0) |
| 935 | status = MODE_NOCLOCK; |
| 936 | |
| 937 | return status; |
| 938 | } |
| 939 | |
| 940 | static const struct drm_connector_helper_funcs |
| 941 | tegra_hdmi_connector_helper_funcs = { |
| 942 | .get_modes = tegra_output_connector_get_modes, |
| 943 | .mode_valid = tegra_hdmi_connector_mode_valid, |
Thierry Reding | 5968271 | 2014-11-28 16:50:59 +0100 | [diff] [blame] | 944 | }; |
| 945 | |
| 946 | static const struct drm_encoder_funcs tegra_hdmi_encoder_funcs = { |
| 947 | .destroy = tegra_output_encoder_destroy, |
| 948 | }; |
| 949 | |
Thierry Reding | 29871b2 | 2015-07-29 09:46:40 +0200 | [diff] [blame] | 950 | static void tegra_hdmi_encoder_disable(struct drm_encoder *encoder) |
Thierry Reding | 5968271 | 2014-11-28 16:50:59 +0100 | [diff] [blame] | 951 | { |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 952 | struct tegra_output *output = encoder_to_output(encoder); |
Thierry Reding | 29871b2 | 2015-07-29 09:46:40 +0200 | [diff] [blame] | 953 | struct tegra_dc *dc = to_tegra_dc(encoder->crtc); |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 954 | struct tegra_hdmi *hdmi = to_hdmi(output); |
Thierry Reding | 29871b2 | 2015-07-29 09:46:40 +0200 | [diff] [blame] | 955 | u32 value; |
| 956 | |
| 957 | /* |
| 958 | * The following accesses registers of the display controller, so make |
| 959 | * sure it's only executed when the output is attached to one. |
| 960 | */ |
| 961 | if (dc) { |
| 962 | value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS); |
| 963 | value &= ~HDMI_ENABLE; |
| 964 | tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS); |
| 965 | |
| 966 | tegra_dc_commit(dc); |
| 967 | } |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 968 | |
| 969 | if (!hdmi->dvi) { |
| 970 | if (hdmi->stereo) |
| 971 | tegra_hdmi_disable_stereo_infoframe(hdmi); |
| 972 | |
| 973 | tegra_hdmi_disable_audio_infoframe(hdmi); |
| 974 | tegra_hdmi_disable_avi_infoframe(hdmi); |
| 975 | tegra_hdmi_disable_audio(hdmi); |
| 976 | } |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 977 | |
Thierry Reding | 5234549 | 2015-08-07 16:00:43 +0200 | [diff] [blame] | 978 | tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_INT_ENABLE); |
| 979 | tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_INT_MASK); |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 980 | |
Thierry Reding | 5234549 | 2015-08-07 16:00:43 +0200 | [diff] [blame] | 981 | pm_runtime_put(hdmi->dev); |
Thierry Reding | 5968271 | 2014-11-28 16:50:59 +0100 | [diff] [blame] | 982 | } |
| 983 | |
Thierry Reding | 29871b2 | 2015-07-29 09:46:40 +0200 | [diff] [blame] | 984 | static void tegra_hdmi_encoder_enable(struct drm_encoder *encoder) |
Thierry Reding | 5968271 | 2014-11-28 16:50:59 +0100 | [diff] [blame] | 985 | { |
Thierry Reding | 29871b2 | 2015-07-29 09:46:40 +0200 | [diff] [blame] | 986 | struct drm_display_mode *mode = &encoder->crtc->state->adjusted_mode; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 987 | unsigned int h_sync_width, h_front_porch, h_back_porch, i, rekey; |
Thierry Reding | 5968271 | 2014-11-28 16:50:59 +0100 | [diff] [blame] | 988 | struct tegra_output *output = encoder_to_output(encoder); |
| 989 | struct tegra_dc *dc = to_tegra_dc(encoder->crtc); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 990 | struct tegra_hdmi *hdmi = to_hdmi(output); |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 991 | unsigned int pulse_start, div82; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 992 | int retries = 1000; |
Thierry Reding | 4ee8cee | 2014-12-08 16:25:14 +0100 | [diff] [blame] | 993 | u32 value; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 994 | int err; |
| 995 | |
Thierry Reding | 5234549 | 2015-08-07 16:00:43 +0200 | [diff] [blame] | 996 | pm_runtime_get_sync(hdmi->dev); |
Mikko Perttunen | 9f15912 | 2013-08-28 18:48:38 +0300 | [diff] [blame] | 997 | |
Thierry Reding | 5234549 | 2015-08-07 16:00:43 +0200 | [diff] [blame] | 998 | /* |
| 999 | * Enable and unmask the HDA codec SCRATCH0 register interrupt. This |
| 1000 | * is used for interoperability between the HDA codec driver and the |
| 1001 | * HDMI driver. |
| 1002 | */ |
| 1003 | tegra_hdmi_writel(hdmi, INT_CODEC_SCRATCH0, HDMI_NV_PDISP_INT_ENABLE); |
| 1004 | tegra_hdmi_writel(hdmi, INT_CODEC_SCRATCH0, HDMI_NV_PDISP_INT_MASK); |
| 1005 | |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 1006 | hdmi->pixel_clock = mode->clock * 1000; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1007 | h_sync_width = mode->hsync_end - mode->hsync_start; |
Lucas Stach | 4049508 | 2012-12-19 21:38:52 +0000 | [diff] [blame] | 1008 | h_back_porch = mode->htotal - mode->hsync_end; |
| 1009 | h_front_porch = mode->hsync_start - mode->hdisplay; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1010 | |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 1011 | err = clk_set_rate(hdmi->clk, hdmi->pixel_clock); |
Thierry Reding | c03bf1b | 2015-02-18 10:34:08 +0100 | [diff] [blame] | 1012 | if (err < 0) { |
| 1013 | dev_err(hdmi->dev, "failed to set HDMI clock frequency: %d\n", |
| 1014 | err); |
| 1015 | } |
| 1016 | |
| 1017 | DRM_DEBUG_KMS("HDMI clock rate: %lu Hz\n", clk_get_rate(hdmi->clk)); |
| 1018 | |
Thierry Reding | 8c8282c | 2014-04-16 10:46:24 +0200 | [diff] [blame] | 1019 | /* power up sequence */ |
| 1020 | value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_PLL0); |
| 1021 | value &= ~SOR_PLL_PDBG; |
| 1022 | tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_PLL0); |
| 1023 | |
| 1024 | usleep_range(10, 20); |
| 1025 | |
| 1026 | value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_PLL0); |
| 1027 | value &= ~SOR_PLL_PWR; |
| 1028 | tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_PLL0); |
| 1029 | |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1030 | tegra_dc_writel(dc, VSYNC_H_POSITION(1), |
| 1031 | DC_DISP_DISP_TIMING_OPTIONS); |
Thierry Reding | 472a6d1 | 2015-08-05 16:39:55 +0200 | [diff] [blame] | 1032 | tegra_dc_writel(dc, DITHER_CONTROL_DISABLE | BASE_COLOR_SIZE_888, |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1033 | DC_DISP_DISP_COLOR_CONTROL); |
| 1034 | |
| 1035 | /* video_preamble uses h_pulse2 */ |
| 1036 | pulse_start = 1 + h_sync_width + h_back_porch - 10; |
| 1037 | |
Thierry Reding | 8fd3ffa | 2015-04-27 14:48:35 +0200 | [diff] [blame] | 1038 | tegra_dc_writel(dc, H_PULSE2_ENABLE, DC_DISP_DISP_SIGNAL_OPTIONS0); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1039 | |
| 1040 | value = PULSE_MODE_NORMAL | PULSE_POLARITY_HIGH | PULSE_QUAL_VACTIVE | |
| 1041 | PULSE_LAST_END_A; |
| 1042 | tegra_dc_writel(dc, value, DC_DISP_H_PULSE2_CONTROL); |
| 1043 | |
| 1044 | value = PULSE_START(pulse_start) | PULSE_END(pulse_start + 8); |
| 1045 | tegra_dc_writel(dc, value, DC_DISP_H_PULSE2_POSITION_A); |
| 1046 | |
| 1047 | value = VSYNC_WINDOW_END(0x210) | VSYNC_WINDOW_START(0x200) | |
| 1048 | VSYNC_WINDOW_ENABLE; |
| 1049 | tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_VSYNC_WINDOW); |
| 1050 | |
| 1051 | if (dc->pipe) |
| 1052 | value = HDMI_SRC_DISPLAYB; |
| 1053 | else |
| 1054 | value = HDMI_SRC_DISPLAYA; |
| 1055 | |
| 1056 | if ((mode->hdisplay == 720) && ((mode->vdisplay == 480) || |
| 1057 | (mode->vdisplay == 576))) |
| 1058 | tegra_hdmi_writel(hdmi, |
| 1059 | value | ARM_VIDEO_RANGE_FULL, |
| 1060 | HDMI_NV_PDISP_INPUT_CONTROL); |
| 1061 | else |
| 1062 | tegra_hdmi_writel(hdmi, |
| 1063 | value | ARM_VIDEO_RANGE_LIMITED, |
| 1064 | HDMI_NV_PDISP_INPUT_CONTROL); |
| 1065 | |
| 1066 | div82 = clk_get_rate(hdmi->clk) / 1000000 * 4; |
| 1067 | value = SOR_REFCLK_DIV_INT(div82 >> 2) | SOR_REFCLK_DIV_FRAC(div82); |
| 1068 | tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_REFCLK); |
| 1069 | |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 1070 | hdmi->dvi = !tegra_output_is_hdmi(output); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1071 | if (!hdmi->dvi) { |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 1072 | err = tegra_hdmi_setup_audio(hdmi); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1073 | if (err < 0) |
| 1074 | hdmi->dvi = true; |
| 1075 | } |
| 1076 | |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 1077 | if (hdmi->config->has_hda) |
| 1078 | tegra_hdmi_write_eld(hdmi); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1079 | |
| 1080 | rekey = HDMI_REKEY_DEFAULT; |
| 1081 | value = HDMI_CTRL_REKEY(rekey); |
| 1082 | value |= HDMI_CTRL_MAX_AC_PACKET((h_sync_width + h_back_porch + |
| 1083 | h_front_porch - rekey - 18) / 32); |
| 1084 | |
| 1085 | if (!hdmi->dvi) |
| 1086 | value |= HDMI_CTRL_ENABLE; |
| 1087 | |
| 1088 | tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_CTRL); |
| 1089 | |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 1090 | if (!hdmi->dvi) { |
| 1091 | tegra_hdmi_setup_avi_infoframe(hdmi, mode); |
| 1092 | tegra_hdmi_setup_audio_infoframe(hdmi); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1093 | |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 1094 | if (hdmi->stereo) |
| 1095 | tegra_hdmi_setup_stereo_infoframe(hdmi); |
| 1096 | } |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1097 | |
| 1098 | /* TMDS CONFIG */ |
Thierry Reding | 59af059 | 2013-10-14 09:43:05 +0200 | [diff] [blame] | 1099 | for (i = 0; i < hdmi->config->num_tmds; i++) { |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 1100 | if (hdmi->pixel_clock <= hdmi->config->tmds[i].pclk) { |
Thierry Reding | 59af059 | 2013-10-14 09:43:05 +0200 | [diff] [blame] | 1101 | tegra_hdmi_setup_tmds(hdmi, &hdmi->config->tmds[i]); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1102 | break; |
| 1103 | } |
| 1104 | } |
| 1105 | |
| 1106 | tegra_hdmi_writel(hdmi, |
Thierry Reding | 5c1c071 | 2015-01-28 16:32:52 +0100 | [diff] [blame] | 1107 | SOR_SEQ_PU_PC(0) | |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1108 | SOR_SEQ_PU_PC_ALT(0) | |
| 1109 | SOR_SEQ_PD_PC(8) | |
| 1110 | SOR_SEQ_PD_PC_ALT(8), |
| 1111 | HDMI_NV_PDISP_SOR_SEQ_CTL); |
| 1112 | |
| 1113 | value = SOR_SEQ_INST_WAIT_TIME(1) | |
| 1114 | SOR_SEQ_INST_WAIT_UNITS_VSYNC | |
| 1115 | SOR_SEQ_INST_HALT | |
| 1116 | SOR_SEQ_INST_PIN_A_LOW | |
| 1117 | SOR_SEQ_INST_PIN_B_LOW | |
| 1118 | SOR_SEQ_INST_DRIVE_PWM_OUT_LO; |
| 1119 | |
| 1120 | tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_SEQ_INST(0)); |
| 1121 | tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_SEQ_INST(8)); |
| 1122 | |
Thierry Reding | 9cbfc73 | 2014-04-16 10:47:36 +0200 | [diff] [blame] | 1123 | value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_CSTM); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1124 | value &= ~SOR_CSTM_ROTCLK(~0); |
| 1125 | value |= SOR_CSTM_ROTCLK(2); |
Thierry Reding | 9cbfc73 | 2014-04-16 10:47:36 +0200 | [diff] [blame] | 1126 | value |= SOR_CSTM_PLLDIV; |
| 1127 | value &= ~SOR_CSTM_LVDS_ENABLE; |
| 1128 | value &= ~SOR_CSTM_MODE_MASK; |
| 1129 | value |= SOR_CSTM_MODE_TMDS; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1130 | tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_CSTM); |
| 1131 | |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1132 | /* start SOR */ |
| 1133 | tegra_hdmi_writel(hdmi, |
| 1134 | SOR_PWR_NORMAL_STATE_PU | |
| 1135 | SOR_PWR_NORMAL_START_NORMAL | |
| 1136 | SOR_PWR_SAFE_STATE_PD | |
| 1137 | SOR_PWR_SETTING_NEW_TRIGGER, |
| 1138 | HDMI_NV_PDISP_SOR_PWR); |
| 1139 | tegra_hdmi_writel(hdmi, |
| 1140 | SOR_PWR_NORMAL_STATE_PU | |
| 1141 | SOR_PWR_NORMAL_START_NORMAL | |
| 1142 | SOR_PWR_SAFE_STATE_PD | |
| 1143 | SOR_PWR_SETTING_NEW_DONE, |
| 1144 | HDMI_NV_PDISP_SOR_PWR); |
| 1145 | |
| 1146 | do { |
| 1147 | BUG_ON(--retries < 0); |
| 1148 | value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_PWR); |
| 1149 | } while (value & SOR_PWR_SETTING_NEW_PENDING); |
| 1150 | |
| 1151 | value = SOR_STATE_ASY_CRCMODE_COMPLETE | |
| 1152 | SOR_STATE_ASY_OWNER_HEAD0 | |
| 1153 | SOR_STATE_ASY_SUBOWNER_BOTH | |
| 1154 | SOR_STATE_ASY_PROTOCOL_SINGLE_TMDS_A | |
| 1155 | SOR_STATE_ASY_DEPOL_POS; |
| 1156 | |
| 1157 | /* setup sync polarities */ |
| 1158 | if (mode->flags & DRM_MODE_FLAG_PHSYNC) |
| 1159 | value |= SOR_STATE_ASY_HSYNCPOL_POS; |
| 1160 | |
| 1161 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) |
| 1162 | value |= SOR_STATE_ASY_HSYNCPOL_NEG; |
| 1163 | |
| 1164 | if (mode->flags & DRM_MODE_FLAG_PVSYNC) |
| 1165 | value |= SOR_STATE_ASY_VSYNCPOL_POS; |
| 1166 | |
| 1167 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 1168 | value |= SOR_STATE_ASY_VSYNCPOL_NEG; |
| 1169 | |
| 1170 | tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_STATE2); |
| 1171 | |
| 1172 | value = SOR_STATE_ASY_HEAD_OPMODE_AWAKE | SOR_STATE_ASY_ORMODE_NORMAL; |
| 1173 | tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_STATE1); |
| 1174 | |
| 1175 | tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_SOR_STATE0); |
| 1176 | tegra_hdmi_writel(hdmi, SOR_STATE_UPDATE, HDMI_NV_PDISP_SOR_STATE0); |
| 1177 | tegra_hdmi_writel(hdmi, value | SOR_STATE_ATTACHED, |
| 1178 | HDMI_NV_PDISP_SOR_STATE1); |
| 1179 | tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_SOR_STATE0); |
| 1180 | |
Thierry Reding | 72d3028 | 2013-12-12 11:06:55 +0100 | [diff] [blame] | 1181 | value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS); |
| 1182 | value |= HDMI_ENABLE; |
| 1183 | tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1184 | |
Thierry Reding | 62b9e06 | 2014-11-21 17:33:33 +0100 | [diff] [blame] | 1185 | tegra_dc_commit(dc); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1186 | |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 1187 | if (!hdmi->dvi) { |
| 1188 | tegra_hdmi_enable_avi_infoframe(hdmi); |
| 1189 | tegra_hdmi_enable_audio_infoframe(hdmi); |
| 1190 | tegra_hdmi_enable_audio(hdmi); |
| 1191 | |
| 1192 | if (hdmi->stereo) |
| 1193 | tegra_hdmi_enable_stereo_infoframe(hdmi); |
| 1194 | } |
| 1195 | |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1196 | /* TODO: add HDCP support */ |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1197 | } |
| 1198 | |
Thierry Reding | a9825a6 | 2014-12-08 16:33:03 +0100 | [diff] [blame] | 1199 | static int |
| 1200 | tegra_hdmi_encoder_atomic_check(struct drm_encoder *encoder, |
| 1201 | struct drm_crtc_state *crtc_state, |
| 1202 | struct drm_connector_state *conn_state) |
| 1203 | { |
| 1204 | struct tegra_output *output = encoder_to_output(encoder); |
| 1205 | struct tegra_dc *dc = to_tegra_dc(conn_state->crtc); |
| 1206 | unsigned long pclk = crtc_state->mode.clock * 1000; |
| 1207 | struct tegra_hdmi *hdmi = to_hdmi(output); |
| 1208 | int err; |
| 1209 | |
| 1210 | err = tegra_dc_state_setup_clock(dc, crtc_state, hdmi->clk_parent, |
| 1211 | pclk, 0); |
| 1212 | if (err < 0) { |
| 1213 | dev_err(output->dev, "failed to setup CRTC state: %d\n", err); |
| 1214 | return err; |
| 1215 | } |
| 1216 | |
| 1217 | return err; |
| 1218 | } |
| 1219 | |
Thierry Reding | 5968271 | 2014-11-28 16:50:59 +0100 | [diff] [blame] | 1220 | static const struct drm_encoder_helper_funcs tegra_hdmi_encoder_helper_funcs = { |
Thierry Reding | 5968271 | 2014-11-28 16:50:59 +0100 | [diff] [blame] | 1221 | .disable = tegra_hdmi_encoder_disable, |
Thierry Reding | 29871b2 | 2015-07-29 09:46:40 +0200 | [diff] [blame] | 1222 | .enable = tegra_hdmi_encoder_enable, |
Thierry Reding | a9825a6 | 2014-12-08 16:33:03 +0100 | [diff] [blame] | 1223 | .atomic_check = tegra_hdmi_encoder_atomic_check, |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1224 | }; |
| 1225 | |
| 1226 | static int tegra_hdmi_show_regs(struct seq_file *s, void *data) |
| 1227 | { |
| 1228 | struct drm_info_node *node = s->private; |
| 1229 | struct tegra_hdmi *hdmi = node->info_ent->data; |
Thierry Reding | 29871b2 | 2015-07-29 09:46:40 +0200 | [diff] [blame] | 1230 | struct drm_crtc *crtc = hdmi->output.encoder.crtc; |
| 1231 | struct drm_device *drm = node->minor->dev; |
| 1232 | int err = 0; |
Mikko Perttunen | ccaddfe | 2013-07-30 11:35:03 +0300 | [diff] [blame] | 1233 | |
Thierry Reding | 29871b2 | 2015-07-29 09:46:40 +0200 | [diff] [blame] | 1234 | drm_modeset_lock_all(drm); |
| 1235 | |
| 1236 | if (!crtc || !crtc->state->active) { |
| 1237 | err = -EBUSY; |
| 1238 | goto unlock; |
| 1239 | } |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1240 | |
| 1241 | #define DUMP_REG(name) \ |
Thierry Reding | 4ee8cee | 2014-12-08 16:25:14 +0100 | [diff] [blame] | 1242 | seq_printf(s, "%-56s %#05x %08x\n", #name, name, \ |
| 1243 | tegra_hdmi_readl(hdmi, name)) |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1244 | |
| 1245 | DUMP_REG(HDMI_CTXSW); |
| 1246 | DUMP_REG(HDMI_NV_PDISP_SOR_STATE0); |
| 1247 | DUMP_REG(HDMI_NV_PDISP_SOR_STATE1); |
| 1248 | DUMP_REG(HDMI_NV_PDISP_SOR_STATE2); |
| 1249 | DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AN_MSB); |
| 1250 | DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AN_LSB); |
| 1251 | DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CN_MSB); |
| 1252 | DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CN_LSB); |
| 1253 | DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AKSV_MSB); |
| 1254 | DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AKSV_LSB); |
| 1255 | DUMP_REG(HDMI_NV_PDISP_RG_HDCP_BKSV_MSB); |
| 1256 | DUMP_REG(HDMI_NV_PDISP_RG_HDCP_BKSV_LSB); |
| 1257 | DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CKSV_MSB); |
| 1258 | DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CKSV_LSB); |
| 1259 | DUMP_REG(HDMI_NV_PDISP_RG_HDCP_DKSV_MSB); |
| 1260 | DUMP_REG(HDMI_NV_PDISP_RG_HDCP_DKSV_LSB); |
| 1261 | DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CTRL); |
| 1262 | DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CMODE); |
| 1263 | DUMP_REG(HDMI_NV_PDISP_RG_HDCP_MPRIME_MSB); |
| 1264 | DUMP_REG(HDMI_NV_PDISP_RG_HDCP_MPRIME_LSB); |
| 1265 | DUMP_REG(HDMI_NV_PDISP_RG_HDCP_SPRIME_MSB); |
| 1266 | DUMP_REG(HDMI_NV_PDISP_RG_HDCP_SPRIME_LSB2); |
| 1267 | DUMP_REG(HDMI_NV_PDISP_RG_HDCP_SPRIME_LSB1); |
| 1268 | DUMP_REG(HDMI_NV_PDISP_RG_HDCP_RI); |
| 1269 | DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CS_MSB); |
| 1270 | DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CS_LSB); |
| 1271 | DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU0); |
| 1272 | DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU_RDATA0); |
| 1273 | DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU1); |
| 1274 | DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU2); |
| 1275 | DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL); |
| 1276 | DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_STATUS); |
| 1277 | DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_HEADER); |
| 1278 | DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_SUBPACK0_LOW); |
| 1279 | DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_SUBPACK0_HIGH); |
| 1280 | DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL); |
| 1281 | DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_STATUS); |
| 1282 | DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_HEADER); |
| 1283 | DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK0_LOW); |
| 1284 | DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK0_HIGH); |
| 1285 | DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK1_LOW); |
| 1286 | DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK1_HIGH); |
| 1287 | DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_CTRL); |
| 1288 | DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_STATUS); |
| 1289 | DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_HEADER); |
| 1290 | DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK0_LOW); |
| 1291 | DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK0_HIGH); |
| 1292 | DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK1_LOW); |
| 1293 | DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK1_HIGH); |
| 1294 | DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK2_LOW); |
| 1295 | DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK2_HIGH); |
| 1296 | DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK3_LOW); |
| 1297 | DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK3_HIGH); |
| 1298 | DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_CTRL); |
| 1299 | DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0320_SUBPACK_LOW); |
| 1300 | DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0320_SUBPACK_HIGH); |
| 1301 | DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_LOW); |
| 1302 | DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_HIGH); |
| 1303 | DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0882_SUBPACK_LOW); |
| 1304 | DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0882_SUBPACK_HIGH); |
| 1305 | DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1764_SUBPACK_LOW); |
| 1306 | DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1764_SUBPACK_HIGH); |
| 1307 | DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0480_SUBPACK_LOW); |
| 1308 | DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0480_SUBPACK_HIGH); |
| 1309 | DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0960_SUBPACK_LOW); |
| 1310 | DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0960_SUBPACK_HIGH); |
| 1311 | DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1920_SUBPACK_LOW); |
| 1312 | DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1920_SUBPACK_HIGH); |
| 1313 | DUMP_REG(HDMI_NV_PDISP_HDMI_CTRL); |
| 1314 | DUMP_REG(HDMI_NV_PDISP_HDMI_VSYNC_KEEPOUT); |
| 1315 | DUMP_REG(HDMI_NV_PDISP_HDMI_VSYNC_WINDOW); |
| 1316 | DUMP_REG(HDMI_NV_PDISP_HDMI_GCP_CTRL); |
| 1317 | DUMP_REG(HDMI_NV_PDISP_HDMI_GCP_STATUS); |
| 1318 | DUMP_REG(HDMI_NV_PDISP_HDMI_GCP_SUBPACK); |
| 1319 | DUMP_REG(HDMI_NV_PDISP_HDMI_CHANNEL_STATUS1); |
| 1320 | DUMP_REG(HDMI_NV_PDISP_HDMI_CHANNEL_STATUS2); |
| 1321 | DUMP_REG(HDMI_NV_PDISP_HDMI_EMU0); |
| 1322 | DUMP_REG(HDMI_NV_PDISP_HDMI_EMU1); |
| 1323 | DUMP_REG(HDMI_NV_PDISP_HDMI_EMU1_RDATA); |
| 1324 | DUMP_REG(HDMI_NV_PDISP_HDMI_SPARE); |
| 1325 | DUMP_REG(HDMI_NV_PDISP_HDMI_SPDIF_CHN_STATUS1); |
| 1326 | DUMP_REG(HDMI_NV_PDISP_HDMI_SPDIF_CHN_STATUS2); |
| 1327 | DUMP_REG(HDMI_NV_PDISP_HDMI_HDCPRIF_ROM_CTRL); |
| 1328 | DUMP_REG(HDMI_NV_PDISP_SOR_CAP); |
| 1329 | DUMP_REG(HDMI_NV_PDISP_SOR_PWR); |
| 1330 | DUMP_REG(HDMI_NV_PDISP_SOR_TEST); |
| 1331 | DUMP_REG(HDMI_NV_PDISP_SOR_PLL0); |
| 1332 | DUMP_REG(HDMI_NV_PDISP_SOR_PLL1); |
| 1333 | DUMP_REG(HDMI_NV_PDISP_SOR_PLL2); |
| 1334 | DUMP_REG(HDMI_NV_PDISP_SOR_CSTM); |
| 1335 | DUMP_REG(HDMI_NV_PDISP_SOR_LVDS); |
| 1336 | DUMP_REG(HDMI_NV_PDISP_SOR_CRCA); |
| 1337 | DUMP_REG(HDMI_NV_PDISP_SOR_CRCB); |
| 1338 | DUMP_REG(HDMI_NV_PDISP_SOR_BLANK); |
| 1339 | DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_CTL); |
| 1340 | DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(0)); |
| 1341 | DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(1)); |
| 1342 | DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(2)); |
| 1343 | DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(3)); |
| 1344 | DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(4)); |
| 1345 | DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(5)); |
| 1346 | DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(6)); |
| 1347 | DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(7)); |
| 1348 | DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(8)); |
| 1349 | DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(9)); |
| 1350 | DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(10)); |
| 1351 | DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(11)); |
| 1352 | DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(12)); |
| 1353 | DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(13)); |
| 1354 | DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(14)); |
| 1355 | DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(15)); |
| 1356 | DUMP_REG(HDMI_NV_PDISP_SOR_VCRCA0); |
| 1357 | DUMP_REG(HDMI_NV_PDISP_SOR_VCRCA1); |
| 1358 | DUMP_REG(HDMI_NV_PDISP_SOR_CCRCA0); |
| 1359 | DUMP_REG(HDMI_NV_PDISP_SOR_CCRCA1); |
| 1360 | DUMP_REG(HDMI_NV_PDISP_SOR_EDATAA0); |
| 1361 | DUMP_REG(HDMI_NV_PDISP_SOR_EDATAA1); |
| 1362 | DUMP_REG(HDMI_NV_PDISP_SOR_COUNTA0); |
| 1363 | DUMP_REG(HDMI_NV_PDISP_SOR_COUNTA1); |
| 1364 | DUMP_REG(HDMI_NV_PDISP_SOR_DEBUGA0); |
| 1365 | DUMP_REG(HDMI_NV_PDISP_SOR_DEBUGA1); |
| 1366 | DUMP_REG(HDMI_NV_PDISP_SOR_TRIG); |
| 1367 | DUMP_REG(HDMI_NV_PDISP_SOR_MSCHECK); |
| 1368 | DUMP_REG(HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT); |
| 1369 | DUMP_REG(HDMI_NV_PDISP_AUDIO_DEBUG0); |
| 1370 | DUMP_REG(HDMI_NV_PDISP_AUDIO_DEBUG1); |
| 1371 | DUMP_REG(HDMI_NV_PDISP_AUDIO_DEBUG2); |
| 1372 | DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(0)); |
| 1373 | DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(1)); |
| 1374 | DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(2)); |
| 1375 | DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(3)); |
| 1376 | DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(4)); |
| 1377 | DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(5)); |
| 1378 | DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(6)); |
| 1379 | DUMP_REG(HDMI_NV_PDISP_AUDIO_PULSE_WIDTH); |
| 1380 | DUMP_REG(HDMI_NV_PDISP_AUDIO_THRESHOLD); |
| 1381 | DUMP_REG(HDMI_NV_PDISP_AUDIO_CNTRL0); |
| 1382 | DUMP_REG(HDMI_NV_PDISP_AUDIO_N); |
| 1383 | DUMP_REG(HDMI_NV_PDISP_HDCPRIF_ROM_TIMING); |
| 1384 | DUMP_REG(HDMI_NV_PDISP_SOR_REFCLK); |
| 1385 | DUMP_REG(HDMI_NV_PDISP_CRC_CONTROL); |
| 1386 | DUMP_REG(HDMI_NV_PDISP_INPUT_CONTROL); |
| 1387 | DUMP_REG(HDMI_NV_PDISP_SCRATCH); |
| 1388 | DUMP_REG(HDMI_NV_PDISP_PE_CURRENT); |
| 1389 | DUMP_REG(HDMI_NV_PDISP_KEY_CTRL); |
| 1390 | DUMP_REG(HDMI_NV_PDISP_KEY_DEBUG0); |
| 1391 | DUMP_REG(HDMI_NV_PDISP_KEY_DEBUG1); |
| 1392 | DUMP_REG(HDMI_NV_PDISP_KEY_DEBUG2); |
| 1393 | DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_0); |
| 1394 | DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_1); |
| 1395 | DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_2); |
| 1396 | DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_3); |
| 1397 | DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_TRIG); |
| 1398 | DUMP_REG(HDMI_NV_PDISP_KEY_SKEY_INDEX); |
| 1399 | DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_CNTRL0); |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 1400 | DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_SPARE0); |
| 1401 | DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_HDA_CODEC_SCRATCH0); |
| 1402 | DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_HDA_CODEC_SCRATCH1); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1403 | DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_HDA_ELD_BUFWR); |
| 1404 | DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_HDA_PRESENSE); |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 1405 | DUMP_REG(HDMI_NV_PDISP_INT_STATUS); |
| 1406 | DUMP_REG(HDMI_NV_PDISP_INT_MASK); |
| 1407 | DUMP_REG(HDMI_NV_PDISP_INT_ENABLE); |
Mikko Perttunen | 7d1d28a | 2013-09-30 16:54:47 +0200 | [diff] [blame] | 1408 | DUMP_REG(HDMI_NV_PDISP_SOR_IO_PEAK_CURRENT); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1409 | |
| 1410 | #undef DUMP_REG |
| 1411 | |
Thierry Reding | 29871b2 | 2015-07-29 09:46:40 +0200 | [diff] [blame] | 1412 | unlock: |
| 1413 | drm_modeset_unlock_all(drm); |
| 1414 | return err; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1415 | } |
| 1416 | |
| 1417 | static struct drm_info_list debugfs_files[] = { |
| 1418 | { "regs", tegra_hdmi_show_regs, 0, NULL }, |
| 1419 | }; |
| 1420 | |
| 1421 | static int tegra_hdmi_debugfs_init(struct tegra_hdmi *hdmi, |
| 1422 | struct drm_minor *minor) |
| 1423 | { |
| 1424 | unsigned int i; |
| 1425 | int err; |
| 1426 | |
| 1427 | hdmi->debugfs = debugfs_create_dir("hdmi", minor->debugfs_root); |
| 1428 | if (!hdmi->debugfs) |
| 1429 | return -ENOMEM; |
| 1430 | |
| 1431 | hdmi->debugfs_files = kmemdup(debugfs_files, sizeof(debugfs_files), |
| 1432 | GFP_KERNEL); |
| 1433 | if (!hdmi->debugfs_files) { |
| 1434 | err = -ENOMEM; |
| 1435 | goto remove; |
| 1436 | } |
| 1437 | |
| 1438 | for (i = 0; i < ARRAY_SIZE(debugfs_files); i++) |
| 1439 | hdmi->debugfs_files[i].data = hdmi; |
| 1440 | |
| 1441 | err = drm_debugfs_create_files(hdmi->debugfs_files, |
| 1442 | ARRAY_SIZE(debugfs_files), |
| 1443 | hdmi->debugfs, minor); |
| 1444 | if (err < 0) |
| 1445 | goto free; |
| 1446 | |
| 1447 | hdmi->minor = minor; |
| 1448 | |
| 1449 | return 0; |
| 1450 | |
| 1451 | free: |
| 1452 | kfree(hdmi->debugfs_files); |
| 1453 | hdmi->debugfs_files = NULL; |
| 1454 | remove: |
| 1455 | debugfs_remove(hdmi->debugfs); |
| 1456 | hdmi->debugfs = NULL; |
| 1457 | |
| 1458 | return err; |
| 1459 | } |
| 1460 | |
Thierry Reding | 4009c22 | 2014-12-19 15:47:30 +0100 | [diff] [blame] | 1461 | static void tegra_hdmi_debugfs_exit(struct tegra_hdmi *hdmi) |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1462 | { |
| 1463 | drm_debugfs_remove_files(hdmi->debugfs_files, ARRAY_SIZE(debugfs_files), |
| 1464 | hdmi->minor); |
| 1465 | hdmi->minor = NULL; |
| 1466 | |
| 1467 | kfree(hdmi->debugfs_files); |
| 1468 | hdmi->debugfs_files = NULL; |
| 1469 | |
| 1470 | debugfs_remove(hdmi->debugfs); |
| 1471 | hdmi->debugfs = NULL; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1472 | } |
| 1473 | |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame] | 1474 | static int tegra_hdmi_init(struct host1x_client *client) |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1475 | { |
Thierry Reding | 9910f5c | 2014-05-22 09:57:15 +0200 | [diff] [blame] | 1476 | struct drm_device *drm = dev_get_drvdata(client->parent); |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1477 | struct tegra_hdmi *hdmi = host1x_client_to_hdmi(client); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1478 | int err; |
| 1479 | |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1480 | hdmi->output.dev = client->dev; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1481 | |
Thierry Reding | 5968271 | 2014-11-28 16:50:59 +0100 | [diff] [blame] | 1482 | drm_connector_init(drm, &hdmi->output.connector, |
| 1483 | &tegra_hdmi_connector_funcs, |
| 1484 | DRM_MODE_CONNECTOR_HDMIA); |
| 1485 | drm_connector_helper_add(&hdmi->output.connector, |
| 1486 | &tegra_hdmi_connector_helper_funcs); |
| 1487 | hdmi->output.connector.dpms = DRM_MODE_DPMS_OFF; |
| 1488 | |
| 1489 | drm_encoder_init(drm, &hdmi->output.encoder, &tegra_hdmi_encoder_funcs, |
Ville Syrjälä | 13a3d91 | 2015-12-09 16:20:18 +0200 | [diff] [blame] | 1490 | DRM_MODE_ENCODER_TMDS, NULL); |
Thierry Reding | 5968271 | 2014-11-28 16:50:59 +0100 | [diff] [blame] | 1491 | drm_encoder_helper_add(&hdmi->output.encoder, |
| 1492 | &tegra_hdmi_encoder_helper_funcs); |
| 1493 | |
| 1494 | drm_mode_connector_attach_encoder(&hdmi->output.connector, |
| 1495 | &hdmi->output.encoder); |
| 1496 | drm_connector_register(&hdmi->output.connector); |
| 1497 | |
Thierry Reding | ea130b2 | 2014-12-19 15:51:35 +0100 | [diff] [blame] | 1498 | err = tegra_output_init(drm, &hdmi->output); |
| 1499 | if (err < 0) { |
| 1500 | dev_err(client->dev, "failed to initialize output: %d\n", err); |
| 1501 | return err; |
| 1502 | } |
Thierry Reding | 5968271 | 2014-11-28 16:50:59 +0100 | [diff] [blame] | 1503 | |
Thierry Reding | ea130b2 | 2014-12-19 15:51:35 +0100 | [diff] [blame] | 1504 | hdmi->output.encoder.possible_crtcs = 0x3; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1505 | |
| 1506 | if (IS_ENABLED(CONFIG_DEBUG_FS)) { |
Thierry Reding | 9910f5c | 2014-05-22 09:57:15 +0200 | [diff] [blame] | 1507 | err = tegra_hdmi_debugfs_init(hdmi, drm->primary); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1508 | if (err < 0) |
| 1509 | dev_err(client->dev, "debugfs setup failed: %d\n", err); |
| 1510 | } |
| 1511 | |
Thierry Reding | fb50a11 | 2014-02-28 16:57:34 +0100 | [diff] [blame] | 1512 | err = regulator_enable(hdmi->hdmi); |
| 1513 | if (err < 0) { |
| 1514 | dev_err(client->dev, "failed to enable HDMI regulator: %d\n", |
| 1515 | err); |
| 1516 | return err; |
| 1517 | } |
| 1518 | |
Thierry Reding | 5968271 | 2014-11-28 16:50:59 +0100 | [diff] [blame] | 1519 | err = regulator_enable(hdmi->pll); |
| 1520 | if (err < 0) { |
| 1521 | dev_err(hdmi->dev, "failed to enable PLL regulator: %d\n", err); |
| 1522 | return err; |
| 1523 | } |
| 1524 | |
| 1525 | err = regulator_enable(hdmi->vdd); |
| 1526 | if (err < 0) { |
| 1527 | dev_err(hdmi->dev, "failed to enable VDD regulator: %d\n", err); |
| 1528 | return err; |
| 1529 | } |
| 1530 | |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1531 | return 0; |
| 1532 | } |
| 1533 | |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame] | 1534 | static int tegra_hdmi_exit(struct host1x_client *client) |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1535 | { |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1536 | struct tegra_hdmi *hdmi = host1x_client_to_hdmi(client); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1537 | |
Thierry Reding | 5968271 | 2014-11-28 16:50:59 +0100 | [diff] [blame] | 1538 | tegra_output_exit(&hdmi->output); |
| 1539 | |
Thierry Reding | 5968271 | 2014-11-28 16:50:59 +0100 | [diff] [blame] | 1540 | regulator_disable(hdmi->vdd); |
| 1541 | regulator_disable(hdmi->pll); |
Thierry Reding | fb50a11 | 2014-02-28 16:57:34 +0100 | [diff] [blame] | 1542 | regulator_disable(hdmi->hdmi); |
| 1543 | |
Thierry Reding | 4009c22 | 2014-12-19 15:47:30 +0100 | [diff] [blame] | 1544 | if (IS_ENABLED(CONFIG_DEBUG_FS)) |
| 1545 | tegra_hdmi_debugfs_exit(hdmi); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1546 | |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1547 | return 0; |
| 1548 | } |
| 1549 | |
| 1550 | static const struct host1x_client_ops hdmi_client_ops = { |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame] | 1551 | .init = tegra_hdmi_init, |
| 1552 | .exit = tegra_hdmi_exit, |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1553 | }; |
| 1554 | |
Thierry Reding | 59af059 | 2013-10-14 09:43:05 +0200 | [diff] [blame] | 1555 | static const struct tegra_hdmi_config tegra20_hdmi_config = { |
| 1556 | .tmds = tegra20_tmds_config, |
| 1557 | .num_tmds = ARRAY_SIZE(tegra20_tmds_config), |
| 1558 | .fuse_override_offset = HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT, |
| 1559 | .fuse_override_value = 1 << 31, |
Mikko Perttunen | 7d1d28a | 2013-09-30 16:54:47 +0200 | [diff] [blame] | 1560 | .has_sor_io_peak_current = false, |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 1561 | .has_hda = false, |
| 1562 | .has_hbr = false, |
Thierry Reding | 59af059 | 2013-10-14 09:43:05 +0200 | [diff] [blame] | 1563 | }; |
| 1564 | |
| 1565 | static const struct tegra_hdmi_config tegra30_hdmi_config = { |
| 1566 | .tmds = tegra30_tmds_config, |
| 1567 | .num_tmds = ARRAY_SIZE(tegra30_tmds_config), |
| 1568 | .fuse_override_offset = HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT, |
| 1569 | .fuse_override_value = 1 << 31, |
Mikko Perttunen | 7d1d28a | 2013-09-30 16:54:47 +0200 | [diff] [blame] | 1570 | .has_sor_io_peak_current = false, |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 1571 | .has_hda = true, |
| 1572 | .has_hbr = false, |
Mikko Perttunen | 7d1d28a | 2013-09-30 16:54:47 +0200 | [diff] [blame] | 1573 | }; |
| 1574 | |
| 1575 | static const struct tegra_hdmi_config tegra114_hdmi_config = { |
| 1576 | .tmds = tegra114_tmds_config, |
| 1577 | .num_tmds = ARRAY_SIZE(tegra114_tmds_config), |
| 1578 | .fuse_override_offset = HDMI_NV_PDISP_SOR_PAD_CTLS0, |
| 1579 | .fuse_override_value = 1 << 31, |
| 1580 | .has_sor_io_peak_current = true, |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 1581 | .has_hda = true, |
| 1582 | .has_hbr = true, |
Thierry Reding | 59af059 | 2013-10-14 09:43:05 +0200 | [diff] [blame] | 1583 | }; |
| 1584 | |
Thierry Reding | fb7be70 | 2013-11-15 16:07:32 +0100 | [diff] [blame] | 1585 | static const struct tegra_hdmi_config tegra124_hdmi_config = { |
| 1586 | .tmds = tegra124_tmds_config, |
| 1587 | .num_tmds = ARRAY_SIZE(tegra124_tmds_config), |
| 1588 | .fuse_override_offset = HDMI_NV_PDISP_SOR_PAD_CTLS0, |
| 1589 | .fuse_override_value = 1 << 31, |
| 1590 | .has_sor_io_peak_current = true, |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 1591 | .has_hda = true, |
| 1592 | .has_hbr = true, |
Thierry Reding | fb7be70 | 2013-11-15 16:07:32 +0100 | [diff] [blame] | 1593 | }; |
| 1594 | |
Thierry Reding | 59af059 | 2013-10-14 09:43:05 +0200 | [diff] [blame] | 1595 | static const struct of_device_id tegra_hdmi_of_match[] = { |
Thierry Reding | fb7be70 | 2013-11-15 16:07:32 +0100 | [diff] [blame] | 1596 | { .compatible = "nvidia,tegra124-hdmi", .data = &tegra124_hdmi_config }, |
Mikko Perttunen | 7d1d28a | 2013-09-30 16:54:47 +0200 | [diff] [blame] | 1597 | { .compatible = "nvidia,tegra114-hdmi", .data = &tegra114_hdmi_config }, |
Thierry Reding | 59af059 | 2013-10-14 09:43:05 +0200 | [diff] [blame] | 1598 | { .compatible = "nvidia,tegra30-hdmi", .data = &tegra30_hdmi_config }, |
| 1599 | { .compatible = "nvidia,tegra20-hdmi", .data = &tegra20_hdmi_config }, |
| 1600 | { }, |
| 1601 | }; |
Stephen Warren | ef70728 | 2014-06-18 16:21:55 -0600 | [diff] [blame] | 1602 | MODULE_DEVICE_TABLE(of, tegra_hdmi_of_match); |
Thierry Reding | 59af059 | 2013-10-14 09:43:05 +0200 | [diff] [blame] | 1603 | |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 1604 | static void hda_format_parse(unsigned int format, unsigned int *rate, |
| 1605 | unsigned int *channels) |
| 1606 | { |
| 1607 | unsigned int mul, div; |
| 1608 | |
| 1609 | if (format & AC_FMT_BASE_44K) |
| 1610 | *rate = 44100; |
| 1611 | else |
| 1612 | *rate = 48000; |
| 1613 | |
| 1614 | mul = (format & AC_FMT_MULT_MASK) >> AC_FMT_MULT_SHIFT; |
| 1615 | div = (format & AC_FMT_DIV_MASK) >> AC_FMT_DIV_SHIFT; |
| 1616 | |
| 1617 | *rate = *rate * (mul + 1) / (div + 1); |
| 1618 | |
| 1619 | *channels = (format & AC_FMT_CHAN_MASK) >> AC_FMT_CHAN_SHIFT; |
| 1620 | } |
| 1621 | |
| 1622 | static irqreturn_t tegra_hdmi_irq(int irq, void *data) |
| 1623 | { |
| 1624 | struct tegra_hdmi *hdmi = data; |
| 1625 | u32 value; |
| 1626 | int err; |
| 1627 | |
| 1628 | value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_INT_STATUS); |
| 1629 | tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_INT_STATUS); |
| 1630 | |
| 1631 | if (value & INT_CODEC_SCRATCH0) { |
| 1632 | unsigned int format; |
| 1633 | u32 value; |
| 1634 | |
| 1635 | value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_AUDIO_HDA_CODEC_SCRATCH0); |
| 1636 | |
| 1637 | if (value & SOR_AUDIO_HDA_CODEC_SCRATCH0_VALID) { |
| 1638 | unsigned int sample_rate, channels; |
| 1639 | |
| 1640 | format = value & SOR_AUDIO_HDA_CODEC_SCRATCH0_FMT_MASK; |
| 1641 | |
| 1642 | hda_format_parse(format, &sample_rate, &channels); |
| 1643 | |
| 1644 | hdmi->audio_sample_rate = sample_rate; |
| 1645 | hdmi->audio_channels = channels; |
| 1646 | |
| 1647 | err = tegra_hdmi_setup_audio(hdmi); |
| 1648 | if (err < 0) { |
| 1649 | tegra_hdmi_disable_audio_infoframe(hdmi); |
| 1650 | tegra_hdmi_disable_audio(hdmi); |
| 1651 | } else { |
| 1652 | tegra_hdmi_setup_audio_infoframe(hdmi); |
| 1653 | tegra_hdmi_enable_audio_infoframe(hdmi); |
| 1654 | tegra_hdmi_enable_audio(hdmi); |
| 1655 | } |
| 1656 | } else { |
| 1657 | tegra_hdmi_disable_audio_infoframe(hdmi); |
| 1658 | tegra_hdmi_disable_audio(hdmi); |
| 1659 | } |
| 1660 | } |
| 1661 | |
| 1662 | return IRQ_HANDLED; |
| 1663 | } |
| 1664 | |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1665 | static int tegra_hdmi_probe(struct platform_device *pdev) |
| 1666 | { |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1667 | struct tegra_hdmi *hdmi; |
| 1668 | struct resource *regs; |
| 1669 | int err; |
| 1670 | |
| 1671 | hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL); |
| 1672 | if (!hdmi) |
| 1673 | return -ENOMEM; |
| 1674 | |
Thierry Reding | 5e4acd3 | 2017-08-21 18:05:10 +0200 | [diff] [blame^] | 1675 | hdmi->config = of_device_get_match_data(&pdev->dev); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1676 | hdmi->dev = &pdev->dev; |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 1677 | |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1678 | hdmi->audio_source = AUTO; |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 1679 | hdmi->audio_sample_rate = 48000; |
| 1680 | hdmi->audio_channels = 2; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1681 | hdmi->stereo = false; |
| 1682 | hdmi->dvi = false; |
| 1683 | |
| 1684 | hdmi->clk = devm_clk_get(&pdev->dev, NULL); |
| 1685 | if (IS_ERR(hdmi->clk)) { |
| 1686 | dev_err(&pdev->dev, "failed to get clock\n"); |
| 1687 | return PTR_ERR(hdmi->clk); |
| 1688 | } |
| 1689 | |
Stephen Warren | ca48080 | 2013-11-06 16:20:54 -0700 | [diff] [blame] | 1690 | hdmi->rst = devm_reset_control_get(&pdev->dev, "hdmi"); |
| 1691 | if (IS_ERR(hdmi->rst)) { |
| 1692 | dev_err(&pdev->dev, "failed to get reset\n"); |
| 1693 | return PTR_ERR(hdmi->rst); |
| 1694 | } |
| 1695 | |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1696 | hdmi->clk_parent = devm_clk_get(&pdev->dev, "parent"); |
| 1697 | if (IS_ERR(hdmi->clk_parent)) |
| 1698 | return PTR_ERR(hdmi->clk_parent); |
| 1699 | |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1700 | err = clk_set_parent(hdmi->clk, hdmi->clk_parent); |
| 1701 | if (err < 0) { |
| 1702 | dev_err(&pdev->dev, "failed to setup clocks: %d\n", err); |
| 1703 | return err; |
| 1704 | } |
| 1705 | |
Thierry Reding | fb50a11 | 2014-02-28 16:57:34 +0100 | [diff] [blame] | 1706 | hdmi->hdmi = devm_regulator_get(&pdev->dev, "hdmi"); |
| 1707 | if (IS_ERR(hdmi->hdmi)) { |
| 1708 | dev_err(&pdev->dev, "failed to get HDMI regulator\n"); |
| 1709 | return PTR_ERR(hdmi->hdmi); |
| 1710 | } |
| 1711 | |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1712 | hdmi->pll = devm_regulator_get(&pdev->dev, "pll"); |
| 1713 | if (IS_ERR(hdmi->pll)) { |
| 1714 | dev_err(&pdev->dev, "failed to get PLL regulator\n"); |
| 1715 | return PTR_ERR(hdmi->pll); |
| 1716 | } |
| 1717 | |
Thierry Reding | 8868568 | 2014-04-16 10:24:12 +0200 | [diff] [blame] | 1718 | hdmi->vdd = devm_regulator_get(&pdev->dev, "vdd"); |
| 1719 | if (IS_ERR(hdmi->vdd)) { |
| 1720 | dev_err(&pdev->dev, "failed to get VDD regulator\n"); |
| 1721 | return PTR_ERR(hdmi->vdd); |
| 1722 | } |
| 1723 | |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1724 | hdmi->output.dev = &pdev->dev; |
| 1725 | |
Thierry Reding | 59d29c0 | 2013-10-14 14:26:42 +0200 | [diff] [blame] | 1726 | err = tegra_output_probe(&hdmi->output); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1727 | if (err < 0) |
| 1728 | return err; |
| 1729 | |
| 1730 | regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Thierry Reding | d4ed602 | 2013-01-21 11:09:02 +0100 | [diff] [blame] | 1731 | hdmi->regs = devm_ioremap_resource(&pdev->dev, regs); |
| 1732 | if (IS_ERR(hdmi->regs)) |
| 1733 | return PTR_ERR(hdmi->regs); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1734 | |
| 1735 | err = platform_get_irq(pdev, 0); |
| 1736 | if (err < 0) |
| 1737 | return err; |
| 1738 | |
| 1739 | hdmi->irq = err; |
| 1740 | |
Thierry Reding | 2ccb396 | 2015-01-15 13:43:18 +0100 | [diff] [blame] | 1741 | err = devm_request_irq(hdmi->dev, hdmi->irq, tegra_hdmi_irq, 0, |
| 1742 | dev_name(hdmi->dev), hdmi); |
| 1743 | if (err < 0) { |
| 1744 | dev_err(&pdev->dev, "failed to request IRQ#%u: %d\n", |
| 1745 | hdmi->irq, err); |
| 1746 | return err; |
| 1747 | } |
| 1748 | |
Thierry Reding | 5234549 | 2015-08-07 16:00:43 +0200 | [diff] [blame] | 1749 | platform_set_drvdata(pdev, hdmi); |
| 1750 | pm_runtime_enable(&pdev->dev); |
| 1751 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1752 | INIT_LIST_HEAD(&hdmi->client.list); |
| 1753 | hdmi->client.ops = &hdmi_client_ops; |
| 1754 | hdmi->client.dev = &pdev->dev; |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1755 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1756 | err = host1x_client_register(&hdmi->client); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1757 | if (err < 0) { |
| 1758 | dev_err(&pdev->dev, "failed to register host1x client: %d\n", |
| 1759 | err); |
| 1760 | return err; |
| 1761 | } |
| 1762 | |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1763 | return 0; |
| 1764 | } |
| 1765 | |
| 1766 | static int tegra_hdmi_remove(struct platform_device *pdev) |
| 1767 | { |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1768 | struct tegra_hdmi *hdmi = platform_get_drvdata(pdev); |
| 1769 | int err; |
| 1770 | |
Thierry Reding | 5234549 | 2015-08-07 16:00:43 +0200 | [diff] [blame] | 1771 | pm_runtime_disable(&pdev->dev); |
| 1772 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1773 | err = host1x_client_unregister(&hdmi->client); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1774 | if (err < 0) { |
| 1775 | dev_err(&pdev->dev, "failed to unregister host1x client: %d\n", |
| 1776 | err); |
| 1777 | return err; |
| 1778 | } |
| 1779 | |
Thierry Reding | 328ec69 | 2014-12-19 15:55:08 +0100 | [diff] [blame] | 1780 | tegra_output_remove(&hdmi->output); |
Thierry Reding | 59d29c0 | 2013-10-14 14:26:42 +0200 | [diff] [blame] | 1781 | |
Thierry Reding | 5234549 | 2015-08-07 16:00:43 +0200 | [diff] [blame] | 1782 | return 0; |
| 1783 | } |
| 1784 | |
| 1785 | #ifdef CONFIG_PM |
| 1786 | static int tegra_hdmi_suspend(struct device *dev) |
| 1787 | { |
| 1788 | struct tegra_hdmi *hdmi = dev_get_drvdata(dev); |
| 1789 | int err; |
| 1790 | |
| 1791 | err = reset_control_assert(hdmi->rst); |
| 1792 | if (err < 0) { |
| 1793 | dev_err(dev, "failed to assert reset: %d\n", err); |
| 1794 | return err; |
| 1795 | } |
| 1796 | |
| 1797 | usleep_range(1000, 2000); |
| 1798 | |
Thierry Reding | d06e7f8 | 2014-04-16 10:43:41 +0200 | [diff] [blame] | 1799 | clk_disable_unprepare(hdmi->clk); |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1800 | |
| 1801 | return 0; |
| 1802 | } |
| 1803 | |
Thierry Reding | 5234549 | 2015-08-07 16:00:43 +0200 | [diff] [blame] | 1804 | static int tegra_hdmi_resume(struct device *dev) |
| 1805 | { |
| 1806 | struct tegra_hdmi *hdmi = dev_get_drvdata(dev); |
| 1807 | int err; |
| 1808 | |
| 1809 | err = clk_prepare_enable(hdmi->clk); |
| 1810 | if (err < 0) { |
| 1811 | dev_err(dev, "failed to enable clock: %d\n", err); |
| 1812 | return err; |
| 1813 | } |
| 1814 | |
| 1815 | usleep_range(1000, 2000); |
| 1816 | |
| 1817 | err = reset_control_deassert(hdmi->rst); |
| 1818 | if (err < 0) { |
| 1819 | dev_err(dev, "failed to deassert reset: %d\n", err); |
| 1820 | clk_disable_unprepare(hdmi->clk); |
| 1821 | return err; |
| 1822 | } |
| 1823 | |
| 1824 | return 0; |
| 1825 | } |
| 1826 | #endif |
| 1827 | |
| 1828 | static const struct dev_pm_ops tegra_hdmi_pm_ops = { |
| 1829 | SET_RUNTIME_PM_OPS(tegra_hdmi_suspend, tegra_hdmi_resume, NULL) |
| 1830 | }; |
| 1831 | |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1832 | struct platform_driver tegra_hdmi_driver = { |
| 1833 | .driver = { |
| 1834 | .name = "tegra-hdmi", |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1835 | .of_match_table = tegra_hdmi_of_match, |
Thierry Reding | 5234549 | 2015-08-07 16:00:43 +0200 | [diff] [blame] | 1836 | .pm = &tegra_hdmi_pm_ops, |
Thierry Reding | edec4af | 2012-11-15 21:28:23 +0000 | [diff] [blame] | 1837 | }, |
| 1838 | .probe = tegra_hdmi_probe, |
| 1839 | .remove = tegra_hdmi_remove, |
| 1840 | }; |