sor.c 69 KB

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