rcar_du_kms.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * rcar_du_kms.c -- R-Car Display Unit Mode Setting
  4. *
  5. * Copyright (C) 2013-2015 Renesas Electronics Corporation
  6. *
  7. * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
  8. */
  9. #include <drm/drmP.h>
  10. #include <drm/drm_atomic.h>
  11. #include <drm/drm_atomic_helper.h>
  12. #include <drm/drm_crtc.h>
  13. #include <drm/drm_crtc_helper.h>
  14. #include <drm/drm_fb_cma_helper.h>
  15. #include <drm/drm_gem_cma_helper.h>
  16. #include <drm/drm_gem_framebuffer_helper.h>
  17. #include <linux/of_graph.h>
  18. #include <linux/wait.h>
  19. #include "rcar_du_crtc.h"
  20. #include "rcar_du_drv.h"
  21. #include "rcar_du_encoder.h"
  22. #include "rcar_du_kms.h"
  23. #include "rcar_du_regs.h"
  24. #include "rcar_du_vsp.h"
  25. /* -----------------------------------------------------------------------------
  26. * Format helpers
  27. */
  28. static const struct rcar_du_format_info rcar_du_format_infos[] = {
  29. {
  30. .fourcc = DRM_FORMAT_RGB565,
  31. .bpp = 16,
  32. .planes = 1,
  33. .pnmr = PnMR_SPIM_TP | PnMR_DDDF_16BPP,
  34. .edf = PnDDCR4_EDF_NONE,
  35. }, {
  36. .fourcc = DRM_FORMAT_ARGB1555,
  37. .bpp = 16,
  38. .planes = 1,
  39. .pnmr = PnMR_SPIM_ALP | PnMR_DDDF_ARGB,
  40. .edf = PnDDCR4_EDF_NONE,
  41. }, {
  42. .fourcc = DRM_FORMAT_XRGB1555,
  43. .bpp = 16,
  44. .planes = 1,
  45. .pnmr = PnMR_SPIM_ALP | PnMR_DDDF_ARGB,
  46. .edf = PnDDCR4_EDF_NONE,
  47. }, {
  48. .fourcc = DRM_FORMAT_XRGB8888,
  49. .bpp = 32,
  50. .planes = 1,
  51. .pnmr = PnMR_SPIM_TP | PnMR_DDDF_16BPP,
  52. .edf = PnDDCR4_EDF_RGB888,
  53. }, {
  54. .fourcc = DRM_FORMAT_ARGB8888,
  55. .bpp = 32,
  56. .planes = 1,
  57. .pnmr = PnMR_SPIM_ALP | PnMR_DDDF_16BPP,
  58. .edf = PnDDCR4_EDF_ARGB8888,
  59. }, {
  60. .fourcc = DRM_FORMAT_UYVY,
  61. .bpp = 16,
  62. .planes = 1,
  63. .pnmr = PnMR_SPIM_TP_OFF | PnMR_DDDF_YC,
  64. .edf = PnDDCR4_EDF_NONE,
  65. }, {
  66. .fourcc = DRM_FORMAT_YUYV,
  67. .bpp = 16,
  68. .planes = 1,
  69. .pnmr = PnMR_SPIM_TP_OFF | PnMR_DDDF_YC,
  70. .edf = PnDDCR4_EDF_NONE,
  71. }, {
  72. .fourcc = DRM_FORMAT_NV12,
  73. .bpp = 12,
  74. .planes = 2,
  75. .pnmr = PnMR_SPIM_TP_OFF | PnMR_DDDF_YC,
  76. .edf = PnDDCR4_EDF_NONE,
  77. }, {
  78. .fourcc = DRM_FORMAT_NV21,
  79. .bpp = 12,
  80. .planes = 2,
  81. .pnmr = PnMR_SPIM_TP_OFF | PnMR_DDDF_YC,
  82. .edf = PnDDCR4_EDF_NONE,
  83. }, {
  84. .fourcc = DRM_FORMAT_NV16,
  85. .bpp = 16,
  86. .planes = 2,
  87. .pnmr = PnMR_SPIM_TP_OFF | PnMR_DDDF_YC,
  88. .edf = PnDDCR4_EDF_NONE,
  89. },
  90. /*
  91. * The following formats are not supported on Gen2 and thus have no
  92. * associated .pnmr or .edf settings.
  93. */
  94. {
  95. .fourcc = DRM_FORMAT_RGB332,
  96. .bpp = 8,
  97. .planes = 1,
  98. }, {
  99. .fourcc = DRM_FORMAT_ARGB4444,
  100. .bpp = 16,
  101. .planes = 1,
  102. }, {
  103. .fourcc = DRM_FORMAT_XRGB4444,
  104. .bpp = 16,
  105. .planes = 1,
  106. }, {
  107. .fourcc = DRM_FORMAT_BGR888,
  108. .bpp = 24,
  109. .planes = 1,
  110. }, {
  111. .fourcc = DRM_FORMAT_RGB888,
  112. .bpp = 24,
  113. .planes = 1,
  114. }, {
  115. .fourcc = DRM_FORMAT_BGRA8888,
  116. .bpp = 32,
  117. .planes = 1,
  118. }, {
  119. .fourcc = DRM_FORMAT_BGRX8888,
  120. .bpp = 32,
  121. .planes = 1,
  122. }, {
  123. .fourcc = DRM_FORMAT_YVYU,
  124. .bpp = 16,
  125. .planes = 1,
  126. }, {
  127. .fourcc = DRM_FORMAT_NV61,
  128. .bpp = 16,
  129. .planes = 2,
  130. }, {
  131. .fourcc = DRM_FORMAT_YUV420,
  132. .bpp = 12,
  133. .planes = 3,
  134. }, {
  135. .fourcc = DRM_FORMAT_YVU420,
  136. .bpp = 12,
  137. .planes = 3,
  138. }, {
  139. .fourcc = DRM_FORMAT_YUV422,
  140. .bpp = 16,
  141. .planes = 3,
  142. }, {
  143. .fourcc = DRM_FORMAT_YVU422,
  144. .bpp = 16,
  145. .planes = 3,
  146. }, {
  147. .fourcc = DRM_FORMAT_YUV444,
  148. .bpp = 24,
  149. .planes = 3,
  150. }, {
  151. .fourcc = DRM_FORMAT_YVU444,
  152. .bpp = 24,
  153. .planes = 3,
  154. },
  155. };
  156. const struct rcar_du_format_info *rcar_du_format_info(u32 fourcc)
  157. {
  158. unsigned int i;
  159. for (i = 0; i < ARRAY_SIZE(rcar_du_format_infos); ++i) {
  160. if (rcar_du_format_infos[i].fourcc == fourcc)
  161. return &rcar_du_format_infos[i];
  162. }
  163. return NULL;
  164. }
  165. /* -----------------------------------------------------------------------------
  166. * Frame buffer
  167. */
  168. int rcar_du_dumb_create(struct drm_file *file, struct drm_device *dev,
  169. struct drm_mode_create_dumb *args)
  170. {
  171. struct rcar_du_device *rcdu = dev->dev_private;
  172. unsigned int min_pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
  173. unsigned int align;
  174. /*
  175. * The R8A7779 DU requires a 16 pixels pitch alignment as documented,
  176. * but the R8A7790 DU seems to require a 128 bytes pitch alignment.
  177. */
  178. if (rcar_du_needs(rcdu, RCAR_DU_QUIRK_ALIGN_128B))
  179. align = 128;
  180. else
  181. align = 16 * args->bpp / 8;
  182. args->pitch = roundup(min_pitch, align);
  183. return drm_gem_cma_dumb_create_internal(file, dev, args);
  184. }
  185. static struct drm_framebuffer *
  186. rcar_du_fb_create(struct drm_device *dev, struct drm_file *file_priv,
  187. const struct drm_mode_fb_cmd2 *mode_cmd)
  188. {
  189. struct rcar_du_device *rcdu = dev->dev_private;
  190. const struct rcar_du_format_info *format;
  191. unsigned int max_pitch;
  192. unsigned int align;
  193. unsigned int i;
  194. format = rcar_du_format_info(mode_cmd->pixel_format);
  195. if (format == NULL) {
  196. dev_dbg(dev->dev, "unsupported pixel format %08x\n",
  197. mode_cmd->pixel_format);
  198. return ERR_PTR(-EINVAL);
  199. }
  200. if (rcdu->info->gen < 3) {
  201. /*
  202. * On Gen2 the DU limits the pitch to 4095 pixels and requires
  203. * buffers to be aligned to a 16 pixels boundary (or 128 bytes
  204. * on some platforms).
  205. */
  206. unsigned int bpp = format->planes == 1 ? format->bpp / 8 : 1;
  207. max_pitch = 4095 * bpp;
  208. if (rcar_du_needs(rcdu, RCAR_DU_QUIRK_ALIGN_128B))
  209. align = 128;
  210. else
  211. align = 16 * bpp;
  212. } else {
  213. /*
  214. * On Gen3 the memory interface is handled by the VSP that
  215. * limits the pitch to 65535 bytes and has no alignment
  216. * constraint.
  217. */
  218. max_pitch = 65535;
  219. align = 1;
  220. }
  221. if (mode_cmd->pitches[0] & (align - 1) ||
  222. mode_cmd->pitches[0] > max_pitch) {
  223. dev_dbg(dev->dev, "invalid pitch value %u\n",
  224. mode_cmd->pitches[0]);
  225. return ERR_PTR(-EINVAL);
  226. }
  227. for (i = 1; i < format->planes; ++i) {
  228. if (mode_cmd->pitches[i] != mode_cmd->pitches[0]) {
  229. dev_dbg(dev->dev,
  230. "luma and chroma pitches do not match\n");
  231. return ERR_PTR(-EINVAL);
  232. }
  233. }
  234. return drm_gem_fb_create(dev, file_priv, mode_cmd);
  235. }
  236. static void rcar_du_output_poll_changed(struct drm_device *dev)
  237. {
  238. struct rcar_du_device *rcdu = dev->dev_private;
  239. drm_fbdev_cma_hotplug_event(rcdu->fbdev);
  240. }
  241. /* -----------------------------------------------------------------------------
  242. * Atomic Check and Update
  243. */
  244. static int rcar_du_atomic_check(struct drm_device *dev,
  245. struct drm_atomic_state *state)
  246. {
  247. struct rcar_du_device *rcdu = dev->dev_private;
  248. int ret;
  249. ret = drm_atomic_helper_check(dev, state);
  250. if (ret)
  251. return ret;
  252. if (rcar_du_has(rcdu, RCAR_DU_FEATURE_VSP1_SOURCE))
  253. return 0;
  254. return rcar_du_atomic_check_planes(dev, state);
  255. }
  256. static void rcar_du_atomic_commit_tail(struct drm_atomic_state *old_state)
  257. {
  258. struct drm_device *dev = old_state->dev;
  259. /* Apply the atomic update. */
  260. drm_atomic_helper_commit_modeset_disables(dev, old_state);
  261. drm_atomic_helper_commit_planes(dev, old_state,
  262. DRM_PLANE_COMMIT_ACTIVE_ONLY);
  263. drm_atomic_helper_commit_modeset_enables(dev, old_state);
  264. drm_atomic_helper_commit_hw_done(old_state);
  265. drm_atomic_helper_wait_for_flip_done(dev, old_state);
  266. drm_atomic_helper_cleanup_planes(dev, old_state);
  267. }
  268. /* -----------------------------------------------------------------------------
  269. * Initialization
  270. */
  271. static const struct drm_mode_config_helper_funcs rcar_du_mode_config_helper = {
  272. .atomic_commit_tail = rcar_du_atomic_commit_tail,
  273. };
  274. static const struct drm_mode_config_funcs rcar_du_mode_config_funcs = {
  275. .fb_create = rcar_du_fb_create,
  276. .output_poll_changed = rcar_du_output_poll_changed,
  277. .atomic_check = rcar_du_atomic_check,
  278. .atomic_commit = drm_atomic_helper_commit,
  279. };
  280. static int rcar_du_encoders_init_one(struct rcar_du_device *rcdu,
  281. enum rcar_du_output output,
  282. struct of_endpoint *ep)
  283. {
  284. struct device_node *connector = NULL;
  285. struct device_node *encoder = NULL;
  286. struct device_node *ep_node = NULL;
  287. struct device_node *entity_ep_node;
  288. struct device_node *entity;
  289. int ret;
  290. /*
  291. * Locate the connected entity and infer its type from the number of
  292. * endpoints.
  293. */
  294. entity = of_graph_get_remote_port_parent(ep->local_node);
  295. if (!entity) {
  296. dev_dbg(rcdu->dev, "unconnected endpoint %pOF, skipping\n",
  297. ep->local_node);
  298. return -ENODEV;
  299. }
  300. if (!of_device_is_available(entity)) {
  301. dev_dbg(rcdu->dev,
  302. "connected entity %pOF is disabled, skipping\n",
  303. entity);
  304. return -ENODEV;
  305. }
  306. entity_ep_node = of_graph_get_remote_endpoint(ep->local_node);
  307. for_each_endpoint_of_node(entity, ep_node) {
  308. if (ep_node == entity_ep_node)
  309. continue;
  310. /*
  311. * We've found one endpoint other than the input, this must
  312. * be an encoder. Locate the connector.
  313. */
  314. encoder = entity;
  315. connector = of_graph_get_remote_port_parent(ep_node);
  316. of_node_put(ep_node);
  317. if (!connector) {
  318. dev_warn(rcdu->dev,
  319. "no connector for encoder %pOF, skipping\n",
  320. encoder);
  321. of_node_put(entity_ep_node);
  322. of_node_put(encoder);
  323. return -ENODEV;
  324. }
  325. break;
  326. }
  327. of_node_put(entity_ep_node);
  328. if (!encoder) {
  329. dev_warn(rcdu->dev,
  330. "no encoder found for endpoint %pOF, skipping\n",
  331. ep->local_node);
  332. return -ENODEV;
  333. }
  334. ret = rcar_du_encoder_init(rcdu, output, encoder, connector);
  335. if (ret && ret != -EPROBE_DEFER)
  336. dev_warn(rcdu->dev,
  337. "failed to initialize encoder %pOF on output %u (%d), skipping\n",
  338. encoder, output, ret);
  339. of_node_put(encoder);
  340. of_node_put(connector);
  341. return ret;
  342. }
  343. static int rcar_du_encoders_init(struct rcar_du_device *rcdu)
  344. {
  345. struct device_node *np = rcdu->dev->of_node;
  346. struct device_node *ep_node;
  347. unsigned int num_encoders = 0;
  348. /*
  349. * Iterate over the endpoints and create one encoder for each output
  350. * pipeline.
  351. */
  352. for_each_endpoint_of_node(np, ep_node) {
  353. enum rcar_du_output output;
  354. struct of_endpoint ep;
  355. unsigned int i;
  356. int ret;
  357. ret = of_graph_parse_endpoint(ep_node, &ep);
  358. if (ret < 0) {
  359. of_node_put(ep_node);
  360. return ret;
  361. }
  362. /* Find the output route corresponding to the port number. */
  363. for (i = 0; i < RCAR_DU_OUTPUT_MAX; ++i) {
  364. if (rcdu->info->routes[i].possible_crtcs &&
  365. rcdu->info->routes[i].port == ep.port) {
  366. output = i;
  367. break;
  368. }
  369. }
  370. if (i == RCAR_DU_OUTPUT_MAX) {
  371. dev_warn(rcdu->dev,
  372. "port %u references unexisting output, skipping\n",
  373. ep.port);
  374. continue;
  375. }
  376. /* Process the output pipeline. */
  377. ret = rcar_du_encoders_init_one(rcdu, output, &ep);
  378. if (ret < 0) {
  379. if (ret == -EPROBE_DEFER) {
  380. of_node_put(ep_node);
  381. return ret;
  382. }
  383. continue;
  384. }
  385. num_encoders++;
  386. }
  387. return num_encoders;
  388. }
  389. static int rcar_du_properties_init(struct rcar_du_device *rcdu)
  390. {
  391. /*
  392. * The color key is expressed as an RGB888 triplet stored in a 32-bit
  393. * integer in XRGB8888 format. Bit 24 is used as a flag to disable (0)
  394. * or enable source color keying (1).
  395. */
  396. rcdu->props.colorkey =
  397. drm_property_create_range(rcdu->ddev, 0, "colorkey",
  398. 0, 0x01ffffff);
  399. if (rcdu->props.colorkey == NULL)
  400. return -ENOMEM;
  401. return 0;
  402. }
  403. static int rcar_du_vsps_init(struct rcar_du_device *rcdu)
  404. {
  405. const struct device_node *np = rcdu->dev->of_node;
  406. struct of_phandle_args args;
  407. struct {
  408. struct device_node *np;
  409. unsigned int crtcs_mask;
  410. } vsps[RCAR_DU_MAX_VSPS] = { { NULL, }, };
  411. unsigned int vsps_count = 0;
  412. unsigned int cells;
  413. unsigned int i;
  414. int ret;
  415. /*
  416. * First parse the DT vsps property to populate the list of VSPs. Each
  417. * entry contains a pointer to the VSP DT node and a bitmask of the
  418. * connected DU CRTCs.
  419. */
  420. cells = of_property_count_u32_elems(np, "vsps") / rcdu->num_crtcs - 1;
  421. if (cells > 1)
  422. return -EINVAL;
  423. for (i = 0; i < rcdu->num_crtcs; ++i) {
  424. unsigned int j;
  425. ret = of_parse_phandle_with_fixed_args(np, "vsps", cells, i,
  426. &args);
  427. if (ret < 0)
  428. goto error;
  429. /*
  430. * Add the VSP to the list or update the corresponding existing
  431. * entry if the VSP has already been added.
  432. */
  433. for (j = 0; j < vsps_count; ++j) {
  434. if (vsps[j].np == args.np)
  435. break;
  436. }
  437. if (j < vsps_count)
  438. of_node_put(args.np);
  439. else
  440. vsps[vsps_count++].np = args.np;
  441. vsps[j].crtcs_mask |= BIT(i);
  442. /* Store the VSP pointer and pipe index in the CRTC. */
  443. rcdu->crtcs[i].vsp = &rcdu->vsps[j];
  444. rcdu->crtcs[i].vsp_pipe = cells >= 1 ? args.args[0] : 0;
  445. }
  446. /*
  447. * Then initialize all the VSPs from the node pointers and CRTCs bitmask
  448. * computed previously.
  449. */
  450. for (i = 0; i < vsps_count; ++i) {
  451. struct rcar_du_vsp *vsp = &rcdu->vsps[i];
  452. vsp->index = i;
  453. vsp->dev = rcdu;
  454. ret = rcar_du_vsp_init(vsp, vsps[i].np, vsps[i].crtcs_mask);
  455. if (ret < 0)
  456. goto error;
  457. }
  458. return 0;
  459. error:
  460. for (i = 0; i < ARRAY_SIZE(vsps); ++i)
  461. of_node_put(vsps[i].np);
  462. return ret;
  463. }
  464. int rcar_du_modeset_init(struct rcar_du_device *rcdu)
  465. {
  466. static const unsigned int mmio_offsets[] = {
  467. DU0_REG_OFFSET, DU2_REG_OFFSET
  468. };
  469. struct drm_device *dev = rcdu->ddev;
  470. struct drm_encoder *encoder;
  471. struct drm_fbdev_cma *fbdev;
  472. unsigned int dpad0_sources;
  473. unsigned int num_encoders;
  474. unsigned int num_groups;
  475. unsigned int swindex;
  476. unsigned int hwindex;
  477. unsigned int i;
  478. int ret;
  479. drm_mode_config_init(dev);
  480. dev->mode_config.min_width = 0;
  481. dev->mode_config.min_height = 0;
  482. dev->mode_config.normalize_zpos = true;
  483. dev->mode_config.funcs = &rcar_du_mode_config_funcs;
  484. dev->mode_config.helper_private = &rcar_du_mode_config_helper;
  485. if (rcdu->info->gen < 3) {
  486. dev->mode_config.max_width = 4095;
  487. dev->mode_config.max_height = 2047;
  488. } else {
  489. /*
  490. * The Gen3 DU uses the VSP1 for memory access, and is limited
  491. * to frame sizes of 8190x8190.
  492. */
  493. dev->mode_config.max_width = 8190;
  494. dev->mode_config.max_height = 8190;
  495. }
  496. rcdu->num_crtcs = hweight8(rcdu->info->channels_mask);
  497. ret = rcar_du_properties_init(rcdu);
  498. if (ret < 0)
  499. return ret;
  500. /*
  501. * Initialize vertical blanking interrupts handling. Start with vblank
  502. * disabled for all CRTCs.
  503. */
  504. ret = drm_vblank_init(dev, (1 << rcdu->num_crtcs) - 1);
  505. if (ret < 0)
  506. return ret;
  507. /* Initialize the groups. */
  508. num_groups = DIV_ROUND_UP(rcdu->num_crtcs, 2);
  509. for (i = 0; i < num_groups; ++i) {
  510. struct rcar_du_group *rgrp = &rcdu->groups[i];
  511. mutex_init(&rgrp->lock);
  512. rgrp->dev = rcdu;
  513. rgrp->mmio_offset = mmio_offsets[i];
  514. rgrp->index = i;
  515. /* Extract the channel mask for this group only. */
  516. rgrp->channels_mask = (rcdu->info->channels_mask >> (2 * i))
  517. & GENMASK(1, 0);
  518. rgrp->num_crtcs = hweight8(rgrp->channels_mask);
  519. /*
  520. * If we have more than one CRTCs in this group pre-associate
  521. * the low-order planes with CRTC 0 and the high-order planes
  522. * with CRTC 1 to minimize flicker occurring when the
  523. * association is changed.
  524. */
  525. rgrp->dptsr_planes = rgrp->num_crtcs > 1
  526. ? (rcdu->info->gen >= 3 ? 0x04 : 0xf0)
  527. : 0;
  528. if (!rcar_du_has(rcdu, RCAR_DU_FEATURE_VSP1_SOURCE)) {
  529. ret = rcar_du_planes_init(rgrp);
  530. if (ret < 0)
  531. return ret;
  532. }
  533. }
  534. /* Initialize the compositors. */
  535. if (rcar_du_has(rcdu, RCAR_DU_FEATURE_VSP1_SOURCE)) {
  536. ret = rcar_du_vsps_init(rcdu);
  537. if (ret < 0)
  538. return ret;
  539. }
  540. /* Create the CRTCs. */
  541. for (swindex = 0, hwindex = 0; swindex < rcdu->num_crtcs; ++hwindex) {
  542. struct rcar_du_group *rgrp;
  543. /* Skip unpopulated DU channels. */
  544. if (!(rcdu->info->channels_mask & BIT(hwindex)))
  545. continue;
  546. rgrp = &rcdu->groups[hwindex / 2];
  547. ret = rcar_du_crtc_create(rgrp, swindex++, hwindex);
  548. if (ret < 0)
  549. return ret;
  550. }
  551. /* Initialize the encoders. */
  552. ret = rcar_du_encoders_init(rcdu);
  553. if (ret < 0)
  554. return ret;
  555. if (ret == 0) {
  556. dev_err(rcdu->dev, "error: no encoder could be initialized\n");
  557. return -EINVAL;
  558. }
  559. num_encoders = ret;
  560. /*
  561. * Set the possible CRTCs and possible clones. There's always at least
  562. * one way for all encoders to clone each other, set all bits in the
  563. * possible clones field.
  564. */
  565. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  566. struct rcar_du_encoder *renc = to_rcar_encoder(encoder);
  567. const struct rcar_du_output_routing *route =
  568. &rcdu->info->routes[renc->output];
  569. encoder->possible_crtcs = route->possible_crtcs;
  570. encoder->possible_clones = (1 << num_encoders) - 1;
  571. }
  572. /*
  573. * Initialize the default DPAD0 source to the index of the first DU
  574. * channel that can be connected to DPAD0. The exact value doesn't
  575. * matter as it should be overwritten by mode setting for the RGB
  576. * output, but it is nonetheless required to ensure a valid initial
  577. * hardware configuration on Gen3 where DU0 can't always be connected to
  578. * DPAD0.
  579. */
  580. dpad0_sources = rcdu->info->routes[RCAR_DU_OUTPUT_DPAD0].possible_crtcs;
  581. rcdu->dpad0_source = ffs(dpad0_sources) - 1;
  582. drm_mode_config_reset(dev);
  583. drm_kms_helper_poll_init(dev);
  584. if (dev->mode_config.num_connector) {
  585. fbdev = drm_fbdev_cma_init(dev, 32,
  586. dev->mode_config.num_connector);
  587. if (IS_ERR(fbdev))
  588. return PTR_ERR(fbdev);
  589. rcdu->fbdev = fbdev;
  590. } else {
  591. dev_info(rcdu->dev,
  592. "no connector found, disabling fbdev emulation\n");
  593. }
  594. return 0;
  595. }