sor.c 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777
  1. /*
  2. * Copyright (C) 2013 NVIDIA Corporation
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #include <linux/clk.h>
  9. #include <linux/clk-provider.h>
  10. #include <linux/debugfs.h>
  11. #include <linux/gpio.h>
  12. #include <linux/io.h>
  13. #include <linux/of_device.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/pm_runtime.h>
  16. #include <linux/regulator/consumer.h>
  17. #include <linux/reset.h>
  18. #include <soc/tegra/pmc.h>
  19. #include <drm/drm_atomic_helper.h>
  20. #include <drm/drm_dp_helper.h>
  21. #include <drm/drm_panel.h>
  22. #include "dc.h"
  23. #include "drm.h"
  24. #include "sor.h"
  25. #define SOR_REKEY 0x38
  26. struct tegra_sor_hdmi_settings {
  27. unsigned long frequency;
  28. u8 vcocap;
  29. u8 ichpmp;
  30. u8 loadadj;
  31. u8 termadj;
  32. u8 tx_pu;
  33. u8 bg_vref;
  34. u8 drive_current[4];
  35. u8 preemphasis[4];
  36. };
  37. #if 1
  38. static const struct tegra_sor_hdmi_settings tegra210_sor_hdmi_defaults[] = {
  39. {
  40. .frequency = 54000000,
  41. .vcocap = 0x0,
  42. .ichpmp = 0x1,
  43. .loadadj = 0x3,
  44. .termadj = 0x9,
  45. .tx_pu = 0x10,
  46. .bg_vref = 0x8,
  47. .drive_current = { 0x33, 0x3a, 0x3a, 0x3a },
  48. .preemphasis = { 0x00, 0x00, 0x00, 0x00 },
  49. }, {
  50. .frequency = 75000000,
  51. .vcocap = 0x3,
  52. .ichpmp = 0x1,
  53. .loadadj = 0x3,
  54. .termadj = 0x9,
  55. .tx_pu = 0x40,
  56. .bg_vref = 0x8,
  57. .drive_current = { 0x33, 0x3a, 0x3a, 0x3a },
  58. .preemphasis = { 0x00, 0x00, 0x00, 0x00 },
  59. }, {
  60. .frequency = 150000000,
  61. .vcocap = 0x3,
  62. .ichpmp = 0x1,
  63. .loadadj = 0x3,
  64. .termadj = 0x9,
  65. .tx_pu = 0x66,
  66. .bg_vref = 0x8,
  67. .drive_current = { 0x33, 0x3a, 0x3a, 0x3a },
  68. .preemphasis = { 0x00, 0x00, 0x00, 0x00 },
  69. }, {
  70. .frequency = 300000000,
  71. .vcocap = 0x3,
  72. .ichpmp = 0x1,
  73. .loadadj = 0x3,
  74. .termadj = 0x9,
  75. .tx_pu = 0x66,
  76. .bg_vref = 0xa,
  77. .drive_current = { 0x33, 0x3f, 0x3f, 0x3f },
  78. .preemphasis = { 0x00, 0x17, 0x17, 0x17 },
  79. }, {
  80. .frequency = 600000000,
  81. .vcocap = 0x3,
  82. .ichpmp = 0x1,
  83. .loadadj = 0x3,
  84. .termadj = 0x9,
  85. .tx_pu = 0x66,
  86. .bg_vref = 0x8,
  87. .drive_current = { 0x33, 0x3f, 0x3f, 0x3f },
  88. .preemphasis = { 0x00, 0x00, 0x00, 0x00 },
  89. },
  90. };
  91. #else
  92. static const struct tegra_sor_hdmi_settings tegra210_sor_hdmi_defaults[] = {
  93. {
  94. .frequency = 75000000,
  95. .vcocap = 0x3,
  96. .ichpmp = 0x1,
  97. .loadadj = 0x3,
  98. .termadj = 0x9,
  99. .tx_pu = 0x40,
  100. .bg_vref = 0x8,
  101. .drive_current = { 0x29, 0x29, 0x29, 0x29 },
  102. .preemphasis = { 0x00, 0x00, 0x00, 0x00 },
  103. }, {
  104. .frequency = 150000000,
  105. .vcocap = 0x3,
  106. .ichpmp = 0x1,
  107. .loadadj = 0x3,
  108. .termadj = 0x9,
  109. .tx_pu = 0x66,
  110. .bg_vref = 0x8,
  111. .drive_current = { 0x30, 0x37, 0x37, 0x37 },
  112. .preemphasis = { 0x01, 0x02, 0x02, 0x02 },
  113. }, {
  114. .frequency = 300000000,
  115. .vcocap = 0x3,
  116. .ichpmp = 0x6,
  117. .loadadj = 0x3,
  118. .termadj = 0x9,
  119. .tx_pu = 0x66,
  120. .bg_vref = 0xf,
  121. .drive_current = { 0x30, 0x37, 0x37, 0x37 },
  122. .preemphasis = { 0x10, 0x3e, 0x3e, 0x3e },
  123. }, {
  124. .frequency = 600000000,
  125. .vcocap = 0x3,
  126. .ichpmp = 0xa,
  127. .loadadj = 0x3,
  128. .termadj = 0xb,
  129. .tx_pu = 0x66,
  130. .bg_vref = 0xe,
  131. .drive_current = { 0x35, 0x3e, 0x3e, 0x3e },
  132. .preemphasis = { 0x02, 0x3f, 0x3f, 0x3f },
  133. },
  134. };
  135. #endif
  136. struct tegra_sor_soc {
  137. bool supports_edp;
  138. bool supports_lvds;
  139. bool supports_hdmi;
  140. bool supports_dp;
  141. const struct tegra_sor_hdmi_settings *settings;
  142. unsigned int num_settings;
  143. const u8 *xbar_cfg;
  144. };
  145. struct tegra_sor;
  146. struct tegra_sor_ops {
  147. const char *name;
  148. int (*probe)(struct tegra_sor *sor);
  149. int (*remove)(struct tegra_sor *sor);
  150. };
  151. struct tegra_sor {
  152. struct host1x_client client;
  153. struct tegra_output output;
  154. struct device *dev;
  155. const struct tegra_sor_soc *soc;
  156. void __iomem *regs;
  157. struct reset_control *rst;
  158. struct clk *clk_parent;
  159. struct clk *clk_brick;
  160. struct clk *clk_safe;
  161. struct clk *clk_src;
  162. struct clk *clk_dp;
  163. struct clk *clk;
  164. struct drm_dp_aux *aux;
  165. struct drm_info_list *debugfs_files;
  166. struct drm_minor *minor;
  167. struct dentry *debugfs;
  168. const struct tegra_sor_ops *ops;
  169. /* for HDMI 2.0 */
  170. struct tegra_sor_hdmi_settings *settings;
  171. unsigned int num_settings;
  172. struct regulator *avdd_io_supply;
  173. struct regulator *vdd_pll_supply;
  174. struct regulator *hdmi_supply;
  175. };
  176. struct tegra_sor_state {
  177. struct drm_connector_state base;
  178. unsigned int bpc;
  179. };
  180. static inline struct tegra_sor_state *
  181. to_sor_state(struct drm_connector_state *state)
  182. {
  183. return container_of(state, struct tegra_sor_state, base);
  184. }
  185. struct tegra_sor_config {
  186. u32 bits_per_pixel;
  187. u32 active_polarity;
  188. u32 active_count;
  189. u32 tu_size;
  190. u32 active_frac;
  191. u32 watermark;
  192. u32 hblank_symbols;
  193. u32 vblank_symbols;
  194. };
  195. static inline struct tegra_sor *
  196. host1x_client_to_sor(struct host1x_client *client)
  197. {
  198. return container_of(client, struct tegra_sor, client);
  199. }
  200. static inline struct tegra_sor *to_sor(struct tegra_output *output)
  201. {
  202. return container_of(output, struct tegra_sor, output);
  203. }
  204. static inline u32 tegra_sor_readl(struct tegra_sor *sor, unsigned long offset)
  205. {
  206. return readl(sor->regs + (offset << 2));
  207. }
  208. static inline void tegra_sor_writel(struct tegra_sor *sor, u32 value,
  209. unsigned long offset)
  210. {
  211. writel(value, sor->regs + (offset << 2));
  212. }
  213. static int tegra_sor_set_parent_clock(struct tegra_sor *sor, struct clk *parent)
  214. {
  215. int err;
  216. clk_disable_unprepare(sor->clk);
  217. err = clk_set_parent(sor->clk, parent);
  218. if (err < 0)
  219. return err;
  220. err = clk_prepare_enable(sor->clk);
  221. if (err < 0)
  222. return err;
  223. return 0;
  224. }
  225. struct tegra_clk_sor_brick {
  226. struct clk_hw hw;
  227. struct tegra_sor *sor;
  228. };
  229. static inline struct tegra_clk_sor_brick *to_brick(struct clk_hw *hw)
  230. {
  231. return container_of(hw, struct tegra_clk_sor_brick, hw);
  232. }
  233. static const char * const tegra_clk_sor_brick_parents[] = {
  234. "pll_d2_out0", "pll_dp"
  235. };
  236. static int tegra_clk_sor_brick_set_parent(struct clk_hw *hw, u8 index)
  237. {
  238. struct tegra_clk_sor_brick *brick = to_brick(hw);
  239. struct tegra_sor *sor = brick->sor;
  240. u32 value;
  241. value = tegra_sor_readl(sor, SOR_CLK_CNTRL);
  242. value &= ~SOR_CLK_CNTRL_DP_CLK_SEL_MASK;
  243. switch (index) {
  244. case 0:
  245. value |= SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_PCLK;
  246. break;
  247. case 1:
  248. value |= SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_DPCLK;
  249. break;
  250. }
  251. tegra_sor_writel(sor, value, SOR_CLK_CNTRL);
  252. return 0;
  253. }
  254. static u8 tegra_clk_sor_brick_get_parent(struct clk_hw *hw)
  255. {
  256. struct tegra_clk_sor_brick *brick = to_brick(hw);
  257. struct tegra_sor *sor = brick->sor;
  258. u8 parent = U8_MAX;
  259. u32 value;
  260. value = tegra_sor_readl(sor, SOR_CLK_CNTRL);
  261. switch (value & SOR_CLK_CNTRL_DP_CLK_SEL_MASK) {
  262. case SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_PCLK:
  263. case SOR_CLK_CNTRL_DP_CLK_SEL_DIFF_PCLK:
  264. parent = 0;
  265. break;
  266. case SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_DPCLK:
  267. case SOR_CLK_CNTRL_DP_CLK_SEL_DIFF_DPCLK:
  268. parent = 1;
  269. break;
  270. }
  271. return parent;
  272. }
  273. static const struct clk_ops tegra_clk_sor_brick_ops = {
  274. .set_parent = tegra_clk_sor_brick_set_parent,
  275. .get_parent = tegra_clk_sor_brick_get_parent,
  276. };
  277. static struct clk *tegra_clk_sor_brick_register(struct tegra_sor *sor,
  278. const char *name)
  279. {
  280. struct tegra_clk_sor_brick *brick;
  281. struct clk_init_data init;
  282. struct clk *clk;
  283. brick = devm_kzalloc(sor->dev, sizeof(*brick), GFP_KERNEL);
  284. if (!brick)
  285. return ERR_PTR(-ENOMEM);
  286. brick->sor = sor;
  287. init.name = name;
  288. init.flags = 0;
  289. init.parent_names = tegra_clk_sor_brick_parents;
  290. init.num_parents = ARRAY_SIZE(tegra_clk_sor_brick_parents);
  291. init.ops = &tegra_clk_sor_brick_ops;
  292. brick->hw.init = &init;
  293. clk = devm_clk_register(sor->dev, &brick->hw);
  294. return clk;
  295. }
  296. static int tegra_sor_dp_train_fast(struct tegra_sor *sor,
  297. struct drm_dp_link *link)
  298. {
  299. unsigned int i;
  300. u8 pattern;
  301. u32 value;
  302. int err;
  303. /* setup lane parameters */
  304. value = SOR_LANE_DRIVE_CURRENT_LANE3(0x40) |
  305. SOR_LANE_DRIVE_CURRENT_LANE2(0x40) |
  306. SOR_LANE_DRIVE_CURRENT_LANE1(0x40) |
  307. SOR_LANE_DRIVE_CURRENT_LANE0(0x40);
  308. tegra_sor_writel(sor, value, SOR_LANE_DRIVE_CURRENT0);
  309. value = SOR_LANE_PREEMPHASIS_LANE3(0x0f) |
  310. SOR_LANE_PREEMPHASIS_LANE2(0x0f) |
  311. SOR_LANE_PREEMPHASIS_LANE1(0x0f) |
  312. SOR_LANE_PREEMPHASIS_LANE0(0x0f);
  313. tegra_sor_writel(sor, value, SOR_LANE_PREEMPHASIS0);
  314. value = SOR_LANE_POSTCURSOR_LANE3(0x00) |
  315. SOR_LANE_POSTCURSOR_LANE2(0x00) |
  316. SOR_LANE_POSTCURSOR_LANE1(0x00) |
  317. SOR_LANE_POSTCURSOR_LANE0(0x00);
  318. tegra_sor_writel(sor, value, SOR_LANE_POSTCURSOR0);
  319. /* disable LVDS mode */
  320. tegra_sor_writel(sor, 0, SOR_LVDS);
  321. value = tegra_sor_readl(sor, SOR_DP_PADCTL0);
  322. value |= SOR_DP_PADCTL_TX_PU_ENABLE;
  323. value &= ~SOR_DP_PADCTL_TX_PU_MASK;
  324. value |= SOR_DP_PADCTL_TX_PU(2); /* XXX: don't hardcode? */
  325. tegra_sor_writel(sor, value, SOR_DP_PADCTL0);
  326. value = tegra_sor_readl(sor, SOR_DP_PADCTL0);
  327. value |= SOR_DP_PADCTL_CM_TXD_3 | SOR_DP_PADCTL_CM_TXD_2 |
  328. SOR_DP_PADCTL_CM_TXD_1 | SOR_DP_PADCTL_CM_TXD_0;
  329. tegra_sor_writel(sor, value, SOR_DP_PADCTL0);
  330. usleep_range(10, 100);
  331. value = tegra_sor_readl(sor, SOR_DP_PADCTL0);
  332. value &= ~(SOR_DP_PADCTL_CM_TXD_3 | SOR_DP_PADCTL_CM_TXD_2 |
  333. SOR_DP_PADCTL_CM_TXD_1 | SOR_DP_PADCTL_CM_TXD_0);
  334. tegra_sor_writel(sor, value, SOR_DP_PADCTL0);
  335. err = drm_dp_aux_prepare(sor->aux, DP_SET_ANSI_8B10B);
  336. if (err < 0)
  337. return err;
  338. for (i = 0, value = 0; i < link->num_lanes; i++) {
  339. unsigned long lane = SOR_DP_TPG_CHANNEL_CODING |
  340. SOR_DP_TPG_SCRAMBLER_NONE |
  341. SOR_DP_TPG_PATTERN_TRAIN1;
  342. value = (value << 8) | lane;
  343. }
  344. tegra_sor_writel(sor, value, SOR_DP_TPG);
  345. pattern = DP_TRAINING_PATTERN_1;
  346. err = drm_dp_aux_train(sor->aux, link, pattern);
  347. if (err < 0)
  348. return err;
  349. value = tegra_sor_readl(sor, SOR_DP_SPARE0);
  350. value |= SOR_DP_SPARE_SEQ_ENABLE;
  351. value &= ~SOR_DP_SPARE_PANEL_INTERNAL;
  352. value |= SOR_DP_SPARE_MACRO_SOR_CLK;
  353. tegra_sor_writel(sor, value, SOR_DP_SPARE0);
  354. for (i = 0, value = 0; i < link->num_lanes; i++) {
  355. unsigned long lane = SOR_DP_TPG_CHANNEL_CODING |
  356. SOR_DP_TPG_SCRAMBLER_NONE |
  357. SOR_DP_TPG_PATTERN_TRAIN2;
  358. value = (value << 8) | lane;
  359. }
  360. tegra_sor_writel(sor, value, SOR_DP_TPG);
  361. pattern = DP_LINK_SCRAMBLING_DISABLE | DP_TRAINING_PATTERN_2;
  362. err = drm_dp_aux_train(sor->aux, link, pattern);
  363. if (err < 0)
  364. return err;
  365. for (i = 0, value = 0; i < link->num_lanes; i++) {
  366. unsigned long lane = SOR_DP_TPG_CHANNEL_CODING |
  367. SOR_DP_TPG_SCRAMBLER_GALIOS |
  368. SOR_DP_TPG_PATTERN_NONE;
  369. value = (value << 8) | lane;
  370. }
  371. tegra_sor_writel(sor, value, SOR_DP_TPG);
  372. pattern = DP_TRAINING_PATTERN_DISABLE;
  373. err = drm_dp_aux_train(sor->aux, link, pattern);
  374. if (err < 0)
  375. return err;
  376. return 0;
  377. }
  378. static void tegra_sor_dp_term_calibrate(struct tegra_sor *sor)
  379. {
  380. u32 mask = 0x08, adj = 0, value;
  381. /* enable pad calibration logic */
  382. value = tegra_sor_readl(sor, SOR_DP_PADCTL0);
  383. value &= ~SOR_DP_PADCTL_PAD_CAL_PD;
  384. tegra_sor_writel(sor, value, SOR_DP_PADCTL0);
  385. value = tegra_sor_readl(sor, SOR_PLL1);
  386. value |= SOR_PLL1_TMDS_TERM;
  387. tegra_sor_writel(sor, value, SOR_PLL1);
  388. while (mask) {
  389. adj |= mask;
  390. value = tegra_sor_readl(sor, SOR_PLL1);
  391. value &= ~SOR_PLL1_TMDS_TERMADJ_MASK;
  392. value |= SOR_PLL1_TMDS_TERMADJ(adj);
  393. tegra_sor_writel(sor, value, SOR_PLL1);
  394. usleep_range(100, 200);
  395. value = tegra_sor_readl(sor, SOR_PLL1);
  396. if (value & SOR_PLL1_TERM_COMPOUT)
  397. adj &= ~mask;
  398. mask >>= 1;
  399. }
  400. value = tegra_sor_readl(sor, SOR_PLL1);
  401. value &= ~SOR_PLL1_TMDS_TERMADJ_MASK;
  402. value |= SOR_PLL1_TMDS_TERMADJ(adj);
  403. tegra_sor_writel(sor, value, SOR_PLL1);
  404. /* disable pad calibration logic */
  405. value = tegra_sor_readl(sor, SOR_DP_PADCTL0);
  406. value |= SOR_DP_PADCTL_PAD_CAL_PD;
  407. tegra_sor_writel(sor, value, SOR_DP_PADCTL0);
  408. }
  409. static void tegra_sor_super_update(struct tegra_sor *sor)
  410. {
  411. tegra_sor_writel(sor, 0, SOR_SUPER_STATE0);
  412. tegra_sor_writel(sor, 1, SOR_SUPER_STATE0);
  413. tegra_sor_writel(sor, 0, SOR_SUPER_STATE0);
  414. }
  415. static void tegra_sor_update(struct tegra_sor *sor)
  416. {
  417. tegra_sor_writel(sor, 0, SOR_STATE0);
  418. tegra_sor_writel(sor, 1, SOR_STATE0);
  419. tegra_sor_writel(sor, 0, SOR_STATE0);
  420. }
  421. static int tegra_sor_setup_pwm(struct tegra_sor *sor, unsigned long timeout)
  422. {
  423. u32 value;
  424. value = tegra_sor_readl(sor, SOR_PWM_DIV);
  425. value &= ~SOR_PWM_DIV_MASK;
  426. value |= 0x400; /* period */
  427. tegra_sor_writel(sor, value, SOR_PWM_DIV);
  428. value = tegra_sor_readl(sor, SOR_PWM_CTL);
  429. value &= ~SOR_PWM_CTL_DUTY_CYCLE_MASK;
  430. value |= 0x400; /* duty cycle */
  431. value &= ~SOR_PWM_CTL_CLK_SEL; /* clock source: PCLK */
  432. value |= SOR_PWM_CTL_TRIGGER;
  433. tegra_sor_writel(sor, value, SOR_PWM_CTL);
  434. timeout = jiffies + msecs_to_jiffies(timeout);
  435. while (time_before(jiffies, timeout)) {
  436. value = tegra_sor_readl(sor, SOR_PWM_CTL);
  437. if ((value & SOR_PWM_CTL_TRIGGER) == 0)
  438. return 0;
  439. usleep_range(25, 100);
  440. }
  441. return -ETIMEDOUT;
  442. }
  443. static int tegra_sor_attach(struct tegra_sor *sor)
  444. {
  445. unsigned long value, timeout;
  446. /* wake up in normal mode */
  447. value = tegra_sor_readl(sor, SOR_SUPER_STATE1);
  448. value |= SOR_SUPER_STATE_HEAD_MODE_AWAKE;
  449. value |= SOR_SUPER_STATE_MODE_NORMAL;
  450. tegra_sor_writel(sor, value, SOR_SUPER_STATE1);
  451. tegra_sor_super_update(sor);
  452. /* attach */
  453. value = tegra_sor_readl(sor, SOR_SUPER_STATE1);
  454. value |= SOR_SUPER_STATE_ATTACHED;
  455. tegra_sor_writel(sor, value, SOR_SUPER_STATE1);
  456. tegra_sor_super_update(sor);
  457. timeout = jiffies + msecs_to_jiffies(250);
  458. while (time_before(jiffies, timeout)) {
  459. value = tegra_sor_readl(sor, SOR_TEST);
  460. if ((value & SOR_TEST_ATTACHED) != 0)
  461. return 0;
  462. usleep_range(25, 100);
  463. }
  464. return -ETIMEDOUT;
  465. }
  466. static int tegra_sor_wakeup(struct tegra_sor *sor)
  467. {
  468. unsigned long value, timeout;
  469. timeout = jiffies + msecs_to_jiffies(250);
  470. /* wait for head to wake up */
  471. while (time_before(jiffies, timeout)) {
  472. value = tegra_sor_readl(sor, SOR_TEST);
  473. value &= SOR_TEST_HEAD_MODE_MASK;
  474. if (value == SOR_TEST_HEAD_MODE_AWAKE)
  475. return 0;
  476. usleep_range(25, 100);
  477. }
  478. return -ETIMEDOUT;
  479. }
  480. static int tegra_sor_power_up(struct tegra_sor *sor, unsigned long timeout)
  481. {
  482. u32 value;
  483. value = tegra_sor_readl(sor, SOR_PWR);
  484. value |= SOR_PWR_TRIGGER | SOR_PWR_NORMAL_STATE_PU;
  485. tegra_sor_writel(sor, value, SOR_PWR);
  486. timeout = jiffies + msecs_to_jiffies(timeout);
  487. while (time_before(jiffies, timeout)) {
  488. value = tegra_sor_readl(sor, SOR_PWR);
  489. if ((value & SOR_PWR_TRIGGER) == 0)
  490. return 0;
  491. usleep_range(25, 100);
  492. }
  493. return -ETIMEDOUT;
  494. }
  495. struct tegra_sor_params {
  496. /* number of link clocks per line */
  497. unsigned int num_clocks;
  498. /* ratio between input and output */
  499. u64 ratio;
  500. /* precision factor */
  501. u64 precision;
  502. unsigned int active_polarity;
  503. unsigned int active_count;
  504. unsigned int active_frac;
  505. unsigned int tu_size;
  506. unsigned int error;
  507. };
  508. static int tegra_sor_compute_params(struct tegra_sor *sor,
  509. struct tegra_sor_params *params,
  510. unsigned int tu_size)
  511. {
  512. u64 active_sym, active_count, frac, approx;
  513. u32 active_polarity, active_frac = 0;
  514. const u64 f = params->precision;
  515. s64 error;
  516. active_sym = params->ratio * tu_size;
  517. active_count = div_u64(active_sym, f) * f;
  518. frac = active_sym - active_count;
  519. /* fraction < 0.5 */
  520. if (frac >= (f / 2)) {
  521. active_polarity = 1;
  522. frac = f - frac;
  523. } else {
  524. active_polarity = 0;
  525. }
  526. if (frac != 0) {
  527. frac = div_u64(f * f, frac); /* 1/fraction */
  528. if (frac <= (15 * f)) {
  529. active_frac = div_u64(frac, f);
  530. /* round up */
  531. if (active_polarity)
  532. active_frac++;
  533. } else {
  534. active_frac = active_polarity ? 1 : 15;
  535. }
  536. }
  537. if (active_frac == 1)
  538. active_polarity = 0;
  539. if (active_polarity == 1) {
  540. if (active_frac) {
  541. approx = active_count + (active_frac * (f - 1)) * f;
  542. approx = div_u64(approx, active_frac * f);
  543. } else {
  544. approx = active_count + f;
  545. }
  546. } else {
  547. if (active_frac)
  548. approx = active_count + div_u64(f, active_frac);
  549. else
  550. approx = active_count;
  551. }
  552. error = div_s64(active_sym - approx, tu_size);
  553. error *= params->num_clocks;
  554. if (error <= 0 && abs(error) < params->error) {
  555. params->active_count = div_u64(active_count, f);
  556. params->active_polarity = active_polarity;
  557. params->active_frac = active_frac;
  558. params->error = abs(error);
  559. params->tu_size = tu_size;
  560. if (error == 0)
  561. return true;
  562. }
  563. return false;
  564. }
  565. static int tegra_sor_compute_config(struct tegra_sor *sor,
  566. const struct drm_display_mode *mode,
  567. struct tegra_sor_config *config,
  568. struct drm_dp_link *link)
  569. {
  570. const u64 f = 100000, link_rate = link->rate * 1000;
  571. const u64 pclk = mode->clock * 1000;
  572. u64 input, output, watermark, num;
  573. struct tegra_sor_params params;
  574. u32 num_syms_per_line;
  575. unsigned int i;
  576. if (!link_rate || !link->num_lanes || !pclk || !config->bits_per_pixel)
  577. return -EINVAL;
  578. output = link_rate * 8 * link->num_lanes;
  579. input = pclk * config->bits_per_pixel;
  580. if (input >= output)
  581. return -ERANGE;
  582. memset(&params, 0, sizeof(params));
  583. params.ratio = div64_u64(input * f, output);
  584. params.num_clocks = div_u64(link_rate * mode->hdisplay, pclk);
  585. params.precision = f;
  586. params.error = 64 * f;
  587. params.tu_size = 64;
  588. for (i = params.tu_size; i >= 32; i--)
  589. if (tegra_sor_compute_params(sor, &params, i))
  590. break;
  591. if (params.active_frac == 0) {
  592. config->active_polarity = 0;
  593. config->active_count = params.active_count;
  594. if (!params.active_polarity)
  595. config->active_count--;
  596. config->tu_size = params.tu_size;
  597. config->active_frac = 1;
  598. } else {
  599. config->active_polarity = params.active_polarity;
  600. config->active_count = params.active_count;
  601. config->active_frac = params.active_frac;
  602. config->tu_size = params.tu_size;
  603. }
  604. dev_dbg(sor->dev,
  605. "polarity: %d active count: %d tu size: %d active frac: %d\n",
  606. config->active_polarity, config->active_count,
  607. config->tu_size, config->active_frac);
  608. watermark = params.ratio * config->tu_size * (f - params.ratio);
  609. watermark = div_u64(watermark, f);
  610. watermark = div_u64(watermark + params.error, f);
  611. config->watermark = watermark + (config->bits_per_pixel / 8) + 2;
  612. num_syms_per_line = (mode->hdisplay * config->bits_per_pixel) *
  613. (link->num_lanes * 8);
  614. if (config->watermark > 30) {
  615. config->watermark = 30;
  616. dev_err(sor->dev,
  617. "unable to compute TU size, forcing watermark to %u\n",
  618. config->watermark);
  619. } else if (config->watermark > num_syms_per_line) {
  620. config->watermark = num_syms_per_line;
  621. dev_err(sor->dev, "watermark too high, forcing to %u\n",
  622. config->watermark);
  623. }
  624. /* compute the number of symbols per horizontal blanking interval */
  625. num = ((mode->htotal - mode->hdisplay) - 7) * link_rate;
  626. config->hblank_symbols = div_u64(num, pclk);
  627. if (link->capabilities & DP_LINK_CAP_ENHANCED_FRAMING)
  628. config->hblank_symbols -= 3;
  629. config->hblank_symbols -= 12 / link->num_lanes;
  630. /* compute the number of symbols per vertical blanking interval */
  631. num = (mode->hdisplay - 25) * link_rate;
  632. config->vblank_symbols = div_u64(num, pclk);
  633. config->vblank_symbols -= 36 / link->num_lanes + 4;
  634. dev_dbg(sor->dev, "blank symbols: H:%u V:%u\n", config->hblank_symbols,
  635. config->vblank_symbols);
  636. return 0;
  637. }
  638. static void tegra_sor_apply_config(struct tegra_sor *sor,
  639. const struct tegra_sor_config *config)
  640. {
  641. u32 value;
  642. value = tegra_sor_readl(sor, SOR_DP_LINKCTL0);
  643. value &= ~SOR_DP_LINKCTL_TU_SIZE_MASK;
  644. value |= SOR_DP_LINKCTL_TU_SIZE(config->tu_size);
  645. tegra_sor_writel(sor, value, SOR_DP_LINKCTL0);
  646. value = tegra_sor_readl(sor, SOR_DP_CONFIG0);
  647. value &= ~SOR_DP_CONFIG_WATERMARK_MASK;
  648. value |= SOR_DP_CONFIG_WATERMARK(config->watermark);
  649. value &= ~SOR_DP_CONFIG_ACTIVE_SYM_COUNT_MASK;
  650. value |= SOR_DP_CONFIG_ACTIVE_SYM_COUNT(config->active_count);
  651. value &= ~SOR_DP_CONFIG_ACTIVE_SYM_FRAC_MASK;
  652. value |= SOR_DP_CONFIG_ACTIVE_SYM_FRAC(config->active_frac);
  653. if (config->active_polarity)
  654. value |= SOR_DP_CONFIG_ACTIVE_SYM_POLARITY;
  655. else
  656. value &= ~SOR_DP_CONFIG_ACTIVE_SYM_POLARITY;
  657. value |= SOR_DP_CONFIG_ACTIVE_SYM_ENABLE;
  658. value |= SOR_DP_CONFIG_DISPARITY_NEGATIVE;
  659. tegra_sor_writel(sor, value, SOR_DP_CONFIG0);
  660. value = tegra_sor_readl(sor, SOR_DP_AUDIO_HBLANK_SYMBOLS);
  661. value &= ~SOR_DP_AUDIO_HBLANK_SYMBOLS_MASK;
  662. value |= config->hblank_symbols & 0xffff;
  663. tegra_sor_writel(sor, value, SOR_DP_AUDIO_HBLANK_SYMBOLS);
  664. value = tegra_sor_readl(sor, SOR_DP_AUDIO_VBLANK_SYMBOLS);
  665. value &= ~SOR_DP_AUDIO_VBLANK_SYMBOLS_MASK;
  666. value |= config->vblank_symbols & 0xffff;
  667. tegra_sor_writel(sor, value, SOR_DP_AUDIO_VBLANK_SYMBOLS);
  668. }
  669. static void tegra_sor_mode_set(struct tegra_sor *sor,
  670. const struct drm_display_mode *mode,
  671. struct tegra_sor_state *state)
  672. {
  673. struct tegra_dc *dc = to_tegra_dc(sor->output.encoder.crtc);
  674. unsigned int vbe, vse, hbe, hse, vbs, hbs;
  675. u32 value;
  676. value = tegra_sor_readl(sor, SOR_STATE1);
  677. value &= ~SOR_STATE_ASY_PIXELDEPTH_MASK;
  678. value &= ~SOR_STATE_ASY_CRC_MODE_MASK;
  679. value &= ~SOR_STATE_ASY_OWNER_MASK;
  680. value |= SOR_STATE_ASY_CRC_MODE_COMPLETE |
  681. SOR_STATE_ASY_OWNER(dc->pipe + 1);
  682. if (mode->flags & DRM_MODE_FLAG_PHSYNC)
  683. value &= ~SOR_STATE_ASY_HSYNCPOL;
  684. if (mode->flags & DRM_MODE_FLAG_NHSYNC)
  685. value |= SOR_STATE_ASY_HSYNCPOL;
  686. if (mode->flags & DRM_MODE_FLAG_PVSYNC)
  687. value &= ~SOR_STATE_ASY_VSYNCPOL;
  688. if (mode->flags & DRM_MODE_FLAG_NVSYNC)
  689. value |= SOR_STATE_ASY_VSYNCPOL;
  690. switch (state->bpc) {
  691. case 16:
  692. value |= SOR_STATE_ASY_PIXELDEPTH_BPP_48_444;
  693. break;
  694. case 12:
  695. value |= SOR_STATE_ASY_PIXELDEPTH_BPP_36_444;
  696. break;
  697. case 10:
  698. value |= SOR_STATE_ASY_PIXELDEPTH_BPP_30_444;
  699. break;
  700. case 8:
  701. value |= SOR_STATE_ASY_PIXELDEPTH_BPP_24_444;
  702. break;
  703. case 6:
  704. value |= SOR_STATE_ASY_PIXELDEPTH_BPP_18_444;
  705. break;
  706. default:
  707. value |= SOR_STATE_ASY_PIXELDEPTH_BPP_24_444;
  708. break;
  709. }
  710. tegra_sor_writel(sor, value, SOR_STATE1);
  711. /*
  712. * TODO: The video timing programming below doesn't seem to match the
  713. * register definitions.
  714. */
  715. value = ((mode->vtotal & 0x7fff) << 16) | (mode->htotal & 0x7fff);
  716. tegra_sor_writel(sor, value, SOR_HEAD_STATE1(dc->pipe));
  717. /* sync end = sync width - 1 */
  718. vse = mode->vsync_end - mode->vsync_start - 1;
  719. hse = mode->hsync_end - mode->hsync_start - 1;
  720. value = ((vse & 0x7fff) << 16) | (hse & 0x7fff);
  721. tegra_sor_writel(sor, value, SOR_HEAD_STATE2(dc->pipe));
  722. /* blank end = sync end + back porch */
  723. vbe = vse + (mode->vtotal - mode->vsync_end);
  724. hbe = hse + (mode->htotal - mode->hsync_end);
  725. value = ((vbe & 0x7fff) << 16) | (hbe & 0x7fff);
  726. tegra_sor_writel(sor, value, SOR_HEAD_STATE3(dc->pipe));
  727. /* blank start = blank end + active */
  728. vbs = vbe + mode->vdisplay;
  729. hbs = hbe + mode->hdisplay;
  730. value = ((vbs & 0x7fff) << 16) | (hbs & 0x7fff);
  731. tegra_sor_writel(sor, value, SOR_HEAD_STATE4(dc->pipe));
  732. /* XXX interlacing support */
  733. tegra_sor_writel(sor, 0x001, SOR_HEAD_STATE5(dc->pipe));
  734. }
  735. static int tegra_sor_detach(struct tegra_sor *sor)
  736. {
  737. unsigned long value, timeout;
  738. /* switch to safe mode */
  739. value = tegra_sor_readl(sor, SOR_SUPER_STATE1);
  740. value &= ~SOR_SUPER_STATE_MODE_NORMAL;
  741. tegra_sor_writel(sor, value, SOR_SUPER_STATE1);
  742. tegra_sor_super_update(sor);
  743. timeout = jiffies + msecs_to_jiffies(250);
  744. while (time_before(jiffies, timeout)) {
  745. value = tegra_sor_readl(sor, SOR_PWR);
  746. if (value & SOR_PWR_MODE_SAFE)
  747. break;
  748. }
  749. if ((value & SOR_PWR_MODE_SAFE) == 0)
  750. return -ETIMEDOUT;
  751. /* go to sleep */
  752. value = tegra_sor_readl(sor, SOR_SUPER_STATE1);
  753. value &= ~SOR_SUPER_STATE_HEAD_MODE_MASK;
  754. tegra_sor_writel(sor, value, SOR_SUPER_STATE1);
  755. tegra_sor_super_update(sor);
  756. /* detach */
  757. value = tegra_sor_readl(sor, SOR_SUPER_STATE1);
  758. value &= ~SOR_SUPER_STATE_ATTACHED;
  759. tegra_sor_writel(sor, value, SOR_SUPER_STATE1);
  760. tegra_sor_super_update(sor);
  761. timeout = jiffies + msecs_to_jiffies(250);
  762. while (time_before(jiffies, timeout)) {
  763. value = tegra_sor_readl(sor, SOR_TEST);
  764. if ((value & SOR_TEST_ATTACHED) == 0)
  765. break;
  766. usleep_range(25, 100);
  767. }
  768. if ((value & SOR_TEST_ATTACHED) != 0)
  769. return -ETIMEDOUT;
  770. return 0;
  771. }
  772. static int tegra_sor_power_down(struct tegra_sor *sor)
  773. {
  774. unsigned long value, timeout;
  775. int err;
  776. value = tegra_sor_readl(sor, SOR_PWR);
  777. value &= ~SOR_PWR_NORMAL_STATE_PU;
  778. value |= SOR_PWR_TRIGGER;
  779. tegra_sor_writel(sor, value, SOR_PWR);
  780. timeout = jiffies + msecs_to_jiffies(250);
  781. while (time_before(jiffies, timeout)) {
  782. value = tegra_sor_readl(sor, SOR_PWR);
  783. if ((value & SOR_PWR_TRIGGER) == 0)
  784. return 0;
  785. usleep_range(25, 100);
  786. }
  787. if ((value & SOR_PWR_TRIGGER) != 0)
  788. return -ETIMEDOUT;
  789. /* switch to safe parent clock */
  790. err = tegra_sor_set_parent_clock(sor, sor->clk_safe);
  791. if (err < 0)
  792. dev_err(sor->dev, "failed to set safe parent clock: %d\n", err);
  793. value = tegra_sor_readl(sor, SOR_DP_PADCTL0);
  794. value &= ~(SOR_DP_PADCTL_PD_TXD_3 | SOR_DP_PADCTL_PD_TXD_0 |
  795. SOR_DP_PADCTL_PD_TXD_1 | SOR_DP_PADCTL_PD_TXD_2);
  796. tegra_sor_writel(sor, value, SOR_DP_PADCTL0);
  797. /* stop lane sequencer */
  798. value = SOR_LANE_SEQ_CTL_TRIGGER | SOR_LANE_SEQ_CTL_SEQUENCE_UP |
  799. SOR_LANE_SEQ_CTL_POWER_STATE_DOWN;
  800. tegra_sor_writel(sor, value, SOR_LANE_SEQ_CTL);
  801. timeout = jiffies + msecs_to_jiffies(250);
  802. while (time_before(jiffies, timeout)) {
  803. value = tegra_sor_readl(sor, SOR_LANE_SEQ_CTL);
  804. if ((value & SOR_LANE_SEQ_CTL_TRIGGER) == 0)
  805. break;
  806. usleep_range(25, 100);
  807. }
  808. if ((value & SOR_LANE_SEQ_CTL_TRIGGER) != 0)
  809. return -ETIMEDOUT;
  810. value = tegra_sor_readl(sor, SOR_PLL2);
  811. value |= SOR_PLL2_PORT_POWERDOWN;
  812. tegra_sor_writel(sor, value, SOR_PLL2);
  813. usleep_range(20, 100);
  814. value = tegra_sor_readl(sor, SOR_PLL0);
  815. value |= SOR_PLL0_VCOPD | SOR_PLL0_PWR;
  816. tegra_sor_writel(sor, value, SOR_PLL0);
  817. value = tegra_sor_readl(sor, SOR_PLL2);
  818. value |= SOR_PLL2_SEQ_PLLCAPPD;
  819. value |= SOR_PLL2_SEQ_PLLCAPPD_ENFORCE;
  820. tegra_sor_writel(sor, value, SOR_PLL2);
  821. usleep_range(20, 100);
  822. return 0;
  823. }
  824. static int tegra_sor_crc_wait(struct tegra_sor *sor, unsigned long timeout)
  825. {
  826. u32 value;
  827. timeout = jiffies + msecs_to_jiffies(timeout);
  828. while (time_before(jiffies, timeout)) {
  829. value = tegra_sor_readl(sor, SOR_CRCA);
  830. if (value & SOR_CRCA_VALID)
  831. return 0;
  832. usleep_range(100, 200);
  833. }
  834. return -ETIMEDOUT;
  835. }
  836. static int tegra_sor_show_crc(struct seq_file *s, void *data)
  837. {
  838. struct drm_info_node *node = s->private;
  839. struct tegra_sor *sor = node->info_ent->data;
  840. struct drm_crtc *crtc = sor->output.encoder.crtc;
  841. struct drm_device *drm = node->minor->dev;
  842. int err = 0;
  843. u32 value;
  844. drm_modeset_lock_all(drm);
  845. if (!crtc || !crtc->state->active) {
  846. err = -EBUSY;
  847. goto unlock;
  848. }
  849. value = tegra_sor_readl(sor, SOR_STATE1);
  850. value &= ~SOR_STATE_ASY_CRC_MODE_MASK;
  851. tegra_sor_writel(sor, value, SOR_STATE1);
  852. value = tegra_sor_readl(sor, SOR_CRC_CNTRL);
  853. value |= SOR_CRC_CNTRL_ENABLE;
  854. tegra_sor_writel(sor, value, SOR_CRC_CNTRL);
  855. value = tegra_sor_readl(sor, SOR_TEST);
  856. value &= ~SOR_TEST_CRC_POST_SERIALIZE;
  857. tegra_sor_writel(sor, value, SOR_TEST);
  858. err = tegra_sor_crc_wait(sor, 100);
  859. if (err < 0)
  860. goto unlock;
  861. tegra_sor_writel(sor, SOR_CRCA_RESET, SOR_CRCA);
  862. value = tegra_sor_readl(sor, SOR_CRCB);
  863. seq_printf(s, "%08x\n", value);
  864. unlock:
  865. drm_modeset_unlock_all(drm);
  866. return err;
  867. }
  868. static int tegra_sor_show_regs(struct seq_file *s, void *data)
  869. {
  870. struct drm_info_node *node = s->private;
  871. struct tegra_sor *sor = node->info_ent->data;
  872. struct drm_crtc *crtc = sor->output.encoder.crtc;
  873. struct drm_device *drm = node->minor->dev;
  874. int err = 0;
  875. drm_modeset_lock_all(drm);
  876. if (!crtc || !crtc->state->active) {
  877. err = -EBUSY;
  878. goto unlock;
  879. }
  880. #define DUMP_REG(name) \
  881. seq_printf(s, "%-38s %#05x %08x\n", #name, name, \
  882. tegra_sor_readl(sor, name))
  883. DUMP_REG(SOR_CTXSW);
  884. DUMP_REG(SOR_SUPER_STATE0);
  885. DUMP_REG(SOR_SUPER_STATE1);
  886. DUMP_REG(SOR_STATE0);
  887. DUMP_REG(SOR_STATE1);
  888. DUMP_REG(SOR_HEAD_STATE0(0));
  889. DUMP_REG(SOR_HEAD_STATE0(1));
  890. DUMP_REG(SOR_HEAD_STATE1(0));
  891. DUMP_REG(SOR_HEAD_STATE1(1));
  892. DUMP_REG(SOR_HEAD_STATE2(0));
  893. DUMP_REG(SOR_HEAD_STATE2(1));
  894. DUMP_REG(SOR_HEAD_STATE3(0));
  895. DUMP_REG(SOR_HEAD_STATE3(1));
  896. DUMP_REG(SOR_HEAD_STATE4(0));
  897. DUMP_REG(SOR_HEAD_STATE4(1));
  898. DUMP_REG(SOR_HEAD_STATE5(0));
  899. DUMP_REG(SOR_HEAD_STATE5(1));
  900. DUMP_REG(SOR_CRC_CNTRL);
  901. DUMP_REG(SOR_DP_DEBUG_MVID);
  902. DUMP_REG(SOR_CLK_CNTRL);
  903. DUMP_REG(SOR_CAP);
  904. DUMP_REG(SOR_PWR);
  905. DUMP_REG(SOR_TEST);
  906. DUMP_REG(SOR_PLL0);
  907. DUMP_REG(SOR_PLL1);
  908. DUMP_REG(SOR_PLL2);
  909. DUMP_REG(SOR_PLL3);
  910. DUMP_REG(SOR_CSTM);
  911. DUMP_REG(SOR_LVDS);
  912. DUMP_REG(SOR_CRCA);
  913. DUMP_REG(SOR_CRCB);
  914. DUMP_REG(SOR_BLANK);
  915. DUMP_REG(SOR_SEQ_CTL);
  916. DUMP_REG(SOR_LANE_SEQ_CTL);
  917. DUMP_REG(SOR_SEQ_INST(0));
  918. DUMP_REG(SOR_SEQ_INST(1));
  919. DUMP_REG(SOR_SEQ_INST(2));
  920. DUMP_REG(SOR_SEQ_INST(3));
  921. DUMP_REG(SOR_SEQ_INST(4));
  922. DUMP_REG(SOR_SEQ_INST(5));
  923. DUMP_REG(SOR_SEQ_INST(6));
  924. DUMP_REG(SOR_SEQ_INST(7));
  925. DUMP_REG(SOR_SEQ_INST(8));
  926. DUMP_REG(SOR_SEQ_INST(9));
  927. DUMP_REG(SOR_SEQ_INST(10));
  928. DUMP_REG(SOR_SEQ_INST(11));
  929. DUMP_REG(SOR_SEQ_INST(12));
  930. DUMP_REG(SOR_SEQ_INST(13));
  931. DUMP_REG(SOR_SEQ_INST(14));
  932. DUMP_REG(SOR_SEQ_INST(15));
  933. DUMP_REG(SOR_PWM_DIV);
  934. DUMP_REG(SOR_PWM_CTL);
  935. DUMP_REG(SOR_VCRC_A0);
  936. DUMP_REG(SOR_VCRC_A1);
  937. DUMP_REG(SOR_VCRC_B0);
  938. DUMP_REG(SOR_VCRC_B1);
  939. DUMP_REG(SOR_CCRC_A0);
  940. DUMP_REG(SOR_CCRC_A1);
  941. DUMP_REG(SOR_CCRC_B0);
  942. DUMP_REG(SOR_CCRC_B1);
  943. DUMP_REG(SOR_EDATA_A0);
  944. DUMP_REG(SOR_EDATA_A1);
  945. DUMP_REG(SOR_EDATA_B0);
  946. DUMP_REG(SOR_EDATA_B1);
  947. DUMP_REG(SOR_COUNT_A0);
  948. DUMP_REG(SOR_COUNT_A1);
  949. DUMP_REG(SOR_COUNT_B0);
  950. DUMP_REG(SOR_COUNT_B1);
  951. DUMP_REG(SOR_DEBUG_A0);
  952. DUMP_REG(SOR_DEBUG_A1);
  953. DUMP_REG(SOR_DEBUG_B0);
  954. DUMP_REG(SOR_DEBUG_B1);
  955. DUMP_REG(SOR_TRIG);
  956. DUMP_REG(SOR_MSCHECK);
  957. DUMP_REG(SOR_XBAR_CTRL);
  958. DUMP_REG(SOR_XBAR_POL);
  959. DUMP_REG(SOR_DP_LINKCTL0);
  960. DUMP_REG(SOR_DP_LINKCTL1);
  961. DUMP_REG(SOR_LANE_DRIVE_CURRENT0);
  962. DUMP_REG(SOR_LANE_DRIVE_CURRENT1);
  963. DUMP_REG(SOR_LANE4_DRIVE_CURRENT0);
  964. DUMP_REG(SOR_LANE4_DRIVE_CURRENT1);
  965. DUMP_REG(SOR_LANE_PREEMPHASIS0);
  966. DUMP_REG(SOR_LANE_PREEMPHASIS1);
  967. DUMP_REG(SOR_LANE4_PREEMPHASIS0);
  968. DUMP_REG(SOR_LANE4_PREEMPHASIS1);
  969. DUMP_REG(SOR_LANE_POSTCURSOR0);
  970. DUMP_REG(SOR_LANE_POSTCURSOR1);
  971. DUMP_REG(SOR_DP_CONFIG0);
  972. DUMP_REG(SOR_DP_CONFIG1);
  973. DUMP_REG(SOR_DP_MN0);
  974. DUMP_REG(SOR_DP_MN1);
  975. DUMP_REG(SOR_DP_PADCTL0);
  976. DUMP_REG(SOR_DP_PADCTL1);
  977. DUMP_REG(SOR_DP_DEBUG0);
  978. DUMP_REG(SOR_DP_DEBUG1);
  979. DUMP_REG(SOR_DP_SPARE0);
  980. DUMP_REG(SOR_DP_SPARE1);
  981. DUMP_REG(SOR_DP_AUDIO_CTRL);
  982. DUMP_REG(SOR_DP_AUDIO_HBLANK_SYMBOLS);
  983. DUMP_REG(SOR_DP_AUDIO_VBLANK_SYMBOLS);
  984. DUMP_REG(SOR_DP_GENERIC_INFOFRAME_HEADER);
  985. DUMP_REG(SOR_DP_GENERIC_INFOFRAME_SUBPACK0);
  986. DUMP_REG(SOR_DP_GENERIC_INFOFRAME_SUBPACK1);
  987. DUMP_REG(SOR_DP_GENERIC_INFOFRAME_SUBPACK2);
  988. DUMP_REG(SOR_DP_GENERIC_INFOFRAME_SUBPACK3);
  989. DUMP_REG(SOR_DP_GENERIC_INFOFRAME_SUBPACK4);
  990. DUMP_REG(SOR_DP_GENERIC_INFOFRAME_SUBPACK5);
  991. DUMP_REG(SOR_DP_GENERIC_INFOFRAME_SUBPACK6);
  992. DUMP_REG(SOR_DP_TPG);
  993. DUMP_REG(SOR_DP_TPG_CONFIG);
  994. DUMP_REG(SOR_DP_LQ_CSTM0);
  995. DUMP_REG(SOR_DP_LQ_CSTM1);
  996. DUMP_REG(SOR_DP_LQ_CSTM2);
  997. #undef DUMP_REG
  998. unlock:
  999. drm_modeset_unlock_all(drm);
  1000. return err;
  1001. }
  1002. static const struct drm_info_list debugfs_files[] = {
  1003. { "crc", tegra_sor_show_crc, 0, NULL },
  1004. { "regs", tegra_sor_show_regs, 0, NULL },
  1005. };
  1006. static int tegra_sor_debugfs_init(struct tegra_sor *sor,
  1007. struct drm_minor *minor)
  1008. {
  1009. const char *name = sor->soc->supports_dp ? "sor1" : "sor";
  1010. unsigned int i;
  1011. int err;
  1012. sor->debugfs = debugfs_create_dir(name, minor->debugfs_root);
  1013. if (!sor->debugfs)
  1014. return -ENOMEM;
  1015. sor->debugfs_files = kmemdup(debugfs_files, sizeof(debugfs_files),
  1016. GFP_KERNEL);
  1017. if (!sor->debugfs_files) {
  1018. err = -ENOMEM;
  1019. goto remove;
  1020. }
  1021. for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
  1022. sor->debugfs_files[i].data = sor;
  1023. err = drm_debugfs_create_files(sor->debugfs_files,
  1024. ARRAY_SIZE(debugfs_files),
  1025. sor->debugfs, minor);
  1026. if (err < 0)
  1027. goto free;
  1028. sor->minor = minor;
  1029. return 0;
  1030. free:
  1031. kfree(sor->debugfs_files);
  1032. sor->debugfs_files = NULL;
  1033. remove:
  1034. debugfs_remove_recursive(sor->debugfs);
  1035. sor->debugfs = NULL;
  1036. return err;
  1037. }
  1038. static void tegra_sor_debugfs_exit(struct tegra_sor *sor)
  1039. {
  1040. drm_debugfs_remove_files(sor->debugfs_files, ARRAY_SIZE(debugfs_files),
  1041. sor->minor);
  1042. sor->minor = NULL;
  1043. kfree(sor->debugfs_files);
  1044. sor->debugfs_files = NULL;
  1045. debugfs_remove_recursive(sor->debugfs);
  1046. sor->debugfs = NULL;
  1047. }
  1048. static void tegra_sor_connector_reset(struct drm_connector *connector)
  1049. {
  1050. struct tegra_sor_state *state;
  1051. state = kzalloc(sizeof(*state), GFP_KERNEL);
  1052. if (!state)
  1053. return;
  1054. if (connector->state) {
  1055. __drm_atomic_helper_connector_destroy_state(connector->state);
  1056. kfree(connector->state);
  1057. }
  1058. __drm_atomic_helper_connector_reset(connector, &state->base);
  1059. }
  1060. static enum drm_connector_status
  1061. tegra_sor_connector_detect(struct drm_connector *connector, bool force)
  1062. {
  1063. struct tegra_output *output = connector_to_output(connector);
  1064. struct tegra_sor *sor = to_sor(output);
  1065. if (sor->aux)
  1066. return drm_dp_aux_detect(sor->aux);
  1067. return tegra_output_connector_detect(connector, force);
  1068. }
  1069. static struct drm_connector_state *
  1070. tegra_sor_connector_duplicate_state(struct drm_connector *connector)
  1071. {
  1072. struct tegra_sor_state *state = to_sor_state(connector->state);
  1073. struct tegra_sor_state *copy;
  1074. copy = kmemdup(state, sizeof(*state), GFP_KERNEL);
  1075. if (!copy)
  1076. return NULL;
  1077. __drm_atomic_helper_connector_duplicate_state(connector, &copy->base);
  1078. return &copy->base;
  1079. }
  1080. static const struct drm_connector_funcs tegra_sor_connector_funcs = {
  1081. .dpms = drm_atomic_helper_connector_dpms,
  1082. .reset = tegra_sor_connector_reset,
  1083. .detect = tegra_sor_connector_detect,
  1084. .fill_modes = drm_helper_probe_single_connector_modes,
  1085. .destroy = tegra_output_connector_destroy,
  1086. .atomic_duplicate_state = tegra_sor_connector_duplicate_state,
  1087. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  1088. };
  1089. static int tegra_sor_connector_get_modes(struct drm_connector *connector)
  1090. {
  1091. struct tegra_output *output = connector_to_output(connector);
  1092. struct tegra_sor *sor = to_sor(output);
  1093. int err;
  1094. if (sor->aux)
  1095. drm_dp_aux_enable(sor->aux);
  1096. err = tegra_output_connector_get_modes(connector);
  1097. if (sor->aux)
  1098. drm_dp_aux_disable(sor->aux);
  1099. return err;
  1100. }
  1101. static enum drm_mode_status
  1102. tegra_sor_connector_mode_valid(struct drm_connector *connector,
  1103. struct drm_display_mode *mode)
  1104. {
  1105. /* HDMI 2.0 modes are not yet supported */
  1106. if (mode->clock > 340000)
  1107. return MODE_NOCLOCK;
  1108. return MODE_OK;
  1109. }
  1110. static const struct drm_connector_helper_funcs tegra_sor_connector_helper_funcs = {
  1111. .get_modes = tegra_sor_connector_get_modes,
  1112. .mode_valid = tegra_sor_connector_mode_valid,
  1113. };
  1114. static const struct drm_encoder_funcs tegra_sor_encoder_funcs = {
  1115. .destroy = tegra_output_encoder_destroy,
  1116. };
  1117. static void tegra_sor_edp_disable(struct drm_encoder *encoder)
  1118. {
  1119. struct tegra_output *output = encoder_to_output(encoder);
  1120. struct tegra_dc *dc = to_tegra_dc(encoder->crtc);
  1121. struct tegra_sor *sor = to_sor(output);
  1122. u32 value;
  1123. int err;
  1124. if (output->panel)
  1125. drm_panel_disable(output->panel);
  1126. err = tegra_sor_detach(sor);
  1127. if (err < 0)
  1128. dev_err(sor->dev, "failed to detach SOR: %d\n", err);
  1129. tegra_sor_writel(sor, 0, SOR_STATE1);
  1130. tegra_sor_update(sor);
  1131. /*
  1132. * The following accesses registers of the display controller, so make
  1133. * sure it's only executed when the output is attached to one.
  1134. */
  1135. if (dc) {
  1136. value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
  1137. value &= ~SOR_ENABLE;
  1138. tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
  1139. tegra_dc_commit(dc);
  1140. }
  1141. err = tegra_sor_power_down(sor);
  1142. if (err < 0)
  1143. dev_err(sor->dev, "failed to power down SOR: %d\n", err);
  1144. if (sor->aux) {
  1145. err = drm_dp_aux_disable(sor->aux);
  1146. if (err < 0)
  1147. dev_err(sor->dev, "failed to disable DP: %d\n", err);
  1148. }
  1149. err = tegra_io_rail_power_off(TEGRA_IO_RAIL_LVDS);
  1150. if (err < 0)
  1151. dev_err(sor->dev, "failed to power off I/O rail: %d\n", err);
  1152. if (output->panel)
  1153. drm_panel_unprepare(output->panel);
  1154. pm_runtime_put(sor->dev);
  1155. }
  1156. #if 0
  1157. static int calc_h_ref_to_sync(const struct drm_display_mode *mode,
  1158. unsigned int *value)
  1159. {
  1160. unsigned int hfp, hsw, hbp, a = 0, b;
  1161. hfp = mode->hsync_start - mode->hdisplay;
  1162. hsw = mode->hsync_end - mode->hsync_start;
  1163. hbp = mode->htotal - mode->hsync_end;
  1164. pr_info("hfp: %u, hsw: %u, hbp: %u\n", hfp, hsw, hbp);
  1165. b = hfp - 1;
  1166. pr_info("a: %u, b: %u\n", a, b);
  1167. pr_info("a + hsw + hbp = %u\n", a + hsw + hbp);
  1168. if (a + hsw + hbp <= 11) {
  1169. a = 1 + 11 - hsw - hbp;
  1170. pr_info("a: %u\n", a);
  1171. }
  1172. if (a > b)
  1173. return -EINVAL;
  1174. if (hsw < 1)
  1175. return -EINVAL;
  1176. if (mode->hdisplay < 16)
  1177. return -EINVAL;
  1178. if (value) {
  1179. if (b > a && a % 2)
  1180. *value = a + 1;
  1181. else
  1182. *value = a;
  1183. }
  1184. return 0;
  1185. }
  1186. #endif
  1187. static void tegra_sor_edp_enable(struct drm_encoder *encoder)
  1188. {
  1189. struct drm_display_mode *mode = &encoder->crtc->state->adjusted_mode;
  1190. struct tegra_output *output = encoder_to_output(encoder);
  1191. struct tegra_dc *dc = to_tegra_dc(encoder->crtc);
  1192. struct tegra_sor *sor = to_sor(output);
  1193. struct tegra_sor_config config;
  1194. struct tegra_sor_state *state;
  1195. struct drm_dp_link link;
  1196. u8 rate, lanes;
  1197. unsigned int i;
  1198. int err = 0;
  1199. u32 value;
  1200. state = to_sor_state(output->connector.state);
  1201. pm_runtime_get_sync(sor->dev);
  1202. if (output->panel)
  1203. drm_panel_prepare(output->panel);
  1204. err = drm_dp_aux_enable(sor->aux);
  1205. if (err < 0)
  1206. dev_err(sor->dev, "failed to enable DP: %d\n", err);
  1207. err = drm_dp_link_probe(sor->aux, &link);
  1208. if (err < 0) {
  1209. dev_err(sor->dev, "failed to probe eDP link: %d\n", err);
  1210. return;
  1211. }
  1212. /* switch to safe parent clock */
  1213. err = tegra_sor_set_parent_clock(sor, sor->clk_safe);
  1214. if (err < 0)
  1215. dev_err(sor->dev, "failed to set safe parent clock: %d\n", err);
  1216. memset(&config, 0, sizeof(config));
  1217. config.bits_per_pixel = state->bpc * 3;
  1218. err = tegra_sor_compute_config(sor, mode, &config, &link);
  1219. if (err < 0)
  1220. dev_err(sor->dev, "failed to compute configuration: %d\n", err);
  1221. value = tegra_sor_readl(sor, SOR_CLK_CNTRL);
  1222. value &= ~SOR_CLK_CNTRL_DP_CLK_SEL_MASK;
  1223. value |= SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_DPCLK;
  1224. tegra_sor_writel(sor, value, SOR_CLK_CNTRL);
  1225. value = tegra_sor_readl(sor, SOR_PLL2);
  1226. value &= ~SOR_PLL2_BANDGAP_POWERDOWN;
  1227. tegra_sor_writel(sor, value, SOR_PLL2);
  1228. usleep_range(20, 100);
  1229. value = tegra_sor_readl(sor, SOR_PLL3);
  1230. value |= SOR_PLL3_PLL_VDD_MODE_3V3;
  1231. tegra_sor_writel(sor, value, SOR_PLL3);
  1232. value = SOR_PLL0_ICHPMP(0xf) | SOR_PLL0_VCOCAP_RST |
  1233. SOR_PLL0_PLLREG_LEVEL_V45 | SOR_PLL0_RESISTOR_EXT;
  1234. tegra_sor_writel(sor, value, SOR_PLL0);
  1235. value = tegra_sor_readl(sor, SOR_PLL2);
  1236. value |= SOR_PLL2_SEQ_PLLCAPPD;
  1237. value &= ~SOR_PLL2_SEQ_PLLCAPPD_ENFORCE;
  1238. value |= SOR_PLL2_LVDS_ENABLE;
  1239. tegra_sor_writel(sor, value, SOR_PLL2);
  1240. value = SOR_PLL1_TERM_COMPOUT | SOR_PLL1_TMDS_TERM;
  1241. tegra_sor_writel(sor, value, SOR_PLL1);
  1242. while (true) {
  1243. value = tegra_sor_readl(sor, SOR_PLL2);
  1244. if ((value & SOR_PLL2_SEQ_PLLCAPPD_ENFORCE) == 0)
  1245. break;
  1246. usleep_range(250, 1000);
  1247. }
  1248. value = tegra_sor_readl(sor, SOR_PLL2);
  1249. value &= ~SOR_PLL2_POWERDOWN_OVERRIDE;
  1250. value &= ~SOR_PLL2_PORT_POWERDOWN;
  1251. tegra_sor_writel(sor, value, SOR_PLL2);
  1252. /*
  1253. * power up
  1254. */
  1255. /* set safe link bandwidth (1.62 Gbps) */
  1256. value = tegra_sor_readl(sor, SOR_CLK_CNTRL);
  1257. value &= ~SOR_CLK_CNTRL_DP_LINK_SPEED_MASK;
  1258. value |= SOR_CLK_CNTRL_DP_LINK_SPEED_G1_62;
  1259. tegra_sor_writel(sor, value, SOR_CLK_CNTRL);
  1260. /* step 1 */
  1261. value = tegra_sor_readl(sor, SOR_PLL2);
  1262. value |= SOR_PLL2_SEQ_PLLCAPPD_ENFORCE | SOR_PLL2_PORT_POWERDOWN |
  1263. SOR_PLL2_BANDGAP_POWERDOWN;
  1264. tegra_sor_writel(sor, value, SOR_PLL2);
  1265. value = tegra_sor_readl(sor, SOR_PLL0);
  1266. value |= SOR_PLL0_VCOPD | SOR_PLL0_PWR;
  1267. tegra_sor_writel(sor, value, SOR_PLL0);
  1268. value = tegra_sor_readl(sor, SOR_DP_PADCTL0);
  1269. value &= ~SOR_DP_PADCTL_PAD_CAL_PD;
  1270. tegra_sor_writel(sor, value, SOR_DP_PADCTL0);
  1271. /* step 2 */
  1272. err = tegra_io_rail_power_on(TEGRA_IO_RAIL_LVDS);
  1273. if (err < 0)
  1274. dev_err(sor->dev, "failed to power on I/O rail: %d\n", err);
  1275. usleep_range(5, 100);
  1276. /* step 3 */
  1277. value = tegra_sor_readl(sor, SOR_PLL2);
  1278. value &= ~SOR_PLL2_BANDGAP_POWERDOWN;
  1279. tegra_sor_writel(sor, value, SOR_PLL2);
  1280. usleep_range(20, 100);
  1281. /* step 4 */
  1282. value = tegra_sor_readl(sor, SOR_PLL0);
  1283. value &= ~SOR_PLL0_VCOPD;
  1284. value &= ~SOR_PLL0_PWR;
  1285. tegra_sor_writel(sor, value, SOR_PLL0);
  1286. value = tegra_sor_readl(sor, SOR_PLL2);
  1287. value &= ~SOR_PLL2_SEQ_PLLCAPPD_ENFORCE;
  1288. tegra_sor_writel(sor, value, SOR_PLL2);
  1289. usleep_range(200, 1000);
  1290. /* step 5 */
  1291. value = tegra_sor_readl(sor, SOR_PLL2);
  1292. value &= ~SOR_PLL2_PORT_POWERDOWN;
  1293. tegra_sor_writel(sor, value, SOR_PLL2);
  1294. /* XXX not in TRM */
  1295. for (value = 0, i = 0; i < 5; i++)
  1296. value |= SOR_XBAR_CTRL_LINK0_XSEL(i, sor->soc->xbar_cfg[i]) |
  1297. SOR_XBAR_CTRL_LINK1_XSEL(i, i);
  1298. tegra_sor_writel(sor, 0x00000000, SOR_XBAR_POL);
  1299. tegra_sor_writel(sor, value, SOR_XBAR_CTRL);
  1300. /* switch to DP parent clock */
  1301. err = tegra_sor_set_parent_clock(sor, sor->clk_dp);
  1302. if (err < 0)
  1303. dev_err(sor->dev, "failed to set parent clock: %d\n", err);
  1304. /* power DP lanes */
  1305. value = tegra_sor_readl(sor, SOR_DP_PADCTL0);
  1306. if (link.num_lanes <= 2)
  1307. value &= ~(SOR_DP_PADCTL_PD_TXD_3 | SOR_DP_PADCTL_PD_TXD_2);
  1308. else
  1309. value |= SOR_DP_PADCTL_PD_TXD_3 | SOR_DP_PADCTL_PD_TXD_2;
  1310. if (link.num_lanes <= 1)
  1311. value &= ~SOR_DP_PADCTL_PD_TXD_1;
  1312. else
  1313. value |= SOR_DP_PADCTL_PD_TXD_1;
  1314. if (link.num_lanes == 0)
  1315. value &= ~SOR_DP_PADCTL_PD_TXD_0;
  1316. else
  1317. value |= SOR_DP_PADCTL_PD_TXD_0;
  1318. tegra_sor_writel(sor, value, SOR_DP_PADCTL0);
  1319. value = tegra_sor_readl(sor, SOR_DP_LINKCTL0);
  1320. value &= ~SOR_DP_LINKCTL_LANE_COUNT_MASK;
  1321. value |= SOR_DP_LINKCTL_LANE_COUNT(link.num_lanes);
  1322. tegra_sor_writel(sor, value, SOR_DP_LINKCTL0);
  1323. /* start lane sequencer */
  1324. value = SOR_LANE_SEQ_CTL_TRIGGER | SOR_LANE_SEQ_CTL_SEQUENCE_DOWN |
  1325. SOR_LANE_SEQ_CTL_POWER_STATE_UP;
  1326. tegra_sor_writel(sor, value, SOR_LANE_SEQ_CTL);
  1327. while (true) {
  1328. value = tegra_sor_readl(sor, SOR_LANE_SEQ_CTL);
  1329. if ((value & SOR_LANE_SEQ_CTL_TRIGGER) == 0)
  1330. break;
  1331. usleep_range(250, 1000);
  1332. }
  1333. /* set link bandwidth */
  1334. value = tegra_sor_readl(sor, SOR_CLK_CNTRL);
  1335. value &= ~SOR_CLK_CNTRL_DP_LINK_SPEED_MASK;
  1336. value |= drm_dp_link_rate_to_bw_code(link.rate) << 2;
  1337. tegra_sor_writel(sor, value, SOR_CLK_CNTRL);
  1338. tegra_sor_apply_config(sor, &config);
  1339. /* enable link */
  1340. value = tegra_sor_readl(sor, SOR_DP_LINKCTL0);
  1341. value |= SOR_DP_LINKCTL_ENABLE;
  1342. value |= SOR_DP_LINKCTL_ENHANCED_FRAME;
  1343. tegra_sor_writel(sor, value, SOR_DP_LINKCTL0);
  1344. for (i = 0, value = 0; i < 4; i++) {
  1345. unsigned long lane = SOR_DP_TPG_CHANNEL_CODING |
  1346. SOR_DP_TPG_SCRAMBLER_GALIOS |
  1347. SOR_DP_TPG_PATTERN_NONE;
  1348. value = (value << 8) | lane;
  1349. }
  1350. tegra_sor_writel(sor, value, SOR_DP_TPG);
  1351. /* enable pad calibration logic */
  1352. value = tegra_sor_readl(sor, SOR_DP_PADCTL0);
  1353. value |= SOR_DP_PADCTL_PAD_CAL_PD;
  1354. tegra_sor_writel(sor, value, SOR_DP_PADCTL0);
  1355. err = drm_dp_link_probe(sor->aux, &link);
  1356. if (err < 0)
  1357. dev_err(sor->dev, "failed to probe eDP link: %d\n", err);
  1358. err = drm_dp_link_power_up(sor->aux, &link);
  1359. if (err < 0)
  1360. dev_err(sor->dev, "failed to power up eDP link: %d\n", err);
  1361. err = drm_dp_link_configure(sor->aux, &link);
  1362. if (err < 0)
  1363. dev_err(sor->dev, "failed to configure eDP link: %d\n", err);
  1364. rate = drm_dp_link_rate_to_bw_code(link.rate);
  1365. lanes = link.num_lanes;
  1366. value = tegra_sor_readl(sor, SOR_CLK_CNTRL);
  1367. value &= ~SOR_CLK_CNTRL_DP_LINK_SPEED_MASK;
  1368. value |= SOR_CLK_CNTRL_DP_LINK_SPEED(rate);
  1369. tegra_sor_writel(sor, value, SOR_CLK_CNTRL);
  1370. value = tegra_sor_readl(sor, SOR_DP_LINKCTL0);
  1371. value &= ~SOR_DP_LINKCTL_LANE_COUNT_MASK;
  1372. value |= SOR_DP_LINKCTL_LANE_COUNT(lanes);
  1373. if (link.capabilities & DP_LINK_CAP_ENHANCED_FRAMING)
  1374. value |= SOR_DP_LINKCTL_ENHANCED_FRAME;
  1375. tegra_sor_writel(sor, value, SOR_DP_LINKCTL0);
  1376. /* disable training pattern generator */
  1377. for (i = 0; i < link.num_lanes; i++) {
  1378. unsigned long lane = SOR_DP_TPG_CHANNEL_CODING |
  1379. SOR_DP_TPG_SCRAMBLER_GALIOS |
  1380. SOR_DP_TPG_PATTERN_NONE;
  1381. value = (value << 8) | lane;
  1382. }
  1383. tegra_sor_writel(sor, value, SOR_DP_TPG);
  1384. err = tegra_sor_dp_train_fast(sor, &link);
  1385. if (err < 0)
  1386. dev_err(sor->dev, "DP fast link training failed: %d\n", err);
  1387. dev_dbg(sor->dev, "fast link training succeeded\n");
  1388. err = tegra_sor_power_up(sor, 250);
  1389. if (err < 0)
  1390. dev_err(sor->dev, "failed to power up SOR: %d\n", err);
  1391. /* CSTM (LVDS, link A/B, upper) */
  1392. value = SOR_CSTM_LVDS | SOR_CSTM_LINK_ACT_A | SOR_CSTM_LINK_ACT_B |
  1393. SOR_CSTM_UPPER;
  1394. tegra_sor_writel(sor, value, SOR_CSTM);
  1395. /* use DP-A protocol */
  1396. value = tegra_sor_readl(sor, SOR_STATE1);
  1397. value &= ~SOR_STATE_ASY_PROTOCOL_MASK;
  1398. value |= SOR_STATE_ASY_PROTOCOL_DP_A;
  1399. tegra_sor_writel(sor, value, SOR_STATE1);
  1400. tegra_sor_mode_set(sor, mode, state);
  1401. /* PWM setup */
  1402. err = tegra_sor_setup_pwm(sor, 250);
  1403. if (err < 0)
  1404. dev_err(sor->dev, "failed to setup PWM: %d\n", err);
  1405. tegra_sor_update(sor);
  1406. value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
  1407. value |= SOR_ENABLE;
  1408. tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
  1409. tegra_dc_commit(dc);
  1410. err = tegra_sor_attach(sor);
  1411. if (err < 0)
  1412. dev_err(sor->dev, "failed to attach SOR: %d\n", err);
  1413. err = tegra_sor_wakeup(sor);
  1414. if (err < 0)
  1415. dev_err(sor->dev, "failed to enable DC: %d\n", err);
  1416. if (output->panel)
  1417. drm_panel_enable(output->panel);
  1418. }
  1419. static int
  1420. tegra_sor_encoder_atomic_check(struct drm_encoder *encoder,
  1421. struct drm_crtc_state *crtc_state,
  1422. struct drm_connector_state *conn_state)
  1423. {
  1424. struct tegra_output *output = encoder_to_output(encoder);
  1425. struct tegra_sor_state *state = to_sor_state(conn_state);
  1426. struct tegra_dc *dc = to_tegra_dc(conn_state->crtc);
  1427. unsigned long pclk = crtc_state->mode.clock * 1000;
  1428. struct tegra_sor *sor = to_sor(output);
  1429. struct drm_display_info *info;
  1430. int err;
  1431. info = &output->connector.display_info;
  1432. err = tegra_dc_state_setup_clock(dc, crtc_state, sor->clk_parent,
  1433. pclk, 0);
  1434. if (err < 0) {
  1435. dev_err(output->dev, "failed to setup CRTC state: %d\n", err);
  1436. return err;
  1437. }
  1438. switch (info->bpc) {
  1439. case 8:
  1440. case 6:
  1441. state->bpc = info->bpc;
  1442. break;
  1443. default:
  1444. DRM_DEBUG_KMS("%u bits-per-color not supported\n", info->bpc);
  1445. state->bpc = 8;
  1446. break;
  1447. }
  1448. return 0;
  1449. }
  1450. static const struct drm_encoder_helper_funcs tegra_sor_edp_helpers = {
  1451. .disable = tegra_sor_edp_disable,
  1452. .enable = tegra_sor_edp_enable,
  1453. .atomic_check = tegra_sor_encoder_atomic_check,
  1454. };
  1455. static inline u32 tegra_sor_hdmi_subpack(const u8 *ptr, size_t size)
  1456. {
  1457. u32 value = 0;
  1458. size_t i;
  1459. for (i = size; i > 0; i--)
  1460. value = (value << 8) | ptr[i - 1];
  1461. return value;
  1462. }
  1463. static void tegra_sor_hdmi_write_infopack(struct tegra_sor *sor,
  1464. const void *data, size_t size)
  1465. {
  1466. const u8 *ptr = data;
  1467. unsigned long offset;
  1468. size_t i, j;
  1469. u32 value;
  1470. switch (ptr[0]) {
  1471. case HDMI_INFOFRAME_TYPE_AVI:
  1472. offset = SOR_HDMI_AVI_INFOFRAME_HEADER;
  1473. break;
  1474. case HDMI_INFOFRAME_TYPE_AUDIO:
  1475. offset = SOR_HDMI_AUDIO_INFOFRAME_HEADER;
  1476. break;
  1477. case HDMI_INFOFRAME_TYPE_VENDOR:
  1478. offset = SOR_HDMI_VSI_INFOFRAME_HEADER;
  1479. break;
  1480. default:
  1481. dev_err(sor->dev, "unsupported infoframe type: %02x\n",
  1482. ptr[0]);
  1483. return;
  1484. }
  1485. value = INFOFRAME_HEADER_TYPE(ptr[0]) |
  1486. INFOFRAME_HEADER_VERSION(ptr[1]) |
  1487. INFOFRAME_HEADER_LEN(ptr[2]);
  1488. tegra_sor_writel(sor, value, offset);
  1489. offset++;
  1490. /*
  1491. * Each subpack contains 7 bytes, divided into:
  1492. * - subpack_low: bytes 0 - 3
  1493. * - subpack_high: bytes 4 - 6 (with byte 7 padded to 0x00)
  1494. */
  1495. for (i = 3, j = 0; i < size; i += 7, j += 8) {
  1496. size_t rem = size - i, num = min_t(size_t, rem, 4);
  1497. value = tegra_sor_hdmi_subpack(&ptr[i], num);
  1498. tegra_sor_writel(sor, value, offset++);
  1499. num = min_t(size_t, rem - num, 3);
  1500. value = tegra_sor_hdmi_subpack(&ptr[i + 4], num);
  1501. tegra_sor_writel(sor, value, offset++);
  1502. }
  1503. }
  1504. static int
  1505. tegra_sor_hdmi_setup_avi_infoframe(struct tegra_sor *sor,
  1506. const struct drm_display_mode *mode)
  1507. {
  1508. u8 buffer[HDMI_INFOFRAME_SIZE(AVI)];
  1509. struct hdmi_avi_infoframe frame;
  1510. u32 value;
  1511. int err;
  1512. /* disable AVI infoframe */
  1513. value = tegra_sor_readl(sor, SOR_HDMI_AVI_INFOFRAME_CTRL);
  1514. value &= ~INFOFRAME_CTRL_SINGLE;
  1515. value &= ~INFOFRAME_CTRL_OTHER;
  1516. value &= ~INFOFRAME_CTRL_ENABLE;
  1517. tegra_sor_writel(sor, value, SOR_HDMI_AVI_INFOFRAME_CTRL);
  1518. err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode);
  1519. if (err < 0) {
  1520. dev_err(sor->dev, "failed to setup AVI infoframe: %d\n", err);
  1521. return err;
  1522. }
  1523. err = hdmi_avi_infoframe_pack(&frame, buffer, sizeof(buffer));
  1524. if (err < 0) {
  1525. dev_err(sor->dev, "failed to pack AVI infoframe: %d\n", err);
  1526. return err;
  1527. }
  1528. tegra_sor_hdmi_write_infopack(sor, buffer, err);
  1529. /* enable AVI infoframe */
  1530. value = tegra_sor_readl(sor, SOR_HDMI_AVI_INFOFRAME_CTRL);
  1531. value |= INFOFRAME_CTRL_CHECKSUM_ENABLE;
  1532. value |= INFOFRAME_CTRL_ENABLE;
  1533. tegra_sor_writel(sor, value, SOR_HDMI_AVI_INFOFRAME_CTRL);
  1534. return 0;
  1535. }
  1536. static void tegra_sor_hdmi_disable_audio_infoframe(struct tegra_sor *sor)
  1537. {
  1538. u32 value;
  1539. value = tegra_sor_readl(sor, SOR_HDMI_AUDIO_INFOFRAME_CTRL);
  1540. value &= ~INFOFRAME_CTRL_ENABLE;
  1541. tegra_sor_writel(sor, value, SOR_HDMI_AUDIO_INFOFRAME_CTRL);
  1542. }
  1543. static struct tegra_sor_hdmi_settings *
  1544. tegra_sor_hdmi_find_settings(struct tegra_sor *sor, unsigned long frequency)
  1545. {
  1546. unsigned int i;
  1547. for (i = 0; i < sor->num_settings; i++)
  1548. if (frequency <= sor->settings[i].frequency)
  1549. return &sor->settings[i];
  1550. return NULL;
  1551. }
  1552. static void tegra_sor_hdmi_disable(struct drm_encoder *encoder)
  1553. {
  1554. struct tegra_output *output = encoder_to_output(encoder);
  1555. struct tegra_dc *dc = to_tegra_dc(encoder->crtc);
  1556. struct tegra_sor *sor = to_sor(output);
  1557. u32 value;
  1558. int err;
  1559. err = tegra_sor_detach(sor);
  1560. if (err < 0)
  1561. dev_err(sor->dev, "failed to detach SOR: %d\n", err);
  1562. tegra_sor_writel(sor, 0, SOR_STATE1);
  1563. tegra_sor_update(sor);
  1564. /* disable display to SOR clock */
  1565. value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
  1566. value &= ~SOR1_TIMING_CYA;
  1567. value &= ~SOR1_ENABLE;
  1568. tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
  1569. tegra_dc_commit(dc);
  1570. err = tegra_sor_power_down(sor);
  1571. if (err < 0)
  1572. dev_err(sor->dev, "failed to power down SOR: %d\n", err);
  1573. err = tegra_io_rail_power_off(TEGRA_IO_RAIL_HDMI);
  1574. if (err < 0)
  1575. dev_err(sor->dev, "failed to power off HDMI rail: %d\n", err);
  1576. pm_runtime_put(sor->dev);
  1577. }
  1578. static void tegra_sor_hdmi_enable(struct drm_encoder *encoder)
  1579. {
  1580. struct tegra_output *output = encoder_to_output(encoder);
  1581. unsigned int h_ref_to_sync = 1, pulse_start, max_ac;
  1582. struct tegra_dc *dc = to_tegra_dc(encoder->crtc);
  1583. struct tegra_sor_hdmi_settings *settings;
  1584. struct tegra_sor *sor = to_sor(output);
  1585. struct tegra_sor_state *state;
  1586. struct drm_display_mode *mode;
  1587. unsigned int div, i;
  1588. u32 value;
  1589. int err;
  1590. state = to_sor_state(output->connector.state);
  1591. mode = &encoder->crtc->state->adjusted_mode;
  1592. pm_runtime_get_sync(sor->dev);
  1593. /* switch to safe parent clock */
  1594. err = tegra_sor_set_parent_clock(sor, sor->clk_safe);
  1595. if (err < 0)
  1596. dev_err(sor->dev, "failed to set safe parent clock: %d\n", err);
  1597. div = clk_get_rate(sor->clk) / 1000000 * 4;
  1598. err = tegra_io_rail_power_on(TEGRA_IO_RAIL_HDMI);
  1599. if (err < 0)
  1600. dev_err(sor->dev, "failed to power on HDMI rail: %d\n", err);
  1601. usleep_range(20, 100);
  1602. value = tegra_sor_readl(sor, SOR_PLL2);
  1603. value &= ~SOR_PLL2_BANDGAP_POWERDOWN;
  1604. tegra_sor_writel(sor, value, SOR_PLL2);
  1605. usleep_range(20, 100);
  1606. value = tegra_sor_readl(sor, SOR_PLL3);
  1607. value &= ~SOR_PLL3_PLL_VDD_MODE_3V3;
  1608. tegra_sor_writel(sor, value, SOR_PLL3);
  1609. value = tegra_sor_readl(sor, SOR_PLL0);
  1610. value &= ~SOR_PLL0_VCOPD;
  1611. value &= ~SOR_PLL0_PWR;
  1612. tegra_sor_writel(sor, value, SOR_PLL0);
  1613. value = tegra_sor_readl(sor, SOR_PLL2);
  1614. value &= ~SOR_PLL2_SEQ_PLLCAPPD_ENFORCE;
  1615. tegra_sor_writel(sor, value, SOR_PLL2);
  1616. usleep_range(200, 400);
  1617. value = tegra_sor_readl(sor, SOR_PLL2);
  1618. value &= ~SOR_PLL2_POWERDOWN_OVERRIDE;
  1619. value &= ~SOR_PLL2_PORT_POWERDOWN;
  1620. tegra_sor_writel(sor, value, SOR_PLL2);
  1621. usleep_range(20, 100);
  1622. value = tegra_sor_readl(sor, SOR_DP_PADCTL0);
  1623. value |= SOR_DP_PADCTL_PD_TXD_3 | SOR_DP_PADCTL_PD_TXD_0 |
  1624. SOR_DP_PADCTL_PD_TXD_1 | SOR_DP_PADCTL_PD_TXD_2;
  1625. tegra_sor_writel(sor, value, SOR_DP_PADCTL0);
  1626. while (true) {
  1627. value = tegra_sor_readl(sor, SOR_LANE_SEQ_CTL);
  1628. if ((value & SOR_LANE_SEQ_CTL_STATE_BUSY) == 0)
  1629. break;
  1630. usleep_range(250, 1000);
  1631. }
  1632. value = SOR_LANE_SEQ_CTL_TRIGGER | SOR_LANE_SEQ_CTL_SEQUENCE_DOWN |
  1633. SOR_LANE_SEQ_CTL_POWER_STATE_UP | SOR_LANE_SEQ_CTL_DELAY(5);
  1634. tegra_sor_writel(sor, value, SOR_LANE_SEQ_CTL);
  1635. while (true) {
  1636. value = tegra_sor_readl(sor, SOR_LANE_SEQ_CTL);
  1637. if ((value & SOR_LANE_SEQ_CTL_TRIGGER) == 0)
  1638. break;
  1639. usleep_range(250, 1000);
  1640. }
  1641. value = tegra_sor_readl(sor, SOR_CLK_CNTRL);
  1642. value &= ~SOR_CLK_CNTRL_DP_LINK_SPEED_MASK;
  1643. value &= ~SOR_CLK_CNTRL_DP_CLK_SEL_MASK;
  1644. if (mode->clock < 340000)
  1645. value |= SOR_CLK_CNTRL_DP_LINK_SPEED_G2_70;
  1646. else
  1647. value |= SOR_CLK_CNTRL_DP_LINK_SPEED_G5_40;
  1648. value |= SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_PCLK;
  1649. tegra_sor_writel(sor, value, SOR_CLK_CNTRL);
  1650. value = tegra_sor_readl(sor, SOR_DP_SPARE0);
  1651. value |= SOR_DP_SPARE_DISP_VIDEO_PREAMBLE;
  1652. value &= ~SOR_DP_SPARE_PANEL_INTERNAL;
  1653. value |= SOR_DP_SPARE_SEQ_ENABLE;
  1654. tegra_sor_writel(sor, value, SOR_DP_SPARE0);
  1655. value = SOR_SEQ_CTL_PU_PC(0) | SOR_SEQ_CTL_PU_PC_ALT(0) |
  1656. SOR_SEQ_CTL_PD_PC(8) | SOR_SEQ_CTL_PD_PC_ALT(8);
  1657. tegra_sor_writel(sor, value, SOR_SEQ_CTL);
  1658. value = SOR_SEQ_INST_DRIVE_PWM_OUT_LO | SOR_SEQ_INST_HALT |
  1659. SOR_SEQ_INST_WAIT_VSYNC | SOR_SEQ_INST_WAIT(1);
  1660. tegra_sor_writel(sor, value, SOR_SEQ_INST(0));
  1661. tegra_sor_writel(sor, value, SOR_SEQ_INST(8));
  1662. /* program the reference clock */
  1663. value = SOR_REFCLK_DIV_INT(div) | SOR_REFCLK_DIV_FRAC(div);
  1664. tegra_sor_writel(sor, value, SOR_REFCLK);
  1665. /* XXX not in TRM */
  1666. for (value = 0, i = 0; i < 5; i++)
  1667. value |= SOR_XBAR_CTRL_LINK0_XSEL(i, sor->soc->xbar_cfg[i]) |
  1668. SOR_XBAR_CTRL_LINK1_XSEL(i, i);
  1669. tegra_sor_writel(sor, 0x00000000, SOR_XBAR_POL);
  1670. tegra_sor_writel(sor, value, SOR_XBAR_CTRL);
  1671. /* switch to parent clock */
  1672. err = clk_set_parent(sor->clk_src, sor->clk_parent);
  1673. if (err < 0)
  1674. dev_err(sor->dev, "failed to set source clock: %d\n", err);
  1675. err = tegra_sor_set_parent_clock(sor, sor->clk_src);
  1676. if (err < 0)
  1677. dev_err(sor->dev, "failed to set parent clock: %d\n", err);
  1678. value = SOR_INPUT_CONTROL_HDMI_SRC_SELECT(dc->pipe);
  1679. /* XXX is this the proper check? */
  1680. if (mode->clock < 75000)
  1681. value |= SOR_INPUT_CONTROL_ARM_VIDEO_RANGE_LIMITED;
  1682. tegra_sor_writel(sor, value, SOR_INPUT_CONTROL);
  1683. max_ac = ((mode->htotal - mode->hdisplay) - SOR_REKEY - 18) / 32;
  1684. value = SOR_HDMI_CTRL_ENABLE | SOR_HDMI_CTRL_MAX_AC_PACKET(max_ac) |
  1685. SOR_HDMI_CTRL_AUDIO_LAYOUT | SOR_HDMI_CTRL_REKEY(SOR_REKEY);
  1686. tegra_sor_writel(sor, value, SOR_HDMI_CTRL);
  1687. /* H_PULSE2 setup */
  1688. pulse_start = h_ref_to_sync + (mode->hsync_end - mode->hsync_start) +
  1689. (mode->htotal - mode->hsync_end) - 10;
  1690. value = PULSE_LAST_END_A | PULSE_QUAL_VACTIVE |
  1691. PULSE_POLARITY_HIGH | PULSE_MODE_NORMAL;
  1692. tegra_dc_writel(dc, value, DC_DISP_H_PULSE2_CONTROL);
  1693. value = PULSE_END(pulse_start + 8) | PULSE_START(pulse_start);
  1694. tegra_dc_writel(dc, value, DC_DISP_H_PULSE2_POSITION_A);
  1695. value = tegra_dc_readl(dc, DC_DISP_DISP_SIGNAL_OPTIONS0);
  1696. value |= H_PULSE2_ENABLE;
  1697. tegra_dc_writel(dc, value, DC_DISP_DISP_SIGNAL_OPTIONS0);
  1698. /* infoframe setup */
  1699. err = tegra_sor_hdmi_setup_avi_infoframe(sor, mode);
  1700. if (err < 0)
  1701. dev_err(sor->dev, "failed to setup AVI infoframe: %d\n", err);
  1702. /* XXX HDMI audio support not implemented yet */
  1703. tegra_sor_hdmi_disable_audio_infoframe(sor);
  1704. /* use single TMDS protocol */
  1705. value = tegra_sor_readl(sor, SOR_STATE1);
  1706. value &= ~SOR_STATE_ASY_PROTOCOL_MASK;
  1707. value |= SOR_STATE_ASY_PROTOCOL_SINGLE_TMDS_A;
  1708. tegra_sor_writel(sor, value, SOR_STATE1);
  1709. /* power up pad calibration */
  1710. value = tegra_sor_readl(sor, SOR_DP_PADCTL0);
  1711. value &= ~SOR_DP_PADCTL_PAD_CAL_PD;
  1712. tegra_sor_writel(sor, value, SOR_DP_PADCTL0);
  1713. /* production settings */
  1714. settings = tegra_sor_hdmi_find_settings(sor, mode->clock * 1000);
  1715. if (!settings) {
  1716. dev_err(sor->dev, "no settings for pixel clock %d Hz\n",
  1717. mode->clock * 1000);
  1718. return;
  1719. }
  1720. value = tegra_sor_readl(sor, SOR_PLL0);
  1721. value &= ~SOR_PLL0_ICHPMP_MASK;
  1722. value &= ~SOR_PLL0_VCOCAP_MASK;
  1723. value |= SOR_PLL0_ICHPMP(settings->ichpmp);
  1724. value |= SOR_PLL0_VCOCAP(settings->vcocap);
  1725. tegra_sor_writel(sor, value, SOR_PLL0);
  1726. tegra_sor_dp_term_calibrate(sor);
  1727. value = tegra_sor_readl(sor, SOR_PLL1);
  1728. value &= ~SOR_PLL1_LOADADJ_MASK;
  1729. value |= SOR_PLL1_LOADADJ(settings->loadadj);
  1730. tegra_sor_writel(sor, value, SOR_PLL1);
  1731. value = tegra_sor_readl(sor, SOR_PLL3);
  1732. value &= ~SOR_PLL3_BG_VREF_LEVEL_MASK;
  1733. value |= SOR_PLL3_BG_VREF_LEVEL(settings->bg_vref);
  1734. tegra_sor_writel(sor, value, SOR_PLL3);
  1735. value = settings->drive_current[0] << 24 |
  1736. settings->drive_current[1] << 16 |
  1737. settings->drive_current[2] << 8 |
  1738. settings->drive_current[3] << 0;
  1739. tegra_sor_writel(sor, value, SOR_LANE_DRIVE_CURRENT0);
  1740. value = settings->preemphasis[0] << 24 |
  1741. settings->preemphasis[1] << 16 |
  1742. settings->preemphasis[2] << 8 |
  1743. settings->preemphasis[3] << 0;
  1744. tegra_sor_writel(sor, value, SOR_LANE_PREEMPHASIS0);
  1745. value = tegra_sor_readl(sor, SOR_DP_PADCTL0);
  1746. value &= ~SOR_DP_PADCTL_TX_PU_MASK;
  1747. value |= SOR_DP_PADCTL_TX_PU_ENABLE;
  1748. value |= SOR_DP_PADCTL_TX_PU(settings->tx_pu);
  1749. tegra_sor_writel(sor, value, SOR_DP_PADCTL0);
  1750. /* power down pad calibration */
  1751. value = tegra_sor_readl(sor, SOR_DP_PADCTL0);
  1752. value |= SOR_DP_PADCTL_PAD_CAL_PD;
  1753. tegra_sor_writel(sor, value, SOR_DP_PADCTL0);
  1754. /* miscellaneous display controller settings */
  1755. value = VSYNC_H_POSITION(1);
  1756. tegra_dc_writel(dc, value, DC_DISP_DISP_TIMING_OPTIONS);
  1757. value = tegra_dc_readl(dc, DC_DISP_DISP_COLOR_CONTROL);
  1758. value &= ~DITHER_CONTROL_MASK;
  1759. value &= ~BASE_COLOR_SIZE_MASK;
  1760. switch (state->bpc) {
  1761. case 6:
  1762. value |= BASE_COLOR_SIZE_666;
  1763. break;
  1764. case 8:
  1765. value |= BASE_COLOR_SIZE_888;
  1766. break;
  1767. default:
  1768. WARN(1, "%u bits-per-color not supported\n", state->bpc);
  1769. value |= BASE_COLOR_SIZE_888;
  1770. break;
  1771. }
  1772. tegra_dc_writel(dc, value, DC_DISP_DISP_COLOR_CONTROL);
  1773. err = tegra_sor_power_up(sor, 250);
  1774. if (err < 0)
  1775. dev_err(sor->dev, "failed to power up SOR: %d\n", err);
  1776. /* configure dynamic range of output */
  1777. value = tegra_sor_readl(sor, SOR_HEAD_STATE0(dc->pipe));
  1778. value &= ~SOR_HEAD_STATE_RANGECOMPRESS_MASK;
  1779. value &= ~SOR_HEAD_STATE_DYNRANGE_MASK;
  1780. tegra_sor_writel(sor, value, SOR_HEAD_STATE0(dc->pipe));
  1781. /* configure colorspace */
  1782. value = tegra_sor_readl(sor, SOR_HEAD_STATE0(dc->pipe));
  1783. value &= ~SOR_HEAD_STATE_COLORSPACE_MASK;
  1784. value |= SOR_HEAD_STATE_COLORSPACE_RGB;
  1785. tegra_sor_writel(sor, value, SOR_HEAD_STATE0(dc->pipe));
  1786. tegra_sor_mode_set(sor, mode, state);
  1787. tegra_sor_update(sor);
  1788. err = tegra_sor_attach(sor);
  1789. if (err < 0)
  1790. dev_err(sor->dev, "failed to attach SOR: %d\n", err);
  1791. /* enable display to SOR clock and generate HDMI preamble */
  1792. value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
  1793. value |= SOR1_ENABLE | SOR1_TIMING_CYA;
  1794. tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
  1795. tegra_dc_commit(dc);
  1796. err = tegra_sor_wakeup(sor);
  1797. if (err < 0)
  1798. dev_err(sor->dev, "failed to wakeup SOR: %d\n", err);
  1799. }
  1800. static const struct drm_encoder_helper_funcs tegra_sor_hdmi_helpers = {
  1801. .disable = tegra_sor_hdmi_disable,
  1802. .enable = tegra_sor_hdmi_enable,
  1803. .atomic_check = tegra_sor_encoder_atomic_check,
  1804. };
  1805. static int tegra_sor_init(struct host1x_client *client)
  1806. {
  1807. struct drm_device *drm = dev_get_drvdata(client->parent);
  1808. const struct drm_encoder_helper_funcs *helpers = NULL;
  1809. struct tegra_sor *sor = host1x_client_to_sor(client);
  1810. int connector = DRM_MODE_CONNECTOR_Unknown;
  1811. int encoder = DRM_MODE_ENCODER_NONE;
  1812. int err;
  1813. if (!sor->aux) {
  1814. if (sor->soc->supports_hdmi) {
  1815. connector = DRM_MODE_CONNECTOR_HDMIA;
  1816. encoder = DRM_MODE_ENCODER_TMDS;
  1817. helpers = &tegra_sor_hdmi_helpers;
  1818. } else if (sor->soc->supports_lvds) {
  1819. connector = DRM_MODE_CONNECTOR_LVDS;
  1820. encoder = DRM_MODE_ENCODER_LVDS;
  1821. }
  1822. } else {
  1823. if (sor->soc->supports_edp) {
  1824. connector = DRM_MODE_CONNECTOR_eDP;
  1825. encoder = DRM_MODE_ENCODER_TMDS;
  1826. helpers = &tegra_sor_edp_helpers;
  1827. } else if (sor->soc->supports_dp) {
  1828. connector = DRM_MODE_CONNECTOR_DisplayPort;
  1829. encoder = DRM_MODE_ENCODER_TMDS;
  1830. }
  1831. }
  1832. sor->output.dev = sor->dev;
  1833. drm_connector_init(drm, &sor->output.connector,
  1834. &tegra_sor_connector_funcs,
  1835. connector);
  1836. drm_connector_helper_add(&sor->output.connector,
  1837. &tegra_sor_connector_helper_funcs);
  1838. sor->output.connector.dpms = DRM_MODE_DPMS_OFF;
  1839. drm_encoder_init(drm, &sor->output.encoder, &tegra_sor_encoder_funcs,
  1840. encoder, NULL);
  1841. drm_encoder_helper_add(&sor->output.encoder, helpers);
  1842. drm_mode_connector_attach_encoder(&sor->output.connector,
  1843. &sor->output.encoder);
  1844. drm_connector_register(&sor->output.connector);
  1845. err = tegra_output_init(drm, &sor->output);
  1846. if (err < 0) {
  1847. dev_err(client->dev, "failed to initialize output: %d\n", err);
  1848. return err;
  1849. }
  1850. sor->output.encoder.possible_crtcs = 0x3;
  1851. if (IS_ENABLED(CONFIG_DEBUG_FS)) {
  1852. err = tegra_sor_debugfs_init(sor, drm->primary);
  1853. if (err < 0)
  1854. dev_err(sor->dev, "debugfs setup failed: %d\n", err);
  1855. }
  1856. if (sor->aux) {
  1857. err = drm_dp_aux_attach(sor->aux, &sor->output);
  1858. if (err < 0) {
  1859. dev_err(sor->dev, "failed to attach DP: %d\n", err);
  1860. return err;
  1861. }
  1862. }
  1863. /*
  1864. * XXX: Remove this reset once proper hand-over from firmware to
  1865. * kernel is possible.
  1866. */
  1867. if (sor->rst) {
  1868. err = reset_control_assert(sor->rst);
  1869. if (err < 0) {
  1870. dev_err(sor->dev, "failed to assert SOR reset: %d\n",
  1871. err);
  1872. return err;
  1873. }
  1874. }
  1875. err = clk_prepare_enable(sor->clk);
  1876. if (err < 0) {
  1877. dev_err(sor->dev, "failed to enable clock: %d\n", err);
  1878. return err;
  1879. }
  1880. usleep_range(1000, 3000);
  1881. if (sor->rst) {
  1882. err = reset_control_deassert(sor->rst);
  1883. if (err < 0) {
  1884. dev_err(sor->dev, "failed to deassert SOR reset: %d\n",
  1885. err);
  1886. return err;
  1887. }
  1888. }
  1889. err = clk_prepare_enable(sor->clk_safe);
  1890. if (err < 0)
  1891. return err;
  1892. err = clk_prepare_enable(sor->clk_dp);
  1893. if (err < 0)
  1894. return err;
  1895. return 0;
  1896. }
  1897. static int tegra_sor_exit(struct host1x_client *client)
  1898. {
  1899. struct tegra_sor *sor = host1x_client_to_sor(client);
  1900. int err;
  1901. tegra_output_exit(&sor->output);
  1902. if (sor->aux) {
  1903. err = drm_dp_aux_detach(sor->aux);
  1904. if (err < 0) {
  1905. dev_err(sor->dev, "failed to detach DP: %d\n", err);
  1906. return err;
  1907. }
  1908. }
  1909. clk_disable_unprepare(sor->clk_safe);
  1910. clk_disable_unprepare(sor->clk_dp);
  1911. clk_disable_unprepare(sor->clk);
  1912. if (IS_ENABLED(CONFIG_DEBUG_FS))
  1913. tegra_sor_debugfs_exit(sor);
  1914. return 0;
  1915. }
  1916. static const struct host1x_client_ops sor_client_ops = {
  1917. .init = tegra_sor_init,
  1918. .exit = tegra_sor_exit,
  1919. };
  1920. static const struct tegra_sor_ops tegra_sor_edp_ops = {
  1921. .name = "eDP",
  1922. };
  1923. static int tegra_sor_hdmi_probe(struct tegra_sor *sor)
  1924. {
  1925. int err;
  1926. sor->avdd_io_supply = devm_regulator_get(sor->dev, "avdd-io");
  1927. if (IS_ERR(sor->avdd_io_supply)) {
  1928. dev_err(sor->dev, "cannot get AVDD I/O supply: %ld\n",
  1929. PTR_ERR(sor->avdd_io_supply));
  1930. return PTR_ERR(sor->avdd_io_supply);
  1931. }
  1932. err = regulator_enable(sor->avdd_io_supply);
  1933. if (err < 0) {
  1934. dev_err(sor->dev, "failed to enable AVDD I/O supply: %d\n",
  1935. err);
  1936. return err;
  1937. }
  1938. sor->vdd_pll_supply = devm_regulator_get(sor->dev, "vdd-pll");
  1939. if (IS_ERR(sor->vdd_pll_supply)) {
  1940. dev_err(sor->dev, "cannot get VDD PLL supply: %ld\n",
  1941. PTR_ERR(sor->vdd_pll_supply));
  1942. return PTR_ERR(sor->vdd_pll_supply);
  1943. }
  1944. err = regulator_enable(sor->vdd_pll_supply);
  1945. if (err < 0) {
  1946. dev_err(sor->dev, "failed to enable VDD PLL supply: %d\n",
  1947. err);
  1948. return err;
  1949. }
  1950. sor->hdmi_supply = devm_regulator_get(sor->dev, "hdmi");
  1951. if (IS_ERR(sor->hdmi_supply)) {
  1952. dev_err(sor->dev, "cannot get HDMI supply: %ld\n",
  1953. PTR_ERR(sor->hdmi_supply));
  1954. return PTR_ERR(sor->hdmi_supply);
  1955. }
  1956. err = regulator_enable(sor->hdmi_supply);
  1957. if (err < 0) {
  1958. dev_err(sor->dev, "failed to enable HDMI supply: %d\n", err);
  1959. return err;
  1960. }
  1961. return 0;
  1962. }
  1963. static int tegra_sor_hdmi_remove(struct tegra_sor *sor)
  1964. {
  1965. regulator_disable(sor->hdmi_supply);
  1966. regulator_disable(sor->vdd_pll_supply);
  1967. regulator_disable(sor->avdd_io_supply);
  1968. return 0;
  1969. }
  1970. static const struct tegra_sor_ops tegra_sor_hdmi_ops = {
  1971. .name = "HDMI",
  1972. .probe = tegra_sor_hdmi_probe,
  1973. .remove = tegra_sor_hdmi_remove,
  1974. };
  1975. static const u8 tegra124_sor_xbar_cfg[5] = {
  1976. 0, 1, 2, 3, 4
  1977. };
  1978. static const struct tegra_sor_soc tegra124_sor = {
  1979. .supports_edp = true,
  1980. .supports_lvds = true,
  1981. .supports_hdmi = false,
  1982. .supports_dp = false,
  1983. .xbar_cfg = tegra124_sor_xbar_cfg,
  1984. };
  1985. static const struct tegra_sor_soc tegra210_sor = {
  1986. .supports_edp = true,
  1987. .supports_lvds = false,
  1988. .supports_hdmi = false,
  1989. .supports_dp = false,
  1990. .xbar_cfg = tegra124_sor_xbar_cfg,
  1991. };
  1992. static const u8 tegra210_sor_xbar_cfg[5] = {
  1993. 2, 1, 0, 3, 4
  1994. };
  1995. static const struct tegra_sor_soc tegra210_sor1 = {
  1996. .supports_edp = false,
  1997. .supports_lvds = false,
  1998. .supports_hdmi = true,
  1999. .supports_dp = true,
  2000. .num_settings = ARRAY_SIZE(tegra210_sor_hdmi_defaults),
  2001. .settings = tegra210_sor_hdmi_defaults,
  2002. .xbar_cfg = tegra210_sor_xbar_cfg,
  2003. };
  2004. static const struct of_device_id tegra_sor_of_match[] = {
  2005. { .compatible = "nvidia,tegra210-sor1", .data = &tegra210_sor1 },
  2006. { .compatible = "nvidia,tegra210-sor", .data = &tegra210_sor },
  2007. { .compatible = "nvidia,tegra124-sor", .data = &tegra124_sor },
  2008. { },
  2009. };
  2010. MODULE_DEVICE_TABLE(of, tegra_sor_of_match);
  2011. static int tegra_sor_probe(struct platform_device *pdev)
  2012. {
  2013. const struct of_device_id *match;
  2014. struct device_node *np;
  2015. struct tegra_sor *sor;
  2016. struct resource *regs;
  2017. int err;
  2018. match = of_match_device(tegra_sor_of_match, &pdev->dev);
  2019. sor = devm_kzalloc(&pdev->dev, sizeof(*sor), GFP_KERNEL);
  2020. if (!sor)
  2021. return -ENOMEM;
  2022. sor->output.dev = sor->dev = &pdev->dev;
  2023. sor->soc = match->data;
  2024. sor->settings = devm_kmemdup(&pdev->dev, sor->soc->settings,
  2025. sor->soc->num_settings *
  2026. sizeof(*sor->settings),
  2027. GFP_KERNEL);
  2028. if (!sor->settings)
  2029. return -ENOMEM;
  2030. sor->num_settings = sor->soc->num_settings;
  2031. np = of_parse_phandle(pdev->dev.of_node, "nvidia,dpaux", 0);
  2032. if (np) {
  2033. sor->aux = drm_dp_aux_find_by_of_node(np);
  2034. of_node_put(np);
  2035. if (!sor->aux)
  2036. return -EPROBE_DEFER;
  2037. }
  2038. if (!sor->aux) {
  2039. if (sor->soc->supports_hdmi) {
  2040. sor->ops = &tegra_sor_hdmi_ops;
  2041. } else if (sor->soc->supports_lvds) {
  2042. dev_err(&pdev->dev, "LVDS not supported yet\n");
  2043. return -ENODEV;
  2044. } else {
  2045. dev_err(&pdev->dev, "unknown (non-DP) support\n");
  2046. return -ENODEV;
  2047. }
  2048. } else {
  2049. if (sor->soc->supports_edp) {
  2050. sor->ops = &tegra_sor_edp_ops;
  2051. } else if (sor->soc->supports_dp) {
  2052. dev_err(&pdev->dev, "DisplayPort not supported yet\n");
  2053. return -ENODEV;
  2054. } else {
  2055. dev_err(&pdev->dev, "unknown (DP) support\n");
  2056. return -ENODEV;
  2057. }
  2058. }
  2059. err = tegra_output_probe(&sor->output);
  2060. if (err < 0) {
  2061. dev_err(&pdev->dev, "failed to probe output: %d\n", err);
  2062. return err;
  2063. }
  2064. if (sor->ops && sor->ops->probe) {
  2065. err = sor->ops->probe(sor);
  2066. if (err < 0) {
  2067. dev_err(&pdev->dev, "failed to probe %s: %d\n",
  2068. sor->ops->name, err);
  2069. goto output;
  2070. }
  2071. }
  2072. regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  2073. sor->regs = devm_ioremap_resource(&pdev->dev, regs);
  2074. if (IS_ERR(sor->regs)) {
  2075. err = PTR_ERR(sor->regs);
  2076. goto remove;
  2077. }
  2078. if (!pdev->dev.pm_domain) {
  2079. sor->rst = devm_reset_control_get(&pdev->dev, "sor");
  2080. if (IS_ERR(sor->rst)) {
  2081. err = PTR_ERR(sor->rst);
  2082. dev_err(&pdev->dev, "failed to get reset control: %d\n",
  2083. err);
  2084. goto remove;
  2085. }
  2086. }
  2087. sor->clk = devm_clk_get(&pdev->dev, NULL);
  2088. if (IS_ERR(sor->clk)) {
  2089. err = PTR_ERR(sor->clk);
  2090. dev_err(&pdev->dev, "failed to get module clock: %d\n", err);
  2091. goto remove;
  2092. }
  2093. if (sor->soc->supports_hdmi || sor->soc->supports_dp) {
  2094. sor->clk_src = devm_clk_get(&pdev->dev, "source");
  2095. if (IS_ERR(sor->clk_src)) {
  2096. err = PTR_ERR(sor->clk_src);
  2097. dev_err(sor->dev, "failed to get source clock: %d\n",
  2098. err);
  2099. goto remove;
  2100. }
  2101. }
  2102. sor->clk_parent = devm_clk_get(&pdev->dev, "parent");
  2103. if (IS_ERR(sor->clk_parent)) {
  2104. err = PTR_ERR(sor->clk_parent);
  2105. dev_err(&pdev->dev, "failed to get parent clock: %d\n", err);
  2106. goto remove;
  2107. }
  2108. sor->clk_safe = devm_clk_get(&pdev->dev, "safe");
  2109. if (IS_ERR(sor->clk_safe)) {
  2110. err = PTR_ERR(sor->clk_safe);
  2111. dev_err(&pdev->dev, "failed to get safe clock: %d\n", err);
  2112. goto remove;
  2113. }
  2114. sor->clk_dp = devm_clk_get(&pdev->dev, "dp");
  2115. if (IS_ERR(sor->clk_dp)) {
  2116. err = PTR_ERR(sor->clk_dp);
  2117. dev_err(&pdev->dev, "failed to get DP clock: %d\n", err);
  2118. goto remove;
  2119. }
  2120. platform_set_drvdata(pdev, sor);
  2121. pm_runtime_enable(&pdev->dev);
  2122. pm_runtime_get_sync(&pdev->dev);
  2123. sor->clk_brick = tegra_clk_sor_brick_register(sor, "sor1_brick");
  2124. pm_runtime_put(&pdev->dev);
  2125. if (IS_ERR(sor->clk_brick)) {
  2126. err = PTR_ERR(sor->clk_brick);
  2127. dev_err(&pdev->dev, "failed to register SOR clock: %d\n", err);
  2128. goto remove;
  2129. }
  2130. INIT_LIST_HEAD(&sor->client.list);
  2131. sor->client.ops = &sor_client_ops;
  2132. sor->client.dev = &pdev->dev;
  2133. err = host1x_client_register(&sor->client);
  2134. if (err < 0) {
  2135. dev_err(&pdev->dev, "failed to register host1x client: %d\n",
  2136. err);
  2137. goto remove;
  2138. }
  2139. return 0;
  2140. remove:
  2141. if (sor->ops && sor->ops->remove)
  2142. sor->ops->remove(sor);
  2143. output:
  2144. tegra_output_remove(&sor->output);
  2145. return err;
  2146. }
  2147. static int tegra_sor_remove(struct platform_device *pdev)
  2148. {
  2149. struct tegra_sor *sor = platform_get_drvdata(pdev);
  2150. int err;
  2151. pm_runtime_disable(&pdev->dev);
  2152. err = host1x_client_unregister(&sor->client);
  2153. if (err < 0) {
  2154. dev_err(&pdev->dev, "failed to unregister host1x client: %d\n",
  2155. err);
  2156. return err;
  2157. }
  2158. if (sor->ops && sor->ops->remove) {
  2159. err = sor->ops->remove(sor);
  2160. if (err < 0)
  2161. dev_err(&pdev->dev, "failed to remove SOR: %d\n", err);
  2162. }
  2163. tegra_output_remove(&sor->output);
  2164. return 0;
  2165. }
  2166. #ifdef CONFIG_PM
  2167. static int tegra_sor_suspend(struct device *dev)
  2168. {
  2169. struct tegra_sor *sor = dev_get_drvdata(dev);
  2170. int err;
  2171. if (sor->rst) {
  2172. err = reset_control_assert(sor->rst);
  2173. if (err < 0) {
  2174. dev_err(dev, "failed to assert reset: %d\n", err);
  2175. return err;
  2176. }
  2177. }
  2178. usleep_range(1000, 2000);
  2179. clk_disable_unprepare(sor->clk);
  2180. return 0;
  2181. }
  2182. static int tegra_sor_resume(struct device *dev)
  2183. {
  2184. struct tegra_sor *sor = dev_get_drvdata(dev);
  2185. int err;
  2186. err = clk_prepare_enable(sor->clk);
  2187. if (err < 0) {
  2188. dev_err(dev, "failed to enable clock: %d\n", err);
  2189. return err;
  2190. }
  2191. usleep_range(1000, 2000);
  2192. if (sor->rst) {
  2193. err = reset_control_deassert(sor->rst);
  2194. if (err < 0) {
  2195. dev_err(dev, "failed to deassert reset: %d\n", err);
  2196. clk_disable_unprepare(sor->clk);
  2197. return err;
  2198. }
  2199. }
  2200. return 0;
  2201. }
  2202. #endif
  2203. static const struct dev_pm_ops tegra_sor_pm_ops = {
  2204. SET_RUNTIME_PM_OPS(tegra_sor_suspend, tegra_sor_resume, NULL)
  2205. };
  2206. struct platform_driver tegra_sor_driver = {
  2207. .driver = {
  2208. .name = "tegra-sor",
  2209. .of_match_table = tegra_sor_of_match,
  2210. .pm = &tegra_sor_pm_ops,
  2211. },
  2212. .probe = tegra_sor_probe,
  2213. .remove = tegra_sor_remove,
  2214. };