hdmi.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563
  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. #include <linux/clk.h>
  10. #include <linux/debugfs.h>
  11. #include <linux/gpio.h>
  12. #include <linux/hdmi.h>
  13. #include <linux/regulator/consumer.h>
  14. #include <linux/reset.h>
  15. #include <drm/drm_atomic_helper.h>
  16. #include <drm/drm_crtc.h>
  17. #include <drm/drm_crtc_helper.h>
  18. #include "hdmi.h"
  19. #include "drm.h"
  20. #include "dc.h"
  21. struct tmds_config {
  22. unsigned int pclk;
  23. u32 pll0;
  24. u32 pll1;
  25. u32 pe_current;
  26. u32 drive_current;
  27. u32 peak_current;
  28. };
  29. struct tegra_hdmi_config {
  30. const struct tmds_config *tmds;
  31. unsigned int num_tmds;
  32. unsigned long fuse_override_offset;
  33. u32 fuse_override_value;
  34. bool has_sor_io_peak_current;
  35. };
  36. struct tegra_hdmi {
  37. struct host1x_client client;
  38. struct tegra_output output;
  39. struct device *dev;
  40. struct regulator *hdmi;
  41. struct regulator *pll;
  42. struct regulator *vdd;
  43. void __iomem *regs;
  44. unsigned int irq;
  45. struct clk *clk_parent;
  46. struct clk *clk;
  47. struct reset_control *rst;
  48. const struct tegra_hdmi_config *config;
  49. unsigned int audio_source;
  50. unsigned int audio_freq;
  51. bool stereo;
  52. bool dvi;
  53. struct drm_info_list *debugfs_files;
  54. struct drm_minor *minor;
  55. struct dentry *debugfs;
  56. };
  57. static inline struct tegra_hdmi *
  58. host1x_client_to_hdmi(struct host1x_client *client)
  59. {
  60. return container_of(client, struct tegra_hdmi, client);
  61. }
  62. static inline struct tegra_hdmi *to_hdmi(struct tegra_output *output)
  63. {
  64. return container_of(output, struct tegra_hdmi, output);
  65. }
  66. #define HDMI_AUDIOCLK_FREQ 216000000
  67. #define HDMI_REKEY_DEFAULT 56
  68. enum {
  69. AUTO = 0,
  70. SPDIF,
  71. HDA,
  72. };
  73. static inline u32 tegra_hdmi_readl(struct tegra_hdmi *hdmi,
  74. unsigned long offset)
  75. {
  76. return readl(hdmi->regs + (offset << 2));
  77. }
  78. static inline void tegra_hdmi_writel(struct tegra_hdmi *hdmi, u32 value,
  79. unsigned long offset)
  80. {
  81. writel(value, hdmi->regs + (offset << 2));
  82. }
  83. struct tegra_hdmi_audio_config {
  84. unsigned int pclk;
  85. unsigned int n;
  86. unsigned int cts;
  87. unsigned int aval;
  88. };
  89. static const struct tegra_hdmi_audio_config tegra_hdmi_audio_32k[] = {
  90. { 25200000, 4096, 25200, 24000 },
  91. { 27000000, 4096, 27000, 24000 },
  92. { 74250000, 4096, 74250, 24000 },
  93. { 148500000, 4096, 148500, 24000 },
  94. { 0, 0, 0, 0 },
  95. };
  96. static const struct tegra_hdmi_audio_config tegra_hdmi_audio_44_1k[] = {
  97. { 25200000, 5880, 26250, 25000 },
  98. { 27000000, 5880, 28125, 25000 },
  99. { 74250000, 4704, 61875, 20000 },
  100. { 148500000, 4704, 123750, 20000 },
  101. { 0, 0, 0, 0 },
  102. };
  103. static const struct tegra_hdmi_audio_config tegra_hdmi_audio_48k[] = {
  104. { 25200000, 6144, 25200, 24000 },
  105. { 27000000, 6144, 27000, 24000 },
  106. { 74250000, 6144, 74250, 24000 },
  107. { 148500000, 6144, 148500, 24000 },
  108. { 0, 0, 0, 0 },
  109. };
  110. static const struct tegra_hdmi_audio_config tegra_hdmi_audio_88_2k[] = {
  111. { 25200000, 11760, 26250, 25000 },
  112. { 27000000, 11760, 28125, 25000 },
  113. { 74250000, 9408, 61875, 20000 },
  114. { 148500000, 9408, 123750, 20000 },
  115. { 0, 0, 0, 0 },
  116. };
  117. static const struct tegra_hdmi_audio_config tegra_hdmi_audio_96k[] = {
  118. { 25200000, 12288, 25200, 24000 },
  119. { 27000000, 12288, 27000, 24000 },
  120. { 74250000, 12288, 74250, 24000 },
  121. { 148500000, 12288, 148500, 24000 },
  122. { 0, 0, 0, 0 },
  123. };
  124. static const struct tegra_hdmi_audio_config tegra_hdmi_audio_176_4k[] = {
  125. { 25200000, 23520, 26250, 25000 },
  126. { 27000000, 23520, 28125, 25000 },
  127. { 74250000, 18816, 61875, 20000 },
  128. { 148500000, 18816, 123750, 20000 },
  129. { 0, 0, 0, 0 },
  130. };
  131. static const struct tegra_hdmi_audio_config tegra_hdmi_audio_192k[] = {
  132. { 25200000, 24576, 25200, 24000 },
  133. { 27000000, 24576, 27000, 24000 },
  134. { 74250000, 24576, 74250, 24000 },
  135. { 148500000, 24576, 148500, 24000 },
  136. { 0, 0, 0, 0 },
  137. };
  138. static const struct tmds_config tegra20_tmds_config[] = {
  139. { /* slow pixel clock modes */
  140. .pclk = 27000000,
  141. .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
  142. SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(0) |
  143. SOR_PLL_TX_REG_LOAD(3),
  144. .pll1 = SOR_PLL_TMDS_TERM_ENABLE,
  145. .pe_current = PE_CURRENT0(PE_CURRENT_0_0_mA) |
  146. PE_CURRENT1(PE_CURRENT_0_0_mA) |
  147. PE_CURRENT2(PE_CURRENT_0_0_mA) |
  148. PE_CURRENT3(PE_CURRENT_0_0_mA),
  149. .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_7_125_mA) |
  150. DRIVE_CURRENT_LANE1(DRIVE_CURRENT_7_125_mA) |
  151. DRIVE_CURRENT_LANE2(DRIVE_CURRENT_7_125_mA) |
  152. DRIVE_CURRENT_LANE3(DRIVE_CURRENT_7_125_mA),
  153. },
  154. { /* high pixel clock modes */
  155. .pclk = UINT_MAX,
  156. .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
  157. SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(1) |
  158. SOR_PLL_TX_REG_LOAD(3),
  159. .pll1 = SOR_PLL_TMDS_TERM_ENABLE | SOR_PLL_PE_EN,
  160. .pe_current = PE_CURRENT0(PE_CURRENT_6_0_mA) |
  161. PE_CURRENT1(PE_CURRENT_6_0_mA) |
  162. PE_CURRENT2(PE_CURRENT_6_0_mA) |
  163. PE_CURRENT3(PE_CURRENT_6_0_mA),
  164. .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_7_125_mA) |
  165. DRIVE_CURRENT_LANE1(DRIVE_CURRENT_7_125_mA) |
  166. DRIVE_CURRENT_LANE2(DRIVE_CURRENT_7_125_mA) |
  167. DRIVE_CURRENT_LANE3(DRIVE_CURRENT_7_125_mA),
  168. },
  169. };
  170. static const struct tmds_config tegra30_tmds_config[] = {
  171. { /* 480p modes */
  172. .pclk = 27000000,
  173. .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
  174. SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(0) |
  175. SOR_PLL_TX_REG_LOAD(0),
  176. .pll1 = SOR_PLL_TMDS_TERM_ENABLE,
  177. .pe_current = PE_CURRENT0(PE_CURRENT_0_0_mA) |
  178. PE_CURRENT1(PE_CURRENT_0_0_mA) |
  179. PE_CURRENT2(PE_CURRENT_0_0_mA) |
  180. PE_CURRENT3(PE_CURRENT_0_0_mA),
  181. .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_5_250_mA) |
  182. DRIVE_CURRENT_LANE1(DRIVE_CURRENT_5_250_mA) |
  183. DRIVE_CURRENT_LANE2(DRIVE_CURRENT_5_250_mA) |
  184. DRIVE_CURRENT_LANE3(DRIVE_CURRENT_5_250_mA),
  185. }, { /* 720p modes */
  186. .pclk = 74250000,
  187. .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
  188. SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(1) |
  189. SOR_PLL_TX_REG_LOAD(0),
  190. .pll1 = SOR_PLL_TMDS_TERM_ENABLE | SOR_PLL_PE_EN,
  191. .pe_current = PE_CURRENT0(PE_CURRENT_5_0_mA) |
  192. PE_CURRENT1(PE_CURRENT_5_0_mA) |
  193. PE_CURRENT2(PE_CURRENT_5_0_mA) |
  194. PE_CURRENT3(PE_CURRENT_5_0_mA),
  195. .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_5_250_mA) |
  196. DRIVE_CURRENT_LANE1(DRIVE_CURRENT_5_250_mA) |
  197. DRIVE_CURRENT_LANE2(DRIVE_CURRENT_5_250_mA) |
  198. DRIVE_CURRENT_LANE3(DRIVE_CURRENT_5_250_mA),
  199. }, { /* 1080p modes */
  200. .pclk = UINT_MAX,
  201. .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
  202. SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(3) |
  203. SOR_PLL_TX_REG_LOAD(0),
  204. .pll1 = SOR_PLL_TMDS_TERM_ENABLE | SOR_PLL_PE_EN,
  205. .pe_current = PE_CURRENT0(PE_CURRENT_5_0_mA) |
  206. PE_CURRENT1(PE_CURRENT_5_0_mA) |
  207. PE_CURRENT2(PE_CURRENT_5_0_mA) |
  208. PE_CURRENT3(PE_CURRENT_5_0_mA),
  209. .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_5_250_mA) |
  210. DRIVE_CURRENT_LANE1(DRIVE_CURRENT_5_250_mA) |
  211. DRIVE_CURRENT_LANE2(DRIVE_CURRENT_5_250_mA) |
  212. DRIVE_CURRENT_LANE3(DRIVE_CURRENT_5_250_mA),
  213. },
  214. };
  215. static const struct tmds_config tegra114_tmds_config[] = {
  216. { /* 480p/576p / 25.2MHz/27MHz modes */
  217. .pclk = 27000000,
  218. .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
  219. SOR_PLL_VCOCAP(0) | SOR_PLL_RESISTORSEL,
  220. .pll1 = SOR_PLL_LOADADJ(3) | SOR_PLL_TMDS_TERMADJ(0),
  221. .pe_current = PE_CURRENT0(PE_CURRENT_0_mA_T114) |
  222. PE_CURRENT1(PE_CURRENT_0_mA_T114) |
  223. PE_CURRENT2(PE_CURRENT_0_mA_T114) |
  224. PE_CURRENT3(PE_CURRENT_0_mA_T114),
  225. .drive_current =
  226. DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_10_400_mA_T114) |
  227. DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_10_400_mA_T114) |
  228. DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_10_400_mA_T114) |
  229. DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_10_400_mA_T114),
  230. .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA) |
  231. PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA) |
  232. PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA) |
  233. PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA),
  234. }, { /* 720p / 74.25MHz modes */
  235. .pclk = 74250000,
  236. .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
  237. SOR_PLL_VCOCAP(1) | SOR_PLL_RESISTORSEL,
  238. .pll1 = SOR_PLL_PE_EN | SOR_PLL_LOADADJ(3) |
  239. SOR_PLL_TMDS_TERMADJ(0),
  240. .pe_current = PE_CURRENT0(PE_CURRENT_15_mA_T114) |
  241. PE_CURRENT1(PE_CURRENT_15_mA_T114) |
  242. PE_CURRENT2(PE_CURRENT_15_mA_T114) |
  243. PE_CURRENT3(PE_CURRENT_15_mA_T114),
  244. .drive_current =
  245. DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_10_400_mA_T114) |
  246. DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_10_400_mA_T114) |
  247. DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_10_400_mA_T114) |
  248. DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_10_400_mA_T114),
  249. .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA) |
  250. PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA) |
  251. PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA) |
  252. PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA),
  253. }, { /* 1080p / 148.5MHz modes */
  254. .pclk = 148500000,
  255. .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
  256. SOR_PLL_VCOCAP(3) | SOR_PLL_RESISTORSEL,
  257. .pll1 = SOR_PLL_PE_EN | SOR_PLL_LOADADJ(3) |
  258. SOR_PLL_TMDS_TERMADJ(0),
  259. .pe_current = PE_CURRENT0(PE_CURRENT_10_mA_T114) |
  260. PE_CURRENT1(PE_CURRENT_10_mA_T114) |
  261. PE_CURRENT2(PE_CURRENT_10_mA_T114) |
  262. PE_CURRENT3(PE_CURRENT_10_mA_T114),
  263. .drive_current =
  264. DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_12_400_mA_T114) |
  265. DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_12_400_mA_T114) |
  266. DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_12_400_mA_T114) |
  267. DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_12_400_mA_T114),
  268. .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA) |
  269. PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA) |
  270. PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA) |
  271. PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA),
  272. }, { /* 225/297MHz modes */
  273. .pclk = UINT_MAX,
  274. .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
  275. SOR_PLL_VCOCAP(0xf) | SOR_PLL_RESISTORSEL,
  276. .pll1 = SOR_PLL_LOADADJ(3) | SOR_PLL_TMDS_TERMADJ(7)
  277. | SOR_PLL_TMDS_TERM_ENABLE,
  278. .pe_current = PE_CURRENT0(PE_CURRENT_0_mA_T114) |
  279. PE_CURRENT1(PE_CURRENT_0_mA_T114) |
  280. PE_CURRENT2(PE_CURRENT_0_mA_T114) |
  281. PE_CURRENT3(PE_CURRENT_0_mA_T114),
  282. .drive_current =
  283. DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_25_200_mA_T114) |
  284. DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_25_200_mA_T114) |
  285. DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_25_200_mA_T114) |
  286. DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_19_200_mA_T114),
  287. .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_3_000_mA) |
  288. PEAK_CURRENT_LANE1(PEAK_CURRENT_3_000_mA) |
  289. PEAK_CURRENT_LANE2(PEAK_CURRENT_3_000_mA) |
  290. PEAK_CURRENT_LANE3(PEAK_CURRENT_0_800_mA),
  291. },
  292. };
  293. static const struct tmds_config tegra124_tmds_config[] = {
  294. { /* 480p/576p / 25.2MHz/27MHz modes */
  295. .pclk = 27000000,
  296. .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
  297. SOR_PLL_VCOCAP(0) | SOR_PLL_RESISTORSEL,
  298. .pll1 = SOR_PLL_LOADADJ(3) | SOR_PLL_TMDS_TERMADJ(0),
  299. .pe_current = PE_CURRENT0(PE_CURRENT_0_mA_T114) |
  300. PE_CURRENT1(PE_CURRENT_0_mA_T114) |
  301. PE_CURRENT2(PE_CURRENT_0_mA_T114) |
  302. PE_CURRENT3(PE_CURRENT_0_mA_T114),
  303. .drive_current =
  304. DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_10_400_mA_T114) |
  305. DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_10_400_mA_T114) |
  306. DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_10_400_mA_T114) |
  307. DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_10_400_mA_T114),
  308. .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA) |
  309. PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA) |
  310. PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA) |
  311. PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA),
  312. }, { /* 720p / 74.25MHz modes */
  313. .pclk = 74250000,
  314. .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
  315. SOR_PLL_VCOCAP(1) | SOR_PLL_RESISTORSEL,
  316. .pll1 = SOR_PLL_PE_EN | SOR_PLL_LOADADJ(3) |
  317. SOR_PLL_TMDS_TERMADJ(0),
  318. .pe_current = PE_CURRENT0(PE_CURRENT_15_mA_T114) |
  319. PE_CURRENT1(PE_CURRENT_15_mA_T114) |
  320. PE_CURRENT2(PE_CURRENT_15_mA_T114) |
  321. PE_CURRENT3(PE_CURRENT_15_mA_T114),
  322. .drive_current =
  323. DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_10_400_mA_T114) |
  324. DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_10_400_mA_T114) |
  325. DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_10_400_mA_T114) |
  326. DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_10_400_mA_T114),
  327. .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA) |
  328. PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA) |
  329. PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA) |
  330. PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA),
  331. }, { /* 1080p / 148.5MHz modes */
  332. .pclk = 148500000,
  333. .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
  334. SOR_PLL_VCOCAP(3) | SOR_PLL_RESISTORSEL,
  335. .pll1 = SOR_PLL_PE_EN | SOR_PLL_LOADADJ(3) |
  336. SOR_PLL_TMDS_TERMADJ(0),
  337. .pe_current = PE_CURRENT0(PE_CURRENT_10_mA_T114) |
  338. PE_CURRENT1(PE_CURRENT_10_mA_T114) |
  339. PE_CURRENT2(PE_CURRENT_10_mA_T114) |
  340. PE_CURRENT3(PE_CURRENT_10_mA_T114),
  341. .drive_current =
  342. DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_12_400_mA_T114) |
  343. DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_12_400_mA_T114) |
  344. DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_12_400_mA_T114) |
  345. DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_12_400_mA_T114),
  346. .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA) |
  347. PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA) |
  348. PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA) |
  349. PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA),
  350. }, { /* 225/297MHz modes */
  351. .pclk = UINT_MAX,
  352. .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
  353. SOR_PLL_VCOCAP(0xf) | SOR_PLL_RESISTORSEL,
  354. .pll1 = SOR_PLL_LOADADJ(3) | SOR_PLL_TMDS_TERMADJ(7)
  355. | SOR_PLL_TMDS_TERM_ENABLE,
  356. .pe_current = PE_CURRENT0(PE_CURRENT_0_mA_T114) |
  357. PE_CURRENT1(PE_CURRENT_0_mA_T114) |
  358. PE_CURRENT2(PE_CURRENT_0_mA_T114) |
  359. PE_CURRENT3(PE_CURRENT_0_mA_T114),
  360. .drive_current =
  361. DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_25_200_mA_T114) |
  362. DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_25_200_mA_T114) |
  363. DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_25_200_mA_T114) |
  364. DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_19_200_mA_T114),
  365. .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_3_000_mA) |
  366. PEAK_CURRENT_LANE1(PEAK_CURRENT_3_000_mA) |
  367. PEAK_CURRENT_LANE2(PEAK_CURRENT_3_000_mA) |
  368. PEAK_CURRENT_LANE3(PEAK_CURRENT_0_800_mA),
  369. },
  370. };
  371. static const struct tegra_hdmi_audio_config *
  372. tegra_hdmi_get_audio_config(unsigned int audio_freq, unsigned int pclk)
  373. {
  374. const struct tegra_hdmi_audio_config *table;
  375. switch (audio_freq) {
  376. case 32000:
  377. table = tegra_hdmi_audio_32k;
  378. break;
  379. case 44100:
  380. table = tegra_hdmi_audio_44_1k;
  381. break;
  382. case 48000:
  383. table = tegra_hdmi_audio_48k;
  384. break;
  385. case 88200:
  386. table = tegra_hdmi_audio_88_2k;
  387. break;
  388. case 96000:
  389. table = tegra_hdmi_audio_96k;
  390. break;
  391. case 176400:
  392. table = tegra_hdmi_audio_176_4k;
  393. break;
  394. case 192000:
  395. table = tegra_hdmi_audio_192k;
  396. break;
  397. default:
  398. return NULL;
  399. }
  400. while (table->pclk) {
  401. if (table->pclk == pclk)
  402. return table;
  403. table++;
  404. }
  405. return NULL;
  406. }
  407. static void tegra_hdmi_setup_audio_fs_tables(struct tegra_hdmi *hdmi)
  408. {
  409. const unsigned int freqs[] = {
  410. 32000, 44100, 48000, 88200, 96000, 176400, 192000
  411. };
  412. unsigned int i;
  413. for (i = 0; i < ARRAY_SIZE(freqs); i++) {
  414. unsigned int f = freqs[i];
  415. unsigned int eight_half;
  416. unsigned int delta;
  417. u32 value;
  418. if (f > 96000)
  419. delta = 2;
  420. else if (f > 48000)
  421. delta = 6;
  422. else
  423. delta = 9;
  424. eight_half = (8 * HDMI_AUDIOCLK_FREQ) / (f * 128);
  425. value = AUDIO_FS_LOW(eight_half - delta) |
  426. AUDIO_FS_HIGH(eight_half + delta);
  427. tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_FS(i));
  428. }
  429. }
  430. static int tegra_hdmi_setup_audio(struct tegra_hdmi *hdmi, unsigned int pclk)
  431. {
  432. struct device_node *node = hdmi->dev->of_node;
  433. const struct tegra_hdmi_audio_config *config;
  434. unsigned int offset = 0;
  435. u32 value;
  436. switch (hdmi->audio_source) {
  437. case HDA:
  438. value = AUDIO_CNTRL0_SOURCE_SELECT_HDAL;
  439. break;
  440. case SPDIF:
  441. value = AUDIO_CNTRL0_SOURCE_SELECT_SPDIF;
  442. break;
  443. default:
  444. value = AUDIO_CNTRL0_SOURCE_SELECT_AUTO;
  445. break;
  446. }
  447. if (of_device_is_compatible(node, "nvidia,tegra30-hdmi")) {
  448. value |= AUDIO_CNTRL0_ERROR_TOLERANCE(6) |
  449. AUDIO_CNTRL0_FRAMES_PER_BLOCK(0xc0);
  450. tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_CNTRL0);
  451. } else {
  452. value |= AUDIO_CNTRL0_INJECT_NULLSMPL;
  453. tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_AUDIO_CNTRL0);
  454. value = AUDIO_CNTRL0_ERROR_TOLERANCE(6) |
  455. AUDIO_CNTRL0_FRAMES_PER_BLOCK(0xc0);
  456. tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_CNTRL0);
  457. }
  458. config = tegra_hdmi_get_audio_config(hdmi->audio_freq, pclk);
  459. if (!config) {
  460. dev_err(hdmi->dev, "cannot set audio to %u at %u pclk\n",
  461. hdmi->audio_freq, pclk);
  462. return -EINVAL;
  463. }
  464. tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_HDMI_ACR_CTRL);
  465. value = AUDIO_N_RESETF | AUDIO_N_GENERATE_ALTERNATE |
  466. AUDIO_N_VALUE(config->n - 1);
  467. tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_N);
  468. tegra_hdmi_writel(hdmi, ACR_SUBPACK_N(config->n) | ACR_ENABLE,
  469. HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_HIGH);
  470. value = ACR_SUBPACK_CTS(config->cts);
  471. tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_LOW);
  472. value = SPARE_HW_CTS | SPARE_FORCE_SW_CTS | SPARE_CTS_RESET_VAL(1);
  473. tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_SPARE);
  474. value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_AUDIO_N);
  475. value &= ~AUDIO_N_RESETF;
  476. tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_N);
  477. if (of_device_is_compatible(node, "nvidia,tegra30-hdmi")) {
  478. switch (hdmi->audio_freq) {
  479. case 32000:
  480. offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_0320;
  481. break;
  482. case 44100:
  483. offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_0441;
  484. break;
  485. case 48000:
  486. offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_0480;
  487. break;
  488. case 88200:
  489. offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_0882;
  490. break;
  491. case 96000:
  492. offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_0960;
  493. break;
  494. case 176400:
  495. offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_1764;
  496. break;
  497. case 192000:
  498. offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_1920;
  499. break;
  500. }
  501. tegra_hdmi_writel(hdmi, config->aval, offset);
  502. }
  503. tegra_hdmi_setup_audio_fs_tables(hdmi);
  504. return 0;
  505. }
  506. static inline u32 tegra_hdmi_subpack(const u8 *ptr, size_t size)
  507. {
  508. u32 value = 0;
  509. size_t i;
  510. for (i = size; i > 0; i--)
  511. value = (value << 8) | ptr[i - 1];
  512. return value;
  513. }
  514. static void tegra_hdmi_write_infopack(struct tegra_hdmi *hdmi, const void *data,
  515. size_t size)
  516. {
  517. const u8 *ptr = data;
  518. unsigned long offset;
  519. size_t i, j;
  520. u32 value;
  521. switch (ptr[0]) {
  522. case HDMI_INFOFRAME_TYPE_AVI:
  523. offset = HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_HEADER;
  524. break;
  525. case HDMI_INFOFRAME_TYPE_AUDIO:
  526. offset = HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_HEADER;
  527. break;
  528. case HDMI_INFOFRAME_TYPE_VENDOR:
  529. offset = HDMI_NV_PDISP_HDMI_GENERIC_HEADER;
  530. break;
  531. default:
  532. dev_err(hdmi->dev, "unsupported infoframe type: %02x\n",
  533. ptr[0]);
  534. return;
  535. }
  536. value = INFOFRAME_HEADER_TYPE(ptr[0]) |
  537. INFOFRAME_HEADER_VERSION(ptr[1]) |
  538. INFOFRAME_HEADER_LEN(ptr[2]);
  539. tegra_hdmi_writel(hdmi, value, offset);
  540. offset++;
  541. /*
  542. * Each subpack contains 7 bytes, divided into:
  543. * - subpack_low: bytes 0 - 3
  544. * - subpack_high: bytes 4 - 6 (with byte 7 padded to 0x00)
  545. */
  546. for (i = 3, j = 0; i < size; i += 7, j += 8) {
  547. size_t rem = size - i, num = min_t(size_t, rem, 4);
  548. value = tegra_hdmi_subpack(&ptr[i], num);
  549. tegra_hdmi_writel(hdmi, value, offset++);
  550. num = min_t(size_t, rem - num, 3);
  551. value = tegra_hdmi_subpack(&ptr[i + 4], num);
  552. tegra_hdmi_writel(hdmi, value, offset++);
  553. }
  554. }
  555. static void tegra_hdmi_setup_avi_infoframe(struct tegra_hdmi *hdmi,
  556. struct drm_display_mode *mode)
  557. {
  558. struct hdmi_avi_infoframe frame;
  559. u8 buffer[17];
  560. ssize_t err;
  561. if (hdmi->dvi) {
  562. tegra_hdmi_writel(hdmi, 0,
  563. HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL);
  564. return;
  565. }
  566. err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode);
  567. if (err < 0) {
  568. dev_err(hdmi->dev, "failed to setup AVI infoframe: %zd\n", err);
  569. return;
  570. }
  571. err = hdmi_avi_infoframe_pack(&frame, buffer, sizeof(buffer));
  572. if (err < 0) {
  573. dev_err(hdmi->dev, "failed to pack AVI infoframe: %zd\n", err);
  574. return;
  575. }
  576. tegra_hdmi_write_infopack(hdmi, buffer, err);
  577. tegra_hdmi_writel(hdmi, INFOFRAME_CTRL_ENABLE,
  578. HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL);
  579. }
  580. static void tegra_hdmi_setup_audio_infoframe(struct tegra_hdmi *hdmi)
  581. {
  582. struct hdmi_audio_infoframe frame;
  583. u8 buffer[14];
  584. ssize_t err;
  585. if (hdmi->dvi) {
  586. tegra_hdmi_writel(hdmi, 0,
  587. HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL);
  588. return;
  589. }
  590. err = hdmi_audio_infoframe_init(&frame);
  591. if (err < 0) {
  592. dev_err(hdmi->dev, "failed to setup audio infoframe: %zd\n",
  593. err);
  594. return;
  595. }
  596. frame.channels = 2;
  597. err = hdmi_audio_infoframe_pack(&frame, buffer, sizeof(buffer));
  598. if (err < 0) {
  599. dev_err(hdmi->dev, "failed to pack audio infoframe: %zd\n",
  600. err);
  601. return;
  602. }
  603. /*
  604. * The audio infoframe has only one set of subpack registers, so the
  605. * infoframe needs to be truncated. One set of subpack registers can
  606. * contain 7 bytes. Including the 3 byte header only the first 10
  607. * bytes can be programmed.
  608. */
  609. tegra_hdmi_write_infopack(hdmi, buffer, min_t(size_t, 10, err));
  610. tegra_hdmi_writel(hdmi, INFOFRAME_CTRL_ENABLE,
  611. HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL);
  612. }
  613. static void tegra_hdmi_setup_stereo_infoframe(struct tegra_hdmi *hdmi)
  614. {
  615. struct hdmi_vendor_infoframe frame;
  616. u8 buffer[10];
  617. ssize_t err;
  618. u32 value;
  619. if (!hdmi->stereo) {
  620. value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
  621. value &= ~GENERIC_CTRL_ENABLE;
  622. tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
  623. return;
  624. }
  625. hdmi_vendor_infoframe_init(&frame);
  626. frame.s3d_struct = HDMI_3D_STRUCTURE_FRAME_PACKING;
  627. err = hdmi_vendor_infoframe_pack(&frame, buffer, sizeof(buffer));
  628. if (err < 0) {
  629. dev_err(hdmi->dev, "failed to pack vendor infoframe: %zd\n",
  630. err);
  631. return;
  632. }
  633. tegra_hdmi_write_infopack(hdmi, buffer, err);
  634. value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
  635. value |= GENERIC_CTRL_ENABLE;
  636. tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
  637. }
  638. static void tegra_hdmi_setup_tmds(struct tegra_hdmi *hdmi,
  639. const struct tmds_config *tmds)
  640. {
  641. u32 value;
  642. tegra_hdmi_writel(hdmi, tmds->pll0, HDMI_NV_PDISP_SOR_PLL0);
  643. tegra_hdmi_writel(hdmi, tmds->pll1, HDMI_NV_PDISP_SOR_PLL1);
  644. tegra_hdmi_writel(hdmi, tmds->pe_current, HDMI_NV_PDISP_PE_CURRENT);
  645. tegra_hdmi_writel(hdmi, tmds->drive_current,
  646. HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT);
  647. value = tegra_hdmi_readl(hdmi, hdmi->config->fuse_override_offset);
  648. value |= hdmi->config->fuse_override_value;
  649. tegra_hdmi_writel(hdmi, value, hdmi->config->fuse_override_offset);
  650. if (hdmi->config->has_sor_io_peak_current)
  651. tegra_hdmi_writel(hdmi, tmds->peak_current,
  652. HDMI_NV_PDISP_SOR_IO_PEAK_CURRENT);
  653. }
  654. static bool tegra_output_is_hdmi(struct tegra_output *output)
  655. {
  656. struct edid *edid;
  657. if (!output->connector.edid_blob_ptr)
  658. return false;
  659. edid = (struct edid *)output->connector.edid_blob_ptr->data;
  660. return drm_detect_hdmi_monitor(edid);
  661. }
  662. static const struct drm_connector_funcs tegra_hdmi_connector_funcs = {
  663. .dpms = drm_atomic_helper_connector_dpms,
  664. .reset = drm_atomic_helper_connector_reset,
  665. .detect = tegra_output_connector_detect,
  666. .fill_modes = drm_helper_probe_single_connector_modes,
  667. .destroy = tegra_output_connector_destroy,
  668. .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  669. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  670. };
  671. static enum drm_mode_status
  672. tegra_hdmi_connector_mode_valid(struct drm_connector *connector,
  673. struct drm_display_mode *mode)
  674. {
  675. struct tegra_output *output = connector_to_output(connector);
  676. struct tegra_hdmi *hdmi = to_hdmi(output);
  677. unsigned long pclk = mode->clock * 1000;
  678. enum drm_mode_status status = MODE_OK;
  679. struct clk *parent;
  680. long err;
  681. parent = clk_get_parent(hdmi->clk_parent);
  682. err = clk_round_rate(parent, pclk * 4);
  683. if (err <= 0)
  684. status = MODE_NOCLOCK;
  685. return status;
  686. }
  687. static const struct drm_connector_helper_funcs
  688. tegra_hdmi_connector_helper_funcs = {
  689. .get_modes = tegra_output_connector_get_modes,
  690. .mode_valid = tegra_hdmi_connector_mode_valid,
  691. .best_encoder = tegra_output_connector_best_encoder,
  692. };
  693. static const struct drm_encoder_funcs tegra_hdmi_encoder_funcs = {
  694. .destroy = tegra_output_encoder_destroy,
  695. };
  696. static void tegra_hdmi_encoder_disable(struct drm_encoder *encoder)
  697. {
  698. struct tegra_dc *dc = to_tegra_dc(encoder->crtc);
  699. u32 value;
  700. /*
  701. * The following accesses registers of the display controller, so make
  702. * sure it's only executed when the output is attached to one.
  703. */
  704. if (dc) {
  705. value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
  706. value &= ~HDMI_ENABLE;
  707. tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
  708. tegra_dc_commit(dc);
  709. }
  710. }
  711. static void tegra_hdmi_encoder_enable(struct drm_encoder *encoder)
  712. {
  713. struct drm_display_mode *mode = &encoder->crtc->state->adjusted_mode;
  714. unsigned int h_sync_width, h_front_porch, h_back_porch, i, rekey;
  715. struct tegra_output *output = encoder_to_output(encoder);
  716. struct tegra_dc *dc = to_tegra_dc(encoder->crtc);
  717. struct device_node *node = output->dev->of_node;
  718. struct tegra_hdmi *hdmi = to_hdmi(output);
  719. unsigned int pulse_start, div82, pclk;
  720. int retries = 1000;
  721. u32 value;
  722. int err;
  723. hdmi->dvi = !tegra_output_is_hdmi(output);
  724. pclk = mode->clock * 1000;
  725. h_sync_width = mode->hsync_end - mode->hsync_start;
  726. h_back_porch = mode->htotal - mode->hsync_end;
  727. h_front_porch = mode->hsync_start - mode->hdisplay;
  728. err = clk_set_rate(hdmi->clk, pclk);
  729. if (err < 0) {
  730. dev_err(hdmi->dev, "failed to set HDMI clock frequency: %d\n",
  731. err);
  732. }
  733. DRM_DEBUG_KMS("HDMI clock rate: %lu Hz\n", clk_get_rate(hdmi->clk));
  734. /* power up sequence */
  735. value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_PLL0);
  736. value &= ~SOR_PLL_PDBG;
  737. tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_PLL0);
  738. usleep_range(10, 20);
  739. value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_PLL0);
  740. value &= ~SOR_PLL_PWR;
  741. tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_PLL0);
  742. tegra_dc_writel(dc, VSYNC_H_POSITION(1),
  743. DC_DISP_DISP_TIMING_OPTIONS);
  744. tegra_dc_writel(dc, DITHER_CONTROL_DISABLE | BASE_COLOR_SIZE_888,
  745. DC_DISP_DISP_COLOR_CONTROL);
  746. /* video_preamble uses h_pulse2 */
  747. pulse_start = 1 + h_sync_width + h_back_porch - 10;
  748. tegra_dc_writel(dc, H_PULSE2_ENABLE, DC_DISP_DISP_SIGNAL_OPTIONS0);
  749. value = PULSE_MODE_NORMAL | PULSE_POLARITY_HIGH | PULSE_QUAL_VACTIVE |
  750. PULSE_LAST_END_A;
  751. tegra_dc_writel(dc, value, DC_DISP_H_PULSE2_CONTROL);
  752. value = PULSE_START(pulse_start) | PULSE_END(pulse_start + 8);
  753. tegra_dc_writel(dc, value, DC_DISP_H_PULSE2_POSITION_A);
  754. value = VSYNC_WINDOW_END(0x210) | VSYNC_WINDOW_START(0x200) |
  755. VSYNC_WINDOW_ENABLE;
  756. tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_VSYNC_WINDOW);
  757. if (dc->pipe)
  758. value = HDMI_SRC_DISPLAYB;
  759. else
  760. value = HDMI_SRC_DISPLAYA;
  761. if ((mode->hdisplay == 720) && ((mode->vdisplay == 480) ||
  762. (mode->vdisplay == 576)))
  763. tegra_hdmi_writel(hdmi,
  764. value | ARM_VIDEO_RANGE_FULL,
  765. HDMI_NV_PDISP_INPUT_CONTROL);
  766. else
  767. tegra_hdmi_writel(hdmi,
  768. value | ARM_VIDEO_RANGE_LIMITED,
  769. HDMI_NV_PDISP_INPUT_CONTROL);
  770. div82 = clk_get_rate(hdmi->clk) / 1000000 * 4;
  771. value = SOR_REFCLK_DIV_INT(div82 >> 2) | SOR_REFCLK_DIV_FRAC(div82);
  772. tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_REFCLK);
  773. if (!hdmi->dvi) {
  774. err = tegra_hdmi_setup_audio(hdmi, pclk);
  775. if (err < 0)
  776. hdmi->dvi = true;
  777. }
  778. if (of_device_is_compatible(node, "nvidia,tegra20-hdmi")) {
  779. /*
  780. * TODO: add ELD support
  781. */
  782. }
  783. rekey = HDMI_REKEY_DEFAULT;
  784. value = HDMI_CTRL_REKEY(rekey);
  785. value |= HDMI_CTRL_MAX_AC_PACKET((h_sync_width + h_back_porch +
  786. h_front_porch - rekey - 18) / 32);
  787. if (!hdmi->dvi)
  788. value |= HDMI_CTRL_ENABLE;
  789. tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_CTRL);
  790. if (hdmi->dvi)
  791. tegra_hdmi_writel(hdmi, 0x0,
  792. HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
  793. else
  794. tegra_hdmi_writel(hdmi, GENERIC_CTRL_AUDIO,
  795. HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
  796. tegra_hdmi_setup_avi_infoframe(hdmi, mode);
  797. tegra_hdmi_setup_audio_infoframe(hdmi);
  798. tegra_hdmi_setup_stereo_infoframe(hdmi);
  799. /* TMDS CONFIG */
  800. for (i = 0; i < hdmi->config->num_tmds; i++) {
  801. if (pclk <= hdmi->config->tmds[i].pclk) {
  802. tegra_hdmi_setup_tmds(hdmi, &hdmi->config->tmds[i]);
  803. break;
  804. }
  805. }
  806. tegra_hdmi_writel(hdmi,
  807. SOR_SEQ_PU_PC(0) |
  808. SOR_SEQ_PU_PC_ALT(0) |
  809. SOR_SEQ_PD_PC(8) |
  810. SOR_SEQ_PD_PC_ALT(8),
  811. HDMI_NV_PDISP_SOR_SEQ_CTL);
  812. value = SOR_SEQ_INST_WAIT_TIME(1) |
  813. SOR_SEQ_INST_WAIT_UNITS_VSYNC |
  814. SOR_SEQ_INST_HALT |
  815. SOR_SEQ_INST_PIN_A_LOW |
  816. SOR_SEQ_INST_PIN_B_LOW |
  817. SOR_SEQ_INST_DRIVE_PWM_OUT_LO;
  818. tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_SEQ_INST(0));
  819. tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_SEQ_INST(8));
  820. value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_CSTM);
  821. value &= ~SOR_CSTM_ROTCLK(~0);
  822. value |= SOR_CSTM_ROTCLK(2);
  823. value |= SOR_CSTM_PLLDIV;
  824. value &= ~SOR_CSTM_LVDS_ENABLE;
  825. value &= ~SOR_CSTM_MODE_MASK;
  826. value |= SOR_CSTM_MODE_TMDS;
  827. tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_CSTM);
  828. /* start SOR */
  829. tegra_hdmi_writel(hdmi,
  830. SOR_PWR_NORMAL_STATE_PU |
  831. SOR_PWR_NORMAL_START_NORMAL |
  832. SOR_PWR_SAFE_STATE_PD |
  833. SOR_PWR_SETTING_NEW_TRIGGER,
  834. HDMI_NV_PDISP_SOR_PWR);
  835. tegra_hdmi_writel(hdmi,
  836. SOR_PWR_NORMAL_STATE_PU |
  837. SOR_PWR_NORMAL_START_NORMAL |
  838. SOR_PWR_SAFE_STATE_PD |
  839. SOR_PWR_SETTING_NEW_DONE,
  840. HDMI_NV_PDISP_SOR_PWR);
  841. do {
  842. BUG_ON(--retries < 0);
  843. value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_PWR);
  844. } while (value & SOR_PWR_SETTING_NEW_PENDING);
  845. value = SOR_STATE_ASY_CRCMODE_COMPLETE |
  846. SOR_STATE_ASY_OWNER_HEAD0 |
  847. SOR_STATE_ASY_SUBOWNER_BOTH |
  848. SOR_STATE_ASY_PROTOCOL_SINGLE_TMDS_A |
  849. SOR_STATE_ASY_DEPOL_POS;
  850. /* setup sync polarities */
  851. if (mode->flags & DRM_MODE_FLAG_PHSYNC)
  852. value |= SOR_STATE_ASY_HSYNCPOL_POS;
  853. if (mode->flags & DRM_MODE_FLAG_NHSYNC)
  854. value |= SOR_STATE_ASY_HSYNCPOL_NEG;
  855. if (mode->flags & DRM_MODE_FLAG_PVSYNC)
  856. value |= SOR_STATE_ASY_VSYNCPOL_POS;
  857. if (mode->flags & DRM_MODE_FLAG_NVSYNC)
  858. value |= SOR_STATE_ASY_VSYNCPOL_NEG;
  859. tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_STATE2);
  860. value = SOR_STATE_ASY_HEAD_OPMODE_AWAKE | SOR_STATE_ASY_ORMODE_NORMAL;
  861. tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_STATE1);
  862. tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_SOR_STATE0);
  863. tegra_hdmi_writel(hdmi, SOR_STATE_UPDATE, HDMI_NV_PDISP_SOR_STATE0);
  864. tegra_hdmi_writel(hdmi, value | SOR_STATE_ATTACHED,
  865. HDMI_NV_PDISP_SOR_STATE1);
  866. tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_SOR_STATE0);
  867. value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
  868. value |= HDMI_ENABLE;
  869. tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
  870. tegra_dc_commit(dc);
  871. /* TODO: add HDCP support */
  872. }
  873. static int
  874. tegra_hdmi_encoder_atomic_check(struct drm_encoder *encoder,
  875. struct drm_crtc_state *crtc_state,
  876. struct drm_connector_state *conn_state)
  877. {
  878. struct tegra_output *output = encoder_to_output(encoder);
  879. struct tegra_dc *dc = to_tegra_dc(conn_state->crtc);
  880. unsigned long pclk = crtc_state->mode.clock * 1000;
  881. struct tegra_hdmi *hdmi = to_hdmi(output);
  882. int err;
  883. err = tegra_dc_state_setup_clock(dc, crtc_state, hdmi->clk_parent,
  884. pclk, 0);
  885. if (err < 0) {
  886. dev_err(output->dev, "failed to setup CRTC state: %d\n", err);
  887. return err;
  888. }
  889. return err;
  890. }
  891. static const struct drm_encoder_helper_funcs tegra_hdmi_encoder_helper_funcs = {
  892. .disable = tegra_hdmi_encoder_disable,
  893. .enable = tegra_hdmi_encoder_enable,
  894. .atomic_check = tegra_hdmi_encoder_atomic_check,
  895. };
  896. static int tegra_hdmi_show_regs(struct seq_file *s, void *data)
  897. {
  898. struct drm_info_node *node = s->private;
  899. struct tegra_hdmi *hdmi = node->info_ent->data;
  900. struct drm_crtc *crtc = hdmi->output.encoder.crtc;
  901. struct drm_device *drm = node->minor->dev;
  902. int err = 0;
  903. drm_modeset_lock_all(drm);
  904. if (!crtc || !crtc->state->active) {
  905. err = -EBUSY;
  906. goto unlock;
  907. }
  908. #define DUMP_REG(name) \
  909. seq_printf(s, "%-56s %#05x %08x\n", #name, name, \
  910. tegra_hdmi_readl(hdmi, name))
  911. DUMP_REG(HDMI_CTXSW);
  912. DUMP_REG(HDMI_NV_PDISP_SOR_STATE0);
  913. DUMP_REG(HDMI_NV_PDISP_SOR_STATE1);
  914. DUMP_REG(HDMI_NV_PDISP_SOR_STATE2);
  915. DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AN_MSB);
  916. DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AN_LSB);
  917. DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CN_MSB);
  918. DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CN_LSB);
  919. DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AKSV_MSB);
  920. DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AKSV_LSB);
  921. DUMP_REG(HDMI_NV_PDISP_RG_HDCP_BKSV_MSB);
  922. DUMP_REG(HDMI_NV_PDISP_RG_HDCP_BKSV_LSB);
  923. DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CKSV_MSB);
  924. DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CKSV_LSB);
  925. DUMP_REG(HDMI_NV_PDISP_RG_HDCP_DKSV_MSB);
  926. DUMP_REG(HDMI_NV_PDISP_RG_HDCP_DKSV_LSB);
  927. DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CTRL);
  928. DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CMODE);
  929. DUMP_REG(HDMI_NV_PDISP_RG_HDCP_MPRIME_MSB);
  930. DUMP_REG(HDMI_NV_PDISP_RG_HDCP_MPRIME_LSB);
  931. DUMP_REG(HDMI_NV_PDISP_RG_HDCP_SPRIME_MSB);
  932. DUMP_REG(HDMI_NV_PDISP_RG_HDCP_SPRIME_LSB2);
  933. DUMP_REG(HDMI_NV_PDISP_RG_HDCP_SPRIME_LSB1);
  934. DUMP_REG(HDMI_NV_PDISP_RG_HDCP_RI);
  935. DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CS_MSB);
  936. DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CS_LSB);
  937. DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU0);
  938. DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU_RDATA0);
  939. DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU1);
  940. DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU2);
  941. DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL);
  942. DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_STATUS);
  943. DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_HEADER);
  944. DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_SUBPACK0_LOW);
  945. DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_SUBPACK0_HIGH);
  946. DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL);
  947. DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_STATUS);
  948. DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_HEADER);
  949. DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK0_LOW);
  950. DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK0_HIGH);
  951. DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK1_LOW);
  952. DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK1_HIGH);
  953. DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
  954. DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_STATUS);
  955. DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_HEADER);
  956. DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK0_LOW);
  957. DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK0_HIGH);
  958. DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK1_LOW);
  959. DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK1_HIGH);
  960. DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK2_LOW);
  961. DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK2_HIGH);
  962. DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK3_LOW);
  963. DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK3_HIGH);
  964. DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_CTRL);
  965. DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0320_SUBPACK_LOW);
  966. DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0320_SUBPACK_HIGH);
  967. DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_LOW);
  968. DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_HIGH);
  969. DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0882_SUBPACK_LOW);
  970. DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0882_SUBPACK_HIGH);
  971. DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1764_SUBPACK_LOW);
  972. DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1764_SUBPACK_HIGH);
  973. DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0480_SUBPACK_LOW);
  974. DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0480_SUBPACK_HIGH);
  975. DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0960_SUBPACK_LOW);
  976. DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0960_SUBPACK_HIGH);
  977. DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1920_SUBPACK_LOW);
  978. DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1920_SUBPACK_HIGH);
  979. DUMP_REG(HDMI_NV_PDISP_HDMI_CTRL);
  980. DUMP_REG(HDMI_NV_PDISP_HDMI_VSYNC_KEEPOUT);
  981. DUMP_REG(HDMI_NV_PDISP_HDMI_VSYNC_WINDOW);
  982. DUMP_REG(HDMI_NV_PDISP_HDMI_GCP_CTRL);
  983. DUMP_REG(HDMI_NV_PDISP_HDMI_GCP_STATUS);
  984. DUMP_REG(HDMI_NV_PDISP_HDMI_GCP_SUBPACK);
  985. DUMP_REG(HDMI_NV_PDISP_HDMI_CHANNEL_STATUS1);
  986. DUMP_REG(HDMI_NV_PDISP_HDMI_CHANNEL_STATUS2);
  987. DUMP_REG(HDMI_NV_PDISP_HDMI_EMU0);
  988. DUMP_REG(HDMI_NV_PDISP_HDMI_EMU1);
  989. DUMP_REG(HDMI_NV_PDISP_HDMI_EMU1_RDATA);
  990. DUMP_REG(HDMI_NV_PDISP_HDMI_SPARE);
  991. DUMP_REG(HDMI_NV_PDISP_HDMI_SPDIF_CHN_STATUS1);
  992. DUMP_REG(HDMI_NV_PDISP_HDMI_SPDIF_CHN_STATUS2);
  993. DUMP_REG(HDMI_NV_PDISP_HDMI_HDCPRIF_ROM_CTRL);
  994. DUMP_REG(HDMI_NV_PDISP_SOR_CAP);
  995. DUMP_REG(HDMI_NV_PDISP_SOR_PWR);
  996. DUMP_REG(HDMI_NV_PDISP_SOR_TEST);
  997. DUMP_REG(HDMI_NV_PDISP_SOR_PLL0);
  998. DUMP_REG(HDMI_NV_PDISP_SOR_PLL1);
  999. DUMP_REG(HDMI_NV_PDISP_SOR_PLL2);
  1000. DUMP_REG(HDMI_NV_PDISP_SOR_CSTM);
  1001. DUMP_REG(HDMI_NV_PDISP_SOR_LVDS);
  1002. DUMP_REG(HDMI_NV_PDISP_SOR_CRCA);
  1003. DUMP_REG(HDMI_NV_PDISP_SOR_CRCB);
  1004. DUMP_REG(HDMI_NV_PDISP_SOR_BLANK);
  1005. DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_CTL);
  1006. DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(0));
  1007. DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(1));
  1008. DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(2));
  1009. DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(3));
  1010. DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(4));
  1011. DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(5));
  1012. DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(6));
  1013. DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(7));
  1014. DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(8));
  1015. DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(9));
  1016. DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(10));
  1017. DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(11));
  1018. DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(12));
  1019. DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(13));
  1020. DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(14));
  1021. DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(15));
  1022. DUMP_REG(HDMI_NV_PDISP_SOR_VCRCA0);
  1023. DUMP_REG(HDMI_NV_PDISP_SOR_VCRCA1);
  1024. DUMP_REG(HDMI_NV_PDISP_SOR_CCRCA0);
  1025. DUMP_REG(HDMI_NV_PDISP_SOR_CCRCA1);
  1026. DUMP_REG(HDMI_NV_PDISP_SOR_EDATAA0);
  1027. DUMP_REG(HDMI_NV_PDISP_SOR_EDATAA1);
  1028. DUMP_REG(HDMI_NV_PDISP_SOR_COUNTA0);
  1029. DUMP_REG(HDMI_NV_PDISP_SOR_COUNTA1);
  1030. DUMP_REG(HDMI_NV_PDISP_SOR_DEBUGA0);
  1031. DUMP_REG(HDMI_NV_PDISP_SOR_DEBUGA1);
  1032. DUMP_REG(HDMI_NV_PDISP_SOR_TRIG);
  1033. DUMP_REG(HDMI_NV_PDISP_SOR_MSCHECK);
  1034. DUMP_REG(HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT);
  1035. DUMP_REG(HDMI_NV_PDISP_AUDIO_DEBUG0);
  1036. DUMP_REG(HDMI_NV_PDISP_AUDIO_DEBUG1);
  1037. DUMP_REG(HDMI_NV_PDISP_AUDIO_DEBUG2);
  1038. DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(0));
  1039. DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(1));
  1040. DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(2));
  1041. DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(3));
  1042. DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(4));
  1043. DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(5));
  1044. DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(6));
  1045. DUMP_REG(HDMI_NV_PDISP_AUDIO_PULSE_WIDTH);
  1046. DUMP_REG(HDMI_NV_PDISP_AUDIO_THRESHOLD);
  1047. DUMP_REG(HDMI_NV_PDISP_AUDIO_CNTRL0);
  1048. DUMP_REG(HDMI_NV_PDISP_AUDIO_N);
  1049. DUMP_REG(HDMI_NV_PDISP_HDCPRIF_ROM_TIMING);
  1050. DUMP_REG(HDMI_NV_PDISP_SOR_REFCLK);
  1051. DUMP_REG(HDMI_NV_PDISP_CRC_CONTROL);
  1052. DUMP_REG(HDMI_NV_PDISP_INPUT_CONTROL);
  1053. DUMP_REG(HDMI_NV_PDISP_SCRATCH);
  1054. DUMP_REG(HDMI_NV_PDISP_PE_CURRENT);
  1055. DUMP_REG(HDMI_NV_PDISP_KEY_CTRL);
  1056. DUMP_REG(HDMI_NV_PDISP_KEY_DEBUG0);
  1057. DUMP_REG(HDMI_NV_PDISP_KEY_DEBUG1);
  1058. DUMP_REG(HDMI_NV_PDISP_KEY_DEBUG2);
  1059. DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_0);
  1060. DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_1);
  1061. DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_2);
  1062. DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_3);
  1063. DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_TRIG);
  1064. DUMP_REG(HDMI_NV_PDISP_KEY_SKEY_INDEX);
  1065. DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_CNTRL0);
  1066. DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_HDA_ELD_BUFWR);
  1067. DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_HDA_PRESENSE);
  1068. DUMP_REG(HDMI_NV_PDISP_SOR_IO_PEAK_CURRENT);
  1069. #undef DUMP_REG
  1070. unlock:
  1071. drm_modeset_unlock_all(drm);
  1072. return err;
  1073. }
  1074. static struct drm_info_list debugfs_files[] = {
  1075. { "regs", tegra_hdmi_show_regs, 0, NULL },
  1076. };
  1077. static int tegra_hdmi_debugfs_init(struct tegra_hdmi *hdmi,
  1078. struct drm_minor *minor)
  1079. {
  1080. unsigned int i;
  1081. int err;
  1082. hdmi->debugfs = debugfs_create_dir("hdmi", minor->debugfs_root);
  1083. if (!hdmi->debugfs)
  1084. return -ENOMEM;
  1085. hdmi->debugfs_files = kmemdup(debugfs_files, sizeof(debugfs_files),
  1086. GFP_KERNEL);
  1087. if (!hdmi->debugfs_files) {
  1088. err = -ENOMEM;
  1089. goto remove;
  1090. }
  1091. for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
  1092. hdmi->debugfs_files[i].data = hdmi;
  1093. err = drm_debugfs_create_files(hdmi->debugfs_files,
  1094. ARRAY_SIZE(debugfs_files),
  1095. hdmi->debugfs, minor);
  1096. if (err < 0)
  1097. goto free;
  1098. hdmi->minor = minor;
  1099. return 0;
  1100. free:
  1101. kfree(hdmi->debugfs_files);
  1102. hdmi->debugfs_files = NULL;
  1103. remove:
  1104. debugfs_remove(hdmi->debugfs);
  1105. hdmi->debugfs = NULL;
  1106. return err;
  1107. }
  1108. static void tegra_hdmi_debugfs_exit(struct tegra_hdmi *hdmi)
  1109. {
  1110. drm_debugfs_remove_files(hdmi->debugfs_files, ARRAY_SIZE(debugfs_files),
  1111. hdmi->minor);
  1112. hdmi->minor = NULL;
  1113. kfree(hdmi->debugfs_files);
  1114. hdmi->debugfs_files = NULL;
  1115. debugfs_remove(hdmi->debugfs);
  1116. hdmi->debugfs = NULL;
  1117. }
  1118. static int tegra_hdmi_init(struct host1x_client *client)
  1119. {
  1120. struct drm_device *drm = dev_get_drvdata(client->parent);
  1121. struct tegra_hdmi *hdmi = host1x_client_to_hdmi(client);
  1122. int err;
  1123. hdmi->output.dev = client->dev;
  1124. drm_connector_init(drm, &hdmi->output.connector,
  1125. &tegra_hdmi_connector_funcs,
  1126. DRM_MODE_CONNECTOR_HDMIA);
  1127. drm_connector_helper_add(&hdmi->output.connector,
  1128. &tegra_hdmi_connector_helper_funcs);
  1129. hdmi->output.connector.dpms = DRM_MODE_DPMS_OFF;
  1130. drm_encoder_init(drm, &hdmi->output.encoder, &tegra_hdmi_encoder_funcs,
  1131. DRM_MODE_ENCODER_TMDS);
  1132. drm_encoder_helper_add(&hdmi->output.encoder,
  1133. &tegra_hdmi_encoder_helper_funcs);
  1134. drm_mode_connector_attach_encoder(&hdmi->output.connector,
  1135. &hdmi->output.encoder);
  1136. drm_connector_register(&hdmi->output.connector);
  1137. err = tegra_output_init(drm, &hdmi->output);
  1138. if (err < 0) {
  1139. dev_err(client->dev, "failed to initialize output: %d\n", err);
  1140. return err;
  1141. }
  1142. hdmi->output.encoder.possible_crtcs = 0x3;
  1143. if (IS_ENABLED(CONFIG_DEBUG_FS)) {
  1144. err = tegra_hdmi_debugfs_init(hdmi, drm->primary);
  1145. if (err < 0)
  1146. dev_err(client->dev, "debugfs setup failed: %d\n", err);
  1147. }
  1148. err = regulator_enable(hdmi->hdmi);
  1149. if (err < 0) {
  1150. dev_err(client->dev, "failed to enable HDMI regulator: %d\n",
  1151. err);
  1152. return err;
  1153. }
  1154. err = regulator_enable(hdmi->pll);
  1155. if (err < 0) {
  1156. dev_err(hdmi->dev, "failed to enable PLL regulator: %d\n", err);
  1157. return err;
  1158. }
  1159. err = regulator_enable(hdmi->vdd);
  1160. if (err < 0) {
  1161. dev_err(hdmi->dev, "failed to enable VDD regulator: %d\n", err);
  1162. return err;
  1163. }
  1164. err = clk_prepare_enable(hdmi->clk);
  1165. if (err < 0) {
  1166. dev_err(hdmi->dev, "failed to enable clock: %d\n", err);
  1167. return err;
  1168. }
  1169. reset_control_deassert(hdmi->rst);
  1170. return 0;
  1171. }
  1172. static int tegra_hdmi_exit(struct host1x_client *client)
  1173. {
  1174. struct tegra_hdmi *hdmi = host1x_client_to_hdmi(client);
  1175. tegra_output_exit(&hdmi->output);
  1176. reset_control_assert(hdmi->rst);
  1177. clk_disable_unprepare(hdmi->clk);
  1178. regulator_disable(hdmi->vdd);
  1179. regulator_disable(hdmi->pll);
  1180. regulator_disable(hdmi->hdmi);
  1181. if (IS_ENABLED(CONFIG_DEBUG_FS))
  1182. tegra_hdmi_debugfs_exit(hdmi);
  1183. return 0;
  1184. }
  1185. static const struct host1x_client_ops hdmi_client_ops = {
  1186. .init = tegra_hdmi_init,
  1187. .exit = tegra_hdmi_exit,
  1188. };
  1189. static const struct tegra_hdmi_config tegra20_hdmi_config = {
  1190. .tmds = tegra20_tmds_config,
  1191. .num_tmds = ARRAY_SIZE(tegra20_tmds_config),
  1192. .fuse_override_offset = HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT,
  1193. .fuse_override_value = 1 << 31,
  1194. .has_sor_io_peak_current = false,
  1195. };
  1196. static const struct tegra_hdmi_config tegra30_hdmi_config = {
  1197. .tmds = tegra30_tmds_config,
  1198. .num_tmds = ARRAY_SIZE(tegra30_tmds_config),
  1199. .fuse_override_offset = HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT,
  1200. .fuse_override_value = 1 << 31,
  1201. .has_sor_io_peak_current = false,
  1202. };
  1203. static const struct tegra_hdmi_config tegra114_hdmi_config = {
  1204. .tmds = tegra114_tmds_config,
  1205. .num_tmds = ARRAY_SIZE(tegra114_tmds_config),
  1206. .fuse_override_offset = HDMI_NV_PDISP_SOR_PAD_CTLS0,
  1207. .fuse_override_value = 1 << 31,
  1208. .has_sor_io_peak_current = true,
  1209. };
  1210. static const struct tegra_hdmi_config tegra124_hdmi_config = {
  1211. .tmds = tegra124_tmds_config,
  1212. .num_tmds = ARRAY_SIZE(tegra124_tmds_config),
  1213. .fuse_override_offset = HDMI_NV_PDISP_SOR_PAD_CTLS0,
  1214. .fuse_override_value = 1 << 31,
  1215. .has_sor_io_peak_current = true,
  1216. };
  1217. static const struct of_device_id tegra_hdmi_of_match[] = {
  1218. { .compatible = "nvidia,tegra124-hdmi", .data = &tegra124_hdmi_config },
  1219. { .compatible = "nvidia,tegra114-hdmi", .data = &tegra114_hdmi_config },
  1220. { .compatible = "nvidia,tegra30-hdmi", .data = &tegra30_hdmi_config },
  1221. { .compatible = "nvidia,tegra20-hdmi", .data = &tegra20_hdmi_config },
  1222. { },
  1223. };
  1224. MODULE_DEVICE_TABLE(of, tegra_hdmi_of_match);
  1225. static int tegra_hdmi_probe(struct platform_device *pdev)
  1226. {
  1227. const struct of_device_id *match;
  1228. struct tegra_hdmi *hdmi;
  1229. struct resource *regs;
  1230. int err;
  1231. match = of_match_node(tegra_hdmi_of_match, pdev->dev.of_node);
  1232. if (!match)
  1233. return -ENODEV;
  1234. hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL);
  1235. if (!hdmi)
  1236. return -ENOMEM;
  1237. hdmi->config = match->data;
  1238. hdmi->dev = &pdev->dev;
  1239. hdmi->audio_source = AUTO;
  1240. hdmi->audio_freq = 44100;
  1241. hdmi->stereo = false;
  1242. hdmi->dvi = false;
  1243. hdmi->clk = devm_clk_get(&pdev->dev, NULL);
  1244. if (IS_ERR(hdmi->clk)) {
  1245. dev_err(&pdev->dev, "failed to get clock\n");
  1246. return PTR_ERR(hdmi->clk);
  1247. }
  1248. hdmi->rst = devm_reset_control_get(&pdev->dev, "hdmi");
  1249. if (IS_ERR(hdmi->rst)) {
  1250. dev_err(&pdev->dev, "failed to get reset\n");
  1251. return PTR_ERR(hdmi->rst);
  1252. }
  1253. hdmi->clk_parent = devm_clk_get(&pdev->dev, "parent");
  1254. if (IS_ERR(hdmi->clk_parent))
  1255. return PTR_ERR(hdmi->clk_parent);
  1256. err = clk_set_parent(hdmi->clk, hdmi->clk_parent);
  1257. if (err < 0) {
  1258. dev_err(&pdev->dev, "failed to setup clocks: %d\n", err);
  1259. return err;
  1260. }
  1261. hdmi->hdmi = devm_regulator_get(&pdev->dev, "hdmi");
  1262. if (IS_ERR(hdmi->hdmi)) {
  1263. dev_err(&pdev->dev, "failed to get HDMI regulator\n");
  1264. return PTR_ERR(hdmi->hdmi);
  1265. }
  1266. hdmi->pll = devm_regulator_get(&pdev->dev, "pll");
  1267. if (IS_ERR(hdmi->pll)) {
  1268. dev_err(&pdev->dev, "failed to get PLL regulator\n");
  1269. return PTR_ERR(hdmi->pll);
  1270. }
  1271. hdmi->vdd = devm_regulator_get(&pdev->dev, "vdd");
  1272. if (IS_ERR(hdmi->vdd)) {
  1273. dev_err(&pdev->dev, "failed to get VDD regulator\n");
  1274. return PTR_ERR(hdmi->vdd);
  1275. }
  1276. hdmi->output.dev = &pdev->dev;
  1277. err = tegra_output_probe(&hdmi->output);
  1278. if (err < 0)
  1279. return err;
  1280. regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1281. hdmi->regs = devm_ioremap_resource(&pdev->dev, regs);
  1282. if (IS_ERR(hdmi->regs))
  1283. return PTR_ERR(hdmi->regs);
  1284. err = platform_get_irq(pdev, 0);
  1285. if (err < 0)
  1286. return err;
  1287. hdmi->irq = err;
  1288. INIT_LIST_HEAD(&hdmi->client.list);
  1289. hdmi->client.ops = &hdmi_client_ops;
  1290. hdmi->client.dev = &pdev->dev;
  1291. err = host1x_client_register(&hdmi->client);
  1292. if (err < 0) {
  1293. dev_err(&pdev->dev, "failed to register host1x client: %d\n",
  1294. err);
  1295. return err;
  1296. }
  1297. platform_set_drvdata(pdev, hdmi);
  1298. return 0;
  1299. }
  1300. static int tegra_hdmi_remove(struct platform_device *pdev)
  1301. {
  1302. struct tegra_hdmi *hdmi = platform_get_drvdata(pdev);
  1303. int err;
  1304. err = host1x_client_unregister(&hdmi->client);
  1305. if (err < 0) {
  1306. dev_err(&pdev->dev, "failed to unregister host1x client: %d\n",
  1307. err);
  1308. return err;
  1309. }
  1310. tegra_output_remove(&hdmi->output);
  1311. clk_disable_unprepare(hdmi->clk_parent);
  1312. clk_disable_unprepare(hdmi->clk);
  1313. return 0;
  1314. }
  1315. struct platform_driver tegra_hdmi_driver = {
  1316. .driver = {
  1317. .name = "tegra-hdmi",
  1318. .owner = THIS_MODULE,
  1319. .of_match_table = tegra_hdmi_of_match,
  1320. },
  1321. .probe = tegra_hdmi_probe,
  1322. .remove = tegra_hdmi_remove,
  1323. };