sor.c 69 KB

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