hub.c 33 KB

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