sor.c 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776
  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. .reset = tegra_sor_connector_reset,
  1082. .detect = tegra_sor_connector_detect,
  1083. .fill_modes = drm_helper_probe_single_connector_modes,
  1084. .destroy = tegra_output_connector_destroy,
  1085. .atomic_duplicate_state = tegra_sor_connector_duplicate_state,
  1086. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  1087. };
  1088. static int tegra_sor_connector_get_modes(struct drm_connector *connector)
  1089. {
  1090. struct tegra_output *output = connector_to_output(connector);
  1091. struct tegra_sor *sor = to_sor(output);
  1092. int err;
  1093. if (sor->aux)
  1094. drm_dp_aux_enable(sor->aux);
  1095. err = tegra_output_connector_get_modes(connector);
  1096. if (sor->aux)
  1097. drm_dp_aux_disable(sor->aux);
  1098. return err;
  1099. }
  1100. static enum drm_mode_status
  1101. tegra_sor_connector_mode_valid(struct drm_connector *connector,
  1102. struct drm_display_mode *mode)
  1103. {
  1104. /* HDMI 2.0 modes are not yet supported */
  1105. if (mode->clock > 340000)
  1106. return MODE_NOCLOCK;
  1107. return MODE_OK;
  1108. }
  1109. static const struct drm_connector_helper_funcs tegra_sor_connector_helper_funcs = {
  1110. .get_modes = tegra_sor_connector_get_modes,
  1111. .mode_valid = tegra_sor_connector_mode_valid,
  1112. };
  1113. static const struct drm_encoder_funcs tegra_sor_encoder_funcs = {
  1114. .destroy = tegra_output_encoder_destroy,
  1115. };
  1116. static void tegra_sor_edp_disable(struct drm_encoder *encoder)
  1117. {
  1118. struct tegra_output *output = encoder_to_output(encoder);
  1119. struct tegra_dc *dc = to_tegra_dc(encoder->crtc);
  1120. struct tegra_sor *sor = to_sor(output);
  1121. u32 value;
  1122. int err;
  1123. if (output->panel)
  1124. drm_panel_disable(output->panel);
  1125. err = tegra_sor_detach(sor);
  1126. if (err < 0)
  1127. dev_err(sor->dev, "failed to detach SOR: %d\n", err);
  1128. tegra_sor_writel(sor, 0, SOR_STATE1);
  1129. tegra_sor_update(sor);
  1130. /*
  1131. * The following accesses registers of the display controller, so make
  1132. * sure it's only executed when the output is attached to one.
  1133. */
  1134. if (dc) {
  1135. value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
  1136. value &= ~SOR_ENABLE;
  1137. tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
  1138. tegra_dc_commit(dc);
  1139. }
  1140. err = tegra_sor_power_down(sor);
  1141. if (err < 0)
  1142. dev_err(sor->dev, "failed to power down SOR: %d\n", err);
  1143. if (sor->aux) {
  1144. err = drm_dp_aux_disable(sor->aux);
  1145. if (err < 0)
  1146. dev_err(sor->dev, "failed to disable DP: %d\n", err);
  1147. }
  1148. err = tegra_io_rail_power_off(TEGRA_IO_RAIL_LVDS);
  1149. if (err < 0)
  1150. dev_err(sor->dev, "failed to power off I/O rail: %d\n", err);
  1151. if (output->panel)
  1152. drm_panel_unprepare(output->panel);
  1153. pm_runtime_put(sor->dev);
  1154. }
  1155. #if 0
  1156. static int calc_h_ref_to_sync(const struct drm_display_mode *mode,
  1157. unsigned int *value)
  1158. {
  1159. unsigned int hfp, hsw, hbp, a = 0, b;
  1160. hfp = mode->hsync_start - mode->hdisplay;
  1161. hsw = mode->hsync_end - mode->hsync_start;
  1162. hbp = mode->htotal - mode->hsync_end;
  1163. pr_info("hfp: %u, hsw: %u, hbp: %u\n", hfp, hsw, hbp);
  1164. b = hfp - 1;
  1165. pr_info("a: %u, b: %u\n", a, b);
  1166. pr_info("a + hsw + hbp = %u\n", a + hsw + hbp);
  1167. if (a + hsw + hbp <= 11) {
  1168. a = 1 + 11 - hsw - hbp;
  1169. pr_info("a: %u\n", a);
  1170. }
  1171. if (a > b)
  1172. return -EINVAL;
  1173. if (hsw < 1)
  1174. return -EINVAL;
  1175. if (mode->hdisplay < 16)
  1176. return -EINVAL;
  1177. if (value) {
  1178. if (b > a && a % 2)
  1179. *value = a + 1;
  1180. else
  1181. *value = a;
  1182. }
  1183. return 0;
  1184. }
  1185. #endif
  1186. static void tegra_sor_edp_enable(struct drm_encoder *encoder)
  1187. {
  1188. struct drm_display_mode *mode = &encoder->crtc->state->adjusted_mode;
  1189. struct tegra_output *output = encoder_to_output(encoder);
  1190. struct tegra_dc *dc = to_tegra_dc(encoder->crtc);
  1191. struct tegra_sor *sor = to_sor(output);
  1192. struct tegra_sor_config config;
  1193. struct tegra_sor_state *state;
  1194. struct drm_dp_link link;
  1195. u8 rate, lanes;
  1196. unsigned int i;
  1197. int err = 0;
  1198. u32 value;
  1199. state = to_sor_state(output->connector.state);
  1200. pm_runtime_get_sync(sor->dev);
  1201. if (output->panel)
  1202. drm_panel_prepare(output->panel);
  1203. err = drm_dp_aux_enable(sor->aux);
  1204. if (err < 0)
  1205. dev_err(sor->dev, "failed to enable DP: %d\n", err);
  1206. err = drm_dp_link_probe(sor->aux, &link);
  1207. if (err < 0) {
  1208. dev_err(sor->dev, "failed to probe eDP link: %d\n", err);
  1209. return;
  1210. }
  1211. /* switch to safe parent clock */
  1212. err = tegra_sor_set_parent_clock(sor, sor->clk_safe);
  1213. if (err < 0)
  1214. dev_err(sor->dev, "failed to set safe parent clock: %d\n", err);
  1215. memset(&config, 0, sizeof(config));
  1216. config.bits_per_pixel = state->bpc * 3;
  1217. err = tegra_sor_compute_config(sor, mode, &config, &link);
  1218. if (err < 0)
  1219. dev_err(sor->dev, "failed to compute configuration: %d\n", err);
  1220. value = tegra_sor_readl(sor, SOR_CLK_CNTRL);
  1221. value &= ~SOR_CLK_CNTRL_DP_CLK_SEL_MASK;
  1222. value |= SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_DPCLK;
  1223. tegra_sor_writel(sor, value, SOR_CLK_CNTRL);
  1224. value = tegra_sor_readl(sor, SOR_PLL2);
  1225. value &= ~SOR_PLL2_BANDGAP_POWERDOWN;
  1226. tegra_sor_writel(sor, value, SOR_PLL2);
  1227. usleep_range(20, 100);
  1228. value = tegra_sor_readl(sor, SOR_PLL3);
  1229. value |= SOR_PLL3_PLL_VDD_MODE_3V3;
  1230. tegra_sor_writel(sor, value, SOR_PLL3);
  1231. value = SOR_PLL0_ICHPMP(0xf) | SOR_PLL0_VCOCAP_RST |
  1232. SOR_PLL0_PLLREG_LEVEL_V45 | SOR_PLL0_RESISTOR_EXT;
  1233. tegra_sor_writel(sor, value, SOR_PLL0);
  1234. value = tegra_sor_readl(sor, SOR_PLL2);
  1235. value |= SOR_PLL2_SEQ_PLLCAPPD;
  1236. value &= ~SOR_PLL2_SEQ_PLLCAPPD_ENFORCE;
  1237. value |= SOR_PLL2_LVDS_ENABLE;
  1238. tegra_sor_writel(sor, value, SOR_PLL2);
  1239. value = SOR_PLL1_TERM_COMPOUT | SOR_PLL1_TMDS_TERM;
  1240. tegra_sor_writel(sor, value, SOR_PLL1);
  1241. while (true) {
  1242. value = tegra_sor_readl(sor, SOR_PLL2);
  1243. if ((value & SOR_PLL2_SEQ_PLLCAPPD_ENFORCE) == 0)
  1244. break;
  1245. usleep_range(250, 1000);
  1246. }
  1247. value = tegra_sor_readl(sor, SOR_PLL2);
  1248. value &= ~SOR_PLL2_POWERDOWN_OVERRIDE;
  1249. value &= ~SOR_PLL2_PORT_POWERDOWN;
  1250. tegra_sor_writel(sor, value, SOR_PLL2);
  1251. /*
  1252. * power up
  1253. */
  1254. /* set safe link bandwidth (1.62 Gbps) */
  1255. value = tegra_sor_readl(sor, SOR_CLK_CNTRL);
  1256. value &= ~SOR_CLK_CNTRL_DP_LINK_SPEED_MASK;
  1257. value |= SOR_CLK_CNTRL_DP_LINK_SPEED_G1_62;
  1258. tegra_sor_writel(sor, value, SOR_CLK_CNTRL);
  1259. /* step 1 */
  1260. value = tegra_sor_readl(sor, SOR_PLL2);
  1261. value |= SOR_PLL2_SEQ_PLLCAPPD_ENFORCE | SOR_PLL2_PORT_POWERDOWN |
  1262. SOR_PLL2_BANDGAP_POWERDOWN;
  1263. tegra_sor_writel(sor, value, SOR_PLL2);
  1264. value = tegra_sor_readl(sor, SOR_PLL0);
  1265. value |= SOR_PLL0_VCOPD | SOR_PLL0_PWR;
  1266. tegra_sor_writel(sor, value, SOR_PLL0);
  1267. value = tegra_sor_readl(sor, SOR_DP_PADCTL0);
  1268. value &= ~SOR_DP_PADCTL_PAD_CAL_PD;
  1269. tegra_sor_writel(sor, value, SOR_DP_PADCTL0);
  1270. /* step 2 */
  1271. err = tegra_io_rail_power_on(TEGRA_IO_RAIL_LVDS);
  1272. if (err < 0)
  1273. dev_err(sor->dev, "failed to power on I/O rail: %d\n", err);
  1274. usleep_range(5, 100);
  1275. /* step 3 */
  1276. value = tegra_sor_readl(sor, SOR_PLL2);
  1277. value &= ~SOR_PLL2_BANDGAP_POWERDOWN;
  1278. tegra_sor_writel(sor, value, SOR_PLL2);
  1279. usleep_range(20, 100);
  1280. /* step 4 */
  1281. value = tegra_sor_readl(sor, SOR_PLL0);
  1282. value &= ~SOR_PLL0_VCOPD;
  1283. value &= ~SOR_PLL0_PWR;
  1284. tegra_sor_writel(sor, value, SOR_PLL0);
  1285. value = tegra_sor_readl(sor, SOR_PLL2);
  1286. value &= ~SOR_PLL2_SEQ_PLLCAPPD_ENFORCE;
  1287. tegra_sor_writel(sor, value, SOR_PLL2);
  1288. usleep_range(200, 1000);
  1289. /* step 5 */
  1290. value = tegra_sor_readl(sor, SOR_PLL2);
  1291. value &= ~SOR_PLL2_PORT_POWERDOWN;
  1292. tegra_sor_writel(sor, value, SOR_PLL2);
  1293. /* XXX not in TRM */
  1294. for (value = 0, i = 0; i < 5; i++)
  1295. value |= SOR_XBAR_CTRL_LINK0_XSEL(i, sor->soc->xbar_cfg[i]) |
  1296. SOR_XBAR_CTRL_LINK1_XSEL(i, i);
  1297. tegra_sor_writel(sor, 0x00000000, SOR_XBAR_POL);
  1298. tegra_sor_writel(sor, value, SOR_XBAR_CTRL);
  1299. /* switch to DP parent clock */
  1300. err = tegra_sor_set_parent_clock(sor, sor->clk_dp);
  1301. if (err < 0)
  1302. dev_err(sor->dev, "failed to set parent clock: %d\n", err);
  1303. /* power DP lanes */
  1304. value = tegra_sor_readl(sor, SOR_DP_PADCTL0);
  1305. if (link.num_lanes <= 2)
  1306. value &= ~(SOR_DP_PADCTL_PD_TXD_3 | SOR_DP_PADCTL_PD_TXD_2);
  1307. else
  1308. value |= SOR_DP_PADCTL_PD_TXD_3 | SOR_DP_PADCTL_PD_TXD_2;
  1309. if (link.num_lanes <= 1)
  1310. value &= ~SOR_DP_PADCTL_PD_TXD_1;
  1311. else
  1312. value |= SOR_DP_PADCTL_PD_TXD_1;
  1313. if (link.num_lanes == 0)
  1314. value &= ~SOR_DP_PADCTL_PD_TXD_0;
  1315. else
  1316. value |= SOR_DP_PADCTL_PD_TXD_0;
  1317. tegra_sor_writel(sor, value, SOR_DP_PADCTL0);
  1318. value = tegra_sor_readl(sor, SOR_DP_LINKCTL0);
  1319. value &= ~SOR_DP_LINKCTL_LANE_COUNT_MASK;
  1320. value |= SOR_DP_LINKCTL_LANE_COUNT(link.num_lanes);
  1321. tegra_sor_writel(sor, value, SOR_DP_LINKCTL0);
  1322. /* start lane sequencer */
  1323. value = SOR_LANE_SEQ_CTL_TRIGGER | SOR_LANE_SEQ_CTL_SEQUENCE_DOWN |
  1324. SOR_LANE_SEQ_CTL_POWER_STATE_UP;
  1325. tegra_sor_writel(sor, value, SOR_LANE_SEQ_CTL);
  1326. while (true) {
  1327. value = tegra_sor_readl(sor, SOR_LANE_SEQ_CTL);
  1328. if ((value & SOR_LANE_SEQ_CTL_TRIGGER) == 0)
  1329. break;
  1330. usleep_range(250, 1000);
  1331. }
  1332. /* set link bandwidth */
  1333. value = tegra_sor_readl(sor, SOR_CLK_CNTRL);
  1334. value &= ~SOR_CLK_CNTRL_DP_LINK_SPEED_MASK;
  1335. value |= drm_dp_link_rate_to_bw_code(link.rate) << 2;
  1336. tegra_sor_writel(sor, value, SOR_CLK_CNTRL);
  1337. tegra_sor_apply_config(sor, &config);
  1338. /* enable link */
  1339. value = tegra_sor_readl(sor, SOR_DP_LINKCTL0);
  1340. value |= SOR_DP_LINKCTL_ENABLE;
  1341. value |= SOR_DP_LINKCTL_ENHANCED_FRAME;
  1342. tegra_sor_writel(sor, value, SOR_DP_LINKCTL0);
  1343. for (i = 0, value = 0; i < 4; i++) {
  1344. unsigned long lane = SOR_DP_TPG_CHANNEL_CODING |
  1345. SOR_DP_TPG_SCRAMBLER_GALIOS |
  1346. SOR_DP_TPG_PATTERN_NONE;
  1347. value = (value << 8) | lane;
  1348. }
  1349. tegra_sor_writel(sor, value, SOR_DP_TPG);
  1350. /* enable pad calibration logic */
  1351. value = tegra_sor_readl(sor, SOR_DP_PADCTL0);
  1352. value |= SOR_DP_PADCTL_PAD_CAL_PD;
  1353. tegra_sor_writel(sor, value, SOR_DP_PADCTL0);
  1354. err = drm_dp_link_probe(sor->aux, &link);
  1355. if (err < 0)
  1356. dev_err(sor->dev, "failed to probe eDP link: %d\n", err);
  1357. err = drm_dp_link_power_up(sor->aux, &link);
  1358. if (err < 0)
  1359. dev_err(sor->dev, "failed to power up eDP link: %d\n", err);
  1360. err = drm_dp_link_configure(sor->aux, &link);
  1361. if (err < 0)
  1362. dev_err(sor->dev, "failed to configure eDP link: %d\n", err);
  1363. rate = drm_dp_link_rate_to_bw_code(link.rate);
  1364. lanes = link.num_lanes;
  1365. value = tegra_sor_readl(sor, SOR_CLK_CNTRL);
  1366. value &= ~SOR_CLK_CNTRL_DP_LINK_SPEED_MASK;
  1367. value |= SOR_CLK_CNTRL_DP_LINK_SPEED(rate);
  1368. tegra_sor_writel(sor, value, SOR_CLK_CNTRL);
  1369. value = tegra_sor_readl(sor, SOR_DP_LINKCTL0);
  1370. value &= ~SOR_DP_LINKCTL_LANE_COUNT_MASK;
  1371. value |= SOR_DP_LINKCTL_LANE_COUNT(lanes);
  1372. if (link.capabilities & DP_LINK_CAP_ENHANCED_FRAMING)
  1373. value |= SOR_DP_LINKCTL_ENHANCED_FRAME;
  1374. tegra_sor_writel(sor, value, SOR_DP_LINKCTL0);
  1375. /* disable training pattern generator */
  1376. for (i = 0; i < link.num_lanes; i++) {
  1377. unsigned long lane = SOR_DP_TPG_CHANNEL_CODING |
  1378. SOR_DP_TPG_SCRAMBLER_GALIOS |
  1379. SOR_DP_TPG_PATTERN_NONE;
  1380. value = (value << 8) | lane;
  1381. }
  1382. tegra_sor_writel(sor, value, SOR_DP_TPG);
  1383. err = tegra_sor_dp_train_fast(sor, &link);
  1384. if (err < 0)
  1385. dev_err(sor->dev, "DP fast link training failed: %d\n", err);
  1386. dev_dbg(sor->dev, "fast link training succeeded\n");
  1387. err = tegra_sor_power_up(sor, 250);
  1388. if (err < 0)
  1389. dev_err(sor->dev, "failed to power up SOR: %d\n", err);
  1390. /* CSTM (LVDS, link A/B, upper) */
  1391. value = SOR_CSTM_LVDS | SOR_CSTM_LINK_ACT_A | SOR_CSTM_LINK_ACT_B |
  1392. SOR_CSTM_UPPER;
  1393. tegra_sor_writel(sor, value, SOR_CSTM);
  1394. /* use DP-A protocol */
  1395. value = tegra_sor_readl(sor, SOR_STATE1);
  1396. value &= ~SOR_STATE_ASY_PROTOCOL_MASK;
  1397. value |= SOR_STATE_ASY_PROTOCOL_DP_A;
  1398. tegra_sor_writel(sor, value, SOR_STATE1);
  1399. tegra_sor_mode_set(sor, mode, state);
  1400. /* PWM setup */
  1401. err = tegra_sor_setup_pwm(sor, 250);
  1402. if (err < 0)
  1403. dev_err(sor->dev, "failed to setup PWM: %d\n", err);
  1404. tegra_sor_update(sor);
  1405. value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
  1406. value |= SOR_ENABLE;
  1407. tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
  1408. tegra_dc_commit(dc);
  1409. err = tegra_sor_attach(sor);
  1410. if (err < 0)
  1411. dev_err(sor->dev, "failed to attach SOR: %d\n", err);
  1412. err = tegra_sor_wakeup(sor);
  1413. if (err < 0)
  1414. dev_err(sor->dev, "failed to enable DC: %d\n", err);
  1415. if (output->panel)
  1416. drm_panel_enable(output->panel);
  1417. }
  1418. static int
  1419. tegra_sor_encoder_atomic_check(struct drm_encoder *encoder,
  1420. struct drm_crtc_state *crtc_state,
  1421. struct drm_connector_state *conn_state)
  1422. {
  1423. struct tegra_output *output = encoder_to_output(encoder);
  1424. struct tegra_sor_state *state = to_sor_state(conn_state);
  1425. struct tegra_dc *dc = to_tegra_dc(conn_state->crtc);
  1426. unsigned long pclk = crtc_state->mode.clock * 1000;
  1427. struct tegra_sor *sor = to_sor(output);
  1428. struct drm_display_info *info;
  1429. int err;
  1430. info = &output->connector.display_info;
  1431. err = tegra_dc_state_setup_clock(dc, crtc_state, sor->clk_parent,
  1432. pclk, 0);
  1433. if (err < 0) {
  1434. dev_err(output->dev, "failed to setup CRTC state: %d\n", err);
  1435. return err;
  1436. }
  1437. switch (info->bpc) {
  1438. case 8:
  1439. case 6:
  1440. state->bpc = info->bpc;
  1441. break;
  1442. default:
  1443. DRM_DEBUG_KMS("%u bits-per-color not supported\n", info->bpc);
  1444. state->bpc = 8;
  1445. break;
  1446. }
  1447. return 0;
  1448. }
  1449. static const struct drm_encoder_helper_funcs tegra_sor_edp_helpers = {
  1450. .disable = tegra_sor_edp_disable,
  1451. .enable = tegra_sor_edp_enable,
  1452. .atomic_check = tegra_sor_encoder_atomic_check,
  1453. };
  1454. static inline u32 tegra_sor_hdmi_subpack(const u8 *ptr, size_t size)
  1455. {
  1456. u32 value = 0;
  1457. size_t i;
  1458. for (i = size; i > 0; i--)
  1459. value = (value << 8) | ptr[i - 1];
  1460. return value;
  1461. }
  1462. static void tegra_sor_hdmi_write_infopack(struct tegra_sor *sor,
  1463. const void *data, size_t size)
  1464. {
  1465. const u8 *ptr = data;
  1466. unsigned long offset;
  1467. size_t i, j;
  1468. u32 value;
  1469. switch (ptr[0]) {
  1470. case HDMI_INFOFRAME_TYPE_AVI:
  1471. offset = SOR_HDMI_AVI_INFOFRAME_HEADER;
  1472. break;
  1473. case HDMI_INFOFRAME_TYPE_AUDIO:
  1474. offset = SOR_HDMI_AUDIO_INFOFRAME_HEADER;
  1475. break;
  1476. case HDMI_INFOFRAME_TYPE_VENDOR:
  1477. offset = SOR_HDMI_VSI_INFOFRAME_HEADER;
  1478. break;
  1479. default:
  1480. dev_err(sor->dev, "unsupported infoframe type: %02x\n",
  1481. ptr[0]);
  1482. return;
  1483. }
  1484. value = INFOFRAME_HEADER_TYPE(ptr[0]) |
  1485. INFOFRAME_HEADER_VERSION(ptr[1]) |
  1486. INFOFRAME_HEADER_LEN(ptr[2]);
  1487. tegra_sor_writel(sor, value, offset);
  1488. offset++;
  1489. /*
  1490. * Each subpack contains 7 bytes, divided into:
  1491. * - subpack_low: bytes 0 - 3
  1492. * - subpack_high: bytes 4 - 6 (with byte 7 padded to 0x00)
  1493. */
  1494. for (i = 3, j = 0; i < size; i += 7, j += 8) {
  1495. size_t rem = size - i, num = min_t(size_t, rem, 4);
  1496. value = tegra_sor_hdmi_subpack(&ptr[i], num);
  1497. tegra_sor_writel(sor, value, offset++);
  1498. num = min_t(size_t, rem - num, 3);
  1499. value = tegra_sor_hdmi_subpack(&ptr[i + 4], num);
  1500. tegra_sor_writel(sor, value, offset++);
  1501. }
  1502. }
  1503. static int
  1504. tegra_sor_hdmi_setup_avi_infoframe(struct tegra_sor *sor,
  1505. const struct drm_display_mode *mode)
  1506. {
  1507. u8 buffer[HDMI_INFOFRAME_SIZE(AVI)];
  1508. struct hdmi_avi_infoframe frame;
  1509. u32 value;
  1510. int err;
  1511. /* disable AVI infoframe */
  1512. value = tegra_sor_readl(sor, SOR_HDMI_AVI_INFOFRAME_CTRL);
  1513. value &= ~INFOFRAME_CTRL_SINGLE;
  1514. value &= ~INFOFRAME_CTRL_OTHER;
  1515. value &= ~INFOFRAME_CTRL_ENABLE;
  1516. tegra_sor_writel(sor, value, SOR_HDMI_AVI_INFOFRAME_CTRL);
  1517. err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode, false);
  1518. if (err < 0) {
  1519. dev_err(sor->dev, "failed to setup AVI infoframe: %d\n", err);
  1520. return err;
  1521. }
  1522. err = hdmi_avi_infoframe_pack(&frame, buffer, sizeof(buffer));
  1523. if (err < 0) {
  1524. dev_err(sor->dev, "failed to pack AVI infoframe: %d\n", err);
  1525. return err;
  1526. }
  1527. tegra_sor_hdmi_write_infopack(sor, buffer, err);
  1528. /* enable AVI infoframe */
  1529. value = tegra_sor_readl(sor, SOR_HDMI_AVI_INFOFRAME_CTRL);
  1530. value |= INFOFRAME_CTRL_CHECKSUM_ENABLE;
  1531. value |= INFOFRAME_CTRL_ENABLE;
  1532. tegra_sor_writel(sor, value, SOR_HDMI_AVI_INFOFRAME_CTRL);
  1533. return 0;
  1534. }
  1535. static void tegra_sor_hdmi_disable_audio_infoframe(struct tegra_sor *sor)
  1536. {
  1537. u32 value;
  1538. value = tegra_sor_readl(sor, SOR_HDMI_AUDIO_INFOFRAME_CTRL);
  1539. value &= ~INFOFRAME_CTRL_ENABLE;
  1540. tegra_sor_writel(sor, value, SOR_HDMI_AUDIO_INFOFRAME_CTRL);
  1541. }
  1542. static struct tegra_sor_hdmi_settings *
  1543. tegra_sor_hdmi_find_settings(struct tegra_sor *sor, unsigned long frequency)
  1544. {
  1545. unsigned int i;
  1546. for (i = 0; i < sor->num_settings; i++)
  1547. if (frequency <= sor->settings[i].frequency)
  1548. return &sor->settings[i];
  1549. return NULL;
  1550. }
  1551. static void tegra_sor_hdmi_disable(struct drm_encoder *encoder)
  1552. {
  1553. struct tegra_output *output = encoder_to_output(encoder);
  1554. struct tegra_dc *dc = to_tegra_dc(encoder->crtc);
  1555. struct tegra_sor *sor = to_sor(output);
  1556. u32 value;
  1557. int err;
  1558. err = tegra_sor_detach(sor);
  1559. if (err < 0)
  1560. dev_err(sor->dev, "failed to detach SOR: %d\n", err);
  1561. tegra_sor_writel(sor, 0, SOR_STATE1);
  1562. tegra_sor_update(sor);
  1563. /* disable display to SOR clock */
  1564. value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
  1565. value &= ~SOR1_TIMING_CYA;
  1566. value &= ~SOR1_ENABLE;
  1567. tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
  1568. tegra_dc_commit(dc);
  1569. err = tegra_sor_power_down(sor);
  1570. if (err < 0)
  1571. dev_err(sor->dev, "failed to power down SOR: %d\n", err);
  1572. err = tegra_io_rail_power_off(TEGRA_IO_RAIL_HDMI);
  1573. if (err < 0)
  1574. dev_err(sor->dev, "failed to power off HDMI rail: %d\n", err);
  1575. pm_runtime_put(sor->dev);
  1576. }
  1577. static void tegra_sor_hdmi_enable(struct drm_encoder *encoder)
  1578. {
  1579. struct tegra_output *output = encoder_to_output(encoder);
  1580. unsigned int h_ref_to_sync = 1, pulse_start, max_ac;
  1581. struct tegra_dc *dc = to_tegra_dc(encoder->crtc);
  1582. struct tegra_sor_hdmi_settings *settings;
  1583. struct tegra_sor *sor = to_sor(output);
  1584. struct tegra_sor_state *state;
  1585. struct drm_display_mode *mode;
  1586. unsigned int div, i;
  1587. u32 value;
  1588. int err;
  1589. state = to_sor_state(output->connector.state);
  1590. mode = &encoder->crtc->state->adjusted_mode;
  1591. pm_runtime_get_sync(sor->dev);
  1592. /* switch to safe parent clock */
  1593. err = tegra_sor_set_parent_clock(sor, sor->clk_safe);
  1594. if (err < 0)
  1595. dev_err(sor->dev, "failed to set safe parent clock: %d\n", err);
  1596. div = clk_get_rate(sor->clk) / 1000000 * 4;
  1597. err = tegra_io_rail_power_on(TEGRA_IO_RAIL_HDMI);
  1598. if (err < 0)
  1599. dev_err(sor->dev, "failed to power on HDMI rail: %d\n", err);
  1600. usleep_range(20, 100);
  1601. value = tegra_sor_readl(sor, SOR_PLL2);
  1602. value &= ~SOR_PLL2_BANDGAP_POWERDOWN;
  1603. tegra_sor_writel(sor, value, SOR_PLL2);
  1604. usleep_range(20, 100);
  1605. value = tegra_sor_readl(sor, SOR_PLL3);
  1606. value &= ~SOR_PLL3_PLL_VDD_MODE_3V3;
  1607. tegra_sor_writel(sor, value, SOR_PLL3);
  1608. value = tegra_sor_readl(sor, SOR_PLL0);
  1609. value &= ~SOR_PLL0_VCOPD;
  1610. value &= ~SOR_PLL0_PWR;
  1611. tegra_sor_writel(sor, value, SOR_PLL0);
  1612. value = tegra_sor_readl(sor, SOR_PLL2);
  1613. value &= ~SOR_PLL2_SEQ_PLLCAPPD_ENFORCE;
  1614. tegra_sor_writel(sor, value, SOR_PLL2);
  1615. usleep_range(200, 400);
  1616. value = tegra_sor_readl(sor, SOR_PLL2);
  1617. value &= ~SOR_PLL2_POWERDOWN_OVERRIDE;
  1618. value &= ~SOR_PLL2_PORT_POWERDOWN;
  1619. tegra_sor_writel(sor, value, SOR_PLL2);
  1620. usleep_range(20, 100);
  1621. value = tegra_sor_readl(sor, SOR_DP_PADCTL0);
  1622. value |= SOR_DP_PADCTL_PD_TXD_3 | SOR_DP_PADCTL_PD_TXD_0 |
  1623. SOR_DP_PADCTL_PD_TXD_1 | SOR_DP_PADCTL_PD_TXD_2;
  1624. tegra_sor_writel(sor, value, SOR_DP_PADCTL0);
  1625. while (true) {
  1626. value = tegra_sor_readl(sor, SOR_LANE_SEQ_CTL);
  1627. if ((value & SOR_LANE_SEQ_CTL_STATE_BUSY) == 0)
  1628. break;
  1629. usleep_range(250, 1000);
  1630. }
  1631. value = SOR_LANE_SEQ_CTL_TRIGGER | SOR_LANE_SEQ_CTL_SEQUENCE_DOWN |
  1632. SOR_LANE_SEQ_CTL_POWER_STATE_UP | SOR_LANE_SEQ_CTL_DELAY(5);
  1633. tegra_sor_writel(sor, value, SOR_LANE_SEQ_CTL);
  1634. while (true) {
  1635. value = tegra_sor_readl(sor, SOR_LANE_SEQ_CTL);
  1636. if ((value & SOR_LANE_SEQ_CTL_TRIGGER) == 0)
  1637. break;
  1638. usleep_range(250, 1000);
  1639. }
  1640. value = tegra_sor_readl(sor, SOR_CLK_CNTRL);
  1641. value &= ~SOR_CLK_CNTRL_DP_LINK_SPEED_MASK;
  1642. value &= ~SOR_CLK_CNTRL_DP_CLK_SEL_MASK;
  1643. if (mode->clock < 340000)
  1644. value |= SOR_CLK_CNTRL_DP_LINK_SPEED_G2_70;
  1645. else
  1646. value |= SOR_CLK_CNTRL_DP_LINK_SPEED_G5_40;
  1647. value |= SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_PCLK;
  1648. tegra_sor_writel(sor, value, SOR_CLK_CNTRL);
  1649. value = tegra_sor_readl(sor, SOR_DP_SPARE0);
  1650. value |= SOR_DP_SPARE_DISP_VIDEO_PREAMBLE;
  1651. value &= ~SOR_DP_SPARE_PANEL_INTERNAL;
  1652. value |= SOR_DP_SPARE_SEQ_ENABLE;
  1653. tegra_sor_writel(sor, value, SOR_DP_SPARE0);
  1654. value = SOR_SEQ_CTL_PU_PC(0) | SOR_SEQ_CTL_PU_PC_ALT(0) |
  1655. SOR_SEQ_CTL_PD_PC(8) | SOR_SEQ_CTL_PD_PC_ALT(8);
  1656. tegra_sor_writel(sor, value, SOR_SEQ_CTL);
  1657. value = SOR_SEQ_INST_DRIVE_PWM_OUT_LO | SOR_SEQ_INST_HALT |
  1658. SOR_SEQ_INST_WAIT_VSYNC | SOR_SEQ_INST_WAIT(1);
  1659. tegra_sor_writel(sor, value, SOR_SEQ_INST(0));
  1660. tegra_sor_writel(sor, value, SOR_SEQ_INST(8));
  1661. /* program the reference clock */
  1662. value = SOR_REFCLK_DIV_INT(div) | SOR_REFCLK_DIV_FRAC(div);
  1663. tegra_sor_writel(sor, value, SOR_REFCLK);
  1664. /* XXX not in TRM */
  1665. for (value = 0, i = 0; i < 5; i++)
  1666. value |= SOR_XBAR_CTRL_LINK0_XSEL(i, sor->soc->xbar_cfg[i]) |
  1667. SOR_XBAR_CTRL_LINK1_XSEL(i, i);
  1668. tegra_sor_writel(sor, 0x00000000, SOR_XBAR_POL);
  1669. tegra_sor_writel(sor, value, SOR_XBAR_CTRL);
  1670. /* switch to parent clock */
  1671. err = clk_set_parent(sor->clk_src, sor->clk_parent);
  1672. if (err < 0)
  1673. dev_err(sor->dev, "failed to set source clock: %d\n", err);
  1674. err = tegra_sor_set_parent_clock(sor, sor->clk_src);
  1675. if (err < 0)
  1676. dev_err(sor->dev, "failed to set parent clock: %d\n", err);
  1677. value = SOR_INPUT_CONTROL_HDMI_SRC_SELECT(dc->pipe);
  1678. /* XXX is this the proper check? */
  1679. if (mode->clock < 75000)
  1680. value |= SOR_INPUT_CONTROL_ARM_VIDEO_RANGE_LIMITED;
  1681. tegra_sor_writel(sor, value, SOR_INPUT_CONTROL);
  1682. max_ac = ((mode->htotal - mode->hdisplay) - SOR_REKEY - 18) / 32;
  1683. value = SOR_HDMI_CTRL_ENABLE | SOR_HDMI_CTRL_MAX_AC_PACKET(max_ac) |
  1684. SOR_HDMI_CTRL_AUDIO_LAYOUT | SOR_HDMI_CTRL_REKEY(SOR_REKEY);
  1685. tegra_sor_writel(sor, value, SOR_HDMI_CTRL);
  1686. /* H_PULSE2 setup */
  1687. pulse_start = h_ref_to_sync + (mode->hsync_end - mode->hsync_start) +
  1688. (mode->htotal - mode->hsync_end) - 10;
  1689. value = PULSE_LAST_END_A | PULSE_QUAL_VACTIVE |
  1690. PULSE_POLARITY_HIGH | PULSE_MODE_NORMAL;
  1691. tegra_dc_writel(dc, value, DC_DISP_H_PULSE2_CONTROL);
  1692. value = PULSE_END(pulse_start + 8) | PULSE_START(pulse_start);
  1693. tegra_dc_writel(dc, value, DC_DISP_H_PULSE2_POSITION_A);
  1694. value = tegra_dc_readl(dc, DC_DISP_DISP_SIGNAL_OPTIONS0);
  1695. value |= H_PULSE2_ENABLE;
  1696. tegra_dc_writel(dc, value, DC_DISP_DISP_SIGNAL_OPTIONS0);
  1697. /* infoframe setup */
  1698. err = tegra_sor_hdmi_setup_avi_infoframe(sor, mode);
  1699. if (err < 0)
  1700. dev_err(sor->dev, "failed to setup AVI infoframe: %d\n", err);
  1701. /* XXX HDMI audio support not implemented yet */
  1702. tegra_sor_hdmi_disable_audio_infoframe(sor);
  1703. /* use single TMDS protocol */
  1704. value = tegra_sor_readl(sor, SOR_STATE1);
  1705. value &= ~SOR_STATE_ASY_PROTOCOL_MASK;
  1706. value |= SOR_STATE_ASY_PROTOCOL_SINGLE_TMDS_A;
  1707. tegra_sor_writel(sor, value, SOR_STATE1);
  1708. /* power up pad calibration */
  1709. value = tegra_sor_readl(sor, SOR_DP_PADCTL0);
  1710. value &= ~SOR_DP_PADCTL_PAD_CAL_PD;
  1711. tegra_sor_writel(sor, value, SOR_DP_PADCTL0);
  1712. /* production settings */
  1713. settings = tegra_sor_hdmi_find_settings(sor, mode->clock * 1000);
  1714. if (!settings) {
  1715. dev_err(sor->dev, "no settings for pixel clock %d Hz\n",
  1716. mode->clock * 1000);
  1717. return;
  1718. }
  1719. value = tegra_sor_readl(sor, SOR_PLL0);
  1720. value &= ~SOR_PLL0_ICHPMP_MASK;
  1721. value &= ~SOR_PLL0_VCOCAP_MASK;
  1722. value |= SOR_PLL0_ICHPMP(settings->ichpmp);
  1723. value |= SOR_PLL0_VCOCAP(settings->vcocap);
  1724. tegra_sor_writel(sor, value, SOR_PLL0);
  1725. tegra_sor_dp_term_calibrate(sor);
  1726. value = tegra_sor_readl(sor, SOR_PLL1);
  1727. value &= ~SOR_PLL1_LOADADJ_MASK;
  1728. value |= SOR_PLL1_LOADADJ(settings->loadadj);
  1729. tegra_sor_writel(sor, value, SOR_PLL1);
  1730. value = tegra_sor_readl(sor, SOR_PLL3);
  1731. value &= ~SOR_PLL3_BG_VREF_LEVEL_MASK;
  1732. value |= SOR_PLL3_BG_VREF_LEVEL(settings->bg_vref);
  1733. tegra_sor_writel(sor, value, SOR_PLL3);
  1734. value = settings->drive_current[0] << 24 |
  1735. settings->drive_current[1] << 16 |
  1736. settings->drive_current[2] << 8 |
  1737. settings->drive_current[3] << 0;
  1738. tegra_sor_writel(sor, value, SOR_LANE_DRIVE_CURRENT0);
  1739. value = settings->preemphasis[0] << 24 |
  1740. settings->preemphasis[1] << 16 |
  1741. settings->preemphasis[2] << 8 |
  1742. settings->preemphasis[3] << 0;
  1743. tegra_sor_writel(sor, value, SOR_LANE_PREEMPHASIS0);
  1744. value = tegra_sor_readl(sor, SOR_DP_PADCTL0);
  1745. value &= ~SOR_DP_PADCTL_TX_PU_MASK;
  1746. value |= SOR_DP_PADCTL_TX_PU_ENABLE;
  1747. value |= SOR_DP_PADCTL_TX_PU(settings->tx_pu);
  1748. tegra_sor_writel(sor, value, SOR_DP_PADCTL0);
  1749. /* power down pad calibration */
  1750. value = tegra_sor_readl(sor, SOR_DP_PADCTL0);
  1751. value |= SOR_DP_PADCTL_PAD_CAL_PD;
  1752. tegra_sor_writel(sor, value, SOR_DP_PADCTL0);
  1753. /* miscellaneous display controller settings */
  1754. value = VSYNC_H_POSITION(1);
  1755. tegra_dc_writel(dc, value, DC_DISP_DISP_TIMING_OPTIONS);
  1756. value = tegra_dc_readl(dc, DC_DISP_DISP_COLOR_CONTROL);
  1757. value &= ~DITHER_CONTROL_MASK;
  1758. value &= ~BASE_COLOR_SIZE_MASK;
  1759. switch (state->bpc) {
  1760. case 6:
  1761. value |= BASE_COLOR_SIZE_666;
  1762. break;
  1763. case 8:
  1764. value |= BASE_COLOR_SIZE_888;
  1765. break;
  1766. default:
  1767. WARN(1, "%u bits-per-color not supported\n", state->bpc);
  1768. value |= BASE_COLOR_SIZE_888;
  1769. break;
  1770. }
  1771. tegra_dc_writel(dc, value, DC_DISP_DISP_COLOR_CONTROL);
  1772. err = tegra_sor_power_up(sor, 250);
  1773. if (err < 0)
  1774. dev_err(sor->dev, "failed to power up SOR: %d\n", err);
  1775. /* configure dynamic range of output */
  1776. value = tegra_sor_readl(sor, SOR_HEAD_STATE0(dc->pipe));
  1777. value &= ~SOR_HEAD_STATE_RANGECOMPRESS_MASK;
  1778. value &= ~SOR_HEAD_STATE_DYNRANGE_MASK;
  1779. tegra_sor_writel(sor, value, SOR_HEAD_STATE0(dc->pipe));
  1780. /* configure colorspace */
  1781. value = tegra_sor_readl(sor, SOR_HEAD_STATE0(dc->pipe));
  1782. value &= ~SOR_HEAD_STATE_COLORSPACE_MASK;
  1783. value |= SOR_HEAD_STATE_COLORSPACE_RGB;
  1784. tegra_sor_writel(sor, value, SOR_HEAD_STATE0(dc->pipe));
  1785. tegra_sor_mode_set(sor, mode, state);
  1786. tegra_sor_update(sor);
  1787. err = tegra_sor_attach(sor);
  1788. if (err < 0)
  1789. dev_err(sor->dev, "failed to attach SOR: %d\n", err);
  1790. /* enable display to SOR clock and generate HDMI preamble */
  1791. value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
  1792. value |= SOR1_ENABLE | SOR1_TIMING_CYA;
  1793. tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
  1794. tegra_dc_commit(dc);
  1795. err = tegra_sor_wakeup(sor);
  1796. if (err < 0)
  1797. dev_err(sor->dev, "failed to wakeup SOR: %d\n", err);
  1798. }
  1799. static const struct drm_encoder_helper_funcs tegra_sor_hdmi_helpers = {
  1800. .disable = tegra_sor_hdmi_disable,
  1801. .enable = tegra_sor_hdmi_enable,
  1802. .atomic_check = tegra_sor_encoder_atomic_check,
  1803. };
  1804. static int tegra_sor_init(struct host1x_client *client)
  1805. {
  1806. struct drm_device *drm = dev_get_drvdata(client->parent);
  1807. const struct drm_encoder_helper_funcs *helpers = NULL;
  1808. struct tegra_sor *sor = host1x_client_to_sor(client);
  1809. int connector = DRM_MODE_CONNECTOR_Unknown;
  1810. int encoder = DRM_MODE_ENCODER_NONE;
  1811. int err;
  1812. if (!sor->aux) {
  1813. if (sor->soc->supports_hdmi) {
  1814. connector = DRM_MODE_CONNECTOR_HDMIA;
  1815. encoder = DRM_MODE_ENCODER_TMDS;
  1816. helpers = &tegra_sor_hdmi_helpers;
  1817. } else if (sor->soc->supports_lvds) {
  1818. connector = DRM_MODE_CONNECTOR_LVDS;
  1819. encoder = DRM_MODE_ENCODER_LVDS;
  1820. }
  1821. } else {
  1822. if (sor->soc->supports_edp) {
  1823. connector = DRM_MODE_CONNECTOR_eDP;
  1824. encoder = DRM_MODE_ENCODER_TMDS;
  1825. helpers = &tegra_sor_edp_helpers;
  1826. } else if (sor->soc->supports_dp) {
  1827. connector = DRM_MODE_CONNECTOR_DisplayPort;
  1828. encoder = DRM_MODE_ENCODER_TMDS;
  1829. }
  1830. }
  1831. sor->output.dev = sor->dev;
  1832. drm_connector_init(drm, &sor->output.connector,
  1833. &tegra_sor_connector_funcs,
  1834. connector);
  1835. drm_connector_helper_add(&sor->output.connector,
  1836. &tegra_sor_connector_helper_funcs);
  1837. sor->output.connector.dpms = DRM_MODE_DPMS_OFF;
  1838. drm_encoder_init(drm, &sor->output.encoder, &tegra_sor_encoder_funcs,
  1839. encoder, NULL);
  1840. drm_encoder_helper_add(&sor->output.encoder, helpers);
  1841. drm_mode_connector_attach_encoder(&sor->output.connector,
  1842. &sor->output.encoder);
  1843. drm_connector_register(&sor->output.connector);
  1844. err = tegra_output_init(drm, &sor->output);
  1845. if (err < 0) {
  1846. dev_err(client->dev, "failed to initialize output: %d\n", err);
  1847. return err;
  1848. }
  1849. sor->output.encoder.possible_crtcs = 0x3;
  1850. if (IS_ENABLED(CONFIG_DEBUG_FS)) {
  1851. err = tegra_sor_debugfs_init(sor, drm->primary);
  1852. if (err < 0)
  1853. dev_err(sor->dev, "debugfs setup failed: %d\n", err);
  1854. }
  1855. if (sor->aux) {
  1856. err = drm_dp_aux_attach(sor->aux, &sor->output);
  1857. if (err < 0) {
  1858. dev_err(sor->dev, "failed to attach DP: %d\n", err);
  1859. return err;
  1860. }
  1861. }
  1862. /*
  1863. * XXX: Remove this reset once proper hand-over from firmware to
  1864. * kernel is possible.
  1865. */
  1866. if (sor->rst) {
  1867. err = reset_control_assert(sor->rst);
  1868. if (err < 0) {
  1869. dev_err(sor->dev, "failed to assert SOR reset: %d\n",
  1870. err);
  1871. return err;
  1872. }
  1873. }
  1874. err = clk_prepare_enable(sor->clk);
  1875. if (err < 0) {
  1876. dev_err(sor->dev, "failed to enable clock: %d\n", err);
  1877. return err;
  1878. }
  1879. usleep_range(1000, 3000);
  1880. if (sor->rst) {
  1881. err = reset_control_deassert(sor->rst);
  1882. if (err < 0) {
  1883. dev_err(sor->dev, "failed to deassert SOR reset: %d\n",
  1884. err);
  1885. return err;
  1886. }
  1887. }
  1888. err = clk_prepare_enable(sor->clk_safe);
  1889. if (err < 0)
  1890. return err;
  1891. err = clk_prepare_enable(sor->clk_dp);
  1892. if (err < 0)
  1893. return err;
  1894. return 0;
  1895. }
  1896. static int tegra_sor_exit(struct host1x_client *client)
  1897. {
  1898. struct tegra_sor *sor = host1x_client_to_sor(client);
  1899. int err;
  1900. tegra_output_exit(&sor->output);
  1901. if (sor->aux) {
  1902. err = drm_dp_aux_detach(sor->aux);
  1903. if (err < 0) {
  1904. dev_err(sor->dev, "failed to detach DP: %d\n", err);
  1905. return err;
  1906. }
  1907. }
  1908. clk_disable_unprepare(sor->clk_safe);
  1909. clk_disable_unprepare(sor->clk_dp);
  1910. clk_disable_unprepare(sor->clk);
  1911. if (IS_ENABLED(CONFIG_DEBUG_FS))
  1912. tegra_sor_debugfs_exit(sor);
  1913. return 0;
  1914. }
  1915. static const struct host1x_client_ops sor_client_ops = {
  1916. .init = tegra_sor_init,
  1917. .exit = tegra_sor_exit,
  1918. };
  1919. static const struct tegra_sor_ops tegra_sor_edp_ops = {
  1920. .name = "eDP",
  1921. };
  1922. static int tegra_sor_hdmi_probe(struct tegra_sor *sor)
  1923. {
  1924. int err;
  1925. sor->avdd_io_supply = devm_regulator_get(sor->dev, "avdd-io");
  1926. if (IS_ERR(sor->avdd_io_supply)) {
  1927. dev_err(sor->dev, "cannot get AVDD I/O supply: %ld\n",
  1928. PTR_ERR(sor->avdd_io_supply));
  1929. return PTR_ERR(sor->avdd_io_supply);
  1930. }
  1931. err = regulator_enable(sor->avdd_io_supply);
  1932. if (err < 0) {
  1933. dev_err(sor->dev, "failed to enable AVDD I/O supply: %d\n",
  1934. err);
  1935. return err;
  1936. }
  1937. sor->vdd_pll_supply = devm_regulator_get(sor->dev, "vdd-pll");
  1938. if (IS_ERR(sor->vdd_pll_supply)) {
  1939. dev_err(sor->dev, "cannot get VDD PLL supply: %ld\n",
  1940. PTR_ERR(sor->vdd_pll_supply));
  1941. return PTR_ERR(sor->vdd_pll_supply);
  1942. }
  1943. err = regulator_enable(sor->vdd_pll_supply);
  1944. if (err < 0) {
  1945. dev_err(sor->dev, "failed to enable VDD PLL supply: %d\n",
  1946. err);
  1947. return err;
  1948. }
  1949. sor->hdmi_supply = devm_regulator_get(sor->dev, "hdmi");
  1950. if (IS_ERR(sor->hdmi_supply)) {
  1951. dev_err(sor->dev, "cannot get HDMI supply: %ld\n",
  1952. PTR_ERR(sor->hdmi_supply));
  1953. return PTR_ERR(sor->hdmi_supply);
  1954. }
  1955. err = regulator_enable(sor->hdmi_supply);
  1956. if (err < 0) {
  1957. dev_err(sor->dev, "failed to enable HDMI supply: %d\n", err);
  1958. return err;
  1959. }
  1960. return 0;
  1961. }
  1962. static int tegra_sor_hdmi_remove(struct tegra_sor *sor)
  1963. {
  1964. regulator_disable(sor->hdmi_supply);
  1965. regulator_disable(sor->vdd_pll_supply);
  1966. regulator_disable(sor->avdd_io_supply);
  1967. return 0;
  1968. }
  1969. static const struct tegra_sor_ops tegra_sor_hdmi_ops = {
  1970. .name = "HDMI",
  1971. .probe = tegra_sor_hdmi_probe,
  1972. .remove = tegra_sor_hdmi_remove,
  1973. };
  1974. static const u8 tegra124_sor_xbar_cfg[5] = {
  1975. 0, 1, 2, 3, 4
  1976. };
  1977. static const struct tegra_sor_soc tegra124_sor = {
  1978. .supports_edp = true,
  1979. .supports_lvds = true,
  1980. .supports_hdmi = false,
  1981. .supports_dp = false,
  1982. .xbar_cfg = tegra124_sor_xbar_cfg,
  1983. };
  1984. static const struct tegra_sor_soc tegra210_sor = {
  1985. .supports_edp = true,
  1986. .supports_lvds = false,
  1987. .supports_hdmi = false,
  1988. .supports_dp = false,
  1989. .xbar_cfg = tegra124_sor_xbar_cfg,
  1990. };
  1991. static const u8 tegra210_sor_xbar_cfg[5] = {
  1992. 2, 1, 0, 3, 4
  1993. };
  1994. static const struct tegra_sor_soc tegra210_sor1 = {
  1995. .supports_edp = false,
  1996. .supports_lvds = false,
  1997. .supports_hdmi = true,
  1998. .supports_dp = true,
  1999. .num_settings = ARRAY_SIZE(tegra210_sor_hdmi_defaults),
  2000. .settings = tegra210_sor_hdmi_defaults,
  2001. .xbar_cfg = tegra210_sor_xbar_cfg,
  2002. };
  2003. static const struct of_device_id tegra_sor_of_match[] = {
  2004. { .compatible = "nvidia,tegra210-sor1", .data = &tegra210_sor1 },
  2005. { .compatible = "nvidia,tegra210-sor", .data = &tegra210_sor },
  2006. { .compatible = "nvidia,tegra124-sor", .data = &tegra124_sor },
  2007. { },
  2008. };
  2009. MODULE_DEVICE_TABLE(of, tegra_sor_of_match);
  2010. static int tegra_sor_probe(struct platform_device *pdev)
  2011. {
  2012. const struct of_device_id *match;
  2013. struct device_node *np;
  2014. struct tegra_sor *sor;
  2015. struct resource *regs;
  2016. int err;
  2017. match = of_match_device(tegra_sor_of_match, &pdev->dev);
  2018. sor = devm_kzalloc(&pdev->dev, sizeof(*sor), GFP_KERNEL);
  2019. if (!sor)
  2020. return -ENOMEM;
  2021. sor->output.dev = sor->dev = &pdev->dev;
  2022. sor->soc = match->data;
  2023. sor->settings = devm_kmemdup(&pdev->dev, sor->soc->settings,
  2024. sor->soc->num_settings *
  2025. sizeof(*sor->settings),
  2026. GFP_KERNEL);
  2027. if (!sor->settings)
  2028. return -ENOMEM;
  2029. sor->num_settings = sor->soc->num_settings;
  2030. np = of_parse_phandle(pdev->dev.of_node, "nvidia,dpaux", 0);
  2031. if (np) {
  2032. sor->aux = drm_dp_aux_find_by_of_node(np);
  2033. of_node_put(np);
  2034. if (!sor->aux)
  2035. return -EPROBE_DEFER;
  2036. }
  2037. if (!sor->aux) {
  2038. if (sor->soc->supports_hdmi) {
  2039. sor->ops = &tegra_sor_hdmi_ops;
  2040. } else if (sor->soc->supports_lvds) {
  2041. dev_err(&pdev->dev, "LVDS not supported yet\n");
  2042. return -ENODEV;
  2043. } else {
  2044. dev_err(&pdev->dev, "unknown (non-DP) support\n");
  2045. return -ENODEV;
  2046. }
  2047. } else {
  2048. if (sor->soc->supports_edp) {
  2049. sor->ops = &tegra_sor_edp_ops;
  2050. } else if (sor->soc->supports_dp) {
  2051. dev_err(&pdev->dev, "DisplayPort not supported yet\n");
  2052. return -ENODEV;
  2053. } else {
  2054. dev_err(&pdev->dev, "unknown (DP) support\n");
  2055. return -ENODEV;
  2056. }
  2057. }
  2058. err = tegra_output_probe(&sor->output);
  2059. if (err < 0) {
  2060. dev_err(&pdev->dev, "failed to probe output: %d\n", err);
  2061. return err;
  2062. }
  2063. if (sor->ops && sor->ops->probe) {
  2064. err = sor->ops->probe(sor);
  2065. if (err < 0) {
  2066. dev_err(&pdev->dev, "failed to probe %s: %d\n",
  2067. sor->ops->name, err);
  2068. goto output;
  2069. }
  2070. }
  2071. regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  2072. sor->regs = devm_ioremap_resource(&pdev->dev, regs);
  2073. if (IS_ERR(sor->regs)) {
  2074. err = PTR_ERR(sor->regs);
  2075. goto remove;
  2076. }
  2077. if (!pdev->dev.pm_domain) {
  2078. sor->rst = devm_reset_control_get(&pdev->dev, "sor");
  2079. if (IS_ERR(sor->rst)) {
  2080. err = PTR_ERR(sor->rst);
  2081. dev_err(&pdev->dev, "failed to get reset control: %d\n",
  2082. err);
  2083. goto remove;
  2084. }
  2085. }
  2086. sor->clk = devm_clk_get(&pdev->dev, NULL);
  2087. if (IS_ERR(sor->clk)) {
  2088. err = PTR_ERR(sor->clk);
  2089. dev_err(&pdev->dev, "failed to get module clock: %d\n", err);
  2090. goto remove;
  2091. }
  2092. if (sor->soc->supports_hdmi || sor->soc->supports_dp) {
  2093. sor->clk_src = devm_clk_get(&pdev->dev, "source");
  2094. if (IS_ERR(sor->clk_src)) {
  2095. err = PTR_ERR(sor->clk_src);
  2096. dev_err(sor->dev, "failed to get source clock: %d\n",
  2097. err);
  2098. goto remove;
  2099. }
  2100. }
  2101. sor->clk_parent = devm_clk_get(&pdev->dev, "parent");
  2102. if (IS_ERR(sor->clk_parent)) {
  2103. err = PTR_ERR(sor->clk_parent);
  2104. dev_err(&pdev->dev, "failed to get parent clock: %d\n", err);
  2105. goto remove;
  2106. }
  2107. sor->clk_safe = devm_clk_get(&pdev->dev, "safe");
  2108. if (IS_ERR(sor->clk_safe)) {
  2109. err = PTR_ERR(sor->clk_safe);
  2110. dev_err(&pdev->dev, "failed to get safe clock: %d\n", err);
  2111. goto remove;
  2112. }
  2113. sor->clk_dp = devm_clk_get(&pdev->dev, "dp");
  2114. if (IS_ERR(sor->clk_dp)) {
  2115. err = PTR_ERR(sor->clk_dp);
  2116. dev_err(&pdev->dev, "failed to get DP clock: %d\n", err);
  2117. goto remove;
  2118. }
  2119. platform_set_drvdata(pdev, sor);
  2120. pm_runtime_enable(&pdev->dev);
  2121. pm_runtime_get_sync(&pdev->dev);
  2122. sor->clk_brick = tegra_clk_sor_brick_register(sor, "sor1_brick");
  2123. pm_runtime_put(&pdev->dev);
  2124. if (IS_ERR(sor->clk_brick)) {
  2125. err = PTR_ERR(sor->clk_brick);
  2126. dev_err(&pdev->dev, "failed to register SOR clock: %d\n", err);
  2127. goto remove;
  2128. }
  2129. INIT_LIST_HEAD(&sor->client.list);
  2130. sor->client.ops = &sor_client_ops;
  2131. sor->client.dev = &pdev->dev;
  2132. err = host1x_client_register(&sor->client);
  2133. if (err < 0) {
  2134. dev_err(&pdev->dev, "failed to register host1x client: %d\n",
  2135. err);
  2136. goto remove;
  2137. }
  2138. return 0;
  2139. remove:
  2140. if (sor->ops && sor->ops->remove)
  2141. sor->ops->remove(sor);
  2142. output:
  2143. tegra_output_remove(&sor->output);
  2144. return err;
  2145. }
  2146. static int tegra_sor_remove(struct platform_device *pdev)
  2147. {
  2148. struct tegra_sor *sor = platform_get_drvdata(pdev);
  2149. int err;
  2150. pm_runtime_disable(&pdev->dev);
  2151. err = host1x_client_unregister(&sor->client);
  2152. if (err < 0) {
  2153. dev_err(&pdev->dev, "failed to unregister host1x client: %d\n",
  2154. err);
  2155. return err;
  2156. }
  2157. if (sor->ops && sor->ops->remove) {
  2158. err = sor->ops->remove(sor);
  2159. if (err < 0)
  2160. dev_err(&pdev->dev, "failed to remove SOR: %d\n", err);
  2161. }
  2162. tegra_output_remove(&sor->output);
  2163. return 0;
  2164. }
  2165. #ifdef CONFIG_PM
  2166. static int tegra_sor_suspend(struct device *dev)
  2167. {
  2168. struct tegra_sor *sor = dev_get_drvdata(dev);
  2169. int err;
  2170. if (sor->rst) {
  2171. err = reset_control_assert(sor->rst);
  2172. if (err < 0) {
  2173. dev_err(dev, "failed to assert reset: %d\n", err);
  2174. return err;
  2175. }
  2176. }
  2177. usleep_range(1000, 2000);
  2178. clk_disable_unprepare(sor->clk);
  2179. return 0;
  2180. }
  2181. static int tegra_sor_resume(struct device *dev)
  2182. {
  2183. struct tegra_sor *sor = dev_get_drvdata(dev);
  2184. int err;
  2185. err = clk_prepare_enable(sor->clk);
  2186. if (err < 0) {
  2187. dev_err(dev, "failed to enable clock: %d\n", err);
  2188. return err;
  2189. }
  2190. usleep_range(1000, 2000);
  2191. if (sor->rst) {
  2192. err = reset_control_deassert(sor->rst);
  2193. if (err < 0) {
  2194. dev_err(dev, "failed to deassert reset: %d\n", err);
  2195. clk_disable_unprepare(sor->clk);
  2196. return err;
  2197. }
  2198. }
  2199. return 0;
  2200. }
  2201. #endif
  2202. static const struct dev_pm_ops tegra_sor_pm_ops = {
  2203. SET_RUNTIME_PM_OPS(tegra_sor_suspend, tegra_sor_resume, NULL)
  2204. };
  2205. struct platform_driver tegra_sor_driver = {
  2206. .driver = {
  2207. .name = "tegra-sor",
  2208. .of_match_table = tegra_sor_of_match,
  2209. .pm = &tegra_sor_pm_ops,
  2210. },
  2211. .probe = tegra_sor_probe,
  2212. .remove = tegra_sor_remove,
  2213. };