omap_crtc.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. /*
  2. * drivers/gpu/drm/omapdrm/omap_crtc.c
  3. *
  4. * Copyright (C) 2011 Texas Instruments
  5. * Author: Rob Clark <rob@ti.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published by
  9. * the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <drm/drm_atomic.h>
  20. #include <drm/drm_atomic_helper.h>
  21. #include <drm/drm_crtc.h>
  22. #include <drm/drm_crtc_helper.h>
  23. #include <drm/drm_mode.h>
  24. #include <drm/drm_plane_helper.h>
  25. #include "omap_drv.h"
  26. #define to_omap_crtc(x) container_of(x, struct omap_crtc, base)
  27. struct omap_crtc {
  28. struct drm_crtc base;
  29. const char *name;
  30. enum omap_channel channel;
  31. struct videomode vm;
  32. bool ignore_digit_sync_lost;
  33. bool enabled;
  34. bool pending;
  35. wait_queue_head_t pending_wait;
  36. struct drm_pending_vblank_event *event;
  37. };
  38. /* -----------------------------------------------------------------------------
  39. * Helper Functions
  40. */
  41. struct videomode *omap_crtc_timings(struct drm_crtc *crtc)
  42. {
  43. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  44. return &omap_crtc->vm;
  45. }
  46. enum omap_channel omap_crtc_channel(struct drm_crtc *crtc)
  47. {
  48. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  49. return omap_crtc->channel;
  50. }
  51. static bool omap_crtc_is_pending(struct drm_crtc *crtc)
  52. {
  53. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  54. unsigned long flags;
  55. bool pending;
  56. spin_lock_irqsave(&crtc->dev->event_lock, flags);
  57. pending = omap_crtc->pending;
  58. spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
  59. return pending;
  60. }
  61. int omap_crtc_wait_pending(struct drm_crtc *crtc)
  62. {
  63. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  64. /*
  65. * Timeout is set to a "sufficiently" high value, which should cover
  66. * a single frame refresh even on slower displays.
  67. */
  68. return wait_event_timeout(omap_crtc->pending_wait,
  69. !omap_crtc_is_pending(crtc),
  70. msecs_to_jiffies(250));
  71. }
  72. /* -----------------------------------------------------------------------------
  73. * DSS Manager Functions
  74. */
  75. /*
  76. * Manager-ops, callbacks from output when they need to configure
  77. * the upstream part of the video pipe.
  78. *
  79. * Most of these we can ignore until we add support for command-mode
  80. * panels.. for video-mode the crtc-helpers already do an adequate
  81. * job of sequencing the setup of the video pipe in the proper order
  82. */
  83. /* ovl-mgr-id -> crtc */
  84. static struct omap_crtc *omap_crtcs[8];
  85. static struct omap_dss_device *omap_crtc_output[8];
  86. /* we can probably ignore these until we support command-mode panels: */
  87. static int omap_crtc_dss_connect(enum omap_channel channel,
  88. struct omap_dss_device *dst)
  89. {
  90. const struct dispc_ops *dispc_ops = dispc_get_ops();
  91. if (omap_crtc_output[channel])
  92. return -EINVAL;
  93. if ((dispc_ops->mgr_get_supported_outputs(channel) & dst->id) == 0)
  94. return -EINVAL;
  95. omap_crtc_output[channel] = dst;
  96. dst->dispc_channel_connected = true;
  97. return 0;
  98. }
  99. static void omap_crtc_dss_disconnect(enum omap_channel channel,
  100. struct omap_dss_device *dst)
  101. {
  102. omap_crtc_output[channel] = NULL;
  103. dst->dispc_channel_connected = false;
  104. }
  105. static void omap_crtc_dss_start_update(enum omap_channel channel)
  106. {
  107. }
  108. /* Called only from the encoder enable/disable and suspend/resume handlers. */
  109. static void omap_crtc_set_enabled(struct drm_crtc *crtc, bool enable)
  110. {
  111. struct drm_device *dev = crtc->dev;
  112. struct omap_drm_private *priv = dev->dev_private;
  113. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  114. enum omap_channel channel = omap_crtc->channel;
  115. struct omap_irq_wait *wait;
  116. u32 framedone_irq, vsync_irq;
  117. int ret;
  118. if (WARN_ON(omap_crtc->enabled == enable))
  119. return;
  120. if (omap_crtc_output[channel]->output_type == OMAP_DISPLAY_TYPE_HDMI) {
  121. priv->dispc_ops->mgr_enable(channel, enable);
  122. omap_crtc->enabled = enable;
  123. return;
  124. }
  125. if (omap_crtc->channel == OMAP_DSS_CHANNEL_DIGIT) {
  126. /*
  127. * Digit output produces some sync lost interrupts during the
  128. * first frame when enabling, so we need to ignore those.
  129. */
  130. omap_crtc->ignore_digit_sync_lost = true;
  131. }
  132. framedone_irq = priv->dispc_ops->mgr_get_framedone_irq(channel);
  133. vsync_irq = priv->dispc_ops->mgr_get_vsync_irq(channel);
  134. if (enable) {
  135. wait = omap_irq_wait_init(dev, vsync_irq, 1);
  136. } else {
  137. /*
  138. * When we disable the digit output, we need to wait for
  139. * FRAMEDONE to know that DISPC has finished with the output.
  140. *
  141. * OMAP2/3 does not have FRAMEDONE irq for digit output, and in
  142. * that case we need to use vsync interrupt, and wait for both
  143. * even and odd frames.
  144. */
  145. if (framedone_irq)
  146. wait = omap_irq_wait_init(dev, framedone_irq, 1);
  147. else
  148. wait = omap_irq_wait_init(dev, vsync_irq, 2);
  149. }
  150. priv->dispc_ops->mgr_enable(channel, enable);
  151. omap_crtc->enabled = enable;
  152. ret = omap_irq_wait(dev, wait, msecs_to_jiffies(100));
  153. if (ret) {
  154. dev_err(dev->dev, "%s: timeout waiting for %s\n",
  155. omap_crtc->name, enable ? "enable" : "disable");
  156. }
  157. if (omap_crtc->channel == OMAP_DSS_CHANNEL_DIGIT) {
  158. omap_crtc->ignore_digit_sync_lost = false;
  159. /* make sure the irq handler sees the value above */
  160. mb();
  161. }
  162. }
  163. static int omap_crtc_dss_enable(enum omap_channel channel)
  164. {
  165. struct omap_crtc *omap_crtc = omap_crtcs[channel];
  166. struct omap_drm_private *priv = omap_crtc->base.dev->dev_private;
  167. priv->dispc_ops->mgr_set_timings(omap_crtc->channel, &omap_crtc->vm);
  168. omap_crtc_set_enabled(&omap_crtc->base, true);
  169. return 0;
  170. }
  171. static void omap_crtc_dss_disable(enum omap_channel channel)
  172. {
  173. struct omap_crtc *omap_crtc = omap_crtcs[channel];
  174. omap_crtc_set_enabled(&omap_crtc->base, false);
  175. }
  176. static void omap_crtc_dss_set_timings(enum omap_channel channel,
  177. const struct videomode *vm)
  178. {
  179. struct omap_crtc *omap_crtc = omap_crtcs[channel];
  180. DBG("%s", omap_crtc->name);
  181. omap_crtc->vm = *vm;
  182. }
  183. static void omap_crtc_dss_set_lcd_config(enum omap_channel channel,
  184. const struct dss_lcd_mgr_config *config)
  185. {
  186. struct omap_crtc *omap_crtc = omap_crtcs[channel];
  187. struct omap_drm_private *priv = omap_crtc->base.dev->dev_private;
  188. DBG("%s", omap_crtc->name);
  189. priv->dispc_ops->mgr_set_lcd_config(omap_crtc->channel, config);
  190. }
  191. static int omap_crtc_dss_register_framedone(
  192. enum omap_channel channel,
  193. void (*handler)(void *), void *data)
  194. {
  195. return 0;
  196. }
  197. static void omap_crtc_dss_unregister_framedone(
  198. enum omap_channel channel,
  199. void (*handler)(void *), void *data)
  200. {
  201. }
  202. static const struct dss_mgr_ops mgr_ops = {
  203. .connect = omap_crtc_dss_connect,
  204. .disconnect = omap_crtc_dss_disconnect,
  205. .start_update = omap_crtc_dss_start_update,
  206. .enable = omap_crtc_dss_enable,
  207. .disable = omap_crtc_dss_disable,
  208. .set_timings = omap_crtc_dss_set_timings,
  209. .set_lcd_config = omap_crtc_dss_set_lcd_config,
  210. .register_framedone_handler = omap_crtc_dss_register_framedone,
  211. .unregister_framedone_handler = omap_crtc_dss_unregister_framedone,
  212. };
  213. /* -----------------------------------------------------------------------------
  214. * Setup, Flush and Page Flip
  215. */
  216. void omap_crtc_error_irq(struct drm_crtc *crtc, uint32_t irqstatus)
  217. {
  218. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  219. if (omap_crtc->ignore_digit_sync_lost) {
  220. irqstatus &= ~DISPC_IRQ_SYNC_LOST_DIGIT;
  221. if (!irqstatus)
  222. return;
  223. }
  224. DRM_ERROR_RATELIMITED("%s: errors: %08x\n", omap_crtc->name, irqstatus);
  225. }
  226. void omap_crtc_vblank_irq(struct drm_crtc *crtc)
  227. {
  228. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  229. struct drm_device *dev = omap_crtc->base.dev;
  230. struct omap_drm_private *priv = dev->dev_private;
  231. bool pending;
  232. spin_lock(&crtc->dev->event_lock);
  233. /*
  234. * If the dispc is busy we're racing the flush operation. Try again on
  235. * the next vblank interrupt.
  236. */
  237. if (priv->dispc_ops->mgr_go_busy(omap_crtc->channel)) {
  238. spin_unlock(&crtc->dev->event_lock);
  239. return;
  240. }
  241. /* Send the vblank event if one has been requested. */
  242. if (omap_crtc->event) {
  243. drm_crtc_send_vblank_event(crtc, omap_crtc->event);
  244. omap_crtc->event = NULL;
  245. }
  246. pending = omap_crtc->pending;
  247. omap_crtc->pending = false;
  248. spin_unlock(&crtc->dev->event_lock);
  249. if (pending)
  250. drm_crtc_vblank_put(crtc);
  251. /* Wake up omap_atomic_complete. */
  252. wake_up(&omap_crtc->pending_wait);
  253. DBG("%s: apply done", omap_crtc->name);
  254. }
  255. static void omap_crtc_write_crtc_properties(struct drm_crtc *crtc)
  256. {
  257. struct omap_drm_private *priv = crtc->dev->dev_private;
  258. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  259. struct omap_overlay_manager_info info;
  260. memset(&info, 0, sizeof(info));
  261. info.default_color = 0x000000;
  262. info.trans_enabled = false;
  263. info.partial_alpha_enabled = false;
  264. info.cpr_enable = false;
  265. priv->dispc_ops->mgr_setup(omap_crtc->channel, &info);
  266. }
  267. /* -----------------------------------------------------------------------------
  268. * CRTC Functions
  269. */
  270. static void omap_crtc_destroy(struct drm_crtc *crtc)
  271. {
  272. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  273. DBG("%s", omap_crtc->name);
  274. drm_crtc_cleanup(crtc);
  275. kfree(omap_crtc);
  276. }
  277. static void omap_crtc_arm_event(struct drm_crtc *crtc)
  278. {
  279. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  280. WARN_ON(omap_crtc->pending);
  281. omap_crtc->pending = true;
  282. if (crtc->state->event) {
  283. omap_crtc->event = crtc->state->event;
  284. crtc->state->event = NULL;
  285. }
  286. }
  287. static void omap_crtc_atomic_enable(struct drm_crtc *crtc,
  288. struct drm_crtc_state *old_state)
  289. {
  290. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  291. int ret;
  292. DBG("%s", omap_crtc->name);
  293. spin_lock_irq(&crtc->dev->event_lock);
  294. drm_crtc_vblank_on(crtc);
  295. ret = drm_crtc_vblank_get(crtc);
  296. WARN_ON(ret != 0);
  297. omap_crtc_arm_event(crtc);
  298. spin_unlock_irq(&crtc->dev->event_lock);
  299. }
  300. static void omap_crtc_atomic_disable(struct drm_crtc *crtc,
  301. struct drm_crtc_state *old_state)
  302. {
  303. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  304. DBG("%s", omap_crtc->name);
  305. spin_lock_irq(&crtc->dev->event_lock);
  306. if (crtc->state->event) {
  307. drm_crtc_send_vblank_event(crtc, crtc->state->event);
  308. crtc->state->event = NULL;
  309. }
  310. spin_unlock_irq(&crtc->dev->event_lock);
  311. drm_crtc_vblank_off(crtc);
  312. }
  313. static void omap_crtc_mode_set_nofb(struct drm_crtc *crtc)
  314. {
  315. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  316. struct drm_display_mode *mode = &crtc->state->adjusted_mode;
  317. struct omap_drm_private *priv = crtc->dev->dev_private;
  318. const u32 flags_mask = DISPLAY_FLAGS_DE_HIGH | DISPLAY_FLAGS_DE_LOW |
  319. DISPLAY_FLAGS_PIXDATA_POSEDGE | DISPLAY_FLAGS_PIXDATA_NEGEDGE |
  320. DISPLAY_FLAGS_SYNC_POSEDGE | DISPLAY_FLAGS_SYNC_NEGEDGE;
  321. unsigned int i;
  322. DBG("%s: set mode: %d:\"%s\" %d %d %d %d %d %d %d %d %d %d 0x%x 0x%x",
  323. omap_crtc->name, mode->base.id, mode->name,
  324. mode->vrefresh, mode->clock,
  325. mode->hdisplay, mode->hsync_start, mode->hsync_end, mode->htotal,
  326. mode->vdisplay, mode->vsync_start, mode->vsync_end, mode->vtotal,
  327. mode->type, mode->flags);
  328. drm_display_mode_to_videomode(mode, &omap_crtc->vm);
  329. /*
  330. * HACK: This fixes the vm flags.
  331. * struct drm_display_mode does not contain the VSYNC/HSYNC/DE flags
  332. * and they get lost when converting back and forth between
  333. * struct drm_display_mode and struct videomode. The hack below
  334. * goes and fetches the missing flags from the panel drivers.
  335. *
  336. * Correct solution would be to use DRM's bus-flags, but that's not
  337. * easily possible before the omapdrm's panel/encoder driver model
  338. * has been changed to the DRM model.
  339. */
  340. for (i = 0; i < priv->num_encoders; ++i) {
  341. struct drm_encoder *encoder = priv->encoders[i];
  342. if (encoder->crtc == crtc) {
  343. struct omap_dss_device *dssdev;
  344. dssdev = omap_encoder_get_dssdev(encoder);
  345. if (dssdev) {
  346. struct videomode vm = {0};
  347. dssdev->driver->get_timings(dssdev, &vm);
  348. omap_crtc->vm.flags |= vm.flags & flags_mask;
  349. }
  350. break;
  351. }
  352. }
  353. }
  354. static int omap_crtc_atomic_check(struct drm_crtc *crtc,
  355. struct drm_crtc_state *state)
  356. {
  357. if (state->color_mgmt_changed && state->gamma_lut) {
  358. uint length = state->gamma_lut->length /
  359. sizeof(struct drm_color_lut);
  360. if (length < 2)
  361. return -EINVAL;
  362. }
  363. return 0;
  364. }
  365. static void omap_crtc_atomic_begin(struct drm_crtc *crtc,
  366. struct drm_crtc_state *old_crtc_state)
  367. {
  368. }
  369. static void omap_crtc_atomic_flush(struct drm_crtc *crtc,
  370. struct drm_crtc_state *old_crtc_state)
  371. {
  372. struct omap_drm_private *priv = crtc->dev->dev_private;
  373. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  374. int ret;
  375. if (crtc->state->color_mgmt_changed) {
  376. struct drm_color_lut *lut = NULL;
  377. uint length = 0;
  378. if (crtc->state->gamma_lut) {
  379. lut = (struct drm_color_lut *)
  380. crtc->state->gamma_lut->data;
  381. length = crtc->state->gamma_lut->length /
  382. sizeof(*lut);
  383. }
  384. priv->dispc_ops->mgr_set_gamma(omap_crtc->channel, lut, length);
  385. }
  386. omap_crtc_write_crtc_properties(crtc);
  387. /* Only flush the CRTC if it is currently enabled. */
  388. if (!omap_crtc->enabled)
  389. return;
  390. DBG("%s: GO", omap_crtc->name);
  391. ret = drm_crtc_vblank_get(crtc);
  392. WARN_ON(ret != 0);
  393. spin_lock_irq(&crtc->dev->event_lock);
  394. priv->dispc_ops->mgr_go(omap_crtc->channel);
  395. omap_crtc_arm_event(crtc);
  396. spin_unlock_irq(&crtc->dev->event_lock);
  397. }
  398. static bool omap_crtc_is_plane_prop(struct drm_crtc *crtc,
  399. struct drm_property *property)
  400. {
  401. struct drm_device *dev = crtc->dev;
  402. struct omap_drm_private *priv = dev->dev_private;
  403. return property == priv->zorder_prop ||
  404. property == crtc->primary->rotation_property;
  405. }
  406. static int omap_crtc_atomic_set_property(struct drm_crtc *crtc,
  407. struct drm_crtc_state *state,
  408. struct drm_property *property,
  409. uint64_t val)
  410. {
  411. if (omap_crtc_is_plane_prop(crtc, property)) {
  412. struct drm_plane_state *plane_state;
  413. struct drm_plane *plane = crtc->primary;
  414. /*
  415. * Delegate property set to the primary plane. Get the plane
  416. * state and set the property directly.
  417. */
  418. plane_state = drm_atomic_get_plane_state(state->state, plane);
  419. if (IS_ERR(plane_state))
  420. return PTR_ERR(plane_state);
  421. return drm_atomic_plane_set_property(plane, plane_state,
  422. property, val);
  423. }
  424. return -EINVAL;
  425. }
  426. static int omap_crtc_atomic_get_property(struct drm_crtc *crtc,
  427. const struct drm_crtc_state *state,
  428. struct drm_property *property,
  429. uint64_t *val)
  430. {
  431. if (omap_crtc_is_plane_prop(crtc, property)) {
  432. /*
  433. * Delegate property get to the primary plane. The
  434. * drm_atomic_plane_get_property() function isn't exported, but
  435. * can be called through drm_object_property_get_value() as that
  436. * will call drm_atomic_get_property() for atomic drivers.
  437. */
  438. return drm_object_property_get_value(&crtc->primary->base,
  439. property, val);
  440. }
  441. return -EINVAL;
  442. }
  443. static const struct drm_crtc_funcs omap_crtc_funcs = {
  444. .reset = drm_atomic_helper_crtc_reset,
  445. .set_config = drm_atomic_helper_set_config,
  446. .destroy = omap_crtc_destroy,
  447. .page_flip = drm_atomic_helper_page_flip,
  448. .gamma_set = drm_atomic_helper_legacy_gamma_set,
  449. .set_property = drm_atomic_helper_crtc_set_property,
  450. .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
  451. .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
  452. .atomic_set_property = omap_crtc_atomic_set_property,
  453. .atomic_get_property = omap_crtc_atomic_get_property,
  454. .enable_vblank = omap_irq_enable_vblank,
  455. .disable_vblank = omap_irq_disable_vblank,
  456. };
  457. static const struct drm_crtc_helper_funcs omap_crtc_helper_funcs = {
  458. .mode_set_nofb = omap_crtc_mode_set_nofb,
  459. .atomic_check = omap_crtc_atomic_check,
  460. .atomic_begin = omap_crtc_atomic_begin,
  461. .atomic_flush = omap_crtc_atomic_flush,
  462. .atomic_enable = omap_crtc_atomic_enable,
  463. .atomic_disable = omap_crtc_atomic_disable,
  464. };
  465. /* -----------------------------------------------------------------------------
  466. * Init and Cleanup
  467. */
  468. static const char *channel_names[] = {
  469. [OMAP_DSS_CHANNEL_LCD] = "lcd",
  470. [OMAP_DSS_CHANNEL_DIGIT] = "tv",
  471. [OMAP_DSS_CHANNEL_LCD2] = "lcd2",
  472. [OMAP_DSS_CHANNEL_LCD3] = "lcd3",
  473. };
  474. void omap_crtc_pre_init(void)
  475. {
  476. memset(omap_crtcs, 0, sizeof(omap_crtcs));
  477. dss_install_mgr_ops(&mgr_ops);
  478. }
  479. void omap_crtc_pre_uninit(void)
  480. {
  481. dss_uninstall_mgr_ops();
  482. }
  483. /* initialize crtc */
  484. struct drm_crtc *omap_crtc_init(struct drm_device *dev,
  485. struct drm_plane *plane, struct omap_dss_device *dssdev)
  486. {
  487. struct omap_drm_private *priv = dev->dev_private;
  488. struct drm_crtc *crtc = NULL;
  489. struct omap_crtc *omap_crtc;
  490. enum omap_channel channel;
  491. struct omap_dss_device *out;
  492. int ret;
  493. out = omapdss_find_output_from_display(dssdev);
  494. channel = out->dispc_channel;
  495. omap_dss_put_device(out);
  496. DBG("%s", channel_names[channel]);
  497. /* Multiple displays on same channel is not allowed */
  498. if (WARN_ON(omap_crtcs[channel] != NULL))
  499. return ERR_PTR(-EINVAL);
  500. omap_crtc = kzalloc(sizeof(*omap_crtc), GFP_KERNEL);
  501. if (!omap_crtc)
  502. return ERR_PTR(-ENOMEM);
  503. crtc = &omap_crtc->base;
  504. init_waitqueue_head(&omap_crtc->pending_wait);
  505. omap_crtc->channel = channel;
  506. omap_crtc->name = channel_names[channel];
  507. ret = drm_crtc_init_with_planes(dev, crtc, plane, NULL,
  508. &omap_crtc_funcs, NULL);
  509. if (ret < 0) {
  510. dev_err(dev->dev, "%s(): could not init crtc for: %s\n",
  511. __func__, dssdev->name);
  512. kfree(omap_crtc);
  513. return ERR_PTR(ret);
  514. }
  515. drm_crtc_helper_add(crtc, &omap_crtc_helper_funcs);
  516. /* The dispc API adapts to what ever size, but the HW supports
  517. * 256 element gamma table for LCDs and 1024 element table for
  518. * OMAP_DSS_CHANNEL_DIGIT. X server assumes 256 element gamma
  519. * tables so lets use that. Size of HW gamma table can be
  520. * extracted with dispc_mgr_gamma_size(). If it returns 0
  521. * gamma table is not supprted.
  522. */
  523. if (priv->dispc_ops->mgr_gamma_size(channel)) {
  524. uint gamma_lut_size = 256;
  525. drm_crtc_enable_color_mgmt(crtc, 0, false, gamma_lut_size);
  526. drm_mode_crtc_set_gamma_size(crtc, gamma_lut_size);
  527. }
  528. omap_plane_install_properties(crtc->primary, &crtc->base);
  529. omap_crtcs[channel] = omap_crtc;
  530. return crtc;
  531. }