hub.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2017 NVIDIA CORPORATION. All rights reserved.
  4. */
  5. #include <linux/clk.h>
  6. #include <linux/delay.h>
  7. #include <linux/dma-mapping.h>
  8. #include <linux/host1x.h>
  9. #include <linux/module.h>
  10. #include <linux/of.h>
  11. #include <linux/of_graph.h>
  12. #include <linux/of_platform.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/pm_runtime.h>
  15. #include <linux/reset.h>
  16. #include <drm/drm_atomic.h>
  17. #include <drm/drm_atomic_helper.h>
  18. #include <drm/drm_blend.h>
  19. #include <drm/drm_fourcc.h>
  20. #include <drm/drm_framebuffer.h>
  21. #include <drm/drm_probe_helper.h>
  22. #include "drm.h"
  23. #include "dc.h"
  24. #include "plane.h"
  25. #define NFB 24
  26. static const u32 tegra_shared_plane_formats[] = {
  27. DRM_FORMAT_ARGB1555,
  28. DRM_FORMAT_RGB565,
  29. DRM_FORMAT_RGBA5551,
  30. DRM_FORMAT_ARGB8888,
  31. DRM_FORMAT_ABGR8888,
  32. /* new on Tegra114 */
  33. DRM_FORMAT_ABGR4444,
  34. DRM_FORMAT_ABGR1555,
  35. DRM_FORMAT_BGRA5551,
  36. DRM_FORMAT_XRGB1555,
  37. DRM_FORMAT_RGBX5551,
  38. DRM_FORMAT_XBGR1555,
  39. DRM_FORMAT_BGRX5551,
  40. DRM_FORMAT_BGR565,
  41. DRM_FORMAT_XRGB8888,
  42. DRM_FORMAT_XBGR8888,
  43. /* planar formats */
  44. DRM_FORMAT_UYVY,
  45. DRM_FORMAT_YUYV,
  46. DRM_FORMAT_YUV420,
  47. DRM_FORMAT_YUV422,
  48. };
  49. static const u64 tegra_shared_plane_modifiers[] = {
  50. DRM_FORMAT_MOD_LINEAR,
  51. DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(0),
  52. DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(1),
  53. DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(2),
  54. DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(3),
  55. DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(4),
  56. DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(5),
  57. /*
  58. * The GPU sector layout is only supported on Tegra194, but these will
  59. * be filtered out later on by ->format_mod_supported() on SoCs where
  60. * it isn't supported.
  61. */
  62. DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(0) | DRM_FORMAT_MOD_NVIDIA_SECTOR_LAYOUT,
  63. DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(1) | DRM_FORMAT_MOD_NVIDIA_SECTOR_LAYOUT,
  64. DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(2) | DRM_FORMAT_MOD_NVIDIA_SECTOR_LAYOUT,
  65. DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(3) | DRM_FORMAT_MOD_NVIDIA_SECTOR_LAYOUT,
  66. DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(4) | DRM_FORMAT_MOD_NVIDIA_SECTOR_LAYOUT,
  67. DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(5) | DRM_FORMAT_MOD_NVIDIA_SECTOR_LAYOUT,
  68. /* sentinel */
  69. DRM_FORMAT_MOD_INVALID
  70. };
  71. static inline unsigned int tegra_plane_offset(struct tegra_plane *plane,
  72. unsigned int offset)
  73. {
  74. if (offset >= 0x500 && offset <= 0x581) {
  75. offset = 0x000 + (offset - 0x500);
  76. return plane->offset + offset;
  77. }
  78. if (offset >= 0x700 && offset <= 0x73c) {
  79. offset = 0x180 + (offset - 0x700);
  80. return plane->offset + offset;
  81. }
  82. if (offset >= 0x800 && offset <= 0x83e) {
  83. offset = 0x1c0 + (offset - 0x800);
  84. return plane->offset + offset;
  85. }
  86. dev_WARN(plane->dc->dev, "invalid offset: %x\n", offset);
  87. return plane->offset + offset;
  88. }
  89. static inline u32 tegra_plane_readl(struct tegra_plane *plane,
  90. unsigned int offset)
  91. {
  92. return tegra_dc_readl(plane->dc, tegra_plane_offset(plane, offset));
  93. }
  94. static inline void tegra_plane_writel(struct tegra_plane *plane, u32 value,
  95. unsigned int offset)
  96. {
  97. tegra_dc_writel(plane->dc, value, tegra_plane_offset(plane, offset));
  98. }
  99. static int tegra_windowgroup_enable(struct tegra_windowgroup *wgrp)
  100. {
  101. int err = 0;
  102. mutex_lock(&wgrp->lock);
  103. if (wgrp->usecount == 0) {
  104. err = host1x_client_resume(wgrp->parent);
  105. if (err < 0) {
  106. dev_err(wgrp->parent->dev, "failed to resume: %d\n", err);
  107. goto unlock;
  108. }
  109. reset_control_deassert(wgrp->rst);
  110. }
  111. wgrp->usecount++;
  112. unlock:
  113. mutex_unlock(&wgrp->lock);
  114. return err;
  115. }
  116. static void tegra_windowgroup_disable(struct tegra_windowgroup *wgrp)
  117. {
  118. int err;
  119. mutex_lock(&wgrp->lock);
  120. if (wgrp->usecount == 1) {
  121. err = reset_control_assert(wgrp->rst);
  122. if (err < 0) {
  123. pr_err("failed to assert reset for window group %u\n",
  124. wgrp->index);
  125. }
  126. host1x_client_suspend(wgrp->parent);
  127. }
  128. wgrp->usecount--;
  129. mutex_unlock(&wgrp->lock);
  130. }
  131. int tegra_display_hub_prepare(struct tegra_display_hub *hub)
  132. {
  133. unsigned int i;
  134. /*
  135. * XXX Enabling/disabling windowgroups needs to happen when the owner
  136. * display controller is disabled. There's currently no good point at
  137. * which this could be executed, so unconditionally enable all window
  138. * groups for now.
  139. */
  140. for (i = 0; i < hub->soc->num_wgrps; i++) {
  141. struct tegra_windowgroup *wgrp = &hub->wgrps[i];
  142. /* Skip orphaned window group whose parent DC is disabled */
  143. if (wgrp->parent)
  144. tegra_windowgroup_enable(wgrp);
  145. }
  146. return 0;
  147. }
  148. void tegra_display_hub_cleanup(struct tegra_display_hub *hub)
  149. {
  150. unsigned int i;
  151. /*
  152. * XXX Remove this once window groups can be more fine-grainedly
  153. * enabled and disabled.
  154. */
  155. for (i = 0; i < hub->soc->num_wgrps; i++) {
  156. struct tegra_windowgroup *wgrp = &hub->wgrps[i];
  157. /* Skip orphaned window group whose parent DC is disabled */
  158. if (wgrp->parent)
  159. tegra_windowgroup_disable(wgrp);
  160. }
  161. }
  162. static void tegra_shared_plane_update(struct tegra_plane *plane)
  163. {
  164. struct tegra_dc *dc = plane->dc;
  165. unsigned long timeout;
  166. u32 mask, value;
  167. mask = COMMON_UPDATE | WIN_A_UPDATE << plane->base.index;
  168. tegra_dc_writel(dc, mask, DC_CMD_STATE_CONTROL);
  169. timeout = jiffies + msecs_to_jiffies(1000);
  170. while (time_before(jiffies, timeout)) {
  171. value = tegra_dc_readl(dc, DC_CMD_STATE_CONTROL);
  172. if ((value & mask) == 0)
  173. break;
  174. usleep_range(100, 400);
  175. }
  176. }
  177. static void tegra_shared_plane_activate(struct tegra_plane *plane)
  178. {
  179. struct tegra_dc *dc = plane->dc;
  180. unsigned long timeout;
  181. u32 mask, value;
  182. mask = COMMON_ACTREQ | WIN_A_ACT_REQ << plane->base.index;
  183. tegra_dc_writel(dc, mask, DC_CMD_STATE_CONTROL);
  184. timeout = jiffies + msecs_to_jiffies(1000);
  185. while (time_before(jiffies, timeout)) {
  186. value = tegra_dc_readl(dc, DC_CMD_STATE_CONTROL);
  187. if ((value & mask) == 0)
  188. break;
  189. usleep_range(100, 400);
  190. }
  191. }
  192. static unsigned int
  193. tegra_shared_plane_get_owner(struct tegra_plane *plane, struct tegra_dc *dc)
  194. {
  195. unsigned int offset =
  196. tegra_plane_offset(plane, DC_WIN_CORE_WINDOWGROUP_SET_CONTROL);
  197. return tegra_dc_readl(dc, offset) & OWNER_MASK;
  198. }
  199. static bool tegra_dc_owns_shared_plane(struct tegra_dc *dc,
  200. struct tegra_plane *plane)
  201. {
  202. struct device *dev = dc->dev;
  203. if (tegra_shared_plane_get_owner(plane, dc) == dc->pipe) {
  204. if (plane->dc == dc)
  205. return true;
  206. dev_WARN(dev, "head %u owns window %u but is not attached\n",
  207. dc->pipe, plane->index);
  208. }
  209. return false;
  210. }
  211. static int tegra_shared_plane_set_owner(struct tegra_plane *plane,
  212. struct tegra_dc *new)
  213. {
  214. unsigned int offset =
  215. tegra_plane_offset(plane, DC_WIN_CORE_WINDOWGROUP_SET_CONTROL);
  216. struct tegra_dc *old = plane->dc, *dc = new ? new : old;
  217. struct device *dev = new ? new->dev : old->dev;
  218. unsigned int owner, index = plane->index;
  219. u32 value;
  220. value = tegra_dc_readl(dc, offset);
  221. owner = value & OWNER_MASK;
  222. if (new && (owner != OWNER_MASK && owner != new->pipe)) {
  223. dev_WARN(dev, "window %u owned by head %u\n", index, owner);
  224. return -EBUSY;
  225. }
  226. /*
  227. * This seems to happen whenever the head has been disabled with one
  228. * or more windows being active. This is harmless because we'll just
  229. * reassign the window to the new head anyway.
  230. */
  231. if (old && owner == OWNER_MASK)
  232. dev_dbg(dev, "window %u not owned by head %u but %u\n", index,
  233. old->pipe, owner);
  234. value &= ~OWNER_MASK;
  235. if (new)
  236. value |= OWNER(new->pipe);
  237. else
  238. value |= OWNER_MASK;
  239. tegra_dc_writel(dc, value, offset);
  240. plane->dc = new;
  241. return 0;
  242. }
  243. static void tegra_shared_plane_setup_scaler(struct tegra_plane *plane)
  244. {
  245. static const unsigned int coeffs[192] = {
  246. 0x00000000, 0x3c70e400, 0x3bb037e4, 0x0c51cc9c,
  247. 0x00100001, 0x3bf0dbfa, 0x3d00f406, 0x3fe003ff,
  248. 0x00300002, 0x3b80cbf5, 0x3da1040d, 0x3fb003fe,
  249. 0x00400002, 0x3b20bff1, 0x3e511015, 0x3f9003fc,
  250. 0x00500002, 0x3ad0b3ed, 0x3f21201d, 0x3f5003fb,
  251. 0x00500003, 0x3aa0a3e9, 0x3ff13026, 0x3f2007f9,
  252. 0x00500403, 0x3a7097e6, 0x00e1402f, 0x3ee007f7,
  253. 0x00500403, 0x3a608be4, 0x01d14c38, 0x3ea00bf6,
  254. 0x00500403, 0x3a507fe2, 0x02e15c42, 0x3e500ff4,
  255. 0x00500402, 0x3a6073e1, 0x03f16c4d, 0x3e000ff2,
  256. 0x00400402, 0x3a706be0, 0x05117858, 0x3db013f0,
  257. 0x00300402, 0x3a905fe0, 0x06318863, 0x3d6017ee,
  258. 0x00300402, 0x3ab057e0, 0x0771986e, 0x3d001beb,
  259. 0x00200001, 0x3af04fe1, 0x08a1a47a, 0x3cb023e9,
  260. 0x00100001, 0x3b2047e2, 0x09e1b485, 0x3c6027e7,
  261. 0x00100000, 0x3b703fe2, 0x0b11c091, 0x3c002fe6,
  262. 0x3f203800, 0x0391103f, 0x3ff0a014, 0x0811606c,
  263. 0x3f2037ff, 0x0351083c, 0x03e11842, 0x3f203c00,
  264. 0x3f302fff, 0x03010439, 0x04311c45, 0x3f104401,
  265. 0x3f302fff, 0x02c0fc35, 0x04812448, 0x3f104802,
  266. 0x3f4027ff, 0x0270f832, 0x04c1284b, 0x3f205003,
  267. 0x3f4023ff, 0x0230f030, 0x0511304e, 0x3f205403,
  268. 0x3f601fff, 0x01f0e82d, 0x05613451, 0x3f205c04,
  269. 0x3f701bfe, 0x01b0e02a, 0x05a13c54, 0x3f306006,
  270. 0x3f7017fe, 0x0170d827, 0x05f14057, 0x3f406807,
  271. 0x3f8017ff, 0x0140d424, 0x0641445a, 0x3f406c08,
  272. 0x3fa013ff, 0x0100cc22, 0x0681485d, 0x3f507409,
  273. 0x3fa00fff, 0x00d0c41f, 0x06d14c60, 0x3f607c0b,
  274. 0x3fc00fff, 0x0090bc1c, 0x07115063, 0x3f80840c,
  275. 0x3fd00bff, 0x0070b41a, 0x07515465, 0x3f908c0e,
  276. 0x3fe007ff, 0x0040b018, 0x07915868, 0x3fb0900f,
  277. 0x3ff00400, 0x0010a816, 0x07d15c6a, 0x3fd09811,
  278. 0x00a04c0e, 0x0460f442, 0x0240a827, 0x05c15859,
  279. 0x0090440d, 0x0440f040, 0x0480fc43, 0x00b05010,
  280. 0x0080400c, 0x0410ec3e, 0x04910044, 0x00d05411,
  281. 0x0070380b, 0x03f0e83d, 0x04b10846, 0x00e05812,
  282. 0x0060340a, 0x03d0e43b, 0x04d10c48, 0x00f06013,
  283. 0x00503009, 0x03b0e039, 0x04e11449, 0x01106415,
  284. 0x00402c08, 0x0390d838, 0x05011c4b, 0x01206c16,
  285. 0x00302807, 0x0370d436, 0x0511204c, 0x01407018,
  286. 0x00302406, 0x0340d034, 0x0531244e, 0x01507419,
  287. 0x00202005, 0x0320cc32, 0x05412c50, 0x01707c1b,
  288. 0x00101c04, 0x0300c431, 0x05613451, 0x0180801d,
  289. 0x00101803, 0x02e0c02f, 0x05713853, 0x01a0881e,
  290. 0x00101002, 0x02b0bc2d, 0x05814054, 0x01c08c20,
  291. 0x00000c02, 0x02a0b82c, 0x05914455, 0x01e09421,
  292. 0x00000801, 0x0280b02a, 0x05a14c57, 0x02009c23,
  293. 0x00000400, 0x0260ac28, 0x05b15458, 0x0220a025,
  294. };
  295. unsigned int ratio, row, column;
  296. for (ratio = 0; ratio <= 2; ratio++) {
  297. for (row = 0; row <= 15; row++) {
  298. for (column = 0; column <= 3; column++) {
  299. unsigned int index = (ratio << 6) + (row << 2) + column;
  300. u32 value;
  301. value = COEFF_INDEX(index) | COEFF_DATA(coeffs[index]);
  302. tegra_plane_writel(plane, value,
  303. DC_WIN_WINDOWGROUP_SET_INPUT_SCALER_COEFF);
  304. }
  305. }
  306. }
  307. }
  308. static void tegra_dc_assign_shared_plane(struct tegra_dc *dc,
  309. struct tegra_plane *plane)
  310. {
  311. u32 value;
  312. int err;
  313. if (!tegra_dc_owns_shared_plane(dc, plane)) {
  314. err = tegra_shared_plane_set_owner(plane, dc);
  315. if (err < 0)
  316. return;
  317. }
  318. value = tegra_plane_readl(plane, DC_WIN_CORE_IHUB_LINEBUF_CONFIG);
  319. value |= MODE_FOUR_LINES;
  320. tegra_plane_writel(plane, value, DC_WIN_CORE_IHUB_LINEBUF_CONFIG);
  321. value = tegra_plane_readl(plane, DC_WIN_CORE_IHUB_WGRP_FETCH_METER);
  322. value = SLOTS(1);
  323. tegra_plane_writel(plane, value, DC_WIN_CORE_IHUB_WGRP_FETCH_METER);
  324. /* disable watermark */
  325. value = tegra_plane_readl(plane, DC_WIN_CORE_IHUB_WGRP_LATENCY_CTLA);
  326. value &= ~LATENCY_CTL_MODE_ENABLE;
  327. tegra_plane_writel(plane, value, DC_WIN_CORE_IHUB_WGRP_LATENCY_CTLA);
  328. value = tegra_plane_readl(plane, DC_WIN_CORE_IHUB_WGRP_LATENCY_CTLB);
  329. value |= WATERMARK_MASK;
  330. tegra_plane_writel(plane, value, DC_WIN_CORE_IHUB_WGRP_LATENCY_CTLB);
  331. /* pipe meter */
  332. value = tegra_plane_readl(plane, DC_WIN_CORE_PRECOMP_WGRP_PIPE_METER);
  333. value = PIPE_METER_INT(0) | PIPE_METER_FRAC(0);
  334. tegra_plane_writel(plane, value, DC_WIN_CORE_PRECOMP_WGRP_PIPE_METER);
  335. /* mempool entries */
  336. value = tegra_plane_readl(plane, DC_WIN_CORE_IHUB_WGRP_POOL_CONFIG);
  337. value = MEMPOOL_ENTRIES(0x331);
  338. tegra_plane_writel(plane, value, DC_WIN_CORE_IHUB_WGRP_POOL_CONFIG);
  339. value = tegra_plane_readl(plane, DC_WIN_CORE_IHUB_THREAD_GROUP);
  340. value &= ~THREAD_NUM_MASK;
  341. value |= THREAD_NUM(plane->base.index);
  342. value |= THREAD_GROUP_ENABLE;
  343. tegra_plane_writel(plane, value, DC_WIN_CORE_IHUB_THREAD_GROUP);
  344. tegra_shared_plane_setup_scaler(plane);
  345. tegra_shared_plane_update(plane);
  346. tegra_shared_plane_activate(plane);
  347. }
  348. static void tegra_dc_remove_shared_plane(struct tegra_dc *dc,
  349. struct tegra_plane *plane)
  350. {
  351. tegra_shared_plane_set_owner(plane, NULL);
  352. }
  353. static int tegra_shared_plane_atomic_check(struct drm_plane *plane,
  354. struct drm_atomic_state *state)
  355. {
  356. struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state,
  357. plane);
  358. struct tegra_plane_state *plane_state = to_tegra_plane_state(new_plane_state);
  359. struct tegra_shared_plane *tegra = to_tegra_shared_plane(plane);
  360. struct tegra_bo_tiling *tiling = &plane_state->tiling;
  361. struct tegra_dc *dc = to_tegra_dc(new_plane_state->crtc);
  362. int err;
  363. /* no need for further checks if the plane is being disabled */
  364. if (!new_plane_state->crtc || !new_plane_state->fb)
  365. return 0;
  366. err = tegra_plane_format(new_plane_state->fb->format->format,
  367. &plane_state->format,
  368. &plane_state->swap);
  369. if (err < 0)
  370. return err;
  371. err = tegra_fb_get_tiling(new_plane_state->fb, tiling);
  372. if (err < 0)
  373. return err;
  374. if (tiling->mode == TEGRA_BO_TILING_MODE_BLOCK &&
  375. !dc->soc->supports_block_linear) {
  376. DRM_ERROR("hardware doesn't support block linear mode\n");
  377. return -EINVAL;
  378. }
  379. if (tiling->sector_layout == TEGRA_BO_SECTOR_LAYOUT_GPU &&
  380. !dc->soc->supports_sector_layout) {
  381. DRM_ERROR("hardware doesn't support GPU sector layout\n");
  382. return -EINVAL;
  383. }
  384. /*
  385. * Tegra doesn't support different strides for U and V planes so we
  386. * error out if the user tries to display a framebuffer with such a
  387. * configuration.
  388. */
  389. if (new_plane_state->fb->format->num_planes > 2) {
  390. if (new_plane_state->fb->pitches[2] != new_plane_state->fb->pitches[1]) {
  391. DRM_ERROR("unsupported UV-plane configuration\n");
  392. return -EINVAL;
  393. }
  394. }
  395. /* XXX scaling is not yet supported, add a check here */
  396. err = tegra_plane_state_add(&tegra->base, new_plane_state);
  397. if (err < 0)
  398. return err;
  399. return 0;
  400. }
  401. static void tegra_shared_plane_atomic_disable(struct drm_plane *plane,
  402. struct drm_atomic_state *state)
  403. {
  404. struct drm_plane_state *old_state = drm_atomic_get_old_plane_state(state,
  405. plane);
  406. struct tegra_plane *p = to_tegra_plane(plane);
  407. struct tegra_dc *dc;
  408. u32 value;
  409. int err;
  410. /* rien ne va plus */
  411. if (!old_state || !old_state->crtc)
  412. return;
  413. dc = to_tegra_dc(old_state->crtc);
  414. err = host1x_client_resume(&dc->client);
  415. if (err < 0) {
  416. dev_err(dc->dev, "failed to resume: %d\n", err);
  417. return;
  418. }
  419. /*
  420. * XXX Legacy helpers seem to sometimes call ->atomic_disable() even
  421. * on planes that are already disabled. Make sure we fallback to the
  422. * head for this particular state instead of crashing.
  423. */
  424. if (WARN_ON(p->dc == NULL))
  425. p->dc = dc;
  426. value = tegra_plane_readl(p, DC_WIN_WIN_OPTIONS);
  427. value &= ~WIN_ENABLE;
  428. tegra_plane_writel(p, value, DC_WIN_WIN_OPTIONS);
  429. tegra_dc_remove_shared_plane(dc, p);
  430. host1x_client_suspend(&dc->client);
  431. }
  432. static inline u32 compute_phase_incr(fixed20_12 in, unsigned int out)
  433. {
  434. u64 tmp, tmp1;
  435. tmp = (u64)dfixed_trunc(in);
  436. tmp1 = (tmp << NFB) + ((u64)out >> 1);
  437. do_div(tmp1, out);
  438. return lower_32_bits(tmp1);
  439. }
  440. static void tegra_shared_plane_atomic_update(struct drm_plane *plane,
  441. struct drm_atomic_state *state)
  442. {
  443. struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state,
  444. plane);
  445. struct tegra_plane_state *tegra_plane_state = to_tegra_plane_state(new_state);
  446. struct tegra_dc *dc = to_tegra_dc(new_state->crtc);
  447. unsigned int zpos = new_state->normalized_zpos;
  448. struct drm_framebuffer *fb = new_state->fb;
  449. struct tegra_plane *p = to_tegra_plane(plane);
  450. u32 value, min_width, bypass = 0;
  451. dma_addr_t base, addr_flag = 0;
  452. unsigned int bpc, planes;
  453. bool yuv;
  454. int err;
  455. /* rien ne va plus */
  456. if (!new_state->crtc || !new_state->fb)
  457. return;
  458. if (!new_state->visible) {
  459. tegra_shared_plane_atomic_disable(plane, state);
  460. return;
  461. }
  462. err = host1x_client_resume(&dc->client);
  463. if (err < 0) {
  464. dev_err(dc->dev, "failed to resume: %d\n", err);
  465. return;
  466. }
  467. yuv = tegra_plane_format_is_yuv(tegra_plane_state->format, &planes, &bpc);
  468. tegra_dc_assign_shared_plane(dc, p);
  469. tegra_plane_writel(p, VCOUNTER, DC_WIN_CORE_ACT_CONTROL);
  470. /* blending */
  471. value = BLEND_FACTOR_DST_ALPHA_ZERO | BLEND_FACTOR_SRC_ALPHA_K2 |
  472. BLEND_FACTOR_DST_COLOR_NEG_K1_TIMES_SRC |
  473. BLEND_FACTOR_SRC_COLOR_K1_TIMES_SRC;
  474. tegra_plane_writel(p, value, DC_WIN_BLEND_MATCH_SELECT);
  475. value = BLEND_FACTOR_DST_ALPHA_ZERO | BLEND_FACTOR_SRC_ALPHA_K2 |
  476. BLEND_FACTOR_DST_COLOR_NEG_K1_TIMES_SRC |
  477. BLEND_FACTOR_SRC_COLOR_K1_TIMES_SRC;
  478. tegra_plane_writel(p, value, DC_WIN_BLEND_NOMATCH_SELECT);
  479. value = K2(255) | K1(255) | WINDOW_LAYER_DEPTH(255 - zpos);
  480. tegra_plane_writel(p, value, DC_WIN_BLEND_LAYER_CONTROL);
  481. /* scaling */
  482. min_width = min(new_state->src_w >> 16, new_state->crtc_w);
  483. value = tegra_plane_readl(p, DC_WINC_PRECOMP_WGRP_PIPE_CAPC);
  484. if (min_width < MAX_PIXELS_5TAP444(value)) {
  485. value = HORIZONTAL_TAPS_5 | VERTICAL_TAPS_5;
  486. } else {
  487. value = tegra_plane_readl(p, DC_WINC_PRECOMP_WGRP_PIPE_CAPE);
  488. if (min_width < MAX_PIXELS_2TAP444(value))
  489. value = HORIZONTAL_TAPS_2 | VERTICAL_TAPS_2;
  490. else
  491. dev_err(dc->dev, "invalid minimum width: %u\n", min_width);
  492. }
  493. value = HORIZONTAL_TAPS_5 | VERTICAL_TAPS_5;
  494. tegra_plane_writel(p, value, DC_WIN_WINDOWGROUP_SET_CONTROL_INPUT_SCALER);
  495. if (new_state->src_w != new_state->crtc_w << 16) {
  496. fixed20_12 width = dfixed_init(new_state->src_w >> 16);
  497. u32 incr = compute_phase_incr(width, new_state->crtc_w) & ~0x1;
  498. u32 init = (1 << (NFB - 1)) + (incr >> 1);
  499. tegra_plane_writel(p, incr, DC_WIN_SET_INPUT_SCALER_HPHASE_INCR);
  500. tegra_plane_writel(p, init, DC_WIN_SET_INPUT_SCALER_H_START_PHASE);
  501. } else {
  502. bypass |= INPUT_SCALER_HBYPASS;
  503. }
  504. if (new_state->src_h != new_state->crtc_h << 16) {
  505. fixed20_12 height = dfixed_init(new_state->src_h >> 16);
  506. u32 incr = compute_phase_incr(height, new_state->crtc_h) & ~0x1;
  507. u32 init = (1 << (NFB - 1)) + (incr >> 1);
  508. tegra_plane_writel(p, incr, DC_WIN_SET_INPUT_SCALER_VPHASE_INCR);
  509. tegra_plane_writel(p, init, DC_WIN_SET_INPUT_SCALER_V_START_PHASE);
  510. } else {
  511. bypass |= INPUT_SCALER_VBYPASS;
  512. }
  513. tegra_plane_writel(p, bypass, DC_WIN_WINDOWGROUP_SET_INPUT_SCALER_USAGE);
  514. /* disable compression */
  515. tegra_plane_writel(p, 0, DC_WINBUF_CDE_CONTROL);
  516. #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
  517. /*
  518. * Physical address bit 39 in Tegra194 is used as a switch for special
  519. * logic that swizzles the memory using either the legacy Tegra or the
  520. * dGPU sector layout.
  521. */
  522. if (tegra_plane_state->tiling.sector_layout == TEGRA_BO_SECTOR_LAYOUT_GPU)
  523. addr_flag = BIT_ULL(39);
  524. #endif
  525. base = tegra_plane_state->iova[0] + fb->offsets[0];
  526. base |= addr_flag;
  527. tegra_plane_writel(p, tegra_plane_state->format, DC_WIN_COLOR_DEPTH);
  528. tegra_plane_writel(p, 0, DC_WIN_PRECOMP_WGRP_PARAMS);
  529. value = V_POSITION(new_state->crtc_y) |
  530. H_POSITION(new_state->crtc_x);
  531. tegra_plane_writel(p, value, DC_WIN_POSITION);
  532. value = V_SIZE(new_state->crtc_h) | H_SIZE(new_state->crtc_w);
  533. tegra_plane_writel(p, value, DC_WIN_SIZE);
  534. value = WIN_ENABLE | COLOR_EXPAND;
  535. tegra_plane_writel(p, value, DC_WIN_WIN_OPTIONS);
  536. value = V_SIZE(new_state->src_h >> 16) | H_SIZE(new_state->src_w >> 16);
  537. tegra_plane_writel(p, value, DC_WIN_CROPPED_SIZE);
  538. tegra_plane_writel(p, upper_32_bits(base), DC_WINBUF_START_ADDR_HI);
  539. tegra_plane_writel(p, lower_32_bits(base), DC_WINBUF_START_ADDR);
  540. value = PITCH(fb->pitches[0]);
  541. tegra_plane_writel(p, value, DC_WIN_PLANAR_STORAGE);
  542. if (yuv && planes > 1) {
  543. base = tegra_plane_state->iova[1] + fb->offsets[1];
  544. base |= addr_flag;
  545. tegra_plane_writel(p, upper_32_bits(base), DC_WINBUF_START_ADDR_HI_U);
  546. tegra_plane_writel(p, lower_32_bits(base), DC_WINBUF_START_ADDR_U);
  547. if (planes > 2) {
  548. base = tegra_plane_state->iova[2] + fb->offsets[2];
  549. base |= addr_flag;
  550. tegra_plane_writel(p, upper_32_bits(base), DC_WINBUF_START_ADDR_HI_V);
  551. tegra_plane_writel(p, lower_32_bits(base), DC_WINBUF_START_ADDR_V);
  552. }
  553. value = PITCH_U(fb->pitches[1]);
  554. if (planes > 2)
  555. value |= PITCH_V(fb->pitches[2]);
  556. tegra_plane_writel(p, value, DC_WIN_PLANAR_STORAGE_UV);
  557. } else {
  558. tegra_plane_writel(p, 0, DC_WINBUF_START_ADDR_U);
  559. tegra_plane_writel(p, 0, DC_WINBUF_START_ADDR_HI_U);
  560. tegra_plane_writel(p, 0, DC_WINBUF_START_ADDR_V);
  561. tegra_plane_writel(p, 0, DC_WINBUF_START_ADDR_HI_V);
  562. tegra_plane_writel(p, 0, DC_WIN_PLANAR_STORAGE_UV);
  563. }
  564. value = CLAMP_BEFORE_BLEND | INPUT_RANGE_FULL;
  565. if (yuv) {
  566. if (bpc < 12)
  567. value |= DEGAMMA_YUV8_10;
  568. else
  569. value |= DEGAMMA_YUV12;
  570. /* XXX parameterize */
  571. value |= COLOR_SPACE_YUV_2020;
  572. } else {
  573. if (!tegra_plane_format_is_indexed(tegra_plane_state->format))
  574. value |= DEGAMMA_SRGB;
  575. }
  576. tegra_plane_writel(p, value, DC_WIN_SET_PARAMS);
  577. value = OFFSET_X(new_state->src_y >> 16) |
  578. OFFSET_Y(new_state->src_x >> 16);
  579. tegra_plane_writel(p, value, DC_WINBUF_CROPPED_POINT);
  580. if (dc->soc->supports_block_linear) {
  581. unsigned long height = tegra_plane_state->tiling.value;
  582. /* XXX */
  583. switch (tegra_plane_state->tiling.mode) {
  584. case TEGRA_BO_TILING_MODE_PITCH:
  585. value = DC_WINBUF_SURFACE_KIND_BLOCK_HEIGHT(0) |
  586. DC_WINBUF_SURFACE_KIND_PITCH;
  587. break;
  588. /* XXX not supported on Tegra186 and later */
  589. case TEGRA_BO_TILING_MODE_TILED:
  590. value = DC_WINBUF_SURFACE_KIND_TILED;
  591. break;
  592. case TEGRA_BO_TILING_MODE_BLOCK:
  593. value = DC_WINBUF_SURFACE_KIND_BLOCK_HEIGHT(height) |
  594. DC_WINBUF_SURFACE_KIND_BLOCK;
  595. break;
  596. }
  597. tegra_plane_writel(p, value, DC_WINBUF_SURFACE_KIND);
  598. }
  599. /* disable gamut CSC */
  600. value = tegra_plane_readl(p, DC_WIN_WINDOW_SET_CONTROL);
  601. value &= ~CONTROL_CSC_ENABLE;
  602. tegra_plane_writel(p, value, DC_WIN_WINDOW_SET_CONTROL);
  603. host1x_client_suspend(&dc->client);
  604. }
  605. static const struct drm_plane_helper_funcs tegra_shared_plane_helper_funcs = {
  606. .prepare_fb = tegra_plane_prepare_fb,
  607. .cleanup_fb = tegra_plane_cleanup_fb,
  608. .atomic_check = tegra_shared_plane_atomic_check,
  609. .atomic_update = tegra_shared_plane_atomic_update,
  610. .atomic_disable = tegra_shared_plane_atomic_disable,
  611. };
  612. struct drm_plane *tegra_shared_plane_create(struct drm_device *drm,
  613. struct tegra_dc *dc,
  614. unsigned int wgrp,
  615. unsigned int index,
  616. enum drm_plane_type type)
  617. {
  618. struct tegra_drm *tegra = drm->dev_private;
  619. struct tegra_display_hub *hub = tegra->hub;
  620. struct tegra_shared_plane *plane;
  621. unsigned int possible_crtcs;
  622. unsigned int num_formats;
  623. const u64 *modifiers;
  624. struct drm_plane *p;
  625. const u32 *formats;
  626. int err;
  627. plane = kzalloc(sizeof(*plane), GFP_KERNEL);
  628. if (!plane)
  629. return ERR_PTR(-ENOMEM);
  630. plane->base.offset = 0x0a00 + 0x0300 * index;
  631. plane->base.index = index;
  632. plane->wgrp = &hub->wgrps[wgrp];
  633. plane->wgrp->parent = &dc->client;
  634. p = &plane->base.base;
  635. /* planes can be assigned to arbitrary CRTCs */
  636. possible_crtcs = BIT(tegra->num_crtcs) - 1;
  637. num_formats = ARRAY_SIZE(tegra_shared_plane_formats);
  638. formats = tegra_shared_plane_formats;
  639. modifiers = tegra_shared_plane_modifiers;
  640. err = drm_universal_plane_init(drm, p, possible_crtcs,
  641. &tegra_plane_funcs, formats,
  642. num_formats, modifiers, type, NULL);
  643. if (err < 0) {
  644. kfree(plane);
  645. return ERR_PTR(err);
  646. }
  647. drm_plane_helper_add(p, &tegra_shared_plane_helper_funcs);
  648. drm_plane_create_zpos_property(p, 0, 0, 255);
  649. return p;
  650. }
  651. static struct drm_private_state *
  652. tegra_display_hub_duplicate_state(struct drm_private_obj *obj)
  653. {
  654. struct tegra_display_hub_state *state;
  655. state = kmemdup(obj->state, sizeof(*state), GFP_KERNEL);
  656. if (!state)
  657. return NULL;
  658. __drm_atomic_helper_private_obj_duplicate_state(obj, &state->base);
  659. return &state->base;
  660. }
  661. static void tegra_display_hub_destroy_state(struct drm_private_obj *obj,
  662. struct drm_private_state *state)
  663. {
  664. struct tegra_display_hub_state *hub_state =
  665. to_tegra_display_hub_state(state);
  666. kfree(hub_state);
  667. }
  668. static const struct drm_private_state_funcs tegra_display_hub_state_funcs = {
  669. .atomic_duplicate_state = tegra_display_hub_duplicate_state,
  670. .atomic_destroy_state = tegra_display_hub_destroy_state,
  671. };
  672. static struct tegra_display_hub_state *
  673. tegra_display_hub_get_state(struct tegra_display_hub *hub,
  674. struct drm_atomic_state *state)
  675. {
  676. struct drm_private_state *priv;
  677. priv = drm_atomic_get_private_obj_state(state, &hub->base);
  678. if (IS_ERR(priv))
  679. return ERR_CAST(priv);
  680. return to_tegra_display_hub_state(priv);
  681. }
  682. int tegra_display_hub_atomic_check(struct drm_device *drm,
  683. struct drm_atomic_state *state)
  684. {
  685. struct tegra_drm *tegra = drm->dev_private;
  686. struct tegra_display_hub_state *hub_state;
  687. struct drm_crtc_state *old, *new;
  688. struct drm_crtc *crtc;
  689. unsigned int i;
  690. if (!tegra->hub)
  691. return 0;
  692. hub_state = tegra_display_hub_get_state(tegra->hub, state);
  693. if (IS_ERR(hub_state))
  694. return PTR_ERR(hub_state);
  695. /*
  696. * The display hub display clock needs to be fed by the display clock
  697. * with the highest frequency to ensure proper functioning of all the
  698. * displays.
  699. *
  700. * Note that this isn't used before Tegra186, but it doesn't hurt and
  701. * conditionalizing it would make the code less clean.
  702. */
  703. for_each_oldnew_crtc_in_state(state, crtc, old, new, i) {
  704. struct tegra_dc_state *dc = to_dc_state(new);
  705. if (new->active) {
  706. if (!hub_state->clk || dc->pclk > hub_state->rate) {
  707. hub_state->dc = to_tegra_dc(dc->base.crtc);
  708. hub_state->clk = hub_state->dc->clk;
  709. hub_state->rate = dc->pclk;
  710. }
  711. }
  712. }
  713. return 0;
  714. }
  715. static void tegra_display_hub_update(struct tegra_dc *dc)
  716. {
  717. u32 value;
  718. int err;
  719. err = host1x_client_resume(&dc->client);
  720. if (err < 0) {
  721. dev_err(dc->dev, "failed to resume: %d\n", err);
  722. return;
  723. }
  724. value = tegra_dc_readl(dc, DC_CMD_IHUB_COMMON_MISC_CTL);
  725. value &= ~LATENCY_EVENT;
  726. tegra_dc_writel(dc, value, DC_CMD_IHUB_COMMON_MISC_CTL);
  727. value = tegra_dc_readl(dc, DC_DISP_IHUB_COMMON_DISPLAY_FETCH_METER);
  728. value = CURS_SLOTS(1) | WGRP_SLOTS(1);
  729. tegra_dc_writel(dc, value, DC_DISP_IHUB_COMMON_DISPLAY_FETCH_METER);
  730. tegra_dc_writel(dc, COMMON_UPDATE, DC_CMD_STATE_CONTROL);
  731. tegra_dc_readl(dc, DC_CMD_STATE_CONTROL);
  732. tegra_dc_writel(dc, COMMON_ACTREQ, DC_CMD_STATE_CONTROL);
  733. tegra_dc_readl(dc, DC_CMD_STATE_CONTROL);
  734. host1x_client_suspend(&dc->client);
  735. }
  736. void tegra_display_hub_atomic_commit(struct drm_device *drm,
  737. struct drm_atomic_state *state)
  738. {
  739. struct tegra_drm *tegra = drm->dev_private;
  740. struct tegra_display_hub *hub = tegra->hub;
  741. struct tegra_display_hub_state *hub_state;
  742. struct device *dev = hub->client.dev;
  743. int err;
  744. hub_state = to_tegra_display_hub_state(hub->base.state);
  745. if (hub_state->clk) {
  746. err = clk_set_rate(hub_state->clk, hub_state->rate);
  747. if (err < 0)
  748. dev_err(dev, "failed to set rate of %pC to %lu Hz\n",
  749. hub_state->clk, hub_state->rate);
  750. err = clk_set_parent(hub->clk_disp, hub_state->clk);
  751. if (err < 0)
  752. dev_err(dev, "failed to set parent of %pC to %pC: %d\n",
  753. hub->clk_disp, hub_state->clk, err);
  754. }
  755. if (hub_state->dc)
  756. tegra_display_hub_update(hub_state->dc);
  757. }
  758. static int tegra_display_hub_init(struct host1x_client *client)
  759. {
  760. struct tegra_display_hub *hub = to_tegra_display_hub(client);
  761. struct drm_device *drm = dev_get_drvdata(client->host);
  762. struct tegra_drm *tegra = drm->dev_private;
  763. struct tegra_display_hub_state *state;
  764. state = kzalloc(sizeof(*state), GFP_KERNEL);
  765. if (!state)
  766. return -ENOMEM;
  767. drm_atomic_private_obj_init(drm, &hub->base, &state->base,
  768. &tegra_display_hub_state_funcs);
  769. tegra->hub = hub;
  770. return 0;
  771. }
  772. static int tegra_display_hub_exit(struct host1x_client *client)
  773. {
  774. struct drm_device *drm = dev_get_drvdata(client->host);
  775. struct tegra_drm *tegra = drm->dev_private;
  776. drm_atomic_private_obj_fini(&tegra->hub->base);
  777. tegra->hub = NULL;
  778. return 0;
  779. }
  780. static int tegra_display_hub_runtime_suspend(struct host1x_client *client)
  781. {
  782. struct tegra_display_hub *hub = to_tegra_display_hub(client);
  783. struct device *dev = client->dev;
  784. unsigned int i = hub->num_heads;
  785. int err;
  786. err = reset_control_assert(hub->rst);
  787. if (err < 0)
  788. return err;
  789. while (i--)
  790. clk_disable_unprepare(hub->clk_heads[i]);
  791. clk_disable_unprepare(hub->clk_hub);
  792. clk_disable_unprepare(hub->clk_dsc);
  793. clk_disable_unprepare(hub->clk_disp);
  794. pm_runtime_put_sync(dev);
  795. return 0;
  796. }
  797. static int tegra_display_hub_runtime_resume(struct host1x_client *client)
  798. {
  799. struct tegra_display_hub *hub = to_tegra_display_hub(client);
  800. struct device *dev = client->dev;
  801. unsigned int i;
  802. int err;
  803. err = pm_runtime_resume_and_get(dev);
  804. if (err < 0) {
  805. dev_err(dev, "failed to get runtime PM: %d\n", err);
  806. return err;
  807. }
  808. err = clk_prepare_enable(hub->clk_disp);
  809. if (err < 0)
  810. goto put_rpm;
  811. err = clk_prepare_enable(hub->clk_dsc);
  812. if (err < 0)
  813. goto disable_disp;
  814. err = clk_prepare_enable(hub->clk_hub);
  815. if (err < 0)
  816. goto disable_dsc;
  817. for (i = 0; i < hub->num_heads; i++) {
  818. err = clk_prepare_enable(hub->clk_heads[i]);
  819. if (err < 0)
  820. goto disable_heads;
  821. }
  822. err = reset_control_deassert(hub->rst);
  823. if (err < 0)
  824. goto disable_heads;
  825. return 0;
  826. disable_heads:
  827. while (i--)
  828. clk_disable_unprepare(hub->clk_heads[i]);
  829. clk_disable_unprepare(hub->clk_hub);
  830. disable_dsc:
  831. clk_disable_unprepare(hub->clk_dsc);
  832. disable_disp:
  833. clk_disable_unprepare(hub->clk_disp);
  834. put_rpm:
  835. pm_runtime_put_sync(dev);
  836. return err;
  837. }
  838. static const struct host1x_client_ops tegra_display_hub_ops = {
  839. .init = tegra_display_hub_init,
  840. .exit = tegra_display_hub_exit,
  841. .suspend = tegra_display_hub_runtime_suspend,
  842. .resume = tegra_display_hub_runtime_resume,
  843. };
  844. static int tegra_display_hub_probe(struct platform_device *pdev)
  845. {
  846. u64 dma_mask = dma_get_mask(pdev->dev.parent);
  847. struct device_node *child = NULL;
  848. struct tegra_display_hub *hub;
  849. struct clk *clk;
  850. unsigned int i;
  851. int err;
  852. err = dma_coerce_mask_and_coherent(&pdev->dev, dma_mask);
  853. if (err < 0) {
  854. dev_err(&pdev->dev, "failed to set DMA mask: %d\n", err);
  855. return err;
  856. }
  857. hub = devm_kzalloc(&pdev->dev, sizeof(*hub), GFP_KERNEL);
  858. if (!hub)
  859. return -ENOMEM;
  860. hub->soc = of_device_get_match_data(&pdev->dev);
  861. hub->clk_disp = devm_clk_get(&pdev->dev, "disp");
  862. if (IS_ERR(hub->clk_disp)) {
  863. err = PTR_ERR(hub->clk_disp);
  864. return err;
  865. }
  866. if (hub->soc->supports_dsc) {
  867. hub->clk_dsc = devm_clk_get(&pdev->dev, "dsc");
  868. if (IS_ERR(hub->clk_dsc)) {
  869. err = PTR_ERR(hub->clk_dsc);
  870. return err;
  871. }
  872. }
  873. hub->clk_hub = devm_clk_get(&pdev->dev, "hub");
  874. if (IS_ERR(hub->clk_hub)) {
  875. err = PTR_ERR(hub->clk_hub);
  876. return err;
  877. }
  878. hub->rst = devm_reset_control_get(&pdev->dev, "misc");
  879. if (IS_ERR(hub->rst)) {
  880. err = PTR_ERR(hub->rst);
  881. return err;
  882. }
  883. hub->wgrps = devm_kcalloc(&pdev->dev, hub->soc->num_wgrps,
  884. sizeof(*hub->wgrps), GFP_KERNEL);
  885. if (!hub->wgrps)
  886. return -ENOMEM;
  887. for (i = 0; i < hub->soc->num_wgrps; i++) {
  888. struct tegra_windowgroup *wgrp = &hub->wgrps[i];
  889. char id[16];
  890. snprintf(id, sizeof(id), "wgrp%u", i);
  891. mutex_init(&wgrp->lock);
  892. wgrp->usecount = 0;
  893. wgrp->index = i;
  894. wgrp->rst = devm_reset_control_get(&pdev->dev, id);
  895. if (IS_ERR(wgrp->rst))
  896. return PTR_ERR(wgrp->rst);
  897. err = reset_control_assert(wgrp->rst);
  898. if (err < 0)
  899. return err;
  900. }
  901. hub->num_heads = of_get_child_count(pdev->dev.of_node);
  902. hub->clk_heads = devm_kcalloc(&pdev->dev, hub->num_heads, sizeof(clk),
  903. GFP_KERNEL);
  904. if (!hub->clk_heads)
  905. return -ENOMEM;
  906. for (i = 0; i < hub->num_heads; i++) {
  907. child = of_get_next_child(pdev->dev.of_node, child);
  908. if (!child) {
  909. dev_err(&pdev->dev, "failed to find node for head %u\n",
  910. i);
  911. return -ENODEV;
  912. }
  913. clk = devm_get_clk_from_child(&pdev->dev, child, "dc");
  914. if (IS_ERR(clk)) {
  915. dev_err(&pdev->dev, "failed to get clock for head %u\n",
  916. i);
  917. of_node_put(child);
  918. return PTR_ERR(clk);
  919. }
  920. hub->clk_heads[i] = clk;
  921. }
  922. of_node_put(child);
  923. /* XXX: enable clock across reset? */
  924. err = reset_control_assert(hub->rst);
  925. if (err < 0)
  926. return err;
  927. platform_set_drvdata(pdev, hub);
  928. pm_runtime_enable(&pdev->dev);
  929. INIT_LIST_HEAD(&hub->client.list);
  930. hub->client.ops = &tegra_display_hub_ops;
  931. hub->client.dev = &pdev->dev;
  932. err = host1x_client_register(&hub->client);
  933. if (err < 0)
  934. dev_err(&pdev->dev, "failed to register host1x client: %d\n",
  935. err);
  936. err = devm_of_platform_populate(&pdev->dev);
  937. if (err < 0)
  938. goto unregister;
  939. return err;
  940. unregister:
  941. host1x_client_unregister(&hub->client);
  942. pm_runtime_disable(&pdev->dev);
  943. return err;
  944. }
  945. static void tegra_display_hub_remove(struct platform_device *pdev)
  946. {
  947. struct tegra_display_hub *hub = platform_get_drvdata(pdev);
  948. unsigned int i;
  949. host1x_client_unregister(&hub->client);
  950. for (i = 0; i < hub->soc->num_wgrps; i++) {
  951. struct tegra_windowgroup *wgrp = &hub->wgrps[i];
  952. mutex_destroy(&wgrp->lock);
  953. }
  954. pm_runtime_disable(&pdev->dev);
  955. }
  956. static const struct tegra_display_hub_soc tegra186_display_hub = {
  957. .num_wgrps = 6,
  958. .supports_dsc = true,
  959. };
  960. static const struct tegra_display_hub_soc tegra194_display_hub = {
  961. .num_wgrps = 6,
  962. .supports_dsc = false,
  963. };
  964. static const struct of_device_id tegra_display_hub_of_match[] = {
  965. {
  966. .compatible = "nvidia,tegra194-display",
  967. .data = &tegra194_display_hub
  968. }, {
  969. .compatible = "nvidia,tegra186-display",
  970. .data = &tegra186_display_hub
  971. }, {
  972. /* sentinel */
  973. }
  974. };
  975. MODULE_DEVICE_TABLE(of, tegra_display_hub_of_match);
  976. struct platform_driver tegra_display_hub_driver = {
  977. .driver = {
  978. .name = "tegra-display-hub",
  979. .of_match_table = tegra_display_hub_of_match,
  980. },
  981. .probe = tegra_display_hub_probe,
  982. .remove_new = tegra_display_hub_remove,
  983. };